diff --git a/configure.ac b/configure.ac index 689b503b..56a02a0f 100644 --- a/configure.ac +++ b/configure.ac @@ -382,6 +382,8 @@ AC_CHECK_FUNCS( setpriority ) AC_CHECK_FUNCS( strerror ) +AC_CHECK_FUNCS( strdup ) + AC_CHECK_FUNCS( mkfifo, [ have_mkfifo=yes ], [ have_mkfifo=no ] ) if test $fifo = "auto"; then diff --git a/src/getlopt.c b/src/getlopt.c index 1b315bdb..2296886b 100644 --- a/src/getlopt.c +++ b/src/getlopt.c @@ -10,23 +10,13 @@ #include #include "config.h" #include "getlopt.h" +#include "compat.h" #include "debug.h" int loptind = 1; /* index in argv[] */ int loptchr = 0; /* index in argv[loptind] */ char *loptarg; /* points to argument if present, else to option */ -#if defined(ultrix) || defined(ULTRIX) -char *strdup (char *src) -{ - char *dest; - - if (!(dest = (char *) malloc(strlen(src)+1))) - return (NULL); - return (strcpy(dest, src)); -} -#endif - topt *findopt (int islong, char *opt, topt *opts) { if (!opts) diff --git a/src/libmpg123/compat.c b/src/libmpg123/compat.c index c081fe57..bb94aee4 100644 --- a/src/libmpg123/compat.c +++ b/src/libmpg123/compat.c @@ -1,7 +1,9 @@ /* - compat: Some compatibility functions. + compat: Some compatibility functions. Basic standard C stuff, that may barely be above/around C89. - copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1 + The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX. + + copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1 see COPYING and AUTHORS files in distribution or http://mpg123.org initially written by Thomas Orgis */ @@ -25,3 +27,15 @@ const char *strerror(int errnum) return (errnum < sys_nerr) ? sys_errlist[errnum] : ""; } #endif + +#ifndef HAVE_STRDUP +char *strdup(const char *src) +{ + char *dest; + + if (!(dest = (char *) malloc(strlen(src)+1))) + return NULL; + else + return strcpy(dest, src); +} +#endif diff --git a/src/libmpg123/compat.h b/src/libmpg123/compat.h index 41181244..44e77d2c 100644 --- a/src/libmpg123/compat.h +++ b/src/libmpg123/compat.h @@ -1,7 +1,11 @@ /* - compat: Some compatibility functions. + compat: Some compatibility functions. Basic standard C stuff, that may barely be above/around C89. - copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1 + The mpg123 code is determined to keep it's legacy. A legacy of old, old UNIX. + It is envisioned to include this compat header instead of any of the "standard" headers, to catch compatibility issues. + So, don't include stdlib.h or string.h ... include compat.h. + + copyright 2007-8 by the mpg123 project - free software under the terms of the LGPL 2.1 see COPYING and AUTHORS files in distribution or http://mpg123.org initially written by Thomas Orgis */ @@ -9,12 +13,24 @@ #ifndef MPG123_COMPAT_H #define MPG123_COMPAT_H +#include "config.h" + +#ifdef HAVE_STDLIB_H /* realloc, size_t */ #include +#endif + +#ifdef HAVE_STRING_H +#include +#endif void *safe_realloc(void *ptr, size_t size); #ifndef HAVE_STRERROR const char *strerror(int errnum); #endif +#ifndef HAVE_STRDUP +char *strdup(const char *s); +#endif + #endif