diff options
Diffstat (limited to 'tools/include/nolibc/stdlib.h')
| -rw-r--r-- | tools/include/nolibc/stdlib.h | 54 | 
1 files changed, 23 insertions, 31 deletions
| diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 86ad378ab1ea..5fd99a480f82 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -4,6 +4,9 @@   * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>   */ +/* make sure to include all global symbols */ +#include "nolibc.h" +  #ifndef _NOLIBC_STDLIB_H  #define _NOLIBC_STDLIB_H @@ -29,6 +32,24 @@ static __attribute__((unused)) char itoa_buffer[21];   * As much as possible, please keep functions alphabetically sorted.   */ +static __inline__ +int abs(int j) +{ +	return j >= 0 ? j : -j; +} + +static __inline__ +long labs(long j) +{ +	return j >= 0 ? j : -j; +} + +static __inline__ +long long llabs(long long j) +{ +	return j >= 0 ? j : -j; +} +  /* must be exported, as it's used by libgcc for various divide functions */  void abort(void);  __attribute__((weak,unused,noreturn,section(".text.nolibc_abort"))) @@ -103,32 +124,6 @@ char *getenv(const char *name)  }  static __attribute__((unused)) -unsigned long getauxval(unsigned long type) -{ -	const unsigned long *auxv = _auxv; -	unsigned long ret; - -	if (!auxv) -		return 0; - -	while (1) { -		if (!auxv[0] && !auxv[1]) { -			ret = 0; -			break; -		} - -		if (auxv[0] == type) { -			ret = auxv[1]; -			break; -		} - -		auxv += 2; -	} - -	return ret; -} - -static __attribute__((unused))  void *malloc(size_t len)  {  	struct nolibc_heap *heap; @@ -275,7 +270,7 @@ int itoa_r(long in, char *buffer)  	int len = 0;  	if (in < 0) { -		in = -in; +		in = -(unsigned long)in;  		*(ptr++) = '-';  		len++;  	} @@ -411,7 +406,7 @@ int i64toa_r(int64_t in, char *buffer)  	int len = 0;  	if (in < 0) { -		in = -in; +		in = -(uint64_t)in;  		*(ptr++) = '-';  		len++;  	} @@ -548,7 +543,4 @@ uintmax_t strtoumax(const char *nptr, char **endptr, int base)  	return __strtox(nptr, endptr, base, 0, UINTMAX_MAX);  } -/* make sure to include all global symbols */ -#include "nolibc.h" -  #endif /* _NOLIBC_STDLIB_H */ | 
