[Pkg-owncloud-commits] [owncloud-client] 258/498: Added function to change the filename to be longer than MAX_PATH

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:56 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 472eed7f209a315305b1b952f19e05eb8f87eccb
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Jun 19 12:56:54 2015 +0200

    Added function to change the filename to be longer than MAX_PATH
---
 csync/src/std/c_string.c | 59 ++++++++++++++++++++++++++++++++++++++++--------
 csync/src/std/c_string.h |  3 +++
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/csync/src/std/c_string.c b/csync/src/std/c_string.c
index d164ee7..8f690cc 100644
--- a/csync/src/std/c_string.c
+++ b/csync/src/std/c_string.c
@@ -274,13 +274,46 @@ char* c_utf8_from_locale(const mbchar_t *wstr)
   return dst;
 }
 
+ const char *makeLongWinPath(const char *str)
+{
+    int len = 0;
+    char *longStr = NULL;
+    int mem_reserved = 0;
+
+    len = strlen(str);
+    // prepend \\?\ and convert '/' => '\' to support long names
+    if( len > 2 ) {
+        int i = 4;
+        // reserve mem for a new string with the prefix
+        mem_reserved = len + 5;
+        longStr = c_malloc(mem_reserved);
+        *longStr = '\0';
+
+        strcpy( longStr, "\\\\?\\"); // prepend string by this four magic chars.
+        strcat( longStr, str );
+
+        while(longStr[i] != '\0') {
+            if(longStr[i] == '/') {
+                longStr[i] = '\\';
+            }
+            i++;
+        }
+        return longStr;
+    } else {
+        return str;
+    }
+}
+
+
 /* Convert a an UTF8 string to multibyte */
 mbchar_t* c_utf8_to_locale(const char *str)
 {
   mbchar_t *dst = NULL;
 #ifdef _WIN32
-  size_t len;
-  int size_needed;
+  size_t len = 0;
+  int size_needed = 0;
+  char *longStr = NULL;
+  int mem_reserved = 0;
 #endif
 
   if (str == NULL ) {
@@ -288,13 +321,21 @@ mbchar_t* c_utf8_to_locale(const char *str)
   }
 
 #ifdef _WIN32
-  len = strlen(str);
-  size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
-  if (size_needed > 0) {
-    int size_char = (size_needed + 1) * sizeof(mbchar_t);
-    dst = c_malloc(size_char);
-    memset((void*)dst, 0, size_char);
-    MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed);
+  longStr = makeLongWinPath(str);
+  if( longStr ) {
+      len = strlen(longStr);
+
+      size_needed = MultiByteToWideChar(CP_UTF8, 0, longStr, len, NULL, 0);
+      if (size_needed > 0) {
+          int size_char = (size_needed + 1) * sizeof(mbchar_t);
+          dst = c_malloc(size_char);
+          memset((void*)dst, 0, size_char);
+          MultiByteToWideChar(CP_UTF8, 0, longStr, -1, dst, size_needed);
+      }
+
+      if( mem_reserved > 0 ) { // FIXME!! free mem.
+          SAFE_FREE(longStr);
+      }
   }
 #else
 #ifdef WITH_ICONV
diff --git a/csync/src/std/c_string.h b/csync/src/std/c_string.h
index 920266c..d8de2e1 100644
--- a/csync/src/std/c_string.h
+++ b/csync/src/std/c_string.h
@@ -154,6 +154,9 @@ void c_strlist_destroy(c_strlist_t *strlist);
  */
  char*   c_utf8_from_locale(const mbchar_t *str);
 
+
+ const char *makeLongWinPath(const char *str);
+
 /**
  * @brief Convert a utf8 encoded string to platform specific locale.
  *

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list