reviewed by: <delete if not using a buddy>

* src/lib/Evil.h:
* src/lib/Makefile.am:
* src/lib/dlfcn/Makefile.am:
* src/lib/dlfcn/dlfcn.c: (get_last_error), (dlopen), (dlsym):
* src/lib/evil.c: (evil_char_to_wchar), (evil_wchar_to_char):
* src/lib/mman/Makefile.am:
* src/lib/mman/mman.c:


SVN revision: 34374
This commit is contained in:
doursse 2008-04-26 16:27:46 +00:00 committed by doursse
parent a6a3a2a9db
commit 6b726880d0
8 changed files with 122 additions and 53 deletions

View File

@ -1,3 +1,15 @@
2008-04-26 Vincent Torri <doursse at users dot sf dot net>
reviewed by: <delete if not using a buddy>
* src/lib/Evil.h:
* src/lib/Makefile.am:
* src/lib/dlfcn/Makefile.am:
* src/lib/dlfcn/dlfcn.c: (get_last_error), (dlopen), (dlsym):
* src/lib/evil.c: (evil_char_to_wchar), (evil_wchar_to_char):
* src/lib/mman/Makefile.am:
* src/lib/mman/mman.c:
2008-04-23 Vincent Torri <doursse at users dot sf dot net>
* configure.ac:

View File

@ -392,6 +392,49 @@ EAPI void evil_sockets_shutdown(void);
EAPI const char *evil_tmpdir_get(void);
#if defined(__CEGCC__) || defined(__MINGW32CE__)
/**
* @brief Convert a string from char * to wchar_t *.
*
* @param text The string to convert.
* @return The converted string.
*
* Convert a string from char * to wchar_t * and return it. If the
* allocation or conversion fails, NULL is returned. On success, the
* returned value must be freed.
*
* Conformity: Non applicable.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI wchar_t *evil_char_to_wchar(const char *text);
/**
* @brief Convert a string from wchar_t * to char *.
*
* @param text The string to convert.
* @return The converted string.
*
* Convert a string from wchar_t * to char * and return it. If the
* allocation or conversion fails, NULL is returned. On success, the
* returned value must be freed.
*
* Conformity: Non applicable.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI char *evil_wchar_to_char(const wchar_t *text);
#endif /* __CEGCC__ || __MINGW32CE__ */
#ifdef __cplusplus
}
#endif

View File

@ -1,7 +1,7 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = dlfcn mman
SUBDIRS = . dlfcn mman
lib_LTLIBRARIES = libevil.la
@ -10,5 +10,6 @@ libevil_la_SOURCES = evil.c
libevil_la_CFLAGS = @win32_cflags@
libevil_la_LIBADD = @win32_libs@
libevil_la_DEPENDENCIES = $(top_builddir)/config.h
libevil_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@

View File

@ -6,4 +6,7 @@ lib_LTLIBRARIES = libdl.la
include_HEADERS = dlfcn.h
libdl_la_SOURCES = dlfcn.c
libdl_la_CFLAGS = @win32_cflags@
libdl_la_LIBADD = $(top_builddir)/src/lib/libevil.la
libdl_la_DEPENDENCIES = $(top_builddir)/src/lib/libevil.la
libdl_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@

View File

@ -5,14 +5,17 @@
#undef WIN32_LEAN_AND_MEAN
#if defined(__CEGCC__) || defined(__MINGW32CE__)
# include <wchar.h>
# include <limits.h>
#endif /* __MINGW32CE__ */
#include "../Evil.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include "dlfcn.h"
#if HAVE___ATTRIBUTE__
# define __UNUSED__ __attribute__((unused))
#else
@ -23,52 +26,6 @@
static char *dl_err = NULL;
static int dl_err_viewed = 0;
#if defined(__CEGCC__) || defined(__MINGW32CE__)
static wchar_t *
string_to_wchar(const char *text)
{
wchar_t *wtext;
int wsize;
wsize = MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, NULL, 0);
if ((wsize == 0) ||
(wsize > (int)(ULONG_MAX/sizeof(wchar_t))))
return NULL;
wtext = malloc(wsize * sizeof(wchar_t));
if (wtext)
if (!MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, wtext, wsize))
return NULL;
return wtext;
}
static char *
wchar_to_string(const wchar_t *text)
{
char * atext;
int size;
int asize;
size = wcslen(text) + 1;
asize = WideCharToMultiByte(CP_ACP, 0, text, size, NULL, 0, NULL, NULL);
if (asize == 0)
return NULL;
atext = (char*)malloc((asize + 1) * sizeof(char));
if (atext)
if (!WideCharToMultiByte(CP_ACP, 0, text, size, atext, asize, NULL, NULL))
return NULL;
atext[asize] = '\0';
return atext;
}
#endif /* __CEGCC__ || __MINGW32CE__ */
static void
get_last_error(char *desc)
{
@ -85,7 +42,7 @@ get_last_error(char *desc)
(LPTSTR)&str, 0, NULL);
#if defined(__CEGCC__) || defined(__MINGW32CE__)
str2 = wchar_to_string(str);
str2 = evil_wchar_to_char(str);
#else
str2 = str;
#endif /* ! __CEGCC__ && ! __MINGW32CE__ */
@ -148,7 +105,7 @@ dlopen(const char* path, int mode __UNUSED__)
{
wchar_t *wpath;
wpath = string_to_wchar(new_path);
wpath = evil_char_to_wchar(new_path);
module = LoadLibrary(wpath);
free(wpath);
}
@ -186,7 +143,7 @@ dlsym(void *handle, const char *symbol)
{
wchar_t *wsymbol;
wsymbol = string_to_wchar(symbol);
wsymbol = evil_char_to_wchar(symbol);
fp = GetProcAddress(handle, wsymbol);
free(wsymbol);
}

View File

@ -15,6 +15,10 @@
# include <sys/syslimits.h>
#endif /* __CEGCC__ */
#if defined(__CEGCC__) || defined(__MINGW32CE__)
# include <wchar.h>
#endif /* __CEGCC__ || __MINGW32CE__ */
#include <sys/types.h>
#include <sys/timeb.h>
#include <fcntl.h>
@ -391,3 +395,50 @@ evil_tmpdir_get(void)
return tmpdir;
}
#if defined(__CEGCC__) || defined(__MINGW32CE__)
wchar_t *
evil_char_to_wchar(const char *text)
{
wchar_t *wtext;
int wsize;
wsize = MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, NULL, 0);
if ((wsize == 0) ||
(wsize > (int)(ULONG_MAX/sizeof(wchar_t))))
return NULL;
wtext = malloc(wsize * sizeof(wchar_t));
if (wtext)
if (!MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, wtext, wsize))
return NULL;
return wtext;
}
char *
evil_wchar_to_char(const wchar_t *text)
{
char * atext;
int size;
int asize;
size = wcslen(text) + 1;
asize = WideCharToMultiByte(CP_ACP, 0, text, size, NULL, 0, NULL, NULL);
if (asize == 0)
return NULL;
atext = (char*)malloc((asize + 1) * sizeof(char));
if (atext)
if (!WideCharToMultiByte(CP_ACP, 0, text, size, atext, asize, NULL, NULL))
return NULL;
atext[asize] = '\0';
return atext;
}
#endif /* __CEGCC__ || __MINGW32CE__ */

View File

@ -6,4 +6,6 @@ lib_LTLIBRARIES = libmman.la
nobase_include_HEADERS = sys/mman.h
libmman_la_SOURCES = mman.c
libmman_la_CFLAGS = @win32_cflags@
libmman_la_DEPENDENCIES = $(top_builddir)/config.h
libmman_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@

View File

@ -8,12 +8,12 @@
# include <io.h>
#endif /* ! __CEGCC__ */
#include "sys/mman.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include "sys/mman.h"
#if HAVE___ATTRIBUTE__
# define __UNUSED__ __attribute__((unused))
#else