Patchwork [libfortran] PR 51803 getcwd() failure

login
register
mail settings
Submitter Tobias Burnus
Date Jan. 11, 2012, 12:55 p.m.
Message ID <4F0D86B2.1080509@net-b.de>
Download mbox | patch
Permalink /patch/135381/
State New
Headers show

Comments

Tobias Burnus - Jan. 11, 2012, 12:55 p.m.
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

Patch

2012-01-11  Tobias Burnus  <burnus@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.  */