diff options
| author | Quentin Schulz <[email protected]> | 2024-01-17 18:59:11 +0100 |
|---|---|---|
| committer | Kever Yang <[email protected]> | 2024-01-19 10:57:36 +0800 |
| commit | 23c1ab92be6332fb528efc2d549898a5f1d17bf9 (patch) | |
| tree | 52cd26e59568ff44b75562c40d3eafa9d7dfbfb9 /env/common.c | |
| parent | 56bb09f5022d46d1244ba02680b6a7f2a0317598 (diff) | |
env: allow to copy value from default environment into a buffer
env_get_default suffers from a particular issue int that it can only
return a value truncated to gd->env_buf (32) characters. This may be
enough for most variables but it isn't for others, so let's allow users
to provide a preallocated buffer to copy the value into instead,
allowing for more control, though it'll still be truncated if the value
size is bigger than the preallocated buffer.
Cc: Quentin Schulz <[email protected]>
Reviewed-by: Tom Rini <[email protected]>
Reviewed-by: Kever Yang <[email protected]>
Signed-off-by: Quentin Schulz <[email protected]>
Diffstat (limited to 'env/common.c')
| -rw-r--r-- | env/common.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/env/common.c b/env/common.c index 656748c1f5b..ebcb10854d8 100644 --- a/env/common.c +++ b/env/common.c @@ -359,6 +359,14 @@ char *env_get_default(const char *name) return NULL; } +/* + * Look up the variable from the default environment and store its value in buf + */ +int env_get_default_into(const char *name, char *buf, unsigned int len) +{ + return env_get_from_linear(default_environment, name, buf, len); +} + void env_set_default(const char *s, int flags) { if (s) { |
