util: fix warning of equal values on logical OR
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 10 Aug 2016 15:42:12 +0000 (12:42 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Wed, 10 Aug 2016 15:45:36 +0000 (12:45 -0300)
shared/util.c: In function ‘read_str_safe’:
shared/util.c:211:24: warning: logical ‘or’ of equal expressions [-Wlogical-op]
    if (errno == EAGAIN || errno == EWOULDBLOCK ||
                        ^~
shared/util.c: In function ‘write_str_safe’:
shared/util.c:237:24: warning: logical ‘or’ of equal expressions [-Wlogical-op]
    if (errno == EAGAIN || errno == EWOULDBLOCK ||
                        ^~

This is because EAGAIN and EWOULDBLOCK have the same value. Prefer
EAGAIN, but add a static assert to catch if it's not the same in another
architecture.

shared/util.c
testsuite/test-testsuite.c

index 1a2b17c..9de080a 100644 (file)
@@ -49,6 +49,8 @@ static const struct kmod_ext {
        { }
 };
 
+assert_cc(EAGAIN == EWOULDBLOCK);
+
 /* string handling functions and memory allocations                         */
 /* ************************************************************************ */
 
@@ -208,8 +210,7 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen)
                        todo -= r;
                        done += r;
                } else {
-                       if (errno == EAGAIN || errno == EWOULDBLOCK ||
-                                                               errno == EINTR)
+                       if (errno == EAGAIN || errno == EINTR)
                                continue;
                        else
                                return -errno;
@@ -234,8 +235,7 @@ ssize_t write_str_safe(int fd, const char *buf, size_t buflen)
                        todo -= r;
                        done += r;
                } else {
-                       if (errno == EAGAIN || errno == EWOULDBLOCK ||
-                                                               errno == EINTR)
+                       if (errno == EAGAIN || errno == EINTR)
                                continue;
                        else
                                return -errno;
index e6867b5..56e7360 100644 (file)
@@ -97,7 +97,7 @@ static int testsuite_rootfs_open(const struct test *t)
                int r = read(fd, buf + done, sizeof(buf) - 1 - done);
                if (r == 0)
                        break;
-               if (r == -EWOULDBLOCK || r == -EAGAIN)
+               if (r == -EAGAIN)
                        continue;
 
                done += r;