Added missing putenv() implementation. Chosed to limit env names to an arbitrary length of 64 bytes.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9768 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c1a8ebfa2d
commit
8c390406d7
@ -1,21 +1,41 @@
|
||||
/*
|
||||
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Distributed under the terms of the Haiku License.
|
||||
**
|
||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <syscalls.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#define RETURN_AND_SET_ERRNO(err) \
|
||||
if (err < 0) { \
|
||||
errno = err; \
|
||||
return -1; \
|
||||
} \
|
||||
return err;
|
||||
|
||||
|
||||
char **environ = NULL;
|
||||
|
||||
|
||||
int setenv(const char *name, const char *value, int overwrite)
|
||||
int
|
||||
setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
return sys_setenv(name, value, overwrite);
|
||||
status_t status = sys_setenv(name, value, overwrite);
|
||||
|
||||
RETURN_AND_SET_ERRNO(status);
|
||||
}
|
||||
|
||||
|
||||
char *getenv(const char *name)
|
||||
char *
|
||||
getenv(const char *name)
|
||||
{
|
||||
char *value;
|
||||
int rc;
|
||||
@ -25,3 +45,22 @@ char *getenv(const char *name)
|
||||
return NULL;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
putenv(const char *string)
|
||||
{
|
||||
char name[64];
|
||||
char *value = strchr(string, '=');
|
||||
|
||||
if (value == NULL || value - string >= (int)sizeof(name)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strlcpy(name, string, value - string);
|
||||
value++;
|
||||
|
||||
return setenv(name, value, true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user