diff options
author | Sean Anderson <seanga2@gmail.com> | 2023-11-04 16:37:51 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-11-16 12:43:49 -0500 |
commit | 9181cb0507d1dd5627cc3d9cd86d427abe00cc21 (patch) | |
tree | 0cd706c4991026ec68c46f009c8fa124e4e8d6e3 /arch/sandbox | |
parent | 333d43f6a3e2aa1d6249d22211d77802614e37e5 (diff) | |
download | u-boot-9181cb0507d1dd5627cc3d9cd86d427abe00cc21.zip u-boot-9181cb0507d1dd5627cc3d9cd86d427abe00cc21.tar.gz u-boot-9181cb0507d1dd5627cc3d9cd86d427abe00cc21.tar.bz2 |
arch: sandbox: Add function to create temporary files
When working with sparse data buffers that may be larger than the address
space, it is convenient to work with files instead. Add a function to create
temporary files of a certain size.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Diffstat (limited to 'arch/sandbox')
-rw-r--r-- | arch/sandbox/cpu/os.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 85d0d6a..8847c4c 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -282,6 +282,23 @@ int os_persistent_file(char *buf, int maxsize, const char *fname) return 0; } +int os_mktemp(char *fname, off_t size) +{ + int fd; + + fd = mkostemp(fname, O_CLOEXEC); + if (fd < 0) + return -errno; + + if (unlink(fname) < 0) + return -errno; + + if (ftruncate(fd, size)) + return -errno; + + return fd; +} + /* Restore tty state when we exit */ static struct termios orig_term; static bool term_setup; |