[MPlayer-dev-eng] [PATCH] move setenv implementation to osdep/

Alexander Strasser eclipse7 at gmx.net
Thu Oct 27 11:30:03 CEST 2005


Hi,

  maybe I am missing something fundamentally but
it did not work at all for me.
  Comments follow, i also attached an updated
patch. Not too well tested so comments and testers
appreciated.

Diego Biurrun wrote:
> On Thu, Oct 27, 2005 at 12:29:15AM +0200, Diego Biurrun wrote:
> > Attached patch should fix bug #342 and generally make sense by removing
> > code duplication.
> > 
> > Any glaring mistakes?  OK to commit?
>   ^^^^^^^^^^^^^^^^^^^^^
[...]
> Index: configure
> ===================================================================
> +/* Define this if your system has setenv */
> +$_def_setenv
> +

  I think the systems missing setenv don't have a
prototype in stdlib.h for it, so we need to provide
one else where.

[...]
> --- /dev/null	2005-10-26 22:03:01.101616344 +0200
> +++ osdep/setenv.c	2005-10-27 00:21:49.000000000 +0200
> @@ -0,0 +1,20 @@
> +/* setenv implementation for systems lacking setenv in stdlib.h. */
> +
> +#ifndef HAVE_SETENV
> +
> +#include <stdlib.h>
> +#include <string.h>
> +
> +static void setenv(const char *name, const char *val, int _xx)

  Static is not the appropriate keyword here. I also don't like
to have a different signature for setenv, at least on my system
it returns int. If this is not normally implemented that way
i take back this one.

> +{
> +    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

  Also completely ignoring the last parameter seems to be
a bad solution. I added an assert to assure it is always
nonzero so at least with debug builds one can notice there
is something wrong. 

  Alex (beastd)
-------------- next part --------------
Index: configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.1095
diff -u -r1.1095 configure
--- configure	25 Oct 2005 13:28:07 -0000	1.1095
+++ configure	27 Oct 2005 08:30:12 -0000
@@ -3304,6 +3304,21 @@
 echores "$_glob"
 
 
+echocheck "setenv()"
+cat > $TMPC << EOF
+#include <stdlib.h>
+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 <sys/sysinfo.h>
@@ -7384,6 +7399,12 @@
 /* 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
 
Index: libao2/ao_sdl.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_sdl.c,v
retrieving revision 1.41
diff -u -r1.41 ao_sdl.c
--- libao2/ao_sdl.c	27 Feb 2005 23:06:32 -0000	1.41
+++ libao2/ao_sdl.c	27 Oct 2005 08:30:12 -0000
@@ -122,22 +122,6 @@
 
 // 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){
Index: libvo/vo_sdl.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_sdl.c,v
retrieving revision 1.122
diff -u -r1.122 vo_sdl.c
--- libvo/vo_sdl.c	5 Aug 2005 01:24:36 -0000	1.122
+++ libvo/vo_sdl.c	27 Oct 2005 08:30:13 -0000
@@ -138,22 +138,6 @@
 #include <SDL.h>
 //#include <SDL/SDL_syswm.h>
 
-#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)) { \
Index: osdep/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/osdep/Makefile,v
retrieving revision 1.19
diff -u -r1.19 Makefile
--- osdep/Makefile	18 Aug 2005 11:26:04 -0000	1.19
+++ osdep/Makefile	27 Oct 2005 08:30:13 -0000
@@ -4,7 +4,7 @@
 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
--- /dev/null	2004-11-03 10:47:25.000000000 +0100
+++ osdep/setenv.c	2005-10-27 10:32:01.000000000 +0200
@@ -0,0 +1,29 @@
+/* setenv implementation for systems lacking it. */
+
+#include "../config.h"
+
+#ifndef HAVE_SETENV
+
+#include <stdlib.h>
+#include <string.h>
+#ifndef MP_DEBUG
+  #define NDEBUG
+#endif
+#include <assert.h>
+
+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


More information about the MPlayer-dev-eng mailing list