Hi,

See attached, please apply.

Greetings,
Jan.

-- 
Jan Nieuwenhuizen <[email protected]> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ®  http://AvatarAcademy.nl  
>From 98e49aefe607b2df4aa23401f219507b515a93f6 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <[email protected]>
Date: Fri, 4 Feb 2011 18:25:17 +0100
Subject: [PATCH 1/4] canonicalize-lgpl: Add support for running without Cygwin, off by default.

2011-02-01  Jan Nieuwenhuizen  <[email protected]>

    * tests/test-canonicalize-lgpl.c (main): Add support for running
    without Cygwin by using CPPFLAGS='-DRM_RF="del /r/q"'.  Off by
    default.
---
 ChangeLog                      |    6 ++++++
 tests/test-canonicalize-lgpl.c |    7 ++++++-
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b025454..0b3df9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-02-04  Jan Nieuwenhuizen  <[email protected]>
+
+	* tests/test-canonicalize-lgpl.c (main): Add support for running
+	without Cygwin by using CPPFLAGS='-DRM_RF="del /r/q"'.  Off by
+	default.
+
 2011-01-31  Eric Blake  <[email protected]>
 
 	dup2: work around Haiku bug
diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c
index 17cdff0..9682ca4 100644
--- a/tests/test-canonicalize-lgpl.c
+++ b/tests/test-canonicalize-lgpl.c
@@ -37,6 +37,11 @@ SIGNATURE_CHECK (canonicalize_file_name, char *, (const char *));
 
 #define BASE "t-can-lgpl.tmp"
 
+#ifndef RM_RF
+/* To run this test without Cygwin, use CPPFLAGS='-DRM_RF="del /r/q"' */
+#define RM_RF "rm -rf"
+#endif
+
 static void *
 null_ptr (void)
 {
@@ -56,7 +61,7 @@ main (void)
      any leftovers from a previous partial run.  */
   {
     int fd;
-    ignore_value (system ("rm -rf " BASE " ise"));
+    ignore_value (system (RM_RF " " BASE " ise"));
     ASSERT (mkdir (BASE, 0700) == 0);
     fd = creat (BASE "/tra", 0600);
     ASSERT (0 <= fd);
-- 
1.7.1

>From 53264cafd08fde37831ad6483d31abf578249b82 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <[email protected]>
Date: Fri, 4 Feb 2011 18:33:26 +0100
Subject: [PATCH 2/4] canonicalize-lgpl: Add basic sanity checks for mingw demonstrating general breakage.

2011-02-04  Jan Nieuwenhuizen  <[email protected]>

	* tests/test-canonicalize-lgpl.c (main)[(_WIN32 || __WIN32__) && ! __CYGWIN__]:
	Add basic sanity checks for mingw along with debug printing demonstrating
	general breakage.
---
 ChangeLog                      |    6 ++++++
 tests/test-canonicalize-lgpl.c |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0b3df9a..24d1998 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-02-04  Jan Nieuwenhuizen  <[email protected]>
 
+	* tests/test-canonicalize-lgpl.c (main)[(_WIN32 || __WIN32__) && ! __CYGWIN__]: 
+	Add basic sanity checks for mingw along with debug printing demonstrating
+	general breakage.
+
+2011-02-04  Jan Nieuwenhuizen  <[email protected]>
+
 	* tests/test-canonicalize-lgpl.c (main): Add support for running
 	without Cygwin by using CPPFLAGS='-DRM_RF="del /r/q"'.  Off by
 	default.
diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c
index 9682ca4..1e10af0 100644
--- a/tests/test-canonicalize-lgpl.c
+++ b/tests/test-canonicalize-lgpl.c
@@ -103,6 +103,44 @@ main (void)
     ASSERT (errno == ENOENT);
   }
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* Check basic drive letter sanity.  */
+  {
+    char *cwd;
+    char *test;
+    char *result;
+
+    /* Check if BASE has a canonical name.  */
+    result = canonicalize_file_name (BASE);
+    fprintf (stderr, "BASE-canon: %s\n", result);
+    ASSERT (result != NULL);
+
+    /* Check if BASE's canonical name is somewhat canonical.  */
+    ASSERT ((strchr (result, '/') == NULL)
+	    != (strchr (result, '\\') == NULL));
+
+    /* Check if CWD has a canonical name.  */
+    cwd = getcwd (NULL, 0);
+    fprintf (stderr, "CWD: %s\n", cwd);
+    result = canonicalize_file_name (cwd);
+    fprintf (stderr, "CWD-canon: %s\n", result);
+    ASSERT (result != NULL);
+
+    /* Check basic drive letter sanity.  */
+    test = "c:/";
+    result = canonicalize_file_name (test);
+    ASSERT (strcmp (result, test) == 0);
+    fprintf (stderr, "C:/-canon: %s\n", result);
+    result = canonicalize_file_name ("C:\\");
+    ASSERT (strcmp (result, test) == 0);
+    fprintf (stderr, "C:\\-canon: %s\n", result);
+    result = canonicalize_file_name ("C:");
+    ASSERT (strcmp (result, test) == 0);
+    fprintf (stderr, "C:-canon: %s\n", result);
+    free (cwd);
+  }
+#endif /* (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ */
+
   /* From here on out, tests involve symlinks.  */
   if (symlink (BASE "/ket", "ise") != 0)
     {
-- 
1.7.1

>From d5b578b84e638c1223de3b25f9614844206673c2 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <[email protected]>
Date: Fri, 4 Feb 2011 18:49:54 +0100
Subject: [PATCH 3/4] canonicalize-lgpl: Add an implementation for mingw to pass newly added tests.

2011-02-04  Jan Nieuwenhuizen  <[email protected]>

	* lib/canonicalize-lgpl.c (__realpath)[(_WIN32 || __WIN32__) && ! __CYGWIN__]:
	Add an implementation for mingw to pass newly added tests.
---
 ChangeLog               |    5 +++
 lib/canonicalize-lgpl.c |   85 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 87 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 24d1998..f984aa8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-02-04  Jan Nieuwenhuizen  <[email protected]>
 
+	* lib/canonicalize-lgpl.c (__realpath)[(_WIN32 || __WIN32__) && ! __CYGWIN__]:
+	Add an implementation for mingw to pass newly added tests.
+
+2011-02-04  Jan Nieuwenhuizen  <[email protected]>
+
 	* tests/test-canonicalize-lgpl.c (main)[(_WIN32 || __WIN32__) && ! __CYGWIN__]: 
 	Add basic sanity checks for mingw along with debug printing demonstrating
 	general breakage.
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 9bfb44f..4a58aa8 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -95,10 +95,42 @@
    that cannot be resolved.  If the path can be resolved, RESOLVED
    holds the same value as the value returned.  */
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#include <ctype.h>
+#include <direct.h>
+#include <windows.h>
+
+static char const *
+slashify (char const *str)
+{
+  char *p = (char*)str;
+  
+  while (*p)
+    {
+      if (*p == '\\')
+	*p = '/';
+      p++;
+    }
+  return str;
+}
+
+static char const *
+strlower (char const *str)
+{
+  char *p = (char*)str;
+  while (*p)
+    {
+      *p = (char)tolower (*p);
+      p++;
+    }
+  return str;
+}
+#endif /* (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ */
+
 char *
 __realpath (const char *name, char *resolved)
 {
-  char *rpath, *dest, *extra_buf = NULL;
+  char *fname, *rpath, *dest, *extra_buf = NULL, *sname = NULL;
   const char *start, *end, *rpath_limit;
   long int path_max;
   int num_links = 0;
@@ -144,6 +176,49 @@ __realpath (const char *name, char *resolved)
     rpath = resolved;
   rpath_limit = rpath + path_max;
 
+  fname = rpath;
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  {
+    sname = malloc (PATH_MAX);
+    if (sname == NULL)
+      goto error;
+    strcpy (sname, name);
+    name = strlower (slashify (sname));
+  }
+  if (name[1] && (name[1] != ':' || name[2] != '/'))
+    {
+      DWORD cwd_len;
+      char root[3] = ".";
+
+      if (name[0] == '/')
+	{
+	  root[0] = *name++;
+	  root[1] = '\0';
+	}
+      else if (name[1] == ':')
+	{
+	  root[0] = *name++;
+	  root[1] = *name++;
+	  root[2] = '\0';
+	}
+
+      cwd_len = GetFullPathName (root, PATH_MAX, fname, NULL);
+      if (!cwd_len)
+	goto error;
+      strlower (slashify (fname));
+      rpath = fname + cwd_len - 1;
+    }
+    else
+      {
+	strncpy (fname, name, 3);
+	name += 2;
+	rpath = fname + 3;
+      }
+  if (1)
+    dest = rpath + 1;
+  else
+#endif /* (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ */
   if (name[0] != '/')
     {
       if (!__getcwd (rpath, path_max))
@@ -241,7 +316,7 @@ __realpath (const char *name, char *resolved)
 #ifdef _LIBC
           if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
 #else
-          if (lstat (rpath, &st) < 0)
+          if (lstat (fname, &st) < 0)
 #endif
             goto error;
 
@@ -329,7 +404,7 @@ __realpath (const char *name, char *resolved)
   if (extra_buf)
     freea (extra_buf);
 
-  return rpath;
+  return fname;
 
 error:
   {
@@ -338,6 +413,10 @@ error:
       freea (extra_buf);
     if (resolved == NULL)
       free (rpath);
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+    if (sname != NULL)
+      free (sname);
+#endif /* (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ */
     errno = saved_errno;
   }
   return NULL;
-- 
1.7.1

>From b50261b20aa7425139f0ab5d8b29a418ad799662 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <[email protected]>
Date: Fri, 4 Feb 2011 18:51:20 +0100
Subject: [PATCH 4/4] canonicalize-lgpl: Remove debug printing.

2011-02-04  Jan Nieuwenhuizen  <[email protected]>

	* tests/test-canonicalize-lgpl.c (main): Remove debug printing.
---
 ChangeLog                      |    4 ++++
 tests/test-canonicalize-lgpl.c |    6 ------
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f984aa8..4251df4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-02-04  Jan Nieuwenhuizen  <[email protected]>
 
+	* tests/test-canonicalize-lgpl.c (main): Remove debug printing.
+
+2011-02-04  Jan Nieuwenhuizen  <[email protected]>
+
 	* lib/canonicalize-lgpl.c (__realpath)[(_WIN32 || __WIN32__) && ! __CYGWIN__]:
 	Add an implementation for mingw to pass newly added tests.
 
diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c
index 1e10af0..5652bc0 100644
--- a/tests/test-canonicalize-lgpl.c
+++ b/tests/test-canonicalize-lgpl.c
@@ -112,7 +112,6 @@ main (void)
 
     /* Check if BASE has a canonical name.  */
     result = canonicalize_file_name (BASE);
-    fprintf (stderr, "BASE-canon: %s\n", result);
     ASSERT (result != NULL);
 
     /* Check if BASE's canonical name is somewhat canonical.  */
@@ -121,22 +120,17 @@ main (void)
 
     /* Check if CWD has a canonical name.  */
     cwd = getcwd (NULL, 0);
-    fprintf (stderr, "CWD: %s\n", cwd);
     result = canonicalize_file_name (cwd);
-    fprintf (stderr, "CWD-canon: %s\n", result);
     ASSERT (result != NULL);
 
     /* Check basic drive letter sanity.  */
     test = "c:/";
     result = canonicalize_file_name (test);
     ASSERT (strcmp (result, test) == 0);
-    fprintf (stderr, "C:/-canon: %s\n", result);
     result = canonicalize_file_name ("C:\\");
     ASSERT (strcmp (result, test) == 0);
-    fprintf (stderr, "C:\\-canon: %s\n", result);
     result = canonicalize_file_name ("C:");
     ASSERT (strcmp (result, test) == 0);
-    fprintf (stderr, "C:-canon: %s\n", result);
     free (cwd);
   }
 #endif /* (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ */
-- 
1.7.1

Reply via email to