dd: use a more portable definition of O_FULLBLOCK
authorEric Blake <ebb9@byu.net>
Thu, 19 Mar 2009 19:14:26 +0000 (20:14 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 20 Mar 2009 14:16:50 +0000 (15:16 +0100)
* src/dd.c (O_FULLBLOCK): Compute its value without using a 180KB
macro.  This avoids triggering a compilation failure with HP-UX's cc.
Reported by Matthew Woehlke.

src/dd.c

index 9a1c875fe11230a4b382e7be3b3b67081c3f0e5c..3ba616b575cf5bb28e2953a3fbb65ec2a842e4ee 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -265,23 +265,28 @@ static struct symbol_value const conversions[] =
 
 enum
   {
-    /* Use a value that is larger than that of any other O_ symbol.  */
-    O_FULLBLOCK = ((MAX (O_APPEND,
-                   MAX (O_BINARY,
-                   MAX (O_CIO,
-                   MAX (O_DIRECT,
-                   MAX (O_DIRECTORY,
-                   MAX (O_DSYNC,
-                   MAX (O_NOATIME,
-                   MAX (O_NOCTTY,
-                   MAX (O_NOFOLLOW,
-                   MAX (O_NOLINKS,
-                   MAX (O_NONBLOCK,
-                   MAX (O_SYNC,
-                   MAX (O_TEXT, 0)))))))))))))) << 1)
+    /* Compute a value that's bitwise disjoint from the union
+       of all O_ values.  */
+    v = ~(0
+          | O_APPEND
+          | O_BINARY
+          | O_CIO
+          | O_DIRECT
+          | O_DIRECTORY
+          | O_DSYNC
+          | O_NOATIME
+          | O_NOCTTY
+          | O_NOFOLLOW
+          | O_NOLINKS
+          | O_NONBLOCK
+          | O_SYNC
+          | O_TEXT
+          ),
+    /* Use its lowest bit.  */
+    O_FULLBLOCK = v ^ (v & (v - 1))
   };
 
-/* Ensure that we didn't shift it off the end.  */
+/* Ensure that we got something.  */
 verify (O_FULLBLOCK != 0);
 
 #define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0)