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.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/libgo/go/os/path_unix.go b/libgo/go/os/path_unix.go
index 36f8e61bf9..ecf098c461 100644
--- a/libgo/go/os/path_unix.go
+++ b/libgo/go/os/path_unix.go
@@ -15,3 +15,21 @@ const (
func IsPathSeparator(c uint8) bool {
return PathSeparator == c
}
+
+// basename removes trailing slashes and the leading directory name from path name
+func basename(name string) string {
+ i := len(name) - 1
+ // Remove trailing slashes
+ for ; i > 0 && name[i] == '/'; i-- {
+ name = name[:i]
+ }
+ // Remove leading directory name
+ for i--; i >= 0; i-- {
+ if name[i] == '/' {
+ name = name[i+1:]
+ break
+ }
+ }
+
+ return name
+}