summaryrefslogtreecommitdiffstats
path: root/otherlibs/unix/putenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs/unix/putenv.c')
-rw-r--r--otherlibs/unix/putenv.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/otherlibs/unix/putenv.c b/otherlibs/unix/putenv.c
new file mode 100644
index 000000000..0e5accc4b
--- /dev/null
+++ b/otherlibs/unix/putenv.c
@@ -0,0 +1,43 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 1998 Institut National de Recherche en Informatique et */
+/* Automatique. Distributed only by permission. */
+/* */
+/***********************************************************************/
+
+/* $Id$ */
+
+#include <memory.h>
+#include <mlvalues.h>
+#include <str.h>
+#include "unixsupport.h"
+
+#ifdef HAS_PUTENV
+
+#include <stdlib.h>
+#include <string.h>
+
+value unix_putenv(value name, value val) /* ML */
+{
+ mlsize_t namelen = string_length(name);
+ mlsize_t vallen = string_length(val);
+ char * s = (char *) stat_alloc(namelen + 1 + vallen + 1);
+
+ bcopy(String_val(name), s, namelen);
+ s[namelen] = '=';
+ bcopy(String_val(val), s + namelen + 1, vallen);
+ s[namelen + 1 + vallen] = 0;
+ if (putenv(s) == -1) uerror("putenv", name);
+ return Val_unit;
+}
+
+#else
+
+value unix_putenv(value name, value val) /* ML */
+{ invalid_argument("putenv not implemented"); }
+
+#endif