summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrantišek Dvořák <valtri@users.sourceforge.net>2005-08-25 15:36:29 +0000
committerFrantišek Dvořák <valtri@users.sourceforge.net>2005-08-25 15:36:29 +0000
commitf45651f26bc3aa1b312d282c5d8c4b04be0c2505 (patch)
tree7ff95ed1ee104e776559c7885539e1ff7a39fe97 /lib
parent21c4975cc49bbbeac0067aa0847b3604ea639676 (diff)
downloadxine-lib-f45651f26bc3aa1b312d282c5d8c4b04be0c2505.tar.gz
xine-lib-f45651f26bc3aa1b312d282c5d8c4b04be0c2505.tar.bz2
*BUGFIX*
Windows ports fixes and improvements due to my current work on toxine: - first experiments with external win32 pthreads, more portable code (pthread_t may be a struct) - headers refactored - moved dirent win32 replacement to lib/, hide it for frontends, used system version, if found, not used non-POSIX dirent->d_reclen (this item doesn't work in MinGW), fix memleak in dvb - separated settings for postproc and avcodec when using external ffmpeg - check for malloc.h in public xine.m4, used it conditionally in xine headers - replaced random() by POSIX more common rand() - prevent one segfault in directx vo plugin, if fails - M$VC port update CVS patchset: 7709 CVS date: 2005/08/25 15:36:29
Diffstat (limited to 'lib')
-rw-r--r--lib/dirent_msvc.c137
-rw-r--r--lib/os_internal.h91
-rw-r--r--lib/setenv.c1
-rw-r--r--lib/strndup.c4
4 files changed, 223 insertions, 10 deletions
diff --git a/lib/dirent_msvc.c b/lib/dirent_msvc.c
new file mode 100644
index 000000000..e36d7402c
--- /dev/null
+++ b/lib/dirent_msvc.c
@@ -0,0 +1,137 @@
+/*
+
+ 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 "config.h"
+#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 *_xine_private_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 = (DIR *) malloc(sizeof *dir)) != 0 &&
+ (dir->name = (char *) 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 _xine_private_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 *_xine_private_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;
+ result->d_reclen = strlen(dir->info.name);
+ }
+ }
+ else
+ {
+ errno = EBADF;
+ }
+
+ return result;
+}
+
+void _xine_private_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/lib/os_internal.h b/lib/os_internal.h
index 2f6d19779..24d810ffd 100644
--- a/lib/os_internal.h
+++ b/lib/os_internal.h
@@ -1,3 +1,6 @@
+#ifndef _XINE_OS_INTERNAL_H
+#define _XINE_OS_INTERNAL_H
+
#include <stddef.h>
#include "os_types.h"
@@ -67,15 +70,93 @@ char *_xine_private_strpbrk(const char *s, const char *accept);
char *_xine_private_strsep(char **stringp, const char *delim);
#endif
-/* replacing lstat by stat */
-#ifndef HAVE_LSTAT
-# define lstat(FILENAME, BUF) stat((FILENAME), (BUF))
-#endif
-
/* macross needed for MSVC */
#ifdef _MSC_VER
# define snprintf _snprintf
# define vsnprintf _vsnprintf
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
+# define M_PI 3.14159265358979323846
+#endif
+
+#ifdef WIN32
+#include <io.h>
+# define mkdir(A, B) _mkdir((A))
+
+# ifndef S_ISDIR
+# define S_ISDIR(m) ((m) & _S_IFDIR)
+# endif
+
+# ifndef S_ISREG
+# define S_ISREG(m) ((m) & _S_IFREG)
+# endif
+
+# ifndef S_ISBLK
+# define S_ISBLK(m) 0
+# endif
+
+# ifndef S_ISCHR
+# define S_ISCHR(m) 0
+# endif
+
+# ifndef S_ISLNK
+# define S_ISLNK(mode) 0
+# endif
+
+# ifndef S_ISSOCK
+# define S_ISSOCK(mode) 0
+# endif
+
+# ifndef S_ISFIFO
+# define S_ISFIFO(mode) 0
+# endif
+
+# ifndef S_IXUSR
+# define S_IXUSR S_IEXEC
+# endif
+
+# ifndef S_IXGRP
+# define S_IXGRP S_IEXEC
+# endif
+
+# ifndef S_IXOTH
+# define S_IXOTH S_IEXEC
+# endif
+
+# if !S_IXUGO
+# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
+# endif
+
+#endif
+
+#ifndef HAVE_READLINK
+# define readlink(PATH, BUF, BUFSIZE) 0
+#endif
+
+/* replacing lstat by stat */
+#ifndef HAVE_LSTAT
+# define lstat(FILENAME, BUF) stat((FILENAME), (BUF))
+#endif
+
+/* replacements of dirent for MSVC platform */
+#ifndef HAVE_OPENDIR
+typedef struct DIR DIR;
+
+struct dirent {
+ unsigned short d_reclen;
+ char *d_name;
+};
+
+DIR *_xine_private_opendir(const char *);
+int _xine_private_closedir(DIR *);
+struct dirent *_xine_private_readdir(DIR *);
+void _xine_private_rewinddir(DIR *);
+
+#define opendir(DIRENT_NAME) _xine_private_opendir((DIRENT_NAME))
+#define closedir(DIRENT_DIR) _xine_private_closedir((DIRENT_DIR))
+#define readdir(DIRENT_DIR) _xine_private_readdir((DIRENT_DIR))
+#define rewinddir(DIRENT_DIR) _xine_private_rewinddir((DIRENT_DIR))
+
+#endif
+
#endif
diff --git a/lib/setenv.c b/lib/setenv.c
index 8087bd661..4f861937f 100644
--- a/lib/setenv.c
+++ b/lib/setenv.c
@@ -2,7 +2,6 @@
#include <stdlib.h>
#include <string.h>
-#include <malloc.h>
#include <stdio.h>
/* This function will leak a small amount of memory */
diff --git a/lib/strndup.c b/lib/strndup.c
index ab7c44626..0f5e4142c 100644
--- a/lib/strndup.c
+++ b/lib/strndup.c
@@ -1,9 +1,5 @@
#include "config.h"
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif