GETENV(9)
π«Ά GETENV(9) β kernel environment variable functions
Okay bestie, welcome to the GETENV(9) page from the Kernel Developer's Manual. This is your cute little guide to the kernel environment variable crew, and yes, they ate π
πΈ NAME πΈ
This page covers the whole squad of kernel environment variable functions:
freeenvkern_getenvgetenv_intgetenv_longgetenv_stringgetenv_quadgetenv_uintgetenv_ulonggetenv_boolgetenv_is_truegetenv_is_falsekern_setenvtestenvkern_unsetenv
They are all about kernel environment variables, periodt π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/systm.h>
void
freeenv(char *env);
char *
kern_getenv(const char *name);
int
getenv_int(const char *name, int *data);
int
getenv_long(const char *name, long *data);
int
getenv_string(const char *name, char *data, int size);
int
getenv_quad(const char *name, quad_t *data);
int
getenv_uint(const char *name, unsigned int *data);
int
getenv_ulong(const char *name, unsigned long *data);
int
getenv_bool(const char *name, bool *data);
bool
getenv_is_true(const char *name);
bool
getenv_is_false(const char *name);
int
kern_setenv(const char *name, const char *value);
int
testenv(const char *name);
int
kern_unsetenv(const char *name);
π DESCRIPTION π
So basically, these functions set, unset, fetch, and parse variables from the kernel's environment. Let's go through them one by one, bestie π«Ά
kern_getenv()β gets the current value of the kernel environment variablenameand returns a pointer to the string value. The caller should not modify the string pointed to by the return value. It may allocate temporary storage, so you must callfreeenv()to release any allocated resources when the value returned bykern_getenv()is no longer needed.freeenv()β releases the resources allocated by a previous call tokern_getenv(). Theenvargument passed tofreeenv()is the pointer returned by the earlier call tokern_getenv(). Likefree(3), theenvargument can beNULL, in which case no action occurs. Iconic cleanup behavior πkern_setenv()β inserts or resets the kernel environment variablenametovalue. If the variablenamealready exists, its value is replaced. This function can fail if an internal limit on the number of environment variables is exceeded.kern_unsetenv()β deletes the kernel environment variablename.testenv()β used to determine if a kernel environment variable exists. It returns a non-zero value if the variablenameexists and zero if it does not. Vibe check: exists or nah πgetenv_int(),getenv_long(),getenv_quad(),getenv_uint(), andgetenv_ulong()β look for a kernel environment variablenameand parse it as a signed integer, long integer, signed 64-bit integer, unsigned integer, or an unsigned long integer, respectively. These functions fail and return zero ifnamedoes not exist or if any invalid characters are present in its value. On success, these functions store the parsed value in the integer variable pointed to bydata. If the parsed value overflows the integer type, a truncated value is stored indataand zero is returned. If the value begins with a prefix of"0x"it is interpreted as hexadecimal. If it begins with a prefix of"0"it is interpreted as octal. Otherwise, the value is interpreted as decimal. The value may contain a single character suffix specifying a unit for the value. The interpreted value is multiplied by the unit's magnitude before being returned. The following unit suffixes are supported:kβ 2^10mβ 2^20gβ 2^30tβ 2^40
getenv_string()β stores a copy of the kernel environment variablenamein the buffer described bydataandsize. If the variable does not exist, zero is returned. If the variable exists, up tosize - 1characters of its value are copied to the buffer pointed to bydatafollowed by a null character and a non-zero value is returned.getenv_bool()β interprets the value of the kernel environment variablenameas a boolean value by performing a case-insensitive comparison against the strings"1","0","true", and"false". If the environment variable exists and has a valid boolean value, then that value will be copied to the variable pointed to bydata. If the environment variable exists but is not a boolean value, then a warning will be printed to the kernel message buffer. Bestie, if it's not a bool, it's gonna get called out πgetenv_is_true()andgetenv_is_false()β wrappers aroundgetenv_bool()that simplify testing for a desired boolean value.
π RETURN VALUES π
kern_getenv()returns a pointer to an environment variable's value on success orNULLif the variable does not exist.kern_setenv()andkern_unsetenv()return zero on success and-1on failure.testenv()returns zero if the specified environment variable does not exist and a non-zero value if it does exist.getenv_int(),getenv_long(),getenv_string(),getenv_quad(),getenv_uint(),getenv_ulong(), andgetenv_bool()return a non-zero value on success and zero on failure.getenv_is_true()andgetenv_is_false()returntrueif the specified environment variable exists and its value matches the desired boolean condition, andfalseotherwise.
This little page is from Debian, dated September 21, 2020 β source/version and date, both noted with love. Bye bestie, go make those kernel env vars behave ππ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2013 Hudson River Trading LLC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms