diff options
Diffstat (limited to 'klibc/klibc/putenv.c')
-rw-r--r-- | klibc/klibc/putenv.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/klibc/klibc/putenv.c b/klibc/klibc/putenv.c new file mode 100644 index 0000000000..8138c653b4 --- /dev/null +++ b/klibc/klibc/putenv.c @@ -0,0 +1,40 @@ +/* + * putenv.c + */ + +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +/* str should be a duplicated version of the input string; + len is the length of the key including the = sign */ +int __put_env(char *str, size_t len, int overwrite); + +int putenv(const char *str) +{ + char *s; + const char *e, *z; + + if ( !str ) { + errno = EINVAL; + return -1; + } + + e = NULL; + for ( z = str ; *z ; z++ ) { + if ( *z == '=' ) + e = z; + } + + if ( !e ) { + errno = EINVAL; + return -1; + } + + s = strdup(str); + if ( !s ) + return -1; + + return __put_env(s, e-str, 1); +} |