]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: avoid a warning form gcc's new -Wlogical-op
authorJim Meyering <meyering@fb.com>
Sat, 9 May 2015 17:57:54 +0000 (10:57 -0700)
committerJim Meyering <meyering@fb.com>
Sun, 10 May 2015 05:49:07 +0000 (22:49 -0700)
Without this change, very recent gcc (e.g., version 6.0.0 20150509)
would print the following when configured with --enable-gcc-warnings:

  src/copy.c:165:30: error: logical 'or' of equal expressions \
    [-Werror=logical-op]
    && (errno == EOPNOTSUPP || errno == ENOTSUP || errno == ENOSYS))
                           ^
* src/system.h (is_ENOTSUP): New function.
* src/copy.c (punch_hole): Use it.
* src/ls.c (errno_unsupported, gobble_file): Use it.

src/copy.c
src/ls.c
src/system.h

index b93c533139b6a992ce81f25c155ec0887b6240cd..3af42957a23c2ebb773f69aaa614e9d55a57bdec 100644 (file)
@@ -161,8 +161,7 @@ punch_hole (int fd, off_t offset, off_t length)
 # if defined FALLOC_FL_PUNCH_HOLE && defined FALLOC_FL_KEEP_SIZE
   ret = fallocate (fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                    offset, length);
-  if (ret < 0
-      && (errno == EOPNOTSUPP || errno == ENOTSUP || errno == ENOSYS))
+  if (ret < 0 && (is_ENOTSUP (errno) || errno == ENOSYS))
     ret = 0;
 # endif
 #endif
index b308dd33ef48ca0f1eceafa4c77976aea83b5191..01404e25cd8c4fca12d0adb1b26e379698b2fe59 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -2828,10 +2828,7 @@ clear_files (void)
 static bool
 errno_unsupported (int err)
 {
-  return (err == EINVAL
-          || err == ENOSYS
-          || err == ENOTSUP
-          || err == EOPNOTSUPP);
+  return (err == EINVAL || err == ENOSYS || is_ENOTSUP (err));
 }
 
 /* Cache *getfilecon failure, when it's trivial to do so.
@@ -3069,7 +3066,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
                  ls fail just because the file (even a command line argument)
                  isn't on the right type of file system.  I.e., a getfilecon
                  failure isn't in the same class as a stat failure.  */
-              if (errno == ENOTSUP || errno == EOPNOTSUPP || errno == ENODATA)
+              if (is_ENOTSUP (errno) || errno == ENODATA)
                 err = 0;
             }
 
index c55f6d8bd13a0a695e2806454fc77472b15e0fae..0e25bc414b3f4775b5369b86e0e091dc5fd16d8c 100644 (file)
@@ -695,3 +695,17 @@ stzncpy (char *restrict dest, char const *restrict src, size_t len)
    in selinux.h before libselinux-2.3 (May 2014).
    When version >= 2.3 is ubiquitous remove this function.  */
 static inline char * se_const (char const * sctx) { return (char *) sctx; }
+
+/* Return true if ERR is ENOTSUP or EOPNOTSUPP, otherwise false.
+   This wrapper function avoids the redundant 'or'd comparison on
+   systems like Linux for which they have the same value.  It also
+   avoids the gcc warning to that effect.  */
+static inline bool
+is_ENOTSUP (int err)
+{
+  return err == EOPNOTSUPP
+#if ENOTSUP != EOPNOTSUPP
+    || err == ENOTSUP
+#endif
+    ;
+}