Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaas Freitag <freitag@owncloud.com>2015-07-02 17:53:48 +0300
committerKlaas Freitag <freitag@owncloud.com>2015-07-08 19:13:39 +0300
commit5214189eb2d9382abd821bbab756ead9f39e1b1d (patch)
tree5629ce25918e727aa1603f806ef84e0929d3f8bd /csync/src/std/c_string.c
parent3aed7fc0beab805f20ea9dc288454a7574dc6b8f (diff)
Moved the makeWinLongPath function to c_path and rename to c_path_to_UNC
Other cleanups like streamlined allocation and more.
Diffstat (limited to 'csync/src/std/c_string.c')
-rw-r--r--csync/src/std/c_string.c65
1 files changed, 3 insertions, 62 deletions
diff --git a/csync/src/std/c_string.c b/csync/src/std/c_string.c
index 7015da65b..0da268cab 100644
--- a/csync/src/std/c_string.c
+++ b/csync/src/std/c_string.c
@@ -32,6 +32,7 @@
#include <wchar.h>
#include "c_string.h"
+#include "c_path.h"
#include "c_alloc.h"
#include "c_macro.h"
@@ -274,63 +275,6 @@ char* c_utf8_from_locale(const mbchar_t *wstr)
return dst;
}
-/*
- * This function takes a path and converts it to a UNC representation of the
- * string. That means that it prepends a \\?\ and convertes all slashes to
- * backslashes.
- *
- * Note the following:
- * - The string must be absolute.
- * - it needs to contain a drive character to be a valid UNC
- * - A conversion is only done if the path len is larger than 245. Otherwise
- * the windows API functions work with the normal "unixoid" representation too.
- *
- * Since the function reallocs memory that it can not free itself, the number of
- * newly allocated bytes are returned in parameter mem_reserved. The calling
- * function will call free on the result pointer if mem_reserved is > 0.
- *
- */
- const char *makeLongWinPath(const char *str, int *mem_reserved)
-{
- int len = 0;
- char *longStr = NULL;
-
- if( mem_reserved ) {
- *mem_reserved = 0;
- }
-
- len = strlen(str);
- // prepend \\?\ and convert '/' => '\' to support long names
- if( len > 245 ) { // Only do realloc for long pathes. Shorter pathes are fine.
- int i = 4;
- // reserve mem for a new string with the prefix
- if( mem_reserved ) {
- *mem_reserved = len + 5;
- }
- longStr = c_malloc(len+5);
- *longStr = '\0';
-
- if( str[0] == '/' ) {
- strcpy( longStr, "\\\\?");
- i=3;
- } else {
- strcpy( longStr, "\\\\?\\"); // prepend string by this four magic chars.
- }
- strcat( longStr, str );
-
- /* replace all occurences of / with the windows native \ */
- 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)
{
@@ -339,7 +283,6 @@ mbchar_t* c_utf8_to_locale(const char *str)
size_t len = 0;
int size_needed = 0;
const char *longStr = NULL;
- int mem_reserved = 0;
#endif
if (str == NULL ) {
@@ -347,7 +290,7 @@ mbchar_t* c_utf8_to_locale(const char *str)
}
#ifdef _WIN32
- longStr = makeLongWinPath(str, &mem_reserved);
+ longStr = c_path_to_UNC(str);
if( longStr ) {
len = strlen(longStr);
@@ -359,9 +302,7 @@ mbchar_t* c_utf8_to_locale(const char *str)
MultiByteToWideChar(CP_UTF8, 0, longStr, -1, dst, size_needed);
}
- if( mem_reserved > 0 ) { // Free mem reserved in hte makeLongWinPath function
- SAFE_FREE(longStr);
- }
+ SAFE_FREE(longStr);
}
#else
#ifdef WITH_ICONV