bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] dd.c: reduce duplication in new O_FULLBLOCK-defining code


From: Jim Meyering
Subject: [PATCH] dd.c: reduce duplication in new O_FULLBLOCK-defining code
Date: Fri, 08 Aug 2008 22:16:17 +0200

This eliminates some recently-introduced duplication in dd.c:

>From 726419a9062abbc07a0ab4d4978bff765d14537e Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 7 Aug 2008 23:01:16 +0200
Subject: [PATCH] dd.c: reduce duplication in new O_FULLBLOCK-defining code

* src/dd.c (MULTIPLE_BITS_SET): New macro, extracted from...
(multiple_bits_set): ...this function.
Use a single-line, and far simpler expression (no need to list all
O_* symbols again) to validate the derived O_FULLBLOCK value.
---
 src/dd.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index 8c9400b..ea852af 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -278,11 +278,10 @@ enum
 /* Ensure that we didn't shift it off the end.  */
 verify (O_FULLBLOCK != 0);

+#define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0)
+
 /* Ensure that this is a single-bit value.  */
-verify ((O_FULLBLOCK &
-        ( O_APPEND | O_BINARY | O_DIRECT | O_DIRECTORY | O_DSYNC
-          | O_NOATIME | O_NOCTTY | O_NOFOLLOW | O_NOLINKS | O_NONBLOCK
-          | O_SYNC | O_TEXT)) == 0);
+verify ( ! MULTIPLE_BITS_SET (O_FULLBLOCK));

 /* Flags, for iflag="..." and oflag="...".  */
 static struct symbol_value const flags[] =
@@ -576,7 +575,7 @@ translate_charset (char const *new_trans)
 static inline bool
 multiple_bits_set (int i)
 {
-  return (i & (i - 1)) != 0;
+  return MULTIPLE_BITS_SET (i);
 }

 /* Print transfer statistics.  */
--
1.6.0.rc2.2.g59bf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]