about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 7959b76f868d..11c75d2cda4c 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -149,10 +149,19 @@ Path dirOf(const Path & path)
 
 string baseNameOf(const Path & path)
 {
-    Path::size_type pos = path.rfind('/');
+    if (path.empty())
+        return string("");
+
+    Path::size_type last = path.length() - 1;
+    if (path[last] == '/' && last > 0)
+        last -= 1;
+
+    Path::size_type pos = path.rfind('/', last);
     if (pos == string::npos)
-        throw Error(format("invalid file name ‘%1%’") % path);
-    return string(path, pos + 1);
+        pos = 0;
+    else
+        pos += 1;
+    return string(path, pos, last - pos + 1);
 }