Mercurial > gnulib
changeset 37129:8dbab94306b9
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>.
Do not remove trailing slash from "//".
Do not assume dlen <= INT_MAX.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 15 Jul 2013 09:44:19 -0700 |
parents | 8fd10f695b27 |
children | 4a2b6252074c |
files | ChangeLog lib/tmpdir.c |
diffstat | 2 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Jul 09 11:35:01 2013 -0700 +++ b/ChangeLog Mon Jul 15 09:44:19 2013 -0700 @@ -1,3 +1,15 @@ +2013-07-15 Paul Eggert <eggert@cs.ucla.edu> + + 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>. + Do not remove trailing slash from "//". + Do not assume dlen <= INT_MAX. + 2013-07-09 Paul Eggert <eggert@cs.ucla.edu> regex: port to --with-included-regex --enable-gcc-warnings non-threaded
--- a/lib/tmpdir.c Tue Jul 09 11:35:01 2013 -0700 +++ b/lib/tmpdir.c Mon Jul 15 09:44:19 2013 -0700 @@ -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,11 @@ { const char *d; size_t dlen, plen; +#ifdef __VMS + bool add_slash = false; +#else + bool add_slash = true; +#endif if (!pfx || !pfx[0]) { @@ -104,7 +109,7 @@ 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)) @@ -138,17 +143,22 @@ } } + /* Remove trailing slashes, except remove just one from "//". */ dlen = strlen (dir); - while (dlen >= 1 && ISSLASH (dir[dlen - 1])) - dlen--; /* remove trailing slashes */ + if (dlen == 2 && ISSLASH (dir[0]) && ISSLASH (dir[1])) + dlen--; + else + while (0 < dlen && ISSLASH (dir[dlen - 1])) + dlen--; /* 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; }