diff options
author | František Dvořák <valtri@users.sourceforge.net> | 2004-09-20 19:30:02 +0000 |
---|---|---|
committer | František Dvořák <valtri@users.sourceforge.net> | 2004-09-20 19:30:02 +0000 |
commit | 7204b84beb0f5cfb166e8d56402371d05bece83b (patch) | |
tree | 16b76662489bd637b04e06e5ee6ca1ea98186dec /lib | |
parent | 747ab57ec201661d72adfdf0ce538d728c0013c5 (diff) | |
download | xine-lib-7204b84beb0f5cfb166e8d56402371d05bece83b.tar.gz xine-lib-7204b84beb0f5cfb166e8d56402371d05bece83b.tar.bz2 |
Build system improvements:
- use replacement functions (macro AC_REPLACE_FUNCS and variable LTLIBOBJS),
each function is in a file placed into lib/ directory,
it was not necessary, but it looks nice, IMHO
- headers cleanups (this was needed):
- prototypes of replacement funtions and macros are placed
into separate os_internal.h (and included by config.h)
- drop include inttypes.h from public xine.h, replaced by custom
os_type.h, idea origins from Ogg/Vorbis public headers
- disable generating inttypes.h: generated replacement isn't enough for
xine-lib but nobody complained (and for M$VC we have special version)
- better including headers for win32, let dvdnav use its mutex wrapper
- updated M$VC port
Result:
- xine is compiled nicely by MinGW, CygWin and paritaly M$VC
- frontends in M$VC port don't require additional helping headers
- moved some platform specific things from xine-utils and win32/contrib
to lib/
Finally I can start with real coding. :-)
CVS patchset: 6982
CVS date: 2004/09/20 19:30:02
Diffstat (limited to 'lib')
-rw-r--r-- | lib/.cvsignore | 6 | ||||
-rw-r--r-- | lib/Makefile.am | 10 | ||||
-rw-r--r-- | lib/Makefile.common | 4 | ||||
-rw-r--r-- | lib/basename.c | 35 | ||||
-rw-r--r-- | lib/gettimeofday.c | 20 | ||||
-rw-r--r-- | lib/hstrerror.c | 24 | ||||
-rw-r--r-- | lib/os_internal.h | 68 | ||||
-rw-r--r-- | lib/os_types.h | 110 | ||||
-rw-r--r-- | lib/setenv.c | 21 | ||||
-rw-r--r-- | lib/strndup.c | 13 | ||||
-rw-r--r-- | lib/strpbrk.c | 15 | ||||
-rw-r--r-- | lib/strsep.c | 36 | ||||
-rw-r--r-- | lib/strtok_r.c | 43 |
13 files changed, 405 insertions, 0 deletions
diff --git a/lib/.cvsignore b/lib/.cvsignore new file mode 100644 index 000000000..7d926a554 --- /dev/null +++ b/lib/.cvsignore @@ -0,0 +1,6 @@ +Makefile +Makefile.in +.libs +.deps +*.lo +*.la diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 000000000..473333be1 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/misc/Makefile.common + +noinst_LTLIBRARIES = libxineposix.la + +noinst_HEADERS = os_internal.h + +include_HEADERS = os_types.h + +libxineposix_la_SOURCES = +libxineposix_la_LIBADD = @LTLIBOBJS@ diff --git a/lib/Makefile.common b/lib/Makefile.common new file mode 100644 index 000000000..c9dd5aab6 --- /dev/null +++ b/lib/Makefile.common @@ -0,0 +1,4 @@ +LIBXINEPOSIX=$(top_builddir)/lib/libxineposix.la + +$(LIBXINEPOSIX): + $(MAKE) -C $(top_builddir)/lib libxineposix.la diff --git a/lib/basename.c b/lib/basename.c new file mode 100644 index 000000000..06f859483 --- /dev/null +++ b/lib/basename.c @@ -0,0 +1,35 @@ +/* + * get base name + * + * (adopted from sh-utils) + */ + +#include "config.h" + +#define FILESYSTEM_PREFIX_LEN(filename) 0 +#define ISSLASH(C) ((C) == '/') + +char *_xine_private_basename(char *name) { + char const *base = name + FILESYSTEM_PREFIX_LEN (name); + char const *p; + + for (p = base; *p; p++) { + if (ISSLASH (*p)) { + /* Treat multiple adjacent slashes like a single slash. */ + do p++; + while (ISSLASH (*p)); + + /* If the file name ends in slash, use the trailing slash as + the basename if no non-slashes have been found. */ + if (! *p) { + if (ISSLASH (*base)) base = p - 1; + break; + } + + /* *P is a non-slash preceded by a slash. */ + base = p; + } + } + + return (char *)base; +} diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c new file mode 100644 index 000000000..fb31f12ef --- /dev/null +++ b/lib/gettimeofday.c @@ -0,0 +1,20 @@ +/* replacement function of gettimeofday */ + +#include "config.h" + +#include <sys/timeb.h> +#ifdef WIN32 +#include <winsock.h> +#else +#include <sys/time.h> +#endif + +int _xine_private_gettimeofday(struct timeval *tv) { + struct timeb tp; + + ftime(&tp); + tv->tv_sec = tp.time; + tv->tv_usec = tp.millitm * 1000; + + return 0; +} diff --git a/lib/hstrerror.c b/lib/hstrerror.c new file mode 100644 index 000000000..87f7f6411 --- /dev/null +++ b/lib/hstrerror.c @@ -0,0 +1,24 @@ +#include "config.h" + +#ifdef WIN32 +#include <winsock.h> +#else +#include <netdb.h> +#endif +#include <errno.h> + +#include "xineintl.h" + +/** + * get error descriptions in DNS lookups + */ +const char *_xine_private_hstrerror(int err) { + switch (err) { + case 0: return _("No error"); + case HOST_NOT_FOUND: return _("Unknown host"); + case NO_DATA: return _("No address associated with name"); + case NO_RECOVERY: return _("Unknown server error"); + case TRY_AGAIN: return _("Host name lookup failure"); + default: return _("Unknown error"); + } +} diff --git a/lib/os_internal.h b/lib/os_internal.h new file mode 100644 index 000000000..77aa7b4d0 --- /dev/null +++ b/lib/os_internal.h @@ -0,0 +1,68 @@ +#include <stddef.h> +#include "os_types.h" + +/* replacement of strndup */ +#ifndef HAVE_STRNDUP +#define strndup(S, N) _xine_private_strndup((S), (N)) +char *_xine_private_strndup(const char *s, size_t n); +#endif + +/* replacement of basename */ +#ifndef HAVE_BASENAME +#define basename(PATH) _xine_private_basename((PATH)) +char *_xine_private_basename(char *path); +#endif + +/* replacement of hstrerror */ +#ifndef HAVE_HSTRERROR +#define hstrerror(ERR) _xine_private_hstrerror((ERR)) +const char *_xine_private_hstrerror(int err); +#endif + +/* replacement of setenv */ +#ifndef HAVE_SETENV +#define setenv(NAME, VALUE, OVERWRITE) _xine_private_setenv((NAME), (VALUE)) +int _xine_private_setenv(const char *name, const char *value); +#endif + +/* replacement of strtok_r */ +#ifndef HAVE_STRTOK_R +#define strtok_r(S, DELIM, PTRPTR) _xine_private_strtok_r((S), (DELIM), (PTRPTR)) +char *_xine_private_strtok_r(char *s, const char *delim, char **ptrptr); +#endif + +/* replacement of gettimeofday */ +#ifndef HAVE_GETTIMEOFDAY +# ifdef WIN32 +# include <winsock.h> +# else +# include <sys/time.h> +# endif +# define gettimeofday(TV, TZ) _xine_private_gettimeofday((TV)) +int _xine_private_gettimeofday(struct timeval *tv); +#endif + +/* replacement of strpbrk */ +#ifndef HAVE_STRPBRK +#define strpbrk(S, ACCEPT) _xine_private_strpbrk((S), (ACCEPT)) +char *_xine_private_strpbrk(const char *s, const char *accept); +#endif + +/* replacement of strsep */ +#ifndef HAVE_STRSEP +#define strsep(STRINGP, DELIM) _xine_private_strsep((STRINGP), (DELIM)) +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 +#endif diff --git a/lib/os_types.h b/lib/os_types.h new file mode 100644 index 000000000..0a49a743d --- /dev/null +++ b/lib/os_types.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2004 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: + * + * Platform dependent types needed by public xine.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 and others + */ +# include <inttypes.h> + +#endif + +#endif /* XINE_OS_TYPES_H */ diff --git a/lib/setenv.c b/lib/setenv.c new file mode 100644 index 000000000..8087bd661 --- /dev/null +++ b/lib/setenv.c @@ -0,0 +1,21 @@ +#include "config.h" + +#include <stdlib.h> +#include <string.h> +#include <malloc.h> +#include <stdio.h> + +/* This function will leak a small amount of memory */ +int _xine_private_setenv(const char *name, const char *val) { + int len; + char *env; + + len = strlen(name) + strlen(val) + 2; + env = malloc(len); + if (env != NULL) { + snprintf(env, len, "%s=%s", name, val); + putenv(env); + return 0; + } else return -1; +} + diff --git a/lib/strndup.c b/lib/strndup.c new file mode 100644 index 000000000..f2caa70f2 --- /dev/null +++ b/lib/strndup.c @@ -0,0 +1,13 @@ +#include "config.h" + +#include <malloc.h> +#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; +} diff --git a/lib/strpbrk.c b/lib/strpbrk.c new file mode 100644 index 000000000..557c1a57b --- /dev/null +++ b/lib/strpbrk.c @@ -0,0 +1,15 @@ +#include <stddef.h> + +/* Shamefully copied from glibc 2.2.3 */ +char *_xine_private_strpbrk(const char *s, const char *accept) { + + while(*s != '\0') { + const char *a = accept; + while(*a != '\0') + if(*a++ == *s) + return(char *) s; + ++s; + } + + return NULL; +} diff --git a/lib/strsep.c b/lib/strsep.c new file mode 100644 index 000000000..101f9600d --- /dev/null +++ b/lib/strsep.c @@ -0,0 +1,36 @@ +#include "config.h" +#include <string.h> + +char *_xine_private_strsep(char **stringp, const char *delim) { + char *begin, *end; + + begin = *stringp; + if(begin == NULL) + return NULL; + + 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); + + if(end) { + *end++ = '\0'; + *stringp = end; + } + else + *stringp = NULL; + + return begin; +} diff --git a/lib/strtok_r.c b/lib/strtok_r.c new file mode 100644 index 000000000..733290422 --- /dev/null +++ b/lib/strtok_r.c @@ -0,0 +1,43 @@ +/* + * written for xine project, 2004 + * + * public domain replacement function for strtok_r() + * + */ + +#include "config.h" + +#include <stddef.h> +#include <string.h> + +char *_xine_private_strtok_r(char *s, const char *delim, char **ptrptr) { + char *next; + size_t toklen, cutlen; + + /* first or next call */ + if (s) *ptrptr = s; + else s = *ptrptr; + + /* end of searching */ + if (!s || s == '\0') return NULL; + + /* cut the initial garbage */ + cutlen = strspn(s, delim); + s = s + cutlen; + + /* pointer before next token */ + if ((toklen = strcspn(s, delim)) == 0) { + *ptrptr = NULL; + return NULL; + } + next = s + toklen; + + /* cut current token */ + *next = '\0'; + + /* prepare next call */ + *ptrptr = next + 1; + + /* return the token */ + return s; +} |