Dear all,
this is a follow up patch, which I think provides a better handling if
either getcwd fails or is not availble - or if the pathname in argv[0]
already is an absolute patch, in which case concatenating
current-working-directory + '/' + argv[0] does not really make sense.
Build on x86-64-linux.
OK for the trunk?
Tobias
2012-01-11 Tobias Burnus <bur...@net-b.de>
PR fortran/51803
* runtime/main.c (store_exe_path): Handle a failure of
getcwd and take absolute pathnames into account.
Index: libgfortran/runtime/main.c
===================================================================
--- libgfortran/runtime/main.c (revision 183092)
+++ libgfortran/runtime/main.c (working copy)
@@ -116,12 +116,17 @@ store_exe_path (const char * argv0)
memset (buf, 0, sizeof (buf));
#ifdef HAVE_GETCWD
cwd = getcwd (buf, sizeof (buf));
- if (!cwd)
- cwd = ".";
#else
- cwd = ".";
+ cwd = NULL;
#endif
+ if (!cwd || argv0[0] == DIR_SEPARATOR)
+ {
+ exe_path = argv0;
+ please_free_exe_path_when_done = 0;
+ return;
+ }
+
/* exe_path will be cwd + "/" + argv[0] + "\0". This will not work
if the executable is not in the cwd, but at this point we're out
of better ideas. */