summaryrefslogtreecommitdiff
path: root/libgcompat/stdlib.c
diff options
context:
space:
mode:
authorA. Wilcox <awilcox@wilcox-tech.com>2018-02-01 22:05:36 +0000
committerA. Wilcox <awilcox@wilcox-tech.com>2018-02-01 22:05:36 +0000
commit88815225fdabe7fa862f1c07abfcc971fdf5b04e (patch)
tree7aaae7c04fcf06aea85505fc028f476a131b9c50 /libgcompat/stdlib.c
parentc545f7393f0a10c182c2c085a36d7099b9c07a7f (diff)
parent78722ef403ffadcb78917e93e1859d43b9bf9df5 (diff)
downloadgcompat-88815225fdabe7fa862f1c07abfcc971fdf5b04e.tar.gz
gcompat-88815225fdabe7fa862f1c07abfcc971fdf5b04e.tar.bz2
gcompat-88815225fdabe7fa862f1c07abfcc971fdf5b04e.tar.xz
gcompat-88815225fdabe7fa862f1c07abfcc971fdf5b04e.zip
Merge branch 'patch-1' into 'master'
Clean up everything and add lots of new functions I hope everything here is okay. I fixed some bugs in existing functions (mostly wrong prototypes or off-by-one errors) and formatted everything to a consistent style. If you'd like me to adjust the style, that's no problem. It wasn't very consistent to start with (within the code, and compared to the documentation). *I added specific notes you may want to comment on to some of the commit messages.* Major features: * Pass correct `argv[0]` in loader * Intercept `readlink("/proc/self/exe")` to allow re-exec * Add almost all reasonable-to-implement functions in LSB 5.0.0 core generic libc. Remaining functions are: - Impossible-to-implement: sigreturn - Not useful: reentrant random (`*rand48_r`, etc.), argz, envz, pmap, rpc (clnt_*, svc*, xdr*), bindresvport - Got tired of it: checked wchar * Add additional functions used by android and its NDK tools (clang, cmake, lldb, ninja, etc.). At this point, I am able to run Android Studio with the bundled prebuilt JDK, and compile, install, and run an android application (including one with native libraries) on a real device, with only a few minor issues: * must export `LD_LIBRARY_PATH=/opt/android-studio/jre/jre/lib/amd64/server` because musl and glibc interpret the variable differently with regards to `dlopen`. This is something that has to be patched in musl builds of openjdk, so it's not a gcompat issue. * ld.bfd fails to parse the argument `--sysroot=/path`, but can parse `--sysroot /path`. So there's some difference with `getopt_long_only` (or getopt in general). May be a bug, may be just an API difference. May be it can be patched up. * LLDB fails to connect to the android phone for native debugging -- I haven't tried it on glibc yet, so it may not be a gcompat issue at all (may be a phone or the app issue). I'd be happy to send some documentation later. See merge request !1
Diffstat (limited to 'libgcompat/stdlib.c')
-rw-r--r--libgcompat/stdlib.c124
1 files changed, 118 insertions, 6 deletions
diff --git a/libgcompat/stdlib.c b/libgcompat/stdlib.c
index 30c904e..a08f914 100644
--- a/libgcompat/stdlib.c
+++ b/libgcompat/stdlib.c
@@ -1,14 +1,126 @@
-#include <assert.h> // assert
-#include <stdlib.h> // strtod
+#include <assert.h> /* assert */
+#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 strtol.
+ */
+long __strtol_internal(const char *nptr, char **endptr, int base, int group)
+{
+ assert(group == 0);
+
+ return strtol(nptr, endptr, base);
+}
+
+/**
+ * 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);
}