Mercurial > libdvdnav.hg
changeset 233:59b5753b09d7 src
Add support for building under MINGW.
author | jcdutton |
---|---|
date | Sun, 01 Feb 2004 17:55:19 +0000 |
parents | b50d37567f61 |
children | fcda42e1ffaa |
files | dvdread/Makefile.am dvdread/dlfcn.c dvdread/dlfcn.h dvdread/dvd_input.c dvdread/dvd_reader.c dvdread/dvd_reader.h dvdread/dvd_udf.c |
diffstat | 7 files changed, 149 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/dvdread/Makefile.am Sun Feb 01 00:44:43 2004 +0000 +++ b/dvdread/Makefile.am Sun Feb 01 17:55:19 2004 +0000 @@ -7,7 +7,7 @@ noinst_LTLIBRARIES = libdvdread.la libdvdread_la_SOURCES = dvd_reader.c nav_read.c ifo_read.c \ - dvd_input.c dvd_udf.c md5.c nav_print.c ifo_print.c + dvd_input.c dvd_udf.c md5.c nav_print.c ifo_print.c libdvdread_la_LIBADD = $(DYNAMIC_LD_LIBS)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dvdread/dlfcn.c Sun Feb 01 17:55:19 2004 +0000 @@ -0,0 +1,96 @@ +/* + * $Id$ + * $Name$ + * + * Adopted from Apache DSO code. + * Portions copyright Apache Software Foundation + * + * Structures and types used to implement dlopen, dlsym, etc. + * on Windows 95/NT. + */ +#include <windows.h> +#include <string.h> +#include <stdio.h> + +#include "dlfcn.h" + +void *dlopen(const char *module_name, int mode) +{ + UINT em; + HINSTANCE dsoh; + char path[MAX_PATH], *p; + /* Load the module... + * per PR2555, the LoadLibraryEx function is very picky about slashes. + * Debugging on NT 4 SP 6a reveals First Chance Exception within NTDLL. + * LoadLibrary in the MS PSDK also reveals that it -explicitly- states + * that backslashes must be used. + * + * Transpose '\' for '/' in the filename. + */ + (void)strncpy(path, module_name, MAX_PATH); + p = path; + while (p = strchr(p, '/')) + *p = '\\'; + + /* First assume the dso/dll's required by -this- dso are sitting in the + * same path or can be found in the usual places. Failing that, let's + * let that dso look in the apache root. + */ + em = SetErrorMode(SEM_FAILCRITICALERRORS); + dsoh = LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!dsoh) + { + SetLastError(0); // clear the last error + dsoh = LoadLibraryEx(path, NULL, 0); + } + SetErrorMode(em); + SetLastError(0); // clear the last error + return (void *)dsoh; +} + +char *dlerror(void) +{ + int len, nErrorCode; + static char errstr[120]; + /* This is -not- threadsafe code, but it's about the best we can do. + * mostly a potential problem for isapi modules, since LoadModule + * errors are handled within a single config thread. + */ + + if((nErrorCode = GetLastError()) == 0) + return((char *)0); + + SetLastError(0); // clear the last error + len = snprintf(errstr, sizeof(errstr), "(%d) ", nErrorCode); + + len += FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + nErrorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ + (LPTSTR) errstr + len, + sizeof(errstr) - len, + NULL + ); + /* FormatMessage may have appended a newline (\r\n). So remove it + * and use ": " instead like the Unix errors. The error may also + * end with a . before the return - if so, trash it. + */ + if (len > 1 && errstr[len-2] == '\r' && errstr[len-1] == '\n') { + if (len > 2 && errstr[len-3] == '.') + len--; + errstr[len-2] = ':'; + errstr[len-1] = ' '; + } + return errstr; +} + +int dlclose(void *handle) +{ + return FreeLibrary(handle); +} + +void *dlsym(void *handle, const char *name) +{ + return GetProcAddress(handle, name); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dvdread/dlfcn.h Sun Feb 01 17:55:19 2004 +0000 @@ -0,0 +1,23 @@ +#ifndef __DLFCN_H__ +# define __DLFCN_H__ +/* + * $Id$ + * $Name$ + * + * + */ +extern void *dlopen (const char *file, int mode); +extern int dlclose (void *handle); +extern void *dlsym (void * handle, const char * name); +extern char *dlerror (void); + +/* These don't mean anything on windows */ +#define RTLD_NEXT ((void *) -1l) +#define RTLD_DEFAULT ((void *) 0) +#define RTLD_LAZY -1 +#define RTLD_NOW -1 +#define RTLD_BINDING_MASK -1 +#define RTLD_NOLOAD -1 +#define RTLD_GLOBAL -1 + +#endif /* __DLFCN_H__ */
--- a/dvdread/dvd_input.c Sun Feb 01 00:44:43 2004 +0000 +++ b/dvdread/dvd_input.c Sun Feb 01 17:55:19 2004 +0000 @@ -24,13 +24,18 @@ #include <fcntl.h> #include <unistd.h> +#ifdef HAVE_DLFCN_H #include <dlfcn.h> +#else +/* Only needed on MINGW at the moment */ +#include "dlfcn.c" +#endif #include "dvd_reader.h" #include "dvd_input.h" -#ifndef _MSC_VER +#ifndef WIN32 #define LIBDVDCSS_NAME = "libdvdcss.so.2" #else #define LIBDVDCSS_NAME = "libdvdcss.dll" @@ -172,7 +177,7 @@ } /* Open the device */ -#ifndef _MSC_VER +#ifndef WIN32 dev->fd = open(target, O_RDONLY | O_EXCL); #else dev->fd = open(target, O_RDONLY | O_BINARY); @@ -290,7 +295,7 @@ #else /* dlopening libdvdcss */ -#ifndef _MSC_VER +#ifndef WIN32 dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY); #else dvdcss_library = dlopen("libdvdcss.dll", RTLD_LAZY);
--- a/dvdread/dvd_reader.c Sun Feb 01 00:44:43 2004 +0000 +++ b/dvdread/dvd_reader.c Sun Feb 01 17:55:19 2004 +0000 @@ -31,6 +31,22 @@ #include <unistd.h> #include <limits.h> #include <dirent.h> + +/* misc win32 helpers */ +#ifdef WIN32 +/* replacement gettimeofday implementation */ +#include <sys/timeb.h> +static inline int gettimeofday( struct timeval *tv, void *tz ) +{ + struct timeb t; + ftime( &t ); + tv->tv_sec = t.time; + tv->tv_usec = t.millitm * 1000; + return 0; +} +#include <io.h> /* read() */ +#define lseek64 _lseeki64 +#endif #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__)|| defined(__DARWIN__) #define SYS_BSD 1 @@ -51,10 +67,6 @@ #define DEFAULT_UDF_CACHE_LEVEL 1 -#ifdef _MSC_VER -#define fchdir chdir -#endif - struct dvd_reader_s { /* Basic information. */ int isImageFile; @@ -386,6 +398,9 @@ return 0; } +#ifndef WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */ + /* Also WIN32 does not have symlinks, so we don't need this bit of code. */ + /* Resolve any symlinks and get the absolut dir name. */ { char *new_path; @@ -402,7 +417,7 @@ } } } - +#endif /** * If we're being asked to open a directory, check if that directory * is the mountpoint for a DVD-ROM which we can use instead.
--- a/dvdread/dvd_reader.h Sun Feb 01 00:44:43 2004 +0000 +++ b/dvdread/dvd_reader.h Sun Feb 01 17:55:19 2004 +0000 @@ -29,6 +29,7 @@ #endif #include <sys/types.h> +#include <inttypes.h> /** * The DVD access interface.
--- a/dvdread/dvd_udf.c Sun Feb 01 00:44:43 2004 +0000 +++ b/dvdread/dvd_udf.c Sun Feb 01 17:55:19 2004 +0000 @@ -34,10 +34,6 @@ #include <stdlib.h> #include <string.h> -#ifndef _MSC_VER -#include <sys/ioctl.h> -#endif /* _MSC_VER */ - #include <sys/types.h> #include <sys/stat.h> #include <unistd.h>