fix compilation with MinGW

SVN revision: 28080
This commit is contained in:
doursse 2007-01-20 15:20:23 +00:00 committed by doursse
parent d4014861d6
commit 9373a62203
5 changed files with 69 additions and 7 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -6,7 +6,7 @@
#ifdef EAPI
#undef EAPI
#endif
#ifdef WIN32
#ifdef _MSC_VER
# ifdef BUILDING_DLL
# define EAPI __declspec(dllexport)
# else

View File

@ -3,7 +3,9 @@
*/
#include <sys/types.h>
#ifndef _WIN32
#include <sys/mman.h>
#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 */