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.
- Parameters
-
[out] | len | pointer to a size_t where getenv_s will store the length of the found environment variable. Might be NULL. |
[out] | dest | pointer to a string where getenv_s will store the contents of the found environment variable. |
[in] | dmax | maximum number of characters that getenv_s is allowed to write to dest (size of the buffer). |
[in] | name | null-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
-
EOK | on success |
-ESNULLP | when dest or name are a NULL pointer |
-ESZEROL | when dmax = 0 |
-ESLEMAX | when dmax > RSIZE_MAX_STR |
-ESNOSPC | when dmax is too small for the value |
-1 | when not found |