Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / lib / unsetenv.c
blob5f9ec6bae8ee9a313465d32eeb5e1aefa359042d
1 /* Copyright (C) 1992,1995-1999,2000-2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <errno.h>
24 #if !_LIBC
25 # if !defined errno && !defined HAVE_ERRNO_DECL
26 extern int errno;
27 # endif
28 # define __set_errno(ev) ((errno) = (ev))
29 #endif
31 #include <stdlib.h>
32 #include <string.h>
33 #if _LIBC || HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
37 #if !_LIBC
38 # define __environ environ
39 # ifndef HAVE_ENVIRON_DECL
40 extern char **environ;
41 # endif
42 #endif
44 #if _LIBC
45 /* This lock protects against simultaneous modifications of `environ'. */
46 # include <bits/libc-lock.h>
47 __libc_lock_define_initialized (static, envlock)
48 # define LOCK __libc_lock_lock (envlock)
49 # define UNLOCK __libc_lock_unlock (envlock)
50 #else
51 # define LOCK
52 # define UNLOCK
53 #endif
55 /* In the GNU C library we must keep the namespace clean. */
56 #ifdef _LIBC
57 # define unsetenv __unsetenv
58 #endif
61 int
62 unsetenv (const char *name)
64 size_t len;
65 char **ep;
67 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
69 __set_errno (EINVAL);
70 return -1;
73 len = strlen (name);
75 LOCK;
77 ep = __environ;
78 while (*ep != NULL)
79 if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
81 /* Found it. Remove this pointer by moving later ones back. */
82 char **dp = ep;
85 dp[0] = dp[1];
86 while (*dp++);
87 /* Continue the loop in case NAME appears again. */
89 else
90 ++ep;
92 UNLOCK;
94 return 0;
97 #ifdef _LIBC
98 # undef unsetenv
99 weak_alias (__unsetenv, unsetenv)
100 #endif