chiark / gitweb /
Always use errno > 0 to help gcc
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Mar 2013 13:24:15 +0000 (09:24 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 29 Mar 2013 14:12:41 +0000 (10:12 -0400)
gcc thinks that errno might be negative, and functions could return
something positive on error (-errno). Should not matter in practice,
but makes an -O4 build much quieter.

12 files changed:
src/fstab-generator/fstab-generator.c
src/libsystemd-bus/sd-bus.c
src/libsystemd-daemon/sd-daemon.c
src/locale/localectl.c
src/shared/calendarspec.c
src/shared/fileio.c
src/shared/socket-util.c
src/shared/time-util.c
src/shared/util.c
src/shared/util.h
src/systemctl/systemctl.c
src/tmpfiles/tmpfiles.c

index 4eaa52d1c248f23e7678cec69d18f7af123dfcb5..2790fc6e8e9b7ebe7a5456a73e06fcf2bda4963b 100644 (file)
@@ -69,7 +69,7 @@ static int mount_find_pri(struct mntent *me, int *ret) {
 
         errno = 0;
         r = strtoul(pri, &end, 10);
-        if (errno != 0)
+        if (errno > 0)
                 return -errno;
 
         if (end == pri || (*end != ',' && *end != 0))
index 6acc59e82c49401ce486e618401a4afbd1c93b78..08a218b7cccbf7174f16f5b2da789fa1a194ffc3 100644 (file)
@@ -507,7 +507,7 @@ static int parse_exec_address(sd_bus *b, const char **p, char **guid) {
 
                         errno = 0;
                         ul = strtoul(*p + 4, (char**) p, 10);
-                        if (errno != 0 || **p != '=' || ul > 256) {
+                        if (errno > 0 || **p != '=' || ul > 256) {
                                 r = -EINVAL;
                                 goto fail;
                         }
index 79d8ca3709ae143c62784174801a5d770dde6793..b1ff43132a3cc89a03fb3f68bc12c6ddeca233ea 100644 (file)
@@ -84,7 +84,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
         errno = 0;
         l = strtoul(e, &p, 10);
 
-        if (errno != 0) {
+        if (errno > 0) {
                 r = -errno;
                 goto finish;
         }
@@ -109,7 +109,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
         errno = 0;
         l = strtoul(e, &p, 10);
 
-        if (errno != 0) {
+        if (errno > 0) {
                 r = -errno;
                 goto finish;
         }
index 9f996dbc9820fa559105f153e6291e7fc30dda07..fc312894c6c20253926a25ab5e5fa164a36bfd58 100644 (file)
@@ -421,7 +421,7 @@ static int add_locales_from_libdir (Set *locales) {
                 errno = 0;
         }
 
-        if (errno != 0) {
+        if (errno > 0) {
                 log_error("Failed to read locale directory: %m");
                 return -errno;
         }
index cc680779b52dd3e113fbb9ebf776b307050ae43b..13f70d8e72edaae269b5fddc5f56142a5b7563e9 100644 (file)
@@ -391,7 +391,7 @@ static int prepend_component(const char **p, CalendarComponent **c) {
 
         errno = 0;
         value = strtoul(*p, &e, 10);
-        if (errno != 0)
+        if (errno > 0)
                 return -errno;
         if (e == *p)
                 return -EINVAL;
@@ -400,7 +400,7 @@ static int prepend_component(const char **p, CalendarComponent **c) {
 
         if (*e == '/') {
                 repeat = strtoul(e+1, &ee, 10);
-                if (errno != 0)
+                if (errno > 0)
                         return -errno;
                 if (ee == e+1)
                         return -EINVAL;
index 0eca4416f81f89901a00a64559f714b07fe26886..1c7d4851303af7ba9caae54809dc83207c8d55a5 100644 (file)
@@ -364,7 +364,7 @@ int write_env_file(const char *fname, char **l) {
         fflush(f);
 
         if (ferror(f)) {
-                if (errno != 0)
+                if (errno > 0)
                         r = -errno;
                 else
                         r = -EIO;
index f6ddea31838512e4435cf4cad1882f1280f13adf..53457886e27ea58cf2d87fe2d12bcef0567e1c42 100644 (file)
@@ -68,7 +68,7 @@ int socket_address_parse(SocketAddress *a, const char *s) {
                 errno = 0;
                 if (inet_pton(AF_INET6, n, &a->sockaddr.in6.sin6_addr) <= 0) {
                         free(n);
-                        return errno != 0 ? -errno : -EINVAL;
+                        return errno > 0 ? -errno : -EINVAL;
                 }
 
                 free(n);
index e192d5ef58d712302231575fce57808f7176ef5e..0c6deb66f4242367192a8da54a9894be7c4e4b0c 100644 (file)
@@ -547,7 +547,7 @@ int parse_usec(const char *t, usec_t *usec) {
                 errno = 0;
                 l = strtoll(p, &e, 10);
 
-                if (errno != 0)
+                if (errno > 0)
                         return -errno;
 
                 if (l < 0)
@@ -627,7 +627,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
                 errno = 0;
                 l = strtoll(p, &e, 10);
 
-                if (errno != 0)
+                if (errno > 0)
                         return -errno;
 
                 if (l < 0)
index 2241b79859ff16233f4a33e7f66aea13efb11464..7281cc8ab88a572b507404f28d5332b7a176437f 100644 (file)
@@ -2265,7 +2265,7 @@ int parse_bytes(const char *t, off_t *bytes) {
                 errno = 0;
                 l = strtoll(p, &e, 10);
 
-                if (errno != 0)
+                if (errno > 0)
                         return -errno;
 
                 if (l < 0)
@@ -4191,7 +4191,7 @@ int get_user_creds(
         }
 
         if (!p)
-                return errno != 0 ? -errno : -ESRCH;
+                return errno > 0 ? -errno : -ESRCH;
 
         if (uid)
                 *uid = p->pw_uid;
@@ -4272,7 +4272,7 @@ int get_group_creds(const char **groupname, gid_t *gid) {
         }
 
         if (!g)
-                return errno != 0 ? -errno : -ESRCH;
+                return errno > 0 ? -errno : -ESRCH;
 
         if (gid)
                 *gid = g->gr_gid;
index aefde5f85a23ffc25e4f3ca974b19892a2b678ff..485733f65074475842237571af8d669d130f7421 100644 (file)
@@ -595,7 +595,7 @@ int create_tmp_dir(char template[], char** dir_name);
 #define FOREACH_DIRENT(de, d, on_error)                                 \
         for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d))   \
                 if (!de) {                                              \
-                        if (errno != 0) {                               \
+                        if (errno > 0) {                                \
                                 on_error;                               \
                         }                                               \
                         break;                                          \
index edd136addddf9bd10dbdfe8ab29c3f568c71f5a0..f7ae47e7c7a2220e2d536a9d0af9489236577207 100644 (file)
@@ -4629,11 +4629,11 @@ static int parse_time_spec(const char *t, usec_t *_u) {
 
                 errno = 0;
                 hour = strtol(t, &e, 10);
-                if (errno != 0 || *e != ':' || hour < 0 || hour > 23)
+                if (errno > 0 || *e != ':' || hour < 0 || hour > 23)
                         return -EINVAL;
 
                 minute = strtol(e+1, &e, 10);
-                if (errno != 0 || *e != 0 || minute < 0 || minute > 59)
+                if (errno > 0 || *e != 0 || minute < 0 || minute > 59)
                         return -EINVAL;
 
                 n = now(CLOCK_REALTIME);
index 614644a0abe59fadaf7bbf8eb378e6abf233f2ff..918702e06f0fa6ea28d79b78521da2856c830af8 100644 (file)
@@ -611,7 +611,7 @@ static int glob_item(Item *i, int (*action)(Item *, const char *)) {
         if ((k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g)) != 0) {
 
                 if (k != GLOB_NOMATCH) {
-                        if (errno != 0)
+                        if (errno > 0)
                                 errno = EIO;
 
                         log_error("glob(%s) failed: %m", i->path);