summaryrefslogtreecommitdiffstats
path: root/libdvdread-embedded/msvc/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'libdvdread-embedded/msvc/contrib')
-rw-r--r--libdvdread-embedded/msvc/contrib/dirent/dirent.c135
-rw-r--r--libdvdread-embedded/msvc/contrib/dirent/dirent.h32
-rw-r--r--libdvdread-embedded/msvc/contrib/dlfcn.c96
-rw-r--r--libdvdread-embedded/msvc/contrib/win32_cs.h40
4 files changed, 303 insertions, 0 deletions
diff --git a/libdvdread-embedded/msvc/contrib/dirent/dirent.c b/libdvdread-embedded/msvc/contrib/dirent/dirent.c
new file mode 100644
index 0000000..0eddd90
--- /dev/null
+++ b/libdvdread-embedded/msvc/contrib/dirent/dirent.c
@@ -0,0 +1,135 @@
+/*
+
+ Implementation of POSIX directory browsing functions and types for Win32.
+
+ Kevlin Henney (mailto:kevlin@acm.org), March 1997.
+
+ Copyright Kevlin Henney, 1997. All rights reserved.
+
+ Permission to use, copy, modify, and distribute this software and its
+ documentation for any purpose is hereby granted without fee, provided
+ that this copyright and permissions notice appear in all copies and
+ derivatives, and that no charge may be made for the software and its
+ documentation except to cover cost of distribution.
+
+ This software is supplied "as is" without express or implied warranty.
+
+ But that said, if there are any problems please get in touch.
+
+*/
+
+#include <dirent.h>
+#include <errno.h>
+#include <io.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef DIR
+
+struct DIR
+{
+ long handle; /* -1 for failed rewind */
+ struct _finddata_t info;
+ struct dirent result; /* d_name null iff first time */
+ char *name; /* NTBS */
+};
+
+#endif
+
+DIR *opendir(const char *name)
+{
+ DIR *dir = 0;
+
+ if(name && name[0])
+ {
+ size_t base_length = strlen(name);
+ const char *all = /* the root directory is a special case... */
+ strchr("/\\", name[base_length - 1]) ? "*" : "/*";
+
+ if((dir = malloc(sizeof *dir)) != 0 &&
+ (dir->name = malloc(base_length + strlen(all) + 1)) != 0)
+ {
+ strcat(strcpy(dir->name, name), all);
+
+ if((dir->handle = _findfirst(dir->name, &dir->info)) != -1)
+ {
+ dir->result.d_name = 0;
+ }
+ else /* rollback */
+ {
+ free(dir->name);
+ free(dir);
+ dir = 0;
+ }
+ }
+ else /* rollback */
+ {
+ free(dir);
+ dir = 0;
+ errno = ENOMEM;
+ }
+ }
+ else
+ {
+ errno = EINVAL;
+ }
+
+ return dir;
+}
+
+int closedir(DIR *dir)
+{
+ int result = -1;
+
+ if(dir)
+ {
+ if(dir->handle != -1)
+ {
+ result = _findclose(dir->handle);
+ }
+
+ free(dir->name);
+ free(dir);
+ }
+
+ if(result == -1) /* map all errors to EBADF */
+ {
+ errno = EBADF;
+ }
+
+ return result;
+}
+
+struct dirent *readdir(DIR *dir)
+{
+ struct dirent *result = 0;
+
+ if(dir && dir->handle != -1)
+ {
+ if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
+ {
+ result = &dir->result;
+ result->d_name = dir->info.name;
+ }
+ }
+ else
+ {
+ errno = EBADF;
+ }
+
+ return result;
+}
+
+void rewinddir(DIR *dir)
+{
+ if(dir && dir->handle != -1)
+ {
+ _findclose(dir->handle);
+ dir->handle = _findfirst(dir->name, &dir->info);
+ dir->result.d_name = 0;
+ }
+ else
+ {
+ errno = EBADF;
+ }
+}
diff --git a/libdvdread-embedded/msvc/contrib/dirent/dirent.h b/libdvdread-embedded/msvc/contrib/dirent/dirent.h
new file mode 100644
index 0000000..28a1773
--- /dev/null
+++ b/libdvdread-embedded/msvc/contrib/dirent/dirent.h
@@ -0,0 +1,32 @@
+/*
+
+ Declaration of POSIX directory browsing functions and types for Win32.
+
+ Kevlin Henney (mailto:kevlin@acm.org), March 1997.
+
+ Copyright Kevlin Henney, 1997. All rights reserved.
+
+ Permission to use, copy, modify, and distribute this software and its
+ documentation for any purpose is hereby granted without fee, provided
+ that this copyright and permissions notice appear in all copies and
+ derivatives, and that no charge may be made for the software and its
+ documentation except to cover cost of distribution.
+
+*/
+
+#ifndef DIRENT_INCLUDED
+#define DIRENT_INCLUDED
+
+typedef struct DIR DIR;
+
+struct dirent
+{
+ char *d_name;
+};
+
+DIR *opendir(const char *);
+int closedir(DIR *);
+struct dirent *readdir(DIR *);
+void rewinddir(DIR *);
+
+#endif
diff --git a/libdvdread-embedded/msvc/contrib/dlfcn.c b/libdvdread-embedded/msvc/contrib/dlfcn.c
new file mode 100644
index 0000000..01b5781
--- /dev/null
+++ b/libdvdread-embedded/msvc/contrib/dlfcn.c
@@ -0,0 +1,96 @@
+/*
+ * 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 "../include/dlfcn.h"
+#include "../include/os_types.h"
+
+void *dlopen(const char *module_name, int mode)
+{
+ UINT em;
+ HINSTANCE dsoh;
+ char path[MAX_PATH], *p;
+ (void)mode;
+ /* 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);
+ path[MAX_PATH - 1] = 0;
+ 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);
+}
diff --git a/libdvdread-embedded/msvc/contrib/win32_cs.h b/libdvdread-embedded/msvc/contrib/win32_cs.h
new file mode 100644
index 0000000..cb29bac
--- /dev/null
+++ b/libdvdread-embedded/msvc/contrib/win32_cs.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of libdvdread.
+ *
+ * libdvdread is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * libdvdread is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with libdvdread; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <windows.h>
+
+static inline wchar_t *_utf8_to_wchar(const char *utf8)
+{
+ wchar_t *wstr;
+ int wlen;
+
+ wlen = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
+ if (wlen < 1) {
+ return NULL;
+ }
+ wstr = (wchar_t*)malloc(sizeof(wchar_t) * wlen);
+ if (!wstr ) {
+ return NULL;
+ }
+ if (!MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, wlen)) {
+ free(wstr);
+ return NULL;
+ }
+ return wstr;
+}