source: trunk/libs/newlib/src/newlib/libc/stdlib/putenv_r.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.7 KB
Line 
1/* This file may have been modified by DJ Delorie (Jan 1991).  If so,
2** these modifications are Copyright (C) 1991 DJ Delorie.
3*/
4
5/*-
6 * Copyright (c) 1988 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms are permitted
10 * provided that: (1) source distributions retain this entire copyright
11 * notice and comment, and (2) distributions including binaries display
12 * the following acknowledgement:  ``This product includes software
13 * developed by the University of California, Berkeley and its contributors''
14 * in the documentation or other materials provided with the distribution
15 * and in all advertising materials mentioning features or use of this
16 * software. Neither the name of the University nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#include <reent.h>
25#include <stdlib.h>
26#include <string.h>
27
28#include "envlock.h"
29
30/* _putenv_r - reentrant version of putenv that either adds
31               or replaces the environment variable "name"
32               with "value" which is specified by str as "name=value". */
33int
34_putenv_r (struct _reent *reent_ptr,
35        char   *str)
36{
37  register char *p, *equal;
38  int rval;
39
40  p = _strdup_r (reent_ptr, str);
41
42  if (!p)
43    return 1;
44
45  if (!(equal = strchr (p, '=')))
46    {
47      (void) _free_r (reent_ptr, p);
48      return 1;
49    }
50
51  *equal = '\0';
52  rval = _setenv_r (reent_ptr, p, equal + 1, 1);
53  (void) _free_r (reent_ptr, p);
54
55  return rval;
56}
Note: See TracBrowser for help on using the repository browser.