libreboot-utils: unified errno handling on returns

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-28 08:32:27 +00:00
parent 49cac232d8
commit 4ecdadb7a6
5 changed files with 34 additions and 72 deletions
+16 -7
View File
@@ -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