mirror of
https://github.com/pine64/blisp.git
synced 2025-02-25 21:33:42 +00:00
Modifications for MacOS to let it find data files in the same directory
as the executable. This is totally wrong for a "normal" MacOS app bundle, but it follows the existing Linux convention.
This commit is contained in:
parent
ec17f896bc
commit
e789cdf809
@ -17,6 +17,29 @@ static struct arg_str* port_name, *chip_type;
|
|||||||
static struct arg_end* end;
|
static struct arg_end* end;
|
||||||
static void* cmd_write_argtable[5];
|
static void* cmd_write_argtable[5];
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Ugh. This stuff is just so messy without C++17 or Qt...
|
||||||
|
// These are not thread safe, but it doesn't place the responsibility
|
||||||
|
// to free an allocated buffer on the caller.nn
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static void get_executable_path(char* buffer_out, uint32_t max_size) {
|
||||||
|
assert (max_size >= PATH_MAX); // n.b. 1024 on MacOS. 4K on most Linux.
|
||||||
|
|
||||||
|
char raw_path_name[PATH_MAX]; // $HOME/../../var/tmp/x
|
||||||
|
char real_path_name[PATH_MAX]; // /var/tmp/x
|
||||||
|
uint32_t raw_path_size = sizeof(raw_path_name);
|
||||||
|
|
||||||
|
if(!_NSGetExecutablePath(raw_path_name, &raw_path_size)) {
|
||||||
|
realpath(raw_path_name, real_path_name);
|
||||||
|
}
|
||||||
|
// *real_path_name is appropriately sized and null terminated.
|
||||||
|
strcpy(buffer_out, real_path_name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
get_binary_folder(char* buffer, uint32_t buffer_size) {
|
get_binary_folder(char* buffer, uint32_t buffer_size) {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@ -24,6 +47,11 @@ get_binary_folder(char* buffer, uint32_t buffer_size) {
|
|||||||
char* pos = strrchr(buffer, '/');
|
char* pos = strrchr(buffer, '/');
|
||||||
pos[0] = '\0';
|
pos[0] = '\0';
|
||||||
return pos - buffer;
|
return pos - buffer;
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
get_executable_path(buffer, buffer_size);
|
||||||
|
char* pos = strrchr(buffer, '/');
|
||||||
|
pos[0] = '\0';
|
||||||
|
return pos - buffer;
|
||||||
#else
|
#else
|
||||||
#error NOT IMPLEMENTED
|
#error NOT IMPLEMENTED
|
||||||
WCHAR path[MAX_PATH];
|
WCHAR path[MAX_PATH];
|
||||||
@ -188,4 +216,4 @@ cmd_write_free() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct cmd cmd_write
|
struct cmd cmd_write
|
||||||
= { "write", cmd_write_args_init, cmd_write_parse_exec, cmd_write_args_print_syntax, cmd_write_free };
|
= { "write", cmd_write_args_init, cmd_write_parse_exec, cmd_write_args_print_syntax, cmd_write_free };
|
||||||
|
Loading…
Reference in New Issue
Block a user