]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: factor out common macros of stat and printf
authorNikolay Nechaev <Nikolay_Nechaev@mail.ru>
Sun, 5 May 2024 09:54:59 +0000 (12:54 +0300)
committerPádraig Brady <P@draigBrady.com>
Sun, 5 May 2024 16:50:22 +0000 (17:50 +0100)
* src/octhexdigits.h: isodigit, hextobin, octtobin macros.
* src/stat.c, src/printf.c: Use octhexdigits.h.
* src/local.mk: Corresponding adjustments.

src/local.mk
src/octhexdigits.h [new file with mode: 0644]
src/printf.c
src/stat.c

index ee377d9335316b2865d052dfd5d2f51d403ea1f1..3356f8a2ab1b77238672c35611f45a04f0cb7467 100644 (file)
@@ -54,6 +54,7 @@ noinst_HEADERS =              \
   src/iopoll.h                 \
   src/longlong.h               \
   src/ls.h                     \
+  src/octhexdigits.h           \
   src/operand2sig.h            \
   src/prog-fprintf.h           \
   src/remove.h                 \
diff --git a/src/octhexdigits.h b/src/octhexdigits.h
new file mode 100644 (file)
index 0000000..d947715
--- /dev/null
@@ -0,0 +1,7 @@
+#define isodigit(c) ('0' <= (c) && (c) <= '7')
+#define octtobin(c) ((c) - '0')
+/* FIXME-maybe: macros names may be misleading: "bin" may be interpreted as
+   "having a value of (char)'0' or (char)'1'". Rename? `hextonative`?
+   `hextoint`?  */
+#define hextobin(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
+                     'A' <= (c) && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
index 9be4f2337be67281614ec78745c0f08a6194fc4c..d6d36094187f006b8619364863ab16d5d9823c60 100644 (file)
@@ -58,6 +58,7 @@
 #include "system.h"
 #include "c-ctype.h"
 #include "cl-strtod.h"
+#include "octhexdigits.h"
 #include "quote.h"
 #include "unicodeio.h"
 #include "xprintf.h"
 
 #define AUTHORS proper_name ("David MacKenzie")
 
-#define isodigit(c) ((c) >= '0' && (c) <= '7')
-#define hextobin(c) ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
-                     (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
-#define octtobin(c) ((c) - '0')
-
 /* The value to return to the calling program.  */
 static int exit_status;
 
index 4a04bd97ffb63b21b5f6d8cf0814b5b4fdd13ef6..632f81cc9cac7f712808bdab208ea8c7ca46b7b2 100644 (file)
@@ -64,6 +64,7 @@
 #include "filemode.h"
 #include "fs.h"
 #include "mountlist.h"
+#include "octhexdigits.h"
 #include "quote.h"
 #include "stat-size.h"
 #include "stat-time.h"
@@ -167,12 +168,6 @@ statfs (char const *filename, struct fs_info *buf)
 # include <sys/nvpair.h>
 #endif
 
-/* FIXME: these are used by printf.c, too */
-#define isodigit(c) ('0' <= (c) && (c) <= '7')
-#define octtobin(c) ((c) - '0')
-#define hextobin(c) ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
-                     (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
-
 static char const digits[] = "0123456789";
 
 /* Flags that are portable for use in printf, for at least one