Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdlib / putenv_r.c
blob459348bb4cbe68d0cc90d82ab431831cdea8acc5
1 /* This file may have been modified by DJ Delorie (Jan 1991). If so,
2 ** these modifications are Copyright (C) 1991 DJ Delorie.
3 */
5 /*-
6 * Copyright (c) 1988 The Regents of the University of California.
7 * All rights reserved.
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 * Neither the name of the University nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #include <reent.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "envlock.h"
29 /* _putenv_r - reentrant version of putenv that either adds
30 or replaces the environment variable "name"
31 with "value" which is specified by str as "name=value". */
32 int
33 _putenv_r (struct _reent *reent_ptr,
34 char *str)
36 register char *p, *equal;
37 int rval;
39 p = _strdup_r (reent_ptr, str);
41 if (!p)
42 return 1;
44 if (!(equal = strchr (p, '=')))
46 (void) _free_r (reent_ptr, p);
47 return 1;
50 *equal = '\0';
51 rval = _setenv_r (reent_ptr, p, equal + 1, 1);
52 (void) _free_r (reent_ptr, p);
54 return rval;