]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/unix.c
Add function basename_safe
[netatalk.git] / libatalk / util / unix.c
index 0e8fcab6aaf323867fad7a44052e7df9abbecca3..6dce0857744151ef4ba9189989712ae9ade92883 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include <sys/wait.h>
+#include <libgen.h>
 
 #include <atalk/adouble.h>
 #include <atalk/ea.h>
@@ -375,3 +376,13 @@ char *realpath_safe(const char *path)
     return resolved_path;
 #endif
 }
+
+/**
+ * Returns pointer to static buffer with basename of path
+ **/
+const char *basename_safe(const char *path)
+{
+    static char buf[MAXPATHLEN+1];
+    strlcpy(buf, path, MAXPATHLEN);
+    return basename(buf);
+}