[libc] Allow strtoul() to interpret negative numbers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
d11b82f0e4
commit
1d33649516
|
@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ipxe/init.h>
|
#include <ipxe/init.h>
|
||||||
|
|
|
@ -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 strtoul ( const char *p, char **endp, int base ) {
|
||||||
unsigned long ret = 0;
|
unsigned long ret = 0;
|
||||||
|
int negative = 0;
|
||||||
unsigned int charval;
|
unsigned int charval;
|
||||||
|
|
||||||
|
while ( isspace ( *p ) )
|
||||||
|
p++;
|
||||||
|
|
||||||
|
if ( *p == '-' ) {
|
||||||
|
negative = 1;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
base = strtoul_base ( &p, base );
|
base = strtoul_base ( &p, base );
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
|
@ -47,6 +56,9 @@ unsigned long strtoul ( const char *p, char **endp, int base ) {
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( negative )
|
||||||
|
ret = -ret;
|
||||||
|
|
||||||
if ( endp )
|
if ( endp )
|
||||||
*endp = ( char * ) p;
|
*endp = ( char * ) p;
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,17 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
*/
|
*/
|
||||||
unsigned long long strtoull ( const char *p, char **endp, int base ) {
|
unsigned long long strtoull ( const char *p, char **endp, int base ) {
|
||||||
unsigned long long ret = 0;
|
unsigned long long ret = 0;
|
||||||
|
int negative = 0;
|
||||||
unsigned int charval;
|
unsigned int charval;
|
||||||
|
|
||||||
|
while ( isspace ( *p ) )
|
||||||
|
p++;
|
||||||
|
|
||||||
|
if ( *p == '-' ) {
|
||||||
|
negative = 1;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
base = strtoul_base ( &p, base );
|
base = strtoul_base ( &p, base );
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
|
@ -41,6 +50,9 @@ unsigned long long strtoull ( const char *p, char **endp, int base ) {
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( negative )
|
||||||
|
ret = -ret;
|
||||||
|
|
||||||
if ( endp )
|
if ( endp )
|
||||||
*endp = ( char * ) p;
|
*endp = ( char * ) p;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <assert.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;
|
const char *p = *pp;
|
||||||
|
|
||||||
while ( isspace ( *p ) )
|
|
||||||
p++;
|
|
||||||
|
|
||||||
if ( base == 0 ) {
|
if ( base == 0 ) {
|
||||||
base = 10;
|
base = 10;
|
||||||
if ( *p == '0' ) {
|
if ( *p == '0' ) {
|
||||||
|
|
Reference in New Issue