forked from enlightenment/efl
* src/bin/evil_test_gettimeofday.c:
add output * src/bin/evil_test_link.c: add a unit test for readlink() * src/lib/evil_link_xp.cpp: fix readlink() and symlink() on Windows XP SVN revision: 38070
This commit is contained in:
parent
dd4a299895
commit
26d595d0d8
|
@ -1,3 +1,14 @@
|
||||||
|
2008-12-09 Vincent Torri <doursse at users dot sf dot net>
|
||||||
|
|
||||||
|
* src/bin/evil_test_gettimeofday.c:
|
||||||
|
add output
|
||||||
|
|
||||||
|
* src/bin/evil_test_link.c:
|
||||||
|
add a unit test for readlink()
|
||||||
|
|
||||||
|
* src/lib/evil_link_xp.cpp:
|
||||||
|
fix readlink() and symlink() on Windows XP
|
||||||
|
|
||||||
2008-12-05 Vincent Torri <doursse at users dot sf dot net>
|
2008-12-05 Vincent Torri <doursse at users dot sf dot net>
|
||||||
|
|
||||||
* src/lib/evil_main.c:
|
* src/lib/evil_main.c:
|
||||||
|
|
|
@ -25,6 +25,7 @@ test_time_tests_run(suite *s)
|
||||||
|
|
||||||
printf ("time : %ld %ld\n", tp1.tv_sec, tp1.tv_usec);
|
printf ("time : %ld %ld\n", tp1.tv_sec, tp1.tv_usec);
|
||||||
printf ("time : %ld %ld\n", tp2.tv_sec, tp2.tv_usec);
|
printf ("time : %ld %ld\n", tp2.tv_sec, tp2.tv_usec);
|
||||||
|
printf ("time : %f\n", (double)tp2.tv_sec - tp1.tv_sec + (tp2.tv_usec - tp1.tv_usec) / 1000000.0);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,90 @@ test_link_test_file_create(const char *name, const char *data)
|
||||||
static int
|
static int
|
||||||
test_link_test_symlink(void)
|
test_link_test_symlink(void)
|
||||||
{
|
{
|
||||||
int res;
|
|
||||||
|
|
||||||
if (!test_link_test_file_create("evil_test_link.dat",
|
if (!test_link_test_file_create("evil_test_link.dat",
|
||||||
"evil_test_link symlink data\n"))
|
"evil_test_link symlink data\n"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (symlink("evil_test_link.dat", "evil_test_link") < 0)
|
if (symlink("evil_test_link.dat", "evil_test_link.lnk") < 0)
|
||||||
|
{
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlink("evil_test_link.lnk") < 0)
|
||||||
|
{
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlink("evil_test_link.dat") < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
test_link_test_readlink(void)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
char *data;
|
||||||
|
FILE *f;
|
||||||
|
ssize_t s1;
|
||||||
|
size_t s2;
|
||||||
|
int l;
|
||||||
|
|
||||||
|
data = "evil_test_link symlink data\n";
|
||||||
|
|
||||||
|
if (!test_link_test_file_create("evil_test_link.dat", data))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (symlink("evil_test_link.dat", "evil_test_link.lnk") < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ((s1 = readlink("evil_test_link.lnk", buf, 1023)) < 0)
|
||||||
|
{
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
unlink("evil_test_link.lnk");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[s1] = '\0';
|
||||||
|
|
||||||
|
f = fopen(buf, "rb");
|
||||||
|
if (!f)
|
||||||
|
{
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
unlink("evil_test_link.lnk");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
l = strlen(data);
|
||||||
|
s2 = fread(buf, 1, l + 1, f);
|
||||||
|
|
||||||
|
if ((int)s2 != (l + 1))
|
||||||
|
{
|
||||||
|
fclose(f);
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
unlink("evil_test_link.lnk");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(buf, data))
|
||||||
|
{
|
||||||
|
fclose(f);
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
unlink("evil_test_link.lnk");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (unlink("evil_test_link.lnk") < 0)
|
||||||
|
{
|
||||||
|
unlink("evil_test_link.dat");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (unlink("evil_test_link.dat") < 0)
|
if (unlink("evil_test_link.dat") < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -56,7 +131,12 @@ test_link_test_symlink(void)
|
||||||
static int
|
static int
|
||||||
test_link_tests_run(suite *s)
|
test_link_tests_run(suite *s)
|
||||||
{
|
{
|
||||||
return test_link_test_symlink();
|
int res;
|
||||||
|
|
||||||
|
res = test_link_test_symlink();
|
||||||
|
res &= test_link_test_readlink();
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
# include <shlobj.h>
|
# include <shlobj.h>
|
||||||
# include <objidl.h>
|
# include <objidl.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include "Evil.h"
|
#include "Evil.h"
|
||||||
|
|
||||||
|
@ -24,12 +25,11 @@
|
||||||
int
|
int
|
||||||
symlink(const char *oldpath, const char *newpath)
|
symlink(const char *oldpath, const char *newpath)
|
||||||
{
|
{
|
||||||
wchar_t new_path[MB_CUR_MAX];
|
wchar_t *wnewpath;
|
||||||
IShellLink *pISL;
|
IShellLink *pISL;
|
||||||
IShellLink **shell_link;
|
IPersistFile *pIPF;
|
||||||
IPersistFile *pIPF;
|
HRESULT res;
|
||||||
IPersistFile **persit_file;
|
size_t size;
|
||||||
HRESULT res;
|
|
||||||
|
|
||||||
res = CoInitialize(NULL);
|
res = CoInitialize(NULL);
|
||||||
if (FAILED(res))
|
if (FAILED(res))
|
||||||
|
@ -39,27 +39,29 @@ symlink(const char *oldpath, const char *newpath)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hack to cleanly remove a warning */
|
|
||||||
shell_link = &pISL;
|
|
||||||
if (FAILED(CoCreateInstance(CLSID_ShellLink,
|
if (FAILED(CoCreateInstance(CLSID_ShellLink,
|
||||||
NULL,
|
NULL,
|
||||||
CLSCTX_INPROC_SERVER,
|
CLSCTX_INPROC_SERVER,
|
||||||
IID_IShellLink,
|
IID_IShellLink,
|
||||||
(void **)shell_link)))
|
(void **)&pISL)))
|
||||||
goto no_instance;
|
goto no_instance;
|
||||||
|
|
||||||
if (FAILED(pISL->SetPath(oldpath)))
|
if (FAILED(pISL->SetPath(oldpath)))
|
||||||
goto no_setpath;
|
goto no_setpath;
|
||||||
|
|
||||||
/* Hack to cleanly remove a warning */
|
if (FAILED(pISL->QueryInterface(IID_IPersistFile, (void **)&pIPF)))
|
||||||
persit_file = &pIPF;
|
|
||||||
if (FAILED(pISL->QueryInterface(IID_IPersistFile, (void **)persit_file)))
|
|
||||||
goto no_queryinterface;
|
goto no_queryinterface;
|
||||||
|
|
||||||
mbstowcs(new_path, newpath, MB_CUR_MAX);
|
size = mbstowcs(NULL, newpath, 0);
|
||||||
if (FAILED(pIPF->Save(new_path, FALSE)))
|
wnewpath = (wchar_t *)malloc((size + 1) * sizeof(wchar_t));
|
||||||
|
if (!wnewpath)
|
||||||
|
goto malloc_failure;
|
||||||
|
if (mbstowcs(wnewpath, newpath, size + 1) == (size_t)(-1))
|
||||||
|
goto translation_failure;
|
||||||
|
if (FAILED(pIPF->Save(wnewpath, FALSE)))
|
||||||
goto no_save;
|
goto no_save;
|
||||||
|
|
||||||
|
free(wnewpath);
|
||||||
pIPF->Release();
|
pIPF->Release();
|
||||||
pISL->Release();
|
pISL->Release();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
@ -67,6 +69,8 @@ symlink(const char *oldpath, const char *newpath)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_save:
|
no_save:
|
||||||
|
translation_failure:
|
||||||
|
malloc_failure:
|
||||||
pIPF->Release();
|
pIPF->Release();
|
||||||
no_queryinterface:
|
no_queryinterface:
|
||||||
no_setpath:
|
no_setpath:
|
||||||
|
@ -79,14 +83,13 @@ symlink(const char *oldpath, const char *newpath)
|
||||||
ssize_t
|
ssize_t
|
||||||
readlink(const char *path, char *buf, size_t bufsiz)
|
readlink(const char *path, char *buf, size_t bufsiz)
|
||||||
{
|
{
|
||||||
wchar_t old_path[MB_CUR_MAX];
|
wchar_t *wpath;
|
||||||
char new_path[PATH_MAX];
|
char new_path[PATH_MAX];
|
||||||
IShellLink *pISL;
|
IShellLink *pISL;
|
||||||
IShellLink **shell_link;
|
IPersistFile *pIPF;
|
||||||
IPersistFile *pIPF;
|
unsigned int length;
|
||||||
IPersistFile **persit_file;
|
HRESULT res;
|
||||||
unsigned int length;
|
size_t size;
|
||||||
HRESULT res;
|
|
||||||
|
|
||||||
res = CoInitialize(NULL);
|
res = CoInitialize(NULL);
|
||||||
if (FAILED(res))
|
if (FAILED(res))
|
||||||
|
@ -96,25 +99,30 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hack to cleanly remove a warning */
|
|
||||||
persit_file = &pIPF;
|
|
||||||
if (FAILED(CoCreateInstance(CLSID_ShellLink,
|
if (FAILED(CoCreateInstance(CLSID_ShellLink,
|
||||||
NULL,
|
NULL,
|
||||||
CLSCTX_INPROC_SERVER,
|
CLSCTX_INPROC_SERVER,
|
||||||
IID_IPersistFile,
|
IID_IShellLink,
|
||||||
(void **)persit_file)))
|
(void **)&pISL)))
|
||||||
goto no_instance;
|
goto couninitialize;
|
||||||
|
|
||||||
mbstowcs(old_path, path, MB_CUR_MAX);
|
if (FAILED(pISL->QueryInterface(IID_IPersistFile, (void **)&pIPF)))
|
||||||
if (FAILED(pIPF->Load(old_path, STGM_READWRITE)))
|
goto release_shell_link;
|
||||||
goto no_load;
|
|
||||||
|
|
||||||
shell_link = &pISL;
|
size = mbstowcs(NULL, path, 0);
|
||||||
if (FAILED(pIPF->QueryInterface(IID_IShellLink, (void **)shell_link)))
|
wpath = (wchar_t *)malloc((size + 1) * sizeof(wchar_t));
|
||||||
goto no_queryinterface;
|
if (!wpath)
|
||||||
|
goto release_persist_file;
|
||||||
|
|
||||||
|
mbstowcs(wpath, path, size + 1);
|
||||||
|
if (FAILED(pIPF->Load(wpath, STGM_READ)))
|
||||||
|
goto free_wpath;
|
||||||
|
|
||||||
|
if (FAILED(pISL->Resolve(NULL, SLR_UPDATE | SLR_NO_UI)))
|
||||||
|
goto free_wpath;
|
||||||
|
|
||||||
if (FAILED(pISL->GetPath(new_path, PATH_MAX, NULL, 0)))
|
if (FAILED(pISL->GetPath(new_path, PATH_MAX, NULL, 0)))
|
||||||
goto no_getpath;
|
goto free_wpath;
|
||||||
|
|
||||||
length = strlen(new_path);
|
length = strlen(new_path);
|
||||||
if (length > bufsiz)
|
if (length > bufsiz)
|
||||||
|
@ -122,18 +130,20 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
||||||
|
|
||||||
memcpy(buf, new_path, length);
|
memcpy(buf, new_path, length);
|
||||||
|
|
||||||
|
free(wpath);
|
||||||
pISL->Release();
|
pISL->Release();
|
||||||
pIPF->Release();
|
pIPF->Release();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
|
|
||||||
no_getpath:
|
free_wpath:
|
||||||
pISL->Release();
|
free(wpath);
|
||||||
no_queryinterface:
|
release_persist_file:
|
||||||
no_load:
|
|
||||||
pIPF->Release();
|
pIPF->Release();
|
||||||
no_instance:
|
release_shell_link:
|
||||||
|
pISL->Release();
|
||||||
|
couninitialize:
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue