diff options
| author | Michael Brown | 2012-04-17 11:15:29 +0200 |
|---|---|---|
| committer | Michael Brown | 2012-04-17 11:42:08 +0200 |
| commit | 1d33649516f2046e9fe692d42fffeeec96a2b858 (patch) | |
| tree | f48462239a4cd88f506b8613cb0c05d885735fcf /src | |
| parent | [multiboot] Include full image URI in command line (diff) | |
| download | ipxe-1d33649516f2046e9fe692d42fffeeec96a2b858.tar.gz ipxe-1d33649516f2046e9fe692d42fffeeec96a2b858.tar.xz ipxe-1d33649516f2046e9fe692d42fffeeec96a2b858.zip | |
[libc] Allow strtoul() to interpret negative numbers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/i386/core/runtime.c | 1 | ||||
| -rw-r--r-- | src/core/misc.c | 12 | ||||
| -rw-r--r-- | src/core/strtoull.c | 12 | ||||
| -rw-r--r-- | src/include/stdlib.h | 4 |
4 files changed, 25 insertions, 4 deletions
diff --git a/src/arch/i386/core/runtime.c b/src/arch/i386/core/runtime.c index efa501e6e..fcfec060f 100644 --- a/src/arch/i386/core/runtime.c +++ b/src/arch/i386/core/runtime.c @@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stddef.h> #include <stdint.h> #include <stdlib.h> +#include <ctype.h> #include <errno.h> #include <assert.h> #include <ipxe/init.h> diff --git a/src/core/misc.c b/src/core/misc.c index 8f56e1fb4..11342481a 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -35,8 +35,17 @@ int inet_aton ( const char *cp, struct in_addr *inp ) { unsigned long strtoul ( const char *p, char **endp, int base ) { unsigned long ret = 0; + int negative = 0; unsigned int charval; + while ( isspace ( *p ) ) + p++; + + if ( *p == '-' ) { + negative = 1; + p++; + } + base = strtoul_base ( &p, base ); while ( 1 ) { @@ -47,6 +56,9 @@ unsigned long strtoul ( const char *p, char **endp, int base ) { p++; } + if ( negative ) + ret = -ret; + if ( endp ) *endp = ( char * ) p; diff --git a/src/core/strtoull.c b/src/core/strtoull.c index b1ceeb45b..00986eef0 100644 --- a/src/core/strtoull.c +++ b/src/core/strtoull.c @@ -29,8 +29,17 @@ FILE_LICENCE ( GPL2_OR_LATER ); */ unsigned long long strtoull ( const char *p, char **endp, int base ) { unsigned long long ret = 0; + int negative = 0; unsigned int charval; + while ( isspace ( *p ) ) + p++; + + if ( *p == '-' ) { + negative = 1; + p++; + } + base = strtoul_base ( &p, base ); while ( 1 ) { @@ -41,6 +50,9 @@ unsigned long long strtoull ( const char *p, char **endp, int base ) { p++; } + if ( negative ) + ret = -ret; + if ( endp ) *endp = ( char * ) p; diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 19a7c8e09..3d30858ff 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -5,7 +5,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stdint.h> #include <assert.h> -#include <ctype.h> /***************************************************************************** * @@ -18,9 +17,6 @@ static inline int strtoul_base ( const char **pp, int base ) { const char *p = *pp; - while ( isspace ( *p ) ) - p++; - if ( base == 0 ) { base = 10; if ( *p == '0' ) { |
