From de07e9bad97b2ecd25f43f51ecb4ad4ab6998681 Mon Sep 17 00:00:00 2001 From: Vincent Torri Date: Fri, 24 Oct 2008 07:32:08 +0000 Subject: [PATCH] reviewed by: patch by: * src/lib/Evil.h: * src/lib/Makefile.am: * src/lib/evil_private.h: * src/lib/evil_stdio.c: * src/lib/evil_stdio.h: * src/lib/evil_stdlib.c: * src/lib/evil_unistd.c: * src/lib/evil_util.c: SVN revision: 37046 --- legacy/evil/ChangeLog | 19 +++++++++++++++ legacy/evil/src/lib/Evil.h | 4 ++++ legacy/evil/src/lib/Makefile.am | 2 +- legacy/evil/src/lib/evil_private.h | 8 +++++++ legacy/evil/src/lib/evil_stdio.c | 38 ++++++++++++++++++++++++++++-- legacy/evil/src/lib/evil_stdio.h | 6 +++-- legacy/evil/src/lib/evil_stdlib.c | 33 ++++++++------------------ legacy/evil/src/lib/evil_unistd.c | 8 +++++-- legacy/evil/src/lib/evil_util.c | 10 ++++++++ 9 files changed, 98 insertions(+), 30 deletions(-) create mode 100644 legacy/evil/src/lib/evil_private.h diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog index 6320068105..db3050d0b7 100644 --- a/legacy/evil/ChangeLog +++ b/legacy/evil/ChangeLog @@ -1,3 +1,22 @@ +2008-10-24 Vincent Torri + + * src/lib/Makefile.am: + * src/lib/evil_util.c: + * src/lib/evil_private.h: + move _evil_stdlib_error_display() from evil_stdlib.c + to evil_util.c and rename it to _evil_error_display() + + * src/lib/evil_stdlib.c: + * src/lib/evil_unistd.c: + use _evil_error_display() + + * src/lib/Evil.h: + overload fopen for mingw32ce + + * src/lib/evil_stdio.c: + * src/lib/evil_stdio.h: + add evil_open to overload fopen (for mingw32ce + 2008-10-22 Vincent Torri * configure.ac: diff --git a/legacy/evil/src/lib/Evil.h b/legacy/evil/src/lib/Evil.h index 10a1fc4307..4fda080bdd 100644 --- a/legacy/evil/src/lib/Evil.h +++ b/legacy/evil/src/lib/Evil.h @@ -149,6 +149,10 @@ typedef unsigned long gid_t; #define pipe(fd) evil_pipe(fd) +#if defined (_WIN32_WCE) && ! defined (__CEGCC__) +# define fopen(path, mode) evil_fopen(path, mode) +#endif /* _WIN32_WCE && ! __CEGCC__ */ + #ifdef __cplusplus } diff --git a/legacy/evil/src/lib/Makefile.am b/legacy/evil/src/lib/Makefile.am index fec88630ea..0733ebe034 100644 --- a/legacy/evil/src/lib/Makefile.am +++ b/legacy/evil/src/lib/Makefile.am @@ -43,4 +43,4 @@ libevil_la_CFLAGS = @win32_cflags@ libevil_la_LIBADD = @win32_libs@ $(EFL_MPATROL_LIBS) libevil_la_LDFLAGS = -no-undefined -Wl,--enable-auto-import -version-info @version_info@ -EXTRA_DIST = evil_fnmatch_private.h +EXTRA_DIST = evil_private.h evil_fnmatch_private.h diff --git a/legacy/evil/src/lib/evil_private.h b/legacy/evil/src/lib/evil_private.h new file mode 100644 index 0000000000..d1c9823a93 --- /dev/null +++ b/legacy/evil/src/lib/evil_private.h @@ -0,0 +1,8 @@ +#ifndef __EVIL_PRIVATE_H__ +#define __EVIL_PRIVATE_H__ + + +void _evil_error_display(LONG res); + + +#endif /* __EVIL_PRIVATE_H__ */ diff --git a/legacy/evil/src/lib/evil_stdio.c b/legacy/evil/src/lib/evil_stdio.c index 37d38c1a40..6f800c2019 100644 --- a/legacy/evil/src/lib/evil_stdio.c +++ b/legacy/evil/src/lib/evil_stdio.c @@ -4,9 +4,10 @@ #endif /* HAVE_CONFIG_H */ #include "Evil.h" +#undef fopen -#ifdef __MINGW32CE__ +#if defined (_WIN32_WCE) && ! defined (__CEGCC__) /* * Error related functions @@ -23,9 +24,42 @@ void perror (const char *s) * */ +FILE *evil_fopen(const char *path, const char *mode) +{ + FILE *f; + char *filename; + + if (*path != '\\') + { + char buf[PATH_MAX]; + int l1; + int l2; + + if (!evil_getcwd(buf, PATH_MAX)) + return NULL; + + l1 = strlen(buf); + l2 = strlen(path); + filename = (char *)malloc(l1 + 1 + l2 + 1); + memcpy(filename, buf, l1); + filename[l1] = '\\'; + memcpy(filename + l1 + 1, path, l2); + filename[l1 + 1 + l2] = '\0'; + } + else + filename = (char *)path; + + f = fopen(filename, mode); + if (*path != '\\') + free(filename); + + return f; +} + void rewind(FILE *stream) { fseek(stream, 0, SEEK_SET); } -#endif /* __MINGW32CE__ */ + +#endif /* _WIN32_WCE && ! __CEGCC__ */ diff --git a/legacy/evil/src/lib/evil_stdio.h b/legacy/evil/src/lib/evil_stdio.h index b386b1e77d..df3d271040 100644 --- a/legacy/evil/src/lib/evil_stdio.h +++ b/legacy/evil/src/lib/evil_stdio.h @@ -2,7 +2,7 @@ #define __EVIL_STDIO_H__ -#ifdef __MINGW32CE__ +#if defined (_WIN32_WCE) && ! defined (__CEGCC__) #include @@ -19,9 +19,11 @@ EAPI void perror (const char *s); * */ +EAPI FILE *evil_fopen(const char *path, const char *mode); + EAPI void rewind(FILE *stream); -#endif /* __MINGW32CE__ */ +#endif /* _WIN32_WCE && ! __CEGCC__ */ #endif /* __EVIL_STDIO_H__ */ diff --git a/legacy/evil/src/lib/evil_stdlib.c b/legacy/evil/src/lib/evil_stdlib.c index fc00206889..0dc3410b9a 100644 --- a/legacy/evil/src/lib/evil_stdlib.c +++ b/legacy/evil/src/lib/evil_stdlib.c @@ -16,19 +16,7 @@ #undef WIN32_LEAN_AND_MEAN #include "Evil.h" - -/*** Local ***/ - -static void -_evil_stdlib_error_display(const char *fct, - LONG res) -{ - char *error; - - error = evil_format_message(res); - fprintf(stderr, "[Evil] [%s] ERROR: %s\n", fct, error); - free(error); -} +#include "evil_private.h" /* * Environment variable related functions @@ -61,7 +49,7 @@ getenv(const char *name) 0, 0, &key)) != ERROR_SUCCESS) { - _evil_stdlib_error_display("getenv", res); + _evil_error_display(res); return NULL; } @@ -69,7 +57,7 @@ getenv(const char *name) if (!wname) { if ((res = RegCloseKey (key)) != ERROR_SUCCESS) - _evil_stdlib_error_display("getenv", res); + _evil_error_display(res); return NULL; } @@ -78,9 +66,8 @@ getenv(const char *name) (LPBYTE)&_evil_stdlib_getenv_buffer, &size)) != ERROR_SUCCESS) { - _evil_stdlib_error_display("getenv", res); if ((res = RegCloseKey (key)) != ERROR_SUCCESS) - _evil_stdlib_error_display("getenv", res); + _evil_error_display(res); free(wname); return NULL; } @@ -89,7 +76,7 @@ getenv(const char *name) if ((res = RegCloseKey (key)) != ERROR_SUCCESS) { - _evil_stdlib_error_display("getenv", res); + _evil_error_display(res); return NULL; } @@ -206,7 +193,7 @@ setenv(const char *name, &key, &disposition)) != ERROR_SUCCESS) { - _evil_stdlib_error_display("setenv", res); + _evil_error_display(res); return -1; } @@ -218,7 +205,7 @@ setenv(const char *name, if (!wname) { if ((res = RegCloseKey (key)) != ERROR_SUCCESS) - _evil_stdlib_error_display("setenv", res); + _evil_error_display(res); return -1; } @@ -229,9 +216,9 @@ setenv(const char *name, strlen(value) + 1)) != ERROR_SUCCESS) { free(wname); - _evil_stdlib_error_display("setenv", res); + _evil_error_display(res); if ((res = RegCloseKey (key)) != ERROR_SUCCESS) - _evil_stdlib_error_display("setenv", res); + _evil_error_display(res); return -1; } @@ -239,7 +226,7 @@ setenv(const char *name, if ((res = RegCloseKey (key)) != ERROR_SUCCESS) { - _evil_stdlib_error_display("setenv", res); + _evil_error_display(res); return -1; } diff --git a/legacy/evil/src/lib/evil_unistd.c b/legacy/evil/src/lib/evil_unistd.c index ac3fe3a25b..ecf61d15d9 100644 --- a/legacy/evil/src/lib/evil_unistd.c +++ b/legacy/evil/src/lib/evil_unistd.c @@ -18,6 +18,7 @@ #endif #include "Evil.h" +#include "evil_private.h" /* * Process identifer related functions @@ -251,7 +252,7 @@ evil_getcwd(char *buffer, size_t size) wchar_t wpath[PATH_MAX]; char *cpath; char *delim; - int ret = 0; + DWORD ret = 0; if (size <= 0) return NULL; @@ -259,7 +260,10 @@ evil_getcwd(char *buffer, size_t size) ret = GetModuleFileName(GetModuleHandle(NULL), (LPWSTR)&wpath, PATH_MAX); if (!ret) - return NULL; + { + _evil_error_display(ret); + return NULL; + } cpath = evil_wchar_to_char(wpath); if (!cpath) diff --git a/legacy/evil/src/lib/evil_util.c b/legacy/evil/src/lib/evil_util.c index fdd1fac61b..6a2f4e2c76 100644 --- a/legacy/evil/src/lib/evil_util.c +++ b/legacy/evil/src/lib/evil_util.c @@ -92,6 +92,16 @@ evil_format_message(long err) return disp; } +void +_evil_error_display(LONG res) +{ + char *error; + + error = evil_format_message(res); + fprintf(stderr, "[Evil] [%s] ERROR: %s\n", __FUNCTION__, error); + free(error); +} + char * evil_last_error_get(void) {