summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/setenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/setenv.c')
-rw-r--r--libc/stdlib/setenv.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c
index d0cfe526d..8704717a7 100644
--- a/libc/stdlib/setenv.c
+++ b/libc/stdlib/setenv.c
@@ -19,6 +19,8 @@
modified for uClibc by Erik Andersen <andersen@codepoet.org>
*/
+#define strndup __strndup
+
#define _GNU_SOURCE
#include <features.h>
#include <errno.h>
@@ -36,6 +38,7 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
# define UNLOCK
#endif
+extern int __unsetenv (__const char *__name) attribute_hidden;
/* If this variable is not a null pointer we allocated the current
environment. */
@@ -48,13 +51,13 @@ static char **last_environ;
must be used directly. This is all complicated by the fact that we try
to reuse values once generated for a `setenv' call since we can never
free the strings. */
-int __add_to_environ (const char *name, const char *value,
+int attribute_hidden __add_to_environ (const char *name, const char *value,
const char *combined, int replace)
{
register char **ep;
register size_t size;
- const size_t namelen = strlen (name);
- const size_t vallen = value != NULL ? strlen (value) + 1 : 0;
+ const size_t namelen = __strlen (name);
+ const size_t vallen = value != NULL ? __strlen (value) + 1 : 0;
LOCK;
@@ -65,7 +68,7 @@ int __add_to_environ (const char *name, const char *value,
size = 0;
if (ep != NULL) {
for (; *ep != NULL; ++ep) {
- if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
+ if (!__strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
break;
else
++size;
@@ -97,13 +100,13 @@ int __add_to_environ (const char *name, const char *value,
return -1;
}
- memcpy (new_environ[size], name, namelen);
+ __memcpy (new_environ[size], name, namelen);
new_environ[size][namelen] = '=';
- memcpy (&new_environ[size][namelen + 1], value, vallen);
+ __memcpy (&new_environ[size][namelen + 1], value, vallen);
}
if (__environ != last_environ) {
- memcpy ((char *) new_environ, (char *) __environ,
+ __memcpy ((char *) new_environ, (char *) __environ,
size * sizeof (char *));
}
@@ -121,9 +124,9 @@ int __add_to_environ (const char *name, const char *value,
UNLOCK;
return -1;
}
- memcpy (np, name, namelen);
+ __memcpy (np, name, namelen);
np[namelen] = '=';
- memcpy (&np[namelen + 1], value, vallen);
+ __memcpy (&np[namelen + 1], value, vallen);
}
*ep = np;
}
@@ -137,21 +140,21 @@ int setenv (const char *name, const char *value, int replace)
return __add_to_environ (name, value, NULL, replace);
}
-int unsetenv (const char *name)
+int attribute_hidden __unsetenv (const char *name)
{
size_t len;
char **ep;
- if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) {
+ if (name == NULL || *name == '\0' || __strchr (name, '=') != NULL) {
__set_errno (EINVAL);
return -1;
}
- len = strlen (name);
+ len = __strlen (name);
LOCK;
ep = __environ;
while (*ep != NULL) {
- if (!strncmp (*ep, name, len) && (*ep)[len] == '=') {
+ if (!__strncmp (*ep, name, len) && (*ep)[len] == '=') {
/* Found it. Remove this pointer by moving later ones back. */
char **dp = ep;
do {
@@ -165,6 +168,7 @@ int unsetenv (const char *name)
UNLOCK;
return 0;
}
+strong_alias(__unsetenv,unsetenv)
/* The `clearenv' was planned to be added to POSIX.1 but probably
never made it. Nevertheless the POSIX.9 standard (POSIX bindings
@@ -187,7 +191,7 @@ int clearenv (void)
int putenv (char *string)
{
int result;
- const char *const name_end = strchr (string, '=');
+ const char *const name_end = __strchr (string, '=');
if (name_end != NULL) {
char *name = strndup(string, name_end - string);
@@ -195,7 +199,7 @@ int putenv (char *string)
free(name);
return(result);
}
- unsetenv (string);
+ __unsetenv (string);
return 0;
}