From fa2d1c9a69ced48a070320857df2298b795ae0c4 Mon Sep 17 00:00:00 2001 From: al Date: Mon, 26 Dec 2005 03:16:48 +0000 Subject: [PATCH] - move our setenv() fallback implementation to osdep - assert that the override param is nonzero (zero is not implemented) - correct return value type to int based on a patch by Diego fixes bugzilla bug #342 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@17246 b3059339-0415-0410-9bf9-f77b7e298cf2 --- configure | 21 +++++++++++++++++++++ libao2/ao_sdl.c | 16 ---------------- libvo/vo_sdl.c | 16 ---------------- osdep/Makefile | 2 +- osdep/setenv.c | 29 +++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 osdep/setenv.c diff --git a/configure b/configure index bef47f069a..5e1116254e 100755 --- a/configure +++ b/configure @@ -3304,6 +3304,21 @@ fi echores "$_glob" +echocheck "setenv()" +cat > $TMPC << EOF +#include +int main (void){ setenv("","",0); return 0; } +EOF +_setenv=no +cc_check && _setenv=yes +if test "$_setenv" = yes ; then + _def_setenv='#define HAVE_SETENV 1' +else + _def_setenv='#undef HAVE_SETENV' +fi +echores "$_setenv" + + echocheck "sys/sysinfo.h" cat > $TMPC << EOF #include @@ -7480,6 +7495,12 @@ $_def_gettimeofday /* Define this if your system has glob */ $_def_glob +/* Define this if your system has setenv */ +$_def_setenv +#ifndef HAVE_SETENV +int setenv(const char *name, const char *val, int overwrite); +#endif + /* Define this if your system has pthreads */ $_def_pthreads diff --git a/libao2/ao_sdl.c b/libao2/ao_sdl.c index d2e506cf55..7c079d2e06 100644 --- a/libao2/ao_sdl.c +++ b/libao2/ao_sdl.c @@ -122,22 +122,6 @@ static int read_buffer(unsigned char* data,int len){ // end ring buffer stuff -#if defined(__MINGW32__) || defined(HPUX) || defined(sgi) || (defined(sun) && defined(__svr4__)) -/* setenv is missing on win32, solaris, IRIX and HPUX */ -static void setenv(const char *name, const char *val, int _xx) -{ - int len = strlen(name) + strlen(val) + 2; - char *env = malloc(len); - - if (env != NULL) { - strcpy(env, name); - strcat(env, "="); - strcat(env, val); - putenv(env); - } -} -#endif - // to set/get/query special features/parameters static int control(int cmd,void *arg){ diff --git a/libvo/vo_sdl.c b/libvo/vo_sdl.c index 2d64e0c06c..078951d474 100644 --- a/libvo/vo_sdl.c +++ b/libvo/vo_sdl.c @@ -138,22 +138,6 @@ LIBVO_EXTERN(sdl) #include //#include -#if defined(__MINGW32__) || defined(HPUX) || defined(sgi) || (defined(sun) && defined(__svr4__)) -/* setenv is missing on win32, solaris, IRIX and HPUX */ -static void setenv(const char *name, const char *val, int _xx) -{ - int len = strlen(name) + strlen(val) + 2; - char *env = malloc(len); - - if (env != NULL) { - strcpy(env, name); - strcat(env, "="); - strcat(env, val); - putenv(env); - } -} -#endif - #ifdef SDL_ENABLE_LOCKS #define SDL_OVR_LOCK(x) if (SDL_LockYUVOverlay (priv->overlay)) { \ diff --git a/osdep/Makefile b/osdep/Makefile index 0cc5c2bbda..341da0d9eb 100644 --- a/osdep/Makefile +++ b/osdep/Makefile @@ -4,7 +4,7 @@ include ../config.mak LIBNAME = libosdep.a SRCS= shmem.c strsep.c strl.c vsscanf.c scandir.c gettimeofday.c fseeko.c \ - swab.c + swab.c setenv.c # timer.c getch = getch2.c diff --git a/osdep/setenv.c b/osdep/setenv.c new file mode 100644 index 0000000000..e0ef9a35bc --- /dev/null +++ b/osdep/setenv.c @@ -0,0 +1,29 @@ +/* setenv implementation for systems lacking it. */ + +#include "../config.h" + +#ifndef HAVE_SETENV + +#include +#include +#ifndef MP_DEBUG + #define NDEBUG +#endif +#include + +int setenv(const char *name, const char *val, int overwrite) +{ + int len = strlen(name) + strlen(val) + 2; + char *env = malloc(len); + if (!env) { return -1; } + + assert(overwrite != 0); + + strcpy(env, name); + strcat(env, "="); + strcat(env, val); + putenv(env); + + return 0; +} +#endif