summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-01-11 12:47:14 -0500
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit6d1d622bf1f4da725d11cbe5c57a757869ae54c6 (patch)
tree1c34ed1dcf37abf41bb154c3fcedd9fb1bce8b88
parent75cbb152e09780f094d869c5d92d6815442f2900 (diff)
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
-rw-r--r--src/basic/cgroup-util.c2
-rw-r--r--src/basic/fileio.c4
-rw-r--r--src/basic/terminal-util.c4
-rw-r--r--src/login/logind-core.c2
-rw-r--r--src/login/logind-dbus.c2
5 files changed, 7 insertions, 7 deletions
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,