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-1020 memchk in utility should honor TMPDIR variable
Date Thu, 09 Oct 2008 16:00:58 GMT
Fix to original patch so that only getenv gets called once and use
PATH_MAX for fname array size.  Also use strlen to get the len of string
instead of sizeof.

Index: util/memchk.cpp
===================================================================
--- util/memchk.cpp     (revision 702657)
+++ util/memchk.cpp     (working copy)
@@ -67,6 +67,9 @@
 #  endif
 #endif   // P_tmpdir
 
+#ifndef PATH_MAX
+#  define PATH_MAX   1024
+#endif
 
 #if defined (_RWSTD_EDG_ECCP) && !defined (_WIN32)
 
@@ -116,9 +119,14 @@
         // operation away (as SunOS does, for instance)
         // fd = open ("/dev/null", O_WRONLY);
 
+        const char *tmpdir = getenv ("TMPDIR");
+        if (tmpdir == NULL) { 
+            tmpdir = P_tmpdir;
+        }
+
 #ifdef _WIN32
 
-        char* const fname = tempnam (P_tmpdir, ".rwmemchk.tmp");
+        char* const fname = tempnam (tmpdir, ".rwmemchk.tmp");
 
         if (!fname)
             return size_t (-1);
@@ -137,10 +145,13 @@
 
 #else   // !_WIN32
 
-#  define TMP_TEMPLATE P_tmpdir "/rwmemchk-XXXXXX"
+        char fname_buf [PATH_MAX];
 
-        char fname_buf [] = TMP_TEMPLATE;
+        size_t len = strlen (tmpdir) - 1;
 
+        memcpy (fname_buf, tmpdir, len);
+        memcpy (fname_buf+len, "/rwmemchk-XXXXXX", sizeof
("/rwmemchk-XXXXXX"));
+
         fd = mkstemp (fname_buf);
 
         if (fd < 0) {

> -----Original Message-----
> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
> Sent: Wednesday, October 08, 2008 11:14 AM
> To: dev@stdcxx.apache.org
> Subject: [PATCH] STDCXX-1020 memchk in utility should honor TMPDIR
> variable
> 
> https://issues.apache.org/jira/browse/STDCXX-1020
> 
> Index: util/memchk.cpp
> ===================================================================
> --- util/memchk.cpp     (revision 702657)
> +++ util/memchk.cpp     (working copy)
> @@ -116,9 +116,11 @@
>          // operation away (as SunOS does, for instance)
>          // fd = open ("/dev/null", O_WRONLY);
> 
> +     char *tmpdir = getenv ("TMPDIR") == NULL ? P_tmpdir : getenv
> ("TMPDIR");
> +
>  #ifdef _WIN32
> 
> -        char* const fname = tempnam (P_tmpdir, ".rwmemchk.tmp");
> +        char* const fname = tempnam (tmpdir, ".rwmemchk.tmp");
> 
>          if (!fname)
>              return size_t (-1);
> @@ -137,10 +139,13 @@
> 
>  #else   // !_WIN32
> 
> -#  define TMP_TEMPLATE P_tmpdir "/rwmemchk-XXXXXX"
> +        char fname_buf [sizeof (tmpdir) + sizeof
("/rwmemchk-XXXXXX")];
> 
> -        char fname_buf [] = TMP_TEMPLATE;
> +        size_t len = sizeof (tmpdir) - 1;
> 
> +        memcpy (fname_buf, tmpdir, len);
> +        memcpy (fname_buf+len, "/rwmemchk-XXXXXX", sizeof
> ("/rwmemchk-XXXXXX"));
> +
>          fd = mkstemp (fname_buf);
> 
>          if (fd < 0) {

Mime
View raw message