diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog index fddc9c68c3..2aa474f871 100644 --- a/legacy/evil/ChangeLog +++ b/legacy/evil/ChangeLog @@ -1,3 +1,32 @@ +2009-01-19 Vincent Torri + + * src/bin/Makefile.am: + * src/bin/evil_suite.c: + * src/bin/evil_test_dlfcn.c: + * src/bin/evil_test_dlfcn.h: + * src/bin/evil_test_environment.c: + * src/bin/evil_test_environment.h: + * src/bin/evil_test_gettimeofday.c: + * src/bin/evil_test_gettimeofday.h: + * src/bin/evil_test_link.c: + * src/bin/evil_test_link.h: + * src/bin/evil_test_mkstemp.c: + * src/bin/evil_test_mkstemp.h: + * src/bin/evil_test_realpath.c: + * src/bin/evil_test_realpath.h: + various fixes in the test suite. + add mkstemp() and realpath tests. + + * src/lib/evil_dirent.c: + fix opendir() when indexation search is not active. + formatting. + + * src/lib/evil_stdlib.c: + fir mkstemp() on both platform + + * src/lib/evil_unistd.c: + remove useless error message. + 2009-01-12 Vincent Torri * src/lib/evil_dirent.c: diff --git a/legacy/evil/src/bin/Makefile.am b/legacy/evil/src/bin/Makefile.am index 872a4a91c8..ac9bb5797a 100644 --- a/legacy/evil/src/bin/Makefile.am +++ b/legacy/evil/src/bin/Makefile.am @@ -18,7 +18,9 @@ evil_test_dlfcn.c \ evil_test_environment.c \ evil_test_gettimeofday.c \ evil_test_link.c \ -evil_test_memcpy.c +evil_test_memcpy.c \ +evil_test_mkstemp.c \ +evil_test_realpath.c if EVIL_HAVE_WINCE @@ -46,4 +48,6 @@ evil_suite.h \ evil_test_dlfcn.h \ evil_test_environment.h \ evil_test_link.h \ -evil_test_memcpy.h +evil_test_memcpy.h \ +evil_test_mkstemp.h \ +evil_test_realpath.h diff --git a/legacy/evil/src/bin/evil_suite.c b/legacy/evil/src/bin/evil_suite.c index 9221a138b7..f9e62e05ac 100644 --- a/legacy/evil/src/bin/evil_suite.c +++ b/legacy/evil/src/bin/evil_suite.c @@ -12,6 +12,8 @@ #include "evil_test_gettimeofday.h" #include "evil_test_link.h" #include "evil_test_memcpy.h" +#include "evil_test_mkstemp.h" +#include "evil_test_realpath.h" typedef int(*function)(suite *s); @@ -171,10 +173,12 @@ int main() { test tests[] = { - { "dlfcn ", test_environment }, + { "dlfcn ", test_dlfcn }, { "environment ", test_environment }, { "gettimeofday", test_gettimeofday }, { "link ", test_link }, + { "mkstemp ", test_mkstemp }, + { "realpath ", test_realpath }, /* { "memcpy ", test_memcpy }, */ { NULL, NULL }, }; @@ -193,7 +197,6 @@ main() for (i = 0; tests[i].name; ++i) { - suite_test_add(s, tests[i].name, tests[i].fct); } diff --git a/legacy/evil/src/bin/evil_test_dlfcn.c b/legacy/evil/src/bin/evil_test_dlfcn.c index d1a4075b68..b0551e1dc4 100644 --- a/legacy/evil/src/bin/evil_test_dlfcn.c +++ b/legacy/evil/src/bin/evil_test_dlfcn.c @@ -2,7 +2,6 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ -#include #include #include @@ -22,7 +21,7 @@ test_dlfcn_test_dlopen() if (!handle) return 0; - if (!dlclose(handle)) + if (dlclose(handle)) return 0; return 1; @@ -53,7 +52,7 @@ test_dlfcn_test_dlsym() return 0; } - if (!dlclose(handle)) + if (dlclose(handle)) return 0; return 1; @@ -64,7 +63,7 @@ test_dlfcn_tests_run(suite *s) { int res; - res = test_dlfcn_test_dlopen(); + res = test_dlfcn_test_dlopen(); res &= test_dlfcn_test_dlsym(); return res; diff --git a/legacy/evil/src/bin/evil_test_dlfcn.h b/legacy/evil/src/bin/evil_test_dlfcn.h index 315f4446dc..0c9bce689e 100644 --- a/legacy/evil/src/bin/evil_test_dlfcn.h +++ b/legacy/evil/src/bin/evil_test_dlfcn.h @@ -1,8 +1,8 @@ -#ifndef __EVIL_TEST_DLFCN__ -#define __EVIL_TEST_DLFCN__ +#ifndef __EVIL_TEST_DLFCN_H__ +#define __EVIL_TEST_DLFCN_H__ int test_dlfcn(suite *s); -#endif /* __EVIL_TEST_DLFCN__ */ +#endif /* __EVIL_TEST_DLFCN_H__ */ diff --git a/legacy/evil/src/bin/evil_test_environment.c b/legacy/evil/src/bin/evil_test_environment.c index e7139a1843..c3538310f4 100644 --- a/legacy/evil/src/bin/evil_test_environment.c +++ b/legacy/evil/src/bin/evil_test_environment.c @@ -1,10 +1,7 @@ - - #ifdef HAVE_CONFIG_H # include "config.h" #endif /* HAVE_CONFIG_H */ -#include #include #include @@ -12,24 +9,165 @@ #include "evil_suite.h" static int -test_env_tests_run(suite *s) +test_env_test_setenv_NULL(void) { char *val; int res; - res = setenv("EVIL_TEST_ENV", "val1", 1); + res = setenv("EVIL_TEST_ENV", NULL, 1); + if (res < 0) + return 0; + + val = getenv("EVIL_TEST_ENV"); + + return val ? 0 : 1; +} + +static int +test_env_test_setenv_NULL_after_set(void) +{ + char *val; + int res; + + res = setenv("EVIL_TEST_ENV", "val", 1); if (res < 0) return 0; val = getenv("EVIL_TEST_ENV"); if (!val) return 0; + + if (strcmp(val, "val")) + return 0; + + res = setenv("EVIL_TEST_ENV", NULL, 1); + if (res < 0) + return 0; + + val = getenv("EVIL_TEST_ENV"); + + return val ? 0 : 1; +} + +static int +test_env_test_getenv_one(void) +{ + char *val; + int res; + + res = setenv("EVIL_TEST_ENV", "val", 1); + if (res < 0) + return 0; + + val = getenv("EVIL_TEST_ENV"); + if (!val) + return 0; + + if (strcmp(val, "val")) + return 0; + + return 1; +} + +static int +test_env_test_getenv_two(void) +{ + char *val; + int res; + + res = setenv("EVIL_TEST_ENV1", "val1", 1); + if (res < 0) + return 0; + + res = setenv("EVIL_TEST_ENV2", "val2", 1); + if (res < 0) + return 0; + + val = getenv("EVIL_TEST_ENV1"); + if (!val) + return 0; + if (strcmp(val, "val1")) + return 0; + + val = getenv("EVIL_TEST_ENV2"); + if (!val) + return 0; + + if (strcmp(val, "val2")) + return 0; + + return 1; +} + +static int +test_env_test_getenv_two_swapped(void) +{ + char *val; + int res; + + res = setenv("EVIL_TEST_ENV1", "val1", 1); + if (res < 0) + return 0; + + res = setenv("EVIL_TEST_ENV2", "val2", 1); + if (res < 0) + return 0; + + val = getenv("EVIL_TEST_ENV2"); + if (!val) + return 0; + if (strcmp(val, "val2")) + return 0; + + val = getenv("EVIL_TEST_ENV1"); + if (!val) + return 0; + if (strcmp(val, "val1")) return 0; return 1; } +static int +test_env_test_unsetenv(void) +{ + char *val; + int res; + + res = setenv("EVIL_TEST_ENV", "val", 1); + if (res < 0) + return 0; + + val = getenv("EVIL_TEST_ENV"); + if (!val) + return 0; + + if (unsetenv("EVIL_TEST_ENV") != 0) + return 0; + + val = getenv("EVIL_TEST_ENV"); + if (val) + return 0; + + return 1; +} + +static int +test_env_tests_run(suite *s) +{ + int res; + + res = test_env_test_setenv_NULL(); + res &= test_env_test_setenv_NULL_after_set(); + res &= test_env_test_getenv_one(); + res &= test_env_test_getenv_two(); + res &= test_env_test_getenv_two_swapped(); + res &= test_env_test_unsetenv(); + + return res; +} + int test_environment(suite *s) { diff --git a/legacy/evil/src/bin/evil_test_environment.h b/legacy/evil/src/bin/evil_test_environment.h index 73d3fbd9d1..763ee401b1 100644 --- a/legacy/evil/src/bin/evil_test_environment.h +++ b/legacy/evil/src/bin/evil_test_environment.h @@ -1,8 +1,8 @@ -#ifndef __EVIL_TEST_ENVIRONMENT__ -#define __EVIL_TEST_ENVIRONMENT__ +#ifndef __EVIL_TEST_ENVIRONMENT_H__ +#define __EVIL_TEST_ENVIRONMENT_H__ int test_environment(suite *s); -#endif /* __EVIL_TEST_ENVIRONMENT__ */ +#endif /* __EVIL_TEST_ENVIRONMENT_H__ */ diff --git a/legacy/evil/src/bin/evil_test_gettimeofday.c b/legacy/evil/src/bin/evil_test_gettimeofday.c index eea330e60c..bc7f01befb 100644 --- a/legacy/evil/src/bin/evil_test_gettimeofday.c +++ b/legacy/evil/src/bin/evil_test_gettimeofday.c @@ -1,10 +1,7 @@ - - #ifdef HAVE_CONFIG_H # include "config.h" #endif /* HAVE_CONFIG_H */ -#include #include #include @@ -13,7 +10,7 @@ #include "evil_suite.h" static int -test_time_tests_run(suite *s) +test_time_test_gettimeofday(void) { struct timeval tp1; struct timeval tp2; @@ -34,6 +31,16 @@ test_time_tests_run(suite *s) return 1; } +static int +test_time_tests_run(suite *s) +{ + int res; + + res = test_time_test_gettimeofday(); + + return res; +} + int test_gettimeofday(suite *s) { diff --git a/legacy/evil/src/bin/evil_test_gettimeofday.h b/legacy/evil/src/bin/evil_test_gettimeofday.h index d4051ef678..ad3155b146 100644 --- a/legacy/evil/src/bin/evil_test_gettimeofday.h +++ b/legacy/evil/src/bin/evil_test_gettimeofday.h @@ -1,8 +1,8 @@ -#ifndef __EVIL_TEST_GETTIMEOFDAY__ -#define __EVIL_TEST_GETTIMEOFDAY__ +#ifndef __EVIL_TEST_GETTIMEOFDAY_H__ +#define __EVIL_TEST_GETTIMEOFDAY_H__ int test_gettimeofday(suite *s); -#endif /* __EVIL_TEST_GETTIMEOFDAY__ */ +#endif /* __EVIL_TEST_GETTIMEOFDAY_H__ */ diff --git a/legacy/evil/src/bin/evil_test_link.c b/legacy/evil/src/bin/evil_test_link.c index 2a4aa30d93..344c6c1de3 100644 --- a/legacy/evil/src/bin/evil_test_link.c +++ b/legacy/evil/src/bin/evil_test_link.c @@ -2,7 +2,6 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ -#include #include #include @@ -144,7 +143,7 @@ test_link_tests_run(suite *s) { int res; - res = test_link_test_symlink(); + res = test_link_test_symlink(); res &= test_link_test_readlink(); return res; diff --git a/legacy/evil/src/bin/evil_test_link.h b/legacy/evil/src/bin/evil_test_link.h index 4867357a17..6f8bfa2328 100644 --- a/legacy/evil/src/bin/evil_test_link.h +++ b/legacy/evil/src/bin/evil_test_link.h @@ -1,8 +1,8 @@ -#ifndef __EVIL_TEST_LINK__ -#define __EVIL_TEST_LINK__ +#ifndef __EVIL_TEST_LINK_H__ +#define __EVIL_TEST_LINK_H__ int test_link(suite *s); -#endif /* __EVIL_TEST_LINK__ */ +#endif /* __EVIL_TEST_LINK_H__ */ diff --git a/legacy/evil/src/bin/evil_test_mkstemp.c b/legacy/evil/src/bin/evil_test_mkstemp.c new file mode 100644 index 0000000000..9a41c93573 --- /dev/null +++ b/legacy/evil/src/bin/evil_test_mkstemp.c @@ -0,0 +1,48 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +#include + +#include "evil_suite.h" + +int test_mkstemp_test(void) +{ + char _template[PATH_MAX]; + char cwd[PATH_MAX]; + int fd; + +#ifdef _WIN32_WCE + if (!getcwd(cwd, PATH_MAX)) + return 0; + _snprintf(_template, PATH_MAX, "%s\\%s", cwd, "file_XXXXXX"); +#else + _snprintf(_template, PATH_MAX, "%s", "file_XXXXXX"); +#endif + + fd = mkstemp(_template); + + if (fd < 0) + return 0; + + return 1; +} + +static int +test_mkstemp_run(suite *s) +{ + int res; + + res = test_mkstemp_test(); + + return res; +} + +int +test_mkstemp(suite *s) +{ + + return test_mkstemp_run(s); +} diff --git a/legacy/evil/src/bin/evil_test_mkstemp.h b/legacy/evil/src/bin/evil_test_mkstemp.h new file mode 100644 index 0000000000..f5bb0c4270 --- /dev/null +++ b/legacy/evil/src/bin/evil_test_mkstemp.h @@ -0,0 +1,8 @@ +#ifndef __EVIL_TEST_MKSTEMP_H__ +#define __EVIL_TEST_MKSTEMP_H__ + + +int test_mkstemp(suite *s); + + +#endif /* __EVIL_TEST_MKSTEMP_H__ */ diff --git a/legacy/evil/src/bin/evil_test_realpath.c b/legacy/evil/src/bin/evil_test_realpath.c new file mode 100644 index 0000000000..246a155e20 --- /dev/null +++ b/legacy/evil/src/bin/evil_test_realpath.c @@ -0,0 +1,42 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +#include + +#include "evil_suite.h" + +int test_realpath_test(void) +{ + char buf[PATH_MAX]; + char *filename; + char *result; + + filename = "evil_suite.exe"; + + if (!(result = realpath(filename, buf))) + return 0; + + printf ("res : %s\n", buf); + + return 1; +} + +static int +test_realpath_run(suite *s) +{ + int res; + + res = test_realpath_test(); + + return res; +} + +int +test_realpath(suite *s) +{ + + return test_realpath_run(s); +} diff --git a/legacy/evil/src/bin/evil_test_realpath.h b/legacy/evil/src/bin/evil_test_realpath.h new file mode 100644 index 0000000000..0205aad149 --- /dev/null +++ b/legacy/evil/src/bin/evil_test_realpath.h @@ -0,0 +1,8 @@ +#ifndef __EVIL_TEST_REALPATH_H__ +#define __EVIL_TEST_REALPATH_H__ + + +int test_realpath(suite *s); + + +#endif /* __EVIL_TEST_REALPATH_H__ */ diff --git a/legacy/evil/src/lib/evil_dirent.c b/legacy/evil/src/lib/evil_dirent.c index aa936afb82..fef2986d4c 100644 --- a/legacy/evil/src/lib/evil_dirent.c +++ b/legacy/evil/src/lib/evil_dirent.c @@ -47,9 +47,9 @@ DIR *opendir(char const *name) wname = evil_char_to_wchar(name); if (!wname) { -#ifdef HAVE_ERRNO_H +# ifdef HAVE_ERRNO_H errno = ENOMEM; -#endif +# endif return NULL; } @@ -68,8 +68,8 @@ DIR *opendir(char const *name) free(wname); #endif - /* directory */ - if (attr != FILE_ATTRIBUTE_DIRECTORY) + /* directory */ + if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { #ifdef HAVE_ERRNO_H errno = ENOTDIR; @@ -77,8 +77,8 @@ DIR *opendir(char const *name) return NULL; } - dir = (DIR *)malloc(sizeof(DIR)); - if (!dir) + dir = (DIR *)malloc(sizeof(DIR)); + if (!dir) { #ifdef HAVE_ERRNO_H errno = ENOMEM; diff --git a/legacy/evil/src/lib/evil_stdlib.c b/legacy/evil/src/lib/evil_stdlib.c index c7a98c1aef..6c6ef64783 100644 --- a/legacy/evil/src/lib/evil_stdlib.c +++ b/legacy/evil/src/lib/evil_stdlib.c @@ -176,6 +176,8 @@ setenv(const char *name, LONG res; DWORD disposition; wchar_t *wname; + char *data; + DWORD size; if (!name || !*name) return -1; @@ -208,11 +210,31 @@ setenv(const char *name, return -1; } + if (value) + { + size = strlen(value); + data = malloc(sizeof(char) * (size + 1)); + if (!data) + return -1; + memcpy((void *)data, value, size); + data[size] = '\0'; + } + else + { + size = 0; + data = malloc(sizeof(char)); + if (!data) + return -1; + data[0] = '\0'; + } + if (!data) + return -1; + if ((res = RegSetValueEx(key, (LPCWSTR)wname, 0, REG_SZ, - (const BYTE *)value, - strlen(value) + 1)) != ERROR_SUCCESS) + (const BYTE *)data, + size + 1)) != ERROR_SUCCESS) { free(wname); _evil_error_display(__FUNCTION__, res); @@ -221,6 +243,7 @@ setenv(const char *name, return -1; } + free(data); free(wname); if ((res = RegCloseKey (key)) != ERROR_SUCCESS) @@ -251,7 +274,7 @@ unsetenv(const char *name) */ int -mkstemp(char *template) +mkstemp(char *__template) { const char lookup[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; char *suffix; @@ -259,12 +282,12 @@ mkstemp(char *template) size_t length; int i; - if (!template) + if (!__template) return 0; - length = strlen(template); + length = strlen(__template); if ((length < 6) || - (strncmp (template + length - 6, "XXXXXX", 6))) + (strncmp (__template + length - 6, "XXXXXX", 6))) { #ifdef HAVE_ERRNO_H errno = EINVAL; @@ -272,7 +295,7 @@ mkstemp(char *template) return -1; } - suffix = template + length - 6; + suffix = __template + length - 6; val = GetTickCount(); val += GetCurrentProcessId(); @@ -298,12 +321,17 @@ mkstemp(char *template) v /= 62; #if ! ( defined(__CEGCC__) || defined(__MINGW32CE__) ) - fd = _open(template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE); + fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE); #else /* __CEGCC__ || __MINGW32CE__ */ { - FILE *f; + FILE *f; + wchar_t *wtemplate; - f = fopen(template, "rwb"); + wtemplate = evil_char_to_wchar(__template); + if (!wtemplate) + return -1; + f = _wfopen(wtemplate, L"rwb"); + free(wtemplate); if (!f) { #ifdef HAVE_ERRNO_H @@ -311,7 +339,7 @@ mkstemp(char *template) #endif /* HAVE_ERRNO_H */ return -1; } - fd = fileno(f); + fd = _fileno(f); } #endif /* __CEGCC__ || __MINGW32CE__ */ if (fd >= 0) @@ -333,13 +361,27 @@ realpath(const char *file_name, char *resolved_name) #if ! ( defined(__CEGCC__) || defined(__MINGW32CE__) ) return _fullpath(resolved_name, file_name, PATH_MAX); #else - int length; + char cwd[PATH_MAX]; + size_t l1; + size_t l2; + size_t l; - length = strlen(file_name); - if ((length + 1) > PATH_MAX) - length = PATH_MAX - 1; - memcpy(resolved_name, file_name, length); - resolved_name[length] = '\0'; + if (!file_name || !resolved_name) + return NULL; + + if (!getcwd(cwd, PATH_MAX)) + return NULL; + + l1 = strlen(cwd); + l2 = strlen(file_name); + l = l1 + l2 + 2; + + if (l > PATH_MAX) + l = PATH_MAX - 1; + memcpy(resolved_name, cwd, l1); + resolved_name[l1] = '\\'; + memcpy(resolved_name + l1 + 1, file_name, l2); + resolved_name[l] = '\0'; return resolved_name; #endif /* __CEGCC__ || __MINGW32CE__ */ diff --git a/legacy/evil/src/lib/evil_unistd.c b/legacy/evil/src/lib/evil_unistd.c index a01da312eb..fc7fd9af32 100644 --- a/legacy/evil/src/lib/evil_unistd.c +++ b/legacy/evil/src/lib/evil_unistd.c @@ -215,7 +215,6 @@ evil_stat(const char *file_name, struct stat *st) handle = FindFirstFile(file, &data); if (handle == INVALID_HANDLE_VALUE) { - _evil_last_error_display(__FUNCTION__); free(file); return -1; }