Scott Zhong wrote:
Changelog:

* src/file.cpp (__rw_mkstemp): use TMPDIR variable from environment if
defined.

here is the patch:

I'm afraid the patch is malformed and doesn't apply (see below).
I tried to quickly fix the errors but to no avail. Can you please
resend it?


Index: src/file.cpp
===================================================================
--- src/file.cpp        (revision 702657)
+++ src/file.cpp        (working copy)
@@ -42,6 +42,7 @@
 #include <stdio.h>    // for P_tmpdir, std{err,in,out}, tmpnam()
 #include <stdlib.h>   // for mkstemp(), strtoul(), size_t
 #include <ctype.h>    // for isalpha(), isspace(), toupper()
+#include <string.h>   // for memcpy()
#if defined (_WIN32) && !defined (__CYGWIN__) @@ -58,6 +59,9 @@ #
                                                ^^^^^^^^^^^^^^^^^^^^^
define _BINARY 0  #endif
^^^^^^^^^^^^^^^^^^^^^^^^^^

This isn't right.

Martin

+#ifndef PATH_MAX
+#  define PATH_MAX   1024
+#endif
#include <rw/_file.h>
 #include <rw/_defs.h>
@@ -257,8 +261,18 @@
 #    define P_tmpdir "/tmp"
 #  endif   // P_tmpdir
- char fnamebuf[] = P_tmpdir "/.rwtmpXXXXXX";
+    const char *tmpdir = getenv ("TMPDIR");
+ if (tmpdir == NULL) { + tmpdir = P_tmpdir;
+    }
+ char fnamebuf [PATH_MAX];
+
+    size_t len = strlen (tmpdir) - 1;
+ + memcpy (fnamebuf, tmpdir, len);
+    memcpy (fnamebuf+len, "/.rwtmpXXXXXX", sizeof ("/.rwtmpXXXXXX"));
+
     fd = mkstemp (fnamebuf);
if (fd >= 0)
@@ -294,7 +308,7 @@
     // names that have no extension. tempnam uses malloc to allocate
     // space for the filename; the program is responsible for freeing
// this space when it is no longer needed. - char* const fname = tempnam (P_tmpdir, ".rwtmp");
+    char* const fname = tempnam (tmpdir, ".rwtmp");
if (!fname)
         return -1;


Reply via email to