You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Scott Zhong <Sc...@roguewave.com> on 2008/10/08 18:15:14 UTC

[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;

Re: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable

Posted by Martin Sebor <ms...@gmail.com>.
Scott Zhong wrote:
> Hi Martin, 
> 
>   There are two different file that happens to have the same name that
> are affected by my patch. One resides under <stdcxx>/src/file.cpp and
> the other is <stdcxx>/tests/src/file.cpp. The patch for this issue
> resides under the former.  I'll update STDCXX-1019 with this.

Ah. I missed that.

> 
> http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/src/file.cpp
> http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/tests/src/file.cpp
> 
> I'm not a committer. I don't believe I am able to send the change log.  

A change log is just a description of the changes. Among other
things, it makes it easier to tell where the file comes from
(i.e., the library or the test suite). Since one of us needs
to commit your patch it also saves us time coming with
a description for your changes.

Martin

> 
>> -----Original Message-----
>> From: Martin Sebor [mailto:msebor@gmail.com]
>> Sent: Saturday, October 11, 2008 4:19 PM
>> To: dev@stdcxx.apache.org
>> Subject: Re: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor
>> TMPDIR environment variable
>>
>> Scott Zhong wrote:
>>> Fix to fnamebuf array size and invoke getenv only once.
>> The fix looks good to me but I'm having trouble applying the patch.
>> You are changing the definition of something called fnamebuf around
>> line 260 but there's no string "fnamebuf" in the file, either on
>> trunk or on branches/4.2.x:
>>
>> $ svn cat
>>
> http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/tests/src/file.cpp
>> http://svn.apache.org/repos/asf/stdcxx/trunk/tests/src/file.cpp | grep
>> fnamebuf || echo NOT FOUND
>> NOT FOUND
>>
>> Could also send your change log entry with the final patch?
>>
>> Thanks
>> Martin
>>
>>> 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
>>>
>>> +#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;
>>>
>>>> -----Original Message-----
>>>> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
>>>> Sent: Wednesday, October 08, 2008 11:03 AM
>>>> To: dev@stdcxx.apache.org
>>>> Subject: RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should
> honor
>>>> TMPDIR environment variable
>>>>
>>>> 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;
> 
> 


RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable

Posted by Scott Zhong <Sc...@roguewave.com>.
Hi Martin, 

  There are two different file that happens to have the same name that
are affected by my patch. One resides under <stdcxx>/src/file.cpp and
the other is <stdcxx>/tests/src/file.cpp. The patch for this issue
resides under the former.  I'll update STDCXX-1019 with this.

http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/src/file.cpp
http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/tests/src/file.cpp

I'm not a committer. I don't believe I am able to send the change log.  

> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com]
> Sent: Saturday, October 11, 2008 4:19 PM
> To: dev@stdcxx.apache.org
> Subject: Re: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor
> TMPDIR environment variable
> 
> Scott Zhong wrote:
> > Fix to fnamebuf array size and invoke getenv only once.
> 
> The fix looks good to me but I'm having trouble applying the patch.
> You are changing the definition of something called fnamebuf around
> line 260 but there's no string "fnamebuf" in the file, either on
> trunk or on branches/4.2.x:
> 
> $ svn cat
>
http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/tests/src/file.cpp
> http://svn.apache.org/repos/asf/stdcxx/trunk/tests/src/file.cpp | grep
> fnamebuf || echo NOT FOUND
> NOT FOUND
> 
> Could also send your change log entry with the final patch?
> 
> Thanks
> Martin
> 
> >
> > 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
> >
> > +#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;
> >
> >> -----Original Message-----
> >> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
> >> Sent: Wednesday, October 08, 2008 11:03 AM
> >> To: dev@stdcxx.apache.org
> >> Subject: RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should
honor
> >> TMPDIR environment variable
> >>
> >> 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;
> >


Re: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable

Posted by Martin Sebor <ms...@gmail.com>.
Scott Zhong wrote:
> Fix to fnamebuf array size and invoke getenv only once.

The fix looks good to me but I'm having trouble applying the patch.
You are changing the definition of something called fnamebuf around
line 260 but there's no string "fnamebuf" in the file, either on
trunk or on branches/4.2.x:

$ svn cat 
http://svn.apache.org/repos/asf/stdcxx/branches/4.2.x/tests/src/file.cpp 
http://svn.apache.org/repos/asf/stdcxx/trunk/tests/src/file.cpp | grep 
fnamebuf || echo NOT FOUND
NOT FOUND

Could also send your change log entry with the final patch?

Thanks
Martin

> 
> 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
>  
> +#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;
> 
>> -----Original Message-----
>> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
>> Sent: Wednesday, October 08, 2008 11:03 AM
>> To: dev@stdcxx.apache.org
>> Subject: RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor
>> TMPDIR environment variable
>>
>> 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;
> 


RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable

Posted by Scott Zhong <Sc...@roguewave.com>.
Fix to fnamebuf array size and invoke getenv only once.

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
 
+#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;

> -----Original Message-----
> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
> Sent: Wednesday, October 08, 2008 11:03 AM
> To: dev@stdcxx.apache.org
> Subject: RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor
> TMPDIR environment variable
> 
> 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;

RE: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable

Posted by Scott Zhong <Sc...@roguewave.com>.
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;