Come to think of it, the code can be simplified; there's no need for a while loop there. I installed the following patch instead.
diff --git a/ChangeLog b/ChangeLog index 4d73a26..9b0cccd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2013-07-15 Paul Eggert <[email protected]> + + tmpdir: port to VMS, to // != /, and to long dirs + * lib/tmpdir.c (__libc_secure_getenv) [!_LIBC]: Rename from + __secure_getenv, so that we're more like the glibc version. + All uses changed. + (path_search): Don't put slash after directory if __VMS. + Problem reported by Steven M. Schweda in + <http://lists.gnu.org/archive/html/bug-gnulib/2013-07/msg00019.html>. + Simplify code to add slash; no need for a loop. + Do not remove trailing slash from "//". + Do not assume dlen <= INT_MAX. + 2013-07-09 Paul Eggert <[email protected]> regex: port to --with-included-regex --enable-gcc-warnings non-threaded diff --git a/lib/tmpdir.c b/lib/tmpdir.c index e804416..405c4bd 100644 --- a/lib/tmpdir.c +++ b/lib/tmpdir.c @@ -53,7 +53,7 @@ # define struct_stat64 struct stat64 #else # define struct_stat64 struct stat -# define __secure_getenv secure_getenv +# define __libc_secure_getenv secure_getenv # define __xstat64(version, path, buf) stat (path, buf) #endif @@ -89,6 +89,7 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, { const char *d; size_t dlen, plen; + bool add_slash; if (!pfx || !pfx[0]) { @@ -104,7 +105,7 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, if (try_tmpdir) { - d = __secure_getenv ("TMPDIR"); + d = __libc_secure_getenv ("TMPDIR"); if (d != NULL && direxists (d)) dir = d; else if (dir != NULL && direxists (dir)) @@ -139,16 +140,20 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, } dlen = strlen (dir); - while (dlen >= 1 && ISSLASH (dir[dlen - 1])) - dlen--; /* remove trailing slashes */ + add_slash = dlen != 0 && !ISSLASH (dir[dlen - 1]); +#ifdef __VMS + if (dlen != 0 && dir[dlen - 1] == ':') + add_slash = false; +#endif /* check we have room for "${dir}/${pfx}XXXXXX\0" */ - if (tmpl_len < dlen + 1 + plen + 6 + 1) + if (tmpl_len < dlen + add_slash + plen + 6 + 1) { __set_errno (EINVAL); return -1; } - sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx); + memcpy (tmpl, dir, dlen); + sprintf (tmpl + dlen, &"/%.*sXXXXXX"[!add_slash], pfx, (int) plen); return 0; }
