From: Zbigniew Jędrzejewski-Szmek Date: Mon, 11 Jan 2016 17:47:14 +0000 (-0500) Subject: tree-wide: check if errno is greater then zero X-Git-Tag: v229.1~1^2~64 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=6d1d622bf1f4da725d11cbe5c57a757869ae54c6 tree-wide: check if errno is greater then zero 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 --- diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 85bbc6703..6211cafc5 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -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) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index bfb75608f..6c0be71df 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -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; } diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 9e7e3b618..9fd4d3806 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -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'); diff --git a/src/login/logind-core.c b/src/login/logind-core.c index c92b38952..be8376822 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -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); } diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 64e67409e..5dfe5aab2 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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,