chiark / gitweb /
tree-wide: check if errno is greater then zero
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 11 Jan 2016 17:47:14 +0000 (12:47 -0500)
committerSven Eden <yamakuzure@gmx.net>
Wed, 17 May 2017 13:22:15 +0000 (15:22 +0200)
gcc is confused by the common idiom of
  return errno ? -errno : -ESOMETHING
and thinks a positive value may be returned. Replace this condition
with errno > 0 to help gcc and avoid many spurious warnings. I filed
a gcc rfe a long time ago, but it hard to say if it will ever be
implemented [1].

Both conventions were used in the codebase, this change makes things
more consistent. This is a follow up to bcb161b0230f.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846

src/basic/cgroup-util.c
src/basic/fileio.c
src/basic/terminal-util.c
src/login/logind-core.c
src/login/logind-dbus.c

index 85bbc670397dc14ce098bdb5588b7158240820f7..6211cafc556948b1d79a83670edbfd26ee50e511 100644 (file)
@@ -87,7 +87,7 @@ int cg_read_pid(FILE *f, pid_t *_pid) {
                 if (feof(f))
                         return 0;
 
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
         }
 
         if (ul <= 0)
index bfb75608f887d26926886398f091c71ea0e6f2ff..6c0be71df9cc0feb6319a74a1c43aaf5cca09dd0 100644 (file)
@@ -154,7 +154,7 @@ int read_one_line_file(const char *fn, char **line) {
         if (!fgets(t, sizeof(t), f)) {
 
                 if (ferror(f))
-                        return errno ? -errno : -EIO;
+                        return errno > 0 ? -errno : -EIO;
 
                 t[0] = 0;
         }
@@ -1059,7 +1059,7 @@ int fflush_and_check(FILE *f) {
         fflush(f);
 
         if (ferror(f))
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return 0;
 }
index 9e7e3b618931bdce13f08c4558acaf95d4ec20ac..9fd4d3806ba0ceb223481f59ddfb3244dbbc9d82 100644 (file)
@@ -121,7 +121,7 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
 
         errno = 0;
         if (!fgets(line, sizeof(line), f))
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         truncate_nl(line);
 
@@ -205,7 +205,7 @@ int ask_string(char **ret, const char *text, ...) {
 
                 errno = 0;
                 if (!fgets(line, sizeof(line), stdin))
-                        return errno ? -errno : -EIO;
+                        return errno > 0 ? -errno : -EIO;
 
                 if (!endswith(line, "\n"))
                         putchar('\n');
index c92b38952e104efa4201570986bfb5de98c11b7b..be83768221af4c16e3746373107a7a0d30599fcb 100644 (file)
@@ -139,7 +139,7 @@ int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user) {
         errno = 0;
         p = getpwuid(uid);
         if (!p)
-                return errno ? -errno : -ENOENT;
+                return errno > 0 ? -errno : -ENOENT;
 
         return manager_add_user(m, uid, p->pw_gid, p->pw_name, _user);
 }
index 64e67409e18429284838a7723a00a2c27dac5c5c..5dfe5aab2ab04d702a3e2d785eda6fb242c45878 100644 (file)
@@ -1117,7 +1117,7 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu
         errno = 0;
         pw = getpwuid(uid);
         if (!pw)
-                return errno ? -errno : -ENOENT;
+                return errno > 0 ? -errno : -ENOENT;
 
         r = bus_verify_polkit_async(
                         message,