summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-08-23 08:25:53 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-08-23 08:25:53 +0000
commit6465d76c38cb27136cce78f37d36b8ec2e72e0ed (patch)
treed7888829219f5092270ffe8f77ef314ab4e73c05
parentb2209d19ac0c409f426693e703fa48d9025660cf (diff)
eina_file : fix functions to behave with paths containing '/' or '\' on Windows
SVN revision: 75604
-rw-r--r--src/lib/eina_file_win32.c89
1 files changed, 45 insertions, 44 deletions
diff --git a/src/lib/eina_file_win32.c b/src/lib/eina_file_win32.c
index af547fa..c010963 100644
--- a/src/lib/eina_file_win32.c
+++ b/src/lib/eina_file_win32.c
@@ -172,19 +172,6 @@ static Eina_Lock _eina_file_lock_cache;
172 172
173static int _eina_file_log_dom = -1; 173static int _eina_file_log_dom = -1;
174 174
175static void
176_eina_file_win32_backslash_change(char *dir)
177{
178 char *tmp;
179
180 tmp = dir;
181 while (*tmp)
182 {
183 if (*tmp == '/') *tmp = '\\';
184 tmp++;
185 }
186}
187
188static Eina_Bool 175static Eina_Bool
189_eina_file_win32_is_dir(const char *dir) 176_eina_file_win32_is_dir(const char *dir)
190{ 177{
@@ -228,7 +215,6 @@ _eina_file_win32_dir_new(const char *dir)
228 215
229 memcpy(new_dir, dir, length); 216 memcpy(new_dir, dir, length);
230 memcpy(new_dir + length, "\\*.*", 5); 217 memcpy(new_dir + length, "\\*.*", 5);
231 _eina_file_win32_backslash_change(new_dir);
232 218
233 return new_dir; 219 return new_dir;
234} 220}
@@ -507,11 +493,24 @@ _eina_file_map_key_hash(const unsigned long int *key, int key_length __UNUSED__)
507static char * 493static char *
508_eina_file_win32_escape(const char *path, size_t *length) 494_eina_file_win32_escape(const char *path, size_t *length)
509{ 495{
510 char *result = strdup(path ? path : ""); 496 char *result;
511 char *p = result; 497 char *p;
512 char *q = result; 498 char *q;
513 size_t len; 499 size_t len;
514 500
501 result = strdup(path ? path : "");
502 if (!result)
503 return NULL;
504
505 p = result;
506 while (*p)
507 {
508 if (*p == '\\') *p = '/';
509 p++;
510 }
511 p = result;
512 q = result;
513
515 if (!result) 514 if (!result)
516 return NULL; 515 return NULL;
517 516
@@ -521,7 +520,7 @@ _eina_file_win32_escape(const char *path, size_t *length)
521 while ((p = strchr(p, '/'))) 520 while ((p = strchr(p, '/')))
522 { 521 {
523 // remove double `/' 522 // remove double `/'
524 if (p[1] == '/') 523 if (p[1] == '/')
525 { 524 {
526 memmove(p, p + 1, --len - (p - result)); 525 memmove(p, p + 1, --len - (p - result));
527 result[len] = '\0'; 526 result[len] = '\0';
@@ -730,7 +729,6 @@ eina_file_path_sanitize(const char *path)
730 if (!path) return NULL; 729 if (!path) return NULL;
731 730
732 len = strlen(path); 731 len = strlen(path);
733 if (len < 3) return NULL;
734 732
735 if (!evil_path_is_absolute(path)) 733 if (!evil_path_is_absolute(path))
736 { 734 {
@@ -740,20 +738,15 @@ eina_file_path_sanitize(const char *path)
740 if (l > 0) 738 if (l > 0)
741 { 739 {
742 char *cwd; 740 char *cwd;
743 DWORD l2; 741 char *tmp;
744 742
745 cwd = alloca(sizeof(char) * (l + 1)); 743 cwd = alloca(sizeof(char) * (l + 1));
746 l2 = GetCurrentDirectory(l + 1, cwd); 744 GetCurrentDirectory(l + 1, cwd);
747 if (l2 == l) 745 len += l + 2;
748 { 746 tmp = alloca(sizeof (char) * len);
749 char *tmp; 747 snprintf(tmp, len, "%s\\%s", cwd, path);
750 748 tmp[len - 1] = '\0';
751 len += l + 2; 749 result = tmp;
752 tmp = alloca(sizeof (char) * len);
753 snprintf(tmp, len, "%s/%s", cwd, path);
754 tmp[len - 1] = '\0';
755 result = tmp;
756 }
757 } 750 }
758 } 751 }
759 752
@@ -839,17 +832,28 @@ eina_file_split(char *path)
839 if (!ea) 832 if (!ea)
840 return NULL; 833 return NULL;
841 834
842 for (current = strchr(path, '\\'); 835 current = path;
843 current; 836 while (*current)
844 path = current + 1, current = strchr(path, '\\'))
845 { 837 {
846 length = current - path; 838 if ((*current == '\\') || (*current == '/'))
839 {
840 if (((*current == '\\') && (current[1] == '\\')) ||
841 ((*current == '/') && (current[1] == '/')))
842 {
843 *current = '\0';
844 goto next_char;
845 }
847 846
848 if (length <= 0) 847 length = current - path;
849 continue; 848 if (length <= 0)
849 goto next_char;
850 850
851 eina_array_push(ea, path); 851 eina_array_push(ea, path);
852 *current = '\0'; 852 *current = '\0';
853 path = current + 1;
854 }
855 next_char:
856 current++;
853 } 857 }
854 858
855 if (*path != '\0') 859 if (*path != '\0')
@@ -891,11 +895,10 @@ eina_file_ls(const char *dir)
891 goto free_it; 895 goto free_it;
892 896
893 memcpy(it->dir, dir, length + 1); 897 memcpy(it->dir, dir, length + 1);
894 if (dir[length - 1] != '\\') 898 if ((dir[length - 1] != '\\') && (dir[length - 1] != '/'))
895 it->length = length; 899 it->length = length;
896 else 900 else
897 it->length = length - 1; 901 it->length = length - 1;
898 _eina_file_win32_backslash_change(it->dir);
899 902
900 it->iterator.version = EINA_ITERATOR_VERSION; 903 it->iterator.version = EINA_ITERATOR_VERSION;
901 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_file_win32_ls_iterator_next); 904 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_file_win32_ls_iterator_next);
@@ -944,17 +947,15 @@ eina_file_direct_ls(const char *dir)
944 947
945 memcpy(it->dir, dir, length + 1); 948 memcpy(it->dir, dir, length + 1);
946 it->length = length; 949 it->length = length;
947 _eina_file_win32_backslash_change(it->dir);
948 950
949 memcpy(it->info.path, dir, length); 951 memcpy(it->info.path, dir, length);
950 if (dir[length - 1] == '\\') 952 if ((dir[length - 1] == '\\') || (dir[length - 1] == '/'))
951 it->info.name_start = length; 953 it->info.name_start = length;
952 else 954 else
953 { 955 {
954 it->info.path[length] = '\\'; 956 it->info.path[length] = '\\';
955 it->info.name_start = length + 1; 957 it->info.name_start = length + 1;
956 } 958 }
957 _eina_file_win32_backslash_change(it->info.path);
958 959
959 it->iterator.version = EINA_ITERATOR_VERSION; 960 it->iterator.version = EINA_ITERATOR_VERSION;
960 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_file_win32_direct_ls_iterator_next); 961 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_file_win32_direct_ls_iterator_next);