1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 02:36:16 +02:00

maint: factor out common macros of stat and printf

* src/octhexdigits.h: isodigit, hextobin, octtobin macros.
* src/stat.c, src/printf.c: Use octhexdigits.h.
* src/local.mk: Corresponding adjustments.
This commit is contained in:
Nikolay Nechaev
2024-05-05 12:54:59 +03:00
committed by Pádraig Brady
parent 292cf89545
commit f069bb710a
4 changed files with 10 additions and 11 deletions

View 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 \

7
src/octhexdigits.h Normal file
View File

@@ -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')

View 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"
@@ -67,11 +68,6 @@
#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;

View 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