From 09607e9055381f6e330a054ee600e7bd7117bb76 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 30 Apr 2020 17:02:04 +0000 Subject: Add support for WASI platform in tmpFile. --- src/misc/util/utilFile.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/misc/util/utilFile.c') 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); -- cgit v1.2.3 From e792072f8a6f016eb5f2c8653f261ba7c88e6392 Mon Sep 17 00:00:00 2001 From: "Mohamed A. Bamakhrama" Date: Mon, 3 Aug 2020 23:19:23 +0200 Subject: Define S_IREAD|IWRITE macros using IRUSR|IWUSR On platforms such as Android, legacy macros are no longer defined. Hence, we define them in terms of the new POSIX macros if the new ones are defined. Otherwise, we throw an error. Signed-off-by: Mohamed A. Bamakhrama Signed-off-by: Miodrag Milanovic --- src/misc/util/utilFile.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/misc/util/utilFile.c') diff --git a/src/misc/util/utilFile.c b/src/misc/util/utilFile.c index b6835daa..f64d71c2 100644 --- a/src/misc/util/utilFile.c +++ b/src/misc/util/utilFile.c @@ -25,6 +25,23 @@ #include #include +// Handle legacy macros +#if !defined(S_IREAD) +#if defined(S_IRUSR) +#define S_IREAD S_IRUSR +#else +#error S_IREAD is undefined +#endif +#endif + +#if !defined(S_IWRITE) +#if defined(S_IWUSR) +#define S_IWRITE S_IWUSR +#else +#error S_IWRITE is undefined +#endif +#endif + #if defined(_MSC_VER) || defined(__MINGW32__) #include #include -- cgit v1.2.3