Add private __getenv_reentrant()
A reentrant variant of getenv().
This commit is contained in:
parent
b38fed9370
commit
8a3fe6d1bf
23
headers/private/libroot/stdlib_private.h
Normal file
23
headers/private/libroot/stdlib_private.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _LIBROOT_STDLIB_PRIVATE_H
|
||||
#define _LIBROOT_STDLIB_PRIVATE_H
|
||||
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
|
||||
ssize_t __getenv_reentrant(const char* name, char* buffer,
|
||||
size_t bufferSize);
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
#endif /* _LIBROOT_STDLIB_PRIVATE_H */
|
@ -15,6 +15,7 @@
|
||||
#include <libroot_private.h>
|
||||
#include <locks.h>
|
||||
#include <runtime_loader.h>
|
||||
#include <stdlib_private.h>
|
||||
#include <syscall_utils.h>
|
||||
#include <user_runtime.h>
|
||||
|
||||
@ -315,3 +316,21 @@ putenv(const char *string)
|
||||
RETURN_AND_SET_ERRNO(status);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
__getenv_reentrant(const char* name, char* buffer, size_t bufferSize)
|
||||
{
|
||||
size_t nameLength = strlen(name);
|
||||
|
||||
lock_variables();
|
||||
|
||||
char* value = find_variable(name, nameLength, NULL);
|
||||
ssize_t result = value != NULL
|
||||
? strlcpy(buffer, value + nameLength + 1, bufferSize)
|
||||
: B_NAME_NOT_FOUND;
|
||||
|
||||
unlock_variables();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user