diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/memmem.c | 49 | ||||
-rw-r--r-- | lib/os_internal.h | 80 | ||||
-rw-r--r-- | lib/timedlock.c | 33 |
4 files changed, 164 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 36b695bc8..c6462037e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,5 +1,7 @@ include $(top_srcdir)/misc/Makefile.common +AM_CFLAGS = $(DEFAULT_OCFLAGS) + EXTRA_DIST = Makefile.common noinst_LTLIBRARIES = libxineposix.la diff --git a/lib/memmem.c b/lib/memmem.c new file mode 100644 index 000000000..1cbe629bd --- /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_internal_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 5f61fb84d..81b5ec8c5 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,7 @@ #endif #include <inttypes.h> +#include <pthread.h> #include "../src/xine-utils/attributes.h" @@ -132,6 +196,13 @@ int xine_private_vasprintf(char **string, const char *format, va_list ap) XINE_F 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 @@ -268,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_internal_memmem (const void *haystack, size_t haystack_len, + const void *needle, size_t needle_len); +#endif + #endif 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; +} |