diff mbox

[libfortran] PR 51803 getcwd() failure

Message ID 4F0D424F.4030808@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Jan. 11, 2012, 8:03 a.m. UTC
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
diff mbox

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.  */