poldek: poldek/misc.c - util__abs_path(): keep ending slash

mis mis at pld-linux.org
Sat Feb 2 12:53:51 CET 2008


Author: mis                          Date: Sat Feb  2 11:53:51 2008 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- util__abs_path(): keep ending slash

---- Files affected:
poldek/poldek:
   misc.c (1.60 -> 1.61) 

---- Diffs:

================================================================
Index: poldek/poldek/misc.c
diff -u poldek/poldek/misc.c:1.60 poldek/poldek/misc.c:1.61
--- poldek/poldek/misc.c:1.60	Tue Jan 22 18:54:53 2008
+++ poldek/poldek/misc.c	Sat Feb  2 12:53:46 2008
@@ -18,6 +18,10 @@
 # include "config.h"
 #endif
 
+#ifndef HAVE_CANONICALIZE_FILE_NAME /* have safe GNU ext? */
+# error "missing safe realpath()"
+#endif
+
 #ifdef HAVE_STRSIGNAL
 # define _GNU_SOURCE 1  /* for strsignal */
 #endif
@@ -524,15 +528,24 @@
 
 char *util__abs_path(const char *path) 
 {
-    if (n_str_ne(path, ".") && strstr(path, "./") == NULL)
-        return NULL;
-    
-#ifdef HAVE_CANONICALIZE_FILE_NAME /* have safe GNU ext? */
-    return realpath(path, NULL);
-#else
-# error "missing safe realpath()"
-#endif
-    return NULL;
+    char *endslash, *rpath = NULL;
+
+    endslash = strrchr(path, '/');
+    if (endslash && *(endslash + 1) != '\0')
+        endslash = NULL;
+
+    rpath = realpath(path, NULL);
+
+    if (endslash) {
+        int n = strlen(rpath);
+        
+        rpath = n_realloc(rpath, n + 2);
+        rpath[n++] = '/';
+        rpath[n] = '\0';
+    }
+
+    DBGF("%s -> %s\n", path, rpath);
+    return rpath;
 }
 
 
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/misc.c?r1=1.60&r2=1.61&f=u



More information about the pld-cvs-commit mailing list