safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
getenv_s.c File Reference
#include "safe_lib.h"
+ Include dependency graph for getenv_s.c:

Functions

EXPORT errno_t getenv_s (size_t *restrict len, char *restrict dest, rsize_t dmax, const char *restrict name)
 The getenv_s function searches for an environmental variable with name name in the host-specified environment list and returns a pointer to the string that is associated with the matched environment variable. More...
 

Function Documentation

◆ getenv_s()

EXPORT errno_t getenv_s ( size_t *restrict  len,
char *restrict  dest,
rsize_t  dmax,
const char *restrict  name 
)

The getenv_s function searches for an environmental variable with name name in the host-specified environment list and returns a pointer to the string that is associated with the matched environment variable.

The set of environmental variables and methods of altering it are implementation-defined. The value of the environment variable is written to the user-provided buffer value (unless null) and the number of bytes written is stored in the user-provided location *len (unless null). If the environment variable is not set in the environment, zero is written to *len (unless null) and '\0' is written to value[0] (unless null). With SAFECLIB_STR_NULL_SLACK defined all elements following the terminating null character (if any) written in the array of dmax characters pointed to by dest are nulled. If secure_getenv() is available, it is used.

Remarks
SPECIFIED IN
Parameters
[out]lenpointer to a size_t where getenv_s will store the length of the found environment variable. Might be NULL.
[out]destpointer to a string where getenv_s will store the contents of the found environment variable.
[in]dmaxmaximum number of characters that getenv_s is allowed to write to dest (size of the buffer).
[in]namenull-terminated character string identifying the name of the environmental variable to look for.
Precondition
name and dest shall not be a null pointer.
dmax shall not be greater than RSIZE_MAX_STR.
dmax shall not equal zero.
dmax shall be greater than the strlen of the returned env value.
Returns
zero if the environment variable was found, non-zero if it was not found of if a runtime constrant violation occurred. On any error, writes zero to *len (unless len is a null pointer).
Return values
EOKon success
-ESNULLPwhen dest or name are a NULL pointer
-ESZEROLwhen dmax = 0
-ESLEMAXwhen dmax > RSIZE_MAX_STR
-ESNOSPCwhen dmax is too small for the value
-1when not found