Source file
src/runtime/os_workdir_ios_arm64.go
1
2
3
4
5 package runtime
6
7 import "unsafe"
8
9 const (
10 maxPathLen = 1024
11 _kCFStringEncodingUTF8 = 0x08000100
12 )
13
14
15
16 func initWorkingDir() {
17 bundle := cfBundleGetMainBundle()
18 if bundle == 0 {
19 writeErrStr("runtime/cgo: no main bundle\n")
20 return
21 }
22 url := cfBundleCopyBundleURL(bundle)
23 if url == 0 {
24
25 return
26 }
27
28 var buf [maxPathLen]byte
29 path := &buf[0]
30 ok := cfURLGetFileSystemRepresentation(url, true, path, uintptr(len(buf)))
31 cfRelease(url)
32 if !ok {
33 writeErrStr("runtime/cgo: cannot get bundle URL path\n")
34 return
35 }
36
37 if chdir(path) != 0 {
38 writeErrStr("runtime/cgo: chdir(")
39 writeErrData(path, int32(findnull(path)))
40 writeErrStr(") failed\n")
41 }
42
43 const goExecWrapperWorkingDirectoryKey = "GoExecWrapperWorkingDirectory\x00"
44 key := cfStringCreateWithCString(0, unsafe.StringData(goExecWrapperWorkingDirectoryKey), _kCFStringEncodingUTF8)
45 if key == 0 {
46 writeErrStr("runtime/cgo: cannot create GoExecWrapperWorkingDirectory string\n")
47 return
48 }
49 wd := cfBundleGetValueForInfoDictionaryKey(bundle, key)
50 cfRelease(key)
51 if wd == 0 {
52 return
53 }
54 if !cfStringGetCString(wd, path, uintptr(len(buf)), _kCFStringEncodingUTF8) {
55 writeErrStr("runtime/cgo: cannot get GoExecWrapperWorkingDirectory string\n")
56 return
57 }
58
59 if chdir(path) != 0 {
60 writeErrStr("runtime/cgo: chdir(")
61 writeErrData(path, int32(findnull(path)))
62 writeErrStr(") failed\n")
63 }
64 }
65
View as plain text