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-401 test suite should honor TMPDIR
Date Thu, 09 Oct 2008 15:50:23 GMT
We need to use PATH_MAX for the fname_buf array size.

Index: tests/src/file.cpp
===================================================================
--- tests/src/file.cpp  (revision 702657)
+++ tests/src/file.cpp  (working copy)
@@ -208,8 +208,13 @@
 #ifndef _RWSTD_NO_MKSTEMP
 #  define TMP_TEMPLATE      "tmpfile-XXXXXX"
 
+    const char *tmpdir = getenv ("TMPDIR");
+    if (tmpdir == NULL) { 
+        tmpdir = P_tmpdir;
+    }
+
     if (!buf) {
-        static char fname_buf [sizeof (P_tmpdir) + sizeof
(TMP_TEMPLATE)];
+        static char fname_buf [PATH_MAX];
 
         buf = fname_buf;
         *buf = '\0';
@@ -217,13 +222,13 @@
 
     if ('\0' == *buf) {
         // copy the template to the buffer; make sure there is exactly
-        // one path separator character between P_tmpdir and the file
+        // one path separator character between tmpdir and the file
         // name template (it doesn't really matter how many there are
         // as long as it's at least one, but one looks better than two
         // in diagnostic messages)
-        size_t len = sizeof (P_tmpdir) - 1;
+        size_t len = strlen (tmpdir) - 1;
 
-        memcpy (buf, P_tmpdir, len);
+        memcpy (buf, tmpdir, len);
         if (_RWSTD_PATH_SEP != buf [len - 1])
             buf [len++] = _RWSTD_PATH_SEP;
 
@@ -251,7 +256,7 @@
 #  ifdef _WIN32
 
     // create a temporary file name
-    char* fname = tempnam (P_tmpdir, ".rwtest-tmp");
+    char* fname = tempnam (tmpdir, ".rwtest-tmp");
 
     if (fname) {
 
@@ -272,7 +277,7 @@
     else {
         fprintf (stderr, "%s:%d: tempnam(\"%s\", \"%s\") failed: %s\n",
                  __FILE__, __LINE__,
-                 P_tmpdir, ".rwtest-tmp", strerror (errno));
+                 tmpdir, ".rwtest-tmp", strerror (errno));
     }
 
 #  else

> -----Original Message-----
> From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
> Sent: Thursday, October 09, 2008 9:31 AM
> To: dev@stdcxx.apache.org
> Subject: RE: [PATCH] STDCXX-401 test suite should honor TMPDIR
> 
> That const_cast isn't suppose to be there.  Here is the correct
version:
> 
> Index: tests/src/file.cpp
> ===================================================================
> --- tests/src/file.cpp  (revision 702657)
> +++ tests/src/file.cpp  (working copy)
> @@ -208,8 +208,13 @@
>  #ifndef _RWSTD_NO_MKSTEMP
>  #  define TMP_TEMPLATE      "tmpfile-XXXXXX"
> 
> +    const char *tmpdir = getenv ("TMPDIR");
> +    if (tmpdir == NULL) {
> +        tmpdir = P_tmpdir;
> +    }
> +
>      if (!buf) {
> -        static char fname_buf [sizeof (P_tmpdir) + sizeof
> (TMP_TEMPLATE)];
> +        static char fname_buf [strlen (tmpdir) + sizeof
> (TMP_TEMPLATE)];
> 
>          buf = fname_buf;
>          *buf = '\0';
> @@ -217,13 +222,13 @@
> 
>      if ('\0' == *buf) {
>          // copy the template to the buffer; make sure there is
exactly
> -        // one path separator character between P_tmpdir and the file
> +        // one path separator character between tmpdir and the file
>          // name template (it doesn't really matter how many there are
>          // as long as it's at least one, but one looks better than
two
>          // in diagnostic messages)
> -        size_t len = sizeof (P_tmpdir) - 1;
> +        size_t len = strlen (tmpdir) - 1;
> 
> -        memcpy (buf, P_tmpdir, len);
> +        memcpy (buf, tmpdir, len);
>          if (_RWSTD_PATH_SEP != buf [len - 1])
>              buf [len++] = _RWSTD_PATH_SEP;
> 
> @@ -251,7 +256,7 @@
>  #  ifdef _WIN32
> 
>      // create a temporary file name
> -    char* fname = tempnam (P_tmpdir, ".rwtest-tmp");
> +    char* fname = tempnam (tmpdir, ".rwtest-tmp");
> 
>      if (fname) {
> 
> @@ -272,7 +277,7 @@
>      else {
>          fprintf (stderr, "%s:%d: tempnam(\"%s\", \"%s\") failed:
%s\n",
>                   __FILE__, __LINE__,
> -                 P_tmpdir, ".rwtest-tmp", strerror (errno));
> +                 tmpdir, ".rwtest-tmp", strerror (errno));
>      }
> 
>  #  else
> 
> > -----Original Message-----
> > From: Scott Zhong [mailto:Scott.Zhong@roguewave.com]
> > Sent: Thursday, October 09, 2008 9:25 AM
> > To: dev@stdcxx.apache.org
> > Subject: RE: [PATCH] STDCXX-401 test suite should honor TMPDIR
> >
> > Hi Farid, thanks for the quick response, here is the new version
with
> > the changes suggested.
> >
> > Index: tests/src/file.cpp
> > ===================================================================
> > --- tests/src/file.cpp  (revision 702657)
> > +++ tests/src/file.cpp  (working copy)
> > @@ -208,8 +208,13 @@
> >  #ifndef _RWSTD_NO_MKSTEMP
> >  #  define TMP_TEMPLATE      "tmpfile-XXXXXX"
> >
> > +    const char *tmpdir = getenv ("TMPDIR");
> > +    if (tmpdir == NULL) {
> > +        tmpdir = const_cast<char>(P_tmpdir);
> > +    }
> > +
> >      if (!buf) {
> > -        static char fname_buf [sizeof (P_tmpdir) + sizeof
> > (TMP_TEMPLATE)];
> > +        static char fname_buf [strlen (tmpdir) + sizeof
> > (TMP_TEMPLATE)];
> >
> >          buf = fname_buf;
> >          *buf = '\0';
> > @@ -217,13 +222,13 @@
> >
> >      if ('\0' == *buf) {
> >          // copy the template to the buffer; make sure there is
> exactly
> > -        // one path separator character between P_tmpdir and the
file
> > +        // one path separator character between tmpdir and the file
> >          // name template (it doesn't really matter how many there
are
> >          // as long as it's at least one, but one looks better than
> two
> >          // in diagnostic messages)
> > -        size_t len = sizeof (P_tmpdir) - 1;
> > +        size_t len = strlen (tmpdir) - 1;
> >
> > -        memcpy (buf, P_tmpdir, len);
> > +        memcpy (buf, tmpdir, len);
> >          if (_RWSTD_PATH_SEP != buf [len - 1])
> >              buf [len++] = _RWSTD_PATH_SEP;
> >
> > @@ -251,7 +256,7 @@
> >  #  ifdef _WIN32
> >
> >      // create a temporary file name
> > -    char* fname = tempnam (P_tmpdir, ".rwtest-tmp");
> > +    char* fname = tempnam (tmpdir, ".rwtest-tmp");
> >
> >      if (fname) {
> >
> > @@ -272,7 +277,7 @@
> >      else {
> >          fprintf (stderr, "%s:%d: tempnam(\"%s\", \"%s\") failed:
> %s\n",
> >                   __FILE__, __LINE__,
> > -                 P_tmpdir, ".rwtest-tmp", strerror (errno));
> > +                 tmpdir, ".rwtest-tmp", strerror (errno));
> >      }
> >
> >  #  else
> >
> > > -----Original Message-----
> > > From: Farid Zaripov [mailto:Farid_Zaripov@epam.com]
> > > Sent: Thursday, October 09, 2008 2:20 AM
> > > To: dev@stdcxx.apache.org
> > > Subject: Re: [PATCH] STDCXX-401 test suite should honor TMPDIR
> > >
> > > Hi Scott.
> > >
> > > > Index: file.cpp
> > > >
> ===================================================================
> > > > --- file.cpp    (revision 702657)
> > > > +++ file.cpp    (working copy)
> > > > @@ -208,8 +208,10 @@
> > > >  #ifndef _RWSTD_NO_MKSTEMP
> > > >  #  define TMP_TEMPLATE      "tmpfile-XXXXXX"
> > > >
> > > > +    char *tmpdir = getenv ("TMPDIR") == NULL ? P_tmpdir :
getenv
> > > ("TMPDIR");
> > >
> > >   tmpdir might be const char*. And why getenv("TMPDIR") is called
> > twice?
> > >
> > > > +
> > > >      if (!buf) {
> > > > -        static char fname_buf [sizeof (P_tmpdir) + sizeof
> > > (TMP_TEMPLATE)];
> > > > +        static char fname_buf [sizeof (tmpdir) + sizeof
> > > (TMP_TEMPLATE)];
> > >
> > >   Here sizeof (tmpdir) != strlen (tmpdir). I think that using here
> > > PATH_MAX is ok.
> > >
> > > [...]
> > > > -        size_t len = sizeof (P_tmpdir) - 1;
> > > > +        size_t len = sizeof (tmpdir) - 1;
> > >
> > >   Same.
> > >
> > > Farid.

Mime
View raw message