]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/os-macosx.mm
help.html: making search box have first tab index
[factor.git] / vm / os-macosx.mm
index 2b855d4881d76006c2f7062fdc974bca1c8b66f3..71c70f7a489cf505f1a90c4e7c5a317c64a5e83e 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <mach/mach_time.h>
 #include <sys/utsname.h>
+#include <unistd.h>
+#include <stdio.h>
 
 #include "master.hpp"
 
@@ -22,8 +24,9 @@ void early_init(void) {
   }
 }
 
+// You must free() this yourself.
 const char* vm_executable_path(void) {
-  return [[[NSBundle mainBundle] executablePath] UTF8String];
+  return safe_strdup([[[NSBundle mainBundle] executablePath] UTF8String]);
 }
 
 const char* default_image_path(void) {
@@ -37,12 +40,11 @@ const char* default_image_path(void) {
 
   if ([path hasSuffix:@".app"] || [path hasSuffix:@".app/"]) {
     NSFileManager* mgr = [NSFileManager defaultManager];
+    NSString* root = [path stringByDeletingLastPathComponent];
+    NSString* resources = [path stringByAppendingPathComponent:@"Contents/Resources"];
 
-    NSString* imageInBundle =
-        [[path stringByAppendingPathComponent:@"Contents/Resources"]
-            stringByAppendingPathComponent:image];
-    NSString* imageAlongBundle = [[path stringByDeletingLastPathComponent]
-        stringByAppendingPathComponent:image];
+    NSString* imageInBundle = [resources stringByAppendingPathComponent:image];
+    NSString* imageAlongBundle = [root stringByAppendingPathComponent:image];
 
     returnVal = ([mgr fileExistsAtPath:imageInBundle] ? imageInBundle
                                                       : imageAlongBundle);
@@ -53,6 +55,7 @@ const char* default_image_path(void) {
     returnVal = [returnVal stringByDeletingLastPathComponent];
     returnVal = [returnVal stringByDeletingLastPathComponent];
     returnVal = [returnVal stringByAppendingPathComponent:image];
+
   } else {
     returnVal = [path stringByAppendingPathComponent:image];
   }
@@ -65,7 +68,7 @@ void factor_vm::init_signals(void) {
   mach_initialize();
 }
 
-/* Amateurs at Apple: implement this function, properly! */
+// Amateurs at Apple: implement this function, properly!
 Protocol* objc_getProtocol(char* name) {
   if (strcmp(name, "NSTextInput") == 0)
     return @protocol(NSTextInput);