incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Zhong" <Scott.Zh...@roguewave.com>
Subject [PATCH] STDCXX-1020 memchk in utility should honor TMPDIR variable
Date Mon, 20 Oct 2008 22:05:47 GMT
Changelog:

util/memchk.cpp (memchk): use TMPDIR variable from environment if
defined.

here is the patch:

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) {

Mime
View raw message