Commit 78365f06 authored by Amos Wenger's avatar Amos Wenger

macox: Add GetHomeDirectory

parent cb060488
Pipeline #10642 passed with stage
in 49 seconds
......@@ -11,12 +11,12 @@ package macox
char *GetExecutablePath(char *cBundlePath) {
NSString* bundlePath = [NSString stringWithUTF8String:cBundlePath];
if (!bundlePath) {
return 0;
return NULL;
}
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
if (!bundle) {
return 0;
return NULL;
}
const char *tempString = [[bundle executablePath] UTF8String];
......@@ -33,7 +33,15 @@ char *GetLibraryPath() {
memcpy(ret, tempString, strlen(tempString) + 1);
return ret;
}
return 0;
return NULL;
}
char *GetHomeDirectory() {
id path = NSHomeDirectory();
const char *tempString = [path UTF8String];
char *ret = malloc(strlen(tempString) + 1);
memcpy(ret, tempString, strlen(tempString) + 1);
return ret;
}
char *GetApplicationSupportPath() {
......@@ -44,7 +52,7 @@ char *GetApplicationSupportPath() {
memcpy(ret, tempString, strlen(tempString) + 1);
return ret;
}
return 0;
return NULL;
}
*/
import "C"
......@@ -74,6 +82,16 @@ func GetLibraryPath() (string, error) {
return C.GoString(cPath), nil
}
func GetHomeDirectory() (string, error) {
cPath := C.GetHomeDirectory()
if uintptr(unsafe.Pointer(cPath)) == 0 {
return "", fmt.Errorf("Could not get home directory")
}
defer C.free(unsafe.Pointer(cPath))
return C.GoString(cPath), nil
}
func GetApplicationSupportPath() (string, error) {
cPath := C.GetApplicationSupportPath()
if uintptr(unsafe.Pointer(cPath)) == 0 {
......
......@@ -19,6 +19,12 @@ func Test_GetLibraryPath(t *testing.T) {
assert.NotEmpty(t, s)
}
func Test_GetHomeDirectory(t *testing.T) {
s, err := macox.GetHomeDirectory()
assert.NoError(t, err)
assert.NotEmpty(t, s)
}
func Test_GetApplicationSupportPath(t *testing.T) {
s, err := macox.GetApplicationSupportPath()
assert.NoError(t, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment