You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/02 20:10:17 UTC

svn commit: r810639 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_file.h os/unix/temps.c os/win32/temps.c

Author: mturk
Date: Wed Sep  2 18:10:17 2009
New Revision: 810639

URL: http://svn.apache.org/viewvc?rev=810639&view=rev
Log:
Make sure paths doesn't end with '/' or '\'

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=810639&r1=810638&r2=810639&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Wed Sep  2 18:10:17 2009
@@ -137,6 +137,21 @@
                                            file lock */
 /** @} */
 
+#define ACR_NO_END_SLASHA(P)                        \
+    if (*(P)) {                                     \
+        size_t _s = strlen((P)) - 1;                \
+        if ((P)[_s] == '/' || (P)[_s] == '\\')      \
+            (P)[_s] =  '\0';                        \
+    } else (void)0
+
+#define ACR_NO_END_SLASHW(P)                        \
+    if (*(P)) {                                     \
+        size_t _s = wcslen((P)) - 1;                \
+        if ((P)[_s] == L'/' || (P)[_s] == L'\\')    \
+            (P)[_s] =  L'\0';                       \
+    } else (void)0
+
+
 typedef struct acr_file_t acr_file_t;
 
 struct acr_file_t {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c?rev=810639&r1=810638&r2=810639&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/temps.c Wed Sep  2 18:10:17 2009
@@ -74,6 +74,7 @@
             ACR_THROW_IO_IF_ERR(ACR_E2BIG);
             return -1;
         }
+        ACR_NO_END_SLASHA(name);
         strlcat(name, "/",    PATH_MAX);
     }
     strlcat(name, prefix,   PATH_MAX);
@@ -132,6 +133,7 @@
                 ACR_THROW_IO_IF_ERR(ACR_E2BIG);
                 return NULL;
             }
+            ACR_NO_END_SLASHA(name);
             strlcat(name, "/", PATH_MAX);
         }
         strlcat(name, prefix, PATH_MAX);
@@ -169,6 +171,7 @@
     char  tp[PATH_MAX];
     int    f;
     strlcpy(tp, path, PATH_MAX);
+    ACR_NO_END_SLASHA(tp);
     strlcat(tp, "/.acrXXXXXX", PATH_MAX);
     f = mkstemp(tp);
     if (f > 0) {
@@ -200,6 +203,7 @@
         i++;
     }
     if (_temp_path[0]) {
+        ACR_NO_END_SLASHA(_temp_path);
         return _temp_path;
     }
     i = 0;
@@ -213,6 +217,7 @@
         i++;
     }
     if (_temp_path[0]) {
+        ACR_NO_END_SLASHA(_temp_path);
         return _temp_path;
     }
     else {
@@ -226,6 +231,7 @@
         }
     }
     if (_temp_path[0]) {
+        ACR_NO_END_SLASHA(_temp_path);
         return _temp_path;
     }
     else

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c?rev=810639&r1=810638&r2=810639&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c Wed Sep  2 18:10:17 2009
@@ -235,6 +235,7 @@
     HANDLE  fh;
 
     wcslcpy(tp, path, TMP_PATH_MAX);
+    ACR_NO_END_SLASHW(tp);
     wcslcat(tp, L"\\.acrXXXXXX", TMP_PATH_MAX);
     fh = getftemp(tp, FILE_ATTRIBUTE_NORMAL);
     if (IS_VALID_HANDLE(fh)) {
@@ -259,6 +260,7 @@
             ACR_THROW_IO_IF_ERR(ACR_E2BIG);
             return -1;
         }
+        ACR_NO_END_SLASHW(name);
         wcslcat(name, L"\\", ACR_MBUFF_SIZ);
     }
     wcslcat(name, prefix, ACR_MBUFF_SIZ);
@@ -303,6 +305,7 @@
             ACR_THROW_IO_IF_ERR(ACR_E2BIG);
             return NULL;
         }
+        ACR_NO_END_SLASHW(name);
         wcslcat(name, L"\\", ACR_MBUFF_SIZ);
     }
     wcslcat(name, prefix, ACR_MBUFF_SIZ);
@@ -341,6 +344,7 @@
         i++;
     }
     if (_temp_path[0]) {
+        ACR_NO_END_SLASHW(_temp_path);
         return _temp_path;
     }
     i = 0;
@@ -352,6 +356,7 @@
         i++;
     }
     if (_temp_path[0]) {
+        ACR_NO_END_SLASHW(_temp_path);
         return _temp_path;
     }
     else {
@@ -365,6 +370,7 @@
         }
     }
     if (_temp_path[0]) {
+        ACR_NO_END_SLASHW(_temp_path);
         return _temp_path;
     }
     else