]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgo/go/os/path_unix.go
libgo: update to Go1.14beta1
[thirdparty/gcc.git] / libgo / go / os / path_unix.go
CommitLineData
adb0401d
ILT
1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5a8ea165 5// +build aix darwin dragonfly freebsd hurd js,wasm linux netbsd openbsd solaris
d8f41257 6
adb0401d
ILT
7package os
8
9const (
10 PathSeparator = '/' // OS-specific path separator
11 PathListSeparator = ':' // OS-specific path list separator
12)
13
af146490 14// IsPathSeparator reports whether c is a directory separator character.
adb0401d
ILT
15func IsPathSeparator(c uint8) bool {
16 return PathSeparator == c
17}
c2047754 18
4f4a855d 19// basename removes trailing slashes and the leading directory name from path name.
c2047754
ILT
20func basename(name string) string {
21 i := len(name) - 1
22 // Remove trailing slashes
23 for ; i > 0 && name[i] == '/'; i-- {
24 name = name[:i]
25 }
26 // Remove leading directory name
27 for i--; i >= 0; i-- {
28 if name[i] == '/' {
29 name = name[i+1:]
30 break
31 }
32 }
33
34 return name
35}
dd931d9b 36
4f4a855d
ILT
37// splitPath returns the base name and parent directory.
38func splitPath(path string) (string, string) {
39 // if no better parent is found, the path is relative from "here"
40 dirname := "."
aa8901e9
ILT
41
42 // Remove all but one leading slash.
43 for len(path) > 1 && path[0] == '/' && path[1] == '/' {
44 path = path[1:]
45 }
4f4a855d
ILT
46
47 i := len(path) - 1
48
aa8901e9 49 // Remove trailing slashes.
4f4a855d
ILT
50 for ; i > 0 && path[i] == '/'; i-- {
51 path = path[:i]
52 }
53
aa8901e9
ILT
54 // if no slashes in path, base is path
55 basename := path
56
4f4a855d
ILT
57 // Remove leading directory path
58 for i--; i >= 0; i-- {
59 if path[i] == '/' {
aa8901e9
ILT
60 if i == 0 {
61 dirname = path[:1]
62 } else {
63 dirname = path[:i]
64 }
4f4a855d
ILT
65 basename = path[i+1:]
66 break
67 }
68 }
69
70 return dirname, basename
71}
72
dd931d9b
ILT
73func fixRootDirectory(p string) string {
74 return p
75}