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