stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Zhong" <Scott.Zh...@roguewave.com>
Subject RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable
Date Wed, 08 Oct 2008 17:02:35 GMT
Posted wrong diff. here is the correct diff

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__)
@@ -257,8 +258,15 @@
 #    define P_tmpdir "/tmp"
 #  endif   // P_tmpdir
 
-    char fnamebuf[] = P_tmpdir "/.rwtmpXXXXXX";
+    char *tmpdir = getenv ("TMPDIR") == NULL ? P_tmpdir : getenv
("TMPDIR");
 
+    char fnamebuf [sizeof (tmpdir) + sizeof ("/.rwtmpXXXXXX")];
+
+    size_t len = sizeof (tmpdir) - 1;
+ 
+    memcpy (fnamebuf, tmpdir, len);
+    memcpy (fnamebuf+len, "/.rwtmpXXXXXX", sizeof ("/.rwtmpXXXXXX"));
+
     fd = mkstemp (fnamebuf);
 
     if (fd >= 0)
@@ -294,7 +302,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;

> -----Original Message-----
> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
> Sent: Wednesday, October 08, 2008 10:15 AM
> To: dev@stdcxx.apache.org
> Subject: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor
TMPDIR
> environment variable
> 
> https://issues.apache.org/jira/browse/STDCXX-1019
> 
> file affected: <stdcxx>/src/file.cpp
> 
> Index: src/file.cpp
> ===================================================================
> --- src/file.cpp        (revision 702657)
> +++ src/file.cpp        (working copy)
> @@ -257,7 +257,9 @@
>  #    define P_tmpdir "/tmp"
>  #  endif   // P_tmpdir
> 
> -    char fnamebuf[] = P_tmpdir "/.rwtmpXXXXXX";
> +    char *tmpdir = getenv ("TMPDIR") == NULL ? P_tmpdir : getenv
> ("TMPDIR");
> +
> +    char fnamebuf[] = tmpdir "/.rwtmpXXXXXX";
> 
>      fd = mkstemp (fnamebuf);
> 
> @@ -294,7 +296,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;

Mime
View raw message