Mercurial > gnulib
annotate lib/unsetenv.c @ 17326:bb52d9cece01
unsetenv etc.: port to Solaris 11 + GNU Emacs
* lib/canonicalize-lgpl.c, lib/getaddrinfo.c, lib/getdelim.c:
* lib/glob.c, lib/random_r.c, lib/setenv.c, lib/tsearch.c:
* lib/unsetenv.c (_GL_ARG_NONNULL): Define before including <config.h>.
GNU Emacs's <config.h> includes <stdlib.h> (which is not a great
idea but is too painful to fix right now), and without this gnulib
change <stdlib.h> was defining _GL_ARG_NONNULL incorrectly when
compiling unsetenv.c on Solaris 11. Fix the problem for
unsetenv.c, and fix other similar occurrences.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Feb 2013 14:58:56 -0800 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16235
diff
changeset
|
1 /* Copyright (C) 1992, 1995-2002, 2005-2013 Free Software Foundation, Inc. |
4080 | 2 This file is part of the GNU C Library. |
3 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
4440
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4080
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
7 (at your option) any later version. |
4080 | 8 |
4440
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4080
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
4080 | 10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
4440
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4080
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4080
diff
changeset
|
12 GNU General Public License for more details. |
4080 | 13 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
4080 | 16 |
12422
f7842310a565
New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
17 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc |
f7842310a565
New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
18 optimizes away the name == NULL test below. */ |
f7842310a565
New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
19 #define _GL_ARG_NONNULL(params) |
f7842310a565
New module 'arg-nonnull'. Declare which arguments expect non-NULL values.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
20 |
17326
bb52d9cece01
unsetenv etc.: port to Solaris 11 + GNU Emacs
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
21 #include <config.h> |
bb52d9cece01
unsetenv etc.: port to Solaris 11 + GNU Emacs
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
22 |
9545
c596ca4e89b4
Split setenv module into setenv and unsetenv. Get rid of setenv.h.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
23 /* Specification. */ |
c596ca4e89b4
Split setenv module into setenv and unsetenv. Get rid of setenv.h.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
24 #include <stdlib.h> |
c596ca4e89b4
Split setenv module into setenv and unsetenv. Get rid of setenv.h.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
25 |
4080 | 26 #include <errno.h> |
27 #if !_LIBC | |
28 # define __set_errno(ev) ((errno) = (ev)) | |
29 #endif | |
30 | |
4683
4452e4c45cc4
Assume ANSI C <string.h>, <stdlib.h>.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
31 #include <string.h> |
6659
54c2c5912cdc
undo last change -- this file is sync'd from gettext
Jim Meyering <jim@meyering.net>
parents:
6650
diff
changeset
|
32 #include <unistd.h> |
4080 | 33 |
34 #if !_LIBC | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
35 # define __environ environ |
4080 | 36 #endif |
37 | |
38 #if _LIBC | |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
39 /* This lock protects against simultaneous modifications of 'environ'. */ |
4080 | 40 # include <bits/libc-lock.h> |
41 __libc_lock_define_initialized (static, envlock) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
42 # define LOCK __libc_lock_lock (envlock) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
43 # define UNLOCK __libc_lock_unlock (envlock) |
4080 | 44 #else |
45 # define LOCK | |
46 # define UNLOCK | |
47 #endif | |
48 | |
49 /* In the GNU C library we must keep the namespace clean. */ | |
50 #ifdef _LIBC | |
51 # define unsetenv __unsetenv | |
52 #endif | |
53 | |
12300
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
54 #if _LIBC || !HAVE_UNSETENV |
4080 | 55 |
56 int | |
57 unsetenv (const char *name) | |
58 { | |
59 size_t len; | |
60 char **ep; | |
61 | |
62 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | |
63 { | |
64 __set_errno (EINVAL); | |
65 return -1; | |
66 } | |
67 | |
68 len = strlen (name); | |
69 | |
70 LOCK; | |
71 | |
72 ep = __environ; | |
73 while (*ep != NULL) | |
74 if (!strncmp (*ep, name, len) && (*ep)[len] == '=') | |
75 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
76 /* Found it. Remove this pointer by moving later ones back. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
77 char **dp = ep; |
4080 | 78 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
79 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
80 dp[0] = dp[1]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
81 while (*dp++); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12307
diff
changeset
|
82 /* Continue the loop in case NAME appears again. */ |
4080 | 83 } |
84 else | |
85 ++ep; | |
86 | |
87 UNLOCK; | |
88 | |
89 return 0; | |
90 } | |
91 | |
92 #ifdef _LIBC | |
93 # undef unsetenv | |
94 weak_alias (__unsetenv, unsetenv) | |
95 #endif | |
12300
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
96 |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
97 #else /* HAVE_UNSETENV */ |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
98 |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
99 # undef unsetenv |
14867
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
100 # if !HAVE_DECL_UNSETENV |
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
101 # if VOID_UNSETENV |
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
102 extern void unsetenv (const char *); |
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
103 # else |
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
104 extern int unsetenv (const char *); |
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
105 # endif |
355e7137b2de
unsetenv: Avoid gcc warning.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
106 # endif |
12300
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
107 |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
108 /* Call the underlying unsetenv, in case there is hidden bookkeeping |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
109 that needs updating beyond just modifying environ. */ |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
110 int |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
111 rpl_unsetenv (const char *name) |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
112 { |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
113 int result = 0; |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
114 if (!name || !*name || strchr (name, '=')) |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
115 { |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
116 errno = EINVAL; |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
117 return -1; |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
118 } |
12307
a15e71d9f0b6
unsetenv: work around Solaris bug
Eric Blake <ebb9@byu.net>
parents:
12300
diff
changeset
|
119 while (getenv (name)) |
12300
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
120 # if !VOID_UNSETENV |
12307
a15e71d9f0b6
unsetenv: work around Solaris bug
Eric Blake <ebb9@byu.net>
parents:
12300
diff
changeset
|
121 result = |
12300
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
122 # endif |
12307
a15e71d9f0b6
unsetenv: work around Solaris bug
Eric Blake <ebb9@byu.net>
parents:
12300
diff
changeset
|
123 unsetenv (name); |
12300
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
124 return result; |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
125 } |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
126 |
c8288fd3f281
setenv, unsetenv: work around various bugs
Eric Blake <ebb9@byu.net>
parents:
9721
diff
changeset
|
127 #endif /* HAVE_UNSETENV */ |