diff osdep/setenv.c @ 17245:44c24de55f9d

- 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
author al
date Mon, 26 Dec 2005 03:16:48 +0000
parents
children d0d487227d60
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/osdep/setenv.c	Mon Dec 26 03:16:48 2005 +0000
@@ -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