diff options
author | Simon Glass <sjg@chromium.org> | 2024-08-07 16:47:24 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-08-09 16:03:19 -0600 |
commit | b254a8359ecdc8ec85cd93e055c6bbeee259df1d (patch) | |
tree | ef8e14b921dd1a74ac6214844a0547a71b788bc8 /arch/sandbox/cpu/os.c | |
parent | d8289e7dfe5541dfef59520917d81cd39e10c8f3 (diff) |
sandbox: Return error code from read/write/seek
The existing API for these functions is different from the rest of
U-Boot, in that any error code must be obtained from the errno variable
on failure. This variable is part of the C library, so accessing it
outside of the special 'sandbox' shim-functions is not ideal.
Adjust the API to return an error code, to avoid this. Update existing
uses to check for any negative value, rather than just -1.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/sandbox/cpu/os.c')
-rw-r--r-- | arch/sandbox/cpu/os.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index da96ebe43c9..f5c9a8aecf2 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -47,12 +47,24 @@ struct os_mem_hdr { ssize_t os_read(int fd, void *buf, size_t count) { - return read(fd, buf, count); + ssize_t ret; + + ret = read(fd, buf, count); + if (ret == -1) + return -errno; + + return ret; } ssize_t os_write(int fd, const void *buf, size_t count) { - return write(fd, buf, count); + ssize_t ret; + + ret = write(fd, buf, count); + if (ret == -1) + return -errno; + + return ret; } int os_printf(const char *fmt, ...) @@ -69,6 +81,8 @@ int os_printf(const char *fmt, ...) off_t os_lseek(int fd, off_t offset, int whence) { + off_t ret; + if (whence == OS_SEEK_SET) whence = SEEK_SET; else if (whence == OS_SEEK_CUR) @@ -77,7 +91,11 @@ off_t os_lseek(int fd, off_t offset, int whence) whence = SEEK_END; else os_exit(1); - return lseek(fd, offset, whence); + ret = lseek(fd, offset, whence); + if (ret == -1) + return -errno; + + return ret; } int os_open(const char *pathname, int os_flags) |