aboutsummaryrefslogtreecommitdiff
path: root/arch/sandbox
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2023-11-04 16:37:51 -0400
committerTom Rini <trini@konsulko.com>2023-11-16 12:43:49 -0500
commit9181cb0507d1dd5627cc3d9cd86d427abe00cc21 (patch)
tree0cd706c4991026ec68c46f009c8fa124e4e8d6e3 /arch/sandbox
parent333d43f6a3e2aa1d6249d22211d77802614e37e5 (diff)
downloadu-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.c17
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;