autoupdate
[gnulib.git] / lib / tmpdir.c
index aa2164d..97fc3ff 100644 (file)
@@ -89,11 +89,7 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
 {
   const char *d;
   size_t dlen, plen;
-#ifdef __VMS
-  bool add_slash = false;
-#else
-  bool add_slash = true;
-#endif
+  bool add_slash;
 
   if (!pfx || !pfx[0])
     {
@@ -143,13 +139,12 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
         }
     }
 
-  /* Remove trailing slashes, except remove just one from "//".  */
   dlen = strlen (dir);
-  if (dlen == 2 && ISSLASH (dir[0]) && ISSLASH (dir[1]))
-    dlen--;
-  else
-    while (0 < dlen && ISSLASH (dir[dlen - 1]))
-      dlen--;
+#ifdef __VMS
+  add_slash = 0;
+#else
+  add_slash = dlen != 0 && !ISSLASH (dir[dlen - 1]);
+#endif
 
   /* check we have room for "${dir}/${pfx}XXXXXX\0" */
   if (tmpl_len < dlen + add_slash + plen + 6 + 1)
@@ -159,6 +154,6 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
     }
 
   memcpy (tmpl, dir, dlen);
-  sprintf (tmpl + dlen, &"/%.*sXXXXXX"[!add_slash], pfx, (int) plen);
+  sprintf (tmpl + dlen, &"/%.*sXXXXXX"[!add_slash], (int) plen, pfx);
   return 0;
 }