forked from enlightenment/efl
* configure.ac:
add c++ compiler checks remove linking against libuid.a as it's not an import lib. * src/bin/Makefile.am: * src/bin/evil_suite.c: * src/bin/evil_test_link.c: * src/bin/evil_test_link.h: add unit test for links. Must be improved. * src/lib/Makefile.am: add unistd.cpp and uuid.c use -fno-exceptions when compiling c++ code * src/lib/evil_unistd.c: * src/lib/evil_unistd.cpp: use C++ api to manage links on Windows XP. Can be considered as heavy but it's cleaner as the internals can change later. I might consider to compile Windows CE code with only C compiler as with mingw32ce, libstdc++ is statically linked to the DLL / app (legacy of mingw stuff), to reduce a bit the DLL size. * src/lib/evil_private.h: declare _evil_error_display() as C function (otherwise linker not happy) * src/lib/evil_stdlib.c: use RegCreateKeyEx() instead of RegOpenKeyEx in getenv(). fix an _evil_error_display() call. * src/lib/evil_util.c: add more error messages * src/lib/evil_uuid.c: define IID_IPersistFile (for links on Windows XP) * src/lib/evil_unistd.h: fix doc SVN revision: 37267
This commit is contained in:
parent
09c1768c99
commit
9a0b7ebd18
|
@ -1,3 +1,44 @@
|
|||
2008-10-28 Vincent Torri <doursse at users dot sf dot net>
|
||||
|
||||
* configure.ac:
|
||||
add c++ compiler checks
|
||||
remove linking against libuid.a as it's not an import lib.
|
||||
|
||||
* src/bin/Makefile.am:
|
||||
* src/bin/evil_suite.c:
|
||||
* src/bin/evil_test_link.c:
|
||||
* src/bin/evil_test_link.h:
|
||||
add unit test for links. Must be improved.
|
||||
|
||||
* src/lib/Makefile.am:
|
||||
add unistd.cpp and uuid.c
|
||||
use -fno-exceptions when compiling c++ code
|
||||
|
||||
* src/lib/evil_unistd.c:
|
||||
* src/lib/evil_unistd.cpp:
|
||||
use C++ api to manage links on Windows XP. Can be considered
|
||||
as heavy but it's cleaner as the internals can change later.
|
||||
I might consider to compile Windows CE code with only C compiler
|
||||
as with mingw32ce, libstdc++ is statically linked to the
|
||||
DLL / app (legacy of mingw stuff), to reduce a bit the DLL size.
|
||||
|
||||
* src/lib/evil_private.h:
|
||||
declare _evil_error_display() as C function (otherwise linker
|
||||
not happy)
|
||||
|
||||
* src/lib/evil_stdlib.c:
|
||||
use RegCreateKeyEx() instead of RegOpenKeyEx in getenv().
|
||||
fix an _evil_error_display() call.
|
||||
|
||||
* src/lib/evil_util.c:
|
||||
add more error messages
|
||||
|
||||
* src/lib/evil_uuid.c:
|
||||
define IID_IPersistFile (for links on Windows XP)
|
||||
|
||||
* src/lib/evil_unistd.h:
|
||||
fix doc
|
||||
|
||||
2008-10-25 Vincent Torri <doursse at users dot sf dot net>
|
||||
|
||||
* src/lib/evil_unistd.c:
|
||||
|
|
|
@ -18,7 +18,6 @@ esac
|
|||
AM_INIT_AUTOMAKE(1.6 dist-bzip2)
|
||||
|
||||
AC_LIBTOOL_WIN32_DLL
|
||||
define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])dnl
|
||||
define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
|
||||
AC_PROG_LIBTOOL
|
||||
|
||||
|
@ -35,7 +34,7 @@ AC_SUBST(version_info)
|
|||
win32_libs=""
|
||||
case "$host_os" in
|
||||
mingw | mingw32 | mingw32msvc)
|
||||
win32_libs="-lole32 -luuid -lws2_32 -lsecur32"
|
||||
win32_libs="-lole32 -lws2_32 -lsecur32"
|
||||
;;
|
||||
cegcc*)
|
||||
win32_libs="-lws2"
|
||||
|
@ -55,6 +54,7 @@ AC_CHECK_HEADERS_ONCE([errno.h])
|
|||
|
||||
### Checks for programs
|
||||
AM_PROG_AS
|
||||
AC_PROG_CXX
|
||||
AC_LANG(C)
|
||||
AC_PROG_CPP
|
||||
AC_PROG_CC
|
||||
|
|
|
@ -14,6 +14,7 @@ bin_PROGRAMS = evil_suite test_dlfcn test_pipe test_evil
|
|||
evil_suite_SOURCES = \
|
||||
evil_suite.c \
|
||||
evil_test_environment.c \
|
||||
evil_test_link.c \
|
||||
evil_test_memcpy.c
|
||||
|
||||
if EVIL_HAVE_WINCE
|
||||
|
@ -44,4 +45,5 @@ test_evil_LDFLAGS = -Wl,--enable-auto-import
|
|||
EXTRA_DIST = \
|
||||
evil_suite.h \
|
||||
evil_test_environment.h \
|
||||
evil_test_link.h \
|
||||
evil_test_memcpy.h
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "evil_suite.h"
|
||||
#include "evil_test_environment.h"
|
||||
#include "evil_test_link.h"
|
||||
#include "evil_test_memcpy.h"
|
||||
|
||||
|
||||
|
@ -150,6 +151,7 @@ main()
|
|||
{
|
||||
test tests[] = {
|
||||
{ "environment", test_environment },
|
||||
{ "link ", test_link },
|
||||
{ "memcpy ", test_memcpy },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
@ -160,10 +162,8 @@ main()
|
|||
if (!s)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
for (i = 0; ; ++i)
|
||||
for (i = 0; tests[i].name; ++i)
|
||||
{
|
||||
if (!tests[i].name)
|
||||
break;
|
||||
|
||||
suite_test_add(s, tests[i].name, tests[i].fct);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Evil.h>
|
||||
|
||||
#include "evil_suite.h"
|
||||
|
||||
static int
|
||||
test_link_test_file_create(const char *name, const char *data)
|
||||
{
|
||||
FILE *f;
|
||||
size_t length;
|
||||
size_t res;
|
||||
|
||||
f = fopen(name, "wb");
|
||||
if (!f)
|
||||
return 0;
|
||||
|
||||
length = strlen(data) + 1;
|
||||
res = fwrite(data, 1, length, f);
|
||||
if (res < length)
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
test_link_test_symlink(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (!test_link_test_file_create("evil_test_link.dat",
|
||||
"evil_test_link symlink data\n"))
|
||||
return 0;
|
||||
|
||||
if (symlink("evil_test_link.dat", "evil_test_link") < 0)
|
||||
return 0;
|
||||
|
||||
if (unlink("evil_test_link.dat") < 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
test_link_tests_run(suite *s)
|
||||
{
|
||||
return test_link_test_symlink();
|
||||
}
|
||||
|
||||
int
|
||||
test_link(suite *s)
|
||||
{
|
||||
|
||||
return test_link_tests_run(s);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef __EVIL_TEST_LINK__
|
||||
#define __EVIL_TEST_LINK__
|
||||
|
||||
|
||||
int test_link(suite *s);
|
||||
|
||||
|
||||
#endif /* __EVIL_TEST_LINK__ */
|
|
@ -35,11 +35,13 @@ evil_stdlib.c \
|
|||
evil_stdio.c \
|
||||
evil_string.c \
|
||||
evil_time.c \
|
||||
evil_unistd.c \
|
||||
evil_util.c
|
||||
evil_unistd.cpp \
|
||||
evil_util.c \
|
||||
evil_uuid.c
|
||||
|
||||
libevil_la_CPPFLAGS = @win32_cppflags@
|
||||
libevil_la_CFLAGS = @win32_cflags@
|
||||
libevil_la_CXXFLAGS = -fno-exceptions
|
||||
libevil_la_LIBADD = @win32_libs@ $(EFL_MPATROL_LIBS)
|
||||
libevil_la_LDFLAGS = -no-undefined -Wl,--enable-auto-import -version-info @version_info@
|
||||
|
||||
|
|
|
@ -2,7 +2,15 @@
|
|||
#define __EVIL_PRIVATE_H__
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void _evil_error_display(const char *fct, LONG res);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __EVIL_PRIVATE_H__ */
|
||||
|
|
|
@ -39,17 +39,20 @@ getenv(const char *name)
|
|||
wchar_t *wname;
|
||||
LONG res;
|
||||
DWORD type;
|
||||
DWORD disposition;
|
||||
DWORD size = PATH_MAX;
|
||||
|
||||
if (!name || !*name)
|
||||
return NULL;
|
||||
|
||||
if ((res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
TEXT("Software\\Efl\\Environment"),
|
||||
0, 0,
|
||||
&key)) != ERROR_SUCCESS)
|
||||
if ((res = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||||
TEXT("Software\\Efl\\Environment"),
|
||||
0, NULL,
|
||||
REG_OPTION_VOLATILE,
|
||||
0, NULL,
|
||||
&key, &disposition)) != ERROR_SUCCESS)
|
||||
{
|
||||
_evil_error_display(__FILE__, res);
|
||||
_evil_error_display(__FUNCTION__, res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
# include <objidl.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
# include <shellapi.h>
|
||||
#endif
|
||||
|
||||
#include "Evil.h"
|
||||
#include "evil_private.h"
|
||||
|
||||
|
@ -37,19 +41,6 @@ getpid(void)
|
|||
*
|
||||
*/
|
||||
|
||||
#if defined(__CEGCC__) || defined(__MINGW32CE__)
|
||||
|
||||
DWORD SHCreateShortcutEx(LPTSTR lpszDir,
|
||||
LPTSTR lpszTarget,
|
||||
LPTSTR szShortcut,
|
||||
LPDWORD lpcbShortcut);
|
||||
|
||||
BOOL SHGetShortcutTarget(LPTSTR szShortcut,
|
||||
LPTSTR szTarget,
|
||||
int cbMax );
|
||||
|
||||
#endif /* __CEGCC__ || __MINGW32CE__ */
|
||||
|
||||
|
||||
/* REMARK: Windows has no symbolic link. */
|
||||
/* Nevertheless, it can create and read .lnk files */
|
||||
|
@ -79,9 +70,7 @@ symlink(const char *oldpath, const char *newpath)
|
|||
|
||||
return res ? 0 : -1;
|
||||
#else
|
||||
# ifdef UNICODE
|
||||
wchar_t new_path[MB_CUR_MAX];
|
||||
# endif /* UNICODE */
|
||||
IShellLink *pISL;
|
||||
IShellLink **shell_link;
|
||||
IPersistFile *pIPF;
|
||||
|
@ -100,41 +89,36 @@ symlink(const char *oldpath, const char *newpath)
|
|||
|
||||
/* Hack to cleanly remove a warning */
|
||||
shell_link = &pISL;
|
||||
if (FAILED(CoCreateInstance(&CLSID_ShellLink,
|
||||
if (FAILED(CoCreateInstance(CLSID_ShellLink,
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
&IID_IShellLink,
|
||||
IID_IShellLink,
|
||||
(void **)shell_link)))
|
||||
goto no_instance;
|
||||
|
||||
if (FAILED(pISL->lpVtbl->SetPath(pISL, oldpath)))
|
||||
if (FAILED(pISL->SetPath(oldpath)))
|
||||
goto no_setpath;
|
||||
|
||||
/* Hack to cleanly remove a warning */
|
||||
persit_file = &pIPF;
|
||||
if (FAILED(pISL->lpVtbl->QueryInterface(pISL, &IID_IPersistFile, (void **)persit_file)))
|
||||
if (FAILED(pISL->QueryInterface(IID_IPersistFile, (void **)persit_file)))
|
||||
goto no_queryinterface;
|
||||
|
||||
# ifdef UNICODE
|
||||
mbstowcs(new_path, newpath, MB_CUR_MAX);
|
||||
if (FAILED(pIPF->lpVtbl->Save(pIPF, new_path, FALSE)))
|
||||
if (FAILED(pIPF->Save(new_path, FALSE)))
|
||||
goto no_save;
|
||||
# else
|
||||
if (FAILED(pIPF->lpVtbl->Save(pIPF, newpath, FALSE)))
|
||||
goto no_save;
|
||||
# endif /* ! UNICODE */
|
||||
|
||||
pIPF->lpVtbl->Release(pIPF);
|
||||
pISL->lpVtbl->Release(pISL);
|
||||
pIPF->Release();
|
||||
pISL->Release();
|
||||
CoUninitialize();
|
||||
|
||||
return 0;
|
||||
|
||||
no_save:
|
||||
pIPF->lpVtbl->Release(pIPF);
|
||||
pIPF->Release();
|
||||
no_queryinterface:
|
||||
no_setpath:
|
||||
pISL->lpVtbl->Release(pISL);
|
||||
pISL->Release();
|
||||
no_instance:
|
||||
CoUninitialize();
|
||||
return -1;
|
||||
|
@ -176,9 +160,7 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
|||
|
||||
return length;
|
||||
#else
|
||||
# ifdef UNICODE
|
||||
wchar_t old_path[MB_CUR_MAX];
|
||||
# endif /* UNICODE */
|
||||
char new_path[PATH_MAX];
|
||||
IShellLink *pISL;
|
||||
IShellLink **shell_link;
|
||||
|
@ -199,27 +181,22 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
|||
|
||||
/* Hack to cleanly remove a warning */
|
||||
persit_file = &pIPF;
|
||||
if (FAILED(CoCreateInstance(&CLSID_ShellLink,
|
||||
if (FAILED(CoCreateInstance(CLSID_ShellLink,
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
&IID_IPersistFile,
|
||||
IID_IPersistFile,
|
||||
(void **)persit_file)))
|
||||
goto no_instance;
|
||||
|
||||
# ifdef UNICODE
|
||||
mbstowcs(old_path, path, MB_CUR_MAX);
|
||||
if (FAILED(pIPF->lpVtbl->Load(pIPF, old_path, STGM_READWRITE)))
|
||||
if (FAILED(pIPF->Load(old_path, STGM_READWRITE)))
|
||||
goto no_load;
|
||||
# else
|
||||
if (FAILED(pIPF->lpVtbl->Load(pIPF, path, STGM_READWRITE)))
|
||||
goto no_load;
|
||||
# endif /* ! UNICODE */
|
||||
|
||||
shell_link = &pISL;
|
||||
if (FAILED(pIPF->lpVtbl->QueryInterface(pIPF, &IID_IShellLink, (void **)shell_link)))
|
||||
if (FAILED(pIPF->QueryInterface(IID_IShellLink, (void **)shell_link)))
|
||||
goto no_queryinterface;
|
||||
|
||||
if (FAILED(pISL->lpVtbl->GetPath(pISL, new_path, PATH_MAX, NULL, 0)))
|
||||
if (FAILED(pISL->GetPath(new_path, PATH_MAX, NULL, 0)))
|
||||
goto no_getpath;
|
||||
|
||||
length = strlen(new_path);
|
||||
|
@ -228,17 +205,17 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
|||
|
||||
memcpy(buf, new_path, length);
|
||||
|
||||
pISL->lpVtbl->Release(pISL);
|
||||
pIPF->lpVtbl->Release(pIPF);
|
||||
pISL->Release();
|
||||
pIPF->Release();
|
||||
CoUninitialize();
|
||||
|
||||
return length;
|
||||
|
||||
no_getpath:
|
||||
pISL->lpVtbl->Release(pISL);
|
||||
pISL->Release();
|
||||
no_queryinterface:
|
||||
no_load:
|
||||
pIPF->lpVtbl->Release(pIPF);
|
||||
pIPF->Release();
|
||||
no_instance:
|
||||
CoUninitialize();
|
||||
return -1;
|
|
@ -71,9 +71,8 @@ EAPI int symlink(const char *oldpath, const char *newpath);
|
|||
* Place the content of the shell link @p path in the buffer
|
||||
* @p buf, which has size @p bufzsiz.
|
||||
*
|
||||
* On success, this function returns the count of characters
|
||||
* placed in the buffer. Otherwise, it returns -1 and errno may
|
||||
* be set to the following value:
|
||||
* On success, this function returns 0. Otherwise, it returns -1 and
|
||||
* errno may be set to the following value:
|
||||
* - ENOMEM: Not enough memory.
|
||||
*
|
||||
* On Windows, the symbolic links do not exist. Nevertheless
|
||||
|
|
|
@ -70,7 +70,12 @@ evil_format_message(long err)
|
|||
(LPTSTR)&msg,
|
||||
0,
|
||||
NULL))
|
||||
return NULL;
|
||||
{
|
||||
char buf[4096];
|
||||
|
||||
snprintf(buf, 4096, "FormatMessage failed with error %ld\n", GetLastError());
|
||||
return strdup(buf);
|
||||
}
|
||||
|
||||
#ifdef UNICODE
|
||||
str = evil_wchar_to_char(msg);
|
||||
|
@ -98,7 +103,7 @@ _evil_error_display(const char *fct, LONG res)
|
|||
char *error;
|
||||
|
||||
error = evil_format_message(res);
|
||||
fprintf(stderr, "[Evil] [%s] ERROR: %s\n", fct, error);
|
||||
fprintf(stderr, "[Evil] [%s] ERROR (%ld): %s\n", fct, res, error);
|
||||
free(error);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#if ! defined(__CEGCC__) && ! defined(__MINGW32CE__)
|
||||
/*
|
||||
* Defines the windows UUID IID_IPersistFile used for links in
|
||||
* evil. This is here since uuid.lib is a static only library and
|
||||
* libtool does not allow you to link a DLL against a static library.
|
||||
*/
|
||||
|
||||
# define INITGUID
|
||||
# include <basetyps.h>
|
||||
DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0);
|
||||
|
||||
#endif /* ! __CEGCC__ && ! __MINGW32CE__ */
|
Loading…
Reference in New Issue