diff options
-rw-r--r-- | lib/pm.h | 21 | ||||
-rw-r--r-- | lib/pmfileio.c | 28 |
2 files changed, 48 insertions, 1 deletions
diff --git a/lib/pm.h b/lib/pm.h index 7870e1c7..21efea20 100644 --- a/lib/pm.h +++ b/lib/pm.h @@ -21,6 +21,7 @@ #include <errno.h> #include <setjmp.h> #include <sys/stat.h> +#include <fcntl.h> #ifdef __cplusplus extern "C" { @@ -75,6 +76,26 @@ extern "C" { #define PURE_FN_ATTR #endif + +/* S_IRUSR is POSIX, defined in <sys/stat.h> Some old BSD systems and Windows + systems have S_IREAD instead. Most Unix today (2011) has both. In 2011, + Android has S_IRUSR and not S_IREAD. + + Some Windows has _S_IREAD. + + We're ignoring S_IREAD now to see if anyone misses it. If there are still + users that need it, we can handle it here. +*/ +#if WIN32 + #define PM_S_IWUSR _S_IWRITE + #define PM_S_IRUSR _S_IREAD +#else + #define PM_S_IWUSR S_IWUSR + #define PM_S_IRUSR S_IRUSR +#endif + + + typedef struct { /* Coordinates of a pixel within an image. Row 0 is the top row. Column 0 is the left column. diff --git a/lib/pmfileio.c b/lib/pmfileio.c index c9a34533..585388c2 100644 --- a/lib/pmfileio.c +++ b/lib/pmfileio.c @@ -113,6 +113,31 @@ tmpDir(void) { static int +tempFileOpenFlags(void) { +/*---------------------------------------------------------------------------- + Open flags (argument to open()) suitable for a new temporary file +-----------------------------------------------------------------------------*/ + int retval; + + retval = 0 + | O_CREAT + | O_RDWR +#ifndef WIN32 + O_EXCL +#endif +#ifdef WIN32 + O_BINARY +#endif + ; + + return retval; +} +, S_IRUSR | S_IWUSR + + + + +static int mkstempx(char * const filenameBuffer) { /*---------------------------------------------------------------------------- This is meant to be equivalent to POSIX mkstemp(). @@ -146,7 +171,8 @@ mkstempx(char * const filenameBuffer) { else { int rc; - rc = open(filenameBuffer, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + rc = open(filenameBuffer, tempFileOpenFlags(), + PM_S_IWUSR | PM_S_IRUSR); if (rc >= 0) { fd = rc; |