* src/lib/Evil.h:

* src/lib/evil.c: (evil_getcwd):
add getgwd-like function
* src/lib/dlfcn/dlfcn.c: (dladdr):
* src/lib/dlfcn/dlfcn.h:
add dladdr-like function. Formatting
Remove unused define
* src/lib/mman/sys/mman.h:
remove unused define


SVN revision: 34392
This commit is contained in:
doursse 2008-04-28 14:34:55 +00:00 committed by doursse
parent 5a76370a57
commit 89fde28967
6 changed files with 194 additions and 16 deletions

View File

@ -1,3 +1,17 @@
2008-04-28 Vincent Torri <doursse at users dot sf dot net>
* src/lib/Evil.h:
* src/lib/evil.c: (evil_getcwd):
add getgwd-like function
* src/lib/dlfcn/dlfcn.c: (dladdr):
* src/lib/dlfcn/dlfcn.h:
add dladdr-like function. Formatting
Remove unused define
* src/lib/mman/sys/mman.h:
remove unused define
2008-04-26 Vincent Torri <doursse at users dot sf dot net>
* src/lib/Evil.h:

View File

@ -389,8 +389,39 @@ EAPI void evil_sockets_shutdown(void);
*
* @ingroup Evil
*/
EAPI const char *evil_tmpdir_get(void);
/**
* @brief Get the current directory.
*
* @param buffer Buffer to store the current directory.
* @param size Size of the buffer.
* @return The current directory.
*
* On Windows desktop, use the _getcwd function in MSVCRT.
*
* On Windows CE, get the current directory by extracting the path
* from the executable that is running and put the result in @p buffer
* of length @p size. If @p size is less or equal than 0, return NULL.
* If the current absolute path would require a buffer longer than
* @p size elements, NULL is returned. If @p buffer is NULL, a buffer
* of length @p size is allocated and is returned. If the allocation
* fails, NULL is returned. On success, @p buffer is returned and
* contains the current directory. The last '\' is not included.
* If @p buffer is NULL, the returned value must be freed if not NULL.
*
* Specially usefull on WinCE where the current directory functionality
* is not supported.
*
* Conformity: Almost POSIX.1 (no errno set)
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP, WinCE.
*
* @ingroup Evil
*/
EAPI char *evil_getcwd(char *buffer, size_t size);
#if defined(__CEGCC__) || defined(__MINGW32CE__)

View File

@ -156,6 +156,46 @@ dlsym(void *handle, const char *symbol)
return fp;
}
int
dladdr (void *addr __UNUSED__, Dl_info *info)
{
TCHAR tpath[PATH_MAX];
char *path;
int length;
int ret = 0;
if (!info)
return 0;
ret = GetModuleFileName(GetModuleHandle(NULL), (LPTSTR)&tpath, PATH_MAX);
if (!ret)
return 0;
#if defined(__CEGCC__) || defined(__MINGW32CE__)
path = evil_wchar_to_char(tpath);
#else
path = tpath;
#endif /* ! __CEGCC__ && ! __MINGW32CE__ */
length = strlen (path);
if (length >= PATH_MAX)
{
length = PATH_MAX - 1;
path[PATH_MAX - 1] = '\0';
}
memcpy (info->dli_fname, path, length + 1);
info->dli_fbase = NULL;
info->dli_sname = NULL;
info->dli_saddr = NULL;
#if defined(__CEGCC__) || defined(__MINGW32CE__)
free (path);
#endif /* __CEGCC__ || __MINGW32CE__ */
return 1;
}
char *
dlerror (void)
{

View File

@ -1,6 +1,12 @@
#ifndef __EVIL_DLFCN_H__
#define __EVIL_DLFCN_H__
#if defined(__CEGCC__) || defined(__MINGW32CE__)
# include <sys/syslimits.h>
#endif /* __MINGW32CE__ */
#ifdef EAPI
# undef EAPI
#endif /* EAPI */
@ -17,11 +23,24 @@
# endif /* ! EFL_EVIL_BUILD */
#endif /* _WIN32 */
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file dlfcn.h
* @brief The file that provides functions to manage dynamic-link libraries
* @defgroup Dlfcn Functions that manage dynamic-link libraries.
*
* This header provides functions to load and unload dynamic-link
* libaries, to get the address of a symbol, and to get diagnostic
* information.
*
*/
/**
* @def RTLD_LAZY
* Lazy function call binding
@ -42,16 +61,24 @@ extern "C" {
# define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible
to other dlopen'ed objs */
/**
* @file dlfcn.h
* @brief The file that provides functions to manage dynamic-link libraries
* @defgroup Dlfcn Functions that manage dynamic-link libraries.
*
* This header provides functions to load and unload dynamic-link
* libaries, to get the address of a symbol, and to get diagnostic
* information.
*
* @typedef Dl_info
* @brief A structure that stores infomation of a calling process.
*/
typedef struct Dl_info Dl_info;
/**
* @struct Dl_info
* @brief A structure that stores infomation of a calling process.
*/
struct Dl_info
{
char *dli_fname[PATH_MAX]; /**< Filename of defining object */
void *dli_fbase; /**< Load address of that object */
const char *dli_sname; /**< Name of nearest lower symbol */
void *dli_saddr; /**< Exact value of nearest symbol */
};
/**
* Map a specified executable module (either a .dll or .exe file)
@ -162,6 +189,30 @@ EAPI int dlclose(void* handle);
*/
EAPI void *dlsym(void* handle, const char* symbol);
/**
* Get the location of the current process (.exe)
*
* @param addr Unused.
* @param info Pointer to the Dl_info to fill.
* @return 1 on success, 0 otherwise.
*
* Fill the dli_fname member of @p info with the absolute name
* of the current calling process (.exe file that is executed).
* All other members are set to @c NULL.
*
* Contrary to the unix function, the full name of the shared
* library is not returned, but insted the full name of the current
* calling process (.exe file).
*
* Conformity: None.
*
* Supported OS: Windows Vista, Windows XP or Windows 2000
* Professional.
*
* @ingroup Dlfcn
*/
EAPI int dladdr (void *addr, Dl_info *info);
/**
* Get diagnostic information
*
@ -190,9 +241,5 @@ EAPI char *dlerror (void);
}
#endif
#ifdef _WIN32
# undef EAPI
# define EAPI
#endif /* _WIN32 */
#endif /* __EVIL_DLFCN_H__ */

View File

@ -396,6 +396,55 @@ evil_tmpdir_get(void)
return tmpdir;
}
char *
evil_getcwd(char *buffer, size_t size)
{
#if defined(__CEGCC__) || defined(__MINGW32CE__)
wchar_t wpath[PATH_MAX];
char *cpath;
char *delim;
int ret = 0;
if (size <= 0)
return NULL;
ret = GetModuleFileName(GetModuleHandle(NULL), (LPWSTR)&wpath, PATH_MAX);
if (!ret)
return NULL;
cpath = evil_wchar_to_char(wpath);
if (!cpath)
return NULL;
if (strlen(cpath) >= (size - 1))
{
free(cpath);
return NULL;
}
delim = strrchr(cpath, '\\');
if (delim)
*delim = '\0';
if (!buffer)
{
buffer = (char *)malloc(sizeof(char) * size);
if (!buffer)
{
free(cpath);
return NULL;
}
}
strcpy(buffer, cpath);
free(cpath);
return buffer;
#else
return _getcwd(buffer, size);
#endif /* ! __CEGCC__ && ! __MINGW32CE__ */
}
#if defined(__CEGCC__) || defined(__MINGW32CE__)

View File

@ -1,6 +1,7 @@
#ifndef __EVIL_SYS_MMAN_H__
#define __EVIL_SYS_MMAN_H__
#ifdef EAPI
# undef EAPI
#endif /* EAPI */
@ -150,10 +151,6 @@ EAPI int munmap(void *addr,
}
#endif
#ifdef _WIN32
# undef EAPI
# define EAPI
#endif /* _WIN32 */
#endif /* __EVIL_SYS_MMAN_H__ */