/* $Id: xputenv 3.2.0.1 1998/07/17 16:46:20 stoklund Exp $ */
/* xputenv.c: set an environment variable without return.

   Copyright (C) 1993, 94, 95, 96, 97, 98 Karl Berry.
   Copyright (C) 1998 Jakob Stoklund Olesen.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#include "kpathsea:config.h"

/* This `x' function is different from the others in that it takes
   different parameters than the standard function; but I find it much
   more convenient to pass the variable and the value separately.  Also,
   this way we can guarantee that the environment value won't become
   garbage.  Also, putenv just overwrites old entries with
   the new, and we want to reclaim that space -- this may be called
   hundreds of times on a run.

   But naturally, some systems do it differently. In this case, it's
   net2 that is smart and does its own saving/freeing.  configure tries
   to determine this.  */

/* Completely rewritten for RISC OS */

#include "OS:os.h"

void
xputenv (const_string var_name, const_string value)
{
  os_error *erp;

  assert (var_name != 0);
  /* Create string type variable */
  erp = xos_set_var_val (var_name, (const byte *) value, strlen (value),
			 0, 0, NULL, NULL);
  if (erp != NULL)
    {
      FATAL2 ("putenv(\"%s\") failed. (%s)", var_name, erp->errmess);
    }
}

/* A special case for setting a variable to a numeric value. For RISC OS
   we might as well use numeric variables */

void
xputenv_int (const_string var_name, int num)
{
  os_error *erp;

  assert (var_name != 0);
  /* Create string type variable */
  erp = xos_set_var_val (var_name, (const byte *) &num, sizeof (int),
			 0, 1, NULL, NULL);
  if (erp != NULL)
    {
      FATAL2 ("putenv_int(\"%s\") failed. (%s)", var_name, erp->errmess);
    }
}
