]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Allow strtoul() to interpret negative numbers
authorMichael Brown <mcb30@ipxe.org>
Tue, 17 Apr 2012 09:15:29 +0000 (10:15 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 17 Apr 2012 09:42:08 +0000 (10:42 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/core/runtime.c
src/core/misc.c
src/core/strtoull.c
src/include/stdlib.h

index efa501e6eab26e8a4a3b1c7aed777b114c0533fd..fcfec060fc12a913871da6e45820526cc4a7943f 100644 (file)
@@ -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>
index 8f56e1fb44ae5a54cc2aa6b0d4d6164bf3b4d4e5..11342481a73c12cfad1163d16d989027accc8d52 100644 (file)
@@ -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;
 
index b1ceeb45b0ecd9c144c2f47a8399158f41fc372e..00986eef0ef9470d8049b51660b6374a2f9c7dfc 100644 (file)
@@ -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;
 
index 19a7c8e09afb8e592ca6c67f074ef7414fd9f07f..3d30858ffcd25e12b3b37da2b362e6d361cf2999 100644 (file)
@@ -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' ) {