aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTom Tromey2012-12-17 07:56:22 -0700
committerTom Tromey2012-12-17 07:56:22 -0700
commit3d6eced1ae51ffd0a782130e7c334052277e2724 (patch)
tree5d1d2ad7cd3374f922886c4a72062511a035c168 /lib
parentbf69f522a9e135f9aa483cedd53e71e915f2bf75 (diff)
parent7c3d167f48d6262ee4e5512aa50a07ee96bc1509 (diff)
downloademacs-3d6eced1ae51ffd0a782130e7c334052277e2724.tar.gz
emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.zip
merge from trunk
Diffstat (limited to 'lib')
-rw-r--r--lib/at-func.c146
-rw-r--r--lib/close-stream.c78
-rw-r--r--lib/close-stream.h2
-rw-r--r--lib/euidaccess.c221
-rw-r--r--lib/faccessat.c45
-rw-r--r--lib/fcntl.in.h347
-rw-r--r--lib/fpending.c30
-rw-r--r--lib/fpending.h30
-rw-r--r--lib/getgroups.c116
-rw-r--r--lib/gnulib.mk144
-rw-r--r--lib/group-member.c119
-rw-r--r--lib/lstat.c2
-rw-r--r--lib/makefile.w32-in24
-rw-r--r--lib/md5.c2
-rw-r--r--lib/pselect.c34
-rw-r--r--lib/putenv.c134
-rw-r--r--lib/root-uid.h30
-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/stdlib.in.h13
-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
-rw-r--r--lib/xalloc-oversized.h38
31 files changed, 2090 insertions, 14 deletions
diff --git a/lib/at-func.c b/lib/at-func.c
new file mode 100644
index 00000000000..481eea475a1
--- /dev/null
+++ b/lib/at-func.c
@@ -0,0 +1,146 @@
1/* Define at-style functions like fstatat, unlinkat, fchownat, etc.
2 Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc.
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/* written by Jim Meyering */
18
19#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
20
21#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD
22# include <errno.h>
23# ifndef ENOTSUP
24# define ENOTSUP EINVAL
25# endif
26#else
27# include "openat.h"
28# include "openat-priv.h"
29# include "save-cwd.h"
30#endif
31
32#ifdef AT_FUNC_USE_F1_COND
33# define CALL_FUNC(F) \
34 (flag == AT_FUNC_USE_F1_COND \
35 ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \
36 : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS))
37# define VALIDATE_FLAG(F) \
38 if (flag & ~AT_FUNC_USE_F1_COND) \
39 { \
40 errno = EINVAL; \
41 return FUNC_FAIL; \
42 }
43#else
44# define CALL_FUNC(F) (AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS))
45# define VALIDATE_FLAG(F) /* empty */
46#endif
47
48#ifdef AT_FUNC_RESULT
49# define FUNC_RESULT AT_FUNC_RESULT
50#else
51# define FUNC_RESULT int
52#endif
53
54#ifdef AT_FUNC_FAIL
55# define FUNC_FAIL AT_FUNC_FAIL
56#else
57# define FUNC_FAIL -1
58#endif
59
60/* Call AT_FUNC_F1 to operate on FILE, which is in the directory
61 open on descriptor FD. If AT_FUNC_USE_F1_COND is defined to a value,
62 AT_FUNC_POST_FILE_PARAM_DECLS must include a parameter named flag;
63 call AT_FUNC_F2 if FLAG is 0 or fail if FLAG contains more bits than
64 AT_FUNC_USE_F1_COND. Return int and fail with -1 unless AT_FUNC_RESULT
65 or AT_FUNC_FAIL are defined. If possible, do it without changing the
66 working directory. Otherwise, resort to using save_cwd/fchdir,
67 then AT_FUNC_F?/restore_cwd. If either the save_cwd or the restore_cwd
68 fails, then give a diagnostic and exit nonzero. */
69FUNC_RESULT
70AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
71{
72 VALIDATE_FLAG (flag);
73
74 if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file))
75 return CALL_FUNC (file);
76
77#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD
78 errno = ENOTSUP;
79 return FUNC_FAIL;
80#else
81 {
82 /* Be careful to choose names unlikely to conflict with
83 AT_FUNC_POST_FILE_PARAM_DECLS. */
84 struct saved_cwd saved_cwd;
85 int saved_errno;
86 FUNC_RESULT err;
87
88 {
89 char proc_buf[OPENAT_BUFFER_SIZE];
90 char *proc_file = openat_proc_name (proc_buf, fd, file);
91 if (proc_file)
92 {
93 FUNC_RESULT proc_result = CALL_FUNC (proc_file);
94 int proc_errno = errno;
95 if (proc_file != proc_buf)
96 free (proc_file);
97 /* If the syscall succeeds, or if it fails with an unexpected
98 errno value, then return right away. Otherwise, fall through
99 and resort to using save_cwd/restore_cwd. */
100 if (FUNC_FAIL != proc_result)
101 return proc_result;
102 if (! EXPECTED_ERRNO (proc_errno))
103 {
104 errno = proc_errno;
105 return proc_result;
106 }
107 }
108 }
109
110 if (save_cwd (&saved_cwd) != 0)
111 openat_save_fail (errno);
112 if (0 <= fd && fd == saved_cwd.desc)
113 {
114 /* If saving the working directory collides with the user's
115 requested fd, then the user's fd must have been closed to
116 begin with. */
117 free_cwd (&saved_cwd);
118 errno = EBADF;
119 return FUNC_FAIL;
120 }
121
122 if (fchdir (fd) != 0)
123 {
124 saved_errno = errno;
125 free_cwd (&saved_cwd);
126 errno = saved_errno;
127 return FUNC_FAIL;
128 }
129
130 err = CALL_FUNC (file);
131 saved_errno = (err == FUNC_FAIL ? errno : 0);
132
133 if (restore_cwd (&saved_cwd) != 0)
134 openat_restore_fail (errno);
135
136 free_cwd (&saved_cwd);
137
138 if (saved_errno)
139 errno = saved_errno;
140 return err;
141 }
142#endif
143}
144#undef CALL_FUNC
145#undef FUNC_RESULT
146#undef FUNC_FAIL
diff --git a/lib/close-stream.c b/lib/close-stream.c
new file mode 100644
index 00000000000..04fa5ece09d
--- /dev/null
+++ b/lib/close-stream.c
@@ -0,0 +1,78 @@
1/* Close a stream, with nicer error checking than fclose's.
2
3 Copyright (C) 1998-2002, 2004, 2006-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#include <config.h>
19
20#include "close-stream.h"
21
22#include <errno.h>
23#include <stdbool.h>
24
25#include "fpending.h"
26
27#if USE_UNLOCKED_IO
28# include "unlocked-io.h"
29#endif
30
31/* Close STREAM. Return 0 if successful, EOF (setting errno)
32 otherwise. A failure might set errno to 0 if the error number
33 cannot be determined.
34
35 A failure with errno set to EPIPE may or may not indicate an error
36 situation worth signaling to the user. See the documentation of the
37 close_stdout_set_ignore_EPIPE function for details.
38
39 If a program writes *anything* to STREAM, that program should close
40 STREAM and make sure that it succeeds before exiting. Otherwise,
41 suppose that you go to the extreme of checking the return status
42 of every function that does an explicit write to STREAM. The last
43 printf can succeed in writing to the internal stream buffer, and yet
44 the fclose(STREAM) could still fail (due e.g., to a disk full error)
45 when it tries to write out that buffered data. Thus, you would be
46 left with an incomplete output file and the offending program would
47 exit successfully. Even calling fflush is not always sufficient,
48 since some file systems (NFS and CODA) buffer written/flushed data
49 until an actual close call.
50
51 Besides, it's wasteful to check the return value from every call
52 that writes to STREAM -- just let the internal stream state record
53 the failure. That's what the ferror test is checking below. */
54
55int
56close_stream (FILE *stream)
57{
58 const bool some_pending = (__fpending (stream) != 0);
59 const bool prev_fail = (ferror (stream) != 0);
60 const bool fclose_fail = (fclose (stream) != 0);
61
62 /* Return an error indication if there was a previous failure or if
63 fclose failed, with one exception: ignore an fclose failure if
64 there was no previous error, no data remains to be flushed, and
65 fclose failed with EBADF. That can happen when a program like cp
66 is invoked like this 'cp a b >&-' (i.e., with standard output
67 closed) and doesn't generate any output (hence no previous error
68 and nothing to be flushed). */
69
70 if (prev_fail || (fclose_fail && (some_pending || errno != EBADF)))
71 {
72 if (! fclose_fail)
73 errno = 0;
74 return EOF;
75 }
76
77 return 0;
78}
diff --git a/lib/close-stream.h b/lib/close-stream.h
new file mode 100644
index 00000000000..be3d4196b06
--- /dev/null
+++ b/lib/close-stream.h
@@ -0,0 +1,2 @@
1#include <stdio.h>
2int close_stream (FILE *stream);
diff --git a/lib/euidaccess.c b/lib/euidaccess.c
new file mode 100644
index 00000000000..ca2ceca5d22
--- /dev/null
+++ b/lib/euidaccess.c
@@ -0,0 +1,221 @@
1/* euidaccess -- check if effective user id can access file
2
3 Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2012 Free
4 Software Foundation, Inc.
5
6 This file is part of the GNU C Library.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21/* Written by David MacKenzie and Torbjorn Granlund.
22 Adapted for GNU C library by Roland McGrath. */
23
24#ifndef _LIBC
25# include <config.h>
26#endif
27
28#include <fcntl.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <unistd.h>
32
33#include "root-uid.h"
34
35#if HAVE_LIBGEN_H
36# include <libgen.h>
37#endif
38
39#include <errno.h>
40#ifndef __set_errno
41# define __set_errno(val) errno = (val)
42#endif
43
44#if defined EACCES && !defined EACCESS
45# define EACCESS EACCES
46#endif
47
48#ifndef F_OK
49# define F_OK 0
50# define X_OK 1
51# define W_OK 2
52# define R_OK 4
53#endif
54
55
56#ifdef _LIBC
57
58# define access __access
59# define getuid __getuid
60# define getgid __getgid
61# define geteuid __geteuid
62# define getegid __getegid
63# define group_member __group_member
64# define euidaccess __euidaccess
65# undef stat
66# define stat stat64
67
68#endif
69
70/* Return 0 if the user has permission of type MODE on FILE;
71 otherwise, return -1 and set 'errno'.
72 Like access, except that it uses the effective user and group
73 id's instead of the real ones, and it does not always check for read-only
74 file system, text busy, etc. */
75
76int
77euidaccess (const char *file, int mode)
78{
79#if HAVE_FACCESSAT /* glibc, AIX 7, Solaris 11, Cygwin 1.7 */
80 return faccessat (AT_FDCWD, file, mode, AT_EACCESS);
81#elif defined EFF_ONLY_OK /* IRIX, OSF/1, Interix */
82 return access (file, mode | EFF_ONLY_OK);
83#elif defined ACC_SELF /* AIX */
84 return accessx (file, mode, ACC_SELF);
85#elif HAVE_EACCESS /* FreeBSD */
86 return eaccess (file, mode);
87#else /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */
88
89 uid_t uid = getuid ();
90 gid_t gid = getgid ();
91 uid_t euid = geteuid ();
92 gid_t egid = getegid ();
93 struct stat stats;
94
95# if HAVE_DECL_SETREGID && PREFER_NONREENTRANT_EUIDACCESS
96
97 /* Define PREFER_NONREENTRANT_EUIDACCESS if you prefer euidaccess to
98 return the correct result even if this would make it
99 nonreentrant. Define this only if your entire application is
100 safe even if the uid or gid might temporarily change. If your
101 application uses signal handlers or threads it is probably not
102 safe. */
103
104 if (mode == F_OK)
105 return stat (file, &stats);
106 else
107 {
108 int result;
109 int saved_errno;
110
111 if (uid != euid)
112 setreuid (euid, uid);
113 if (gid != egid)
114 setregid (egid, gid);
115
116 result = access (file, mode);
117 saved_errno = errno;
118
119 /* Restore them. */
120 if (uid != euid)
121 setreuid (uid, euid);
122 if (gid != egid)
123 setregid (gid, egid);
124
125 errno = saved_errno;
126 return result;
127 }
128
129# else
130
131 /* The following code assumes the traditional Unix model, and is not
132 correct on systems that have ACLs or the like. However, it's
133 better than nothing, and it is reentrant. */
134
135 unsigned int granted;
136 if (uid == euid && gid == egid)
137 /* If we are not set-uid or set-gid, access does the same. */
138 return access (file, mode);
139
140 if (stat (file, &stats) != 0)
141 return -1;
142
143 /* The super-user can read and write any file, and execute any file
144 that anyone can execute. */
145 if (euid == ROOT_UID
146 && ((mode & X_OK) == 0
147 || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
148 return 0;
149
150 /* Convert the mode to traditional form, clearing any bogus bits. */
151 if (R_OK == 4 && W_OK == 2 && X_OK == 1 && F_OK == 0)
152 mode &= 7;
153 else
154 mode = ((mode & R_OK ? 4 : 0)
155 + (mode & W_OK ? 2 : 0)
156 + (mode & X_OK ? 1 : 0));
157
158 if (mode == 0)
159 return 0; /* The file exists. */
160
161 /* Convert the file's permission bits to traditional form. */
162 if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6)
163 && S_IRGRP == (4 << 3) && S_IWGRP == (2 << 3) && S_IXGRP == (1 << 3)
164 && S_IROTH == (4 << 0) && S_IWOTH == (2 << 0) && S_IXOTH == (1 << 0))
165 granted = stats.st_mode;
166 else
167 granted = ((stats.st_mode & S_IRUSR ? 4 << 6 : 0)
168 + (stats.st_mode & S_IWUSR ? 2 << 6 : 0)
169 + (stats.st_mode & S_IXUSR ? 1 << 6 : 0)
170 + (stats.st_mode & S_IRGRP ? 4 << 3 : 0)
171 + (stats.st_mode & S_IWGRP ? 2 << 3 : 0)
172 + (stats.st_mode & S_IXGRP ? 1 << 3 : 0)
173 + (stats.st_mode & S_IROTH ? 4 << 0 : 0)
174 + (stats.st_mode & S_IWOTH ? 2 << 0 : 0)
175 + (stats.st_mode & S_IXOTH ? 1 << 0 : 0));
176
177 if (euid == stats.st_uid)
178 granted >>= 6;
179 else if (egid == stats.st_gid || group_member (stats.st_gid))
180 granted >>= 3;
181
182 if ((mode & ~granted) == 0)
183 return 0;
184 __set_errno (EACCESS);
185 return -1;
186
187# endif
188#endif
189}
190#undef euidaccess
191#ifdef weak_alias
192weak_alias (__euidaccess, euidaccess)
193#endif
194
195#ifdef TEST
196# include <error.h>
197# include <stdio.h>
198# include <stdlib.h>
199
200char *program_name;
201
202int
203main (int argc, char **argv)
204{
205 char *file;
206 int mode;
207 int err;
208
209 program_name = argv[0];
210 if (argc < 3)
211 abort ();
212 file = argv[1];
213 mode = atoi (argv[2]);
214
215 err = euidaccess (file, mode);
216 printf ("%d\n", err);
217 if (err != 0)
218 error (0, errno, "%s", file);
219 exit (0);
220}
221#endif
diff --git a/lib/faccessat.c b/lib/faccessat.c
new file mode 100644
index 00000000000..d11a3efaad6
--- /dev/null
+++ b/lib/faccessat.c
@@ -0,0 +1,45 @@
1/* Check the access rights of a file relative to an open directory.
2 Copyright (C) 2009-2012 Free Software Foundation, Inc.
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/* written by Eric Blake */
18
19#include <config.h>
20
21#include <unistd.h>
22#include <fcntl.h>
23
24#ifndef HAVE_ACCESS
25/* Mingw lacks access, but it also lacks real vs. effective ids, so
26 the gnulib euidaccess module is good enough. */
27# undef access
28# define access euidaccess
29#endif
30
31/* Invoke access or euidaccess on file, FILE, using mode MODE, in the directory
32 open on descriptor FD. If possible, do it without changing the
33 working directory. Otherwise, resort to using save_cwd/fchdir, then
34 (access|euidaccess)/restore_cwd. If either the save_cwd or the
35 restore_cwd fails, then give a diagnostic and exit nonzero.
36 Note that this implementation only supports AT_EACCESS, although some
37 native versions also support AT_SYMLINK_NOFOLLOW. */
38
39#define AT_FUNC_NAME faccessat
40#define AT_FUNC_F1 euidaccess
41#define AT_FUNC_F2 access
42#define AT_FUNC_USE_F1_COND AT_EACCESS
43#define AT_FUNC_POST_FILE_PARAM_DECLS , int mode, int flag
44#define AT_FUNC_POST_FILE_ARGS , mode
45#include "at-func.c"
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
new file mode 100644
index 00000000000..604c31b7984
--- /dev/null
+++ b/lib/fcntl.in.h
@@ -0,0 +1,347 @@
1/* Like <fcntl.h>, but with non-working flags defined to 0.
2
3 Copyright (C) 2006-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#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@
22#endif
23@PRAGMA_COLUMNS@
24
25#if defined __need_system_fcntl_h
26/* Special invocation convention. */
27
28/* Needed before <sys/stat.h>.
29 May also define off_t to a 64-bit type on native Windows. */
30#include <sys/types.h>
31/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
32 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
33 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
34 extern "C" { ... } block, which leads to errors in C++ mode with the
35 overridden <sys/stat.h> from gnulib. These errors are known to be gone
36 with g++ version >= 4.3. */
37#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
38# include <sys/stat.h>
39#endif
40#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
41
42#else
43/* Normal invocation convention. */
44
45#ifndef _@GUARD_PREFIX@_FCNTL_H
46
47/* Needed before <sys/stat.h>.
48 May also define off_t to a 64-bit type on native Windows. */
49#include <sys/types.h>
50/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
51 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
52 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
53 extern "C" { ... } block, which leads to errors in C++ mode with the
54 overridden <sys/stat.h> from gnulib. These errors are known to be gone
55 with g++ version >= 4.3. */
56#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
57# include <sys/stat.h>
58#endif
59/* The include_next requires a split double-inclusion guard. */
60#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
61
62#ifndef _@GUARD_PREFIX@_FCNTL_H
63#define _@GUARD_PREFIX@_FCNTL_H
64
65#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
66# include <unistd.h>
67#endif
68
69/* Native Windows platforms declare open(), creat() in <io.h>. */
70#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
71 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
72# include <io.h>
73#endif
74
75
76/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
77
78/* The definition of _GL_ARG_NONNULL is copied here. */
79
80/* The definition of _GL_WARN_ON_USE is copied here. */
81
82
83/* Declare overridden functions. */
84
85#if @GNULIB_FCNTL@
86# if @REPLACE_FCNTL@
87# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
88# undef fcntl
89# define fcntl rpl_fcntl
90# endif
91_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
92_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
93# else
94# if !@HAVE_FCNTL@
95_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
96# endif
97_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
98# endif
99_GL_CXXALIASWARN (fcntl);
100#elif defined GNULIB_POSIXCHECK
101# undef fcntl
102# if HAVE_RAW_DECL_FCNTL
103_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
104 "use gnulib module fcntl for portability");
105# endif
106#endif
107
108#if @GNULIB_OPEN@
109# if @REPLACE_OPEN@
110# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
111# undef open
112# define open rpl_open
113# endif
114_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
115 _GL_ARG_NONNULL ((1)));
116_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
117# else
118_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
119# endif
120/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
121 default argument. _GL_CXXALIASWARN does not work in this case. */
122# if !defined __hpux
123_GL_CXXALIASWARN (open);
124# endif
125#elif defined GNULIB_POSIXCHECK
126# undef open
127/* Assume open is always declared. */
128_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
129 "use gnulib module open for portability");
130#endif
131
132#if @GNULIB_OPENAT@
133# if @REPLACE_OPENAT@
134# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
135# undef openat
136# define openat rpl_openat
137# endif
138_GL_FUNCDECL_RPL (openat, int,
139 (int fd, char const *file, int flags, /* mode_t mode */ ...)
140 _GL_ARG_NONNULL ((2)));
141_GL_CXXALIAS_RPL (openat, int,
142 (int fd, char const *file, int flags, /* mode_t mode */ ...));
143# else
144# if !@HAVE_OPENAT@
145_GL_FUNCDECL_SYS (openat, int,
146 (int fd, char const *file, int flags, /* mode_t mode */ ...)
147 _GL_ARG_NONNULL ((2)));
148# endif
149_GL_CXXALIAS_SYS (openat, int,
150 (int fd, char const *file, int flags, /* mode_t mode */ ...));
151# endif
152_GL_CXXALIASWARN (openat);
153#elif defined GNULIB_POSIXCHECK
154# undef openat
155# if HAVE_RAW_DECL_OPENAT
156_GL_WARN_ON_USE (openat, "openat is not portable - "
157 "use gnulib module openat for portability");
158# endif
159#endif
160
161
162/* Fix up the FD_* macros, only known to be missing on mingw. */
163
164#ifndef FD_CLOEXEC
165# define FD_CLOEXEC 1
166#endif
167
168/* Fix up the supported F_* macros. Intentionally leave other F_*
169 macros undefined. Only known to be missing on mingw. */
170
171#ifndef F_DUPFD_CLOEXEC
172# define F_DUPFD_CLOEXEC 0x40000000
173/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
174# define GNULIB_defined_F_DUPFD_CLOEXEC 1
175#else
176# define GNULIB_defined_F_DUPFD_CLOEXEC 0
177#endif
178
179#ifndef F_DUPFD
180# define F_DUPFD 1
181#endif
182
183#ifndef F_GETFD
184# define F_GETFD 2
185#endif
186
187/* Fix up the O_* macros. */
188
189#if !defined O_DIRECT && defined O_DIRECTIO
190/* Tru64 spells it 'O_DIRECTIO'. */
191# define O_DIRECT O_DIRECTIO
192#endif
193
194#if !defined O_CLOEXEC && defined O_NOINHERIT
195/* Mingw spells it 'O_NOINHERIT'. */
196# define O_CLOEXEC O_NOINHERIT
197#endif
198
199#ifndef O_CLOEXEC
200# define O_CLOEXEC 0
201#endif
202
203#ifndef O_DIRECT
204# define O_DIRECT 0
205#endif
206
207#ifndef O_DIRECTORY
208# define O_DIRECTORY 0
209#endif
210
211#ifndef O_DSYNC
212# define O_DSYNC 0
213#endif
214
215#ifndef O_EXEC
216# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
217#endif
218
219#ifndef O_IGNORE_CTTY
220# define O_IGNORE_CTTY 0
221#endif
222
223#ifndef O_NDELAY
224# define O_NDELAY 0
225#endif
226
227#ifndef O_NOATIME
228# define O_NOATIME 0
229#endif
230
231#ifndef O_NONBLOCK
232# define O_NONBLOCK O_NDELAY
233#endif
234
235/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
236 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
237 or to 0 as fallback. */
238#if @GNULIB_NONBLOCKING@
239# if O_NONBLOCK
240# define GNULIB_defined_O_NONBLOCK 0
241# else
242# define GNULIB_defined_O_NONBLOCK 1
243# undef O_NONBLOCK
244# define O_NONBLOCK 0x40000000
245# endif
246#endif
247
248#ifndef O_NOCTTY
249# define O_NOCTTY 0
250#endif
251
252#ifndef O_NOFOLLOW
253# define O_NOFOLLOW 0
254#endif
255
256#ifndef O_NOLINK
257# define O_NOLINK 0
258#endif
259
260#ifndef O_NOLINKS
261# define O_NOLINKS 0
262#endif
263
264#ifndef O_NOTRANS
265# define O_NOTRANS 0
266#endif
267
268#ifndef O_RSYNC
269# define O_RSYNC 0
270#endif
271
272#ifndef O_SEARCH
273# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
274#endif
275
276#ifndef O_SYNC
277# define O_SYNC 0
278#endif
279
280#ifndef O_TTY_INIT
281# define O_TTY_INIT 0
282#endif
283
284#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
285# undef O_ACCMODE
286# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
287#endif
288
289/* For systems that distinguish between text and binary I/O.
290 O_BINARY is usually declared in fcntl.h */
291#if !defined O_BINARY && defined _O_BINARY
292 /* For MSC-compatible compilers. */
293# define O_BINARY _O_BINARY
294# define O_TEXT _O_TEXT
295#endif
296
297#if defined __BEOS__ || defined __HAIKU__
298 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
299# undef O_BINARY
300# undef O_TEXT
301#endif
302
303#ifndef O_BINARY
304# define O_BINARY 0
305# define O_TEXT 0
306#endif
307
308/* Fix up the AT_* macros. */
309
310/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
311 value exceeds INT_MAX, so its use as an int doesn't conform to the
312 C standard, and GCC and Sun C complain in some cases. If the bug
313 is present, undef AT_FDCWD here, so it can be redefined below. */
314#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
315# undef AT_FDCWD
316#endif
317
318/* Use the same bit pattern as Solaris 9, but with the proper
319 signedness. The bit pattern is important, in case this actually is
320 Solaris with the above workaround. */
321#ifndef AT_FDCWD
322# define AT_FDCWD (-3041965)
323#endif
324
325/* Use the same values as Solaris 9. This shouldn't matter, but
326 there's no real reason to differ. */
327#ifndef AT_SYMLINK_NOFOLLOW
328# define AT_SYMLINK_NOFOLLOW 4096
329#endif
330
331#ifndef AT_REMOVEDIR
332# define AT_REMOVEDIR 1
333#endif
334
335/* Solaris 9 lacks these two, so just pick unique values. */
336#ifndef AT_SYMLINK_FOLLOW
337# define AT_SYMLINK_FOLLOW 2
338#endif
339
340#ifndef AT_EACCESS
341# define AT_EACCESS 4
342#endif
343
344
345#endif /* _@GUARD_PREFIX@_FCNTL_H */
346#endif /* _@GUARD_PREFIX@_FCNTL_H */
347#endif
diff --git a/lib/fpending.c b/lib/fpending.c
new file mode 100644
index 00000000000..2591d534377
--- /dev/null
+++ b/lib/fpending.c
@@ -0,0 +1,30 @@
1/* fpending.c -- return the number of pending output bytes on a stream
2 Copyright (C) 2000, 2004, 2006-2007, 2009-2012 Free Software Foundation,
3 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 Jim Meyering. */
19
20#include <config.h>
21
22#include "fpending.h"
23
24/* Return the number of pending (aka buffered, unflushed)
25 bytes on the stream, FP, that is open for writing. */
26size_t
27__fpending (FILE *fp)
28{
29 return PENDING_OUTPUT_N_BYTES;
30}
diff --git a/lib/fpending.h b/lib/fpending.h
new file mode 100644
index 00000000000..0365287ba76
--- /dev/null
+++ b/lib/fpending.h
@@ -0,0 +1,30 @@
1/* Declare __fpending.
2
3 Copyright (C) 2000, 2003, 2005-2006, 2009-2012 Free Software Foundation,
4 Inc.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 Written by Jim Meyering. */
20
21#include <stddef.h>
22#include <stdio.h>
23
24#if HAVE_DECL___FPENDING
25# if HAVE_STDIO_EXT_H
26# include <stdio_ext.h>
27# endif
28#else
29size_t __fpending (FILE *);
30#endif
diff --git a/lib/getgroups.c b/lib/getgroups.c
new file mode 100644
index 00000000000..f9d36236afe
--- /dev/null
+++ b/lib/getgroups.c
@@ -0,0 +1,116 @@
1/* provide consistent interface to getgroups for systems that don't allow N==0
2
3 Copyright (C) 1996, 1999, 2003, 2006-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 Jim Meyering */
19
20#include <config.h>
21
22#include <unistd.h>
23
24#include <errno.h>
25#include <stdlib.h>
26#include <stdint.h>
27
28#if !HAVE_GETGROUPS
29
30/* Provide a stub that fails with ENOSYS, since there is no group
31 information available on mingw. */
32int
33getgroups (int n _GL_UNUSED, GETGROUPS_T *groups _GL_UNUSED)
34{
35 errno = ENOSYS;
36 return -1;
37}
38
39#else /* HAVE_GETGROUPS */
40
41# undef getgroups
42# ifndef GETGROUPS_ZERO_BUG
43# define GETGROUPS_ZERO_BUG 0
44# endif
45
46/* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always
47 fails. On other systems, it returns the number of supplemental
48 groups for the process. This function handles that special case
49 and lets the system-provided function handle all others. However,
50 it can fail with ENOMEM if memory is tight. It is unspecified
51 whether the effective group id is included in the list. */
52
53int
54rpl_getgroups (int n, gid_t *group)
55{
56 int n_groups;
57 GETGROUPS_T *gbuf;
58 int saved_errno;
59
60 if (n < 0)
61 {
62 errno = EINVAL;
63 return -1;
64 }
65
66 if (n != 0 || !GETGROUPS_ZERO_BUG)
67 {
68 int result;
69 if (sizeof *group == sizeof *gbuf)
70 return getgroups (n, (GETGROUPS_T *) group);
71
72 if (SIZE_MAX / sizeof *gbuf <= n)
73 {
74 errno = ENOMEM;
75 return -1;
76 }
77 gbuf = malloc (n * sizeof *gbuf);
78 if (!gbuf)
79 return -1;
80 result = getgroups (n, gbuf);
81 if (0 <= result)
82 {
83 n = result;
84 while (n--)
85 group[n] = gbuf[n];
86 }
87 saved_errno = errno;
88 free (gbuf);
89 errno == saved_errno;
90 return result;
91 }
92
93 n = 20;
94 while (1)
95 {
96 /* No need to worry about address arithmetic overflow here,
97 since the ancient systems that we're running on have low
98 limits on the number of secondary groups. */
99 gbuf = malloc (n * sizeof *gbuf);
100 if (!gbuf)
101 return -1;
102 n_groups = getgroups (n, gbuf);
103 if (n_groups == -1 ? errno != EINVAL : n_groups < n)
104 break;
105 free (gbuf);
106 n *= 2;
107 }
108
109 saved_errno = errno;
110 free (gbuf);
111 errno = saved_errno;
112
113 return n_groups;
114}
115
116#endif /* HAVE_GETGROUPS */
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index d49eb4fdf7a..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=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --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 crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo 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 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
@@ -84,6 +84,14 @@ EXTRA_DIST += careadlinkat.h
84 84
85## end gnulib module careadlinkat 85## end gnulib module careadlinkat
86 86
87## begin gnulib module close-stream
88
89libgnu_a_SOURCES += close-stream.c
90
91EXTRA_DIST += close-stream.h
92
93## end gnulib module close-stream
94
87## begin gnulib module crypto/md5 95## begin gnulib module crypto/md5
88 96
89libgnu_a_SOURCES += md5.c 97libgnu_a_SOURCES += md5.c
@@ -150,6 +158,17 @@ EXTRA_libgnu_a_SOURCES += dup2.c
150 158
151## end gnulib module dup2 159## end gnulib module dup2
152 160
161## begin gnulib module euidaccess
162
163if gl_GNULIB_ENABLED_euidaccess
164
165endif
166EXTRA_DIST += euidaccess.c
167
168EXTRA_libgnu_a_SOURCES += euidaccess.c
169
170## end gnulib module euidaccess
171
153## begin gnulib module execinfo 172## begin gnulib module execinfo
154 173
155BUILT_SOURCES += $(EXECINFO_H) 174BUILT_SOURCES += $(EXECINFO_H)
@@ -175,6 +194,50 @@ EXTRA_libgnu_a_SOURCES += execinfo.c
175 194
176## end gnulib module execinfo 195## end gnulib module execinfo
177 196
197## begin gnulib module faccessat
198
199
200EXTRA_DIST += at-func.c faccessat.c
201
202EXTRA_libgnu_a_SOURCES += at-func.c faccessat.c
203
204## end gnulib module faccessat
205
206## begin gnulib module fcntl-h
207
208BUILT_SOURCES += fcntl.h
209
210# We need the following in order to create <fcntl.h> when the system
211# doesn't have one that works with the given compiler.
212fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
213 $(AM_V_GEN)rm -f $@-t $@ && \
214 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
215 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
216 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
217 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
218 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
219 -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
220 -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \
221 -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \
222 -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \
223 -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \
224 -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
225 -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
226 -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
227 -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
228 -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
229 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
230 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
231 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
232 < $(srcdir)/fcntl.in.h; \
233 } > $@-t && \
234 mv $@-t $@
235MOSTLYCLEANFILES += fcntl.h fcntl.h-t
236
237EXTRA_DIST += fcntl.in.h
238
239## end gnulib module fcntl-h
240
178## begin gnulib module filemode 241## begin gnulib module filemode
179 242
180libgnu_a_SOURCES += filemode.c 243libgnu_a_SOURCES += filemode.c
@@ -183,6 +246,26 @@ EXTRA_DIST += filemode.h
183 246
184## end gnulib module filemode 247## end gnulib module filemode
185 248
249## begin gnulib module fpending
250
251
252EXTRA_DIST += fpending.c fpending.h
253
254EXTRA_libgnu_a_SOURCES += fpending.c
255
256## end gnulib module fpending
257
258## begin gnulib module getgroups
259
260if gl_GNULIB_ENABLED_getgroups
261
262endif
263EXTRA_DIST += getgroups.c
264
265EXTRA_libgnu_a_SOURCES += getgroups.c
266
267## end gnulib module getgroups
268
186## begin gnulib module getloadavg 269## begin gnulib module getloadavg
187 270
188 271
@@ -242,6 +325,17 @@ EXTRA_libgnu_a_SOURCES += gettimeofday.c
242 325
243## end gnulib module gettimeofday 326## end gnulib module gettimeofday
244 327
328## begin gnulib module group-member
329
330if gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1
331
332endif
333EXTRA_DIST += group-member.c
334
335EXTRA_libgnu_a_SOURCES += group-member.c
336
337## end gnulib module group-member
338
245## begin gnulib module ignore-value 339## begin gnulib module ignore-value
246 340
247 341
@@ -345,6 +439,15 @@ EXTRA_libgnu_a_SOURCES += pthread_sigmask.c
345 439
346## end gnulib module pthread_sigmask 440## end gnulib module pthread_sigmask
347 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
348## begin gnulib module readlink 451## begin gnulib module readlink
349 452
350 453
@@ -354,6 +457,24 @@ EXTRA_libgnu_a_SOURCES += readlink.c
354 457
355## end gnulib module readlink 458## end gnulib module readlink
356 459
460## begin gnulib module root-uid
461
462if gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c
463
464endif
465EXTRA_DIST += root-uid.h
466
467## end gnulib module root-uid
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
357## begin gnulib module signal-h 478## begin gnulib module signal-h
358 479
359BUILT_SOURCES += signal.h 480BUILT_SOURCES += signal.h
@@ -653,6 +774,7 @@ EXTRA_DIST += stdint.in.h
653## begin gnulib module stdio 774## begin gnulib module stdio
654 775
655BUILT_SOURCES += stdio.h 776BUILT_SOURCES += stdio.h
777libgnu_a_SOURCES += stdio.c
656 778
657# 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
658# doesn't have one that works with the given compiler. 780# doesn't have one that works with the given compiler.
@@ -857,6 +979,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
857 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ 979 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
858 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ 980 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
859 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 981 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
982 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \
860 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \ 983 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
861 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 984 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
862 -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \ 985 -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
@@ -1147,6 +1270,7 @@ EXTRA_DIST += u64.h
1147## begin gnulib module unistd 1270## begin gnulib module unistd
1148 1271
1149BUILT_SOURCES += unistd.h 1272BUILT_SOURCES += unistd.h
1273libgnu_a_SOURCES += unistd.c
1150 1274
1151# 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
1152# <unistd.h> when the system doesn't have one. 1276# <unistd.h> when the system doesn't have one.
@@ -1294,6 +1418,15 @@ EXTRA_DIST += unistd.in.h
1294 1418
1295## end gnulib module unistd 1419## end gnulib module unistd
1296 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
1297## begin gnulib module utimens 1430## begin gnulib module utimens
1298 1431
1299libgnu_a_SOURCES += utimens.c 1432libgnu_a_SOURCES += utimens.c
@@ -1311,6 +1444,15 @@ EXTRA_DIST += verify.h
1311 1444
1312## end gnulib module verify 1445## end gnulib module verify
1313 1446
1447## begin gnulib module xalloc-oversized
1448
1449if gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec
1450
1451endif
1452EXTRA_DIST += xalloc-oversized.h
1453
1454## end gnulib module xalloc-oversized
1455
1314 1456
1315mostlyclean-local: mostlyclean-generic 1457mostlyclean-local: mostlyclean-generic
1316 @for dir in '' $(MOSTLYCLEANDIRS); do \ 1458 @for dir in '' $(MOSTLYCLEANDIRS); do \
diff --git a/lib/group-member.c b/lib/group-member.c
new file mode 100644
index 00000000000..5fcc7e01d0c
--- /dev/null
+++ b/lib/group-member.c
@@ -0,0 +1,119 @@
1/* group-member.c -- determine whether group id is in calling user's group list
2
3 Copyright (C) 1994, 1997-1998, 2003, 2005-2006, 2009-2012 Free Software
4 Foundation, Inc.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21/* Specification. */
22#include <unistd.h>
23
24#include <stdio.h>
25#include <sys/types.h>
26#include <stdlib.h>
27
28#include "xalloc-oversized.h"
29
30/* Most processes have no more than this many groups, and for these
31 processes we can avoid using malloc. */
32enum { GROUPBUF_SIZE = 100 };
33
34struct group_info
35 {
36 gid_t *group;
37 gid_t groupbuf[GROUPBUF_SIZE];
38 };
39
40static void
41free_group_info (struct group_info const *g)
42{
43 if (g->group != g->groupbuf)
44 free (g->group);
45}
46
47static int
48get_group_info (struct group_info *gi)
49{
50 int n_groups = getgroups (GROUPBUF_SIZE, gi->groupbuf);
51 gi->group = gi->groupbuf;
52
53 if (n_groups < 0)
54 {
55 int n_group_slots = getgroups (0, NULL);
56 if (0 <= n_group_slots
57 && ! xalloc_oversized (n_group_slots, sizeof *gi->group))
58 {
59 gi->group = malloc (n_group_slots * sizeof *gi->group);
60 if (gi->group)
61 n_groups = getgroups (n_group_slots, gi->group);
62 }
63 }
64
65 /* In case of error, the user loses. */
66 return n_groups;
67}
68
69/* Return non-zero if GID is one that we have in our groups list.
70 Note that the groups list is not guaranteed to contain the current
71 or effective group ID, so they should generally be checked
72 separately. */
73
74int
75group_member (gid_t gid)
76{
77 int i;
78 int found;
79 struct group_info gi;
80 int n_groups = get_group_info (&gi);
81
82 /* Search through the list looking for GID. */
83 found = 0;
84 for (i = 0; i < n_groups; i++)
85 {
86 if (gid == gi.group[i])
87 {
88 found = 1;
89 break;
90 }
91 }
92
93 free_group_info (&gi);
94
95 return found;
96}
97
98#ifdef TEST
99
100char *program_name;
101
102int
103main (int argc, char **argv)
104{
105 int i;
106
107 program_name = argv[0];
108
109 for (i = 1; i < argc; i++)
110 {
111 gid_t gid;
112
113 gid = atoi (argv[i]);
114 printf ("%d: %s\n", gid, group_member (gid) ? "yes" : "no");
115 }
116 exit (0);
117}
118
119#endif /* TEST */
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 f0cea56f829..1482d686acb 100644
--- a/lib/makefile.w32-in
+++ b/lib/makefile.w32-in
@@ -26,9 +26,11 @@ LIBS =
26GNULIBOBJS = $(BLD)/c-ctype.$(O) \ 26GNULIBOBJS = $(BLD)/c-ctype.$(O) \
27 $(BLD)/c-strcasecmp.$(O) \ 27 $(BLD)/c-strcasecmp.$(O) \
28 $(BLD)/c-strncasecmp.$(O) \ 28 $(BLD)/c-strncasecmp.$(O) \
29 $(BLD)/close-stream.$(O) \
29 $(BLD)/dtoastr.$(O) \ 30 $(BLD)/dtoastr.$(O) \
30 $(BLD)/dtotimespec.$(O) \ 31 $(BLD)/dtotimespec.$(O) \
31 $(BLD)/execinfo.$(O) \ 32 $(BLD)/execinfo.$(O) \
33 $(BLD)/fpending.$(O) \
32 $(BLD)/getopt.$(O) \ 34 $(BLD)/getopt.$(O) \
33 $(BLD)/getopt1.$(O) \ 35 $(BLD)/getopt1.$(O) \
34 $(BLD)/gettime.$(O) \ 36 $(BLD)/gettime.$(O) \
@@ -40,6 +42,7 @@ GNULIBOBJS = $(BLD)/c-ctype.$(O) \
40 $(BLD)/sha1.$(O) \ 42 $(BLD)/sha1.$(O) \
41 $(BLD)/sha256.$(O) \ 43 $(BLD)/sha256.$(O) \
42 $(BLD)/sha512.$(O) \ 44 $(BLD)/sha512.$(O) \
45 $(BLD)/sig2str.$(O) \
43 $(BLD)/stat-time.$(O) \ 46 $(BLD)/stat-time.$(O) \
44 $(BLD)/timespec.$(O) \ 47 $(BLD)/timespec.$(O) \
45 $(BLD)/u64.$(O) \ 48 $(BLD)/u64.$(O) \
@@ -100,6 +103,8 @@ U64_H = $(GNU_LIB)/u64.h \
100 $(NT_INC)/stdint.h 103 $(NT_INC)/stdint.h
101SHA512_H = $(GNU_LIB)/sha512.h \ 104SHA512_H = $(GNU_LIB)/sha512.h \
102 $(U64_H) 105 $(U64_H)
106SIG2STR_H = $(GNU_LIB)/sig2str.h \
107 $(GNU_LIB)/intprops.h
103STAT_TIME_H = $(GNU_LIB)/stat-time.h \ 108STAT_TIME_H = $(GNU_LIB)/stat-time.h \
104 $(NT_INC)/sys/stat.h 109 $(NT_INC)/sys/stat.h
105 110
@@ -120,6 +125,13 @@ $(BLD)/c-strncasecmp.$(O) : \
120 $(CONFIG_H) \ 125 $(CONFIG_H) \
121 $(C_CTYPE_H) 126 $(C_CTYPE_H)
122 127
128$(BLD)/close-stream.$(O) : \
129 $(GNU_LIB)/close-stream.c \
130 $(GNU_LIB)/close-stream.h \
131 $(GNU_LIB)/fpending.h \
132 $(NT_INC)/stdbool.h \
133 $(CONFIG_H)
134
123$(BLD)/dtoastr.$(O) : \ 135$(BLD)/dtoastr.$(O) : \
124 $(GNU_LIB)/dtoastr.c \ 136 $(GNU_LIB)/dtoastr.c \
125 $(FTOASTR_C) 137 $(FTOASTR_C)
@@ -135,6 +147,11 @@ $(BLD)/execinfo.$(O) : \
135 $(GNU_LIB)/execinfo.h \ 147 $(GNU_LIB)/execinfo.h \
136 $(CONFIG_H) 148 $(CONFIG_H)
137 149
150$(BLD)/fpending.$(O) : \
151 $(GNU_LIB)/fpending.c \
152 $(GNU_LIB)/fpending.h \
153 $(CONFIG_H)
154
138$(BLD)/getopt.$(O) : \ 155$(BLD)/getopt.$(O) : \
139 $(GNU_LIB)/getopt.c \ 156 $(GNU_LIB)/getopt.c \
140 $(GNU_LIB)/getopt.h \ 157 $(GNU_LIB)/getopt.h \
@@ -225,6 +242,12 @@ $(BLD)/filemode.$(O) : \
225 $(CONFIG_H) \ 242 $(CONFIG_H) \
226 $(FILEMODE_H) 243 $(FILEMODE_H)
227 244
245$(BLD)/sig2str.$(O) : \
246 $(GNU_LIB)/sig2str.c \
247 $(CONFIG_H) \
248 $(SIG2STR_H)
249
250
228# The following dependencies are for supporting parallel builds, where 251# The following dependencies are for supporting parallel builds, where
229# we must make sure $(BLD) exists before any compilation starts. 252# we must make sure $(BLD) exists before any compilation starts.
230# 253#
@@ -308,4 +331,3 @@ getopt_h:
308 331
309execinfo.h: execinfo.in.h 332execinfo.h: execinfo.in.h
310 $(CP) execinfo.in.h $@ 333 $(CP) execinfo.in.h $@
311
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/pselect.c b/lib/pselect.c
index d8ebc70f6c6..1b6d099dccf 100644
--- a/lib/pselect.c
+++ b/lib/pselect.c
@@ -33,6 +33,8 @@
33 pointer parameter stands for no descriptors, an infinite timeout, 33 pointer parameter stands for no descriptors, an infinite timeout,
34 or an unaffected signal mask. */ 34 or an unaffected signal mask. */
35 35
36#if !HAVE_PSELECT
37
36int 38int
37pselect (int nfds, fd_set *restrict rfds, 39pselect (int nfds, fd_set *restrict rfds,
38 fd_set *restrict wfds, fd_set *restrict xfds, 40 fd_set *restrict wfds, fd_set *restrict xfds,
@@ -74,3 +76,35 @@ pselect (int nfds, fd_set *restrict rfds,
74 76
75 return select_result; 77 return select_result;
76} 78}
79
80#else /* HAVE_PSELECT */
81# include <unistd.h>
82# undef pselect
83
84int
85rpl_pselect (int nfds, fd_set *restrict rfds,
86 fd_set *restrict wfds, fd_set *restrict xfds,
87 struct timespec const *restrict timeout,
88 sigset_t const *restrict sigmask)
89{
90 int i;
91
92 /* FreeBSD 8.2 has a bug: it does not always detect invalid fds. */
93 if (nfds < 0 || nfds > FD_SETSIZE)
94 {
95 errno = EINVAL;
96 return -1;
97 }
98 for (i = 0; i < nfds; i++)
99 {
100 if (((rfds && FD_ISSET (i, rfds))
101 || (wfds && FD_ISSET (i, wfds))
102 || (xfds && FD_ISSET (i, xfds)))
103 && dup2 (i, i) != i)
104 return -1;
105 }
106
107 return pselect (nfds, rfds, wfds, xfds, timeout, sigmask);
108}
109
110#endif
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/root-uid.h b/lib/root-uid.h
new file mode 100644
index 00000000000..2379773c291
--- /dev/null
+++ b/lib/root-uid.h
@@ -0,0 +1,30 @@
1/* The user ID that always has appropriate privileges in the POSIX sense.
2
3 Copyright 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#ifndef ROOT_UID_H_
21#define ROOT_UID_H_
22
23/* The user ID that always has appropriate privileges in the POSIX sense. */
24#ifdef __TANDEM
25# define ROOT_UID 65535
26#else
27# define ROOT_UID 0
28#endif
29
30#endif
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/stdlib.in.h b/lib/stdlib.in.h
index 1d67ec64c66..65558402bf3 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -457,10 +457,19 @@ _GL_WARN_ON_USE (posix_openpt, "posix_openpt is not portable - "
457#if @GNULIB_PTSNAME@ 457#if @GNULIB_PTSNAME@
458/* Return the pathname of the pseudo-terminal slave associated with 458/* Return the pathname of the pseudo-terminal slave associated with
459 the master FD is open on, or NULL on errors. */ 459 the master FD is open on, or NULL on errors. */
460# if !@HAVE_PTSNAME@ 460# if @REPLACE_PTSNAME@
461# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
462# undef ptsname
463# define ptsname rpl_ptsname
464# endif
465_GL_FUNCDECL_RPL (ptsname, char *, (int fd));
466_GL_CXXALIAS_RPL (ptsname, char *, (int fd));
467# else
468# if !@HAVE_PTSNAME@
461_GL_FUNCDECL_SYS (ptsname, char *, (int fd)); 469_GL_FUNCDECL_SYS (ptsname, char *, (int fd));
462# endif 470# endif
463_GL_CXXALIAS_SYS (ptsname, char *, (int fd)); 471_GL_CXXALIAS_SYS (ptsname, char *, (int fd));
472# endif
464_GL_CXXALIASWARN (ptsname); 473_GL_CXXALIASWARN (ptsname);
465#elif defined GNULIB_POSIXCHECK 474#elif defined GNULIB_POSIXCHECK
466# undef ptsname 475# undef ptsname
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 */
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h
new file mode 100644
index 00000000000..ad777d8dd79
--- /dev/null
+++ b/lib/xalloc-oversized.h
@@ -0,0 +1,38 @@
1/* xalloc-oversized.h -- memory allocation size checking
2
3 Copyright (C) 1990-2000, 2003-2004, 2006-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#ifndef XALLOC_OVERSIZED_H_
19# define XALLOC_OVERSIZED_H_
20
21# include <stddef.h>
22
23/* Return 1 if an array of N objects, each of size S, cannot exist due
24 to size arithmetic overflow. S must be positive and N must be
25 nonnegative. This is a macro, not a function, so that it
26 works correctly even when SIZE_MAX < N.
27
28 By gnulib convention, SIZE_MAX represents overflow in size
29 calculations, so the conservative dividend to use here is
30 SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
31 However, malloc (SIZE_MAX) fails on all known hosts where
32 sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
33 exactly-SIZE_MAX allocations on such hosts; this avoids a test and
34 branch when S is known to be 1. */
35# define xalloc_oversized(n, s) \
36 ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
37
38#endif /* !XALLOC_OVERSIZED_H_ */