diff options
| author | Jakob Kaivo <jkk@ung.org> | 2024-05-28 15:50:03 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2024-05-28 15:50:03 -0400 |
| commit | c9ec058657f9f8b3fd39a16f1a9e993b4a1e982e (patch) | |
| tree | 6cf1abadd04a1a9049d82ffe0e78be7f8b4cece2 /src/stdlib/getenv.c | |
| parent | b4cd7036bea6c6440fbbcdaebe53c864c87a5646 (diff) | |
abstract out "forced" implementations of functions from future specifications
Diffstat (limited to 'src/stdlib/getenv.c')
| -rw-r--r-- | src/stdlib/getenv.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/stdlib/getenv.c b/src/stdlib/getenv.c index 989a5f84..c85c1922 100644 --- a/src/stdlib/getenv.c +++ b/src/stdlib/getenv.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <string.h> #include "_stdlib.h" +#include "_readonly.h" /** get an environment variable **/ @@ -8,13 +9,20 @@ char * getenv(const char * name) { size_t len = 0; size_t i = 0; + static char *variable = NULL; SIGNAL_SAFE(0); + if (variable == NULL) { + variable = __readonly(RO_ALLOC, "getenv"); + } len = strlen(name); for (i = 0; environ[i] != NULL; i++) { if (!strncmp(environ[i], name, len) && environ[i][len] == '=') { - return environ[i] + len + 1; + __readonly(RO_UNLOCK, variable); + strcpy(variable, environ[i] + len + 1); + __readonly(RO_LOCK, variable); + return variable; } } |
