diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-10-17 12:51:08 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2007-10-17 12:51:08 +0800 |
commit | d15aba899e3779eb8d2c9843c1d1d5b3efbfc20e (patch) | |
tree | ab5192f6f0fffffcf608aac0516de13bf42cd0cd /src/mystring.c | |
parent | [BUILTIN] Disallow completely blank strings in non-arithmetic context. (diff) | |
download | dash-d15aba899e3779eb8d2c9843c1d1d5b3efbfc20e.tar.gz dash-d15aba899e3779eb8d2c9843c1d1d5b3efbfc20e.zip |
[SHELL] Replace shared illnum message by badnum function.
This patch adds the badnum function and uses it to mostly replace the use of illnum except in miscbltin where the current code turns out to be smaller because of the twin sh_error calls.
Diffstat (limited to 'src/mystring.c')
-rw-r--r-- | src/mystring.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/mystring.c b/src/mystring.c index 8e1200a..ce48c82 100644 --- a/src/mystring.c +++ b/src/mystring.c @@ -108,6 +108,10 @@ prefix(const char *string, const char *pfx) return (char *) string; } +void badnum(const char *s) +{ + sh_error(illnum, s); +} /* * Convert a string into an integer of type intmax_t. Alow trailing spaces. @@ -121,20 +125,20 @@ intmax_t atomax(const char *s, int base) r = strtoimax(s, &p, base); if (errno != 0) - sh_error(illnum, s); + badnum(s); /* * Disallow completely blank strings in non-arithmetic (base != 0) * contexts. */ - if (base && (p == s)) - sh_error(illnum, s); + if (p == s && base) + badnum(s); while (isspace((unsigned char)*p)) p++; if (*p) - sh_error(illnum, s); + badnum(s); return r; } @@ -155,7 +159,7 @@ number(const char *s) intmax_t n = atomax10(s); if (n < 0 || n > INT_MAX) - sh_error(illnum, s); + badnum(s); return n; } |