summaryrefslogtreecommitdiff
path: root/libgo/go/os/path_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/os/path_unix.go')
-rw-r--r--libgo/go/os/path_unix.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/libgo/go/os/path_unix.go b/libgo/go/os/path_unix.go
index 3cb0e3acc4d..be373a50a91 100644
--- a/libgo/go/os/path_unix.go
+++ b/libgo/go/os/path_unix.go
@@ -16,7 +16,7 @@ func IsPathSeparator(c uint8) bool {
return PathSeparator == c
}
-// basename removes trailing slashes and the leading directory name from path name
+// basename removes trailing slashes and the leading directory name from path name.
func basename(name string) string {
i := len(name) - 1
// Remove trailing slashes
@@ -34,6 +34,32 @@ func basename(name string) string {
return name
}
+// splitPath returns the base name and parent directory.
+func splitPath(path string) (string, string) {
+ // if no better parent is found, the path is relative from "here"
+ dirname := "."
+ // if no slashes in path, base is path
+ basename := path
+
+ i := len(path) - 1
+
+ // Remove trailing slashes
+ for ; i > 0 && path[i] == '/'; i-- {
+ path = path[:i]
+ }
+
+ // Remove leading directory path
+ for i--; i >= 0; i-- {
+ if path[i] == '/' {
+ dirname = path[:i+1]
+ basename = path[i+1:]
+ break
+ }
+ }
+
+ return dirname, basename
+}
+
func fixRootDirectory(p string) string {
return p
}