runtime: abort stack scan in cases that we cannot unwind the stack
[gcc.git] / libgo / go / os / path_unix.go
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
5 // +build aix darwin dragonfly freebsd hurd js,wasm linux nacl netbsd openbsd solaris
6
7 package os
8
9 const (
10 PathSeparator = '/' // OS-specific path separator
11 PathListSeparator = ':' // OS-specific path list separator
12 )
13
14 // IsPathSeparator reports whether c is a directory separator character.
15 func IsPathSeparator(c uint8) bool {
16 return PathSeparator == c
17 }
18
19 // basename removes trailing slashes and the leading directory name from path name.
20 func 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 }
36
37 // splitPath returns the base name and parent directory.
38 func splitPath(path string) (string, string) {
39 // if no better parent is found, the path is relative from "here"
40 dirname := "."
41 // if no slashes in path, base is path
42 basename := path
43
44 i := len(path) - 1
45
46 // Remove trailing slashes
47 for ; i > 0 && path[i] == '/'; i-- {
48 path = path[:i]
49 }
50
51 // Remove leading directory path
52 for i--; i >= 0; i-- {
53 if path[i] == '/' {
54 dirname = path[:i+1]
55 basename = path[i+1:]
56 break
57 }
58 }
59
60 return dirname, basename
61 }
62
63 func fixRootDirectory(p string) string {
64 return p
65 }