#include <mach/mach_time.h>
#include <sys/utsname.h>
+#include <unistd.h>
+#include <stdio.h>
#include "master.hpp"
}
}
+// 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) {
NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle bundlePath];
- NSString* executable = [[bundle executablePath] lastPathComponent];
+ NSString* executablePath = [[bundle executablePath] stringByResolvingSymlinksInPath];
+ NSString* executable = [executablePath lastPathComponent];
NSString* image = [executable stringByAppendingString:@".image"];
NSString* returnVal;
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);
- } else
+ } else if ([executablePath hasSuffix:@".app/Contents/MacOS/factor"]) {
+ returnVal = executablePath;
+ returnVal = [returnVal stringByDeletingLastPathComponent];
+ returnVal = [returnVal stringByDeletingLastPathComponent];
+ returnVal = [returnVal stringByDeletingLastPathComponent];
+ returnVal = [returnVal stringByDeletingLastPathComponent];
+ returnVal = [returnVal stringByAppendingPathComponent:image];
+
+ } else {
returnVal = [path stringByAppendingPathComponent:image];
+ }
return [returnVal UTF8String];
}
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);
return nil;
}
-u64 nano_count() {
- u64 time = mach_absolute_time();
+uint64_t nano_count() {
+ uint64_t time = mach_absolute_time();
- static u64 scaling_factor = 0;
+ static uint64_t scaling_factor = 0;
if (!scaling_factor) {
mach_timebase_info_data_t info;
kern_return_t ret = mach_timebase_info(&info);