...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package path
16
17
18 type OS string
19
20 const (
21 Unix OS = "unix"
22 Windows OS = "windows"
23 Plan9 OS = "plan9"
24 )
25
26
27
28
29 type os struct {
30 osInfo
31 Separator byte
32 ListSeparator byte
33 }
34
35 func (o os) isWindows() bool {
36 return o.Separator == '\\'
37 }
38
39 type osInfo interface {
40 IsPathSeparator(b byte) bool
41 splitList(path string) []string
42 volumeNameLen(path string) int
43 IsAbs(path string) (b bool)
44 HasPrefix(p, prefix string) bool
45 join(elem []string) string
46 sameWord(a, b string) bool
47 }
48
49 func getOS(o OS) os {
50 switch o {
51 case Windows:
52 return windows
53 case Plan9:
54 return plan9
55 default:
56 return unix
57 }
58 }
59
60 var (
61 plan9 = os{
62 osInfo: &plan9Info{},
63 Separator: plan9Separator,
64 ListSeparator: plan9ListSeparator,
65 }
66 unix = os{
67 osInfo: &unixInfo{},
68 Separator: unixSeparator,
69 ListSeparator: unixListSeparator,
70 }
71 windows = os{
72 osInfo: &windowsInfo{},
73 Separator: windowsSeparator,
74 ListSeparator: windowsListSeparator,
75 }
76 )
77
View as plain text