summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--configure.in4
-rw-r--r--src/actions.c80
3 files changed, 41 insertions, 53 deletions
diff --git a/ChangeLog b/ChangeLog
index ee96283..b829357 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-12-11 Shawn <sabetts@sfu.ca>
+
+ * configure.in (AC_CHECK_FUNCS): Add check for putenv, remove
+ check for setenv and unsetenv.
+
+ * src/actions.c (setenv): remove function
+ (unsetenv): likewise
+ (cmd_setenv): use putenv instead of setenv.
+ (cmd_unsetenv): likewise
+
2002-12-09 Shawn Betts <sabetts@sfu.ca>
* src/actions.c (spawn): only add DISPLAY to the environment if it
diff --git a/configure.in b/configure.in
index 97f9d94..1e0c528 100644
--- a/configure.in
+++ b/configure.in
@@ -17,7 +17,7 @@ dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
-dnl $Id: configure.in,v 1.31 2002/11/20 09:29:37 sabetts Exp $
+dnl $Id: configure.in,v 1.32 2002/12/11 20:35:17 sabetts Exp $
AC_INIT(src/main.c)
AM_INIT_AUTOMAKE(ratpoison, 1.2.0-cvs)
@@ -89,7 +89,7 @@ AC_CHECK_HEADERS(unistd.h stdarg.h)
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
-AC_CHECK_FUNCS(getopt getopt_long setsid setpgid setpgrp setenv unsetenv vsnprintf )
+AC_CHECK_FUNCS(getopt getopt_long setsid setpgid setpgrp putenv vsnprintf )
AC_TYPE_SIGNAL
diff --git a/src/actions.c b/src/actions.c
index bdb2b76..b46b16c 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -2128,50 +2128,11 @@ cmd_defbgcolor (int interactive, void *data)
return NULL;
}
-#if !defined(HAVE_SETENV) || !defined(setenv)
-/* For systems, such as Solaris, where setenv is not implemented
- * in libc */
-/* FIXME: overwrite has no effect in this implementation! */
-int
-setenv (const char *name, const char *value, int overwrite)
-{
- char *tmp;
- int i;
-
- tmp = (char *)malloc (strlen(name) + strlen(value) + 2);
- strcpy(tmp, name);
- strcat(tmp, "=");
- strcat(tmp, value);
-
- i = putenv(tmp);
-
- free(tmp);
-
- return i;
-}
-#endif
-
-#ifndef HAVE_UNSETENV
-/* For systems which lack unsetenv (eg, Solaris) */
-void
-unsetenv (const char *name)
-{
- char *tmp;
-
- tmp = (char *)malloc (strlen(name) + 2);
- strcpy (tmp, name);
- strcat (tmp, "=");
-
- putenv(tmp);
-
- free(tmp);
-}
-#endif
-
char *
cmd_setenv (int interactive, void *data)
{
- char *var, *string;
+ char *name, *value;
+ struct sbuf *env;
if (data == NULL)
{
@@ -2180,20 +2141,36 @@ cmd_setenv (int interactive, void *data)
}
/* Get the 2 arguments. */
- var = xmalloc (strlen (data) + 1);
- string = xmalloc (strlen (data) + 1);
- if (sscanf (data, "%s %s", var, string) < 2)
+ name = xmalloc (strlen (data) + 1);
+ value = xmalloc (strlen (data) + 1);
+ if (sscanf (data, "%s %s", name, value) < 2)
{
message (" setenv: Two arguments required ");
- free (var);
- free (string);
+ free (name);
+ free (value);
return NULL;
}
- setenv (var, string, 1);
+ /* Setup the environment string. */
+ env = sbuf_new(0);
+ sbuf_concat (env, name);
+ sbuf_concat (env, "=");
+ sbuf_concat (env, value);
+ free (name);
+ free (value);
+
+ /* Stick it in the environment. */
+ PRINT_DEBUG("%s\n", sbuf_get(env));
+ putenv (sbuf_get (env));
+
+ /* According to the docs, the actual string is placed in the
+ environment, not the data the string points to. This means
+ modifying the string (or freeing it) directly changes the
+ environment. So, don't free the environment string, just the sbuf
+ data structure. */
+ env->data = NULL;
+ sbuf_free (env);
- free (var);
- free (string);
return NULL;
}
@@ -2210,7 +2187,7 @@ cmd_getenv (int interactive, void *data)
return NULL;
}
- /* Get the 2 arguments. */
+ /* Get the argument. */
var = xmalloc (strlen (data) + 1);
if (sscanf (data, "%s", var) < 1)
{
@@ -2263,7 +2240,8 @@ cmd_unsetenv (int interactive, void *data)
return NULL;
}
- unsetenv ((char *)data);
+ /* Remove all instances of the env. var. */
+ putenv ((char *)data);
return NULL;
}