stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <mse...@gmail.com>
Subject Re: [PATCH] STDCXX-1019 __rw_mkstemp in file.cpp should honor TMPDIR environment variable
Date Sat, 11 Oct 2008 22:18:57 GMT
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;
> 


Mime
View raw message