diff options
author | Simon Glass <sjg@chromium.org> | 2023-08-24 13:55:37 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-08-25 17:55:19 -0400 |
commit | e2d22f782297bcec8b0b55d15b9a04e92bd4ea83 (patch) | |
tree | 3e23633bfe4f55378e48764ca1fd03ff3fbaec08 /arch/sandbox/cpu/os.c | |
parent | 8d6337e69147557fb3c4b89a27156ac468a20500 (diff) |
sandbox: Add a way to access persistent test files
Some pytests create files in the persistent-data directory. It is useful
to be able to access these files in C tests. Add a function which can
locate a file given its leaf name, using the environment variable set
up in test/py/conftest.py
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, 24 insertions, 0 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 9e93a0fa571..85d0d6a1703 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -258,6 +258,30 @@ int os_unmap(void *buf, int size) return 0; } +int os_persistent_file(char *buf, int maxsize, const char *fname) +{ + const char *dirname = getenv("U_BOOT_PERSISTENT_DATA_DIR"); + char *ptr; + int len; + + len = strlen(fname) + (dirname ? strlen(dirname) + 1 : 0) + 1; + if (len > maxsize) + return -ENOSPC; + + ptr = buf; + if (dirname) { + strcpy(ptr, dirname); + ptr += strlen(dirname); + *ptr++ = '/'; + } + strcpy(ptr, fname); + + if (access(buf, F_OK) == -1) + return -ENOENT; + + return 0; +} + /* Restore tty state when we exit */ static struct termios orig_term; static bool term_setup; |