summaryrefslogtreecommitdiff
path: root/src/printf.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-04-06 20:58:16 +0000
committerJim Meyering <jim@meyering.net>1997-04-06 20:58:16 +0000
commitca70b66b7223a30031a64979d5dc9012d46f97e9 (patch)
treeb14df4ee7ed185717757130f660a5366aed20f2e /src/printf.c
parentb3f0804efd2951e8639476f93e622487f584b2af (diff)
downloadcoreutils-ca70b66b7223a30031a64979d5dc9012d46f97e9.tar.xz
(STRTOX): New macro to eliminate code duplication.
(xstrtod, xstrtol, xstrtoul): Remove functions. Use the STRTOX instead.
Diffstat (limited to 'src/printf.c')
-rw-r--r--src/printf.c68
1 files changed, 31 insertions, 37 deletions
diff --git a/src/printf.c b/src/printf.c
index 515d7d93d..6b0501426 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -54,8 +54,8 @@
#ifndef STDC_HEADERS
double strtod ();
-long strtol ();
-unsigned long strtoul ();
+long int strtol ();
+unsigned long int strtoul ();
#endif
#define isodigit(c) ((c) >= '0' && (c) <= '7')
@@ -134,41 +134,35 @@ verify (const char *s, const char *end)
}
}
-static unsigned long
-xstrtoul (const char *s)
-{
- char *end;
- unsigned long val;
-
- errno = 0;
- val = strtoul (s, &end, 0);
- verify (s, end);
- return val;
-}
-
-static long
-xstrtol (const char *s)
-{
- char *end;
- long val;
-
- errno = 0;
- val = strtol (s, &end, 0);
- verify (s, end);
- return val;
-}
-
-static double
-xstrtod (const char *s)
-{
- char *end;
- double val;
-
- errno = 0;
- val = strtod (s, &end);
- verify (s, end);
- return val;
-}
+#define STRTOX(TYPE, FUNC_NAME, LIB_FUNC_EXPR) \
+static TYPE \
+FUNC_NAME (const char *s) \
+{ \
+ char *end; \
+ TYPE val; \
+ \
+ if (*s == '\"' || *s == '\'') \
+ { \
+ val = *(unsigned char *) ++s; \
+ if (*++s != 0) \
+ { \
+ error (0, 0, \
+ _("%s: character(s) following character constant"), s); \
+ exit_status = 1; \
+ } \
+ } \
+ else \
+ { \
+ errno = 0; \
+ val = LIB_FUNC_EXPR; \
+ verify (s, end); \
+ } \
+ return val; \
+} \
+
+STRTOX (unsigned long int, xstrtoul, (strtoul (s, &end, 0)))
+STRTOX (long int, xstrtol, (strtol (s, &end, 0)))
+STRTOX (double, xstrtod, (strtod (s, &end)))
/* Output a single-character \ escape. */