4 #include <pbd/dirname.h>
8 PBD::dirname (const char *path)
15 if ((slash = strrchr (path, '/')) == 0) {
19 if (*(slash+1) == '\0') {
23 len = (size_t) (slash - path);
24 ret = (char *) malloc (sizeof (char) * (len + 1));
26 snprintf (ret, len, "%*s", (int)len, path);
31 PBD::dirname (const std::string str)
33 std::string::size_type slash = str.find_last_of ('/');
36 if (slash == std::string::npos) {
40 /* remove trailing multiple slashes (legal under POSIX) */
42 dir = str.substr (0, slash);
45 while (slash > 1 && dir[slash-1] == '/') {
47 dir = dir.substr (0, slash);