Source file
src/os/path_unix.go
1
2
3
4
5
6
7 package os
8
9 const (
10 PathSeparator = '/'
11 PathListSeparator = ':'
12 )
13
14
15 func IsPathSeparator(c uint8) bool {
16 return PathSeparator == c
17 }
18
19
20 func basename(name string) string {
21 i := len(name) - 1
22
23 for ; i > 0 && name[i] == '/'; i-- {
24 name = name[:i]
25 }
26
27 for i--; i >= 0; i-- {
28 if name[i] == '/' {
29 name = name[i+1:]
30 break
31 }
32 }
33
34 return name
35 }
36
37
38 func splitPath(path string) (string, string) {
39
40 dirname := "."
41
42
43 for len(path) > 1 && path[0] == '/' && path[1] == '/' {
44 path = path[1:]
45 }
46
47 i := len(path) - 1
48
49
50 for ; i > 0 && path[i] == '/'; i-- {
51 path = path[:i]
52 }
53
54
55 basename := path
56
57
58 for i--; i >= 0; i-- {
59 if path[i] == '/' {
60 if i == 0 {
61 dirname = path[:1]
62 } else {
63 dirname = path[:i]
64 }
65 basename = path[i+1:]
66 break
67 }
68 }
69
70 return dirname, basename
71 }
72
73 func fixRootDirectory(p string) string {
74 return p
75 }
76
View as plain text