diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-01-22 02:13:18 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-01-22 02:13:18 +0000 |
commit | fdcc03929065b5bf5dd93553db219ea3e05c8c34 (patch) | |
tree | ca90dc8d9e89febdcd4160956c1b8ec098a4efc9 /lib/mesa/src/util/u_process.c | |
parent | 3c9de4a7e13712b5696750bbd59a18c848742022 (diff) |
Import Mesa 19.2.8
Diffstat (limited to 'lib/mesa/src/util/u_process.c')
-rw-r--r-- | lib/mesa/src/util/u_process.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/mesa/src/util/u_process.c b/lib/mesa/src/util/u_process.c index a1667e780..371335303 100644 --- a/lib/mesa/src/util/u_process.c +++ b/lib/mesa/src/util/u_process.c @@ -32,11 +32,16 @@ #undef GET_PROGRAM_NAME -#if (defined(__GNU_LIBRARY__) || defined(__GLIBC__)) && !defined(__UCLIBC__) -# if !defined(__GLIBC__) || (__GLIBC__ < 2) -/* These aren't declared in any libc5 header */ -extern char *program_invocation_name, *program_invocation_short_name; -# endif +#if defined(__linux__) && defined(HAVE_PROGRAM_INVOCATION_NAME) + +static char *path = NULL; + +static void __freeProgramPath() +{ + free(path); + path = NULL; +} + static const char * __getProgramName() { @@ -49,10 +54,10 @@ __getProgramName() * Strip these arguments out by using the realpath only if it was * a prefix of the invocation name. */ - static char *path; - - if (!path) + if (!path) { path = realpath("/proc/self/exe", NULL); + atexit(__freeProgramPath); + } if (path && strncmp(path, program_invocation_name, strlen(path)) == 0) { /* This shouldn't be null because path is a a prefix, @@ -75,7 +80,7 @@ __getProgramName() return program_invocation_name; } # define GET_PROGRAM_NAME() __getProgramName() -#elif defined(__CYGWIN__) +#elif defined(HAVE_PROGRAM_INVOCATION_NAME) # define GET_PROGRAM_NAME() program_invocation_short_name #elif defined(__FreeBSD__) && (__FreeBSD__ >= 2) # include <osreldate.h> |