diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-28 08:32:27 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-28 08:32:27 +0000 |
| commit | 4ecdadb7a601b0613e65bf8547d17b39ed87153f (patch) | |
| tree | 2f29c2b6adc0b2891ceed08541b8c4645df2c413 /util/libreboot-utils/lib/string.c | |
| parent | 49cac232d8e3cc6147a530d4f7971832f6b869b5 (diff) | |
libreboot-utils: unified errno handling on returns
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib/string.c')
| -rw-r--r-- | util/libreboot-utils/lib/string.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index 9e38a9e9..76141c58 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -201,14 +201,10 @@ scatn(ssize_t sc, const char **sv, errno = saved_errno; return 0; err: - if (ct != NULL) - free(ct); - if (size != NULL) - free(size); - if (errno == saved_errno) - errno = EFAULT; + free_and_set_null(&ct); + free_and_set_null((char **)&size); - return -1; + return set_errno(saved_errno, EFAULT); } /* strict strcat */ @@ -285,6 +281,19 @@ err: return -1; } +/* on functions that return with errno, + * i sometimes have a default fallback, + * which is set if errno wasn't changed, + * under error condition. + */ +int +set_errno(int saved_errno, int fallback) +{ + if (errno == saved_errno) + errno = fallback; + return -1; +} + /* the one for nvmutil state is in state.c */ /* this one just exits */ void |
