This is the mail archive of the cygwin-patches mailing list for the Cygwin 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: Problem with sh/bash and snapshot cygwin1-20050825.dll


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>> While you're at it, fix realpath(NULL, buf) to set buf[0]='\0', instead of
>> leaving garbage there.
>
>http://cygwin.com/acronyms/#PTC

Also, strdup() is faster than malloc()/strcpy(), since it calculates the
path length only once instead of twice.

>> Also, realpath("//..", buf) should be "//", not "/", since it is its own
>> root (there is no way to make // a subdirectory of /).  And when pwd is
>> //, realpath("..", buf) is correctly "//", but realpath("../..", buf) is
>> mistakenly "/".
>
>http://cygwin.com/acronyms/#PTC

Unfortunately, I don't have copyright assignment (I've tried convincing my
employer; I'll try again), and this would push me over my current
contribution limits.

2005-08-26  Eric Blake  <ebb9@byu.net>

	* path.cc (realpath): Truncate resolved when path is NULL.  Use
	strdup when resolved is NULL.

- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDDxRe84KuGfSFAYARAnXaAJ0b9xkB+hhmp9GQk0S52vSlzbtqkwCdGlfE
wjGOq/B2Iv2JyJ2HA81HZIc=
=EXXF
-----END PGP SIGNATURE-----
Index: path.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/path.cc,v
retrieving revision 1.388
diff -u -p -b -r1.388 path.cc
--- path.cc	25 Aug 2005 21:18:26 -0000	1.388
+++ path.cc	26 Aug 2005 13:07:29 -0000
@@ -50,6 +50,7 @@ details. */
 #include "winsup.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/mount.h>
 #include <mntent.h>
 #include <unistd.h>
@@ -3657,6 +3658,8 @@ realpath (const char *path, char *resolv
   /* Make sure the right errno is returned if path is NULL. */
   if (!path)
     {
+      if (resolved)
+	resolved[0] = '\0';
       set_errno (EINVAL);
       return NULL;
     }
@@ -3677,11 +3680,7 @@ realpath (const char *path, char *resolv
   if (!real_path.error && real_path.exists ())
     {
       if (!resolved)
-	{
-          resolved = (char *) malloc (strlen (real_path.normalized_path) + 1);
-          if (!resolved)
-	    return NULL;
-        }
+	return strdup (real_path.normalized_path);
       return strcpy (resolved, real_path.normalized_path);
     }
 

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