summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/asprintf.c2
-rw-r--r--lib/memmem.c49
-rw-r--r--lib/os_internal.h85
-rw-r--r--lib/os_types.h111
-rw-r--r--lib/strndup.c60
-rw-r--r--lib/strsep.c98
-rw-r--r--lib/strtok_r.c8
-rw-r--r--lib/timedlock.c33
9 files changed, 289 insertions, 160 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 36b695bc8..931c411ac 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,10 +1,11 @@
include $(top_srcdir)/misc/Makefile.common
+AM_CFLAGS = $(DEFAULT_OCFLAGS)
+
EXTRA_DIST = Makefile.common
noinst_LTLIBRARIES = libxineposix.la
noinst_HEADERS = os_internal.h
-xineinclude_HEADERS = os_types.h
libxineposix_la_SOURCES =
libxineposix_la_LIBADD = @LTLIBOBJS@
diff --git a/lib/asprintf.c b/lib/asprintf.c
index 6c9d90664..1027e82dd 100644
--- a/lib/asprintf.c
+++ b/lib/asprintf.c
@@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*/
diff --git a/lib/memmem.c b/lib/memmem.c
new file mode 100644
index 000000000..75a989d94
--- /dev/null
+++ b/lib/memmem.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 1991,92,93,94,96,97,98,2000,2004,2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program 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, or (at your option)
+ any later version.
+
+ This program 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 this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+
+#include <stddef.h>
+#include <string.h>
+
+/* Return the first occurrence of NEEDLE in HAYSTACK. */
+void *xine_private_memmem (const void *haystack, size_t haystack_len,
+ const void *needle, size_t needle_len)
+{
+ const char *begin;
+ const char *const last_possible
+ = (const char *) haystack + haystack_len - needle_len;
+
+ if (needle_len == 0)
+ /* The first occurrence of the empty string is deemed to occur at
+ the beginning of the string. */
+ return (void *) haystack;
+
+ /* Sanity check, otherwise the loop might search through the whole
+ memory. */
+ if (haystack_len < needle_len)
+ return NULL;
+
+ for (begin = (const char *) haystack; begin <= last_possible; ++begin)
+ if (begin[0] == ((const char *) needle)[0] &&
+ !memcmp ((const void *) &begin[1],
+ (const void *) ((const char *) needle + 1),
+ needle_len - 1))
+ return (void *) begin;
+
+ return NULL;
+}
diff --git a/lib/os_internal.h b/lib/os_internal.h
index 8ecfbaeab..873c4c3b7 100644
--- a/lib/os_internal.h
+++ b/lib/os_internal.h
@@ -1,6 +1,69 @@
#ifndef _XINE_OS_INTERNAL_H
#define _XINE_OS_INTERNAL_H
+/* When using Apple's GCC, __APPLE__ will be defined. This is a whole lot of
+ * messiness, but it's necessary in order to perform universal builds properly.
+ * It's meant to over-ride configure time stuff that would be different at
+ * compile time.
+ */
+#if defined(__APPLE__) && defined(XINE_MACOSX_UNIVERSAL_BINARY)
+
+/* __ppc__, __ppc64__, __i386__, __x86_64__ are interesting arch macros */
+#undef HOST_ARCH
+#if defined(__ppc__) || defined(__ppc64__)
+#define ARCH_PPC
+#if defined(__ppc64__)
+#define HOST_ARCH "darwin/powerpc64"
+#else
+#define HOST_ARCH "darwin/powerpc"
+#endif
+#elif defined(__i386__) || defined(__x86_64__)
+#define ARCH_X86
+#define BITFIELD_LSBF
+#define HAVE_MMX
+#if defined(__x86_64__)
+#define ARCH_X86_64
+#define HOST_ARCH "darwin/x86_64"
+#elif defined(__i386__)
+#define ARCH_X86_32
+#define HOST_ARCH "darwin/x86_32"
+#else
+#error unrecognized/unsupported CPU type building for Apple Darwin
+#endif
+#endif
+
+/* See /Developer/SDKs/MacOSX10.4u.sdk/usr/include/machine/limits.h */
+#if SIZEOF_INT != 4
+#undef SIZEOF_INT
+#define SIZEOF_INT 4
+#endif
+
+#if defined(__LP64__) && SIZEOF_LONG != 8
+#undef SIZEOF_LONG
+#define SIZEOF_LONG 8
+#elif !defined(__LP64__) && SIZEOF_LONG != 4
+#undef SIZEOF_LONG
+#define SIZEOF_LONG 4
+#endif
+
+/* WORDS_BIGENDIAN (replaces AC_C_BIGENDIAN autoconf test at compile time) */
+#include <machine/endian.h>
+#if BYTE_ORDER == BIG_ENDIAN
+#define WORDS_BIGENDIAN 1
+#else
+#undef WORDS_BIGENDIAN
+#endif
+
+#if defined(__LP64__)
+#define FPM_64BIT 1
+#elif defined(__ppc__) || defined(__ppc64__)
+#define FPM_PPC 1
+#elif defined(__i386__) || defined(__x86_64__)
+#define FPM_INTEL 1
+#endif
+
+#endif /* __APPLE__ */
+
#include <stddef.h>
#include <stdarg.h>
@@ -17,6 +80,8 @@
#endif
#include <inttypes.h>
+#include <pthread.h>
+#include <xine/attributes.h>
#if defined(WIN32) || defined(__CYGWIN__)
@@ -120,8 +185,8 @@ void xine_private_unsetenv(const char *name);
#define asprintf(STRINGPP, FORMAT, ...) xine_private_asprintf((STRINGPP), FORMAT, __VA_ARGS__)
#endif
#define vasprintf(STRINGPP, FORMAT, VA_ARG) xine_private_vasprintf((STRINGPP), (FORMAT), (VA_ARG))
-int xine_private_asprintf(char **string, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
-int xine_private_vasprintf(char **string, const char *format, va_list ap) __attribute__ ((format (printf, 2, 0)));
+int xine_private_asprintf(char **string, const char *format, ...) XINE_FORMAT_PRINTF(2, 3);
+int xine_private_vasprintf(char **string, const char *format, va_list ap) XINE_FORMAT_PRINTF(2, 0);
#endif
/* replacement of strndup */
@@ -131,6 +196,13 @@ int xine_private_vasprintf(char **string, const char *format, va_list ap) __attr
char *xine_private_strndup(const char *s, size_t n);
#endif
+/* replacement of pthread_mutex_timedlock */
+#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
+#define HAVE_PTHREAD_MUTEX_TIMEDLOCK
+#define pthread_mutex_timedlock(M, T) xine_private_pthread_mutex_timedlock((M), (T))
+int xine_private_pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout);
+#endif
+
/* handle non-standard function names */
#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
# define HAVE_SNPRINTF
@@ -267,4 +339,13 @@ void xine_private_rewinddir(DIR *);
#endif
+/* replacement of memmem */
+#ifndef HAVE_MEMMEM
+#define HAVE_MEMMEM
+#define memmem(H, HL, N, NL) \
+ xine_private_memmem((H), (HL), (N), (NL))
+void *xine_private_memmem (const void *haystack, size_t haystack_len,
+ const void *needle, size_t needle_len);
+#endif
+
#endif
diff --git a/lib/os_types.h b/lib/os_types.h
deleted file mode 100644
index 0cee183cc..000000000
--- a/lib/os_types.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2004-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * $Id: os_types.h,v 1.5 2006/04/08 16:42:23 valtri Exp $ Ext
- *
- * Platform dependent types needed by public xine.h.
- * Types not needed by xine.h are specified in os_internal.h.
- *
- * Heavily based on os_types.h from OggVorbis (BSD License),
- * not tested on all platforms with xine.
- */
-
-#ifndef XINE_OS_TYPES_H
-#define XINE_OS_TYPES_H
-
-#if defined(_WIN32) && !defined(__GNUC__)
-
- /* MSVC/Borland */
- typedef __int8 int8_t;
- typedef unsigned __int8 uint8_t;
- typedef __int16 int16_t;
- typedef unsigned __int16 uint16_t;
- typedef __int32 int32_t;
- typedef unsigned __int32 uint32_t;
- typedef __int64 int64_t;
- typedef unsigned __int64 uint64_t;
-
-#elif defined(__MACOS__)
-
-# include <sys/types.h>
- typedef SInt8 int8_t;
- typedef UInt8 uint8_t;
- typedef SInt16 int16_t;
- typedef UInt16 uint16_t;
- typedef SInt32 int32_t;
- typedef UInt32 uint32_t;
- typedef SInt64 int64_t;
- typedef UInt64 uint64_t;
-
-#elif defined(__MACOSX__) /* MacOS X Framework build */
-
-# include <sys/types.h>
- typedef u_int8_t uint8_t;
- typedef u_int16_t uint16_t;
- typedef u_int32_t uint32_t;
- typedef u_int64_t uint64_t;
-
-#elif defined (__EMX__)
-
- /* OS/2 GCC */
- typedef signed char int8_t;
- typedef unsigned char uint8_t;
- typedef short int16_t;
- typedef unsigned short uint16_t;
- typedef int int32_t;
- typedef unsigned int uint32_t;
- typedef long long int64_t;
- typedef unsigned long long int64_t;
-
-#elif defined (DJGPP)
-
- /* DJGPP */
- typedef signed char int8_t;
- typedef unsigned char uint8_t;
- typedef short int16_t;
- typedef unsigned short uint16_t;
- typedef int int32_t;
- typedef unsigned int uint32_t;
- typedef long long int64_t;
- typedef unsigned long long uint64_t;
-
-#elif defined(R5900)
-
- /* PS2 EE */
- typedef signed char int8_t;
- typedef unsigned char uint8_t;
- typedef short int16_t;
- typedef unsigned short int16_t;
- typedef int int32_t;
- typedef unsigned uint32_t;
- typedef long int64_t;
- typedef unsigned long int64_t;
-
-#else
-
- /*
- * CygWin: _WIN32 & __GNUC__
- * BeOS: __BEOS__
- * Linux, Solaris, Mac and others
- */
-# include <inttypes.h>
-
-#endif
-
-#endif /* XINE_OS_TYPES_H */
diff --git a/lib/strndup.c b/lib/strndup.c
index 9f347db87..1e01aa018 100644
--- a/lib/strndup.c
+++ b/lib/strndup.c
@@ -1,16 +1,56 @@
+/* $NetBSD: strndup.c,v 1.4 2007/07/03 12:11:09 nakayama Exp $ */
+
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ * Modified for xine project.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
#include "config.h"
-#ifdef HAVE_STDLIB_H
+#include <errno.h>
#include <stdlib.h>
-#endif
-
#include <string.h>
-char *xine_private_strndup(const char *s, size_t n) {
- char *ret;
-
- ret = malloc (n + 1);
- strncpy(ret, s, n);
- ret[n] = '\0';
- return ret;
+char *
+xine_private_strndup(const char *str, size_t n)
+{
+ size_t len;
+ char *copy;
+
+ if (!str)
+ return (NULL);
+
+ for (len = 0; len < n && str[len]; len++)
+ continue;
+
+ if (!(copy = malloc(len + 1)))
+ return (NULL);
+ memcpy(copy, str, len);
+ copy[len] = '\0';
+ return (copy);
}
diff --git a/lib/strsep.c b/lib/strsep.c
index d63a12f56..3170e4867 100644
--- a/lib/strsep.c
+++ b/lib/strsep.c
@@ -1,36 +1,72 @@
-#include "config.h"
-#include <string.h>
-
-char *xine_private_strsep(char **stringp, const char *delim) {
- char *begin, *end;
+/* $OpenBSD: strsep.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
- begin = *stringp;
- if(begin == NULL)
- return NULL;
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
- if(delim[0] == '\0' || delim[1] == '\0') {
- char ch = delim[0];
-
- if(ch == '\0')
- end = NULL;
- else {
- if(*begin == ch)
- end = begin;
- else if(*begin == '\0')
- end = NULL;
- else
- end = strchr(begin + 1, ch);
- }
- }
- else
- end = strpbrk(begin, delim);
+#include "config.h"
+#include <string.h>
+#include <stdio.h>
- if(end) {
- *end++ = '\0';
- *stringp = end;
- }
- else
- *stringp = NULL;
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+xine_private_strsep(char **stringp, const char *delim)
+{
+ char *s;
+ const char *spanp;
+ int c, sc;
+ char *tok;
- return begin;
+ if ((s = *stringp) == NULL)
+ return (NULL);
+ for (tok = s;;) {
+ c = *s++;
+ spanp = delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = 0;
+ *stringp = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+ /* NOTREACHED */
}
diff --git a/lib/strtok_r.c b/lib/strtok_r.c
index cead029a2..8a5284a42 100644
--- a/lib/strtok_r.c
+++ b/lib/strtok_r.c
@@ -19,7 +19,7 @@ char *xine_private_strtok_r(char *s, const char *delim, char **ptrptr) {
else s = *ptrptr;
/* end of searching */
- if (!s || s == '\0') return NULL;
+ if (!s || !*s) return NULL;
/* cut the initial garbage */
cutlen = strspn(s, delim);
@@ -32,12 +32,12 @@ char *xine_private_strtok_r(char *s, const char *delim, char **ptrptr) {
}
next = s + toklen;
+ /* prepare next call */
+ *ptrptr = *next ? next + 1 : NULL;
+
/* cut current token */
*next = '\0';
- /* prepare next call */
- *ptrptr = next + 1;
-
/* return the token */
return s;
}
diff --git a/lib/timedlock.c b/lib/timedlock.c
new file mode 100644
index 000000000..997ef6235
--- /dev/null
+++ b/lib/timedlock.c
@@ -0,0 +1,33 @@
+#include "config.h"
+
+#include <errno.h>
+
+#define _x_min(a, b) ((a) < (b) ? (a) : (b))
+
+int xine_private_pthread_mutex_timedlock(pthread_mutex_t *mutex,
+ const struct timespec *abs_timeout)
+{
+ int pthread_rc;
+ struct timespec remaining, slept, ts;
+
+ remaining = *abs_timeout;
+ while ((pthread_rc = pthread_mutex_trylock(mutex)) == EBUSY) {
+ ts.tv_sec = 0;
+ ts.tv_nsec = (remaining.tv_sec > 0 ? 10000000
+ : _x_min(remaining.tv_nsec, 10000000));
+ nanosleep(&ts, &slept);
+ ts.tv_nsec -= slept.tv_nsec;
+ if (ts.tv_nsec <= remaining.tv_nsec) {
+ remaining.tv_nsec -= ts.tv_nsec;
+ }
+ else {
+ remaining.tv_sec--;
+ remaining.tv_nsec = (1000000 - (ts.tv_nsec - remaining.tv_nsec));
+ }
+ if (remaining.tv_sec < 0 || (!remaining.tv_sec && remaining.tv_nsec <= 0)) {
+ return ETIMEDOUT;
+ }
+ }
+
+ return pthread_rc;
+}