Patchwork [libfortran] PR 51803 getcwd() failure

login
register
mail settings
Submitter Tobias Burnus
Date Jan. 11, 2012, 2:04 p.m.
Message ID <4F0D9708.509@net-b.de>
Download mbox | patch
Permalink /patch/135390/
State New
Headers show

Comments

Tobias Burnus - Jan. 11, 2012, 2:04 p.m.
On 01/11/2012 02:08 PM, Janne Blomqvist wrote:
> Checking for an absolute path is already done a few lines up. So if
> you prefer the kind of approach that you have in your patch, IMHO a
> more correct patch would be

I had a quick chat with Kai and decided to leave the lower part as is. 
However, I realized that the check for an absolute path is not correct 
for Windows. With the help of Kai I came up with the attached version.

OK for the trunk?

Tobias
Janne Blomqvist - Jan. 11, 2012, 2:36 p.m.
On Wed, Jan 11, 2012 at 16:04, Tobias Burnus <burnus@net-b.de> wrote:
> On 01/11/2012 02:08 PM, Janne Blomqvist wrote:
>>
>> Checking for an absolute path is already done a few lines up. So if
>> you prefer the kind of approach that you have in your patch, IMHO a
>> more correct patch would be
>
>
> I had a quick chat with Kai and decided to leave the lower part as is.
> However, I realized that the check for an absolute path is not correct for
> Windows. With the help of Kai I came up with the attached version.
>
>
> OK for the trunk?

With the minor change

s/an simulator/a simulator/

in the comment, Ok.

In practice, I don't think this matters at the moment, since the only
place where exe_path is used is when building the argument list for
addr2line in the backtrace generation. Which we don't do on Windows
anyway, since windows lacks fork, exec, and pipe which we require to
launch the subprocess.

Making cwd "const char*" is also Ok.

Patch

2012-01-11  Tobias Burnus  <burnus@net-b.de>

	* runtime/main.c (store_exe_path): Fix absolute path
	detection for Windows.

Index: libgfortran/runtime/main.c
===================================================================
--- libgfortran/runtime/main.c	(revision 183093)
+++ libgfortran/runtime/main.c	(working copy)
@@ -105,15 +105,22 @@  store_exe_path (const char * argv0)
     }
 #endif
 
-  /* On the simulator argv is not set.  */
-  if (argv0 == NULL || argv0[0] == '/')
+  /* If the path is absolute or on an simulator where argv is not set.  */
+#ifdef __MINGW32__
+  if (argv0 == NULL
+      || ('A' <= argv0[0] && argv0[0] <= 'Z' && argv0[1] == ':')
+      || ('a' <= argv0[0] && argv0[0] <= 'z' && argv0[1] == ':')
+      || (argv0[0] == '/' && argv0[1] == '/')
+      || (argv0[0] == '\\' && argv0[1] == '\\'))
+#else
+  if (argv0 == NULL || argv0[0] == DIR_SEPARATOR)
+#endif
     {
       exe_path = argv0;
       please_free_exe_path_when_done = 0;
       return;
     }
 
-  memset (buf, 0, sizeof (buf));
 #ifdef HAVE_GETCWD
   cwd = getcwd (buf, sizeof (buf));
   if (!cwd)