On Wed, Jan 11, 2012 at 14:55, Tobias Burnus <bur...@net-b.de> wrote:
> 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.

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

Index: main.c
===================================================================
--- main.c      (revision 183091)
+++ main.c      (working copy)
@@ -106,22 +106,26 @@
 #endif

   /* On the simulator argv is not set.  */
-  if (argv0 == NULL || argv0[0] == '/')
+  if (argv0 == NULL || argv0[0] == DIR_SEPARATOR)
     {
       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)
-    cwd = ".";
 #else
-  cwd = ".";
+  cwd = NULL;
 #endif

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


Also, I removed the memset() call as superfluous; getcwd() makes sure
that the buffer is null terminated or it will return NULL instead of a
pointer to the string.

For my part this fixed patch would be Ok.

-- 
Janne Blomqvist

Reply via email to