aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBill Wohler2012-12-08 17:19:00 -0800
committerBill Wohler2012-12-08 17:19:00 -0800
commite1b489df7af8f7034f8c2ef275b786e93a39df31 (patch)
tree2edc9307185e2c77b98fe75f6d7eb0476c58c7e3 /lib
parentce974958f93ffa2e1bd01b4dd85dcb8ec1395787 (diff)
parentc6c08d3f8fe4d2c9e588189e46d60a30ef3e8d20 (diff)
downloademacs-e1b489df7af8f7034f8c2ef275b786e93a39df31.tar.gz
emacs-e1b489df7af8f7034f8c2ef275b786e93a39df31.zip
Merge from trunk; up to 2012-12-09T01:04:43Z!rgm@gnu.org.
Diffstat (limited to 'lib')
-rw-r--r--lib/gnulib.mk31
-rw-r--r--lib/lstat.c2
-rw-r--r--lib/makefile.w32-in9
-rw-r--r--lib/md5.c2
-rw-r--r--lib/putenv.c134
-rw-r--r--lib/sha1.c2
-rw-r--r--lib/sha256.c2
-rw-r--r--lib/sha512.c2
-rw-r--r--lib/sig2str.c345
-rw-r--r--lib/sig2str.h43
-rw-r--r--lib/stat.c2
-rw-r--r--lib/stdio.c3
-rw-r--r--lib/stdio.in.h8
-rw-r--r--lib/sys_stat.in.h2
-rw-r--r--lib/unistd.c3
-rw-r--r--lib/unistd.in.h10
-rw-r--r--lib/unsetenv.c127
17 files changed, 715 insertions, 12 deletions
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 834f63169e2..420520fbce7 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -21,7 +21,7 @@
21# the same distribution terms as the rest of that program. 21# the same distribution terms as the rest of that program.
22# 22#
23# Generated by gnulib-tool. 23# Generated by gnulib-tool.
24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings 24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask putenv readlink sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings
25 25
26 26
27MOSTLYCLEANFILES += core *.stackdump 27MOSTLYCLEANFILES += core *.stackdump
@@ -439,6 +439,15 @@ EXTRA_libgnu_a_SOURCES += pthread_sigmask.c
439 439
440## end gnulib module pthread_sigmask 440## end gnulib module pthread_sigmask
441 441
442## begin gnulib module putenv
443
444
445EXTRA_DIST += putenv.c
446
447EXTRA_libgnu_a_SOURCES += putenv.c
448
449## end gnulib module putenv
450
442## begin gnulib module readlink 451## begin gnulib module readlink
443 452
444 453
@@ -457,6 +466,15 @@ EXTRA_DIST += root-uid.h
457 466
458## end gnulib module root-uid 467## end gnulib module root-uid
459 468
469## begin gnulib module sig2str
470
471
472EXTRA_DIST += sig2str.c sig2str.h
473
474EXTRA_libgnu_a_SOURCES += sig2str.c
475
476## end gnulib module sig2str
477
460## begin gnulib module signal-h 478## begin gnulib module signal-h
461 479
462BUILT_SOURCES += signal.h 480BUILT_SOURCES += signal.h
@@ -756,6 +774,7 @@ EXTRA_DIST += stdint.in.h
756## begin gnulib module stdio 774## begin gnulib module stdio
757 775
758BUILT_SOURCES += stdio.h 776BUILT_SOURCES += stdio.h
777libgnu_a_SOURCES += stdio.c
759 778
760# We need the following in order to create <stdio.h> when the system 779# We need the following in order to create <stdio.h> when the system
761# doesn't have one that works with the given compiler. 780# doesn't have one that works with the given compiler.
@@ -1251,6 +1270,7 @@ EXTRA_DIST += u64.h
1251## begin gnulib module unistd 1270## begin gnulib module unistd
1252 1271
1253BUILT_SOURCES += unistd.h 1272BUILT_SOURCES += unistd.h
1273libgnu_a_SOURCES += unistd.c
1254 1274
1255# We need the following in order to create an empty placeholder for 1275# We need the following in order to create an empty placeholder for
1256# <unistd.h> when the system doesn't have one. 1276# <unistd.h> when the system doesn't have one.
@@ -1398,6 +1418,15 @@ EXTRA_DIST += unistd.in.h
1398 1418
1399## end gnulib module unistd 1419## end gnulib module unistd
1400 1420
1421## begin gnulib module unsetenv
1422
1423
1424EXTRA_DIST += unsetenv.c
1425
1426EXTRA_libgnu_a_SOURCES += unsetenv.c
1427
1428## end gnulib module unsetenv
1429
1401## begin gnulib module utimens 1430## begin gnulib module utimens
1402 1431
1403libgnu_a_SOURCES += utimens.c 1432libgnu_a_SOURCES += utimens.c
diff --git a/lib/lstat.c b/lib/lstat.c
index db119a10d3f..97fe6bb2d53 100644
--- a/lib/lstat.c
+++ b/lib/lstat.c
@@ -35,7 +35,7 @@ typedef int dummy;
35# include <sys/stat.h> 35# include <sys/stat.h>
36# undef __need_system_sys_stat_h 36# undef __need_system_sys_stat_h
37 37
38static inline int 38static int
39orig_lstat (const char *filename, struct stat *buf) 39orig_lstat (const char *filename, struct stat *buf)
40{ 40{
41 return lstat (filename, buf); 41 return lstat (filename, buf);
diff --git a/lib/makefile.w32-in b/lib/makefile.w32-in
index 67171e07900..b27e21032b3 100644
--- a/lib/makefile.w32-in
+++ b/lib/makefile.w32-in
@@ -42,6 +42,7 @@ GNULIBOBJS = $(BLD)/c-ctype.$(O) \
42 $(BLD)/sha1.$(O) \ 42 $(BLD)/sha1.$(O) \
43 $(BLD)/sha256.$(O) \ 43 $(BLD)/sha256.$(O) \
44 $(BLD)/sha512.$(O) \ 44 $(BLD)/sha512.$(O) \
45 $(BLD)/sig2str.$(O) \
45 $(BLD)/stat-time.$(O) \ 46 $(BLD)/stat-time.$(O) \
46 $(BLD)/timespec.$(O) \ 47 $(BLD)/timespec.$(O) \
47 $(BLD)/u64.$(O) \ 48 $(BLD)/u64.$(O) \
@@ -239,6 +240,13 @@ $(BLD)/filemode.$(O) : \
239 $(CONFIG_H) \ 240 $(CONFIG_H) \
240 $(FILEMODE_H) 241 $(FILEMODE_H)
241 242
243$(BLD)/sig2str.$(O) : \
244 $(GNU_LIB)/sig2str.c \
245 $(CONFIG_H) \
246 $(GNU_LIB)/sig2str.h \
247 $(GNU_LIB)/intprops.h
248
249
242# The following dependencies are for supporting parallel builds, where 250# The following dependencies are for supporting parallel builds, where
243# we must make sure $(BLD) exists before any compilation starts. 251# we must make sure $(BLD) exists before any compilation starts.
244# 252#
@@ -322,4 +330,3 @@ getopt_h:
322 330
323execinfo.h: execinfo.in.h 331execinfo.h: execinfo.in.h
324 $(CP) execinfo.in.h $@ 332 $(CP) execinfo.in.h $@
325
diff --git a/lib/md5.c b/lib/md5.c
index 30b7e50e3ae..6e6d61270dd 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -83,7 +83,7 @@ md5_init_ctx (struct md5_ctx *ctx)
83/* Copy the 4 byte value from v into the memory location pointed to by *cp, 83/* Copy the 4 byte value from v into the memory location pointed to by *cp,
84 If your architecture allows unaligned access this is equivalent to 84 If your architecture allows unaligned access this is equivalent to
85 * (uint32_t *) cp = v */ 85 * (uint32_t *) cp = v */
86static inline void 86static void
87set_uint32 (char *cp, uint32_t v) 87set_uint32 (char *cp, uint32_t v)
88{ 88{
89 memcpy (cp, &v, sizeof v); 89 memcpy (cp, &v, sizeof v);
diff --git a/lib/putenv.c b/lib/putenv.c
new file mode 100644
index 00000000000..3c0f7ead330
--- /dev/null
+++ b/lib/putenv.c
@@ -0,0 +1,134 @@
1/* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2012 Free Software
2 Foundation, Inc.
3
4 NOTE: The canonical source of this file is maintained with the GNU C
5 Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
6
7 This program is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or any
10 later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include <config.h>
21
22/* Specification. */
23#include <stdlib.h>
24
25#include <stddef.h>
26
27/* Include errno.h *after* sys/types.h to work around header problems
28 on AIX 3.2.5. */
29#include <errno.h>
30#ifndef __set_errno
31# define __set_errno(ev) ((errno) = (ev))
32#endif
33
34#include <string.h>
35#include <unistd.h>
36
37#if _LIBC
38# if HAVE_GNU_LD
39# define environ __environ
40# else
41extern char **environ;
42# endif
43#endif
44
45#if _LIBC
46/* This lock protects against simultaneous modifications of 'environ'. */
47# include <bits/libc-lock.h>
48__libc_lock_define_initialized (static, envlock)
49# define LOCK __libc_lock_lock (envlock)
50# define UNLOCK __libc_lock_unlock (envlock)
51#else
52# define LOCK
53# define UNLOCK
54#endif
55
56static 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 {
76 /* Found it. Remove this pointer by moving later ones back. */
77 char **dp = ep;
78
79 do
80 dp[0] = dp[1];
81 while (*dp++);
82 /* Continue the loop in case NAME appears again. */
83 }
84 else
85 ++ep;
86
87 UNLOCK;
88
89 return 0;
90}
91
92
93/* Put STRING, which is of the form "NAME=VALUE", in the environment.
94 If STRING contains no '=', then remove STRING from the environment. */
95int
96putenv (char *string)
97{
98 const char *const name_end = strchr (string, '=');
99 register size_t size;
100 register char **ep;
101
102 if (name_end == NULL)
103 {
104 /* Remove the variable from the environment. */
105 return _unsetenv (string);
106 }
107
108 size = 0;
109 for (ep = environ; *ep != NULL; ++ep)
110 if (!strncmp (*ep, string, name_end - string) &&
111 (*ep)[name_end - string] == '=')
112 break;
113 else
114 ++size;
115
116 if (*ep == NULL)
117 {
118 static char **last_environ = NULL;
119 char **new_environ = (char **) malloc ((size + 2) * sizeof (char *));
120 if (new_environ == NULL)
121 return -1;
122 (void) memcpy ((void *) new_environ, (void *) environ,
123 size * sizeof (char *));
124 new_environ[size] = (char *) string;
125 new_environ[size + 1] = NULL;
126 free (last_environ);
127 last_environ = new_environ;
128 environ = new_environ;
129 }
130 else
131 *ep = string;
132
133 return 0;
134}
diff --git a/lib/sha1.c b/lib/sha1.c
index 0d82af14bc9..b9505dd9467 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -70,7 +70,7 @@ sha1_init_ctx (struct sha1_ctx *ctx)
70/* Copy the 4 byte value from v into the memory location pointed to by *cp, 70/* Copy the 4 byte value from v into the memory location pointed to by *cp,
71 If your architecture allows unaligned access this is equivalent to 71 If your architecture allows unaligned access this is equivalent to
72 * (uint32_t *) cp = v */ 72 * (uint32_t *) cp = v */
73static inline void 73static void
74set_uint32 (char *cp, uint32_t v) 74set_uint32 (char *cp, uint32_t v)
75{ 75{
76 memcpy (cp, &v, sizeof v); 76 memcpy (cp, &v, sizeof v);
diff --git a/lib/sha256.c b/lib/sha256.c
index a8d29da18dd..55273c6a3bc 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -90,7 +90,7 @@ sha224_init_ctx (struct sha256_ctx *ctx)
90/* Copy the value from v into the memory location pointed to by *cp, 90/* Copy the value from v into the memory location pointed to by *cp,
91 If your architecture allows unaligned access this is equivalent to 91 If your architecture allows unaligned access this is equivalent to
92 * (uint32_t *) cp = v */ 92 * (uint32_t *) cp = v */
93static inline void 93static void
94set_uint32 (char *cp, uint32_t v) 94set_uint32 (char *cp, uint32_t v)
95{ 95{
96 memcpy (cp, &v, sizeof v); 96 memcpy (cp, &v, sizeof v);
diff --git a/lib/sha512.c b/lib/sha512.c
index cf62f2034e5..dfb67a305d8 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -97,7 +97,7 @@ sha384_init_ctx (struct sha512_ctx *ctx)
97/* Copy the value from V into the memory location pointed to by *CP, 97/* Copy the value from V into the memory location pointed to by *CP,
98 If your architecture allows unaligned access, this is equivalent to 98 If your architecture allows unaligned access, this is equivalent to
99 * (__typeof__ (v) *) cp = v */ 99 * (__typeof__ (v) *) cp = v */
100static inline void 100static void
101set_uint64 (char *cp, u64 v) 101set_uint64 (char *cp, u64 v)
102{ 102{
103 memcpy (cp, &v, sizeof v); 103 memcpy (cp, &v, sizeof v);
diff --git a/lib/sig2str.c b/lib/sig2str.c
new file mode 100644
index 00000000000..2f5b21cc36f
--- /dev/null
+++ b/lib/sig2str.c
@@ -0,0 +1,345 @@
1/* sig2str.c -- convert between signal names and numbers
2
3 Copyright (C) 2002, 2004, 2006, 2009-2012 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20#include <config.h>
21
22#include <limits.h>
23#include <signal.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
27
28#include "sig2str.h"
29
30#ifndef SIGRTMIN
31# define SIGRTMIN 0
32# undef SIGRTMAX
33#endif
34#ifndef SIGRTMAX
35# define SIGRTMAX (SIGRTMIN - 1)
36#endif
37
38#define NUMNAME(name) { SIG##name, #name }
39
40/* Signal names and numbers. Put the preferred name first. */
41static struct numname { int num; char const name[8]; } numname_table[] =
42 {
43 /* Signals required by POSIX 1003.1-2001 base, listed in
44 traditional numeric order where possible. */
45#ifdef SIGHUP
46 NUMNAME (HUP),
47#endif
48#ifdef SIGINT
49 NUMNAME (INT),
50#endif
51#ifdef SIGQUIT
52 NUMNAME (QUIT),
53#endif
54#ifdef SIGILL
55 NUMNAME (ILL),
56#endif
57#ifdef SIGTRAP
58 NUMNAME (TRAP),
59#endif
60#ifdef SIGABRT
61 NUMNAME (ABRT),
62#endif
63#ifdef SIGFPE
64 NUMNAME (FPE),
65#endif
66#ifdef SIGKILL
67 NUMNAME (KILL),
68#endif
69#ifdef SIGSEGV
70 NUMNAME (SEGV),
71#endif
72 /* On Haiku, SIGSEGV == SIGBUS, but we prefer SIGSEGV to match
73 strsignal.c output, so SIGBUS must be listed second. */
74#ifdef SIGBUS
75 NUMNAME (BUS),
76#endif
77#ifdef SIGPIPE
78 NUMNAME (PIPE),
79#endif
80#ifdef SIGALRM
81 NUMNAME (ALRM),
82#endif
83#ifdef SIGTERM
84 NUMNAME (TERM),
85#endif
86#ifdef SIGUSR1
87 NUMNAME (USR1),
88#endif
89#ifdef SIGUSR2
90 NUMNAME (USR2),
91#endif
92#ifdef SIGCHLD
93 NUMNAME (CHLD),
94#endif
95#ifdef SIGURG
96 NUMNAME (URG),
97#endif
98#ifdef SIGSTOP
99 NUMNAME (STOP),
100#endif
101#ifdef SIGTSTP
102 NUMNAME (TSTP),
103#endif
104#ifdef SIGCONT
105 NUMNAME (CONT),
106#endif
107#ifdef SIGTTIN
108 NUMNAME (TTIN),
109#endif
110#ifdef SIGTTOU
111 NUMNAME (TTOU),
112#endif
113
114 /* Signals required by POSIX 1003.1-2001 with the XSI extension. */
115#ifdef SIGSYS
116 NUMNAME (SYS),
117#endif
118#ifdef SIGPOLL
119 NUMNAME (POLL),
120#endif
121#ifdef SIGVTALRM
122 NUMNAME (VTALRM),
123#endif
124#ifdef SIGPROF
125 NUMNAME (PROF),
126#endif
127#ifdef SIGXCPU
128 NUMNAME (XCPU),
129#endif
130#ifdef SIGXFSZ
131 NUMNAME (XFSZ),
132#endif
133
134 /* Unix Version 7. */
135#ifdef SIGIOT
136 NUMNAME (IOT), /* Older name for ABRT. */
137#endif
138#ifdef SIGEMT
139 NUMNAME (EMT),
140#endif
141
142 /* USG Unix. */
143#ifdef SIGPHONE
144 NUMNAME (PHONE),
145#endif
146#ifdef SIGWIND
147 NUMNAME (WIND),
148#endif
149
150 /* Unix System V. */
151#ifdef SIGCLD
152 NUMNAME (CLD),
153#endif
154#ifdef SIGPWR
155 NUMNAME (PWR),
156#endif
157
158 /* GNU/Linux 2.2 and Solaris 8. */
159#ifdef SIGCANCEL
160 NUMNAME (CANCEL),
161#endif
162#ifdef SIGLWP
163 NUMNAME (LWP),
164#endif
165#ifdef SIGWAITING
166 NUMNAME (WAITING),
167#endif
168#ifdef SIGFREEZE
169 NUMNAME (FREEZE),
170#endif
171#ifdef SIGTHAW
172 NUMNAME (THAW),
173#endif
174#ifdef SIGLOST
175 NUMNAME (LOST),
176#endif
177#ifdef SIGWINCH
178 NUMNAME (WINCH),
179#endif
180
181 /* GNU/Linux 2.2. */
182#ifdef SIGINFO
183 NUMNAME (INFO),
184#endif
185#ifdef SIGIO
186 NUMNAME (IO),
187#endif
188#ifdef SIGSTKFLT
189 NUMNAME (STKFLT),
190#endif
191
192 /* AIX 5L. */
193#ifdef SIGDANGER
194 NUMNAME (DANGER),
195#endif
196#ifdef SIGGRANT
197 NUMNAME (GRANT),
198#endif
199#ifdef SIGMIGRATE
200 NUMNAME (MIGRATE),
201#endif
202#ifdef SIGMSG
203 NUMNAME (MSG),
204#endif
205#ifdef SIGPRE
206 NUMNAME (PRE),
207#endif
208#ifdef SIGRETRACT
209 NUMNAME (RETRACT),
210#endif
211#ifdef SIGSAK
212 NUMNAME (SAK),
213#endif
214#ifdef SIGSOUND
215 NUMNAME (SOUND),
216#endif
217
218 /* Older AIX versions. */
219#ifdef SIGALRM1
220 NUMNAME (ALRM1), /* unknown; taken from Bash 2.05 */
221#endif
222#ifdef SIGKAP
223 NUMNAME (KAP), /* Older name for SIGGRANT. */
224#endif
225#ifdef SIGVIRT
226 NUMNAME (VIRT), /* unknown; taken from Bash 2.05 */
227#endif
228#ifdef SIGWINDOW
229 NUMNAME (WINDOW), /* Older name for SIGWINCH. */
230#endif
231
232 /* BeOS */
233#ifdef SIGKILLTHR
234 NUMNAME (KILLTHR),
235#endif
236
237 /* Older HP-UX versions. */
238#ifdef SIGDIL
239 NUMNAME (DIL),
240#endif
241
242 /* Korn shell and Bash, of uncertain vintage. */
243 { 0, "EXIT" }
244 };
245
246#define NUMNAME_ENTRIES (sizeof numname_table / sizeof numname_table[0])
247
248/* ISDIGIT differs from isdigit, as follows:
249 - Its arg may be any int or unsigned int; it need not be an unsigned char
250 or EOF.
251 - It's typically faster.
252 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
253 isdigit unless it's important to use the locale's definition
254 of "digit" even when the host does not conform to POSIX. */
255#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
256
257/* Convert the signal name SIGNAME to a signal number. Return the
258 signal number if successful, -1 otherwise. */
259
260static int
261str2signum (char const *signame)
262{
263 if (ISDIGIT (*signame))
264 {
265 char *endp;
266 long int n = strtol (signame, &endp, 10);
267 if (! *endp && n <= SIGNUM_BOUND)
268 return n;
269 }
270 else
271 {
272 unsigned int i;
273 for (i = 0; i < NUMNAME_ENTRIES; i++)
274 if (strcmp (numname_table[i].name, signame) == 0)
275 return numname_table[i].num;
276
277 {
278 char *endp;
279 int rtmin = SIGRTMIN;
280 int rtmax = SIGRTMAX;
281
282 if (0 < rtmin && strncmp (signame, "RTMIN", 5) == 0)
283 {
284 long int n = strtol (signame + 5, &endp, 10);
285 if (! *endp && 0 <= n && n <= rtmax - rtmin)
286 return rtmin + n;
287 }
288 else if (0 < rtmax && strncmp (signame, "RTMAX", 5) == 0)
289 {
290 long int n = strtol (signame + 5, &endp, 10);
291 if (! *endp && rtmin - rtmax <= n && n <= 0)
292 return rtmax + n;
293 }
294 }
295 }
296
297 return -1;
298}
299
300/* Convert the signal name SIGNAME to the signal number *SIGNUM.
301 Return 0 if successful, -1 otherwise. */
302
303int
304str2sig (char const *signame, int *signum)
305{
306 *signum = str2signum (signame);
307 return *signum < 0 ? -1 : 0;
308}
309
310/* Convert SIGNUM to a signal name in SIGNAME. SIGNAME must point to
311 a buffer of at least SIG2STR_MAX bytes. Return 0 if successful, -1
312 otherwise. */
313
314int
315sig2str (int signum, char *signame)
316{
317 unsigned int i;
318 for (i = 0; i < NUMNAME_ENTRIES; i++)
319 if (numname_table[i].num == signum)
320 {
321 strcpy (signame, numname_table[i].name);
322 return 0;
323 }
324
325 {
326 int rtmin = SIGRTMIN;
327 int rtmax = SIGRTMAX;
328
329 if (! (rtmin <= signum && signum <= rtmax))
330 return -1;
331
332 if (signum <= rtmin + (rtmax - rtmin) / 2)
333 {
334 int delta = signum - rtmin;
335 sprintf (signame, delta ? "RTMIN+%d" : "RTMIN", delta);
336 }
337 else
338 {
339 int delta = rtmax - signum;
340 sprintf (signame, delta ? "RTMAX-%d" : "RTMAX", delta);
341 }
342
343 return 0;
344 }
345}
diff --git a/lib/sig2str.h b/lib/sig2str.h
new file mode 100644
index 00000000000..75eff7d7c1a
--- /dev/null
+++ b/lib/sig2str.h
@@ -0,0 +1,43 @@
1/* sig2str.h -- convert between signal names and numbers
2
3 Copyright (C) 2002, 2005, 2009-2012 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20#include <signal.h>
21
22/* Don't override system declarations of SIG2STR_MAX, sig2str, str2sig. */
23#ifndef SIG2STR_MAX
24
25# include "intprops.h"
26
27/* Size of a buffer needed to hold a signal name like "HUP". */
28# define SIG2STR_MAX (sizeof "SIGRTMAX" + INT_STRLEN_BOUND (int) - 1)
29
30int sig2str (int, char *);
31int str2sig (char const *, int *);
32
33#endif
34
35/* An upper bound on signal numbers allowed by the system. */
36
37#if defined _sys_nsig
38# define SIGNUM_BOUND (_sys_nsig - 1)
39#elif defined NSIG
40# define SIGNUM_BOUND (NSIG - 1)
41#else
42# define SIGNUM_BOUND 64
43#endif
diff --git a/lib/stat.c b/lib/stat.c
index 75995408906..c0bcb88320f 100644
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -42,7 +42,7 @@
42# endif 42# endif
43#endif 43#endif
44 44
45static inline int 45static int
46orig_stat (const char *filename, struct stat *buf) 46orig_stat (const char *filename, struct stat *buf)
47{ 47{
48 return stat (filename, buf); 48 return stat (filename, buf);
diff --git a/lib/stdio.c b/lib/stdio.c
new file mode 100644
index 00000000000..e6ed82996b7
--- /dev/null
+++ b/lib/stdio.c
@@ -0,0 +1,3 @@
1#include <config.h>
2#define _GL_STDIO_INLINE _GL_EXTERN_INLINE
3#include "stdio.h"
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index b1b543dee72..f3b52d28f6b 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -46,6 +46,11 @@
46#ifndef _@GUARD_PREFIX@_STDIO_H 46#ifndef _@GUARD_PREFIX@_STDIO_H
47#define _@GUARD_PREFIX@_STDIO_H 47#define _@GUARD_PREFIX@_STDIO_H
48 48
49_GL_INLINE_HEADER_BEGIN
50#ifndef _GL_STDIO_INLINE
51# define _GL_STDIO_INLINE _GL_INLINE
52#endif
53
49/* Get va_list. Needed on many systems, including glibc 2.8. */ 54/* Get va_list. Needed on many systems, including glibc 2.8. */
50#include <stdarg.h> 55#include <stdarg.h>
51 56
@@ -581,7 +586,7 @@ _GL_CXXALIAS_SYS (fwrite, size_t,
581 This affects only function declaration attributes, so it's not 586 This affects only function declaration attributes, so it's not
582 needed for C++. */ 587 needed for C++. */
583# if !defined __cplusplus && 0 < __USE_FORTIFY_LEVEL 588# if !defined __cplusplus && 0 < __USE_FORTIFY_LEVEL
584static inline size_t _GL_ARG_NONNULL ((1, 4)) 589_GL_STDIO_INLINE size_t _GL_ARG_NONNULL ((1, 4))
585rpl_fwrite (const void *ptr, size_t s, size_t n, FILE *stream) 590rpl_fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
586{ 591{
587 size_t r = fwrite (ptr, s, n, stream); 592 size_t r = fwrite (ptr, s, n, stream);
@@ -1333,6 +1338,7 @@ _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1333 "POSIX compliance"); 1338 "POSIX compliance");
1334#endif 1339#endif
1335 1340
1341_GL_INLINE_HEADER_END
1336 1342
1337#endif /* _@GUARD_PREFIX@_STDIO_H */ 1343#endif /* _@GUARD_PREFIX@_STDIO_H */
1338#endif /* _@GUARD_PREFIX@_STDIO_H */ 1344#endif /* _@GUARD_PREFIX@_STDIO_H */
diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h
index 2efc1e92e06..ac05ddb5cec 100644
--- a/lib/sys_stat.in.h
+++ b/lib/sys_stat.in.h
@@ -497,7 +497,7 @@ _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
497# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 497# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
498 498
499# if !GNULIB_defined_rpl_mkdir 499# if !GNULIB_defined_rpl_mkdir
500static inline int 500static int
501rpl_mkdir (char const *name, mode_t mode) 501rpl_mkdir (char const *name, mode_t mode)
502{ 502{
503 return _mkdir (name); 503 return _mkdir (name);
diff --git a/lib/unistd.c b/lib/unistd.c
new file mode 100644
index 00000000000..6c6a8e268c0
--- /dev/null
+++ b/lib/unistd.c
@@ -0,0 +1,3 @@
1#include <config.h>
2#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
3#include "unistd.h"
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index e904e512ee8..6171f77ac71 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -127,6 +127,11 @@
127# include <getopt.h> 127# include <getopt.h>
128#endif 128#endif
129 129
130_GL_INLINE_HEADER_BEGIN
131#ifndef _GL_UNISTD_INLINE
132# define _GL_UNISTD_INLINE _GL_INLINE
133#endif
134
130/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 135/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
131 136
132/* The definition of _GL_ARG_NONNULL is copied here. */ 137/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -404,7 +409,7 @@ extern char **environ;
404# endif 409# endif
405#elif defined GNULIB_POSIXCHECK 410#elif defined GNULIB_POSIXCHECK
406# if HAVE_RAW_DECL_ENVIRON 411# if HAVE_RAW_DECL_ENVIRON
407static inline char *** 412_GL_UNISTD_INLINE char ***
408rpl_environ (void) 413rpl_environ (void)
409{ 414{
410 return &environ; 415 return &environ;
@@ -862,7 +867,7 @@ _GL_CXXALIAS_RPL (getpagesize, int, (void));
862# define getpagesize() _gl_getpagesize () 867# define getpagesize() _gl_getpagesize ()
863# else 868# else
864# if !GNULIB_defined_getpagesize_function 869# if !GNULIB_defined_getpagesize_function
865static inline int 870_GL_UNISTD_INLINE int
866getpagesize () 871getpagesize ()
867{ 872{
868 return _gl_getpagesize (); 873 return _gl_getpagesize ();
@@ -1530,6 +1535,7 @@ _GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
1530_GL_CXXALIASWARN (write); 1535_GL_CXXALIASWARN (write);
1531#endif 1536#endif
1532 1537
1538_GL_INLINE_HEADER_END
1533 1539
1534#endif /* _@GUARD_PREFIX@_UNISTD_H */ 1540#endif /* _@GUARD_PREFIX@_UNISTD_H */
1535#endif /* _@GUARD_PREFIX@_UNISTD_H */ 1541#endif /* _@GUARD_PREFIX@_UNISTD_H */
diff --git a/lib/unsetenv.c b/lib/unsetenv.c
new file mode 100644
index 00000000000..ddbe9a4d293
--- /dev/null
+++ b/lib/unsetenv.c
@@ -0,0 +1,127 @@
1/* Copyright (C) 1992, 1995-2002, 2005-2012 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program 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
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
20 optimizes away the name == NULL test below. */
21#define _GL_ARG_NONNULL(params)
22
23/* Specification. */
24#include <stdlib.h>
25
26#include <errno.h>
27#if !_LIBC
28# define __set_errno(ev) ((errno) = (ev))
29#endif
30
31#include <string.h>
32#include <unistd.h>
33
34#if !_LIBC
35# define __environ environ
36#endif
37
38#if _LIBC
39/* This lock protects against simultaneous modifications of 'environ'. */
40# include <bits/libc-lock.h>
41__libc_lock_define_initialized (static, envlock)
42# define LOCK __libc_lock_lock (envlock)
43# define UNLOCK __libc_lock_unlock (envlock)
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
54#if _LIBC || !HAVE_UNSETENV
55
56int
57unsetenv (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 {
76 /* Found it. Remove this pointer by moving later ones back. */
77 char **dp = ep;
78
79 do
80 dp[0] = dp[1];
81 while (*dp++);
82 /* Continue the loop in case NAME appears again. */
83 }
84 else
85 ++ep;
86
87 UNLOCK;
88
89 return 0;
90}
91
92#ifdef _LIBC
93# undef unsetenv
94weak_alias (__unsetenv, unsetenv)
95#endif
96
97#else /* HAVE_UNSETENV */
98
99# undef unsetenv
100# if !HAVE_DECL_UNSETENV
101# if VOID_UNSETENV
102extern void unsetenv (const char *);
103# else
104extern int unsetenv (const char *);
105# endif
106# endif
107
108/* Call the underlying unsetenv, in case there is hidden bookkeeping
109 that needs updating beyond just modifying environ. */
110int
111rpl_unsetenv (const char *name)
112{
113 int result = 0;
114 if (!name || !*name || strchr (name, '='))
115 {
116 errno = EINVAL;
117 return -1;
118 }
119 while (getenv (name))
120# if !VOID_UNSETENV
121 result =
122# endif
123 unsetenv (name);
124 return result;
125}
126
127#endif /* HAVE_UNSETENV */