forked from enlightenment/efl
add a readlink equivalent for Windows
SVN revision: 31663
This commit is contained in:
parent
a22ebcafac
commit
21339321e9
|
@ -35,10 +35,10 @@ symlink (const char *oldpath, const char *newpath)
|
|||
wchar_t new_path[MB_CUR_MAX];
|
||||
|
||||
/* Hack to cleanly remove a warning */
|
||||
shell_link = &pISL;
|
||||
if (FAILED(CoInitialize(NULL)))
|
||||
return -1;
|
||||
|
||||
shell_link = &pISL;
|
||||
if (FAILED(CoCreateInstance(&CLSID_ShellLink,
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
|
@ -73,6 +73,62 @@ symlink (const char *oldpath, const char *newpath)
|
|||
CoUninitialize();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
readlink(const char *path, char *buf, size_t bufsiz)
|
||||
{
|
||||
IShellLink *pISL;
|
||||
IShellLink **shell_link;
|
||||
IPersistFile *pIPF;
|
||||
IPersistFile **persit_file;
|
||||
wchar_t old_path[MB_CUR_MAX];
|
||||
char new_path[MB_CUR_MAX];
|
||||
int length;
|
||||
|
||||
/* Hack to cleanly remove a warning */
|
||||
if (FAILED(CoInitialize(NULL)))
|
||||
return -1;
|
||||
|
||||
persit_file = &pIPF;
|
||||
if (FAILED(CoCreateInstance(&CLSID_ShellLink,
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
&IID_IPersistFile,
|
||||
(void **)persit_file)))
|
||||
goto no_instance;
|
||||
|
||||
mbstowcs(old_path, path, MB_CUR_MAX);
|
||||
if (FAILED(pIPF->lpVtbl->Load(pIPF, old_path, STGM_READWRITE)))
|
||||
goto no_load;
|
||||
|
||||
shell_link = &pISL;
|
||||
if (FAILED(pIPF->lpVtbl->QueryInterface(pIPF, &IID_IShellLink, (void **)shell_link)))
|
||||
goto no_queryinterface;
|
||||
|
||||
if (FAILED(pISL->lpVtbl->GetPath(pISL, new_path, MB_CUR_MAX, NULL, 0)))
|
||||
goto no_getpath;
|
||||
|
||||
length = strlen(new_path);
|
||||
if (length > bufsiz)
|
||||
length = bufsiz;
|
||||
|
||||
memcpy(buf, new_path, length);
|
||||
|
||||
pISL->lpVtbl->Release(pISL);
|
||||
pIPF->lpVtbl->Release(pIPF);
|
||||
CoUninitialize();
|
||||
|
||||
return length;
|
||||
|
||||
no_getpath:
|
||||
pISL->lpVtbl->Release(pISL);
|
||||
no_queryinterface:
|
||||
no_load:
|
||||
pIPF->lpVtbl->Release(pIPF);
|
||||
no_instance:
|
||||
CoUninitialize();
|
||||
return -1;
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* externally accessible functions */
|
||||
|
@ -237,19 +293,14 @@ ecore_file_recursive_rm(const char *dir)
|
|||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char path[PATH_MAX];
|
||||
#ifndef _WIN32
|
||||
char buf[PATH_MAX];
|
||||
#endif /* _WIN32 */
|
||||
struct stat st;
|
||||
int ret;
|
||||
|
||||
/* On Windows, no link */
|
||||
#ifndef _WIN32
|
||||
if (readlink(dir, buf, sizeof(buf)) > 0)
|
||||
{
|
||||
return ecore_file_unlink(dir);
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
ret = stat(dir, &st);
|
||||
if ((ret == 0) && (S_ISDIR(st.st_mode)))
|
||||
|
@ -506,16 +557,12 @@ ecore_file_can_exec(const char *file)
|
|||
EAPI char *
|
||||
ecore_file_readlink(const char *link)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
char buf[PATH_MAX];
|
||||
int count;
|
||||
|
||||
if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL;
|
||||
buf[count] = 0;
|
||||
return strdup(buf);
|
||||
#else
|
||||
return NULL;
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue