Source file src/runtime/os_workdir_ios_arm64.go

     1  // Copyright 2026 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  package runtime
     6  
     7  import "unsafe"
     8  
     9  const (
    10  	maxPathLen             = 1024
    11  	_kCFStringEncodingUTF8 = 0x08000100
    12  )
    13  
    14  // initWorkingDir sets the current working directory to the app root on iOS.
    15  // By default ios/arm64 processes start in "/".
    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  		// No app bundle URL found.
    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