diff options
author | Marek BehĂșn <marek.behun@nic.cz> | 2021-10-17 18:36:35 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-10-21 21:50:48 +0300 |
commit | 3112ce0ce8195880aec5e9373434a85e21c3e1af (patch) | |
tree | e7527ddf9d7a128ed80c75a27a58ab5fc2e19a65 /cmd | |
parent | 6b6e3eeba9f96b5d908a9b46b7bb25e76109a0c7 (diff) | |
download | u-boot-3112ce0ce8195880aec5e9373434a85e21c3e1af.tar.xz |
env: Make return value of env_get_f() behave like sprintf() on success
Currently the env_get_f() function's return value behaves weirdly: it
returns the number of bytes written into `buf`, but whether this is
excluding the terminating NULL-byte or including it depends on whether
there was enough space in `buf`.
Change the function to always return the actual length of the value of
the environment variable (excluding the terminating NULL-byte) on
success. This makes it behave like sprintf().
All users of this function in U-Boot are compatible with this change.
Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/nvedit.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 063cc76282..527b522e9e 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -735,7 +735,7 @@ int env_get_f(const char *name, char *buf, unsigned len) for (p = env; *p != '\0'; p = end + 1) { const char *value; - int n; + int n, res; for (end = p; *end != '\0'; ++end) if (end - env >= CONFIG_ENV_SIZE) @@ -745,11 +745,13 @@ int env_get_f(const char *name, char *buf, unsigned len) if (value == NULL) continue; + res = end - value; + /* found; copy out */ for (n = 0; n < len; ++n, ++buf) { *buf = *value++; if (*buf == '\0') - return n; + return res; } if (n) @@ -758,7 +760,7 @@ int env_get_f(const char *name, char *buf, unsigned len) printf("env_buf [%u bytes] too small for value of \"%s\"\n", len, name); - return n; + return res; } return -1; |