Patchwork [libfortran] PR 51803 getcwd() failure

login
register
mail settings
Submitter Tobias Burnus
Date Jan. 11, 2012, 8:03 a.m.
Message ID <4F0D424F.4030808@net-b.de>
Download mbox | patch
Permalink /patch/135365/
State New
Headers show

Comments

Tobias Burnus - Jan. 11, 2012, 8:03 a.m.
Hi Janne,


On 01/11/2012 08:37 AM, Janne Blomqvist wrote:
> Index: runtime/main.c
> ===================================================================
> --- runtime/main.c      (revision 183089)
> +++ runtime/main.c      (working copy)
> @@ -116,8 +116,10 @@ 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 = ".";
>   #endif

I had preferred a patch like the following.

Tobias

Patch

--- a/libgfortran/runtime/main.c
+++ b/libgfortran/runtime/main.c
@@ -117,9 +117,16 @@  store_exe_path (const char * argv0)
  #ifdef HAVE_GETCWD
    cwd = getcwd (buf, sizeof (buf));
  #else
-  cwd = "";
+  cwd = NULL;
  #endif

+  if (cwd == NULL)
+    {
+      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.  */