apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r960665 - in /apr/apr/trunk: file_io/win32/filepath.c test/testnames.c
Date Mon, 05 Jul 2010 19:37:01 GMT
Author: gstein
Date: Mon Jul  5 19:37:01 2010
New Revision: 960665

URL: http://svn.apache.org/viewvc?rev=960665&view=rev
Log:
Remove assumption that drive letters are always uppercase.

* file_io/win32/filepath.c:
  (same_drive): new helper function
  (apr_filepath_merge): use helper rather than a simple comparison

* test/testnames.c:
  (merge_lowercasedrive): do some tests with lowercase drive names

Patch by: Bert Huijben <bert {at} qqmail.nl>

Modified:
    apr/apr/trunk/file_io/win32/filepath.c
    apr/apr/trunk/test/testnames.c

Modified: apr/apr/trunk/file_io/win32/filepath.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/filepath.c?rev=960665&r1=960664&r2=960665&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/filepath.c (original)
+++ apr/apr/trunk/file_io/win32/filepath.c Mon Jul  5 19:37:01 2010
@@ -327,6 +327,27 @@ APR_DECLARE(apr_status_t) apr_filepath_r
 #endif /* ndef(NETWARE) */
 }
 
+#if !defined(NETWARE)
+static int same_drive(const char *path1, const char *path2)
+{
+    char drive1 = path1[0];
+    char drive2 = path2[0];
+
+    if (!drive1 || !drive2 || path1[1] != ':' || path2[1] != ':')
+        return FALSE;
+
+    if (drive1 == drive2)
+        return TRUE;
+
+    if (drive1 >= 'a' && drive1 <= 'z')
+        drive1 += 'A' - 'a';
+
+    if (drive2 >= 'a' && drive2 <= 'z')
+        drive2 += 'A' - 'a';
+
+    return (drive1 == drive2);
+}
+#endif
 
 APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, 
                                              const char *basepath, 
@@ -540,7 +561,7 @@ APR_DECLARE(apr_status_t) apr_filepath_m
              * use the basepath _if_ it matches this drive letter!
              * Otherwise we must discard the basepath.
              */
-            if (addroot[0] == baseroot[0] && baseroot[1] == ':') {
+            if (same_drive(addroot, baseroot)) {
 #endif
                 /* Base the result path on the basepath
                  */

Modified: apr/apr/trunk/test/testnames.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testnames.c?rev=960665&r1=960664&r2=960665&view=diff
==============================================================================
--- apr/apr/trunk/test/testnames.c (original)
+++ apr/apr/trunk/test/testnames.c Mon Jul  5 19:37:01 2010
@@ -21,6 +21,11 @@
 #include "apr_general.h"
 #include "apr_pools.h"
 #include "apr_lib.h"
+#include "apr_strings.h"
+
+#if defined(WIN32)
+#include <direct.h>
+#endif
 
 #if defined(WIN32) || defined(OS2)
 #define ABS_ROOT "C:/"
@@ -175,6 +180,42 @@ static void merge_notabs(abts_case *tc, 
     ABTS_STR_EQUAL(tc, "foo/baz", dstpath);
 }
 
+#if defined (WIN32)
+static void merge_lowercasedrive(abts_case *tc, void *data)
+{
+  char current_dir[1024];
+  char current_dir_on_C[1024];
+  char *dir_on_c;
+  char *testdir;
+  apr_status_t rv;
+
+  /* Change the current directory on C: from something like "C:\dir"
+     to something like "c:\dir" to replicate the failing case. */
+  ABTS_PTR_NOTNULL(tc, _getcwd(current_dir, sizeof(current_dir)));
+
+   /* 3 stands for drive C: */
+  ABTS_PTR_NOTNULL(tc, _getdcwd(3, current_dir_on_C,
+	                            sizeof(current_dir_on_C)));
+
+  /* Use the same path, but now with a lower case driveletter */
+  dir_on_c = apr_pstrdup(p, current_dir_on_C);
+  dir_on_c[0] = (char)tolower(dir_on_c[0]);
+
+  chdir(dir_on_c);
+
+  /* Now merge a drive relative path with an upper case drive letter. */
+  rv = apr_filepath_merge(&testdir, NULL, "C:hi",
+                          APR_FILEPATH_NOTRELATIVE, p);
+
+  /* Change back to original directory for next tests */
+  chdir("C:\\"); /* Switch to upper case */
+  chdir(current_dir_on_C); /* Switch cwd on C: */
+  chdir(current_dir); /* Switch back to original cwd */
+
+  ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+#endif
+
 static void root_absolute(abts_case *tc, void *data)
 {
     apr_status_t rv;
@@ -294,6 +335,9 @@ abts_suite *testnames(abts_suite *suite)
     abts_run_test(suite, merge_notabs, NULL);
     abts_run_test(suite, merge_notabsfail, NULL);
     abts_run_test(suite, merge_dotdot_dotdot_dotdot, NULL);
+#if defined(WIN32)
+    abts_run_test(suite, merge_lowercasedrive, NULL);
+#endif
 
     abts_run_test(suite, root_absolute, NULL);
     abts_run_test(suite, root_relative, NULL);



Mime
View raw message