summaryrefslogtreecommitdiff
path: root/src/lib/evil
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@free.fr>2013-03-18 23:40:03 +0100
committerCedric BAIL <cedric.bail@samsung.com>2013-03-19 15:15:46 +0900
commit9e745d4a2c8080f56d79df49b1bdffe9e41f66b6 (patch)
treeb6ec99bce90069181301c9547a37d02eae6a74c1 /src/lib/evil
parentb6318788216cda81f13cbba8de3f2606bf90b1d0 (diff)
efl: add macro to swap Windows and Unix path separators.
Diffstat (limited to 'src/lib/evil')
-rw-r--r--src/lib/evil/dlfcn.c9
-rw-r--r--src/lib/evil/evil_dirent.c26
-rw-r--r--src/lib/evil/evil_libgen.c8
-rw-r--r--src/lib/evil/evil_stdio.c18
-rw-r--r--src/lib/evil/evil_stdio.h14
-rw-r--r--src/lib/evil/evil_unistd.c8
6 files changed, 30 insertions, 53 deletions
diff --git a/src/lib/evil/dlfcn.c b/src/lib/evil/dlfcn.c
index a877653ec6..823398c934 100644
--- a/src/lib/evil/dlfcn.c
+++ b/src/lib/evil/dlfcn.c
@@ -196,7 +196,6 @@ dladdr (const void *addr EVIL_UNUSED, Dl_info *info)
196 TCHAR tpath[PATH_MAX]; 196 TCHAR tpath[PATH_MAX];
197 MEMORY_BASIC_INFORMATION mbi; 197 MEMORY_BASIC_INFORMATION mbi;
198 char *path; 198 char *path;
199 char *tmp;
200 size_t length; 199 size_t length;
201 int ret = 0; 200 int ret = 0;
202 201
@@ -236,13 +235,7 @@ dladdr (const void *addr EVIL_UNUSED, Dl_info *info)
236 path[PATH_MAX - 1] = '\0'; 235 path[PATH_MAX - 1] = '\0';
237 } 236 }
238 237
239 /* replace '/' by '\' */ 238 EVIL_PATH_SEP_UNIX_TO_WIN32(path);
240 tmp = path;
241 while (*tmp)
242 {
243 if (*tmp == '/') *tmp = '\\';
244 tmp++;
245 }
246 239
247 memcpy (info->dli_fname, path, length + 1); 240 memcpy (info->dli_fname, path, length + 1);
248 info->dli_fbase = NULL; 241 info->dli_fbase = NULL;
diff --git a/src/lib/evil/evil_dirent.c b/src/lib/evil/evil_dirent.c
index 041899d53e..1a0b19b83b 100644
--- a/src/lib/evil/evil_dirent.c
+++ b/src/lib/evil/evil_dirent.c
@@ -19,8 +19,7 @@ struct DIR
19DIR *opendir(char const *name) 19DIR *opendir(char const *name)
20{ 20{
21 DIR *dir; 21 DIR *dir;
22 char *tmp1; 22 char *tmp;
23 char *tmp2;
24 DWORD attr; 23 DWORD attr;
25 size_t l; 24 size_t l;
26#ifdef UNICODE 25#ifdef UNICODE
@@ -71,39 +70,34 @@ DIR *opendir(char const *name)
71 } 70 }
72 71
73 l = strlen(name); 72 l = strlen(name);
74 tmp1 = (char *)malloc(sizeof(char) * l + 5); 73 tmp = (char *)malloc(sizeof(char) * l + 5);
75 if (!tmp1) 74 if (!tmp)
76 { 75 {
77 errno = ENOMEM; 76 errno = ENOMEM;
78 return NULL; 77 return NULL;
79 } 78 }
80 79
81 memcpy(tmp1, name, l); 80 memcpy(tmp, name, l);
82 memcpy(tmp1 + l, "\\*.*", 5); 81 memcpy(tmp + l, "\\*.*", 5);
83 82
84 tmp2 = tmp1; 83 EVIL_PATH_SEP_UNIX_TO_WIN32(tmp);
85 while (*tmp2)
86 {
87 if (*tmp2 == '/') *tmp2 = '\\';
88 tmp2++;
89 }
90 84
91#ifdef UNICODE 85#ifdef UNICODE
92 wname = evil_char_to_wchar(tmp1); 86 wname = evil_char_to_wchar(tmp);
93 if (!wname) 87 if (!wname)
94 { 88 {
95 errno = ENOMEM; 89 errno = ENOMEM;
96 free(tmp1); 90 free(tmp);
97 91
98 return NULL; 92 return NULL;
99 } 93 }
100 dir->handle = FindFirstFile(wname, &dir->data); 94 dir->handle = FindFirstFile(wname, &dir->data);
101 free(wname); 95 free(wname);
102#else 96#else
103 dir->handle = FindFirstFile(tmp1, &dir->data); 97 dir->handle = FindFirstFile(tmp, &dir->data);
104#endif 98#endif
105 99
106 free(tmp1); 100 free(tmp);
107 101
108 if (dir->handle == INVALID_HANDLE_VALUE) 102 if (dir->handle == INVALID_HANDLE_VALUE)
109 { 103 {
diff --git a/src/lib/evil/evil_libgen.c b/src/lib/evil/evil_libgen.c
index 7e98f74386..779193fe30 100644
--- a/src/lib/evil/evil_libgen.c
+++ b/src/lib/evil/evil_libgen.c
@@ -31,12 +31,8 @@ evil_basename(char *path)
31 memcpy(_evil_basename_buf, "C:\\", 4); 31 memcpy(_evil_basename_buf, "C:\\", 4);
32 return _evil_basename_buf; 32 return _evil_basename_buf;
33 } 33 }
34 p2 = p1; 34
35 while (*p2) 35 EVIL_PATH_SEP_UNIX_TO_WIN32(p1);
36 {
37 if (*p2 == '/') *p2 = '\\';
38 p2++;
39 }
40 36
41 /* remove trailing backslashes */ 37 /* remove trailing backslashes */
42 p2 = p1 + (length - 1); 38 p2 = p1 + (length - 1);
diff --git a/src/lib/evil/evil_stdio.c b/src/lib/evil/evil_stdio.c
index 1aa6f67537..231e5043d6 100644
--- a/src/lib/evil/evil_stdio.c
+++ b/src/lib/evil/evil_stdio.c
@@ -29,7 +29,6 @@ FILE *evil_fopen(const char *path, const char *mode)
29{ 29{
30 FILE *f; 30 FILE *f;
31 char *filename; 31 char *filename;
32 char *tmp;
33 32
34 if (!path || !*path) 33 if (!path || !*path)
35 return NULL; 34 return NULL;
@@ -56,13 +55,7 @@ FILE *evil_fopen(const char *path, const char *mode)
56 else 55 else
57 filename = _strdup(path); 56 filename = _strdup(path);
58 57
59 tmp = filename; 58 EVIL_PATH_SEP_UNIX_TO_WIN32(filename);
60 while (*tmp)
61 {
62 if (*tmp == '/')
63 *tmp = '\\';
64 tmp++;
65 }
66 59
67 printf ("fopen : %s\n", filename); 60 printf ("fopen : %s\n", filename);
68 61
@@ -108,7 +101,6 @@ FILE *evil_fopen_native(const char *path, const char *mode)
108{ 101{
109 HANDLE handle; 102 HANDLE handle;
110 char *filename; 103 char *filename;
111 char *tmp;
112 wchar_t *wfilename; 104 wchar_t *wfilename;
113 DWORD acs = GENERIC_READ; 105 DWORD acs = GENERIC_READ;
114 DWORD creation; 106 DWORD creation;
@@ -138,13 +130,7 @@ FILE *evil_fopen_native(const char *path, const char *mode)
138 else 130 else
139 filename = _strdup(path); 131 filename = _strdup(path);
140 132
141 tmp = filename; 133 EVIL_PATH_SEP_UNIX_TO_WIN32(filename);
142 while (*tmp)
143 {
144 if (*tmp == '/')
145 *tmp = '\\';
146 tmp++;
147 }
148 printf ("fopen native : %s\n", filename); 134 printf ("fopen native : %s\n", filename);
149 135
150 wfilename = evil_char_to_wchar(filename); 136 wfilename = evil_char_to_wchar(filename);
diff --git a/src/lib/evil/evil_stdio.h b/src/lib/evil/evil_stdio.h
index 2b831c4a86..0baf00f5b8 100644
--- a/src/lib/evil/evil_stdio.h
+++ b/src/lib/evil/evil_stdio.h
@@ -13,6 +13,20 @@
13 * @{ 13 * @{
14 */ 14 */
15 15
16#define EVIL_PATH_SEP_SWAP(p, s1, s2) \
17 do { \
18 char *_evil_path_tmp; \
19 _evil_path_tmp = p; \
20 while (*_evil_path_tmp) \
21 { \
22 if (*_evil_path_tmp == s1) \
23 *_evil_path_tmp = s2; \
24 _evil_path_tmp++; \
25 } \
26 } while (0)
27
28#define EVIL_PATH_SEP_WIN32_TO_UNIX(p) EVIL_PATH_SEP_SWAP(p, '\\', '/')
29#define EVIL_PATH_SEP_UNIX_TO_WIN32(p) EVIL_PATH_SEP_SWAP(p, '/', '\\')
16 30
17#ifdef _WIN32_WCE 31#ifdef _WIN32_WCE
18 32
diff --git a/src/lib/evil/evil_unistd.c b/src/lib/evil/evil_unistd.c
index 31c018a2f6..eb1c832094 100644
--- a/src/lib/evil/evil_unistd.c
+++ b/src/lib/evil/evil_unistd.c
@@ -169,7 +169,6 @@ evil_stat(const char *file_name, struct stat *st)
169 WIN32_FIND_DATA data; 169 WIN32_FIND_DATA data;
170 HANDLE handle; 170 HANDLE handle;
171 char *f; 171 char *f;
172 char *tmp;
173 wchar_t *file; 172 wchar_t *file;
174 int permission = 0; 173 int permission = 0;
175 174
@@ -180,12 +179,7 @@ evil_stat(const char *file_name, struct stat *st)
180 if (!f) 179 if (!f)
181 return -1; 180 return -1;
182 181
183 tmp = f; 182 EVIL_PATH_SEP_UNIX_TO_WIN32(f);
184 while (*tmp)
185 {
186 if (*tmp == '/') *tmp = '\\';
187 tmp++;
188 }
189 183
190 if (!strcmp(file_name, "\\")) 184 if (!strcmp(file_name, "\\"))
191 { 185 {