diff options
author | Daniel Serpell <daniel.serpell@gmail.com> | 2019-12-25 23:53:47 -0300 |
---|---|---|
committer | dmsc <daniel.serpell@gmail.com> | 2019-12-26 11:20:00 -0400 |
commit | a9044bbc34d0948b1dead4a259e8a2e5df1737e2 (patch) | |
tree | f4a8262d207c531d59697a16f46a614fc539d9e6 | |
parent | 3de0b11003cae275161451e899e2b6e310e4ef37 (diff) | |
download | emu2-a9044bbc34d0948b1dead4a259e8a2e5df1737e2.tar.gz |
Adds osx support for reading executable path.
This is needed for implementing process spawning.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | src/dos.c | 5 | ||||
-rw-r--r-- | src/utils.c | 35 | ||||
-rw-r--r-- | src/utils.h | 7 |
4 files changed, 48 insertions, 4 deletions
@@ -2,7 +2,7 @@ CC=gcc CFLAGS=-O3 -flto -Wall -g -Werror=implicit-function-declaration -Werror=int-conversion LDLIBS=-lm -OBJS=cpu.o loader.o main.o dosnames.o dis.o dos.o keyb.o dbg.o timer.o video.o +OBJS=cpu.o loader.o main.o dosnames.o dis.o dos.o keyb.o dbg.o timer.o utils.o video.o all: obj emu2 @@ -24,11 +24,12 @@ obj/cpu.o: src/cpu.c src/cpu.h src/dbg.h src/dis.h src/emu.h obj/dbg.o: src/dbg.c src/dbg.h src/env.h obj/dis.o: src/dis.c src/dis.h src/emu.h obj/dos.o: src/dos.c src/dos.h src/dbg.h src/dosnames.h src/emu.h src/env.h \ - src/keyb.h src/loader.h src/timer.h src/video.h + src/keyb.h src/loader.h src/timer.h src/utils.h src/video.h obj/dosnames.o: src/dosnames.c src/dbg.h src/dosnames.h src/emu.h src/env.h obj/keyb.o: src/keyb.c src/keyb.h src/dbg.h src/emu.h obj/loader.o: src/loader.c src/loader.h src/dbg.h src/emu.h obj/main.o: src/main.c src/dbg.h src/dos.h src/dosnames.h src/emu.h \ src/keyb.h src/timer.h src/video.h obj/timer.o: src/timer.c src/dbg.h src/timer.h src/emu.h +obj/utils.o: src/utils.c src/utils.h src/dbg.h obj/video.o: src/video.c src/video.h src/dbg.h src/emu.h @@ -6,6 +6,7 @@ #include "keyb.h" #include "loader.h" #include "timer.h" +#include "utils.h" #include "video.h" #include <errno.h> @@ -792,8 +793,8 @@ static int run_emulator(char *file, const char *prgname, char *cmdline, char *en // Accumulate args: char *args[64]; int i; - char exe_path[4096] = {0,}; - if(readlink("/proc/self/exe", exe_path, 4096) == -1) + const char *exe_path = get_program_exe_path(); + if(!exe_path) print_error("can't get emulator path.\n"); args[0] = prog_name; args[1] = file; diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..3a17b65 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,35 @@ +/* Platform dependent utility functions */ +#include "utils.h" +#include "dbg.h" +#include <unistd.h> + +#ifdef __APPLE__ +#include <mach-o/dyld.h> +#endif + +const char *get_program_exe_path(void) +{ +#if defined(__linux__) || defined(__CYGWIN__) + + static char exe_path[4096] = {0,}; + if(readlink("/proc/self/exe", exe_path, 4095) == -1) + return 0; + else + return exe_path; + +#elif defined(__APPLE__) + + static char exe_path[4096] = {0,}; + uint32_t length=4095; + if(_NSGetExecutablePath(exe_path, &length)) + return 0; + else + return exe_path; +#else + + /* No implementation */ + return 0; + +#endif +} + diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..ea4c413 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,7 @@ +/* Platform dependent utility functions */ +#pragma once + +/* Returns the full path to the program executable */ +const char *get_program_exe_path(void); + + |