about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-02-15 16:53:01 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-02-15 16:53:01 +0000
commit464fe7d9fca764d2ccc619a6204bebb80119e416 (patch)
tree94813b9ce7878712fbb2779212f8c649045e6491 /lib
parentf1fd8f35257f39e1681d68d7d2dc381ef58643c3 (diff)
downloadnetpbm-mirror-464fe7d9fca764d2ccc619a6204bebb80119e416.tar.gz
netpbm-mirror-464fe7d9fca764d2ccc619a6204bebb80119e416.tar.xz
netpbm-mirror-464fe7d9fca764d2ccc619a6204bebb80119e416.zip
Release 10.47.36
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@1655 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/pm.h21
-rw-r--r--lib/pmfileio.c31
2 files changed, 49 insertions, 3 deletions
diff --git a/lib/pm.h b/lib/pm.h
index 4ba20aa5..a0c2005e 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 VMS
 #include <perror.h>
@@ -79,6 +80,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.
+*/
+#ifdef 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 585b0d0f..a9099b94 100644
--- a/lib/pmfileio.c
+++ b/lib/pmfileio.c
@@ -120,6 +120,30 @@ 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;
+}
+
+
+
+
+static int
 mkstempx(char * const filenameBuffer) {
 /*----------------------------------------------------------------------------
   This is meant to be equivalent to POSIX mkstemp().
@@ -153,9 +177,10 @@ 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) {
+            if (rc >= 0) {
                 fd = rc;
                 gotFile = TRUE;
             } else {
@@ -247,7 +272,7 @@ pm_make_tmpfile_fd(int *         const fdP,
     asprintfN(&filenameTemplate, "%s%s%s%s", 
               tmpdir, dirseparator, pm_progname, "_XXXXXX");
 
-    if (filenameTemplate == NULL)
+    if (filenameTemplate == pm_strsol)
         asprintfN(&error,
                   "Unable to allocate storage for temporary file name");
     else {