PatchworkOS  10941b4
A non-POSIX operating system.
Loading...
Searching...
No Matches
env.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/sync/mutex.h>
4
5#include <stdlib.h>
6#include <sys/defs.h>
7
8/**
9 * @brief Environment variables.
10 * @defgroup kernel_proc_env Environment
11 * @ingroup kernel_proc
12 *
13 * @{
14 */
15
16/**
17 * @brief Environment variable structure.
18 * @struct env_var_t
19 */
20typedef struct
21{
22 char* key;
23 char* value;
24} env_var_t;
25
26/**
27 * @brief Environment structure.
28 * @struct env_t
29 *
30 * Stored in `process_t::env`.
31 */
32typedef struct
33{
35 size_t count;
37} env_t;
38
39/**
40 * @brief Initialize the environment.
41 *
42 * @param env The environment to initialize.
43 */
44void env_init(env_t* env);
45
46/**
47 * @brief Deinitialize the environment.
48 *
49 * @param env The environment to deinitialize.
50 */
51void env_deinit(env_t* env);
52
53/**
54 * @brief Copy environment variables from one environment to another.
55 *
56 * @param dest The destination environment.
57 * @param src The source environment.
58 * @return On success, `0`. On failure, returns `ERR` and `errno` is set.
59 */
60uint64_t env_copy(env_t* dest, env_t* src);
61
62/**
63 * @brief Get the value of an environment variable.
64 *
65 * @param env The environment to search in.
66 * @param key The name of the environment variable.
67 * @return A pointer to the value of the environment variable or `NULL` if it does not exist.
68 */
69const char* env_get(env_t* env, const char* key);
70
71/**
72 * @brief Set the value of an environment variable.
73 *
74 * If the variable already exists, its value will be updated.
75 *
76 * @param env The environment to modify.
77 * @param key The name of the environment variable.
78 * @param value The value to set the environment variable to.
79 * @return On success, `0`. On failure, returns `ERR` and `errno` is set.
80 */
81uint64_t env_set(env_t* env, const char* key, const char* value);
82
83/**
84 * @brief Unset an environment variable.
85 *
86 * If the variable does not exist, this function does nothing.
87 *
88 * @param env The environment to modify.
89 * @param key The name of the environment variable.
90 * @return On success, `0`. On failure, returns `ERR` and `errno` is set.
91 */
92uint64_t env_unset(env_t* env, const char* key);
93
94/** @} */
const char * env_get(env_t *env, const char *key)
Get the value of an environment variable.
Definition env.c:47
uint64_t env_set(env_t *env, const char *key, const char *value)
Set the value of an environment variable.
Definition env.c:67
void env_init(env_t *env)
Initialize the environment.
Definition env.c:8
uint64_t env_copy(env_t *dest, env_t *src)
Copy environment variables from one environment to another.
Definition env.c:26
uint64_t env_unset(env_t *env, const char *key)
Unset an environment variable.
Definition env.c:127
void env_deinit(env_t *env)
Deinitialize the environment.
Definition env.c:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Environment structure.
Definition env.h:33
mutex_t mutex
Definition env.h:36
env_var_t * vars
Definition env.h:34
size_t count
Definition env.h:35
Environment variable structure.
Definition env.h:21
char * value
Definition env.h:23
char * key
Definition env.h:22
Mutex structure.
Definition mutex.h:41