summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2001-10-30 09:20:48 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2001-10-30 09:20:48 +0000
commit78887cfdc8b1699db09d9d695ff3a1024a32050e (patch)
treeead60ade77d98200098dc120a950f2a7cb154dd4
parente531b9367c8d8e7ce6d33eabb83273775b4a76c1 (diff)
Utiliser /proc/self/exe sous Linux (PR#557)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3945 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--byterun/main.c14
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 */