diff options
-rw-r--r-- | byterun/main.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/byterun/main.c b/byterun/main.c index cd2575c09..54f118d24 100644 --- a/byterun/main.c +++ b/byterun/main.c @@ -21,6 +21,10 @@ extern void caml_main (char **); +#ifdef __linux__ +#include <unistd.h> +#endif + #ifdef _WIN32 extern void expand_command_line (int *, char ***); #endif @@ -33,8 +37,18 @@ extern void expand_command_line (int *, char ***); int main(int argc, char **argv) { #ifdef _WIN32 + /* Expand wildcards and diversions in command line */ expand_command_line(&argc, &argv); #endif +#ifdef __linux__ + /* Recover argv[0] from /proc/self/exe, much more reliable */ + char exename[1024]; + int retcode = readlink("/proc/self/exe", exename, sizeof(exename)); + if (retcode != -1 && retcode < sizeof(exename)) { + exename[retcode] = 0; + argv[0] = exename; + } +#endif #if macintosh rotatecursor_options (&something_to_do, 0, NULL); #endif /* macintosh */ |