X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Fprintf.c;h=28f8aa45cbb16fc13fb9b66f5b52af4dd1dc78a0;hb=138d71bc35b86964a4c2bd97f7f578edfead1925;hp=003423d5615b9a7976db7858c9123b32b8dd40c4;hpb=cbe31dace5fb24304694d399b9eb267fbe752516;p=oweals%2Fbusybox.git diff --git a/coreutils/printf.c b/coreutils/printf.c index 003423d56..28f8aa45c 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -55,6 +55,7 @@ #include #include #include +#include #include "busybox.h" @@ -92,28 +93,9 @@ static const int S_IFMT = 0170000; #define IN_CTYPE_DOMAIN(c) 1 -#ifdef isblank -# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c)) -#else -# define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif -#ifdef isgraph -# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c)) -#else -# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c)) -#endif - -#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c)) -#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c)) -#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c)) -#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c)) -#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c)) -#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c)) -#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) -#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c)) #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c)) #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) -#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) +#define ISDIGIT(c) (((unsigned char) (c)) - '0' <= 9) #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') @@ -124,14 +106,10 @@ static int print_esc __P((char *escstart)); static int print_formatted __P((char *format, int argc, char **argv)); static long xstrtol __P((char *s)); static unsigned long xstrtoul __P((char *s)); -static void print_direc -__P( - - (char *start, size_t length, int field_width, int precision, - char *argument)); +static void print_direc __P( (char *start, size_t length, + int field_width, int precision, char *argument)); static void print_esc_char __P((int c)); static void print_esc_string __P((char *str)); -static void verify __P((char *s, char *end)); /* The value to return to the calling program. */ static int exit_status; @@ -143,7 +121,7 @@ int printf_main(int argc, char **argv) exit_status = 0; if (argc <= 1 || **(argv + 1) == '-') { - show_usage(); + bb_show_usage(); } format = argv[1]; @@ -424,51 +402,51 @@ print_direc(char *start, size_t length, int field_width, int precision, free(p); } -static unsigned long xstrtoul(char *s) +static unsigned long xstrtoul(char *arg) { - char *end; - unsigned long val; + unsigned long result; + char *endptr; + //int errno_save = errno; + + assert(arg!=NULL); errno = 0; - val = strtoul(s, &end, 0); - verify(s, end); - return val; + result = strtoul(arg, &endptr, 10); + if (errno != 0 || *endptr!='\0' || endptr==arg) + fprintf(stderr, "%s", arg); + //errno = errno_save; + return result; } -static long xstrtol(char *s) +static long xstrtol(char *arg) { - char *end; - long val; + long result; + char *endptr; + //int errno_save = errno; + + assert(arg!=NULL); errno = 0; - val = strtol(s, &end, 0); - verify(s, end); - return val; + result = strtoul(arg, &endptr, 10); + if (errno != 0 || *endptr!='\0' || endptr==arg) + fprintf(stderr, "%s", arg); + //errno = errno_save; + return result; } -static double xstrtod(char *s) +static double xstrtod(char *arg) { - char *end; - double val; + double result; + char *endptr; + //int errno_save = errno; + + assert(arg!=NULL); errno = 0; - val = strtod(s, &end); - verify(s, end); - return val; + result = strtod(arg, &endptr); + if (errno != 0 || *endptr!='\0' || endptr==arg) + fprintf(stderr, "%s", arg); + //errno = errno_save; + return result; } -static void verify(char *s, char *end) -{ - if (errno) { - fprintf(stderr, "%s", s); - exit_status = 1; - } else if (*end) { - /* - if (s == end) - fprintf(stderr, "%s: expected numeric", s); - else - fprintf(stderr, "%s: not completely converted", s); - */ - exit_status = 1; - } -}