summaryrefslogtreecommitdiffstats
path: root/otherlibs/unix/putenv.c
blob: 3bd7b4519709232f927f91bfc0e97a20b6a431e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1998 Institut National de Recherche en Informatique et   */
/*  Automatique.  Distributed only by permission.                      */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include <stdlib.h>
#include <string.h>

#include <memory.h>
#include <mlvalues.h>
#include <str.h>

#include "unixsupport.h"

#ifdef HAS_PUTENV

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