summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore_file/ecore_file.c
diff options
context:
space:
mode:
authordoursse <doursse>2007-09-09 11:05:02 +0000
committerdoursse <doursse@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2007-09-09 11:05:02 +0000
commit21339321e92297514f509c3b1064a89f18a411ce (patch)
tree4a2bf223db4fdafa4964830aa80b974375b691b6 /legacy/ecore/src/lib/ecore_file/ecore_file.c
parenta22ebcafac691bc328ffad72bdeba18226ecfc80 (diff)
add a readlink equivalent for Windows
SVN revision: 31663
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore_file/ecore_file.c69
1 files changed, 58 insertions, 11 deletions
diff --git a/legacy/ecore/src/lib/ecore_file/ecore_file.c b/legacy/ecore/src/lib/ecore_file/ecore_file.c
index 2c7655e6a9..d9997ce327 100644
--- a/legacy/ecore/src/lib/ecore_file/ecore_file.c
+++ b/legacy/ecore/src/lib/ecore_file/ecore_file.c
@@ -26,7 +26,7 @@ static int init = 0;
26/* Nevertheless, it can creates .lnk files */ 26/* Nevertheless, it can creates .lnk files */
27#ifdef _WIN32 27#ifdef _WIN32
28static int 28static int
29symlink (const char *oldpath, const char *newpath) 29symlink(const char *oldpath, const char *newpath)
30{ 30{
31 IShellLink *pISL; 31 IShellLink *pISL;
32 IShellLink **shell_link; 32 IShellLink **shell_link;
@@ -35,10 +35,10 @@ symlink (const char *oldpath, const char *newpath)
35 wchar_t new_path[MB_CUR_MAX]; 35 wchar_t new_path[MB_CUR_MAX];
36 36
37 /* Hack to cleanly remove a warning */ 37 /* Hack to cleanly remove a warning */
38 shell_link = &pISL;
39 if (FAILED(CoInitialize(NULL))) 38 if (FAILED(CoInitialize(NULL)))
40 return -1; 39 return -1;
41 40
41 shell_link = &pISL;
42 if (FAILED(CoCreateInstance(&CLSID_ShellLink, 42 if (FAILED(CoCreateInstance(&CLSID_ShellLink,
43 NULL, 43 NULL,
44 CLSCTX_INPROC_SERVER, 44 CLSCTX_INPROC_SERVER,
@@ -73,6 +73,62 @@ symlink (const char *oldpath, const char *newpath)
73 CoUninitialize(); 73 CoUninitialize();
74 return -1; 74 return -1;
75} 75}
76
77static int
78readlink(const char *path, char *buf, size_t bufsiz)
79{
80 IShellLink *pISL;
81 IShellLink **shell_link;
82 IPersistFile *pIPF;
83 IPersistFile **persit_file;
84 wchar_t old_path[MB_CUR_MAX];
85 char new_path[MB_CUR_MAX];
86 int length;
87
88 /* Hack to cleanly remove a warning */
89 if (FAILED(CoInitialize(NULL)))
90 return -1;
91
92 persit_file = &pIPF;
93 if (FAILED(CoCreateInstance(&CLSID_ShellLink,
94 NULL,
95 CLSCTX_INPROC_SERVER,
96 &IID_IPersistFile,
97 (void **)persit_file)))
98 goto no_instance;
99
100 mbstowcs(old_path, path, MB_CUR_MAX);
101 if (FAILED(pIPF->lpVtbl->Load(pIPF, old_path, STGM_READWRITE)))
102 goto no_load;
103
104 shell_link = &pISL;
105 if (FAILED(pIPF->lpVtbl->QueryInterface(pIPF, &IID_IShellLink, (void **)shell_link)))
106 goto no_queryinterface;
107
108 if (FAILED(pISL->lpVtbl->GetPath(pISL, new_path, MB_CUR_MAX, NULL, 0)))
109 goto no_getpath;
110
111 length = strlen(new_path);
112 if (length > bufsiz)
113 length = bufsiz;
114
115 memcpy(buf, new_path, length);
116
117 pISL->lpVtbl->Release(pISL);
118 pIPF->lpVtbl->Release(pIPF);
119 CoUninitialize();
120
121 return length;
122
123 no_getpath:
124 pISL->lpVtbl->Release(pISL);
125 no_queryinterface:
126 no_load:
127 pIPF->lpVtbl->Release(pIPF);
128 no_instance:
129 CoUninitialize();
130 return -1;
131}
76#endif /* _WIN32 */ 132#endif /* _WIN32 */
77 133
78/* externally accessible functions */ 134/* externally accessible functions */
@@ -237,19 +293,14 @@ ecore_file_recursive_rm(const char *dir)
237 DIR *dirp; 293 DIR *dirp;
238 struct dirent *dp; 294 struct dirent *dp;
239 char path[PATH_MAX]; 295 char path[PATH_MAX];
240#ifndef _WIN32
241 char buf[PATH_MAX]; 296 char buf[PATH_MAX];
242#endif /* _WIN32 */
243 struct stat st; 297 struct stat st;
244 int ret; 298 int ret;
245 299
246 /* On Windows, no link */
247#ifndef _WIN32
248 if (readlink(dir, buf, sizeof(buf)) > 0) 300 if (readlink(dir, buf, sizeof(buf)) > 0)
249 { 301 {
250 return ecore_file_unlink(dir); 302 return ecore_file_unlink(dir);
251 } 303 }
252#endif /* _WIN32 */
253 304
254 ret = stat(dir, &st); 305 ret = stat(dir, &st);
255 if ((ret == 0) && (S_ISDIR(st.st_mode))) 306 if ((ret == 0) && (S_ISDIR(st.st_mode)))
@@ -506,16 +557,12 @@ ecore_file_can_exec(const char *file)
506EAPI char * 557EAPI char *
507ecore_file_readlink(const char *link) 558ecore_file_readlink(const char *link)
508{ 559{
509#ifndef _WIN32
510 char buf[PATH_MAX]; 560 char buf[PATH_MAX];
511 int count; 561 int count;
512 562
513 if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL; 563 if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL;
514 buf[count] = 0; 564 buf[count] = 0;
515 return strdup(buf); 565 return strdup(buf);
516#else
517 return NULL;
518#endif /* _WIN32 */
519} 566}
520 567
521/** 568/**