This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch libfortran] PR 51803 getcwd() failure


Same patch with a minor update: I changed "cwd" from "char *" to "const char *" as I spotted a compile time warning for
cwd = ".";
which was along the lines that by the assignment the const qualifier is lost.


Too bad that we cannot enable -Werror for libgfortran.


On 01/11/2012 03:04 PM, Tobias Burnus wrote:
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?
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)
@@ -86,7 +86,8 @@ store_exe_path (const char * argv0)
 #define DIR_SEPARATOR '/'
 #endif
 
-  char buf[PATH_MAX], *cwd, *path;
+  char buf[PATH_MAX], *path;
+  const char *cwd;
 
   /* This can only happen if store_exe_path is called multiple times.  */
   if (please_free_exe_path_when_done)
@@ -105,15 +106,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)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]