diff options
author | whitequark <whitequark@whitequark.org> | 2020-04-30 17:02:04 +0000 |
---|---|---|
committer | Eddie Hung <eddie@fpgeh.com> | 2020-05-01 08:25:53 -0700 |
commit | 09607e9055381f6e330a054ee600e7bd7117bb76 (patch) | |
tree | ee092ea898d86c7ace89db3d5dd76766df68984d /src/misc/util | |
parent | 11c4f998b25b6c07f4081cea10e2532ebcb7f4d4 (diff) | |
download | abc-09607e9055381f6e330a054ee600e7bd7117bb76.tar.gz abc-09607e9055381f6e330a054ee600e7bd7117bb76.tar.bz2 abc-09607e9055381f6e330a054ee600e7bd7117bb76.zip |
Add support for WASI platform in tmpFile.
Diffstat (limited to 'src/misc/util')
-rw-r--r-- | src/misc/util/utilFile.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/misc/util/utilFile.c b/src/misc/util/utilFile.c index 4bb2f4c6..b6835daa 100644 --- a/src/misc/util/utilFile.c +++ b/src/misc/util/utilFile.c @@ -102,6 +102,17 @@ int tmpFile(const char* prefix, const char* suffix, char** out_name) } assert(0); // -- could not open temporary file return 0; +#elif defined(__wasm) + static int seq = 0; // no risk of collision since we're in a sandbox + int fd; + *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 9); + sprintf(*out_name, "%s%08d%s", prefix, seq++, suffix); + fd = open(*out_name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE); + if (fd == -1){ + free(*out_name); + *out_name = NULL; + } + return fd; #else int fd; *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 7); |