diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-14 22:53:21 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-15 00:02:54 -0600 |
commit | f87541521e517e8b65a196eada58aceb098ca918 (patch) | |
tree | 35c0a4e2b4cf1915959ae35573d1b3f452b30175 | |
parent | 101dbb13a1d0270b931291607962e6780ec856a5 (diff) | |
download | gcompat-f87541521e517e8b65a196eada58aceb098ca918.tar.gz gcompat-f87541521e517e8b65a196eada58aceb098ca918.tar.bz2 gcompat-f87541521e517e8b65a196eada58aceb098ca918.tar.xz gcompat-f87541521e517e8b65a196eada58aceb098ca918.zip |
stdlib: Implement most LSB functions plus more
* Fix prototype of __realpath_chk.
* Add all strto* functions from LSB, plus the ones thata were previously
incorrectly in string.c
The main missing LSB functions are the reentrant random functions, which
should not be used anyway.
Signed-off-by: Samuel Holland <samuel@sholland.org>
-rw-r--r-- | libgcompat/stdlib.c | 112 | ||||
-rw-r--r-- | libgcompat/string.c | 13 |
2 files changed, 107 insertions, 18 deletions
diff --git a/libgcompat/stdlib.c b/libgcompat/stdlib.c index 6783615..c1eaa92 100644 --- a/libgcompat/stdlib.c +++ b/libgcompat/stdlib.c @@ -1,14 +1,116 @@ #include <assert.h> /* assert */ -#include <stdlib.h> /* strtod */ +#include <limits.h> /* PATH_MAX */ +#include <locale.h> /* locale_t */ +#include <stddef.h> /* NULL, size_t */ +#include <stdlib.h> /* getenv, realpath, strto* */ +#include <unistd.h> /* get*id */ -char *__realpath_chk(const char *path, char *resolved_path) +/** + * Resolve a pathname, with buffer overflow checking. + * + * LSB 5.0: LSB-Core-generic/baselib---realpath-chk-1.html + */ +char *__realpath_chk(const char *path, char *resolved_path, size_t resolved_len) { assert(path != NULL); + assert(resolved_path != NULL); + assert(resolved_len >= PATH_MAX); + return realpath(path, resolved_path); } -double __strtod_internal(const char *__nptr, char **__endptr, int __group) +/** + * Get an environment variable. + */ +char *__secure_getenv(const char *name) +{ + if (geteuid() != getuid() || getegid() != getgid()) { + return NULL; + } + + return getenv(name); +} + +/** + * Underlying function for strtod. + * + * "__group shall be 0 or the behavior of __strtod_internal() is undefined." + * + * LSB 5.0: LSB-Core-generic/baselib---strtod-internal-1.html + */ +double __strtod_internal(const char *nptr, char **endptr, int group) +{ + assert(group == 0); + + return strtod(nptr, endptr); +} + +/** + * Underlying function for strtof. + * + * "__group shall be 0 or the behavior of __strtof_internal() is undefined." + * + * LSB 5.0: LSB-Core-generic/baselib---strtof-internal.html + */ +float __strtof_internal(const char *nptr, char **endptr, int group) +{ + assert(group == 0); + + return strtof(nptr, endptr); +} + +/** + * Underlying function for strtold. + * + * "__group shall be 0 or the behavior of __strtold_internal() is undefined." + * + * LSB 5.0: LSB-Core-generic/baselib---strtold-internal-1.html + */ +long double __strtold_internal(const char *nptr, char **endptr, int group) +{ + assert(group == 0); + + return strtold(nptr, endptr); +} + +/** + * Convert string value to a long long integer. + * + * Some day, when musl supports LC_NUMERIC, we can probably remove this. + */ +long long int strtoll_l(const char *nptr, char **endptr, int base, + locale_t locale) +{ + return strtoll(nptr, endptr, base); +} + +/** + * Convert string value to a long long integer. + * + * LSB 5.0: LSB-Core-generic/baselib-strtoq-3.html + */ +long long strtoq(const char *nptr, char **endptr, int base) +{ + return strtoll(nptr, endptr, base); +} + +/** + * Convert a string to an unsigned long long. + * + * Some day, when musl supports LC_NUMERIC, we can probably remove this. + */ +unsigned long long int strtoull_l(const char *nptr, char **endptr, int base, + locale_t locale) +{ + return strtoull(nptr, endptr, base); +} + +/** + * Convert a string to an unsigned long long. + * + * LSB 5.0: LSB-Core-generic/baselib-strtouq-3.html + */ +unsigned long long strtouq(const char *nptr, char **endptr, int base) { - assert(__group == 0); - return strtod(__nptr, __endptr); + return strtoull(nptr, endptr, base); } diff --git a/libgcompat/string.c b/libgcompat/string.c index 7ca0bf6..2c05caf 100644 --- a/libgcompat/string.c +++ b/libgcompat/string.c @@ -84,16 +84,3 @@ char *__strsep_g(char **stringp, const char *delim) { return strsep(stringp, delim); } - -/* Some day, when musl supports LC_NUMERIC, we can probably remove these */ -long long int strtoll_l(const char *nptr, char **endptr, int base, - locale_t locale) -{ - return strtoll(nptr, endptr, base); -} - -unsigned long long int strtoull_l(const char *nptr, char **endptr, int base, - locale_t locale) -{ - return strtoull(nptr, endptr, base); -} |