[xiph-commits] r16860 - trunk/ao/src/plugins/esd

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sun Jan 31 02:42:33 PST 2010


Author: xiphmont
Date: 2010-01-31 02:42:33 -0800 (Sun, 31 Jan 2010)
New Revision: 16860

Modified:
   trunk/ao/src/plugins/esd/ao_esd.c
Log:
ao_esd was both putting an automatic into the environment during 
autodetest as well as failing to remove it when done.



Modified: trunk/ao/src/plugins/esd/ao_esd.c
===================================================================
--- trunk/ao/src/plugins/esd/ao_esd.c	2010-01-31 10:34:47 UTC (rev 16859)
+++ trunk/ao/src/plugins/esd/ao_esd.c	2010-01-31 10:42:33 UTC (rev 16860)
@@ -38,6 +38,8 @@
 #include <ao/ao.h>
 #include <ao/plugin.h>
 
+extern char **environ;
+
 static char *ao_esd_options[] = {"host","matrix","verbose","quiet","debug"};
 static ao_info ao_esd_info =
 {
@@ -59,14 +61,48 @@
 	char *host;
 } ao_esd_internal;
 
+/* An old favorite from the UNIX-hater's handbook.
+   two things worth noting:
+   1) 'not found' returns -1 with a zero errno
+   2) removed strings are freed
+*/
 
+int portable_unsetenv(char *name){
+  char **p = environ;
+  if(name){
+    if(strchr(name,'=')){
+      errno=EINVAL;
+      return -1;
+    }
+    while(*p){
+      char *pos = strchr(*p,'=');
+      if((pos && !strncmp(name,*p,(pos-*p))) ||
+         (!pos && !strcmp(name,*p))){
+        /* assume we can free it */
+        free(*p);
+        /* scrunch.  Not actually O bigger than moving last into the
+           slot as we need to scan the whole environment anyway */
+        do{
+          *p = *(p+1);
+          p++;
+        }while(*p);
+        return 0;
+      }
+      p++;
+    }
+  }
+  errno = 0;
+  return -1; /* not found */
+}
+
 int ao_plugin_test()
 {
 	int sock;
 
 	/* don't wake up the beast while detecting */
-	putenv("ESD_NO_SPAWN=1");
+	putenv(strdup("ESD_NO_SPAWN=1"));
 	sock = esd_open_sound(NULL);
+        portable_unsetenv("ESD_NO_SPAWN");
 	if (sock < 0)
 		return 0;
 	if (esd_get_standby_mode(sock) != ESM_RUNNING) {



More information about the commits mailing list