From 9373a622034f55900d678079c73d011a5d34ce95 Mon Sep 17 00:00:00 2001 From: doursse Date: Sat, 20 Jan 2007 15:20:23 +0000 Subject: [PATCH] fix compilation with MinGW SVN revision: 28080 --- legacy/eet/INSTALL | 5 ++++ legacy/eet/configure.in | 15 +++++++---- legacy/eet/eet-config.in | 2 +- legacy/eet/src/lib/Eet.h | 2 +- legacy/eet/src/lib/eet_lib.c | 52 ++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 7 deletions(-) diff --git a/legacy/eet/INSTALL b/legacy/eet/INSTALL index 3a3ad7ed8f..61f792e143 100644 --- a/legacy/eet/INSTALL +++ b/legacy/eet/INSTALL @@ -12,3 +12,8 @@ To install (run this as root, or the user who handles installs): make install NOTE: You MUST make install Eet for it to run properly. + +NOTE: for compilation with MinGW, fnmatch.h is probably missing. + That file can be found here: +http://www.koders.com/c/fid2B518462CB1EED3D4E31E271DB83CD1582F6EEBE.aspx + It should be installed in the mingw include directory. diff --git a/legacy/eet/configure.in b/legacy/eet/configure.in index 5360d7ba80..f1dceb372d 100644 --- a/legacy/eet/configure.in +++ b/legacy/eet/configure.in @@ -21,6 +21,7 @@ AC_CHECK_HEADER(jpeglib.h,, AC_MSG_ERROR("Cannot find jpeglib.h. Make sure your AC_CHECK_HEADERS(netinet/in.h) +winsock_libs="" case "$host_os" in mingw|mingw32) winsock_libs="-lwsock32" @@ -29,15 +30,19 @@ esac AC_SUBST(winsock_libs) -AC_CHECK_HEADER(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file])) +AC_CHECK_HEADER(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file. MinGW users: see the INSTALL file])) +fnmatch_libs="" AC_CHECK_FUNCS(fnmatch, res=yes, res=no) if test "x$res" = "xno"; then - AC_CHECK_LIB(fnmatch, fnmatch, res=yes, res=no) + AC_CHECK_LIB(fnmatch, fnmatch, res=yes fnmatch_libs="-lfnmatch", res=no) +dnl Test for compilation with MinGW. +dnl fnmatch function is in the libiberty library if test "x$res" = "xno"; then - AC_MSG_ERROR([Cannot find fnmatch() in neither libc nor libfnmatch]) - else - fnmatch_libs="-lfnmatch" + AC_CHECK_LIB(iberty, fnmatch, res=yes fnmatch_libs="-liberty", res=no) + fi + if test "x$res" = "xno"; then + AC_MSG_ERROR([Cannot find fnmatch() in neither libc nor libfnmatch, nor libiberty]) fi fi diff --git a/legacy/eet/eet-config.in b/legacy/eet/eet-config.in index 9cb37773da..e08f1c1f4f 100644 --- a/legacy/eet/eet-config.in +++ b/legacy/eet/eet-config.in @@ -46,7 +46,7 @@ while test $# -gt 0; do ;; --libs) libdirs=-L@libdir@ - echo $libdirs -leet -lz -ljpeg + echo $libdirs -leet -lz -ljpeg @fnmatch_libs@ @winsock_libs@ ;; *) echo "${usage}" 1>&2 diff --git a/legacy/eet/src/lib/Eet.h b/legacy/eet/src/lib/Eet.h index 89e404be22..70adda3d2e 100644 --- a/legacy/eet/src/lib/Eet.h +++ b/legacy/eet/src/lib/Eet.h @@ -6,7 +6,7 @@ #ifdef EAPI #undef EAPI #endif -#ifdef WIN32 +#ifdef _MSC_VER # ifdef BUILDING_DLL # define EAPI __declspec(dllexport) # else diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c index 902e7fcfd9..f13d881a57 100644 --- a/legacy/eet/src/lib/eet_lib.c +++ b/legacy/eet/src/lib/eet_lib.c @@ -3,7 +3,9 @@ */ #include +#ifndef _WIN32 #include +#endif #include "Eet.h" #include "Eet_private.h" @@ -12,6 +14,22 @@ #undef HAVE_REALPATH #endif +#ifdef _WIN32 + +#ifndef F_SETFD +#define F_SETFD 2 +#endif + +#ifndef PROT_READ +#define PROT_READ 1 +#endif + +#ifndef FD_CLOEXEC +#define FD_CLOEXEC 1 +#endif + +#endif + #define EET_MAGIC_FILE 0x1ee7ff00 #define EET_MAGIC_FILE_HEADER 0x1ee7ff01 @@ -471,6 +489,9 @@ eet_open(const char *file, Eet_File_Mode mode) { Eet_File *ef; struct stat file_stat; +#ifdef _WIN32 + HANDLE h; +#endif if (!file) return NULL; @@ -558,7 +579,15 @@ eet_open(const char *file, Eet_File_Mode mode) if (eet_test_close(!ef->fp, ef)) return NULL; +#ifndef _WIN32 fcntl(fileno(ef->fp), F_SETFD, FD_CLOEXEC); +#else + /* FIXME: check if that code is needed / correct */ + h = (HANDLE) _get_osfhandle (fileno(ef->fp)); + if (h == (HANDLE) -1) + return NULL; + SetHandleInformation (h, HANDLE_FLAG_INHERIT, 0); +#endif /* if we opened for read or read-write */ if ((mode == EET_FILE_MODE_READ) || (mode == EET_FILE_MODE_READ_WRITE)) { @@ -568,10 +597,29 @@ eet_open(const char *file, Eet_File_Mode mode) int num_entries; int byte_entries; int i; +#ifdef _WIN32 + HANDLE fm; +#endif + ef->data_size = file_stat.st_size; +#ifndef _WIN32 ef->data = mmap(NULL, ef->data_size, PROT_READ, MAP_SHARED, fileno(ef->fp), 0); +#else + fm = CreateFileMapping((HANDLE) _get_osfhandle (fileno(ef->fp)), + NULL, + PAGE_READONLY, + 0, + 0, + NULL); + ef->data = MapViewOfFile(fm, + FILE_MAP_READ, + 0, + 0, + ef->data_size); + CloseHandle(fm); +#endif if (eet_test_close((ef->data == (void *)-1) || (ef->data == NULL), ef)) return NULL; @@ -825,7 +873,11 @@ eet_close(Eet_File *ef) } free(ef->header); } +#ifndef _WIN32 if (ef->data) munmap(ef->data, ef->data_size); +#else + if (ef->data) UnmapViewOfFile (ef->data); +#endif if (ef->fp) fclose(ef->fp); /* zero out ram for struct - caution tactic against stale memory use */