*** empty log message ***
[gnulib.git] / lib / path-concat.c
index fe70f75..d6dafc9 100644 (file)
@@ -1,5 +1,5 @@
 /* path-concat.c -- concatenate two arbitrary pathnames
-   Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -32,6 +32,9 @@
 #include <sys/types.h>
 
 char *malloc ();
+#ifndef strdup
+char *strdup ();
+#endif
 
 #ifndef DIRECTORY_SEPARATOR
 # define DIRECTORY_SEPARATOR '/'
@@ -83,10 +86,13 @@ path_concat (const char *dir, const char *base, char **base_in_result)
 
   p = mempcpy (p_concat, dir, dir_len);
 
-  if (ISSLASH (*(p - 1)) && ISSLASH(*base))
-    --p;
-  else if (!ISSLASH (*(p - 1)) && !ISSLASH(*base))
-    *p++ = DIRECTORY_SEPARATOR;
+  if (dir_len > 0)
+    {
+      if (ISSLASH (*(p - 1)) && ISSLASH(*base))
+       --p;
+      else if (!ISSLASH (*(p - 1)) && !ISSLASH(*base))
+       *p++ = DIRECTORY_SEPARATOR;
+    }
 
   if (base_in_result)
     *base_in_result = p;