summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2010-04-07 21:11:46 -0400
committerThomas Guyot-Sionnest <dermoth@aei.ca>2010-04-12 21:26:35 -0400
commit74da141e618ef99959d509cb2e7be35a348a39db (patch)
tree88ebc38b381a1021fc2d74864a71e230ae591c3d
parentc63a4f726a0b6ad8cf6040f947754a81fd4683bb (diff)
downloadmonitoring-plugins-74da141e618ef99959d509cb2e7be35a348a39db.tar.gz
Sync with the latest Gnulib code (177f525)
Signed-off-by: Thomas Guyot-Sionnest <dermoth@aei.ca>
-rw-r--r--.gitignore23
-rw-r--r--build-aux/arg-nonnull.h26
-rw-r--r--build-aux/c++defs.h251
-rwxr-xr-xbuild-aux/config.rpath2
-rwxr-xr-xbuild-aux/mkinstalldirs158
-rw-r--r--build-aux/warn-on-use.h102
-rw-r--r--gl/Makefile.am761
-rw-r--r--gl/alignof.h34
-rw-r--r--gl/alloca.c154
-rw-r--r--gl/alloca.in.h4
-rw-r--r--gl/arpa_inet.in.h43
-rw-r--r--gl/asnprintf.c2
-rw-r--r--gl/asprintf.c3
-rw-r--r--gl/base64.c338
-rw-r--r--gl/base64.h16
-rw-r--r--gl/basename-lgpl.c75
-rw-r--r--gl/basename.c74
-rw-r--r--gl/btowc.c5
-rw-r--r--gl/c-strtod.c14
-rw-r--r--gl/c-strtod.h2
-rw-r--r--gl/cloexec.c49
-rw-r--r--gl/cloexec.h36
-rw-r--r--gl/close-hook.c91
-rw-r--r--gl/close-hook.h72
-rw-r--r--[-rwxr-xr-x]gl/config.charset1116
-rw-r--r--gl/creat-safer.c2
-rw-r--r--gl/dirname-lgpl.c86
-rw-r--r--gl/dirname.c64
-rw-r--r--gl/dirname.h13
-rw-r--r--gl/dup-safer.c10
-rw-r--r--gl/dup2.c128
-rw-r--r--gl/errno.in.h7
-rw-r--r--gl/error.c152
-rw-r--r--gl/error.h24
-rw-r--r--gl/exitfail.c3
-rw-r--r--gl/exitfail.h2
-rw-r--r--gl/fcntl--.h7
-rw-r--r--gl/fcntl-safer.h6
-rw-r--r--gl/fcntl.c294
-rw-r--r--gl/fcntl.in.h165
-rw-r--r--gl/fd-safer.c3
-rw-r--r--gl/float+.h2
-rw-r--r--gl/float.in.h2
-rw-r--r--gl/floor.c34
-rw-r--r--gl/floorf.c2
-rw-r--r--gl/fsusage.c38
-rw-r--r--gl/fsusage.h16
-rw-r--r--gl/full-read.c2
-rw-r--r--gl/full-read.h2
-rw-r--r--gl/full-write.c13
-rw-r--r--gl/full-write.h2
-rw-r--r--gl/gai_strerror.c3
-rw-r--r--gl/getaddrinfo.c174
-rw-r--r--gl/getdtablesize.c63
-rw-r--r--gl/gethostname.c55
-rw-r--r--gl/getloadavg.c258
-rw-r--r--gl/getopt.c1275
-rw-r--r--gl/getopt.in.h70
-rw-r--r--gl/getopt1.c140
-rw-r--r--gl/getopt_int.h38
-rw-r--r--gl/gettext.h33
-rw-r--r--gl/inet_ntop.c92
-rw-r--r--gl/intprops.h50
-rw-r--r--gl/langinfo.in.h162
-rw-r--r--gl/localcharset.c482
-rw-r--r--gl/localcharset.h2
-rw-r--r--gl/locale.in.h74
-rw-r--r--gl/m4/00gnulib.m42
-rw-r--r--gl/m4/alloca.m43
-rw-r--r--gl/m4/arpa_inet_h.m425
-rw-r--r--gl/m4/base64.m42
-rw-r--r--gl/m4/btowc.m445
-rw-r--r--gl/m4/c-strtod.m424
-rw-r--r--gl/m4/cloexec.m42
-rw-r--r--gl/m4/codeset.m42
-rw-r--r--gl/m4/dirname.m414
-rw-r--r--gl/m4/dos.m434
-rw-r--r--gl/m4/double-slash-root.m442
-rw-r--r--gl/m4/dup2.m458
-rw-r--r--gl/m4/errno_h.m47
-rw-r--r--gl/m4/error.m46
-rw-r--r--gl/m4/exitfail.m413
-rw-r--r--gl/m4/extensions.m422
-rw-r--r--gl/m4/fcntl-o.m481
-rw-r--r--gl/m4/fcntl-safer.m412
-rw-r--r--gl/m4/fcntl.m483
-rw-r--r--gl/m4/fcntl_h.m493
-rw-r--r--gl/m4/float_h.m42
-rw-r--r--gl/m4/floorf.m49
-rw-r--r--gl/m4/fstypename.m43
-rw-r--r--gl/m4/fsusage.m485
-rw-r--r--gl/m4/getaddrinfo.m425
-rw-r--r--gl/m4/getdtablesize.m415
-rw-r--r--gl/m4/gethostname.m490
-rw-r--r--gl/m4/getloadavg.m445
-rw-r--r--gl/m4/getopt.m4288
-rw-r--r--gl/m4/gettext.m42
-rw-r--r--gl/m4/glibc2.m410
-rw-r--r--gl/m4/glibc21.m410
-rw-r--r--gl/m4/gnulib-cache.m42
-rw-r--r--gl/m4/gnulib-common.m4105
-rw-r--r--gl/m4/gnulib-comp.m4305
-rw-r--r--gl/m4/gnulib-tool.m42
-rw-r--r--gl/m4/hostent.m42
-rw-r--r--gl/m4/iconv.m429
-rw-r--r--gl/m4/include_next.m498
-rw-r--r--gl/m4/inet_ntop.m421
-rw-r--r--gl/m4/inline.m42
-rw-r--r--gl/m4/intdiv0.m42
-rw-r--r--gl/m4/intl.m42
-rw-r--r--gl/m4/intldir.m42
-rw-r--r--gl/m4/intlmacosx.m42
-rw-r--r--gl/m4/intmax.m42
-rw-r--r--gl/m4/intmax_t.m43
-rw-r--r--gl/m4/inttypes-pri.m42
-rw-r--r--gl/m4/inttypes_h.m42
-rw-r--r--gl/m4/langinfo_h.m477
-rw-r--r--gl/m4/lcmessage.m43
-rw-r--r--gl/m4/lib-ld.m48
-rw-r--r--gl/m4/lib-link.m49
-rw-r--r--gl/m4/lib-prefix.m42
-rw-r--r--gl/m4/localcharset.m45
-rw-r--r--gl/m4/locale-fr.m42
-rw-r--r--gl/m4/locale-ja.m42
-rw-r--r--gl/m4/locale-zh.m42
-rw-r--r--gl/m4/locale_h.m492
-rw-r--r--gl/m4/lock.m42
-rw-r--r--gl/m4/longlong.m466
-rw-r--r--gl/m4/ls-mntd-fs.m486
-rw-r--r--gl/m4/malloc.m42
-rw-r--r--gl/m4/math_h.m453
-rw-r--r--gl/m4/mbrtowc.m465
-rw-r--r--gl/m4/mbsinit.m412
-rw-r--r--gl/m4/mbstate_t.m418
-rw-r--r--gl/m4/memchr.m485
-rw-r--r--gl/m4/mktime.m467
-rw-r--r--gl/m4/mmap-anon.m459
-rw-r--r--gl/m4/mode_t.m426
-rw-r--r--gl/m4/mountlist.m44
-rw-r--r--gl/m4/multiarch.m42
-rw-r--r--gl/m4/netdb_h.m47
-rw-r--r--gl/m4/netinet_in_h.m42
-rw-r--r--gl/m4/nl_langinfo.m425
-rw-r--r--gl/m4/nls.m43
-rw-r--r--gl/m4/onceonly.m43
-rw-r--r--gl/m4/open.m426
-rw-r--r--gl/m4/po.m42
-rw-r--r--gl/m4/printf-posix.m42
-rw-r--r--gl/m4/printf.m42
-rw-r--r--gl/m4/progtest.m42
-rw-r--r--gl/m4/regex.m4275
-rw-r--r--gl/m4/safe-read.m43
-rw-r--r--gl/m4/safe-write.m42
-rw-r--r--gl/m4/servent.m42
-rw-r--r--gl/m4/size_max.m417
-rw-r--r--gl/m4/snprintf.m42
-rw-r--r--gl/m4/sockets.m490
-rw-r--r--gl/m4/socklen.m440
-rw-r--r--gl/m4/sockpfaf.m420
-rw-r--r--gl/m4/ssize_t.m42
-rw-r--r--gl/m4/stat.m463
-rw-r--r--gl/m4/stdbool.m4140
-rw-r--r--gl/m4/stddef_h.m445
-rw-r--r--gl/m4/stdint.m414
-rw-r--r--gl/m4/stdint_h.m42
-rw-r--r--gl/m4/stdio_h.m4127
-rw-r--r--gl/m4/stdlib_h.m455
-rw-r--r--gl/m4/strdup.m425
-rw-r--r--gl/m4/strerror.m42
-rw-r--r--gl/m4/string_h.m475
-rw-r--r--gl/m4/strndup.m448
-rw-r--r--gl/m4/strnlen.m43
-rw-r--r--gl/m4/strstr.m479
-rw-r--r--gl/m4/sys_socket_h.m437
-rw-r--r--gl/m4/sys_stat_h.m482
-rw-r--r--gl/m4/threadlib.m454
-rw-r--r--gl/m4/time_h.m462
-rw-r--r--gl/m4/time_r.m449
-rw-r--r--gl/m4/timegm.m426
-rw-r--r--gl/m4/uintmax_t.m42
-rw-r--r--gl/m4/unistd-safer.m42
-rw-r--r--gl/m4/unistd_h.m481
-rw-r--r--gl/m4/vasnprintf.m42
-rw-r--r--gl/m4/vasprintf.m43
-rw-r--r--gl/m4/visibility.m42
-rw-r--r--gl/m4/vsnprintf.m42
-rw-r--r--gl/m4/warn-on-use.m445
-rw-r--r--gl/m4/wchar_h.m4 (renamed from gl/m4/wchar.m4)104
-rw-r--r--gl/m4/wchar_t.m42
-rw-r--r--gl/m4/wcrtomb.m475
-rw-r--r--gl/m4/wctype_h.m4 (renamed from gl/m4/wctype.m4)36
-rw-r--r--gl/m4/wint_t.m42
-rw-r--r--gl/m4/write.m42
-rw-r--r--gl/m4/xalloc.m43
-rw-r--r--gl/m4/xsize.m42
-rw-r--r--gl/m4/xstrndup.m42
-rw-r--r--gl/malloc.c2
-rw-r--r--gl/math.in.h585
-rw-r--r--gl/mbrtowc.c474
-rw-r--r--gl/mbsinit.c2
-rw-r--r--gl/memchr.c172
-rw-r--r--gl/memchr.valgrind14
-rw-r--r--gl/mktime-internal.h4
-rw-r--r--gl/mktime.c378
-rw-r--r--gl/mountlist.c476
-rw-r--r--gl/mountlist.h16
-rw-r--r--gl/netdb.in.h116
-rw-r--r--gl/netinet_in.in.h10
-rw-r--r--gl/nl_langinfo.c260
-rw-r--r--gl/open-safer.c12
-rw-r--r--gl/open.c76
-rw-r--r--gl/pipe-safer.c22
-rw-r--r--gl/printf-args.c211
-rw-r--r--gl/printf-args.h55
-rw-r--r--gl/printf-parse.c940
-rw-r--r--gl/printf-parse.h21
-rw-r--r--gl/ref-add.sin2
-rw-r--r--gl/ref-del.sin2
-rw-r--r--gl/regcomp.c172
-rw-r--r--gl/regex.c3
-rw-r--r--gl/regex.h5
-rw-r--r--gl/regex_internal.c101
-rw-r--r--gl/regex_internal.h26
-rw-r--r--gl/regexec.c161
-rw-r--r--gl/safe-read.c12
-rw-r--r--gl/safe-read.h2
-rw-r--r--gl/safe-write.c2
-rw-r--r--gl/safe-write.h2
-rw-r--r--gl/size_max.h2
-rw-r--r--gl/snprintf.c12
-rw-r--r--gl/sockets.c118
-rw-r--r--gl/sockets.h51
-rw-r--r--gl/stat.c104
-rw-r--r--gl/stdbool.in.h2
-rw-r--r--gl/stddef.in.h86
-rw-r--r--gl/stdint.in.h17
-rw-r--r--gl/stdio-write.c48
-rw-r--r--gl/stdio.in.h1269
-rw-r--r--gl/stdlib.in.h624
-rw-r--r--gl/str-two-way.h429
-rw-r--r--gl/strdup.c4
-rw-r--r--gl/streq.h2
-rw-r--r--gl/strerror.c18
-rw-r--r--gl/string.in.h729
-rw-r--r--gl/stripslash.c3
-rw-r--r--gl/strndup.c4
-rw-r--r--gl/strnlen.c2
-rw-r--r--gl/strstr.c83
-rw-r--r--gl/sys_socket.in.h671
-rw-r--r--gl/sys_stat.in.h638
-rw-r--r--gl/time.in.h169
-rw-r--r--gl/time_r.c4
-rw-r--r--gl/timegm.c6
-rw-r--r--gl/unistd--.h7
-rw-r--r--gl/unistd-safer.h13
-rw-r--r--gl/unistd.in.h1182
-rw-r--r--gl/vasnprintf.c8063
-rw-r--r--gl/vasnprintf.h17
-rw-r--r--gl/vasprintf.c2
-rw-r--r--gl/verify.h6
-rw-r--r--gl/vsnprintf.c12
-rw-r--r--gl/w32sock.h61
-rw-r--r--gl/wchar.in.h346
-rw-r--r--gl/wcrtomb.c12
-rw-r--r--gl/wctype.in.h261
-rw-r--r--gl/write.c18
-rw-r--r--gl/xalloc-die.c4
-rw-r--r--gl/xalloc.h59
-rw-r--r--gl/xmalloc.c6
-rw-r--r--gl/xsize.h2
-rw-r--r--gl/xstrndup.c2
-rw-r--r--gl/xstrndup.h2
-rwxr-xr-xtools/setup4
273 files changed, 20118 insertions, 11261 deletions
diff --git a/.gitignore b/.gitignore
index 867ec6af..da856290 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,6 @@ NP-VERSION-FILE
5# / 5# /
6/aclocal.m4 6/aclocal.m4
7/autom4te*.cache 7/autom4te*.cache
8/build-*
9/Cache.pm 8/Cache.pm
10/command.cfg 9/command.cfg
11/compile 10/compile
@@ -25,12 +24,14 @@ NP-VERSION-FILE
25/THANKS 24/THANKS
26 25
27# /build-aux/ 26# /build-aux/
27/build-aux/*~
28/build-aux/compile 28/build-aux/compile
29/build-aux/config.guess 29/build-aux/config.guess
30/build-aux/config.sub 30/build-aux/config.sub
31/build-aux/depcomp 31/build-aux/depcomp
32/build-aux/install-sh 32/build-aux/install-sh
33/build-aux/missing 33/build-aux/missing
34/build-aux/mkinstalldirs
34 35
35# /doc/ 36# /doc/
36/doc/developer-guidelines.html 37/doc/developer-guidelines.html
@@ -46,28 +47,38 @@ NP-VERSION-FILE
46# /gl/ 47# /gl/
47/gl/.deps 48/gl/.deps
48/gl/alloca.h 49/gl/alloca.h
50/gl/arg-nonnull.h
49/gl/arpa 51/gl/arpa
52/gl/arpa_inet.h
53/gl/c++defs.h
54/gl/charset.alias
50/gl/configmake.h 55/gl/configmake.h
51/gl/errno.h 56/gl/errno.h
52/gl/float.h
53/gl/fcntl.h 57/gl/fcntl.h
58/gl/float.h
54/gl/getopt.h 59/gl/getopt.h
60/gl/langinfo.h
55/gl/libgnu.a 61/gl/libgnu.a
62/gl/locale.h
56/gl/Makefile 63/gl/Makefile
57/gl/Makefile.in 64/gl/Makefile.in
58/gl/math.h 65/gl/math.h
66/gl/netdb.h
59/gl/netinet_in.h 67/gl/netinet_in.h
60/gl/ref-del.sed
61/gl/ref-add.sed 68/gl/ref-add.sed
62/gl/charset.alias 69/gl/ref-del.sed
63/gl/stdint.h
64/gl/stdbool.h 70/gl/stdbool.h
65/gl/stdlib.h 71/gl/stddef.h
72/gl/stdint.h
66/gl/stdio.h 73/gl/stdio.h
74/gl/stdlib.h
67/gl/string.h 75/gl/string.h
68/gl/sys_socket.h 76/gl/sys_socket.h
77/gl/sys_stat.h
78/gl/sys
69/gl/time.h 79/gl/time.h
70/gl/unistd.h 80/gl/unistd.h
81/gl/warn-on-use.h
71/gl/wchar.h 82/gl/wchar.h
72/gl/wctype.h 83/gl/wctype.h
73 84
diff --git a/build-aux/arg-nonnull.h b/build-aux/arg-nonnull.h
new file mode 100644
index 00000000..7e3e2db8
--- /dev/null
+++ b/build-aux/arg-nonnull.h
@@ -0,0 +1,26 @@
1/* A C macro for declaring that specific arguments must not be NULL.
2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by 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 GNU
12 Lesser 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/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
18 that the values passed as arguments n, ..., m must be non-NULL pointers.
19 n = 1 stands for the first argument, n = 2 for the second argument etc. */
20#ifndef _GL_ARG_NONNULL
21# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
22# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
23# else
24# define _GL_ARG_NONNULL(params)
25# endif
26#endif
diff --git a/build-aux/c++defs.h b/build-aux/c++defs.h
new file mode 100644
index 00000000..7d710898
--- /dev/null
+++ b/build-aux/c++defs.h
@@ -0,0 +1,251 @@
1/* C++ compatible function declaration macros.
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by 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 GNU
12 Lesser 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#ifndef _GL_CXXDEFS_H
18#define _GL_CXXDEFS_H
19
20/* The three most frequent use cases of these macros are:
21
22 * For providing a substitute for a function that is missing on some
23 platforms, but is declared and works fine on the platforms on which
24 it exists:
25
26 #if @GNULIB_FOO@
27 # if !@HAVE_FOO@
28 _GL_FUNCDECL_SYS (foo, ...);
29 # endif
30 _GL_CXXALIAS_SYS (foo, ...);
31 _GL_CXXALIASWARN (foo);
32 #elif defined GNULIB_POSIXCHECK
33 ...
34 #endif
35
36 * For providing a replacement for a function that exists on all platforms,
37 but is broken/insufficient and needs to be replaced on some platforms:
38
39 #if @GNULIB_FOO@
40 # if @REPLACE_FOO@
41 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
42 # undef foo
43 # define foo rpl_foo
44 # endif
45 _GL_FUNCDECL_RPL (foo, ...);
46 _GL_CXXALIAS_RPL (foo, ...);
47 # else
48 _GL_CXXALIAS_SYS (foo, ...);
49 # endif
50 _GL_CXXALIASWARN (foo);
51 #elif defined GNULIB_POSIXCHECK
52 ...
53 #endif
54
55 * For providing a replacement for a function that exists on some platforms
56 but is broken/insufficient and needs to be replaced on some of them and
57 is additionally either missing or undeclared on some other platforms:
58
59 #if @GNULIB_FOO@
60 # if @REPLACE_FOO@
61 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
62 # undef foo
63 # define foo rpl_foo
64 # endif
65 _GL_FUNCDECL_RPL (foo, ...);
66 _GL_CXXALIAS_RPL (foo, ...);
67 # else
68 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
69 _GL_FUNCDECL_SYS (foo, ...);
70 # endif
71 _GL_CXXALIAS_SYS (foo, ...);
72 # endif
73 _GL_CXXALIASWARN (foo);
74 #elif defined GNULIB_POSIXCHECK
75 ...
76 #endif
77*/
78
79/* _GL_EXTERN_C declaration;
80 performs the declaration with C linkage. */
81#if defined __cplusplus
82# define _GL_EXTERN_C extern "C"
83#else
84# define _GL_EXTERN_C extern
85#endif
86
87/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
88 declares a replacement function, named rpl_func, with the given prototype,
89 consisting of return type, parameters, and attributes.
90 Example:
91 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
92 _GL_ARG_NONNULL ((1)));
93 */
94#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
95 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
96#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
97 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
98
99/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
100 declares the system function, named func, with the given prototype,
101 consisting of return type, parameters, and attributes.
102 Example:
103 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
104 _GL_ARG_NONNULL ((1)));
105 */
106#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
107 _GL_EXTERN_C rettype func parameters_and_attributes
108
109/* _GL_CXXALIAS_RPL (func, rettype, parameters);
110 declares a C++ alias called GNULIB_NAMESPACE::func
111 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
112 Example:
113 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
114 */
115#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
116 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
117#if defined __cplusplus && defined GNULIB_NAMESPACE
118# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
119 namespace GNULIB_NAMESPACE \
120 { \
121 rettype (*const func) parameters = ::rpl_func; \
122 } \
123 _GL_EXTERN_C int _gl_cxxalias_dummy
124#else
125# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
126 _GL_EXTERN_C int _gl_cxxalias_dummy
127#endif
128
129/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
130 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
131 except that the C function rpl_func may have a slightly different
132 declaration. A cast is used to silence the "invalid conversion" error
133 that would otherwise occur. */
134#if defined __cplusplus && defined GNULIB_NAMESPACE
135# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
136 namespace GNULIB_NAMESPACE \
137 { \
138 rettype (*const func) parameters = \
139 reinterpret_cast<rettype(*)parameters>(::rpl_func); \
140 } \
141 _GL_EXTERN_C int _gl_cxxalias_dummy
142#else
143# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
144 _GL_EXTERN_C int _gl_cxxalias_dummy
145#endif
146
147/* _GL_CXXALIAS_SYS (func, rettype, parameters);
148 declares a C++ alias called GNULIB_NAMESPACE::func
149 that redirects to the system provided function func, if GNULIB_NAMESPACE
150 is defined.
151 Example:
152 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
153 */
154#if defined __cplusplus && defined GNULIB_NAMESPACE
155 /* If we were to write
156 rettype (*const func) parameters = ::func;
157 like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
158 better (remove an indirection through a 'static' pointer variable),
159 but then the _GL_CXXALIASWARN macro below would cause a warning not only
160 for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
161# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
162 namespace GNULIB_NAMESPACE \
163 { \
164 static rettype (*func) parameters = ::func; \
165 } \
166 _GL_EXTERN_C int _gl_cxxalias_dummy
167#else
168# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
169 _GL_EXTERN_C int _gl_cxxalias_dummy
170#endif
171
172/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
173 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
174 except that the C function func may have a slightly different declaration.
175 A cast is used to silence the "invalid conversion" error that would
176 otherwise occur. */
177#if defined __cplusplus && defined GNULIB_NAMESPACE
178# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
179 namespace GNULIB_NAMESPACE \
180 { \
181 static rettype (*func) parameters = \
182 reinterpret_cast<rettype(*)parameters>(::func); \
183 } \
184 _GL_EXTERN_C int _gl_cxxalias_dummy
185#else
186# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
187 _GL_EXTERN_C int _gl_cxxalias_dummy
188#endif
189
190/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
191 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
192 except that the C function is picked among a set of overloaded functions,
193 namely the one with rettype2 and parameters2. Two consecutive casts
194 are used to silence the "cannot find a match" and "invalid conversion"
195 errors that would otherwise occur. */
196#if defined __cplusplus && defined GNULIB_NAMESPACE
197 /* The outer cast must be a reinterpret_cast.
198 The inner cast: When the function is defined as a set of overloaded
199 functions, it works as a static_cast<>, choosing the designated variant.
200 When the function is defined as a single variant, it works as a
201 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
202# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
203 namespace GNULIB_NAMESPACE \
204 { \
205 static rettype (*func) parameters = \
206 reinterpret_cast<rettype(*)parameters>( \
207 (rettype2(*)parameters2)(::func)); \
208 } \
209 _GL_EXTERN_C int _gl_cxxalias_dummy
210#else
211# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
212 _GL_EXTERN_C int _gl_cxxalias_dummy
213#endif
214
215/* _GL_CXXALIASWARN (func);
216 causes a warning to be emitted when ::func is used but not when
217 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
218 variants. */
219#if defined __cplusplus && defined GNULIB_NAMESPACE
220# define _GL_CXXALIASWARN(func) \
221 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
222# define _GL_CXXALIASWARN_1(func,namespace) \
223 _GL_CXXALIASWARN_2 (func, namespace)
224# define _GL_CXXALIASWARN_2(func,namespace) \
225 _GL_WARN_ON_USE (func, \
226 "The symbol ::" #func " refers to the system function. " \
227 "Use " #namespace "::" #func " instead.")
228#else
229# define _GL_CXXALIASWARN(func) \
230 _GL_EXTERN_C int _gl_cxxalias_dummy
231#endif
232
233/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
234 causes a warning to be emitted when the given overloaded variant of ::func
235 is used but not when GNULIB_NAMESPACE::func is used. */
236#if defined __cplusplus && defined GNULIB_NAMESPACE
237# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
238 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
239 GNULIB_NAMESPACE)
240# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
241 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
242# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
243 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
244 "The symbol ::" #func " refers to the system function. " \
245 "Use " #namespace "::" #func " instead.")
246#else
247# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
248 _GL_EXTERN_C int _gl_cxxalias_dummy
249#endif
250
251#endif /* _GL_CXXDEFS_H */
diff --git a/build-aux/config.rpath b/build-aux/config.rpath
index 85c2f209..17298f23 100755
--- a/build-aux/config.rpath
+++ b/build-aux/config.rpath
@@ -2,7 +2,7 @@
2# Output a system dependent set of variables, describing how to set the 2# Output a system dependent set of variables, describing how to set the
3# run time search path of shared libraries in an executable. 3# run time search path of shared libraries in an executable.
4# 4#
5# Copyright 1996-2008 Free Software Foundation, Inc. 5# Copyright 1996-2010 Free Software Foundation, Inc.
6# Taken from GNU libtool, 2001 6# Taken from GNU libtool, 2001
7# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996 7# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8# 8#
diff --git a/build-aux/mkinstalldirs b/build-aux/mkinstalldirs
deleted file mode 100755
index 259dbfcd..00000000
--- a/build-aux/mkinstalldirs
+++ /dev/null
@@ -1,158 +0,0 @@
1#! /bin/sh
2# mkinstalldirs --- make directory hierarchy
3
4scriptversion=2005-06-29.22
5
6# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
7# Created: 1993-05-16
8# Public domain.
9#
10# This file is maintained in Automake, please report
11# bugs to <bug-automake@gnu.org> or send patches to
12# <automake-patches@gnu.org>.
13
14errstatus=0
15dirmode=
16
17usage="\
18Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
19
20Create each directory DIR (with mode MODE, if specified), including all
21leading file name components.
22
23Report bugs to <bug-automake@gnu.org>."
24
25# process command line arguments
26while test $# -gt 0 ; do
27 case $1 in
28 -h | --help | --h*) # -h for help
29 echo "$usage"
30 exit $?
31 ;;
32 -m) # -m PERM arg
33 shift
34 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
35 dirmode=$1
36 shift
37 ;;
38 --version)
39 echo "$0 $scriptversion"
40 exit $?
41 ;;
42 --) # stop option processing
43 shift
44 break
45 ;;
46 -*) # unknown option
47 echo "$usage" 1>&2
48 exit 1
49 ;;
50 *) # first non-opt arg
51 break
52 ;;
53 esac
54done
55
56for file
57do
58 if test -d "$file"; then
59 shift
60 else
61 break
62 fi
63done
64
65case $# in
66 0) exit 0 ;;
67esac
68
69# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
70# mkdir -p a/c at the same time, both will detect that a is missing,
71# one will create a, then the other will try to create a and die with
72# a "File exists" error. This is a problem when calling mkinstalldirs
73# from a parallel make. We use --version in the probe to restrict
74# ourselves to GNU mkdir, which is thread-safe.
75case $dirmode in
76 '')
77 if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
78 echo "mkdir -p -- $*"
79 exec mkdir -p -- "$@"
80 else
81 # On NextStep and OpenStep, the `mkdir' command does not
82 # recognize any option. It will interpret all options as
83 # directories to create, and then abort because `.' already
84 # exists.
85 test -d ./-p && rmdir ./-p
86 test -d ./--version && rmdir ./--version
87 fi
88 ;;
89 *)
90 if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
91 test ! -d ./--version; then
92 echo "mkdir -m $dirmode -p -- $*"
93 exec mkdir -m "$dirmode" -p -- "$@"
94 else
95 # Clean up after NextStep and OpenStep mkdir.
96 for d in ./-m ./-p ./--version "./$dirmode";
97 do
98 test -d $d && rmdir $d
99 done
100 fi
101 ;;
102esac
103
104for file
105do
106 case $file in
107 /*) pathcomp=/ ;;
108 *) pathcomp= ;;
109 esac
110 oIFS=$IFS
111 IFS=/
112 set fnord $file
113 shift
114 IFS=$oIFS
115
116 for d
117 do
118 test "x$d" = x && continue
119
120 pathcomp=$pathcomp$d
121 case $pathcomp in
122 -*) pathcomp=./$pathcomp ;;
123 esac
124
125 if test ! -d "$pathcomp"; then
126 echo "mkdir $pathcomp"
127
128 mkdir "$pathcomp" || lasterr=$?
129
130 if test ! -d "$pathcomp"; then
131 errstatus=$lasterr
132 else
133 if test ! -z "$dirmode"; then
134 echo "chmod $dirmode $pathcomp"
135 lasterr=
136 chmod "$dirmode" "$pathcomp" || lasterr=$?
137
138 if test ! -z "$lasterr"; then
139 errstatus=$lasterr
140 fi
141 fi
142 fi
143 fi
144
145 pathcomp=$pathcomp/
146 done
147done
148
149exit $errstatus
150
151# Local Variables:
152# mode: shell-script
153# sh-indentation: 2
154# eval: (add-hook 'write-file-hooks 'time-stamp)
155# time-stamp-start: "scriptversion="
156# time-stamp-format: "%:y-%02m-%02d.%02H"
157# time-stamp-end: "$"
158# End:
diff --git a/build-aux/warn-on-use.h b/build-aux/warn-on-use.h
new file mode 100644
index 00000000..1cd5062d
--- /dev/null
+++ b/build-aux/warn-on-use.h
@@ -0,0 +1,102 @@
1/* A C macro for emitting warnings if a function is used.
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by 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 GNU
12 Lesser 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/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
18 for FUNCTION which will then trigger a compiler warning containing
19 the text of "literal string" anywhere that function is called, if
20 supported by the compiler. If the compiler does not support this
21 feature, the macro expands to an unused extern declaration.
22
23 This macro is useful for marking a function as a potential
24 portability trap, with the intent that "literal string" include
25 instructions on the replacement function that should be used
26 instead. However, one of the reasons that a function is a
27 portability trap is if it has the wrong signature. Declaring
28 FUNCTION with a different signature in C is a compilation error, so
29 this macro must use the same type as any existing declaration so
30 that programs that avoid the problematic FUNCTION do not fail to
31 compile merely because they included a header that poisoned the
32 function. But this implies that _GL_WARN_ON_USE is only safe to
33 use if FUNCTION is known to already have a declaration. Use of
34 this macro implies that there must not be any other macro hiding
35 the declaration of FUNCTION; but undefining FUNCTION first is part
36 of the poisoning process anyway (although for symbols that are
37 provided only via a macro, the result is a compilation error rather
38 than a warning containing "literal string"). Also note that in
39 C++, it is only safe to use if FUNCTION has no overloads.
40
41 For an example, it is possible to poison 'getline' by:
42 - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
43 [getline]) in configure.ac, which potentially defines
44 HAVE_RAW_DECL_GETLINE
45 - adding this code to a header that wraps the system <stdio.h>:
46 #undef getline
47 #if HAVE_RAW_DECL_GETLINE
48 _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
49 "not universally present; use the gnulib module getline");
50 #endif
51
52 It is not possible to directly poison global variables. But it is
53 possible to write a wrapper accessor function, and poison that
54 (less common usage, like &environ, will cause a compilation error
55 rather than issue the nice warning, but the end result of informing
56 the developer about their portability problem is still achieved):
57 #if HAVE_RAW_DECL_ENVIRON
58 static inline char ***rpl_environ (void) { return &environ; }
59 _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
60 # undef environ
61 # define environ (*rpl_environ ())
62 #endif
63 */
64#ifndef _GL_WARN_ON_USE
65
66# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
67/* A compiler attribute is available in gcc versions 4.3.0 and later. */
68# define _GL_WARN_ON_USE(function, message) \
69extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
70
71# else /* Unsupported. */
72# define _GL_WARN_ON_USE(function, message) \
73_GL_WARN_EXTERN_C int _gl_warn_on_use
74# endif
75#endif
76
77/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
78 is like _GL_WARN_ON_USE (function, "string"), except that the function is
79 declared with the given prototype, consisting of return type, parameters,
80 and attributes.
81 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
82 not work in this case. */
83#ifndef _GL_WARN_ON_USE_CXX
84# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
85# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
86extern rettype function parameters_and_attributes \
87 __attribute__ ((__warning__ (msg)))
88# else /* Unsupported. */
89# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
90_GL_WARN_EXTERN_C int _gl_warn_on_use
91# endif
92#endif
93
94/* _GL_WARN_EXTERN_C declaration;
95 performs the declaration with C linkage. */
96#ifndef _GL_WARN_EXTERN_C
97# if defined __cplusplus
98# define _GL_WARN_EXTERN_C extern "C"
99# else
100# define _GL_WARN_EXTERN_C extern
101# endif
102#endif
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 87fe0316..e2dc38b7 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -1,6 +1,6 @@
1## DO NOT EDIT! GENERATED AUTOMATICALLY! 1## DO NOT EDIT! GENERATED AUTOMATICALLY!
2## Process this file with automake to produce Makefile.in. 2## Process this file with automake to produce Makefile.in.
3# Copyright (C) 2002-2009 Free Software Foundation, Inc. 3# Copyright (C) 2002-2010 Free Software Foundation, Inc.
4# 4#
5# This file is free software, distributed under the terms of the GNU 5# This file is free software, distributed under the terms of the GNU
6# General Public License. As a special exception to the GNU General 6# General Public License. As a special exception to the GNU General
@@ -62,9 +62,10 @@ BUILT_SOURCES += $(ALLOCA_H)
62# We need the following in order to create <alloca.h> when the system 62# We need the following in order to create <alloca.h> when the system
63# doesn't have one that works with the given compiler. 63# doesn't have one that works with the given compiler.
64alloca.h: alloca.in.h 64alloca.h: alloca.in.h
65 $(AM_V_GEN)rm -f $@-t $@ && \
65 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 66 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
66 cat $(srcdir)/alloca.in.h; \ 67 cat $(srcdir)/alloca.in.h; \
67 } > $@-t 68 } > $@-t && \
68 mv -f $@-t $@ 69 mv -f $@-t $@
69MOSTLYCLEANFILES += alloca.h alloca.h-t 70MOSTLYCLEANFILES += alloca.h alloca.h-t
70 71
@@ -72,15 +73,39 @@ EXTRA_DIST += alloca.in.h
72 73
73## end gnulib module alloca-opt 74## end gnulib module alloca-opt
74 75
76## begin gnulib module arg-nonnull
77
78# The BUILT_SOURCES created by this Makefile snippet are not used via #include
79# statements but through direct file reference. Therefore this snippet must be
80# present in all Makefile.am that need it. This is ensured by the applicability
81# 'all' defined above.
82
83BUILT_SOURCES += arg-nonnull.h
84# The arg-nonnull.h that gets inserted into generated .h files is the same as
85# build-aux/arg-nonnull.h, except that it has the copyright header cut off.
86arg-nonnull.h: $(top_srcdir)/build-aux/arg-nonnull.h
87 $(AM_V_GEN)rm -f $@-t $@ && \
88 sed -n -e '/GL_ARG_NONNULL/,$$p' \
89 < $(top_srcdir)/build-aux/arg-nonnull.h \
90 > $@-t && \
91 mv $@-t $@
92MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
93
94ARG_NONNULL_H=arg-nonnull.h
95
96EXTRA_DIST += $(top_srcdir)/build-aux/arg-nonnull.h
97
98## end gnulib module arg-nonnull
99
75## begin gnulib module arpa_inet 100## begin gnulib module arpa_inet
76 101
77BUILT_SOURCES += $(ARPA_INET_H) 102BUILT_SOURCES += arpa/inet.h
78 103
79# We need the following in order to create <arpa/inet.h> when the system 104# We need the following in order to create <arpa/inet.h> when the system
80# doesn't have one. 105# doesn't have one.
81arpa/inet.h: arpa_inet.in.h 106arpa/inet.h: arpa_inet.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H)
82 @MKDIR_P@ arpa 107 $(AM_V_at)$(MKDIR_P) arpa
83 rm -f $@-t $@ 108 $(AM_V_GEN)rm -f $@-t $@ && \
84 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 109 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
85 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 110 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
86 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 111 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
@@ -90,9 +115,10 @@ arpa/inet.h: arpa_inet.in.h
90 -e 's|@''GNULIB_INET_PTON''@|$(GNULIB_INET_PTON)|g' \ 115 -e 's|@''GNULIB_INET_PTON''@|$(GNULIB_INET_PTON)|g' \
91 -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ 116 -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
92 -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ 117 -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
93 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 118 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
119 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
94 < $(srcdir)/arpa_inet.in.h; \ 120 < $(srcdir)/arpa_inet.in.h; \
95 } > $@-t 121 } > $@-t && \
96 mv $@-t $@ 122 mv $@-t $@
97MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t 123MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t
98MOSTLYCLEANDIRS += arpa 124MOSTLYCLEANDIRS += arpa
@@ -116,6 +142,30 @@ EXTRA_libgnu_a_SOURCES += btowc.c
116 142
117## end gnulib module btowc 143## end gnulib module btowc
118 144
145## begin gnulib module c++defs
146
147# The BUILT_SOURCES created by this Makefile snippet are not used via #include
148# statements but through direct file reference. Therefore this snippet must be
149# present in all Makefile.am that need it. This is ensured by the applicability
150# 'all' defined above.
151
152BUILT_SOURCES += c++defs.h
153# The c++defs.h that gets inserted into generated .h files is the same as
154# build-aux/c++defs.h, except that it has the copyright header cut off.
155c++defs.h: $(top_srcdir)/build-aux/c++defs.h
156 $(AM_V_GEN)rm -f $@-t $@ && \
157 sed -n -e '/_GL_CXXDEFS/,$$p' \
158 < $(top_srcdir)/build-aux/c++defs.h \
159 > $@-t && \
160 mv $@-t $@
161MOSTLYCLEANFILES += c++defs.h c++defs.h-t
162
163CXXDEFS_H=c++defs.h
164
165EXTRA_DIST += $(top_srcdir)/build-aux/c++defs.h
166
167## end gnulib module c++defs
168
119## begin gnulib module c-strtod 169## begin gnulib module c-strtod
120 170
121 171
@@ -134,6 +184,14 @@ EXTRA_libgnu_a_SOURCES += cloexec.c
134 184
135## end gnulib module cloexec 185## end gnulib module cloexec
136 186
187## begin gnulib module close-hook
188
189libgnu_a_SOURCES += close-hook.c
190
191EXTRA_DIST += close-hook.h
192
193## end gnulib module close-hook
194
137## begin gnulib module configmake 195## begin gnulib module configmake
138 196
139# Retrieve values of the variables through 'configure' followed by 197# Retrieve values of the variables through 'configure' followed by
@@ -154,7 +212,7 @@ EXTRA_libgnu_a_SOURCES += cloexec.c
154# The Automake-defined pkg* macros are appended, in the order 212# The Automake-defined pkg* macros are appended, in the order
155# listed in the Automake 1.10a+ documentation. 213# listed in the Automake 1.10a+ documentation.
156configmake.h: Makefile 214configmake.h: Makefile
157 rm -f $@-t 215 $(AM_V_GEN)rm -f $@-t && \
158 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 216 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
159 echo '#define PREFIX "$(prefix)"'; \ 217 echo '#define PREFIX "$(prefix)"'; \
160 echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ 218 echo '#define EXEC_PREFIX "$(exec_prefix)"'; \
@@ -183,7 +241,7 @@ configmake.h: Makefile
183 echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ 241 echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \
184 echo '#define PKGLIBDIR "$(pkglibdir)"'; \ 242 echo '#define PKGLIBDIR "$(pkglibdir)"'; \
185 echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ 243 echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \
186 } | sed '/""/d' > $@-t 244 } | sed '/""/d' > $@-t && \
187 if test -f $@ && cmp $@-t $@ > /dev/null; then \ 245 if test -f $@ && cmp $@-t $@ > /dev/null; then \
188 rm -f $@-t; \ 246 rm -f $@-t; \
189 else \ 247 else \
@@ -198,12 +256,30 @@ CLEANFILES += configmake.h configmake.h-t
198## begin gnulib module dirname 256## begin gnulib module dirname
199 257
200 258
201EXTRA_DIST += basename.c dirname.c dirname.h stripslash.c 259EXTRA_DIST += basename.c dirname.c stripslash.c
202 260
203EXTRA_libgnu_a_SOURCES += basename.c dirname.c stripslash.c 261EXTRA_libgnu_a_SOURCES += basename.c dirname.c stripslash.c
204 262
205## end gnulib module dirname 263## end gnulib module dirname
206 264
265## begin gnulib module dirname-lgpl
266
267
268EXTRA_DIST += basename-lgpl.c dirname-lgpl.c dirname.h stripslash.c
269
270EXTRA_libgnu_a_SOURCES += basename-lgpl.c dirname-lgpl.c stripslash.c
271
272## end gnulib module dirname-lgpl
273
274## begin gnulib module dup2
275
276
277EXTRA_DIST += dup2.c
278
279EXTRA_libgnu_a_SOURCES += dup2.c
280
281## end gnulib module dup2
282
207## begin gnulib module errno 283## begin gnulib module errno
208 284
209BUILT_SOURCES += $(ERRNO_H) 285BUILT_SOURCES += $(ERRNO_H)
@@ -211,7 +287,7 @@ BUILT_SOURCES += $(ERRNO_H)
211# We need the following in order to create <errno.h> when the system 287# We need the following in order to create <errno.h> when the system
212# doesn't have one that is POSIX compliant. 288# doesn't have one that is POSIX compliant.
213errno.h: errno.in.h 289errno.h: errno.in.h
214 rm -f $@-t $@ 290 $(AM_V_GEN)rm -f $@-t $@ && \
215 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 291 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
216 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 292 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
217 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 293 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
@@ -223,7 +299,7 @@ errno.h: errno.in.h
223 -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \ 299 -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \
224 -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \ 300 -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \
225 < $(srcdir)/errno.in.h; \ 301 < $(srcdir)/errno.in.h; \
226 } > $@-t 302 } > $@-t && \
227 mv $@-t $@ 303 mv $@-t $@
228MOSTLYCLEANFILES += errno.h errno.h-t 304MOSTLYCLEANFILES += errno.h errno.h-t
229 305
@@ -242,35 +318,52 @@ EXTRA_libgnu_a_SOURCES += error.c
242 318
243## begin gnulib module exitfail 319## begin gnulib module exitfail
244 320
321libgnu_a_SOURCES += exitfail.c
245 322
246EXTRA_DIST += exitfail.c exitfail.h 323EXTRA_DIST += exitfail.h
247
248EXTRA_libgnu_a_SOURCES += exitfail.c
249 324
250## end gnulib module exitfail 325## end gnulib module exitfail
251 326
252## begin gnulib module fcntl 327## begin gnulib module fcntl
253 328
254BUILT_SOURCES += $(FCNTL_H) 329
330EXTRA_DIST += fcntl.c
331
332EXTRA_libgnu_a_SOURCES += fcntl.c
333
334## end gnulib module fcntl
335
336## begin gnulib module fcntl-h
337
338BUILT_SOURCES += fcntl.h
255 339
256# We need the following in order to create <fcntl.h> when the system 340# We need the following in order to create <fcntl.h> when the system
257# doesn't have one that works with the given compiler. 341# doesn't have one that works with the given compiler.
258fcntl.h: fcntl.in.h 342fcntl.h: fcntl.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
259 rm -f $@-t $@ 343 $(AM_V_GEN)rm -f $@-t $@ && \
260 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 344 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
261 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 345 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
262 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 346 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
263 -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \ 347 -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
348 -e 's|@''GNULIB_FCNTL''@|$(GNULIB_FCNTL)|g' \
264 -e 's|@''GNULIB_OPEN''@|$(GNULIB_OPEN)|g' \ 349 -e 's|@''GNULIB_OPEN''@|$(GNULIB_OPEN)|g' \
350 -e 's|@''GNULIB_OPENAT''@|$(GNULIB_OPENAT)|g' \
351 -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
352 -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
353 -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
265 -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \ 354 -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
355 -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
356 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
357 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
358 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
266 < $(srcdir)/fcntl.in.h; \ 359 < $(srcdir)/fcntl.in.h; \
267 } > $@-t 360 } > $@-t && \
268 mv $@-t $@ 361 mv $@-t $@
269MOSTLYCLEANFILES += fcntl.h fcntl.h-t 362MOSTLYCLEANFILES += fcntl.h fcntl.h-t
270 363
271EXTRA_DIST += fcntl.in.h 364EXTRA_DIST += fcntl.in.h
272 365
273## end gnulib module fcntl 366## end gnulib module fcntl-h
274 367
275## begin gnulib module fcntl-safer 368## begin gnulib module fcntl-safer
276 369
@@ -288,13 +381,13 @@ BUILT_SOURCES += $(FLOAT_H)
288# We need the following in order to create <float.h> when the system 381# We need the following in order to create <float.h> when the system
289# doesn't have one that works with the given compiler. 382# doesn't have one that works with the given compiler.
290float.h: float.in.h 383float.h: float.in.h
291 rm -f $@-t $@ 384 $(AM_V_GEN)rm -f $@-t $@ && \
292 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 385 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
293 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 386 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
294 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 387 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
295 -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \ 388 -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \
296 < $(srcdir)/float.in.h; \ 389 < $(srcdir)/float.in.h; \
297 } > $@-t 390 } > $@-t && \
298 mv $@-t $@ 391 mv $@-t $@
299MOSTLYCLEANFILES += float.h float.h-t 392MOSTLYCLEANFILES += float.h float.h-t
300 393
@@ -341,10 +434,19 @@ EXTRA_libgnu_a_SOURCES += gai_strerror.c getaddrinfo.c
341 434
342## end gnulib module getaddrinfo 435## end gnulib module getaddrinfo
343 436
437## begin gnulib module getdtablesize
438
439
440EXTRA_DIST += getdtablesize.c
441
442EXTRA_libgnu_a_SOURCES += getdtablesize.c
443
444## end gnulib module getdtablesize
445
344## begin gnulib module gethostname 446## begin gnulib module gethostname
345 447
346 448
347EXTRA_DIST += gethostname.c 449EXTRA_DIST += gethostname.c w32sock.h
348 450
349EXTRA_libgnu_a_SOURCES += gethostname.c 451EXTRA_libgnu_a_SOURCES += gethostname.c
350 452
@@ -359,16 +461,22 @@ EXTRA_libgnu_a_SOURCES += getloadavg.c
359 461
360## end gnulib module getloadavg 462## end gnulib module getloadavg
361 463
362## begin gnulib module getopt 464## begin gnulib module getopt-posix
363 465
364BUILT_SOURCES += $(GETOPT_H) 466BUILT_SOURCES += $(GETOPT_H)
365 467
366# We need the following in order to create <getopt.h> when the system 468# We need the following in order to create <getopt.h> when the system
367# doesn't have one that works with the given compiler. 469# doesn't have one that works with the given compiler.
368getopt.h: getopt.in.h 470getopt.h: getopt.in.h $(ARG_NONNULL_H)
471 $(AM_V_GEN)rm -f $@-t $@ && \
369 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 472 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
370 cat $(srcdir)/getopt.in.h; \ 473 sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \
371 } > $@-t 474 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
475 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
476 -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \
477 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
478 < $(srcdir)/getopt.in.h; \
479 } > $@-t && \
372 mv -f $@-t $@ 480 mv -f $@-t $@
373MOSTLYCLEANFILES += getopt.h getopt.h-t 481MOSTLYCLEANFILES += getopt.h getopt.h-t
374 482
@@ -376,7 +484,7 @@ EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h
376 484
377EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c 485EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c
378 486
379## end gnulib module getopt 487## end gnulib module getopt-posix
380 488
381## begin gnulib module gettext 489## begin gnulib module gettext
382 490
@@ -423,13 +531,34 @@ EXTRA_DIST += intprops.h
423 531
424## end gnulib module intprops 532## end gnulib module intprops
425 533
426## begin gnulib module link-warning 534## begin gnulib module langinfo
427 535
428LINK_WARNING_H=$(top_srcdir)/build-aux/link-warning.h 536BUILT_SOURCES += langinfo.h
429 537
430EXTRA_DIST += $(top_srcdir)/build-aux/link-warning.h 538# We need the following in order to create an empty placeholder for
539# <langinfo.h> when the system doesn't have one.
540langinfo.h: langinfo.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
541 $(AM_V_GEN)rm -f $@-t $@ && \
542 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
543 sed -e 's|@''HAVE_LANGINFO_H''@|$(HAVE_LANGINFO_H)|g' \
544 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
545 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
546 -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \
547 -e 's|@''GNULIB_NL_LANGINFO''@|$(GNULIB_NL_LANGINFO)|g' \
548 -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \
549 -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \
550 -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \
551 -e 's|@''REPLACE_NL_LANGINFO''@|$(REPLACE_NL_LANGINFO)|g' \
552 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
553 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
554 < $(srcdir)/langinfo.in.h; \
555 } > $@-t && \
556 mv $@-t $@
557MOSTLYCLEANFILES += langinfo.h langinfo.h-t
558
559EXTRA_DIST += langinfo.in.h
431 560
432## end gnulib module link-warning 561## end gnulib module langinfo
433 562
434## begin gnulib module localcharset 563## begin gnulib module localcharset
435 564
@@ -489,14 +618,14 @@ uninstall-localcharset: all-local
489 fi 618 fi
490 619
491charset.alias: config.charset 620charset.alias: config.charset
492 rm -f t-$@ $@ 621 $(AM_V_GEN)rm -f t-$@ $@ && \
493 $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ 622 $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ && \
494 mv t-$@ $@ 623 mv t-$@ $@
495 624
496SUFFIXES += .sed .sin 625SUFFIXES += .sed .sin
497.sin.sed: 626.sin.sed:
498 rm -f t-$@ $@ 627 $(AM_V_GEN)rm -f t-$@ $@ && \
499 sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ 628 sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ && \
500 mv t-$@ $@ 629 mv t-$@ $@
501 630
502CLEANFILES += charset.alias ref-add.sed ref-del.sed 631CLEANFILES += charset.alias ref-add.sed ref-del.sed
@@ -505,6 +634,34 @@ EXTRA_DIST += config.charset ref-add.sin ref-del.sin
505 634
506## end gnulib module localcharset 635## end gnulib module localcharset
507 636
637## begin gnulib module locale
638
639BUILT_SOURCES += locale.h
640
641# We need the following in order to create <locale.h> when the system
642# doesn't have one that provides all definitions.
643locale.h: locale.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
644 $(AM_V_GEN)rm -f $@-t $@ && \
645 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
646 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
647 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
648 -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \
649 -e 's|@''GNULIB_DUPLOCALE''@|$(GNULIB_DUPLOCALE)|g' \
650 -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \
651 -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
652 -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \
653 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
654 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
655 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
656 < $(srcdir)/locale.in.h; \
657 } > $@-t && \
658 mv $@-t $@
659MOSTLYCLEANFILES += locale.h locale.h-t
660
661EXTRA_DIST += locale.in.h
662
663## end gnulib module locale
664
508## begin gnulib module malloc 665## begin gnulib module malloc
509 666
510 667
@@ -529,14 +686,19 @@ BUILT_SOURCES += math.h
529 686
530# We need the following in order to create <math.h> when the system 687# We need the following in order to create <math.h> when the system
531# doesn't have one that works with the given compiler. 688# doesn't have one that works with the given compiler.
532math.h: math.in.h 689math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
533 rm -f $@-t $@ 690 $(AM_V_GEN)rm -f $@-t $@ && \
534 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 691 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
535 sed -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \ 692 sed -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \
536 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 693 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
537 -e 's|@''NEXT_MATH_H''@|$(NEXT_MATH_H)|g' \ 694 -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \
695 -e 's|@''GNULIB_ACOSL''@|$(GNULIB_ACOSL)|g' \
696 -e 's|@''GNULIB_ASINL''@|$(GNULIB_ASINL)|g' \
697 -e 's|@''GNULIB_ATANL''@|$(GNULIB_ATANL)|g' \
538 -e 's|@''GNULIB_CEILF''@|$(GNULIB_CEILF)|g' \ 698 -e 's|@''GNULIB_CEILF''@|$(GNULIB_CEILF)|g' \
539 -e 's|@''GNULIB_CEILL''@|$(GNULIB_CEILL)|g' \ 699 -e 's|@''GNULIB_CEILL''@|$(GNULIB_CEILL)|g' \
700 -e 's|@''GNULIB_COSL''@|$(GNULIB_COSL)|g' \
701 -e 's|@''GNULIB_EXPL''@|$(GNULIB_EXPL)|g' \
540 -e 's|@''GNULIB_FLOORF''@|$(GNULIB_FLOORF)|g' \ 702 -e 's|@''GNULIB_FLOORF''@|$(GNULIB_FLOORF)|g' \
541 -e 's|@''GNULIB_FLOORL''@|$(GNULIB_FLOORL)|g' \ 703 -e 's|@''GNULIB_FLOORL''@|$(GNULIB_FLOORL)|g' \
542 -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \ 704 -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \
@@ -548,30 +710,52 @@ math.h: math.in.h
548 -e 's|@''GNULIB_ISNAND''@|$(GNULIB_ISNAND)|g' \ 710 -e 's|@''GNULIB_ISNAND''@|$(GNULIB_ISNAND)|g' \
549 -e 's|@''GNULIB_ISNANL''@|$(GNULIB_ISNANL)|g' \ 711 -e 's|@''GNULIB_ISNANL''@|$(GNULIB_ISNANL)|g' \
550 -e 's|@''GNULIB_LDEXPL''@|$(GNULIB_LDEXPL)|g' \ 712 -e 's|@''GNULIB_LDEXPL''@|$(GNULIB_LDEXPL)|g' \
551 -e 's|@''GNULIB_MATHL''@|$(GNULIB_MATHL)|g' \ 713 -e 's|@''GNULIB_LOGB''@|$(GNULIB_LOGB)|g' \
714 -e 's|@''GNULIB_LOGL''@|$(GNULIB_LOGL)|g' \
552 -e 's|@''GNULIB_ROUND''@|$(GNULIB_ROUND)|g' \ 715 -e 's|@''GNULIB_ROUND''@|$(GNULIB_ROUND)|g' \
553 -e 's|@''GNULIB_ROUNDF''@|$(GNULIB_ROUNDF)|g' \ 716 -e 's|@''GNULIB_ROUNDF''@|$(GNULIB_ROUNDF)|g' \
554 -e 's|@''GNULIB_ROUNDL''@|$(GNULIB_ROUNDL)|g' \ 717 -e 's|@''GNULIB_ROUNDL''@|$(GNULIB_ROUNDL)|g' \
555 -e 's|@''GNULIB_SIGNBIT''@|$(GNULIB_SIGNBIT)|g' \ 718 -e 's|@''GNULIB_SIGNBIT''@|$(GNULIB_SIGNBIT)|g' \
719 -e 's|@''GNULIB_SINL''@|$(GNULIB_SINL)|g' \
720 -e 's|@''GNULIB_SQRTL''@|$(GNULIB_SQRTL)|g' \
721 -e 's|@''GNULIB_TANL''@|$(GNULIB_TANL)|g' \
556 -e 's|@''GNULIB_TRUNC''@|$(GNULIB_TRUNC)|g' \ 722 -e 's|@''GNULIB_TRUNC''@|$(GNULIB_TRUNC)|g' \
557 -e 's|@''GNULIB_TRUNCF''@|$(GNULIB_TRUNCF)|g' \ 723 -e 's|@''GNULIB_TRUNCF''@|$(GNULIB_TRUNCF)|g' \
558 -e 's|@''GNULIB_TRUNCL''@|$(GNULIB_TRUNCL)|g' \ 724 -e 's|@''GNULIB_TRUNCL''@|$(GNULIB_TRUNCL)|g' \
725 -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \
726 -e 's|@''HAVE_ASINL''@|$(HAVE_ASINL)|g' \
727 -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \
728 -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \
729 -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \
559 -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \ 730 -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
560 -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \ 731 -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
561 -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \ 732 -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
733 -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \
734 -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \
735 -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \
736 -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \
562 -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ 737 -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \
563 -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \ 738 -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \
564 -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \ 739 -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \
740 -e 's|@''HAVE_DECL_CEILF''@|$(HAVE_DECL_CEILF)|g' \
741 -e 's|@''HAVE_DECL_CEILL''@|$(HAVE_DECL_CEILL)|g' \
565 -e 's|@''HAVE_DECL_COSL''@|$(HAVE_DECL_COSL)|g' \ 742 -e 's|@''HAVE_DECL_COSL''@|$(HAVE_DECL_COSL)|g' \
566 -e 's|@''HAVE_DECL_EXPL''@|$(HAVE_DECL_EXPL)|g' \ 743 -e 's|@''HAVE_DECL_EXPL''@|$(HAVE_DECL_EXPL)|g' \
744 -e 's|@''HAVE_DECL_FLOORF''@|$(HAVE_DECL_FLOORF)|g' \
745 -e 's|@''HAVE_DECL_FLOORL''@|$(HAVE_DECL_FLOORL)|g' \
567 -e 's|@''HAVE_DECL_FREXPL''@|$(HAVE_DECL_FREXPL)|g' \ 746 -e 's|@''HAVE_DECL_FREXPL''@|$(HAVE_DECL_FREXPL)|g' \
568 -e 's|@''HAVE_DECL_LDEXPL''@|$(HAVE_DECL_LDEXPL)|g' \ 747 -e 's|@''HAVE_DECL_LDEXPL''@|$(HAVE_DECL_LDEXPL)|g' \
748 -e 's|@''HAVE_DECL_LOGB''@|$(HAVE_DECL_LOGB)|g' \
569 -e 's|@''HAVE_DECL_LOGL''@|$(HAVE_DECL_LOGL)|g' \ 749 -e 's|@''HAVE_DECL_LOGL''@|$(HAVE_DECL_LOGL)|g' \
750 -e 's|@''HAVE_DECL_ROUND''@|$(HAVE_DECL_ROUND)|g' \
751 -e 's|@''HAVE_DECL_ROUNDF''@|$(HAVE_DECL_ROUNDF)|g' \
752 -e 's|@''HAVE_DECL_ROUNDL''@|$(HAVE_DECL_ROUNDL)|g' \
570 -e 's|@''HAVE_DECL_SINL''@|$(HAVE_DECL_SINL)|g' \ 753 -e 's|@''HAVE_DECL_SINL''@|$(HAVE_DECL_SINL)|g' \
571 -e 's|@''HAVE_DECL_SQRTL''@|$(HAVE_DECL_SQRTL)|g' \ 754 -e 's|@''HAVE_DECL_SQRTL''@|$(HAVE_DECL_SQRTL)|g' \
572 -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \ 755 -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \
573 -e 's|@''HAVE_DECL_TRUNC''@|$(HAVE_DECL_TRUNC)|g' \ 756 -e 's|@''HAVE_DECL_TRUNC''@|$(HAVE_DECL_TRUNC)|g' \
574 -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \ 757 -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \
758 -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \
575 -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ 759 -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \
576 -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ 760 -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \
577 -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \ 761 -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \
@@ -590,9 +774,11 @@ math.h: math.in.h
590 -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \ 774 -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \
591 -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ 775 -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \
592 -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ 776 -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \
593 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 777 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
778 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
779 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
594 < $(srcdir)/math.in.h; \ 780 < $(srcdir)/math.in.h; \
595 } > $@-t 781 } > $@-t && \
596 mv $@-t $@ 782 mv $@-t $@
597MOSTLYCLEANFILES += math.h math.h-t 783MOSTLYCLEANFILES += math.h math.h-t
598 784
@@ -618,10 +804,19 @@ EXTRA_libgnu_a_SOURCES += mbsinit.c
618 804
619## end gnulib module mbsinit 805## end gnulib module mbsinit
620 806
807## begin gnulib module memchr
808
809
810EXTRA_DIST += memchr.c memchr.valgrind
811
812EXTRA_libgnu_a_SOURCES += memchr.c
813
814## end gnulib module memchr
815
621## begin gnulib module mktime 816## begin gnulib module mktime
622 817
623 818
624EXTRA_DIST += mktime.c 819EXTRA_DIST += mktime-internal.h mktime.c
625 820
626EXTRA_libgnu_a_SOURCES += mktime.c 821EXTRA_libgnu_a_SOURCES += mktime.c
627 822
@@ -642,8 +837,8 @@ BUILT_SOURCES += $(NETDB_H)
642 837
643# We need the following in order to create <netdb.h> when the system 838# We need the following in order to create <netdb.h> when the system
644# doesn't have one that works with the given compiler. 839# doesn't have one that works with the given compiler.
645netdb.h: netdb.in.h 840netdb.h: netdb.in.h $(ARG_NONNULL_H)
646 rm -f $@-t $@ 841 $(AM_V_GEN)rm -f $@-t $@ && \
647 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 842 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
648 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 843 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
649 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 844 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
@@ -655,8 +850,9 @@ netdb.h: netdb.in.h
655 -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \ 850 -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
656 -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \ 851 -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
657 -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \ 852 -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
853 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
658 < $(srcdir)/netdb.in.h; \ 854 < $(srcdir)/netdb.in.h; \
659 } > $@-t 855 } > $@-t && \
660 mv $@-t $@ 856 mv $@-t $@
661MOSTLYCLEANFILES += netdb.h netdb.h-t 857MOSTLYCLEANFILES += netdb.h netdb.h-t
662 858
@@ -671,15 +867,15 @@ BUILT_SOURCES += $(NETINET_IN_H)
671# We need the following in order to create <netinet/in.h> when the system 867# We need the following in order to create <netinet/in.h> when the system
672# doesn't have one. 868# doesn't have one.
673netinet/in.h: netinet_in.in.h 869netinet/in.h: netinet_in.in.h
674 @MKDIR_P@ netinet 870 $(AM_V_at)$(MKDIR_P) netinet
675 rm -f $@-t $@ 871 $(AM_V_GEN)rm -f $@-t $@ && \
676 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 872 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
677 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 873 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
678 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 874 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
679 -e 's|@''NEXT_NETINET_IN_H''@|$(NEXT_NETINET_IN_H)|g' \ 875 -e 's|@''NEXT_NETINET_IN_H''@|$(NEXT_NETINET_IN_H)|g' \
680 -e 's|@''HAVE_NETINET_IN_H''@|$(HAVE_NETINET_IN_H)|g' \ 876 -e 's|@''HAVE_NETINET_IN_H''@|$(HAVE_NETINET_IN_H)|g' \
681 < $(srcdir)/netinet_in.in.h; \ 877 < $(srcdir)/netinet_in.in.h; \
682 } > $@-t 878 } > $@-t && \
683 mv $@-t $@ 879 mv $@-t $@
684MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t 880MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t
685MOSTLYCLEANDIRS += netinet 881MOSTLYCLEANDIRS += netinet
@@ -688,6 +884,15 @@ EXTRA_DIST += netinet_in.in.h
688 884
689## end gnulib module netinet_in 885## end gnulib module netinet_in
690 886
887## begin gnulib module nl_langinfo
888
889
890EXTRA_DIST += nl_langinfo.c
891
892EXTRA_libgnu_a_SOURCES += nl_langinfo.c
893
894## end gnulib module nl_langinfo
895
691## begin gnulib module open 896## begin gnulib module open
692 897
693 898
@@ -739,6 +944,23 @@ EXTRA_libgnu_a_SOURCES += snprintf.c
739 944
740## end gnulib module snprintf 945## end gnulib module snprintf
741 946
947## begin gnulib module sockets
948
949libgnu_a_SOURCES += sockets.h sockets.c
950
951EXTRA_DIST += w32sock.h
952
953## end gnulib module sockets
954
955## begin gnulib module stat
956
957
958EXTRA_DIST += stat.c
959
960EXTRA_libgnu_a_SOURCES += stat.c
961
962## end gnulib module stat
963
742## begin gnulib module stdbool 964## begin gnulib module stdbool
743 965
744BUILT_SOURCES += $(STDBOOL_H) 966BUILT_SOURCES += $(STDBOOL_H)
@@ -746,10 +968,10 @@ BUILT_SOURCES += $(STDBOOL_H)
746# We need the following in order to create <stdbool.h> when the system 968# We need the following in order to create <stdbool.h> when the system
747# doesn't have one that works. 969# doesn't have one that works.
748stdbool.h: stdbool.in.h 970stdbool.h: stdbool.in.h
749 rm -f $@-t $@ 971 $(AM_V_GEN)rm -f $@-t $@ && \
750 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 972 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
751 sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \ 973 sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \
752 } > $@-t 974 } > $@-t && \
753 mv $@-t $@ 975 mv $@-t $@
754MOSTLYCLEANFILES += stdbool.h stdbool.h-t 976MOSTLYCLEANFILES += stdbool.h stdbool.h-t
755 977
@@ -757,6 +979,29 @@ EXTRA_DIST += stdbool.in.h
757 979
758## end gnulib module stdbool 980## end gnulib module stdbool
759 981
982## begin gnulib module stddef
983
984BUILT_SOURCES += $(STDDEF_H)
985
986# We need the following in order to create <stddef.h> when the system
987# doesn't have one that works with the given compiler.
988stddef.h: stddef.in.h
989 $(AM_V_GEN)rm -f $@-t $@ && \
990 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
991 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
992 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
993 -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
994 -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
995 -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \
996 < $(srcdir)/stddef.in.h; \
997 } > $@-t && \
998 mv $@-t $@
999MOSTLYCLEANFILES += stddef.h stddef.h-t
1000
1001EXTRA_DIST += stddef.in.h
1002
1003## end gnulib module stddef
1004
760## begin gnulib module stdint 1005## begin gnulib module stdint
761 1006
762BUILT_SOURCES += $(STDINT_H) 1007BUILT_SOURCES += $(STDINT_H)
@@ -764,7 +1009,7 @@ BUILT_SOURCES += $(STDINT_H)
764# We need the following in order to create <stdint.h> when the system 1009# We need the following in order to create <stdint.h> when the system
765# doesn't have one that works with the given compiler. 1010# doesn't have one that works with the given compiler.
766stdint.h: stdint.in.h 1011stdint.h: stdint.in.h
767 rm -f $@-t $@ 1012 $(AM_V_GEN)rm -f $@-t $@ && \
768 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1013 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
769 sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ 1014 sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
770 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1015 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
@@ -791,7 +1036,7 @@ stdint.h: stdint.in.h
791 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ 1036 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
792 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ 1037 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
793 < $(srcdir)/stdint.in.h; \ 1038 < $(srcdir)/stdint.in.h; \
794 } > $@-t 1039 } > $@-t && \
795 mv $@-t $@ 1040 mv $@-t $@
796MOSTLYCLEANFILES += stdint.h stdint.h-t 1041MOSTLYCLEANFILES += stdint.h stdint.h-t
797 1042
@@ -805,81 +1050,100 @@ BUILT_SOURCES += stdio.h
805 1050
806# We need the following in order to create <stdio.h> when the system 1051# We need the following in order to create <stdio.h> when the system
807# doesn't have one that works with the given compiler. 1052# doesn't have one that works with the given compiler.
808stdio.h: stdio.in.h 1053stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
809 rm -f $@-t $@ 1054 $(AM_V_GEN)rm -f $@-t $@ && \
810 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1055 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
811 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1056 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
812 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1057 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
813 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \ 1058 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
814 -e 's|@''GNULIB_FPRINTF''@|$(GNULIB_FPRINTF)|g' \
815 -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
816 -e 's|@''GNULIB_PRINTF''@|$(GNULIB_PRINTF)|g' \
817 -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \
818 -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
819 -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
820 -e 's|@''GNULIB_VFPRINTF''@|$(GNULIB_VFPRINTF)|g' \
821 -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
822 -e 's|@''GNULIB_VPRINTF''@|$(GNULIB_VPRINTF)|g' \
823 -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
824 -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
825 -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
826 -e 's|@''GNULIB_DPRINTF''@|$(GNULIB_DPRINTF)|g' \ 1059 -e 's|@''GNULIB_DPRINTF''@|$(GNULIB_DPRINTF)|g' \
827 -e 's|@''GNULIB_VDPRINTF''@|$(GNULIB_VDPRINTF)|g' \ 1060 -e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
828 -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \ 1061 -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
829 -e 's|@''GNULIB_OBSTACK_PRINTF''@|$(GNULIB_OBSTACK_PRINTF)|g' \
830 -e 's|@''GNULIB_OBSTACK_PRINTF_POSIX''@|$(GNULIB_OBSTACK_PRINTF_POSIX)|g' \
831 -e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \ 1062 -e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \
1063 -e 's|@''GNULIB_FPRINTF''@|$(GNULIB_FPRINTF)|g' \
1064 -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
1065 -e 's|@''GNULIB_FPURGE''@|$(GNULIB_FPURGE)|g' \
1066 -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
1067 -e 's|@''GNULIB_FPUTS''@|$(GNULIB_FPUTS)|g' \
832 -e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \ 1068 -e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \
833 -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \ 1069 -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
834 -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \ 1070 -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
835 -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \ 1071 -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
836 -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \ 1072 -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
837 -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
838 -e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
839 -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
840 -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
841 -e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
842 -e 's|@''GNULIB_FPUTS''@|$(GNULIB_FPUTS)|g' \
843 -e 's|@''GNULIB_PUTS''@|$(GNULIB_PUTS)|g' \
844 -e 's|@''GNULIB_FWRITE''@|$(GNULIB_FWRITE)|g' \ 1073 -e 's|@''GNULIB_FWRITE''@|$(GNULIB_FWRITE)|g' \
845 -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \ 1074 -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \
846 -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \ 1075 -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \
1076 -e 's|@''GNULIB_OBSTACK_PRINTF''@|$(GNULIB_OBSTACK_PRINTF)|g' \
1077 -e 's|@''GNULIB_OBSTACK_PRINTF_POSIX''@|$(GNULIB_OBSTACK_PRINTF_POSIX)|g' \
847 -e 's|@''GNULIB_PERROR''@|$(GNULIB_PERROR)|g' \ 1078 -e 's|@''GNULIB_PERROR''@|$(GNULIB_PERROR)|g' \
1079 -e 's|@''GNULIB_POPEN''@|$(GNULIB_POPEN)|g' \
1080 -e 's|@''GNULIB_PRINTF''@|$(GNULIB_PRINTF)|g' \
1081 -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \
1082 -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
1083 -e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
1084 -e 's|@''GNULIB_PUTS''@|$(GNULIB_PUTS)|g' \
1085 -e 's|@''GNULIB_REMOVE''@|$(GNULIB_REMOVE)|g' \
1086 -e 's|@''GNULIB_RENAME''@|$(GNULIB_RENAME)|g' \
1087 -e 's|@''GNULIB_RENAMEAT''@|$(GNULIB_RENAMEAT)|g' \
1088 -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
1089 -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
848 -e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \ 1090 -e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \
849 -e 's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \ 1091 -e 's|@''GNULIB_TMPFILE''@|$(GNULIB_TMPFILE)|g' \
850 -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ 1092 -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
851 -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \ 1093 -e 's|@''GNULIB_VDPRINTF''@|$(GNULIB_VDPRINTF)|g' \
852 -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ 1094 -e 's|@''GNULIB_VFPRINTF''@|$(GNULIB_VFPRINTF)|g' \
853 -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \ 1095 -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
854 -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \ 1096 -e 's|@''GNULIB_VPRINTF''@|$(GNULIB_VPRINTF)|g' \
1097 -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
1098 -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
1099 -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
1100 < $(srcdir)/stdio.in.h | \
1101 sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
1102 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
1103 -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
1104 -e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \
855 -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \ 1105 -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
856 -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
857 -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \ 1106 -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
858 -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
859 -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
860 -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \ 1107 -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
861 -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \ 1108 -e 's|@''HAVE_FSEEKO''@|$(HAVE_FSEEKO)|g' \
862 -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \ 1109 -e 's|@''HAVE_FTELLO''@|$(HAVE_FTELLO)|g' \
863 -e 's|@''REPLACE_VDPRINTF''@|$(REPLACE_VDPRINTF)|g' \ 1110 -e 's|@''HAVE_RENAMEAT''@|$(HAVE_RENAMEAT)|g' \
864 -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \ 1111 -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
865 -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \ 1112 -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \
866 -e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \ 1113 -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \
867 -e 's|@''REPLACE_OBSTACK_PRINTF''@|$(REPLACE_OBSTACK_PRINTF)|g' \ 1114 -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
1115 -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
868 -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \ 1116 -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
1117 -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
1118 -e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \
869 -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \ 1119 -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \
870 -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
871 -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \ 1120 -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \
872 -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \ 1121 -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
873 -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \ 1122 -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
874 -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \ 1123 -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
875 -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \ 1124 -e 's|@''REPLACE_GETDELIM''@|$(REPLACE_GETDELIM)|g' \
876 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
877 -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
878 -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \ 1125 -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \
1126 -e 's|@''REPLACE_OBSTACK_PRINTF''@|$(REPLACE_OBSTACK_PRINTF)|g' \
879 -e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \ 1127 -e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \
880 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 1128 -e 's|@''REPLACE_POPEN''@|$(REPLACE_POPEN)|g' \
881 < $(srcdir)/stdio.in.h; \ 1129 -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \
882 } > $@-t 1130 -e 's|@''REPLACE_REMOVE''@|$(REPLACE_REMOVE)|g' \
1131 -e 's|@''REPLACE_RENAME''@|$(REPLACE_RENAME)|g' \
1132 -e 's|@''REPLACE_RENAMEAT''@|$(REPLACE_RENAMEAT)|g' \
1133 -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
1134 -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
1135 -e 's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \
1136 -e 's|@''REPLACE_TMPFILE''@|$(REPLACE_TMPFILE)|g' \
1137 -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
1138 -e 's|@''REPLACE_VDPRINTF''@|$(REPLACE_VDPRINTF)|g' \
1139 -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
1140 -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \
1141 -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
1142 -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
1143 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1144 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1145 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
1146 } > $@-t && \
883 mv $@-t $@ 1147 mv $@-t $@
884MOSTLYCLEANFILES += stdio.h stdio.h-t 1148MOSTLYCLEANFILES += stdio.h stdio.h-t
885 1149
@@ -895,36 +1159,53 @@ BUILT_SOURCES += stdlib.h
895 1159
896# We need the following in order to create <stdlib.h> when the system 1160# We need the following in order to create <stdlib.h> when the system
897# doesn't have one that works with the given compiler. 1161# doesn't have one that works with the given compiler.
898stdlib.h: stdlib.in.h 1162stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
899 rm -f $@-t $@ 1163 $(AM_V_GEN)rm -f $@-t $@ && \
900 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1164 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
901 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1165 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
902 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1166 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
903 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ 1167 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
904 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
905 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
906 -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
907 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
908 -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \ 1168 -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
1169 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
1170 -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \
909 -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \ 1171 -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
910 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ 1172 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
1173 -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
1174 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
911 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ 1175 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
1176 -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
1177 -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
912 -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \ 1178 -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
1179 -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \
1180 -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \
913 -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \ 1181 -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
914 -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \ 1182 -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
1183 -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
1184 -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \
915 -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \ 1185 -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \
916 -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \ 1186 -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
917 -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \ 1187 -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \
918 -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \ 1188 -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \
919 -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \ 1189 -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
1190 -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
920 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ 1191 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
921 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 1192 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
922 -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ 1193 -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
1194 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
1195 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
923 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ 1196 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
1197 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
924 -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ 1198 -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
925 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ 1199 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
926 -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ 1200 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
1201 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
1202 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
1203 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
1204 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
1205 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
927 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ 1206 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
1207 -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
1208 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
928 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ 1209 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
929 -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \ 1210 -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
930 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \ 1211 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
@@ -932,15 +1213,20 @@ stdlib.h: stdlib.in.h
932 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ 1213 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
933 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ 1214 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
934 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ 1215 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
1216 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
935 -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ 1217 -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
936 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ 1218 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
937 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 1219 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
938 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 1220 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
1221 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
1222 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
939 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ 1223 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
940 -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \ 1224 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
941 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 1225 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1226 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1227 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
942 < $(srcdir)/stdlib.in.h; \ 1228 < $(srcdir)/stdlib.in.h; \
943 } > $@-t 1229 } > $@-t && \
944 mv $@-t $@ 1230 mv $@-t $@
945MOSTLYCLEANFILES += stdlib.h stdlib.h-t 1231MOSTLYCLEANFILES += stdlib.h stdlib.h-t
946 1232
@@ -979,8 +1265,8 @@ BUILT_SOURCES += string.h
979 1265
980# We need the following in order to create <string.h> when the system 1266# We need the following in order to create <string.h> when the system
981# doesn't have one that works with the given compiler. 1267# doesn't have one that works with the given compiler.
982string.h: string.in.h 1268string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
983 rm -f $@-t $@ 1269 $(AM_V_GEN)rm -f $@-t $@ && \
984 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1270 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
985 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1271 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
986 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1272 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
@@ -999,6 +1285,7 @@ string.h: string.in.h
999 -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \ 1285 -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \
1000 -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \ 1286 -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \
1001 -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \ 1287 -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \
1288 -e 's|@''GNULIB_MEMCHR''@|$(GNULIB_MEMCHR)|g' \
1002 -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \ 1289 -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \
1003 -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \ 1290 -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \
1004 -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \ 1291 -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \
@@ -1007,6 +1294,7 @@ string.h: string.in.h
1007 -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \ 1294 -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \
1008 -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \ 1295 -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \
1009 -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \ 1296 -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \
1297 -e 's|@''GNULIB_STRNCAT''@|$(GNULIB_STRNCAT)|g' \
1010 -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \ 1298 -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \
1011 -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \ 1299 -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \
1012 -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \ 1300 -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \
@@ -1017,6 +1305,9 @@ string.h: string.in.h
1017 -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \ 1305 -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \
1018 -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \ 1306 -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \
1019 -e 's|@''GNULIB_STRVERSCMP''@|$(GNULIB_STRVERSCMP)|g' \ 1307 -e 's|@''GNULIB_STRVERSCMP''@|$(GNULIB_STRVERSCMP)|g' \
1308 < $(srcdir)/string.in.h | \
1309 sed -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \
1310 -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \
1020 -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ 1311 -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
1021 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ 1312 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
1022 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ 1313 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
@@ -1025,25 +1316,31 @@ string.h: string.in.h
1025 -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ 1316 -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \
1026 -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ 1317 -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \
1027 -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ 1318 -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \
1028 -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \
1029 -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ 1319 -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \
1030 -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ 1320 -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \
1031 -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ 1321 -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \
1032 -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ 1322 -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \
1033 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ 1323 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \
1034 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ 1324 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
1035 -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \
1036 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ 1325 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
1037 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ 1326 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
1327 -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \
1328 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
1038 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ 1329 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
1039 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ 1330 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
1040 -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ 1331 -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \
1041 -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ 1332 -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
1042 -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ 1333 -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
1334 -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \
1335 -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \
1043 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ 1336 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \
1044 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 1337 -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \
1338 -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \
1339 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1340 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1341 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
1045 < $(srcdir)/string.in.h; \ 1342 < $(srcdir)/string.in.h; \
1046 } > $@-t 1343 } > $@-t && \
1047 mv $@-t $@ 1344 mv $@-t $@
1048MOSTLYCLEANFILES += string.h string.h-t 1345MOSTLYCLEANFILES += string.h string.h-t
1049 1346
@@ -1069,14 +1366,24 @@ EXTRA_libgnu_a_SOURCES += strnlen.c
1069 1366
1070## end gnulib module strnlen 1367## end gnulib module strnlen
1071 1368
1369## begin gnulib module strstr-simple
1370
1371
1372EXTRA_DIST += str-two-way.h strstr.c
1373
1374EXTRA_libgnu_a_SOURCES += strstr.c
1375
1376## end gnulib module strstr-simple
1377
1072## begin gnulib module sys_socket 1378## begin gnulib module sys_socket
1073 1379
1074BUILT_SOURCES += $(SYS_SOCKET_H) 1380BUILT_SOURCES += sys/socket.h
1075 1381
1076# We need the following in order to create <sys/socket.h> when the system 1382# We need the following in order to create <sys/socket.h> when the system
1077# doesn't have one that works with the given compiler. 1383# doesn't have one that works with the given compiler.
1078sys/socket.h: sys_socket.in.h 1384sys/socket.h: sys_socket.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
1079 @MKDIR_P@ sys 1385 $(AM_V_at)$(MKDIR_P) sys
1386 $(AM_V_GEN)rm -f $@-t $@ && \
1080 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1387 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
1081 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1388 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1082 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1389 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
@@ -1097,12 +1404,17 @@ sys/socket.h: sys_socket.in.h
1097 -e 's|@''GNULIB_SENDTO''@|$(GNULIB_SENDTO)|g' \ 1404 -e 's|@''GNULIB_SENDTO''@|$(GNULIB_SENDTO)|g' \
1098 -e 's|@''GNULIB_SETSOCKOPT''@|$(GNULIB_SETSOCKOPT)|g' \ 1405 -e 's|@''GNULIB_SETSOCKOPT''@|$(GNULIB_SETSOCKOPT)|g' \
1099 -e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \ 1406 -e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \
1407 -e 's|@''GNULIB_ACCEPT4''@|$(GNULIB_ACCEPT4)|g' \
1100 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ 1408 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
1101 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \ 1409 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
1102 -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \ 1410 -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
1103 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 1411 -e 's|@''HAVE_SA_FAMILY_T''@|$(HAVE_SA_FAMILY_T)|g' \
1412 -e 's|@''HAVE_ACCEPT4''@|$(HAVE_ACCEPT4)|g' \
1413 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1414 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1415 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1104 < $(srcdir)/sys_socket.in.h; \ 1416 < $(srcdir)/sys_socket.in.h; \
1105 } > $@-t 1417 } > $@-t && \
1106 mv -f $@-t $@ 1418 mv -f $@-t $@
1107MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t 1419MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
1108MOSTLYCLEANDIRS += sys 1420MOSTLYCLEANDIRS += sys
@@ -1111,26 +1423,96 @@ EXTRA_DIST += sys_socket.in.h
1111 1423
1112## end gnulib module sys_socket 1424## end gnulib module sys_socket
1113 1425
1426## begin gnulib module sys_stat
1427
1428BUILT_SOURCES += sys/stat.h
1429
1430# We need the following in order to create <sys/stat.h> when the system
1431# has one that is incomplete.
1432sys/stat.h: sys_stat.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1433 $(AM_V_at)$(MKDIR_P) sys
1434 $(AM_V_GEN)rm -f $@-t $@ && \
1435 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
1436 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1437 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1438 -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
1439 -e 's|@''GNULIB_FCHMODAT''@|$(GNULIB_FCHMODAT)|g' \
1440 -e 's|@''GNULIB_FSTATAT''@|$(GNULIB_FSTATAT)|g' \
1441 -e 's|@''GNULIB_FUTIMENS''@|$(GNULIB_FUTIMENS)|g' \
1442 -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \
1443 -e 's|@''GNULIB_LSTAT''@|$(GNULIB_LSTAT)|g' \
1444 -e 's|@''GNULIB_MKDIRAT''@|$(GNULIB_MKDIRAT)|g' \
1445 -e 's|@''GNULIB_MKFIFO''@|$(GNULIB_MKFIFO)|g' \
1446 -e 's|@''GNULIB_MKFIFOAT''@|$(GNULIB_MKFIFOAT)|g' \
1447 -e 's|@''GNULIB_MKNOD''@|$(GNULIB_MKNOD)|g' \
1448 -e 's|@''GNULIB_MKNODAT''@|$(GNULIB_MKNODAT)|g' \
1449 -e 's|@''GNULIB_STAT''@|$(GNULIB_STAT)|g' \
1450 -e 's|@''GNULIB_UTIMENSAT''@|$(GNULIB_UTIMENSAT)|g' \
1451 -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
1452 -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
1453 -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
1454 -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
1455 -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
1456 -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \
1457 -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \
1458 -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \
1459 -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \
1460 -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \
1461 -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \
1462 -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \
1463 -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \
1464 -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \
1465 -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
1466 -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
1467 -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \
1468 -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \
1469 -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
1470 -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \
1471 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1472 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1473 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1474 < $(srcdir)/sys_stat.in.h; \
1475 } > $@-t && \
1476 mv $@-t $@
1477MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
1478MOSTLYCLEANDIRS += sys
1479
1480EXTRA_DIST += sys_stat.in.h
1481
1482## end gnulib module sys_stat
1483
1114## begin gnulib module time 1484## begin gnulib module time
1115 1485
1116BUILT_SOURCES += time.h 1486BUILT_SOURCES += time.h
1117 1487
1118# We need the following in order to create <time.h> when the system 1488# We need the following in order to create <time.h> when the system
1119# doesn't have one that works with the given compiler. 1489# doesn't have one that works with the given compiler.
1120time.h: time.in.h 1490time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1121 rm -f $@-t $@ 1491 $(AM_V_GEN)rm -f $@-t $@ && \
1122 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1492 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
1123 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1493 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1124 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1494 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1125 -e 's|@NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ 1495 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
1126 -e 's|@REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ 1496 -e 's|@''GNULIB_MKTIME''@|$(GNULIB_MKTIME)|g' \
1127 -e 's|@REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ 1497 -e 's|@''GNULIB_NANOSLEEP''@|$(GNULIB_NANOSLEEP)|g' \
1128 -e 's|@REPLACE_STRPTIME''@|$(REPLACE_STRPTIME)|g' \ 1498 -e 's|@''GNULIB_STRPTIME''@|$(GNULIB_STRPTIME)|g' \
1129 -e 's|@REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ 1499 -e 's|@''GNULIB_TIMEGM''@|$(GNULIB_TIMEGM)|g' \
1130 -e 's|@SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ 1500 -e 's|@''GNULIB_TIME_R''@|$(GNULIB_TIME_R)|g' \
1131 -e 's|@TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ 1501 -e 's|@''HAVE_LOCALTIME_R''@|$(HAVE_LOCALTIME_R)|g' \
1502 -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
1503 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
1504 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
1505 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
1506 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
1507 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
1508 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
1509 -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
1510 -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
1511 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1512 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1513 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1132 < $(srcdir)/time.in.h; \ 1514 < $(srcdir)/time.in.h; \
1133 } > $@-t 1515 } > $@-t && \
1134 mv $@-t $@ 1516 mv $@-t $@
1135MOSTLYCLEANFILES += time.h time.h-t 1517MOSTLYCLEANFILES += time.h time.h-t
1136 1518
@@ -1150,7 +1532,7 @@ EXTRA_libgnu_a_SOURCES += time_r.c
1150## begin gnulib module timegm 1532## begin gnulib module timegm
1151 1533
1152 1534
1153EXTRA_DIST += timegm.c 1535EXTRA_DIST += mktime-internal.h timegm.c
1154 1536
1155EXTRA_libgnu_a_SOURCES += timegm.c 1537EXTRA_libgnu_a_SOURCES += timegm.c
1156 1538
@@ -1162,8 +1544,8 @@ BUILT_SOURCES += unistd.h
1162 1544
1163# We need the following in order to create an empty placeholder for 1545# We need the following in order to create an empty placeholder for
1164# <unistd.h> when the system doesn't have one. 1546# <unistd.h> when the system doesn't have one.
1165unistd.h: unistd.in.h 1547unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1166 rm -f $@-t $@ 1548 $(AM_V_GEN)rm -f $@-t $@ && \
1167 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1549 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
1168 sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ 1550 sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
1169 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1551 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
@@ -1172,53 +1554,104 @@ unistd.h: unistd.in.h
1172 -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ 1554 -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \
1173 -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \ 1555 -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
1174 -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ 1556 -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
1557 -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \
1175 -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \ 1558 -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
1176 -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \ 1559 -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
1560 -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \
1177 -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ 1561 -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
1562 -e 's|@''GNULIB_FCHOWNAT''@|$(GNULIB_FCHOWNAT)|g' \
1178 -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \ 1563 -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \
1179 -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ 1564 -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
1180 -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ 1565 -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
1181 -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \ 1566 -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
1182 -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \ 1567 -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
1568 -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \
1183 -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ 1569 -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
1570 -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \
1184 -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ 1571 -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
1185 -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ 1572 -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
1186 -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \ 1573 -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
1187 -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \ 1574 -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
1188 -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \ 1575 -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \
1576 -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \
1189 -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \ 1577 -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
1578 -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \
1579 -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \
1190 -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \ 1580 -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
1581 -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \
1582 -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \
1191 -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \ 1583 -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
1584 -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \
1585 -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \
1586 -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \
1587 -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \
1192 -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \ 1588 -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \
1589 -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \
1590 -e 's|@''GNULIB_UNLINKAT''@|$(GNULIB_UNLINKAT)|g' \
1591 -e 's|@''GNULIB_USLEEP''@|$(GNULIB_USLEEP)|g' \
1193 -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \ 1592 -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \
1593 < $(srcdir)/unistd.in.h | \
1594 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
1194 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ 1595 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
1596 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
1195 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ 1597 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
1598 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
1599 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
1600 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
1196 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ 1601 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
1197 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ 1602 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
1198 -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \ 1603 -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \
1199 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ 1604 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
1605 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
1200 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ 1606 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
1607 -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
1201 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ 1608 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
1202 -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \ 1609 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
1203 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ 1610 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
1611 -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
1612 -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \
1613 -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \
1204 -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ 1614 -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
1615 -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \
1205 -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ 1616 -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
1617 -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \
1618 -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \
1619 -e 's|@''HAVE_TTYNAME_R''@|$(HAVE_TTYNAME_R)|g' \
1620 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
1621 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
1206 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ 1622 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
1207 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ 1623 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
1624 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
1625 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
1208 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ 1626 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
1209 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ 1627 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
1210 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ 1628 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
1211 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ 1629 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
1212 -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ 1630 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
1631 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
1632 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
1213 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ 1633 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
1634 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
1214 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ 1635 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
1215 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ 1636 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
1637 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
1638 -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \
1216 -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ 1639 -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
1640 -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \
1641 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
1642 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
1643 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
1644 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
1645 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
1646 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
1647 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
1217 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ 1648 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
1218 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ 1649 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
1219 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 1650 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
1220 < $(srcdir)/unistd.in.h; \ 1651 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1221 } > $@-t 1652 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1653 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
1654 } > $@-t && \
1222 mv $@-t $@ 1655 mv $@-t $@
1223MOSTLYCLEANFILES += unistd.h unistd.h-t 1656MOSTLYCLEANFILES += unistd.h unistd.h-t
1224 1657
@@ -1268,14 +1701,33 @@ EXTRA_libgnu_a_SOURCES += vsnprintf.c
1268 1701
1269## end gnulib module vsnprintf 1702## end gnulib module vsnprintf
1270 1703
1704## begin gnulib module warn-on-use
1705
1706BUILT_SOURCES += warn-on-use.h
1707# The warn-on-use.h that gets inserted into generated .h files is the same as
1708# build-aux/warn-on-use.h, except that it has the copyright header cut off.
1709warn-on-use.h: $(top_srcdir)/build-aux/warn-on-use.h
1710 $(AM_V_GEN)rm -f $@-t $@ && \
1711 sed -n -e '/^.ifndef/,$$p' \
1712 < $(top_srcdir)/build-aux/warn-on-use.h \
1713 > $@-t && \
1714 mv $@-t $@
1715MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
1716
1717WARN_ON_USE_H=warn-on-use.h
1718
1719EXTRA_DIST += $(top_srcdir)/build-aux/warn-on-use.h
1720
1721## end gnulib module warn-on-use
1722
1271## begin gnulib module wchar 1723## begin gnulib module wchar
1272 1724
1273BUILT_SOURCES += $(WCHAR_H) 1725BUILT_SOURCES += wchar.h
1274 1726
1275# We need the following in order to create <wchar.h> when the system 1727# We need the following in order to create <wchar.h> when the system
1276# version does not work standalone. 1728# version does not work standalone.
1277wchar.h: wchar.in.h 1729wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1278 rm -f $@-t $@ 1730 $(AM_V_GEN)rm -f $@-t $@ && \
1279 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1731 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
1280 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1732 sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1281 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1733 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
@@ -1316,9 +1768,11 @@ wchar.h: wchar.in.h
1316 -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \ 1768 -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \
1317 -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ 1769 -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \
1318 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ 1770 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
1319 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ 1771 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1772 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1773 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1320 < $(srcdir)/wchar.in.h; \ 1774 < $(srcdir)/wchar.in.h; \
1321 } > $@-t 1775 } > $@-t && \
1322 mv $@-t $@ 1776 mv $@-t $@
1323MOSTLYCLEANFILES += wchar.h wchar.h-t 1777MOSTLYCLEANFILES += wchar.h wchar.h-t
1324 1778
@@ -1337,22 +1791,25 @@ EXTRA_libgnu_a_SOURCES += wcrtomb.c
1337 1791
1338## begin gnulib module wctype 1792## begin gnulib module wctype
1339 1793
1340BUILT_SOURCES += $(WCTYPE_H) 1794BUILT_SOURCES += wctype.h
1341 1795
1342# We need the following in order to create <wctype.h> when the system 1796# We need the following in order to create <wctype.h> when the system
1343# doesn't have one that works with the given compiler. 1797# doesn't have one that works with the given compiler.
1344wctype.h: wctype.in.h 1798wctype.h: wctype.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
1345 rm -f $@-t $@ 1799 $(AM_V_GEN)rm -f $@-t $@ && \
1346 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1800 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
1347 sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ 1801 sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \
1348 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1802 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1349 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1803 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1350 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ 1804 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
1805 -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \
1351 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ 1806 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \
1352 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ 1807 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
1353 -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ 1808 -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \
1809 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1810 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1354 < $(srcdir)/wctype.in.h; \ 1811 < $(srcdir)/wctype.in.h; \
1355 } > $@-t 1812 } > $@-t && \
1356 mv $@-t $@ 1813 mv $@-t $@
1357MOSTLYCLEANFILES += wctype.h wctype.h-t 1814MOSTLYCLEANFILES += wctype.h wctype.h-t
1358 1815
diff --git a/gl/alignof.h b/gl/alignof.h
index 896382b0..240468c6 100644
--- a/gl/alignof.h
+++ b/gl/alignof.h
@@ -1,5 +1,5 @@
1/* Determine alignment of types. 1/* Determine alignment of types.
2 Copyright (C) 2003-2004, 2006, 2009 Free Software Foundation, Inc. 2 Copyright (C) 2003-2004, 2006, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -20,14 +20,34 @@
20 20
21#include <stddef.h> 21#include <stddef.h>
22 22
23/* Determine the alignment of a type at compile time. */ 23/* Determine the alignment of a structure slot (field) of a given type,
24#if defined __GNUC__ 24 at compile time. Note that the result depends on the ABI.
25# define alignof __alignof__ 25 Note: The result cannot be used as a value for an 'enum' constant,
26#elif defined __cplusplus 26 due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
27#if defined __cplusplus
27 template <class type> struct alignof_helper { char __slot1; type __slot2; }; 28 template <class type> struct alignof_helper { char __slot1; type __slot2; };
28# define alignof(type) offsetof (alignof_helper<type>, __slot2) 29# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
30#else
31# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
32#endif
33
34/* Determine the good alignment of a object of the given type at compile time.
35 Note that this is not necessarily the same as alignof_slot(type).
36 For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
37 - when -malign-double is not specified: alignof_slot(double) = 4,
38 - when -malign-double is specified: alignof_slot(double) = 8.
39 Note: The result cannot be used as a value for an 'enum' constant,
40 due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
41#if defined __GNUC__
42# define alignof_type __alignof__
29#else 43#else
30# define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2) 44# define alignof_type alignof_slot
31#endif 45#endif
32 46
47/* alignof is an alias for alignof_slot semantics, since that's what most
48 callers need.
49 Note: The result cannot be used as a value for an 'enum' constant,
50 due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
51#define alignof alignof_slot
52
33#endif /* _ALIGNOF_H */ 53#endif /* _ALIGNOF_H */
diff --git a/gl/alloca.c b/gl/alloca.c
index ff1cb7e9..75afdb96 100644
--- a/gl/alloca.c
+++ b/gl/alloca.c
@@ -81,37 +81,37 @@ long i00afunc ();
81 STACK_DIRECTION = 0 => direction of growth unknown */ 81 STACK_DIRECTION = 0 => direction of growth unknown */
82 82
83# ifndef STACK_DIRECTION 83# ifndef STACK_DIRECTION
84# define STACK_DIRECTION 0 /* Direction unknown. */ 84# define STACK_DIRECTION 0 /* Direction unknown. */
85# endif 85# endif
86 86
87# if STACK_DIRECTION != 0 87# if STACK_DIRECTION != 0
88 88
89# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ 89# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
90 90
91# else /* STACK_DIRECTION == 0; need run-time code. */ 91# else /* STACK_DIRECTION == 0; need run-time code. */
92 92
93static int stack_dir; /* 1 or -1 once known. */ 93static int stack_dir; /* 1 or -1 once known. */
94# define STACK_DIR stack_dir 94# define STACK_DIR stack_dir
95 95
96static void 96static void
97find_stack_direction (void) 97find_stack_direction (void)
98{ 98{
99 static char *addr = NULL; /* Address of first `dummy', once known. */ 99 static char *addr = NULL; /* Address of first `dummy', once known. */
100 auto char dummy; /* To get stack address. */ 100 auto char dummy; /* To get stack address. */
101 101
102 if (addr == NULL) 102 if (addr == NULL)
103 { /* Initial entry. */ 103 { /* Initial entry. */
104 addr = ADDRESS_FUNCTION (dummy); 104 addr = ADDRESS_FUNCTION (dummy);
105 105
106 find_stack_direction (); /* Recurse once. */ 106 find_stack_direction (); /* Recurse once. */
107 } 107 }
108 else 108 else
109 { 109 {
110 /* Second entry. */ 110 /* Second entry. */
111 if (ADDRESS_FUNCTION (dummy) > addr) 111 if (ADDRESS_FUNCTION (dummy) > addr)
112 stack_dir = 1; /* Stack grew upward. */ 112 stack_dir = 1; /* Stack grew upward. */
113 else 113 else
114 stack_dir = -1; /* Stack grew downward. */ 114 stack_dir = -1; /* Stack grew downward. */
115 } 115 }
116} 116}
117 117
@@ -124,21 +124,21 @@ find_stack_direction (void)
124 It is very important that sizeof(header) agree with malloc 124 It is very important that sizeof(header) agree with malloc
125 alignment chunk size. The following default should work okay. */ 125 alignment chunk size. The following default should work okay. */
126 126
127# ifndef ALIGN_SIZE 127# ifndef ALIGN_SIZE
128# define ALIGN_SIZE sizeof(double) 128# define ALIGN_SIZE sizeof(double)
129# endif 129# endif
130 130
131typedef union hdr 131typedef union hdr
132{ 132{
133 char align[ALIGN_SIZE]; /* To force sizeof(header). */ 133 char align[ALIGN_SIZE]; /* To force sizeof(header). */
134 struct 134 struct
135 { 135 {
136 union hdr *next; /* For chaining headers. */ 136 union hdr *next; /* For chaining headers. */
137 char *deep; /* For stack depth measure. */ 137 char *deep; /* For stack depth measure. */
138 } h; 138 } h;
139} header; 139} header;
140 140
141static header *last_alloca_header = NULL; /* -> last alloca header. */ 141static header *last_alloca_header = NULL; /* -> last alloca header. */
142 142
143/* Return a pointer to at least SIZE bytes of storage, 143/* Return a pointer to at least SIZE bytes of storage,
144 which will be automatically reclaimed upon exit from 144 which will be automatically reclaimed upon exit from
@@ -150,11 +150,11 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
150void * 150void *
151alloca (size_t size) 151alloca (size_t size)
152{ 152{
153 auto char probe; /* Probes stack depth: */ 153 auto char probe; /* Probes stack depth: */
154 register char *depth = ADDRESS_FUNCTION (probe); 154 register char *depth = ADDRESS_FUNCTION (probe);
155 155
156# if STACK_DIRECTION == 0 156# if STACK_DIRECTION == 0
157 if (STACK_DIR == 0) /* Unknown growth direction. */ 157 if (STACK_DIR == 0) /* Unknown growth direction. */
158 find_stack_direction (); 158 find_stack_direction ();
159# endif 159# endif
160 160
@@ -162,7 +162,7 @@ alloca (size_t size)
162 was allocated from deeper in the stack than currently. */ 162 was allocated from deeper in the stack than currently. */
163 163
164 { 164 {
165 register header *hp; /* Traverses linked list. */ 165 register header *hp; /* Traverses linked list. */
166 166
167# ifdef emacs 167# ifdef emacs
168 BLOCK_INPUT; 168 BLOCK_INPUT;
@@ -170,18 +170,18 @@ alloca (size_t size)
170 170
171 for (hp = last_alloca_header; hp != NULL;) 171 for (hp = last_alloca_header; hp != NULL;)
172 if ((STACK_DIR > 0 && hp->h.deep > depth) 172 if ((STACK_DIR > 0 && hp->h.deep > depth)
173 || (STACK_DIR < 0 && hp->h.deep < depth)) 173 || (STACK_DIR < 0 && hp->h.deep < depth))
174 { 174 {
175 register header *np = hp->h.next; 175 register header *np = hp->h.next;
176 176
177 free (hp); /* Collect garbage. */ 177 free (hp); /* Collect garbage. */
178 178
179 hp = np; /* -> next header. */ 179 hp = np; /* -> next header. */
180 } 180 }
181 else 181 else
182 break; /* Rest are not deeper. */ 182 break; /* Rest are not deeper. */
183 183
184 last_alloca_header = hp; /* -> last valid storage. */ 184 last_alloca_header = hp; /* -> last valid storage. */
185 185
186# ifdef emacs 186# ifdef emacs
187 UNBLOCK_INPUT; 187 UNBLOCK_INPUT;
@@ -189,7 +189,7 @@ alloca (size_t size)
189 } 189 }
190 190
191 if (size == 0) 191 if (size == 0)
192 return NULL; /* No allocation required. */ 192 return NULL; /* No allocation required. */
193 193
194 /* Allocate combined header + user data storage. */ 194 /* Allocate combined header + user data storage. */
195 195
@@ -229,10 +229,10 @@ alloca (size_t size)
229/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ 229/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
230struct stack_control_header 230struct stack_control_header
231 { 231 {
232 long shgrow:32; /* Number of times stack has grown. */ 232 long shgrow:32; /* Number of times stack has grown. */
233 long shaseg:32; /* Size of increments to stack. */ 233 long shaseg:32; /* Size of increments to stack. */
234 long shhwm:32; /* High water mark of stack. */ 234 long shhwm:32; /* High water mark of stack. */
235 long shsize:32; /* Current size of stack (all segments). */ 235 long shsize:32; /* Current size of stack (all segments). */
236 }; 236 };
237 237
238/* The stack segment linkage control information occurs at 238/* The stack segment linkage control information occurs at
@@ -244,21 +244,21 @@ struct stack_control_header
244 244
245struct stack_segment_linkage 245struct stack_segment_linkage
246 { 246 {
247 long ss[0200]; /* 0200 overflow words. */ 247 long ss[0200]; /* 0200 overflow words. */
248 long sssize:32; /* Number of words in this segment. */ 248 long sssize:32; /* Number of words in this segment. */
249 long ssbase:32; /* Offset to stack base. */ 249 long ssbase:32; /* Offset to stack base. */
250 long:32; 250 long:32;
251 long sspseg:32; /* Offset to linkage control of previous 251 long sspseg:32; /* Offset to linkage control of previous
252 segment of stack. */ 252 segment of stack. */
253 long:32; 253 long:32;
254 long sstcpt:32; /* Pointer to task common address block. */ 254 long sstcpt:32; /* Pointer to task common address block. */
255 long sscsnm; /* Private control structure number for 255 long sscsnm; /* Private control structure number for
256 microtasking. */ 256 microtasking. */
257 long ssusr1; /* Reserved for user. */ 257 long ssusr1; /* Reserved for user. */
258 long ssusr2; /* Reserved for user. */ 258 long ssusr2; /* Reserved for user. */
259 long sstpid; /* Process ID for pid based multi-tasking. */ 259 long sstpid; /* Process ID for pid based multi-tasking. */
260 long ssgvup; /* Pointer to multitasking thread giveup. */ 260 long ssgvup; /* Pointer to multitasking thread giveup. */
261 long sscray[7]; /* Reserved for Cray Research. */ 261 long sscray[7]; /* Reserved for Cray Research. */
262 long ssa0; 262 long ssa0;
263 long ssa1; 263 long ssa1;
264 long ssa2; 264 long ssa2;
@@ -282,27 +282,27 @@ struct stack_segment_linkage
282 returned by the STKSTAT library routine. */ 282 returned by the STKSTAT library routine. */
283struct stk_stat 283struct stk_stat
284 { 284 {
285 long now; /* Current total stack size. */ 285 long now; /* Current total stack size. */
286 long maxc; /* Amount of contiguous space which would 286 long maxc; /* Amount of contiguous space which would
287 be required to satisfy the maximum 287 be required to satisfy the maximum
288 stack demand to date. */ 288 stack demand to date. */
289 long high_water; /* Stack high-water mark. */ 289 long high_water; /* Stack high-water mark. */
290 long overflows; /* Number of stack overflow ($STKOFEN) calls. */ 290 long overflows; /* Number of stack overflow ($STKOFEN) calls. */
291 long hits; /* Number of internal buffer hits. */ 291 long hits; /* Number of internal buffer hits. */
292 long extends; /* Number of block extensions. */ 292 long extends; /* Number of block extensions. */
293 long stko_mallocs; /* Block allocations by $STKOFEN. */ 293 long stko_mallocs; /* Block allocations by $STKOFEN. */
294 long underflows; /* Number of stack underflow calls ($STKRETN). */ 294 long underflows; /* Number of stack underflow calls ($STKRETN). */
295 long stko_free; /* Number of deallocations by $STKRETN. */ 295 long stko_free; /* Number of deallocations by $STKRETN. */
296 long stkm_free; /* Number of deallocations by $STKMRET. */ 296 long stkm_free; /* Number of deallocations by $STKMRET. */
297 long segments; /* Current number of stack segments. */ 297 long segments; /* Current number of stack segments. */
298 long maxs; /* Maximum number of stack segments so far. */ 298 long maxs; /* Maximum number of stack segments so far. */
299 long pad_size; /* Stack pad size. */ 299 long pad_size; /* Stack pad size. */
300 long current_address; /* Current stack segment address. */ 300 long current_address; /* Current stack segment address. */
301 long current_size; /* Current stack segment size. This 301 long current_size; /* Current stack segment size. This
302 number is actually corrupted by STKSTAT to 302 number is actually corrupted by STKSTAT to
303 include the fifteen word trailer area. */ 303 include the fifteen word trailer area. */
304 long initial_address; /* Address of initial segment. */ 304 long initial_address; /* Address of initial segment. */
305 long initial_size; /* Size of initial segment. */ 305 long initial_size; /* Size of initial segment. */
306 }; 306 };
307 307
308/* The following structure describes the data structure which trails 308/* The following structure describes the data structure which trails
@@ -311,13 +311,13 @@ struct stk_stat
311 311
312struct stk_trailer 312struct stk_trailer
313 { 313 {
314 long this_address; /* Address of this block. */ 314 long this_address; /* Address of this block. */
315 long this_size; /* Size of this block (does not include 315 long this_size; /* Size of this block (does not include
316 this trailer). */ 316 this trailer). */
317 long unknown2; 317 long unknown2;
318 long unknown3; 318 long unknown3;
319 long link; /* Address of trailer block of previous 319 long link; /* Address of trailer block of previous
320 segment. */ 320 segment. */
321 long unknown5; 321 long unknown5;
322 long unknown6; 322 long unknown6;
323 long unknown7; 323 long unknown7;
@@ -355,8 +355,8 @@ i00afunc (long *address)
355 /* Set up the iteration. */ 355 /* Set up the iteration. */
356 356
357 trailer = (struct stk_trailer *) (status.current_address 357 trailer = (struct stk_trailer *) (status.current_address
358 + status.current_size 358 + status.current_size
359 - 15); 359 - 15);
360 360
361 /* There must be at least one stack segment. Therefore it is 361 /* There must be at least one stack segment. Therefore it is
362 a fatal error if "trailer" is null. */ 362 a fatal error if "trailer" is null. */
@@ -371,10 +371,10 @@ i00afunc (long *address)
371 block = (long *) trailer->this_address; 371 block = (long *) trailer->this_address;
372 size = trailer->this_size; 372 size = trailer->this_size;
373 if (block == 0 || size == 0) 373 if (block == 0 || size == 0)
374 abort (); 374 abort ();
375 trailer = (struct stk_trailer *) trailer->link; 375 trailer = (struct stk_trailer *) trailer->link;
376 if ((block <= address) && (address < (block + size))) 376 if ((block <= address) && (address < (block + size)))
377 break; 377 break;
378 } 378 }
379 379
380 /* Set the result to the offset in this segment and add the sizes 380 /* Set the result to the offset in this segment and add the sizes
@@ -390,7 +390,7 @@ i00afunc (long *address)
390 do 390 do
391 { 391 {
392 if (trailer->this_size <= 0) 392 if (trailer->this_size <= 0)
393 abort (); 393 abort ();
394 result += trailer->this_size; 394 result += trailer->this_size;
395 trailer = (struct stk_trailer *) trailer->link; 395 trailer = (struct stk_trailer *) trailer->link;
396 } 396 }
@@ -453,7 +453,7 @@ i00afunc (long address)
453 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); 453 fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
454# endif 454# endif
455 if (pseg == 0) 455 if (pseg == 0)
456 break; 456 break;
457 stkl = stkl - pseg; 457 stkl = stkl - pseg;
458 ssptr = (struct stack_segment_linkage *) stkl; 458 ssptr = (struct stack_segment_linkage *) stkl;
459 size = ssptr->sssize; 459 size = ssptr->sssize;
diff --git a/gl/alloca.in.h b/gl/alloca.in.h
index 6269607a..44f20b7a 100644
--- a/gl/alloca.in.h
+++ b/gl/alloca.in.h
@@ -1,7 +1,7 @@
1/* Memory allocation on the stack. 1/* Memory allocation on the stack.
2 2
3 Copyright (C) 1995, 1999, 2001-2004, 2006-2008 Free Software 3 Copyright (C) 1995, 1999, 2001-2004, 2006-2010 Free Software Foundation,
4 Foundation, Inc. 4 Inc.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published 7 under the terms of the GNU General Public License as published
diff --git a/gl/arpa_inet.in.h b/gl/arpa_inet.in.h
index ac933991..f7c3bc72 100644
--- a/gl/arpa_inet.in.h
+++ b/gl/arpa_inet.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <arpa/inet.h>. 1/* A GNU-like <arpa/inet.h>.
2 2
3 Copyright (C) 2005-2006, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2008-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -18,16 +18,19 @@
18 18
19#ifndef _GL_ARPA_INET_H 19#ifndef _GL_ARPA_INET_H
20 20
21#if __GNUC__ >= 3
22@PRAGMA_SYSTEM_HEADER@
23#endif
24
21/* Gnulib's sys/socket.h is responsible for pulling in winsock2.h etc 25/* Gnulib's sys/socket.h is responsible for pulling in winsock2.h etc
22 under MinGW. */ 26 under MinGW.
23#include <sys/socket.h> 27 But avoid namespace pollution on glibc systems. */
28#ifndef __GLIBC__
29# include <sys/socket.h>
30#endif
24 31
25#if @HAVE_ARPA_INET_H@ 32#if @HAVE_ARPA_INET_H@
26 33
27# if __GNUC__ >= 3
28@PRAGMA_SYSTEM_HEADER@
29# endif
30
31/* The include_next requires a split double-inclusion guard. */ 34/* The include_next requires a split double-inclusion guard. */
32# @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@ 35# @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@
33 36
@@ -36,7 +39,9 @@
36#ifndef _GL_ARPA_INET_H 39#ifndef _GL_ARPA_INET_H
37#define _GL_ARPA_INET_H 40#define _GL_ARPA_INET_H
38 41
39/* The definition of GL_LINK_WARNING is copied here. */ 42/* The definition of _GL_ARG_NONNULL is copied here. */
43
44/* The definition of _GL_WARN_ON_USE is copied here. */
40 45
41#ifdef __cplusplus 46#ifdef __cplusplus
42extern "C" { 47extern "C" {
@@ -60,26 +65,28 @@ extern "C" {
60 For more details, see the POSIX:2001 specification 65 For more details, see the POSIX:2001 specification
61 <http://www.opengroup.org/susv3xsh/inet_ntop.html>. */ 66 <http://www.opengroup.org/susv3xsh/inet_ntop.html>. */
62extern const char *inet_ntop (int af, const void *restrict src, 67extern const char *inet_ntop (int af, const void *restrict src,
63 char *restrict dst, socklen_t cnt); 68 char *restrict dst, socklen_t cnt)
69 _GL_ARG_NONNULL ((2, 3));
64# endif 70# endif
65#elif defined GNULIB_POSIXCHECK 71#elif defined GNULIB_POSIXCHECK
66# undef inet_ntop 72# undef inet_ntop
67# define inet_ntop(af,src,dst,cnt) \ 73# if HAVE_RAW_DECL_INET_NTOP
68 (GL_LINK_WARNING ("inet_ntop is unportable - " \ 74_GL_WARN_ON_USE (inet_ntop, "inet_ntop is unportable - "
69 "use gnulib module inet_ntop for portability"), \ 75 "use gnulib module inet_ntop for portability");
70 inet_ntop (af, src, dst, cnt)) 76# endif
71#endif 77#endif
72 78
73#if @GNULIB_INET_PTON@ 79#if @GNULIB_INET_PTON@
74# if !@HAVE_DECL_INET_PTON@ 80# if !@HAVE_DECL_INET_PTON@
75extern int inet_pton (int af, const char *restrict src, void *restrict dst); 81extern int inet_pton (int af, const char *restrict src, void *restrict dst)
82 _GL_ARG_NONNULL ((2, 3));
76# endif 83# endif
77#elif defined GNULIB_POSIXCHECK 84#elif defined GNULIB_POSIXCHECK
78# undef inet_pton 85# undef inet_pton
79# define inet_pton(af,src,dst) \ 86# if HAVE_RAW_DECL_INET_PTON
80 (GL_LINK_WARNING ("inet_pton is unportable - " \ 87_GL_WARN_ON_USE (inet_pton, "inet_pton is unportable - "
81 "use gnulib module inet_pton for portability"), \ 88 "use gnulib module inet_pton for portability");
82 inet_pton (af, src, dst)) 89# endif
83#endif 90#endif
84 91
85#ifdef __cplusplus 92#ifdef __cplusplus
diff --git a/gl/asnprintf.c b/gl/asnprintf.c
index bf2abf3c..3bd2229d 100644
--- a/gl/asnprintf.c
+++ b/gl/asnprintf.c
@@ -1,5 +1,5 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002, 2006, 2009, 2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/asprintf.c b/gl/asprintf.c
index 0bbecf81..8273ecf9 100644
--- a/gl/asprintf.c
+++ b/gl/asprintf.c
@@ -1,5 +1,6 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation,
3 Inc.
3 4
4 This program is free software; you can redistribute it and/or modify 5 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 it under the terms of the GNU General Public License as published by
diff --git a/gl/base64.c b/gl/base64.c
index 42ccc9c2..d99e175f 100644
--- a/gl/base64.c
+++ b/gl/base64.c
@@ -1,5 +1,5 @@
1/* base64.c -- Encode binary data using printable characters. 1/* base64.c -- Encode binary data using printable characters.
2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006 Free Software 2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2009, 2010 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
@@ -67,7 +67,7 @@ to_uchar (char ch)
67 terminate the output buffer. */ 67 terminate the output buffer. */
68void 68void
69base64_encode (const char *restrict in, size_t inlen, 69base64_encode (const char *restrict in, size_t inlen,
70 char *restrict out, size_t outlen) 70 char *restrict out, size_t outlen)
71{ 71{
72 static const char b64str[64] = 72 static const char b64str[64] =
73 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 73 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -76,27 +76,27 @@ base64_encode (const char *restrict in, size_t inlen,
76 { 76 {
77 *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f]; 77 *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f];
78 if (!--outlen) 78 if (!--outlen)
79 break; 79 break;
80 *out++ = b64str[((to_uchar (in[0]) << 4) 80 *out++ = b64str[((to_uchar (in[0]) << 4)
81 + (--inlen ? to_uchar (in[1]) >> 4 : 0)) 81 + (--inlen ? to_uchar (in[1]) >> 4 : 0))
82 & 0x3f]; 82 & 0x3f];
83 if (!--outlen) 83 if (!--outlen)
84 break; 84 break;
85 *out++ = 85 *out++ =
86 (inlen 86 (inlen
87 ? b64str[((to_uchar (in[1]) << 2) 87 ? b64str[((to_uchar (in[1]) << 2)
88 + (--inlen ? to_uchar (in[2]) >> 6 : 0)) 88 + (--inlen ? to_uchar (in[2]) >> 6 : 0))
89 & 0x3f] 89 & 0x3f]
90 : '='); 90 : '=');
91 if (!--outlen) 91 if (!--outlen)
92 break; 92 break;
93 *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '='; 93 *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '=';
94 if (!--outlen) 94 if (!--outlen)
95 break; 95 break;
96 if (inlen) 96 if (inlen)
97 inlen--; 97 inlen--;
98 if (inlen) 98 if (inlen)
99 in += 3; 99 in += 3;
100 } 100 }
101 101
102 if (outlen) 102 if (outlen)
@@ -153,71 +153,71 @@ base64_encode_alloc (const char *in, size_t inlen, char **out)
153 153
154 IBM C V6 for AIX mishandles "#define B64(x) ...'x'...", so use "_" 154 IBM C V6 for AIX mishandles "#define B64(x) ...'x'...", so use "_"
155 as the formal parameter rather than "x". */ 155 as the formal parameter rather than "x". */
156#define B64(_) \ 156#define B64(_) \
157 ((_) == 'A' ? 0 \ 157 ((_) == 'A' ? 0 \
158 : (_) == 'B' ? 1 \ 158 : (_) == 'B' ? 1 \
159 : (_) == 'C' ? 2 \ 159 : (_) == 'C' ? 2 \
160 : (_) == 'D' ? 3 \ 160 : (_) == 'D' ? 3 \
161 : (_) == 'E' ? 4 \ 161 : (_) == 'E' ? 4 \
162 : (_) == 'F' ? 5 \ 162 : (_) == 'F' ? 5 \
163 : (_) == 'G' ? 6 \ 163 : (_) == 'G' ? 6 \
164 : (_) == 'H' ? 7 \ 164 : (_) == 'H' ? 7 \
165 : (_) == 'I' ? 8 \ 165 : (_) == 'I' ? 8 \
166 : (_) == 'J' ? 9 \ 166 : (_) == 'J' ? 9 \
167 : (_) == 'K' ? 10 \ 167 : (_) == 'K' ? 10 \
168 : (_) == 'L' ? 11 \ 168 : (_) == 'L' ? 11 \
169 : (_) == 'M' ? 12 \ 169 : (_) == 'M' ? 12 \
170 : (_) == 'N' ? 13 \ 170 : (_) == 'N' ? 13 \
171 : (_) == 'O' ? 14 \ 171 : (_) == 'O' ? 14 \
172 : (_) == 'P' ? 15 \ 172 : (_) == 'P' ? 15 \
173 : (_) == 'Q' ? 16 \ 173 : (_) == 'Q' ? 16 \
174 : (_) == 'R' ? 17 \ 174 : (_) == 'R' ? 17 \
175 : (_) == 'S' ? 18 \ 175 : (_) == 'S' ? 18 \
176 : (_) == 'T' ? 19 \ 176 : (_) == 'T' ? 19 \
177 : (_) == 'U' ? 20 \ 177 : (_) == 'U' ? 20 \
178 : (_) == 'V' ? 21 \ 178 : (_) == 'V' ? 21 \
179 : (_) == 'W' ? 22 \ 179 : (_) == 'W' ? 22 \
180 : (_) == 'X' ? 23 \ 180 : (_) == 'X' ? 23 \
181 : (_) == 'Y' ? 24 \ 181 : (_) == 'Y' ? 24 \
182 : (_) == 'Z' ? 25 \ 182 : (_) == 'Z' ? 25 \
183 : (_) == 'a' ? 26 \ 183 : (_) == 'a' ? 26 \
184 : (_) == 'b' ? 27 \ 184 : (_) == 'b' ? 27 \
185 : (_) == 'c' ? 28 \ 185 : (_) == 'c' ? 28 \
186 : (_) == 'd' ? 29 \ 186 : (_) == 'd' ? 29 \
187 : (_) == 'e' ? 30 \ 187 : (_) == 'e' ? 30 \
188 : (_) == 'f' ? 31 \ 188 : (_) == 'f' ? 31 \
189 : (_) == 'g' ? 32 \ 189 : (_) == 'g' ? 32 \
190 : (_) == 'h' ? 33 \ 190 : (_) == 'h' ? 33 \
191 : (_) == 'i' ? 34 \ 191 : (_) == 'i' ? 34 \
192 : (_) == 'j' ? 35 \ 192 : (_) == 'j' ? 35 \
193 : (_) == 'k' ? 36 \ 193 : (_) == 'k' ? 36 \
194 : (_) == 'l' ? 37 \ 194 : (_) == 'l' ? 37 \
195 : (_) == 'm' ? 38 \ 195 : (_) == 'm' ? 38 \
196 : (_) == 'n' ? 39 \ 196 : (_) == 'n' ? 39 \
197 : (_) == 'o' ? 40 \ 197 : (_) == 'o' ? 40 \
198 : (_) == 'p' ? 41 \ 198 : (_) == 'p' ? 41 \
199 : (_) == 'q' ? 42 \ 199 : (_) == 'q' ? 42 \
200 : (_) == 'r' ? 43 \ 200 : (_) == 'r' ? 43 \
201 : (_) == 's' ? 44 \ 201 : (_) == 's' ? 44 \
202 : (_) == 't' ? 45 \ 202 : (_) == 't' ? 45 \
203 : (_) == 'u' ? 46 \ 203 : (_) == 'u' ? 46 \
204 : (_) == 'v' ? 47 \ 204 : (_) == 'v' ? 47 \
205 : (_) == 'w' ? 48 \ 205 : (_) == 'w' ? 48 \
206 : (_) == 'x' ? 49 \ 206 : (_) == 'x' ? 49 \
207 : (_) == 'y' ? 50 \ 207 : (_) == 'y' ? 50 \
208 : (_) == 'z' ? 51 \ 208 : (_) == 'z' ? 51 \
209 : (_) == '0' ? 52 \ 209 : (_) == '0' ? 52 \
210 : (_) == '1' ? 53 \ 210 : (_) == '1' ? 53 \
211 : (_) == '2' ? 54 \ 211 : (_) == '2' ? 54 \
212 : (_) == '3' ? 55 \ 212 : (_) == '3' ? 55 \
213 : (_) == '4' ? 56 \ 213 : (_) == '4' ? 56 \
214 : (_) == '5' ? 57 \ 214 : (_) == '5' ? 57 \
215 : (_) == '6' ? 58 \ 215 : (_) == '6' ? 58 \
216 : (_) == '7' ? 59 \ 216 : (_) == '7' ? 59 \
217 : (_) == '8' ? 60 \ 217 : (_) == '8' ? 60 \
218 : (_) == '9' ? 61 \ 218 : (_) == '9' ? 61 \
219 : (_) == '+' ? 62 \ 219 : (_) == '+' ? 62 \
220 : (_) == '/' ? 63 \ 220 : (_) == '/' ? 63 \
221 : -1) 221 : -1)
222 222
223static const signed char b64[0x100] = { 223static const signed char b64[0x100] = {
@@ -328,12 +328,12 @@ get_4 (struct base64_decode_context *ctx,
328 { 328 {
329 char const *t = *in; 329 char const *t = *in;
330 if (4 <= in_end - *in && memchr (t, '\n', 4) == NULL) 330 if (4 <= in_end - *in && memchr (t, '\n', 4) == NULL)
331 { 331 {
332 /* This is the common case: no newline. */ 332 /* This is the common case: no newline. */
333 *in += 4; 333 *in += 4;
334 *n_non_newline = 4; 334 *n_non_newline = 4;
335 return (char *) t; 335 return (char *) t;
336 } 336 }
337 } 337 }
338 338
339 { 339 {
@@ -341,13 +341,13 @@ get_4 (struct base64_decode_context *ctx,
341 char const *p = *in; 341 char const *p = *in;
342 while (p < in_end) 342 while (p < in_end)
343 { 343 {
344 char c = *p++; 344 char c = *p++;
345 if (c != '\n') 345 if (c != '\n')
346 { 346 {
347 ctx->buf[ctx->i++] = c; 347 ctx->buf[ctx->i++] = c;
348 if (ctx->i == 4) 348 if (ctx->i == 4)
349 break; 349 break;
350 } 350 }
351 } 351 }
352 352
353 *in = p; 353 *in = p;
@@ -356,12 +356,12 @@ get_4 (struct base64_decode_context *ctx,
356 } 356 }
357} 357}
358 358
359#define return_false \ 359#define return_false \
360 do \ 360 do \
361 { \ 361 { \
362 *outp = out; \ 362 *outp = out; \
363 return false; \ 363 return false; \
364 } \ 364 } \
365 while (false) 365 while (false)
366 366
367/* Decode up to four bytes of base64-encoded data, IN, of length INLEN 367/* Decode up to four bytes of base64-encoded data, IN, of length INLEN
@@ -372,7 +372,7 @@ get_4 (struct base64_decode_context *ctx,
372 *OUTLEN to reflect the number of bytes remaining in *OUT. */ 372 *OUTLEN to reflect the number of bytes remaining in *OUT. */
373static inline bool 373static inline bool
374decode_4 (char const *restrict in, size_t inlen, 374decode_4 (char const *restrict in, size_t inlen,
375 char *restrict *outp, size_t *outleft) 375 char *restrict *outp, size_t *outleft)
376{ 376{
377 char *out = *outp; 377 char *out = *outp;
378 if (inlen < 2) 378 if (inlen < 2)
@@ -384,7 +384,7 @@ decode_4 (char const *restrict in, size_t inlen,
384 if (*outleft) 384 if (*outleft)
385 { 385 {
386 *out++ = ((b64[to_uchar (in[0])] << 2) 386 *out++ = ((b64[to_uchar (in[0])] << 2)
387 | (b64[to_uchar (in[1])] >> 4)); 387 | (b64[to_uchar (in[1])] >> 4));
388 --*outleft; 388 --*outleft;
389 } 389 }
390 390
@@ -394,43 +394,43 @@ decode_4 (char const *restrict in, size_t inlen,
394 if (in[2] == '=') 394 if (in[2] == '=')
395 { 395 {
396 if (inlen != 4) 396 if (inlen != 4)
397 return_false; 397 return_false;
398 398
399 if (in[3] != '=') 399 if (in[3] != '=')
400 return_false; 400 return_false;
401 } 401 }
402 else 402 else
403 { 403 {
404 if (!isbase64 (in[2])) 404 if (!isbase64 (in[2]))
405 return_false; 405 return_false;
406 406
407 if (*outleft) 407 if (*outleft)
408 { 408 {
409 *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0) 409 *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0)
410 | (b64[to_uchar (in[2])] >> 2)); 410 | (b64[to_uchar (in[2])] >> 2));
411 --*outleft; 411 --*outleft;
412 } 412 }
413 413
414 if (inlen == 3) 414 if (inlen == 3)
415 return_false; 415 return_false;
416 416
417 if (in[3] == '=') 417 if (in[3] == '=')
418 { 418 {
419 if (inlen != 4) 419 if (inlen != 4)
420 return_false; 420 return_false;
421 } 421 }
422 else 422 else
423 { 423 {
424 if (!isbase64 (in[3])) 424 if (!isbase64 (in[3]))
425 return_false; 425 return_false;
426 426
427 if (*outleft) 427 if (*outleft)
428 { 428 {
429 *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0) 429 *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0)
430 | b64[to_uchar (in[3])]); 430 | b64[to_uchar (in[3])]);
431 --*outleft; 431 --*outleft;
432 } 432 }
433 } 433 }
434 } 434 }
435 435
436 *outp = out; 436 *outp = out;
@@ -457,8 +457,8 @@ decode_4 (char const *restrict in, size_t inlen,
457 457
458bool 458bool
459base64_decode_ctx (struct base64_decode_context *ctx, 459base64_decode_ctx (struct base64_decode_context *ctx,
460 const char *restrict in, size_t inlen, 460 const char *restrict in, size_t inlen,
461 char *restrict out, size_t *outlen) 461 char *restrict out, size_t *outlen)
462{ 462{
463 size_t outleft = *outlen; 463 size_t outleft = *outlen;
464 bool ignore_newlines = ctx != NULL; 464 bool ignore_newlines = ctx != NULL;
@@ -476,57 +476,57 @@ base64_decode_ctx (struct base64_decode_context *ctx,
476 { 476 {
477 size_t outleft_save = outleft; 477 size_t outleft_save = outleft;
478 if (ctx_i == 0 && !flush_ctx) 478 if (ctx_i == 0 && !flush_ctx)
479 { 479 {
480 while (true) 480 while (true)
481 { 481 {
482 /* Save a copy of outleft, in case we need to re-parse this 482 /* Save a copy of outleft, in case we need to re-parse this
483 block of four bytes. */ 483 block of four bytes. */
484 outleft_save = outleft; 484 outleft_save = outleft;
485 if (!decode_4 (in, inlen, &out, &outleft)) 485 if (!decode_4 (in, inlen, &out, &outleft))
486 break; 486 break;
487 487
488 in += 4; 488 in += 4;
489 inlen -= 4; 489 inlen -= 4;
490 } 490 }
491 } 491 }
492 492
493 if (inlen == 0 && !flush_ctx) 493 if (inlen == 0 && !flush_ctx)
494 break; 494 break;
495 495
496 /* Handle the common case of 72-byte wrapped lines. 496 /* Handle the common case of 72-byte wrapped lines.
497 This also handles any other multiple-of-4-byte wrapping. */ 497 This also handles any other multiple-of-4-byte wrapping. */
498 if (inlen && *in == '\n' && ignore_newlines) 498 if (inlen && *in == '\n' && ignore_newlines)
499 { 499 {
500 ++in; 500 ++in;
501 --inlen; 501 --inlen;
502 continue; 502 continue;
503 } 503 }
504 504
505 /* Restore OUT and OUTLEFT. */ 505 /* Restore OUT and OUTLEFT. */
506 out -= outleft_save - outleft; 506 out -= outleft_save - outleft;
507 outleft = outleft_save; 507 outleft = outleft_save;
508 508
509 { 509 {
510 char const *in_end = in + inlen; 510 char const *in_end = in + inlen;
511 char const *non_nl; 511 char const *non_nl;
512 512
513 if (ignore_newlines) 513 if (ignore_newlines)
514 non_nl = get_4 (ctx, &in, in_end, &inlen); 514 non_nl = get_4 (ctx, &in, in_end, &inlen);
515 else 515 else
516 non_nl = in; /* Might have nl in this case. */ 516 non_nl = in; /* Might have nl in this case. */
517 517
518 /* If the input is empty or consists solely of newlines (0 non-newlines), 518 /* If the input is empty or consists solely of newlines (0 non-newlines),
519 then we're done. Likewise if there are fewer than 4 bytes when not 519 then we're done. Likewise if there are fewer than 4 bytes when not
520 flushing context and not treating newlines as garbage. */ 520 flushing context and not treating newlines as garbage. */
521 if (inlen == 0 || (inlen < 4 && !flush_ctx && ignore_newlines)) 521 if (inlen == 0 || (inlen < 4 && !flush_ctx && ignore_newlines))
522 { 522 {
523 inlen = 0; 523 inlen = 0;
524 break; 524 break;
525 } 525 }
526 if (!decode_4 (non_nl, inlen, &out, &outleft)) 526 if (!decode_4 (non_nl, inlen, &out, &outleft))
527 break; 527 break;
528 528
529 inlen = in_end - in; 529 inlen = in_end - in;
530 } 530 }
531 } 531 }
532 532
@@ -548,8 +548,8 @@ base64_decode_ctx (struct base64_decode_context *ctx,
548 undefined. */ 548 undefined. */
549bool 549bool
550base64_decode_alloc_ctx (struct base64_decode_context *ctx, 550base64_decode_alloc_ctx (struct base64_decode_context *ctx,
551 const char *in, size_t inlen, char **out, 551 const char *in, size_t inlen, char **out,
552 size_t *outlen) 552 size_t *outlen)
553{ 553{
554 /* This may allocate a few bytes too many, depending on input, 554 /* This may allocate a few bytes too many, depending on input,
555 but it's not worth the extra CPU time to compute the exact size. 555 but it's not worth the extra CPU time to compute the exact size.
diff --git a/gl/base64.h b/gl/base64.h
index 63b6abcb..2be394bd 100644
--- a/gl/base64.h
+++ b/gl/base64.h
@@ -1,5 +1,5 @@
1/* base64.h -- Encode binary data using printable characters. 1/* base64.h -- Encode binary data using printable characters.
2 Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
3 Written by Simon Josefsson. 3 Written by Simon Josefsson.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
@@ -38,24 +38,24 @@ struct base64_decode_context
38extern bool isbase64 (char ch); 38extern bool isbase64 (char ch);
39 39
40extern void base64_encode (const char *restrict in, size_t inlen, 40extern void base64_encode (const char *restrict in, size_t inlen,
41 char *restrict out, size_t outlen); 41 char *restrict out, size_t outlen);
42 42
43extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out); 43extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
44 44
45extern void base64_decode_ctx_init (struct base64_decode_context *ctx); 45extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
46 46
47extern bool base64_decode_ctx (struct base64_decode_context *ctx, 47extern bool base64_decode_ctx (struct base64_decode_context *ctx,
48 const char *restrict in, size_t inlen, 48 const char *restrict in, size_t inlen,
49 char *restrict out, size_t *outlen); 49 char *restrict out, size_t *outlen);
50 50
51extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx, 51extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
52 const char *in, size_t inlen, 52 const char *in, size_t inlen,
53 char **out, size_t *outlen); 53 char **out, size_t *outlen);
54 54
55#define base64_decode(in, inlen, out, outlen) \ 55#define base64_decode(in, inlen, out, outlen) \
56 base64_decode_ctx (NULL, in, inlen, out, outlen) 56 base64_decode_ctx (NULL, in, inlen, out, outlen)
57 57
58#define base64_decode_alloc(in, inlen, out, outlen) \ 58#define base64_decode_alloc(in, inlen, out, outlen) \
59 base64_decode_alloc_ctx (NULL, in, inlen, out, outlen) 59 base64_decode_alloc_ctx (NULL, in, inlen, out, outlen)
60 60
61#endif /* BASE64_H */ 61#endif /* BASE64_H */
diff --git a/gl/basename-lgpl.c b/gl/basename-lgpl.c
new file mode 100644
index 00000000..a35ff01c
--- /dev/null
+++ b/gl/basename-lgpl.c
@@ -0,0 +1,75 @@
1/* basename.c -- return the last element in a file name
2
3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2010 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#include "dirname.h"
22
23#include <string.h>
24
25/* Return the address of the last file name component of NAME. If
26 NAME has no relative file name components because it is a file
27 system root, return the empty string. */
28
29char *
30last_component (char const *name)
31{
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
33 char const *p;
34 bool saw_slash = false;
35
36 while (ISSLASH (*base))
37 base++;
38
39 for (p = base; *p; p++)
40 {
41 if (ISSLASH (*p))
42 saw_slash = true;
43 else if (saw_slash)
44 {
45 base = p;
46 saw_slash = false;
47 }
48 }
49
50 return (char *) base;
51}
52
53/* Return the length of the basename NAME. Typically NAME is the
54 value returned by base_name or last_component. Act like strlen
55 (NAME), except omit all trailing slashes. */
56
57size_t
58base_len (char const *name)
59{
60 size_t len;
61 size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
62
63 for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
64 continue;
65
66 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
67 && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
68 return 2;
69
70 if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
71 && len == prefix_len && ISSLASH (name[prefix_len]))
72 return prefix_len + 1;
73
74 return len;
75}
diff --git a/gl/basename.c b/gl/basename.c
index 426ed40f..24da93ac 100644
--- a/gl/basename.c
+++ b/gl/basename.c
@@ -1,7 +1,7 @@
1/* basename.c -- return the last element in a file name 1/* basename.c -- return the last element in a file name
2 2
3 Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free 3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2010 Free Software
4 Software Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 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 7 it under the terms of the GNU General Public License as published by
@@ -24,52 +24,6 @@
24#include "xalloc.h" 24#include "xalloc.h"
25#include "xstrndup.h" 25#include "xstrndup.h"
26 26
27/* Return the address of the last file name component of NAME. If
28 NAME has no relative file name components because it is a file
29 system root, return the empty string. */
30
31char *
32last_component (char const *name)
33{
34 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
35 char const *p;
36 bool saw_slash = false;
37
38 while (ISSLASH (*base))
39 base++;
40
41 for (p = base; *p; p++)
42 {
43 if (ISSLASH (*p))
44 saw_slash = true;
45 else if (saw_slash)
46 {
47 base = p;
48 saw_slash = false;
49 }
50 }
51
52 return (char *) base;
53}
54
55
56/* In general, we can't use the builtin `basename' function if available,
57 since it has different meanings in different environments.
58 In some environments the builtin `basename' modifies its argument.
59
60 Return the last file name component of NAME, allocated with
61 xmalloc. On systems with drive letters, a leading "./"
62 distinguishes relative names that would otherwise look like a drive
63 letter. Unlike POSIX basename(), NAME cannot be NULL,
64 base_name("") returns "", and the first trailing slash is not
65 stripped.
66
67 If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
68 lstat (base_name (NAME)); } will access the same file. Likewise,
69 if the sequence { chdir (dir_name (NAME));
70 rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
71 to "foo" in the same directory NAME was in. */
72
73char * 27char *
74base_name (char const *name) 28base_name (char const *name)
75{ 29{
@@ -102,27 +56,3 @@ base_name (char const *name)
102 /* Finally, copy the basename. */ 56 /* Finally, copy the basename. */
103 return xstrndup (base, length); 57 return xstrndup (base, length);
104} 58}
105
106/* Return the length of the basename NAME. Typically NAME is the
107 value returned by base_name or last_component. Act like strlen
108 (NAME), except omit all trailing slashes. */
109
110size_t
111base_len (char const *name)
112{
113 size_t len;
114 size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
115
116 for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
117 continue;
118
119 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
120 && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
121 return 2;
122
123 if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
124 && len == prefix_len && ISSLASH (name[prefix_len]))
125 return prefix_len + 1;
126
127 return len;
128}
diff --git a/gl/btowc.c b/gl/btowc.c
index 7f3b9663..8744602a 100644
--- a/gl/btowc.c
+++ b/gl/btowc.c
@@ -1,5 +1,5 @@
1/* Convert unibyte character to wide character. 1/* Convert unibyte character to wide character.
2 Copyright (C) 2008 Free Software Foundation, Inc. 2 Copyright (C) 2008, 2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
@@ -21,6 +21,7 @@
21#include <wchar.h> 21#include <wchar.h>
22 22
23#include <stdio.h> 23#include <stdio.h>
24#include <stdlib.h>
24 25
25wint_t 26wint_t
26btowc (int c) 27btowc (int c)
@@ -32,7 +33,7 @@ btowc (int c)
32 33
33 buf[0] = c; 34 buf[0] = c;
34 if (mbtowc (&wc, buf, 1) >= 0) 35 if (mbtowc (&wc, buf, 1) >= 0)
35 return wc; 36 return wc;
36 } 37 }
37 return WEOF; 38 return WEOF;
38} 39}
diff --git a/gl/c-strtod.c b/gl/c-strtod.c
index 51e996e5..38d472bd 100644
--- a/gl/c-strtod.c
+++ b/gl/c-strtod.c
@@ -1,6 +1,6 @@
1/* Convert string to double, using the C locale. 1/* Convert string to double, using the C locale.
2 2
3 Copyright (C) 2003, 2004, 2006, 2009 Free Software Foundation, Inc. 3 Copyright (C) 2003-2004, 2006, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -73,7 +73,7 @@ C_STRTOD (char const *nptr, char **endptr)
73 if (!locale) 73 if (!locale)
74 { 74 {
75 if (endptr) 75 if (endptr)
76 *endptr = (char *) nptr; 76 *endptr = (char *) nptr;
77 return 0; /* errno is set here */ 77 return 0; /* errno is set here */
78 } 78 }
79 79
@@ -87,11 +87,11 @@ C_STRTOD (char const *nptr, char **endptr)
87 { 87 {
88 saved_locale = strdup (saved_locale); 88 saved_locale = strdup (saved_locale);
89 if (saved_locale == NULL) 89 if (saved_locale == NULL)
90 { 90 {
91 if (endptr) 91 if (endptr)
92 *endptr = (char *) nptr; 92 *endptr = (char *) nptr;
93 return 0; /* errno is set here */ 93 return 0; /* errno is set here */
94 } 94 }
95 setlocale (LC_NUMERIC, "C"); 95 setlocale (LC_NUMERIC, "C");
96 } 96 }
97 97
diff --git a/gl/c-strtod.h b/gl/c-strtod.h
index 2b3f8473..c2adf1e4 100644
--- a/gl/c-strtod.h
+++ b/gl/c-strtod.h
@@ -1,6 +1,6 @@
1/* Convert string to double, using the C locale. 1/* Convert string to double, using the C locale.
2 2
3 Copyright (C) 2003-2004, 2009 Free Software Foundation, Inc. 3 Copyright (C) 2003-2004, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/cloexec.c b/gl/cloexec.c
index ff8105ba..2d12efef 100644
--- a/gl/cloexec.c
+++ b/gl/cloexec.c
@@ -1,6 +1,6 @@
1/* closexec.c - set or clear the close-on-exec descriptor flag 1/* closexec.c - set or clear the close-on-exec descriptor flag
2 2
3 Copyright (C) 1991, 2004, 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 1991, 2004-2006, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -21,21 +21,24 @@
21 21
22#include "cloexec.h" 22#include "cloexec.h"
23 23
24#include <unistd.h> 24#include <errno.h>
25#include <fcntl.h> 25#include <fcntl.h>
26 26#include <unistd.h>
27#ifndef FD_CLOEXEC
28# define FD_CLOEXEC 1
29#endif
30 27
31/* Set the `FD_CLOEXEC' flag of DESC if VALUE is true, 28/* Set the `FD_CLOEXEC' flag of DESC if VALUE is true,
32 or clear the flag if VALUE is false. 29 or clear the flag if VALUE is false.
33 Return 0 on success, or -1 on error with `errno' set. */ 30 Return 0 on success, or -1 on error with `errno' set.
31
32 Note that on MingW, this function does NOT protect DESC from being
33 inherited into spawned children. Instead, either use dup_cloexec
34 followed by closing the original DESC, or use interfaces such as
35 open or pipe2 that accept flags like O_CLOEXEC to create DESC
36 non-inheritable in the first place. */
34 37
35int 38int
36set_cloexec_flag (int desc, bool value) 39set_cloexec_flag (int desc, bool value)
37{ 40{
38#if defined F_GETFD && defined F_SETFD 41#ifdef F_SETFD
39 42
40 int flags = fcntl (desc, F_GETFD, 0); 43 int flags = fcntl (desc, F_GETFD, 0);
41 44
@@ -44,15 +47,37 @@ set_cloexec_flag (int desc, bool value)
44 int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC); 47 int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
45 48
46 if (flags == newflags 49 if (flags == newflags
47 || fcntl (desc, F_SETFD, newflags) != -1) 50 || fcntl (desc, F_SETFD, newflags) != -1)
48 return 0; 51 return 0;
49 } 52 }
50 53
51 return -1; 54 return -1;
52 55
53#else 56#else /* !F_SETFD */
57
58 /* Use dup2 to reject invalid file descriptors; the cloexec flag
59 will be unaffected. */
60 if (desc < 0)
61 {
62 errno = EBADF;
63 return -1;
64 }
65 if (dup2 (desc, desc) < 0)
66 /* errno is EBADF here. */
67 return -1;
54 68
69 /* There is nothing we can do on this kind of platform. Punt. */
55 return 0; 70 return 0;
71#endif /* !F_SETFD */
72}
73
56 74
57#endif 75/* Duplicates a file handle FD, while marking the copy to be closed
76 prior to exec or spawn. Returns -1 and sets errno if FD could not
77 be duplicated. */
78
79int
80dup_cloexec (int fd)
81{
82 return fcntl (fd, F_DUPFD_CLOEXEC, 0);
58} 83}
diff --git a/gl/cloexec.h b/gl/cloexec.h
index c25921d6..e3a2cb85 100644
--- a/gl/cloexec.h
+++ b/gl/cloexec.h
@@ -1,2 +1,38 @@
1/* closexec.c - set or clear the close-on-exec descriptor flag
2
3 Copyright (C) 2004, 2009-2010 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*/
19
1#include <stdbool.h> 20#include <stdbool.h>
21
22/* Set the `FD_CLOEXEC' flag of DESC if VALUE is true,
23 or clear the flag if VALUE is false.
24 Return 0 on success, or -1 on error with `errno' set.
25
26 Note that on MingW, this function does NOT protect DESC from being
27 inherited into spawned children. Instead, either use dup_cloexec
28 followed by closing the original DESC, or use interfaces such as
29 open or pipe2 that accept flags like O_CLOEXEC to create DESC
30 non-inheritable in the first place. */
31
2int set_cloexec_flag (int desc, bool value); 32int set_cloexec_flag (int desc, bool value);
33
34/* Duplicates a file handle FD, while marking the copy to be closed
35 prior to exec or spawn. Returns -1 and sets errno if FD could not
36 be duplicated. */
37
38int dup_cloexec (int fd);
diff --git a/gl/close-hook.c b/gl/close-hook.c
new file mode 100644
index 00000000..0253c4dc
--- /dev/null
+++ b/gl/close-hook.c
@@ -0,0 +1,91 @@
1/* Hook for making the close() function extensible.
2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
4
5 This program is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by 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 GNU
13 Lesser 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/* Specification. */
21#include "close-hook.h"
22
23#include <stdlib.h>
24#include <unistd.h>
25
26#undef close
27
28
29/* Currently, this entire code is only needed for the handling of sockets
30 on native Windows platforms. */
31#if WINDOWS_SOCKETS
32
33/* The first and last link in the doubly linked list.
34 Initially the list is empty. */
35static struct close_hook anchor = { &anchor, &anchor, NULL };
36
37int
38execute_close_hooks (int fd, const struct close_hook *remaining_list)
39{
40 if (remaining_list == &anchor)
41 /* End of list reached. */
42 return close (fd);
43 else
44 return remaining_list->private_fn (fd, remaining_list->private_next);
45}
46
47int
48execute_all_close_hooks (int fd)
49{
50 return execute_close_hooks (fd, anchor.private_next);
51}
52
53void
54register_close_hook (close_hook_fn hook, struct close_hook *link)
55{
56 if (link->private_next == NULL && link->private_prev == NULL)
57 {
58 /* Add the link to the doubly linked list. */
59 link->private_next = anchor.private_next;
60 link->private_prev = &anchor;
61 link->private_fn = hook;
62 anchor.private_next->private_prev = link;
63 anchor.private_next = link;
64 }
65 else
66 {
67 /* The link is already in use. */
68 if (link->private_fn != hook)
69 abort ();
70 }
71}
72
73void
74unregister_close_hook (struct close_hook *link)
75{
76 struct close_hook *next = link->private_next;
77 struct close_hook *prev = link->private_prev;
78
79 if (next != NULL && prev != NULL)
80 {
81 /* The link is in use. Remove it from the doubly linked list. */
82 prev->private_next = next;
83 next->private_prev = prev;
84 /* Clear the link, to mark it unused. */
85 link->private_next = NULL;
86 link->private_prev = NULL;
87 link->private_fn = NULL;
88 }
89}
90
91#endif
diff --git a/gl/close-hook.h b/gl/close-hook.h
new file mode 100644
index 00000000..1e115516
--- /dev/null
+++ b/gl/close-hook.h
@@ -0,0 +1,72 @@
1/* Hook for making the close() function extensible.
2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by 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 GNU
12 Lesser 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
18#ifndef CLOSE_HOOK_H
19#define CLOSE_HOOK_H
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25
26/* Currently, this entire code is only needed for the handling of sockets
27 on native Windows platforms. */
28#if WINDOWS_SOCKETS
29
30
31/* An element of the list of close hooks.
32 The fields of this structure are considered private. */
33struct close_hook
34{
35 /* Doubly linked list. */
36 struct close_hook *private_next;
37 struct close_hook *private_prev;
38 /* Function that treats the types of FD that it knows about and calls
39 execute_close_hooks (FD, REMAINING_LIST) as a fallback. */
40 int (*private_fn) (int fd, const struct close_hook *remaining_list);
41};
42
43/* This type of function closes FD, applying special knowledge for the FD
44 types it knows about, and calls execute_close_hooks (FD, REMAINING_LIST)
45 for the other FD types. */
46typedef int (*close_hook_fn) (int fd, const struct close_hook *remaining_list);
47
48/* Execute the close hooks in REMAINING_LIST.
49 Return 0 or -1, like close() would do. */
50extern int execute_close_hooks (int fd, const struct close_hook *remaining_list);
51
52/* Execute all close hooks.
53 Return 0 or -1, like close() would do. */
54extern int execute_all_close_hooks (int fd);
55
56/* Add a function to the list of close hooks.
57 The LINK variable points to a piece of memory which is guaranteed to be
58 accessible until the corresponding call to unregister_close_hook. */
59extern void register_close_hook (close_hook_fn hook, struct close_hook *link);
60
61/* Removes a function from the list of close hooks. */
62extern void unregister_close_hook (struct close_hook *link);
63
64
65#endif
66
67
68#ifdef __cplusplus
69}
70#endif
71
72#endif /* CLOSE_HOOK_H */
diff --git a/gl/config.charset b/gl/config.charset
index 7f912120..2959df89 100755..100644
--- a/gl/config.charset
+++ b/gl/config.charset
@@ -1,7 +1,7 @@
1#! /bin/sh 1#! /bin/sh
2# Output a system dependent table of character encoding aliases. 2# Output a system dependent table of character encoding aliases.
3# 3#
4# Copyright (C) 2000-2004, 2006-2009 Free Software Foundation, Inc. 4# Copyright (C) 2000-2004, 2006-2010 Free Software Foundation, Inc.
5# 5#
6# This program is free software; you can redistribute it and/or modify 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 7# it under the terms of the GNU General Public License as published by
@@ -123,561 +123,561 @@ echo "# It was automatically generated from config.charset."
123# List of references, updated during installation: 123# List of references, updated during installation:
124echo "# Packages using this file: " 124echo "# Packages using this file: "
125case "$os" in 125case "$os" in
126 linux-gnulibc1*) 126 linux-gnulibc1*)
127 # Linux libc5 doesn't have nl_langinfo(CODESET); therefore 127 # Linux libc5 doesn't have nl_langinfo(CODESET); therefore
128 # localcharset.c falls back to using the full locale name 128 # localcharset.c falls back to using the full locale name
129 # from the environment variables. 129 # from the environment variables.
130 echo "C ASCII" 130 echo "C ASCII"
131 echo "POSIX ASCII" 131 echo "POSIX ASCII"
132 for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \ 132 for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \
133 en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \ 133 en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \
134 en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \ 134 en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \
135 es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \ 135 es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \
136 et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \ 136 et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \
137 fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \ 137 fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \
138 it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \ 138 it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \
139 sv_FI sv_SE; do 139 sv_FI sv_SE; do
140 echo "$l ISO-8859-1" 140 echo "$l ISO-8859-1"
141 echo "$l.iso-8859-1 ISO-8859-1" 141 echo "$l.iso-8859-1 ISO-8859-1"
142 echo "$l.iso-8859-15 ISO-8859-15" 142 echo "$l.iso-8859-15 ISO-8859-15"
143 echo "$l.iso-8859-15@euro ISO-8859-15" 143 echo "$l.iso-8859-15@euro ISO-8859-15"
144 echo "$l@euro ISO-8859-15" 144 echo "$l@euro ISO-8859-15"
145 echo "$l.cp-437 CP437" 145 echo "$l.cp-437 CP437"
146 echo "$l.cp-850 CP850" 146 echo "$l.cp-850 CP850"
147 echo "$l.cp-1252 CP1252" 147 echo "$l.cp-1252 CP1252"
148 echo "$l.cp-1252@euro CP1252" 148 echo "$l.cp-1252@euro CP1252"
149 #echo "$l.atari-st ATARI-ST" # not a commonly used encoding 149 #echo "$l.atari-st ATARI-ST" # not a commonly used encoding
150 echo "$l.utf-8 UTF-8" 150 echo "$l.utf-8 UTF-8"
151 echo "$l.utf-8@euro UTF-8" 151 echo "$l.utf-8@euro UTF-8"
152 done 152 done
153 for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \ 153 for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \
154 sl_SI sr sr_CS sr_YU; do 154 sl_SI sr sr_CS sr_YU; do
155 echo "$l ISO-8859-2" 155 echo "$l ISO-8859-2"
156 echo "$l.iso-8859-2 ISO-8859-2" 156 echo "$l.iso-8859-2 ISO-8859-2"
157 echo "$l.cp-852 CP852" 157 echo "$l.cp-852 CP852"
158 echo "$l.cp-1250 CP1250" 158 echo "$l.cp-1250 CP1250"
159 echo "$l.utf-8 UTF-8" 159 echo "$l.utf-8 UTF-8"
160 done 160 done
161 for l in mk mk_MK ru ru_RU; do 161 for l in mk mk_MK ru ru_RU; do
162 echo "$l ISO-8859-5" 162 echo "$l ISO-8859-5"
163 echo "$l.iso-8859-5 ISO-8859-5" 163 echo "$l.iso-8859-5 ISO-8859-5"
164 echo "$l.koi8-r KOI8-R" 164 echo "$l.koi8-r KOI8-R"
165 echo "$l.cp-866 CP866" 165 echo "$l.cp-866 CP866"
166 echo "$l.cp-1251 CP1251" 166 echo "$l.cp-1251 CP1251"
167 echo "$l.utf-8 UTF-8" 167 echo "$l.utf-8 UTF-8"
168 done 168 done
169 for l in ar ar_SA; do 169 for l in ar ar_SA; do
170 echo "$l ISO-8859-6" 170 echo "$l ISO-8859-6"
171 echo "$l.iso-8859-6 ISO-8859-6" 171 echo "$l.iso-8859-6 ISO-8859-6"
172 echo "$l.cp-864 CP864" 172 echo "$l.cp-864 CP864"
173 #echo "$l.cp-868 CP868" # not a commonly used encoding 173 #echo "$l.cp-868 CP868" # not a commonly used encoding
174 echo "$l.cp-1256 CP1256" 174 echo "$l.cp-1256 CP1256"
175 echo "$l.utf-8 UTF-8" 175 echo "$l.utf-8 UTF-8"
176 done 176 done
177 for l in el el_GR gr gr_GR; do 177 for l in el el_GR gr gr_GR; do
178 echo "$l ISO-8859-7" 178 echo "$l ISO-8859-7"
179 echo "$l.iso-8859-7 ISO-8859-7" 179 echo "$l.iso-8859-7 ISO-8859-7"
180 echo "$l.cp-869 CP869" 180 echo "$l.cp-869 CP869"
181 echo "$l.cp-1253 CP1253" 181 echo "$l.cp-1253 CP1253"
182 echo "$l.cp-1253@euro CP1253" 182 echo "$l.cp-1253@euro CP1253"
183 echo "$l.utf-8 UTF-8" 183 echo "$l.utf-8 UTF-8"
184 echo "$l.utf-8@euro UTF-8" 184 echo "$l.utf-8@euro UTF-8"
185 done 185 done
186 for l in he he_IL iw iw_IL; do 186 for l in he he_IL iw iw_IL; do
187 echo "$l ISO-8859-8" 187 echo "$l ISO-8859-8"
188 echo "$l.iso-8859-8 ISO-8859-8" 188 echo "$l.iso-8859-8 ISO-8859-8"
189 echo "$l.cp-862 CP862" 189 echo "$l.cp-862 CP862"
190 echo "$l.cp-1255 CP1255" 190 echo "$l.cp-1255 CP1255"
191 echo "$l.utf-8 UTF-8" 191 echo "$l.utf-8 UTF-8"
192 done 192 done
193 for l in tr tr_TR; do 193 for l in tr tr_TR; do
194 echo "$l ISO-8859-9" 194 echo "$l ISO-8859-9"
195 echo "$l.iso-8859-9 ISO-8859-9" 195 echo "$l.iso-8859-9 ISO-8859-9"
196 echo "$l.cp-857 CP857" 196 echo "$l.cp-857 CP857"
197 echo "$l.cp-1254 CP1254" 197 echo "$l.cp-1254 CP1254"
198 echo "$l.utf-8 UTF-8" 198 echo "$l.utf-8 UTF-8"
199 done 199 done
200 for l in lt lt_LT lv lv_LV; do 200 for l in lt lt_LT lv lv_LV; do
201 #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name 201 #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name
202 echo "$l ISO-8859-13" 202 echo "$l ISO-8859-13"
203 done 203 done
204 for l in ru_UA uk uk_UA; do 204 for l in ru_UA uk uk_UA; do
205 echo "$l KOI8-U" 205 echo "$l KOI8-U"
206 done 206 done
207 for l in zh zh_CN; do 207 for l in zh zh_CN; do
208 #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name 208 #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name
209 echo "$l GB2312" 209 echo "$l GB2312"
210 done 210 done
211 for l in ja ja_JP ja_JP.EUC; do 211 for l in ja ja_JP ja_JP.EUC; do
212 echo "$l EUC-JP" 212 echo "$l EUC-JP"
213 done 213 done
214 for l in ko ko_KR; do 214 for l in ko ko_KR; do
215 echo "$l EUC-KR" 215 echo "$l EUC-KR"
216 done 216 done
217 for l in th th_TH; do 217 for l in th th_TH; do
218 echo "$l TIS-620" 218 echo "$l TIS-620"
219 done 219 done
220 for l in fa fa_IR; do 220 for l in fa fa_IR; do
221 #echo "$l ISIRI-3342" # a broken encoding 221 #echo "$l ISIRI-3342" # a broken encoding
222 echo "$l.utf-8 UTF-8" 222 echo "$l.utf-8 UTF-8"
223 done 223 done
224 ;; 224 ;;
225 linux* | *-gnu*) 225 linux* | *-gnu*)
226 # With glibc-2.1 or newer, we don't need any canonicalization, 226 # With glibc-2.1 or newer, we don't need any canonicalization,
227 # because glibc has iconv and both glibc and libiconv support all 227 # because glibc has iconv and both glibc and libiconv support all
228 # GNU canonical names directly. Therefore, the Makefile does not 228 # GNU canonical names directly. Therefore, the Makefile does not
229 # need to install the alias file at all. 229 # need to install the alias file at all.
230 # The following applies only to glibc-2.0.x and older libcs. 230 # The following applies only to glibc-2.0.x and older libcs.
231 echo "ISO_646.IRV:1983 ASCII" 231 echo "ISO_646.IRV:1983 ASCII"
232 ;; 232 ;;
233 aix*) 233 aix*)
234 echo "ISO8859-1 ISO-8859-1" 234 echo "ISO8859-1 ISO-8859-1"
235 echo "ISO8859-2 ISO-8859-2" 235 echo "ISO8859-2 ISO-8859-2"
236 echo "ISO8859-5 ISO-8859-5" 236 echo "ISO8859-5 ISO-8859-5"
237 echo "ISO8859-6 ISO-8859-6" 237 echo "ISO8859-6 ISO-8859-6"
238 echo "ISO8859-7 ISO-8859-7" 238 echo "ISO8859-7 ISO-8859-7"
239 echo "ISO8859-8 ISO-8859-8" 239 echo "ISO8859-8 ISO-8859-8"
240 echo "ISO8859-9 ISO-8859-9" 240 echo "ISO8859-9 ISO-8859-9"
241 echo "ISO8859-15 ISO-8859-15" 241 echo "ISO8859-15 ISO-8859-15"
242 echo "IBM-850 CP850" 242 echo "IBM-850 CP850"
243 echo "IBM-856 CP856" 243 echo "IBM-856 CP856"
244 echo "IBM-921 ISO-8859-13" 244 echo "IBM-921 ISO-8859-13"
245 echo "IBM-922 CP922" 245 echo "IBM-922 CP922"
246 echo "IBM-932 CP932" 246 echo "IBM-932 CP932"
247 echo "IBM-943 CP943" 247 echo "IBM-943 CP943"
248 echo "IBM-1046 CP1046" 248 echo "IBM-1046 CP1046"
249 echo "IBM-1124 CP1124" 249 echo "IBM-1124 CP1124"
250 echo "IBM-1129 CP1129" 250 echo "IBM-1129 CP1129"
251 echo "IBM-1252 CP1252" 251 echo "IBM-1252 CP1252"
252 echo "IBM-eucCN GB2312" 252 echo "IBM-eucCN GB2312"
253 echo "IBM-eucJP EUC-JP" 253 echo "IBM-eucJP EUC-JP"
254 echo "IBM-eucKR EUC-KR" 254 echo "IBM-eucKR EUC-KR"
255 echo "IBM-eucTW EUC-TW" 255 echo "IBM-eucTW EUC-TW"
256 echo "big5 BIG5" 256 echo "big5 BIG5"
257 echo "GBK GBK" 257 echo "GBK GBK"
258 echo "TIS-620 TIS-620" 258 echo "TIS-620 TIS-620"
259 echo "UTF-8 UTF-8" 259 echo "UTF-8 UTF-8"
260 ;; 260 ;;
261 hpux*) 261 hpux*)
262 echo "iso88591 ISO-8859-1" 262 echo "iso88591 ISO-8859-1"
263 echo "iso88592 ISO-8859-2" 263 echo "iso88592 ISO-8859-2"
264 echo "iso88595 ISO-8859-5" 264 echo "iso88595 ISO-8859-5"
265 echo "iso88596 ISO-8859-6" 265 echo "iso88596 ISO-8859-6"
266 echo "iso88597 ISO-8859-7" 266 echo "iso88597 ISO-8859-7"
267 echo "iso88598 ISO-8859-8" 267 echo "iso88598 ISO-8859-8"
268 echo "iso88599 ISO-8859-9" 268 echo "iso88599 ISO-8859-9"
269 echo "iso885915 ISO-8859-15" 269 echo "iso885915 ISO-8859-15"
270 echo "roman8 HP-ROMAN8" 270 echo "roman8 HP-ROMAN8"
271 echo "arabic8 HP-ARABIC8" 271 echo "arabic8 HP-ARABIC8"
272 echo "greek8 HP-GREEK8" 272 echo "greek8 HP-GREEK8"
273 echo "hebrew8 HP-HEBREW8" 273 echo "hebrew8 HP-HEBREW8"
274 echo "turkish8 HP-TURKISH8" 274 echo "turkish8 HP-TURKISH8"
275 echo "kana8 HP-KANA8" 275 echo "kana8 HP-KANA8"
276 echo "tis620 TIS-620" 276 echo "tis620 TIS-620"
277 echo "big5 BIG5" 277 echo "big5 BIG5"
278 echo "eucJP EUC-JP" 278 echo "eucJP EUC-JP"
279 echo "eucKR EUC-KR" 279 echo "eucKR EUC-KR"
280 echo "eucTW EUC-TW" 280 echo "eucTW EUC-TW"
281 echo "hp15CN GB2312" 281 echo "hp15CN GB2312"
282 #echo "ccdc ?" # what is this? 282 #echo "ccdc ?" # what is this?
283 echo "SJIS SHIFT_JIS" 283 echo "SJIS SHIFT_JIS"
284 echo "utf8 UTF-8" 284 echo "utf8 UTF-8"
285 ;; 285 ;;
286 irix*) 286 irix*)
287 echo "ISO8859-1 ISO-8859-1" 287 echo "ISO8859-1 ISO-8859-1"
288 echo "ISO8859-2 ISO-8859-2" 288 echo "ISO8859-2 ISO-8859-2"
289 echo "ISO8859-5 ISO-8859-5" 289 echo "ISO8859-5 ISO-8859-5"
290 echo "ISO8859-7 ISO-8859-7" 290 echo "ISO8859-7 ISO-8859-7"
291 echo "ISO8859-9 ISO-8859-9" 291 echo "ISO8859-9 ISO-8859-9"
292 echo "eucCN GB2312" 292 echo "eucCN GB2312"
293 echo "eucJP EUC-JP" 293 echo "eucJP EUC-JP"
294 echo "eucKR EUC-KR" 294 echo "eucKR EUC-KR"
295 echo "eucTW EUC-TW" 295 echo "eucTW EUC-TW"
296 ;; 296 ;;
297 osf*) 297 osf*)
298 echo "ISO8859-1 ISO-8859-1" 298 echo "ISO8859-1 ISO-8859-1"
299 echo "ISO8859-2 ISO-8859-2" 299 echo "ISO8859-2 ISO-8859-2"
300 echo "ISO8859-4 ISO-8859-4" 300 echo "ISO8859-4 ISO-8859-4"
301 echo "ISO8859-5 ISO-8859-5" 301 echo "ISO8859-5 ISO-8859-5"
302 echo "ISO8859-7 ISO-8859-7" 302 echo "ISO8859-7 ISO-8859-7"
303 echo "ISO8859-8 ISO-8859-8" 303 echo "ISO8859-8 ISO-8859-8"
304 echo "ISO8859-9 ISO-8859-9" 304 echo "ISO8859-9 ISO-8859-9"
305 echo "ISO8859-15 ISO-8859-15" 305 echo "ISO8859-15 ISO-8859-15"
306 echo "cp850 CP850" 306 echo "cp850 CP850"
307 echo "big5 BIG5" 307 echo "big5 BIG5"
308 echo "dechanyu DEC-HANYU" 308 echo "dechanyu DEC-HANYU"
309 echo "dechanzi GB2312" 309 echo "dechanzi GB2312"
310 echo "deckanji DEC-KANJI" 310 echo "deckanji DEC-KANJI"
311 echo "deckorean EUC-KR" 311 echo "deckorean EUC-KR"
312 echo "eucJP EUC-JP" 312 echo "eucJP EUC-JP"
313 echo "eucKR EUC-KR" 313 echo "eucKR EUC-KR"
314 echo "eucTW EUC-TW" 314 echo "eucTW EUC-TW"
315 echo "GBK GBK" 315 echo "GBK GBK"
316 echo "KSC5601 CP949" 316 echo "KSC5601 CP949"
317 echo "sdeckanji EUC-JP" 317 echo "sdeckanji EUC-JP"
318 echo "SJIS SHIFT_JIS" 318 echo "SJIS SHIFT_JIS"
319 echo "TACTIS TIS-620" 319 echo "TACTIS TIS-620"
320 echo "UTF-8 UTF-8" 320 echo "UTF-8 UTF-8"
321 ;; 321 ;;
322 solaris*) 322 solaris*)
323 echo "646 ASCII" 323 echo "646 ASCII"
324 echo "ISO8859-1 ISO-8859-1" 324 echo "ISO8859-1 ISO-8859-1"
325 echo "ISO8859-2 ISO-8859-2" 325 echo "ISO8859-2 ISO-8859-2"
326 echo "ISO8859-3 ISO-8859-3" 326 echo "ISO8859-3 ISO-8859-3"
327 echo "ISO8859-4 ISO-8859-4" 327 echo "ISO8859-4 ISO-8859-4"
328 echo "ISO8859-5 ISO-8859-5" 328 echo "ISO8859-5 ISO-8859-5"
329 echo "ISO8859-6 ISO-8859-6" 329 echo "ISO8859-6 ISO-8859-6"
330 echo "ISO8859-7 ISO-8859-7" 330 echo "ISO8859-7 ISO-8859-7"
331 echo "ISO8859-8 ISO-8859-8" 331 echo "ISO8859-8 ISO-8859-8"
332 echo "ISO8859-9 ISO-8859-9" 332 echo "ISO8859-9 ISO-8859-9"
333 echo "ISO8859-15 ISO-8859-15" 333 echo "ISO8859-15 ISO-8859-15"
334 echo "koi8-r KOI8-R" 334 echo "koi8-r KOI8-R"
335 echo "ansi-1251 CP1251" 335 echo "ansi-1251 CP1251"
336 echo "BIG5 BIG5" 336 echo "BIG5 BIG5"
337 echo "Big5-HKSCS BIG5-HKSCS" 337 echo "Big5-HKSCS BIG5-HKSCS"
338 echo "gb2312 GB2312" 338 echo "gb2312 GB2312"
339 echo "GBK GBK" 339 echo "GBK GBK"
340 echo "GB18030 GB18030" 340 echo "GB18030 GB18030"
341 echo "cns11643 EUC-TW" 341 echo "cns11643 EUC-TW"
342 echo "5601 EUC-KR" 342 echo "5601 EUC-KR"
343 echo "ko_KR.johap92 JOHAB" 343 echo "ko_KR.johap92 JOHAB"
344 echo "eucJP EUC-JP" 344 echo "eucJP EUC-JP"
345 echo "PCK SHIFT_JIS" 345 echo "PCK SHIFT_JIS"
346 echo "TIS620.2533 TIS-620" 346 echo "TIS620.2533 TIS-620"
347 #echo "sun_eu_greek ?" # what is this? 347 #echo "sun_eu_greek ?" # what is this?
348 echo "UTF-8 UTF-8" 348 echo "UTF-8 UTF-8"
349 ;; 349 ;;
350 freebsd* | os2*) 350 freebsd* | os2*)
351 # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore 351 # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
352 # localcharset.c falls back to using the full locale name 352 # localcharset.c falls back to using the full locale name
353 # from the environment variables. 353 # from the environment variables.
354 # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just 354 # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
355 # reuse FreeBSD's locale data for OS/2. 355 # reuse FreeBSD's locale data for OS/2.
356 echo "C ASCII" 356 echo "C ASCII"
357 echo "US-ASCII ASCII" 357 echo "US-ASCII ASCII"
358 for l in la_LN lt_LN; do 358 for l in la_LN lt_LN; do
359 echo "$l.ASCII ASCII" 359 echo "$l.ASCII ASCII"
360 done 360 done
361 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ 361 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
362 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \ 362 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \
363 lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do 363 lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do
364 echo "$l.ISO_8859-1 ISO-8859-1" 364 echo "$l.ISO_8859-1 ISO-8859-1"
365 echo "$l.DIS_8859-15 ISO-8859-15" 365 echo "$l.DIS_8859-15 ISO-8859-15"
366 done 366 done
367 for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do 367 for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do
368 echo "$l.ISO_8859-2 ISO-8859-2" 368 echo "$l.ISO_8859-2 ISO-8859-2"
369 done 369 done
370 for l in la_LN lt_LT; do 370 for l in la_LN lt_LT; do
371 echo "$l.ISO_8859-4 ISO-8859-4" 371 echo "$l.ISO_8859-4 ISO-8859-4"
372 done 372 done
373 for l in ru_RU ru_SU; do 373 for l in ru_RU ru_SU; do
374 echo "$l.KOI8-R KOI8-R" 374 echo "$l.KOI8-R KOI8-R"
375 echo "$l.ISO_8859-5 ISO-8859-5" 375 echo "$l.ISO_8859-5 ISO-8859-5"
376 echo "$l.CP866 CP866" 376 echo "$l.CP866 CP866"
377 done 377 done
378 echo "uk_UA.KOI8-U KOI8-U" 378 echo "uk_UA.KOI8-U KOI8-U"
379 echo "zh_TW.BIG5 BIG5" 379 echo "zh_TW.BIG5 BIG5"
380 echo "zh_TW.Big5 BIG5" 380 echo "zh_TW.Big5 BIG5"
381 echo "zh_CN.EUC GB2312" 381 echo "zh_CN.EUC GB2312"
382 echo "ja_JP.EUC EUC-JP" 382 echo "ja_JP.EUC EUC-JP"
383 echo "ja_JP.SJIS SHIFT_JIS" 383 echo "ja_JP.SJIS SHIFT_JIS"
384 echo "ja_JP.Shift_JIS SHIFT_JIS" 384 echo "ja_JP.Shift_JIS SHIFT_JIS"
385 echo "ko_KR.EUC EUC-KR" 385 echo "ko_KR.EUC EUC-KR"
386 ;; 386 ;;
387 netbsd*) 387 netbsd*)
388 echo "646 ASCII" 388 echo "646 ASCII"
389 echo "ISO8859-1 ISO-8859-1" 389 echo "ISO8859-1 ISO-8859-1"
390 echo "ISO8859-2 ISO-8859-2" 390 echo "ISO8859-2 ISO-8859-2"
391 echo "ISO8859-4 ISO-8859-4" 391 echo "ISO8859-4 ISO-8859-4"
392 echo "ISO8859-5 ISO-8859-5" 392 echo "ISO8859-5 ISO-8859-5"
393 echo "ISO8859-7 ISO-8859-7" 393 echo "ISO8859-7 ISO-8859-7"
394 echo "ISO8859-13 ISO-8859-13" 394 echo "ISO8859-13 ISO-8859-13"
395 echo "ISO8859-15 ISO-8859-15" 395 echo "ISO8859-15 ISO-8859-15"
396 echo "eucCN GB2312" 396 echo "eucCN GB2312"
397 echo "eucJP EUC-JP" 397 echo "eucJP EUC-JP"
398 echo "eucKR EUC-KR" 398 echo "eucKR EUC-KR"
399 echo "eucTW EUC-TW" 399 echo "eucTW EUC-TW"
400 echo "BIG5 BIG5" 400 echo "BIG5 BIG5"
401 echo "SJIS SHIFT_JIS" 401 echo "SJIS SHIFT_JIS"
402 ;; 402 ;;
403 openbsd*) 403 openbsd*)
404 echo "646 ASCII" 404 echo "646 ASCII"
405 echo "ISO8859-1 ISO-8859-1" 405 echo "ISO8859-1 ISO-8859-1"
406 echo "ISO8859-2 ISO-8859-2" 406 echo "ISO8859-2 ISO-8859-2"
407 echo "ISO8859-4 ISO-8859-4" 407 echo "ISO8859-4 ISO-8859-4"
408 echo "ISO8859-5 ISO-8859-5" 408 echo "ISO8859-5 ISO-8859-5"
409 echo "ISO8859-7 ISO-8859-7" 409 echo "ISO8859-7 ISO-8859-7"
410 echo "ISO8859-13 ISO-8859-13" 410 echo "ISO8859-13 ISO-8859-13"
411 echo "ISO8859-15 ISO-8859-15" 411 echo "ISO8859-15 ISO-8859-15"
412 ;; 412 ;;
413 darwin[56]*) 413 darwin[56]*)
414 # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore 414 # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore
415 # localcharset.c falls back to using the full locale name 415 # localcharset.c falls back to using the full locale name
416 # from the environment variables. 416 # from the environment variables.
417 echo "C ASCII" 417 echo "C ASCII"
418 for l in en_AU en_CA en_GB en_US la_LN; do 418 for l in en_AU en_CA en_GB en_US la_LN; do
419 echo "$l.US-ASCII ASCII" 419 echo "$l.US-ASCII ASCII"
420 done 420 done
421 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ 421 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
422 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \ 422 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \
423 nl_NL no_NO pt_PT sv_SE; do 423 nl_NL no_NO pt_PT sv_SE; do
424 echo "$l ISO-8859-1" 424 echo "$l ISO-8859-1"
425 echo "$l.ISO8859-1 ISO-8859-1" 425 echo "$l.ISO8859-1 ISO-8859-1"
426 echo "$l.ISO8859-15 ISO-8859-15" 426 echo "$l.ISO8859-15 ISO-8859-15"
427 done 427 done
428 for l in la_LN; do 428 for l in la_LN; do
429 echo "$l.ISO8859-1 ISO-8859-1" 429 echo "$l.ISO8859-1 ISO-8859-1"
430 echo "$l.ISO8859-15 ISO-8859-15" 430 echo "$l.ISO8859-15 ISO-8859-15"
431 done 431 done
432 for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do 432 for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do
433 echo "$l.ISO8859-2 ISO-8859-2" 433 echo "$l.ISO8859-2 ISO-8859-2"
434 done 434 done
435 for l in la_LN lt_LT; do 435 for l in la_LN lt_LT; do
436 echo "$l.ISO8859-4 ISO-8859-4" 436 echo "$l.ISO8859-4 ISO-8859-4"
437 done 437 done
438 for l in ru_RU; do 438 for l in ru_RU; do
439 echo "$l.KOI8-R KOI8-R" 439 echo "$l.KOI8-R KOI8-R"
440 echo "$l.ISO8859-5 ISO-8859-5" 440 echo "$l.ISO8859-5 ISO-8859-5"
441 echo "$l.CP866 CP866" 441 echo "$l.CP866 CP866"
442 done 442 done
443 for l in bg_BG; do 443 for l in bg_BG; do
444 echo "$l.CP1251 CP1251" 444 echo "$l.CP1251 CP1251"
445 done 445 done
446 echo "uk_UA.KOI8-U KOI8-U" 446 echo "uk_UA.KOI8-U KOI8-U"
447 echo "zh_TW.BIG5 BIG5" 447 echo "zh_TW.BIG5 BIG5"
448 echo "zh_TW.Big5 BIG5" 448 echo "zh_TW.Big5 BIG5"
449 echo "zh_CN.EUC GB2312" 449 echo "zh_CN.EUC GB2312"
450 echo "ja_JP.EUC EUC-JP" 450 echo "ja_JP.EUC EUC-JP"
451 echo "ja_JP.SJIS SHIFT_JIS" 451 echo "ja_JP.SJIS SHIFT_JIS"
452 echo "ko_KR.EUC EUC-KR" 452 echo "ko_KR.EUC EUC-KR"
453 ;; 453 ;;
454 darwin*) 454 darwin*)
455 # Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is 455 # Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is
456 # useless: 456 # useless:
457 # - It returns the empty string when LANG is set to a locale of the 457 # - It returns the empty string when LANG is set to a locale of the
458 # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8 458 # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
459 # LC_CTYPE file. 459 # LC_CTYPE file.
460 # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by 460 # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
461 # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case. 461 # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
462 # - The documentation says: 462 # - The documentation says:
463 # "... all code that calls BSD system routines should ensure 463 # "... all code that calls BSD system routines should ensure
464 # that the const *char parameters of these routines are in UTF-8 464 # that the const *char parameters of these routines are in UTF-8
465 # encoding. All BSD system functions expect their string 465 # encoding. All BSD system functions expect their string
466 # parameters to be in UTF-8 encoding and nothing else." 466 # parameters to be in UTF-8 encoding and nothing else."
467 # It also says 467 # It also says
468 # "An additional caveat is that string parameters for files, 468 # "An additional caveat is that string parameters for files,
469 # paths, and other file-system entities must be in canonical 469 # paths, and other file-system entities must be in canonical
470 # UTF-8. In a canonical UTF-8 Unicode string, all decomposable 470 # UTF-8. In a canonical UTF-8 Unicode string, all decomposable
471 # characters are decomposed ..." 471 # characters are decomposed ..."
472 # but this is not true: You can pass non-decomposed UTF-8 strings 472 # but this is not true: You can pass non-decomposed UTF-8 strings
473 # to file system functions, and it is the OS which will convert 473 # to file system functions, and it is the OS which will convert
474 # them to decomposed UTF-8 before accessing the file system. 474 # them to decomposed UTF-8 before accessing the file system.
475 # - The Apple Terminal application displays UTF-8 by default. 475 # - The Apple Terminal application displays UTF-8 by default.
476 # - However, other applications are free to use different encodings: 476 # - However, other applications are free to use different encodings:
477 # - xterm uses ISO-8859-1 by default. 477 # - xterm uses ISO-8859-1 by default.
478 # - TextEdit uses MacRoman by default. 478 # - TextEdit uses MacRoman by default.
479 # We prefer UTF-8 over decomposed UTF-8-MAC because one should 479 # We prefer UTF-8 over decomposed UTF-8-MAC because one should
480 # minimize the use of decomposed Unicode. Unfortunately, through the 480 # minimize the use of decomposed Unicode. Unfortunately, through the
481 # Darwin file system, decomposed UTF-8 strings are leaked into user 481 # Darwin file system, decomposed UTF-8 strings are leaked into user
482 # space nevertheless. 482 # space nevertheless.
483 # Then there are also the locales with encodings other than US-ASCII 483 # Then there are also the locales with encodings other than US-ASCII
484 # and UTF-8. These locales can be occasionally useful to users (e.g. 484 # and UTF-8. These locales can be occasionally useful to users (e.g.
485 # when grepping through ISO-8859-1 encoded text files), when all their 485 # when grepping through ISO-8859-1 encoded text files), when all their
486 # file names are in US-ASCII. 486 # file names are in US-ASCII.
487 echo "ISO8859-1 ISO-8859-1" 487 echo "ISO8859-1 ISO-8859-1"
488 echo "ISO8859-2 ISO-8859-2" 488 echo "ISO8859-2 ISO-8859-2"
489 echo "ISO8859-4 ISO-8859-4" 489 echo "ISO8859-4 ISO-8859-4"
490 echo "ISO8859-5 ISO-8859-5" 490 echo "ISO8859-5 ISO-8859-5"
491 echo "ISO8859-7 ISO-8859-7" 491 echo "ISO8859-7 ISO-8859-7"
492 echo "ISO8859-9 ISO-8859-9" 492 echo "ISO8859-9 ISO-8859-9"
493 echo "ISO8859-13 ISO-8859-13" 493 echo "ISO8859-13 ISO-8859-13"
494 echo "ISO8859-15 ISO-8859-15" 494 echo "ISO8859-15 ISO-8859-15"
495 echo "KOI8-R KOI8-R" 495 echo "KOI8-R KOI8-R"
496 echo "KOI8-U KOI8-U" 496 echo "KOI8-U KOI8-U"
497 echo "CP866 CP866" 497 echo "CP866 CP866"
498 echo "CP949 CP949" 498 echo "CP949 CP949"
499 echo "CP1131 CP1131" 499 echo "CP1131 CP1131"
500 echo "CP1251 CP1251" 500 echo "CP1251 CP1251"
501 echo "eucCN GB2312" 501 echo "eucCN GB2312"
502 echo "GB2312 GB2312" 502 echo "GB2312 GB2312"
503 echo "eucJP EUC-JP" 503 echo "eucJP EUC-JP"
504 echo "eucKR EUC-KR" 504 echo "eucKR EUC-KR"
505 echo "Big5 BIG5" 505 echo "Big5 BIG5"
506 echo "Big5HKSCS BIG5-HKSCS" 506 echo "Big5HKSCS BIG5-HKSCS"
507 echo "GBK GBK" 507 echo "GBK GBK"
508 echo "GB18030 GB18030" 508 echo "GB18030 GB18030"
509 echo "SJIS SHIFT_JIS" 509 echo "SJIS SHIFT_JIS"
510 echo "ARMSCII-8 ARMSCII-8" 510 echo "ARMSCII-8 ARMSCII-8"
511 echo "PT154 PT154" 511 echo "PT154 PT154"
512 #echo "ISCII-DEV ?" 512 #echo "ISCII-DEV ?"
513 echo "* UTF-8" 513 echo "* UTF-8"
514 ;; 514 ;;
515 beos* | haiku*) 515 beos* | haiku*)
516 # BeOS and Haiku have a single locale, and it has UTF-8 encoding. 516 # BeOS and Haiku have a single locale, and it has UTF-8 encoding.
517 echo "* UTF-8" 517 echo "* UTF-8"
518 ;; 518 ;;
519 msdosdjgpp*) 519 msdosdjgpp*)
520 # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore 520 # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore
521 # localcharset.c falls back to using the full locale name 521 # localcharset.c falls back to using the full locale name
522 # from the environment variables. 522 # from the environment variables.
523 echo "#" 523 echo "#"
524 echo "# The encodings given here may not all be correct." 524 echo "# The encodings given here may not all be correct."
525 echo "# If you find that the encoding given for your language and" 525 echo "# If you find that the encoding given for your language and"
526 echo "# country is not the one your DOS machine actually uses, just" 526 echo "# country is not the one your DOS machine actually uses, just"
527 echo "# correct it in this file, and send a mail to" 527 echo "# correct it in this file, and send a mail to"
528 echo "# Juan Manuel Guerrero <juan.guerrero@gmx.de>" 528 echo "# Juan Manuel Guerrero <juan.guerrero@gmx.de>"
529 echo "# and Bruno Haible <bruno@clisp.org>." 529 echo "# and Bruno Haible <bruno@clisp.org>."
530 echo "#" 530 echo "#"
531 echo "C ASCII" 531 echo "C ASCII"
532 # ISO-8859-1 languages 532 # ISO-8859-1 languages
533 echo "ca CP850" 533 echo "ca CP850"
534 echo "ca_ES CP850" 534 echo "ca_ES CP850"
535 echo "da CP865" # not CP850 ?? 535 echo "da CP865" # not CP850 ??
536 echo "da_DK CP865" # not CP850 ?? 536 echo "da_DK CP865" # not CP850 ??
537 echo "de CP850" 537 echo "de CP850"
538 echo "de_AT CP850" 538 echo "de_AT CP850"
539 echo "de_CH CP850" 539 echo "de_CH CP850"
540 echo "de_DE CP850" 540 echo "de_DE CP850"
541 echo "en CP850" 541 echo "en CP850"
542 echo "en_AU CP850" # not CP437 ?? 542 echo "en_AU CP850" # not CP437 ??
543 echo "en_CA CP850" 543 echo "en_CA CP850"
544 echo "en_GB CP850" 544 echo "en_GB CP850"
545 echo "en_NZ CP437" 545 echo "en_NZ CP437"
546 echo "en_US CP437" 546 echo "en_US CP437"
547 echo "en_ZA CP850" # not CP437 ?? 547 echo "en_ZA CP850" # not CP437 ??
548 echo "es CP850" 548 echo "es CP850"
549 echo "es_AR CP850" 549 echo "es_AR CP850"
550 echo "es_BO CP850" 550 echo "es_BO CP850"
551 echo "es_CL CP850" 551 echo "es_CL CP850"
552 echo "es_CO CP850" 552 echo "es_CO CP850"
553 echo "es_CR CP850" 553 echo "es_CR CP850"
554 echo "es_CU CP850" 554 echo "es_CU CP850"
555 echo "es_DO CP850" 555 echo "es_DO CP850"
556 echo "es_EC CP850" 556 echo "es_EC CP850"
557 echo "es_ES CP850" 557 echo "es_ES CP850"
558 echo "es_GT CP850" 558 echo "es_GT CP850"
559 echo "es_HN CP850" 559 echo "es_HN CP850"
560 echo "es_MX CP850" 560 echo "es_MX CP850"
561 echo "es_NI CP850" 561 echo "es_NI CP850"
562 echo "es_PA CP850" 562 echo "es_PA CP850"
563 echo "es_PY CP850" 563 echo "es_PY CP850"
564 echo "es_PE CP850" 564 echo "es_PE CP850"
565 echo "es_SV CP850" 565 echo "es_SV CP850"
566 echo "es_UY CP850" 566 echo "es_UY CP850"
567 echo "es_VE CP850" 567 echo "es_VE CP850"
568 echo "et CP850" 568 echo "et CP850"
569 echo "et_EE CP850" 569 echo "et_EE CP850"
570 echo "eu CP850" 570 echo "eu CP850"
571 echo "eu_ES CP850" 571 echo "eu_ES CP850"
572 echo "fi CP850" 572 echo "fi CP850"
573 echo "fi_FI CP850" 573 echo "fi_FI CP850"
574 echo "fr CP850" 574 echo "fr CP850"
575 echo "fr_BE CP850" 575 echo "fr_BE CP850"
576 echo "fr_CA CP850" 576 echo "fr_CA CP850"
577 echo "fr_CH CP850" 577 echo "fr_CH CP850"
578 echo "fr_FR CP850" 578 echo "fr_FR CP850"
579 echo "ga CP850" 579 echo "ga CP850"
580 echo "ga_IE CP850" 580 echo "ga_IE CP850"
581 echo "gd CP850" 581 echo "gd CP850"
582 echo "gd_GB CP850" 582 echo "gd_GB CP850"
583 echo "gl CP850" 583 echo "gl CP850"
584 echo "gl_ES CP850" 584 echo "gl_ES CP850"
585 echo "id CP850" # not CP437 ?? 585 echo "id CP850" # not CP437 ??
586 echo "id_ID CP850" # not CP437 ?? 586 echo "id_ID CP850" # not CP437 ??
587 echo "is CP861" # not CP850 ?? 587 echo "is CP861" # not CP850 ??
588 echo "is_IS CP861" # not CP850 ?? 588 echo "is_IS CP861" # not CP850 ??
589 echo "it CP850" 589 echo "it CP850"
590 echo "it_CH CP850" 590 echo "it_CH CP850"
591 echo "it_IT CP850" 591 echo "it_IT CP850"
592 echo "lt CP775" 592 echo "lt CP775"
593 echo "lt_LT CP775" 593 echo "lt_LT CP775"
594 echo "lv CP775" 594 echo "lv CP775"
595 echo "lv_LV CP775" 595 echo "lv_LV CP775"
596 echo "nb CP865" # not CP850 ?? 596 echo "nb CP865" # not CP850 ??
597 echo "nb_NO CP865" # not CP850 ?? 597 echo "nb_NO CP865" # not CP850 ??
598 echo "nl CP850" 598 echo "nl CP850"
599 echo "nl_BE CP850" 599 echo "nl_BE CP850"
600 echo "nl_NL CP850" 600 echo "nl_NL CP850"
601 echo "nn CP865" # not CP850 ?? 601 echo "nn CP865" # not CP850 ??
602 echo "nn_NO CP865" # not CP850 ?? 602 echo "nn_NO CP865" # not CP850 ??
603 echo "no CP865" # not CP850 ?? 603 echo "no CP865" # not CP850 ??
604 echo "no_NO CP865" # not CP850 ?? 604 echo "no_NO CP865" # not CP850 ??
605 echo "pt CP850" 605 echo "pt CP850"
606 echo "pt_BR CP850" 606 echo "pt_BR CP850"
607 echo "pt_PT CP850" 607 echo "pt_PT CP850"
608 echo "sv CP850" 608 echo "sv CP850"
609 echo "sv_SE CP850" 609 echo "sv_SE CP850"
610 # ISO-8859-2 languages 610 # ISO-8859-2 languages
611 echo "cs CP852" 611 echo "cs CP852"
612 echo "cs_CZ CP852" 612 echo "cs_CZ CP852"
613 echo "hr CP852" 613 echo "hr CP852"
614 echo "hr_HR CP852" 614 echo "hr_HR CP852"
615 echo "hu CP852" 615 echo "hu CP852"
616 echo "hu_HU CP852" 616 echo "hu_HU CP852"
617 echo "pl CP852" 617 echo "pl CP852"
618 echo "pl_PL CP852" 618 echo "pl_PL CP852"
619 echo "ro CP852" 619 echo "ro CP852"
620 echo "ro_RO CP852" 620 echo "ro_RO CP852"
621 echo "sk CP852" 621 echo "sk CP852"
622 echo "sk_SK CP852" 622 echo "sk_SK CP852"
623 echo "sl CP852" 623 echo "sl CP852"
624 echo "sl_SI CP852" 624 echo "sl_SI CP852"
625 echo "sq CP852" 625 echo "sq CP852"
626 echo "sq_AL CP852" 626 echo "sq_AL CP852"
627 echo "sr CP852" # CP852 or CP866 or CP855 ?? 627 echo "sr CP852" # CP852 or CP866 or CP855 ??
628 echo "sr_CS CP852" # CP852 or CP866 or CP855 ?? 628 echo "sr_CS CP852" # CP852 or CP866 or CP855 ??
629 echo "sr_YU CP852" # CP852 or CP866 or CP855 ?? 629 echo "sr_YU CP852" # CP852 or CP866 or CP855 ??
630 # ISO-8859-3 languages 630 # ISO-8859-3 languages
631 echo "mt CP850" 631 echo "mt CP850"
632 echo "mt_MT CP850" 632 echo "mt_MT CP850"
633 # ISO-8859-5 languages 633 # ISO-8859-5 languages
634 echo "be CP866" 634 echo "be CP866"
635 echo "be_BE CP866" 635 echo "be_BE CP866"
636 echo "bg CP866" # not CP855 ?? 636 echo "bg CP866" # not CP855 ??
637 echo "bg_BG CP866" # not CP855 ?? 637 echo "bg_BG CP866" # not CP855 ??
638 echo "mk CP866" # not CP855 ?? 638 echo "mk CP866" # not CP855 ??
639 echo "mk_MK CP866" # not CP855 ?? 639 echo "mk_MK CP866" # not CP855 ??
640 echo "ru CP866" 640 echo "ru CP866"
641 echo "ru_RU CP866" 641 echo "ru_RU CP866"
642 echo "uk CP1125" 642 echo "uk CP1125"
643 echo "uk_UA CP1125" 643 echo "uk_UA CP1125"
644 # ISO-8859-6 languages 644 # ISO-8859-6 languages
645 echo "ar CP864" 645 echo "ar CP864"
646 echo "ar_AE CP864" 646 echo "ar_AE CP864"
647 echo "ar_DZ CP864" 647 echo "ar_DZ CP864"
648 echo "ar_EG CP864" 648 echo "ar_EG CP864"
649 echo "ar_IQ CP864" 649 echo "ar_IQ CP864"
650 echo "ar_IR CP864" 650 echo "ar_IR CP864"
651 echo "ar_JO CP864" 651 echo "ar_JO CP864"
652 echo "ar_KW CP864" 652 echo "ar_KW CP864"
653 echo "ar_MA CP864" 653 echo "ar_MA CP864"
654 echo "ar_OM CP864" 654 echo "ar_OM CP864"
655 echo "ar_QA CP864" 655 echo "ar_QA CP864"
656 echo "ar_SA CP864" 656 echo "ar_SA CP864"
657 echo "ar_SY CP864" 657 echo "ar_SY CP864"
658 # ISO-8859-7 languages 658 # ISO-8859-7 languages
659 echo "el CP869" 659 echo "el CP869"
660 echo "el_GR CP869" 660 echo "el_GR CP869"
661 # ISO-8859-8 languages 661 # ISO-8859-8 languages
662 echo "he CP862" 662 echo "he CP862"
663 echo "he_IL CP862" 663 echo "he_IL CP862"
664 # ISO-8859-9 languages 664 # ISO-8859-9 languages
665 echo "tr CP857" 665 echo "tr CP857"
666 echo "tr_TR CP857" 666 echo "tr_TR CP857"
667 # Japanese 667 # Japanese
668 echo "ja CP932" 668 echo "ja CP932"
669 echo "ja_JP CP932" 669 echo "ja_JP CP932"
670 # Chinese 670 # Chinese
671 echo "zh_CN GBK" 671 echo "zh_CN GBK"
672 echo "zh_TW CP950" # not CP938 ?? 672 echo "zh_TW CP950" # not CP938 ??
673 # Korean 673 # Korean
674 echo "kr CP949" # not CP934 ?? 674 echo "kr CP949" # not CP934 ??
675 echo "kr_KR CP949" # not CP934 ?? 675 echo "kr_KR CP949" # not CP934 ??
676 # Thai 676 # Thai
677 echo "th CP874" 677 echo "th CP874"
678 echo "th_TH CP874" 678 echo "th_TH CP874"
679 # Other 679 # Other
680 echo "eo CP850" 680 echo "eo CP850"
681 echo "eo_EO CP850" 681 echo "eo_EO CP850"
682 ;; 682 ;;
683esac 683esac
diff --git a/gl/creat-safer.c b/gl/creat-safer.c
index fc314ba4..da0418df 100644
--- a/gl/creat-safer.c
+++ b/gl/creat-safer.c
@@ -1,6 +1,6 @@
1/* Invoke creat, but avoid some glitches. 1/* Invoke creat, but avoid some glitches.
2 2
3 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/dirname-lgpl.c b/gl/dirname-lgpl.c
new file mode 100644
index 00000000..d4506e06
--- /dev/null
+++ b/gl/dirname-lgpl.c
@@ -0,0 +1,86 @@
1/* dirname.c -- return all but the last element in a file name
2
3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2010 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#include "dirname.h"
22
23#include <stdlib.h>
24#include <string.h>
25
26/* Return the length of the prefix of FILE that will be used by
27 dir_name. If FILE is in the working directory, this returns zero
28 even though `dir_name (FILE)' will return ".". Works properly even
29 if there are trailing slashes (by effectively ignoring them). */
30
31size_t
32dir_len (char const *file)
33{
34 size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
35 size_t length;
36
37 /* Advance prefix_length beyond important leading slashes. */
38 prefix_length += (prefix_length != 0
39 ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
40 && ISSLASH (file[prefix_length]))
41 : (ISSLASH (file[0])
42 ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
43 && ISSLASH (file[1]) && ! ISSLASH (file[2])
44 ? 2 : 1))
45 : 0));
46
47 /* Strip the basename and any redundant slashes before it. */
48 for (length = last_component (file) - file;
49 prefix_length < length; length--)
50 if (! ISSLASH (file[length - 1]))
51 break;
52 return length;
53}
54
55
56/* In general, we can't use the builtin `dirname' function if available,
57 since it has different meanings in different environments.
58 In some environments the builtin `dirname' modifies its argument.
59
60 Return the leading directories part of FILE, allocated with malloc.
61 Works properly even if there are trailing slashes (by effectively
62 ignoring them). Return NULL on failure.
63
64 If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
65 lstat (base_name (FILE)); } will access the same file. Likewise,
66 if the sequence { chdir (dir_name (FILE));
67 rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
68 to "foo" in the same directory FILE was in. */
69
70char *
71mdir_name (char const *file)
72{
73 size_t length = dir_len (file);
74 bool append_dot = (length == 0
75 || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
76 && length == FILE_SYSTEM_PREFIX_LEN (file)
77 && file[2] != '\0' && ! ISSLASH (file[2])));
78 char *dir = malloc (length + append_dot + 1);
79 if (!dir)
80 return NULL;
81 memcpy (dir, file, length);
82 if (append_dot)
83 dir[length++] = '.';
84 dir[length] = '\0';
85 return dir;
86}
diff --git a/gl/dirname.c b/gl/dirname.c
index c27e5b5d..953a9acc 100644
--- a/gl/dirname.c
+++ b/gl/dirname.c
@@ -1,6 +1,6 @@
1/* dirname.c -- return all but the last element in a file name 1/* dirname.c -- return all but the last element in a file name
2 2
3 Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software 3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2010 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This program is free software: you can redistribute it and/or modify
@@ -20,65 +20,19 @@
20 20
21#include "dirname.h" 21#include "dirname.h"
22 22
23#include <stdlib.h>
23#include <string.h> 24#include <string.h>
24#include "xalloc.h" 25#include "xalloc.h"
25 26
26/* Return the length of the prefix of FILE that will be used by 27/* Just like mdir_name (dirname-lgpl.c), except, rather than
27 dir_name. If FILE is in the working directory, this returns zero 28 returning NULL upon malloc failure, here, we report the
28 even though `dir_name (FILE)' will return ".". Works properly even 29 "memory exhausted" condition and exit. */
29 if there are trailing slashes (by effectively ignoring them). */
30
31size_t
32dir_len (char const *file)
33{
34 size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
35 size_t length;
36
37 /* Advance prefix_length beyond important leading slashes. */
38 prefix_length += (prefix_length != 0
39 ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
40 && ISSLASH (file[prefix_length]))
41 : (ISSLASH (file[0])
42 ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
43 && ISSLASH (file[1]) && ! ISSLASH (file[2])
44 ? 2 : 1))
45 : 0));
46
47 /* Strip the basename and any redundant slashes before it. */
48 for (length = last_component (file) - file;
49 prefix_length < length; length--)
50 if (! ISSLASH (file[length - 1]))
51 break;
52 return length;
53}
54
55
56/* In general, we can't use the builtin `dirname' function if available,
57 since it has different meanings in different environments.
58 In some environments the builtin `dirname' modifies its argument.
59
60 Return the leading directories part of FILE, allocated with xmalloc.
61 Works properly even if there are trailing slashes (by effectively
62 ignoring them). Unlike POSIX dirname(), FILE cannot be NULL.
63
64 If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
65 lstat (base_name (FILE)); } will access the same file. Likewise,
66 if the sequence { chdir (dir_name (FILE));
67 rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
68 to "foo" in the same directory FILE was in. */
69 30
70char * 31char *
71dir_name (char const *file) 32dir_name (char const *file)
72{ 33{
73 size_t length = dir_len (file); 34 char *result = mdir_name (file);
74 bool append_dot = (length == 0 35 if (!result)
75 || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 36 xalloc_die ();
76 && length == FILE_SYSTEM_PREFIX_LEN (file) 37 return result;
77 && file[2] != '\0' && ! ISSLASH (file[2])));
78 char *dir = xmalloc (length + append_dot + 1);
79 memcpy (dir, file, length);
80 if (append_dot)
81 dir[length++] = '.';
82 dir[length] = '\0';
83 return dir;
84} 38}
diff --git a/gl/dirname.h b/gl/dirname.h
index f592350b..fb19508f 100644
--- a/gl/dirname.h
+++ b/gl/dirname.h
@@ -1,6 +1,7 @@
1/* Take file names apart into directory and base names. 1/* Take file names apart into directory and base names.
2 2
3 Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc. 3 Copyright (C) 1998, 2001, 2003-2006, 2009-2010 Free Software Foundation,
4 Inc.
4 5
5 This program is free software: you can redistribute it and/or modify 6 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 it under the terms of the GNU General Public License as published by
@@ -34,9 +35,9 @@
34 /* This internal macro assumes ASCII, but all hosts that support drive 35 /* This internal macro assumes ASCII, but all hosts that support drive
35 letters use ASCII. */ 36 letters use ASCII. */
36# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \ 37# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
37 <= 'z' - 'a') 38 <= 'z' - 'a')
38# define FILE_SYSTEM_PREFIX_LEN(Filename) \ 39# define FILE_SYSTEM_PREFIX_LEN(Filename) \
39 (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) 40 (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
40# else 41# else
41# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 42# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
42# endif 43# endif
@@ -54,12 +55,16 @@
54# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) 55# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
55# else 56# else
56# define IS_ABSOLUTE_FILE_NAME(F) \ 57# define IS_ABSOLUTE_FILE_NAME(F) \
57 (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) 58 (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
58# endif 59# endif
59# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) 60# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
60 61
62# if GNULIB_DIRNAME
61char *base_name (char const *file); 63char *base_name (char const *file);
62char *dir_name (char const *file); 64char *dir_name (char const *file);
65# endif
66
67char *mdir_name (char const *file);
63size_t base_len (char const *file); 68size_t base_len (char const *file);
64size_t dir_len (char const *file); 69size_t dir_len (char const *file);
65char *last_component (char const *file); 70char *last_component (char const *file);
diff --git a/gl/dup-safer.c b/gl/dup-safer.c
index 7d9b2be3..33f599be 100644
--- a/gl/dup-safer.c
+++ b/gl/dup-safer.c
@@ -1,7 +1,6 @@
1/* Invoke dup, but avoid some glitches. 1/* Invoke dup, but avoid some glitches.
2 2
3 Copyright (C) 2001, 2004, 2005, 2006, 2009 Free Software 3 Copyright (C) 2001, 2004-2006, 2009-2010 Free Software Foundation, Inc.
4 Foundation, Inc.
5 4
6 This program is free software: you can redistribute it and/or modify 5 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 6 it under the terms of the GNU General Public License as published by
@@ -23,7 +22,6 @@
23#include "unistd-safer.h" 22#include "unistd-safer.h"
24 23
25#include <fcntl.h> 24#include <fcntl.h>
26
27#include <unistd.h> 25#include <unistd.h>
28 26
29/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or 27/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
@@ -32,11 +30,5 @@
32int 30int
33dup_safer (int fd) 31dup_safer (int fd)
34{ 32{
35#if defined F_DUPFD && !defined FCHDIR_REPLACEMENT
36 return fcntl (fd, F_DUPFD, STDERR_FILENO + 1); 33 return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
37#else
38 /* fd_safer calls us back, but eventually the recursion unwinds and
39 does the right thing. */
40 return fd_safer (dup (fd));
41#endif
42} 34}
diff --git a/gl/dup2.c b/gl/dup2.c
new file mode 100644
index 00000000..a4422bf3
--- /dev/null
+++ b/gl/dup2.c
@@ -0,0 +1,128 @@
1/* Duplicate an open file descriptor to a specified file descriptor.
2
3 Copyright (C) 1999, 2004-2007, 2009-2010 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/* Specification. */
23#include <unistd.h>
24
25#include <errno.h>
26#include <fcntl.h>
27
28#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
29/* Get declarations of the Win32 API functions. */
30# define WIN32_LEAN_AND_MEAN
31# include <windows.h>
32#endif
33
34#if HAVE_DUP2
35
36# undef dup2
37
38int
39rpl_dup2 (int fd, int desired_fd)
40{
41 int result;
42# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
43 /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open,
44 dup2 (fd, fd) returns 0, but all further attempts to use fd in
45 future dup2 calls will hang. */
46 if (fd == desired_fd)
47 {
48 if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
49 {
50 errno = EBADF;
51 return -1;
52 }
53 return fd;
54 }
55 /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
56 http://bugs.winehq.org/show_bug.cgi?id=21289 */
57 if (desired_fd < 0)
58 {
59 errno = EBADF;
60 return -1;
61 }
62# endif
63 result = dup2 (fd, desired_fd);
64# ifdef __linux__
65 /* Correct a Linux return value.
66 <http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.30.y.git;a=commitdiff;h=2b79bc4f7ebbd5af3c8b867968f9f15602d5f802>
67 */
68 if (fd == desired_fd && result == (unsigned int) -EBADF)
69 {
70 errno = EBADF;
71 result = -1;
72 }
73# endif
74 if (result == 0)
75 result = desired_fd;
76 /* Correct a cygwin 1.5.x errno value. */
77 else if (result == -1 && errno == EMFILE)
78 errno = EBADF;
79# if REPLACE_FCHDIR
80 if (fd != desired_fd && result != -1)
81 result = _gl_register_dup (fd, result);
82# endif
83 return result;
84}
85
86#else /* !HAVE_DUP2 */
87
88/* On older platforms, dup2 did not exist. */
89
90# ifndef F_DUPFD
91static int
92dupfd (int fd, int desired_fd)
93{
94 int duplicated_fd = dup (fd);
95 if (duplicated_fd < 0 || duplicated_fd == desired_fd)
96 return duplicated_fd;
97 else
98 {
99 int r = dupfd (fd, desired_fd);
100 int e = errno;
101 close (duplicated_fd);
102 errno = e;
103 return r;
104 }
105}
106# endif
107
108int
109dup2 (int fd, int desired_fd)
110{
111 int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
112 if (result == -1 || fd == desired_fd)
113 return result;
114 close (desired_fd);
115# ifdef F_DUPFD
116 result = fcntl (fd, F_DUPFD, desired_fd);
117# if REPLACE_FCHDIR
118 if (0 <= result)
119 result = _gl_register_dup (fd, result);
120# endif
121# else
122 result = dupfd (fd, desired_fd);
123# endif
124 if (result == -1 && (errno == EMFILE || errno == EINVAL))
125 errno = EBADF;
126 return result;
127}
128#endif /* !HAVE_DUP2 */
diff --git a/gl/errno.in.h b/gl/errno.in.h
index 51ac6624..140e5d13 100644
--- a/gl/errno.in.h
+++ b/gl/errno.in.h
@@ -1,6 +1,6 @@
1/* A POSIX-like <errno.h>. 1/* A POSIX-like <errno.h>.
2 2
3 Copyright (C) 2008 Free Software Foundation, Inc. 3 Copyright (C) 2008-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -145,6 +145,11 @@
145# define GNULIB_defined_ENOTSUP 1 145# define GNULIB_defined_ENOTSUP 1
146# endif 146# endif
147 147
148# ifndef ESTALE
149# define ESTALE 2009
150# define GNULIB_defined_ESTALE 1
151# endif
152
148# ifndef ECANCELED 153# ifndef ECANCELED
149# define ECANCELED 2008 154# define ECANCELED 2008
150# define GNULIB_defined_ECANCELED 1 155# define GNULIB_defined_ECANCELED 1
diff --git a/gl/error.c b/gl/error.c
index 3177bd5d..c79e8d42 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -1,5 +1,5 @@
1/* Error handler for noninteractive utilities 1/* Error handler for noninteractive utilities
2 Copyright (C) 1990-1998, 2000-2007 Free Software Foundation, Inc. 2 Copyright (C) 1990-1998, 2000-2007, 2009-2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
@@ -70,8 +70,8 @@ unsigned int error_message_count;
70extern void __error (int status, int errnum, const char *message, ...) 70extern void __error (int status, int errnum, const char *message, ...)
71 __attribute__ ((__format__ (__printf__, 3, 4))); 71 __attribute__ ((__format__ (__printf__, 3, 4)));
72extern void __error_at_line (int status, int errnum, const char *file_name, 72extern void __error_at_line (int status, int errnum, const char *file_name,
73 unsigned int line_number, const char *message, 73 unsigned int line_number, const char *message,
74 ...) 74 ...)
75 __attribute__ ((__format__ (__printf__, 5, 6)));; 75 __attribute__ ((__format__ (__printf__, 5, 6)));;
76# define error __error 76# define error __error
77# define error_at_line __error_at_line 77# define error_at_line __error_at_line
@@ -85,6 +85,9 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
85 85
86#else /* not _LIBC */ 86#else /* not _LIBC */
87 87
88# include <fcntl.h>
89# include <unistd.h>
90
88# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P 91# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
89# ifndef HAVE_DECL_STRERROR_R 92# ifndef HAVE_DECL_STRERROR_R
90"this configure-time declaration test was not run" 93"this configure-time declaration test was not run"
@@ -98,8 +101,33 @@ extern char *program_name;
98 101
99# if HAVE_STRERROR_R || defined strerror_r 102# if HAVE_STRERROR_R || defined strerror_r
100# define __strerror_r strerror_r 103# define __strerror_r strerror_r
101# endif /* HAVE_STRERROR_R || defined strerror_r */ 104# endif /* HAVE_STRERROR_R || defined strerror_r */
102#endif /* not _LIBC */ 105#endif /* not _LIBC */
106
107static inline void
108flush_stdout (void)
109{
110#if !_LIBC && defined F_GETFL
111 int stdout_fd;
112
113# if GNULIB_FREOPEN_SAFER
114 /* Use of gnulib's freopen-safer module normally ensures that
115 fileno (stdout) == 1
116 whenever stdout is open. */
117 stdout_fd = STDOUT_FILENO;
118# else
119 /* POSIX states that fileno (stdout) after fclose is unspecified. But in
120 practice it is not a problem, because stdout is statically allocated and
121 the fd of a FILE stream is stored as a field in its allocated memory. */
122 stdout_fd = fileno (stdout);
123# endif
124 /* POSIX states that fflush (stdout) after fclose is unspecified; it
125 is safe in glibc, but not on all other platforms. fflush (NULL)
126 is always defined, but too draconian. */
127 if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL))
128#endif
129 fflush (stdout);
130}
103 131
104static void 132static void
105print_errno_message (int errnum) 133print_errno_message (int errnum)
@@ -147,58 +175,58 @@ error_tail (int status, int errnum, const char *message, va_list args)
147 bool use_malloc = false; 175 bool use_malloc = false;
148 176
149 while (1) 177 while (1)
150 { 178 {
151 if (__libc_use_alloca (len * sizeof (wchar_t))) 179 if (__libc_use_alloca (len * sizeof (wchar_t)))
152 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); 180 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
153 else 181 else
154 { 182 {
155 if (!use_malloc) 183 if (!use_malloc)
156 wmessage = NULL; 184 wmessage = NULL;
157 185
158 wchar_t *p = (wchar_t *) realloc (wmessage, 186 wchar_t *p = (wchar_t *) realloc (wmessage,
159 len * sizeof (wchar_t)); 187 len * sizeof (wchar_t));
160 if (p == NULL) 188 if (p == NULL)
161 { 189 {
162 free (wmessage); 190 free (wmessage);
163 fputws_unlocked (L"out of memory\n", stderr); 191 fputws_unlocked (L"out of memory\n", stderr);
164 return; 192 return;
165 } 193 }
166 wmessage = p; 194 wmessage = p;
167 use_malloc = true; 195 use_malloc = true;
168 } 196 }
169 197
170 memset (&st, '\0', sizeof (st)); 198 memset (&st, '\0', sizeof (st));
171 tmp = message; 199 tmp = message;
172 200
173 res = mbsrtowcs (wmessage, &tmp, len, &st); 201 res = mbsrtowcs (wmessage, &tmp, len, &st);
174 if (res != len) 202 if (res != len)
175 break; 203 break;
176 204
177 if (__builtin_expect (len >= SIZE_MAX / 2, 0)) 205 if (__builtin_expect (len >= SIZE_MAX / 2, 0))
178 { 206 {
179 /* This really should not happen if everything is fine. */ 207 /* This really should not happen if everything is fine. */
180 res = (size_t) -1; 208 res = (size_t) -1;
181 break; 209 break;
182 } 210 }
183 211
184 len *= 2; 212 len *= 2;
185 } 213 }
186 214
187 if (res == (size_t) -1) 215 if (res == (size_t) -1)
188 { 216 {
189 /* The string cannot be converted. */ 217 /* The string cannot be converted. */
190 if (use_malloc) 218 if (use_malloc)
191 { 219 {
192 free (wmessage); 220 free (wmessage);
193 use_malloc = false; 221 use_malloc = false;
194 } 222 }
195 wmessage = (wchar_t *) L"???"; 223 wmessage = (wchar_t *) L"???";
196 } 224 }
197 225
198 __vfwprintf (stderr, wmessage, args); 226 __vfwprintf (stderr, wmessage, args);
199 227
200 if (use_malloc) 228 if (use_malloc)
201 free (wmessage); 229 free (wmessage);
202 } 230 }
203 else 231 else
204#endif 232#endif
@@ -233,10 +261,10 @@ error (int status, int errnum, const char *message, ...)
233 cancellation. Therefore disable cancellation for now. */ 261 cancellation. Therefore disable cancellation for now. */
234 int state = PTHREAD_CANCEL_ENABLE; 262 int state = PTHREAD_CANCEL_ENABLE;
235 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), 263 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
236 0); 264 0);
237#endif 265#endif
238 266
239 fflush (stdout); 267 flush_stdout ();
240#ifdef _LIBC 268#ifdef _LIBC
241 _IO_flockfile (stderr); 269 _IO_flockfile (stderr);
242#endif 270#endif
@@ -268,7 +296,7 @@ int error_one_per_line;
268 296
269void 297void
270error_at_line (int status, int errnum, const char *file_name, 298error_at_line (int status, int errnum, const char *file_name,
271 unsigned int line_number, const char *message, ...) 299 unsigned int line_number, const char *message, ...)
272{ 300{
273 va_list args; 301 va_list args;
274 302
@@ -278,10 +306,10 @@ error_at_line (int status, int errnum, const char *file_name,
278 static unsigned int old_line_number; 306 static unsigned int old_line_number;
279 307
280 if (old_line_number == line_number 308 if (old_line_number == line_number
281 && (file_name == old_file_name 309 && (file_name == old_file_name
282 || strcmp (old_file_name, file_name) == 0)) 310 || strcmp (old_file_name, file_name) == 0))
283 /* Simply return and print nothing. */ 311 /* Simply return and print nothing. */
284 return; 312 return;
285 313
286 old_file_name = file_name; 314 old_file_name = file_name;
287 old_line_number = line_number; 315 old_line_number = line_number;
@@ -292,10 +320,10 @@ error_at_line (int status, int errnum, const char *file_name,
292 cancellation. Therefore disable cancellation for now. */ 320 cancellation. Therefore disable cancellation for now. */
293 int state = PTHREAD_CANCEL_ENABLE; 321 int state = PTHREAD_CANCEL_ENABLE;
294 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), 322 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
295 0); 323 0);
296#endif 324#endif
297 325
298 fflush (stdout); 326 flush_stdout ();
299#ifdef _LIBC 327#ifdef _LIBC
300 _IO_flockfile (stderr); 328 _IO_flockfile (stderr);
301#endif 329#endif
@@ -312,10 +340,10 @@ error_at_line (int status, int errnum, const char *file_name,
312 340
313#if _LIBC 341#if _LIBC
314 __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", 342 __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
315 file_name, line_number); 343 file_name, line_number);
316#else 344#else
317 fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", 345 fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
318 file_name, line_number); 346 file_name, line_number);
319#endif 347#endif
320 348
321 va_start (args, message); 349 va_start (args, message);
diff --git a/gl/error.h b/gl/error.h
index 6d496811..9deef02d 100644
--- a/gl/error.h
+++ b/gl/error.h
@@ -1,5 +1,6 @@
1/* Declaration for error-reporting function 1/* Declaration for error-reporting function
2 Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008 Free Software Foundation, Inc. 2 Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008, 2009, 2010 Free Software
3 Foundation, Inc.
3 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
4 5
5 This program is free software: you can redistribute it and/or modify 6 This program is free software: you can redistribute it and/or modify
@@ -19,19 +20,18 @@
19#define _ERROR_H 1 20#define _ERROR_H 1
20 21
21#ifndef __attribute__ 22#ifndef __attribute__
22/* This feature is available in gcc versions 2.5 and later. */ 23/* The __attribute__ feature is available in gcc versions 2.5 and later.
23# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) 24 The __-protected variants of the attributes 'format' and 'printf' are
24# define __attribute__(Spec) /* empty */ 25 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
25# endif 26 We enable __attribute__ only if these are supported too, because
26/* The __-protected variants of `format' and `printf' attributes 27 gnulib and libintl do '#define printf __printf__' when they override
27 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 28 the 'printf' function. */
28# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 29# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
29# define __format__ format 30# define __attribute__(Spec) /* empty */
30# define __printf__ printf
31# endif 31# endif
32#endif 32#endif
33 33
34#ifdef __cplusplus 34#ifdef __cplusplus
35extern "C" { 35extern "C" {
36#endif 36#endif
37 37
@@ -43,7 +43,7 @@ extern void error (int __status, int __errnum, const char *__format, ...)
43 __attribute__ ((__format__ (__printf__, 3, 4))); 43 __attribute__ ((__format__ (__printf__, 3, 4)));
44 44
45extern void error_at_line (int __status, int __errnum, const char *__fname, 45extern void error_at_line (int __status, int __errnum, const char *__fname,
46 unsigned int __lineno, const char *__format, ...) 46 unsigned int __lineno, const char *__format, ...)
47 __attribute__ ((__format__ (__printf__, 5, 6))); 47 __attribute__ ((__format__ (__printf__, 5, 6)));
48 48
49/* If NULL, error will flush stdout, then print on stderr the program 49/* If NULL, error will flush stdout, then print on stderr the program
@@ -58,7 +58,7 @@ extern unsigned int error_message_count;
58 variable controls whether this mode is selected or not. */ 58 variable controls whether this mode is selected or not. */
59extern int error_one_per_line; 59extern int error_one_per_line;
60 60
61#ifdef __cplusplus 61#ifdef __cplusplus
62} 62}
63#endif 63#endif
64 64
diff --git a/gl/exitfail.c b/gl/exitfail.c
index 6d1fe4ae..3b63f8a1 100644
--- a/gl/exitfail.c
+++ b/gl/exitfail.c
@@ -1,6 +1,7 @@
1/* Failure exit status 1/* Failure exit status
2 2
3 Copyright (C) 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2002, 2003, 2005, 2006, 2007, 2009, 2010 Free Software
4 Foundation, Inc.
4 5
5 This program is free software: you can redistribute it and/or modify 6 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 it under the terms of the GNU General Public License as published by
diff --git a/gl/exitfail.h b/gl/exitfail.h
index 713f2591..7ffffe5c 100644
--- a/gl/exitfail.h
+++ b/gl/exitfail.h
@@ -1,6 +1,6 @@
1/* Failure exit status 1/* Failure exit status
2 2
3 Copyright (C) 2002 Free Software Foundation, Inc. 3 Copyright (C) 2002, 2009, 2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/fcntl--.h b/gl/fcntl--.h
index 5a6a8792..7baa2cbc 100644
--- a/gl/fcntl--.h
+++ b/gl/fcntl--.h
@@ -1,6 +1,6 @@
1/* Like fcntl.h, but redefine some names to avoid glitches. 1/* Like fcntl.h, but redefine some names to avoid glitches.
2 2
3 Copyright (C) 2005 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -25,3 +25,8 @@
25 25
26#undef creat 26#undef creat
27#define creat creat_safer 27#define creat creat_safer
28
29#if GNULIB_OPENAT_SAFER
30# undef openat
31# define openat openat_safer
32#endif
diff --git a/gl/fcntl-safer.h b/gl/fcntl-safer.h
index 99f38656..5c76b4bc 100644
--- a/gl/fcntl-safer.h
+++ b/gl/fcntl-safer.h
@@ -1,6 +1,6 @@
1/* Invoke fcntl-like functions, but avoid some glitches. 1/* Invoke fcntl-like functions, but avoid some glitches.
2 2
3 Copyright (C) 2005 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -21,3 +21,7 @@
21 21
22int open_safer (char const *, int, ...); 22int open_safer (char const *, int, ...);
23int creat_safer (char const *, mode_t); 23int creat_safer (char const *, mode_t);
24
25#if GNULIB_OPENAT_SAFER
26int openat_safer (int, char const *, int, ...);
27#endif
diff --git a/gl/fcntl.c b/gl/fcntl.c
new file mode 100644
index 00000000..c51e8ded
--- /dev/null
+++ b/gl/fcntl.c
@@ -0,0 +1,294 @@
1/* Provide file descriptor control.
2
3 Copyright (C) 2009, 2010 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 Eric Blake <ebb9@byu.net>. */
19
20#include <config.h>
21
22/* Specification. */
23#include <fcntl.h>
24
25#include <errno.h>
26#include <limits.h>
27#include <stdarg.h>
28#include <unistd.h>
29
30#if !HAVE_FCNTL
31# define rpl_fcntl fcntl
32#endif
33#undef fcntl
34
35#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
36/* Get declarations of the Win32 API functions. */
37# define WIN32_LEAN_AND_MEAN
38# include <windows.h>
39
40/* Upper bound on getdtablesize(). See lib/getdtablesize.c. */
41# define OPEN_MAX_MAX 0x10000
42
43/* Duplicate OLDFD into the first available slot of at least NEWFD,
44 which must be positive, with FLAGS determining whether the duplicate
45 will be inheritable. */
46static int
47dupfd (int oldfd, int newfd, int flags)
48{
49 /* Mingw has no way to create an arbitrary fd. Iterate until all
50 file descriptors less than newfd are filled up. */
51 HANDLE curr_process = GetCurrentProcess ();
52 HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
53 unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
54 unsigned int fds_to_close_bound = 0;
55 int result;
56 BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
57 int mode;
58
59 if (newfd < 0 || getdtablesize () <= newfd)
60 {
61 errno = EINVAL;
62 return -1;
63 }
64 if (old_handle == INVALID_HANDLE_VALUE
65 || (mode = setmode (oldfd, O_BINARY)) == -1)
66 {
67 /* oldfd is not open, or is an unassigned standard file
68 descriptor. */
69 errno = EBADF;
70 return -1;
71 }
72 setmode (oldfd, mode);
73 flags |= mode;
74
75 for (;;)
76 {
77 HANDLE new_handle;
78 int duplicated_fd;
79 unsigned int index;
80
81 if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
82 old_handle, /* SourceHandle */
83 curr_process, /* TargetProcessHandle */
84 (PHANDLE) &new_handle, /* TargetHandle */
85 (DWORD) 0, /* DesiredAccess */
86 inherit, /* InheritHandle */
87 DUPLICATE_SAME_ACCESS)) /* Options */
88 {
89 /* TODO: Translate GetLastError () into errno. */
90 errno = EMFILE;
91 result = -1;
92 break;
93 }
94 duplicated_fd = _open_osfhandle ((long) new_handle, flags);
95 if (duplicated_fd < 0)
96 {
97 CloseHandle (new_handle);
98 errno = EMFILE;
99 result = -1;
100 break;
101 }
102 if (newfd <= duplicated_fd)
103 {
104 result = duplicated_fd;
105 break;
106 }
107
108 /* Set the bit duplicated_fd in fds_to_close[]. */
109 index = (unsigned int) duplicated_fd / CHAR_BIT;
110 if (fds_to_close_bound <= index)
111 {
112 if (sizeof fds_to_close <= index)
113 /* Need to increase OPEN_MAX_MAX. */
114 abort ();
115 memset (fds_to_close + fds_to_close_bound, '\0',
116 index + 1 - fds_to_close_bound);
117 fds_to_close_bound = index + 1;
118 }
119 fds_to_close[index] |= 1 << ((unsigned int) duplicated_fd % CHAR_BIT);
120 }
121
122 /* Close the previous fds that turned out to be too small. */
123 {
124 int saved_errno = errno;
125 unsigned int duplicated_fd;
126
127 for (duplicated_fd = 0;
128 duplicated_fd < fds_to_close_bound * CHAR_BIT;
129 duplicated_fd++)
130 if ((fds_to_close[duplicated_fd / CHAR_BIT]
131 >> (duplicated_fd % CHAR_BIT))
132 & 1)
133 close (duplicated_fd);
134
135 errno = saved_errno;
136 }
137
138# if REPLACE_FCHDIR
139 if (0 <= result)
140 result = _gl_register_dup (oldfd, result);
141# endif
142 return result;
143}
144#endif /* W32 */
145
146/* Perform the specified ACTION on the file descriptor FD, possibly
147 using the argument ARG further described below. This replacement
148 handles the following actions, and forwards all others on to the
149 native fcntl. An unrecognized ACTION returns -1 with errno set to
150 EINVAL.
151
152 F_DUPFD - duplicate FD, with int ARG being the minimum target fd.
153 If successful, return the duplicate, which will be inheritable;
154 otherwise return -1 and set errno.
155
156 F_DUPFD_CLOEXEC - duplicate FD, with int ARG being the minimum
157 target fd. If successful, return the duplicate, which will not be
158 inheritable; otherwise return -1 and set errno.
159
160 F_GETFD - ARG need not be present. If successful, return a
161 non-negative value containing the descriptor flags of FD (only
162 FD_CLOEXEC is portable, but other flags may be present); otherwise
163 return -1 and set errno. */
164
165int
166rpl_fcntl (int fd, int action, /* arg */...)
167{
168 va_list arg;
169 int result = -1;
170 va_start (arg, action);
171 switch (action)
172 {
173
174#if !HAVE_FCNTL
175 case F_DUPFD:
176 {
177 int target = va_arg (arg, int);
178 result = dupfd (fd, target, 0);
179 break;
180 }
181#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
182 case F_DUPFD:
183 {
184 int target = va_arg (arg, int);
185 /* Detect invalid target; needed for cygwin 1.5.x. */
186 if (target < 0 || getdtablesize () <= target)
187 errno = EINVAL;
188 else
189 {
190 result = fcntl (fd, action, target);
191# if REPLACE_FCHDIR
192 if (0 <= result)
193 result = _gl_register_dup (fd, result);
194# endif
195 }
196 break;
197 } /* F_DUPFD */
198#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */
199
200 case F_DUPFD_CLOEXEC:
201 {
202 int target = va_arg (arg, int);
203
204#if !HAVE_FCNTL
205 result = dupfd (fd, target, O_CLOEXEC);
206 break;
207#else /* HAVE_FCNTL */
208 /* Try the system call first, if the headers claim it exists
209 (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
210 may be running with a glibc that has the macro but with an
211 older kernel that does not support it. Cache the
212 information on whether the system call really works, but
213 avoid caching failure if the corresponding F_DUPFD fails
214 for any reason. 0 = unknown, 1 = yes, -1 = no. */
215 static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
216 if (0 <= have_dupfd_cloexec)
217 {
218 result = fcntl (fd, action, target);
219 if (0 <= result || errno != EINVAL)
220 {
221 have_dupfd_cloexec = 1;
222# if REPLACE_FCHDIR
223 if (0 <= result)
224 result = _gl_register_dup (fd, result);
225# endif
226 }
227 else
228 {
229 result = rpl_fcntl (fd, F_DUPFD, target);
230 if (result < 0)
231 break;
232 have_dupfd_cloexec = -1;
233 }
234 }
235 else
236 result = rpl_fcntl (fd, F_DUPFD, target);
237 if (0 <= result && have_dupfd_cloexec == -1)
238 {
239 int flags = fcntl (result, F_GETFD);
240 if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
241 {
242 int saved_errno = errno;
243 close (result);
244 errno = saved_errno;
245 result = -1;
246 }
247 }
248 break;
249#endif /* HAVE_FCNTL */
250 } /* F_DUPFD_CLOEXEC */
251
252#if !HAVE_FCNTL
253 case F_GETFD:
254 {
255# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
256 HANDLE handle = (HANDLE) _get_osfhandle (fd);
257 DWORD flags;
258 if (handle == INVALID_HANDLE_VALUE
259 || GetHandleInformation (handle, &flags) == 0)
260 errno = EBADF;
261 else
262 result = (flags & HANDLE_FLAG_INHERIT) ? 0 : FD_CLOEXEC;
263# else /* !W32 */
264 /* Use dup2 to reject invalid file descriptors. No way to
265 access this information, so punt. */
266 if (0 <= dup2 (fd, fd))
267 result = 0;
268# endif /* !W32 */
269 break;
270 } /* F_GETFD */
271#endif /* !HAVE_FCNTL */
272
273 /* Implementing F_SETFD on mingw is not trivial - there is no
274 API for changing the O_NOINHERIT bit on an fd, and merely
275 changing the HANDLE_FLAG_INHERIT bit on the underlying handle
276 can lead to odd state. It may be possible by duplicating the
277 handle, using _open_osfhandle with the right flags, then
278 using dup2 to move the duplicate onto the original, but that
279 is not supported for now. */
280
281 default:
282 {
283#if HAVE_FCNTL
284 void *p = va_arg (arg, void *);
285 result = fcntl (fd, action, p);
286#else
287 errno = EINVAL;
288#endif
289 break;
290 }
291 }
292 va_end (arg);
293 return result;
294}
diff --git a/gl/fcntl.in.h b/gl/fcntl.in.h
index fd7520e8..8fb78522 100644
--- a/gl/fcntl.in.h
+++ b/gl/fcntl.in.h
@@ -1,6 +1,6 @@
1/* Like <fcntl.h>, but with non-working flags defined to 0. 1/* Like <fcntl.h>, but with non-working flags defined to 0.
2 2
3 Copyright (C) 2006-2008 Free Software Foundation, Inc. 3 Copyright (C) 2006-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -25,8 +25,9 @@
25/* Special invocation convention. */ 25/* Special invocation convention. */
26 26
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
29#include <unistd.h> 29# include <sys/stat.h>
30#endif
30#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ 31#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
31 32
32#else 33#else
@@ -35,38 +36,126 @@
35#ifndef _GL_FCNTL_H 36#ifndef _GL_FCNTL_H
36 37
37#include <sys/types.h> 38#include <sys/types.h>
38#include <sys/stat.h> 39#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
39#include <unistd.h> 40# include <sys/stat.h>
41#endif
40/* The include_next requires a split double-inclusion guard. */ 42/* The include_next requires a split double-inclusion guard. */
41#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ 43#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
42 44
43#ifndef _GL_FCNTL_H 45#ifndef _GL_FCNTL_H
44#define _GL_FCNTL_H 46#define _GL_FCNTL_H
45 47
48#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
49# include <unistd.h>
50#endif
51
52
53/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
54
55/* The definition of _GL_ARG_NONNULL is copied here. */
56
57/* The definition of _GL_WARN_ON_USE is copied here. */
58
46 59
47/* Declare overridden functions. */ 60/* Declare overridden functions. */
48 61
49#ifdef __cplusplus 62#if @GNULIB_FCNTL@
50extern "C" { 63# if @REPLACE_FCNTL@
64# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
65# undef fcntl
66# define fcntl rpl_fcntl
67# endif
68_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
69_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
70# else
71# if !@HAVE_FCNTL@
72_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
73# endif
74_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
75# endif
76_GL_CXXALIASWARN (fcntl);
77#elif defined GNULIB_POSIXCHECK
78# undef fcntl
79# if HAVE_RAW_DECL_FCNTL
80_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
81 "use gnulib module fcntl for portability");
82# endif
51#endif 83#endif
52 84
53#if @GNULIB_OPEN@ 85#if @GNULIB_OPEN@
54# if @REPLACE_OPEN@ 86# if @REPLACE_OPEN@
55# undef open 87# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
56# define open rpl_open 88# undef open
57extern int open (const char *filename, int flags, ...); 89# define open rpl_open
90# endif
91_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
92 _GL_ARG_NONNULL ((1)));
93_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
94# else
95_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
58# endif 96# endif
97_GL_CXXALIASWARN (open);
98#elif defined GNULIB_POSIXCHECK
99# undef open
100/* Assume open is always declared. */
101_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
102 "use gnulib module open for portability");
59#endif 103#endif
60 104
61#ifdef FCHDIR_REPLACEMENT 105#if @GNULIB_OPENAT@
62/* gnulib internal function. */ 106# if @REPLACE_OPENAT@
63extern void _gl_register_fd (int fd, const char *filename); 107# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
108# undef openat
109# define openat rpl_openat
110# endif
111_GL_FUNCDECL_RPL (openat, int,
112 (int fd, char const *file, int flags, /* mode_t mode */ ...)
113 _GL_ARG_NONNULL ((2)));
114_GL_CXXALIAS_RPL (openat, int,
115 (int fd, char const *file, int flags, /* mode_t mode */ ...));
116# else
117# if !@HAVE_OPENAT@
118_GL_FUNCDECL_SYS (openat, int,
119 (int fd, char const *file, int flags, /* mode_t mode */ ...)
120 _GL_ARG_NONNULL ((2)));
121# endif
122_GL_CXXALIAS_SYS (openat, int,
123 (int fd, char const *file, int flags, /* mode_t mode */ ...));
124# endif
125_GL_CXXALIASWARN (openat);
126#elif defined GNULIB_POSIXCHECK
127# undef openat
128# if HAVE_RAW_DECL_OPENAT
129_GL_WARN_ON_USE (openat, "openat is not portable - "
130 "use gnulib module openat for portability");
131# endif
132#endif
133
134
135/* Fix up the FD_* macros, only known to be missing on mingw. */
136
137#ifndef FD_CLOEXEC
138# define FD_CLOEXEC 1
139#endif
140
141/* Fix up the supported F_* macros. Intentionally leave other F_*
142 macros undefined. Only known to be missing on mingw. */
143
144#ifndef F_DUPFD_CLOEXEC
145# define F_DUPFD_CLOEXEC 0x40000000
146/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
147# define GNULIB_defined_F_DUPFD_CLOEXEC 1
148#else
149# define GNULIB_defined_F_DUPFD_CLOEXEC 0
64#endif 150#endif
65 151
66#ifdef __cplusplus 152#ifndef F_DUPFD
67} 153# define F_DUPFD 1
68#endif 154#endif
69 155
156#ifndef F_GETFD
157# define F_GETFD 2
158#endif
70 159
71/* Fix up the O_* macros. */ 160/* Fix up the O_* macros. */
72 161
@@ -75,6 +164,12 @@ extern void _gl_register_fd (int fd, const char *filename);
75# define O_DIRECT O_DIRECTIO 164# define O_DIRECT O_DIRECTIO
76#endif 165#endif
77 166
167#if !defined O_CLOEXEC && defined O_NOINHERIT
168/* Mingw spells it `O_NOINHERIT'. Intentionally leave it
169 undefined if not available. */
170# define O_CLOEXEC O_NOINHERIT
171#endif
172
78#ifndef O_DIRECT 173#ifndef O_DIRECT
79# define O_DIRECT 0 174# define O_DIRECT 0
80#endif 175#endif
@@ -119,6 +214,10 @@ extern void _gl_register_fd (int fd, const char *filename);
119# define O_SYNC 0 214# define O_SYNC 0
120#endif 215#endif
121 216
217#ifndef O_TTY_INIT
218# define O_TTY_INIT 0
219#endif
220
122/* For systems that distinguish between text and binary I/O. 221/* For systems that distinguish between text and binary I/O.
123 O_BINARY is usually declared in fcntl.h */ 222 O_BINARY is usually declared in fcntl.h */
124#if !defined O_BINARY && defined _O_BINARY 223#if !defined O_BINARY && defined _O_BINARY
@@ -138,6 +237,42 @@ extern void _gl_register_fd (int fd, const char *filename);
138# define O_TEXT 0 237# define O_TEXT 0
139#endif 238#endif
140 239
240/* Fix up the AT_* macros. */
241
242/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
243 value exceeds INT_MAX, so its use as an int doesn't conform to the
244 C standard, and GCC and Sun C complain in some cases. If the bug
245 is present, undef AT_FDCWD here, so it can be redefined below. */
246#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
247# undef AT_FDCWD
248#endif
249
250/* Use the same bit pattern as Solaris 9, but with the proper
251 signedness. The bit pattern is important, in case this actually is
252 Solaris with the above workaround. */
253#ifndef AT_FDCWD
254# define AT_FDCWD (-3041965)
255#endif
256
257/* Use the same values as Solaris 9. This shouldn't matter, but
258 there's no real reason to differ. */
259#ifndef AT_SYMLINK_NOFOLLOW
260# define AT_SYMLINK_NOFOLLOW 4096
261#endif
262
263#ifndef AT_REMOVEDIR
264# define AT_REMOVEDIR 1
265#endif
266
267/* Solaris 9 lacks these two, so just pick unique values. */
268#ifndef AT_SYMLINK_FOLLOW
269# define AT_SYMLINK_FOLLOW 2
270#endif
271
272#ifndef AT_EACCESS
273# define AT_EACCESS 4
274#endif
275
141 276
142#endif /* _GL_FCNTL_H */ 277#endif /* _GL_FCNTL_H */
143#endif /* _GL_FCNTL_H */ 278#endif /* _GL_FCNTL_H */
diff --git a/gl/fd-safer.c b/gl/fd-safer.c
index fb990018..c1c60005 100644
--- a/gl/fd-safer.c
+++ b/gl/fd-safer.c
@@ -1,6 +1,6 @@
1/* Return a safer copy of a file descriptor. 1/* Return a safer copy of a file descriptor.
2 2
3 Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@
22#include "unistd-safer.h" 22#include "unistd-safer.h"
23 23
24#include <errno.h> 24#include <errno.h>
25
26#include <unistd.h> 25#include <unistd.h>
27 26
28/* Return FD, unless FD would be a copy of standard input, output, or 27/* Return FD, unless FD would be a copy of standard input, output, or
diff --git a/gl/float+.h b/gl/float+.h
index 240fe365..b55e5e6d 100644
--- a/gl/float+.h
+++ b/gl/float+.h
@@ -1,5 +1,5 @@
1/* Supplemental information about the floating-point formats. 1/* Supplemental information about the floating-point formats.
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2007. 3 Written by Bruno Haible <bruno@clisp.org>, 2007.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
diff --git a/gl/float.in.h b/gl/float.in.h
index 9ba2bce4..caf822f1 100644
--- a/gl/float.in.h
+++ b/gl/float.in.h
@@ -1,6 +1,6 @@
1/* A correct <float.h>. 1/* A correct <float.h>.
2 2
3 Copyright (C) 2007-2008 Free Software Foundation, Inc. 3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/floor.c b/gl/floor.c
index 05a6591a..593b5268 100644
--- a/gl/floor.c
+++ b/gl/floor.c
@@ -1,5 +1,5 @@
1/* Round towards negative infinity. 1/* Round towards negative infinity.
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -67,27 +67,27 @@ FUNC (DOUBLE x)
67 { 67 {
68 /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ 68 /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */
69 if (z < TWO_MANT_DIG) 69 if (z < TWO_MANT_DIG)
70 { 70 {
71 /* Round to the next integer (nearest or up or down, doesn't matter). */ 71 /* Round to the next integer (nearest or up or down, doesn't matter). */
72 z += TWO_MANT_DIG; 72 z += TWO_MANT_DIG;
73 z -= TWO_MANT_DIG; 73 z -= TWO_MANT_DIG;
74 /* Enforce rounding down. */ 74 /* Enforce rounding down. */
75 if (z > y) 75 if (z > y)
76 z -= L_(1.0); 76 z -= L_(1.0);
77 } 77 }
78 } 78 }
79 else if (z < L_(0.0)) 79 else if (z < L_(0.0))
80 { 80 {
81 /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ 81 /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */
82 if (z > - TWO_MANT_DIG) 82 if (z > - TWO_MANT_DIG)
83 { 83 {
84 /* Round to the next integer (nearest or up or down, doesn't matter). */ 84 /* Round to the next integer (nearest or up or down, doesn't matter). */
85 z -= TWO_MANT_DIG; 85 z -= TWO_MANT_DIG;
86 z += TWO_MANT_DIG; 86 z += TWO_MANT_DIG;
87 /* Enforce rounding down. */ 87 /* Enforce rounding down. */
88 if (z > y) 88 if (z > y)
89 z -= L_(1.0); 89 z -= L_(1.0);
90 } 90 }
91 } 91 }
92 return z; 92 return z;
93} 93}
diff --git a/gl/floorf.c b/gl/floorf.c
index f0aff338..eae57934 100644
--- a/gl/floorf.c
+++ b/gl/floorf.c
@@ -1,5 +1,5 @@
1/* Round towards negative infinity. 1/* Round towards negative infinity.
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/fsusage.c b/gl/fsusage.c
index db0d3bc5..10db467d 100644
--- a/gl/fsusage.c
+++ b/gl/fsusage.c
@@ -1,7 +1,7 @@
1/* fsusage.c -- return space usage of mounted file systems 1/* fsusage.c -- return space usage of mounted file systems
2 2
3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009 3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2010 Free Software
4 Free Software Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 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 7 it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
23#include <limits.h> 23#include <limits.h>
24#include <sys/types.h> 24#include <sys/types.h>
25 25
26#if STAT_STATVFS /* POSIX 1003.1-2001 (and later) with XSI */ 26#if STAT_STATVFS /* POSIX 1003.1-2001 (and later) with XSI */
27# include <sys/statvfs.h> 27# include <sys/statvfs.h>
28#else 28#else
29/* Don't include backward-compatibility files unless they're needed. 29/* Don't include backward-compatibility files unless they're needed.
@@ -40,16 +40,16 @@
40# if HAVE_SYS_VFS_H 40# if HAVE_SYS_VFS_H
41# include <sys/vfs.h> 41# include <sys/vfs.h>
42# endif 42# endif
43# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ 43# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */
44# include <sys/fs/s5param.h> 44# include <sys/fs/s5param.h>
45# endif 45# endif
46# if defined HAVE_SYS_FILSYS_H && !defined _CRAY 46# if defined HAVE_SYS_FILSYS_H && !defined _CRAY
47# include <sys/filsys.h> /* SVR2 */ 47# include <sys/filsys.h> /* SVR2 */
48# endif 48# endif
49# if HAVE_SYS_STATFS_H 49# if HAVE_SYS_STATFS_H
50# include <sys/statfs.h> 50# include <sys/statfs.h>
51# endif 51# endif
52# if HAVE_DUSTAT_H /* AIX PS/2 */ 52# if HAVE_DUSTAT_H /* AIX PS/2 */
53# include <sys/dustat.h> 53# include <sys/dustat.h>
54# endif 54# endif
55# include "full-read.h" 55# include "full-read.h"
@@ -67,13 +67,13 @@
67#define PROPAGATE_ALL_ONES(x) \ 67#define PROPAGATE_ALL_ONES(x) \
68 ((sizeof (x) < sizeof (uintmax_t) \ 68 ((sizeof (x) < sizeof (uintmax_t) \
69 && (~ (x) == (sizeof (x) < sizeof (int) \ 69 && (~ (x) == (sizeof (x) < sizeof (int) \
70 ? - (1 << (sizeof (x) * CHAR_BIT)) \ 70 ? - (1 << (sizeof (x) * CHAR_BIT)) \
71 : 0))) \ 71 : 0))) \
72 ? UINTMAX_MAX : (uintmax_t) (x)) 72 ? UINTMAX_MAX : (uintmax_t) (x))
73 73
74/* Extract the top bit of X as an uintmax_t value. */ 74/* Extract the top bit of X as an uintmax_t value. */
75#define EXTRACT_TOP_BIT(x) ((x) \ 75#define EXTRACT_TOP_BIT(x) ((x) \
76 & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1))) 76 & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1)))
77 77
78/* If a value is negative, many space usage primitives store it into an 78/* If a value is negative, many space usage primitives store it into an
79 integer variable by assignment, even if the variable's type is unsigned. 79 integer variable by assignment, even if the variable's type is unsigned.
@@ -94,7 +94,7 @@
94int 94int
95get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) 95get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
96{ 96{
97#if defined STAT_STATVFS /* POSIX */ 97#if defined STAT_STATVFS /* POSIX */
98 98
99 struct statvfs fsd; 99 struct statvfs fsd;
100 100
@@ -103,10 +103,10 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
103 103
104 /* f_frsize isn't guaranteed to be supported. */ 104 /* f_frsize isn't guaranteed to be supported. */
105 fsp->fsu_blocksize = (fsd.f_frsize 105 fsp->fsu_blocksize = (fsd.f_frsize
106 ? PROPAGATE_ALL_ONES (fsd.f_frsize) 106 ? PROPAGATE_ALL_ONES (fsd.f_frsize)
107 : PROPAGATE_ALL_ONES (fsd.f_bsize)); 107 : PROPAGATE_ALL_ONES (fsd.f_bsize));
108 108
109#elif defined STAT_STATFS2_FS_DATA /* Ultrix */ 109#elif defined STAT_STATFS2_FS_DATA /* Ultrix */
110 110
111 struct fs_data fsd; 111 struct fs_data fsd;
112 112
@@ -121,7 +121,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
121 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); 121 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot);
122 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); 122 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
123 123
124#elif defined STAT_READ_FILSYS /* SVR2 */ 124#elif defined STAT_READ_FILSYS /* SVR2 */
125# ifndef SUPERBOFF 125# ifndef SUPERBOFF
126# define SUPERBOFF (SUPERB * 512) 126# define SUPERBOFF (SUPERB * 512)
127# endif 127# endif
@@ -152,8 +152,8 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
152 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree); 152 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree);
153 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0; 153 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0;
154 fsp->fsu_files = (fsd.s_isize == -1 154 fsp->fsu_files = (fsd.s_isize == -1
155 ? UINTMAX_MAX 155 ? UINTMAX_MAX
156 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); 156 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
157 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); 157 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
158 158
159#elif defined STAT_STATFS3_OSF1 159#elif defined STAT_STATFS3_OSF1
@@ -165,7 +165,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
165 165
166 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 166 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
167 167
168#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ 168#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
169 169
170 struct statfs fsd; 170 struct statfs fsd;
171 171
@@ -189,7 +189,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
189 } 189 }
190# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ 190# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
191 191
192#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */ 192#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */
193 193
194 struct statfs fsd; 194 struct statfs fsd;
195 195
@@ -198,7 +198,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
198 198
199 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 199 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
200 200
201#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ 201#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
202 202
203# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN 203# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN
204# define f_bavail f_bfree 204# define f_bavail f_bfree
diff --git a/gl/fsusage.h b/gl/fsusage.h
index b32abe18..bb2d86f1 100644
--- a/gl/fsusage.h
+++ b/gl/fsusage.h
@@ -1,6 +1,6 @@
1/* fsusage.h -- declarations for file system space usage info 1/* fsusage.h -- declarations for file system space usage info
2 2
3 Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005, 2006 Free Software 3 Copyright (C) 1991-1992, 1997, 2003-2006, 2009-2010 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This program is free software: you can redistribute it and/or modify
@@ -26,13 +26,13 @@
26 26
27struct fs_usage 27struct fs_usage
28{ 28{
29 uintmax_t fsu_blocksize; /* Size of a block. */ 29 uintmax_t fsu_blocksize; /* Size of a block. */
30 uintmax_t fsu_blocks; /* Total blocks. */ 30 uintmax_t fsu_blocks; /* Total blocks. */
31 uintmax_t fsu_bfree; /* Free blocks available to superuser. */ 31 uintmax_t fsu_bfree; /* Free blocks available to superuser. */
32 uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ 32 uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */
33 bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ 33 bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */
34 uintmax_t fsu_files; /* Total file nodes. */ 34 uintmax_t fsu_files; /* Total file nodes. */
35 uintmax_t fsu_ffree; /* Free file nodes. */ 35 uintmax_t fsu_ffree; /* Free file nodes. */
36}; 36};
37 37
38int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); 38int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp);
diff --git a/gl/full-read.c b/gl/full-read.c
index fb7212bb..e5de3760 100644
--- a/gl/full-read.c
+++ b/gl/full-read.c
@@ -1,5 +1,5 @@
1/* An interface to read that retries after partial reads and interrupts. 1/* An interface to read that retries after partial reads and interrupts.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc. 2 Copyright (C) 2002-2003, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/full-read.h b/gl/full-read.h
index a341ee00..a41f617c 100644
--- a/gl/full-read.h
+++ b/gl/full-read.h
@@ -1,6 +1,6 @@
1/* An interface to read() that reads all it is asked to read. 1/* An interface to read() that reads all it is asked to read.
2 2
3 Copyright (C) 2002 Free Software Foundation, Inc. 3 Copyright (C) 2002, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/full-write.c b/gl/full-write.c
index 51f2d381..5d9b7c33 100644
--- a/gl/full-write.c
+++ b/gl/full-write.c
@@ -1,7 +1,6 @@
1/* An interface to read and write that retries (if necessary) until complete. 1/* An interface to read and write that retries (if necessary) until complete.
2 2
3 Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3 Copyright (C) 1993-1994, 1997-2006, 2009-2010 Free Software Foundation, Inc.
4 2004, 2005, 2006 Free Software Foundation, Inc.
5 4
6 This program is free software: you can redistribute it and/or modify 5 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 6 it under the terms of the GNU General Public License as published by
@@ -65,12 +64,12 @@ full_rw (int fd, const void *buf, size_t count)
65 { 64 {
66 size_t n_rw = safe_rw (fd, ptr, count); 65 size_t n_rw = safe_rw (fd, ptr, count);
67 if (n_rw == (size_t) -1) 66 if (n_rw == (size_t) -1)
68 break; 67 break;
69 if (n_rw == 0) 68 if (n_rw == 0)
70 { 69 {
71 errno = ZERO_BYTE_TRANSFER_ERRNO; 70 errno = ZERO_BYTE_TRANSFER_ERRNO;
72 break; 71 break;
73 } 72 }
74 total += n_rw; 73 total += n_rw;
75 ptr += n_rw; 74 ptr += n_rw;
76 count -= n_rw; 75 count -= n_rw;
diff --git a/gl/full-write.h b/gl/full-write.h
index 9a801464..15d61808 100644
--- a/gl/full-write.h
+++ b/gl/full-write.h
@@ -1,6 +1,6 @@
1/* An interface to write() that writes all it is asked to write. 1/* An interface to write() that writes all it is asked to write.
2 2
3 Copyright (C) 2002-2003 Free Software Foundation, Inc. 3 Copyright (C) 2002-2003, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c
index afbcdbb4..c05b5c47 100644
--- a/gl/gai_strerror.c
+++ b/gl/gai_strerror.c
@@ -1,4 +1,5 @@
1/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc. 1/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008, 2009, 2010 Free
2 Software Foundation, Inc.
2 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
3 Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997. 4 Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
4 5
diff --git a/gl/getaddrinfo.c b/gl/getaddrinfo.c
index f09cf9ee..6aa676c8 100644
--- a/gl/getaddrinfo.c
+++ b/gl/getaddrinfo.c
@@ -1,6 +1,5 @@
1/* Get address information (partial implementation). 1/* Get address information (partial implementation).
2 Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software 2 Copyright (C) 1997, 2001-2002, 2004-2010 Free Software Foundation, Inc.
3 Foundation, Inc.
4 Contributed by Simon Josefsson <simon@josefsson.org>. 3 Contributed by Simon Josefsson <simon@josefsson.org>.
5 4
6 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
@@ -19,6 +18,10 @@
19 18
20#include <config.h> 19#include <config.h>
21 20
21/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
22 optimizes away the sa == NULL test below. */
23#define _GL_ARG_NONNULL(params)
24
22#include <netdb.h> 25#include <netdb.h>
23 26
24#if HAVE_NETINET_IN_H 27#if HAVE_NETINET_IN_H
@@ -58,12 +61,12 @@
58 61
59#ifdef WIN32_NATIVE 62#ifdef WIN32_NATIVE
60typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, 63typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
61 const struct addrinfo*, 64 const struct addrinfo*,
62 struct addrinfo**); 65 struct addrinfo**);
63typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*); 66typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*);
64typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*, 67typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*,
65 socklen_t, char*, DWORD, 68 socklen_t, char*, DWORD,
66 char*, DWORD, int); 69 char*, DWORD, int);
67 70
68static getaddrinfo_func getaddrinfo_ptr = NULL; 71static getaddrinfo_func getaddrinfo_ptr = NULL;
69static freeaddrinfo_func freeaddrinfo_ptr = NULL; 72static freeaddrinfo_func freeaddrinfo_ptr = NULL;
@@ -123,9 +126,9 @@ validate_family (int family)
123 socket addresses. */ 126 socket addresses. */
124int 127int
125getaddrinfo (const char *restrict nodename, 128getaddrinfo (const char *restrict nodename,
126 const char *restrict servname, 129 const char *restrict servname,
127 const struct addrinfo *restrict hints, 130 const struct addrinfo *restrict hints,
128 struct addrinfo **restrict res) 131 struct addrinfo **restrict res)
129{ 132{
130 struct addrinfo *tmp; 133 struct addrinfo *tmp;
131 int port = 0; 134 int port = 0;
@@ -165,7 +168,7 @@ getaddrinfo (const char *restrict nodename,
165 if (!nodename) 168 if (!nodename)
166 { 169 {
167 if (!(hints->ai_flags & AI_PASSIVE)) 170 if (!(hints->ai_flags & AI_PASSIVE))
168 return EAI_NONAME; 171 return EAI_NONAME;
169 172
170#ifdef HAVE_IPV6 173#ifdef HAVE_IPV6
171 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; 174 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0";
@@ -178,24 +181,24 @@ getaddrinfo (const char *restrict nodename,
178 { 181 {
179 struct servent *se = NULL; 182 struct servent *se = NULL;
180 const char *proto = 183 const char *proto =
181 (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; 184 (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
182 185
183 if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV)) 186 if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV))
184 /* FIXME: Use getservbyname_r if available. */ 187 /* FIXME: Use getservbyname_r if available. */
185 se = getservbyname (servname, proto); 188 se = getservbyname (servname, proto);
186 189
187 if (!se) 190 if (!se)
188 { 191 {
189 char *c; 192 char *c;
190 if (!(*servname >= '0' && *servname <= '9')) 193 if (!(*servname >= '0' && *servname <= '9'))
191 return EAI_NONAME; 194 return EAI_NONAME;
192 port = strtoul (servname, &c, 10); 195 port = strtoul (servname, &c, 10);
193 if (*c || port > 0xffff) 196 if (*c || port > 0xffff)
194 return EAI_NONAME; 197 return EAI_NONAME;
195 port = htons (port); 198 port = htons (port);
196 } 199 }
197 else 200 else
198 port = se->s_port; 201 port = se->s_port;
199 } 202 }
200 203
201 /* FIXME: Use gethostbyname_r if available. */ 204 /* FIXME: Use gethostbyname_r if available. */
@@ -230,23 +233,23 @@ getaddrinfo (const char *restrict nodename,
230#if HAVE_IPV6 233#if HAVE_IPV6
231 case PF_INET6: 234 case PF_INET6:
232 { 235 {
233 struct v6_pair *p = storage; 236 struct v6_pair *p = storage;
234 struct sockaddr_in6 *sinp = &p->sockaddr_in6; 237 struct sockaddr_in6 *sinp = &p->sockaddr_in6;
235 tmp = &p->addrinfo; 238 tmp = &p->addrinfo;
236 239
237 if (port) 240 if (port)
238 sinp->sin6_port = port; 241 sinp->sin6_port = port;
239 242
240 if (he->h_length != sizeof (sinp->sin6_addr)) 243 if (he->h_length != sizeof (sinp->sin6_addr))
241 { 244 {
242 free (storage); 245 free (storage);
243 return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ 246 return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */
244 } 247 }
245 248
246 memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); 249 memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr);
247 250
248 tmp->ai_addr = (struct sockaddr *) sinp; 251 tmp->ai_addr = (struct sockaddr *) sinp;
249 tmp->ai_addrlen = sizeof *sinp; 252 tmp->ai_addrlen = sizeof *sinp;
250 } 253 }
251 break; 254 break;
252#endif 255#endif
@@ -254,23 +257,23 @@ getaddrinfo (const char *restrict nodename,
254#if HAVE_IPV4 257#if HAVE_IPV4
255 case PF_INET: 258 case PF_INET:
256 { 259 {
257 struct v4_pair *p = storage; 260 struct v4_pair *p = storage;
258 struct sockaddr_in *sinp = &p->sockaddr_in; 261 struct sockaddr_in *sinp = &p->sockaddr_in;
259 tmp = &p->addrinfo; 262 tmp = &p->addrinfo;
260 263
261 if (port) 264 if (port)
262 sinp->sin_port = port; 265 sinp->sin_port = port;
263 266
264 if (he->h_length != sizeof (sinp->sin_addr)) 267 if (he->h_length != sizeof (sinp->sin_addr))
265 { 268 {
266 free (storage); 269 free (storage);
267 return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ 270 return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */
268 } 271 }
269 272
270 memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); 273 memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr);
271 274
272 tmp->ai_addr = (struct sockaddr *) sinp; 275 tmp->ai_addr = (struct sockaddr *) sinp;
273 tmp->ai_addrlen = sizeof *sinp; 276 tmp->ai_addrlen = sizeof *sinp;
274 } 277 }
275 break; 278 break;
276#endif 279#endif
@@ -284,16 +287,16 @@ getaddrinfo (const char *restrict nodename,
284 { 287 {
285 const char *cn; 288 const char *cn;
286 if (he->h_name) 289 if (he->h_name)
287 cn = he->h_name; 290 cn = he->h_name;
288 else 291 else
289 cn = nodename; 292 cn = nodename;
290 293
291 tmp->ai_canonname = strdup (cn); 294 tmp->ai_canonname = strdup (cn);
292 if (!tmp->ai_canonname) 295 if (!tmp->ai_canonname)
293 { 296 {
294 free (storage); 297 free (storage);
295 return EAI_MEMORY; 298 return EAI_MEMORY;
296 } 299 }
297 } 300 }
298 301
299 tmp->ai_protocol = (hints) ? hints->ai_protocol : 0; 302 tmp->ai_protocol = (hints) ? hints->ai_protocol : 0;
@@ -348,15 +351,16 @@ freeaddrinfo (struct addrinfo *ai)
348 } 351 }
349} 352}
350 353
351int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, 354int
352 char *restrict node, socklen_t nodelen, 355getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
353 char *restrict service, socklen_t servicelen, 356 char *restrict node, socklen_t nodelen,
354 int flags) 357 char *restrict service, socklen_t servicelen,
358 int flags)
355{ 359{
356#ifdef WIN32_NATIVE 360#ifdef WIN32_NATIVE
357 if (use_win32_p ()) 361 if (use_win32_p ())
358 return getnameinfo_ptr (sa, salen, node, nodelen, 362 return getnameinfo_ptr (sa, salen, node, nodelen,
359 service, servicelen, flags); 363 service, servicelen, flags);
360#endif 364#endif
361 365
362 /* FIXME: Support other flags. */ 366 /* FIXME: Support other flags. */
@@ -373,13 +377,13 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
373#if HAVE_IPV4 377#if HAVE_IPV4
374 case AF_INET: 378 case AF_INET:
375 if (salen < sizeof (struct sockaddr_in)) 379 if (salen < sizeof (struct sockaddr_in))
376 return EAI_FAMILY; 380 return EAI_FAMILY;
377 break; 381 break;
378#endif 382#endif
379#if HAVE_IPV6 383#if HAVE_IPV6
380 case AF_INET6: 384 case AF_INET6:
381 if (salen < sizeof (struct sockaddr_in6)) 385 if (salen < sizeof (struct sockaddr_in6))
382 return EAI_FAMILY; 386 return EAI_FAMILY;
383 break; 387 break;
384#endif 388#endif
385 default: 389 default:
@@ -389,28 +393,28 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
389 if (node && nodelen > 0 && flags & NI_NUMERICHOST) 393 if (node && nodelen > 0 && flags & NI_NUMERICHOST)
390 { 394 {
391 switch (sa->sa_family) 395 switch (sa->sa_family)
392 { 396 {
393#if HAVE_IPV4 397#if HAVE_IPV4
394 case AF_INET: 398 case AF_INET:
395 if (!inet_ntop (AF_INET, 399 if (!inet_ntop (AF_INET,
396 &(((const struct sockaddr_in *) sa)->sin_addr), 400 &(((const struct sockaddr_in *) sa)->sin_addr),
397 node, nodelen)) 401 node, nodelen))
398 return EAI_SYSTEM; 402 return EAI_SYSTEM;
399 break; 403 break;
400#endif 404#endif
401 405
402#if HAVE_IPV6 406#if HAVE_IPV6
403 case AF_INET6: 407 case AF_INET6:
404 if (!inet_ntop (AF_INET6, 408 if (!inet_ntop (AF_INET6,
405 &(((const struct sockaddr_in6 *) sa)->sin6_addr), 409 &(((const struct sockaddr_in6 *) sa)->sin6_addr),
406 node, nodelen)) 410 node, nodelen))
407 return EAI_SYSTEM; 411 return EAI_SYSTEM;
408 break; 412 break;
409#endif 413#endif
410 414
411 default: 415 default:
412 return EAI_FAMILY; 416 return EAI_FAMILY;
413 } 417 }
414 } 418 }
415 419
416 if (service && servicelen > 0 && flags & NI_NUMERICSERV) 420 if (service && servicelen > 0 && flags & NI_NUMERICSERV)
@@ -422,13 +426,13 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
422#if HAVE_IPV6 426#if HAVE_IPV6
423 case AF_INET6: 427 case AF_INET6:
424#endif 428#endif
425 { 429 {
426 unsigned short int port 430 unsigned short int port
427 = ntohs (((const struct sockaddr_in *) sa)->sin_port); 431 = ntohs (((const struct sockaddr_in *) sa)->sin_port);
428 if (servicelen <= snprintf (service, servicelen, "%u", port)) 432 if (servicelen <= snprintf (service, servicelen, "%u", port))
429 return EAI_OVERFLOW; 433 return EAI_OVERFLOW;
430 } 434 }
431 break; 435 break;
432 } 436 }
433 437
434 return 0; 438 return 0;
diff --git a/gl/getdtablesize.c b/gl/getdtablesize.c
new file mode 100644
index 00000000..a565a2de
--- /dev/null
+++ b/gl/getdtablesize.c
@@ -0,0 +1,63 @@
1/* getdtablesize() function for platforms that don't have it.
2 Copyright (C) 2008-2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008.
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/* Specification. */
21#include <unistd.h>
22
23#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
24
25#include <stdio.h>
26
27/* Cache for the previous getdtablesize () result. */
28static int dtablesize;
29
30int
31getdtablesize (void)
32{
33 if (dtablesize == 0)
34 {
35 /* We are looking for the number N such that the valid file descriptors
36 are 0..N-1. It can be obtained through a loop as follows:
37 {
38 int fd;
39 for (fd = 3; fd < 65536; fd++)
40 if (dup2 (0, fd) == -1)
41 break;
42 return fd;
43 }
44 On Windows XP, the result is 2048.
45 The drawback of this loop is that it allocates memory for a libc
46 internal array that is never freed.
47
48 The number N can also be obtained as the upper bound for
49 _getmaxstdio (). _getmaxstdio () returns the maximum number of open
50 FILE objects. The sanity check in _setmaxstdio reveals the maximum
51 number of file descriptors. This too allocates memory, but it is
52 freed when we call _setmaxstdio with the original value. */
53 int orig_max_stdio = _getmaxstdio ();
54 unsigned int bound;
55 for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2)
56 ;
57 _setmaxstdio (orig_max_stdio);
58 dtablesize = bound;
59 }
60 return dtablesize;
61}
62
63#endif
diff --git a/gl/gethostname.c b/gl/gethostname.c
index acff351d..b0da748f 100644
--- a/gl/gethostname.c
+++ b/gl/gethostname.c
@@ -1,6 +1,7 @@
1/* gethostname emulation for SysV and POSIX.1. 1/* gethostname emulation for SysV and POSIX.1.
2 2
3 Copyright (C) 1992, 2003, 2006, 2008 Free Software Foundation, Inc. 3 Copyright (C) 1992, 2003, 2006, 2008, 2009, 2010 Free Software Foundation,
4 Inc.
4 5
5 This program is free software: you can redistribute it and/or modify 6 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 it under the terms of the GNU General Public License as published by
@@ -15,10 +16,14 @@
15 You should have received a copy of the GNU General Public License 16 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 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 18
18/* David MacKenzie <djm@gnu.ai.mit.edu> */ 19/* David MacKenzie <djm@gnu.ai.mit.edu>
20 Windows port by Simon Josefsson <simon@josefsson.org> */
19 21
20#include <config.h> 22#include <config.h>
21 23
24#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
25/* Unix API. */
26
22/* Specification. */ 27/* Specification. */
23#include <unistd.h> 28#include <unistd.h>
24 29
@@ -50,7 +55,51 @@ gethostname (char *name, size_t len)
50 } 55 }
51 strncpy (name, uts.nodename, len); 56 strncpy (name, uts.nodename, len);
52#else 57#else
53 strcpy (name, ""); /* Hardcode your system name if you want. */ 58 strcpy (name, ""); /* Hardcode your system name if you want. */
54#endif 59#endif
55 return 0; 60 return 0;
56} 61}
62
63#else
64/* Native Windows API. Which primitive to choose?
65 - gethostname() requires linking with -lws2_32.
66 - GetComputerName() does not return the right kind of hostname.
67 - GetComputerNameEx(ComputerNameDnsHostname,...) returns the right hostname,
68 but it is hard to use portably:
69 - It requires defining _WIN32_WINNT to at least 0x0500.
70 - With mingw, it also requires
71 "#define GetComputerNameEx GetComputerNameExA".
72 - With older versions of mingw, none of the declarations are present at
73 all, not even of the enum value ComputerNameDnsHostname.
74 So we use gethostname(). Linking with -lws2_32 is the least evil. */
75
76#define WIN32_LEAN_AND_MEAN
77/* Get winsock2.h. */
78#include <unistd.h>
79
80/* Get INT_MAX. */
81#include <limits.h>
82
83/* Get set_winsock_errno. */
84#include "w32sock.h"
85
86#include "sockets.h"
87
88#undef gethostname
89
90int
91rpl_gethostname (char *name, size_t len)
92{
93 int r;
94
95 if (len > INT_MAX)
96 len = INT_MAX;
97 gl_sockets_startup (SOCKETS_1_1);
98 r = gethostname (name, (int) len);
99 if (r < 0)
100 set_winsock_errno ();
101
102 return r;
103}
104
105#endif
diff --git a/gl/getloadavg.c b/gl/getloadavg.c
index 5a4005ce..c6d782b4 100644
--- a/gl/getloadavg.c
+++ b/gl/getloadavg.c
@@ -1,8 +1,7 @@
1/* Get the system load averages. 1/* Get the system load averages.
2 2
3 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 3 Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2010 Free Software
4 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free 4 Foundation, Inc.
5 Software Foundation, Inc.
6 5
7 NOTE: The canonical source of this file is maintained with gnulib. 6 NOTE: The canonical source of this file is maintained with gnulib.
8 Bugs can be reported to bug-gnulib@gnu.org. 7 Bugs can be reported to bug-gnulib@gnu.org.
@@ -22,58 +21,58 @@
22 21
23/* Compile-time symbols that this file uses: 22/* Compile-time symbols that this file uses:
24 23
25 HAVE_PSTAT_GETDYNAMIC Define this if your system has the 24 HAVE_PSTAT_GETDYNAMIC Define this if your system has the
26 pstat_getdynamic function. I think it 25 pstat_getdynamic function. I think it
27 is unique to HPUX9. The best way to get the 26 is unique to HPUX9. The best way to get the
28 definition is through the AC_FUNC_GETLOADAVG 27 definition is through the AC_FUNC_GETLOADAVG
29 macro that comes with autoconf 2.13 or newer. 28 macro that comes with autoconf 2.13 or newer.
30 If that isn't an option, then just put 29 If that isn't an option, then just put
31 AC_CHECK_FUNCS(pstat_getdynamic) in your 30 AC_CHECK_FUNCS(pstat_getdynamic) in your
32 configure.in file. 31 configure.in file.
33 HAVE_LIBPERFSTAT Define this if your system has the 32 HAVE_LIBPERFSTAT Define this if your system has the
34 perfstat_cpu_total function in libperfstat (AIX). 33 perfstat_cpu_total function in libperfstat (AIX).
35 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. 34 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist.
36 KERNEL_FILE Name of the kernel file to nlist. 35 KERNEL_FILE Name of the kernel file to nlist.
37 LDAV_CVT() Scale the load average from the kernel. 36 LDAV_CVT() Scale the load average from the kernel.
38 Returns a double. 37 Returns a double.
39 LDAV_SYMBOL Name of kernel symbol giving load average. 38 LDAV_SYMBOL Name of kernel symbol giving load average.
40 LOAD_AVE_TYPE Type of the load average array in the kernel. 39 LOAD_AVE_TYPE Type of the load average array in the kernel.
41 Must be defined unless one of 40 Must be defined unless one of
42 apollo, DGUX, NeXT, or UMAX is defined; 41 apollo, DGUX, NeXT, or UMAX is defined;
43 or we have libkstat; 42 or we have libkstat;
44 otherwise, no load average is available. 43 otherwise, no load average is available.
45 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults 44 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults
46 to this. 45 to this.
47 NLIST_STRUCT Include nlist.h, not a.out.h, and 46 NLIST_STRUCT Include nlist.h, not a.out.h.
48 the nlist n_name element is a pointer, 47 N_NAME_POINTER The nlist n_name element is a pointer,
49 not an array. 48 not an array.
50 HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'. 49 HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'.
51 LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing 50 LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing
52 load averages. 51 load averages.
53 52
54 Specific system predefines this file uses, aside from setting 53 Specific system predefines this file uses, aside from setting
55 default values if not emacs: 54 default values if not emacs:
56 55
57 apollo 56 apollo
58 BSD Real BSD, not just BSD-like. 57 BSD Real BSD, not just BSD-like.
59 convex 58 convex
60 DGUX 59 DGUX
61 eunice UNIX emulator under VMS. 60 eunice UNIX emulator under VMS.
62 hpux 61 hpux
63 __MSDOS__ No-op for MSDOS. 62 __MSDOS__ No-op for MSDOS.
64 NeXT 63 NeXT
65 sgi 64 sgi
66 sequent Sequent Dynix 3.x.x (BSD) 65 sequent Sequent Dynix 3.x.x (BSD)
67 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) 66 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV)
68 sony_news NEWS-OS (works at least for 4.1C) 67 sony_news NEWS-OS (works at least for 4.1C)
69 UMAX 68 UMAX
70 UMAX4_3 69 UMAX4_3
71 VMS 70 VMS
72 WINDOWS32 No-op for Windows95/NT. 71 WINDOWS32 No-op for Windows95/NT.
73 __linux__ Linux: assumes /proc file system mounted. 72 __linux__ Linux: assumes /proc file system mounted.
74 Support from Michael K. Johnson. 73 Support from Michael K. Johnson.
75 __CYGWIN__ Cygwin emulates linux /proc/loadavg. 74 __CYGWIN__ Cygwin emulates linux /proc/loadavg.
76 __NetBSD__ NetBSD: assumes /kern file system mounted. 75 __NetBSD__ NetBSD: assumes /kern file system mounted.
77 76
78 In addition, to avoid nesting many #ifdefs, we internally set 77 In addition, to avoid nesting many #ifdefs, we internally set
79 LDAV_DONE to indicate that the load average has been computed. 78 LDAV_DONE to indicate that the load average has been computed.
@@ -112,7 +111,6 @@
112# include "c-strtod.h" 111# include "c-strtod.h"
113# include "cloexec.h" 112# include "cloexec.h"
114# include "intprops.h" 113# include "intprops.h"
115# include "xalloc.h"
116 114
117/* The existing Emacs configuration files define a macro called 115/* The existing Emacs configuration files define a macro called
118 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and 116 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
@@ -203,7 +201,7 @@
203 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine 201 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine
204 that with a couple of other things and we'll have a unique match. */ 202 that with a couple of other things and we'll have a unique match. */
205# if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES) 203# if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES)
206# define tek4300 /* Define by emacs, but not by other users. */ 204# define tek4300 /* Define by emacs, but not by other users. */
207# endif 205# endif
208 206
209 207
@@ -317,7 +315,7 @@
317# define FSCALE 65536.0 315# define FSCALE 65536.0
318# endif 316# endif
319 317
320# endif /* Not FSCALE. */ 318# endif /* Not FSCALE. */
321 319
322# if !defined (LDAV_CVT) && defined (FSCALE) 320# if !defined (LDAV_CVT) && defined (FSCALE)
323# define LDAV_CVT(n) (((double) (n)) / FSCALE) 321# define LDAV_CVT(n) (((double) (n)) / FSCALE)
@@ -478,7 +476,7 @@ static unsigned int samples;
478# endif /* UMAX */ 476# endif /* UMAX */
479 477
480# ifdef DGUX 478# ifdef DGUX
481static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ 479static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
482# endif /* DGUX */ 480# endif /* DGUX */
483 481
484# if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE) 482# if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE)
@@ -507,7 +505,7 @@ static kvm_t *kd;
507int 505int
508getloadavg (double loadavg[], int nelem) 506getloadavg (double loadavg[], int nelem)
509{ 507{
510 int elem = 0; /* Return value. */ 508 int elem = 0; /* Return value. */
511 509
512# ifdef NO_GET_LOAD_AVG 510# ifdef NO_GET_LOAD_AVG
513# define LDAV_DONE 511# define LDAV_DONE
@@ -549,16 +547,16 @@ getloadavg (double loadavg[], int nelem)
549 { 547 {
550 kn = kstat_data_lookup (ksp, "avenrun_5min"); 548 kn = kstat_data_lookup (ksp, "avenrun_5min");
551 if (kn != 0) 549 if (kn != 0)
552 { 550 {
553 loadavg[elem++] = (double) kn->value.ul / FSCALE; 551 loadavg[elem++] = (double) kn->value.ul / FSCALE;
554 552
555 if (nelem >= 3) 553 if (nelem >= 3)
556 { 554 {
557 kn = kstat_data_lookup (ksp, "avenrun_15min"); 555 kn = kstat_data_lookup (ksp, "avenrun_15min");
558 if (kn != 0) 556 if (kn != 0)
559 loadavg[elem++] = (double) kn->value.ul / FSCALE; 557 loadavg[elem++] = (double) kn->value.ul / FSCALE;
560 } 558 }
561 } 559 }
562 } 560 }
563 561
564 kstat_close (kc); 562 kstat_close (kc);
@@ -626,11 +624,11 @@ getloadavg (double loadavg[], int nelem)
626 errno = 0; 624 errno = 0;
627 d = c_strtod (ptr, &endptr); 625 d = c_strtod (ptr, &endptr);
628 if (ptr == endptr || (d == 0 && errno != 0)) 626 if (ptr == endptr || (d == 0 && errno != 0))
629 { 627 {
630 if (elem == 0) 628 if (elem == 0)
631 return -1; 629 return -1;
632 break; 630 break;
633 } 631 }
634 loadavg[elem] = d; 632 loadavg[elem] = d;
635 ptr = endptr; 633 ptr = endptr;
636 } 634 }
@@ -655,8 +653,8 @@ getloadavg (double loadavg[], int nelem)
655 if (fp == NULL) 653 if (fp == NULL)
656 return -1; 654 return -1;
657 count = fscanf (fp, "%lu %lu %lu %lu\n", 655 count = fscanf (fp, "%lu %lu %lu %lu\n",
658 &load_ave[0], &load_ave[1], &load_ave[2], 656 &load_ave[0], &load_ave[1], &load_ave[2],
659 &scale); 657 &scale);
660 (void) fclose (fp); 658 (void) fclose (fp);
661 if (count != 4) 659 if (count != 4)
662 return -1; 660 return -1;
@@ -682,21 +680,21 @@ getloadavg (double loadavg[], int nelem)
682 if (!getloadavg_initialized) 680 if (!getloadavg_initialized)
683 { 681 {
684 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) 682 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS)
685 getloadavg_initialized = true; 683 getloadavg_initialized = true;
686 } 684 }
687 685
688 if (getloadavg_initialized) 686 if (getloadavg_initialized)
689 { 687 {
690 info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 688 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
691 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, 689 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
692 (processor_set_info_t) &info, &info_count) 690 (processor_set_info_t) &info, &info_count)
693 != KERN_SUCCESS) 691 != KERN_SUCCESS)
694 getloadavg_initialized = false; 692 getloadavg_initialized = false;
695 else 693 else
696 { 694 {
697 if (nelem > 0) 695 if (nelem > 0)
698 loadavg[elem++] = (double) info.load_average / LOAD_SCALE; 696 loadavg[elem++] = (double) info.load_average / LOAD_SCALE;
699 } 697 }
700 } 698 }
701 699
702 if (!getloadavg_initialized) 700 if (!getloadavg_initialized)
@@ -728,24 +726,24 @@ getloadavg (double loadavg[], int nelem)
728 desc.sd_size = sizeof conf; 726 desc.sd_size = sizeof conf;
729 727
730 if (inq_stats (1, &desc)) 728 if (inq_stats (1, &desc))
731 return -1; 729 return -1;
732 730
733 c = 0; 731 c = 0;
734 for (i = 0; i < conf.config_maxclass; ++i) 732 for (i = 0; i < conf.config_maxclass; ++i)
735 { 733 {
736 struct class_stats stats; 734 struct class_stats stats;
737 bzero ((char *) &stats, sizeof stats); 735 bzero ((char *) &stats, sizeof stats);
738 736
739 desc.sd_type = CPUTYPE_CLASS; 737 desc.sd_type = CPUTYPE_CLASS;
740 desc.sd_objid = i; 738 desc.sd_objid = i;
741 desc.sd_addr = (char *) &stats; 739 desc.sd_addr = (char *) &stats;
742 desc.sd_size = sizeof stats; 740 desc.sd_size = sizeof stats;
743 741
744 if (inq_stats (1, &desc)) 742 if (inq_stats (1, &desc))
745 return -1; 743 return -1;
746 744
747 c += stats.class_numcpus; 745 c += stats.class_numcpus;
748 } 746 }
749 cpus = c; 747 cpus = c;
750 samples = cpus < 2 ? 3 : (2 * cpus / 3); 748 samples = cpus < 2 ? 3 : (2 * cpus / 3);
751 } 749 }
@@ -766,7 +764,7 @@ getloadavg (double loadavg[], int nelem)
766 { 764 {
767 load += proc_sum_data.ps_nrun[j]; 765 load += proc_sum_data.ps_nrun[j];
768 if (j++ == PS_NRUNSIZE) 766 if (j++ == PS_NRUNSIZE)
769 j = 0; 767 j = 0;
770 } 768 }
771 769
772 if (nelem > 0) 770 if (nelem > 0)
@@ -779,8 +777,8 @@ getloadavg (double loadavg[], int nelem)
779 it's not supposed to fail. The first argument is for no 777 it's not supposed to fail. The first argument is for no
780 apparent reason of type `long int *'. */ 778 apparent reason of type `long int *'. */
781 dg_sys_info ((long int *) &load_info, 779 dg_sys_info ((long int *) &load_info,
782 DG_SYS_INFO_LOAD_INFO_TYPE, 780 DG_SYS_INFO_LOAD_INFO_TYPE,
783 DG_SYS_INFO_LOAD_VERSION_0); 781 DG_SYS_INFO_LOAD_VERSION_0);
784 782
785 if (nelem > 0) 783 if (nelem > 0)
786 loadavg[elem++] = load_info.one_minute; 784 loadavg[elem++] = load_info.one_minute;
@@ -824,7 +822,7 @@ getloadavg (double loadavg[], int nelem)
824 = (load_ave.tl_lscale == 0 822 = (load_ave.tl_lscale == 0
825 ? load_ave.tl_avenrun.d[0] 823 ? load_ave.tl_avenrun.d[0]
826 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); 824 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale));
827# endif /* OSF_MIPS */ 825# endif /* OSF_MIPS */
828 826
829# if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32)) 827# if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32))
830# define LDAV_DONE 828# define LDAV_DONE
@@ -844,8 +842,8 @@ getloadavg (double loadavg[], int nelem)
844 for (elem = 0; elem < nelem; elem++) 842 for (elem = 0; elem < nelem; elem++)
845 loadavg[elem] 843 loadavg[elem]
846 = (load_ave.tl_lscale == 0 844 = (load_ave.tl_lscale == 0
847 ? load_ave.tl_avenrun.d[elem] 845 ? load_ave.tl_avenrun.d[elem]
848 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); 846 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale));
849# endif /* OSF_ALPHA */ 847# endif /* OSF_ALPHA */
850 848
851# if ! defined LDAV_DONE && defined __VMS 849# if ! defined LDAV_DONE && defined __VMS
@@ -872,13 +870,13 @@ getloadavg (double loadavg[], int nelem)
872 $DESCRIPTOR (descriptor, "LAV0:"); 870 $DESCRIPTOR (descriptor, "LAV0:");
873# endif 871# endif
874 if (sys$assign (&descriptor, &channel, 0, 0) & 1) 872 if (sys$assign (&descriptor, &channel, 0, 0) & 1)
875 getloadavg_initialized = true; 873 getloadavg_initialized = true;
876 } 874 }
877 875
878 /* Read the load average vector. */ 876 /* Read the load average vector. */
879 if (getloadavg_initialized 877 if (getloadavg_initialized
880 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0, 878 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0,
881 load_ave, 12, 0, 0, 0, 0) & 1)) 879 load_ave, 12, 0, 0, 0, 0) & 1))
882 { 880 {
883 sys$dassgn (channel); 881 sys$dassgn (channel);
884 getloadavg_initialized = false; 882 getloadavg_initialized = false;
@@ -892,7 +890,7 @@ getloadavg (double loadavg[], int nelem)
892 890
893 /* UNIX-specific code -- read the average from /dev/kmem. */ 891 /* UNIX-specific code -- read the average from /dev/kmem. */
894 892
895# define LDAV_PRIVILEGED /* This code requires special installation. */ 893# define LDAV_PRIVILEGED /* This code requires special installation. */
896 894
897 LOAD_AVE_TYPE load_ave[3]; 895 LOAD_AVE_TYPE load_ave[3];
898 896
@@ -900,7 +898,7 @@ getloadavg (double loadavg[], int nelem)
900 if (offset == 0) 898 if (offset == 0)
901 { 899 {
902# ifndef sgi 900# ifndef sgi
903# ifndef NLIST_STRUCT 901# if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER
904 strcpy (nl[0].n_name, LDAV_SYMBOL); 902 strcpy (nl[0].n_name, LDAV_SYMBOL);
905 strcpy (nl[1].n_name, ""); 903 strcpy (nl[1].n_name, "");
906# else /* NLIST_STRUCT */ 904# else /* NLIST_STRUCT */
@@ -916,25 +914,25 @@ getloadavg (double loadavg[], int nelem)
916# ifndef SUNOS_5 914# ifndef SUNOS_5
917 if ( 915 if (
918# if !(defined (_AIX) && !defined (ps2)) 916# if !(defined (_AIX) && !defined (ps2))
919 nlist (KERNEL_FILE, nl) 917 nlist (KERNEL_FILE, nl)
920# else /* _AIX */ 918# else /* _AIX */
921 knlist (nl, 1, sizeof (nl[0])) 919 knlist (nl, 1, sizeof (nl[0]))
922# endif 920# endif
923 >= 0) 921 >= 0)
924 /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ 922 /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */
925 { 923 {
926# ifdef FIXUP_KERNEL_SYMBOL_ADDR 924# ifdef FIXUP_KERNEL_SYMBOL_ADDR
927 FIXUP_KERNEL_SYMBOL_ADDR (nl); 925 FIXUP_KERNEL_SYMBOL_ADDR (nl);
928# endif 926# endif
929 offset = nl[0].n_value; 927 offset = nl[0].n_value;
930 } 928 }
931# endif /* !SUNOS_5 */ 929# endif /* !SUNOS_5 */
932# else /* sgi */ 930# else /* sgi */
933 int ldav_off; 931 int ldav_off;
934 932
935 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); 933 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
936 if (ldav_off != -1) 934 if (ldav_off != -1)
937 offset = (long int) ldav_off & 0x7fffffff; 935 offset = (long int) ldav_off & 0x7fffffff;
938# endif /* sgi */ 936# endif /* sgi */
939 } 937 }
940 938
@@ -944,23 +942,23 @@ getloadavg (double loadavg[], int nelem)
944# ifndef SUNOS_5 942# ifndef SUNOS_5
945 channel = open ("/dev/kmem", O_RDONLY); 943 channel = open ("/dev/kmem", O_RDONLY);
946 if (channel >= 0) 944 if (channel >= 0)
947 { 945 {
948 /* Set the channel to close on exec, so it does not 946 /* Set the channel to close on exec, so it does not
949 litter any child's descriptor table. */ 947 litter any child's descriptor table. */
950 set_cloexec_flag (channel, true); 948 set_cloexec_flag (channel, true);
951 getloadavg_initialized = true; 949 getloadavg_initialized = true;
952 } 950 }
953# else /* SUNOS_5 */ 951# else /* SUNOS_5 */
954 /* We pass 0 for the kernel, corefile, and swapfile names 952 /* We pass 0 for the kernel, corefile, and swapfile names
955 to use the currently running kernel. */ 953 to use the currently running kernel. */
956 kd = kvm_open (0, 0, 0, O_RDONLY, 0); 954 kd = kvm_open (0, 0, 0, O_RDONLY, 0);
957 if (kd != 0) 955 if (kd != 0)
958 { 956 {
959 /* nlist the currently running kernel. */ 957 /* nlist the currently running kernel. */
960 kvm_nlist (kd, nl); 958 kvm_nlist (kd, nl);
961 offset = nl[0].n_value; 959 offset = nl[0].n_value;
962 getloadavg_initialized = true; 960 getloadavg_initialized = true;
963 } 961 }
964# endif /* SUNOS_5 */ 962# endif /* SUNOS_5 */
965 } 963 }
966 964
@@ -970,19 +968,19 @@ getloadavg (double loadavg[], int nelem)
970 /* Try to read the load. */ 968 /* Try to read the load. */
971# ifndef SUNOS_5 969# ifndef SUNOS_5
972 if (lseek (channel, offset, 0) == -1L 970 if (lseek (channel, offset, 0) == -1L
973 || read (channel, (char *) load_ave, sizeof (load_ave)) 971 || read (channel, (char *) load_ave, sizeof (load_ave))
974 != sizeof (load_ave)) 972 != sizeof (load_ave))
975 { 973 {
976 close (channel); 974 close (channel);
977 getloadavg_initialized = false; 975 getloadavg_initialized = false;
978 } 976 }
979# else /* SUNOS_5 */ 977# else /* SUNOS_5 */
980 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) 978 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave))
981 != sizeof (load_ave)) 979 != sizeof (load_ave))
982 { 980 {
983 kvm_close (kd); 981 kvm_close (kd);
984 getloadavg_initialized = false; 982 getloadavg_initialized = false;
985 } 983 }
986# endif /* SUNOS_5 */ 984# endif /* SUNOS_5 */
987 } 985 }
988 986
@@ -1026,24 +1024,24 @@ main (int argc, char **argv)
1026 double avg[3]; 1024 double avg[3];
1027 int loads; 1025 int loads;
1028 1026
1029 errno = 0; /* Don't be misled if it doesn't set errno. */ 1027 errno = 0; /* Don't be misled if it doesn't set errno. */
1030 loads = getloadavg (avg, 3); 1028 loads = getloadavg (avg, 3);
1031 if (loads == -1) 1029 if (loads == -1)
1032 { 1030 {
1033 perror ("Error getting load average"); 1031 perror ("Error getting load average");
1034 return EXIT_FAILURE; 1032 return EXIT_FAILURE;
1035 } 1033 }
1036 if (loads > 0) 1034 if (loads > 0)
1037 printf ("1-minute: %f ", avg[0]); 1035 printf ("1-minute: %f ", avg[0]);
1038 if (loads > 1) 1036 if (loads > 1)
1039 printf ("5-minute: %f ", avg[1]); 1037 printf ("5-minute: %f ", avg[1]);
1040 if (loads > 2) 1038 if (loads > 2)
1041 printf ("15-minute: %f ", avg[2]); 1039 printf ("15-minute: %f ", avg[2]);
1042 if (loads > 0) 1040 if (loads > 0)
1043 putchar ('\n'); 1041 putchar ('\n');
1044 1042
1045 if (naptime == 0) 1043 if (naptime == 0)
1046 break; 1044 break;
1047 sleep (naptime); 1045 sleep (naptime);
1048 } 1046 }
1049 1047
diff --git a/gl/getopt.c b/gl/getopt.c
index f1e6d1f7..aaabc8d1 100644
--- a/gl/getopt.c
+++ b/gl/getopt.c
@@ -1,9 +1,9 @@
1/* Getopt for GNU. 1/* Getopt for GNU.
2 NOTE: getopt is now part of the C library, so if you don't know what 2 NOTE: getopt is part of the C library, so if you don't know what
3 "Keep this file name-space clean" means, talk to drepper@gnu.org 3 "Keep this file name-space clean" means, talk to drepper@gnu.org
4 before changing it! 4 before changing it!
5 Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006,2008 5 Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2010 Free Software
6 Free Software Foundation, Inc. 6 Foundation, Inc.
7 This file is part of the GNU C Library. 7 This file is part of the GNU C Library.
8 8
9 This program is free software: you can redistribute it and/or modify 9 This program is free software: you can redistribute it and/or modify
@@ -41,12 +41,9 @@
41# include <wchar.h> 41# include <wchar.h>
42#endif 42#endif
43 43
44#ifndef attribute_hidden 44/* This version of `getopt' appears to the caller like standard Unix `getopt'
45# define attribute_hidden 45 but it behaves differently for the user, since it allows the user
46#endif 46 to intersperse the options with the other arguments.
47
48/* Unlike standard Unix `getopt', functions like `getopt_long'
49 let the user intersperse the options with the other arguments.
50 47
51 As `getopt_long' works, it permutes the elements of ARGV so that, 48 As `getopt_long' works, it permutes the elements of ARGV so that,
52 when it is done, all the options precede everything else. Thus 49 when it is done, all the options precede everything else. Thus
@@ -54,7 +51,7 @@
54 51
55 Using `getopt' or setting the environment variable POSIXLY_CORRECT 52 Using `getopt' or setting the environment variable POSIXLY_CORRECT
56 disables permutation. 53 disables permutation.
57 Then the application's behavior is completely standard. 54 Then the behavior is completely standard.
58 55
59 GNU application programs can use a third alternative mode in which 56 GNU application programs can use a third alternative mode in which
60 they can distinguish the relative order of options and other arguments. */ 57 they can distinguish the relative order of options and other arguments. */
@@ -121,18 +118,18 @@ extern char *__getopt_nonoption_flags;
121 118
122# ifdef USE_NONOPTION_FLAGS 119# ifdef USE_NONOPTION_FLAGS
123# define SWAP_FLAGS(ch1, ch2) \ 120# define SWAP_FLAGS(ch1, ch2) \
124 if (d->__nonoption_flags_len > 0) \ 121 if (d->__nonoption_flags_len > 0) \
125 { \ 122 { \
126 char __tmp = __getopt_nonoption_flags[ch1]; \ 123 char __tmp = __getopt_nonoption_flags[ch1]; \
127 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ 124 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
128 __getopt_nonoption_flags[ch2] = __tmp; \ 125 __getopt_nonoption_flags[ch2] = __tmp; \
129 } 126 }
130# else 127# else
131# define SWAP_FLAGS(ch1, ch2) 128# define SWAP_FLAGS(ch1, ch2)
132# endif 129# endif
133#else /* !_LIBC */ 130#else /* !_LIBC */
134# define SWAP_FLAGS(ch1, ch2) 131# define SWAP_FLAGS(ch1, ch2)
135#endif /* _LIBC */ 132#endif /* _LIBC */
136 133
137/* Exchange two adjacent subsequences of ARGV. 134/* Exchange two adjacent subsequences of ARGV.
138 One subsequence is elements [first_nonopt,last_nonopt) 135 One subsequence is elements [first_nonopt,last_nonopt)
@@ -163,57 +160,57 @@ exchange (char **argv, struct _getopt_data *d)
163 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len) 160 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
164 { 161 {
165 /* We must extend the array. The user plays games with us and 162 /* We must extend the array. The user plays games with us and
166 presents new arguments. */ 163 presents new arguments. */
167 char *new_str = malloc (top + 1); 164 char *new_str = malloc (top + 1);
168 if (new_str == NULL) 165 if (new_str == NULL)
169 d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0; 166 d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
170 else 167 else
171 { 168 {
172 memset (__mempcpy (new_str, __getopt_nonoption_flags, 169 memset (__mempcpy (new_str, __getopt_nonoption_flags,
173 d->__nonoption_flags_max_len), 170 d->__nonoption_flags_max_len),
174 '\0', top + 1 - d->__nonoption_flags_max_len); 171 '\0', top + 1 - d->__nonoption_flags_max_len);
175 d->__nonoption_flags_max_len = top + 1; 172 d->__nonoption_flags_max_len = top + 1;
176 __getopt_nonoption_flags = new_str; 173 __getopt_nonoption_flags = new_str;
177 } 174 }
178 } 175 }
179#endif 176#endif
180 177
181 while (top > middle && middle > bottom) 178 while (top > middle && middle > bottom)
182 { 179 {
183 if (top - middle > middle - bottom) 180 if (top - middle > middle - bottom)
184 { 181 {
185 /* Bottom segment is the short one. */ 182 /* Bottom segment is the short one. */
186 int len = middle - bottom; 183 int len = middle - bottom;
187 register int i; 184 register int i;
188 185
189 /* Swap it with the top part of the top segment. */ 186 /* Swap it with the top part of the top segment. */
190 for (i = 0; i < len; i++) 187 for (i = 0; i < len; i++)
191 { 188 {
192 tem = argv[bottom + i]; 189 tem = argv[bottom + i];
193 argv[bottom + i] = argv[top - (middle - bottom) + i]; 190 argv[bottom + i] = argv[top - (middle - bottom) + i];
194 argv[top - (middle - bottom) + i] = tem; 191 argv[top - (middle - bottom) + i] = tem;
195 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); 192 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
196 } 193 }
197 /* Exclude the moved bottom segment from further swapping. */ 194 /* Exclude the moved bottom segment from further swapping. */
198 top -= len; 195 top -= len;
199 } 196 }
200 else 197 else
201 { 198 {
202 /* Top segment is the short one. */ 199 /* Top segment is the short one. */
203 int len = top - middle; 200 int len = top - middle;
204 register int i; 201 register int i;
205 202
206 /* Swap it with the bottom part of the bottom segment. */ 203 /* Swap it with the bottom part of the bottom segment. */
207 for (i = 0; i < len; i++) 204 for (i = 0; i < len; i++)
208 { 205 {
209 tem = argv[bottom + i]; 206 tem = argv[bottom + i];
210 argv[bottom + i] = argv[middle + i]; 207 argv[bottom + i] = argv[middle + i];
211 argv[middle + i] = tem; 208 argv[middle + i] = tem;
212 SWAP_FLAGS (bottom + i, middle + i); 209 SWAP_FLAGS (bottom + i, middle + i);
213 } 210 }
214 /* Exclude the moved top segment from further swapping. */ 211 /* Exclude the moved top segment from further swapping. */
215 bottom += len; 212 bottom += len;
216 } 213 }
217 } 214 }
218 215
219 /* Update records for the slots the non-options now occupy. */ 216 /* Update records for the slots the non-options now occupy. */
@@ -225,8 +222,9 @@ exchange (char **argv, struct _getopt_data *d)
225/* Initialize the internal data when the first call is made. */ 222/* Initialize the internal data when the first call is made. */
226 223
227static const char * 224static const char *
228_getopt_initialize (int argc, char **argv, const char *optstring, 225_getopt_initialize (int argc _GL_UNUSED,
229 int posixly_correct, struct _getopt_data *d) 226 char **argv _GL_UNUSED, const char *optstring,
227 struct _getopt_data *d, int posixly_correct)
230{ 228{
231 /* Start processing options with ARGV-element 1 (since ARGV-element 0 229 /* Start processing options with ARGV-element 1 (since ARGV-element 0
232 is the program name); the sequence of previously skipped 230 is the program name); the sequence of previously skipped
@@ -260,25 +258,25 @@ _getopt_initialize (int argc, char **argv, const char *optstring,
260 && argc == __libc_argc && argv == __libc_argv) 258 && argc == __libc_argc && argv == __libc_argv)
261 { 259 {
262 if (d->__nonoption_flags_max_len == 0) 260 if (d->__nonoption_flags_max_len == 0)
263 { 261 {
264 if (__getopt_nonoption_flags == NULL 262 if (__getopt_nonoption_flags == NULL
265 || __getopt_nonoption_flags[0] == '\0') 263 || __getopt_nonoption_flags[0] == '\0')
266 d->__nonoption_flags_max_len = -1; 264 d->__nonoption_flags_max_len = -1;
267 else 265 else
268 { 266 {
269 const char *orig_str = __getopt_nonoption_flags; 267 const char *orig_str = __getopt_nonoption_flags;
270 int len = d->__nonoption_flags_max_len = strlen (orig_str); 268 int len = d->__nonoption_flags_max_len = strlen (orig_str);
271 if (d->__nonoption_flags_max_len < argc) 269 if (d->__nonoption_flags_max_len < argc)
272 d->__nonoption_flags_max_len = argc; 270 d->__nonoption_flags_max_len = argc;
273 __getopt_nonoption_flags = 271 __getopt_nonoption_flags =
274 (char *) malloc (d->__nonoption_flags_max_len); 272 (char *) malloc (d->__nonoption_flags_max_len);
275 if (__getopt_nonoption_flags == NULL) 273 if (__getopt_nonoption_flags == NULL)
276 d->__nonoption_flags_max_len = -1; 274 d->__nonoption_flags_max_len = -1;
277 else 275 else
278 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), 276 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
279 '\0', d->__nonoption_flags_max_len - len); 277 '\0', d->__nonoption_flags_max_len - len);
280 } 278 }
281 } 279 }
282 d->__nonoption_flags_len = d->__nonoption_flags_max_len; 280 d->__nonoption_flags_len = d->__nonoption_flags_max_len;
283 } 281 }
284 else 282 else
@@ -330,6 +328,10 @@ _getopt_initialize (int argc, char **argv, const char *optstring,
330 `flag' field is nonzero, the value of the option's `val' field 328 `flag' field is nonzero, the value of the option's `val' field
331 if the `flag' field is zero. 329 if the `flag' field is zero.
332 330
331 The elements of ARGV aren't really const, because we permute them.
332 But we pretend they're const in the prototype to be compatible
333 with other systems.
334
333 LONGOPTS is a vector of `struct option' terminated by an 335 LONGOPTS is a vector of `struct option' terminated by an
334 element containing a name which is zero. 336 element containing a name which is zero.
335 337
@@ -338,15 +340,12 @@ _getopt_initialize (int argc, char **argv, const char *optstring,
338 recent call. 340 recent call.
339 341
340 If LONG_ONLY is nonzero, '-' as well as '--' can introduce 342 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
341 long-named options. 343 long-named options. */
342
343 If POSIXLY_CORRECT is nonzero, behave as if the POSIXLY_CORRECT
344 environment variable were set. */
345 344
346int 345int
347_getopt_internal_r (int argc, char **argv, const char *optstring, 346_getopt_internal_r (int argc, char **argv, const char *optstring,
348 const struct option *longopts, int *longind, 347 const struct option *longopts, int *longind,
349 int long_only, int posixly_correct, struct _getopt_data *d) 348 int long_only, struct _getopt_data *d, int posixly_correct)
350{ 349{
351 int print_errors = d->opterr; 350 int print_errors = d->opterr;
352 if (optstring[0] == ':') 351 if (optstring[0] == ':')
@@ -360,9 +359,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
360 if (d->optind == 0 || !d->__initialized) 359 if (d->optind == 0 || !d->__initialized)
361 { 360 {
362 if (d->optind == 0) 361 if (d->optind == 0)
363 d->optind = 1; /* Don't scan ARGV[0], the program name. */ 362 d->optind = 1; /* Don't scan ARGV[0], the program name. */
364 optstring = _getopt_initialize (argc, argv, optstring, 363 optstring = _getopt_initialize (argc, argv, optstring, d,
365 posixly_correct, d); 364 posixly_correct);
366 d->__initialized = 1; 365 d->__initialized = 1;
367 } 366 }
368 367
@@ -372,8 +371,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
372 is only used when the used in the GNU libc. */ 371 is only used when the used in the GNU libc. */
373#if defined _LIBC && defined USE_NONOPTION_FLAGS 372#if defined _LIBC && defined USE_NONOPTION_FLAGS
374# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \ 373# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
375 || (d->optind < d->__nonoption_flags_len \ 374 || (d->optind < d->__nonoption_flags_len \
376 && __getopt_nonoption_flags[d->optind] == '1')) 375 && __getopt_nonoption_flags[d->optind] == '1'))
377#else 376#else
378# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0') 377# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
379#endif 378#endif
@@ -383,78 +382,78 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
383 /* Advance to the next ARGV-element. */ 382 /* Advance to the next ARGV-element. */
384 383
385 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been 384 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
386 moved back by the user (who may also have changed the arguments). */ 385 moved back by the user (who may also have changed the arguments). */
387 if (d->__last_nonopt > d->optind) 386 if (d->__last_nonopt > d->optind)
388 d->__last_nonopt = d->optind; 387 d->__last_nonopt = d->optind;
389 if (d->__first_nonopt > d->optind) 388 if (d->__first_nonopt > d->optind)
390 d->__first_nonopt = d->optind; 389 d->__first_nonopt = d->optind;
391 390
392 if (d->__ordering == PERMUTE) 391 if (d->__ordering == PERMUTE)
393 { 392 {
394 /* If we have just processed some options following some non-options, 393 /* If we have just processed some options following some non-options,
395 exchange them so that the options come first. */ 394 exchange them so that the options come first. */
396 395
397 if (d->__first_nonopt != d->__last_nonopt 396 if (d->__first_nonopt != d->__last_nonopt
398 && d->__last_nonopt != d->optind) 397 && d->__last_nonopt != d->optind)
399 exchange ((char **) argv, d); 398 exchange ((char **) argv, d);
400 else if (d->__last_nonopt != d->optind) 399 else if (d->__last_nonopt != d->optind)
401 d->__first_nonopt = d->optind; 400 d->__first_nonopt = d->optind;
402 401
403 /* Skip any additional non-options 402 /* Skip any additional non-options
404 and extend the range of non-options previously skipped. */ 403 and extend the range of non-options previously skipped. */
405 404
406 while (d->optind < argc && NONOPTION_P) 405 while (d->optind < argc && NONOPTION_P)
407 d->optind++; 406 d->optind++;
408 d->__last_nonopt = d->optind; 407 d->__last_nonopt = d->optind;
409 } 408 }
410 409
411 /* The special ARGV-element `--' means premature end of options. 410 /* The special ARGV-element `--' means premature end of options.
412 Skip it like a null option, 411 Skip it like a null option,
413 then exchange with previous non-options as if it were an option, 412 then exchange with previous non-options as if it were an option,
414 then skip everything else like a non-option. */ 413 then skip everything else like a non-option. */
415 414
416 if (d->optind != argc && !strcmp (argv[d->optind], "--")) 415 if (d->optind != argc && !strcmp (argv[d->optind], "--"))
417 { 416 {
418 d->optind++; 417 d->optind++;
419 418
420 if (d->__first_nonopt != d->__last_nonopt 419 if (d->__first_nonopt != d->__last_nonopt
421 && d->__last_nonopt != d->optind) 420 && d->__last_nonopt != d->optind)
422 exchange ((char **) argv, d); 421 exchange ((char **) argv, d);
423 else if (d->__first_nonopt == d->__last_nonopt) 422 else if (d->__first_nonopt == d->__last_nonopt)
424 d->__first_nonopt = d->optind; 423 d->__first_nonopt = d->optind;
425 d->__last_nonopt = argc; 424 d->__last_nonopt = argc;
426 425
427 d->optind = argc; 426 d->optind = argc;
428 } 427 }
429 428
430 /* If we have done all the ARGV-elements, stop the scan 429 /* If we have done all the ARGV-elements, stop the scan
431 and back over any non-options that we skipped and permuted. */ 430 and back over any non-options that we skipped and permuted. */
432 431
433 if (d->optind == argc) 432 if (d->optind == argc)
434 { 433 {
435 /* Set the next-arg-index to point at the non-options 434 /* Set the next-arg-index to point at the non-options
436 that we previously skipped, so the caller will digest them. */ 435 that we previously skipped, so the caller will digest them. */
437 if (d->__first_nonopt != d->__last_nonopt) 436 if (d->__first_nonopt != d->__last_nonopt)
438 d->optind = d->__first_nonopt; 437 d->optind = d->__first_nonopt;
439 return -1; 438 return -1;
440 } 439 }
441 440
442 /* If we have come to a non-option and did not permute it, 441 /* If we have come to a non-option and did not permute it,
443 either stop the scan or describe it to the caller and pass it by. */ 442 either stop the scan or describe it to the caller and pass it by. */
444 443
445 if (NONOPTION_P) 444 if (NONOPTION_P)
446 { 445 {
447 if (d->__ordering == REQUIRE_ORDER) 446 if (d->__ordering == REQUIRE_ORDER)
448 return -1; 447 return -1;
449 d->optarg = argv[d->optind++]; 448 d->optarg = argv[d->optind++];
450 return 1; 449 return 1;
451 } 450 }
452 451
453 /* We have found another option-ARGV-element. 452 /* We have found another option-ARGV-element.
454 Skip the initial punctuation. */ 453 Skip the initial punctuation. */
455 454
456 d->__nextchar = (argv[d->optind] + 1 455 d->__nextchar = (argv[d->optind] + 1
457 + (longopts != NULL && argv[d->optind][1] == '-')); 456 + (longopts != NULL && argv[d->optind][1] == '-'));
458 } 457 }
459 458
460 /* Decode the current option-ARGV-element. */ 459 /* Decode the current option-ARGV-element. */
@@ -474,8 +473,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
474 473
475 if (longopts != NULL 474 if (longopts != NULL
476 && (argv[d->optind][1] == '-' 475 && (argv[d->optind][1] == '-'
477 || (long_only && (argv[d->optind][2] 476 || (long_only && (argv[d->optind][2]
478 || !strchr (optstring, argv[d->optind][1]))))) 477 || !strchr (optstring, argv[d->optind][1])))))
479 { 478 {
480 char *nameend; 479 char *nameend;
481 const struct option *p; 480 const struct option *p;
@@ -486,251 +485,251 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
486 int option_index; 485 int option_index;
487 486
488 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) 487 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
489 /* Do nothing. */ ; 488 /* Do nothing. */ ;
490 489
491 /* Test all long options for either exact match 490 /* Test all long options for either exact match
492 or abbreviated matches. */ 491 or abbreviated matches. */
493 for (p = longopts, option_index = 0; p->name; p++, option_index++) 492 for (p = longopts, option_index = 0; p->name; p++, option_index++)
494 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) 493 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
495 { 494 {
496 if ((unsigned int) (nameend - d->__nextchar) 495 if ((unsigned int) (nameend - d->__nextchar)
497 == (unsigned int) strlen (p->name)) 496 == (unsigned int) strlen (p->name))
498 { 497 {
499 /* Exact match found. */ 498 /* Exact match found. */
500 pfound = p; 499 pfound = p;
501 indfound = option_index; 500 indfound = option_index;
502 exact = 1; 501 exact = 1;
503 break; 502 break;
504 } 503 }
505 else if (pfound == NULL) 504 else if (pfound == NULL)
506 { 505 {
507 /* First nonexact match found. */ 506 /* First nonexact match found. */
508 pfound = p; 507 pfound = p;
509 indfound = option_index; 508 indfound = option_index;
510 } 509 }
511 else if (long_only 510 else if (long_only
512 || pfound->has_arg != p->has_arg 511 || pfound->has_arg != p->has_arg
513 || pfound->flag != p->flag 512 || pfound->flag != p->flag
514 || pfound->val != p->val) 513 || pfound->val != p->val)
515 /* Second or later nonexact match found. */ 514 /* Second or later nonexact match found. */
516 ambig = 1; 515 ambig = 1;
517 } 516 }
518 517
519 if (ambig && !exact) 518 if (ambig && !exact)
520 { 519 {
521 if (print_errors) 520 if (print_errors)
522 { 521 {
523#if defined _LIBC && defined USE_IN_LIBIO 522#if defined _LIBC && defined USE_IN_LIBIO
524 char *buf; 523 char *buf;
525 524
526 if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), 525 if (__asprintf (&buf, _("%s: option '%s' is ambiguous\n"),
527 argv[0], argv[d->optind]) >= 0) 526 argv[0], argv[d->optind]) >= 0)
528 { 527 {
529 _IO_flockfile (stderr); 528 _IO_flockfile (stderr);
530 529
531 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 530 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
532 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 531 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
533 532
534 __fxprintf (NULL, "%s", buf); 533 __fxprintf (NULL, "%s", buf);
535 534
536 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 535 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
537 _IO_funlockfile (stderr); 536 _IO_funlockfile (stderr);
538 537
539 free (buf); 538 free (buf);
540 } 539 }
541#else 540#else
542 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 541 fprintf (stderr, _("%s: option '%s' is ambiguous\n"),
543 argv[0], argv[d->optind]); 542 argv[0], argv[d->optind]);
544#endif 543#endif
545 } 544 }
546 d->__nextchar += strlen (d->__nextchar); 545 d->__nextchar += strlen (d->__nextchar);
547 d->optind++; 546 d->optind++;
548 d->optopt = 0; 547 d->optopt = 0;
549 return '?'; 548 return '?';
550 } 549 }
551 550
552 if (pfound != NULL) 551 if (pfound != NULL)
553 { 552 {
554 option_index = indfound; 553 option_index = indfound;
555 d->optind++; 554 d->optind++;
556 if (*nameend) 555 if (*nameend)
557 { 556 {
558 /* Don't test has_arg with >, because some C compilers don't 557 /* Don't test has_arg with >, because some C compilers don't
559 allow it to be used on enums. */ 558 allow it to be used on enums. */
560 if (pfound->has_arg) 559 if (pfound->has_arg)
561 d->optarg = nameend + 1; 560 d->optarg = nameend + 1;
562 else 561 else
563 { 562 {
564 if (print_errors) 563 if (print_errors)
565 { 564 {
566#if defined _LIBC && defined USE_IN_LIBIO 565#if defined _LIBC && defined USE_IN_LIBIO
567 char *buf; 566 char *buf;
568 int n; 567 int n;
569#endif 568#endif
570 569
571 if (argv[d->optind - 1][1] == '-') 570 if (argv[d->optind - 1][1] == '-')
572 { 571 {
573 /* --option */ 572 /* --option */
574#if defined _LIBC && defined USE_IN_LIBIO 573#if defined _LIBC && defined USE_IN_LIBIO
575 n = __asprintf (&buf, _("\ 574 n = __asprintf (&buf, _("\
576%s: option `--%s' doesn't allow an argument\n"), 575%s: option '--%s' doesn't allow an argument\n"),
577 argv[0], pfound->name); 576 argv[0], pfound->name);
578#else 577#else
579 fprintf (stderr, _("\ 578 fprintf (stderr, _("\
580%s: option `--%s' doesn't allow an argument\n"), 579%s: option '--%s' doesn't allow an argument\n"),
581 argv[0], pfound->name); 580 argv[0], pfound->name);
582#endif 581#endif
583 } 582 }
584 else 583 else
585 { 584 {
586 /* +option or -option */ 585 /* +option or -option */
587#if defined _LIBC && defined USE_IN_LIBIO 586#if defined _LIBC && defined USE_IN_LIBIO
588 n = __asprintf (&buf, _("\ 587 n = __asprintf (&buf, _("\
589%s: option `%c%s' doesn't allow an argument\n"), 588%s: option '%c%s' doesn't allow an argument\n"),
590 argv[0], argv[d->optind - 1][0], 589 argv[0], argv[d->optind - 1][0],
591 pfound->name); 590 pfound->name);
592#else 591#else
593 fprintf (stderr, _("\ 592 fprintf (stderr, _("\
594%s: option `%c%s' doesn't allow an argument\n"), 593%s: option '%c%s' doesn't allow an argument\n"),
595 argv[0], argv[d->optind - 1][0], 594 argv[0], argv[d->optind - 1][0],
596 pfound->name); 595 pfound->name);
597#endif 596#endif
598 } 597 }
599 598
600#if defined _LIBC && defined USE_IN_LIBIO 599#if defined _LIBC && defined USE_IN_LIBIO
601 if (n >= 0) 600 if (n >= 0)
602 { 601 {
603 _IO_flockfile (stderr); 602 _IO_flockfile (stderr);
604 603
605 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 604 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
606 ((_IO_FILE *) stderr)->_flags2 605 ((_IO_FILE *) stderr)->_flags2
607 |= _IO_FLAGS2_NOTCANCEL; 606 |= _IO_FLAGS2_NOTCANCEL;
608 607
609 __fxprintf (NULL, "%s", buf); 608 __fxprintf (NULL, "%s", buf);
610 609
611 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 610 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
612 _IO_funlockfile (stderr); 611 _IO_funlockfile (stderr);
613 612
614 free (buf); 613 free (buf);
615 } 614 }
616#endif 615#endif
617 } 616 }
618 617
619 d->__nextchar += strlen (d->__nextchar); 618 d->__nextchar += strlen (d->__nextchar);
620 619
621 d->optopt = pfound->val; 620 d->optopt = pfound->val;
622 return '?'; 621 return '?';
623 } 622 }
624 } 623 }
625 else if (pfound->has_arg == 1) 624 else if (pfound->has_arg == 1)
626 { 625 {
627 if (d->optind < argc) 626 if (d->optind < argc)
628 d->optarg = argv[d->optind++]; 627 d->optarg = argv[d->optind++];
629 else 628 else
630 { 629 {
631 if (print_errors) 630 if (print_errors)
632 { 631 {
633#if defined _LIBC && defined USE_IN_LIBIO 632#if defined _LIBC && defined USE_IN_LIBIO
634 char *buf; 633 char *buf;
635 634
636 if (__asprintf (&buf, _("\ 635 if (__asprintf (&buf, _("\
637%s: option `%s' requires an argument\n"), 636%s: option '%s' requires an argument\n"),
638 argv[0], argv[d->optind - 1]) >= 0) 637 argv[0], argv[d->optind - 1]) >= 0)
639 { 638 {
640 _IO_flockfile (stderr); 639 _IO_flockfile (stderr);
641 640
642 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 641 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
643 ((_IO_FILE *) stderr)->_flags2 642 ((_IO_FILE *) stderr)->_flags2
644 |= _IO_FLAGS2_NOTCANCEL; 643 |= _IO_FLAGS2_NOTCANCEL;
645 644
646 __fxprintf (NULL, "%s", buf); 645 __fxprintf (NULL, "%s", buf);
647 646
648 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 647 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
649 _IO_funlockfile (stderr); 648 _IO_funlockfile (stderr);
650 649
651 free (buf); 650 free (buf);
652 } 651 }
653#else 652#else
654 fprintf (stderr, 653 fprintf (stderr,
655 _("%s: option `%s' requires an argument\n"), 654 _("%s: option '%s' requires an argument\n"),
656 argv[0], argv[d->optind - 1]); 655 argv[0], argv[d->optind - 1]);
657#endif 656#endif
658 } 657 }
659 d->__nextchar += strlen (d->__nextchar); 658 d->__nextchar += strlen (d->__nextchar);
660 d->optopt = pfound->val; 659 d->optopt = pfound->val;
661 return optstring[0] == ':' ? ':' : '?'; 660 return optstring[0] == ':' ? ':' : '?';
662 } 661 }
663 } 662 }
664 d->__nextchar += strlen (d->__nextchar); 663 d->__nextchar += strlen (d->__nextchar);
665 if (longind != NULL) 664 if (longind != NULL)
666 *longind = option_index; 665 *longind = option_index;
667 if (pfound->flag) 666 if (pfound->flag)
668 { 667 {
669 *(pfound->flag) = pfound->val; 668 *(pfound->flag) = pfound->val;
670 return 0; 669 return 0;
671 } 670 }
672 return pfound->val; 671 return pfound->val;
673 } 672 }
674 673
675 /* Can't find it as a long option. If this is not getopt_long_only, 674 /* Can't find it as a long option. If this is not getopt_long_only,
676 or the option starts with '--' or is not a valid short 675 or the option starts with '--' or is not a valid short
677 option, then it's an error. 676 option, then it's an error.
678 Otherwise interpret it as a short option. */ 677 Otherwise interpret it as a short option. */
679 if (!long_only || argv[d->optind][1] == '-' 678 if (!long_only || argv[d->optind][1] == '-'
680 || strchr (optstring, *d->__nextchar) == NULL) 679 || strchr (optstring, *d->__nextchar) == NULL)
681 { 680 {
682 if (print_errors) 681 if (print_errors)
683 { 682 {
684#if defined _LIBC && defined USE_IN_LIBIO 683#if defined _LIBC && defined USE_IN_LIBIO
685 char *buf; 684 char *buf;
686 int n; 685 int n;
687#endif 686#endif
688 687
689 if (argv[d->optind][1] == '-') 688 if (argv[d->optind][1] == '-')
690 { 689 {
691 /* --option */ 690 /* --option */
692#if defined _LIBC && defined USE_IN_LIBIO 691#if defined _LIBC && defined USE_IN_LIBIO
693 n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), 692 n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
694 argv[0], d->__nextchar); 693 argv[0], d->__nextchar);
695#else 694#else
696 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), 695 fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
697 argv[0], d->__nextchar); 696 argv[0], d->__nextchar);
698#endif 697#endif
699 } 698 }
700 else 699 else
701 { 700 {
702 /* +option or -option */ 701 /* +option or -option */
703#if defined _LIBC && defined USE_IN_LIBIO 702#if defined _LIBC && defined USE_IN_LIBIO
704 n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), 703 n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
705 argv[0], argv[d->optind][0], d->__nextchar); 704 argv[0], argv[d->optind][0], d->__nextchar);
706#else 705#else
707 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), 706 fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
708 argv[0], argv[d->optind][0], d->__nextchar); 707 argv[0], argv[d->optind][0], d->__nextchar);
709#endif 708#endif
710 } 709 }
711 710
712#if defined _LIBC && defined USE_IN_LIBIO 711#if defined _LIBC && defined USE_IN_LIBIO
713 if (n >= 0) 712 if (n >= 0)
714 { 713 {
715 _IO_flockfile (stderr); 714 _IO_flockfile (stderr);
716 715
717 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 716 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
718 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 717 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
719 718
720 __fxprintf (NULL, "%s", buf); 719 __fxprintf (NULL, "%s", buf);
721 720
722 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 721 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
723 _IO_funlockfile (stderr); 722 _IO_funlockfile (stderr);
724 723
725 free (buf); 724 free (buf);
726 } 725 }
727#endif 726#endif
728 } 727 }
729 d->__nextchar = (char *) ""; 728 d->__nextchar = (char *) "";
730 d->optind++; 729 d->optind++;
731 d->optopt = 0; 730 d->optopt = 0;
732 return '?'; 731 return '?';
733 } 732 }
734 } 733 }
735 734
736 /* Look at and handle the next short option-character. */ 735 /* Look at and handle the next short option-character. */
@@ -745,335 +744,321 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
745 744
746 if (temp == NULL || c == ':') 745 if (temp == NULL || c == ':')
747 { 746 {
748 if (print_errors) 747 if (print_errors)
749 { 748 {
750#if defined _LIBC && defined USE_IN_LIBIO 749#if defined _LIBC && defined USE_IN_LIBIO
751 char *buf; 750 char *buf;
752 int n; 751 int n;
753#endif 752#endif
754 753
755 if (d->__posixly_correct)
756 {
757 /* 1003.2 specifies the format of this message. */
758#if defined _LIBC && defined USE_IN_LIBIO
759 n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
760 argv[0], c);
761#else
762 fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
763#endif
764 }
765 else
766 {
767#if defined _LIBC && defined USE_IN_LIBIO 754#if defined _LIBC && defined USE_IN_LIBIO
768 n = __asprintf (&buf, _("%s: invalid option -- %c\n"), 755 n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
769 argv[0], c); 756 argv[0], c);
770#else 757#else
771 fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); 758 fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
772#endif 759#endif
773 }
774 760
775#if defined _LIBC && defined USE_IN_LIBIO 761#if defined _LIBC && defined USE_IN_LIBIO
776 if (n >= 0) 762 if (n >= 0)
777 { 763 {
778 _IO_flockfile (stderr); 764 _IO_flockfile (stderr);
779 765
780 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 766 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
781 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 767 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
782 768
783 __fxprintf (NULL, "%s", buf); 769 __fxprintf (NULL, "%s", buf);
784 770
785 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 771 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
786 _IO_funlockfile (stderr); 772 _IO_funlockfile (stderr);
787 773
788 free (buf); 774 free (buf);
789 } 775 }
790#endif 776#endif
791 } 777 }
792 d->optopt = c; 778 d->optopt = c;
793 return '?'; 779 return '?';
794 } 780 }
795 /* Convenience. Treat POSIX -W foo same as long option --foo */ 781 /* Convenience. Treat POSIX -W foo same as long option --foo */
796 if (temp[0] == 'W' && temp[1] == ';') 782 if (temp[0] == 'W' && temp[1] == ';')
797 { 783 {
798 char *nameend; 784 char *nameend;
799 const struct option *p; 785 const struct option *p;
800 const struct option *pfound = NULL; 786 const struct option *pfound = NULL;
801 int exact = 0; 787 int exact = 0;
802 int ambig = 0; 788 int ambig = 0;
803 int indfound = 0; 789 int indfound = 0;
804 int option_index; 790 int option_index;
805 791
806 /* This is an option that requires an argument. */ 792 /* This is an option that requires an argument. */
807 if (*d->__nextchar != '\0') 793 if (*d->__nextchar != '\0')
808 { 794 {
809 d->optarg = d->__nextchar; 795 d->optarg = d->__nextchar;
810 /* If we end this ARGV-element by taking the rest as an arg, 796 /* If we end this ARGV-element by taking the rest as an arg,
811 we must advance to the next element now. */ 797 we must advance to the next element now. */
812 d->optind++; 798 d->optind++;
813 } 799 }
814 else if (d->optind == argc) 800 else if (d->optind == argc)
815 { 801 {
816 if (print_errors) 802 if (print_errors)
817 { 803 {
818 /* 1003.2 specifies the format of this message. */
819#if defined _LIBC && defined USE_IN_LIBIO 804#if defined _LIBC && defined USE_IN_LIBIO
820 char *buf; 805 char *buf;
821 806
822 if (__asprintf (&buf, 807 if (__asprintf (&buf,
823 _("%s: option requires an argument -- %c\n"), 808 _("%s: option requires an argument -- '%c'\n"),
824 argv[0], c) >= 0) 809 argv[0], c) >= 0)
825 { 810 {
826 _IO_flockfile (stderr); 811 _IO_flockfile (stderr);
827 812
828 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 813 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
829 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 814 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
830 815
831 __fxprintf (NULL, "%s", buf); 816 __fxprintf (NULL, "%s", buf);
832 817
833 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 818 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
834 _IO_funlockfile (stderr); 819 _IO_funlockfile (stderr);
835 820
836 free (buf); 821 free (buf);
837 } 822 }
838#else 823#else
839 fprintf (stderr, _("%s: option requires an argument -- %c\n"), 824 fprintf (stderr,
840 argv[0], c); 825 _("%s: option requires an argument -- '%c'\n"),
826 argv[0], c);
841#endif 827#endif
842 } 828 }
843 d->optopt = c; 829 d->optopt = c;
844 if (optstring[0] == ':') 830 if (optstring[0] == ':')
845 c = ':'; 831 c = ':';
846 else 832 else
847 c = '?'; 833 c = '?';
848 return c; 834 return c;
849 } 835 }
850 else 836 else
851 /* We already incremented `d->optind' once; 837 /* We already incremented `d->optind' once;
852 increment it again when taking next ARGV-elt as argument. */ 838 increment it again when taking next ARGV-elt as argument. */
853 d->optarg = argv[d->optind++]; 839 d->optarg = argv[d->optind++];
854 840
855 /* optarg is now the argument, see if it's in the 841 /* optarg is now the argument, see if it's in the
856 table of longopts. */ 842 table of longopts. */
857 843
858 for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '='; 844 for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
859 nameend++) 845 nameend++)
860 /* Do nothing. */ ; 846 /* Do nothing. */ ;
861 847
862 /* Test all long options for either exact match 848 /* Test all long options for either exact match
863 or abbreviated matches. */ 849 or abbreviated matches. */
864 for (p = longopts, option_index = 0; p->name; p++, option_index++) 850 for (p = longopts, option_index = 0; p->name; p++, option_index++)
865 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) 851 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
866 { 852 {
867 if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name)) 853 if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
868 { 854 {
869 /* Exact match found. */ 855 /* Exact match found. */
870 pfound = p; 856 pfound = p;
871 indfound = option_index; 857 indfound = option_index;
872 exact = 1; 858 exact = 1;
873 break; 859 break;
874 } 860 }
875 else if (pfound == NULL) 861 else if (pfound == NULL)
876 { 862 {
877 /* First nonexact match found. */ 863 /* First nonexact match found. */
878 pfound = p; 864 pfound = p;
879 indfound = option_index; 865 indfound = option_index;
880 } 866 }
881 else 867 else
882 /* Second or later nonexact match found. */ 868 /* Second or later nonexact match found. */
883 ambig = 1; 869 ambig = 1;
884 } 870 }
885 if (ambig && !exact) 871 if (ambig && !exact)
886 { 872 {
887 if (print_errors) 873 if (print_errors)
888 { 874 {
889#if defined _LIBC && defined USE_IN_LIBIO 875#if defined _LIBC && defined USE_IN_LIBIO
890 char *buf; 876 char *buf;
891 877
892 if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), 878 if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
893 argv[0], argv[d->optind]) >= 0) 879 argv[0], argv[d->optind]) >= 0)
894 { 880 {
895 _IO_flockfile (stderr); 881 _IO_flockfile (stderr);
896 882
897 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 883 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
898 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 884 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
899 885
900 __fxprintf (NULL, "%s", buf); 886 __fxprintf (NULL, "%s", buf);
901 887
902 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 888 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
903 _IO_funlockfile (stderr); 889 _IO_funlockfile (stderr);
904 890
905 free (buf); 891 free (buf);
906 } 892 }
907#else 893#else
908 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 894 fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
909 argv[0], argv[d->optind]); 895 argv[0], argv[d->optind]);
910#endif 896#endif
911 } 897 }
912 d->__nextchar += strlen (d->__nextchar); 898 d->__nextchar += strlen (d->__nextchar);
913 d->optind++; 899 d->optind++;
914 return '?'; 900 return '?';
915 } 901 }
916 if (pfound != NULL) 902 if (pfound != NULL)
917 { 903 {
918 option_index = indfound; 904 option_index = indfound;
919 if (*nameend) 905 if (*nameend)
920 { 906 {
921 /* Don't test has_arg with >, because some C compilers don't 907 /* Don't test has_arg with >, because some C compilers don't
922 allow it to be used on enums. */ 908 allow it to be used on enums. */
923 if (pfound->has_arg) 909 if (pfound->has_arg)
924 d->optarg = nameend + 1; 910 d->optarg = nameend + 1;
925 else 911 else
926 { 912 {
927 if (print_errors) 913 if (print_errors)
928 { 914 {
929#if defined _LIBC && defined USE_IN_LIBIO 915#if defined _LIBC && defined USE_IN_LIBIO
930 char *buf; 916 char *buf;
931 917
932 if (__asprintf (&buf, _("\ 918 if (__asprintf (&buf, _("\
933%s: option `-W %s' doesn't allow an argument\n"), 919%s: option '-W %s' doesn't allow an argument\n"),
934 argv[0], pfound->name) >= 0) 920 argv[0], pfound->name) >= 0)
935 { 921 {
936 _IO_flockfile (stderr); 922 _IO_flockfile (stderr);
937 923
938 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 924 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
939 ((_IO_FILE *) stderr)->_flags2 925 ((_IO_FILE *) stderr)->_flags2
940 |= _IO_FLAGS2_NOTCANCEL; 926 |= _IO_FLAGS2_NOTCANCEL;
941 927
942 __fxprintf (NULL, "%s", buf); 928 __fxprintf (NULL, "%s", buf);
943 929
944 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 930 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
945 _IO_funlockfile (stderr); 931 _IO_funlockfile (stderr);
946 932
947 free (buf); 933 free (buf);
948 } 934 }
949#else 935#else
950 fprintf (stderr, _("\ 936 fprintf (stderr, _("\
951%s: option `-W %s' doesn't allow an argument\n"), 937%s: option '-W %s' doesn't allow an argument\n"),
952 argv[0], pfound->name); 938 argv[0], pfound->name);
953#endif 939#endif
954 } 940 }
955 941
956 d->__nextchar += strlen (d->__nextchar); 942 d->__nextchar += strlen (d->__nextchar);
957 return '?'; 943 return '?';
958 } 944 }
959 } 945 }
960 else if (pfound->has_arg == 1) 946 else if (pfound->has_arg == 1)
961 { 947 {
962 if (d->optind < argc) 948 if (d->optind < argc)
963 d->optarg = argv[d->optind++]; 949 d->optarg = argv[d->optind++];
964 else 950 else
965 { 951 {
966 if (print_errors) 952 if (print_errors)
967 { 953 {
968#if defined _LIBC && defined USE_IN_LIBIO 954#if defined _LIBC && defined USE_IN_LIBIO
969 char *buf; 955 char *buf;
970 956
971 if (__asprintf (&buf, _("\ 957 if (__asprintf (&buf, _("\
972%s: option `%s' requires an argument\n"), 958%s: option '%s' requires an argument\n"),
973 argv[0], argv[d->optind - 1]) >= 0) 959 argv[0], argv[d->optind - 1]) >= 0)
974 { 960 {
975 _IO_flockfile (stderr); 961 _IO_flockfile (stderr);
976 962
977 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 963 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
978 ((_IO_FILE *) stderr)->_flags2 964 ((_IO_FILE *) stderr)->_flags2
979 |= _IO_FLAGS2_NOTCANCEL; 965 |= _IO_FLAGS2_NOTCANCEL;
980 966
981 __fxprintf (NULL, "%s", buf); 967 __fxprintf (NULL, "%s", buf);
982 968
983 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 969 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
984 _IO_funlockfile (stderr); 970 _IO_funlockfile (stderr);
985 971
986 free (buf); 972 free (buf);
987 } 973 }
988#else 974#else
989 fprintf (stderr, 975 fprintf (stderr,
990 _("%s: option `%s' requires an argument\n"), 976 _("%s: option '%s' requires an argument\n"),
991 argv[0], argv[d->optind - 1]); 977 argv[0], argv[d->optind - 1]);
992#endif 978#endif
993 } 979 }
994 d->__nextchar += strlen (d->__nextchar); 980 d->__nextchar += strlen (d->__nextchar);
995 return optstring[0] == ':' ? ':' : '?'; 981 return optstring[0] == ':' ? ':' : '?';
996 } 982 }
997 } 983 }
998 d->__nextchar += strlen (d->__nextchar); 984 d->__nextchar += strlen (d->__nextchar);
999 if (longind != NULL) 985 if (longind != NULL)
1000 *longind = option_index; 986 *longind = option_index;
1001 if (pfound->flag) 987 if (pfound->flag)
1002 { 988 {
1003 *(pfound->flag) = pfound->val; 989 *(pfound->flag) = pfound->val;
1004 return 0; 990 return 0;
1005 } 991 }
1006 return pfound->val; 992 return pfound->val;
1007 } 993 }
1008 d->__nextchar = NULL; 994 d->__nextchar = NULL;
1009 return 'W'; /* Let the application handle it. */ 995 return 'W'; /* Let the application handle it. */
1010 } 996 }
1011 if (temp[1] == ':') 997 if (temp[1] == ':')
1012 { 998 {
1013 if (temp[2] == ':') 999 if (temp[2] == ':')
1014 { 1000 {
1015 /* This is an option that accepts an argument optionally. */ 1001 /* This is an option that accepts an argument optionally. */
1016 if (*d->__nextchar != '\0') 1002 if (*d->__nextchar != '\0')
1017 { 1003 {
1018 d->optarg = d->__nextchar; 1004 d->optarg = d->__nextchar;
1019 d->optind++; 1005 d->optind++;
1020 } 1006 }
1021 else 1007 else
1022 d->optarg = NULL; 1008 d->optarg = NULL;
1023 d->__nextchar = NULL; 1009 d->__nextchar = NULL;
1024 } 1010 }
1025 else 1011 else
1026 { 1012 {
1027 /* This is an option that requires an argument. */ 1013 /* This is an option that requires an argument. */
1028 if (*d->__nextchar != '\0') 1014 if (*d->__nextchar != '\0')
1029 { 1015 {
1030 d->optarg = d->__nextchar; 1016 d->optarg = d->__nextchar;
1031 /* If we end this ARGV-element by taking the rest as an arg, 1017 /* If we end this ARGV-element by taking the rest as an arg,
1032 we must advance to the next element now. */ 1018 we must advance to the next element now. */
1033 d->optind++; 1019 d->optind++;
1034 } 1020 }
1035 else if (d->optind == argc) 1021 else if (d->optind == argc)
1036 { 1022 {
1037 if (print_errors) 1023 if (print_errors)
1038 { 1024 {
1039 /* 1003.2 specifies the format of this message. */
1040#if defined _LIBC && defined USE_IN_LIBIO 1025#if defined _LIBC && defined USE_IN_LIBIO
1041 char *buf; 1026 char *buf;
1042 1027
1043 if (__asprintf (&buf, _("\ 1028 if (__asprintf (&buf, _("\
1044%s: option requires an argument -- %c\n"), 1029%s: option requires an argument -- '%c'\n"),
1045 argv[0], c) >= 0) 1030 argv[0], c) >= 0)
1046 { 1031 {
1047 _IO_flockfile (stderr); 1032 _IO_flockfile (stderr);
1048 1033
1049 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 1034 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1050 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 1035 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1051 1036
1052 __fxprintf (NULL, "%s", buf); 1037 __fxprintf (NULL, "%s", buf);
1053 1038
1054 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 1039 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
1055 _IO_funlockfile (stderr); 1040 _IO_funlockfile (stderr);
1056 1041
1057 free (buf); 1042 free (buf);
1058 } 1043 }
1059#else 1044#else
1060 fprintf (stderr, 1045 fprintf (stderr,
1061 _("%s: option requires an argument -- %c\n"), 1046 _("%s: option requires an argument -- '%c'\n"),
1062 argv[0], c); 1047 argv[0], c);
1063#endif 1048#endif
1064 } 1049 }
1065 d->optopt = c; 1050 d->optopt = c;
1066 if (optstring[0] == ':') 1051 if (optstring[0] == ':')
1067 c = ':'; 1052 c = ':';
1068 else 1053 else
1069 c = '?'; 1054 c = '?';
1070 } 1055 }
1071 else 1056 else
1072 /* We already incremented `optind' once; 1057 /* We already incremented `optind' once;
1073 increment it again when taking next ARGV-elt as argument. */ 1058 increment it again when taking next ARGV-elt as argument. */
1074 d->optarg = argv[d->optind++]; 1059 d->optarg = argv[d->optind++];
1075 d->__nextchar = NULL; 1060 d->__nextchar = NULL;
1076 } 1061 }
1077 } 1062 }
1078 return c; 1063 return c;
1079 } 1064 }
@@ -1081,16 +1066,17 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
1081 1066
1082int 1067int
1083_getopt_internal (int argc, char **argv, const char *optstring, 1068_getopt_internal (int argc, char **argv, const char *optstring,
1084 const struct option *longopts, int *longind, 1069 const struct option *longopts, int *longind, int long_only,
1085 int long_only, int posixly_correct) 1070 int posixly_correct)
1086{ 1071{
1087 int result; 1072 int result;
1088 1073
1089 getopt_data.optind = optind; 1074 getopt_data.optind = optind;
1090 getopt_data.opterr = opterr; 1075 getopt_data.opterr = opterr;
1091 1076
1092 result = _getopt_internal_r (argc, argv, optstring, longopts, longind, 1077 result = _getopt_internal_r (argc, argv, optstring, longopts,
1093 long_only, posixly_correct, &getopt_data); 1078 longind, long_only, &getopt_data,
1079 posixly_correct);
1094 1080
1095 optind = getopt_data.optind; 1081 optind = getopt_data.optind;
1096 optarg = getopt_data.optarg; 1082 optarg = getopt_data.optarg;
@@ -1110,10 +1096,23 @@ enum { POSIXLY_CORRECT = 1 };
1110int 1096int
1111getopt (int argc, char *const *argv, const char *optstring) 1097getopt (int argc, char *const *argv, const char *optstring)
1112{ 1098{
1113 return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0, 1099 return _getopt_internal (argc, (char **) argv, optstring,
1114 POSIXLY_CORRECT); 1100 (const struct option *) 0,
1101 (int *) 0,
1102 0, POSIXLY_CORRECT);
1115} 1103}
1116 1104
1105#ifdef _LIBC
1106int
1107__posix_getopt (int argc, char *const *argv, const char *optstring)
1108{
1109 return _getopt_internal (argc, argv, optstring,
1110 (const struct option *) 0,
1111 (int *) 0,
1112 0, 1);
1113}
1114#endif
1115
1117 1116
1118#ifdef TEST 1117#ifdef TEST
1119 1118
@@ -1132,51 +1131,51 @@ main (int argc, char **argv)
1132 1131
1133 c = getopt (argc, argv, "abc:d:0123456789"); 1132 c = getopt (argc, argv, "abc:d:0123456789");
1134 if (c == -1) 1133 if (c == -1)
1135 break; 1134 break;
1136 1135
1137 switch (c) 1136 switch (c)
1138 { 1137 {
1139 case '0': 1138 case '0':
1140 case '1': 1139 case '1':
1141 case '2': 1140 case '2':
1142 case '3': 1141 case '3':
1143 case '4': 1142 case '4':
1144 case '5': 1143 case '5':
1145 case '6': 1144 case '6':
1146 case '7': 1145 case '7':
1147 case '8': 1146 case '8':
1148 case '9': 1147 case '9':
1149 if (digit_optind != 0 && digit_optind != this_option_optind) 1148 if (digit_optind != 0 && digit_optind != this_option_optind)
1150 printf ("digits occur in two different argv-elements.\n"); 1149 printf ("digits occur in two different argv-elements.\n");
1151 digit_optind = this_option_optind; 1150 digit_optind = this_option_optind;
1152 printf ("option %c\n", c); 1151 printf ("option %c\n", c);
1153 break; 1152 break;
1154 1153
1155 case 'a': 1154 case 'a':
1156 printf ("option a\n"); 1155 printf ("option a\n");
1157 break; 1156 break;
1158 1157
1159 case 'b': 1158 case 'b':
1160 printf ("option b\n"); 1159 printf ("option b\n");
1161 break; 1160 break;
1162 1161
1163 case 'c': 1162 case 'c':
1164 printf ("option c with value `%s'\n", optarg); 1163 printf ("option c with value '%s'\n", optarg);
1165 break; 1164 break;
1166 1165
1167 case '?': 1166 case '?':
1168 break; 1167 break;
1169 1168
1170 default: 1169 default:
1171 printf ("?? getopt returned character code 0%o ??\n", c); 1170 printf ("?? getopt returned character code 0%o ??\n", c);
1172 } 1171 }
1173 } 1172 }
1174 1173
1175 if (optind < argc) 1174 if (optind < argc)
1176 { 1175 {
1177 printf ("non-option ARGV-elements: "); 1176 printf ("non-option ARGV-elements: ");
1178 while (optind < argc) 1177 while (optind < argc)
1179 printf ("%s ", argv[optind++]); 1178 printf ("%s ", argv[optind++]);
1180 printf ("\n"); 1179 printf ("\n");
1181 } 1180 }
1182 1181
diff --git a/gl/getopt.in.h b/gl/getopt.in.h
index d2d3e6e6..57a8e899 100644
--- a/gl/getopt.in.h
+++ b/gl/getopt.in.h
@@ -1,6 +1,6 @@
1/* Declarations for getopt. 1/* Declarations for getopt.
2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007 2 Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2010 Free Software
3 Free Software Foundation, Inc. 3 Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This program is free software: you can redistribute it and/or modify
@@ -16,24 +16,42 @@
16 You should have received a copy of the GNU General Public License 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/>. */ 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 18
19#ifndef _GETOPT_H 19#ifndef _GL_GETOPT_H
20
21#if __GNUC__ >= 3
22@PRAGMA_SYSTEM_HEADER@
23#endif
24
25/* The include_next requires a split double-inclusion guard. We must
26 also inform the replacement unistd.h to not recursively use
27 <getopt.h>; our definitions will be present soon enough. */
28#if @HAVE_GETOPT_H@
29# define _GL_SYSTEM_GETOPT
30# @INCLUDE_NEXT@ @NEXT_GETOPT_H@
31# undef _GL_SYSTEM_GETOPT
32#endif
33
34#ifndef _GL_GETOPT_H
20 35
21#ifndef __need_getopt 36#ifndef __need_getopt
22# define _GETOPT_H 1 37# define _GL_GETOPT_H 1
23#endif 38#endif
24 39
25/* Standalone applications should #define __GETOPT_PREFIX to an 40/* Standalone applications should #define __GETOPT_PREFIX to an
26 identifier that prefixes the external functions and variables 41 identifier that prefixes the external functions and variables
27 defined in this header. When this happens, include the 42 defined in this header. When this happens, include the
28 headers that might declare getopt so that they will not cause 43 headers that might declare getopt so that they will not cause
29 confusion if included after this file. Then systematically rename 44 confusion if included after this file (if the system had <getopt.h>,
45 we have already included it). Then systematically rename
30 identifiers so that they do not collide with the system functions 46 identifiers so that they do not collide with the system functions
31 and variables. Renaming avoids problems with some compilers and 47 and variables. Renaming avoids problems with some compilers and
32 linkers. */ 48 linkers. */
33#if defined __GETOPT_PREFIX && !defined __need_getopt 49#if defined __GETOPT_PREFIX && !defined __need_getopt
34# include <stdlib.h> 50# if !@HAVE_GETOPT_H@
35# include <stdio.h> 51# include <stdlib.h>
36# include <unistd.h> 52# include <stdio.h>
53# include <unistd.h>
54# endif
37# undef __need_getopt 55# undef __need_getopt
38# undef getopt 56# undef getopt
39# undef getopt_long 57# undef getopt_long
@@ -42,6 +60,7 @@
42# undef opterr 60# undef opterr
43# undef optind 61# undef optind
44# undef optopt 62# undef optopt
63# undef option
45# define __GETOPT_CONCAT(x, y) x ## y 64# define __GETOPT_CONCAT(x, y) x ## y
46# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) 65# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
47# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) 66# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
@@ -52,6 +71,8 @@
52# define opterr __GETOPT_ID (opterr) 71# define opterr __GETOPT_ID (opterr)
53# define optind __GETOPT_ID (optind) 72# define optind __GETOPT_ID (optind)
54# define optopt __GETOPT_ID (optopt) 73# define optopt __GETOPT_ID (optopt)
74# define option __GETOPT_ID (option)
75# define _getopt_internal __GETOPT_ID (getopt_internal)
55#endif 76#endif
56 77
57/* Standalone applications get correct prototypes for getopt_long and 78/* Standalone applications get correct prototypes for getopt_long and
@@ -94,12 +115,14 @@
94# define __GNUC_PREREQ(maj, min) (0) 115# define __GNUC_PREREQ(maj, min) (0)
95# endif 116# endif
96# if defined __cplusplus && __GNUC_PREREQ (2,8) 117# if defined __cplusplus && __GNUC_PREREQ (2,8)
97# define __THROW throw () 118# define __THROW throw ()
98# else 119# else
99# define __THROW 120# define __THROW
100# endif 121# endif
101#endif 122#endif
102 123
124/* The definition of _GL_ARG_NONNULL is copied here. */
125
103#ifdef __cplusplus 126#ifdef __cplusplus
104extern "C" { 127extern "C" {
105#endif 128#endif
@@ -142,9 +165,9 @@ extern int optopt;
142 zero. 165 zero.
143 166
144 The field `has_arg' is: 167 The field `has_arg' is:
145 no_argument (or 0) if the option does not take an argument, 168 no_argument (or 0) if the option does not take an argument,
146 required_argument (or 1) if the option requires an argument, 169 required_argument (or 1) if the option requires an argument,
147 optional_argument (or 2) if the option takes an optional argument. 170 optional_argument (or 2) if the option takes an optional argument.
148 171
149 If the field `flag' is not NULL, it points to a variable that is set 172 If the field `flag' is not NULL, it points to a variable that is set
150 to the value given in the field `val' when the option is found, but 173 to the value given in the field `val' when the option is found, but
@@ -169,10 +192,10 @@ struct option
169 192
170/* Names for the values of the `has_arg' field of `struct option'. */ 193/* Names for the values of the `has_arg' field of `struct option'. */
171 194
172# define no_argument 0 195# define no_argument 0
173# define required_argument 1 196# define required_argument 1
174# define optional_argument 2 197# define optional_argument 2
175#endif /* need getopt */ 198#endif /* need getopt */
176 199
177 200
178/* Get definitions and prototypes for functions to process the 201/* Get definitions and prototypes for functions to process the
@@ -201,17 +224,17 @@ struct option
201 the environment, then do not permute arguments. */ 224 the environment, then do not permute arguments. */
202 225
203extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) 226extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
204 __THROW; 227 __THROW _GL_ARG_NONNULL ((2, 3));
205 228
206#ifndef __need_getopt 229#ifndef __need_getopt
207extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, 230extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
208 const char *__shortopts, 231 const char *__shortopts,
209 const struct option *__longopts, int *__longind) 232 const struct option *__longopts, int *__longind)
210 __THROW; 233 __THROW _GL_ARG_NONNULL ((2, 3));
211extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, 234extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
212 const char *__shortopts, 235 const char *__shortopts,
213 const struct option *__longopts, int *__longind) 236 const struct option *__longopts, int *__longind)
214 __THROW; 237 __THROW _GL_ARG_NONNULL ((2, 3));
215 238
216#endif 239#endif
217 240
@@ -223,3 +246,4 @@ extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
223#undef __need_getopt 246#undef __need_getopt
224 247
225#endif /* getopt.h */ 248#endif /* getopt.h */
249#endif /* getopt.h */
diff --git a/gl/getopt1.c b/gl/getopt1.c
index ba115c47..046d69f9 100644
--- a/gl/getopt1.c
+++ b/gl/getopt1.c
@@ -1,6 +1,6 @@
1/* getopt_long and getopt_long_only entry points for GNU getopt. 1/* getopt_long and getopt_long_only entry points for GNU getopt.
2 Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006,2009 2 Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
3 Free Software Foundation, Inc. 3 1998, 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This program is free software: you can redistribute it and/or modify
@@ -32,25 +32,25 @@
32#include <stdlib.h> 32#include <stdlib.h>
33#endif 33#endif
34 34
35#ifndef NULL 35#ifndef NULL
36#define NULL 0 36#define NULL 0
37#endif 37#endif
38 38
39int 39int
40getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, 40getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
41 const struct option *long_options, int *opt_index) 41 const struct option *long_options, int *opt_index)
42{ 42{
43 return _getopt_internal (argc, (char **) argv, options, long_options, 43 return _getopt_internal (argc, (char **) argv, options, long_options,
44 opt_index, 0, 0); 44 opt_index, 0, 0);
45} 45}
46 46
47int 47int
48_getopt_long_r (int argc, char **argv, const char *options, 48_getopt_long_r (int argc, char **argv, const char *options,
49 const struct option *long_options, int *opt_index, 49 const struct option *long_options, int *opt_index,
50 struct _getopt_data *d) 50 struct _getopt_data *d)
51{ 51{
52 return _getopt_internal_r (argc, argv, options, long_options, opt_index, 52 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
53 0, 0, d); 53 0, d, 0);
54} 54}
55 55
56/* Like getopt_long, but '-' as well as '--' can indicate a long option. 56/* Like getopt_long, but '-' as well as '--' can indicate a long option.
@@ -60,20 +60,20 @@ _getopt_long_r (int argc, char **argv, const char *options,
60 60
61int 61int
62getopt_long_only (int argc, char *__getopt_argv_const *argv, 62getopt_long_only (int argc, char *__getopt_argv_const *argv,
63 const char *options, 63 const char *options,
64 const struct option *long_options, int *opt_index) 64 const struct option *long_options, int *opt_index)
65{ 65{
66 return _getopt_internal (argc, (char **) argv, options, long_options, 66 return _getopt_internal (argc, (char **) argv, options, long_options,
67 opt_index, 1, 0); 67 opt_index, 1, 0);
68} 68}
69 69
70int 70int
71_getopt_long_only_r (int argc, char **argv, const char *options, 71_getopt_long_only_r (int argc, char **argv, const char *options,
72 const struct option *long_options, int *opt_index, 72 const struct option *long_options, int *opt_index,
73 struct _getopt_data *d) 73 struct _getopt_data *d)
74{ 74{
75 return _getopt_internal_r (argc, argv, options, long_options, opt_index, 75 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
76 1, 0, d); 76 1, d, 0);
77} 77}
78 78
79 79
@@ -93,74 +93,74 @@ main (int argc, char **argv)
93 int option_index = 0; 93 int option_index = 0;
94 static const struct option long_options[] = 94 static const struct option long_options[] =
95 { 95 {
96 {"add", 1, 0, 0}, 96 {"add", 1, 0, 0},
97 {"append", 0, 0, 0}, 97 {"append", 0, 0, 0},
98 {"delete", 1, 0, 0}, 98 {"delete", 1, 0, 0},
99 {"verbose", 0, 0, 0}, 99 {"verbose", 0, 0, 0},
100 {"create", 0, 0, 0}, 100 {"create", 0, 0, 0},
101 {"file", 1, 0, 0}, 101 {"file", 1, 0, 0},
102 {0, 0, 0, 0} 102 {0, 0, 0, 0}
103 }; 103 };
104 104
105 c = getopt_long (argc, argv, "abc:d:0123456789", 105 c = getopt_long (argc, argv, "abc:d:0123456789",
106 long_options, &option_index); 106 long_options, &option_index);
107 if (c == -1) 107 if (c == -1)
108 break; 108 break;
109 109
110 switch (c) 110 switch (c)
111 { 111 {
112 case 0: 112 case 0:
113 printf ("option %s", long_options[option_index].name); 113 printf ("option %s", long_options[option_index].name);
114 if (optarg) 114 if (optarg)
115 printf (" with arg %s", optarg); 115 printf (" with arg %s", optarg);
116 printf ("\n"); 116 printf ("\n");
117 break; 117 break;
118 118
119 case '0': 119 case '0':
120 case '1': 120 case '1':
121 case '2': 121 case '2':
122 case '3': 122 case '3':
123 case '4': 123 case '4':
124 case '5': 124 case '5':
125 case '6': 125 case '6':
126 case '7': 126 case '7':
127 case '8': 127 case '8':
128 case '9': 128 case '9':
129 if (digit_optind != 0 && digit_optind != this_option_optind) 129 if (digit_optind != 0 && digit_optind != this_option_optind)
130 printf ("digits occur in two different argv-elements.\n"); 130 printf ("digits occur in two different argv-elements.\n");
131 digit_optind = this_option_optind; 131 digit_optind = this_option_optind;
132 printf ("option %c\n", c); 132 printf ("option %c\n", c);
133 break; 133 break;
134 134
135 case 'a': 135 case 'a':
136 printf ("option a\n"); 136 printf ("option a\n");
137 break; 137 break;
138 138
139 case 'b': 139 case 'b':
140 printf ("option b\n"); 140 printf ("option b\n");
141 break; 141 break;
142 142
143 case 'c': 143 case 'c':
144 printf ("option c with value `%s'\n", optarg); 144 printf ("option c with value `%s'\n", optarg);
145 break; 145 break;
146 146
147 case 'd': 147 case 'd':
148 printf ("option d with value `%s'\n", optarg); 148 printf ("option d with value `%s'\n", optarg);
149 break; 149 break;
150 150
151 case '?': 151 case '?':
152 break; 152 break;
153 153
154 default: 154 default:
155 printf ("?? getopt returned character code 0%o ??\n", c); 155 printf ("?? getopt returned character code 0%o ??\n", c);
156 } 156 }
157 } 157 }
158 158
159 if (optind < argc) 159 if (optind < argc)
160 { 160 {
161 printf ("non-option ARGV-elements: "); 161 printf ("non-option ARGV-elements: ");
162 while (optind < argc) 162 while (optind < argc)
163 printf ("%s ", argv[optind++]); 163 printf ("%s ", argv[optind++]);
164 printf ("\n"); 164 printf ("\n");
165 } 165 }
166 166
diff --git a/gl/getopt_int.h b/gl/getopt_int.h
index 3c6628bb..169def5b 100644
--- a/gl/getopt_int.h
+++ b/gl/getopt_int.h
@@ -1,6 +1,6 @@
1/* Internal declarations for getopt. 1/* Internal declarations for getopt.
2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004 2 Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2010 Free Software
3 Free Software Foundation, Inc. 3 Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This program is free software: you can redistribute it and/or modify
@@ -17,12 +17,14 @@
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 18
19#ifndef _GETOPT_INT_H 19#ifndef _GETOPT_INT_H
20#define _GETOPT_INT_H 1 20#define _GETOPT_INT_H 1
21
22#include <getopt.h>
21 23
22extern int _getopt_internal (int ___argc, char **___argv, 24extern int _getopt_internal (int ___argc, char **___argv,
23 const char *__shortopts, 25 const char *__shortopts,
24 const struct option *__longopts, int *__longind, 26 const struct option *__longopts, int *__longind,
25 int __long_only, int __posixly_correct); 27 int __long_only, int __posixly_correct);
26 28
27 29
28/* Reentrant versions which can handle parsing multiple argument 30/* Reentrant versions which can handle parsing multiple argument
@@ -108,23 +110,23 @@ struct _getopt_data
108 110
109/* The initializer is necessary to set OPTIND and OPTERR to their 111/* The initializer is necessary to set OPTIND and OPTERR to their
110 default values and to clear the initialization flag. */ 112 default values and to clear the initialization flag. */
111#define _GETOPT_DATA_INITIALIZER { 1, 1 } 113#define _GETOPT_DATA_INITIALIZER { 1, 1 }
112 114
113extern int _getopt_internal_r (int ___argc, char **___argv, 115extern int _getopt_internal_r (int ___argc, char **___argv,
114 const char *__shortopts, 116 const char *__shortopts,
115 const struct option *__longopts, int *__longind, 117 const struct option *__longopts, int *__longind,
116 int __long_only, int __posixly_correct, 118 int __long_only, struct _getopt_data *__data,
117 struct _getopt_data *__data); 119 int __posixly_correct);
118 120
119extern int _getopt_long_r (int ___argc, char **___argv, 121extern int _getopt_long_r (int ___argc, char **___argv,
120 const char *__shortopts, 122 const char *__shortopts,
121 const struct option *__longopts, int *__longind, 123 const struct option *__longopts, int *__longind,
122 struct _getopt_data *__data); 124 struct _getopt_data *__data);
123 125
124extern int _getopt_long_only_r (int ___argc, char **___argv, 126extern int _getopt_long_only_r (int ___argc, char **___argv,
125 const char *__shortopts, 127 const char *__shortopts,
126 const struct option *__longopts, 128 const struct option *__longopts,
127 int *__longind, 129 int *__longind,
128 struct _getopt_data *__data); 130 struct _getopt_data *__data);
129 131
130#endif /* getopt_int.h */ 132#endif /* getopt_int.h */
diff --git a/gl/gettext.h b/gl/gettext.h
index 8cf2dca0..881ae330 100644
--- a/gl/gettext.h
+++ b/gl/gettext.h
@@ -1,5 +1,6 @@
1/* Convenience header for conditional use of GNU <libintl.h>. 1/* Convenience header for conditional use of GNU <libintl.h>.
2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009 Free Software Foundation, Inc. 2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2010 Free Software
3 Foundation, Inc.
3 4
4 This program is free software; you can redistribute it and/or modify 5 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 it under the terms of the GNU General Public License as published by
@@ -80,7 +81,7 @@
80 ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) 81 ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
81# undef dcngettext 82# undef dcngettext
82# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 83# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
83 ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) 84 ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
84# undef textdomain 85# undef textdomain
85# define textdomain(Domainname) ((const char *) (Domainname)) 86# define textdomain(Domainname) ((const char *) (Domainname))
86# undef bindtextdomain 87# undef bindtextdomain
@@ -140,8 +141,8 @@ inline
140#endif 141#endif
141static const char * 142static const char *
142pgettext_aux (const char *domain, 143pgettext_aux (const char *domain,
143 const char *msg_ctxt_id, const char *msgid, 144 const char *msg_ctxt_id, const char *msgid,
144 int category) 145 int category)
145{ 146{
146 const char *translation = dcgettext (domain, msg_ctxt_id, category); 147 const char *translation = dcgettext (domain, msg_ctxt_id, category);
147 if (translation == msg_ctxt_id) 148 if (translation == msg_ctxt_id)
@@ -159,9 +160,9 @@ inline
159#endif 160#endif
160static const char * 161static const char *
161npgettext_aux (const char *domain, 162npgettext_aux (const char *domain,
162 const char *msg_ctxt_id, const char *msgid, 163 const char *msg_ctxt_id, const char *msgid,
163 const char *msgid_plural, unsigned long int n, 164 const char *msgid_plural, unsigned long int n,
164 int category) 165 int category)
165{ 166{
166 const char *translation = 167 const char *translation =
167 dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 168 dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
@@ -199,8 +200,8 @@ inline
199#endif 200#endif
200static const char * 201static const char *
201dcpgettext_expr (const char *domain, 202dcpgettext_expr (const char *domain,
202 const char *msgctxt, const char *msgid, 203 const char *msgctxt, const char *msgid,
203 int category) 204 int category)
204{ 205{
205 size_t msgctxt_len = strlen (msgctxt) + 1; 206 size_t msgctxt_len = strlen (msgctxt) + 1;
206 size_t msgid_len = strlen (msgid) + 1; 207 size_t msgid_len = strlen (msgid) + 1;
@@ -222,10 +223,10 @@ dcpgettext_expr (const char *domain,
222 translation = dcgettext (domain, msg_ctxt_id, category); 223 translation = dcgettext (domain, msg_ctxt_id, category);
223#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 224#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
224 if (msg_ctxt_id != buf) 225 if (msg_ctxt_id != buf)
225 free (msg_ctxt_id); 226 free (msg_ctxt_id);
226#endif 227#endif
227 if (translation != msg_ctxt_id) 228 if (translation != msg_ctxt_id)
228 return translation; 229 return translation;
229 } 230 }
230 return msgid; 231 return msgid;
231} 232}
@@ -244,9 +245,9 @@ inline
244#endif 245#endif
245static const char * 246static const char *
246dcnpgettext_expr (const char *domain, 247dcnpgettext_expr (const char *domain,
247 const char *msgctxt, const char *msgid, 248 const char *msgctxt, const char *msgid,
248 const char *msgid_plural, unsigned long int n, 249 const char *msgid_plural, unsigned long int n,
249 int category) 250 int category)
250{ 251{
251 size_t msgctxt_len = strlen (msgctxt) + 1; 252 size_t msgctxt_len = strlen (msgctxt) + 1;
252 size_t msgid_len = strlen (msgid) + 1; 253 size_t msgid_len = strlen (msgid) + 1;
@@ -268,10 +269,10 @@ dcnpgettext_expr (const char *domain,
268 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 269 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
269#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 270#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
270 if (msg_ctxt_id != buf) 271 if (msg_ctxt_id != buf)
271 free (msg_ctxt_id); 272 free (msg_ctxt_id);
272#endif 273#endif
273 if (!(translation == msg_ctxt_id || translation == msgid_plural)) 274 if (!(translation == msg_ctxt_id || translation == msgid_plural))
274 return translation; 275 return translation;
275 } 276 }
276 return (n == 1 ? msgid : msgid_plural); 277 return (n == 1 ? msgid : msgid_plural);
277} 278}
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c
index be091ff9..baaa23f8 100644
--- a/gl/inet_ntop.c
+++ b/gl/inet_ntop.c
@@ -1,6 +1,6 @@
1/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form 1/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form
2 2
3 Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2008-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -42,10 +42,6 @@
42#include <string.h> 42#include <string.h>
43#include <errno.h> 43#include <errno.h>
44 44
45#ifndef EAFNOSUPPORT
46# define EAFNOSUPPORT EINVAL
47#endif
48
49#define NS_IN6ADDRSZ 16 45#define NS_IN6ADDRSZ 16
50#define NS_INT16SZ 2 46#define NS_INT16SZ 2
51 47
@@ -63,15 +59,15 @@ static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t si
63 59
64/* char * 60/* char *
65 * inet_ntop(af, src, dst, size) 61 * inet_ntop(af, src, dst, size)
66 * convert a network format address to presentation format. 62 * convert a network format address to presentation format.
67 * return: 63 * return:
68 * pointer to presentation format address (`dst'), or NULL (see errno). 64 * pointer to presentation format address (`dst'), or NULL (see errno).
69 * author: 65 * author:
70 * Paul Vixie, 1996. 66 * Paul Vixie, 1996.
71 */ 67 */
72const char * 68const char *
73inet_ntop (int af, const void *restrict src, 69inet_ntop (int af, const void *restrict src,
74 char *restrict dst, socklen_t cnt) 70 char *restrict dst, socklen_t cnt)
75{ 71{
76 switch (af) 72 switch (af)
77 { 73 {
@@ -94,14 +90,14 @@ inet_ntop (int af, const void *restrict src,
94 90
95/* const char * 91/* const char *
96 * inet_ntop4(src, dst, size) 92 * inet_ntop4(src, dst, size)
97 * format an IPv4 address 93 * format an IPv4 address
98 * return: 94 * return:
99 * `dst' (as a const) 95 * `dst' (as a const)
100 * notes: 96 * notes:
101 * (1) uses no statics 97 * (1) uses no statics
102 * (2) takes a u_char* not an in_addr as input 98 * (2) takes a u_char* not an in_addr as input
103 * author: 99 * author:
104 * Paul Vixie, 1996. 100 * Paul Vixie, 1996.
105 */ 101 */
106static const char * 102static const char *
107inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) 103inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
@@ -126,9 +122,9 @@ inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
126 122
127/* const char * 123/* const char *
128 * inet_ntop6(src, dst, size) 124 * inet_ntop6(src, dst, size)
129 * convert IPv6 binary address into presentation (printable) format 125 * convert IPv6 binary address into presentation (printable) format
130 * author: 126 * author:
131 * Paul Vixie, 1996. 127 * Paul Vixie, 1996.
132 */ 128 */
133static const char * 129static const char *
134inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) 130inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
@@ -161,26 +157,26 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
161 for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) 157 for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
162 { 158 {
163 if (words[i] == 0) 159 if (words[i] == 0)
164 { 160 {
165 if (cur.base == -1) 161 if (cur.base == -1)
166 cur.base = i, cur.len = 1; 162 cur.base = i, cur.len = 1;
167 else 163 else
168 cur.len++; 164 cur.len++;
169 } 165 }
170 else 166 else
171 { 167 {
172 if (cur.base != -1) 168 if (cur.base != -1)
173 { 169 {
174 if (best.base == -1 || cur.len > best.len) 170 if (best.base == -1 || cur.len > best.len)
175 best = cur; 171 best = cur;
176 cur.base = -1; 172 cur.base = -1;
177 } 173 }
178 } 174 }
179 } 175 }
180 if (cur.base != -1) 176 if (cur.base != -1)
181 { 177 {
182 if (best.base == -1 || cur.len > best.len) 178 if (best.base == -1 || cur.len > best.len)
183 best = cur; 179 best = cur;
184 } 180 }
185 if (best.base != -1 && best.len < 2) 181 if (best.base != -1 && best.len < 2)
186 best.base = -1; 182 best.base = -1;
@@ -193,28 +189,28 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
193 { 189 {
194 /* Are we inside the best run of 0x00's? */ 190 /* Are we inside the best run of 0x00's? */
195 if (best.base != -1 && i >= best.base && i < (best.base + best.len)) 191 if (best.base != -1 && i >= best.base && i < (best.base + best.len))
196 { 192 {
197 if (i == best.base) 193 if (i == best.base)
198 *tp++ = ':'; 194 *tp++ = ':';
199 continue; 195 continue;
200 } 196 }
201 /* Are we following an initial run of 0x00s or any real hex? */ 197 /* Are we following an initial run of 0x00s or any real hex? */
202 if (i != 0) 198 if (i != 0)
203 *tp++ = ':'; 199 *tp++ = ':';
204 /* Is this address an encapsulated IPv4? */ 200 /* Is this address an encapsulated IPv4? */
205 if (i == 6 && best.base == 0 && 201 if (i == 6 && best.base == 0 &&
206 (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) 202 (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
207 { 203 {
208 if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) 204 if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp)))
209 return (NULL); 205 return (NULL);
210 tp += strlen (tp); 206 tp += strlen (tp);
211 break; 207 break;
212 } 208 }
213 { 209 {
214 int len = sprintf (tp, "%x", words[i]); 210 int len = sprintf (tp, "%x", words[i]);
215 if (len < 0) 211 if (len < 0)
216 return NULL; 212 return NULL;
217 tp += len; 213 tp += len;
218 } 214 }
219 } 215 }
220 /* Was it a trailing run of 0x00's? */ 216 /* Was it a trailing run of 0x00's? */
diff --git a/gl/intprops.h b/gl/intprops.h
index 002161ee..46f4d47d 100644
--- a/gl/intprops.h
+++ b/gl/intprops.h
@@ -1,6 +1,7 @@
1/* intprops.h -- properties of integer types 1/* intprops.h -- properties of integer types
2 2
3 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009, 2010 Free Software
4 Foundation, Inc.
4 5
5 This program is free software: you can redistribute it and/or modify 6 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 it under the terms of the GNU General Public License as published by
@@ -17,40 +18,43 @@
17 18
18/* Written by Paul Eggert. */ 19/* Written by Paul Eggert. */
19 20
20#include <limits.h> 21#ifndef GL_INTPROPS_H
22# define GL_INTPROPS_H
23
24# include <limits.h>
21 25
22/* The extra casts in the following macros work around compiler bugs, 26/* The extra casts in the following macros work around compiler bugs,
23 e.g., in Cray C 5.0.3.0. */ 27 e.g., in Cray C 5.0.3.0. */
24 28
25/* True if the arithmetic type T is an integer type. bool counts as 29/* True if the arithmetic type T is an integer type. bool counts as
26 an integer. */ 30 an integer. */
27#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) 31# define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
28 32
29/* True if negative values of the signed integer type T use two's 33/* True if negative values of the signed integer type T use two's
30 complement, ones' complement, or signed magnitude representation, 34 complement, ones' complement, or signed magnitude representation,
31 respectively. Much GNU code assumes two's complement, but some 35 respectively. Much GNU code assumes two's complement, but some
32 people like to be portable to all possible C hosts. */ 36 people like to be portable to all possible C hosts. */
33#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1) 37# define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
34#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0) 38# define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
35#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1) 39# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
36 40
37/* True if the arithmetic type T is signed. */ 41/* True if the arithmetic type T is signed. */
38#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) 42# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
39 43
40/* The maximum and minimum values for the integer type T. These 44/* The maximum and minimum values for the integer type T. These
41 macros have undefined behavior if T is signed and has padding bits. 45 macros have undefined behavior if T is signed and has padding bits.
42 If this is a problem for you, please let us know how to fix it for 46 If this is a problem for you, please let us know how to fix it for
43 your host. */ 47 your host. */
44#define TYPE_MINIMUM(t) \ 48# define TYPE_MINIMUM(t) \
45 ((t) (! TYPE_SIGNED (t) \ 49 ((t) (! TYPE_SIGNED (t) \
46 ? (t) 0 \ 50 ? (t) 0 \
47 : TYPE_SIGNED_MAGNITUDE (t) \ 51 : TYPE_SIGNED_MAGNITUDE (t) \
48 ? ~ (t) 0 \ 52 ? ~ (t) 0 \
49 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) 53 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
50#define TYPE_MAXIMUM(t) \ 54# define TYPE_MAXIMUM(t) \
51 ((t) (! TYPE_SIGNED (t) \ 55 ((t) (! TYPE_SIGNED (t) \
52 ? (t) -1 \ 56 ? (t) -1 \
53 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) 57 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
54 58
55/* Return zero if T can be determined to be an unsigned type. 59/* Return zero if T can be determined to be an unsigned type.
56 Otherwise, return 1. 60 Otherwise, return 1.
@@ -58,20 +62,22 @@
58 tighter bound. Otherwise, it overestimates the true bound by one byte 62 tighter bound. Otherwise, it overestimates the true bound by one byte
59 when applied to unsigned types of size 2, 4, 16, ... bytes. 63 when applied to unsigned types of size 2, 4, 16, ... bytes.
60 The symbol signed_type_or_expr__ is private to this header file. */ 64 The symbol signed_type_or_expr__ is private to this header file. */
61#if __GNUC__ >= 2 65# if __GNUC__ >= 2
62# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t)) 66# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
63#else 67# else
64# define signed_type_or_expr__(t) 1 68# define signed_type_or_expr__(t) 1
65#endif 69# endif
66 70
67/* Bound on length of the string representing an integer type or expression T. 71/* Bound on length of the string representing an integer type or expression T.
68 Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485; 72 Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
69 add 1 for integer division truncation; add 1 more for a minus sign 73 add 1 for integer division truncation; add 1 more for a minus sign
70 if needed. */ 74 if needed. */
71#define INT_STRLEN_BOUND(t) \ 75# define INT_STRLEN_BOUND(t) \
72 ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \ 76 ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
73 + signed_type_or_expr__ (t) + 1) 77 + signed_type_or_expr__ (t) + 1)
74 78
75/* Bound on buffer size needed to represent an integer type or expression T, 79/* Bound on buffer size needed to represent an integer type or expression T,
76 including the terminating null. */ 80 including the terminating null. */
77#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) 81# define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
82
83#endif /* GL_INTPROPS_H */
diff --git a/gl/langinfo.in.h b/gl/langinfo.in.h
new file mode 100644
index 00000000..0865d96c
--- /dev/null
+++ b/gl/langinfo.in.h
@@ -0,0 +1,162 @@
1/* Substitute for and wrapper around <langinfo.h>.
2 Copyright (C) 2009, 2010 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, or (at your option)
7 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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18/*
19 * POSIX <langinfo.h> for platforms that lack it or have an incomplete one.
20 * <http://www.opengroup.org/onlinepubs/9699919799/basedefs/langinfo.h.html>
21 */
22
23#ifndef _GL_LANGINFO_H
24
25#if __GNUC__ >= 3
26@PRAGMA_SYSTEM_HEADER@
27#endif
28
29/* The include_next requires a split double-inclusion guard. */
30#if @HAVE_LANGINFO_H@
31# @INCLUDE_NEXT@ @NEXT_LANGINFO_H@
32#endif
33
34#ifndef _GL_LANGINFO_H
35#define _GL_LANGINFO_H
36
37
38#if !@HAVE_LANGINFO_H@
39
40/* A platform that lacks <langinfo.h>. */
41
42/* Assume that it also lacks <nl_types.h> and the nl_item type. */
43typedef int nl_item;
44
45/* nl_langinfo items of the LC_CTYPE category */
46# define CODESET 10000
47/* nl_langinfo items of the LC_NUMERIC category */
48# define RADIXCHAR 10001
49# define THOUSEP 10002
50/* nl_langinfo items of the LC_TIME category */
51# define D_T_FMT 10003
52# define D_FMT 10004
53# define T_FMT 10005
54# define T_FMT_AMPM 10006
55# define AM_STR 10007
56# define PM_STR 10008
57# define DAY_1 10009
58# define DAY_2 (DAY_1 + 1)
59# define DAY_3 (DAY_1 + 2)
60# define DAY_4 (DAY_1 + 3)
61# define DAY_5 (DAY_1 + 4)
62# define DAY_6 (DAY_1 + 5)
63# define DAY_7 (DAY_1 + 6)
64# define ABDAY_1 10016
65# define ABDAY_2 (ABDAY_1 + 1)
66# define ABDAY_3 (ABDAY_1 + 2)
67# define ABDAY_4 (ABDAY_1 + 3)
68# define ABDAY_5 (ABDAY_1 + 4)
69# define ABDAY_6 (ABDAY_1 + 5)
70# define ABDAY_7 (ABDAY_1 + 6)
71# define MON_1 10023
72# define MON_2 (MON_1 + 1)
73# define MON_3 (MON_1 + 2)
74# define MON_4 (MON_1 + 3)
75# define MON_5 (MON_1 + 4)
76# define MON_6 (MON_1 + 5)
77# define MON_7 (MON_1 + 6)
78# define MON_8 (MON_1 + 7)
79# define MON_9 (MON_1 + 8)
80# define MON_10 (MON_1 + 9)
81# define MON_11 (MON_1 + 10)
82# define MON_12 (MON_1 + 11)
83# define ABMON_1 10035
84# define ABMON_2 (ABMON_1 + 1)
85# define ABMON_3 (ABMON_1 + 2)
86# define ABMON_4 (ABMON_1 + 3)
87# define ABMON_5 (ABMON_1 + 4)
88# define ABMON_6 (ABMON_1 + 5)
89# define ABMON_7 (ABMON_1 + 6)
90# define ABMON_8 (ABMON_1 + 7)
91# define ABMON_9 (ABMON_1 + 8)
92# define ABMON_10 (ABMON_1 + 9)
93# define ABMON_11 (ABMON_1 + 10)
94# define ABMON_12 (ABMON_1 + 11)
95# define ERA 10047
96# define ERA_D_FMT 10048
97# define ERA_D_T_FMT 10049
98# define ERA_T_FMT 10050
99# define ALT_DIGITS 10051
100/* nl_langinfo items of the LC_MONETARY category */
101# define CRNCYSTR 10052
102/* nl_langinfo items of the LC_MESSAGES category */
103# define YESEXPR 10053
104# define NOEXPR 10054
105
106#else
107
108/* A platform that has <langinfo.h>. */
109
110# if !@HAVE_LANGINFO_CODESET@
111# define CODESET 10000
112# define GNULIB_defined_CODESET 1
113# endif
114
115# if !@HAVE_LANGINFO_ERA@
116# define ERA 10047
117# define ERA_D_FMT 10048
118# define ERA_D_T_FMT 10049
119# define ERA_T_FMT 10050
120# define ALT_DIGITS 10051
121# define GNULIB_defined_ERA 1
122# endif
123
124#endif
125
126/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
127
128/* The definition of _GL_WARN_ON_USE is copied here. */
129
130/* Declare overridden functions. */
131
132
133/* Return a piece of locale dependent information.
134 Note: The difference between nl_langinfo (CODESET) and locale_charset ()
135 is that the latter normalizes the encoding names to GNU conventions. */
136
137#if @GNULIB_NL_LANGINFO@
138# if @REPLACE_NL_LANGINFO@
139# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
140# undef nl_langinfo
141# define nl_langinfo rpl_nl_langinfo
142# endif
143_GL_FUNCDECL_RPL (nl_langinfo, char *, (nl_item item));
144_GL_CXXALIAS_RPL (nl_langinfo, char *, (nl_item item));
145# else
146# if !@HAVE_NL_LANGINFO@
147_GL_FUNCDECL_SYS (nl_langinfo, char *, (nl_item item));
148# endif
149_GL_CXXALIAS_SYS (nl_langinfo, char *, (nl_item item));
150# endif
151_GL_CXXALIASWARN (nl_langinfo);
152#elif defined GNULIB_POSIXCHECK
153# undef nl_langinfo
154# if HAVE_RAW_DECL_NL_LANGINFO
155_GL_WARN_ON_USE (nl_langinfo, "nl_langinfo is not portable - "
156 "use gnulib module nl_langinfo for portability");
157# endif
158#endif
159
160
161#endif /* _GL_LANGINFO_H */
162#endif /* _GL_LANGINFO_H */
diff --git a/gl/localcharset.c b/gl/localcharset.c
index a7ca94c1..a04dc446 100644
--- a/gl/localcharset.c
+++ b/gl/localcharset.c
@@ -1,6 +1,6 @@
1/* Determine a canonical name for the current locale's character encoding. 1/* Determine a canonical name for the current locale's character encoding.
2 2
3 Copyright (C) 2000-2006, 2008-2009 Free Software Foundation, Inc. 3 Copyright (C) 2000-2006, 2008-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
23/* Specification. */ 23/* Specification. */
24#include "localcharset.h" 24#include "localcharset.h"
25 25
26#include <fcntl.h>
26#include <stddef.h> 27#include <stddef.h>
27#include <stdio.h> 28#include <stdio.h>
28#include <string.h> 29#include <string.h>
@@ -44,6 +45,7 @@
44#endif 45#endif
45 46
46#if !defined WIN32_NATIVE 47#if !defined WIN32_NATIVE
48# include <unistd.h>
47# if HAVE_LANGINFO_CODESET 49# if HAVE_LANGINFO_CODESET
48# include <langinfo.h> 50# include <langinfo.h>
49# else 51# else
@@ -75,6 +77,11 @@
75# include "configmake.h" 77# include "configmake.h"
76#endif 78#endif
77 79
80/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */
81#ifndef O_NOFOLLOW
82# define O_NOFOLLOW 0
83#endif
84
78#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ 85#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
79 /* Win32, Cygwin, OS/2, DOS */ 86 /* Win32, Cygwin, OS/2, DOS */
80# define ISSLASH(C) ((C) == '/' || (C) == '\\') 87# define ISSLASH(C) ((C) == '/' || (C) == '\\')
@@ -117,192 +124,219 @@ get_charset_aliases (void)
117 if (cp == NULL) 124 if (cp == NULL)
118 { 125 {
119#if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) 126#if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
120 FILE *fp;
121 const char *dir; 127 const char *dir;
122 const char *base = "charset.alias"; 128 const char *base = "charset.alias";
123 char *file_name; 129 char *file_name;
124 130
125 /* Make it possible to override the charset.alias location. This is 131 /* Make it possible to override the charset.alias location. This is
126 necessary for running the testsuite before "make install". */ 132 necessary for running the testsuite before "make install". */
127 dir = getenv ("CHARSETALIASDIR"); 133 dir = getenv ("CHARSETALIASDIR");
128 if (dir == NULL || dir[0] == '\0') 134 if (dir == NULL || dir[0] == '\0')
129 dir = relocate (LIBDIR); 135 dir = relocate (LIBDIR);
130 136
131 /* Concatenate dir and base into freshly allocated file_name. */ 137 /* Concatenate dir and base into freshly allocated file_name. */
132 { 138 {
133 size_t dir_len = strlen (dir); 139 size_t dir_len = strlen (dir);
134 size_t base_len = strlen (base); 140 size_t base_len = strlen (base);
135 int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); 141 int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
136 file_name = (char *) malloc (dir_len + add_slash + base_len + 1); 142 file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
137 if (file_name != NULL) 143 if (file_name != NULL)
138 { 144 {
139 memcpy (file_name, dir, dir_len); 145 memcpy (file_name, dir, dir_len);
140 if (add_slash) 146 if (add_slash)
141 file_name[dir_len] = DIRECTORY_SEPARATOR; 147 file_name[dir_len] = DIRECTORY_SEPARATOR;
142 memcpy (file_name + dir_len + add_slash, base, base_len + 1); 148 memcpy (file_name + dir_len + add_slash, base, base_len + 1);
143 } 149 }
144 } 150 }
145 151
146 if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL) 152 if (file_name == NULL)
147 /* Out of memory or file not found, treat it as empty. */ 153 /* Out of memory. Treat the file as empty. */
148 cp = ""; 154 cp = "";
149 else 155 else
150 { 156 {
151 /* Parse the file's contents. */ 157 int fd;
152 char *res_ptr = NULL; 158
153 size_t res_size = 0; 159 /* Open the file. Reject symbolic links on platforms that support
154 160 O_NOFOLLOW. This is a security feature. Without it, an attacker
155 for (;;) 161 could retrieve parts of the contents (namely, the tail of the
156 { 162 first line that starts with "* ") of an arbitrary file by placing
157 int c; 163 a symbolic link to that file under the name "charset.alias" in
158 char buf1[50+1]; 164 some writable directory and defining the environment variable
159 char buf2[50+1]; 165 CHARSETALIASDIR to point to that directory. */
160 size_t l1, l2; 166 fd = open (file_name,
161 char *old_res_ptr; 167 O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0));
162 168 if (fd < 0)
163 c = getc (fp); 169 /* File not found. Treat it as empty. */
164 if (c == EOF) 170 cp = "";
165 break; 171 else
166 if (c == '\n' || c == ' ' || c == '\t') 172 {
167 continue; 173 FILE *fp;
168 if (c == '#') 174
169 { 175 fp = fdopen (fd, "r");
170 /* Skip comment, to end of line. */ 176 if (fp == NULL)
171 do 177 {
172 c = getc (fp); 178 /* Out of memory. Treat the file as empty. */
173 while (!(c == EOF || c == '\n')); 179 close (fd);
174 if (c == EOF) 180 cp = "";
175 break; 181 }
176 continue; 182 else
177 } 183 {
178 ungetc (c, fp); 184 /* Parse the file's contents. */
179 if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) 185 char *res_ptr = NULL;
180 break; 186 size_t res_size = 0;
181 l1 = strlen (buf1); 187
182 l2 = strlen (buf2); 188 for (;;)
183 old_res_ptr = res_ptr; 189 {
184 if (res_size == 0) 190 int c;
185 { 191 char buf1[50+1];
186 res_size = l1 + 1 + l2 + 1; 192 char buf2[50+1];
187 res_ptr = (char *) malloc (res_size + 1); 193 size_t l1, l2;
188 } 194 char *old_res_ptr;
189 else 195
190 { 196 c = getc (fp);
191 res_size += l1 + 1 + l2 + 1; 197 if (c == EOF)
192 res_ptr = (char *) realloc (res_ptr, res_size + 1); 198 break;
193 } 199 if (c == '\n' || c == ' ' || c == '\t')
194 if (res_ptr == NULL) 200 continue;
195 { 201 if (c == '#')
196 /* Out of memory. */ 202 {
197 res_size = 0; 203 /* Skip comment, to end of line. */
198 if (old_res_ptr != NULL) 204 do
199 free (old_res_ptr); 205 c = getc (fp);
200 break; 206 while (!(c == EOF || c == '\n'));
201 } 207 if (c == EOF)
202 strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); 208 break;
203 strcpy (res_ptr + res_size - (l2 + 1), buf2); 209 continue;
204 } 210 }
205 fclose (fp); 211 ungetc (c, fp);
206 if (res_size == 0) 212 if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
207 cp = ""; 213 break;
208 else 214 l1 = strlen (buf1);
209 { 215 l2 = strlen (buf2);
210 *(res_ptr + res_size) = '\0'; 216 old_res_ptr = res_ptr;
211 cp = res_ptr; 217 if (res_size == 0)
212 } 218 {
213 } 219 res_size = l1 + 1 + l2 + 1;
214 220 res_ptr = (char *) malloc (res_size + 1);
215 if (file_name != NULL) 221 }
216 free (file_name); 222 else
223 {
224 res_size += l1 + 1 + l2 + 1;
225 res_ptr = (char *) realloc (res_ptr, res_size + 1);
226 }
227 if (res_ptr == NULL)
228 {
229 /* Out of memory. */
230 res_size = 0;
231 if (old_res_ptr != NULL)
232 free (old_res_ptr);
233 break;
234 }
235 strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
236 strcpy (res_ptr + res_size - (l2 + 1), buf2);
237 }
238 fclose (fp);
239 if (res_size == 0)
240 cp = "";
241 else
242 {
243 *(res_ptr + res_size) = '\0';
244 cp = res_ptr;
245 }
246 }
247 }
248
249 free (file_name);
250 }
217 251
218#else 252#else
219 253
220# if defined DARWIN7 254# if defined DARWIN7
221 /* To avoid the trouble of installing a file that is shared by many 255 /* To avoid the trouble of installing a file that is shared by many
222 GNU packages -- many packaging systems have problems with this --, 256 GNU packages -- many packaging systems have problems with this --,
223 simply inline the aliases here. */ 257 simply inline the aliases here. */
224 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" 258 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
225 "ISO8859-2" "\0" "ISO-8859-2" "\0" 259 "ISO8859-2" "\0" "ISO-8859-2" "\0"
226 "ISO8859-4" "\0" "ISO-8859-4" "\0" 260 "ISO8859-4" "\0" "ISO-8859-4" "\0"
227 "ISO8859-5" "\0" "ISO-8859-5" "\0" 261 "ISO8859-5" "\0" "ISO-8859-5" "\0"
228 "ISO8859-7" "\0" "ISO-8859-7" "\0" 262 "ISO8859-7" "\0" "ISO-8859-7" "\0"
229 "ISO8859-9" "\0" "ISO-8859-9" "\0" 263 "ISO8859-9" "\0" "ISO-8859-9" "\0"
230 "ISO8859-13" "\0" "ISO-8859-13" "\0" 264 "ISO8859-13" "\0" "ISO-8859-13" "\0"
231 "ISO8859-15" "\0" "ISO-8859-15" "\0" 265 "ISO8859-15" "\0" "ISO-8859-15" "\0"
232 "KOI8-R" "\0" "KOI8-R" "\0" 266 "KOI8-R" "\0" "KOI8-R" "\0"
233 "KOI8-U" "\0" "KOI8-U" "\0" 267 "KOI8-U" "\0" "KOI8-U" "\0"
234 "CP866" "\0" "CP866" "\0" 268 "CP866" "\0" "CP866" "\0"
235 "CP949" "\0" "CP949" "\0" 269 "CP949" "\0" "CP949" "\0"
236 "CP1131" "\0" "CP1131" "\0" 270 "CP1131" "\0" "CP1131" "\0"
237 "CP1251" "\0" "CP1251" "\0" 271 "CP1251" "\0" "CP1251" "\0"
238 "eucCN" "\0" "GB2312" "\0" 272 "eucCN" "\0" "GB2312" "\0"
239 "GB2312" "\0" "GB2312" "\0" 273 "GB2312" "\0" "GB2312" "\0"
240 "eucJP" "\0" "EUC-JP" "\0" 274 "eucJP" "\0" "EUC-JP" "\0"
241 "eucKR" "\0" "EUC-KR" "\0" 275 "eucKR" "\0" "EUC-KR" "\0"
242 "Big5" "\0" "BIG5" "\0" 276 "Big5" "\0" "BIG5" "\0"
243 "Big5HKSCS" "\0" "BIG5-HKSCS" "\0" 277 "Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
244 "GBK" "\0" "GBK" "\0" 278 "GBK" "\0" "GBK" "\0"
245 "GB18030" "\0" "GB18030" "\0" 279 "GB18030" "\0" "GB18030" "\0"
246 "SJIS" "\0" "SHIFT_JIS" "\0" 280 "SJIS" "\0" "SHIFT_JIS" "\0"
247 "ARMSCII-8" "\0" "ARMSCII-8" "\0" 281 "ARMSCII-8" "\0" "ARMSCII-8" "\0"
248 "PT154" "\0" "PT154" "\0" 282 "PT154" "\0" "PT154" "\0"
249 /*"ISCII-DEV" "\0" "?" "\0"*/ 283 /*"ISCII-DEV" "\0" "?" "\0"*/
250 "*" "\0" "UTF-8" "\0"; 284 "*" "\0" "UTF-8" "\0";
251# endif 285# endif
252 286
253# if defined VMS 287# if defined VMS
254 /* To avoid the troubles of an extra file charset.alias_vms in the 288 /* To avoid the troubles of an extra file charset.alias_vms in the
255 sources of many GNU packages, simply inline the aliases here. */ 289 sources of many GNU packages, simply inline the aliases here. */
256 /* The list of encodings is taken from the OpenVMS 7.3-1 documentation 290 /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
257 "Compaq C Run-Time Library Reference Manual for OpenVMS systems" 291 "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
258 section 10.7 "Handling Different Character Sets". */ 292 section 10.7 "Handling Different Character Sets". */
259 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" 293 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
260 "ISO8859-2" "\0" "ISO-8859-2" "\0" 294 "ISO8859-2" "\0" "ISO-8859-2" "\0"
261 "ISO8859-5" "\0" "ISO-8859-5" "\0" 295 "ISO8859-5" "\0" "ISO-8859-5" "\0"
262 "ISO8859-7" "\0" "ISO-8859-7" "\0" 296 "ISO8859-7" "\0" "ISO-8859-7" "\0"
263 "ISO8859-8" "\0" "ISO-8859-8" "\0" 297 "ISO8859-8" "\0" "ISO-8859-8" "\0"
264 "ISO8859-9" "\0" "ISO-8859-9" "\0" 298 "ISO8859-9" "\0" "ISO-8859-9" "\0"
265 /* Japanese */ 299 /* Japanese */
266 "eucJP" "\0" "EUC-JP" "\0" 300 "eucJP" "\0" "EUC-JP" "\0"
267 "SJIS" "\0" "SHIFT_JIS" "\0" 301 "SJIS" "\0" "SHIFT_JIS" "\0"
268 "DECKANJI" "\0" "DEC-KANJI" "\0" 302 "DECKANJI" "\0" "DEC-KANJI" "\0"
269 "SDECKANJI" "\0" "EUC-JP" "\0" 303 "SDECKANJI" "\0" "EUC-JP" "\0"
270 /* Chinese */ 304 /* Chinese */
271 "eucTW" "\0" "EUC-TW" "\0" 305 "eucTW" "\0" "EUC-TW" "\0"
272 "DECHANYU" "\0" "DEC-HANYU" "\0" 306 "DECHANYU" "\0" "DEC-HANYU" "\0"
273 "DECHANZI" "\0" "GB2312" "\0" 307 "DECHANZI" "\0" "GB2312" "\0"
274 /* Korean */ 308 /* Korean */
275 "DECKOREAN" "\0" "EUC-KR" "\0"; 309 "DECKOREAN" "\0" "EUC-KR" "\0";
276# endif 310# endif
277 311
278# if defined WIN32_NATIVE || defined __CYGWIN__ 312# if defined WIN32_NATIVE || defined __CYGWIN__
279 /* To avoid the troubles of installing a separate file in the same 313 /* To avoid the troubles of installing a separate file in the same
280 directory as the DLL and of retrieving the DLL's directory at 314 directory as the DLL and of retrieving the DLL's directory at
281 runtime, simply inline the aliases here. */ 315 runtime, simply inline the aliases here. */
282 316
283 cp = "CP936" "\0" "GBK" "\0" 317 cp = "CP936" "\0" "GBK" "\0"
284 "CP1361" "\0" "JOHAB" "\0" 318 "CP1361" "\0" "JOHAB" "\0"
285 "CP20127" "\0" "ASCII" "\0" 319 "CP20127" "\0" "ASCII" "\0"
286 "CP20866" "\0" "KOI8-R" "\0" 320 "CP20866" "\0" "KOI8-R" "\0"
287 "CP20936" "\0" "GB2312" "\0" 321 "CP20936" "\0" "GB2312" "\0"
288 "CP21866" "\0" "KOI8-RU" "\0" 322 "CP21866" "\0" "KOI8-RU" "\0"
289 "CP28591" "\0" "ISO-8859-1" "\0" 323 "CP28591" "\0" "ISO-8859-1" "\0"
290 "CP28592" "\0" "ISO-8859-2" "\0" 324 "CP28592" "\0" "ISO-8859-2" "\0"
291 "CP28593" "\0" "ISO-8859-3" "\0" 325 "CP28593" "\0" "ISO-8859-3" "\0"
292 "CP28594" "\0" "ISO-8859-4" "\0" 326 "CP28594" "\0" "ISO-8859-4" "\0"
293 "CP28595" "\0" "ISO-8859-5" "\0" 327 "CP28595" "\0" "ISO-8859-5" "\0"
294 "CP28596" "\0" "ISO-8859-6" "\0" 328 "CP28596" "\0" "ISO-8859-6" "\0"
295 "CP28597" "\0" "ISO-8859-7" "\0" 329 "CP28597" "\0" "ISO-8859-7" "\0"
296 "CP28598" "\0" "ISO-8859-8" "\0" 330 "CP28598" "\0" "ISO-8859-8" "\0"
297 "CP28599" "\0" "ISO-8859-9" "\0" 331 "CP28599" "\0" "ISO-8859-9" "\0"
298 "CP28605" "\0" "ISO-8859-15" "\0" 332 "CP28605" "\0" "ISO-8859-15" "\0"
299 "CP38598" "\0" "ISO-8859-8" "\0" 333 "CP38598" "\0" "ISO-8859-8" "\0"
300 "CP51932" "\0" "EUC-JP" "\0" 334 "CP51932" "\0" "EUC-JP" "\0"
301 "CP51936" "\0" "GB2312" "\0" 335 "CP51936" "\0" "GB2312" "\0"
302 "CP51949" "\0" "EUC-KR" "\0" 336 "CP51949" "\0" "EUC-KR" "\0"
303 "CP51950" "\0" "EUC-TW" "\0" 337 "CP51950" "\0" "EUC-TW" "\0"
304 "CP54936" "\0" "GB18030" "\0" 338 "CP54936" "\0" "GB18030" "\0"
305 "CP65001" "\0" "UTF-8" "\0"; 339 "CP65001" "\0" "UTF-8" "\0";
306# endif 340# endif
307#endif 341#endif
308 342
@@ -335,7 +369,7 @@ locale_charset (void)
335 codeset = nl_langinfo (CODESET); 369 codeset = nl_langinfo (CODESET);
336 370
337# ifdef __CYGWIN__ 371# ifdef __CYGWIN__
338 /* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always 372 /* Cygwin 1.5.x does not have locales. nl_langinfo (CODESET) always
339 returns "US-ASCII". As long as this is not fixed, return the suffix 373 returns "US-ASCII". As long as this is not fixed, return the suffix
340 of the locale name from the environment variables (if present) or 374 of the locale name from the environment variables (if present) or
341 the codepage as a number. */ 375 the codepage as a number. */
@@ -346,36 +380,46 @@ locale_charset (void)
346 380
347 locale = getenv ("LC_ALL"); 381 locale = getenv ("LC_ALL");
348 if (locale == NULL || locale[0] == '\0') 382 if (locale == NULL || locale[0] == '\0')
349 { 383 {
350 locale = getenv ("LC_CTYPE"); 384 locale = getenv ("LC_CTYPE");
351 if (locale == NULL || locale[0] == '\0') 385 if (locale == NULL || locale[0] == '\0')
352 locale = getenv ("LANG"); 386 locale = getenv ("LANG");
353 } 387 }
354 if (locale != NULL && locale[0] != '\0') 388 if (locale != NULL && locale[0] != '\0')
355 { 389 {
356 /* If the locale name contains an encoding after the dot, return 390 /* If the locale name contains an encoding after the dot, return
357 it. */ 391 it. */
358 const char *dot = strchr (locale, '.'); 392 const char *dot = strchr (locale, '.');
359 393
360 if (dot != NULL) 394 if (dot != NULL)
361 { 395 {
362 const char *modifier; 396 const char *modifier;
363 397
364 dot++; 398 dot++;
365 /* Look for the possible @... trailer and remove it, if any. */ 399 /* Look for the possible @... trailer and remove it, if any. */
366 modifier = strchr (dot, '@'); 400 modifier = strchr (dot, '@');
367 if (modifier == NULL) 401 if (modifier == NULL)
368 return dot; 402 return dot;
369 if (modifier - dot < sizeof (buf)) 403 if (modifier - dot < sizeof (buf))
370 { 404 {
371 memcpy (buf, dot, modifier - dot); 405 memcpy (buf, dot, modifier - dot);
372 buf [modifier - dot] = '\0'; 406 buf [modifier - dot] = '\0';
373 return buf; 407 return buf;
374 } 408 }
375 } 409 }
376 } 410 }
377 411
378 /* Woe32 has a function returning the locale's codepage as a number. */ 412 /* Woe32 has a function returning the locale's codepage as a number:
413 GetACP(). This encoding is used by Cygwin, unless the user has set
414 the environment variable CYGWIN=codepage:oem (which very few people
415 do).
416 Output directed to console windows needs to be converted (to
417 GetOEMCP() if the console is using a raster font, or to
418 GetConsoleOutputCP() if it is using a TrueType font). Cygwin does
419 this conversion transparently (see winsup/cygwin/fhandler_console.cc),
420 converting to GetConsoleOutputCP(). This leads to correct results,
421 except when SetConsoleOutputCP has been called and a raster font is
422 in use. */
379 sprintf (buf, "CP%u", GetACP ()); 423 sprintf (buf, "CP%u", GetACP ());
380 codeset = buf; 424 codeset = buf;
381 } 425 }
@@ -397,11 +441,11 @@ locale_charset (void)
397 { 441 {
398 locale = getenv ("LC_ALL"); 442 locale = getenv ("LC_ALL");
399 if (locale == NULL || locale[0] == '\0') 443 if (locale == NULL || locale[0] == '\0')
400 { 444 {
401 locale = getenv ("LC_CTYPE"); 445 locale = getenv ("LC_CTYPE");
402 if (locale == NULL || locale[0] == '\0') 446 if (locale == NULL || locale[0] == '\0')
403 locale = getenv ("LANG"); 447 locale = getenv ("LANG");
404 } 448 }
405 } 449 }
406 450
407 /* On some old systems, one used to set locale = "iso8859_1". On others, 451 /* On some old systems, one used to set locale = "iso8859_1". On others,
@@ -415,7 +459,13 @@ locale_charset (void)
415 459
416 static char buf[2 + 10 + 1]; 460 static char buf[2 + 10 + 1];
417 461
418 /* Woe32 has a function returning the locale's codepage as a number. */ 462 /* Woe32 has a function returning the locale's codepage as a number:
463 GetACP().
464 When the output goes to a console window, it needs to be provided in
465 GetOEMCP() encoding if the console is using a raster font, or in
466 GetConsoleOutputCP() encoding if it is using a TrueType font.
467 But in GUI programs and for output sent to files and pipes, GetACP()
468 encoding is the best bet. */
419 sprintf (buf, "CP%u", GetACP ()); 469 sprintf (buf, "CP%u", GetACP ());
420 codeset = buf; 470 codeset = buf;
421 471
@@ -433,7 +483,7 @@ locale_charset (void)
433 { 483 {
434 locale = getenv ("LC_CTYPE"); 484 locale = getenv ("LC_CTYPE");
435 if (locale == NULL || locale[0] == '\0') 485 if (locale == NULL || locale[0] == '\0')
436 locale = getenv ("LANG"); 486 locale = getenv ("LANG");
437 } 487 }
438 if (locale != NULL && locale[0] != '\0') 488 if (locale != NULL && locale[0] != '\0')
439 { 489 {
@@ -441,21 +491,21 @@ locale_charset (void)
441 const char *dot = strchr (locale, '.'); 491 const char *dot = strchr (locale, '.');
442 492
443 if (dot != NULL) 493 if (dot != NULL)
444 { 494 {
445 const char *modifier; 495 const char *modifier;
446 496
447 dot++; 497 dot++;
448 /* Look for the possible @... trailer and remove it, if any. */ 498 /* Look for the possible @... trailer and remove it, if any. */
449 modifier = strchr (dot, '@'); 499 modifier = strchr (dot, '@');
450 if (modifier == NULL) 500 if (modifier == NULL)
451 return dot; 501 return dot;
452 if (modifier - dot < sizeof (buf)) 502 if (modifier - dot < sizeof (buf))
453 { 503 {
454 memcpy (buf, dot, modifier - dot); 504 memcpy (buf, dot, modifier - dot);
455 buf [modifier - dot] = '\0'; 505 buf [modifier - dot] = '\0';
456 return buf; 506 return buf;
457 } 507 }
458 } 508 }
459 509
460 /* Resolve through the charset.alias file. */ 510 /* Resolve through the charset.alias file. */
461 codeset = locale; 511 codeset = locale;
@@ -464,12 +514,12 @@ locale_charset (void)
464 { 514 {
465 /* OS/2 has a function returning the locale's codepage as a number. */ 515 /* OS/2 has a function returning the locale's codepage as a number. */
466 if (DosQueryCp (sizeof (cp), cp, &cplen)) 516 if (DosQueryCp (sizeof (cp), cp, &cplen))
467 codeset = ""; 517 codeset = "";
468 else 518 else
469 { 519 {
470 sprintf (buf, "CP%u", cp[0]); 520 sprintf (buf, "CP%u", cp[0]);
471 codeset = buf; 521 codeset = buf;
472 } 522 }
473 } 523 }
474 524
475#endif 525#endif
@@ -483,10 +533,10 @@ locale_charset (void)
483 *aliases != '\0'; 533 *aliases != '\0';
484 aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) 534 aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
485 if (strcmp (codeset, aliases) == 0 535 if (strcmp (codeset, aliases) == 0
486 || (aliases[0] == '*' && aliases[1] == '\0')) 536 || (aliases[0] == '*' && aliases[1] == '\0'))
487 { 537 {
488 codeset = aliases + strlen (aliases) + 1; 538 codeset = aliases + strlen (aliases) + 1;
489 break; 539 break;
490 } 540 }
491 541
492 /* Don't return an empty string. GNU libc and GNU libiconv interpret 542 /* Don't return an empty string. GNU libc and GNU libiconv interpret
diff --git a/gl/localcharset.h b/gl/localcharset.h
index b9a3013a..899b3bae 100644
--- a/gl/localcharset.h
+++ b/gl/localcharset.h
@@ -1,5 +1,5 @@
1/* Determine a canonical name for the current locale's character encoding. 1/* Determine a canonical name for the current locale's character encoding.
2 Copyright (C) 2000-2003 Free Software Foundation, Inc. 2 Copyright (C) 2000-2003, 2009-2010 Free Software Foundation, Inc.
3 This file is part of the GNU CHARSET Library. 3 This file is part of the GNU CHARSET Library.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
diff --git a/gl/locale.in.h b/gl/locale.in.h
new file mode 100644
index 00000000..75b52993
--- /dev/null
+++ b/gl/locale.in.h
@@ -0,0 +1,74 @@
1/* A POSIX <locale.h>.
2 Copyright (C) 2007-2010 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#ifndef _GL_LOCALE_H
18
19#if __GNUC__ >= 3
20@PRAGMA_SYSTEM_HEADER@
21#endif
22
23/* The include_next requires a split double-inclusion guard. */
24#@INCLUDE_NEXT@ @NEXT_LOCALE_H@
25
26#ifndef _GL_LOCALE_H
27#define _GL_LOCALE_H
28
29/* NetBSD 5.0 mis-defines NULL. */
30#include <stddef.h>
31
32/* MacOS X 10.5 defines the locale_t type in <xlocale.h>. */
33#if @HAVE_XLOCALE_H@
34# include <xlocale.h>
35#endif
36
37/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
38
39/* The definition of _GL_ARG_NONNULL is copied here. */
40
41/* The definition of _GL_WARN_ON_USE is copied here. */
42
43/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
44 On systems that don't define it, use the same value as GNU libintl. */
45#if !defined LC_MESSAGES
46# define LC_MESSAGES 1729
47#endif
48
49#if @GNULIB_DUPLOCALE@
50# if @REPLACE_DUPLOCALE@
51# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
52# undef duplocale
53# define duplocale rpl_duplocale
54# endif
55_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
56_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
57# else
58# if @HAVE_DUPLOCALE@
59_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
60# endif
61# endif
62# if @HAVE_DUPLOCALE@
63_GL_CXXALIASWARN (duplocale);
64# endif
65#elif defined GNULIB_POSIXCHECK
66# undef duplocale
67# if HAVE_RAW_DECL_DUPLOCALE
68_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
69 "use gnulib module duplocale for portability");
70# endif
71#endif
72
73#endif /* _GL_LOCALE_H */
74#endif /* _GL_LOCALE_H */
diff --git a/gl/m4/00gnulib.m4 b/gl/m4/00gnulib.m4
index d4d04d15..301469b3 100644
--- a/gl/m4/00gnulib.m4
+++ b/gl/m4/00gnulib.m4
@@ -1,5 +1,5 @@
1# 00gnulib.m4 serial 2 1# 00gnulib.m4 serial 2
2dnl Copyright (C) 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/alloca.m4 b/gl/m4/alloca.m4
index 4b978e13..f3ee3438 100644
--- a/gl/m4/alloca.m4
+++ b/gl/m4/alloca.m4
@@ -1,5 +1,6 @@
1# alloca.m4 serial 9 1# alloca.m4 serial 9
2dnl Copyright (C) 2002-2004, 2006, 2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2006-2007, 2009-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/arpa_inet_h.m4 b/gl/m4/arpa_inet_h.m4
index a6e63df0..15a30e2b 100644
--- a/gl/m4/arpa_inet_h.m4
+++ b/gl/m4/arpa_inet_h.m4
@@ -1,5 +1,5 @@
1# arpa_inet_h.m4 serial 5 1# arpa_inet_h.m4 serial 8
2dnl Copyright (C) 2006, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -16,27 +16,35 @@ AC_DEFUN([gl_HEADER_ARPA_INET],
16 if test $ac_cv_header_arpa_inet_h = yes; then 16 if test $ac_cv_header_arpa_inet_h = yes; then
17 HAVE_ARPA_INET_H=1 17 HAVE_ARPA_INET_H=1
18 else 18 else
19 ARPA_INET_H='arpa/inet.h'
20 HAVE_ARPA_INET_H=0 19 HAVE_ARPA_INET_H=0
21 fi 20 fi
22 AC_SUBST([HAVE_ARPA_INET_H]) 21 AC_SUBST([HAVE_ARPA_INET_H])
23 dnl Execute this unconditionally, because ARPA_INET_H may be set by other 22 dnl <arpa/inet.h> is always overridden, because of GNULIB_POSIXCHECK.
24 dnl modules, after this code is executed.
25 gl_CHECK_NEXT_HEADERS([arpa/inet.h]) 23 gl_CHECK_NEXT_HEADERS([arpa/inet.h])
24
25 dnl Check for declarations of anything we want to poison if the
26 dnl corresponding gnulib module is not in use.
27 gl_WARN_ON_USE_PREPARE([[
28/* On some systems, this header is not self-consistent. */
29#ifndef __GLIBC__
30# include <sys/socket.h>
31#endif
32#include <arpa/inet.h>
33 ]], [inet_ntop inet_pton])
26]) 34])
27 35
28dnl Unconditionally enables the replacement of <arpa/inet.h>. 36dnl Unconditionally enables the replacement of <arpa/inet.h>.
29AC_DEFUN([gl_REPLACE_ARPA_INET_H], 37AC_DEFUN([gl_REPLACE_ARPA_INET_H],
30[ 38[
31 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS]) 39 dnl This is a no-op, because <arpa/inet.h> is always overridden.
32 ARPA_INET_H='arpa/inet.h' 40 :
33]) 41])
34 42
35AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR], 43AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR],
36[ 44[
37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 45 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
38 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS]) 46 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
39 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 47 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
40]) 48])
41 49
42AC_DEFUN([gl_ARPA_INET_H_DEFAULTS], 50AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
@@ -46,5 +54,4 @@ AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
46 dnl Assume proper GNU behavior unless another module says otherwise. 54 dnl Assume proper GNU behavior unless another module says otherwise.
47 HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP]) 55 HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP])
48 HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON]) 56 HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON])
49 ARPA_INET_H=''; AC_SUBST([ARPA_INET_H])
50]) 57])
diff --git a/gl/m4/base64.m4 b/gl/m4/base64.m4
index 24801efa..d1e13522 100644
--- a/gl/m4/base64.m4
+++ b/gl/m4/base64.m4
@@ -1,5 +1,5 @@
1# base64.m4 serial 3 1# base64.m4 serial 3
2dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/btowc.m4 b/gl/m4/btowc.m4
index b46f74fb..c4ee4e41 100644
--- a/gl/m4/btowc.m4
+++ b/gl/m4/btowc.m4
@@ -1,5 +1,5 @@
1# btowc.m4 serial 4 1# btowc.m4 serial 6
2dnl Copyright (C) 2008-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -8,15 +8,49 @@ AC_DEFUN([gl_FUNC_BTOWC],
8[ 8[
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10 10
11 dnl Check whether <wchar.h> is usable at all, first. Otherwise the test
12 dnl program below may lead to an endless loop. See
13 dnl <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>.
14 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
15
11 AC_CHECK_FUNCS_ONCE([btowc]) 16 AC_CHECK_FUNCS_ONCE([btowc])
12 if test $ac_cv_func_btowc = no; then 17 if test $ac_cv_func_btowc = no; then
13 HAVE_BTOWC=0 18 HAVE_BTOWC=0
14 else 19 else
15 20
16 dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF.
17 AC_REQUIRE([AC_PROG_CC]) 21 AC_REQUIRE([AC_PROG_CC])
18 AC_REQUIRE([gt_LOCALE_FR]) 22 AC_REQUIRE([gt_LOCALE_FR])
19 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 23 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24
25 dnl Cygwin 1.7.2 btowc('\0') is WEOF, not 0.
26 AC_CACHE_CHECK([whether btowc(0) is correct],
27 [gl_cv_func_btowc_nul],
28 [
29 AC_TRY_RUN([
30#include <stdio.h>
31#include <string.h>
32#include <wchar.h>
33int main ()
34{
35 if (btowc ('\0') != 0)
36 return 1;
37 return 0;
38}],
39 [gl_cv_func_btowc_nul=yes],
40 [gl_cv_func_btowc_nul=no],
41 [
42changequote(,)dnl
43 case "$host_os" in
44 # Guess no on Cygwin.
45 cygwin*) gl_cv_func_btowc_nul="guessing no" ;;
46 # Guess yes otherwise.
47 *) gl_cv_func_btowc_nul="guessing yes" ;;
48 esac
49changequote([,])dnl
50 ])
51 ])
52
53 dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF.
20 AC_CACHE_CHECK([whether btowc(EOF) is correct], 54 AC_CACHE_CHECK([whether btowc(EOF) is correct],
21 [gl_cv_func_btowc_eof], 55 [gl_cv_func_btowc_eof],
22 [ 56 [
@@ -50,6 +84,11 @@ int main ()
50 [:]) 84 [:])
51 fi 85 fi
52 ]) 86 ])
87
88 case "$gl_cv_func_btowc_nul" in
89 *yes) ;;
90 *) REPLACE_BTOWC=1 ;;
91 esac
53 case "$gl_cv_func_btowc_eof" in 92 case "$gl_cv_func_btowc_eof" in
54 *yes) ;; 93 *yes) ;;
55 *) REPLACE_BTOWC=1 ;; 94 *) REPLACE_BTOWC=1 ;;
diff --git a/gl/m4/c-strtod.m4 b/gl/m4/c-strtod.m4
index ba954354..41cf18e9 100644
--- a/gl/m4/c-strtod.m4
+++ b/gl/m4/c-strtod.m4
@@ -1,6 +1,6 @@
1# c-strtod.m4 serial 11 1# c-strtod.m4 serial 11
2 2
3# Copyright (C) 2004, 2005, 2006, 2009 Free Software Foundation, Inc. 3# Copyright (C) 2004-2006, 2009-2010 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation 4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it, 5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved. 6# with or without modifications, as long as this notice is preserved.
@@ -14,17 +14,17 @@ AC_DEFUN([gl_C99_STRTOLD],
14 [AC_LINK_IFELSE( 14 [AC_LINK_IFELSE(
15 [AC_LANG_PROGRAM( 15 [AC_LANG_PROGRAM(
16 [[/* On HP-UX before 11.23, strtold returns a struct instead of 16 [[/* On HP-UX before 11.23, strtold returns a struct instead of
17 long double. Reject implementations like that, by requiring 17 long double. Reject implementations like that, by requiring
18 compatibility with the C99 prototype. */ 18 compatibility with the C99 prototype. */
19 #include <stdlib.h> 19 #include <stdlib.h>
20 static long double (*p) (char const *, char **) = strtold; 20 static long double (*p) (char const *, char **) = strtold;
21 static long double 21 static long double
22 test (char const *nptr, char **endptr) 22 test (char const *nptr, char **endptr)
23 { 23 {
24 long double r; 24 long double r;
25 r = strtold (nptr, endptr); 25 r = strtold (nptr, endptr);
26 return r; 26 return r;
27 }]], 27 }]],
28 [[return test ("1.0", NULL) != 1 || p ("1.0", NULL) != 1;]])], 28 [[return test ("1.0", NULL) != 1 || p ("1.0", NULL) != 1;]])],
29 [gl_cv_func_c99_strtold=yes], 29 [gl_cv_func_c99_strtold=yes],
30 [gl_cv_func_c99_strtold=no])]) 30 [gl_cv_func_c99_strtold=no])])
diff --git a/gl/m4/cloexec.m4 b/gl/m4/cloexec.m4
index 4c4e26a1..c75595ca 100644
--- a/gl/m4/cloexec.m4
+++ b/gl/m4/cloexec.m4
@@ -1,5 +1,5 @@
1#serial 6 1#serial 6
2dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/codeset.m4 b/gl/m4/codeset.m4
index 413217bd..a53c0426 100644
--- a/gl/m4/codeset.m4
+++ b/gl/m4/codeset.m4
@@ -1,5 +1,5 @@
1# codeset.m4 serial 4 (gettext-0.18) 1# codeset.m4 serial 4 (gettext-0.18)
2dnl Copyright (C) 2000-2002, 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/dirname.m4 b/gl/m4/dirname.m4
index e35da965..576b5bea 100644
--- a/gl/m4/dirname.m4
+++ b/gl/m4/dirname.m4
@@ -1,18 +1,26 @@
1#serial 7 -*- autoconf -*- 1#serial 8 -*- autoconf -*-
2dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7AC_DEFUN([gl_DIRNAME], 7AC_DEFUN([gl_DIRNAME],
8[ 8[
9 AC_REQUIRE([gl_DIRNAME_LGPL])
9 AC_LIBOBJ([basename]) 10 AC_LIBOBJ([basename])
10 AC_LIBOBJ([dirname]) 11 AC_LIBOBJ([dirname])
12])
13
14AC_DEFUN([gl_DIRNAME_LGPL],
15[
16 AC_LIBOBJ([basename-lgpl])
17 AC_LIBOBJ([dirname-lgpl])
11 AC_LIBOBJ([stripslash]) 18 AC_LIBOBJ([stripslash])
12 19
13 dnl Prerequisites of lib/dirname.h. 20 dnl Prerequisites of lib/dirname.h.
14 AC_REQUIRE([gl_AC_DOS]) 21 AC_REQUIRE([gl_AC_DOS])
15 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) 22 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
16 23
17 dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c. 24 dnl No prerequisites of lib/basename-lgpl.c, lib/dirname-lgpl.c,
25 dnl lib/stripslash.c.
18]) 26])
diff --git a/gl/m4/dos.m4 b/gl/m4/dos.m4
index dd59571c..5660542b 100644
--- a/gl/m4/dos.m4
+++ b/gl/m4/dos.m4
@@ -1,9 +1,9 @@
1#serial 10 -*- autoconf -*- 1#serial 11 -*- autoconf -*-
2 2
3# Define some macros required for proper operation of code in lib/*.c 3# Define some macros required for proper operation of code in lib/*.c
4# on MSDOS/Windows systems. 4# on MSDOS/Windows systems.
5 5
6# Copyright (C) 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc. 6# Copyright (C) 2000-2001, 2004-2006, 2009-2010 Free Software Foundation, Inc.
7# This file is free software; the Free Software Foundation 7# This file is free software; the Free Software Foundation
8# gives unlimited permission to copy and/or distribute it, 8# gives unlimited permission to copy and/or distribute it,
9# with or without modifications, as long as this notice is preserved. 9# with or without modifications, as long as this notice is preserved.
@@ -14,31 +14,31 @@ AC_DEFUN([gl_AC_DOS],
14 [ 14 [
15 AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], 15 AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos],
16 [ 16 [
17 AC_TRY_COMPILE([], 17 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
18 [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ 18#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__
19neither MSDOS nor Windows 19neither MSDOS nor Windows
20#endif], 20#endif]])],
21 [ac_cv_win_or_dos=yes], 21 [ac_cv_win_or_dos=yes],
22 [ac_cv_win_or_dos=no]) 22 [ac_cv_win_or_dos=no])
23 ]) 23 ])
24 24
25 if test x"$ac_cv_win_or_dos" = xyes; then 25 if test x"$ac_cv_win_or_dos" = xyes; then
26 ac_fs_accepts_drive_letter_prefix=1 26 ac_fs_accepts_drive_letter_prefix=1
27 ac_fs_backslash_is_file_name_separator=1 27 ac_fs_backslash_is_file_name_separator=1
28 AC_CACHE_CHECK([whether drive letter can start relative path], 28 AC_CACHE_CHECK([whether drive letter can start relative path],
29 [ac_cv_drive_letter_can_be_relative], 29 [ac_cv_drive_letter_can_be_relative],
30 [ 30 [
31 AC_TRY_COMPILE([], 31 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
32 [#if defined __CYGWIN__ 32#if defined __CYGWIN__
33drive letters are always absolute 33drive letters are always absolute
34#endif], 34#endif]])],
35 [ac_cv_drive_letter_can_be_relative=yes], 35 [ac_cv_drive_letter_can_be_relative=yes],
36 [ac_cv_drive_letter_can_be_relative=no]) 36 [ac_cv_drive_letter_can_be_relative=no])
37 ]) 37 ])
38 if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then 38 if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then
39 ac_fs_drive_letter_can_be_relative=1 39 ac_fs_drive_letter_can_be_relative=1
40 else 40 else
41 ac_fs_drive_letter_can_be_relative=0 41 ac_fs_drive_letter_can_be_relative=0
42 fi 42 fi
43 else 43 else
44 ac_fs_accepts_drive_letter_prefix=0 44 ac_fs_accepts_drive_letter_prefix=0
diff --git a/gl/m4/double-slash-root.m4 b/gl/m4/double-slash-root.m4
index 8c6841bc..66a79c0f 100644
--- a/gl/m4/double-slash-root.m4
+++ b/gl/m4/double-slash-root.m4
@@ -1,5 +1,5 @@
1# double-slash-root.m4 serial 4 -*- Autoconf -*- 1# double-slash-root.m4 serial 4 -*- Autoconf -*-
2dnl Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -9,27 +9,27 @@ AC_DEFUN([gl_DOUBLE_SLASH_ROOT],
9 AC_REQUIRE([AC_CANONICAL_HOST]) 9 AC_REQUIRE([AC_CANONICAL_HOST])
10 AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root], 10 AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root],
11 [ if test x"$cross_compiling" = xyes ; then 11 [ if test x"$cross_compiling" = xyes ; then
12 # When cross-compiling, there is no way to tell whether // is special 12 # When cross-compiling, there is no way to tell whether // is special
13 # short of a list of hosts. However, the only known hosts to date 13 # short of a list of hosts. However, the only known hosts to date
14 # that have a distinct // are Apollo DomainOS (too old to port to), 14 # that have a distinct // are Apollo DomainOS (too old to port to),
15 # Cygwin, and z/OS. If anyone knows of another system for which // has 15 # Cygwin, and z/OS. If anyone knows of another system for which // has
16 # special semantics and is distinct from /, please report it to 16 # special semantics and is distinct from /, please report it to
17 # <bug-gnulib@gnu.org>. 17 # <bug-gnulib@gnu.org>.
18 case $host in 18 case $host in
19 *-cygwin | i370-ibm-openedition) 19 *-cygwin | i370-ibm-openedition)
20 gl_cv_double_slash_root=yes ;; 20 gl_cv_double_slash_root=yes ;;
21 *) 21 *)
22 # Be optimistic and assume that / and // are the same when we 22 # Be optimistic and assume that / and // are the same when we
23 # don't know. 23 # don't know.
24 gl_cv_double_slash_root='unknown, assuming no' ;; 24 gl_cv_double_slash_root='unknown, assuming no' ;;
25 esac 25 esac
26 else 26 else
27 set x `ls -di / // 2>/dev/null` 27 set x `ls -di / // 2>/dev/null`
28 if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then 28 if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then
29 gl_cv_double_slash_root=no 29 gl_cv_double_slash_root=no
30 else 30 else
31 gl_cv_double_slash_root=yes 31 gl_cv_double_slash_root=yes
32 fi 32 fi
33 fi]) 33 fi])
34 if test "$gl_cv_double_slash_root" = yes; then 34 if test "$gl_cv_double_slash_root" = yes; then
35 AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1], 35 AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1],
diff --git a/gl/m4/dup2.m4 b/gl/m4/dup2.m4
new file mode 100644
index 00000000..998d66f8
--- /dev/null
+++ b/gl/m4/dup2.m4
@@ -0,0 +1,58 @@
1#serial 10
2dnl Copyright (C) 2002, 2005, 2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_DUP2],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_CHECK_FUNCS_ONCE([dup2])
12 if test $ac_cv_func_dup2 = no; then
13 HAVE_DUP2=0
14 AC_LIBOBJ([dup2])
15 else
16 AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
17 [AC_RUN_IFELSE([
18 AC_LANG_PROGRAM([[#include <unistd.h>
19#include <errno.h>]],
20 [if (dup2 (1, 1) == 0)
21 return 1;
22 close (0);
23 if (dup2 (0, 0) != -1)
24 return 2;
25 /* Many gnulib modules require POSIX conformance of EBADF. */
26 if (dup2 (1, 1000000) == -1 && errno != EBADF)
27 return 3;
28 return 0;
29 ])
30 ],
31 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
32 [case "$host_os" in
33 mingw*) # on this platform, dup2 always returns 0 for success
34 gl_cv_func_dup2_works=no;;
35 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
36 gl_cv_func_dup2_works=no;;
37 linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
38 # closed fd may yield -EBADF instead of -1 / errno=EBADF.
39 gl_cv_func_dup2_works=no;;
40 freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF.
41 gl_cv_func_dup2_works=no;;
42 *) gl_cv_func_dup2_works=yes;;
43 esac])
44 ])
45 if test "$gl_cv_func_dup2_works" = no; then
46 gl_REPLACE_DUP2
47 fi
48 fi
49])
50
51AC_DEFUN([gl_REPLACE_DUP2],
52[
53 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
54 if test $ac_cv_func_dup2 = yes; then
55 REPLACE_DUP2=1
56 fi
57 AC_LIBOBJ([dup2])
58])
diff --git a/gl/m4/errno_h.m4 b/gl/m4/errno_h.m4
index 16188d9b..d02a0393 100644
--- a/gl/m4/errno_h.m4
+++ b/gl/m4/errno_h.m4
@@ -1,5 +1,5 @@
1# errno_h.m4 serial 5 1# errno_h.m4 serial 6
2dnl Copyright (C) 2004, 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -34,6 +34,9 @@ booboo
34#if !defined ENOTSUP 34#if !defined ENOTSUP
35booboo 35booboo
36#endif 36#endif
37#if !defined ESTALE
38booboo
39#endif
37#if !defined ECANCELED 40#if !defined ECANCELED
38booboo 41booboo
39#endif 42#endif
diff --git a/gl/m4/error.m4 b/gl/m4/error.m4
index 7c7746e2..9f1307a4 100644
--- a/gl/m4/error.m4
+++ b/gl/m4/error.m4
@@ -1,7 +1,6 @@
1#serial 11 1#serial 12
2 2
3# Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004 Free Software 3# Copyright (C) 1996-1998, 2001-2004, 2009-2010 Free Software Foundation, Inc.
4# Foundation, Inc.
5# 4#
6# This file is free software; the Free Software Foundation 5# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 6# gives unlimited permission to copy and/or distribute it,
@@ -18,5 +17,6 @@ AC_DEFUN([gl_ERROR],
18AC_DEFUN([gl_PREREQ_ERROR], 17AC_DEFUN([gl_PREREQ_ERROR],
19[ 18[
20 AC_REQUIRE([AC_FUNC_STRERROR_R]) 19 AC_REQUIRE([AC_FUNC_STRERROR_R])
20 AC_REQUIRE([AC_C_INLINE])
21 : 21 :
22]) 22])
diff --git a/gl/m4/exitfail.m4 b/gl/m4/exitfail.m4
deleted file mode 100644
index b7a691e5..00000000
--- a/gl/m4/exitfail.m4
+++ /dev/null
@@ -1,13 +0,0 @@
1# exitfail.m4 serial 6
2dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_EXITFAIL],
8[
9 AC_LIBOBJ([exitfail])
10
11 dnl No prerequisites of lib/exitfail.c.
12 :
13])
diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4
index ba6d5e19..7d9458a8 100644
--- a/gl/m4/extensions.m4
+++ b/gl/m4/extensions.m4
@@ -1,7 +1,7 @@
1# serial 8 -*- Autoconf -*- 1# serial 9 -*- Autoconf -*-
2# Enable extensions on systems that normally disable them. 2# Enable extensions on systems that normally disable them.
3 3
4# Copyright (C) 2003, 2006-2009 Free Software Foundation, Inc. 4# Copyright (C) 2003, 2006-2010 Free Software Foundation, Inc.
5# This file is free software; the Free Software Foundation 5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it, 6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved. 7# with or without modifications, as long as this notice is preserved.
@@ -12,6 +12,20 @@
12# enough in this area it's likely we'll need to redefine 12# enough in this area it's likely we'll need to redefine
13# AC_USE_SYSTEM_EXTENSIONS for quite some time. 13# AC_USE_SYSTEM_EXTENSIONS for quite some time.
14 14
15# If autoconf reports a warning
16# warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
17# or warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
18# the fix is
19# 1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked
20# but always AC_REQUIREd,
21# 2) to ensure that for each occurrence of
22# AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
23# or
24# AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
25# the corresponding gnulib module description has 'extensions' among
26# its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS
27# invocation occurs in gl_EARLY, not in gl_INIT.
28
15# AC_USE_SYSTEM_EXTENSIONS 29# AC_USE_SYSTEM_EXTENSIONS
16# ------------------------ 30# ------------------------
17# Enable extensions on systems that normally disable them, 31# Enable extensions on systems that normally disable them,
@@ -74,8 +88,8 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
74 [ac_cv_safe_to_define___extensions__], 88 [ac_cv_safe_to_define___extensions__],
75 [AC_COMPILE_IFELSE( 89 [AC_COMPILE_IFELSE(
76 [AC_LANG_PROGRAM([[ 90 [AC_LANG_PROGRAM([[
77# define __EXTENSIONS__ 1 91# define __EXTENSIONS__ 1
78 ]AC_INCLUDES_DEFAULT])], 92 ]AC_INCLUDES_DEFAULT])],
79 [ac_cv_safe_to_define___extensions__=yes], 93 [ac_cv_safe_to_define___extensions__=yes],
80 [ac_cv_safe_to_define___extensions__=no])]) 94 [ac_cv_safe_to_define___extensions__=no])])
81 test $ac_cv_safe_to_define___extensions__ = yes && 95 test $ac_cv_safe_to_define___extensions__ = yes &&
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4
new file mode 100644
index 00000000..d416a61c
--- /dev/null
+++ b/gl/m4/fcntl-o.m4
@@ -0,0 +1,81 @@
1# fcntl-o.m4 serial 1
2dnl Copyright (C) 2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl Written by Paul Eggert.
8
9# Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
10# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
11# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
12AC_DEFUN([gl_FCNTL_O_FLAGS],
13[
14 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
15 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
17 [AC_RUN_IFELSE(
18 [AC_LANG_PROGRAM(
19 [[#include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #ifndef O_NOATIME
24 #define O_NOATIME 0
25 #endif
26 #ifndef O_NOFOLLOW
27 #define O_NOFOLLOW 0
28 #endif
29 static int const constants[] =
30 {
31 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
32 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
33 };
34 ]],
35 [[
36 int status = !constants;
37 {
38 static char const sym[] = "conftest.sym";
39 if (symlink (".", sym) != 0
40 || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0)
41 status |= 32;
42 unlink (sym);
43 }
44 {
45 static char const file[] = "confdefs.h";
46 int fd = open (file, O_RDONLY | O_NOATIME);
47 char c;
48 struct stat st0, st1;
49 if (fd < 0
50 || fstat (fd, &st0) != 0
51 || sleep (1) != 0
52 || read (fd, &c, 1) != 1
53 || close (fd) != 0
54 || stat (file, &st1) != 0
55 || st0.st_atime != st1.st_atime)
56 status |= 64;
57 }
58 return status;]])],
59 [gl_cv_header_working_fcntl_h=yes],
60 [case $? in #(
61 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
62 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
63 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
64 *) gl_cv_header_working_fcntl_h='no';;
65 esac],
66 [gl_cv_header_working_fcntl_h=cross-compiling])])
67
68 case $gl_cv_header_working_fcntl_h in #(
69 *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
70 *) ac_val=1;;
71 esac
72 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
73 [Define to 1 if O_NOATIME works.])
74
75 case $gl_cv_header_working_fcntl_h in #(
76 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
77 *) ac_val=1;;
78 esac
79 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
80 [Define to 1 if O_NOFOLLOW works.])
81])
diff --git a/gl/m4/fcntl-safer.m4 b/gl/m4/fcntl-safer.m4
index 3475b0a7..1a739b09 100644
--- a/gl/m4/fcntl-safer.m4
+++ b/gl/m4/fcntl-safer.m4
@@ -1,5 +1,5 @@
1#serial 5 1#serial 7
2dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -8,4 +8,12 @@ AC_DEFUN([gl_FCNTL_SAFER],
8[ 8[
9 AC_LIBOBJ([open-safer]) 9 AC_LIBOBJ([open-safer])
10 AC_LIBOBJ([creat-safer]) 10 AC_LIBOBJ([creat-safer])
11 # Prerequisites of lib/open-safer.c.
12 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
13])
14
15AC_DEFUN([gl_OPENAT_SAFER],
16[
17 AC_REQUIRE([gl_FCNTL_SAFER])
18 AC_LIBOBJ([openat-safer])
11]) 19])
diff --git a/gl/m4/fcntl.m4 b/gl/m4/fcntl.m4
new file mode 100644
index 00000000..fcb5f447
--- /dev/null
+++ b/gl/m4/fcntl.m4
@@ -0,0 +1,83 @@
1# fcntl.m4 serial 3
2dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# For now, this module ensures that fcntl()
8# - supports F_DUPFD correctly
9# - supports or emulates F_DUPFD_CLOEXEC
10# - supports F_GETFD
11# Still to be ported to mingw:
12# - F_SETFD
13# - F_GETFL, F_SETFL
14# - F_GETOWN, F_SETOWN
15# - F_GETLK, F_SETLK, F_SETLKW
16AC_DEFUN([gl_FUNC_FCNTL],
17[
18 dnl Persuade glibc to expose F_DUPFD_CLOEXEC.
19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
20 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
21 AC_REQUIRE([AC_CANONICAL_HOST])
22 AC_CHECK_FUNCS_ONCE([fcntl])
23 if test $ac_cv_func_fcntl = no; then
24 gl_REPLACE_FCNTL
25 else
26 dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
27 AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
28 [gl_cv_func_fcntl_f_dupfd_works],
29 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
30#include <fcntl.h>
31]], [[return fcntl (0, F_DUPFD, -1) != -1;
32 ]])],
33 [gl_cv_func_fcntl_f_dupfd_works=yes],
34 [gl_cv_func_fcntl_f_dupfd_works=no],
35 [# Guess that it works on glibc systems
36 case $host_os in #((
37 *-gnu*) gl_cv_func_fcntl_f_dupfd_works="guessing yes";;
38 *) gl_cv_func_fcntl_f_dupfd_works="guessing no";;
39 esac])])
40 case $gl_cv_func_fcntl_f_dupfd_works in
41 *yes) ;;
42 *) gl_REPLACE_FCNTL
43 AC_DEFINE([FCNTL_DUPFD_BUGGY], [1], [Define this to 1 if F_DUPFD
44 behavior does not match POSIX]) ;;
45 esac
46
47 dnl Many systems lack F_DUPFD_CLOEXEC
48 AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC],
49 [gl_cv_func_fcntl_f_dupfd_cloexec],
50 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
51#include <fcntl.h>
52#ifndef F_DUPFD_CLOEXEC
53choke me
54#endif
55 ]])],
56 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
57#ifdef __linux__
58/* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace
59 it to support the semantics on older kernels that failed with EINVAL. */
60choke me
61#endif
62 ]])],
63 [gl_cv_func_fcntl_f_dupfd_cloexec=yes],
64 [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])],
65 [gl_cv_func_fcntl_f_dupfd_cloexec=no])])
66 if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then
67 gl_REPLACE_FCNTL
68 dnl No witness macro needed for this bug.
69 fi
70 fi
71])
72
73AC_DEFUN([gl_REPLACE_FCNTL],
74[
75 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
76 AC_CHECK_FUNCS_ONCE([fcntl])
77 if test $ac_cv_func_fcntl = no; then
78 HAVE_FCNTL=0
79 else
80 REPLACE_FCNTL=1
81 fi
82 AC_LIBOBJ([fcntl])
83])
diff --git a/gl/m4/fcntl_h.m4 b/gl/m4/fcntl_h.m4
index 1ae0b15a..e41915c3 100644
--- a/gl/m4/fcntl_h.m4
+++ b/gl/m4/fcntl_h.m4
@@ -1,5 +1,6 @@
1# serial 12
1# Configure fcntl.h. 2# Configure fcntl.h.
2dnl Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. 3dnl Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -9,88 +10,34 @@ dnl Written by Paul Eggert.
9AC_DEFUN([gl_FCNTL_H], 10AC_DEFUN([gl_FCNTL_H],
10[ 11[
11 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) 12 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
12 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW. 13 AC_REQUIRE([gl_FCNTL_O_FLAGS])
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
15 [AC_RUN_IFELSE(
16 [AC_LANG_PROGRAM(
17 [[#include <sys/types.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #ifndef O_NOATIME
22 #define O_NOATIME 0
23 #endif
24 #ifndef O_NOFOLLOW
25 #define O_NOFOLLOW 0
26 #endif
27 static int const constants[] =
28 {
29 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
30 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
31 };
32 ]],
33 [[
34 int status = !constants;
35 {
36 static char const sym[] = "conftest.sym";
37 if (symlink (".", sym) != 0
38 || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0)
39 status |= 32;
40 }
41 {
42 static char const file[] = "confdefs.h";
43 int fd = open (file, O_RDONLY | O_NOATIME);
44 char c;
45 struct stat st0, st1;
46 if (fd < 0
47 || fstat (fd, &st0) != 0
48 || sleep (1) != 0
49 || read (fd, &c, 1) != 1
50 || close (fd) != 0
51 || stat (file, &st1) != 0
52 || st0.st_atime != st1.st_atime)
53 status |= 64;
54 }
55 return status;]])],
56 [gl_cv_header_working_fcntl_h=yes],
57 [case $? in #(
58 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
59 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
60 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
61 *) gl_cv_header_working_fcntl_h='no';;
62 esac],
63 [gl_cv_header_working_fcntl_h=cross-compiling])])
64
65 case $gl_cv_header_working_fcntl_h in #(
66 *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
67 *) ac_val=1;;
68 esac
69 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
70 [Define to 1 if O_NOATIME works.])
71
72 case $gl_cv_header_working_fcntl_h in #(
73 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
74 *) ac_val=1;;
75 esac
76 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
77 [Define to 1 if O_NOFOLLOW works.])
78
79 gl_CHECK_NEXT_HEADERS([fcntl.h]) 14 gl_CHECK_NEXT_HEADERS([fcntl.h])
80 FCNTL_H='fcntl.h' 15
81 AC_SUBST([FCNTL_H]) 16 dnl Check for declarations of anything we want to poison if the
17 dnl corresponding gnulib module is not in use, if it is not common
18 dnl enough to be declared everywhere.
19 gl_WARN_ON_USE_PREPARE([[#include <fcntl.h>
20 ]], [fcntl openat])
82]) 21])
83 22
84AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], 23AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
85[ 24[
86 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 25 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
87 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) 26 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
88 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 27 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
28 dnl Define it also as a C macro, for the benefit of the unit tests.
29 gl_MODULE_INDICATOR_FOR_TESTS([$1])
89]) 30])
90 31
91AC_DEFUN([gl_FCNTL_H_DEFAULTS], 32AC_DEFUN([gl_FCNTL_H_DEFAULTS],
92[ 33[
93 GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) 34 GNULIB_FCNTL=0; AC_SUBST([GNULIB_FCNTL])
35 GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN])
36 GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT])
94 dnl Assume proper GNU behavior unless another module says otherwise. 37 dnl Assume proper GNU behavior unless another module says otherwise.
95 REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) 38 HAVE_FCNTL=1; AC_SUBST([HAVE_FCNTL])
39 HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT])
40 REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL])
41 REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN])
42 REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT])
96]) 43])
diff --git a/gl/m4/float_h.m4 b/gl/m4/float_h.m4
index d36e3a46..a74a0d95 100644
--- a/gl/m4/float_h.m4
+++ b/gl/m4/float_h.m4
@@ -1,5 +1,5 @@
1# float_h.m4 serial 3 1# float_h.m4 serial 3
2dnl Copyright (C) 2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/floorf.m4 b/gl/m4/floorf.m4
index 915e5664..fb17a5ea 100644
--- a/gl/m4/floorf.m4
+++ b/gl/m4/floorf.m4
@@ -1,5 +1,5 @@
1# floorf.m4 serial 4 1# floorf.m4 serial 6
2dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -20,13 +20,12 @@ AC_DEFUN([gl_FUNC_FLOORF],
20 REPLACE_FLOORF=1 20 REPLACE_FLOORF=1
21 fi 21 fi
22 else 22 else
23 REPLACE_FLOORF=1 23 HAVE_DECL_FLOORF=0
24 fi 24 fi
25 if test $REPLACE_FLOORF = 1; then 25 if test $HAVE_DECL_FLOORF = 0 || test $REPLACE_FLOORF = 1; then
26 AC_LIBOBJ([floorf]) 26 AC_LIBOBJ([floorf])
27 FLOORF_LIBM= 27 FLOORF_LIBM=
28 fi 28 fi
29 AC_SUBST([REPLACE_FLOORF])
30 AC_SUBST([FLOORF_LIBM]) 29 AC_SUBST([FLOORF_LIBM])
31]) 30])
32 31
diff --git a/gl/m4/fstypename.m4 b/gl/m4/fstypename.m4
index aa676f3a..9e81efe3 100644
--- a/gl/m4/fstypename.m4
+++ b/gl/m4/fstypename.m4
@@ -6,7 +6,8 @@ dnl See if struct statfs has the f_fstypename member.
6dnl If so, define HAVE_STRUCT_STATFS_F_FSTYPENAME. 6dnl If so, define HAVE_STRUCT_STATFS_F_FSTYPENAME.
7dnl 7dnl
8 8
9# Copyright (C) 1998, 1999, 2001, 2004, 2006 Free Software Foundation, Inc. 9# Copyright (C) 1998-1999, 2001, 2004, 2006, 2009-2010 Free Software
10# Foundation, Inc.
10# This file is free software; the Free Software Foundation 11# This file is free software; the Free Software Foundation
11# gives unlimited permission to copy and/or distribute it, 12# gives unlimited permission to copy and/or distribute it,
12# with or without modifications, as long as this notice is preserved. 13# with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/fsusage.m4 b/gl/m4/fsusage.m4
index 8b8cbf72..216b9dd8 100644
--- a/gl/m4/fsusage.m4
+++ b/gl/m4/fsusage.m4
@@ -1,7 +1,7 @@
1# serial 24 1# serial 25
2# Obtaining file system usage information. 2# Obtaining file system usage information.
3 3
4# Copyright (C) 1997-1998, 2000-2001, 2003-2009 Free Software Foundation, Inc. 4# Copyright (C) 1997-1998, 2000-2001, 2003-2010 Free Software Foundation, Inc.
5# 5#
6# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
@@ -46,7 +46,7 @@ ac_fsusage_space=no
46if test $ac_fsusage_space = no; then 46if test $ac_fsusage_space = no; then
47 # SVR4 47 # SVR4
48 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs], 48 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
49 [AC_TRY_LINK([#include <sys/types.h> 49 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
50#if defined __GLIBC__ && defined __linux__ 50#if defined __GLIBC__ && defined __linux__
51Do not use statvfs on systems with GNU libc on Linux, because that function 51Do not use statvfs on systems with GNU libc on Linux, because that function
52stats all preceding entries in /proc/mounts, and that makes df hang if even 52stats all preceding entries in /proc/mounts, and that makes df hang if even
@@ -59,14 +59,14 @@ a system call.
59"Do not use Tru64's statvfs implementation" 59"Do not use Tru64's statvfs implementation"
60#endif 60#endif
61 61
62#include <sys/statvfs.h>], 62#include <sys/statvfs.h>]],
63 [struct statvfs fsd; statvfs (0, &fsd);], 63 [[struct statvfs fsd; statvfs (0, &fsd);]])],
64 fu_cv_sys_stat_statvfs=yes, 64 [fu_cv_sys_stat_statvfs=yes],
65 fu_cv_sys_stat_statvfs=no)]) 65 [fu_cv_sys_stat_statvfs=no])])
66 if test $fu_cv_sys_stat_statvfs = yes; then 66 if test $fu_cv_sys_stat_statvfs = yes; then
67 ac_fsusage_space=yes 67 ac_fsusage_space=yes
68 AC_DEFINE([STAT_STATVFS], [1], 68 AC_DEFINE([STAT_STATVFS], [1],
69 [ Define if there is a function named statvfs. (SVR4)]) 69 [ Define if there is a function named statvfs. (SVR4)])
70 fi 70 fi
71fi 71fi
72 72
@@ -74,7 +74,7 @@ if test $ac_fsusage_space = no; then
74 # DEC Alpha running OSF/1 74 # DEC Alpha running OSF/1
75 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)]) 75 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
76 AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1], 76 AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
77 [AC_TRY_RUN([ 77 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
78#include <sys/param.h> 78#include <sys/param.h>
79#include <sys/types.h> 79#include <sys/types.h>
80#include <sys/mount.h> 80#include <sys/mount.h>
@@ -84,15 +84,15 @@ if test $ac_fsusage_space = no; then
84 struct statfs fsd; 84 struct statfs fsd;
85 fsd.f_fsize = 0; 85 fsd.f_fsize = 0;
86 return statfs (".", &fsd, sizeof (struct statfs)) != 0; 86 return statfs (".", &fsd, sizeof (struct statfs)) != 0;
87 }], 87 }]])],
88 fu_cv_sys_stat_statfs3_osf1=yes, 88 [fu_cv_sys_stat_statfs3_osf1=yes],
89 fu_cv_sys_stat_statfs3_osf1=no, 89 [fu_cv_sys_stat_statfs3_osf1=no],
90 fu_cv_sys_stat_statfs3_osf1=no)]) 90 [fu_cv_sys_stat_statfs3_osf1=no])])
91 AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1]) 91 AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
92 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then 92 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
93 ac_fsusage_space=yes 93 ac_fsusage_space=yes
94 AC_DEFINE([STAT_STATFS3_OSF1], [1], 94 AC_DEFINE([STAT_STATFS3_OSF1], [1],
95 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)]) 95 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
96 fi 96 fi
97fi 97fi
98 98
@@ -101,7 +101,7 @@ if test $ac_fsusage_space = no; then
101 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl 101 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
102member (AIX, 4.3BSD)]) 102member (AIX, 4.3BSD)])
103 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize], 103 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
104 [AC_TRY_RUN([ 104 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
105#ifdef HAVE_SYS_PARAM_H 105#ifdef HAVE_SYS_PARAM_H
106#include <sys/param.h> 106#include <sys/param.h>
107#endif 107#endif
@@ -117,10 +117,10 @@ member (AIX, 4.3BSD)])
117 struct statfs fsd; 117 struct statfs fsd;
118 fsd.f_bsize = 0; 118 fsd.f_bsize = 0;
119 return statfs (".", &fsd) != 0; 119 return statfs (".", &fsd) != 0;
120 }], 120 }]])],
121 fu_cv_sys_stat_statfs2_bsize=yes, 121 [fu_cv_sys_stat_statfs2_bsize=yes],
122 fu_cv_sys_stat_statfs2_bsize=no, 122 [fu_cv_sys_stat_statfs2_bsize=no],
123 fu_cv_sys_stat_statfs2_bsize=no)]) 123 [fu_cv_sys_stat_statfs2_bsize=no])])
124 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize]) 124 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
125 if test $fu_cv_sys_stat_statfs2_bsize = yes; then 125 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
126 ac_fsusage_space=yes 126 ac_fsusage_space=yes
@@ -134,22 +134,23 @@ if test $ac_fsusage_space = no; then
134# SVR3 134# SVR3
135 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)]) 135 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
136 AC_CACHE_VAL([fu_cv_sys_stat_statfs4], 136 AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
137 [AC_TRY_RUN([#include <sys/types.h> 137 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
138#include <sys/types.h>
138#include <sys/statfs.h> 139#include <sys/statfs.h>
139 int 140 int
140 main () 141 main ()
141 { 142 {
142 struct statfs fsd; 143 struct statfs fsd;
143 return statfs (".", &fsd, sizeof fsd, 0) != 0; 144 return statfs (".", &fsd, sizeof fsd, 0) != 0;
144 }], 145 }]])],
145 fu_cv_sys_stat_statfs4=yes, 146 [fu_cv_sys_stat_statfs4=yes],
146 fu_cv_sys_stat_statfs4=no, 147 [fu_cv_sys_stat_statfs4=no],
147 fu_cv_sys_stat_statfs4=no)]) 148 [fu_cv_sys_stat_statfs4=no])])
148 AC_MSG_RESULT([$fu_cv_sys_stat_statfs4]) 149 AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
149 if test $fu_cv_sys_stat_statfs4 = yes; then 150 if test $fu_cv_sys_stat_statfs4 = yes; then
150 ac_fsusage_space=yes 151 ac_fsusage_space=yes
151 AC_DEFINE([STAT_STATFS4], [1], 152 AC_DEFINE([STAT_STATFS4], [1],
152 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)]) 153 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
153 fi 154 fi
154fi 155fi
155 156
@@ -158,7 +159,8 @@ if test $ac_fsusage_space = no; then
158 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl 159 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
159member (4.4BSD and NetBSD)]) 160member (4.4BSD and NetBSD)])
160 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize], 161 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
161 [AC_TRY_RUN([#include <sys/types.h> 162 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
163#include <sys/types.h>
162#ifdef HAVE_SYS_PARAM_H 164#ifdef HAVE_SYS_PARAM_H
163#include <sys/param.h> 165#include <sys/param.h>
164#endif 166#endif
@@ -171,10 +173,10 @@ member (4.4BSD and NetBSD)])
171 struct statfs fsd; 173 struct statfs fsd;
172 fsd.f_fsize = 0; 174 fsd.f_fsize = 0;
173 return statfs (".", &fsd) != 0; 175 return statfs (".", &fsd) != 0;
174 }], 176 }]])],
175 fu_cv_sys_stat_statfs2_fsize=yes, 177 [fu_cv_sys_stat_statfs2_fsize=yes],
176 fu_cv_sys_stat_statfs2_fsize=no, 178 [fu_cv_sys_stat_statfs2_fsize=no],
177 fu_cv_sys_stat_statfs2_fsize=no)]) 179 [fu_cv_sys_stat_statfs2_fsize=no])])
178 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize]) 180 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
179 if test $fu_cv_sys_stat_statfs2_fsize = yes; then 181 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
180 ac_fsusage_space=yes 182 ac_fsusage_space=yes
@@ -188,7 +190,8 @@ if test $ac_fsusage_space = no; then
188 # Ultrix 190 # Ultrix
189 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)]) 191 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
190 AC_CACHE_VAL([fu_cv_sys_stat_fs_data], 192 AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
191 [AC_TRY_RUN([#include <sys/types.h> 193 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
194#include <sys/types.h>
192#ifdef HAVE_SYS_PARAM_H 195#ifdef HAVE_SYS_PARAM_H
193#include <sys/param.h> 196#include <sys/param.h>
194#endif 197#endif
@@ -205,10 +208,10 @@ if test $ac_fsusage_space = no; then
205 /* Ultrix's statfs returns 1 for success, 208 /* Ultrix's statfs returns 1 for success,
206 0 for not mounted, -1 for failure. */ 209 0 for not mounted, -1 for failure. */
207 return statfs (".", &fsd) != 1; 210 return statfs (".", &fsd) != 1;
208 }], 211 }]])],
209 fu_cv_sys_stat_fs_data=yes, 212 [fu_cv_sys_stat_fs_data=yes],
210 fu_cv_sys_stat_fs_data=no, 213 [fu_cv_sys_stat_fs_data=no],
211 fu_cv_sys_stat_fs_data=no)]) 214 [fu_cv_sys_stat_fs_data=no])])
212 AC_MSG_RESULT([$fu_cv_sys_stat_fs_data]) 215 AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
213 if test $fu_cv_sys_stat_fs_data = yes; then 216 if test $fu_cv_sys_stat_fs_data = yes; then
214 ac_fsusage_space=yes 217 ac_fsusage_space=yes
@@ -220,12 +223,12 @@ fi
220 223
221if test $ac_fsusage_space = no; then 224if test $ac_fsusage_space = no; then
222 # SVR2 225 # SVR2
223 AC_TRY_CPP([#include <sys/filsys.h> 226 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
224 ], 227 ]])],
225 AC_DEFINE([STAT_READ_FILSYS], [1], 228 [AC_DEFINE([STAT_READ_FILSYS], [1],
226 [Define if there is no specific function for reading file systems usage 229 [Define if there is no specific function for reading file systems usage
227 information and you have the <sys/filsys.h> header file. (SVR2)]) 230 information and you have the <sys/filsys.h> header file. (SVR2)])
228 ac_fsusage_space=yes) 231 ac_fsusage_space=yes])
229fi 232fi
230 233
231AS_IF([test $ac_fsusage_space = yes], [$1], [$2]) 234AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
@@ -246,8 +249,8 @@ choke -- this is a workaround for a Sun-specific problem
246#endif 249#endif
247#include <sys/types.h> 250#include <sys/types.h>
248#include <sys/vfs.h>]], 251#include <sys/vfs.h>]],
249 [[struct statfs t; long c = *(t.f_spare); 252 [[struct statfs t; long c = *(t.f_spare);
250 if (c) return 0;]])], 253 if (c) return 0;]])],
251 [fu_cv_sys_truncating_statfs=yes], 254 [fu_cv_sys_truncating_statfs=yes],
252 [fu_cv_sys_truncating_statfs=no])]) 255 [fu_cv_sys_truncating_statfs=no])])
253 if test $fu_cv_sys_truncating_statfs = yes; then 256 if test $fu_cv_sys_truncating_statfs = yes; then
diff --git a/gl/m4/getaddrinfo.m4 b/gl/m4/getaddrinfo.m4
index 40886719..bc3066db 100644
--- a/gl/m4/getaddrinfo.m4
+++ b/gl/m4/getaddrinfo.m4
@@ -1,5 +1,5 @@
1# getaddrinfo.m4 serial 20 1# getaddrinfo.m4 serial 23
2dnl Copyright (C) 2004-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -25,7 +25,7 @@ AC_DEFUN([gl_GETADDRINFO],
25 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB" 25 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
26 26
27 AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [ 27 AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
28 AC_TRY_LINK([ 28 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
29#include <sys/types.h> 29#include <sys/types.h>
30#ifdef HAVE_SYS_SOCKET_H 30#ifdef HAVE_SYS_SOCKET_H
31#include <sys/socket.h> 31#include <sys/socket.h>
@@ -34,21 +34,21 @@ AC_DEFUN([gl_GETADDRINFO],
34#include <netdb.h> 34#include <netdb.h>
35#endif 35#endif
36#include <stddef.h> 36#include <stddef.h>
37], [getaddrinfo("", "", NULL, NULL);], 37]], [[getaddrinfo("", "", NULL, NULL);]])],
38 [gl_cv_func_getaddrinfo=yes], 38 [gl_cv_func_getaddrinfo=yes],
39 [gl_cv_func_getaddrinfo=no])]) 39 [gl_cv_func_getaddrinfo=no])])
40 if test $gl_cv_func_getaddrinfo = no; then 40 if test $gl_cv_func_getaddrinfo = no; then
41 AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32], 41 AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32],
42 gl_cv_w32_getaddrinfo, [ 42 gl_cv_w32_getaddrinfo, [
43 gl_cv_w32_getaddrinfo=no 43 gl_cv_w32_getaddrinfo=no
44 am_save_LIBS="$LIBS" 44 am_save_LIBS="$LIBS"
45 LIBS="$LIBS -lws2_32" 45 LIBS="$LIBS -lws2_32"
46 AC_TRY_LINK([ 46 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
47#ifdef HAVE_WS2TCPIP_H 47#ifdef HAVE_WS2TCPIP_H
48#include <ws2tcpip.h> 48#include <ws2tcpip.h>
49#endif 49#endif
50#include <stddef.h> 50#include <stddef.h>
51], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes) 51]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])], [gl_cv_w32_getaddrinfo=yes])
52 LIBS="$am_save_LIBS" 52 LIBS="$am_save_LIBS"
53 ]) 53 ])
54 if test "$gl_cv_w32_getaddrinfo" = "yes"; then 54 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
@@ -64,7 +64,7 @@ AC_DEFUN([gl_GETADDRINFO],
64 # header included somehow. 64 # header included somehow.
65 AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)], 65 AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
66 gl_cv_func_gai_strerror, [ 66 gl_cv_func_gai_strerror, [
67 AC_TRY_LINK([ 67 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
68#include <sys/types.h> 68#include <sys/types.h>
69#ifdef HAVE_SYS_SOCKET_H 69#ifdef HAVE_SYS_SOCKET_H
70#include <sys/socket.h> 70#include <sys/socket.h>
@@ -76,7 +76,7 @@ AC_DEFUN([gl_GETADDRINFO],
76#include <ws2tcpip.h> 76#include <ws2tcpip.h>
77#endif 77#endif
78#include <stddef.h> 78#include <stddef.h>
79], [gai_strerror (NULL);], 79]], [[gai_strerror (NULL);]])],
80 [gl_cv_func_gai_strerror=yes], 80 [gl_cv_func_gai_strerror=yes],
81 [gl_cv_func_gai_strerror=no])]) 81 [gl_cv_func_gai_strerror=no])])
82 if test $gl_cv_func_gai_strerror = no; then 82 if test $gl_cv_func_gai_strerror = no; then
@@ -96,6 +96,7 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
96 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H 96 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
97 AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB 97 AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
98 AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB 98 AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
99 AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB
99 AC_REQUIRE([AC_C_RESTRICT]) 100 AC_REQUIRE([AC_C_RESTRICT])
100 AC_REQUIRE([gl_SOCKET_FAMILIES]) 101 AC_REQUIRE([gl_SOCKET_FAMILIES])
101 AC_REQUIRE([gl_HEADER_SYS_SOCKET]) 102 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
@@ -163,4 +164,10 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
163 *" $SERVENT_LIB "*) ;; 164 *" $SERVENT_LIB "*) ;;
164 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;; 165 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
165 esac 166 esac
167
168 dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
169 case " $GETADDRINFO_LIB " in
170 *" $INET_NTOP_LIB "*) ;;
171 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;;
172 esac
166]) 173])
diff --git a/gl/m4/getdtablesize.m4 b/gl/m4/getdtablesize.m4
new file mode 100644
index 00000000..d2386284
--- /dev/null
+++ b/gl/m4/getdtablesize.m4
@@ -0,0 +1,15 @@
1# getdtablesize.m4 serial 1
2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_GETDTABLESIZE],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_CHECK_FUNCS_ONCE([getdtablesize])
11 if test $ac_cv_func_getdtablesize != yes; then
12 HAVE_GETDTABLESIZE=0
13 AC_LIBOBJ([getdtablesize])
14 fi
15])
diff --git a/gl/m4/gethostname.m4 b/gl/m4/gethostname.m4
index 6b6fca95..ef0b43ef 100644
--- a/gl/m4/gethostname.m4
+++ b/gl/m4/gethostname.m4
@@ -1,21 +1,101 @@
1# gethostname.m4 serial 5 1# gethostname.m4 serial 9
2dnl Copyright (C) 2002, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7# Ensure
8# - the gethostname() function,
9# - the HOST_NAME_MAX macro in <limits.h>.
7AC_DEFUN([gl_FUNC_GETHOSTNAME], 10AC_DEFUN([gl_FUNC_GETHOSTNAME],
8[ 11[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 12 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 gl_PREREQ_SYS_H_WINSOCK2 13 gl_PREREQ_SYS_H_WINSOCK2
11 AC_REPLACE_FUNCS([gethostname]) 14
12 if test $ac_cv_func_gethostname = no; then 15 dnl Where is gethostname() defined?
16 dnl - On native Windows, it is in ws2_32.dll.
17 dnl - Otherwise is is in libc.
18 GETHOSTNAME_LIB=
19 AC_CHECK_FUNCS([gethostname], , [
20 AC_CACHE_CHECK([for gethostname in winsock2.h and -lws2_32],
21 [gl_cv_w32_gethostname],
22 [gl_cv_w32_gethostname=no
23 gl_save_LIBS="$LIBS"
24 LIBS="$LIBS -lws2_32"
25 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
26#ifdef HAVE_WINSOCK2_H
27#include <winsock2.h>
28#endif
29#include <stddef.h>
30]], [[gethostname(NULL, 0);]])], [gl_cv_w32_gethostname=yes])
31 LIBS="$gl_save_LIBS"
32 ])
33 if test "$gl_cv_w32_gethostname" = "yes"; then
34 GETHOSTNAME_LIB="-lws2_32"
35 fi
36 ])
37 AC_SUBST([GETHOSTNAME_LIB])
38
39 if test "$ac_cv_func_gethostname" = no; then
40 AC_LIBOBJ([gethostname])
13 HAVE_GETHOSTNAME=0 41 HAVE_GETHOSTNAME=0
14 gl_PREREQ_GETHOSTNAME 42 gl_PREREQ_GETHOSTNAME
15 fi 43 fi
44
45 dnl Also provide HOST_NAME_MAX when <limits.h> lacks it.
46 dnl - On most Unix systems, use MAXHOSTNAMELEN from <sys/param.h> instead.
47 dnl - On Solaris, Cygwin, BeOS, use MAXHOSTNAMELEN from <netdb.h> instead.
48 dnl - On mingw, use 256, because
49 dnl <http://msdn.microsoft.com/en-us/library/ms738527.aspx> says:
50 dnl "if a buffer of 256 bytes is passed in the name parameter and
51 dnl the namelen parameter is set to 256, the buffer size will always
52 dnl be adequate."
53 dnl With this, there is no need to use sysconf (_SC_HOST_NAME_MAX), which
54 dnl is not a compile-time constant.
55 dnl We cannot override <limits.h> using the usual technique, because
56 dnl gl_CHECK_NEXT_HEADERS does not work for <limits.h>. Therefore retrieve
57 dnl the value of HOST_NAME_MAX at configure time.
58 AC_CHECK_HEADERS_ONCE([sys/param.h])
59 AC_CHECK_HEADERS_ONCE([sys/socket.h])
60 AC_CHECK_HEADERS_ONCE([netdb.h])
61 AC_CACHE_CHECK([for HOST_NAME_MAX], [gl_cv_decl_HOST_NAME_MAX], [
62 gl_cv_decl_HOST_NAME_MAX=
63 AC_EGREP_CPP([lucky], [
64#include <limits.h>
65#ifdef HOST_NAME_MAX
66lucky
67#endif
68 ], [gl_cv_decl_HOST_NAME_MAX=yes])
69 if test -z "$gl_cv_decl_HOST_NAME_MAX"; then
70 dnl It's not defined in <limits.h>. Substitute it.
71 if test "$gl_cv_w32_gethostname" = yes; then
72 dnl mingw.
73 gl_cv_decl_HOST_NAME_MAX=256
74 else
75 _AC_COMPUTE_INT([MAXHOSTNAMELEN], [gl_cv_decl_HOST_NAME_MAX], [
76#include <sys/types.h>
77#if HAVE_SYS_PARAM_H
78# include <sys/param.h>
79#endif
80#if HAVE_SYS_SOCKET_H
81# include <sys/socket.h>
82#endif
83#if HAVE_NETDB_H
84# include <netdb.h>
85#endif
86])
87 fi
88 fi
89 ])
90 if test "$gl_cv_decl_HOST_NAME_MAX" != yes; then
91 AC_DEFINE_UNQUOTED([HOST_NAME_MAX], [$gl_cv_decl_HOST_NAME_MAX],
92 [Define HOST_NAME_MAX when <limits.h> does not define it.])
93 fi
16]) 94])
17 95
18# Prerequisites of lib/gethostname.c. 96# Prerequisites of lib/gethostname.c.
19AC_DEFUN([gl_PREREQ_GETHOSTNAME], [ 97AC_DEFUN([gl_PREREQ_GETHOSTNAME], [
20 AC_CHECK_FUNCS([uname]) 98 if test "$gl_cv_w32_gethostname" != "yes"; then
99 AC_CHECK_FUNCS([uname])
100 fi
21]) 101])
diff --git a/gl/m4/getloadavg.m4 b/gl/m4/getloadavg.m4
index 015bcac2..0a731c4f 100644
--- a/gl/m4/getloadavg.m4
+++ b/gl/m4/getloadavg.m4
@@ -1,7 +1,7 @@
1# Check for getloadavg. 1# Check for getloadavg.
2 2
3# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003, 3# Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2010 Free Software
4# 2006, 2008, 2009 Free Software Foundation, Inc. 4# Foundation, Inc.
5 5
6# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
@@ -60,17 +60,17 @@ if test $gl_have_func = no; then
60 gl_getloadavg_LIBS=$LIBS 60 gl_getloadavg_LIBS=$LIBS
61 LIBS="-L/usr/local/lib $LIBS" 61 LIBS="-L/usr/local/lib $LIBS"
62 AC_CHECK_LIB([getloadavg], [getloadavg], 62 AC_CHECK_LIB([getloadavg], [getloadavg],
63 [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS]) 63 [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
64fi 64fi
65 65
66# Make sure it is really in the library, if we think we found it, 66# Make sure it is really in the library, if we think we found it,
67# otherwise set up the replacement function. 67# otherwise set up the replacement function.
68AC_CHECK_FUNCS([getloadavg], [], 68AC_CHECK_FUNCS([getloadavg], [],
69 [gl_PREREQ_GETLOADAVG]) 69 [gl_PREREQ_GETLOADAVG])
70 70
71# Some definitions of getloadavg require that the program be installed setgid. 71# Some definitions of getloadavg require that the program be installed setgid.
72AC_CACHE_CHECK([whether getloadavg requires setgid], 72AC_CACHE_CHECK([whether getloadavg requires setgid],
73 gl_cv_func_getloadavg_setgid, 73 gl_cv_func_getloadavg_setgid,
74[AC_EGREP_CPP([Yowza Am I SETGID yet], 74[AC_EGREP_CPP([Yowza Am I SETGID yet],
75[#define CONFIGURING_GETLOADAVG 75[#define CONFIGURING_GETLOADAVG
76#include "$srcdir/$1/getloadavg.c" 76#include "$srcdir/$1/getloadavg.c"
@@ -78,13 +78,13 @@ AC_CACHE_CHECK([whether getloadavg requires setgid],
78Yowza Am I SETGID yet 78Yowza Am I SETGID yet
79#endif 79#endif
80], 80],
81 gl_cv_func_getloadavg_setgid=yes, 81 gl_cv_func_getloadavg_setgid=yes,
82 gl_cv_func_getloadavg_setgid=no)]) 82 gl_cv_func_getloadavg_setgid=no)])
83if test $gl_cv_func_getloadavg_setgid = yes; then 83if test $gl_cv_func_getloadavg_setgid = yes; then
84 NEED_SETGID=true 84 NEED_SETGID=true
85 AC_DEFINE([GETLOADAVG_PRIVILEGED], [1], 85 AC_DEFINE([GETLOADAVG_PRIVILEGED], [1],
86 [Define to 1 if the `getloadavg' function needs to be run setuid 86 [Define to 1 if the `getloadavg' function needs to be run setuid
87 or setgid.]) 87 or setgid.])
88else 88else
89 NEED_SETGID=false 89 NEED_SETGID=false
90fi 90fi
@@ -98,8 +98,8 @@ if test $gl_cv_func_getloadavg_setgid = yes; then
98 test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem` 98 test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
99 gl_cv_group_kmem=`echo $ac_ls_output \ 99 gl_cv_group_kmem=`echo $ac_ls_output \
100 | sed -ne ['s/[ ][ ]*/ /g 100 | sed -ne ['s/[ ][ ]*/ /g
101 s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/ 101 s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/
102 / /s/.* //;p']` 102 / /s/.* //;p']`
103]) 103])
104 AC_SUBST([KMEM_GROUP], [$gl_cv_group_kmem])dnl 104 AC_SUBST([KMEM_GROUP], [$gl_cv_group_kmem])dnl
105fi 105fi
@@ -154,8 +154,8 @@ if test $gl_have_func = no; then
154 [gl_have_func=yes 154 [gl_have_func=yes
155 AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.]) 155 AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
156 AC_DEFINE([UMAX4_3], [1], 156 AC_DEFINE([UMAX4_3], [1],
157 [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h> 157 [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
158 instead of <sys/cpustats.h>.])]) 158 instead of <sys/cpustats.h>.])])
159fi 159fi
160 160
161if test $gl_have_func = no; then 161if test $gl_have_func = no; then
@@ -169,10 +169,19 @@ fi
169 169
170AC_CHECK_HEADERS([nlist.h], 170AC_CHECK_HEADERS([nlist.h],
171[AC_CHECK_MEMBERS([struct nlist.n_un.n_name], 171[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
172 [AC_DEFINE([NLIST_NAME_UNION], [1], 172 [AC_DEFINE([NLIST_NAME_UNION], [1],
173 [Define to 1 if your `struct nlist' has an 173 [Define to 1 if your `struct nlist' has an
174 `n_un' member. Obsolete, depend on 174 `n_un' member. Obsolete, depend on
175 `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [], 175 `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
176 [@%:@include <nlist.h>]) 176 [@%:@include <nlist.h>])
177 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
178 [[struct nlist x;
179 #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
180 x.n_un.n_name = "";
181 #else
182 x.n_name = "";
183 #endif]])],
184 [AC_DEFINE([N_NAME_POINTER], [1],
185 [Define to 1 if the nlist n_name member is a pointer])])
177])dnl 186])dnl
178])# gl_PREREQ_GETLOADAVG 187])# gl_PREREQ_GETLOADAVG
diff --git a/gl/m4/getopt.m4 b/gl/m4/getopt.m4
index 9b683c2f..a19805ea 100644
--- a/gl/m4/getopt.m4
+++ b/gl/m4/getopt.m4
@@ -1,82 +1,272 @@
1# getopt.m4 serial 14 1# getopt.m4 serial 24
2dnl Copyright (C) 2002-2006, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7# The getopt module assume you want GNU getopt, with getopt_long etc, 7# Request a POSIX compliant getopt function.
8# rather than vanilla POSIX getopt. This means your code should 8AC_DEFUN([gl_FUNC_GETOPT_POSIX],
9# always include <getopt.h> for the getopt prototypes. 9[
10 m4_divert_text([DEFAULTS], [gl_getopt_required=POSIX])
11 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12 gl_GETOPT_IFELSE([
13 gl_REPLACE_GETOPT
14 ],
15 [])
16])
17
18# Request a POSIX compliant getopt function with GNU extensions (such as
19# options with optional arguments) and the functions getopt_long,
20# getopt_long_only.
21AC_DEFUN([gl_FUNC_GETOPT_GNU],
22[
23 m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU])
24
25 AC_REQUIRE([gl_FUNC_GETOPT_POSIX])
26])
10 27
11AC_DEFUN([gl_GETOPT_SUBSTITUTE], 28# Request the gnulib implementation of the getopt functions unconditionally.
29# argp.m4 uses this.
30AC_DEFUN([gl_REPLACE_GETOPT],
12[ 31[
32 dnl Arrange for getopt.h to be created.
33 gl_GETOPT_SUBSTITUTE_HEADER
34 dnl Arrange for unistd.h to include getopt.h.
35 GNULIB_UNISTD_H_GETOPT=1
36 dnl Arrange to compile the getopt implementation.
13 AC_LIBOBJ([getopt]) 37 AC_LIBOBJ([getopt])
14 AC_LIBOBJ([getopt1]) 38 AC_LIBOBJ([getopt1])
15 gl_GETOPT_SUBSTITUTE_HEADER
16 gl_PREREQ_GETOPT 39 gl_PREREQ_GETOPT
17]) 40])
18 41
19AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], 42# emacs' configure.in uses this.
43AC_DEFUN([gl_GETOPT_IFELSE],
20[ 44[
21 GETOPT_H=getopt.h 45 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
22 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]], 46 AS_IF([test -n "$gl_replace_getopt"], [$1], [$2])
23 [Define to rpl_ if the getopt replacement functions and variables
24 should be used.])
25 AC_SUBST([GETOPT_H])
26]) 47])
27 48
49# Determine whether to replace the entire getopt facility.
28AC_DEFUN([gl_GETOPT_CHECK_HEADERS], 50AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
29[ 51[
30 if test -z "$GETOPT_H"; then 52 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
31 AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h]) 53
54 dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt.
55 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
56
57 gl_CHECK_NEXT_HEADERS([getopt.h])
58 AC_CHECK_HEADERS_ONCE([getopt.h])
59 if test $ac_cv_header_getopt_h = yes; then
60 HAVE_GETOPT_H=1
61 else
62 HAVE_GETOPT_H=0
63 fi
64 AC_SUBST([HAVE_GETOPT_H])
65
66 gl_replace_getopt=
67
68 dnl Test whether <getopt.h> is available.
69 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
70 AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes])
71 fi
72
73 dnl Test whether the function getopt_long is available.
74 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
75 AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
32 fi 76 fi
33 77
34 if test -z "$GETOPT_H"; then 78 dnl BSD getopt_long uses an incompatible method to reset option processing.
35 AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h]) 79 dnl Existence of the variable, in and of itself, is not a reason to replace
80 dnl getopt, but knowledge of the variable is needed to determine how to
81 dnl reset and whether a reset reparses the environment.
82 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
83 AC_CHECK_DECLS([optreset], [], [],
84 [[#include <getopt.h>]])
36 fi 85 fi
37 86
38 dnl BSD getopt_long uses an incompatible method to reset option processing, 87 dnl mingw's getopt (in libmingwex.a) does weird things when the options
39 dnl and (as of 2004-10-15) mishandles optional option-arguments. 88 dnl strings starts with '+' and it's not the first call. Some internal state
40 if test -z "$GETOPT_H"; then 89 dnl is left over from earlier calls, and neither setting optind = 0 nor
41 AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>]) 90 dnl setting optreset = 1 get rid of this internal state.
91 dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
92 if test -z "$gl_replace_getopt"; then
93 AC_CACHE_CHECK([whether getopt is POSIX compatible],
94 [gl_cv_func_getopt_posix],
95 [
96 dnl This test fails on mingw and succeeds on all other platforms.
97 AC_RUN_IFELSE([AC_LANG_SOURCE([[
98#include <unistd.h>
99#include <stdlib.h>
100#include <string.h>
101
102#if !HAVE_DECL_OPTRESET
103# define OPTIND_MIN 0
104#else
105# define OPTIND_MIN 1
106#endif
107
108int
109main ()
110{
111 {
112 int argc = 0;
113 char *argv[10];
114 int c;
115
116 argv[argc++] = "program";
117 argv[argc++] = "-a";
118 argv[argc++] = "foo";
119 argv[argc++] = "bar";
120 argv[argc] = NULL;
121 optind = OPTIND_MIN;
122 opterr = 0;
123
124 c = getopt (argc, argv, "ab");
125 if (!(c == 'a'))
126 return 1;
127 c = getopt (argc, argv, "ab");
128 if (!(c == -1))
129 return 2;
130 if (!(optind == 2))
131 return 3;
132 }
133 /* Some internal state exists at this point. */
134 {
135 int argc = 0;
136 char *argv[10];
137 int c;
138
139 argv[argc++] = "program";
140 argv[argc++] = "donald";
141 argv[argc++] = "-p";
142 argv[argc++] = "billy";
143 argv[argc++] = "duck";
144 argv[argc++] = "-a";
145 argv[argc++] = "bar";
146 argv[argc] = NULL;
147 optind = OPTIND_MIN;
148 opterr = 0;
149
150 c = getopt (argc, argv, "+abp:q:");
151 if (!(c == -1))
152 return 4;
153 if (!(strcmp (argv[0], "program") == 0))
154 return 5;
155 if (!(strcmp (argv[1], "donald") == 0))
156 return 6;
157 if (!(strcmp (argv[2], "-p") == 0))
158 return 7;
159 if (!(strcmp (argv[3], "billy") == 0))
160 return 8;
161 if (!(strcmp (argv[4], "duck") == 0))
162 return 9;
163 if (!(strcmp (argv[5], "-a") == 0))
164 return 10;
165 if (!(strcmp (argv[6], "bar") == 0))
166 return 11;
167 if (!(optind == 1))
168 return 12;
169 }
170
171 return 0;
172}
173]])],
174 [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no],
175 [case "$host_os" in
176 mingw*) gl_cv_func_getopt_posix="guessing no";;
177 *) gl_cv_func_getopt_posix="guessing yes";;
178 esac
179 ])
180 ])
181 case "$gl_cv_func_getopt_posix" in
182 *no) gl_replace_getopt=yes ;;
183 esac
42 fi 184 fi
43 185
44 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an 186 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
45 dnl option string (as of 2005-05-05). 187 AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_getopt_gnu],
46 if test -z "$GETOPT_H"; then 188 [# Even with POSIXLY_CORRECT, the GNU extension of leading '-' in the
47 AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt], 189 # optstring is necessary for programs like m4 that have POSIX-mandated
48 [AC_RUN_IFELSE( 190 # semantics for supporting options interspersed with files.
49 [AC_LANG_PROGRAM([[#include <getopt.h>]], 191 # Also, since getopt_long is a GNU extension, we require optind=0.
50 [[ 192 gl_had_POSIXLY_CORRECT=${POSIXLY_CORRECT:+yes}
51 char *myargv[3]; 193 POSIXLY_CORRECT=1
52 myargv[0] = "conftest"; 194 export POSIXLY_CORRECT
53 myargv[1] = "-+"; 195 AC_RUN_IFELSE(
54 myargv[2] = 0; 196 [AC_LANG_PROGRAM([[#include <getopt.h>
55 return getopt (2, myargv, "+a") != '?'; 197 #include <stddef.h>
56 ]])], 198 #include <string.h>
57 [gl_cv_func_gnu_getopt=yes], 199 ]], [[
58 [gl_cv_func_gnu_getopt=no], 200 /* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw,
59 [dnl cross compiling - pessimistically guess based on decls 201 and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
60 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an 202 OSF/1 5.1, Solaris 10. */
61 dnl option string (as of 2005-05-05). 203 {
62 AC_CHECK_DECL([getopt_clip], 204 char *myargv[3];
63 [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes], 205 myargv[0] = "conftest";
64 [#include <getopt.h>])])]) 206 myargv[1] = "-+";
65 if test "$gl_cv_func_gnu_getopt" = "no"; then 207 myargv[2] = 0;
66 GETOPT_H=getopt.h 208 opterr = 0;
209 if (getopt (2, myargv, "+a") != '?')
210 return 1;
211 }
212 /* This code succeeds on glibc 2.8, mingw,
213 and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11,
214 IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x. */
215 {
216 char *argv[] = { "program", "-p", "foo", "bar", NULL };
217
218 optind = 1;
219 if (getopt (4, argv, "p::") != 'p')
220 return 2;
221 if (optarg != NULL)
222 return 3;
223 if (getopt (4, argv, "p::") != -1)
224 return 4;
225 if (optind != 2)
226 return 5;
227 }
228 /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0. */
229 {
230 char *argv[] = { "program", "foo", "-p", NULL };
231 optind = 0;
232 if (getopt (3, argv, "-p") != 1)
233 return 6;
234 if (getopt (3, argv, "-p") != 'p')
235 return 7;
236 }
237 return 0;
238 ]])],
239 [gl_cv_func_getopt_gnu=yes],
240 [gl_cv_func_getopt_gnu=no],
241 [dnl Cross compiling. Guess based on host and declarations.
242 case $host_os:$ac_cv_have_decl_optreset in
243 *-gnu*:* | mingw*:*) gl_cv_func_getopt_gnu=no;;
244 *:yes) gl_cv_func_getopt_gnu=no;;
245 *) gl_cv_func_getopt_gnu=yes;;
246 esac
247 ])
248 if test "$gl_had_POSIXLY_CORRECT" != yes; then
249 AS_UNSET([POSIXLY_CORRECT])
250 fi
251 ])
252 if test "$gl_cv_func_getopt_gnu" = "no"; then
253 gl_replace_getopt=yes
67 fi 254 fi
68 fi 255 fi
69]) 256])
70 257
71AC_DEFUN([gl_GETOPT_IFELSE], 258# emacs' configure.in uses this.
259AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
72[ 260[
73 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS]) 261 GETOPT_H=getopt.h
74 AS_IF([test -n "$GETOPT_H"], [$1], [$2]) 262 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
263 [Define to rpl_ if the getopt replacement functions and variables
264 should be used.])
265 AC_SUBST([GETOPT_H])
75]) 266])
76 267
77AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
78
79# Prerequisites of lib/getopt*. 268# Prerequisites of lib/getopt*.
269# emacs' configure.in uses this.
80AC_DEFUN([gl_PREREQ_GETOPT], 270AC_DEFUN([gl_PREREQ_GETOPT],
81[ 271[
82 AC_CHECK_DECLS_ONCE([getenv]) 272 AC_CHECK_DECLS_ONCE([getenv])
diff --git a/gl/m4/gettext.m4 b/gl/m4/gettext.m4
index d90c8500..d6dc3fe2 100644
--- a/gl/m4/gettext.m4
+++ b/gl/m4/gettext.m4
@@ -1,5 +1,5 @@
1# gettext.m4 serial 62 (gettext-0.18) 1# gettext.m4 serial 62 (gettext-0.18)
2dnl Copyright (C) 1995-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/glibc2.m4 b/gl/m4/glibc2.m4
index fe58a0f3..f148c12c 100644
--- a/gl/m4/glibc2.m4
+++ b/gl/m4/glibc2.m4
@@ -1,5 +1,5 @@
1# glibc2.m4 serial 2 1# glibc2.m4 serial 2
2dnl Copyright (C) 2000-2002, 2004, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2004, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -12,16 +12,16 @@ AC_DEFUN([gt_GLIBC2],
12 AC_CACHE_CHECK([whether we are using the GNU C Library 2 or newer], 12 AC_CACHE_CHECK([whether we are using the GNU C Library 2 or newer],
13 [ac_cv_gnu_library_2], 13 [ac_cv_gnu_library_2],
14 [AC_EGREP_CPP([Lucky GNU user], 14 [AC_EGREP_CPP([Lucky GNU user],
15 [ 15 [
16#include <features.h> 16#include <features.h>
17#ifdef __GNU_LIBRARY__ 17#ifdef __GNU_LIBRARY__
18 #if (__GLIBC__ >= 2) 18 #if (__GLIBC__ >= 2)
19 Lucky GNU user 19 Lucky GNU user
20 #endif 20 #endif
21#endif 21#endif
22 ], 22 ],
23 [ac_cv_gnu_library_2=yes], 23 [ac_cv_gnu_library_2=yes],
24 [ac_cv_gnu_library_2=no]) 24 [ac_cv_gnu_library_2=no])
25 ] 25 ]
26 ) 26 )
27 AC_SUBST([GLIBC2]) 27 AC_SUBST([GLIBC2])
diff --git a/gl/m4/glibc21.m4 b/gl/m4/glibc21.m4
index 93fbf474..68ada9d4 100644
--- a/gl/m4/glibc21.m4
+++ b/gl/m4/glibc21.m4
@@ -1,5 +1,5 @@
1# glibc21.m4 serial 4 1# glibc21.m4 serial 4
2dnl Copyright (C) 2000-2002, 2004, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2004, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -12,16 +12,16 @@ AC_DEFUN([gl_GLIBC21],
12 AC_CACHE_CHECK([whether we are using the GNU C Library 2.1 or newer], 12 AC_CACHE_CHECK([whether we are using the GNU C Library 2.1 or newer],
13 [ac_cv_gnu_library_2_1], 13 [ac_cv_gnu_library_2_1],
14 [AC_EGREP_CPP([Lucky GNU user], 14 [AC_EGREP_CPP([Lucky GNU user],
15 [ 15 [
16#include <features.h> 16#include <features.h>
17#ifdef __GNU_LIBRARY__ 17#ifdef __GNU_LIBRARY__
18 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) 18 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
19 Lucky GNU user 19 Lucky GNU user
20 #endif 20 #endif
21#endif 21#endif
22 ], 22 ],
23 [ac_cv_gnu_library_2_1=yes], 23 [ac_cv_gnu_library_2_1=yes],
24 [ac_cv_gnu_library_2_1=no]) 24 [ac_cv_gnu_library_2_1=no])
25 ] 25 ]
26 ) 26 )
27 AC_SUBST([GLIBC21]) 27 AC_SUBST([GLIBC21])
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 385f5432..0ac6b969 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -1,4 +1,4 @@
1# Copyright (C) 2002-2009 Free Software Foundation, Inc. 1# Copyright (C) 2002-2010 Free Software Foundation, Inc.
2# 2#
3# This file is free software, distributed under the terms of the GNU 3# This file is free software, distributed under the terms of the GNU
4# General Public License. As a special exception to the GNU General 4# General Public License. As a special exception to the GNU General
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index c8fda203..9cc519e7 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,5 +1,5 @@
1# gnulib-common.m4 serial 11 1# gnulib-common.m4 serial 18
2dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -23,23 +23,77 @@ AC_DEFUN([gl_COMMON_BODY], [
23# define __GNUC_STDC_INLINE__ 1 23# define __GNUC_STDC_INLINE__ 1
24#endif]) 24#endif])
25 AH_VERBATIM([unused_parameter], 25 AH_VERBATIM([unused_parameter],
26[/* Define as a marker that can be attached to function parameter declarations 26[/* Define as a marker that can be attached to declarations that might not
27 for parameters that are not used. This helps to reduce warnings, such as 27 be used. This helps to reduce warnings, such as from
28 from GCC -Wunused-parameter. */ 28 GCC -Wunused-parameter. */
29#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 29#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
30# define _UNUSED_PARAMETER_ __attribute__ ((__unused__)) 30# define _GL_UNUSED __attribute__ ((__unused__))
31#else 31#else
32# define _UNUSED_PARAMETER_ 32# define _GL_UNUSED
33#endif 33#endif
34/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
35 is a misnomer outside of parameter lists. */
36#define _UNUSED_PARAMETER_ _GL_UNUSED
34]) 37])
35]) 38])
36 39
40# gl_MODULE_INDICATOR_CONDITION
41# expands to a C preprocessor expression that evaluates to 1 or 0, depending
42# whether a gnulib module that has been requested shall be considered present
43# or not.
44AC_DEFUN([gl_MODULE_INDICATOR_CONDITION], [1])
45
46# gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
47# sets the shell variable that indicates the presence of the given module to
48# a C preprocessor expression that will evaluate to 1.
49AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
50[
51 GNULIB_[]m4_translit([[$1]],
52 [abcdefghijklmnopqrstuvwxyz./-],
53 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=gl_MODULE_INDICATOR_CONDITION
54])
55
37# gl_MODULE_INDICATOR([modulename]) 56# gl_MODULE_INDICATOR([modulename])
38# defines a C macro indicating the presence of the given module. 57# defines a C macro indicating the presence of the given module
58# in a location where it can be used.
59# | Value | Value |
60# | in lib/ | in tests/ |
61# --------------------------------------------+---------+-----------+
62# Module present among main modules: | 1 | 1 |
63# --------------------------------------------+---------+-----------+
64# Module present among tests-related modules: | 0 | 1 |
65# --------------------------------------------+---------+-----------+
66# Module not present at all: | 0 | 0 |
67# --------------------------------------------+---------+-----------+
39AC_DEFUN([gl_MODULE_INDICATOR], 68AC_DEFUN([gl_MODULE_INDICATOR],
40[ 69[
41 AC_DEFINE([GNULIB_]translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1], 70 AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
42 [Define to 1 when using the gnulib module ]$1[.]) 71 [abcdefghijklmnopqrstuvwxyz./-],
72 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
73 [gl_MODULE_INDICATOR_CONDITION],
74 [Define to a C preprocessor expression that evaluates to 1 or 0,
75 depending whether the gnulib module $1 shall be considered present.])
76])
77
78# gl_MODULE_INDICATOR_FOR_TESTS([modulename])
79# defines a C macro indicating the presence of the given module
80# in lib or tests. This is useful to determine whether the module
81# should be tested.
82# | Value | Value |
83# | in lib/ | in tests/ |
84# --------------------------------------------+---------+-----------+
85# Module present among main modules: | 1 | 1 |
86# --------------------------------------------+---------+-----------+
87# Module present among tests-related modules: | 1 | 1 |
88# --------------------------------------------+---------+-----------+
89# Module not present at all: | 0 | 0 |
90# --------------------------------------------+---------+-----------+
91AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
92[
93 AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
94 [abcdefghijklmnopqrstuvwxyz./-],
95 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
96 [Define to 1 when the gnulib module $1 should be tested.])
43]) 97])
44 98
45# m4_foreach_w 99# m4_foreach_w
@@ -49,10 +103,25 @@ m4_ifndef([m4_foreach_w],
49 [m4_define([m4_foreach_w], 103 [m4_define([m4_foreach_w],
50 [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) 104 [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
51 105
106# AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
107# ----------------------------------------------------
108# Backport of autoconf-2.63b's macro.
109# Remove this macro when we can assume autoconf >= 2.64.
110m4_ifndef([AS_VAR_IF],
111[m4_define([AS_VAR_IF],
112[AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
113
52# AC_PROG_MKDIR_P 114# AC_PROG_MKDIR_P
53# is a backport of autoconf-2.60's AC_PROG_MKDIR_P. 115# is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix
54# Remove this macro when we can assume autoconf >= 2.60. 116# for interoperability with automake-1.9.6 from autoconf-2.62.
55m4_ifdef([AC_PROG_MKDIR_P], [], [ 117# Remove this macro when we can assume autoconf >= 2.62 or
118# autoconf >= 2.60 && automake >= 1.10.
119m4_ifdef([AC_PROG_MKDIR_P], [
120 dnl For automake-1.9.6 && autoconf < 2.62: Ensure MKDIR_P is AC_SUBSTed.
121 m4_define([AC_PROG_MKDIR_P],
122 m4_defn([AC_PROG_MKDIR_P])[
123 AC_SUBST([MKDIR_P])])], [
124 dnl For autoconf < 2.60: Backport of AC_PROG_MKDIR_P.
56 AC_DEFUN_ONCE([AC_PROG_MKDIR_P], 125 AC_DEFUN_ONCE([AC_PROG_MKDIR_P],
57 [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake 126 [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
58 MKDIR_P='$(mkdir_p)' 127 MKDIR_P='$(mkdir_p)'
@@ -70,13 +139,13 @@ AC_DEFUN([AC_C_RESTRICT],
70 for ac_kw in __restrict __restrict__ _Restrict restrict; do 139 for ac_kw in __restrict __restrict__ _Restrict restrict; do
71 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 140 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
72 [[typedef int * int_ptr; 141 [[typedef int * int_ptr;
73 int foo (int_ptr $ac_kw ip) { 142 int foo (int_ptr $ac_kw ip) {
74 return ip[0]; 143 return ip[0];
75 }]], 144 }]],
76 [[int s[1]; 145 [[int s[1];
77 int * $ac_kw t = s; 146 int * $ac_kw t = s;
78 t[0] = 0; 147 t[0] = 0;
79 return foo(t)]])], 148 return foo(t)]])],
80 [ac_cv_c_restrict=$ac_kw]) 149 [ac_cv_c_restrict=$ac_kw])
81 test "$ac_cv_c_restrict" != no && break 150 test "$ac_cv_c_restrict" != no && break
82 done 151 done
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 005cc4eb..4a956e44 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -1,5 +1,5 @@
1# DO NOT EDIT! GENERATED AUTOMATICALLY! 1# DO NOT EDIT! GENERATED AUTOMATICALLY!
2# Copyright (C) 2002-2009 Free Software Foundation, Inc. 2# Copyright (C) 2002-2010 Free Software Foundation, Inc.
3# 3#
4# This file is free software, distributed under the terms of the GNU 4# This file is free software, distributed under the terms of the GNU
5# General Public License. As a special exception to the GNU General 5# General Public License. As a special exception to the GNU General
@@ -25,7 +25,108 @@ AC_DEFUN([gl_EARLY],
25 m4_pattern_allow([^gl_LIBOBJS$])dnl a variable 25 m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
26 m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable 26 m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
27 AC_REQUIRE([AC_PROG_RANLIB]) 27 AC_REQUIRE([AC_PROG_RANLIB])
28 # Code from module alignof:
29 # Code from module alloca:
30 # Code from module alloca-opt:
31 # Code from module arg-nonnull:
32 # Code from module arpa_inet:
33 # Code from module base64:
34 # Code from module btowc:
35 # Code from module c++defs:
36 # Code from module c-strtod:
37 # Code from module cloexec:
38 # Code from module close-hook:
39 # Code from module configmake:
40 # Code from module dirname:
41 # Code from module dirname-lgpl:
42 # Code from module double-slash-root:
43 # Code from module dup2:
44 # Code from module errno:
45 # Code from module error:
46 # Code from module exitfail:
47 # Code from module extensions:
28 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 48 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
49 # Code from module fcntl:
50 # Code from module fcntl-h:
51 # Code from module fcntl-safer:
52 # Code from module float:
53 # Code from module floorf:
54 # Code from module fsusage:
55 # Code from module full-read:
56 # Code from module full-write:
57 # Code from module getaddrinfo:
58 # Code from module getdtablesize:
59 # Code from module gethostname:
60 # Code from module getloadavg:
61 # Code from module getopt:
62 # Code from module getopt-gnu:
63 # Code from module getopt-posix:
64 # Code from module gettext:
65 # Code from module gettext-h:
66 # Code from module havelib:
67 # Code from module hostent:
68 # Code from module include_next:
69 # Code from module inet_ntop:
70 # Code from module inline:
71 # Code from module intprops:
72 # Code from module langinfo:
73 # Code from module localcharset:
74 # Code from module locale:
75 # Code from module malloc:
76 # Code from module malloc-posix:
77 # Code from module math:
78 # Code from module mbrtowc:
79 # Code from module mbsinit:
80 # Code from module memchr:
81 # Code from module mktime:
82 # Code from module mountlist:
83 # Code from module multiarch:
84 # Code from module netdb:
85 # Code from module netinet_in:
86 # Code from module nl_langinfo:
87 # Code from module open:
88 # Code from module regex:
89 # Code from module safe-read:
90 # Code from module safe-write:
91 # Code from module servent:
92 # Code from module size_max:
93 # Code from module snprintf:
94 # Code from module sockets:
95 # Code from module socklen:
96 # Code from module ssize_t:
97 # Code from module stat:
98 # Code from module stdbool:
99 # Code from module stddef:
100 # Code from module stdint:
101 # Code from module stdio:
102 # Code from module stdlib:
103 # Code from module strdup-posix:
104 # Code from module streq:
105 # Code from module strerror:
106 # Code from module string:
107 # Code from module strndup:
108 # Code from module strnlen:
109 # Code from module strstr-simple:
110 # Code from module sys_socket:
111 # Code from module sys_stat:
112 # Code from module time:
113 # Code from module time_r:
114 # Code from module timegm:
115 # Code from module unistd:
116 # Code from module unistd-safer:
117 # Code from module vasnprintf:
118 # Code from module vasprintf:
119 # Code from module verify:
120 # Code from module vsnprintf:
121 # Code from module warn-on-use:
122 # Code from module wchar:
123 # Code from module wcrtomb:
124 # Code from module wctype:
125 # Code from module write:
126 # Code from module xalloc:
127 # Code from module xalloc-die:
128 # Code from module xsize:
129 # Code from module xstrndup:
29]) 130])
30 131
31# This macro should be invoked from ./configure.in, in the section 132# This macro should be invoked from ./configure.in, in the section
@@ -36,6 +137,7 @@ AC_DEFUN([gl_INIT],
36 gl_cond_libtool=false 137 gl_cond_libtool=false
37 gl_libdeps= 138 gl_libdeps=
38 gl_ltlibdeps= 139 gl_ltlibdeps=
140 gl_m4_base='gl/m4'
39 m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ])) 141 m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ]))
40 m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS])) 142 m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS]))
41 m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) 143 m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES]))
@@ -43,111 +145,239 @@ AC_DEFUN([gl_INIT],
43 m4_pushdef([gl_LIBSOURCES_DIR], []) 145 m4_pushdef([gl_LIBSOURCES_DIR], [])
44 gl_COMMON 146 gl_COMMON
45 gl_source_base='gl' 147 gl_source_base='gl'
148 # Code from module alignof:
149 # Code from module alloca:
150 # Code from module alloca-opt:
46 gl_FUNC_ALLOCA 151 gl_FUNC_ALLOCA
152 # Code from module arg-nonnull:
153 # Code from module arpa_inet:
47 gl_HEADER_ARPA_INET 154 gl_HEADER_ARPA_INET
48 AC_PROG_MKDIR_P 155 AC_PROG_MKDIR_P
156 # Code from module base64:
49 gl_FUNC_BASE64 157 gl_FUNC_BASE64
158 # Code from module btowc:
50 gl_FUNC_BTOWC 159 gl_FUNC_BTOWC
51 gl_WCHAR_MODULE_INDICATOR([btowc]) 160 gl_WCHAR_MODULE_INDICATOR([btowc])
161 # Code from module c++defs:
162 # Code from module c-strtod:
52 gl_C_STRTOD 163 gl_C_STRTOD
164 # Code from module cloexec:
53 gl_CLOEXEC 165 gl_CLOEXEC
166 gl_MODULE_INDICATOR_FOR_TESTS([cloexec])
167 # Code from module close-hook:
168 # Code from module configmake:
169 # Code from module dirname:
54 gl_DIRNAME 170 gl_DIRNAME
171 gl_MODULE_INDICATOR([dirname])
172 # Code from module dirname-lgpl:
173 gl_DIRNAME_LGPL
174 # Code from module double-slash-root:
55 gl_DOUBLE_SLASH_ROOT 175 gl_DOUBLE_SLASH_ROOT
176 # Code from module dup2:
177 gl_FUNC_DUP2
178 gl_UNISTD_MODULE_INDICATOR([dup2])
179 # Code from module errno:
56 gl_HEADER_ERRNO_H 180 gl_HEADER_ERRNO_H
181 # Code from module error:
57 gl_ERROR 182 gl_ERROR
58 m4_ifdef([AM_XGETTEXT_OPTION], 183 m4_ifdef([AM_XGETTEXT_OPTION],
59 [AM_XGETTEXT_OPTION([--flag=error:3:c-format]) 184 [AM_][XGETTEXT_OPTION([--flag=error:3:c-format])
60 AM_XGETTEXT_OPTION([--flag=error_at_line:5:c-format])]) 185 AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
61 gl_EXITFAIL 186 # Code from module exitfail:
187 # Code from module extensions:
188 # Code from module fcntl:
189 gl_FUNC_FCNTL
190 gl_FCNTL_MODULE_INDICATOR([fcntl])
191 # Code from module fcntl-h:
62 gl_FCNTL_H 192 gl_FCNTL_H
193 # Code from module fcntl-safer:
63 gl_FCNTL_SAFER 194 gl_FCNTL_SAFER
64 gl_MODULE_INDICATOR([fcntl-safer]) 195 gl_MODULE_INDICATOR([fcntl-safer])
196 # Code from module float:
65 gl_FLOAT_H 197 gl_FLOAT_H
198 # Code from module floorf:
66 gl_FUNC_FLOORF 199 gl_FUNC_FLOORF
67 gl_MATH_MODULE_INDICATOR([floorf]) 200 gl_MATH_MODULE_INDICATOR([floorf])
201 # Code from module fsusage:
68 gl_FSUSAGE 202 gl_FSUSAGE
203 # Code from module full-read:
204 # Code from module full-write:
205 # Code from module getaddrinfo:
69 gl_GETADDRINFO 206 gl_GETADDRINFO
70 gl_NETDB_MODULE_INDICATOR([getaddrinfo]) 207 gl_NETDB_MODULE_INDICATOR([getaddrinfo])
208 # Code from module getdtablesize:
209 gl_FUNC_GETDTABLESIZE
210 gl_UNISTD_MODULE_INDICATOR([getdtablesize])
211 # Code from module gethostname:
71 gl_FUNC_GETHOSTNAME 212 gl_FUNC_GETHOSTNAME
72 gl_UNISTD_MODULE_INDICATOR([gethostname]) 213 gl_UNISTD_MODULE_INDICATOR([gethostname])
214 # Code from module getloadavg:
73 gl_GETLOADAVG([$gl_source_base]) 215 gl_GETLOADAVG([$gl_source_base])
74 gl_STDLIB_MODULE_INDICATOR([getloadavg]) 216 gl_STDLIB_MODULE_INDICATOR([getloadavg])
75 gl_GETOPT 217 # Code from module getopt:
218 # Code from module getopt-gnu:
219 gl_FUNC_GETOPT_GNU
220 gl_MODULE_INDICATOR_FOR_TESTS([getopt-gnu])
221 # Code from module getopt-posix:
222 gl_FUNC_GETOPT_POSIX
223 # Code from module gettext:
76 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. 224 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac.
77 AM_GNU_GETTEXT_VERSION([0.17]) 225 AM_GNU_GETTEXT_VERSION([0.17])
226 # Code from module gettext-h:
78 AC_SUBST([LIBINTL]) 227 AC_SUBST([LIBINTL])
79 AC_SUBST([LTLIBINTL]) 228 AC_SUBST([LTLIBINTL])
229 # Code from module havelib:
230 # Code from module hostent:
80 gl_HOSTENT 231 gl_HOSTENT
81 gl_INET_NTOP 232 # Code from module include_next:
233 # Code from module inet_ntop:
234 gl_FUNC_INET_NTOP
82 gl_ARPA_INET_MODULE_INDICATOR([inet_ntop]) 235 gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
236 # Code from module inline:
83 gl_INLINE 237 gl_INLINE
238 # Code from module intprops:
239 # Code from module langinfo:
240 gl_LANGINFO_H
241 # Code from module localcharset:
84 gl_LOCALCHARSET 242 gl_LOCALCHARSET
85 LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(top_builddir)/$gl_source_base\"" 243 LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(top_builddir)/$gl_source_base\""
86 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT]) 244 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
245 # Code from module locale:
246 gl_LOCALE_H
247 # Code from module malloc:
87 AC_FUNC_MALLOC 248 AC_FUNC_MALLOC
88 AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.]) 249 AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.])
250 # Code from module malloc-posix:
89 gl_FUNC_MALLOC_POSIX 251 gl_FUNC_MALLOC_POSIX
90 gl_STDLIB_MODULE_INDICATOR([malloc-posix]) 252 gl_STDLIB_MODULE_INDICATOR([malloc-posix])
253 # Code from module math:
91 gl_MATH_H 254 gl_MATH_H
255 # Code from module mbrtowc:
92 gl_FUNC_MBRTOWC 256 gl_FUNC_MBRTOWC
93 gl_WCHAR_MODULE_INDICATOR([mbrtowc]) 257 gl_WCHAR_MODULE_INDICATOR([mbrtowc])
258 # Code from module mbsinit:
94 gl_FUNC_MBSINIT 259 gl_FUNC_MBSINIT
95 gl_WCHAR_MODULE_INDICATOR([mbsinit]) 260 gl_WCHAR_MODULE_INDICATOR([mbsinit])
261 # Code from module memchr:
262 gl_FUNC_MEMCHR
263 gl_STRING_MODULE_INDICATOR([memchr])
264 # Code from module mktime:
96 gl_FUNC_MKTIME 265 gl_FUNC_MKTIME
266 gl_TIME_MODULE_INDICATOR([mktime])
267 # Code from module mountlist:
97 gl_MOUNTLIST 268 gl_MOUNTLIST
269 # Code from module multiarch:
98 gl_MULTIARCH 270 gl_MULTIARCH
271 # Code from module netdb:
99 gl_HEADER_NETDB 272 gl_HEADER_NETDB
273 # Code from module netinet_in:
100 gl_HEADER_NETINET_IN 274 gl_HEADER_NETINET_IN
101 AC_PROG_MKDIR_P 275 AC_PROG_MKDIR_P
276 # Code from module nl_langinfo:
277 gl_FUNC_NL_LANGINFO
278 gl_LANGINFO_MODULE_INDICATOR([nl_langinfo])
279 # Code from module open:
102 gl_FUNC_OPEN 280 gl_FUNC_OPEN
103 gl_MODULE_INDICATOR([open])
104 gl_FCNTL_MODULE_INDICATOR([open]) 281 gl_FCNTL_MODULE_INDICATOR([open])
282 # Code from module regex:
105 gl_REGEX 283 gl_REGEX
284 # Code from module safe-read:
106 gl_SAFE_READ 285 gl_SAFE_READ
286 # Code from module safe-write:
107 gl_SAFE_WRITE 287 gl_SAFE_WRITE
288 # Code from module servent:
108 gl_SERVENT 289 gl_SERVENT
290 # Code from module size_max:
109 gl_SIZE_MAX 291 gl_SIZE_MAX
292 # Code from module snprintf:
110 gl_FUNC_SNPRINTF 293 gl_FUNC_SNPRINTF
111 gl_STDIO_MODULE_INDICATOR([snprintf]) 294 gl_STDIO_MODULE_INDICATOR([snprintf])
295 # Code from module sockets:
296 gl_SOCKETS
297 # Code from module socklen:
112 gl_TYPE_SOCKLEN_T 298 gl_TYPE_SOCKLEN_T
299 # Code from module ssize_t:
113 gt_TYPE_SSIZE_T 300 gt_TYPE_SSIZE_T
301 # Code from module stat:
302 gl_FUNC_STAT
303 gl_SYS_STAT_MODULE_INDICATOR([stat])
304 # Code from module stdbool:
114 AM_STDBOOL_H 305 AM_STDBOOL_H
306 # Code from module stddef:
307 gl_STDDEF_H
308 # Code from module stdint:
115 gl_STDINT_H 309 gl_STDINT_H
310 # Code from module stdio:
116 gl_STDIO_H 311 gl_STDIO_H
312 # Code from module stdlib:
117 gl_STDLIB_H 313 gl_STDLIB_H
314 # Code from module strdup-posix:
118 gl_FUNC_STRDUP_POSIX 315 gl_FUNC_STRDUP_POSIX
119 gl_STRING_MODULE_INDICATOR([strdup]) 316 gl_STRING_MODULE_INDICATOR([strdup])
317 # Code from module streq:
318 # Code from module strerror:
120 gl_FUNC_STRERROR 319 gl_FUNC_STRERROR
121 gl_STRING_MODULE_INDICATOR([strerror]) 320 gl_STRING_MODULE_INDICATOR([strerror])
321 # Code from module string:
122 gl_HEADER_STRING_H 322 gl_HEADER_STRING_H
323 # Code from module strndup:
123 gl_FUNC_STRNDUP 324 gl_FUNC_STRNDUP
124 gl_STRING_MODULE_INDICATOR([strndup]) 325 gl_STRING_MODULE_INDICATOR([strndup])
326 # Code from module strnlen:
125 gl_FUNC_STRNLEN 327 gl_FUNC_STRNLEN
126 gl_STRING_MODULE_INDICATOR([strnlen]) 328 gl_STRING_MODULE_INDICATOR([strnlen])
329 # Code from module strstr-simple:
330 gl_FUNC_STRSTR_SIMPLE
331 gl_STRING_MODULE_INDICATOR([strstr])
332 # Code from module sys_socket:
127 gl_HEADER_SYS_SOCKET 333 gl_HEADER_SYS_SOCKET
128 AC_PROG_MKDIR_P 334 AC_PROG_MKDIR_P
335 # Code from module sys_stat:
336 gl_HEADER_SYS_STAT_H
337 AC_PROG_MKDIR_P
338 # Code from module time:
129 gl_HEADER_TIME_H 339 gl_HEADER_TIME_H
340 # Code from module time_r:
130 gl_TIME_R 341 gl_TIME_R
342 gl_TIME_MODULE_INDICATOR([time_r])
343 # Code from module timegm:
131 gl_FUNC_TIMEGM 344 gl_FUNC_TIMEGM
345 gl_TIME_MODULE_INDICATOR([timegm])
346 # Code from module unistd:
132 gl_UNISTD_H 347 gl_UNISTD_H
348 # Code from module unistd-safer:
133 gl_UNISTD_SAFER 349 gl_UNISTD_SAFER
350 # Code from module vasnprintf:
134 gl_FUNC_VASNPRINTF 351 gl_FUNC_VASNPRINTF
352 # Code from module vasprintf:
135 gl_FUNC_VASPRINTF 353 gl_FUNC_VASPRINTF
136 gl_STDIO_MODULE_INDICATOR([vasprintf]) 354 gl_STDIO_MODULE_INDICATOR([vasprintf])
137 m4_ifdef([AM_XGETTEXT_OPTION], 355 m4_ifdef([AM_XGETTEXT_OPTION],
138 [AM_XGETTEXT_OPTION([--flag=asprintf:2:c-format]) 356 [AM_][XGETTEXT_OPTION([--flag=asprintf:2:c-format])
139 AM_XGETTEXT_OPTION([--flag=vasprintf:2:c-format])]) 357 AM_][XGETTEXT_OPTION([--flag=vasprintf:2:c-format])])
358 # Code from module verify:
359 # Code from module vsnprintf:
140 gl_FUNC_VSNPRINTF 360 gl_FUNC_VSNPRINTF
141 gl_STDIO_MODULE_INDICATOR([vsnprintf]) 361 gl_STDIO_MODULE_INDICATOR([vsnprintf])
362 # Code from module warn-on-use:
363 # Code from module wchar:
142 gl_WCHAR_H 364 gl_WCHAR_H
365 # Code from module wcrtomb:
143 gl_FUNC_WCRTOMB 366 gl_FUNC_WCRTOMB
144 gl_WCHAR_MODULE_INDICATOR([wcrtomb]) 367 gl_WCHAR_MODULE_INDICATOR([wcrtomb])
368 # Code from module wctype:
145 gl_WCTYPE_H 369 gl_WCTYPE_H
370 # Code from module write:
146 gl_FUNC_WRITE 371 gl_FUNC_WRITE
147 gl_UNISTD_MODULE_INDICATOR([write]) 372 gl_UNISTD_MODULE_INDICATOR([write])
373 # Code from module xalloc:
148 gl_XALLOC 374 gl_XALLOC
375 # Code from module xalloc-die:
376 # Code from module xsize:
149 gl_XSIZE 377 gl_XSIZE
378 # Code from module xstrndup:
150 gl_XSTRNDUP 379 gl_XSTRNDUP
380 # End of code from modules
151 m4_ifval(gl_LIBSOURCES_LIST, [ 381 m4_ifval(gl_LIBSOURCES_LIST, [
152 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || 382 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
153 for gl_file in ]gl_LIBSOURCES_LIST[ ; do 383 for gl_file in ]gl_LIBSOURCES_LIST[ ; do
@@ -170,7 +400,7 @@ AC_DEFUN([gl_INIT],
170 if test -n "$gl_LIBOBJS"; then 400 if test -n "$gl_LIBOBJS"; then
171 # Remove the extension. 401 # Remove the extension.
172 sed_drop_objext='s/\.o$//;s/\.obj$//' 402 sed_drop_objext='s/\.o$//;s/\.obj$//'
173 for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do 403 for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do
174 gl_libobjs="$gl_libobjs $i.$ac_objext" 404 gl_libobjs="$gl_libobjs $i.$ac_objext"
175 gl_ltlibobjs="$gl_ltlibobjs $i.lo" 405 gl_ltlibobjs="$gl_ltlibobjs $i.lo"
176 done 406 done
@@ -187,6 +417,13 @@ AC_DEFUN([gl_INIT],
187 m4_pushdef([gltests_LIBSOURCES_DIR], []) 417 m4_pushdef([gltests_LIBSOURCES_DIR], [])
188 gl_COMMON 418 gl_COMMON
189 gl_source_base='tests' 419 gl_source_base='tests'
420changequote(,)dnl
421 gltests_WITNESS=IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e 's/[^A-Z0-9_]/_/g'`_GNULIB_TESTS
422changequote([, ])dnl
423 AC_SUBST([gltests_WITNESS])
424 gl_module_indicator_condition=$gltests_WITNESS
425 m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition])
426 m4_popdef([gl_MODULE_INDICATOR_CONDITION])
190 m4_ifval(gltests_LIBSOURCES_LIST, [ 427 m4_ifval(gltests_LIBSOURCES_LIST, [
191 m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ || 428 m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ ||
192 for gl_file in ]gltests_LIBSOURCES_LIST[ ; do 429 for gl_file in ]gltests_LIBSOURCES_LIST[ ; do
@@ -209,7 +446,7 @@ AC_DEFUN([gl_INIT],
209 if test -n "$gltests_LIBOBJS"; then 446 if test -n "$gltests_LIBOBJS"; then
210 # Remove the extension. 447 # Remove the extension.
211 sed_drop_objext='s/\.o$//;s/\.obj$//' 448 sed_drop_objext='s/\.o$//;s/\.obj$//'
212 for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do 449 for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do
213 gltests_libobjs="$gltests_libobjs $i.$ac_objext" 450 gltests_libobjs="$gltests_libobjs $i.$ac_objext"
214 gltests_ltlibobjs="$gltests_ltlibobjs $i.lo" 451 gltests_ltlibobjs="$gltests_ltlibobjs $i.lo"
215 done 452 done
@@ -280,8 +517,10 @@ AC_DEFUN([gltests_LIBSOURCES], [
280# This macro records the list of files which have been installed by 517# This macro records the list of files which have been installed by
281# gnulib-tool and may be removed by future gnulib-tool invocations. 518# gnulib-tool and may be removed by future gnulib-tool invocations.
282AC_DEFUN([gl_FILE_LIST], [ 519AC_DEFUN([gl_FILE_LIST], [
520 build-aux/arg-nonnull.h
521 build-aux/c++defs.h
283 build-aux/config.rpath 522 build-aux/config.rpath
284 build-aux/link-warning.h 523 build-aux/warn-on-use.h
285 lib/alignof.h 524 lib/alignof.h
286 lib/alloca.c 525 lib/alloca.c
287 lib/alloca.in.h 526 lib/alloca.in.h
@@ -290,17 +529,22 @@ AC_DEFUN([gl_FILE_LIST], [
290 lib/asprintf.c 529 lib/asprintf.c
291 lib/base64.c 530 lib/base64.c
292 lib/base64.h 531 lib/base64.h
532 lib/basename-lgpl.c
293 lib/basename.c 533 lib/basename.c
294 lib/btowc.c 534 lib/btowc.c
295 lib/c-strtod.c 535 lib/c-strtod.c
296 lib/c-strtod.h 536 lib/c-strtod.h
297 lib/cloexec.c 537 lib/cloexec.c
298 lib/cloexec.h 538 lib/cloexec.h
539 lib/close-hook.c
540 lib/close-hook.h
299 lib/config.charset 541 lib/config.charset
300 lib/creat-safer.c 542 lib/creat-safer.c
543 lib/dirname-lgpl.c
301 lib/dirname.c 544 lib/dirname.c
302 lib/dirname.h 545 lib/dirname.h
303 lib/dup-safer.c 546 lib/dup-safer.c
547 lib/dup2.c
304 lib/errno.in.h 548 lib/errno.in.h
305 lib/error.c 549 lib/error.c
306 lib/error.h 550 lib/error.h
@@ -308,6 +552,7 @@ AC_DEFUN([gl_FILE_LIST], [
308 lib/exitfail.h 552 lib/exitfail.h
309 lib/fcntl--.h 553 lib/fcntl--.h
310 lib/fcntl-safer.h 554 lib/fcntl-safer.h
555 lib/fcntl.c
311 lib/fcntl.in.h 556 lib/fcntl.in.h
312 lib/fd-safer.c 557 lib/fd-safer.c
313 lib/float+.h 558 lib/float+.h
@@ -322,6 +567,7 @@ AC_DEFUN([gl_FILE_LIST], [
322 lib/full-write.h 567 lib/full-write.h
323 lib/gai_strerror.c 568 lib/gai_strerror.c
324 lib/getaddrinfo.c 569 lib/getaddrinfo.c
570 lib/getdtablesize.c
325 lib/gethostname.c 571 lib/gethostname.c
326 lib/getloadavg.c 572 lib/getloadavg.c
327 lib/getopt.c 573 lib/getopt.c
@@ -331,17 +577,23 @@ AC_DEFUN([gl_FILE_LIST], [
331 lib/gettext.h 577 lib/gettext.h
332 lib/inet_ntop.c 578 lib/inet_ntop.c
333 lib/intprops.h 579 lib/intprops.h
580 lib/langinfo.in.h
334 lib/localcharset.c 581 lib/localcharset.c
335 lib/localcharset.h 582 lib/localcharset.h
583 lib/locale.in.h
336 lib/malloc.c 584 lib/malloc.c
337 lib/math.in.h 585 lib/math.in.h
338 lib/mbrtowc.c 586 lib/mbrtowc.c
339 lib/mbsinit.c 587 lib/mbsinit.c
588 lib/memchr.c
589 lib/memchr.valgrind
590 lib/mktime-internal.h
340 lib/mktime.c 591 lib/mktime.c
341 lib/mountlist.c 592 lib/mountlist.c
342 lib/mountlist.h 593 lib/mountlist.h
343 lib/netdb.in.h 594 lib/netdb.in.h
344 lib/netinet_in.in.h 595 lib/netinet_in.in.h
596 lib/nl_langinfo.c
345 lib/open-safer.c 597 lib/open-safer.c
346 lib/open.c 598 lib/open.c
347 lib/pipe-safer.c 599 lib/pipe-safer.c
@@ -363,11 +615,16 @@ AC_DEFUN([gl_FILE_LIST], [
363 lib/safe-write.h 615 lib/safe-write.h
364 lib/size_max.h 616 lib/size_max.h
365 lib/snprintf.c 617 lib/snprintf.c
618 lib/sockets.c
619 lib/sockets.h
620 lib/stat.c
366 lib/stdbool.in.h 621 lib/stdbool.in.h
622 lib/stddef.in.h
367 lib/stdint.in.h 623 lib/stdint.in.h
368 lib/stdio-write.c 624 lib/stdio-write.c
369 lib/stdio.in.h 625 lib/stdio.in.h
370 lib/stdlib.in.h 626 lib/stdlib.in.h
627 lib/str-two-way.h
371 lib/strdup.c 628 lib/strdup.c
372 lib/streq.h 629 lib/streq.h
373 lib/strerror.c 630 lib/strerror.c
@@ -375,7 +632,9 @@ AC_DEFUN([gl_FILE_LIST], [
375 lib/stripslash.c 632 lib/stripslash.c
376 lib/strndup.c 633 lib/strndup.c
377 lib/strnlen.c 634 lib/strnlen.c
635 lib/strstr.c
378 lib/sys_socket.in.h 636 lib/sys_socket.in.h
637 lib/sys_stat.in.h
379 lib/time.in.h 638 lib/time.in.h
380 lib/time_r.c 639 lib/time_r.c
381 lib/timegm.c 640 lib/timegm.c
@@ -387,6 +646,7 @@ AC_DEFUN([gl_FILE_LIST], [
387 lib/vasprintf.c 646 lib/vasprintf.c
388 lib/verify.h 647 lib/verify.h
389 lib/vsnprintf.c 648 lib/vsnprintf.c
649 lib/w32sock.h
390 lib/wchar.in.h 650 lib/wchar.in.h
391 lib/wcrtomb.c 651 lib/wcrtomb.c
392 lib/wctype.in.h 652 lib/wctype.in.h
@@ -408,17 +668,20 @@ AC_DEFUN([gl_FILE_LIST], [
408 m4/dirname.m4 668 m4/dirname.m4
409 m4/dos.m4 669 m4/dos.m4
410 m4/double-slash-root.m4 670 m4/double-slash-root.m4
671 m4/dup2.m4
411 m4/errno_h.m4 672 m4/errno_h.m4
412 m4/error.m4 673 m4/error.m4
413 m4/exitfail.m4
414 m4/extensions.m4 674 m4/extensions.m4
675 m4/fcntl-o.m4
415 m4/fcntl-safer.m4 676 m4/fcntl-safer.m4
677 m4/fcntl.m4
416 m4/fcntl_h.m4 678 m4/fcntl_h.m4
417 m4/float_h.m4 679 m4/float_h.m4
418 m4/floorf.m4 680 m4/floorf.m4
419 m4/fstypename.m4 681 m4/fstypename.m4
420 m4/fsusage.m4 682 m4/fsusage.m4
421 m4/getaddrinfo.m4 683 m4/getaddrinfo.m4
684 m4/getdtablesize.m4
422 m4/gethostname.m4 685 m4/gethostname.m4
423 m4/getloadavg.m4 686 m4/getloadavg.m4
424 m4/getopt.m4 687 m4/getopt.m4
@@ -439,6 +702,7 @@ AC_DEFUN([gl_FILE_LIST], [
439 m4/intmax_t.m4 702 m4/intmax_t.m4
440 m4/inttypes-pri.m4 703 m4/inttypes-pri.m4
441 m4/inttypes_h.m4 704 m4/inttypes_h.m4
705 m4/langinfo_h.m4
442 m4/lcmessage.m4 706 m4/lcmessage.m4
443 m4/lib-ld.m4 707 m4/lib-ld.m4
444 m4/lib-link.m4 708 m4/lib-link.m4
@@ -447,6 +711,7 @@ AC_DEFUN([gl_FILE_LIST], [
447 m4/locale-fr.m4 711 m4/locale-fr.m4
448 m4/locale-ja.m4 712 m4/locale-ja.m4
449 m4/locale-zh.m4 713 m4/locale-zh.m4
714 m4/locale_h.m4
450 m4/lock.m4 715 m4/lock.m4
451 m4/longlong.m4 716 m4/longlong.m4
452 m4/ls-mntd-fs.m4 717 m4/ls-mntd-fs.m4
@@ -455,11 +720,15 @@ AC_DEFUN([gl_FILE_LIST], [
455 m4/mbrtowc.m4 720 m4/mbrtowc.m4
456 m4/mbsinit.m4 721 m4/mbsinit.m4
457 m4/mbstate_t.m4 722 m4/mbstate_t.m4
723 m4/memchr.m4
458 m4/mktime.m4 724 m4/mktime.m4
725 m4/mmap-anon.m4
726 m4/mode_t.m4
459 m4/mountlist.m4 727 m4/mountlist.m4
460 m4/multiarch.m4 728 m4/multiarch.m4
461 m4/netdb_h.m4 729 m4/netdb_h.m4
462 m4/netinet_in_h.m4 730 m4/netinet_in_h.m4
731 m4/nl_langinfo.m4
463 m4/nls.m4 732 m4/nls.m4
464 m4/onceonly.m4 733 m4/onceonly.m4
465 m4/open.m4 734 m4/open.m4
@@ -473,10 +742,13 @@ AC_DEFUN([gl_FILE_LIST], [
473 m4/servent.m4 742 m4/servent.m4
474 m4/size_max.m4 743 m4/size_max.m4
475 m4/snprintf.m4 744 m4/snprintf.m4
745 m4/sockets.m4
476 m4/socklen.m4 746 m4/socklen.m4
477 m4/sockpfaf.m4 747 m4/sockpfaf.m4
478 m4/ssize_t.m4 748 m4/ssize_t.m4
749 m4/stat.m4
479 m4/stdbool.m4 750 m4/stdbool.m4
751 m4/stddef_h.m4
480 m4/stdint.m4 752 m4/stdint.m4
481 m4/stdint_h.m4 753 m4/stdint_h.m4
482 m4/stdio_h.m4 754 m4/stdio_h.m4
@@ -486,7 +758,9 @@ AC_DEFUN([gl_FILE_LIST], [
486 m4/string_h.m4 758 m4/string_h.m4
487 m4/strndup.m4 759 m4/strndup.m4
488 m4/strnlen.m4 760 m4/strnlen.m4
761 m4/strstr.m4
489 m4/sys_socket_h.m4 762 m4/sys_socket_h.m4
763 m4/sys_stat_h.m4
490 m4/threadlib.m4 764 m4/threadlib.m4
491 m4/time_h.m4 765 m4/time_h.m4
492 m4/time_r.m4 766 m4/time_r.m4
@@ -498,10 +772,11 @@ AC_DEFUN([gl_FILE_LIST], [
498 m4/vasprintf.m4 772 m4/vasprintf.m4
499 m4/visibility.m4 773 m4/visibility.m4
500 m4/vsnprintf.m4 774 m4/vsnprintf.m4
501 m4/wchar.m4 775 m4/warn-on-use.m4
776 m4/wchar_h.m4
502 m4/wchar_t.m4 777 m4/wchar_t.m4
503 m4/wcrtomb.m4 778 m4/wcrtomb.m4
504 m4/wctype.m4 779 m4/wctype_h.m4
505 m4/wint_t.m4 780 m4/wint_t.m4
506 m4/write.m4 781 m4/write.m4
507 m4/xalloc.m4 782 m4/xalloc.m4
diff --git a/gl/m4/gnulib-tool.m4 b/gl/m4/gnulib-tool.m4
index 4438d488..69e7733b 100644
--- a/gl/m4/gnulib-tool.m4
+++ b/gl/m4/gnulib-tool.m4
@@ -1,5 +1,5 @@
1# gnulib-tool.m4 serial 2 1# gnulib-tool.m4 serial 2
2dnl Copyright (C) 2004-2005 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2005, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/hostent.m4 b/gl/m4/hostent.m4
index 4a96af7a..11110411 100644
--- a/gl/m4/hostent.m4
+++ b/gl/m4/hostent.m4
@@ -1,5 +1,5 @@
1# hostent.m4 serial 1 1# hostent.m4 serial 1
2dnl Copyright (C) 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/iconv.m4 b/gl/m4/iconv.m4
index 3cc62682..f46ff142 100644
--- a/gl/m4/iconv.m4
+++ b/gl/m4/iconv.m4
@@ -1,5 +1,5 @@
1# iconv.m4 serial AM7 (gettext-0.18) 1# iconv.m4 serial 9 (gettext-0.18)
2dnl Copyright (C) 2000-2002, 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -58,7 +58,7 @@ AC_DEFUN([AM_ICONV_LINK],
58 ]) 58 ])
59 if test "$am_cv_func_iconv" = yes; then 59 if test "$am_cv_func_iconv" = yes; then
60 AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [ 60 AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
61 dnl This tests against bugs in AIX 5.1 and HP-UX 11.11. 61 dnl This tests against bugs in AIX 5.1, HP-UX 11.11, Solaris 10.
62 am_save_LIBS="$LIBS" 62 am_save_LIBS="$LIBS"
63 if test $am_cv_lib_iconv = yes; then 63 if test $am_cv_lib_iconv = yes; then
64 LIBS="$LIBS $LIBICONV" 64 LIBS="$LIBS $LIBICONV"
@@ -87,6 +87,25 @@ int main ()
87 return 1; 87 return 1;
88 } 88 }
89 } 89 }
90 /* Test against Solaris 10 bug: Failures are not distinguishable from
91 successful returns. */
92 {
93 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
94 if (cd_ascii_to_88591 != (iconv_t)(-1))
95 {
96 static const char input[] = "\263";
97 char buf[10];
98 const char *inptr = input;
99 size_t inbytesleft = strlen (input);
100 char *outptr = buf;
101 size_t outbytesleft = sizeof (buf);
102 size_t res = iconv (cd_ascii_to_88591,
103 (char **) &inptr, &inbytesleft,
104 &outptr, &outbytesleft);
105 if (res == 0)
106 return 1;
107 }
108 }
90#if 0 /* This bug could be worked around by the caller. */ 109#if 0 /* This bug could be worked around by the caller. */
91 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ 110 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
92 { 111 {
@@ -172,8 +191,8 @@ size_t iconv();
172], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"]) 191], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"])
173 am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) 192 am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
174 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` 193 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
175 AC_MSG_RESULT([${ac_t:- 194 AC_MSG_RESULT([
176 }$am_cv_proto_iconv]) 195 $am_cv_proto_iconv])
177 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1], 196 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
178 [Define as const if the declaration of iconv() needs const.]) 197 [Define as const if the declaration of iconv() needs const.])
179 fi 198 fi
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4
index d6101fe3..c7e0672f 100644
--- a/gl/m4/include_next.m4
+++ b/gl/m4/include_next.m4
@@ -1,5 +1,5 @@
1# include_next.m4 serial 12 1# include_next.m4 serial 14
2dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -104,10 +104,16 @@ EOF
104# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be 104# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
105# '<foo.h>'; otherwise define it to be 105# '<foo.h>'; otherwise define it to be
106# '"///usr/include/foo.h"', or whatever other absolute file name is suitable. 106# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
107# Also, if #include_next works as first preprocessing directive in a file,
108# define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
109# be
110# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
107# That way, a header file with the following line: 111# That way, a header file with the following line:
108# #@INCLUDE_NEXT@ @NEXT_FOO_H@ 112# #@INCLUDE_NEXT@ @NEXT_FOO_H@
113# or
114# #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
109# behaves (after sed substitution) as if it contained 115# behaves (after sed substitution) as if it contained
110# #include_next <foo.h> 116# #include_next <foo.h>
111# even if the compiler does not support include_next. 117# even if the compiler does not support include_next.
112# The three "///" are to pacify Sun C 5.8, which otherwise would say 118# The three "///" are to pacify Sun C 5.8, which otherwise would say
113# "warning: #include of /usr/include/... may be non-portable". 119# "warning: #include of /usr/include/... may be non-portable".
@@ -123,49 +129,59 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS],
123 129
124 m4_foreach_w([gl_HEADER_NAME], [$1], 130 m4_foreach_w([gl_HEADER_NAME], [$1],
125 [AS_VAR_PUSHDEF([gl_next_header], 131 [AS_VAR_PUSHDEF([gl_next_header],
126 [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME]))) 132 [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
127 if test $gl_cv_have_include_next = yes; then 133 if test $gl_cv_have_include_next = yes; then
128 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) 134 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
129 else 135 else
130 AC_CACHE_CHECK( 136 AC_CACHE_CHECK(
131 [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], 137 [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
132 m4_quote(m4_defn([gl_next_header])), 138 m4_defn([gl_next_header]),
133 [AS_VAR_PUSHDEF([gl_header_exists], 139 [AS_VAR_PUSHDEF([gl_header_exists],
134 [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME]))) 140 [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
135 if test AS_VAR_GET(gl_header_exists) = yes; then 141 if test AS_VAR_GET(gl_header_exists) = yes; then
136 AC_LANG_CONFTEST( 142 AC_LANG_CONFTEST(
137 [AC_LANG_SOURCE( 143 [AC_LANG_SOURCE(
138 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] 144 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
139 )]) 145 )])
140 dnl AIX "xlc -E" and "cc -E" omit #line directives for header files 146 dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
141 dnl that contain only a #include of other header files and no 147 dnl that contain only a #include of other header files and no
142 dnl non-comment tokens of their own. This leads to a failure to 148 dnl non-comment tokens of their own. This leads to a failure to
143 dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h> 149 dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
144 dnl and others. The workaround is to force preservation of comments 150 dnl and others. The workaround is to force preservation of comments
145 dnl through option -C. This ensures all necessary #line directives 151 dnl through option -C. This ensures all necessary #line directives
146 dnl are present. GCC supports option -C as well. 152 dnl are present. GCC supports option -C as well.
147 case "$host_os" in 153 case "$host_os" in
148 aix*) gl_absname_cpp="$ac_cpp -C" ;; 154 aix*) gl_absname_cpp="$ac_cpp -C" ;;
149 *) gl_absname_cpp="$ac_cpp" ;; 155 *) gl_absname_cpp="$ac_cpp" ;;
150 esac 156 esac
151 dnl eval is necessary to expand gl_absname_cpp. 157 dnl eval is necessary to expand gl_absname_cpp.
152 dnl Ultrix and Pyramid sh refuse to redirect output of eval, 158 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
153 dnl so use subshell. 159 dnl so use subshell.
154 AS_VAR_SET([gl_next_header], 160 AS_VAR_SET([gl_next_header],
155 ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | 161 ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
156 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{ 162 sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
157 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1# 163 s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
158 s#^/[^/]#//&# 164 s#^/[^/]#//&#
159 p 165 p
160 q 166 q
161 }'`'"']) 167 }'`'"'])
162 else 168 else
163 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) 169 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
164 fi 170 fi
165 AS_VAR_POPDEF([gl_header_exists])]) 171 AS_VAR_POPDEF([gl_header_exists])])
166 fi 172 fi
167 AC_SUBST( 173 AC_SUBST(
168 AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))), 174 AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
169 [AS_VAR_GET([gl_next_header])]) 175 [AS_VAR_GET([gl_next_header])])
176 if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
177 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
178 gl_next_as_first_directive='<'gl_HEADER_NAME'>'
179 else
180 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
181 gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
182 fi
183 AC_SUBST(
184 AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
185 [$gl_next_as_first_directive])
170 AS_VAR_POPDEF([gl_next_header])]) 186 AS_VAR_POPDEF([gl_next_header])])
171]) 187])
diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4
index 2bbdca10..a6d219c2 100644
--- a/gl/m4/inet_ntop.m4
+++ b/gl/m4/inet_ntop.m4
@@ -1,27 +1,28 @@
1# inet_ntop.m4 serial 9 1# inet_ntop.m4 serial 12
2dnl Copyright (C) 2005, 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7AC_DEFUN([gl_INET_NTOP], 7AC_DEFUN([gl_FUNC_INET_NTOP],
8[ 8[
9 dnl Persuade Solaris <arpa/inet.h> to declare inet_ntop. 9 dnl Persuade Solaris <arpa/inet.h> to declare inet_ntop.
10 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 10 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
11 11
12 gl_REPLACE_ARPA_INET_H 12 gl_REPLACE_ARPA_INET_H
13 13
14 dnl The AC_SEARCH_LIBS call is a hack to persuade the Solaris 8 linker to 14 dnl Most platforms that provide inet_ntop define it in libc.
15 dnl find inet_ntop. 15 dnl Solaris 8..10 provide inet_ntop in libnsl instead.
16 dnl
17 dnl It is the responsibility of gl_INET_NTOP's caller to arrange for
18 dnl -lnsl if it is needed. Normally -lnsl is not needed on Solaris 8,
19 dnl since inet_ntop is needed only by getaddrinfo, and getaddrinfo
20 dnl isn't built on Solaris 8.
21 gl_save_LIBS=$LIBS 16 gl_save_LIBS=$LIBS
22 AC_SEARCH_LIBS([inet_ntop], [nsl], [], 17 AC_SEARCH_LIBS([inet_ntop], [nsl], [],
23 [AC_REPLACE_FUNCS([inet_ntop])]) 18 [AC_REPLACE_FUNCS([inet_ntop])])
24 LIBS=$gl_save_LIBS 19 LIBS=$gl_save_LIBS
20 INET_NTOP_LIB=
21 if test "$ac_cv_search_inet_ntop" != "no" &&
22 test "$ac_cv_search_inet_ntop" != "none required"; then
23 INET_NTOP_LIB="$ac_cv_search_inet_ntop"
24 fi
25 AC_SUBST([INET_NTOP_LIB])
25 26
26 gl_PREREQ_INET_NTOP 27 gl_PREREQ_INET_NTOP
27]) 28])
diff --git a/gl/m4/inline.m4 b/gl/m4/inline.m4
index cee51099..4ef768de 100644
--- a/gl/m4/inline.m4
+++ b/gl/m4/inline.m4
@@ -1,5 +1,5 @@
1# inline.m4 serial 4 1# inline.m4 serial 4
2dnl Copyright (C) 2006, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/intdiv0.m4 b/gl/m4/intdiv0.m4
index 29e6e0aa..289c4df5 100644
--- a/gl/m4/intdiv0.m4
+++ b/gl/m4/intdiv0.m4
@@ -1,5 +1,5 @@
1# intdiv0.m4 serial 3 (gettext-0.18) 1# intdiv0.m4 serial 3 (gettext-0.18)
2dnl Copyright (C) 2002, 2007-2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/intl.m4 b/gl/m4/intl.m4
index 934408bb..5e17fea9 100644
--- a/gl/m4/intl.m4
+++ b/gl/m4/intl.m4
@@ -1,5 +1,5 @@
1# intl.m4 serial 8 (gettext-0.17) 1# intl.m4 serial 8 (gettext-0.17)
2dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/intldir.m4 b/gl/m4/intldir.m4
index 0980e6f2..ebae76d3 100644
--- a/gl/m4/intldir.m4
+++ b/gl/m4/intldir.m4
@@ -1,5 +1,5 @@
1# intldir.m4 serial 2 (gettext-0.18) 1# intldir.m4 serial 2 (gettext-0.18)
2dnl Copyright (C) 2006, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/intlmacosx.m4 b/gl/m4/intlmacosx.m4
index c24837c4..dd910259 100644
--- a/gl/m4/intlmacosx.m4
+++ b/gl/m4/intlmacosx.m4
@@ -1,5 +1,5 @@
1# intlmacosx.m4 serial 3 (gettext-0.18) 1# intlmacosx.m4 serial 3 (gettext-0.18)
2dnl Copyright (C) 2004-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/intmax.m4 b/gl/m4/intmax.m4
index a3785e99..74aaaf5e 100644
--- a/gl/m4/intmax.m4
+++ b/gl/m4/intmax.m4
@@ -1,5 +1,5 @@
1# intmax.m4 serial 5 (gettext-0.18) 1# intmax.m4 serial 5 (gettext-0.18)
2dnl Copyright (C) 2002-2005, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2005, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/intmax_t.m4 b/gl/m4/intmax_t.m4
index 264cb571..975caac5 100644
--- a/gl/m4/intmax_t.m4
+++ b/gl/m4/intmax_t.m4
@@ -1,5 +1,6 @@
1# intmax_t.m4 serial 7 1# intmax_t.m4 serial 7
2dnl Copyright (C) 1997-2004, 2006-2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2006-2007, 2009-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/inttypes-pri.m4 b/gl/m4/inttypes-pri.m4
index 98fec7bc..718a4f4e 100644
--- a/gl/m4/inttypes-pri.m4
+++ b/gl/m4/inttypes-pri.m4
@@ -1,5 +1,5 @@
1# inttypes-pri.m4 serial 6 (gettext-0.18) 1# inttypes-pri.m4 serial 6 (gettext-0.18)
2dnl Copyright (C) 1997-2002, 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2002, 2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/inttypes_h.m4 b/gl/m4/inttypes_h.m4
index f4ca1602..782d77ed 100644
--- a/gl/m4/inttypes_h.m4
+++ b/gl/m4/inttypes_h.m4
@@ -1,5 +1,5 @@
1# inttypes_h.m4 serial 9 1# inttypes_h.m4 serial 9
2dnl Copyright (C) 1997-2004, 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/langinfo_h.m4 b/gl/m4/langinfo_h.m4
new file mode 100644
index 00000000..11a56980
--- /dev/null
+++ b/gl/m4/langinfo_h.m4
@@ -0,0 +1,77 @@
1# langinfo_h.m4 serial 6
2dnl Copyright (C) 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_LANGINFO_H],
8[
9 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
10
11 dnl Persuade glibc-2.0.6 <langinfo.h> to define CODESET.
12 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
13
14 dnl <langinfo.h> is always overridden, because of GNULIB_POSIXCHECK.
15 gl_CHECK_NEXT_HEADERS([langinfo.h])
16
17 dnl Determine whether <langinfo.h> exists. It is missing on mingw and BeOS.
18 HAVE_LANGINFO_CODESET=0
19 HAVE_LANGINFO_ERA=0
20 AC_CHECK_HEADERS_ONCE([langinfo.h])
21 if test $ac_cv_header_langinfo_h = yes; then
22 HAVE_LANGINFO_H=1
23 dnl Determine what <langinfo.h> defines. CODESET and ERA etc. are missing
24 dnl on OpenBSD 3.8.
25 AC_CACHE_CHECK([whether langinfo.h defines CODESET],
26 [gl_cv_header_langinfo_codeset],
27 [AC_COMPILE_IFELSE(
28 [AC_LANG_PROGRAM([[#include <langinfo.h>
29int a = CODESET;
30]])],
31 [gl_cv_header_langinfo_codeset=yes],
32 [gl_cv_header_langinfo_codeset=no])
33 ])
34 if test $gl_cv_header_langinfo_codeset = yes; then
35 HAVE_LANGINFO_CODESET=1
36 fi
37 AC_CACHE_CHECK([whether langinfo.h defines ERA],
38 [gl_cv_header_langinfo_era],
39 [AC_COMPILE_IFELSE(
40 [AC_LANG_PROGRAM([[#include <langinfo.h>
41int a = ERA;
42]])],
43 [gl_cv_header_langinfo_era=yes],
44 [gl_cv_header_langinfo_era=no])
45 ])
46 if test $gl_cv_header_langinfo_era = yes; then
47 HAVE_LANGINFO_ERA=1
48 fi
49 else
50 HAVE_LANGINFO_H=0
51 fi
52 AC_SUBST([HAVE_LANGINFO_H])
53 AC_SUBST([HAVE_LANGINFO_CODESET])
54 AC_SUBST([HAVE_LANGINFO_ERA])
55
56 dnl Check for declarations of anything we want to poison if the
57 dnl corresponding gnulib module is not in use.
58 gl_WARN_ON_USE_PREPARE([[#include <langinfo.h>
59 ]], [nl_langinfo])
60])
61
62AC_DEFUN([gl_LANGINFO_MODULE_INDICATOR],
63[
64 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
65 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
66 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
67 dnl Define it also as a C macro, for the benefit of the unit tests.
68 gl_MODULE_INDICATOR_FOR_TESTS([$1])
69])
70
71AC_DEFUN([gl_LANGINFO_H_DEFAULTS],
72[
73 GNULIB_NL_LANGINFO=0; AC_SUBST([GNULIB_NL_LANGINFO])
74 dnl Assume proper GNU behavior unless another module says otherwise.
75 HAVE_NL_LANGINFO=1; AC_SUBST([HAVE_NL_LANGINFO])
76 REPLACE_NL_LANGINFO=0; AC_SUBST([REPLACE_NL_LANGINFO])
77])
diff --git a/gl/m4/lcmessage.m4 b/gl/m4/lcmessage.m4
index fa8e4167..1a705431 100644
--- a/gl/m4/lcmessage.m4
+++ b/gl/m4/lcmessage.m4
@@ -1,5 +1,6 @@
1# lcmessage.m4 serial 6 (gettext-0.18) 1# lcmessage.m4 serial 6 (gettext-0.18)
2dnl Copyright (C) 1995-2002, 2004-2005, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2002, 2004-2005, 2008-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/lib-ld.m4 b/gl/m4/lib-ld.m4
index e4863f2c..ebb30528 100644
--- a/gl/m4/lib-ld.m4
+++ b/gl/m4/lib-ld.m4
@@ -1,5 +1,5 @@
1# lib-ld.m4 serial 4 (gettext-0.18) 1# lib-ld.m4 serial 4 (gettext-0.18)
2dnl Copyright (C) 1996-2003, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1996-2003, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -59,7 +59,7 @@ if test "$GCC" = yes; then
59 # Canonicalize the path of ld 59 # Canonicalize the path of ld
60 ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` 60 ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
61 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do 61 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
62 ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` 62 ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
63 done 63 done
64 test -z "$LD" && LD="$ac_prog" 64 test -z "$LD" && LD="$ac_prog"
65 ;; 65 ;;
@@ -89,9 +89,9 @@ AC_CACHE_VAL([acl_cv_path_LD],
89 # Break only if it was the GNU/non-GNU ld that we prefer. 89 # Break only if it was the GNU/non-GNU ld that we prefer.
90 case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in 90 case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in
91 *GNU* | *'with BFD'*) 91 *GNU* | *'with BFD'*)
92 test "$with_gnu_ld" != no && break ;; 92 test "$with_gnu_ld" != no && break ;;
93 *) 93 *)
94 test "$with_gnu_ld" != yes && break ;; 94 test "$with_gnu_ld" != yes && break ;;
95 esac 95 esac
96 fi 96 fi
97 done 97 done
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4
index 21442033..90e1ac91 100644
--- a/gl/m4/lib-link.m4
+++ b/gl/m4/lib-link.m4
@@ -1,5 +1,5 @@
1# lib-link.m4 serial 19 (gettext-0.18) 1# lib-link.m4 serial 20 (gettext-0.18)
2dnl Copyright (C) 2001-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -82,7 +82,7 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
82 ]) 82 ])
83 if test "$ac_cv_lib[]Name" = yes; then 83 if test "$ac_cv_lib[]Name" = yes; then
84 HAVE_LIB[]NAME=yes 84 HAVE_LIB[]NAME=yes
85 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib[]$1 library.]) 85 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
86 AC_MSG_CHECKING([how to link with lib[]$1]) 86 AC_MSG_CHECKING([how to link with lib[]$1])
87 AC_MSG_RESULT([$LIB[]NAME]) 87 AC_MSG_RESULT([$LIB[]NAME])
88 else 88 else
@@ -210,6 +210,9 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
210 LTLIB[]NAME= 210 LTLIB[]NAME=
211 INC[]NAME= 211 INC[]NAME=
212 LIB[]NAME[]_PREFIX= 212 LIB[]NAME[]_PREFIX=
213 dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
214 dnl computed. So it has to be reset here.
215 HAVE_LIB[]NAME=
213 rpathdirs= 216 rpathdirs=
214 ltrpathdirs= 217 ltrpathdirs=
215 names_already_handled= 218 names_already_handled=
diff --git a/gl/m4/lib-prefix.m4 b/gl/m4/lib-prefix.m4
index 4b7ee335..1601ceae 100644
--- a/gl/m4/lib-prefix.m4
+++ b/gl/m4/lib-prefix.m4
@@ -1,5 +1,5 @@
1# lib-prefix.m4 serial 7 (gettext-0.18) 1# lib-prefix.m4 serial 7 (gettext-0.18)
2dnl Copyright (C) 2001-2005, 2008-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2005, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/localcharset.m4 b/gl/m4/localcharset.m4
index e9601041..ee2e801b 100644
--- a/gl/m4/localcharset.m4
+++ b/gl/m4/localcharset.m4
@@ -1,5 +1,5 @@
1# localcharset.m4 serial 6 1# localcharset.m4 serial 7
2dnl Copyright (C) 2002, 2004, 2006, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -8,6 +8,7 @@ AC_DEFUN([gl_LOCALCHARSET],
8[ 8[
9 dnl Prerequisites of lib/localcharset.c. 9 dnl Prerequisites of lib/localcharset.c.
10 AC_REQUIRE([AM_LANGINFO_CODESET]) 10 AC_REQUIRE([AM_LANGINFO_CODESET])
11 AC_REQUIRE([gl_FCNTL_O_FLAGS])
11 AC_CHECK_DECLS_ONCE([getc_unlocked]) 12 AC_CHECK_DECLS_ONCE([getc_unlocked])
12 13
13 dnl Prerequisites of the lib/Makefile.am snippet. 14 dnl Prerequisites of the lib/Makefile.am snippet.
diff --git a/gl/m4/locale-fr.m4 b/gl/m4/locale-fr.m4
index 653a5bc2..001f5390 100644
--- a/gl/m4/locale-fr.m4
+++ b/gl/m4/locale-fr.m4
@@ -1,5 +1,5 @@
1# locale-fr.m4 serial 11 1# locale-fr.m4 serial 11
2dnl Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/locale-ja.m4 b/gl/m4/locale-ja.m4
index 93605764..0eedaf14 100644
--- a/gl/m4/locale-ja.m4
+++ b/gl/m4/locale-ja.m4
@@ -1,5 +1,5 @@
1# locale-ja.m4 serial 7 1# locale-ja.m4 serial 7
2dnl Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/locale-zh.m4 b/gl/m4/locale-zh.m4
index 36a5f1df..777fd141 100644
--- a/gl/m4/locale-zh.m4
+++ b/gl/m4/locale-zh.m4
@@ -1,5 +1,5 @@
1# locale-zh.m4 serial 6 1# locale-zh.m4 serial 6
2dnl Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/locale_h.m4 b/gl/m4/locale_h.m4
new file mode 100644
index 00000000..18a119b8
--- /dev/null
+++ b/gl/m4/locale_h.m4
@@ -0,0 +1,92 @@
1# locale_h.m4 serial 10
2dnl Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_LOCALE_H],
8[
9 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
10 dnl once only, before all statements that occur in other macros.
11 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
12
13 dnl Persuade glibc <locale.h> to define locale_t.
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16 dnl If <stddef.h> is replaced, then <locale.h> must also be replaced.
17 AC_REQUIRE([gl_STDDEF_H])
18
19 AC_CACHE_CHECK([whether locale.h conforms to POSIX:2001],
20 [gl_cv_header_locale_h_posix2001],
21 [AC_TRY_COMPILE([#include <locale.h>
22int x = LC_MESSAGES;], [],
23 [gl_cv_header_locale_h_posix2001=yes],
24 [gl_cv_header_locale_h_posix2001=no])])
25
26 dnl Check for <xlocale.h>.
27 AC_CHECK_HEADERS_ONCE([xlocale.h])
28 if test $ac_cv_header_xlocale_h = yes; then
29 HAVE_XLOCALE_H=1
30 dnl Check whether use of locale_t requires inclusion of <xlocale.h>,
31 dnl e.g. on MacOS X 10.5. If <locale.h> does not define locale_t by
32 dnl itself, we assume that <xlocale.h> will do so.
33 AC_CACHE_CHECK([whether locale.h defines locale_t],
34 [gl_cv_header_locale_has_locale_t],
35 [AC_TRY_COMPILE([#include <locale.h>
36locale_t x;], [],
37 [gl_cv_header_locale_has_locale_t=yes],
38 [gl_cv_header_locale_has_locale_t=no])
39 ])
40 if test $gl_cv_header_locale_has_locale_t = yes; then
41 gl_cv_header_locale_h_needs_xlocale_h=no
42 else
43 gl_cv_header_locale_h_needs_xlocale_h=yes
44 fi
45 else
46 HAVE_XLOCALE_H=0
47 gl_cv_header_locale_h_needs_xlocale_h=no
48 fi
49 AC_SUBST([HAVE_XLOCALE_H])
50
51 dnl <locale.h> is always overridden, because of GNULIB_POSIXCHECK.
52 gl_CHECK_NEXT_HEADERS([locale.h])
53
54 if test -n "$STDDEF_H" \
55 || test $gl_cv_header_locale_h_posix2001 = no \
56 || test $gl_cv_header_locale_h_needs_xlocale_h = yes; then
57 gl_REPLACE_LOCALE_H
58 fi
59
60 dnl Check for declarations of anything we want to poison if the
61 dnl corresponding gnulib module is not in use.
62 gl_WARN_ON_USE_PREPARE([[#include <locale.h>
63/* Some systems provide declarations in a non-standard header. */
64#if HAVE_XLOCALE_H
65# include <xlocale.h>
66#endif
67 ]], [duplocale])
68])
69
70dnl Unconditionally enables the replacement of <locale.h>.
71AC_DEFUN([gl_REPLACE_LOCALE_H],
72[
73 dnl This is a no-op, because <locale.h> is always overridden.
74 :
75])
76
77AC_DEFUN([gl_LOCALE_MODULE_INDICATOR],
78[
79 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
80 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
81 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
82 dnl Define it also as a C macro, for the benefit of the unit tests.
83 gl_MODULE_INDICATOR_FOR_TESTS([$1])
84])
85
86AC_DEFUN([gl_LOCALE_H_DEFAULTS],
87[
88 GNULIB_DUPLOCALE=0; AC_SUBST([GNULIB_DUPLOCALE])
89 dnl Assume proper GNU behavior unless another module says otherwise.
90 HAVE_DUPLOCALE=1; AC_SUBST([HAVE_DUPLOCALE])
91 REPLACE_DUPLOCALE=0; AC_SUBST([REPLACE_DUPLOCALE])
92])
diff --git a/gl/m4/lock.m4 b/gl/m4/lock.m4
index b416e31a..9da8465e 100644
--- a/gl/m4/lock.m4
+++ b/gl/m4/lock.m4
@@ -1,5 +1,5 @@
1# lock.m4 serial 10 (gettext-0.18) 1# lock.m4 serial 10 (gettext-0.18)
2dnl Copyright (C) 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/longlong.m4 b/gl/m4/longlong.m4
index eedc8d56..cca3c1a9 100644
--- a/gl/m4/longlong.m4
+++ b/gl/m4/longlong.m4
@@ -1,5 +1,5 @@
1# longlong.m4 serial 14 1# longlong.m4 serial 14
2dnl Copyright (C) 1999-2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1999-2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -20,30 +20,30 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT],
20 [AC_LINK_IFELSE( 20 [AC_LINK_IFELSE(
21 [_AC_TYPE_LONG_LONG_SNIPPET], 21 [_AC_TYPE_LONG_LONG_SNIPPET],
22 [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. 22 [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
23 dnl If cross compiling, assume the bug isn't important, since 23 dnl If cross compiling, assume the bug isn't important, since
24 dnl nobody cross compiles for this platform as far as we know. 24 dnl nobody cross compiles for this platform as far as we know.
25 AC_RUN_IFELSE( 25 AC_RUN_IFELSE(
26 [AC_LANG_PROGRAM( 26 [AC_LANG_PROGRAM(
27 [[@%:@include <limits.h> 27 [[@%:@include <limits.h>
28 @%:@ifndef LLONG_MAX 28 @%:@ifndef LLONG_MAX
29 @%:@ define HALF \ 29 @%:@ define HALF \
30 (1LL << (sizeof (long long int) * CHAR_BIT - 2)) 30 (1LL << (sizeof (long long int) * CHAR_BIT - 2))
31 @%:@ define LLONG_MAX (HALF - 1 + HALF) 31 @%:@ define LLONG_MAX (HALF - 1 + HALF)
32 @%:@endif]], 32 @%:@endif]],
33 [[long long int n = 1; 33 [[long long int n = 1;
34 int i; 34 int i;
35 for (i = 0; ; i++) 35 for (i = 0; ; i++)
36 { 36 {
37 long long int m = n << i; 37 long long int m = n << i;
38 if (m >> i != n) 38 if (m >> i != n)
39 return 1; 39 return 1;
40 if (LLONG_MAX / 2 < m) 40 if (LLONG_MAX / 2 < m)
41 break; 41 break;
42 } 42 }
43 return 0;]])], 43 return 0;]])],
44 [ac_cv_type_long_long_int=yes], 44 [ac_cv_type_long_long_int=yes],
45 [ac_cv_type_long_long_int=no], 45 [ac_cv_type_long_long_int=no],
46 [ac_cv_type_long_long_int=yes])], 46 [ac_cv_type_long_long_int=yes])],
47 [ac_cv_type_long_long_int=no])]) 47 [ac_cv_type_long_long_int=no])])
48 if test $ac_cv_type_long_long_int = yes; then 48 if test $ac_cv_type_long_long_int = yes; then
49 AC_DEFINE([HAVE_LONG_LONG_INT], [1], 49 AC_DEFINE([HAVE_LONG_LONG_INT], [1],
@@ -83,24 +83,24 @@ AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
83[ 83[
84 AC_LANG_PROGRAM( 84 AC_LANG_PROGRAM(
85 [[/* For now, do not test the preprocessor; as of 2007 there are too many 85 [[/* For now, do not test the preprocessor; as of 2007 there are too many
86 implementations with broken preprocessors. Perhaps this can 86 implementations with broken preprocessors. Perhaps this can
87 be revisited in 2012. In the meantime, code should not expect 87 be revisited in 2012. In the meantime, code should not expect
88 #if to work with literals wider than 32 bits. */ 88 #if to work with literals wider than 32 bits. */
89 /* Test literals. */ 89 /* Test literals. */
90 long long int ll = 9223372036854775807ll; 90 long long int ll = 9223372036854775807ll;
91 long long int nll = -9223372036854775807LL; 91 long long int nll = -9223372036854775807LL;
92 unsigned long long int ull = 18446744073709551615ULL; 92 unsigned long long int ull = 18446744073709551615ULL;
93 /* Test constant expressions. */ 93 /* Test constant expressions. */
94 typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) 94 typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
95 ? 1 : -1)]; 95 ? 1 : -1)];
96 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 96 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
97 ? 1 : -1)]; 97 ? 1 : -1)];
98 int i = 63;]], 98 int i = 63;]],
99 [[/* Test availability of runtime routines for shift and division. */ 99 [[/* Test availability of runtime routines for shift and division. */
100 long long int llmax = 9223372036854775807ll; 100 long long int llmax = 9223372036854775807ll;
101 unsigned long long int ullmax = 18446744073709551615ull; 101 unsigned long long int ullmax = 18446744073709551615ull;
102 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) 102 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
103 | (llmax / ll) | (llmax % ll) 103 | (llmax / ll) | (llmax % ll)
104 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) 104 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
105 | (ullmax / ull) | (ullmax % ull));]]) 105 | (ullmax / ull) | (ullmax % ull));]])
106]) 106])
diff --git a/gl/m4/ls-mntd-fs.m4 b/gl/m4/ls-mntd-fs.m4
index 32ccb984..40b93366 100644
--- a/gl/m4/ls-mntd-fs.m4
+++ b/gl/m4/ls-mntd-fs.m4
@@ -1,7 +1,7 @@
1# serial 27 1# serial 28
2# How to list mounted file systems. 2# How to list mounted file systems.
3 3
4# Copyright (C) 1998-2004, 2006, 2009 Free Software Foundation, Inc. 4# Copyright (C) 1998-2004, 2006, 2009-2010 Free Software Foundation, Inc.
5# 5#
6# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
@@ -84,7 +84,7 @@ if test -z "$ac_list_mounted_fs"; then
84yes 84yes
85#endif 85#endif
86 ], [test $ac_cv_func_listmntent = yes \ 86 ], [test $ac_cv_func_listmntent = yes \
87 && fu_cv_sys_mounted_cray_listmntent=yes] 87 && fu_cv_sys_mounted_cray_listmntent=yes]
88 ) 88 )
89 ] 89 ]
90 ) 90 )
@@ -101,14 +101,14 @@ if test -z "$ac_list_mounted_fs"; then
101 # AIX. 101 # AIX.
102 AC_MSG_CHECKING([for mntctl function and struct vmount]) 102 AC_MSG_CHECKING([for mntctl function and struct vmount])
103 AC_CACHE_VAL([fu_cv_sys_mounted_vmount], 103 AC_CACHE_VAL([fu_cv_sys_mounted_vmount],
104 [AC_TRY_CPP([#include <fshelp.h>], 104 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
105 fu_cv_sys_mounted_vmount=yes, 105 [fu_cv_sys_mounted_vmount=yes],
106 fu_cv_sys_mounted_vmount=no)]) 106 [fu_cv_sys_mounted_vmount=no])])
107 AC_MSG_RESULT([$fu_cv_sys_mounted_vmount]) 107 AC_MSG_RESULT([$fu_cv_sys_mounted_vmount])
108 if test $fu_cv_sys_mounted_vmount = yes; then 108 if test $fu_cv_sys_mounted_vmount = yes; then
109 ac_list_mounted_fs=found 109 ac_list_mounted_fs=found
110 AC_DEFINE([MOUNTED_VMOUNT], [1], 110 AC_DEFINE([MOUNTED_VMOUNT], [1],
111 [Define if there is a function named mntctl that can be used to read 111 [Define if there is a function named mntctl that can be used to read
112 the list of mounted file systems, and there is a system header file 112 the list of mounted file systems, and there is a system header file
113 that declares `struct vmount.' (AIX)]) 113 that declares `struct vmount.' (AIX)])
114 fi 114 fi
@@ -123,27 +123,27 @@ if test $ac_cv_func_getmntent = yes; then
123 # 4.3BSD, SunOS, HP-UX, Dynix, Irix 123 # 4.3BSD, SunOS, HP-UX, Dynix, Irix
124 AC_MSG_CHECKING([for one-argument getmntent function]) 124 AC_MSG_CHECKING([for one-argument getmntent function])
125 AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1], 125 AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1],
126 [AC_TRY_COMPILE([ 126 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
127/* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */ 127/* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
128#include <stdio.h> 128#include <stdio.h>
129 129
130#include <mntent.h> 130#include <mntent.h>
131#if !defined MOUNTED 131#if !defined MOUNTED
132# if defined _PATH_MOUNTED /* GNU libc */ 132# if defined _PATH_MOUNTED /* GNU libc */
133# define MOUNTED _PATH_MOUNTED 133# define MOUNTED _PATH_MOUNTED
134# endif 134# endif
135# if defined MNT_MNTTAB /* HP-UX. */ 135# if defined MNT_MNTTAB /* HP-UX. */
136# define MOUNTED MNT_MNTTAB 136# define MOUNTED MNT_MNTTAB
137# endif 137# endif
138# if defined MNTTABNAME /* Dynix. */ 138# if defined MNTTABNAME /* Dynix. */
139# define MOUNTED MNTTABNAME 139# define MOUNTED MNTTABNAME
140# endif 140# endif
141#endif 141#endif
142], 142]],
143 [ struct mntent *mnt = 0; char *table = MOUNTED; 143 [[ struct mntent *mnt = 0; char *table = MOUNTED;
144 if (sizeof mnt && sizeof table) return 0;], 144 if (sizeof mnt && sizeof table) return 0;]])],
145 fu_cv_sys_mounted_getmntent1=yes, 145 [fu_cv_sys_mounted_getmntent1=yes],
146 fu_cv_sys_mounted_getmntent1=no)]) 146 [fu_cv_sys_mounted_getmntent1=no])])
147 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent1]) 147 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent1])
148 if test $fu_cv_sys_mounted_getmntent1 = yes; then 148 if test $fu_cv_sys_mounted_getmntent1 = yes; then
149 ac_list_mounted_fs=found 149 ac_list_mounted_fs=found
@@ -179,25 +179,25 @@ if test -z "$ac_list_mounted_fs"; then
179 179
180 AC_MSG_CHECKING([for getfsstat function]) 180 AC_MSG_CHECKING([for getfsstat function])
181 AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat], 181 AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat],
182 [AC_TRY_LINK([ 182 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
183#include <sys/types.h> 183#include <sys/types.h>
184#if HAVE_STRUCT_FSSTAT_F_FSTYPENAME 184#if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
185# define FS_TYPE(Ent) ((Ent).f_fstypename) 185# define FS_TYPE(Ent) ((Ent).f_fstypename)
186#else 186#else
187# define FS_TYPE(Ent) mnt_names[(Ent).f_type] 187# define FS_TYPE(Ent) mnt_names[(Ent).f_type]
188#endif 188#endif
189]$getfsstat_includes 189$getfsstat_includes]]
190, 190,
191 [struct statfs *stats; 191 [[struct statfs *stats;
192 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); 192 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
193 char *t = FS_TYPE (*stats); ], 193 char *t = FS_TYPE (*stats); ]])],
194 fu_cv_sys_mounted_getfsstat=yes, 194 [fu_cv_sys_mounted_getfsstat=yes],
195 fu_cv_sys_mounted_getfsstat=no)]) 195 [fu_cv_sys_mounted_getfsstat=no])])
196 AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat]) 196 AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat])
197 if test $fu_cv_sys_mounted_getfsstat = yes; then 197 if test $fu_cv_sys_mounted_getfsstat = yes; then
198 ac_list_mounted_fs=found 198 ac_list_mounted_fs=found
199 AC_DEFINE([MOUNTED_GETFSSTAT], [1], 199 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
200 [Define if there is a function named getfsstat for reading the 200 [Define if there is a function named getfsstat for reading the
201 list of mounted file systems. (DEC Alpha running OSF/1)]) 201 list of mounted file systems. (DEC Alpha running OSF/1)])
202 fi 202 fi
203fi 203fi
@@ -206,12 +206,12 @@ if test -z "$ac_list_mounted_fs"; then
206 # SVR3 206 # SVR3
207 AC_MSG_CHECKING([for FIXME existence of three headers]) 207 AC_MSG_CHECKING([for FIXME existence of three headers])
208 AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp], 208 AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp],
209 [AC_TRY_CPP([ 209 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
210#include <sys/statfs.h> 210#include <sys/statfs.h>
211#include <sys/fstyp.h> 211#include <sys/fstyp.h>
212#include <mnttab.h>], 212#include <mnttab.h>]])],
213 fu_cv_sys_mounted_fread_fstyp=yes, 213 [fu_cv_sys_mounted_fread_fstyp=yes],
214 fu_cv_sys_mounted_fread_fstyp=no)]) 214 [fu_cv_sys_mounted_fread_fstyp=no])])
215 AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp]) 215 AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp])
216 if test $fu_cv_sys_mounted_fread_fstyp = yes; then 216 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
217 ac_list_mounted_fs=found 217 ac_list_mounted_fs=found
@@ -228,15 +228,15 @@ if test -z "$ac_list_mounted_fs"; then
228 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo], 228 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo],
229 [ 229 [
230 test "$ac_cv_func_getmntinfo" = yes \ 230 test "$ac_cv_func_getmntinfo" = yes \
231 && fu_cv_sys_mounted_getmntinfo=yes \ 231 && fu_cv_sys_mounted_getmntinfo=yes \
232 || fu_cv_sys_mounted_getmntinfo=no 232 || fu_cv_sys_mounted_getmntinfo=no
233 ]) 233 ])
234 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo]) 234 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo])
235 if test $fu_cv_sys_mounted_getmntinfo = yes; then 235 if test $fu_cv_sys_mounted_getmntinfo = yes; then
236 AC_MSG_CHECKING([whether getmntinfo returns statvfs structures]) 236 AC_MSG_CHECKING([whether getmntinfo returns statvfs structures])
237 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2], 237 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2],
238 [ 238 [
239 AC_TRY_COMPILE([ 239 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
240#if HAVE_SYS_PARAM_H 240#if HAVE_SYS_PARAM_H
241# include <sys/param.h> 241# include <sys/param.h>
242#endif 242#endif
@@ -248,7 +248,7 @@ if test -z "$ac_list_mounted_fs"; then
248# include <sys/statvfs.h> 248# include <sys/statvfs.h>
249#endif 249#endif
250extern int getmntinfo (struct statfs **, int); 250extern int getmntinfo (struct statfs **, int);
251 ], [], 251 ]], [])],
252 [fu_cv_sys_mounted_getmntinfo2=no], 252 [fu_cv_sys_mounted_getmntinfo2=no],
253 [fu_cv_sys_mounted_getmntinfo2=yes]) 253 [fu_cv_sys_mounted_getmntinfo2=yes])
254 ]) 254 ])
@@ -256,13 +256,13 @@ extern int getmntinfo (struct statfs **, int);
256 if test $fu_cv_sys_mounted_getmntinfo2 = no; then 256 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
257 ac_list_mounted_fs=found 257 ac_list_mounted_fs=found
258 AC_DEFINE([MOUNTED_GETMNTINFO], [1], 258 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
259 [Define if there is a function named getmntinfo for reading the 259 [Define if there is a function named getmntinfo for reading the
260 list of mounted file systems and it returns an array of 260 list of mounted file systems and it returns an array of
261 'struct statfs'. (4.4BSD, Darwin)]) 261 'struct statfs'. (4.4BSD, Darwin)])
262 else 262 else
263 ac_list_mounted_fs=found 263 ac_list_mounted_fs=found
264 AC_DEFINE([MOUNTED_GETMNTINFO2], [1], 264 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
265 [Define if there is a function named getmntinfo for reading the 265 [Define if there is a function named getmntinfo for reading the
266 list of mounted file systems and it returns an array of 266 list of mounted file systems and it returns an array of
267 'struct statvfs'. (NetBSD 3.0)]) 267 'struct statvfs'. (NetBSD 3.0)])
268 fi 268 fi
@@ -273,11 +273,11 @@ if test -z "$ac_list_mounted_fs"; then
273 # Ultrix 273 # Ultrix
274 AC_MSG_CHECKING([for getmnt function]) 274 AC_MSG_CHECKING([for getmnt function])
275 AC_CACHE_VAL([fu_cv_sys_mounted_getmnt], 275 AC_CACHE_VAL([fu_cv_sys_mounted_getmnt],
276 [AC_TRY_CPP([ 276 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
277#include <sys/fs_types.h> 277#include <sys/fs_types.h>
278#include <sys/mount.h>], 278#include <sys/mount.h>]])],
279 fu_cv_sys_mounted_getmnt=yes, 279 [fu_cv_sys_mounted_getmnt=yes],
280 fu_cv_sys_mounted_getmnt=no)]) 280 [fu_cv_sys_mounted_getmnt=no])])
281 AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt]) 281 AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt])
282 if test $fu_cv_sys_mounted_getmnt = yes; then 282 if test $fu_cv_sys_mounted_getmnt = yes; then
283 ac_list_mounted_fs=found 283 ac_list_mounted_fs=found
@@ -294,7 +294,7 @@ if test -z "$ac_list_mounted_fs"; then
294 AC_MSG_CHECKING([for BEOS mounted file system support functions]) 294 AC_MSG_CHECKING([for BEOS mounted file system support functions])
295 if test $ac_cv_header_fs_info_h = yes \ 295 if test $ac_cv_header_fs_info_h = yes \
296 && test $ac_cv_func_next_dev = yes \ 296 && test $ac_cv_func_next_dev = yes \
297 && test $ac_cv_func_fs_stat_dev = yes; then 297 && test $ac_cv_func_fs_stat_dev = yes; then
298 fu_result=yes 298 fu_result=yes
299 else 299 else
300 fu_result=no 300 fu_result=no
@@ -312,14 +312,14 @@ if test -z "$ac_list_mounted_fs"; then
312 # SVR2 312 # SVR2
313 AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab]) 313 AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
314 AC_CACHE_VAL([fu_cv_sys_mounted_fread], 314 AC_CACHE_VAL([fu_cv_sys_mounted_fread],
315 [AC_TRY_CPP([#include <mnttab.h>], 315 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
316 fu_cv_sys_mounted_fread=yes, 316 [fu_cv_sys_mounted_fread=yes],
317 fu_cv_sys_mounted_fread=no)]) 317 [fu_cv_sys_mounted_fread=no])])
318 AC_MSG_RESULT([$fu_cv_sys_mounted_fread]) 318 AC_MSG_RESULT([$fu_cv_sys_mounted_fread])
319 if test $fu_cv_sys_mounted_fread = yes; then 319 if test $fu_cv_sys_mounted_fread = yes; then
320 ac_list_mounted_fs=found 320 ac_list_mounted_fs=found
321 AC_DEFINE([MOUNTED_FREAD], [1], 321 AC_DEFINE([MOUNTED_FREAD], [1],
322 [Define if there is no specific function for reading the list of 322 [Define if there is no specific function for reading the list of
323 mounted file systems. fread will be used to read /etc/mnttab. 323 mounted file systems. fread will be used to read /etc/mnttab.
324 (SVR2) ]) 324 (SVR2) ])
325 fi 325 fi
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4
index 80701716..910ac922 100644
--- a/gl/m4/malloc.m4
+++ b/gl/m4/malloc.m4
@@ -1,5 +1,5 @@
1# malloc.m4 serial 9 1# malloc.m4 serial 9
2dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/math_h.m4 b/gl/m4/math_h.m4
index d941bc33..2d89ca3f 100644
--- a/gl/m4/math_h.m4
+++ b/gl/m4/math_h.m4
@@ -1,5 +1,5 @@
1# math_h.m4 serial 14 1# math_h.m4 serial 21
2dnl Copyright (C) 2007-2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -8,6 +8,8 @@ AC_DEFUN([gl_MATH_H],
8[ 8[
9 AC_REQUIRE([gl_MATH_H_DEFAULTS]) 9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 gl_CHECK_NEXT_HEADERS([math.h]) 10 gl_CHECK_NEXT_HEADERS([math.h])
11 AC_REQUIRE([AC_C_INLINE])
12
11 AC_CACHE_CHECK([whether NAN macro works], [gl_cv_header_math_nan_works], 13 AC_CACHE_CHECK([whether NAN macro works], [gl_cv_header_math_nan_works],
12 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>]], 14 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>]],
13 [[/* Solaris 10 has a broken definition of NAN. Other platforms 15 [[/* Solaris 10 has a broken definition of NAN. Other platforms
@@ -15,9 +17,9 @@ AC_DEFUN([gl_MATH_H],
15 test only needs to fail when NAN is provided but wrong. */ 17 test only needs to fail when NAN is provided but wrong. */
16 float f = 1.0f; 18 float f = 1.0f;
17#ifdef NAN 19#ifdef NAN
18 f = NAN; 20 f = NAN;
19#endif 21#endif
20 return f == 0;]])], 22 return f == 0;]])],
21 [gl_cv_header_math_nan_works=yes], 23 [gl_cv_header_math_nan_works=yes],
22 [gl_cv_header_math_nan_works=no])]) 24 [gl_cv_header_math_nan_works=no])])
23 if test $gl_cv_header_math_nan_works = no; then 25 if test $gl_cv_header_math_nan_works = no; then
@@ -26,26 +28,39 @@ AC_DEFUN([gl_MATH_H],
26 AC_CACHE_CHECK([whether HUGE_VAL works], [gl_cv_header_math_huge_val_works], 28 AC_CACHE_CHECK([whether HUGE_VAL works], [gl_cv_header_math_huge_val_works],
27 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>]], 29 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>]],
28 [[/* Solaris 10 has a broken definition of HUGE_VAL. */ 30 [[/* Solaris 10 has a broken definition of HUGE_VAL. */
29 double d = HUGE_VAL; 31 double d = HUGE_VAL;
30 return d == 0;]])], 32 return d == 0;]])],
31 [gl_cv_header_math_huge_val_works=yes], 33 [gl_cv_header_math_huge_val_works=yes],
32 [gl_cv_header_math_huge_val_works=no])]) 34 [gl_cv_header_math_huge_val_works=no])])
33 if test $gl_cv_header_math_huge_val_works = no; then 35 if test $gl_cv_header_math_huge_val_works = no; then
34 REPLACE_HUGE_VAL=1 36 REPLACE_HUGE_VAL=1
35 fi 37 fi
38
39 dnl Check for declarations of anything we want to poison if the
40 dnl corresponding gnulib module is not in use.
41 gl_WARN_ON_USE_PREPARE([[#include <math.h>
42 ]], [acosl asinl atanl ceilf ceill cosl expl floorf floorl frexpl
43 ldexpl logb logl round roundf roundl sinl sqrtl tanl trunc truncf truncl])
36]) 44])
37 45
38AC_DEFUN([gl_MATH_MODULE_INDICATOR], 46AC_DEFUN([gl_MATH_MODULE_INDICATOR],
39[ 47[
40 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 48 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
41 AC_REQUIRE([gl_MATH_H_DEFAULTS]) 49 AC_REQUIRE([gl_MATH_H_DEFAULTS])
42 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 50 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
51 dnl Define it also as a C macro, for the benefit of the unit tests.
52 gl_MODULE_INDICATOR_FOR_TESTS([$1])
43]) 53])
44 54
45AC_DEFUN([gl_MATH_H_DEFAULTS], 55AC_DEFUN([gl_MATH_H_DEFAULTS],
46[ 56[
57 GNULIB_ACOSL=0; AC_SUBST([GNULIB_ACOSL])
58 GNULIB_ASINL=0; AC_SUBST([GNULIB_ASINL])
59 GNULIB_ATANL=0; AC_SUBST([GNULIB_ATANL])
47 GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF]) 60 GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF])
48 GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL]) 61 GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL])
62 GNULIB_COSL=0; AC_SUBST([GNULIB_COSL])
63 GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL])
49 GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) 64 GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF])
50 GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) 65 GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL])
51 GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) 66 GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP])
@@ -57,31 +72,53 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
57 GNULIB_ISNAND=0; AC_SUBST([GNULIB_ISNAND]) 72 GNULIB_ISNAND=0; AC_SUBST([GNULIB_ISNAND])
58 GNULIB_ISNANL=0; AC_SUBST([GNULIB_ISNANL]) 73 GNULIB_ISNANL=0; AC_SUBST([GNULIB_ISNANL])
59 GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) 74 GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL])
60 GNULIB_MATHL=0; AC_SUBST([GNULIB_MATHL]) 75 GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB])
76 GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL])
61 GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND]) 77 GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND])
62 GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF]) 78 GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF])
63 GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) 79 GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL])
64 GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT]) 80 GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT])
81 GNULIB_SINL=0; AC_SUBST([GNULIB_SINL])
82 GNULIB_SQRTL=0; AC_SUBST([GNULIB_SQRTL])
83 GNULIB_TANL=0; AC_SUBST([GNULIB_TANL])
65 GNULIB_TRUNC=0; AC_SUBST([GNULIB_TRUNC]) 84 GNULIB_TRUNC=0; AC_SUBST([GNULIB_TRUNC])
66 GNULIB_TRUNCF=0; AC_SUBST([GNULIB_TRUNCF]) 85 GNULIB_TRUNCF=0; AC_SUBST([GNULIB_TRUNCF])
67 GNULIB_TRUNCL=0; AC_SUBST([GNULIB_TRUNCL]) 86 GNULIB_TRUNCL=0; AC_SUBST([GNULIB_TRUNCL])
68 dnl Assume proper GNU behavior unless another module says otherwise. 87 dnl Assume proper GNU behavior unless another module says otherwise.
88 HAVE_ACOSL=1; AC_SUBST([HAVE_ACOSL])
89 HAVE_ASINL=1; AC_SUBST([HAVE_ASINL])
90 HAVE_ATANL=1; AC_SUBST([HAVE_ATANL])
91 HAVE_COSL=1; AC_SUBST([HAVE_COSL])
92 HAVE_EXPL=1; AC_SUBST([HAVE_EXPL])
69 HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF]) 93 HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF])
70 HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND]) 94 HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND])
71 HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL]) 95 HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL])
96 HAVE_LOGL=1; AC_SUBST([HAVE_LOGL])
97 HAVE_SINL=1; AC_SUBST([HAVE_SINL])
98 HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL])
99 HAVE_TANL=1; AC_SUBST([HAVE_TANL])
72 HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) 100 HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL])
73 HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) 101 HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL])
74 HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) 102 HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL])
103 HAVE_DECL_CEILF=1; AC_SUBST([HAVE_DECL_CEILF])
104 HAVE_DECL_CEILL=1; AC_SUBST([HAVE_DECL_CEILL])
75 HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL]) 105 HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL])
76 HAVE_DECL_EXPL=1; AC_SUBST([HAVE_DECL_EXPL]) 106 HAVE_DECL_EXPL=1; AC_SUBST([HAVE_DECL_EXPL])
107 HAVE_DECL_FLOORF=1; AC_SUBST([HAVE_DECL_FLOORF])
108 HAVE_DECL_FLOORL=1; AC_SUBST([HAVE_DECL_FLOORL])
77 HAVE_DECL_FREXPL=1; AC_SUBST([HAVE_DECL_FREXPL]) 109 HAVE_DECL_FREXPL=1; AC_SUBST([HAVE_DECL_FREXPL])
78 HAVE_DECL_LDEXPL=1; AC_SUBST([HAVE_DECL_LDEXPL]) 110 HAVE_DECL_LDEXPL=1; AC_SUBST([HAVE_DECL_LDEXPL])
111 HAVE_DECL_LOGB=1; AC_SUBST([HAVE_DECL_LOGB])
79 HAVE_DECL_LOGL=1; AC_SUBST([HAVE_DECL_LOGL]) 112 HAVE_DECL_LOGL=1; AC_SUBST([HAVE_DECL_LOGL])
113 HAVE_DECL_ROUND=1; AC_SUBST([HAVE_DECL_ROUND])
114 HAVE_DECL_ROUNDF=1; AC_SUBST([HAVE_DECL_ROUNDF])
115 HAVE_DECL_ROUNDL=1; AC_SUBST([HAVE_DECL_ROUNDL])
80 HAVE_DECL_SINL=1; AC_SUBST([HAVE_DECL_SINL]) 116 HAVE_DECL_SINL=1; AC_SUBST([HAVE_DECL_SINL])
81 HAVE_DECL_SQRTL=1; AC_SUBST([HAVE_DECL_SQRTL]) 117 HAVE_DECL_SQRTL=1; AC_SUBST([HAVE_DECL_SQRTL])
82 HAVE_DECL_TANL=1; AC_SUBST([HAVE_DECL_TANL]) 118 HAVE_DECL_TANL=1; AC_SUBST([HAVE_DECL_TANL])
83 HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC]) 119 HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC])
84 HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF]) 120 HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF])
121 HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL])
85 REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF]) 122 REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF])
86 REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL]) 123 REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL])
87 REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF]) 124 REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF])
diff --git a/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4
index 11d7d23e..606de5c9 100644
--- a/gl/m4/mbrtowc.m4
+++ b/gl/m4/mbrtowc.m4
@@ -1,5 +1,6 @@
1# mbrtowc.m4 serial 15 1# mbrtowc.m4 serial 17
2dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2002, 2004-2005, 2008-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -10,38 +11,39 @@ AC_DEFUN([gl_FUNC_MBRTOWC],
10 11
11 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 12 AC_REQUIRE([AC_TYPE_MBSTATE_T])
12 gl_MBSTATE_T_BROKEN 13 gl_MBSTATE_T_BROKEN
13 if test $REPLACE_MBSTATE_T = 1; then 14
14 REPLACE_MBRTOWC=1
15 fi
16 AC_CHECK_FUNCS_ONCE([mbrtowc]) 15 AC_CHECK_FUNCS_ONCE([mbrtowc])
17 if test $ac_cv_func_mbrtowc = no; then 16 if test $ac_cv_func_mbrtowc = no; then
18 HAVE_MBRTOWC=0 17 HAVE_MBRTOWC=0
19 fi 18 else
20 if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 1; then 19 if test $REPLACE_MBSTATE_T = 1; then
21 gl_MBRTOWC_NULL_ARG 20 REPLACE_MBRTOWC=1
22 gl_MBRTOWC_RETVAL 21 else
23 gl_MBRTOWC_NUL_RETVAL 22 gl_MBRTOWC_NULL_ARG
24 case "$gl_cv_func_mbrtowc_null_arg" in 23 gl_MBRTOWC_RETVAL
25 *yes) ;; 24 gl_MBRTOWC_NUL_RETVAL
26 *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1], 25 case "$gl_cv_func_mbrtowc_null_arg" in
27 [Define if the mbrtowc function has the NULL string argument bug.]) 26 *yes) ;;
28 REPLACE_MBRTOWC=1 27 *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
29 ;; 28 [Define if the mbrtowc function has the NULL string argument bug.])
30 esac 29 REPLACE_MBRTOWC=1
31 case "$gl_cv_func_mbrtowc_retval" in 30 ;;
32 *yes) ;; 31 esac
33 *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1], 32 case "$gl_cv_func_mbrtowc_retval" in
34 [Define if the mbrtowc function returns a wrong return value.]) 33 *yes) ;;
35 REPLACE_MBRTOWC=1 34 *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
36 ;; 35 [Define if the mbrtowc function returns a wrong return value.])
37 esac 36 REPLACE_MBRTOWC=1
38 case "$gl_cv_func_mbrtowc_nul_retval" in 37 ;;
39 *yes) ;; 38 esac
40 *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1], 39 case "$gl_cv_func_mbrtowc_nul_retval" in
41 [Define if the mbrtowc function does not return 0 for a NUL character.]) 40 *yes) ;;
42 REPLACE_MBRTOWC=1 41 *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
43 ;; 42 [Define if the mbrtowc function does not return 0 for a NUL character.])
44 esac 43 REPLACE_MBRTOWC=1
44 ;;
45 esac
46 fi
45 fi 47 fi
46 if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then 48 if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
47 gl_REPLACE_WCHAR_H 49 gl_REPLACE_WCHAR_H
@@ -156,6 +158,7 @@ changequote([,])dnl
156 if test $LOCALE_ZH_CN != none; then 158 if test $LOCALE_ZH_CN != none; then
157 AC_TRY_RUN([ 159 AC_TRY_RUN([
158#include <locale.h> 160#include <locale.h>
161#include <stdlib.h>
159#include <string.h> 162#include <string.h>
160#include <wchar.h> 163#include <wchar.h>
161int main () 164int main ()
diff --git a/gl/m4/mbsinit.m4 b/gl/m4/mbsinit.m4
index 03b055cd..46c106fc 100644
--- a/gl/m4/mbsinit.m4
+++ b/gl/m4/mbsinit.m4
@@ -1,5 +1,5 @@
1# mbsinit.m4 serial 3 1# mbsinit.m4 serial 4
2dnl Copyright (C) 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -10,12 +10,14 @@ AC_DEFUN([gl_FUNC_MBSINIT],
10 10
11 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
12 gl_MBSTATE_T_BROKEN 12 gl_MBSTATE_T_BROKEN
13 if test $REPLACE_MBSTATE_T = 1; then 13
14 REPLACE_MBSINIT=1
15 fi
16 AC_CHECK_FUNCS_ONCE([mbsinit]) 14 AC_CHECK_FUNCS_ONCE([mbsinit])
17 if test $ac_cv_func_mbsinit = no; then 15 if test $ac_cv_func_mbsinit = no; then
18 HAVE_MBSINIT=0 16 HAVE_MBSINIT=0
17 else
18 if test $REPLACE_MBSTATE_T = 1; then
19 REPLACE_MBSINIT=1
20 fi
19 fi 21 fi
20 if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then 22 if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then
21 gl_REPLACE_WCHAR_H 23 gl_REPLACE_WCHAR_H
diff --git a/gl/m4/mbstate_t.m4 b/gl/m4/mbstate_t.m4
index d4ec6f0f..3e2df29f 100644
--- a/gl/m4/mbstate_t.m4
+++ b/gl/m4/mbstate_t.m4
@@ -1,5 +1,5 @@
1# mbstate_t.m4 serial 12 1# mbstate_t.m4 serial 12
2dnl Copyright (C) 2000-2002, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -18,17 +18,17 @@ AC_DEFUN([AC_TYPE_MBSTATE_T],
18 18
19 AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t], 19 AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],
20 [AC_COMPILE_IFELSE( 20 [AC_COMPILE_IFELSE(
21 [AC_LANG_PROGRAM( 21 [AC_LANG_PROGRAM(
22 [AC_INCLUDES_DEFAULT[ 22 [AC_INCLUDES_DEFAULT[
23# include <wchar.h>]], 23# include <wchar.h>]],
24 [[mbstate_t x; return sizeof x;]])], 24 [[mbstate_t x; return sizeof x;]])],
25 [ac_cv_type_mbstate_t=yes], 25 [ac_cv_type_mbstate_t=yes],
26 [ac_cv_type_mbstate_t=no])]) 26 [ac_cv_type_mbstate_t=no])])
27 if test $ac_cv_type_mbstate_t = yes; then 27 if test $ac_cv_type_mbstate_t = yes; then
28 AC_DEFINE([HAVE_MBSTATE_T], [1], 28 AC_DEFINE([HAVE_MBSTATE_T], [1],
29 [Define to 1 if <wchar.h> declares mbstate_t.]) 29 [Define to 1 if <wchar.h> declares mbstate_t.])
30 else 30 else
31 AC_DEFINE([mbstate_t], [int], 31 AC_DEFINE([mbstate_t], [int],
32 [Define to a type if <wchar.h> does not define.]) 32 [Define to a type if <wchar.h> does not define.])
33 fi 33 fi
34]) 34])
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4
new file mode 100644
index 00000000..ab773b81
--- /dev/null
+++ b/gl/m4/memchr.m4
@@ -0,0 +1,85 @@
1# memchr.m4 serial 8
2dnl Copyright (C) 2002-2004, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
8[
9 dnl Check for prerequisites for memory fence checks.
10 gl_FUNC_MMAP_ANON
11 AC_CHECK_HEADERS_ONCE([sys/mman.h])
12 AC_CHECK_FUNCS_ONCE([mprotect])
13
14 dnl These days, we assume memchr is present. But just in case...
15 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
16 AC_CHECK_FUNCS_ONCE([memchr])
17 if test $ac_cv_func_memchr = yes; then
18 # Detect platform-specific bugs in some versions of glibc:
19 # memchr should not dereference anything with length 0
20 # http://bugzilla.redhat.com/499689
21 # memchr should not dereference overestimated length after a match
22 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
23 # http://sourceware.org/bugzilla/show_bug.cgi?id=10162
24 # Assume that memchr works on platforms that lack mprotect.
25 AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
26 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
27#include <string.h>
28#if HAVE_SYS_MMAN_H
29# include <fcntl.h>
30# include <unistd.h>
31# include <sys/types.h>
32# include <sys/mman.h>
33# ifndef MAP_FILE
34# define MAP_FILE 0
35# endif
36#endif
37]], [[
38 char *fence = NULL;
39#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
40# if HAVE_MAP_ANONYMOUS
41 const int flags = MAP_ANONYMOUS | MAP_PRIVATE;
42 const int fd = -1;
43# else /* !HAVE_MAP_ANONYMOUS */
44 const int flags = MAP_FILE | MAP_PRIVATE;
45 int fd = open ("/dev/zero", O_RDONLY, 0666);
46 if (fd >= 0)
47# endif
48 {
49 int pagesize = getpagesize ();
50 char *two_pages =
51 (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
52 flags, fd, 0);
53 if (two_pages != (char *)(-1)
54 && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
55 fence = two_pages + pagesize;
56 }
57#endif
58 if (fence)
59 {
60 if (memchr (fence, 0, 0))
61 return 1;
62 strcpy (fence - 9, "12345678");
63 if (memchr (fence - 9, 0, 79) != fence - 1)
64 return 2;
65 }
66 return 0;
67]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no],
68 [dnl Be pessimistic for now.
69 gl_cv_func_memchr_works="guessing no"])])
70 if test "$gl_cv_func_memchr_works" != yes; then
71 REPLACE_MEMCHR=1
72 fi
73 else
74 HAVE_MEMCHR=0
75 fi
76 if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
77 AC_LIBOBJ([memchr])
78 gl_PREREQ_MEMCHR
79 fi
80])
81
82# Prerequisites of lib/memchr.c.
83AC_DEFUN([gl_PREREQ_MEMCHR], [
84 AC_CHECK_HEADERS([bp-sym.h])
85])
diff --git a/gl/m4/mktime.m4 b/gl/m4/mktime.m4
index 1e926e86..44b8d878 100644
--- a/gl/m4/mktime.m4
+++ b/gl/m4/mktime.m4
@@ -1,5 +1,6 @@
1# serial 15 1# serial 15
2dnl Copyright (C) 2002-2003, 2005-2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -85,8 +86,8 @@ static int
85mktime_test (time_t now) 86mktime_test (time_t now)
86{ 87{
87 return (mktime_test1 (now) 88 return (mktime_test1 (now)
88 && mktime_test1 ((time_t) (time_t_max - now)) 89 && mktime_test1 ((time_t) (time_t_max - now))
89 && mktime_test1 ((time_t) (time_t_min + now))); 90 && mktime_test1 ((time_t) (time_t_min + now)));
90} 91}
91 92
92static int 93static int
@@ -116,17 +117,17 @@ bigtime_test (int j)
116 { 117 {
117 struct tm *lt = localtime (&now); 118 struct tm *lt = localtime (&now);
118 if (! (lt 119 if (! (lt
119 && lt->tm_year == tm.tm_year 120 && lt->tm_year == tm.tm_year
120 && lt->tm_mon == tm.tm_mon 121 && lt->tm_mon == tm.tm_mon
121 && lt->tm_mday == tm.tm_mday 122 && lt->tm_mday == tm.tm_mday
122 && lt->tm_hour == tm.tm_hour 123 && lt->tm_hour == tm.tm_hour
123 && lt->tm_min == tm.tm_min 124 && lt->tm_min == tm.tm_min
124 && lt->tm_sec == tm.tm_sec 125 && lt->tm_sec == tm.tm_sec
125 && lt->tm_yday == tm.tm_yday 126 && lt->tm_yday == tm.tm_yday
126 && lt->tm_wday == tm.tm_wday 127 && lt->tm_wday == tm.tm_wday
127 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst) 128 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
128 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst)))) 129 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
129 return 0; 130 return 0;
130 } 131 }
131 return 1; 132 return 1;
132} 133}
@@ -158,7 +159,7 @@ year_2050_test ()
158 to the correct answer that we can assume the discrepancy is 159 to the correct answer that we can assume the discrepancy is
159 due to leap seconds. */ 160 due to leap seconds. */
160 return (t == (time_t) -1 161 return (t == (time_t) -1
161 || (0 < t && answer - 120 <= t && t <= answer + 120)); 162 || (0 < t && answer - 120 <= t && t <= answer + 120));
162} 163}
163 164
164int 165int
@@ -176,7 +177,7 @@ main ()
176 { 177 {
177 t = (time_t_max << 1) + 1; 178 t = (time_t_max << 1) + 1;
178 if (t <= time_t_max) 179 if (t <= time_t_max)
179 break; 180 break;
180 time_t_max = t; 181 time_t_max = t;
181 } 182 }
182 time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max; 183 time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
@@ -185,29 +186,29 @@ main ()
185 for (i = 0; i < N_STRINGS; i++) 186 for (i = 0; i < N_STRINGS; i++)
186 { 187 {
187 if (tz_strings[i]) 188 if (tz_strings[i])
188 putenv (tz_strings[i]); 189 putenv (tz_strings[i]);
189 190
190 for (t = 0; t <= time_t_max - delta; t += delta) 191 for (t = 0; t <= time_t_max - delta; t += delta)
191 if (! mktime_test (t)) 192 if (! mktime_test (t))
192 return 1; 193 return 1;
193 if (! (mktime_test ((time_t) 1) 194 if (! (mktime_test ((time_t) 1)
194 && mktime_test ((time_t) (60 * 60)) 195 && mktime_test ((time_t) (60 * 60))
195 && mktime_test ((time_t) (60 * 60 * 24)))) 196 && mktime_test ((time_t) (60 * 60 * 24))))
196 return 1; 197 return 1;
197 198
198 for (j = 1; ; j <<= 1) 199 for (j = 1; ; j <<= 1)
199 if (! bigtime_test (j)) 200 if (! bigtime_test (j))
200 return 1; 201 return 1;
201 else if (INT_MAX / 2 < j) 202 else if (INT_MAX / 2 < j)
202 break; 203 break;
203 if (! bigtime_test (INT_MAX)) 204 if (! bigtime_test (INT_MAX))
204 return 1; 205 return 1;
205 } 206 }
206 return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ()); 207 return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
207}]])], 208}]])],
208 [ac_cv_func_working_mktime=yes], 209 [ac_cv_func_working_mktime=yes],
209 [ac_cv_func_working_mktime=no], 210 [ac_cv_func_working_mktime=no],
210 [ac_cv_func_working_mktime=no])]) 211 [ac_cv_func_working_mktime=no])])
211if test $ac_cv_func_working_mktime = no; then 212if test $ac_cv_func_working_mktime = no; then
212 AC_LIBOBJ([mktime]) 213 AC_LIBOBJ([mktime])
213fi 214fi
@@ -215,12 +216,14 @@ fi
215 216
216AC_DEFUN([gl_FUNC_MKTIME], 217AC_DEFUN([gl_FUNC_MKTIME],
217[ 218[
219 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
218 AC_FUNC_MKTIME 220 AC_FUNC_MKTIME
219 dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]). 221 dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
220 if test $ac_cv_func_working_mktime = no; then 222 if test $ac_cv_func_working_mktime = no; then
221 AC_DEFINE([mktime], [rpl_mktime], 223 REPLACE_MKTIME=1
222 [Define to rpl_mktime if the replacement function should be used.])
223 gl_PREREQ_MKTIME 224 gl_PREREQ_MKTIME
225 else
226 REPLACE_MKTIME=0
224 fi 227 fi
225]) 228])
226 229
diff --git a/gl/m4/mmap-anon.m4 b/gl/m4/mmap-anon.m4
new file mode 100644
index 00000000..a6b7b9ac
--- /dev/null
+++ b/gl/m4/mmap-anon.m4
@@ -0,0 +1,59 @@
1# mmap-anon.m4 serial 8
2dnl Copyright (C) 2005, 2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# Detect how mmap can be used to create anonymous (not file-backed) memory
8# mappings.
9# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
10# and MAP_ANON exist and have the same value.
11# - On HP-UX, only MAP_ANONYMOUS exists.
12# - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
13# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
14# used.
15
16AC_DEFUN([gl_FUNC_MMAP_ANON],
17[
18 dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
19 AC_REQUIRE([AC_PROG_CPP])
20 AC_REQUIRE([AC_PROG_EGREP])
21
22 dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
23 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
24
25 # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
26 # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
27 # irrelevant for anonymous mappings.
28 AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no])
29
30 # Try to allow MAP_ANONYMOUS.
31 gl_have_mmap_anonymous=no
32 if test $gl_have_mmap = yes; then
33 AC_MSG_CHECKING([for MAP_ANONYMOUS])
34 AC_EGREP_CPP([I cant identify this map.], [
35#include <sys/mman.h>
36#ifdef MAP_ANONYMOUS
37 I cant identify this map.
38#endif
39],
40 [gl_have_mmap_anonymous=yes])
41 if test $gl_have_mmap_anonymous != yes; then
42 AC_EGREP_CPP([I cant identify this map.], [
43#include <sys/mman.h>
44#ifdef MAP_ANON
45 I cant identify this map.
46#endif
47],
48 [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
49 [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.])
50 gl_have_mmap_anonymous=yes])
51 fi
52 AC_MSG_RESULT([$gl_have_mmap_anonymous])
53 if test $gl_have_mmap_anonymous = yes; then
54 AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
55 [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
56 config.h and <sys/mman.h>.])
57 fi
58 fi
59])
diff --git a/gl/m4/mode_t.m4 b/gl/m4/mode_t.m4
new file mode 100644
index 00000000..3178dfd3
--- /dev/null
+++ b/gl/m4/mode_t.m4
@@ -0,0 +1,26 @@
1# mode_t.m4 serial 2
2dnl Copyright (C) 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# For using mode_t, it's sufficient to use AC_TYPE_MODE_T and
8# include <sys/types.h>.
9
10# Define PROMOTED_MODE_T to the type that is the result of "default argument
11# promotion" (ISO C 6.5.2.2.(6)) of the type mode_t.
12AC_DEFUN([gl_PROMOTED_TYPE_MODE_T],
13[
14 AC_REQUIRE([AC_TYPE_MODE_T])
15 AC_CACHE_CHECK([for promoted mode_t type], [gl_cv_promoted_mode_t], [
16 dnl Assume mode_t promotes to 'int' if and only if it is smaller than 'int',
17 dnl and to itself otherwise. This assumption is not guaranteed by the ISO C
18 dnl standard, but we don't know of any real-world counterexamples.
19 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]],
20 [[typedef int array[2 * (sizeof (mode_t) < sizeof (int)) - 1];]])],
21 [gl_cv_promoted_mode_t='int'],
22 [gl_cv_promoted_mode_t='mode_t'])
23 ])
24 AC_DEFINE_UNQUOTED([PROMOTED_MODE_T], [$gl_cv_promoted_mode_t],
25 [Define to the type that is the result of default argument promotions of type mode_t.])
26])
diff --git a/gl/m4/mountlist.m4 b/gl/m4/mountlist.m4
index f62c57a2..f2d59501 100644
--- a/gl/m4/mountlist.m4
+++ b/gl/m4/mountlist.m4
@@ -1,5 +1,5 @@
1# serial 10 1# serial 10
2dnl Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_MOUNTLIST], 7AC_DEFUN([gl_MOUNTLIST],
8[ 8[
9 gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], 9 gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes],
10 [gl_cv_list_mounted_fs=no]) 10 [gl_cv_list_mounted_fs=no])
11 if test $gl_cv_list_mounted_fs = yes; then 11 if test $gl_cv_list_mounted_fs = yes; then
12 AC_LIBOBJ([mountlist]) 12 AC_LIBOBJ([mountlist])
13 gl_PREREQ_MOUNTLIST_EXTRA 13 gl_PREREQ_MOUNTLIST_EXTRA
diff --git a/gl/m4/multiarch.m4 b/gl/m4/multiarch.m4
index ec377bac..389bd2bb 100644
--- a/gl/m4/multiarch.m4
+++ b/gl/m4/multiarch.m4
@@ -1,5 +1,5 @@
1# multiarch.m4 serial 5 1# multiarch.m4 serial 5
2dnl Copyright (C) 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/netdb_h.m4 b/gl/m4/netdb_h.m4
index 5a12251f..40ba8f66 100644
--- a/gl/m4/netdb_h.m4
+++ b/gl/m4/netdb_h.m4
@@ -1,5 +1,5 @@
1# netdb_h.m4 serial 5 1# netdb_h.m4 serial 7
2dnl Copyright (C) 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_HEADER_NETDB], 7AC_DEFUN([gl_HEADER_NETDB],
8[ 8[
9 AC_REQUIRE([gl_NETDB_H_DEFAULTS]) 9 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
10 AC_CHECK_HEADERS_ONCE([netdb.h])
10 gl_CHECK_NEXT_HEADERS([netdb.h]) 11 gl_CHECK_NEXT_HEADERS([netdb.h])
11 if test $ac_cv_header_netdb_h = yes; then 12 if test $ac_cv_header_netdb_h = yes; then
12 AC_COMPILE_IFELSE( 13 AC_COMPILE_IFELSE(
@@ -30,7 +31,7 @@ AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
30[ 31[
31 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 32 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
32 AC_REQUIRE([gl_NETDB_H_DEFAULTS]) 33 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
33 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 34 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
34]) 35])
35 36
36AC_DEFUN([gl_NETDB_H_DEFAULTS], 37AC_DEFUN([gl_NETDB_H_DEFAULTS],
diff --git a/gl/m4/netinet_in_h.m4 b/gl/m4/netinet_in_h.m4
index 47fd9cc3..cc7a44cc 100644
--- a/gl/m4/netinet_in_h.m4
+++ b/gl/m4/netinet_in_h.m4
@@ -1,5 +1,5 @@
1# netinet_in_h.m4 serial 4 1# netinet_in_h.m4 serial 4
2dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/nl_langinfo.m4 b/gl/m4/nl_langinfo.m4
new file mode 100644
index 00000000..ad456a26
--- /dev/null
+++ b/gl/m4/nl_langinfo.m4
@@ -0,0 +1,25 @@
1# nl_langinfo.m4 serial 3
2dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_NL_LANGINFO],
8[
9 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
10 AC_REQUIRE([gl_LANGINFO_H])
11 AC_CHECK_FUNCS_ONCE([nl_langinfo])
12 if test $ac_cv_func_nl_langinfo = yes; then
13 if test $HAVE_LANGINFO_CODESET = 1 && test $HAVE_LANGINFO_ERA = 1; then
14 :
15 else
16 REPLACE_NL_LANGINFO=1
17 AC_DEFINE([REPLACE_NL_LANGINFO], [1],
18 [Define if nl_langinfo exists but is overridden by gnulib.])
19 AC_LIBOBJ([nl_langinfo])
20 fi
21 else
22 HAVE_NL_LANGINFO=0
23 AC_LIBOBJ([nl_langinfo])
24 fi
25])
diff --git a/gl/m4/nls.m4 b/gl/m4/nls.m4
index 0b364342..003704c4 100644
--- a/gl/m4/nls.m4
+++ b/gl/m4/nls.m4
@@ -1,5 +1,6 @@
1# nls.m4 serial 5 (gettext-0.18) 1# nls.m4 serial 5 (gettext-0.18)
2dnl Copyright (C) 1995-2003, 2005-2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2003, 2005-2006, 2008-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/onceonly.m4 b/gl/m4/onceonly.m4
index 108cd6c1..4a3cd84d 100644
--- a/gl/m4/onceonly.m4
+++ b/gl/m4/onceonly.m4
@@ -1,5 +1,6 @@
1# onceonly.m4 serial 6 1# onceonly.m4 serial 6
2dnl Copyright (C) 2002-2003, 2005-2006, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2006, 2008-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software, distributed under the terms of the GNU 4dnl This file is free software, distributed under the terms of the GNU
4dnl General Public License. As a special exception to the GNU General 5dnl General Public License. As a special exception to the GNU General
5dnl Public License, this file may be distributed as part of a program 6dnl Public License, this file may be distributed as part of a program
diff --git a/gl/m4/open.m4 b/gl/m4/open.m4
index 6e286c96..d705b3a1 100644
--- a/gl/m4/open.m4
+++ b/gl/m4/open.m4
@@ -1,5 +1,5 @@
1# open.m4 serial 5 1# open.m4 serial 8
2dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -13,10 +13,15 @@ AC_DEFUN([gl_FUNC_OPEN],
13 ;; 13 ;;
14 *) 14 *)
15 dnl open("foo/") should not create a file when the file name has a 15 dnl open("foo/") should not create a file when the file name has a
16 dnl trailing slash. 16 dnl trailing slash. FreeBSD only has the problem on symlinks.
17 AC_CHECK_FUNCS_ONCE([lstat])
17 AC_CACHE_CHECK([whether open recognizes a trailing slash], 18 AC_CACHE_CHECK([whether open recognizes a trailing slash],
18 [gl_cv_func_open_slash], 19 [gl_cv_func_open_slash],
19 [ 20 [# Assume that if we have lstat, we can also check symlinks.
21 if test $ac_cv_func_lstat = yes; then
22 touch conftest.tmp
23 ln -s conftest.tmp conftest.lnk
24 fi
20 AC_TRY_RUN([ 25 AC_TRY_RUN([
21#include <fcntl.h> 26#include <fcntl.h>
22#if HAVE_UNISTD_H 27#if HAVE_UNISTD_H
@@ -24,18 +29,22 @@ AC_DEFUN([gl_FUNC_OPEN],
24#endif 29#endif
25int main () 30int main ()
26{ 31{
32#if HAVE_LSTAT
33 if (open ("conftest.lnk/", O_RDONLY) != -1) return 2;
34#endif
27 return open ("conftest.sl/", O_CREAT, 0600) >= 0; 35 return open ("conftest.sl/", O_CREAT, 0600) >= 0;
28}], [gl_cv_func_open_slash=yes], [gl_cv_func_open_slash=no], 36}], [gl_cv_func_open_slash=yes], [gl_cv_func_open_slash=no],
29 [ 37 [
30changequote(,)dnl 38changequote(,)dnl
31 case "$host_os" in 39 case "$host_os" in
40 freebsd*) gl_cv_func_open_slash="guessing no" ;;
32 solaris2.[0-9]*) gl_cv_func_open_slash="guessing no" ;; 41 solaris2.[0-9]*) gl_cv_func_open_slash="guessing no" ;;
33 hpux*) gl_cv_func_open_slash="guessing no" ;; 42 hpux*) gl_cv_func_open_slash="guessing no" ;;
34 *) gl_cv_func_open_slash="guessing yes" ;; 43 *) gl_cv_func_open_slash="guessing yes" ;;
35 esac 44 esac
36changequote([,])dnl 45changequote([,])dnl
37 ]) 46 ])
38 rm -f conftest.sl 47 rm -f conftest.sl conftest.tmp conftest.lnk
39 ]) 48 ])
40 case "$gl_cv_func_open_slash" in 49 case "$gl_cv_func_open_slash" in
41 *no) 50 *no)
@@ -51,16 +60,15 @@ changequote([,])dnl
51AC_DEFUN([gl_REPLACE_OPEN], 60AC_DEFUN([gl_REPLACE_OPEN],
52[ 61[
53 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) 62 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
54 if test $REPLACE_OPEN != 1; then
55 AC_LIBOBJ([open])
56 gl_PREREQ_OPEN
57 fi
58 REPLACE_OPEN=1 63 REPLACE_OPEN=1
64 AC_LIBOBJ([open])
65 gl_PREREQ_OPEN
59]) 66])
60 67
61# Prerequisites of lib/open.c. 68# Prerequisites of lib/open.c.
62AC_DEFUN([gl_PREREQ_OPEN], 69AC_DEFUN([gl_PREREQ_OPEN],
63[ 70[
64 AC_REQUIRE([AC_C_INLINE]) 71 AC_REQUIRE([AC_C_INLINE])
72 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
65 : 73 :
66]) 74])
diff --git a/gl/m4/po.m4 b/gl/m4/po.m4
index 2284fa50..960efe15 100644
--- a/gl/m4/po.m4
+++ b/gl/m4/po.m4
@@ -1,5 +1,5 @@
1# po.m4 serial 17 (gettext-0.18) 1# po.m4 serial 17 (gettext-0.18)
2dnl Copyright (C) 1995-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/printf-posix.m4 b/gl/m4/printf-posix.m4
index 5922d278..1eacf95a 100644
--- a/gl/m4/printf-posix.m4
+++ b/gl/m4/printf-posix.m4
@@ -1,5 +1,5 @@
1# printf-posix.m4 serial 5 (gettext-0.18) 1# printf-posix.m4 serial 5 (gettext-0.18)
2dnl Copyright (C) 2003, 2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4
index 87aa45c5..ebca5364 100644
--- a/gl/m4/printf.m4
+++ b/gl/m4/printf.m4
@@ -1,5 +1,5 @@
1# printf.m4 serial 33 1# printf.m4 serial 33
2dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/progtest.m4 b/gl/m4/progtest.m4
index e1d445d2..2d804ac9 100644
--- a/gl/m4/progtest.m4
+++ b/gl/m4/progtest.m4
@@ -1,5 +1,5 @@
1# progtest.m4 serial 6 (gettext-0.18) 1# progtest.m4 serial 6 (gettext-0.18)
2dnl Copyright (C) 1996-2003, 2005, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1996-2003, 2005, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/regex.m4 b/gl/m4/regex.m4
index aef53d29..95784e4b 100644
--- a/gl/m4/regex.m4
+++ b/gl/m4/regex.m4
@@ -1,7 +1,7 @@
1# serial 54 1# serial 56
2 2
3# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 3# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
4# 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 4# 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5# 5#
6# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
@@ -18,146 +18,154 @@ AC_DEFUN([gl_REGEX],
18 18
19 AC_ARG_WITH([included-regex], 19 AC_ARG_WITH([included-regex],
20 [AS_HELP_STRING([--without-included-regex], 20 [AS_HELP_STRING([--without-included-regex],
21 [don't compile regex; this is the default on systems 21 [don't compile regex; this is the default on systems
22 with recent-enough versions of the GNU C Library 22 with recent-enough versions of the GNU C Library
23 (use with caution on other systems).])]) 23 (use with caution on other systems).])])
24 24
25 case $with_included_regex in #( 25 case $with_included_regex in #(
26 yes|no) ac_use_included_regex=$with_included_regex 26 yes|no) ac_use_included_regex=$with_included_regex
27 ;; 27 ;;
28 '') 28 '')
29 # If the system regex support is good enough that it passes the 29 # If the system regex support is good enough that it passes the
30 # following run test, then default to *not* using the included regex.c. 30 # following run test, then default to *not* using the included regex.c.
31 # If cross compiling, assume the test would fail and use the included 31 # If cross compiling, assume the test would fail and use the included
32 # regex.c. 32 # regex.c.
33 AC_CACHE_CHECK([for working re_compile_pattern], 33 AC_CACHE_CHECK([for working re_compile_pattern],
34 [gl_cv_func_re_compile_pattern_working], 34 [gl_cv_func_re_compile_pattern_working],
35 [AC_RUN_IFELSE( 35 [AC_RUN_IFELSE(
36 [AC_LANG_PROGRAM( 36 [AC_LANG_PROGRAM(
37 [AC_INCLUDES_DEFAULT[ 37 [AC_INCLUDES_DEFAULT[
38 #if HAVE_LOCALE_H 38 #if HAVE_LOCALE_H
39 #include <locale.h> 39 #include <locale.h>
40 #endif 40 #endif
41 #include <limits.h> 41 #include <limits.h>
42 #include <regex.h> 42 #include <regex.h>
43 ]], 43 ]],
44 [[static struct re_pattern_buffer regex; 44 [[static struct re_pattern_buffer regex;
45 unsigned char folded_chars[UCHAR_MAX + 1]; 45 unsigned char folded_chars[UCHAR_MAX + 1];
46 int i; 46 int i;
47 const char *s; 47 const char *s;
48 struct re_registers regs; 48 struct re_registers regs;
49 49
50 #if HAVE_LOCALE_H 50 #if HAVE_LOCALE_H
51 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html 51 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
52 This test needs valgrind to catch the bug on Debian 52 This test needs valgrind to catch the bug on Debian
53 GNU/Linux 3.1 x86, but it might catch the bug better 53 GNU/Linux 3.1 x86, but it might catch the bug better
54 on other platforms and it shouldn't hurt to try the 54 on other platforms and it shouldn't hurt to try the
55 test here. */ 55 test here. */
56 if (setlocale (LC_ALL, "en_US.UTF-8")) 56 if (setlocale (LC_ALL, "en_US.UTF-8"))
57 { 57 {
58 static char const pat[] = "insert into"; 58 static char const pat[] = "insert into";
59 static char const data[] = 59 static char const data[] =
60 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; 60 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
61 re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE 61 re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE
62 | RE_ICASE); 62 | RE_ICASE);
63 memset (&regex, 0, sizeof regex); 63 memset (&regex, 0, sizeof regex);
64 s = re_compile_pattern (pat, sizeof pat - 1, &regex); 64 s = re_compile_pattern (pat, sizeof pat - 1, &regex);
65 if (s) 65 if (s)
66 return 1; 66 return 1;
67 if (re_search (&regex, data, sizeof data - 1, 67 if (re_search (&regex, data, sizeof data - 1,
68 0, sizeof data - 1, &regs) 68 0, sizeof data - 1, &regs)
69 != -1) 69 != -1)
70 return 1; 70 return 1;
71 if (! setlocale (LC_ALL, "C")) 71 if (! setlocale (LC_ALL, "C"))
72 return 1; 72 return 1;
73 } 73 }
74 #endif 74 #endif
75 75
76 /* This test is from glibc bug 3957, reported by Andrew Mackey. */ 76 /* This test is from glibc bug 3957, reported by Andrew Mackey. */
77 re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE); 77 re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
78 memset (&regex, 0, sizeof regex); 78 memset (&regex, 0, sizeof regex);
79 s = re_compile_pattern ("a[^x]b", 6, &regex); 79 s = re_compile_pattern ("a[^x]b", 6, &regex);
80 if (s) 80 if (s)
81 return 1; 81 return 1;
82 82
83 /* This should fail, but succeeds for glibc-2.5. */ 83 /* This should fail, but succeeds for glibc-2.5. */
84 if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1) 84 if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
85 return 1; 85 return 1;
86 86
87 /* This regular expression is from Spencer ere test number 75 87 /* This regular expression is from Spencer ere test number 75
88 in grep-2.3. */ 88 in grep-2.3. */
89 re_set_syntax (RE_SYNTAX_POSIX_EGREP); 89 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
90 memset (&regex, 0, sizeof regex); 90 memset (&regex, 0, sizeof regex);
91 for (i = 0; i <= UCHAR_MAX; i++) 91 for (i = 0; i <= UCHAR_MAX; i++)
92 folded_chars[i] = i; 92 folded_chars[i] = i;
93 regex.translate = folded_chars; 93 regex.translate = folded_chars;
94 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex); 94 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
95 /* This should fail with _Invalid character class name_ error. */ 95 /* This should fail with _Invalid character class name_ error. */
96 if (!s) 96 if (!s)
97 return 1; 97 return 1;
98 98
99 /* This should succeed, but does not for glibc-2.1.3. */ 99 /* Ensure that [b-a] is diagnosed as invalid, when
100 memset (&regex, 0, sizeof regex); 100 using RE_NO_EMPTY_RANGES. */
101 s = re_compile_pattern ("{1", 2, &regex); 101 re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES);
102 102 memset (&regex, 0, sizeof regex);
103 if (s) 103 s = re_compile_pattern ("a[b-a]", 6, &regex);
104 return 1; 104 if (s == 0)
105 105 return 1;
106 /* The following example is derived from a problem report 106
107 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ 107 /* This should succeed, but does not for glibc-2.1.3. */
108 memset (&regex, 0, sizeof regex); 108 memset (&regex, 0, sizeof regex);
109 s = re_compile_pattern ("[an\371]*n", 7, &regex); 109 s = re_compile_pattern ("{1", 2, &regex);
110 if (s) 110
111 return 1; 111 if (s)
112 112 return 1;
113 /* This should match, but does not for glibc-2.2.1. */ 113
114 if (re_match (&regex, "an", 2, 0, &regs) != 2) 114 /* The following example is derived from a problem report
115 return 1; 115 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
116 116 memset (&regex, 0, sizeof regex);
117 memset (&regex, 0, sizeof regex); 117 s = re_compile_pattern ("[an\371]*n", 7, &regex);
118 s = re_compile_pattern ("x", 1, &regex); 118 if (s)
119 if (s) 119 return 1;
120 return 1; 120
121 121 /* This should match, but does not for glibc-2.2.1. */
122 /* glibc-2.2.93 does not work with a negative RANGE argument. */ 122 if (re_match (&regex, "an", 2, 0, &regs) != 2)
123 if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1) 123 return 1;
124 return 1; 124
125 125 memset (&regex, 0, sizeof regex);
126 /* The version of regex.c in older versions of gnulib 126 s = re_compile_pattern ("x", 1, &regex);
127 ignored RE_ICASE. Detect that problem too. */ 127 if (s)
128 re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); 128 return 1;
129 memset (&regex, 0, sizeof regex); 129
130 s = re_compile_pattern ("x", 1, &regex); 130 /* glibc-2.2.93 does not work with a negative RANGE argument. */
131 if (s) 131 if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
132 return 1; 132 return 1;
133 133
134 if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0) 134 /* The version of regex.c in older versions of gnulib
135 return 1; 135 ignored RE_ICASE. Detect that problem too. */
136 136 re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
137 /* Catch a bug reported by Vin Shelton in 137 memset (&regex, 0, sizeof regex);
138 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html 138 s = re_compile_pattern ("x", 1, &regex);
139 */ 139 if (s)
140 re_set_syntax (RE_SYNTAX_POSIX_BASIC 140 return 1;
141 & ~RE_CONTEXT_INVALID_DUP 141
142 & ~RE_NO_EMPTY_RANGES); 142 if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
143 memset (&regex, 0, sizeof regex); 143 return 1;
144 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex); 144
145 if (s) 145 /* Catch a bug reported by Vin Shelton in
146 return 1; 146 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
147 147 */
148 /* REG_STARTEND was added to glibc on 2004-01-15. 148 re_set_syntax (RE_SYNTAX_POSIX_BASIC
149 Reject older versions. */ 149 & ~RE_CONTEXT_INVALID_DUP
150 if (! REG_STARTEND) 150 & ~RE_NO_EMPTY_RANGES);
151 return 1; 151 memset (&regex, 0, sizeof regex);
152 152 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
153 /* Reject hosts whose regoff_t values are too narrow. 153 if (s)
154 These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t 154 return 1;
155 and 32-bit int. */ 155
156 if (sizeof (regoff_t) < sizeof (ptrdiff_t) 156 /* REG_STARTEND was added to glibc on 2004-01-15.
157 || sizeof (regoff_t) < sizeof (ssize_t)) 157 Reject older versions. */
158 return 1; 158 if (! REG_STARTEND)
159 159 return 1;
160 return 0;]])], 160
161 /* Reject hosts whose regoff_t values are too narrow.
162 These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
163 and 32-bit int. */
164 if (sizeof (regoff_t) < sizeof (ptrdiff_t)
165 || sizeof (regoff_t) < sizeof (ssize_t))
166 return 1;
167
168 return 0;]])],
161 [gl_cv_func_re_compile_pattern_working=yes], 169 [gl_cv_func_re_compile_pattern_working=yes],
162 [gl_cv_func_re_compile_pattern_working=no], 170 [gl_cv_func_re_compile_pattern_working=no],
163 dnl When crosscompiling, assume it is not working. 171 dnl When crosscompiling, assume it is not working.
@@ -213,6 +221,7 @@ AC_DEFUN([gl_REGEX],
213AC_DEFUN([gl_PREREQ_REGEX], 221AC_DEFUN([gl_PREREQ_REGEX],
214[ 222[
215 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 223 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
224 AC_REQUIRE([AC_C_INLINE])
216 AC_REQUIRE([AC_C_RESTRICT]) 225 AC_REQUIRE([AC_C_RESTRICT])
217 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 226 AC_REQUIRE([AC_TYPE_MBSTATE_T])
218 AC_CHECK_HEADERS([libintl.h]) 227 AC_CHECK_HEADERS([libintl.h])
diff --git a/gl/m4/safe-read.m4 b/gl/m4/safe-read.m4
index 7a89d0a6..d087bd30 100644
--- a/gl/m4/safe-read.m4
+++ b/gl/m4/safe-read.m4
@@ -1,5 +1,6 @@
1# safe-read.m4 serial 5 1# safe-read.m4 serial 5
2dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2006, 2009-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/safe-write.m4 b/gl/m4/safe-write.m4
index db119ffa..2ff11d27 100644
--- a/gl/m4/safe-write.m4
+++ b/gl/m4/safe-write.m4
@@ -1,5 +1,5 @@
1# safe-write.m4 serial 3 1# safe-write.m4 serial 3
2dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/servent.m4 b/gl/m4/servent.m4
index 242f9e36..2ed961a4 100644
--- a/gl/m4/servent.m4
+++ b/gl/m4/servent.m4
@@ -1,5 +1,5 @@
1# servent.m4 serial 1 1# servent.m4 serial 1
2dnl Copyright (C) 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/size_max.m4 b/gl/m4/size_max.m4
index e0e7b3ff..ce992db1 100644
--- a/gl/m4/size_max.m4
+++ b/gl/m4/size_max.m4
@@ -1,5 +1,5 @@
1# size_max.m4 serial 7 1# size_max.m4 serial 9
2dnl Copyright (C) 2003, 2005-2006, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -10,8 +10,7 @@ AC_DEFUN([gl_SIZE_MAX],
10[ 10[
11 AC_CHECK_HEADERS([stdint.h]) 11 AC_CHECK_HEADERS([stdint.h])
12 dnl First test whether the system already has SIZE_MAX. 12 dnl First test whether the system already has SIZE_MAX.
13 AC_MSG_CHECKING([for SIZE_MAX]) 13 AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [
14 AC_CACHE_VAL([gl_cv_size_max], [
15 gl_cv_size_max= 14 gl_cv_size_max=
16 AC_EGREP_CPP([Found it], [ 15 AC_EGREP_CPP([Found it], [
17#include <limits.h> 16#include <limits.h>
@@ -54,11 +53,19 @@ Found it
54 fi 53 fi
55 fi 54 fi
56 ]) 55 ])
57 AC_MSG_RESULT([$gl_cv_size_max])
58 if test "$gl_cv_size_max" != yes; then 56 if test "$gl_cv_size_max" != yes; then
59 AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], 57 AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max],
60 [Define as the maximum value of type 'size_t', if the system doesn't define it.]) 58 [Define as the maximum value of type 'size_t', if the system doesn't define it.])
61 fi 59 fi
60 dnl Don't redefine SIZE_MAX in config.h if config.h is re-included after
61 dnl <stdint.h>. Remember that the #undef in AH_VERBATIM gets replaced with
62 dnl #define by AC_DEFINE_UNQUOTED.
63 AH_VERBATIM([SIZE_MAX],
64[/* Define as the maximum value of type 'size_t', if the system doesn't define
65 it. */
66#ifndef SIZE_MAX
67# undef SIZE_MAX
68#endif])
62]) 69])
63 70
64dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. 71dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
diff --git a/gl/m4/snprintf.m4 b/gl/m4/snprintf.m4
index 6021786e..522b107b 100644
--- a/gl/m4/snprintf.m4
+++ b/gl/m4/snprintf.m4
@@ -1,5 +1,5 @@
1# snprintf.m4 serial 5 1# snprintf.m4 serial 5
2dnl Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/sockets.m4 b/gl/m4/sockets.m4
new file mode 100644
index 00000000..aefb9360
--- /dev/null
+++ b/gl/m4/sockets.m4
@@ -0,0 +1,90 @@
1# sockets.m4 serial 6
2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_SOCKETS],
8[
9 AC_REQUIRE([AC_C_INLINE])
10
11 gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H
12 LIBSOCKET=
13 if test $HAVE_WINSOCK2_H = 1; then
14 dnl Native Windows API (not Cygwin).
15 AC_CACHE_CHECK([if we need to call WSAStartup in winsock2.h and -lws2_32],
16 [gl_cv_func_wsastartup], [
17 gl_save_LIBS="$LIBS"
18 LIBS="$LIBS -lws2_32"
19 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
20#ifdef HAVE_WINSOCK2_H
21# include <winsock2.h>
22#endif]], [[
23 WORD wVersionRequested = MAKEWORD(1, 1);
24 WSADATA wsaData;
25 int err = WSAStartup(wVersionRequested, &wsaData);
26 WSACleanup ();]])],
27 gl_cv_func_wsastartup=yes, gl_cv_func_wsastartup=no)
28 LIBS="$gl_save_LIBS"
29 ])
30 if test "$gl_cv_func_wsastartup" = "yes"; then
31 AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
32 LIBSOCKET='-lws2_32'
33 fi
34 else
35 dnl Unix API.
36 dnl Solaris has most socket functions in libsocket.
37 dnl Haiku has most socket functions in libnetwork.
38 dnl BeOS has most socket functions in libnet.
39 AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
40 gl_cv_lib_socket=
41 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
42#ifdef __cplusplus
43"C"
44#endif
45char setsockopt();]], [[setsockopt();]])],
46 [],
47 [gl_save_LIBS="$LIBS"
48 LIBS="$gl_save_LIBS -lsocket"
49 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
50#ifdef __cplusplus
51"C"
52#endif
53char setsockopt();]], [[setsockopt();]])],
54 [gl_cv_lib_socket="-lsocket"])
55 if test -z "$gl_cv_lib_socket"; then
56 LIBS="$gl_save_LIBS -lnetwork"
57 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
58#ifdef __cplusplus
59"C"
60#endif
61char setsockopt();]], [[setsockopt();]])],
62 [gl_cv_lib_socket="-lnetwork"])
63 if test -z "$gl_cv_lib_socket"; then
64 LIBS="$gl_save_LIBS -lnet"
65 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
66#ifdef __cplusplus
67"C"
68#endif
69char setsockopt();]], [[setsockopt();]])],
70 [gl_cv_lib_socket="-lnet"])
71 fi
72 fi
73 LIBS="$gl_save_LIBS"
74 ])
75 if test -z "$gl_cv_lib_socket"; then
76 gl_cv_lib_socket="none needed"
77 fi
78 ])
79 if test "$gl_cv_lib_socket" != "none needed"; then
80 LIBSOCKET="$gl_cv_lib_socket"
81 fi
82 fi
83 AC_SUBST([LIBSOCKET])
84 gl_PREREQ_SOCKETS
85])
86
87# Prerequisites of lib/sockets.c.
88AC_DEFUN([gl_PREREQ_SOCKETS], [
89 :
90])
diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4
index b755757b..2933d4b8 100644
--- a/gl/m4/socklen.m4
+++ b/gl/m4/socklen.m4
@@ -1,5 +1,5 @@
1# socklen.m4 serial 6 1# socklen.m4 serial 7
2dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -20,30 +20,30 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T],
20 AC_CHECK_TYPE([socklen_t], , 20 AC_CHECK_TYPE([socklen_t], ,
21 [AC_MSG_CHECKING([for socklen_t equivalent]) 21 [AC_MSG_CHECKING([for socklen_t equivalent])
22 AC_CACHE_VAL([gl_cv_socklen_t_equiv], 22 AC_CACHE_VAL([gl_cv_socklen_t_equiv],
23 [# Systems have either "struct sockaddr *" or 23 [# Systems have either "struct sockaddr *" or
24 # "void *" as the second argument to getpeername 24 # "void *" as the second argument to getpeername
25 gl_cv_socklen_t_equiv= 25 gl_cv_socklen_t_equiv=
26 for arg2 in "struct sockaddr" void; do 26 for arg2 in "struct sockaddr" void; do
27 for t in int size_t "unsigned int" "long int" "unsigned long int"; do 27 for t in int size_t "unsigned int" "long int" "unsigned long int"; do
28 AC_TRY_COMPILE( 28 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
29 [#include <sys/types.h> 29 [[#include <sys/types.h>
30 #include <sys/socket.h> 30 #include <sys/socket.h>
31 31
32 int getpeername (int, $arg2 *, $t *);], 32 int getpeername (int, $arg2 *, $t *);]],
33 [$t len; 33 [[$t len;
34 getpeername (0, 0, &len);], 34 getpeername (0, 0, &len);]])],
35 [gl_cv_socklen_t_equiv="$t"]) 35 [gl_cv_socklen_t_equiv="$t"])
36 test "$gl_cv_socklen_t_equiv" != "" && break 36 test "$gl_cv_socklen_t_equiv" != "" && break
37 done 37 done
38 test "$gl_cv_socklen_t_equiv" != "" && break 38 test "$gl_cv_socklen_t_equiv" != "" && break
39 done 39 done
40 ]) 40 ])
41 if test "$gl_cv_socklen_t_equiv" = ""; then 41 if test "$gl_cv_socklen_t_equiv" = ""; then
42 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 42 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
43 fi 43 fi
44 AC_MSG_RESULT([$gl_cv_socklen_t_equiv]) 44 AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
45 AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], 45 AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
46 [type to use in place of socklen_t if not defined])], 46 [type to use in place of socklen_t if not defined])],
47 [#include <sys/types.h> 47 [#include <sys/types.h>
48 #if HAVE_SYS_SOCKET_H 48 #if HAVE_SYS_SOCKET_H
49 # include <sys/socket.h> 49 # include <sys/socket.h>
diff --git a/gl/m4/sockpfaf.m4 b/gl/m4/sockpfaf.m4
index 99ea06f9..8a0c2360 100644
--- a/gl/m4/sockpfaf.m4
+++ b/gl/m4/sockpfaf.m4
@@ -1,5 +1,5 @@
1# sockpfaf.m4 serial 6 1# sockpfaf.m4 serial 7
2dnl Copyright (C) 2004, 2006, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -18,7 +18,7 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
18 18
19 AC_MSG_CHECKING([for IPv4 sockets]) 19 AC_MSG_CHECKING([for IPv4 sockets])
20 AC_CACHE_VAL([gl_cv_socket_ipv4], 20 AC_CACHE_VAL([gl_cv_socket_ipv4],
21 [AC_TRY_COMPILE([#include <sys/types.h> 21 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
22#ifdef HAVE_SYS_SOCKET_H 22#ifdef HAVE_SYS_SOCKET_H
23#include <sys/socket.h> 23#include <sys/socket.h>
24#endif 24#endif
@@ -27,9 +27,9 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
27#endif 27#endif
28#ifdef HAVE_WINSOCK2_H 28#ifdef HAVE_WINSOCK2_H
29#include <winsock2.h> 29#include <winsock2.h>
30#endif], 30#endif]],
31[int x = AF_INET; struct in_addr y; struct sockaddr_in z; 31[[int x = AF_INET; struct in_addr y; struct sockaddr_in z;
32 if (&x && &y && &z) return 0;], 32 if (&x && &y && &z) return 0;]])],
33 gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)]) 33 gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)])
34 AC_MSG_RESULT([$gl_cv_socket_ipv4]) 34 AC_MSG_RESULT([$gl_cv_socket_ipv4])
35 if test $gl_cv_socket_ipv4 = yes; then 35 if test $gl_cv_socket_ipv4 = yes; then
@@ -38,7 +38,7 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
38 38
39 AC_MSG_CHECKING([for IPv6 sockets]) 39 AC_MSG_CHECKING([for IPv6 sockets])
40 AC_CACHE_VAL([gl_cv_socket_ipv6], 40 AC_CACHE_VAL([gl_cv_socket_ipv6],
41 [AC_TRY_COMPILE([#include <sys/types.h> 41 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
42#ifdef HAVE_SYS_SOCKET_H 42#ifdef HAVE_SYS_SOCKET_H
43#include <sys/socket.h> 43#include <sys/socket.h>
44#endif 44#endif
@@ -47,9 +47,9 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
47#endif 47#endif
48#ifdef HAVE_WINSOCK2_H 48#ifdef HAVE_WINSOCK2_H
49#include <winsock2.h> 49#include <winsock2.h>
50#endif], 50#endif]],
51[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z; 51[[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;
52 if (&x && &y && &z) return 0;], 52 if (&x && &y && &z) return 0;]])],
53 gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)]) 53 gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)])
54 AC_MSG_RESULT([$gl_cv_socket_ipv6]) 54 AC_MSG_RESULT([$gl_cv_socket_ipv6])
55 if test $gl_cv_socket_ipv6 = yes; then 55 if test $gl_cv_socket_ipv6 = yes; then
diff --git a/gl/m4/ssize_t.m4 b/gl/m4/ssize_t.m4
index 4eaef93c..e0ccee3a 100644
--- a/gl/m4/ssize_t.m4
+++ b/gl/m4/ssize_t.m4
@@ -1,5 +1,5 @@
1# ssize_t.m4 serial 4 (gettext-0.15) 1# ssize_t.m4 serial 4 (gettext-0.15)
2dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2003, 2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/stat.m4 b/gl/m4/stat.m4
new file mode 100644
index 00000000..acd32d86
--- /dev/null
+++ b/gl/m4/stat.m4
@@ -0,0 +1,63 @@
1# serial 4
2
3# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4#
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9AC_DEFUN([gl_FUNC_STAT],
10[
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 AC_REQUIRE([gl_AC_DOS])
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 AC_CHECK_FUNCS_ONCE([lstat])
15 dnl mingw is the only known platform where stat(".") and stat("./") differ
16 AC_CACHE_CHECK([whether stat handles trailing slashes on directories],
17 [gl_cv_func_stat_dir_slash],
18 [AC_RUN_IFELSE(
19 [AC_LANG_PROGRAM(
20 [[#include <sys/stat.h>
21]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])],
22 [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no],
23 [case $host_os in
24 mingw*) gl_cv_func_stat_dir_slash="guessing no";;
25 *) gl_cv_func_stat_dir_slash="guessing yes";;
26 esac])])
27 dnl Solaris 9 mistakenly succeeds on stat("file/")
28 dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/")
29 AC_CACHE_CHECK([whether stat handles trailing slashes on files],
30 [gl_cv_func_stat_file_slash],
31 [touch conftest.tmp
32 # Assume that if we have lstat, we can also check symlinks.
33 if test $ac_cv_func_lstat = yes; then
34 ln -s conftest.tmp conftest.lnk
35 fi
36 AC_RUN_IFELSE(
37 [AC_LANG_PROGRAM(
38 [[#include <sys/stat.h>
39]], [[struct stat st;
40 if (!stat ("conftest.tmp/", &st)) return 1;
41#if HAVE_LSTAT
42 if (!stat ("conftest.lnk/", &st)) return 2;
43#endif
44 ]])],
45 [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
46 [gl_cv_func_stat_file_slash="guessing no"])
47 rm -f conftest.tmp conftest.lnk])
48 case $gl_cv_func_stat_dir_slash in
49 *no) REPLACE_STAT=1
50 AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs
51 help when passed a directory name with a trailing slash]);;
52 esac
53 case $gl_cv_func_stat_file_slash in
54 *no) REPLACE_STAT=1
55 AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
56 help when passed a file name with a trailing slash]);;
57 esac
58 if test $REPLACE_STAT = 1; then
59 AC_LIBOBJ([stat])
60 dnl Prerequisites of lib/stat.c.
61 AC_REQUIRE([AC_C_INLINE])
62 fi
63])
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4
index 57c804a8..3d672d74 100644
--- a/gl/m4/stdbool.m4
+++ b/gl/m4/stdbool.m4
@@ -1,6 +1,6 @@
1# Check for stdbool.h that conforms to C99. 1# Check for stdbool.h that conforms to C99.
2 2
3dnl Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc. 3dnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -38,77 +38,77 @@ AC_DEFUN([AC_HEADER_STDBOOL],
38 [AC_CACHE_CHECK([for stdbool.h that conforms to C99], 38 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
39 [ac_cv_header_stdbool_h], 39 [ac_cv_header_stdbool_h],
40 [AC_TRY_COMPILE( 40 [AC_TRY_COMPILE(
41 [ 41 [
42 #include <stdbool.h> 42 #include <stdbool.h>
43 #ifndef bool 43 #ifndef bool
44 "error: bool is not defined" 44 "error: bool is not defined"
45 #endif 45 #endif
46 #ifndef false 46 #ifndef false
47 "error: false is not defined" 47 "error: false is not defined"
48 #endif 48 #endif
49 #if false 49 #if false
50 "error: false is not 0" 50 "error: false is not 0"
51 #endif 51 #endif
52 #ifndef true 52 #ifndef true
53 "error: true is not defined" 53 "error: true is not defined"
54 #endif 54 #endif
55 #if true != 1 55 #if true != 1
56 "error: true is not 1" 56 "error: true is not 1"
57 #endif 57 #endif
58 #ifndef __bool_true_false_are_defined 58 #ifndef __bool_true_false_are_defined
59 "error: __bool_true_false_are_defined is not defined" 59 "error: __bool_true_false_are_defined is not defined"
60 #endif 60 #endif
61 61
62 struct s { _Bool s: 1; _Bool t; } s; 62 struct s { _Bool s: 1; _Bool t; } s;
63 63
64 char a[true == 1 ? 1 : -1]; 64 char a[true == 1 ? 1 : -1];
65 char b[false == 0 ? 1 : -1]; 65 char b[false == 0 ? 1 : -1];
66 char c[__bool_true_false_are_defined == 1 ? 1 : -1]; 66 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
67 char d[(bool) 0.5 == true ? 1 : -1]; 67 char d[(bool) 0.5 == true ? 1 : -1];
68 bool e = &s; 68 bool e = &s;
69 char f[(_Bool) 0.0 == false ? 1 : -1]; 69 char f[(_Bool) 0.0 == false ? 1 : -1];
70 char g[true]; 70 char g[true];
71 char h[sizeof (_Bool)]; 71 char h[sizeof (_Bool)];
72 char i[sizeof s.t]; 72 char i[sizeof s.t];
73 enum { j = false, k = true, l = false * true, m = true * 256 }; 73 enum { j = false, k = true, l = false * true, m = true * 256 };
74 _Bool n[m]; 74 _Bool n[m];
75 char o[sizeof n == m * sizeof n[0] ? 1 : -1]; 75 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
76 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; 76 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
77 #if defined __xlc__ || defined __GNUC__ 77 #if defined __xlc__ || defined __GNUC__
78 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 78 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
79 reported by James Lemley on 2005-10-05; see 79 reported by James Lemley on 2005-10-05; see
80 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html 80 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
81 This test is not quite right, since xlc is allowed to 81 This test is not quite right, since xlc is allowed to
82 reject this program, as the initializer for xlcbug is 82 reject this program, as the initializer for xlcbug is
83 not one of the forms that C requires support for. 83 not one of the forms that C requires support for.
84 However, doing the test right would require a run-time 84 However, doing the test right would require a run-time
85 test, and that would make cross-compilation harder. 85 test, and that would make cross-compilation harder.
86 Let us hope that IBM fixes the xlc bug, and also adds 86 Let us hope that IBM fixes the xlc bug, and also adds
87 support for this kind of constant expression. In the 87 support for this kind of constant expression. In the
88 meantime, this test will reject xlc, which is OK, since 88 meantime, this test will reject xlc, which is OK, since
89 our stdbool.h substitute should suffice. We also test 89 our stdbool.h substitute should suffice. We also test
90 this with GCC, where it should work, to detect more 90 this with GCC, where it should work, to detect more
91 quickly whether someone messes up the test in the 91 quickly whether someone messes up the test in the
92 future. */ 92 future. */
93 char digs[] = "0123456789"; 93 char digs[] = "0123456789";
94 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); 94 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
95 #endif 95 #endif
96 /* Catch a bug in an HP-UX C compiler. See 96 /* Catch a bug in an HP-UX C compiler. See
97 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html 97 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
98 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html 98 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
99 */ 99 */
100 _Bool q = true; 100 _Bool q = true;
101 _Bool *pq = &q; 101 _Bool *pq = &q;
102 ], 102 ],
103 [ 103 [
104 *pq |= q; 104 *pq |= q;
105 *pq |= ! q; 105 *pq |= ! q;
106 /* Refer to every declared value, to avoid compiler optimizations. */ 106 /* Refer to every declared value, to avoid compiler optimizations. */
107 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l 107 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
108 + !m + !n + !o + !p + !q + !pq); 108 + !m + !n + !o + !p + !q + !pq);
109 ], 109 ],
110 [ac_cv_header_stdbool_h=yes], 110 [ac_cv_header_stdbool_h=yes],
111 [ac_cv_header_stdbool_h=no])]) 111 [ac_cv_header_stdbool_h=no])])
112 AC_CHECK_TYPES([_Bool]) 112 AC_CHECK_TYPES([_Bool])
113 if test $ac_cv_header_stdbool_h = yes; then 113 if test $ac_cv_header_stdbool_h = yes; then
114 AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.]) 114 AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.])
diff --git a/gl/m4/stddef_h.m4 b/gl/m4/stddef_h.m4
new file mode 100644
index 00000000..c3ae5694
--- /dev/null
+++ b/gl/m4/stddef_h.m4
@@ -0,0 +1,45 @@
1dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues.
2# stddef_h.m4 serial 2
3dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_STDDEF_H],
9[
10 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
11 AC_REQUIRE([gt_TYPE_WCHAR_T])
12 if test $gt_cv_c_wchar_t = no; then
13 HAVE_WCHAR_T=0
14 STDDEF_H=stddef.h
15 fi
16 AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
17 [gl_cv_decl_null_works],
18 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
19 int test[2 * (sizeof NULL == sizeof (void *)) -1];
20]])],
21 [gl_cv_decl_null_works=yes],
22 [gl_cv_decl_null_works=no])])
23 if test $gl_cv_decl_null_works = no; then
24 REPLACE_NULL=1
25 STDDEF_H=stddef.h
26 fi
27 if test -n "$STDDEF_H"; then
28 gl_CHECK_NEXT_HEADERS([stddef.h])
29 fi
30])
31
32AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
33[
34 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
35 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
36 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
37])
38
39AC_DEFUN([gl_STDDEF_H_DEFAULTS],
40[
41 dnl Assume proper GNU behavior unless another module says otherwise.
42 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
43 HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T])
44 STDDEF_H=''; AC_SUBST([STDDEF_H])
45])
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4
index a2e8bdd6..1cc57e6e 100644
--- a/gl/m4/stdint.m4
+++ b/gl/m4/stdint.m4
@@ -1,5 +1,5 @@
1# stdint.m4 serial 34 1# stdint.m4 serial 34
2dnl Copyright (C) 2001-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -396,12 +396,12 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX],
396 for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do 396 for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do
397 case $glsuf in 397 case $glsuf in
398 '') gltype1='int';; 398 '') gltype1='int';;
399 l) gltype1='long int';; 399 l) gltype1='long int';;
400 ll) gltype1='long long int';; 400 ll) gltype1='long long int';;
401 i64) gltype1='__int64';; 401 i64) gltype1='__int64';;
402 u) gltype1='unsigned int';; 402 u) gltype1='unsigned int';;
403 ul) gltype1='unsigned long int';; 403 ul) gltype1='unsigned long int';;
404 ull) gltype1='unsigned long long int';; 404 ull) gltype1='unsigned long long int';;
405 ui64)gltype1='unsigned __int64';; 405 ui64)gltype1='unsigned __int64';;
406 esac 406 esac
407 AC_COMPILE_IFELSE( 407 AC_COMPILE_IFELSE(
diff --git a/gl/m4/stdint_h.m4 b/gl/m4/stdint_h.m4
index 82f0c244..b8e3c6cc 100644
--- a/gl/m4/stdint_h.m4
+++ b/gl/m4/stdint_h.m4
@@ -1,5 +1,5 @@
1# stdint_h.m4 serial 8 1# stdint_h.m4 serial 8
2dnl Copyright (C) 1997-2004, 2006, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2006, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
index 846b65d3..1d1d95e5 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,5 +1,5 @@
1# stdio_h.m4 serial 15 1# stdio_h.m4 serial 30
2dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_STDIO_H], 7AC_DEFUN([gl_STDIO_H],
8[ 8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([AC_C_INLINE])
10 gl_CHECK_NEXT_HEADERS([stdio.h]) 11 gl_CHECK_NEXT_HEADERS([stdio.h])
11 dnl No need to create extra modules for these functions. Everyone who uses 12 dnl No need to create extra modules for these functions. Everyone who uses
12 dnl <stdio.h> likely needs them. 13 dnl <stdio.h> likely needs them.
@@ -30,86 +31,110 @@ AC_DEFUN([gl_STDIO_H],
30 AC_LIBOBJ([stdio-write]) 31 AC_LIBOBJ([stdio-write])
31 fi 32 fi
32 ]) 33 ])
34
35 dnl Check for declarations of anything we want to poison if the
36 dnl corresponding gnulib module is not in use, and which is not
37 dnl guaranteed by C89.
38 gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
39 ]], [dprintf fpurge fseeko ftello getdelim getline popen renameat
40 snprintf tmpfile vdprintf vsnprintf])
33]) 41])
34 42
35AC_DEFUN([gl_STDIO_MODULE_INDICATOR], 43AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
36[ 44[
37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 45 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
38 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 46 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
39 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 47 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
48 dnl Define it also as a C macro, for the benefit of the unit tests.
49 gl_MODULE_INDICATOR_FOR_TESTS([$1])
40]) 50])
41 51
42AC_DEFUN([gl_STDIO_H_DEFAULTS], 52AC_DEFUN([gl_STDIO_H_DEFAULTS],
43[ 53[
44 GNULIB_FPRINTF=0; AC_SUBST([GNULIB_FPRINTF])
45 GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX])
46 GNULIB_PRINTF=0; AC_SUBST([GNULIB_PRINTF])
47 GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX])
48 GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
49 GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX])
50 GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF])
51 GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
52 GNULIB_VPRINTF=0; AC_SUBST([GNULIB_VPRINTF])
53 GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX])
54 GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
55 GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
56 GNULIB_DPRINTF=0; AC_SUBST([GNULIB_DPRINTF]) 54 GNULIB_DPRINTF=0; AC_SUBST([GNULIB_DPRINTF])
57 GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF]) 55 GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE])
58 GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF]) 56 GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
59 GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF])
60 GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
61 GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN]) 57 GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN])
58 GNULIB_FPRINTF=0; AC_SUBST([GNULIB_FPRINTF])
59 GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX])
60 GNULIB_FPURGE=0; AC_SUBST([GNULIB_FPURGE])
61 GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC])
62 GNULIB_FPUTS=0; AC_SUBST([GNULIB_FPUTS])
62 GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN]) 63 GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN])
63 GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK]) 64 GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK])
64 GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO]) 65 GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO])
65 GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL]) 66 GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL])
66 GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO]) 67 GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
67 GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
68 GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE])
69 GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC])
70 GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC])
71 GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR])
72 GNULIB_FPUTS=0; AC_SUBST([GNULIB_FPUTS])
73 GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS])
74 GNULIB_FWRITE=0; AC_SUBST([GNULIB_FWRITE]) 68 GNULIB_FWRITE=0; AC_SUBST([GNULIB_FWRITE])
75 GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM]) 69 GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM])
76 GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE]) 70 GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE])
71 GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF])
72 GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
77 GNULIB_PERROR=0; AC_SUBST([GNULIB_PERROR]) 73 GNULIB_PERROR=0; AC_SUBST([GNULIB_PERROR])
74 GNULIB_POPEN=0; AC_SUBST([GNULIB_POPEN])
75 GNULIB_PRINTF=0; AC_SUBST([GNULIB_PRINTF])
76 GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX])
77 GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC])
78 GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR])
79 GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS])
80 GNULIB_REMOVE=0; AC_SUBST([GNULIB_REMOVE])
81 GNULIB_RENAME=0; AC_SUBST([GNULIB_RENAME])
82 GNULIB_RENAMEAT=0; AC_SUBST([GNULIB_RENAMEAT])
83 GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
84 GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX])
78 GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE]) 85 GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
86 GNULIB_TMPFILE=0; AC_SUBST([GNULIB_TMPFILE])
87 GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF])
88 GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF])
89 GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF])
90 GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
91 GNULIB_VPRINTF=0; AC_SUBST([GNULIB_VPRINTF])
92 GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX])
93 GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
94 GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
79 dnl Assume proper GNU behavior unless another module says otherwise. 95 dnl Assume proper GNU behavior unless another module says otherwise.
80 REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS]) 96 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
81 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) 97 HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
82 REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF]) 98 HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
83 REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF]) 99 HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
84 REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
85 REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
86 HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF]) 100 HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF])
87 REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
88 HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF]) 101 HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
89 REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
90 REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])
91 HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF]) 102 HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF])
92 REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF]) 103 HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
93 HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF]) 104 HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
94 REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF]) 105 HAVE_RENAMEAT=1; AC_SUBST([HAVE_RENAMEAT])
95 HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF]) 106 HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
96 REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF]) 107 HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF])
97 HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF]) 108 REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF])
98 REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF]) 109 REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE])
110 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
99 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN]) 111 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
112 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
113 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
100 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN]) 114 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
101 HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
102 REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
103 REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK]) 115 REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
104 HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO]) 116 REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
105 REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
106 REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL]) 117 REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
107 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) 118 REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
108 REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE]) 119 REPLACE_GETDELIM=0; AC_SUBST([REPLACE_GETDELIM])
109 HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
110 HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
111 REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE]) 120 REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
121 REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF])
112 REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR]) 122 REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR])
123 REPLACE_POPEN=0; AC_SUBST([REPLACE_POPEN])
124 REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF])
125 REPLACE_REMOVE=0; AC_SUBST([REPLACE_REMOVE])
126 REPLACE_RENAME=0; AC_SUBST([REPLACE_RENAME])
127 REPLACE_RENAMEAT=0; AC_SUBST([REPLACE_RENAMEAT])
128 REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
129 REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
130 REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
131 REPLACE_TMPFILE=0; AC_SUBST([REPLACE_TMPFILE])
132 REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
133 REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF])
134 REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF])
135 REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
136 REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
137 REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])
113]) 138])
114 139
115dnl Code shared by fseeko and ftello. Determine if large files are supported, 140dnl Code shared by fseeko and ftello. Determine if large files are supported,
@@ -128,6 +153,6 @@ AC_DEFUN([gl_STDIN_LARGE_OFFSET],
128 choke me 153 choke me
129# endif 154# endif
130#endif]])], 155#endif]])],
131 [gl_cv_var_stdin_large_offset=yes], 156 [gl_cv_var_stdin_large_offset=yes],
132 [gl_cv_var_stdin_large_offset=no])]) 157 [gl_cv_var_stdin_large_offset=no])])
133]) 158])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index b295f16b..dd84796d 100644
--- a/gl/m4/stdlib_h.m4
+++ b/gl/m4/stdlib_h.m4
@@ -1,5 +1,5 @@
1# stdlib_h.m4 serial 15 1# stdlib_h.m4 serial 28
2dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -22,41 +22,75 @@ AC_DEFUN([gl_STDLIB_H],
22 # include <random.h> 22 # include <random.h>
23 #endif 23 #endif
24 ]]) 24 ]])
25
26 dnl Check for declarations of anything we want to poison if the
27 dnl corresponding gnulib module is not in use, and which is not
28 dnl guaranteed by C89.
29 gl_WARN_ON_USE_PREPARE([[#include <stdlib.h>
30#if HAVE_SYS_LOADAVG_H
31# include <sys/loadavg.h>
32#endif
33#if HAVE_RANDOM_H
34# include <random.h>
35#endif
36 ]], [atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp
37 mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
38 setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt
39 unsetenv])
25]) 40])
26 41
27AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], 42AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
28[ 43[
29 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 44 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
30 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 45 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
31 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 46 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
47 dnl Define it also as a C macro, for the benefit of the unit tests.
48 gl_MODULE_INDICATOR_FOR_TESTS([$1])
32]) 49])
33 50
34AC_DEFUN([gl_STDLIB_H_DEFAULTS], 51AC_DEFUN([gl_STDLIB_H_DEFAULTS],
35[ 52[
36 GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX])
37 GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
38 GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
39 GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL]) 53 GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL])
54 GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
55 GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
40 GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG]) 56 GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG])
41 GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) 57 GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT])
58 GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT])
59 GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX])
42 GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) 60 GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
61 GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP])
62 GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS])
43 GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP]) 63 GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
64 GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS])
65 GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME])
44 GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV]) 66 GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
45 GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R]) 67 GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R])
68 GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
69 GNULIB_REALPATH=0; AC_SUBST([GNULIB_REALPATH])
46 GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH]) 70 GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH])
47 GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV]) 71 GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
48 GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD]) 72 GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD])
49 GNULIB_STRTOLL=0; AC_SUBST([GNULIB_STRTOLL]) 73 GNULIB_STRTOLL=0; AC_SUBST([GNULIB_STRTOLL])
50 GNULIB_STRTOULL=0; AC_SUBST([GNULIB_STRTOULL]) 74 GNULIB_STRTOULL=0; AC_SUBST([GNULIB_STRTOULL])
75 GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
51 GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV]) 76 GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
52 dnl Assume proper GNU behavior unless another module says otherwise. 77 dnl Assume proper GNU behavior unless another module says otherwise.
53 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) 78 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
54 HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX]) 79 HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX])
80 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
81 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
55 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) 82 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
83 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT])
56 HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX]) 84 HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
57 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) 85 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
58 HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX]) 86 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
87 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
88 HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP])
89 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
90 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
59 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) 91 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
92 HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
93 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
60 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH]) 94 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
61 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) 95 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
62 HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD]) 96 HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD])
@@ -64,10 +98,13 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
64 HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL]) 98 HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL])
65 HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA]) 99 HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA])
66 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) 100 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
101 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
67 HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV]) 102 HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV])
68 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) 103 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
69 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) 104 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
70 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) 105 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
106 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
107 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
71 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD]) 108 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
72 VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV]) 109 REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV])
73]) 110])
diff --git a/gl/m4/strdup.m4 b/gl/m4/strdup.m4
index d7daac2b..ce40c215 100644
--- a/gl/m4/strdup.m4
+++ b/gl/m4/strdup.m4
@@ -1,6 +1,6 @@
1# strdup.m4 serial 11 1# strdup.m4 serial 12
2 2
3dnl Copyright (C) 2002-2009 Free Software Foundation, Inc. 3dnl Copyright (C) 2002-2010 Free Software Foundation, Inc.
4 4
5dnl This file is free software; the Free Software Foundation 5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it, 6dnl gives unlimited permission to copy and/or distribute it,
@@ -9,29 +9,36 @@ dnl with or without modifications, as long as this notice is preserved.
9AC_DEFUN([gl_FUNC_STRDUP], 9AC_DEFUN([gl_FUNC_STRDUP],
10[ 10[
11 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 11 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
12 AC_REPLACE_FUNCS([strdup]) 12 AC_CHECK_FUNCS_ONCE([strdup])
13 if test $ac_cv_func_strdup != yes; then
14 AC_LIBOBJ([strdup])
15 gl_PREREQ_STRDUP
16 fi
13 AC_CHECK_DECLS_ONCE([strdup]) 17 AC_CHECK_DECLS_ONCE([strdup])
14 if test $ac_cv_have_decl_strdup = no; then 18 if test $ac_cv_have_decl_strdup = no; then
15 HAVE_DECL_STRDUP=0 19 HAVE_DECL_STRDUP=0
16 fi 20 fi
17 gl_PREREQ_STRDUP
18]) 21])
19 22
20AC_DEFUN([gl_FUNC_STRDUP_POSIX], 23AC_DEFUN([gl_FUNC_STRDUP_POSIX],
21[ 24[
22 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 25 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
23 AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) 26 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
24 if test $gl_cv_func_malloc_posix != yes; then 27 AC_CHECK_FUNCS_ONCE([strdup])
25 REPLACE_STRDUP=1 28 if test $ac_cv_func_strdup = yes; then
26 AC_LIBOBJ([strdup]) 29 if test $gl_cv_func_malloc_posix != yes; then
30 REPLACE_STRDUP=1
31 AC_LIBOBJ([strdup])
32 gl_PREREQ_STRDUP
33 fi
27 else 34 else
28 AC_REPLACE_FUNCS([strdup]) 35 AC_LIBOBJ([strdup])
36 gl_PREREQ_STRDUP
29 fi 37 fi
30 AC_CHECK_DECLS_ONCE([strdup]) 38 AC_CHECK_DECLS_ONCE([strdup])
31 if test $ac_cv_have_decl_strdup = no; then 39 if test $ac_cv_have_decl_strdup = no; then
32 HAVE_DECL_STRDUP=0 40 HAVE_DECL_STRDUP=0
33 fi 41 fi
34 gl_PREREQ_STRDUP
35]) 42])
36 43
37# Prerequisites of lib/strdup.c. 44# Prerequisites of lib/strdup.c.
diff --git a/gl/m4/strerror.m4 b/gl/m4/strerror.m4
index 8c16ca9a..1649b245 100644
--- a/gl/m4/strerror.m4
+++ b/gl/m4/strerror.m4
@@ -1,5 +1,5 @@
1# strerror.m4 serial 9 1# strerror.m4 serial 9
2dnl Copyright (C) 2002, 2007-2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4
index 2d5553c3..cf26123e 100644
--- a/gl/m4/string_h.m4
+++ b/gl/m4/string_h.m4
@@ -1,11 +1,11 @@
1# Configure a GNU-like replacement for <string.h>. 1# Configure a GNU-like replacement for <string.h>.
2 2
3# Copyright (C) 2007, 2008 Free Software Foundation, Inc. 3# Copyright (C) 2007-2010 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation 4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it, 5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved. 6# with or without modifications, as long as this notice is preserved.
7 7
8# serial 6 8# serial 16
9 9
10# Written by Paul Eggert. 10# Written by Paul Eggert.
11 11
@@ -21,17 +21,29 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY],
21 AC_REQUIRE([AC_C_RESTRICT]) 21 AC_REQUIRE([AC_C_RESTRICT])
22 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 22 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
23 gl_CHECK_NEXT_HEADERS([string.h]) 23 gl_CHECK_NEXT_HEADERS([string.h])
24
25 dnl Check for declarations of anything we want to poison if the
26 dnl corresponding gnulib module is not in use, and which is not
27 dnl guaranteed by C89.
28 gl_WARN_ON_USE_PREPARE([[#include <string.h>
29 ]],
30 [memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul strdup
31 strncat strndup strnlen strpbrk strsep strcasestr strtok_r strsignal
32 strverscmp])
24]) 33])
25 34
26AC_DEFUN([gl_STRING_MODULE_INDICATOR], 35AC_DEFUN([gl_STRING_MODULE_INDICATOR],
27[ 36[
28 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
29 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 38 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
30 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 39 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
40 dnl Define it also as a C macro, for the benefit of the unit tests.
41 gl_MODULE_INDICATOR_FOR_TESTS([$1])
31]) 42])
32 43
33AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], 44AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
34[ 45[
46 GNULIB_MEMCHR=0; AC_SUBST([GNULIB_MEMCHR])
35 GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) 47 GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM])
36 GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) 48 GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY])
37 GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) 49 GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR])
@@ -40,6 +52,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
40 GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) 52 GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY])
41 GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) 53 GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL])
42 GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) 54 GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP])
55 GNULIB_STRNCAT=0; AC_SUBST([GNULIB_STRNCAT])
43 GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) 56 GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP])
44 GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) 57 GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN])
45 GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) 58 GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK])
@@ -63,30 +76,36 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
63 GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R]) 76 GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R])
64 GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR]) 77 GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR])
65 GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL]) 78 GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL])
66 GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP]) 79 GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP])
80 HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN])
67 dnl Assume proper GNU behavior unless another module says otherwise. 81 dnl Assume proper GNU behavior unless another module says otherwise.
68 HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM]) 82 HAVE_MEMCHR=1; AC_SUBST([HAVE_MEMCHR])
69 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) 83 HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM])
70 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) 84 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY])
71 HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR]) 85 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR])
72 HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY]) 86 HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR])
73 HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY]) 87 HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY])
74 HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL]) 88 HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY])
75 HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP]) 89 HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL])
76 HAVE_STRNDUP=1; AC_SUBST([HAVE_STRNDUP]) 90 HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP])
77 HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP]) 91 HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP])
78 HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN]) 92 HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN])
79 HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK]) 93 HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK])
80 HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP]) 94 HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP])
81 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) 95 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR])
82 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) 96 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R])
83 HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) 97 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL])
84 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) 98 HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP])
85 HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) 99 REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR])
86 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) 100 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM])
87 REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) 101 REPLACE_STPNCPY=0; AC_SUBST([REPLACE_STPNCPY])
88 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) 102 REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP])
89 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) 103 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR])
90 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) 104 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR])
91 REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) 105 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
106 REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT])
107 REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP])
108 REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL])
109 REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R])
110 UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R])
92]) 111])
diff --git a/gl/m4/strndup.m4 b/gl/m4/strndup.m4
index 4fa7d5a7..810313cd 100644
--- a/gl/m4/strndup.m4
+++ b/gl/m4/strndup.m4
@@ -1,5 +1,5 @@
1# strndup.m4 serial 16 1# strndup.m4 serial 17
2dnl Copyright (C) 2002-2003, 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -9,17 +9,20 @@ AC_DEFUN([gl_FUNC_STRNDUP],
9 dnl Persuade glibc <string.h> to declare strndup(). 9 dnl Persuade glibc <string.h> to declare strndup().
10 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 10 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11 11
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 13 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
13 AC_CHECK_DECLS_ONCE([strndup]) 14 AC_CHECK_DECLS_ONCE([strndup])
15 AC_CHECK_FUNCS_ONCE([strndup])
14 if test $ac_cv_have_decl_strndup = no; then 16 if test $ac_cv_have_decl_strndup = no; then
15 HAVE_DECL_STRNDUP=0 17 HAVE_DECL_STRNDUP=0
16 fi 18 fi
17 19
18 # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. 20 if test $ac_cv_func_strndup = yes; then
19 AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup], 21 # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
20 [AC_RUN_IFELSE([ 22 AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
21 AC_LANG_PROGRAM([[#include <string.h> 23 [AC_RUN_IFELSE([
22 #include <stdlib.h>]], [[ 24 AC_LANG_PROGRAM([[#include <string.h>
25 #include <stdlib.h>]], [[
23#ifndef HAVE_DECL_STRNDUP 26#ifndef HAVE_DECL_STRNDUP
24 extern char *strndup (const char *, size_t); 27 extern char *strndup (const char *, size_t);
25#endif 28#endif
@@ -28,26 +31,19 @@ AC_DEFUN([gl_FUNC_STRNDUP],
28 free (s); 31 free (s);
29 s = strndup ("shorter string", 13); 32 s = strndup ("shorter string", 13);
30 return s[13] != '\0';]])], 33 return s[13] != '\0';]])],
31 [gl_cv_func_strndup=yes], 34 [gl_cv_func_strndup_works=yes],
32 [gl_cv_func_strndup=no], 35 [gl_cv_func_strndup_works=no],
33 [AC_CHECK_FUNC([strndup], 36 [case $host_os in
34 [AC_EGREP_CPP([too risky], [ 37 aix*) gl_cv_func_strndup_works="guessing no";;
35#ifdef _AIX 38 *) gl_cv_func_strndup_works="guessing yes";;
36 too risky 39 esac])])
37#endif 40 case $gl_cv_func_strndup_works in
38 ], 41 *no)
39 [gl_cv_func_strndup=no], 42 REPLACE_STRNDUP=1
40 [gl_cv_func_strndup=yes])], 43 AC_LIBOBJ([strndup])
41 [gl_cv_func_strndup=no])])]) 44 ;;
42 if test $gl_cv_func_strndup = yes; then 45 esac
43 AC_DEFINE([HAVE_STRNDUP], [1],
44 [Define if you have the strndup() function and it works.])
45 else 46 else
46 HAVE_STRNDUP=0
47 AC_LIBOBJ([strndup]) 47 AC_LIBOBJ([strndup])
48 gl_PREREQ_STRNDUP
49 fi 48 fi
50]) 49])
51
52# Prerequisites of lib/strndup.c.
53AC_DEFUN([gl_PREREQ_STRNDUP], [:])
diff --git a/gl/m4/strnlen.m4 b/gl/m4/strnlen.m4
index 1c97859d..cd48948f 100644
--- a/gl/m4/strnlen.m4
+++ b/gl/m4/strnlen.m4
@@ -1,5 +1,6 @@
1# strnlen.m4 serial 10 1# strnlen.m4 serial 10
2dnl Copyright (C) 2002-2003, 2005-2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/strstr.m4 b/gl/m4/strstr.m4
new file mode 100644
index 00000000..779957aa
--- /dev/null
+++ b/gl/m4/strstr.m4
@@ -0,0 +1,79 @@
1# strstr.m4 serial 7
2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl Check that strstr works.
8AC_DEFUN([gl_FUNC_STRSTR_SIMPLE],
9[
10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_MEMCHR])
12 if test "$gl_cv_func_memchr_works" != yes; then
13 REPLACE_STRSTR=1
14 AC_LIBOBJ([strstr])
15 fi
16]) # gl_FUNC_STRSTR_SIMPLE
17
18dnl Additionally, check that strstr is efficient.
19AC_DEFUN([gl_FUNC_STRSTR],
20[
21 AC_REQUIRE([gl_FUNC_STRSTR_SIMPLE])
22 if test $REPLACE_STRSTR = 0; then
23 AC_CACHE_CHECK([whether strstr works in linear time],
24 [gl_cv_func_strstr_linear],
25 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
26#include <signal.h> /* for signal */
27#include <string.h> /* for memmem */
28#include <stdlib.h> /* for malloc */
29#include <unistd.h> /* for alarm */
30]], [[size_t m = 1000000;
31 char *haystack = (char *) malloc (2 * m + 2);
32 char *needle = (char *) malloc (m + 2);
33 void *result = 0;
34 /* Failure to compile this test due to missing alarm is okay,
35 since all such platforms (mingw) also have quadratic strstr. */
36 signal (SIGALRM, SIG_DFL);
37 alarm (5);
38 /* Check for quadratic performance. */
39 if (haystack && needle)
40 {
41 memset (haystack, 'A', 2 * m);
42 haystack[2 * m] = 'B';
43 haystack[2 * m + 1] = 0;
44 memset (needle, 'A', m);
45 needle[m] = 'B';
46 needle[m + 1] = 0;
47 result = strstr (haystack, needle);
48 }
49 return !result;]])],
50 [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no],
51 [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a
52 dnl strstr that works in linear time.
53 AC_EGREP_CPP([Lucky user],
54 [
55#include <features.h>
56#ifdef __GNU_LIBRARY__
57 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)
58 Lucky user
59 #endif
60#endif
61#ifdef __CYGWIN__
62 #include <cygwin/version.h>
63 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
64 Lucky user
65 #endif
66#endif
67 ],
68 [gl_cv_func_strstr_linear=yes],
69 [gl_cv_func_strstr_linear="guessing no"])
70 ])
71 ])
72 if test "$gl_cv_func_strstr_linear" != yes; then
73 REPLACE_STRSTR=1
74 fi
75 fi
76 if test $REPLACE_STRSTR = 1; then
77 AC_LIBOBJ([strstr])
78 fi
79]) # gl_FUNC_STRSTR
diff --git a/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4
index d1cb9c20..9f4db562 100644
--- a/gl/m4/sys_socket_h.m4
+++ b/gl/m4/sys_socket_h.m4
@@ -1,5 +1,5 @@
1# sys_socket_h.m4 serial 12 1# sys_socket_h.m4 serial 17
2dnl Copyright (C) 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -19,7 +19,6 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
19 [gl_cv_header_sys_socket_h_selfcontained=no]) 19 [gl_cv_header_sys_socket_h_selfcontained=no])
20 ]) 20 ])
21 if test $gl_cv_header_sys_socket_h_selfcontained = yes; then 21 if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
22 SYS_SOCKET_H=''
23 dnl If the shutdown function exists, <sys/socket.h> should define 22 dnl If the shutdown function exists, <sys/socket.h> should define
24 dnl SHUT_RD, SHUT_WR, SHUT_RDWR. 23 dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
25 AC_CHECK_FUNCS([shutdown]) 24 AC_CHECK_FUNCS([shutdown])
@@ -37,12 +36,10 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
37 SYS_SOCKET_H='sys/socket.h' 36 SYS_SOCKET_H='sys/socket.h'
38 fi 37 fi
39 fi 38 fi
40 else
41 SYS_SOCKET_H='sys/socket.h'
42 fi 39 fi
43 # We need to check for ws2tcpip.h now. 40 # We need to check for ws2tcpip.h now.
44 gl_PREREQ_SYS_H_SOCKET 41 gl_PREREQ_SYS_H_SOCKET
45 AC_CHECK_TYPES([struct sockaddr_storage],,,[ 42 AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
46 /* sys/types.h is not needed according to POSIX, but the 43 /* sys/types.h is not needed according to POSIX, but the
47 sys/socket.h in i386-unknown-freebsd4.10 and 44 sys/socket.h in i386-unknown-freebsd4.10 and
48 powerpc-apple-darwin5.5 required it. */ 45 powerpc-apple-darwin5.5 required it. */
@@ -56,12 +53,23 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
56]) 53])
57 if test $ac_cv_type_struct_sockaddr_storage = no; then 54 if test $ac_cv_type_struct_sockaddr_storage = no; then
58 HAVE_STRUCT_SOCKADDR_STORAGE=0 55 HAVE_STRUCT_SOCKADDR_STORAGE=0
59 SYS_SOCKET_H='sys/socket.h'
60 fi 56 fi
61 if test -n "$SYS_SOCKET_H"; then 57 if test $ac_cv_type_sa_family_t = no; then
62 gl_PREREQ_SYS_H_WINSOCK2 58 HAVE_SA_FAMILY_T=0
63 fi 59 fi
64 AC_SUBST([SYS_SOCKET_H]) 60 gl_PREREQ_SYS_H_WINSOCK2
61
62 dnl Check for declarations of anything we want to poison if the
63 dnl corresponding gnulib module is not in use.
64 gl_WARN_ON_USE_PREPARE([[
65/* Some systems require prerequisite headers. */
66#include <sys/types.h>
67#if !defined __GLIBC__ && HAVE_SYS_TIME_H
68# include <sys/time.h>
69#endif
70#include <sys/select.h>
71 ]], [socket connect accept bind getpeername getsockname getsockopt
72 listen recv send recvfrom sendto setsockopt shutdown accept4])
65]) 73])
66 74
67AC_DEFUN([gl_PREREQ_SYS_H_SOCKET], 75AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
@@ -88,7 +96,7 @@ AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
88 AC_SUBST([HAVE_WS2TCPIP_H]) 96 AC_SUBST([HAVE_WS2TCPIP_H])
89]) 97])
90 98
91# Common prerequisites of of the <sys/socket.h> replacement and of the 99# Common prerequisites of the <sys/socket.h> replacement and of the
92# <sys/select.h> replacement. 100# <sys/select.h> replacement.
93# Sets and substitutes HAVE_WINSOCK2_H. 101# Sets and substitutes HAVE_WINSOCK2_H.
94AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2], 102AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
@@ -117,7 +125,9 @@ AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
117[ 125[
118 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 126 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
119 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS]) 127 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
120 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 128 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
129 dnl Define it also as a C macro, for the benefit of the unit tests.
130 gl_MODULE_INDICATOR_FOR_TESTS([$1])
121]) 131])
122 132
123AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS], 133AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
@@ -136,5 +146,8 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
136 GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO]) 146 GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
137 GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT]) 147 GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
138 GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN]) 148 GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
149 GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
139 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE]) 150 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
151 HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
152 HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
140]) 153])
diff --git a/gl/m4/sys_stat_h.m4 b/gl/m4/sys_stat_h.m4
new file mode 100644
index 00000000..7181c253
--- /dev/null
+++ b/gl/m4/sys_stat_h.m4
@@ -0,0 +1,82 @@
1# sys_stat_h.m4 serial 24 -*- Autoconf -*-
2dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Eric Blake.
8dnl Provide a GNU-like <sys/stat.h>.
9
10AC_DEFUN([gl_HEADER_SYS_STAT_H],
11[
12 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
13
14 dnl For the mkdir substitute.
15 AC_REQUIRE([AC_C_INLINE])
16
17 dnl Check for broken stat macros.
18 AC_REQUIRE([AC_HEADER_STAT])
19
20 gl_CHECK_NEXT_HEADERS([sys/stat.h])
21
22 dnl Define types that are supposed to be defined in <sys/types.h> or
23 dnl <sys/stat.h>.
24 AC_CHECK_TYPE([nlink_t], [],
25 [AC_DEFINE([nlink_t], [int],
26 [Define to the type of st_nlink in struct stat, or a supertype.])],
27 [#include <sys/types.h>
28 #include <sys/stat.h>])
29
30 dnl Check for declarations of anything we want to poison if the
31 dnl corresponding gnulib module is not in use.
32 gl_WARN_ON_USE_PREPARE([[#include <sys/stat.h>
33 ]], [fchmodat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
34 mknod mknodat stat utimensat])
35]) # gl_HEADER_SYS_STAT_H
36
37AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
38[
39 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
40 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
41 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
42 dnl Define it also as a C macro, for the benefit of the unit tests.
43 gl_MODULE_INDICATOR_FOR_TESTS([$1])
44])
45
46AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
47[
48 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
49 GNULIB_FCHMODAT=0; AC_SUBST([GNULIB_FCHMODAT])
50 GNULIB_FSTATAT=0; AC_SUBST([GNULIB_FSTATAT])
51 GNULIB_FUTIMENS=0; AC_SUBST([GNULIB_FUTIMENS])
52 GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD])
53 GNULIB_LSTAT=0; AC_SUBST([GNULIB_LSTAT])
54 GNULIB_MKDIRAT=0; AC_SUBST([GNULIB_MKDIRAT])
55 GNULIB_MKFIFO=0; AC_SUBST([GNULIB_MKFIFO])
56 GNULIB_MKFIFOAT=0; AC_SUBST([GNULIB_MKFIFOAT])
57 GNULIB_MKNOD=0; AC_SUBST([GNULIB_MKNOD])
58 GNULIB_MKNODAT=0; AC_SUBST([GNULIB_MKNODAT])
59 GNULIB_STAT=0; AC_SUBST([GNULIB_STAT])
60 GNULIB_UTIMENSAT=0; AC_SUBST([GNULIB_UTIMENSAT])
61 dnl Assume proper GNU behavior unless another module says otherwise.
62 HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT])
63 HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT])
64 HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS])
65 HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD])
66 HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT])
67 HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT])
68 HAVE_MKFIFO=1; AC_SUBST([HAVE_MKFIFO])
69 HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT])
70 HAVE_MKNOD=1; AC_SUBST([HAVE_MKNOD])
71 HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT])
72 HAVE_UTIMENSAT=1; AC_SUBST([HAVE_UTIMENSAT])
73 REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT])
74 REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT])
75 REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS])
76 REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
77 REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
78 REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO])
79 REPLACE_MKNOD=0; AC_SUBST([REPLACE_MKNOD])
80 REPLACE_STAT=0; AC_SUBST([REPLACE_STAT])
81 REPLACE_UTIMENSAT=0; AC_SUBST([REPLACE_UTIMENSAT])
82])
diff --git a/gl/m4/threadlib.m4 b/gl/m4/threadlib.m4
index 3dd38aa8..05cc4ffa 100644
--- a/gl/m4/threadlib.m4
+++ b/gl/m4/threadlib.m4
@@ -1,5 +1,5 @@
1# threadlib.m4 serial 3 (gettext-0.18) 1# threadlib.m4 serial 5 (gettext-0.18)
2dnl Copyright (C) 2005-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -52,13 +52,24 @@ AC_HELP_STRING([--disable-threads], [build without multithread safety]),
52 [if test -n "$gl_use_threads_default"; then 52 [if test -n "$gl_use_threads_default"; then
53 gl_use_threads="$gl_use_threads_default" 53 gl_use_threads="$gl_use_threads_default"
54 else 54 else
55changequote(,)dnl
55 case "$host_os" in 56 case "$host_os" in
56 dnl Disable multithreading by default on OSF/1, because it interferes 57 dnl Disable multithreading by default on OSF/1, because it interferes
57 dnl with fork()/exec(): When msgexec is linked with -lpthread, its 58 dnl with fork()/exec(): When msgexec is linked with -lpthread, its
58 dnl child process gets an endless segmentation fault inside execvp(). 59 dnl child process gets an endless segmentation fault inside execvp().
60 dnl Disable multithreading by default on Cygwin 1.5.x, because it has
61 dnl bugs that lead to endless loops or crashes. See
62 dnl <http://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
59 osf*) gl_use_threads=no ;; 63 osf*) gl_use_threads=no ;;
64 cygwin*)
65 case `uname -r` in
66 1.[0-5].*) gl_use_threads=no ;;
67 *) gl_use_threads=yes ;;
68 esac
69 ;;
60 *) gl_use_threads=yes ;; 70 *) gl_use_threads=yes ;;
61 esac 71 esac
72changequote([,])dnl
62 fi 73 fi
63 ]) 74 ])
64 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then 75 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
@@ -96,11 +107,34 @@ AC_DEFUN([gl_THREADLIB_BODY],
96 LTLIBMULTITHREAD= 107 LTLIBMULTITHREAD=
97 if test "$gl_use_threads" != no; then 108 if test "$gl_use_threads" != no; then
98 dnl Check whether the compiler and linker support weak declarations. 109 dnl Check whether the compiler and linker support weak declarations.
99 AC_MSG_CHECKING([whether imported symbols can be declared weak]) 110 AC_CACHE_CHECK([whether imported symbols can be declared weak],
100 gl_have_weak=no 111 [gl_cv_have_weak],
101 AC_TRY_LINK([extern void xyzzy (); 112 [gl_cv_have_weak=no
102#pragma weak xyzzy], [xyzzy();], [gl_have_weak=yes]) 113 dnl First, test whether the compiler accepts it syntactically.
103 AC_MSG_RESULT([$gl_have_weak]) 114 AC_TRY_LINK([extern void xyzzy ();
115#pragma weak xyzzy], [xyzzy();], [gl_cv_have_weak=maybe])
116 if test $gl_cv_have_weak = maybe; then
117 dnl Second, test whether it actually works. On Cygwin 1.7.2, with
118 dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
119 AC_TRY_RUN([
120#include <stdio.h>
121#pragma weak fputs
122int main ()
123{
124 return (fputs == NULL);
125}], [gl_cv_have_weak=yes], [gl_cv_have_weak=no],
126 [dnl When cross-compiling, assume that only ELF platforms support
127 dnl weak symbols.
128 AC_EGREP_CPP([Extensible Linking Format],
129 [#ifdef __ELF__
130 Extensible Linking Format
131 #endif
132 ],
133 [gl_cv_have_weak="guessing yes"],
134 [gl_cv_have_weak="guessing no"])
135 ])
136 fi
137 ])
104 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then 138 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
105 # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that 139 # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
106 # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY. 140 # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.
@@ -154,7 +188,7 @@ AC_DEFUN([gl_THREADLIB_BODY],
154 AC_DEFINE([USE_POSIX_THREADS], [1], 188 AC_DEFINE([USE_POSIX_THREADS], [1],
155 [Define if the POSIX multithreading library can be used.]) 189 [Define if the POSIX multithreading library can be used.])
156 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then 190 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
157 if test $gl_have_weak = yes; then 191 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
158 AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], 192 AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
159 [Define if references to the POSIX multithreading library should be made weak.]) 193 [Define if references to the POSIX multithreading library should be made weak.])
160 LIBTHREAD= 194 LIBTHREAD=
@@ -182,7 +216,7 @@ AC_DEFUN([gl_THREADLIB_BODY],
182 LTLIBMULTITHREAD="$LTLIBTHREAD" 216 LTLIBMULTITHREAD="$LTLIBTHREAD"
183 AC_DEFINE([USE_SOLARIS_THREADS], [1], 217 AC_DEFINE([USE_SOLARIS_THREADS], [1],
184 [Define if the old Solaris multithreading library can be used.]) 218 [Define if the old Solaris multithreading library can be used.])
185 if test $gl_have_weak = yes; then 219 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
186 AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1], 220 AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1],
187 [Define if references to the old Solaris multithreading library should be made weak.]) 221 [Define if references to the old Solaris multithreading library should be made weak.])
188 LIBTHREAD= 222 LIBTHREAD=
@@ -208,7 +242,7 @@ AC_DEFUN([gl_THREADLIB_BODY],
208 AC_DEFINE([USE_PTH_THREADS], [1], 242 AC_DEFINE([USE_PTH_THREADS], [1],
209 [Define if the GNU Pth multithreading library can be used.]) 243 [Define if the GNU Pth multithreading library can be used.])
210 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then 244 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
211 if test $gl_have_weak = yes; then 245 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
212 AC_DEFINE([USE_PTH_THREADS_WEAK], [1], 246 AC_DEFINE([USE_PTH_THREADS_WEAK], [1],
213 [Define if references to the GNU Pth multithreading library should be made weak.]) 247 [Define if references to the GNU Pth multithreading library should be made weak.])
214 LIBTHREAD= 248 LIBTHREAD=
diff --git a/gl/m4/time_h.m4 b/gl/m4/time_h.m4
index d42a635e..b88ba94d 100644
--- a/gl/m4/time_h.m4
+++ b/gl/m4/time_h.m4
@@ -1,7 +1,6 @@
1# Configure a more-standard replacement for <time.h>. 1# Configure a more-standard replacement for <time.h>.
2 2
3# Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software 3# Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc.
4# Foundation, Inc.
5 4
6# This file is free software; the Free Software Foundation 5# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 6# gives unlimited permission to copy and/or distribute it,
@@ -24,17 +23,6 @@ AC_DEFUN([gl_HEADER_TIME_H_BODY],
24 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) 23 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
25]) 24])
26 25
27AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
28[
29 dnl If another module says to replace or to not replace, do that.
30 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
31 dnl this lets maintainers check for portability.
32 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
33 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
34 REPLACE_STRPTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRPTIME])
35 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
36])
37
38dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared 26dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
39dnl in time.h or sys/time.h. 27dnl in time.h or sys/time.h.
40 28
@@ -45,9 +33,9 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
45 [gl_cv_sys_struct_timespec_in_time_h], 33 [gl_cv_sys_struct_timespec_in_time_h],
46 [AC_COMPILE_IFELSE( 34 [AC_COMPILE_IFELSE(
47 [AC_LANG_PROGRAM( 35 [AC_LANG_PROGRAM(
48 [[#include <time.h> 36 [[#include <time.h>
49 ]], 37 ]],
50 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], 38 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
51 [gl_cv_sys_struct_timespec_in_time_h=yes], 39 [gl_cv_sys_struct_timespec_in_time_h=yes],
52 [gl_cv_sys_struct_timespec_in_time_h=no])]) 40 [gl_cv_sys_struct_timespec_in_time_h=no])])
53 41
@@ -59,12 +47,12 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
59 AC_CACHE_CHECK([for struct timespec in <sys/time.h>], 47 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
60 [gl_cv_sys_struct_timespec_in_sys_time_h], 48 [gl_cv_sys_struct_timespec_in_sys_time_h],
61 [AC_COMPILE_IFELSE( 49 [AC_COMPILE_IFELSE(
62 [AC_LANG_PROGRAM( 50 [AC_LANG_PROGRAM(
63 [[#include <sys/time.h> 51 [[#include <sys/time.h>
64 ]], 52 ]],
65 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], 53 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
66 [gl_cv_sys_struct_timespec_in_sys_time_h=yes], 54 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
67 [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) 55 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
68 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then 56 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
69 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 57 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
70 fi 58 fi
@@ -72,3 +60,33 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
72 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) 60 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
73 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) 61 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
74]) 62])
63
64AC_DEFUN([gl_TIME_MODULE_INDICATOR],
65[
66 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
67 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
68 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
69 dnl Define it also as a C macro, for the benefit of the unit tests.
70 gl_MODULE_INDICATOR_FOR_TESTS([$1])
71])
72
73AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
74[
75 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
76 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
77 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
78 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
79 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
80 dnl Assume proper GNU behavior unless another module says otherwise.
81 HAVE_LOCALTIME_R=1; AC_SUBST([HAVE_LOCALTIME_R])
82 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
83 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
84 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
85 dnl If another module says to replace or to not replace, do that.
86 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
87 dnl this lets maintainers check for portability.
88 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
89 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
90 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
91 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
92])
diff --git a/gl/m4/time_r.m4 b/gl/m4/time_r.m4
index c871b56d..9e82d39f 100644
--- a/gl/m4/time_r.m4
+++ b/gl/m4/time_r.m4
@@ -1,6 +1,6 @@
1dnl Reentrant time functions like localtime_r. 1dnl Reentrant time functions: localtime_r, gmtime_r.
2 2
3dnl Copyright (C) 2003, 2006, 2007, 2008 Free Software Foundation, Inc. 3dnl Copyright (C) 2003, 2006-2010 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -9,29 +9,40 @@ dnl Written by Paul Eggert.
9 9
10AC_DEFUN([gl_TIME_R], 10AC_DEFUN([gl_TIME_R],
11[ 11[
12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r. 12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 14
15 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 15 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
16 AC_REQUIRE([AC_C_RESTRICT]) 16 AC_REQUIRE([AC_C_RESTRICT])
17 17
18 AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature], 18 AC_CHECK_FUNCS_ONCE([localtime_r])
19 [gl_cv_time_r_posix], 19 if test $ac_cv_func_localtime_r = yes; then
20 [AC_TRY_COMPILE( 20 AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
21 [#include <time.h>], 21 [gl_cv_time_r_posix],
22 [/* We don't need to append 'restrict's to the argument types, 22 [AC_COMPILE_IFELSE(
23 even though the POSIX signature has the 'restrict's, 23 [AC_LANG_PROGRAM(
24 since C99 says they can't affect type compatibility. */ 24 [[#include <time.h>]],
25 struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r; 25 [[/* We don't need to append 'restrict's to the argument types,
26 if (ptr) return 0; 26 even though the POSIX signature has the 'restrict's,
27 /* Check the return type is a pointer. On HP-UX 10 it is 'int'. */ 27 since C99 says they can't affect type compatibility. */
28 *localtime_r (0, 0);], 28 struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
29 [gl_cv_time_r_posix=yes], 29 if (ptr) return 0;
30 [gl_cv_time_r_posix=no])]) 30 /* Check the return type is a pointer.
31 if test $gl_cv_time_r_posix = yes; then 31 On HP-UX 10 it is 'int'. */
32 REPLACE_LOCALTIME_R=0 32 *localtime_r (0, 0);]])
33 ],
34 [gl_cv_time_r_posix=yes],
35 [gl_cv_time_r_posix=no])
36 ])
37 if test $gl_cv_time_r_posix = yes; then
38 REPLACE_LOCALTIME_R=0
39 else
40 REPLACE_LOCALTIME_R=1
41 fi
33 else 42 else
34 REPLACE_LOCALTIME_R=1 43 HAVE_LOCALTIME_R=0
44 fi
45 if test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1; then
35 AC_LIBOBJ([time_r]) 46 AC_LIBOBJ([time_r])
36 gl_PREREQ_TIME_R 47 gl_PREREQ_TIME_R
37 fi 48 fi
diff --git a/gl/m4/timegm.m4 b/gl/m4/timegm.m4
index be323c9b..bdaafbff 100644
--- a/gl/m4/timegm.m4
+++ b/gl/m4/timegm.m4
@@ -1,5 +1,5 @@
1# timegm.m4 serial 6 1# timegm.m4 serial 8
2dnl Copyright (C) 2003, 2007, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -8,18 +8,18 @@ AC_DEFUN([gl_FUNC_TIMEGM],
8[ 8[
9 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 9 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_MKTIME]) 10 AC_REQUIRE([gl_FUNC_MKTIME])
11 if test $ac_cv_func_working_mktime = no; then 11 REPLACE_TIMEGM=0
12 # Assume that timegm is buggy if mktime is. 12 AC_CHECK_FUNCS_ONCE([timegm])
13 AC_LIBOBJ([timegm])
14 ac_cv_func_timegm=no
15 else
16 AC_REPLACE_FUNCS([timegm])
17 fi
18 REPLACE_TIMEGM=1
19 if test $ac_cv_func_timegm = yes; then 13 if test $ac_cv_func_timegm = yes; then
20 AC_CHECK_DECLS([timegm], [REPLACE_TIMEGM=0], [], [#include <time.h>]) 14 if test $ac_cv_func_working_mktime = no; then
15 # Assume that timegm is buggy if mktime is.
16 REPLACE_TIMEGM=1
17 fi
18 else
19 HAVE_TIMEGM=0
21 fi 20 fi
22 if test $REPLACE_TIMEGM = 1; then 21 if test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1; then
22 AC_LIBOBJ([timegm])
23 gl_PREREQ_TIMEGM 23 gl_PREREQ_TIMEGM
24 fi 24 fi
25]) 25])
@@ -34,7 +34,7 @@ AC_DEFUN([gl_PREREQ_TIMEGM], [
34 # so we need to substitute our own mktime implementation. 34 # so we need to substitute our own mktime implementation.
35 AC_LIBOBJ([mktime]) 35 AC_LIBOBJ([mktime])
36 AC_DEFINE([mktime], [rpl_mktime], 36 AC_DEFINE([mktime], [rpl_mktime],
37 [Define to rpl_mktime if the replacement function should be used.]) 37 [Define to rpl_mktime if the replacement function should be used.])
38 gl_PREREQ_MKTIME]) 38 gl_PREREQ_MKTIME])
39 fi 39 fi
40]) 40])
diff --git a/gl/m4/uintmax_t.m4 b/gl/m4/uintmax_t.m4
index 734b6933..03b51bcf 100644
--- a/gl/m4/uintmax_t.m4
+++ b/gl/m4/uintmax_t.m4
@@ -1,5 +1,5 @@
1# uintmax_t.m4 serial 12 1# uintmax_t.m4 serial 12
2dnl Copyright (C) 1997-2004, 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/unistd-safer.m4 b/gl/m4/unistd-safer.m4
index 09adf931..74c3ce60 100644
--- a/gl/m4/unistd-safer.m4
+++ b/gl/m4/unistd-safer.m4
@@ -1,5 +1,5 @@
1#serial 8 1#serial 8
2dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4
index ff9a4ea0..8c2eec64 100644
--- a/gl/m4/unistd_h.m4
+++ b/gl/m4/unistd_h.m4
@@ -1,5 +1,5 @@
1# unistd_h.m4 serial 17 1# unistd_h.m4 serial 45
2dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -11,6 +11,7 @@ AC_DEFUN([gl_UNISTD_H],
11 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 11 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
12 dnl once only, before all statements that occur in other macros. 12 dnl once only, before all statements that occur in other macros.
13 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 13 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
14 AC_REQUIRE([AC_C_INLINE])
14 15
15 gl_CHECK_NEXT_HEADERS([unistd.h]) 16 gl_CHECK_NEXT_HEADERS([unistd.h])
16 17
@@ -21,13 +22,33 @@ AC_DEFUN([gl_UNISTD_H],
21 HAVE_UNISTD_H=0 22 HAVE_UNISTD_H=0
22 fi 23 fi
23 AC_SUBST([HAVE_UNISTD_H]) 24 AC_SUBST([HAVE_UNISTD_H])
25
26 dnl Check for declarations of anything we want to poison if the
27 dnl corresponding gnulib module is not in use.
28 gl_WARN_ON_USE_PREPARE([[#include <unistd.h>
29/* Some systems declare various items in the wrong headers. */
30#ifndef __GLIBC__
31# include <fcntl.h>
32# include <stdio.h>
33# include <stdlib.h>
34# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
35# include <io.h>
36# endif
37#endif
38 ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat
39 fsync ftruncate getcwd getdomainname getdtablesize getgroups
40 gethostname getlogin getlogin_r getpagesize getusershell setusershell
41 endusershell lchown link linkat lseek pipe2 pread readlink readlinkat
42 rmdir sleep symlink symlinkat ttyname_r unlink unlinkat usleep])
24]) 43])
25 44
26AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], 45AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
27[ 46[
28 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 47 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
29 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 48 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
30 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 49 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
50 dnl Define it also as a C macro, for the benefit of the unit tests.
51 gl_MODULE_INDICATOR_FOR_TESTS([$1])
31]) 52])
32 53
33AC_DEFUN([gl_UNISTD_H_DEFAULTS], 54AC_DEFUN([gl_UNISTD_H_DEFAULTS],
@@ -35,49 +56,99 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
35 GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) 56 GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
36 GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE]) 57 GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE])
37 GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) 58 GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2])
59 GNULIB_DUP3=0; AC_SUBST([GNULIB_DUP3])
38 GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON]) 60 GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON])
39 GNULIB_EUIDACCESS=0; AC_SUBST([GNULIB_EUIDACCESS]) 61 GNULIB_EUIDACCESS=0; AC_SUBST([GNULIB_EUIDACCESS])
62 GNULIB_FACCESSAT=0; AC_SUBST([GNULIB_FACCESSAT])
40 GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) 63 GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR])
64 GNULIB_FCHOWNAT=0; AC_SUBST([GNULIB_FCHOWNAT])
41 GNULIB_FSYNC=0; AC_SUBST([GNULIB_FSYNC]) 65 GNULIB_FSYNC=0; AC_SUBST([GNULIB_FSYNC])
42 GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) 66 GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
43 GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) 67 GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
44 GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME]) 68 GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME])
45 GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE]) 69 GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE])
70 GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS])
46 GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) 71 GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME])
72 GNULIB_GETLOGIN=0; AC_SUBST([GNULIB_GETLOGIN])
47 GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) 73 GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
48 GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) 74 GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE])
49 GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL]) 75 GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL])
50 GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN]) 76 GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN])
51 GNULIB_LINK=0; AC_SUBST([GNULIB_LINK]) 77 GNULIB_LINK=0; AC_SUBST([GNULIB_LINK])
78 GNULIB_LINKAT=0; AC_SUBST([GNULIB_LINKAT])
52 GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) 79 GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
80 GNULIB_PIPE2=0; AC_SUBST([GNULIB_PIPE2])
81 GNULIB_PREAD=0; AC_SUBST([GNULIB_PREAD])
53 GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK]) 82 GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
83 GNULIB_READLINKAT=0; AC_SUBST([GNULIB_READLINKAT])
84 GNULIB_RMDIR=0; AC_SUBST([GNULIB_RMDIR])
54 GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP]) 85 GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
86 GNULIB_SYMLINK=0; AC_SUBST([GNULIB_SYMLINK])
87 GNULIB_SYMLINKAT=0; AC_SUBST([GNULIB_SYMLINKAT])
88 GNULIB_TTYNAME_R=0; AC_SUBST([GNULIB_TTYNAME_R])
89 GNULIB_UNISTD_H_GETOPT=0; AC_SUBST([GNULIB_UNISTD_H_GETOPT])
55 GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE]) 90 GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE])
91 GNULIB_UNLINK=0; AC_SUBST([GNULIB_UNLINK])
92 GNULIB_UNLINKAT=0; AC_SUBST([GNULIB_UNLINKAT])
93 GNULIB_USLEEP=0; AC_SUBST([GNULIB_USLEEP])
56 GNULIB_WRITE=0; AC_SUBST([GNULIB_WRITE]) 94 GNULIB_WRITE=0; AC_SUBST([GNULIB_WRITE])
57 dnl Assume proper GNU behavior unless another module says otherwise. 95 dnl Assume proper GNU behavior unless another module says otherwise.
96 HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN])
58 HAVE_DUP2=1; AC_SUBST([HAVE_DUP2]) 97 HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
98 HAVE_DUP3=1; AC_SUBST([HAVE_DUP3])
59 HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS]) 99 HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS])
100 HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT])
101 HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR])
102 HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT])
60 HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC]) 103 HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC])
61 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) 104 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
62 HAVE_GETDOMAINNAME=1; AC_SUBST([HAVE_GETDOMAINNAME]) 105 HAVE_GETDOMAINNAME=1; AC_SUBST([HAVE_GETDOMAINNAME])
63 HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) 106 HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE])
107 HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS])
64 HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) 108 HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME])
109 HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN])
65 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) 110 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
66 HAVE_GETUSERSHELL=1; AC_SUBST([HAVE_GETUSERSHELL]) 111 HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN])
67 HAVE_LINK=1; AC_SUBST([HAVE_LINK]) 112 HAVE_LINK=1; AC_SUBST([HAVE_LINK])
113 HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT])
114 HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2])
115 HAVE_PREAD=1; AC_SUBST([HAVE_PREAD])
68 HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) 116 HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
117 HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT])
69 HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) 118 HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
119 HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK])
120 HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT])
121 HAVE_TTYNAME_R=1; AC_SUBST([HAVE_TTYNAME_R])
122 HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT])
123 HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP])
70 HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) 124 HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON])
71 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) 125 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
126 HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
127 HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL])
72 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) 128 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H])
73 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) 129 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H])
74 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) 130 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
75 REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) 131 REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE])
76 REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) 132 REPLACE_DUP=0; AC_SUBST([REPLACE_DUP])
133 REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2])
134 REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT])
77 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) 135 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
136 REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS])
78 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) 137 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
79 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) 138 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
139 REPLACE_LINK=0; AC_SUBST([REPLACE_LINK])
140 REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT])
80 REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) 141 REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
142 REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD])
143 REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK])
144 REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR])
145 REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP])
146 REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK])
147 REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK])
148 REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT])
149 REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP])
81 REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE]) 150 REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE])
82 UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H]) 151 UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
152 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
153 AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
83]) 154])
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index 3a1d1e01..50a20cca 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,5 +1,5 @@
1# vasnprintf.m4 serial 29 1# vasnprintf.m4 serial 29
2dnl Copyright (C) 2002-2004, 2006-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2006-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/vasprintf.m4 b/gl/m4/vasprintf.m4
index 074b03cf..b142bc0f 100644
--- a/gl/m4/vasprintf.m4
+++ b/gl/m4/vasprintf.m4
@@ -1,5 +1,6 @@
1# vasprintf.m4 serial 6 1# vasprintf.m4 serial 6
2dnl Copyright (C) 2002-2003, 2006-2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2006-2007, 2009-2010 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/visibility.m4 b/gl/m4/visibility.m4
index 70bca564..6d3f9c9d 100644
--- a/gl/m4/visibility.m4
+++ b/gl/m4/visibility.m4
@@ -1,5 +1,5 @@
1# visibility.m4 serial 2 (gettext-0.18) 1# visibility.m4 serial 2 (gettext-0.18)
2dnl Copyright (C) 2005, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/vsnprintf.m4 b/gl/m4/vsnprintf.m4
index 3b37d460..ed189c23 100644
--- a/gl/m4/vsnprintf.m4
+++ b/gl/m4/vsnprintf.m4
@@ -1,5 +1,5 @@
1# vsnprintf.m4 serial 5 1# vsnprintf.m4 serial 5
2dnl Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/warn-on-use.m4 b/gl/m4/warn-on-use.m4
new file mode 100644
index 00000000..42daae87
--- /dev/null
+++ b/gl/m4/warn-on-use.m4
@@ -0,0 +1,45 @@
1# warn-on-use.m4 serial 2
2dnl Copyright (C) 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES)
8# ---------------------------------------
9# For each whitespace-separated element in the list of NAMES, define
10# HAVE_RAW_DECL_name if the function has a declaration among INCLUDES
11# even after being undefined as a macro.
12#
13# See warn-on-use.h for some hints on how to poison function names, as
14# well as ideas on poisoning global variables and macros. NAMES may
15# include global variables, but remember that only functions work with
16# _GL_WARN_ON_USE. Typically, INCLUDES only needs to list a single
17# header, but if the replacement header pulls in other headers because
18# some systems declare functions in the wrong header, then INCLUDES
19# should do likewise.
20#
21# If you assume C89, then it is generally safe to assume declarations
22# for functions declared in that standard (such as gets) without
23# needing gl_WARN_ON_USE_PREPARE.
24AC_DEFUN([gl_WARN_ON_USE_PREPARE],
25[
26 m4_foreach_w([gl_decl], [$2],
27 [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
28 [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
29 undefining macros.])])dnl
30 for gl_func in m4_flatten([$2]); do
31 AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
32 AC_CACHE_CHECK([whether $gl_func is declared without a macro],
33 gl_Symbol,
34 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
35[@%:@undef $gl_func
36 (void) $gl_func;])],
37 [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])])
38 AS_VAR_IF(gl_Symbol, [yes],
39 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
40 dnl shortcut - if the raw declaration exists, then set a cache
41 dnl variable to allow skipping any later AC_CHECK_DECL efforts
42 eval ac_cv_have_decl_$gl_func=yes])
43 AS_VAR_POPDEF([gl_Symbol])dnl
44 done
45])
diff --git a/gl/m4/wchar.m4 b/gl/m4/wchar_h.m4
index 2e52a82a..8cae82dd 100644
--- a/gl/m4/wchar.m4
+++ b/gl/m4/wchar_h.m4
@@ -1,23 +1,30 @@
1dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues. 1dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2 2
3dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. 3dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7 7
8dnl Written by Eric Blake. 8dnl Written by Eric Blake.
9 9
10# wchar.m4 serial 23 10# wchar_h.m4 serial 33
11 11
12AC_DEFUN([gl_WCHAR_H], 12AC_DEFUN([gl_WCHAR_H],
13[ 13[
14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
15 AC_CACHE_CHECK([whether <wchar.h> is standalone], 15 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
16 [gl_cv_header_wchar_h_standalone], 16 dnl Prepare for creating substitute <wchar.h>.
17 [AC_COMPILE_IFELSE([[#include <wchar.h> 17 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
18wchar_t w;]], 18 dnl character support).
19 [gl_cv_header_wchar_h_standalone=yes], 19 dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
20 [gl_cv_header_wchar_h_standalone=no])]) 20 AC_CHECK_HEADERS_ONCE([wchar.h])
21 gl_CHECK_NEXT_HEADERS([wchar.h])
22 if test $ac_cv_header_wchar_h = yes; then
23 HAVE_WCHAR_H=1
24 else
25 HAVE_WCHAR_H=0
26 fi
27 AC_SUBST([HAVE_WCHAR_H])
21 28
22 AC_REQUIRE([gt_TYPE_WINT_T]) 29 AC_REQUIRE([gt_TYPE_WINT_T])
23 if test $gt_cv_c_wint_t = yes; then 30 if test $gt_cv_c_wint_t = yes; then
@@ -27,36 +34,82 @@ wchar_t w;]],
27 fi 34 fi
28 AC_SUBST([HAVE_WINT_T]) 35 AC_SUBST([HAVE_WINT_T])
29 36
30 if test $gl_cv_header_wchar_h_standalone != yes || test $gt_cv_c_wint_t != yes; then 37 dnl Check for declarations of anything we want to poison if the
31 WCHAR_H=wchar.h 38 dnl corresponding gnulib module is not in use.
32 fi 39 gl_WARN_ON_USE_PREPARE([[
40/* Some systems require additional headers. */
41#ifndef __GLIBC__
42# include <stddef.h>
43# include <stdio.h>
44# include <time.h>
45#endif
46#include <wchar.h>
47 ]], [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
48 wcsrtombs wcsnrtombs wcwidth])
49])
33 50
34 dnl Prepare for creating substitute <wchar.h>. 51dnl Check whether <wchar.h> is usable at all.
35 dnl Do it always: WCHAR_H may be empty here but can be set later. 52AC_DEFUN([gl_WCHAR_H_INLINE_OK],
36 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide 53[
37 dnl character support). 54 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
38 AC_CHECK_HEADERS_ONCE([wchar.h]) 55 dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
39 if test $ac_cv_header_wchar_h = yes; then 56 dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
40 HAVE_WCHAR_H=1 57 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
41 else 58 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
42 HAVE_WCHAR_H=0 59 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
60 [gl_cv_header_wchar_h_correct_inline],
61 [gl_cv_header_wchar_h_correct_inline=yes
62 AC_LANG_CONFTEST([
63 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
64#include <wchar.h>
65extern int zero (void);
66int main () { return zero(); }
67]])])
68 if AC_TRY_EVAL([ac_compile]); then
69 mv conftest.$ac_objext conftest1.$ac_objext
70 AC_LANG_CONFTEST([
71 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
72#include <wchar.h>
73int zero (void) { return 0; }
74]])])
75 if AC_TRY_EVAL([ac_compile]); then
76 mv conftest.$ac_objext conftest2.$ac_objext
77 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
78 :
79 else
80 gl_cv_header_wchar_h_correct_inline=no
81 fi
82 fi
83 fi
84 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
85 ])
86 if test $gl_cv_header_wchar_h_correct_inline = no; then
87 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
88This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
89C99 mode. You have four options:
90 - Add the flag -fgnu89-inline to CC and reconfigure, or
91 - Fix your include files, using parts of
92 <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
93 - Use a gcc version older than 4.3, or
94 - Don't use the flags -std=c99 or -std=gnu99.
95Configuration aborted.])
43 fi 96 fi
44 AC_SUBST([HAVE_WCHAR_H])
45 gl_CHECK_NEXT_HEADERS([wchar.h])
46]) 97])
47 98
48dnl Unconditionally enables the replacement of <wchar.h>. 99dnl Unconditionally enables the replacement of <wchar.h>.
49AC_DEFUN([gl_REPLACE_WCHAR_H], 100AC_DEFUN([gl_REPLACE_WCHAR_H],
50[ 101[
51 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 102 dnl This is a no-op, because <wchar.h> is always overridden.
52 WCHAR_H=wchar.h 103 :
53]) 104])
54 105
55AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], 106AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
56[ 107[
57 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 108 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
58 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 109 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
59 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 110 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
111 dnl Define it also as a C macro, for the benefit of the unit tests.
112 gl_MODULE_INDICATOR_FOR_TESTS([$1])
60]) 113])
61 114
62AC_DEFUN([gl_WCHAR_H_DEFAULTS], 115AC_DEFUN([gl_WCHAR_H_DEFAULTS],
@@ -96,5 +149,4 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
96 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS]) 149 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
97 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS]) 150 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
98 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) 151 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
99 WCHAR_H=''; AC_SUBST([WCHAR_H])
100]) 152])
diff --git a/gl/m4/wchar_t.m4 b/gl/m4/wchar_t.m4
index fb27a7f6..ed804e66 100644
--- a/gl/m4/wchar_t.m4
+++ b/gl/m4/wchar_t.m4
@@ -1,5 +1,5 @@
1# wchar_t.m4 serial 3 (gettext-0.18) 1# wchar_t.m4 serial 3 (gettext-0.18)
2dnl Copyright (C) 2002-2003, 2008, 2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/wcrtomb.m4 b/gl/m4/wcrtomb.m4
index cb7d9263..6a2d772a 100644
--- a/gl/m4/wcrtomb.m4
+++ b/gl/m4/wcrtomb.m4
@@ -1,5 +1,5 @@
1# wcrtomb.m4 serial 4 1# wcrtomb.m4 serial 5
2dnl Copyright (C) 2008-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -10,37 +10,37 @@ AC_DEFUN([gl_FUNC_WCRTOMB],
10 10
11 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
12 gl_MBSTATE_T_BROKEN 12 gl_MBSTATE_T_BROKEN
13 if test $REPLACE_MBSTATE_T = 1; then 13
14 REPLACE_WCRTOMB=1
15 fi
16 AC_CHECK_FUNCS_ONCE([wcrtomb]) 14 AC_CHECK_FUNCS_ONCE([wcrtomb])
17 if test $ac_cv_func_wcrtomb = no; then 15 if test $ac_cv_func_wcrtomb = no; then
18 HAVE_WCRTOMB=0 16 HAVE_WCRTOMB=0
19 fi 17 else
20 if test $HAVE_WCRTOMB != 0 && test $REPLACE_WCRTOMB != 1; then 18 if test $REPLACE_MBSTATE_T = 1; then
21 dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes 19 REPLACE_WCRTOMB=1
22 dnl returns 0 instead of 1. 20 else
23 AC_REQUIRE([AC_PROG_CC]) 21 dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
24 AC_REQUIRE([gt_LOCALE_FR]) 22 dnl returns 0 instead of 1.
25 AC_REQUIRE([gt_LOCALE_FR_UTF8]) 23 AC_REQUIRE([AC_PROG_CC])
26 AC_REQUIRE([gt_LOCALE_JA]) 24 AC_REQUIRE([gt_LOCALE_FR])
27 AC_REQUIRE([gt_LOCALE_ZH_CN]) 25 AC_REQUIRE([gt_LOCALE_FR_UTF8])
28 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 26 AC_REQUIRE([gt_LOCALE_JA])
29 AC_CACHE_CHECK([whether wcrtomb return value is correct], 27 AC_REQUIRE([gt_LOCALE_ZH_CN])
30 [gl_cv_func_wcrtomb_retval], 28 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
31 [ 29 AC_CACHE_CHECK([whether wcrtomb return value is correct],
32 dnl Initial guess, used when cross-compiling or when no suitable locale 30 [gl_cv_func_wcrtomb_retval],
33 dnl is present. 31 [
32 dnl Initial guess, used when cross-compiling or when no suitable locale
33 dnl is present.
34changequote(,)dnl 34changequote(,)dnl
35 case "$host_os" in 35 case "$host_os" in
36 # Guess no on AIX 4, OSF/1 and Solaris. 36 # Guess no on AIX 4, OSF/1 and Solaris.
37 aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;; 37 aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
38 # Guess yes otherwise. 38 # Guess yes otherwise.
39 *) gl_cv_func_wcrtomb_retval="guessing yes" ;; 39 *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
40 esac 40 esac
41changequote([,])dnl 41changequote([,])dnl
42 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then 42 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
43 AC_TRY_RUN([ 43 AC_TRY_RUN([
44#include <locale.h> 44#include <locale.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <string.h> 46#include <string.h>
@@ -69,15 +69,16 @@ int main ()
69 } 69 }
70 return 0; 70 return 0;
71}], 71}],
72 [gl_cv_func_wcrtomb_retval=yes], 72 [gl_cv_func_wcrtomb_retval=yes],
73 [gl_cv_func_wcrtomb_retval=no], 73 [gl_cv_func_wcrtomb_retval=no],
74 [:]) 74 [:])
75 fi 75 fi
76 ]) 76 ])
77 case "$gl_cv_func_wcrtomb_retval" in 77 case "$gl_cv_func_wcrtomb_retval" in
78 *yes) ;; 78 *yes) ;;
79 *) REPLACE_WCRTOMB=1 ;; 79 *) REPLACE_WCRTOMB=1 ;;
80 esac 80 esac
81 fi
81 fi 82 fi
82 if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then 83 if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then
83 gl_REPLACE_WCHAR_H 84 gl_REPLACE_WCHAR_H
diff --git a/gl/m4/wctype.m4 b/gl/m4/wctype_h.m4
index 6a1b6f07..32924514 100644
--- a/gl/m4/wctype.m4
+++ b/gl/m4/wctype_h.m4
@@ -1,8 +1,8 @@
1# wctype.m4 serial 2 1# wctype_h.m4 serial 6
2 2
3dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it. 3dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
4 4
5dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. 5dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
6dnl This file is free software; the Free Software Foundation 6dnl This file is free software; the Free Software Foundation
7dnl gives unlimited permission to copy and/or distribute it, 7dnl gives unlimited permission to copy and/or distribute it,
8dnl with or without modifications, as long as this notice is preserved. 8dnl with or without modifications, as long as this notice is preserved.
@@ -12,6 +12,7 @@ dnl Written by Paul Eggert.
12AC_DEFUN([gl_WCTYPE_H], 12AC_DEFUN([gl_WCTYPE_H],
13[ 13[
14 AC_REQUIRE([AC_PROG_CC]) 14 AC_REQUIRE([AC_PROG_CC])
15 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_CHECK_FUNCS_ONCE([iswcntrl]) 16 AC_CHECK_FUNCS_ONCE([iswcntrl])
16 if test $ac_cv_func_iswcntrl = yes; then 17 if test $ac_cv_func_iswcntrl = yes; then
17 HAVE_ISWCNTRL=1 18 HAVE_ISWCNTRL=1
@@ -19,6 +20,13 @@ AC_DEFUN([gl_WCTYPE_H],
19 HAVE_ISWCNTRL=0 20 HAVE_ISWCNTRL=0
20 fi 21 fi
21 AC_SUBST([HAVE_ISWCNTRL]) 22 AC_SUBST([HAVE_ISWCNTRL])
23 AC_CHECK_FUNCS_ONCE([iswblank])
24 if test $ac_cv_func_iswblank = yes; then
25 HAVE_ISWBLANK=1
26 else
27 HAVE_ISWBLANK=0
28 fi
29 AC_SUBST([HAVE_ISWBLANK])
22 AC_CHECK_HEADERS_ONCE([wctype.h]) 30 AC_CHECK_HEADERS_ONCE([wctype.h])
23 AC_REQUIRE([AC_C_INLINE]) 31 AC_REQUIRE([AC_C_INLINE])
24 32
@@ -30,40 +38,34 @@ AC_DEFUN([gl_WCTYPE_H],
30 fi 38 fi
31 AC_SUBST([HAVE_WINT_T]) 39 AC_SUBST([HAVE_WINT_T])
32 40
33 WCTYPE_H=wctype.h
34 if test $ac_cv_header_wctype_h = yes; then 41 if test $ac_cv_header_wctype_h = yes; then
35 if test $ac_cv_func_iswcntrl = yes; then 42 if test $ac_cv_func_iswcntrl = yes; then
36 dnl Linux libc5 has an iswprint function that returns 0 for all arguments. 43 dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
37 dnl The other functions are likely broken in the same way. 44 dnl The other functions are likely broken in the same way.
38 AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works], 45 AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
39 [ 46 [
40 AC_TRY_RUN([#include <stddef.h> 47 AC_RUN_IFELSE([AC_LANG_SOURCE([[
41 #include <stdio.h> 48 #include <stddef.h>
42 #include <time.h> 49 #include <stdio.h>
43 #include <wchar.h> 50 #include <time.h>
44 #include <wctype.h> 51 #include <wchar.h>
45 int main () { return iswprint ('x') == 0; }], 52 #include <wctype.h>
53 int main () { return iswprint ('x') == 0; }]])],
46 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no], 54 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
47 [AC_TRY_COMPILE([#include <stdlib.h> 55 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
48 #if __GNU_LIBRARY__ == 1 56 #if __GNU_LIBRARY__ == 1
49 Linux libc5 i18n is broken. 57 Linux libc5 i18n is broken.
50 #endif], [], 58 #endif]], [])],
51 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no]) 59 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no])
52 ]) 60 ])
53 ]) 61 ])
54 if test $gl_cv_func_iswcntrl_works = yes; then
55 WCTYPE_H=
56 fi
57 fi 62 fi
58 dnl Compute NEXT_WCTYPE_H even if WCTYPE_H is empty,
59 dnl for the benefit of builds from non-distclean directories.
60 gl_CHECK_NEXT_HEADERS([wctype.h]) 63 gl_CHECK_NEXT_HEADERS([wctype.h])
61 HAVE_WCTYPE_H=1 64 HAVE_WCTYPE_H=1
62 else 65 else
63 HAVE_WCTYPE_H=0 66 HAVE_WCTYPE_H=0
64 fi 67 fi
65 AC_SUBST([HAVE_WCTYPE_H]) 68 AC_SUBST([HAVE_WCTYPE_H])
66 AC_SUBST([WCTYPE_H])
67 69
68 if test "$gl_cv_func_iswcntrl_works" = no; then 70 if test "$gl_cv_func_iswcntrl_works" = no; then
69 REPLACE_ISWCNTRL=1 71 REPLACE_ISWCNTRL=1
diff --git a/gl/m4/wint_t.m4 b/gl/m4/wint_t.m4
index 47a4363d..a6c7d15c 100644
--- a/gl/m4/wint_t.m4
+++ b/gl/m4/wint_t.m4
@@ -1,5 +1,5 @@
1# wint_t.m4 serial 4 (gettext-0.18) 1# wint_t.m4 serial 4 (gettext-0.18)
2dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/write.m4 b/gl/m4/write.m4
index 812b19b3..56325aba 100644
--- a/gl/m4/write.m4
+++ b/gl/m4/write.m4
@@ -1,5 +1,5 @@
1# write.m4 serial 1 1# write.m4 serial 1
2dnl Copyright (C) 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/xalloc.m4 b/gl/m4/xalloc.m4
index 837a948c..83247fe3 100644
--- a/gl/m4/xalloc.m4
+++ b/gl/m4/xalloc.m4
@@ -1,5 +1,6 @@
1# xalloc.m4 serial 16 1# xalloc.m4 serial 16
2dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software
3dnl Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/xsize.m4 b/gl/m4/xsize.m4
index 631893cf..b653693a 100644
--- a/gl/m4/xsize.m4
+++ b/gl/m4/xsize.m4
@@ -1,5 +1,5 @@
1# xsize.m4 serial 4 1# xsize.m4 serial 4
2dnl Copyright (C) 2003-2004, 2008 Free Software Foundation, Inc. 2dnl Copyright (C) 2003-2004, 2008-2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/xstrndup.m4 b/gl/m4/xstrndup.m4
index 8a30ab15..74302cc9 100644
--- a/gl/m4/xstrndup.m4
+++ b/gl/m4/xstrndup.m4
@@ -1,5 +1,5 @@
1# xstrndup.m4 serial 2 1# xstrndup.m4 serial 2
2dnl Copyright (C) 2003 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/malloc.c b/gl/malloc.c
index f2f66637..a3095c17 100644
--- a/gl/malloc.c
+++ b/gl/malloc.c
@@ -1,6 +1,6 @@
1/* malloc() function that is glibc compatible. 1/* malloc() function that is glibc compatible.
2 2
3 Copyright (C) 1997, 1998, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 1997-1998, 2006-2007, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/math.in.h b/gl/math.in.h
index a0efefda..fbc29184 100644
--- a/gl/math.in.h
+++ b/gl/math.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <math.h>. 1/* A GNU-like <math.h>.
2 2
3 Copyright (C) 2002-2003, 2007-2009 Free Software Foundation, Inc. 3 Copyright (C) 2002-2003, 2007-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -22,18 +22,48 @@
22#endif 22#endif
23 23
24/* The include_next requires a split double-inclusion guard. */ 24/* The include_next requires a split double-inclusion guard. */
25#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_MATH_H@ 25#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
26 26
27#ifndef _GL_MATH_H 27#ifndef _GL_MATH_H
28#define _GL_MATH_H 28#define _GL_MATH_H
29 29
30 30
31/* The definition of GL_LINK_WARNING is copied here. */ 31/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
32 32
33 33/* The definition of _GL_ARG_NONNULL is copied here. */
34#ifdef __cplusplus 34
35extern "C" { 35/* The definition of _GL_WARN_ON_USE is copied here. */
36#endif 36
37/* Helper macros to define a portability warning for the
38 classification macro FUNC called with VALUE. POSIX declares the
39 classification macros with an argument of real-floating (that is,
40 one of float, double, or long double). */
41#define _GL_WARN_REAL_FLOATING_DECL(func) \
42static inline int \
43rpl_ ## func ## f (float f) \
44{ \
45 return func (f); \
46} \
47static inline int \
48rpl_ ## func ## d (double d) \
49{ \
50 return func (d); \
51} \
52static inline int \
53rpl_ ## func ## l (long double l) \
54{ \
55 return func (l); \
56} \
57_GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \
58 "use gnulib module " #func " for portability"); \
59_GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \
60 "use gnulib module " #func " for portability"); \
61_GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \
62 "use gnulib module " #func " for portability")
63#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \
64 (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \
65 : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \
66 : rpl_ ## func ## l (value))
37 67
38 68
39/* POSIX allows platforms that don't support NAN. But all major 69/* POSIX allows platforms that don't support NAN. But all major
@@ -64,6 +94,7 @@ _NaN ()
64# define HUGE_VAL (1.0 / 0.0) 94# define HUGE_VAL (1.0 / 0.0)
65#endif 95#endif
66 96
97
67/* Write x as 98/* Write x as
68 x = mantissa * 2^exp 99 x = mantissa * 2^exp
69 where 100 where
@@ -73,129 +104,198 @@ _NaN ()
73 Store exp in *EXPPTR and return mantissa. */ 104 Store exp in *EXPPTR and return mantissa. */
74#if @GNULIB_FREXP@ 105#if @GNULIB_FREXP@
75# if @REPLACE_FREXP@ 106# if @REPLACE_FREXP@
76# define frexp rpl_frexp 107# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
77extern double frexp (double x, int *expptr); 108# define frexp rpl_frexp
109# endif
110_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
111_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
112# else
113_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
78# endif 114# endif
115_GL_CXXALIASWARN (frexp);
79#elif defined GNULIB_POSIXCHECK 116#elif defined GNULIB_POSIXCHECK
80# undef frexp 117# undef frexp
81# define frexp(x,e) \ 118/* Assume frexp is always declared. */
82 (GL_LINK_WARNING ("frexp is unportable - " \ 119_GL_WARN_ON_USE (frexp, "frexp is unportable - "
83 "use gnulib module frexp for portability"), \ 120 "use gnulib module frexp for portability");
84 frexp (x, e))
85#endif 121#endif
86 122
87 123
88#if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@ 124#if @GNULIB_LOGB@
89extern long double acosl (long double x); 125# if !@HAVE_DECL_LOGB@
126_GL_EXTERN_C double logb (double x);
127# endif
128#elif defined GNULIB_POSIXCHECK
129# undef logb
130# if HAVE_RAW_DECL_LOGB
131_GL_WARN_ON_USE (logb, "logb is unportable - "
132 "use gnulib module logb for portability");
133# endif
90#endif 134#endif
91#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 135
136
137#if @GNULIB_ACOSL@
138# if !@HAVE_ACOSL@ || !@HAVE_DECL_ACOSL@
139_GL_FUNCDECL_SYS (acosl, long double, (long double x));
140# endif
141_GL_CXXALIAS_SYS (acosl, long double, (long double x));
142_GL_CXXALIASWARN (acosl);
143#elif defined GNULIB_POSIXCHECK
92# undef acosl 144# undef acosl
93# define acosl(x) \ 145# if HAVE_RAW_DECL_ACOSL
94 (GL_LINK_WARNING ("acosl is unportable - " \ 146_GL_WARN_ON_USE (acosl, "acosl is unportable - "
95 "use gnulib module mathl for portability"), \ 147 "use gnulib module mathl for portability");
96 acosl (x)) 148# endif
97#endif 149#endif
98 150
99 151
100#if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@ 152#if @GNULIB_ASINL@
101extern long double asinl (long double x); 153# if !@HAVE_ASINL@ || !@HAVE_DECL_ASINL@
102#endif 154_GL_FUNCDECL_SYS (asinl, long double, (long double x));
103#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 155# endif
156_GL_CXXALIAS_SYS (asinl, long double, (long double x));
157_GL_CXXALIASWARN (asinl);
158#elif defined GNULIB_POSIXCHECK
104# undef asinl 159# undef asinl
105# define asinl(x) \ 160# if HAVE_RAW_DECL_ASINL
106 (GL_LINK_WARNING ("asinl is unportable - " \ 161_GL_WARN_ON_USE (asinl, "asinl is unportable - "
107 "use gnulib module mathl for portability"), \ 162 "use gnulib module mathl for portability");
108 asinl (x)) 163# endif
109#endif 164#endif
110 165
111 166
112#if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@ 167#if @GNULIB_ATANL@
113extern long double atanl (long double x); 168# if !@HAVE_ATANL@ || !@HAVE_DECL_ATANL@
114#endif 169_GL_FUNCDECL_SYS (atanl, long double, (long double x));
115#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 170# endif
171_GL_CXXALIAS_SYS (atanl, long double, (long double x));
172_GL_CXXALIASWARN (atanl);
173#elif defined GNULIB_POSIXCHECK
116# undef atanl 174# undef atanl
117# define atanl(x) \ 175# if HAVE_RAW_DECL_ATANL
118 (GL_LINK_WARNING ("atanl is unportable - " \ 176_GL_WARN_ON_USE (atanl, "atanl is unportable - "
119 "use gnulib module mathl for portability"), \ 177 "use gnulib module mathl for portability");
120 atanl (x)) 178# endif
121#endif 179#endif
122 180
123 181
124#if @GNULIB_CEILF@ 182#if @GNULIB_CEILF@
125# if @REPLACE_CEILF@ 183# if @REPLACE_CEILF@
126# define ceilf rpl_ceilf 184# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
127extern float ceilf (float x); 185# define ceilf rpl_ceilf
186# endif
187_GL_FUNCDECL_RPL (ceilf, float, (float x));
188_GL_CXXALIAS_RPL (ceilf, float, (float x));
189# else
190# if !@HAVE_DECL_CEILF@
191_GL_FUNCDECL_SYS (ceilf, float, (float x));
192# endif
193_GL_CXXALIAS_SYS (ceilf, float, (float x));
128# endif 194# endif
195_GL_CXXALIASWARN (ceilf);
129#elif defined GNULIB_POSIXCHECK 196#elif defined GNULIB_POSIXCHECK
130# undef ceilf 197# undef ceilf
131# define ceilf(x) \ 198# if HAVE_RAW_DECL_CEILF
132 (GL_LINK_WARNING ("ceilf is unportable - " \ 199_GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
133 "use gnulib module ceilf for portability"), \ 200 "use gnulib module ceilf for portability");
134 ceilf (x)) 201# endif
135#endif 202#endif
136 203
137#if @GNULIB_CEILL@ 204#if @GNULIB_CEILL@
138# if @REPLACE_CEILL@ 205# if @REPLACE_CEILL@
139# define ceill rpl_ceill 206# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
140extern long double ceill (long double x); 207# define ceill rpl_ceill
208# endif
209_GL_FUNCDECL_RPL (ceill, long double, (long double x));
210_GL_CXXALIAS_RPL (ceill, long double, (long double x));
211# else
212# if !@HAVE_DECL_CEILL@
213_GL_FUNCDECL_SYS (ceill, long double, (long double x));
214# endif
215_GL_CXXALIAS_SYS (ceill, long double, (long double x));
141# endif 216# endif
217_GL_CXXALIASWARN (ceill);
142#elif defined GNULIB_POSIXCHECK 218#elif defined GNULIB_POSIXCHECK
143# undef ceill 219# undef ceill
144# define ceill(x) \ 220# if HAVE_RAW_DECL_CEILL
145 (GL_LINK_WARNING ("ceill is unportable - " \ 221_GL_WARN_ON_USE (ceill, "ceill is unportable - "
146 "use gnulib module ceill for portability"), \ 222 "use gnulib module ceill for portability");
147 ceill (x)) 223# endif
148#endif 224#endif
149 225
150 226
151#if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@ 227#if @GNULIB_COSL@
152extern long double cosl (long double x); 228# if !@HAVE_COSL@ || !@HAVE_DECL_COSL@
153#endif 229_GL_FUNCDECL_SYS (cosl, long double, (long double x));
154#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 230# endif
231_GL_CXXALIAS_SYS (cosl, long double, (long double x));
232_GL_CXXALIASWARN (cosl);
233#elif defined GNULIB_POSIXCHECK
155# undef cosl 234# undef cosl
156# define cosl(x) \ 235# if HAVE_RAW_DECL_COSL
157 (GL_LINK_WARNING ("cosl is unportable - " \ 236_GL_WARN_ON_USE (cosl, "cosl is unportable - "
158 "use gnulib module mathl for portability"), \ 237 "use gnulib module mathl for portability");
159 cosl (x)) 238# endif
160#endif 239#endif
161 240
162 241
163#if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@ 242#if @GNULIB_EXPL@
164extern long double expl (long double x); 243# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
165#endif 244_GL_FUNCDECL_SYS (expl, long double, (long double x));
166#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 245# endif
246_GL_CXXALIAS_SYS (expl, long double, (long double x));
247_GL_CXXALIASWARN (expl);
248#elif defined GNULIB_POSIXCHECK
167# undef expl 249# undef expl
168# define expl(x) \ 250# if HAVE_RAW_DECL_EXPL
169 (GL_LINK_WARNING ("expl is unportable - " \ 251_GL_WARN_ON_USE (expl, "expl is unportable - "
170 "use gnulib module mathl for portability"), \ 252 "use gnulib module mathl for portability");
171 expl (x)) 253# endif
172#endif 254#endif
173 255
174 256
175#if @GNULIB_FLOORF@ 257#if @GNULIB_FLOORF@
176# if @REPLACE_FLOORF@ 258# if @REPLACE_FLOORF@
177# define floorf rpl_floorf 259# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
178extern float floorf (float x); 260# define floorf rpl_floorf
261# endif
262_GL_FUNCDECL_RPL (floorf, float, (float x));
263_GL_CXXALIAS_RPL (floorf, float, (float x));
264#else
265# if !@HAVE_DECL_FLOORF@
266_GL_FUNCDECL_SYS (floorf, float, (float x));
267# endif
268_GL_CXXALIAS_SYS (floorf, float, (float x));
179# endif 269# endif
270_GL_CXXALIASWARN (floorf);
180#elif defined GNULIB_POSIXCHECK 271#elif defined GNULIB_POSIXCHECK
181# undef floorf 272# undef floorf
182# define floorf(x) \ 273# if HAVE_RAW_DECL_FLOORF
183 (GL_LINK_WARNING ("floorf is unportable - " \ 274_GL_WARN_ON_USE (floorf, "floorf is unportable - "
184 "use gnulib module floorf for portability"), \ 275 "use gnulib module floorf for portability");
185 floorf (x)) 276# endif
186#endif 277#endif
187 278
188#if @GNULIB_FLOORL@ 279#if @GNULIB_FLOORL@
189# if @REPLACE_FLOORL@ 280# if @REPLACE_FLOORL@
190# define floorl rpl_floorl 281# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191extern long double floorl (long double x); 282# define floorl rpl_floorl
283# endif
284_GL_FUNCDECL_RPL (floorl, long double, (long double x));
285_GL_CXXALIAS_RPL (floorl, long double, (long double x));
286# else
287# if !@HAVE_DECL_FLOORL@
288_GL_FUNCDECL_SYS (floorl, long double, (long double x));
289# endif
290_GL_CXXALIAS_SYS (floorl, long double, (long double x));
192# endif 291# endif
292_GL_CXXALIASWARN (floorl);
193#elif defined GNULIB_POSIXCHECK 293#elif defined GNULIB_POSIXCHECK
194# undef floorl 294# undef floorl
195# define floorl(x) \ 295# if HAVE_RAW_DECL_FLOORL
196 (GL_LINK_WARNING ("floorl is unportable - " \ 296_GL_WARN_ON_USE (floorl, "floorl is unportable - "
197 "use gnulib module floorl for portability"), \ 297 "use gnulib module floorl for portability");
198 floorl (x)) 298# endif
199#endif 299#endif
200 300
201 301
@@ -207,173 +307,247 @@ extern long double floorl (long double x);
207 If x is infinite or NaN: mantissa = x, exp unspecified. 307 If x is infinite or NaN: mantissa = x, exp unspecified.
208 Store exp in *EXPPTR and return mantissa. */ 308 Store exp in *EXPPTR and return mantissa. */
209#if @GNULIB_FREXPL@ && @REPLACE_FREXPL@ 309#if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
210# define frexpl rpl_frexpl 310# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311# define frexpl rpl_frexpl
312# endif
313_GL_FUNCDECL_RPL (frexpl, long double,
314 (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
315_GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
316#else
317# if !@HAVE_DECL_FREXPL@
318_GL_FUNCDECL_SYS (frexpl, long double,
319 (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
320# endif
321# if @GNULIB_FREXPL@
322_GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
323# endif
211#endif 324#endif
212#if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@ 325#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@)
213extern long double frexpl (long double x, int *expptr); 326_GL_CXXALIASWARN (frexpl);
214#endif 327#endif
215#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK 328#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
216# undef frexpl 329# undef frexpl
217# define frexpl(x,e) \ 330# if HAVE_RAW_DECL_FREXPL
218 (GL_LINK_WARNING ("frexpl is unportable - " \ 331_GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
219 "use gnulib module frexpl for portability"), \ 332 "use gnulib module frexpl for portability");
220 frexpl (x, e)) 333# endif
221#endif 334#endif
222 335
223 336
224/* Return x * 2^exp. */ 337/* Return x * 2^exp. */
225#if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@ 338#if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
226# define ldexpl rpl_ldexpl 339# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
340# define ldexpl rpl_ldexpl
341# endif
342_GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
343_GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
344#else
345# if !@HAVE_DECL_LDEXPL@
346_GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
347# endif
348# if @GNULIB_LDEXPL@
349_GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
350# endif
227#endif 351#endif
228#if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@ 352#if @GNULIB_LDEXPL@
229extern long double ldexpl (long double x, int exp); 353_GL_CXXALIASWARN (ldexpl);
230#endif 354#endif
231#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK 355#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
232# undef ldexpl 356# undef ldexpl
233# define ldexpl(x,e) \ 357# if HAVE_RAW_DECL_LDEXPL
234 (GL_LINK_WARNING ("ldexpl is unportable - " \ 358_GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
235 "use gnulib module ldexpl for portability"), \ 359 "use gnulib module ldexpl for portability");
236 ldexpl (x, e)) 360# endif
237#endif 361#endif
238 362
239 363
240#if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@ 364#if @GNULIB_LOGL@
241extern long double logl (long double x); 365# if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@
242#endif 366_GL_FUNCDECL_SYS (logl, long double, (long double x));
243#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 367# endif
368_GL_CXXALIAS_SYS (logl, long double, (long double x));
369_GL_CXXALIASWARN (logl);
370#elif defined GNULIB_POSIXCHECK
244# undef logl 371# undef logl
245# define logl(x) \ 372# if HAVE_RAW_DECL_LOGL
246 (GL_LINK_WARNING ("logl is unportable - " \ 373_GL_WARN_ON_USE (logl, "logl is unportable - "
247 "use gnulib module mathl for portability"), \ 374 "use gnulib module mathl for portability");
248 logl (x)) 375# endif
249#endif 376#endif
250 377
251 378
252#if @GNULIB_ROUNDF@ 379#if @GNULIB_ROUNDF@
253# if @REPLACE_ROUNDF@ 380# if @REPLACE_ROUNDF@
254# undef roundf 381# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
255# define roundf rpl_roundf 382# undef roundf
256extern float roundf (float x); 383# define roundf rpl_roundf
384# endif
385_GL_FUNCDECL_RPL (roundf, float, (float x));
386_GL_CXXALIAS_RPL (roundf, float, (float x));
387# else
388# if !@HAVE_DECL_ROUNDF@
389_GL_FUNCDECL_SYS (roundf, float, (float x));
390# endif
391_GL_CXXALIAS_SYS (roundf, float, (float x));
257# endif 392# endif
393_GL_CXXALIASWARN (roundf);
258#elif defined GNULIB_POSIXCHECK 394#elif defined GNULIB_POSIXCHECK
259# undef roundf 395# undef roundf
260# define roundf(x) \ 396# if HAVE_RAW_DECL_ROUNDF
261 (GL_LINK_WARNING ("roundf is unportable - " \ 397_GL_WARN_ON_USE (roundf, "roundf is unportable - "
262 "use gnulib module roundf for portability"), \ 398 "use gnulib module roundf for portability");
263 roundf (x)) 399# endif
264#endif 400#endif
265 401
266#if @GNULIB_ROUND@ 402#if @GNULIB_ROUND@
267# if @REPLACE_ROUND@ 403# if @REPLACE_ROUND@
268# undef round 404# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
269# define round rpl_round 405# undef round
270extern double round (double x); 406# define round rpl_round
407# endif
408_GL_FUNCDECL_RPL (round, double, (double x));
409_GL_CXXALIAS_RPL (round, double, (double x));
410# else
411# if !@HAVE_DECL_ROUND@
412_GL_FUNCDECL_SYS (round, double, (double x));
413# endif
414_GL_CXXALIAS_SYS (round, double, (double x));
271# endif 415# endif
416_GL_CXXALIASWARN (round);
272#elif defined GNULIB_POSIXCHECK 417#elif defined GNULIB_POSIXCHECK
273# undef round 418# undef round
274# define round(x) \ 419# if HAVE_RAW_DECL_ROUND
275 (GL_LINK_WARNING ("round is unportable - " \ 420_GL_WARN_ON_USE (round, "round is unportable - "
276 "use gnulib module round for portability"), \ 421 "use gnulib module round for portability");
277 round (x)) 422# endif
278#endif 423#endif
279 424
280#if @GNULIB_ROUNDL@ 425#if @GNULIB_ROUNDL@
281# if @REPLACE_ROUNDL@ 426# if @REPLACE_ROUNDL@
282# undef roundl 427# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
283# define roundl rpl_roundl 428# undef roundl
284extern long double roundl (long double x); 429# define roundl rpl_roundl
430# endif
431_GL_FUNCDECL_RPL (roundl, long double, (long double x));
432_GL_CXXALIAS_RPL (roundl, long double, (long double x));
433# else
434# if !@HAVE_DECL_ROUNDL@
435_GL_FUNCDECL_SYS (roundl, long double, (long double x));
436# endif
437_GL_CXXALIAS_SYS (roundl, long double, (long double x));
285# endif 438# endif
439_GL_CXXALIASWARN (roundl);
286#elif defined GNULIB_POSIXCHECK 440#elif defined GNULIB_POSIXCHECK
287# undef roundl 441# undef roundl
288# define roundl(x) \ 442# if HAVE_RAW_DECL_ROUNDL
289 (GL_LINK_WARNING ("roundl is unportable - " \ 443_GL_WARN_ON_USE (roundl, "roundl is unportable - "
290 "use gnulib module roundl for portability"), \ 444 "use gnulib module roundl for portability");
291 roundl (x)) 445# endif
292#endif 446#endif
293 447
294 448
295#if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@ 449#if @GNULIB_SINL@
296extern long double sinl (long double x); 450# if !@HAVE_SINL@ || !@HAVE_DECL_SINL@
297#endif 451_GL_FUNCDECL_SYS (sinl, long double, (long double x));
298#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 452# endif
453_GL_CXXALIAS_SYS (sinl, long double, (long double x));
454_GL_CXXALIASWARN (sinl);
455#elif defined GNULIB_POSIXCHECK
299# undef sinl 456# undef sinl
300# define sinl(x) \ 457# if HAVE_RAW_DECL_SINL
301 (GL_LINK_WARNING ("sinl is unportable - " \ 458_GL_WARN_ON_USE (sinl, "sinl is unportable - "
302 "use gnulib module mathl for portability"), \ 459 "use gnulib module mathl for portability");
303 sinl (x)) 460# endif
304#endif 461#endif
305 462
306 463
307#if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@ 464#if @GNULIB_SQRTL@
308extern long double sqrtl (long double x); 465# if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@
309#endif 466_GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
310#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 467# endif
468_GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
469_GL_CXXALIASWARN (sqrtl);
470#elif defined GNULIB_POSIXCHECK
311# undef sqrtl 471# undef sqrtl
312# define sqrtl(x) \ 472# if HAVE_RAW_DECL_SQRTL
313 (GL_LINK_WARNING ("sqrtl is unportable - " \ 473_GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
314 "use gnulib module mathl for portability"), \ 474 "use gnulib module mathl for portability");
315 sqrtl (x)) 475# endif
316#endif 476#endif
317 477
318 478
319#if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@ 479#if @GNULIB_TANL@
320extern long double tanl (long double x); 480# if !@HAVE_TANL@ || !@HAVE_DECL_TANL@
321#endif 481_GL_FUNCDECL_SYS (tanl, long double, (long double x));
322#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK 482# endif
483_GL_CXXALIAS_SYS (tanl, long double, (long double x));
484_GL_CXXALIASWARN (tanl);
485#elif defined GNULIB_POSIXCHECK
323# undef tanl 486# undef tanl
324# define tanl(x) \ 487# if HAVE_RAW_DECL_TANL
325 (GL_LINK_WARNING ("tanl is unportable - " \ 488_GL_WARN_ON_USE (tanl, "tanl is unportable - "
326 "use gnulib module mathl for portability"), \ 489 "use gnulib module mathl for portability");
327 tanl (x)) 490# endif
328#endif 491#endif
329 492
330 493
331#if @GNULIB_TRUNCF@ 494#if @GNULIB_TRUNCF@
332# if !@HAVE_DECL_TRUNCF@ 495# if !@HAVE_DECL_TRUNCF@
333# define truncf rpl_truncf 496_GL_FUNCDECL_SYS (truncf, float, (float x));
334extern float truncf (float x);
335# endif 497# endif
498_GL_CXXALIAS_SYS (truncf, float, (float x));
499_GL_CXXALIASWARN (truncf);
336#elif defined GNULIB_POSIXCHECK 500#elif defined GNULIB_POSIXCHECK
337# undef truncf 501# undef truncf
338# define truncf(x) \ 502# if HAVE_RAW_DECL_TRUNCF
339 (GL_LINK_WARNING ("truncf is unportable - " \ 503_GL_WARN_ON_USE (truncf, "truncf is unportable - "
340 "use gnulib module truncf for portability"), \ 504 "use gnulib module truncf for portability");
341 truncf (x)) 505# endif
342#endif 506#endif
343 507
344#if @GNULIB_TRUNC@ 508#if @GNULIB_TRUNC@
345# if !@HAVE_DECL_TRUNC@ 509# if !@HAVE_DECL_TRUNC@
346# define trunc rpl_trunc 510_GL_FUNCDECL_SYS (trunc, double, (double x));
347extern double trunc (double x);
348# endif 511# endif
512_GL_CXXALIAS_SYS (trunc, double, (double x));
513_GL_CXXALIASWARN (trunc);
349#elif defined GNULIB_POSIXCHECK 514#elif defined GNULIB_POSIXCHECK
350# undef trunc 515# undef trunc
351# define trunc(x) \ 516# if HAVE_RAW_DECL_TRUNC
352 (GL_LINK_WARNING ("trunc is unportable - " \ 517_GL_WARN_ON_USE (trunc, "trunc is unportable - "
353 "use gnulib module trunc for portability"), \ 518 "use gnulib module trunc for portability");
354 trunc (x)) 519# endif
355#endif 520#endif
356 521
357#if @GNULIB_TRUNCL@ 522#if @GNULIB_TRUNCL@
358# if @REPLACE_TRUNCL@ 523# if @REPLACE_TRUNCL@
359# undef truncl 524# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
360# define truncl rpl_truncl 525# undef truncl
361extern long double truncl (long double x); 526# define truncl rpl_truncl
527# endif
528_GL_FUNCDECL_RPL (truncl, long double, (long double x));
529_GL_CXXALIAS_RPL (truncl, long double, (long double x));
530# else
531# if !@HAVE_DECL_TRUNCL@
532_GL_FUNCDECL_SYS (truncl, long double, (long double x));
533# endif
534_GL_CXXALIAS_SYS (truncl, long double, (long double x));
362# endif 535# endif
536_GL_CXXALIASWARN (truncl);
363#elif defined GNULIB_POSIXCHECK 537#elif defined GNULIB_POSIXCHECK
364# undef truncl 538# undef truncl
365# define truncl(x) \ 539# if HAVE_RAW_DECL_TRUNCL
366 (GL_LINK_WARNING ("truncl is unportable - " \ 540_GL_WARN_ON_USE (truncl, "truncl is unportable - "
367 "use gnulib module truncl for portability"), \ 541 "use gnulib module truncl for portability");
368 truncl (x)) 542# endif
369#endif 543#endif
370 544
371 545
372#if @GNULIB_ISFINITE@ 546#if @GNULIB_ISFINITE@
373# if @REPLACE_ISFINITE@ 547# if @REPLACE_ISFINITE@
374extern int gl_isfinitef (float x); 548_GL_EXTERN_C int gl_isfinitef (float x);
375extern int gl_isfinited (double x); 549_GL_EXTERN_C int gl_isfinited (double x);
376extern int gl_isfinitel (long double x); 550_GL_EXTERN_C int gl_isfinitel (long double x);
377# undef isfinite 551# undef isfinite
378# define isfinite(x) \ 552# define isfinite(x) \
379 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \ 553 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
@@ -381,15 +555,19 @@ extern int gl_isfinitel (long double x);
381 gl_isfinitef (x)) 555 gl_isfinitef (x))
382# endif 556# endif
383#elif defined GNULIB_POSIXCHECK 557#elif defined GNULIB_POSIXCHECK
384 /* How to override a macro? */ 558# if defined isfinite
559_GL_WARN_REAL_FLOATING_DECL (isfinite);
560# undef isfinite
561# define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
562# endif
385#endif 563#endif
386 564
387 565
388#if @GNULIB_ISINF@ 566#if @GNULIB_ISINF@
389# if @REPLACE_ISINF@ 567# if @REPLACE_ISINF@
390extern int gl_isinff (float x); 568_GL_EXTERN_C int gl_isinff (float x);
391extern int gl_isinfd (double x); 569_GL_EXTERN_C int gl_isinfd (double x);
392extern int gl_isinfl (long double x); 570_GL_EXTERN_C int gl_isinfl (long double x);
393# undef isinf 571# undef isinf
394# define isinf(x) \ 572# define isinf(x) \
395 (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \ 573 (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
@@ -397,7 +575,11 @@ extern int gl_isinfl (long double x);
397 gl_isinff (x)) 575 gl_isinff (x))
398# endif 576# endif
399#elif defined GNULIB_POSIXCHECK 577#elif defined GNULIB_POSIXCHECK
400 /* How to override a macro? */ 578# if defined isinf
579_GL_WARN_REAL_FLOATING_DECL (isinf);
580# undef isinf
581# define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
582# endif
401#endif 583#endif
402 584
403 585
@@ -406,7 +588,6 @@ extern int gl_isinfl (long double x);
406# if @HAVE_ISNANF@ 588# if @HAVE_ISNANF@
407/* The original <math.h> included above provides a declaration of isnan macro 589/* The original <math.h> included above provides a declaration of isnan macro
408 or (older) isnanf function. */ 590 or (older) isnanf function. */
409# include <math.h>
410# if __GNUC__ >= 4 591# if __GNUC__ >= 4
411 /* GCC 4.0 and newer provides three built-ins for isnan. */ 592 /* GCC 4.0 and newer provides three built-ins for isnan. */
412# undef isnanf 593# undef isnanf
@@ -419,7 +600,7 @@ extern int gl_isinfl (long double x);
419/* Test whether X is a NaN. */ 600/* Test whether X is a NaN. */
420# undef isnanf 601# undef isnanf
421# define isnanf rpl_isnanf 602# define isnanf rpl_isnanf
422extern int isnanf (float x); 603_GL_EXTERN_C int isnanf (float x);
423# endif 604# endif
424#endif 605#endif
425 606
@@ -429,7 +610,6 @@ extern int isnanf (float x);
429 to 'double' numbers earlier but now is a type-generic macro. */ 610 to 'double' numbers earlier but now is a type-generic macro. */
430# if @HAVE_ISNAND@ 611# if @HAVE_ISNAND@
431/* The original <math.h> included above provides a declaration of isnan macro. */ 612/* The original <math.h> included above provides a declaration of isnan macro. */
432# include <math.h>
433# if __GNUC__ >= 4 613# if __GNUC__ >= 4
434 /* GCC 4.0 and newer provides three built-ins for isnan. */ 614 /* GCC 4.0 and newer provides three built-ins for isnan. */
435# undef isnand 615# undef isnand
@@ -442,7 +622,7 @@ extern int isnanf (float x);
442/* Test whether X is a NaN. */ 622/* Test whether X is a NaN. */
443# undef isnand 623# undef isnand
444# define isnand rpl_isnand 624# define isnand rpl_isnand
445extern int isnand (double x); 625_GL_EXTERN_C int isnand (double x);
446# endif 626# endif
447#endif 627#endif
448 628
@@ -450,7 +630,6 @@ extern int isnand (double x);
450/* Test for NaN for 'long double' numbers. */ 630/* Test for NaN for 'long double' numbers. */
451# if @HAVE_ISNANL@ 631# if @HAVE_ISNANL@
452/* The original <math.h> included above provides a declaration of isnan macro or (older) isnanl function. */ 632/* The original <math.h> included above provides a declaration of isnan macro or (older) isnanl function. */
453# include <math.h>
454# if __GNUC__ >= 4 633# if __GNUC__ >= 4
455 /* GCC 4.0 and newer provides three built-ins for isnan. */ 634 /* GCC 4.0 and newer provides three built-ins for isnan. */
456# undef isnanl 635# undef isnanl
@@ -463,7 +642,7 @@ extern int isnand (double x);
463/* Test whether X is a NaN. */ 642/* Test whether X is a NaN. */
464# undef isnanl 643# undef isnanl
465# define isnanl rpl_isnanl 644# define isnanl rpl_isnanl
466extern int isnanl (long double x); 645_GL_EXTERN_C int isnanl (long double x);
467# endif 646# endif
468#endif 647#endif
469 648
@@ -477,19 +656,19 @@ extern int isnanl (long double x);
477# if @HAVE_ISNANF@ && __GNUC__ >= 4 656# if @HAVE_ISNANF@ && __GNUC__ >= 4
478# define gl_isnan_f(x) __builtin_isnan ((float)(x)) 657# define gl_isnan_f(x) __builtin_isnan ((float)(x))
479# else 658# else
480extern int rpl_isnanf (float x); 659_GL_EXTERN_C int rpl_isnanf (float x);
481# define gl_isnan_f(x) rpl_isnanf (x) 660# define gl_isnan_f(x) rpl_isnanf (x)
482# endif 661# endif
483# if @HAVE_ISNAND@ && __GNUC__ >= 4 662# if @HAVE_ISNAND@ && __GNUC__ >= 4
484# define gl_isnan_d(x) __builtin_isnan ((double)(x)) 663# define gl_isnan_d(x) __builtin_isnan ((double)(x))
485# else 664# else
486extern int rpl_isnand (double x); 665_GL_EXTERN_C int rpl_isnand (double x);
487# define gl_isnan_d(x) rpl_isnand (x) 666# define gl_isnan_d(x) rpl_isnand (x)
488# endif 667# endif
489# if @HAVE_ISNANL@ && __GNUC__ >= 4 668# if @HAVE_ISNANL@ && __GNUC__ >= 4
490# define gl_isnan_l(x) __builtin_isnan ((long double)(x)) 669# define gl_isnan_l(x) __builtin_isnan ((long double)(x))
491# else 670# else
492extern int rpl_isnanl (long double x); 671_GL_EXTERN_C int rpl_isnanl (long double x);
493# define gl_isnan_l(x) rpl_isnanl (x) 672# define gl_isnan_l(x) rpl_isnanl (x)
494# endif 673# endif
495# undef isnan 674# undef isnan
@@ -499,7 +678,11 @@ extern int rpl_isnanl (long double x);
499 gl_isnan_f (x)) 678 gl_isnan_f (x))
500# endif 679# endif
501#elif defined GNULIB_POSIXCHECK 680#elif defined GNULIB_POSIXCHECK
502 /* How to override a macro? */ 681# if defined isnan
682_GL_WARN_REAL_FLOATING_DECL (isnan);
683# undef isnan
684# define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
685# endif
503#endif 686#endif
504 687
505 688
@@ -514,38 +697,38 @@ extern int rpl_isnanl (long double x);
514# endif 697# endif
515# if @REPLACE_SIGNBIT@ 698# if @REPLACE_SIGNBIT@
516# undef signbit 699# undef signbit
517extern int gl_signbitf (float arg); 700_GL_EXTERN_C int gl_signbitf (float arg);
518extern int gl_signbitd (double arg); 701_GL_EXTERN_C int gl_signbitd (double arg);
519extern int gl_signbitl (long double arg); 702_GL_EXTERN_C int gl_signbitl (long double arg);
520# if __GNUC__ >= 2 && !__STRICT_ANSI__ 703# if __GNUC__ >= 2 && !__STRICT_ANSI__
521# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf 704# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
522# define gl_signbitf_OPTIMIZED_MACRO 705# define gl_signbitf_OPTIMIZED_MACRO
523# define gl_signbitf(arg) \ 706# define gl_signbitf(arg) \
524 ({ union { float _value; \ 707 ({ union { float _value; \
525 unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ 708 unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
526 } _m; \ 709 } _m; \
527 _m._value = (arg); \ 710 _m._value = (arg); \
528 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \ 711 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
529 }) 712 })
530# endif 713# endif
531# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd 714# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
532# define gl_signbitd_OPTIMIZED_MACRO 715# define gl_signbitd_OPTIMIZED_MACRO
533# define gl_signbitd(arg) \ 716# define gl_signbitd(arg) \
534 ({ union { double _value; \ 717 ({ union { double _value; \
535 unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ 718 unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
536 } _m; \ 719 } _m; \
537 _m._value = (arg); \ 720 _m._value = (arg); \
538 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \ 721 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
539 }) 722 })
540# endif 723# endif
541# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl 724# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
542# define gl_signbitl_OPTIMIZED_MACRO 725# define gl_signbitl_OPTIMIZED_MACRO
543# define gl_signbitl(arg) \ 726# define gl_signbitl(arg) \
544 ({ union { long double _value; \ 727 ({ union { long double _value; \
545 unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ 728 unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
546 } _m; \ 729 } _m; \
547 _m._value = (arg); \ 730 _m._value = (arg); \
548 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \ 731 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
549 }) 732 })
550# endif 733# endif
551# endif 734# endif
@@ -555,13 +738,13 @@ extern int gl_signbitl (long double arg);
555 gl_signbitf (x)) 738 gl_signbitf (x))
556# endif 739# endif
557#elif defined GNULIB_POSIXCHECK 740#elif defined GNULIB_POSIXCHECK
558 /* How to override a macro? */ 741# if defined signbit
742_GL_WARN_REAL_FLOATING_DECL (signbit);
743# undef signbit
744# define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
745# endif
559#endif 746#endif
560 747
561 748
562#ifdef __cplusplus
563}
564#endif
565
566#endif /* _GL_MATH_H */ 749#endif /* _GL_MATH_H */
567#endif /* _GL_MATH_H */ 750#endif /* _GL_MATH_H */
diff --git a/gl/mbrtowc.c b/gl/mbrtowc.c
index 0fec5f1c..5c2650e9 100644
--- a/gl/mbrtowc.c
+++ b/gl/mbrtowc.c
@@ -1,5 +1,5 @@
1/* Convert multibyte character to wide character. 1/* Convert multibyte character to wide character.
2 Copyright (C) 1999-2002, 2005-2009 Free Software Foundation, Inc. 2 Copyright (C) 1999-2002, 2005-2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
@@ -63,30 +63,30 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
63 switch (nstate) 63 switch (nstate)
64 { 64 {
65 case 0: 65 case 0:
66 p = s; 66 p = s;
67 m = n; 67 m = n;
68 break; 68 break;
69 case 3: 69 case 3:
70 buf[2] = pstate[3]; 70 buf[2] = pstate[3];
71 /*FALLTHROUGH*/ 71 /*FALLTHROUGH*/
72 case 2: 72 case 2:
73 buf[1] = pstate[2]; 73 buf[1] = pstate[2];
74 /*FALLTHROUGH*/ 74 /*FALLTHROUGH*/
75 case 1: 75 case 1:
76 buf[0] = pstate[1]; 76 buf[0] = pstate[1];
77 p = buf; 77 p = buf;
78 m = nstate; 78 m = nstate;
79 buf[m++] = s[0]; 79 buf[m++] = s[0];
80 if (n >= 2 && m < 4) 80 if (n >= 2 && m < 4)
81 { 81 {
82 buf[m++] = s[1]; 82 buf[m++] = s[1];
83 if (n >= 3 && m < 4) 83 if (n >= 3 && m < 4)
84 buf[m++] = s[2]; 84 buf[m++] = s[2];
85 } 85 }
86 break; 86 break;
87 default: 87 default:
88 errno = EINVAL; 88 errno = EINVAL;
89 return (size_t)(-1); 89 return (size_t)(-1);
90 } 90 }
91 91
92 /* Here m > 0. */ 92 /* Here m > 0. */
@@ -99,208 +99,208 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
99 int res = mbtowc (pwc, p, m); 99 int res = mbtowc (pwc, p, m);
100 100
101 if (res >= 0) 101 if (res >= 0)
102 { 102 {
103 if (pwc != NULL && ((*pwc == 0) != (res == 0))) 103 if (pwc != NULL && ((*pwc == 0) != (res == 0)))
104 abort (); 104 abort ();
105 if (nstate >= (res > 0 ? res : 1)) 105 if (nstate >= (res > 0 ? res : 1))
106 abort (); 106 abort ();
107 res -= nstate; 107 res -= nstate;
108 pstate[0] = 0; 108 pstate[0] = 0;
109 return res; 109 return res;
110 } 110 }
111 111
112 /* mbtowc does not distinguish between invalid and incomplete multibyte 112 /* mbtowc does not distinguish between invalid and incomplete multibyte
113 sequences. But mbrtowc needs to make this distinction. 113 sequences. But mbrtowc needs to make this distinction.
114 There are two possible approaches: 114 There are two possible approaches:
115 - Use iconv() and its return value. 115 - Use iconv() and its return value.
116 - Use built-in knowledge about the possible encodings. 116 - Use built-in knowledge about the possible encodings.
117 Given the low quality of implementation of iconv() on the systems that 117 Given the low quality of implementation of iconv() on the systems that
118 lack mbrtowc(), we use the second approach. 118 lack mbrtowc(), we use the second approach.
119 The possible encodings are: 119 The possible encodings are:
120 - 8-bit encodings, 120 - 8-bit encodings,
121 - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, 121 - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
122 - UTF-8. 122 - UTF-8.
123 Use specialized code for each. */ 123 Use specialized code for each. */
124 if (m >= 4 || m >= MB_CUR_MAX) 124 if (m >= 4 || m >= MB_CUR_MAX)
125 goto invalid; 125 goto invalid;
126 /* Here MB_CUR_MAX > 1 and 0 < m < 4. */ 126 /* Here MB_CUR_MAX > 1 and 0 < m < 4. */
127 { 127 {
128 const char *encoding = locale_charset (); 128 const char *encoding = locale_charset ();
129 129
130 if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) 130 if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
131 { 131 {
132 /* Cf. unistr/u8-mblen.c. */ 132 /* Cf. unistr/u8-mblen.c. */
133 unsigned char c = (unsigned char) p[0]; 133 unsigned char c = (unsigned char) p[0];
134 134
135 if (c >= 0xc2) 135 if (c >= 0xc2)
136 { 136 {
137 if (c < 0xe0) 137 if (c < 0xe0)
138 { 138 {
139 if (m == 1) 139 if (m == 1)
140 goto incomplete; 140 goto incomplete;
141 } 141 }
142 else if (c < 0xf0) 142 else if (c < 0xf0)
143 { 143 {
144 if (m == 1) 144 if (m == 1)
145 goto incomplete; 145 goto incomplete;
146 if (m == 2) 146 if (m == 2)
147 { 147 {
148 unsigned char c2 = (unsigned char) p[1]; 148 unsigned char c2 = (unsigned char) p[1];
149 149
150 if ((c2 ^ 0x80) < 0x40 150 if ((c2 ^ 0x80) < 0x40
151 && (c >= 0xe1 || c2 >= 0xa0) 151 && (c >= 0xe1 || c2 >= 0xa0)
152 && (c != 0xed || c2 < 0xa0)) 152 && (c != 0xed || c2 < 0xa0))
153 goto incomplete; 153 goto incomplete;
154 } 154 }
155 } 155 }
156 else if (c <= 0xf4) 156 else if (c <= 0xf4)
157 { 157 {
158 if (m == 1) 158 if (m == 1)
159 goto incomplete; 159 goto incomplete;
160 else /* m == 2 || m == 3 */ 160 else /* m == 2 || m == 3 */
161 { 161 {
162 unsigned char c2 = (unsigned char) p[1]; 162 unsigned char c2 = (unsigned char) p[1];
163 163
164 if ((c2 ^ 0x80) < 0x40 164 if ((c2 ^ 0x80) < 0x40
165 && (c >= 0xf1 || c2 >= 0x90) 165 && (c >= 0xf1 || c2 >= 0x90)
166 && (c < 0xf4 || (c == 0xf4 && c2 < 0x90))) 166 && (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
167 { 167 {
168 if (m == 2) 168 if (m == 2)
169 goto incomplete; 169 goto incomplete;
170 else /* m == 3 */ 170 else /* m == 3 */
171 { 171 {
172 unsigned char c3 = (unsigned char) p[2]; 172 unsigned char c3 = (unsigned char) p[2];
173 173
174 if ((c3 ^ 0x80) < 0x40) 174 if ((c3 ^ 0x80) < 0x40)
175 goto incomplete; 175 goto incomplete;
176 } 176 }
177 } 177 }
178 } 178 }
179 } 179 }
180 } 180 }
181 goto invalid; 181 goto invalid;
182 } 182 }
183 183
184 /* As a reference for this code, you can use the GNU libiconv 184 /* As a reference for this code, you can use the GNU libiconv
185 implementation. Look for uses of the RET_TOOFEW macro. */ 185 implementation. Look for uses of the RET_TOOFEW macro. */
186 186
187 if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) 187 if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
188 { 188 {
189 if (m == 1) 189 if (m == 1)
190 { 190 {
191 unsigned char c = (unsigned char) p[0]; 191 unsigned char c = (unsigned char) p[0];
192 192
193 if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f) 193 if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
194 goto incomplete; 194 goto incomplete;
195 } 195 }
196 if (m == 2) 196 if (m == 2)
197 { 197 {
198 unsigned char c = (unsigned char) p[0]; 198 unsigned char c = (unsigned char) p[0];
199 199
200 if (c == 0x8f) 200 if (c == 0x8f)
201 { 201 {
202 unsigned char c2 = (unsigned char) p[1]; 202 unsigned char c2 = (unsigned char) p[1];
203 203
204 if (c2 >= 0xa1 && c2 < 0xff) 204 if (c2 >= 0xa1 && c2 < 0xff)
205 goto incomplete; 205 goto incomplete;
206 } 206 }
207 } 207 }
208 goto invalid; 208 goto invalid;
209 } 209 }
210 if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) 210 if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
211 || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) 211 || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
212 || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) 212 || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
213 { 213 {
214 if (m == 1) 214 if (m == 1)
215 { 215 {
216 unsigned char c = (unsigned char) p[0]; 216 unsigned char c = (unsigned char) p[0];
217 217
218 if (c >= 0xa1 && c < 0xff) 218 if (c >= 0xa1 && c < 0xff)
219 goto incomplete; 219 goto incomplete;
220 } 220 }
221 goto invalid; 221 goto invalid;
222 } 222 }
223 if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) 223 if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
224 { 224 {
225 if (m == 1) 225 if (m == 1)
226 { 226 {
227 unsigned char c = (unsigned char) p[0]; 227 unsigned char c = (unsigned char) p[0];
228 228
229 if ((c >= 0xa1 && c < 0xff) || c == 0x8e) 229 if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
230 goto incomplete; 230 goto incomplete;
231 } 231 }
232 else /* m == 2 || m == 3 */ 232 else /* m == 2 || m == 3 */
233 { 233 {
234 unsigned char c = (unsigned char) p[0]; 234 unsigned char c = (unsigned char) p[0];
235 235
236 if (c == 0x8e) 236 if (c == 0x8e)
237 goto incomplete; 237 goto incomplete;
238 } 238 }
239 goto invalid; 239 goto invalid;
240 } 240 }
241 if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) 241 if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
242 { 242 {
243 if (m == 1) 243 if (m == 1)
244 { 244 {
245 unsigned char c = (unsigned char) p[0]; 245 unsigned char c = (unsigned char) p[0];
246 246
247 if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) 247 if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
248 goto incomplete; 248 goto incomplete;
249 } 249 }
250 else /* m == 2 || m == 3 */ 250 else /* m == 2 || m == 3 */
251 { 251 {
252 unsigned char c = (unsigned char) p[0]; 252 unsigned char c = (unsigned char) p[0];
253 253
254 if (c >= 0x90 && c <= 0xe3) 254 if (c >= 0x90 && c <= 0xe3)
255 { 255 {
256 unsigned char c2 = (unsigned char) p[1]; 256 unsigned char c2 = (unsigned char) p[1];
257 257
258 if (c2 >= 0x30 && c2 <= 0x39) 258 if (c2 >= 0x30 && c2 <= 0x39)
259 { 259 {
260 if (m == 2) 260 if (m == 2)
261 goto incomplete; 261 goto incomplete;
262 else /* m == 3 */ 262 else /* m == 3 */
263 { 263 {
264 unsigned char c3 = (unsigned char) p[2]; 264 unsigned char c3 = (unsigned char) p[2];
265 265
266 if (c3 >= 0x81 && c3 <= 0xfe) 266 if (c3 >= 0x81 && c3 <= 0xfe)
267 goto incomplete; 267 goto incomplete;
268 } 268 }
269 } 269 }
270 } 270 }
271 } 271 }
272 goto invalid; 272 goto invalid;
273 } 273 }
274 if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) 274 if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
275 { 275 {
276 if (m == 1) 276 if (m == 1)
277 { 277 {
278 unsigned char c = (unsigned char) p[0]; 278 unsigned char c = (unsigned char) p[0];
279 279
280 if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) 280 if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
281 || (c >= 0xf0 && c <= 0xf9)) 281 || (c >= 0xf0 && c <= 0xf9))
282 goto incomplete; 282 goto incomplete;
283 } 283 }
284 goto invalid; 284 goto invalid;
285 } 285 }
286 286
287 /* An unknown multibyte encoding. */ 287 /* An unknown multibyte encoding. */
288 goto incomplete; 288 goto incomplete;
289 } 289 }
290 290
291 incomplete: 291 incomplete:
292 { 292 {
293 size_t k = nstate; 293 size_t k = nstate;
294 /* Here 0 <= k < m < 4. */ 294 /* Here 0 <= k < m < 4. */
295 pstate[++k] = s[0]; 295 pstate[++k] = s[0];
296 if (k < m) 296 if (k < m)
297 { 297 {
298 pstate[++k] = s[1]; 298 pstate[++k] = s[1];
299 if (k < m) 299 if (k < m)
300 pstate[++k] = s[2]; 300 pstate[++k] = s[2];
301 } 301 }
302 if (k != m) 302 if (k != m)
303 abort (); 303 abort ();
304 } 304 }
305 pstate[0] = m; 305 pstate[0] = m;
306 return (size_t)(-2); 306 return (size_t)(-2);
@@ -341,25 +341,25 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
341 341
342 if (!mbsinit (ps)) 342 if (!mbsinit (ps))
343 { 343 {
344 /* Parse the rest of the multibyte character byte for byte. */ 344 /* Parse the rest of the multibyte character byte for byte. */
345 size_t count = 0; 345 size_t count = 0;
346 for (; n > 0; s++, n--) 346 for (; n > 0; s++, n--)
347 { 347 {
348 wchar_t wc; 348 wchar_t wc;
349 size_t ret = mbrtowc (&wc, s, 1, ps); 349 size_t ret = mbrtowc (&wc, s, 1, ps);
350 350
351 if (ret == (size_t)(-1)) 351 if (ret == (size_t)(-1))
352 return (size_t)(-1); 352 return (size_t)(-1);
353 count++; 353 count++;
354 if (ret != (size_t)(-2)) 354 if (ret != (size_t)(-2))
355 { 355 {
356 /* The multibyte character has been completed. */ 356 /* The multibyte character has been completed. */
357 if (pwc != NULL) 357 if (pwc != NULL)
358 *pwc = wc; 358 *pwc = wc;
359 return (wc == 0 ? 0 : count); 359 return (wc == 0 ? 0 : count);
360 } 360 }
361 } 361 }
362 return (size_t)(-2); 362 return (size_t)(-2);
363 } 363 }
364 } 364 }
365# endif 365# endif
@@ -371,10 +371,10 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
371 371
372 if (ret != (size_t)(-1) && ret != (size_t)(-2)) 372 if (ret != (size_t)(-1) && ret != (size_t)(-2))
373 { 373 {
374 if (pwc != NULL) 374 if (pwc != NULL)
375 *pwc = wc; 375 *pwc = wc;
376 if (wc == 0) 376 if (wc == 0)
377 ret = 0; 377 ret = 0;
378 } 378 }
379 return ret; 379 return ret;
380 } 380 }
diff --git a/gl/mbsinit.c b/gl/mbsinit.c
index 81fed5a1..066ddfe5 100644
--- a/gl/mbsinit.c
+++ b/gl/mbsinit.c
@@ -1,5 +1,5 @@
1/* Test for initial conversion state. 1/* Test for initial conversion state.
2 Copyright (C) 2008 Free Software Foundation, Inc. 2 Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
diff --git a/gl/memchr.c b/gl/memchr.c
new file mode 100644
index 00000000..6c2b2d6c
--- /dev/null
+++ b/gl/memchr.c
@@ -0,0 +1,172 @@
1/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2010
2 Free Software Foundation, Inc.
3
4 Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
5 with help from Dan Sahlin (dan@sics.se) and
6 commentary by Jim Blandy (jimb@ai.mit.edu);
7 adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
8 and implemented by Roland McGrath (roland@ai.mit.edu).
9
10NOTE: The canonical source of this file is maintained with the GNU C Library.
11Bugs can be reported to bug-glibc@prep.ai.mit.edu.
12
13This program is free software: you can redistribute it and/or modify it
14under the terms of the GNU General Public License as published by the
15Free Software Foundation; either version 3 of the License, or any
16later version.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>. */
25
26#ifndef _LIBC
27# include <config.h>
28#endif
29
30#include <string.h>
31
32#include <stddef.h>
33
34#if defined _LIBC
35# include <memcopy.h>
36#else
37# define reg_char char
38#endif
39
40#include <limits.h>
41
42#if HAVE_BP_SYM_H || defined _LIBC
43# include <bp-sym.h>
44#else
45# define BP_SYM(sym) sym
46#endif
47
48#undef __memchr
49#ifdef _LIBC
50# undef memchr
51#endif
52
53#ifndef weak_alias
54# define __memchr memchr
55#endif
56
57/* Search no more than N bytes of S for C. */
58void *
59__memchr (void const *s, int c_in, size_t n)
60{
61 /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
62 long instead of a 64-bit uintmax_t tends to give better
63 performance. On 64-bit hardware, unsigned long is generally 64
64 bits already. Change this typedef to experiment with
65 performance. */
66 typedef unsigned long int longword;
67
68 const unsigned char *char_ptr;
69 const longword *longword_ptr;
70 longword repeated_one;
71 longword repeated_c;
72 unsigned reg_char c;
73
74 c = (unsigned char) c_in;
75
76 /* Handle the first few bytes by reading one byte at a time.
77 Do this until CHAR_PTR is aligned on a longword boundary. */
78 for (char_ptr = (const unsigned char *) s;
79 n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
80 --n, ++char_ptr)
81 if (*char_ptr == c)
82 return (void *) char_ptr;
83
84 longword_ptr = (const longword *) char_ptr;
85
86 /* All these elucidatory comments refer to 4-byte longwords,
87 but the theory applies equally well to any size longwords. */
88
89 /* Compute auxiliary longword values:
90 repeated_one is a value which has a 1 in every byte.
91 repeated_c has c in every byte. */
92 repeated_one = 0x01010101;
93 repeated_c = c | (c << 8);
94 repeated_c |= repeated_c << 16;
95 if (0xffffffffU < (longword) -1)
96 {
97 repeated_one |= repeated_one << 31 << 1;
98 repeated_c |= repeated_c << 31 << 1;
99 if (8 < sizeof (longword))
100 {
101 size_t i;
102
103 for (i = 64; i < sizeof (longword) * 8; i *= 2)
104 {
105 repeated_one |= repeated_one << i;
106 repeated_c |= repeated_c << i;
107 }
108 }
109 }
110
111 /* Instead of the traditional loop which tests each byte, we will test a
112 longword at a time. The tricky part is testing if *any of the four*
113 bytes in the longword in question are equal to c. We first use an xor
114 with repeated_c. This reduces the task to testing whether *any of the
115 four* bytes in longword1 is zero.
116
117 We compute tmp =
118 ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
119 That is, we perform the following operations:
120 1. Subtract repeated_one.
121 2. & ~longword1.
122 3. & a mask consisting of 0x80 in every byte.
123 Consider what happens in each byte:
124 - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
125 and step 3 transforms it into 0x80. A carry can also be propagated
126 to more significant bytes.
127 - If a byte of longword1 is nonzero, let its lowest 1 bit be at
128 position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
129 the byte ends in a single bit of value 0 and k bits of value 1.
130 After step 2, the result is just k bits of value 1: 2^k - 1. After
131 step 3, the result is 0. And no carry is produced.
132 So, if longword1 has only non-zero bytes, tmp is zero.
133 Whereas if longword1 has a zero byte, call j the position of the least
134 significant zero byte. Then the result has a zero at positions 0, ...,
135 j-1 and a 0x80 at position j. We cannot predict the result at the more
136 significant bytes (positions j+1..3), but it does not matter since we
137 already have a non-zero bit at position 8*j+7.
138
139 So, the test whether any byte in longword1 is zero is equivalent to
140 testing whether tmp is nonzero. */
141
142 while (n >= sizeof (longword))
143 {
144 longword longword1 = *longword_ptr ^ repeated_c;
145
146 if ((((longword1 - repeated_one) & ~longword1)
147 & (repeated_one << 7)) != 0)
148 break;
149 longword_ptr++;
150 n -= sizeof (longword);
151 }
152
153 char_ptr = (const unsigned char *) longword_ptr;
154
155 /* At this point, we know that either n < sizeof (longword), or one of the
156 sizeof (longword) bytes starting at char_ptr is == c. On little-endian
157 machines, we could determine the first such byte without any further
158 memory accesses, just by looking at the tmp result from the last loop
159 iteration. But this does not work on big-endian machines. Choose code
160 that works in both cases. */
161
162 for (; n > 0; --n, ++char_ptr)
163 {
164 if (*char_ptr == c)
165 return (void *) char_ptr;
166 }
167
168 return NULL;
169}
170#ifdef weak_alias
171weak_alias (__memchr, BP_SYM (memchr))
172#endif
diff --git a/gl/memchr.valgrind b/gl/memchr.valgrind
new file mode 100644
index 00000000..60f247e1
--- /dev/null
+++ b/gl/memchr.valgrind
@@ -0,0 +1,14 @@
1# Suppress a valgrind message about use of uninitialized memory in memchr().
2# POSIX states that when the character is found, memchr must not read extra
3# bytes in an overestimated length (for example, where memchr is used to
4# implement strnlen). However, we use a safe word read to provide a speedup.
5{
6 memchr-value4
7 Memcheck:Value4
8 fun:rpl_memchr
9}
10{
11 memchr-value8
12 Memcheck:Value8
13 fun:rpl_memchr
14}
diff --git a/gl/mktime-internal.h b/gl/mktime-internal.h
new file mode 100644
index 00000000..4287acf4
--- /dev/null
+++ b/gl/mktime-internal.h
@@ -0,0 +1,4 @@
1#include <time.h>
2time_t mktime_internal (struct tm *,
3 struct tm * (*) (time_t const *, struct tm *),
4 time_t *);
diff --git a/gl/mktime.c b/gl/mktime.c
index 0f30d43f..b0324b82 100644
--- a/gl/mktime.c
+++ b/gl/mktime.c
@@ -1,5 +1,5 @@
1/* Convert a `struct tm' to a time_t value. 1/* Convert a `struct tm' to a time_t value.
2 Copyright (C) 1993-1999, 2002-2005, 2006, 2007 Free Software Foundation, Inc. 2 Copyright (C) 1993-1999, 2002-2007, 2009-2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 Contributed by Paul Eggert <eggert@twinsun.com>. 4 Contributed by Paul Eggert <eggert@twinsun.com>.
5 5
@@ -36,7 +36,7 @@
36 36
37#include <limits.h> 37#include <limits.h>
38 38
39#include <string.h> /* For the real memcpy prototype. */ 39#include <string.h> /* For the real memcpy prototype. */
40 40
41#if DEBUG 41#if DEBUG
42# include <stdio.h> 42# include <stdio.h>
@@ -55,9 +55,9 @@
55 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift 55 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
56 right in the usual way when A < 0, so SHR falls back on division if 56 right in the usual way when A < 0, so SHR falls back on division if
57 ordinary A >> B doesn't seem to be the usual signed shift. */ 57 ordinary A >> B doesn't seem to be the usual signed shift. */
58#define SHR(a, b) \ 58#define SHR(a, b) \
59 (-1 >> 1 == -1 \ 59 (-1 >> 1 == -1 \
60 ? (a) >> (b) \ 60 ? (a) >> (b) \
61 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) 61 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
62 62
63/* The extra casts in the following macros work around compiler bugs, 63/* The extra casts in the following macros work around compiler bugs,
@@ -84,14 +84,14 @@
84 your host. */ 84 your host. */
85#define TYPE_MINIMUM(t) \ 85#define TYPE_MINIMUM(t) \
86 ((t) (! TYPE_SIGNED (t) \ 86 ((t) (! TYPE_SIGNED (t) \
87 ? (t) 0 \ 87 ? (t) 0 \
88 : TYPE_SIGNED_MAGNITUDE (t) \ 88 : TYPE_SIGNED_MAGNITUDE (t) \
89 ? ~ (t) 0 \ 89 ? ~ (t) 0 \
90 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) 90 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
91#define TYPE_MAXIMUM(t) \ 91#define TYPE_MAXIMUM(t) \
92 ((t) (! TYPE_SIGNED (t) \ 92 ((t) (! TYPE_SIGNED (t) \
93 ? (t) -1 \ 93 ? (t) -1 \
94 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) 94 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
95 95
96#ifndef TIME_T_MIN 96#ifndef TIME_T_MIN
97# define TIME_T_MIN TYPE_MINIMUM (time_t) 97# define TIME_T_MIN TYPE_MINIMUM (time_t)
@@ -123,7 +123,7 @@ leapyear (long int year)
123 return 123 return
124 ((year & 3) == 0 124 ((year & 3) == 0
125 && (year % 100 != 0 125 && (year % 100 != 0
126 || ((year / 100) & 3) == (- (TM_YEAR_BASE / 100) & 3))); 126 || ((year / 100) & 3) == (- (TM_YEAR_BASE / 100) & 3)));
127} 127}
128 128
129/* How many days come before each month (0-12). */ 129/* How many days come before each month (0-12). */
@@ -147,6 +147,7 @@ const unsigned short int __mon_yday[2][13] =
147# undef __localtime_r 147# undef __localtime_r
148# define __localtime_r localtime_r 148# define __localtime_r localtime_r
149# define __mktime_internal mktime_internal 149# define __mktime_internal mktime_internal
150# include "mktime-internal.h"
150#endif 151#endif
151 152
152/* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) - 153/* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) -
@@ -162,11 +163,14 @@ const unsigned short int __mon_yday[2][13] =
162 163
163static inline time_t 164static inline time_t
164ydhms_diff (long int year1, long int yday1, int hour1, int min1, int sec1, 165ydhms_diff (long int year1, long int yday1, int hour1, int min1, int sec1,
165 int year0, int yday0, int hour0, int min0, int sec0) 166 int year0, int yday0, int hour0, int min0, int sec0)
166{ 167{
167 verify (C99_integer_division, -1 / 2 == 0); 168 verify (C99_integer_division, -1 / 2 == 0);
169#if 0 /* This assertion fails on 32-bit systems with 64-bit time_t, such as
170 NetBSD 5 on i386. */
168 verify (long_int_year_and_yday_are_wide_enough, 171 verify (long_int_year_and_yday_are_wide_enough,
169 INT_MAX <= LONG_MAX / 2 || TIME_T_MAX <= UINT_MAX); 172 INT_MAX <= LONG_MAX / 2 || TIME_T_MAX <= UINT_MAX);
173#endif
170 174
171 /* Compute intervening leap days correctly even if year is negative. 175 /* Compute intervening leap days correctly even if year is negative.
172 Take care to avoid integer overflow here. */ 176 Take care to avoid integer overflow here. */
@@ -198,16 +202,16 @@ ydhms_diff (long int year1, long int yday1, int hour1, int min1, int sec1,
198 yield a value equal to *T. */ 202 yield a value equal to *T. */
199static time_t 203static time_t
200guess_time_tm (long int year, long int yday, int hour, int min, int sec, 204guess_time_tm (long int year, long int yday, int hour, int min, int sec,
201 const time_t *t, const struct tm *tp) 205 const time_t *t, const struct tm *tp)
202{ 206{
203 if (tp) 207 if (tp)
204 { 208 {
205 time_t d = ydhms_diff (year, yday, hour, min, sec, 209 time_t d = ydhms_diff (year, yday, hour, min, sec,
206 tp->tm_year, tp->tm_yday, 210 tp->tm_year, tp->tm_yday,
207 tp->tm_hour, tp->tm_min, tp->tm_sec); 211 tp->tm_hour, tp->tm_min, tp->tm_sec);
208 time_t t1 = *t + d; 212 time_t t1 = *t + d;
209 if ((t1 < *t) == (TYPE_SIGNED (time_t) ? d < 0 : TIME_T_MAX / 2 < d)) 213 if ((t1 < *t) == (TYPE_SIGNED (time_t) ? d < 0 : TIME_T_MAX / 2 < d))
210 return t1; 214 return t1;
211 } 215 }
212 216
213 /* Overflow occurred one way or another. Return the nearest result 217 /* Overflow occurred one way or another. Return the nearest result
@@ -216,8 +220,8 @@ guess_time_tm (long int year, long int yday, int hour, int min, int sec,
216 match; and don't oscillate between two values, as that would 220 match; and don't oscillate between two values, as that would
217 confuse the spring-forward gap detector. */ 221 confuse the spring-forward gap detector. */
218 return (*t < TIME_T_MIDPOINT 222 return (*t < TIME_T_MIDPOINT
219 ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) 223 ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN)
220 : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); 224 : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX));
221} 225}
222 226
223/* Use CONVERT to convert *T to a broken down time in *TP. 227/* Use CONVERT to convert *T to a broken down time in *TP.
@@ -225,7 +229,7 @@ guess_time_tm (long int year, long int yday, int hour, int min, int sec,
225 it is the nearest in-range value and then convert that. */ 229 it is the nearest in-range value and then convert that. */
226static struct tm * 230static struct tm *
227ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), 231ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
228 time_t *t, struct tm *tp) 232 time_t *t, struct tm *tp)
229{ 233{
230 struct tm *r = convert (t, tp); 234 struct tm *r = convert (t, tp);
231 235
@@ -235,27 +239,27 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
235 time_t ok = 0; 239 time_t ok = 0;
236 240
237 /* BAD is a known unconvertible time_t, and OK is a known good one. 241 /* BAD is a known unconvertible time_t, and OK is a known good one.
238 Use binary search to narrow the range between BAD and OK until 242 Use binary search to narrow the range between BAD and OK until
239 they differ by 1. */ 243 they differ by 1. */
240 while (bad != ok + (bad < 0 ? -1 : 1)) 244 while (bad != ok + (bad < 0 ? -1 : 1))
241 { 245 {
242 time_t mid = *t = (bad < 0 246 time_t mid = *t = (bad < 0
243 ? bad + ((ok - bad) >> 1) 247 ? bad + ((ok - bad) >> 1)
244 : ok + ((bad - ok) >> 1)); 248 : ok + ((bad - ok) >> 1));
245 r = convert (t, tp); 249 r = convert (t, tp);
246 if (r) 250 if (r)
247 ok = mid; 251 ok = mid;
248 else 252 else
249 bad = mid; 253 bad = mid;
250 } 254 }
251 255
252 if (!r && ok) 256 if (!r && ok)
253 { 257 {
254 /* The last conversion attempt failed; 258 /* The last conversion attempt failed;
255 revert to the most recent successful attempt. */ 259 revert to the most recent successful attempt. */
256 *t = ok; 260 *t = ok;
257 r = convert (t, tp); 261 r = convert (t, tp);
258 } 262 }
259 } 263 }
260 264
261 return r; 265 return r;
@@ -270,8 +274,8 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
270 This function is external because it is used also by timegm.c. */ 274 This function is external because it is used also by timegm.c. */
271time_t 275time_t
272__mktime_internal (struct tm *tp, 276__mktime_internal (struct tm *tp,
273 struct tm *(*convert) (const time_t *, struct tm *), 277 struct tm *(*convert) (const time_t *, struct tm *),
274 time_t *offset) 278 time_t *offset)
275{ 279{
276 time_t t, gt, t0, t1, t2; 280 time_t t, gt, t0, t1, t2;
277 struct tm tm; 281 struct tm tm;
@@ -292,7 +296,7 @@ __mktime_internal (struct tm *tp,
292 int year_requested = tp->tm_year; 296 int year_requested = tp->tm_year;
293 /* Normalize the value. */ 297 /* Normalize the value. */
294 int isdst = ((tp->tm_isdst >> (8 * sizeof (tp->tm_isdst) - 1)) 298 int isdst = ((tp->tm_isdst >> (8 * sizeof (tp->tm_isdst) - 1))
295 | (tp->tm_isdst != 0)); 299 | (tp->tm_isdst != 0));
296 300
297 /* 1 if the previous probe was DST. */ 301 /* 1 if the previous probe was DST. */
298 int dst2; 302 int dst2;
@@ -312,8 +316,8 @@ __mktime_internal (struct tm *tp,
312 /* Calculate day of year from year, month, and day of month. 316 /* Calculate day of year from year, month, and day of month.
313 The result need not be in range. */ 317 The result need not be in range. */
314 int mon_yday = ((__mon_yday[leapyear (year)] 318 int mon_yday = ((__mon_yday[leapyear (year)]
315 [mon_remainder + 12 * negative_mon_remainder]) 319 [mon_remainder + 12 * negative_mon_remainder])
316 - 1); 320 - 1);
317 long int lmday = mday; 321 long int lmday = mday;
318 long int yday = mon_yday + lmday; 322 long int yday = mon_yday + lmday;
319 323
@@ -324,33 +328,33 @@ __mktime_internal (struct tm *tp,
324 if (LEAP_SECONDS_POSSIBLE) 328 if (LEAP_SECONDS_POSSIBLE)
325 { 329 {
326 /* Handle out-of-range seconds specially, 330 /* Handle out-of-range seconds specially,
327 since ydhms_tm_diff assumes every minute has 60 seconds. */ 331 since ydhms_tm_diff assumes every minute has 60 seconds. */
328 if (sec < 0) 332 if (sec < 0)
329 sec = 0; 333 sec = 0;
330 if (59 < sec) 334 if (59 < sec)
331 sec = 59; 335 sec = 59;
332 } 336 }
333 337
334 /* Invert CONVERT by probing. First assume the same offset as last 338 /* Invert CONVERT by probing. First assume the same offset as last
335 time. */ 339 time. */
336 340
337 t0 = ydhms_diff (year, yday, hour, min, sec, 341 t0 = ydhms_diff (year, yday, hour, min, sec,
338 EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset); 342 EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset);
339 343
340 if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3) 344 if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3)
341 { 345 {
342 /* time_t isn't large enough to rule out overflows, so check 346 /* time_t isn't large enough to rule out overflows, so check
343 for major overflows. A gross check suffices, since if t0 347 for major overflows. A gross check suffices, since if t0
344 has overflowed, it is off by a multiple of TIME_T_MAX - 348 has overflowed, it is off by a multiple of TIME_T_MAX -
345 TIME_T_MIN + 1. So ignore any component of the difference 349 TIME_T_MIN + 1. So ignore any component of the difference
346 that is bounded by a small value. */ 350 that is bounded by a small value. */
347 351
348 /* Approximate log base 2 of the number of time units per 352 /* Approximate log base 2 of the number of time units per
349 biennium. A biennium is 2 years; use this unit instead of 353 biennium. A biennium is 2 years; use this unit instead of
350 years to avoid integer overflow. For example, 2 average 354 years to avoid integer overflow. For example, 2 average
351 Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds, 355 Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds,
352 which is 63113904 seconds, and rint (log2 (63113904)) is 356 which is 63113904 seconds, and rint (log2 (63113904)) is
353 26. */ 357 26. */
354 int ALOG2_SECONDS_PER_BIENNIUM = 26; 358 int ALOG2_SECONDS_PER_BIENNIUM = 26;
355 int ALOG2_MINUTES_PER_BIENNIUM = 20; 359 int ALOG2_MINUTES_PER_BIENNIUM = 20;
356 int ALOG2_HOURS_PER_BIENNIUM = 14; 360 int ALOG2_HOURS_PER_BIENNIUM = 14;
@@ -358,64 +362,64 @@ __mktime_internal (struct tm *tp,
358 int LOG2_YEARS_PER_BIENNIUM = 1; 362 int LOG2_YEARS_PER_BIENNIUM = 1;
359 363
360 int approx_requested_biennia = 364 int approx_requested_biennia =
361 (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM) 365 (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM)
362 - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM) 366 - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM)
363 + SHR (mday, ALOG2_DAYS_PER_BIENNIUM) 367 + SHR (mday, ALOG2_DAYS_PER_BIENNIUM)
364 + SHR (hour, ALOG2_HOURS_PER_BIENNIUM) 368 + SHR (hour, ALOG2_HOURS_PER_BIENNIUM)
365 + SHR (min, ALOG2_MINUTES_PER_BIENNIUM) 369 + SHR (min, ALOG2_MINUTES_PER_BIENNIUM)
366 + (LEAP_SECONDS_POSSIBLE 370 + (LEAP_SECONDS_POSSIBLE
367 ? 0 371 ? 0
368 : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM))); 372 : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM)));
369 373
370 int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM); 374 int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM);
371 int diff = approx_biennia - approx_requested_biennia; 375 int diff = approx_biennia - approx_requested_biennia;
372 int abs_diff = diff < 0 ? - diff : diff; 376 int abs_diff = diff < 0 ? - diff : diff;
373 377
374 /* IRIX 4.0.5 cc miscaculates TIME_T_MIN / 3: it erroneously 378 /* IRIX 4.0.5 cc miscaculates TIME_T_MIN / 3: it erroneously
375 gives a positive value of 715827882. Setting a variable 379 gives a positive value of 715827882. Setting a variable
376 first then doing math on it seems to work. 380 first then doing math on it seems to work.
377 (ghazi@caip.rutgers.edu) */ 381 (ghazi@caip.rutgers.edu) */
378 time_t time_t_max = TIME_T_MAX; 382 time_t time_t_max = TIME_T_MAX;
379 time_t time_t_min = TIME_T_MIN; 383 time_t time_t_min = TIME_T_MIN;
380 time_t overflow_threshold = 384 time_t overflow_threshold =
381 (time_t_max / 3 - time_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM; 385 (time_t_max / 3 - time_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM;
382 386
383 if (overflow_threshold < abs_diff) 387 if (overflow_threshold < abs_diff)
384 { 388 {
385 /* Overflow occurred. Try repairing it; this might work if 389 /* Overflow occurred. Try repairing it; this might work if
386 the time zone offset is enough to undo the overflow. */ 390 the time zone offset is enough to undo the overflow. */
387 time_t repaired_t0 = -1 - t0; 391 time_t repaired_t0 = -1 - t0;
388 approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM); 392 approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM);
389 diff = approx_biennia - approx_requested_biennia; 393 diff = approx_biennia - approx_requested_biennia;
390 abs_diff = diff < 0 ? - diff : diff; 394 abs_diff = diff < 0 ? - diff : diff;
391 if (overflow_threshold < abs_diff) 395 if (overflow_threshold < abs_diff)
392 return -1; 396 return -1;
393 guessed_offset += repaired_t0 - t0; 397 guessed_offset += repaired_t0 - t0;
394 t0 = repaired_t0; 398 t0 = repaired_t0;
395 } 399 }
396 } 400 }
397 401
398 /* Repeatedly use the error to improve the guess. */ 402 /* Repeatedly use the error to improve the guess. */
399 403
400 for (t = t1 = t2 = t0, dst2 = 0; 404 for (t = t1 = t2 = t0, dst2 = 0;
401 (gt = guess_time_tm (year, yday, hour, min, sec, &t, 405 (gt = guess_time_tm (year, yday, hour, min, sec, &t,
402 ranged_convert (convert, &t, &tm)), 406 ranged_convert (convert, &t, &tm)),
403 t != gt); 407 t != gt);
404 t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0) 408 t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0)
405 if (t == t1 && t != t2 409 if (t == t1 && t != t2
406 && (tm.tm_isdst < 0 410 && (tm.tm_isdst < 0
407 || (isdst < 0 411 || (isdst < 0
408 ? dst2 <= (tm.tm_isdst != 0) 412 ? dst2 <= (tm.tm_isdst != 0)
409 : (isdst != 0) != (tm.tm_isdst != 0)))) 413 : (isdst != 0) != (tm.tm_isdst != 0))))
410 /* We can't possibly find a match, as we are oscillating 414 /* We can't possibly find a match, as we are oscillating
411 between two values. The requested time probably falls 415 between two values. The requested time probably falls
412 within a spring-forward gap of size GT - T. Follow the common 416 within a spring-forward gap of size GT - T. Follow the common
413 practice in this case, which is to return a time that is GT - T 417 practice in this case, which is to return a time that is GT - T
414 away from the requested time, preferring a time whose 418 away from the requested time, preferring a time whose
415 tm_isdst differs from the requested value. (If no tm_isdst 419 tm_isdst differs from the requested value. (If no tm_isdst
416 was requested and only one of the two values has a nonzero 420 was requested and only one of the two values has a nonzero
417 tm_isdst, prefer that value.) In practice, this is more 421 tm_isdst, prefer that value.) In practice, this is more
418 useful than returning -1. */ 422 useful than returning -1. */
419 goto offset_found; 423 goto offset_found;
420 else if (--remaining_probes == 0) 424 else if (--remaining_probes == 0)
421 return -1; 425 return -1;
@@ -425,52 +429,52 @@ __mktime_internal (struct tm *tp,
425 if (isdst != tm.tm_isdst && 0 <= isdst && 0 <= tm.tm_isdst) 429 if (isdst != tm.tm_isdst && 0 <= isdst && 0 <= tm.tm_isdst)
426 { 430 {
427 /* tm.tm_isdst has the wrong value. Look for a neighboring 431 /* tm.tm_isdst has the wrong value. Look for a neighboring
428 time with the right value, and use its UTC offset. 432 time with the right value, and use its UTC offset.
429 433
430 Heuristic: probe the adjacent timestamps in both directions, 434 Heuristic: probe the adjacent timestamps in both directions,
431 looking for the desired isdst. This should work for all real 435 looking for the desired isdst. This should work for all real
432 time zone histories in the tz database. */ 436 time zone histories in the tz database. */
433 437
434 /* Distance between probes when looking for a DST boundary. In 438 /* Distance between probes when looking for a DST boundary. In
435 tzdata2003a, the shortest period of DST is 601200 seconds 439 tzdata2003a, the shortest period of DST is 601200 seconds
436 (e.g., America/Recife starting 2000-10-08 01:00), and the 440 (e.g., America/Recife starting 2000-10-08 01:00), and the
437 shortest period of non-DST surrounded by DST is 694800 441 shortest period of non-DST surrounded by DST is 694800
438 seconds (Africa/Tunis starting 1943-04-17 01:00). Use the 442 seconds (Africa/Tunis starting 1943-04-17 01:00). Use the
439 minimum of these two values, so we don't miss these short 443 minimum of these two values, so we don't miss these short
440 periods when probing. */ 444 periods when probing. */
441 int stride = 601200; 445 int stride = 601200;
442 446
443 /* The longest period of DST in tzdata2003a is 536454000 seconds 447 /* The longest period of DST in tzdata2003a is 536454000 seconds
444 (e.g., America/Jujuy starting 1946-10-01 01:00). The longest 448 (e.g., America/Jujuy starting 1946-10-01 01:00). The longest
445 period of non-DST is much longer, but it makes no real sense 449 period of non-DST is much longer, but it makes no real sense
446 to search for more than a year of non-DST, so use the DST 450 to search for more than a year of non-DST, so use the DST
447 max. */ 451 max. */
448 int duration_max = 536454000; 452 int duration_max = 536454000;
449 453
450 /* Search in both directions, so the maximum distance is half 454 /* Search in both directions, so the maximum distance is half
451 the duration; add the stride to avoid off-by-1 problems. */ 455 the duration; add the stride to avoid off-by-1 problems. */
452 int delta_bound = duration_max / 2 + stride; 456 int delta_bound = duration_max / 2 + stride;
453 457
454 int delta, direction; 458 int delta, direction;
455 459
456 for (delta = stride; delta < delta_bound; delta += stride) 460 for (delta = stride; delta < delta_bound; delta += stride)
457 for (direction = -1; direction <= 1; direction += 2) 461 for (direction = -1; direction <= 1; direction += 2)
458 { 462 {
459 time_t ot = t + delta * direction; 463 time_t ot = t + delta * direction;
460 if ((ot < t) == (direction < 0)) 464 if ((ot < t) == (direction < 0))
461 { 465 {
462 struct tm otm; 466 struct tm otm;
463 ranged_convert (convert, &ot, &otm); 467 ranged_convert (convert, &ot, &otm);
464 if (otm.tm_isdst == isdst) 468 if (otm.tm_isdst == isdst)
465 { 469 {
466 /* We found the desired tm_isdst. 470 /* We found the desired tm_isdst.
467 Extrapolate back to the desired time. */ 471 Extrapolate back to the desired time. */
468 t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm); 472 t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm);
469 ranged_convert (convert, &t, &tm); 473 ranged_convert (convert, &t, &tm);
470 goto offset_found; 474 goto offset_found;
471 } 475 }
472 } 476 }
473 } 477 }
474 } 478 }
475 479
476 offset_found: 480 offset_found:
@@ -479,14 +483,14 @@ __mktime_internal (struct tm *tp,
479 if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) 483 if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec)
480 { 484 {
481 /* Adjust time to reflect the tm_sec requested, not the normalized value. 485 /* Adjust time to reflect the tm_sec requested, not the normalized value.
482 Also, repair any damage from a false match due to a leap second. */ 486 Also, repair any damage from a false match due to a leap second. */
483 int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec; 487 int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec;
484 t1 = t + sec_requested; 488 t1 = t + sec_requested;
485 t2 = t1 + sec_adjustment; 489 t2 = t1 + sec_adjustment;
486 if (((t1 < t) != (sec_requested < 0)) 490 if (((t1 < t) != (sec_requested < 0))
487 | ((t2 < t1) != (sec_adjustment < 0)) 491 | ((t2 < t1) != (sec_adjustment < 0))
488 | ! convert (&t2, &tm)) 492 | ! convert (&t2, &tm))
489 return -1; 493 return -1;
490 t = t2; 494 t = t2;
491 } 495 }
492 496
@@ -530,13 +534,13 @@ static int
530not_equal_tm (const struct tm *a, const struct tm *b) 534not_equal_tm (const struct tm *a, const struct tm *b)
531{ 535{
532 return ((a->tm_sec ^ b->tm_sec) 536 return ((a->tm_sec ^ b->tm_sec)
533 | (a->tm_min ^ b->tm_min) 537 | (a->tm_min ^ b->tm_min)
534 | (a->tm_hour ^ b->tm_hour) 538 | (a->tm_hour ^ b->tm_hour)
535 | (a->tm_mday ^ b->tm_mday) 539 | (a->tm_mday ^ b->tm_mday)
536 | (a->tm_mon ^ b->tm_mon) 540 | (a->tm_mon ^ b->tm_mon)
537 | (a->tm_year ^ b->tm_year) 541 | (a->tm_year ^ b->tm_year)
538 | (a->tm_yday ^ b->tm_yday) 542 | (a->tm_yday ^ b->tm_yday)
539 | (a->tm_isdst ^ b->tm_isdst)); 543 | (a->tm_isdst ^ b->tm_isdst));
540} 544}
541 545
542static void 546static void
@@ -544,9 +548,9 @@ print_tm (const struct tm *tp)
544{ 548{
545 if (tp) 549 if (tp)
546 printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d", 550 printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d",
547 tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday, 551 tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday,
548 tp->tm_hour, tp->tm_min, tp->tm_sec, 552 tp->tm_hour, tp->tm_min, tp->tm_sec,
549 tp->tm_yday, tp->tm_wday, tp->tm_isdst); 553 tp->tm_yday, tp->tm_wday, tp->tm_isdst);
550 else 554 else
551 printf ("0"); 555 printf ("0");
552} 556}
@@ -578,11 +582,11 @@ main (int argc, char **argv)
578 582
579 if ((argc == 3 || argc == 4) 583 if ((argc == 3 || argc == 4)
580 && (sscanf (argv[1], "%d-%d-%d%c", 584 && (sscanf (argv[1], "%d-%d-%d%c",
581 &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer) 585 &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer)
582 == 3) 586 == 3)
583 && (sscanf (argv[2], "%d:%d:%d%c", 587 && (sscanf (argv[2], "%d:%d:%d%c",
584 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer) 588 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer)
585 == 3)) 589 == 3))
586 { 590 {
587 tm.tm_year -= TM_YEAR_BASE; 591 tm.tm_year -= TM_YEAR_BASE;
588 tm.tm_mon--; 592 tm.tm_mon--;
@@ -591,10 +595,10 @@ main (int argc, char **argv)
591 tl = mktime (&tmk); 595 tl = mktime (&tmk);
592 lt = localtime (&tl); 596 lt = localtime (&tl);
593 if (lt) 597 if (lt)
594 { 598 {
595 tml = *lt; 599 tml = *lt;
596 lt = &tml; 600 lt = &tml;
597 } 601 }
598 printf ("mktime returns %ld == ", (long int) tl); 602 printf ("mktime returns %ld == ", (long int) tl);
599 print_tm (&tmk); 603 print_tm (&tmk);
600 printf ("\n"); 604 printf ("\n");
@@ -607,51 +611,51 @@ main (int argc, char **argv)
607 time_t to = atol (argv[3]); 611 time_t to = atol (argv[3]);
608 612
609 if (argc == 4) 613 if (argc == 4)
610 for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) 614 for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
611 { 615 {
612 lt = localtime (&tl); 616 lt = localtime (&tl);
613 if (lt) 617 if (lt)
614 { 618 {
615 tmk = tml = *lt; 619 tmk = tml = *lt;
616 tk = mktime (&tmk); 620 tk = mktime (&tmk);
617 status |= check_result (tk, tmk, tl, &tml); 621 status |= check_result (tk, tmk, tl, &tml);
618 } 622 }
619 else 623 else
620 { 624 {
621 printf ("localtime (%ld) yields 0\n", (long int) tl); 625 printf ("localtime (%ld) yields 0\n", (long int) tl);
622 status = 1; 626 status = 1;
623 } 627 }
624 tl1 = tl + by; 628 tl1 = tl + by;
625 if ((tl1 < tl) != (by < 0)) 629 if ((tl1 < tl) != (by < 0))
626 break; 630 break;
627 } 631 }
628 else 632 else
629 for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) 633 for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
630 { 634 {
631 /* Null benchmark. */ 635 /* Null benchmark. */
632 lt = localtime (&tl); 636 lt = localtime (&tl);
633 if (lt) 637 if (lt)
634 { 638 {
635 tmk = tml = *lt; 639 tmk = tml = *lt;
636 tk = tl; 640 tk = tl;
637 status |= check_result (tk, tmk, tl, &tml); 641 status |= check_result (tk, tmk, tl, &tml);
638 } 642 }
639 else 643 else
640 { 644 {
641 printf ("localtime (%ld) yields 0\n", (long int) tl); 645 printf ("localtime (%ld) yields 0\n", (long int) tl);
642 status = 1; 646 status = 1;
643 } 647 }
644 tl1 = tl + by; 648 tl1 = tl + by;
645 if ((tl1 < tl) != (by < 0)) 649 if ((tl1 < tl) != (by < 0))
646 break; 650 break;
647 } 651 }
648 } 652 }
649 else 653 else
650 printf ("Usage:\ 654 printf ("Usage:\
651\t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\ 655\t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\
652\t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\ 656\t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\
653\t%s FROM BY TO - # Do not test those values (for benchmark).\n", 657\t%s FROM BY TO - # Do not test those values (for benchmark).\n",
654 argv[0], argv[0], argv[0]); 658 argv[0], argv[0], argv[0]);
655 659
656 return status; 660 return status;
657} 661}
diff --git a/gl/mountlist.c b/gl/mountlist.c
index 50e90eed..996b71a1 100644
--- a/gl/mountlist.c
+++ b/gl/mountlist.c
@@ -1,6 +1,6 @@
1/* mountlist.c -- return a list of mounted file systems 1/* mountlist.c -- return a list of mounted file systems
2 2
3 Copyright (C) 1991, 1992, 1997-2009 Free Software Foundation, Inc. 3 Copyright (C) 1991-1992, 1997-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -37,10 +37,10 @@
37# include <sys/param.h> 37# include <sys/param.h>
38#endif 38#endif
39 39
40#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ 40#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */
41# if HAVE_SYS_UCRED_H 41# if HAVE_SYS_UCRED_H
42# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS, 42# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS,
43 NGROUPS is used as an array dimension in ucred.h */ 43 NGROUPS is used as an array dimension in ucred.h */
44# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */ 44# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
45# endif 45# endif
46# if HAVE_SYS_MOUNT_H 46# if HAVE_SYS_MOUNT_H
@@ -56,44 +56,44 @@
56# endif 56# endif
57#endif /* MOUNTED_GETFSSTAT */ 57#endif /* MOUNTED_GETFSSTAT */
58 58
59#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ 59#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
60# include <mntent.h> 60# include <mntent.h>
61# if !defined MOUNTED 61# if !defined MOUNTED
62# if defined _PATH_MOUNTED /* GNU libc */ 62# if defined _PATH_MOUNTED /* GNU libc */
63# define MOUNTED _PATH_MOUNTED 63# define MOUNTED _PATH_MOUNTED
64# endif 64# endif
65# if defined MNT_MNTTAB /* HP-UX. */ 65# if defined MNT_MNTTAB /* HP-UX. */
66# define MOUNTED MNT_MNTTAB 66# define MOUNTED MNT_MNTTAB
67# endif 67# endif
68# if defined MNTTABNAME /* Dynix. */ 68# if defined MNTTABNAME /* Dynix. */
69# define MOUNTED MNTTABNAME 69# define MOUNTED MNTTABNAME
70# endif 70# endif
71# endif 71# endif
72#endif 72#endif
73 73
74#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ 74#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
75# include <sys/mount.h> 75# include <sys/mount.h>
76#endif 76#endif
77 77
78#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ 78#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */
79# include <sys/statvfs.h> 79# include <sys/statvfs.h>
80#endif 80#endif
81 81
82#ifdef MOUNTED_GETMNT /* Ultrix. */ 82#ifdef MOUNTED_GETMNT /* Ultrix. */
83# include <sys/mount.h> 83# include <sys/mount.h>
84# include <sys/fs_types.h> 84# include <sys/fs_types.h>
85#endif 85#endif
86 86
87#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */ 87#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */
88# include <fs_info.h> 88# include <fs_info.h>
89# include <dirent.h> 89# include <dirent.h>
90#endif 90#endif
91 91
92#ifdef MOUNTED_FREAD /* SVR2. */ 92#ifdef MOUNTED_FREAD /* SVR2. */
93# include <mnttab.h> 93# include <mnttab.h>
94#endif 94#endif
95 95
96#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */ 96#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
97# include <mnttab.h> 97# include <mnttab.h>
98# include <sys/fstyp.h> 98# include <sys/fstyp.h>
99# include <sys/statfs.h> 99# include <sys/statfs.h>
@@ -103,11 +103,11 @@
103# include <mntent.h> 103# include <mntent.h>
104#endif 104#endif
105 105
106#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ 106#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
107# include <sys/mnttab.h> 107# include <sys/mnttab.h>
108#endif 108#endif
109 109
110#ifdef MOUNTED_VMOUNT /* AIX. */ 110#ifdef MOUNTED_VMOUNT /* AIX. */
111# include <fshelp.h> 111# include <fshelp.h>
112# include <sys/vfs.h> 112# include <sys/vfs.h>
113#endif 113#endif
@@ -125,7 +125,7 @@
125 125
126#undef MNT_IGNORE 126#undef MNT_IGNORE
127#if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT 127#if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT
128# define MNT_IGNORE(M) hasmntopt ((M), MNTOPT_IGNORE) 128# define MNT_IGNORE(M) hasmntopt (M, MNTOPT_IGNORE)
129#else 129#else
130# define MNT_IGNORE(M) 0 130# define MNT_IGNORE(M) 0
131#endif 131#endif
@@ -145,26 +145,26 @@
145#undef closedir 145#undef closedir
146 146
147#ifndef ME_DUMMY 147#ifndef ME_DUMMY
148# define ME_DUMMY(Fs_name, Fs_type) \ 148# define ME_DUMMY(Fs_name, Fs_type) \
149 (strcmp (Fs_type, "autofs") == 0 \ 149 (strcmp (Fs_type, "autofs") == 0 \
150 || strcmp (Fs_type, "none") == 0 \ 150 || strcmp (Fs_type, "none") == 0 \
151 || strcmp (Fs_type, "proc") == 0 \ 151 || strcmp (Fs_type, "proc") == 0 \
152 || strcmp (Fs_type, "subfs") == 0 \ 152 || strcmp (Fs_type, "subfs") == 0 \
153 /* for NetBSD 3.0 */ \ 153 /* for NetBSD 3.0 */ \
154 || strcmp (Fs_type, "kernfs") == 0 \ 154 || strcmp (Fs_type, "kernfs") == 0 \
155 /* for Irix 6.5 */ \ 155 /* for Irix 6.5 */ \
156 || strcmp (Fs_type, "ignore") == 0) 156 || strcmp (Fs_type, "ignore") == 0)
157#endif 157#endif
158 158
159#ifndef ME_REMOTE 159#ifndef ME_REMOTE
160/* A file system is `remote' if its Fs_name contains a `:' 160/* A file system is `remote' if its Fs_name contains a `:'
161 or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */ 161 or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */
162# define ME_REMOTE(Fs_name, Fs_type) \ 162# define ME_REMOTE(Fs_name, Fs_type) \
163 (strchr (Fs_name, ':') != NULL \ 163 (strchr (Fs_name, ':') != NULL \
164 || ((Fs_name)[0] == '/' \ 164 || ((Fs_name)[0] == '/' \
165 && (Fs_name)[1] == '/' \ 165 && (Fs_name)[1] == '/' \
166 && (strcmp (Fs_type, "smbfs") == 0 \ 166 && (strcmp (Fs_type, "smbfs") == 0 \
167 || strcmp (Fs_type, "cifs") == 0))) 167 || strcmp (Fs_type, "cifs") == 0)))
168#endif 168#endif
169 169
170#if MOUNTED_GETMNTINFO 170#if MOUNTED_GETMNTINFO
@@ -277,7 +277,7 @@ fsp_to_string (const struct statfs *fsp)
277 277
278#endif /* MOUNTED_GETMNTINFO */ 278#endif /* MOUNTED_GETMNTINFO */
279 279
280#ifdef MOUNTED_VMOUNT /* AIX. */ 280#ifdef MOUNTED_VMOUNT /* AIX. */
281static char * 281static char *
282fstype_to_string (int t) 282fstype_to_string (int t)
283{ 283{
@@ -315,10 +315,10 @@ dev_from_mount_options (char const *mount_options)
315 errno = 0; 315 errno = 0;
316 dev = strtoul (optval, &optvalend, 16); 316 dev = strtoul (optval, &optvalend, 16);
317 if (optval != optvalend 317 if (optval != optvalend
318 && (*optvalend == '\0' || *optvalend == ',') 318 && (*optvalend == '\0' || *optvalend == ',')
319 && ! (dev == ULONG_MAX && errno == ERANGE) 319 && ! (dev == ULONG_MAX && errno == ERANGE)
320 && dev == (dev_t) dev) 320 && dev == (dev_t) dev)
321 return dev; 321 return dev;
322 } 322 }
323 323
324# endif 324# endif
@@ -383,18 +383,18 @@ read_file_system_list (bool need_fs_type)
383 383
384 while ((mnt = getmntent (fp))) 384 while ((mnt = getmntent (fp)))
385 { 385 {
386 me = xmalloc (sizeof *me); 386 me = xmalloc (sizeof *me);
387 me->me_devname = xstrdup (mnt->mnt_fsname); 387 me->me_devname = xstrdup (mnt->mnt_fsname);
388 me->me_mountdir = xstrdup (mnt->mnt_dir); 388 me->me_mountdir = xstrdup (mnt->mnt_dir);
389 me->me_type = xstrdup (mnt->mnt_type); 389 me->me_type = xstrdup (mnt->mnt_type);
390 me->me_type_malloced = 1; 390 me->me_type_malloced = 1;
391 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 391 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
392 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 392 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
393 me->me_dev = dev_from_mount_options (mnt->mnt_opts); 393 me->me_dev = dev_from_mount_options (mnt->mnt_opts);
394 394
395 /* Add to the linked list. */ 395 /* Add to the linked list. */
396 *mtail = me; 396 *mtail = me;
397 mtail = &me->me_next; 397 mtail = &me->me_next;
398 } 398 }
399 399
400 if (endmntent (fp) == 0) 400 if (endmntent (fp) == 0)
@@ -402,7 +402,7 @@ read_file_system_list (bool need_fs_type)
402 } 402 }
403#endif /* MOUNTED_GETMNTENT1. */ 403#endif /* MOUNTED_GETMNTENT1. */
404 404
405#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ 405#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
406 { 406 {
407 struct statfs *fsp; 407 struct statfs *fsp;
408 int entries; 408 int entries;
@@ -412,25 +412,25 @@ read_file_system_list (bool need_fs_type)
412 return NULL; 412 return NULL;
413 for (; entries-- > 0; fsp++) 413 for (; entries-- > 0; fsp++)
414 { 414 {
415 char *fs_type = fsp_to_string (fsp); 415 char *fs_type = fsp_to_string (fsp);
416 416
417 me = xmalloc (sizeof *me); 417 me = xmalloc (sizeof *me);
418 me->me_devname = xstrdup (fsp->f_mntfromname); 418 me->me_devname = xstrdup (fsp->f_mntfromname);
419 me->me_mountdir = xstrdup (fsp->f_mntonname); 419 me->me_mountdir = xstrdup (fsp->f_mntonname);
420 me->me_type = fs_type; 420 me->me_type = fs_type;
421 me->me_type_malloced = 0; 421 me->me_type_malloced = 0;
422 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 422 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
423 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 423 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
424 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 424 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
425 425
426 /* Add to the linked list. */ 426 /* Add to the linked list. */
427 *mtail = me; 427 *mtail = me;
428 mtail = &me->me_next; 428 mtail = &me->me_next;
429 } 429 }
430 } 430 }
431#endif /* MOUNTED_GETMNTINFO */ 431#endif /* MOUNTED_GETMNTINFO */
432 432
433#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ 433#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */
434 { 434 {
435 struct statvfs *fsp; 435 struct statvfs *fsp;
436 int entries; 436 int entries;
@@ -440,44 +440,44 @@ read_file_system_list (bool need_fs_type)
440 return NULL; 440 return NULL;
441 for (; entries-- > 0; fsp++) 441 for (; entries-- > 0; fsp++)
442 { 442 {
443 me = xmalloc (sizeof *me); 443 me = xmalloc (sizeof *me);
444 me->me_devname = xstrdup (fsp->f_mntfromname); 444 me->me_devname = xstrdup (fsp->f_mntfromname);
445 me->me_mountdir = xstrdup (fsp->f_mntonname); 445 me->me_mountdir = xstrdup (fsp->f_mntonname);
446 me->me_type = xstrdup (fsp->f_fstypename); 446 me->me_type = xstrdup (fsp->f_fstypename);
447 me->me_type_malloced = 1; 447 me->me_type_malloced = 1;
448 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 448 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
449 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 449 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
450 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 450 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
451 451
452 /* Add to the linked list. */ 452 /* Add to the linked list. */
453 *mtail = me; 453 *mtail = me;
454 mtail = &me->me_next; 454 mtail = &me->me_next;
455 } 455 }
456 } 456 }
457#endif /* MOUNTED_GETMNTINFO2 */ 457#endif /* MOUNTED_GETMNTINFO2 */
458 458
459#ifdef MOUNTED_GETMNT /* Ultrix. */ 459#ifdef MOUNTED_GETMNT /* Ultrix. */
460 { 460 {
461 int offset = 0; 461 int offset = 0;
462 int val; 462 int val;
463 struct fs_data fsd; 463 struct fs_data fsd;
464 464
465 while (errno = 0, 465 while (errno = 0,
466 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, 466 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
467 (char *) 0))) 467 (char *) 0)))
468 { 468 {
469 me = xmalloc (sizeof *me); 469 me = xmalloc (sizeof *me);
470 me->me_devname = xstrdup (fsd.fd_req.devname); 470 me->me_devname = xstrdup (fsd.fd_req.devname);
471 me->me_mountdir = xstrdup (fsd.fd_req.path); 471 me->me_mountdir = xstrdup (fsd.fd_req.path);
472 me->me_type = gt_names[fsd.fd_req.fstype]; 472 me->me_type = gt_names[fsd.fd_req.fstype];
473 me->me_type_malloced = 0; 473 me->me_type_malloced = 0;
474 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 474 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
475 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 475 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
476 me->me_dev = fsd.fd_req.dev; 476 me->me_dev = fsd.fd_req.dev;
477 477
478 /* Add to the linked list. */ 478 /* Add to the linked list. */
479 *mtail = me; 479 *mtail = me;
480 mtail = &me->me_next; 480 mtail = &me->me_next;
481 } 481 }
482 if (val < 0) 482 if (val < 0)
483 goto free_then_fail; 483 goto free_then_fail;
@@ -537,7 +537,7 @@ read_file_system_list (bool need_fs_type)
537 537
538 if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) 538 if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode))
539 { 539 {
540 struct rootdir_entry *re = xmalloc (sizeof *re); 540 struct rootdir_entry *re = xmalloc (sizeof *re);
541 re->name = name; 541 re->name = name;
542 re->dev = statbuf.st_dev; 542 re->dev = statbuf.st_dev;
543 re->ino = statbuf.st_ino; 543 re->ino = statbuf.st_ino;
@@ -563,11 +563,11 @@ read_file_system_list (bool need_fs_type)
563 if (re->dev == fi.dev && re->ino == fi.root) 563 if (re->dev == fi.dev && re->ino == fi.root)
564 break; 564 break;
565 565
566 me = xmalloc (sizeof *me); 566 me = xmalloc (sizeof *me);
567 me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); 567 me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name);
568 me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); 568 me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
569 me->me_type = xstrdup (fi.fsh_name); 569 me->me_type = xstrdup (fi.fsh_name);
570 me->me_type_malloced = 1; 570 me->me_type_malloced = 1;
571 me->me_dev = fi.dev; 571 me->me_dev = fi.dev;
572 me->me_dummy = 0; 572 me->me_dummy = 0;
573 me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; 573 me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0;
@@ -588,7 +588,7 @@ read_file_system_list (bool need_fs_type)
588 } 588 }
589#endif /* MOUNTED_FS_STAT_DEV */ 589#endif /* MOUNTED_FS_STAT_DEV */
590 590
591#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ 591#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */
592 { 592 {
593 int numsys, counter; 593 int numsys, counter;
594 size_t bufsize; 594 size_t bufsize;
@@ -606,24 +606,24 @@ read_file_system_list (bool need_fs_type)
606 606
607 if (numsys < 0) 607 if (numsys < 0)
608 { 608 {
609 free (stats); 609 free (stats);
610 return (NULL); 610 return (NULL);
611 } 611 }
612 612
613 for (counter = 0; counter < numsys; counter++) 613 for (counter = 0; counter < numsys; counter++)
614 { 614 {
615 me = xmalloc (sizeof *me); 615 me = xmalloc (sizeof *me);
616 me->me_devname = xstrdup (stats[counter].f_mntfromname); 616 me->me_devname = xstrdup (stats[counter].f_mntfromname);
617 me->me_mountdir = xstrdup (stats[counter].f_mntonname); 617 me->me_mountdir = xstrdup (stats[counter].f_mntonname);
618 me->me_type = xstrdup (FS_TYPE (stats[counter])); 618 me->me_type = xstrdup (FS_TYPE (stats[counter]));
619 me->me_type_malloced = 1; 619 me->me_type_malloced = 1;
620 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 620 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
621 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 621 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
622 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 622 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
623 623
624 /* Add to the linked list. */ 624 /* Add to the linked list. */
625 *mtail = me; 625 *mtail = me;
626 mtail = &me->me_next; 626 mtail = &me->me_next;
627 } 627 }
628 628
629 free (stats); 629 free (stats);
@@ -642,47 +642,47 @@ read_file_system_list (bool need_fs_type)
642 642
643 while (fread (&mnt, sizeof mnt, 1, fp) > 0) 643 while (fread (&mnt, sizeof mnt, 1, fp) > 0)
644 { 644 {
645 me = xmalloc (sizeof *me); 645 me = xmalloc (sizeof *me);
646# ifdef GETFSTYP /* SVR3. */ 646# ifdef GETFSTYP /* SVR3. */
647 me->me_devname = xstrdup (mnt.mt_dev); 647 me->me_devname = xstrdup (mnt.mt_dev);
648# else 648# else
649 me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6); 649 me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
650 strcpy (me->me_devname, "/dev/"); 650 strcpy (me->me_devname, "/dev/");
651 strcpy (me->me_devname + 5, mnt.mt_dev); 651 strcpy (me->me_devname + 5, mnt.mt_dev);
652# endif 652# endif
653 me->me_mountdir = xstrdup (mnt.mt_filsys); 653 me->me_mountdir = xstrdup (mnt.mt_filsys);
654 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 654 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
655 me->me_type = ""; 655 me->me_type = "";
656 me->me_type_malloced = 0; 656 me->me_type_malloced = 0;
657# ifdef GETFSTYP /* SVR3. */ 657# ifdef GETFSTYP /* SVR3. */
658 if (need_fs_type) 658 if (need_fs_type)
659 { 659 {
660 struct statfs fsd; 660 struct statfs fsd;
661 char typebuf[FSTYPSZ]; 661 char typebuf[FSTYPSZ];
662 662
663 if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 663 if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
664 && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) 664 && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
665 { 665 {
666 me->me_type = xstrdup (typebuf); 666 me->me_type = xstrdup (typebuf);
667 me->me_type_malloced = 1; 667 me->me_type_malloced = 1;
668 } 668 }
669 } 669 }
670# endif 670# endif
671 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 671 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
672 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 672 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
673 673
674 /* Add to the linked list. */ 674 /* Add to the linked list. */
675 *mtail = me; 675 *mtail = me;
676 mtail = &me->me_next; 676 mtail = &me->me_next;
677 } 677 }
678 678
679 if (ferror (fp)) 679 if (ferror (fp))
680 { 680 {
681 /* The last fread() call must have failed. */ 681 /* The last fread() call must have failed. */
682 int saved_errno = errno; 682 int saved_errno = errno;
683 fclose (fp); 683 fclose (fp);
684 errno = saved_errno; 684 errno = saved_errno;
685 goto free_then_fail; 685 goto free_then_fail;
686 } 686 }
687 687
688 if (fclose (fp) == EOF) 688 if (fclose (fp) == EOF)
@@ -690,29 +690,29 @@ read_file_system_list (bool need_fs_type)
690 } 690 }
691#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ 691#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
692 692
693#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ 693#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */
694 { 694 {
695 struct mntent **mnttbl = getmnttbl (), **ent; 695 struct mntent **mnttbl = getmnttbl (), **ent;
696 for (ent=mnttbl;*ent;ent++) 696 for (ent=mnttbl;*ent;ent++)
697 { 697 {
698 me = xmalloc (sizeof *me); 698 me = xmalloc (sizeof *me);
699 me->me_devname = xstrdup ( (*ent)->mt_resource); 699 me->me_devname = xstrdup ( (*ent)->mt_resource);
700 me->me_mountdir = xstrdup ( (*ent)->mt_directory); 700 me->me_mountdir = xstrdup ( (*ent)->mt_directory);
701 me->me_type = xstrdup ((*ent)->mt_fstype); 701 me->me_type = xstrdup ((*ent)->mt_fstype);
702 me->me_type_malloced = 1; 702 me->me_type_malloced = 1;
703 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 703 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
704 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 704 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
705 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 705 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
706 706
707 /* Add to the linked list. */ 707 /* Add to the linked list. */
708 *mtail = me; 708 *mtail = me;
709 mtail = &me->me_next; 709 mtail = &me->me_next;
710 } 710 }
711 endmnttbl (); 711 endmnttbl ();
712 } 712 }
713#endif 713#endif
714 714
715#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ 715#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
716 { 716 {
717 struct mnttab mnt; 717 struct mnttab mnt;
718 char *table = MNTTAB; 718 char *table = MNTTAB;
@@ -731,19 +731,19 @@ read_file_system_list (bool need_fs_type)
731 lockfd = open (MNTTAB_LOCK, O_RDONLY); 731 lockfd = open (MNTTAB_LOCK, O_RDONLY);
732 if (0 <= lockfd) 732 if (0 <= lockfd)
733 { 733 {
734 struct flock flock; 734 struct flock flock;
735 flock.l_type = F_RDLCK; 735 flock.l_type = F_RDLCK;
736 flock.l_whence = SEEK_SET; 736 flock.l_whence = SEEK_SET;
737 flock.l_start = 0; 737 flock.l_start = 0;
738 flock.l_len = 0; 738 flock.l_len = 0;
739 while (fcntl (lockfd, F_SETLKW, &flock) == -1) 739 while (fcntl (lockfd, F_SETLKW, &flock) == -1)
740 if (errno != EINTR) 740 if (errno != EINTR)
741 { 741 {
742 int saved_errno = errno; 742 int saved_errno = errno;
743 close (lockfd); 743 close (lockfd);
744 errno = saved_errno; 744 errno = saved_errno;
745 return NULL; 745 return NULL;
746 } 746 }
747 } 747 }
748 else if (errno != ENOENT) 748 else if (errno != ENOENT)
749 return NULL; 749 return NULL;
@@ -755,23 +755,23 @@ read_file_system_list (bool need_fs_type)
755 ret = errno; 755 ret = errno;
756 else 756 else
757 { 757 {
758 while ((ret = getmntent (fp, &mnt)) == 0) 758 while ((ret = getmntent (fp, &mnt)) == 0)
759 { 759 {
760 me = xmalloc (sizeof *me); 760 me = xmalloc (sizeof *me);
761 me->me_devname = xstrdup (mnt.mnt_special); 761 me->me_devname = xstrdup (mnt.mnt_special);
762 me->me_mountdir = xstrdup (mnt.mnt_mountp); 762 me->me_mountdir = xstrdup (mnt.mnt_mountp);
763 me->me_type = xstrdup (mnt.mnt_fstype); 763 me->me_type = xstrdup (mnt.mnt_fstype);
764 me->me_type_malloced = 1; 764 me->me_type_malloced = 1;
765 me->me_dummy = MNT_IGNORE (&mnt) != 0; 765 me->me_dummy = MNT_IGNORE (&mnt) != 0;
766 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 766 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
767 me->me_dev = dev_from_mount_options (mnt.mnt_mntopts); 767 me->me_dev = dev_from_mount_options (mnt.mnt_mntopts);
768 768
769 /* Add to the linked list. */ 769 /* Add to the linked list. */
770 *mtail = me; 770 *mtail = me;
771 mtail = &me->me_next; 771 mtail = &me->me_next;
772 } 772 }
773 773
774 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1; 774 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
775 } 775 }
776 776
777 if (0 <= lockfd && close (lockfd) != 0) 777 if (0 <= lockfd && close (lockfd) != 0)
@@ -779,13 +779,13 @@ read_file_system_list (bool need_fs_type)
779 779
780 if (0 <= ret) 780 if (0 <= ret)
781 { 781 {
782 errno = ret; 782 errno = ret;
783 goto free_then_fail; 783 goto free_then_fail;
784 } 784 }
785 } 785 }
786#endif /* MOUNTED_GETMNTENT2. */ 786#endif /* MOUNTED_GETMNTENT2. */
787 787
788#ifdef MOUNTED_VMOUNT /* AIX. */ 788#ifdef MOUNTED_VMOUNT /* AIX. */
789 { 789 {
790 int bufsize; 790 int bufsize;
791 char *entries, *thisent; 791 char *entries, *thisent;
@@ -802,53 +802,53 @@ read_file_system_list (bool need_fs_type)
802 n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); 802 n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
803 if (n_entries < 0) 803 if (n_entries < 0)
804 { 804 {
805 int saved_errno = errno; 805 int saved_errno = errno;
806 free (entries); 806 free (entries);
807 errno = saved_errno; 807 errno = saved_errno;
808 return NULL; 808 return NULL;
809 } 809 }
810 810
811 for (i = 0, thisent = entries; 811 for (i = 0, thisent = entries;
812 i < n_entries; 812 i < n_entries;
813 i++, thisent += vmp->vmt_length) 813 i++, thisent += vmp->vmt_length)
814 { 814 {
815 char *options, *ignore; 815 char *options, *ignore;
816 816
817 vmp = (struct vmount *) thisent; 817 vmp = (struct vmount *) thisent;
818 me = xmalloc (sizeof *me); 818 me = xmalloc (sizeof *me);
819 if (vmp->vmt_flags & MNT_REMOTE) 819 if (vmp->vmt_flags & MNT_REMOTE)
820 { 820 {
821 char *host, *dir; 821 char *host, *dir;
822 822
823 me->me_remote = 1; 823 me->me_remote = 1;
824 /* Prepend the remote dirname. */ 824 /* Prepend the remote dirname. */
825 host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; 825 host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
826 dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; 826 dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
827 me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2); 827 me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2);
828 strcpy (me->me_devname, host); 828 strcpy (me->me_devname, host);
829 strcat (me->me_devname, ":"); 829 strcat (me->me_devname, ":");
830 strcat (me->me_devname, dir); 830 strcat (me->me_devname, dir);
831 } 831 }
832 else 832 else
833 { 833 {
834 me->me_remote = 0; 834 me->me_remote = 0;
835 me->me_devname = xstrdup (thisent + 835 me->me_devname = xstrdup (thisent +
836 vmp->vmt_data[VMT_OBJECT].vmt_off); 836 vmp->vmt_data[VMT_OBJECT].vmt_off);
837 } 837 }
838 me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); 838 me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
839 me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); 839 me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
840 me->me_type_malloced = 1; 840 me->me_type_malloced = 1;
841 options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; 841 options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
842 ignore = strstr (options, "ignore"); 842 ignore = strstr (options, "ignore");
843 me->me_dummy = (ignore 843 me->me_dummy = (ignore
844 && (ignore == options || ignore[-1] == ',') 844 && (ignore == options || ignore[-1] == ',')
845 && (ignore[sizeof "ignore" - 1] == ',' 845 && (ignore[sizeof "ignore" - 1] == ','
846 || ignore[sizeof "ignore" - 1] == '\0')); 846 || ignore[sizeof "ignore" - 1] == '\0'));
847 me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */ 847 me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
848 848
849 /* Add to the linked list. */ 849 /* Add to the linked list. */
850 *mtail = me; 850 *mtail = me;
851 mtail = &me->me_next; 851 mtail = &me->me_next;
852 } 852 }
853 free (entries); 853 free (entries);
854 } 854 }
@@ -865,13 +865,13 @@ read_file_system_list (bool need_fs_type)
865 865
866 while (mount_list) 866 while (mount_list)
867 { 867 {
868 me = mount_list->me_next; 868 me = mount_list->me_next;
869 free (mount_list->me_devname); 869 free (mount_list->me_devname);
870 free (mount_list->me_mountdir); 870 free (mount_list->me_mountdir);
871 if (mount_list->me_type_malloced) 871 if (mount_list->me_type_malloced)
872 free (mount_list->me_type); 872 free (mount_list->me_type);
873 free (mount_list); 873 free (mount_list);
874 mount_list = me; 874 mount_list = me;
875 } 875 }
876 876
877 errno = saved_errno; 877 errno = saved_errno;
diff --git a/gl/mountlist.h b/gl/mountlist.h
index e54bb49e..ad66def5 100644
--- a/gl/mountlist.h
+++ b/gl/mountlist.h
@@ -1,7 +1,7 @@
1/* mountlist.h -- declarations for list of mounted file systems 1/* mountlist.h -- declarations for list of mounted file systems
2 2
3 Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003, 2004, 2005 3 Copyright (C) 1991-1992, 1998, 2000-2005, 2009-2010 Free Software
4 Free Software Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 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 7 it under the terms of the GNU General Public License as published by
@@ -25,12 +25,12 @@
25/* A mount table entry. */ 25/* A mount table entry. */
26struct mount_entry 26struct mount_entry
27{ 27{
28 char *me_devname; /* Device node name, including "/dev/". */ 28 char *me_devname; /* Device node name, including "/dev/". */
29 char *me_mountdir; /* Mount point directory name. */ 29 char *me_mountdir; /* Mount point directory name. */
30 char *me_type; /* "nfs", "4.2", etc. */ 30 char *me_type; /* "nfs", "4.2", etc. */
31 dev_t me_dev; /* Device number of me_mountdir. */ 31 dev_t me_dev; /* Device number of me_mountdir. */
32 unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */ 32 unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */
33 unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ 33 unsigned int me_remote : 1; /* Nonzero for remote fileystems. */
34 unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */ 34 unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */
35 struct mount_entry *me_next; 35 struct mount_entry *me_next;
36}; 36};
diff --git a/gl/netdb.in.h b/gl/netdb.in.h
index 363206d3..73db46a5 100644
--- a/gl/netdb.in.h
+++ b/gl/netdb.in.h
@@ -1,5 +1,5 @@
1/* Provide a netdb.h header file for systems lacking it (read: MinGW). 1/* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008 Free Software Foundation, Inc. 2 Copyright (C) 2008-2010 Free Software Foundation, Inc.
3 Written by Simon Josefsson. 3 Written by Simon Josefsson.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
@@ -22,11 +22,11 @@
22 22
23#ifndef _GL_NETDB_H 23#ifndef _GL_NETDB_H
24 24
25#if @HAVE_NETDB_H@ 25#if __GNUC__ >= 3
26
27# if __GNUC__ >= 3
28@PRAGMA_SYSTEM_HEADER@ 26@PRAGMA_SYSTEM_HEADER@
29# endif 27#endif
28
29#if @HAVE_NETDB_H@
30 30
31/* The include_next requires a split double-inclusion guard. */ 31/* The include_next requires a split double-inclusion guard. */
32# @INCLUDE_NEXT@ @NEXT_NETDB_H@ 32# @INCLUDE_NEXT@ @NEXT_NETDB_H@
@@ -39,6 +39,8 @@
39/* Get netdb.h definitions such as struct hostent for MinGW. */ 39/* Get netdb.h definitions such as struct hostent for MinGW. */
40#include <sys/socket.h> 40#include <sys/socket.h>
41 41
42/* The definition of _GL_ARG_NONNULL is copied here. */
43
42/* Declarations for a platform that lacks <netdb.h>, or where it is 44/* Declarations for a platform that lacks <netdb.h>, or where it is
43 incomplete. */ 45 incomplete. */
44 46
@@ -49,53 +51,59 @@
49/* Structure to contain information about address of a service provider. */ 51/* Structure to contain information about address of a service provider. */
50struct addrinfo 52struct addrinfo
51{ 53{
52 int ai_flags; /* Input flags. */ 54 int ai_flags; /* Input flags. */
53 int ai_family; /* Protocol family for socket. */ 55 int ai_family; /* Protocol family for socket. */
54 int ai_socktype; /* Socket type. */ 56 int ai_socktype; /* Socket type. */
55 int ai_protocol; /* Protocol for socket. */ 57 int ai_protocol; /* Protocol for socket. */
56 socklen_t ai_addrlen; /* Length of socket address. */ 58 socklen_t ai_addrlen; /* Length of socket address. */
57 struct sockaddr *ai_addr; /* Socket address for socket. */ 59 struct sockaddr *ai_addr; /* Socket address for socket. */
58 char *ai_canonname; /* Canonical name for service location. */ 60 char *ai_canonname; /* Canonical name for service location. */
59 struct addrinfo *ai_next; /* Pointer to next in list. */ 61 struct addrinfo *ai_next; /* Pointer to next in list. */
60}; 62};
61# endif 63# endif
62 64
63/* Possible values for `ai_flags' field in `addrinfo' structure. */ 65/* Possible values for `ai_flags' field in `addrinfo' structure. */
64# ifndef AI_PASSIVE 66# ifndef AI_PASSIVE
65# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ 67# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
66# endif 68# endif
67# ifndef AI_CANONNAME 69# ifndef AI_CANONNAME
68# define AI_CANONNAME 0x0002 /* Request for canonical name. */ 70# define AI_CANONNAME 0x0002 /* Request for canonical name. */
69# endif 71# endif
70# ifndef AI_NUMERICSERV 72# ifndef AI_NUMERICSERV
71# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ 73# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
72# endif 74# endif
73 75
74# if 0 76# if 0
75/* The commented out definitions below are not yet implemented in the 77# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
76 GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact, 78# endif
77 cause conflicts on systems with a getaddrinfo() function which does not
78 define them.
79 79
80 If they are restored, be sure to protect the definitions with #ifndef. */ 80/* These symbolic constants are required to be present by POSIX, but
81# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ 81 our getaddrinfo replacement doesn't use them (yet). Setting them
82# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ 82 to 0 on systems that doesn't have them avoids causing problems for
83# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ 83 system getaddrinfo implementations that would be confused by
84# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose 84 unknown values. */
85 returned address type.. */ 85# ifndef AI_V4MAPPED
86# endif /* 0 */ 86# define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
87# endif
88# ifndef AI_ALL
89# define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
90# endif
91# ifndef AI_ADDRCONFIG
92# define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
93 returned address type. */
94# endif
87 95
88/* Error values for `getaddrinfo' function. */ 96/* Error values for `getaddrinfo' function. */
89# ifndef EAI_BADFLAGS 97# ifndef EAI_BADFLAGS
90# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ 98# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
91# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ 99# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
92# define EAI_AGAIN -3 /* Temporary failure in name resolution. */ 100# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
93# define EAI_FAIL -4 /* Non-recoverable failure in name res. */ 101# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
94# define EAI_NODATA -5 /* No address associated with NAME. */ 102# define EAI_NODATA -5 /* No address associated with NAME. */
95# define EAI_FAMILY -6 /* `ai_family' not supported. */ 103# define EAI_FAMILY -6 /* `ai_family' not supported. */
96# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ 104# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
97# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ 105# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
98# define EAI_MEMORY -10 /* Memory allocation failure. */ 106# define EAI_MEMORY -10 /* Memory allocation failure. */
99# endif 107# endif
100 108
101/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least 109/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
@@ -107,15 +115,15 @@ struct addrinfo
107 115
108# ifndef EAI_OVERFLOW 116# ifndef EAI_OVERFLOW
109/* Not defined on mingw32 and Haiku. */ 117/* Not defined on mingw32 and Haiku. */
110# define EAI_OVERFLOW -12 /* Argument buffer overflow. */ 118# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
111# endif 119# endif
112# ifndef EAI_ADDRFAMILY 120# ifndef EAI_ADDRFAMILY
113/* Not defined on mingw32. */ 121/* Not defined on mingw32. */
114# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ 122# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
115# endif 123# endif
116# ifndef EAI_SYSTEM 124# ifndef EAI_SYSTEM
117/* Not defined on mingw32. */ 125/* Not defined on mingw32. */
118# define EAI_SYSTEM -11 /* System error returned in `errno'. */ 126# define EAI_SYSTEM -11 /* System error returned in `errno'. */
119# endif 127# endif
120 128
121# if 0 129# if 0
@@ -124,12 +132,12 @@ struct addrinfo
124 132
125 If they are restored, be sure to protect the definitions with #ifndef. */ 133 If they are restored, be sure to protect the definitions with #ifndef. */
126# ifndef EAI_INPROGRESS 134# ifndef EAI_INPROGRESS
127# define EAI_INPROGRESS -100 /* Processing request in progress. */ 135# define EAI_INPROGRESS -100 /* Processing request in progress. */
128# define EAI_CANCELED -101 /* Request canceled. */ 136# define EAI_CANCELED -101 /* Request canceled. */
129# define EAI_NOTCANCELED -102 /* Request not canceled. */ 137# define EAI_NOTCANCELED -102 /* Request not canceled. */
130# define EAI_ALLDONE -103 /* All requests done. */ 138# define EAI_ALLDONE -103 /* All requests done. */
131# define EAI_INTR -104 /* Interrupted by a signal. */ 139# define EAI_INTR -104 /* Interrupted by a signal. */
132# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ 140# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
133# endif 141# endif
134# endif 142# endif
135 143
@@ -139,16 +147,17 @@ struct addrinfo
139 For more details, see the POSIX:2001 specification 147 For more details, see the POSIX:2001 specification
140 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ 148 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
141extern int getaddrinfo (const char *restrict nodename, 149extern int getaddrinfo (const char *restrict nodename,
142 const char *restrict servname, 150 const char *restrict servname,
143 const struct addrinfo *restrict hints, 151 const struct addrinfo *restrict hints,
144 struct addrinfo **restrict res); 152 struct addrinfo **restrict res)
153 _GL_ARG_NONNULL ((4));
145# endif 154# endif
146 155
147# if !@HAVE_DECL_FREEADDRINFO@ 156# if !@HAVE_DECL_FREEADDRINFO@
148/* Free `addrinfo' structure AI including associated storage. 157/* Free `addrinfo' structure AI including associated storage.
149 For more details, see the POSIX:2001 specification 158 For more details, see the POSIX:2001 specification
150 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ 159 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
151extern void freeaddrinfo (struct addrinfo *ai); 160extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1));
152# endif 161# endif
153 162
154# if !@HAVE_DECL_GAI_STRERROR@ 163# if !@HAVE_DECL_GAI_STRERROR@
@@ -162,10 +171,11 @@ extern const char *gai_strerror (int ecode);
162/* Convert socket address to printable node and service names. 171/* Convert socket address to printable node and service names.
163 For more details, see the POSIX:2001 specification 172 For more details, see the POSIX:2001 specification
164 <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */ 173 <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
165extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, 174extern int getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
166 char *restrict node, socklen_t nodelen, 175 char *restrict node, socklen_t nodelen,
167 char *restrict service, socklen_t servicelen, 176 char *restrict service, socklen_t servicelen,
168 int flags); 177 int flags)
178 _GL_ARG_NONNULL ((1));
169# endif 179# endif
170 180
171/* Possible flags for getnameinfo. */ 181/* Possible flags for getnameinfo. */
diff --git a/gl/netinet_in.in.h b/gl/netinet_in.in.h
index 97e11a7e..7f0ff421 100644
--- a/gl/netinet_in.in.h
+++ b/gl/netinet_in.in.h
@@ -1,5 +1,5 @@
1/* Substitute for <netinet/in.h>. 1/* Substitute for <netinet/in.h>.
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. 2 Copyright (C) 2007-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -17,11 +17,11 @@
17 17
18#ifndef _GL_NETINET_IN_H 18#ifndef _GL_NETINET_IN_H
19 19
20#if @HAVE_NETINET_IN_H@ 20#if __GNUC__ >= 3
21
22# if __GNUC__ >= 3
23@PRAGMA_SYSTEM_HEADER@ 21@PRAGMA_SYSTEM_HEADER@
24# endif 22#endif
23
24#if @HAVE_NETINET_IN_H@
25 25
26/* On many platforms, <netinet/in.h> assumes prior inclusion of 26/* On many platforms, <netinet/in.h> assumes prior inclusion of
27 <sys/types.h>. */ 27 <sys/types.h>. */
diff --git a/gl/nl_langinfo.c b/gl/nl_langinfo.c
new file mode 100644
index 00000000..e81c81e7
--- /dev/null
+++ b/gl/nl_langinfo.c
@@ -0,0 +1,260 @@
1/* nl_langinfo() replacement: query locale dependent information.
2
3 Copyright (C) 2007-2010 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/* Specification. */
21#include <langinfo.h>
22
23#if REPLACE_NL_LANGINFO
24
25/* Override nl_langinfo with support for added nl_item values. */
26
27# include <locale.h>
28# include <string.h>
29
30# undef nl_langinfo
31
32char *
33rpl_nl_langinfo (nl_item item)
34{
35 switch (item)
36 {
37# if GNULIB_defined_CODESET
38 case CODESET:
39 {
40 const char *locale;
41 static char buf[2 + 10 + 1];
42
43 locale = setlocale (LC_CTYPE, NULL);
44 if (locale != NULL && locale[0] != '\0')
45 {
46 /* If the locale name contains an encoding after the dot, return
47 it. */
48 const char *dot = strchr (locale, '.');
49
50 if (dot != NULL)
51 {
52 const char *modifier;
53
54 dot++;
55 /* Look for the possible @... trailer and remove it, if any. */
56 modifier = strchr (dot, '@');
57 if (modifier == NULL)
58 return dot;
59 if (modifier - dot < sizeof (buf))
60 {
61 memcpy (buf, dot, modifier - dot);
62 buf [modifier - dot] = '\0';
63 return buf;
64 }
65 }
66 }
67 return "";
68 }
69# endif
70# if GNULIB_defined_ERA
71 case ERA:
72 /* The format is not standardized. In glibc it is a sequence of strings
73 of the form "direction:offset:start_date:end_date:era_name:era_format"
74 with an empty string at the end. */
75 return "";
76 case ERA_D_FMT:
77 /* The %Ex conversion in strftime behaves like %x if the locale does not
78 have an alternative time format. */
79 item = D_FMT;
80 break;
81 case ERA_D_T_FMT:
82 /* The %Ec conversion in strftime behaves like %c if the locale does not
83 have an alternative time format. */
84 item = D_T_FMT;
85 break;
86 case ERA_T_FMT:
87 /* The %EX conversion in strftime behaves like %X if the locale does not
88 have an alternative time format. */
89 item = T_FMT;
90 break;
91 case ALT_DIGITS:
92 /* The format is not standardized. In glibc it is a sequence of 10
93 strings, appended in memory. */
94 return "\0\0\0\0\0\0\0\0\0\0";
95# endif
96 default:
97 break;
98 }
99 return nl_langinfo (item);
100}
101
102#else
103
104/* Provide nl_langinfo from scratch. */
105
106# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
107
108/* Native Windows platforms. */
109
110# define WIN32_LEAN_AND_MEAN /* avoid including junk */
111# include <windows.h>
112
113# include <stdio.h>
114
115# else
116
117/* An old Unix platform without locales, such as Linux libc5 or BeOS. */
118
119# endif
120
121# include <locale.h>
122
123char *
124nl_langinfo (nl_item item)
125{
126 switch (item)
127 {
128 /* nl_langinfo items of the LC_CTYPE category */
129 case CODESET:
130# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
131 {
132 static char buf[2 + 10 + 1];
133
134 /* Woe32 has a function returning the locale's codepage as a number. */
135 sprintf (buf, "CP%u", GetACP ());
136 return buf;
137 }
138# elif defined __BEOS__
139 return "UTF-8";
140# else
141 return "ISO-8859-1";
142# endif
143 /* nl_langinfo items of the LC_NUMERIC category */
144 case RADIXCHAR:
145 return localeconv () ->decimal_point;
146 case THOUSEP:
147 return localeconv () ->thousands_sep;
148 /* nl_langinfo items of the LC_TIME category.
149 TODO: Really use the locale. */
150 case D_T_FMT:
151 case ERA_D_T_FMT:
152 return "%a %b %e %H:%M:%S %Y";
153 case D_FMT:
154 case ERA_D_FMT:
155 return "%m/%d/%y";
156 case T_FMT:
157 case ERA_T_FMT:
158 return "%H:%M:%S";
159 case T_FMT_AMPM:
160 return "%I:%M:%S %p";
161 case AM_STR:
162 return "AM";
163 case PM_STR:
164 return "PM";
165 case DAY_1:
166 return "Sunday";
167 case DAY_2:
168 return "Monday";
169 case DAY_3:
170 return "Tuesday";
171 case DAY_4:
172 return "Wednesday";
173 case DAY_5:
174 return "Thursday";
175 case DAY_6:
176 return "Friday";
177 case DAY_7:
178 return "Saturday";
179 case ABDAY_1:
180 return "Sun";
181 case ABDAY_2:
182 return "Mon";
183 case ABDAY_3:
184 return "Tue";
185 case ABDAY_4:
186 return "Wed";
187 case ABDAY_5:
188 return "Thu";
189 case ABDAY_6:
190 return "Fri";
191 case ABDAY_7:
192 return "Sat";
193 case MON_1:
194 return "January";
195 case MON_2:
196 return "February";
197 case MON_3:
198 return "March";
199 case MON_4:
200 return "April";
201 case MON_5:
202 return "May";
203 case MON_6:
204 return "June";
205 case MON_7:
206 return "July";
207 case MON_8:
208 return "August";
209 case MON_9:
210 return "September";
211 case MON_10:
212 return "October";
213 case MON_11:
214 return "November";
215 case MON_12:
216 return "December";
217 case ABMON_1:
218 return "Jan";
219 case ABMON_2:
220 return "Feb";
221 case ABMON_3:
222 return "Mar";
223 case ABMON_4:
224 return "Apr";
225 case ABMON_5:
226 return "May";
227 case ABMON_6:
228 return "Jun";
229 case ABMON_7:
230 return "Jul";
231 case ABMON_8:
232 return "Aug";
233 case ABMON_9:
234 return "Sep";
235 case ABMON_10:
236 return "Oct";
237 case ABMON_11:
238 return "Nov";
239 case ABMON_12:
240 return "Dec";
241 case ERA:
242 return "";
243 case ALT_DIGITS:
244 return "\0\0\0\0\0\0\0\0\0\0";
245 /* nl_langinfo items of the LC_MONETARY category
246 TODO: Really use the locale. */
247 case CRNCYSTR:
248 return "-";
249 /* nl_langinfo items of the LC_MESSAGES category
250 TODO: Really use the locale. */
251 case YESEXPR:
252 return "^[yY]";
253 case NOEXPR:
254 return "^[nN]";
255 default:
256 return "";
257 }
258}
259
260#endif
diff --git a/gl/open-safer.c b/gl/open-safer.c
index 15bf6a65..3b36471f 100644
--- a/gl/open-safer.c
+++ b/gl/open-safer.c
@@ -1,6 +1,6 @@
1/* Invoke open, but avoid some glitches. 1/* Invoke open, but avoid some glitches.
2 2
3 Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2008-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -35,13 +35,9 @@ open_safer (char const *file, int flags, ...)
35 va_list ap; 35 va_list ap;
36 va_start (ap, flags); 36 va_start (ap, flags);
37 37
38 /* Assume mode_t promotes to int if and only if it is smaller. 38 /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
39 This assumption isn't guaranteed by the C standard, but we 39 creates crashing code when 'mode_t' is smaller than 'int'. */
40 don't know of any real-world counterexamples. */ 40 mode = va_arg (ap, PROMOTED_MODE_T);
41 if (sizeof (mode_t) < sizeof (int))
42 mode = va_arg (ap, int);
43 else
44 mode = va_arg (ap, mode_t);
45 41
46 va_end (ap); 42 va_end (ap);
47 } 43 }
diff --git a/gl/open.c b/gl/open.c
index 13af2746..f612b802 100644
--- a/gl/open.c
+++ b/gl/open.c
@@ -1,5 +1,5 @@
1/* Open a descriptor to a file. 1/* Open a descriptor to a file.
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. 2 Copyright (C) 2007-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -38,6 +38,11 @@ orig_open (const char *filename, int flags, mode_t mode)
38#include <string.h> 38#include <string.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/stat.h> 40#include <sys/stat.h>
41#include <unistd.h>
42
43#ifndef REPLACE_OPEN_DIRECTORY
44# define REPLACE_OPEN_DIRECTORY 0
45#endif
41 46
42int 47int
43open (const char *filename, int flags, ...) 48open (const char *filename, int flags, ...)
@@ -51,12 +56,9 @@ open (const char *filename, int flags, ...)
51 va_list arg; 56 va_list arg;
52 va_start (arg, flags); 57 va_start (arg, flags);
53 58
54 /* If mode_t is narrower than int, use the promoted type (int), 59 /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
55 not mode_t. Use sizeof to guess whether mode_t is narrower; 60 creates crashing code when 'mode_t' is smaller than 'int'. */
56 we don't know of any practical counterexamples. */ 61 mode = va_arg (arg, PROMOTED_MODE_T);
57 mode = (sizeof (mode_t) < sizeof (int)
58 ? va_arg (arg, int)
59 : va_arg (arg, mode_t));
60 62
61 va_end (arg); 63 va_end (arg);
62 } 64 }
@@ -92,15 +94,38 @@ open (const char *filename, int flags, ...)
92 { 94 {
93 size_t len = strlen (filename); 95 size_t len = strlen (filename);
94 if (len > 0 && filename[len - 1] == '/') 96 if (len > 0 && filename[len - 1] == '/')
95 { 97 {
96 errno = EISDIR; 98 errno = EISDIR;
97 return -1; 99 return -1;
98 } 100 }
99 } 101 }
100#endif 102#endif
101 103
102 fd = orig_open (filename, flags, mode); 104 fd = orig_open (filename, flags, mode);
103 105
106#if REPLACE_FCHDIR
107 /* Implementing fchdir and fdopendir requires the ability to open a
108 directory file descriptor. If open doesn't support that (as on
109 mingw), we use a dummy file that behaves the same as directories
110 on Linux (ie. always reports EOF on attempts to read()), and
111 override fstat() in fchdir.c to hide the fact that we have a
112 dummy. */
113 if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
114 && (flags & O_ACCMODE) == O_RDONLY)
115 {
116 struct stat statbuf;
117 if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
118 {
119 /* Maximum recursion depth of 1. */
120 fd = open ("/dev/null", flags, mode);
121 if (0 <= fd)
122 fd = _gl_register_fd (fd, filename);
123 }
124 else
125 errno = EACCES;
126 }
127#endif
128
104#if OPEN_TRAILING_SLASH_BUG 129#if OPEN_TRAILING_SLASH_BUG
105 /* If the filename ends in a slash and fd does not refer to a directory, 130 /* If the filename ends in a slash and fd does not refer to a directory,
106 then fail. 131 then fail.
@@ -116,24 +141,25 @@ open (const char *filename, int flags, ...)
116 with ENOTDIR. */ 141 with ENOTDIR. */
117 if (fd >= 0) 142 if (fd >= 0)
118 { 143 {
144 /* We know len is positive, since open did not fail with ENOENT. */
119 size_t len = strlen (filename); 145 size_t len = strlen (filename);
120 if (len > 0 && filename[len - 1] == '/') 146 if (filename[len - 1] == '/')
121 { 147 {
122 struct stat statbuf; 148 struct stat statbuf;
123 149
124 if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) 150 if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
125 { 151 {
126 close (fd); 152 close (fd);
127 errno = ENOTDIR; 153 errno = ENOTDIR;
128 return -1; 154 return -1;
129 } 155 }
130 } 156 }
131 } 157 }
132#endif 158#endif
133 159
134#ifdef FCHDIR_REPLACEMENT 160#if REPLACE_FCHDIR
135 if (fd >= 0) 161 if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
136 _gl_register_fd (fd, filename); 162 fd = _gl_register_fd (fd, filename);
137#endif 163#endif
138 164
139 return fd; 165 return fd;
diff --git a/gl/pipe-safer.c b/gl/pipe-safer.c
index 0fc68505..ae9f2e3e 100644
--- a/gl/pipe-safer.c
+++ b/gl/pipe-safer.c
@@ -1,5 +1,5 @@
1/* Invoke pipe, but avoid some glitches. 1/* Invoke pipe, but avoid some glitches.
2 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -35,16 +35,16 @@ pipe_safer (int fd[2])
35 { 35 {
36 int i; 36 int i;
37 for (i = 0; i < 2; i++) 37 for (i = 0; i < 2; i++)
38 { 38 {
39 fd[i] = fd_safer (fd[i]); 39 fd[i] = fd_safer (fd[i]);
40 if (fd[i] < 0) 40 if (fd[i] < 0)
41 { 41 {
42 int e = errno; 42 int e = errno;
43 close (fd[1 - i]); 43 close (fd[1 - i]);
44 errno = e; 44 errno = e;
45 return -1; 45 return -1;
46 } 46 }
47 } 47 }
48 48
49 return 0; 49 return 0;
50 } 50 }
diff --git a/gl/printf-args.c b/gl/printf-args.c
index 871c720a..46c03a21 100644
--- a/gl/printf-args.c
+++ b/gl/printf-args.c
@@ -1,5 +1,6 @@
1/* Decomposed printf argument list. 1/* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2005-2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2010 Free Software
3 Foundation, Inc.
3 4
4 This program is free software; you can redistribute it and/or modify 5 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 it under the terms of the GNU General Public License as published by
@@ -42,146 +43,146 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
42 switch (ap->type) 43 switch (ap->type)
43 { 44 {
44 case TYPE_SCHAR: 45 case TYPE_SCHAR:
45 ap->a.a_schar = va_arg (args, /*signed char*/ int); 46 ap->a.a_schar = va_arg (args, /*signed char*/ int);
46 break; 47 break;
47 case TYPE_UCHAR: 48 case TYPE_UCHAR:
48 ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); 49 ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
49 break; 50 break;
50 case TYPE_SHORT: 51 case TYPE_SHORT:
51 ap->a.a_short = va_arg (args, /*short*/ int); 52 ap->a.a_short = va_arg (args, /*short*/ int);
52 break; 53 break;
53 case TYPE_USHORT: 54 case TYPE_USHORT:
54 ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); 55 ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
55 break; 56 break;
56 case TYPE_INT: 57 case TYPE_INT:
57 ap->a.a_int = va_arg (args, int); 58 ap->a.a_int = va_arg (args, int);
58 break; 59 break;
59 case TYPE_UINT: 60 case TYPE_UINT:
60 ap->a.a_uint = va_arg (args, unsigned int); 61 ap->a.a_uint = va_arg (args, unsigned int);
61 break; 62 break;
62 case TYPE_LONGINT: 63 case TYPE_LONGINT:
63 ap->a.a_longint = va_arg (args, long int); 64 ap->a.a_longint = va_arg (args, long int);
64 break; 65 break;
65 case TYPE_ULONGINT: 66 case TYPE_ULONGINT:
66 ap->a.a_ulongint = va_arg (args, unsigned long int); 67 ap->a.a_ulongint = va_arg (args, unsigned long int);
67 break; 68 break;
68#if HAVE_LONG_LONG_INT 69#if HAVE_LONG_LONG_INT
69 case TYPE_LONGLONGINT: 70 case TYPE_LONGLONGINT:
70 ap->a.a_longlongint = va_arg (args, long long int); 71 ap->a.a_longlongint = va_arg (args, long long int);
71 break; 72 break;
72 case TYPE_ULONGLONGINT: 73 case TYPE_ULONGLONGINT:
73 ap->a.a_ulonglongint = va_arg (args, unsigned long long int); 74 ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
74 break; 75 break;
75#endif 76#endif
76 case TYPE_DOUBLE: 77 case TYPE_DOUBLE:
77 ap->a.a_double = va_arg (args, double); 78 ap->a.a_double = va_arg (args, double);
78 break; 79 break;
79 case TYPE_LONGDOUBLE: 80 case TYPE_LONGDOUBLE:
80 ap->a.a_longdouble = va_arg (args, long double); 81 ap->a.a_longdouble = va_arg (args, long double);
81 break; 82 break;
82 case TYPE_CHAR: 83 case TYPE_CHAR:
83 ap->a.a_char = va_arg (args, int); 84 ap->a.a_char = va_arg (args, int);
84 break; 85 break;
85#if HAVE_WINT_T 86#if HAVE_WINT_T
86 case TYPE_WIDE_CHAR: 87 case TYPE_WIDE_CHAR:
87 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by 88 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
88 default argument promotions", this is not the case in mingw32, 89 default argument promotions", this is not the case in mingw32,
89 where wint_t is 'unsigned short'. */ 90 where wint_t is 'unsigned short'. */
90 ap->a.a_wide_char = 91 ap->a.a_wide_char =
91 (sizeof (wint_t) < sizeof (int) 92 (sizeof (wint_t) < sizeof (int)
92 ? va_arg (args, int) 93 ? (wint_t) va_arg (args, int)
93 : va_arg (args, wint_t)); 94 : va_arg (args, wint_t));
94 break; 95 break;
95#endif 96#endif
96 case TYPE_STRING: 97 case TYPE_STRING:
97 ap->a.a_string = va_arg (args, const char *); 98 ap->a.a_string = va_arg (args, const char *);
98 /* A null pointer is an invalid argument for "%s", but in practice 99 /* A null pointer is an invalid argument for "%s", but in practice
99 it occurs quite frequently in printf statements that produce 100 it occurs quite frequently in printf statements that produce
100 debug output. Use a fallback in this case. */ 101 debug output. Use a fallback in this case. */
101 if (ap->a.a_string == NULL) 102 if (ap->a.a_string == NULL)
102 ap->a.a_string = "(NULL)"; 103 ap->a.a_string = "(NULL)";
103 break; 104 break;
104#if HAVE_WCHAR_T 105#if HAVE_WCHAR_T
105 case TYPE_WIDE_STRING: 106 case TYPE_WIDE_STRING:
106 ap->a.a_wide_string = va_arg (args, const wchar_t *); 107 ap->a.a_wide_string = va_arg (args, const wchar_t *);
107 /* A null pointer is an invalid argument for "%ls", but in practice 108 /* A null pointer is an invalid argument for "%ls", but in practice
108 it occurs quite frequently in printf statements that produce 109 it occurs quite frequently in printf statements that produce
109 debug output. Use a fallback in this case. */ 110 debug output. Use a fallback in this case. */
110 if (ap->a.a_wide_string == NULL) 111 if (ap->a.a_wide_string == NULL)
111 { 112 {
112 static const wchar_t wide_null_string[] = 113 static const wchar_t wide_null_string[] =
113 { 114 {
114 (wchar_t)'(', 115 (wchar_t)'(',
115 (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', 116 (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
116 (wchar_t)')', 117 (wchar_t)')',
117 (wchar_t)0 118 (wchar_t)0
118 }; 119 };
119 ap->a.a_wide_string = wide_null_string; 120 ap->a.a_wide_string = wide_null_string;
120 } 121 }
121 break; 122 break;
122#endif 123#endif
123 case TYPE_POINTER: 124 case TYPE_POINTER:
124 ap->a.a_pointer = va_arg (args, void *); 125 ap->a.a_pointer = va_arg (args, void *);
125 break; 126 break;
126 case TYPE_COUNT_SCHAR_POINTER: 127 case TYPE_COUNT_SCHAR_POINTER:
127 ap->a.a_count_schar_pointer = va_arg (args, signed char *); 128 ap->a.a_count_schar_pointer = va_arg (args, signed char *);
128 break; 129 break;
129 case TYPE_COUNT_SHORT_POINTER: 130 case TYPE_COUNT_SHORT_POINTER:
130 ap->a.a_count_short_pointer = va_arg (args, short *); 131 ap->a.a_count_short_pointer = va_arg (args, short *);
131 break; 132 break;
132 case TYPE_COUNT_INT_POINTER: 133 case TYPE_COUNT_INT_POINTER:
133 ap->a.a_count_int_pointer = va_arg (args, int *); 134 ap->a.a_count_int_pointer = va_arg (args, int *);
134 break; 135 break;
135 case TYPE_COUNT_LONGINT_POINTER: 136 case TYPE_COUNT_LONGINT_POINTER:
136 ap->a.a_count_longint_pointer = va_arg (args, long int *); 137 ap->a.a_count_longint_pointer = va_arg (args, long int *);
137 break; 138 break;
138#if HAVE_LONG_LONG_INT 139#if HAVE_LONG_LONG_INT
139 case TYPE_COUNT_LONGLONGINT_POINTER: 140 case TYPE_COUNT_LONGLONGINT_POINTER:
140 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); 141 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
141 break; 142 break;
142#endif 143#endif
143#if ENABLE_UNISTDIO 144#if ENABLE_UNISTDIO
144 /* The unistdio extensions. */ 145 /* The unistdio extensions. */
145 case TYPE_U8_STRING: 146 case TYPE_U8_STRING:
146 ap->a.a_u8_string = va_arg (args, const uint8_t *); 147 ap->a.a_u8_string = va_arg (args, const uint8_t *);
147 /* A null pointer is an invalid argument for "%U", but in practice 148 /* A null pointer is an invalid argument for "%U", but in practice
148 it occurs quite frequently in printf statements that produce 149 it occurs quite frequently in printf statements that produce
149 debug output. Use a fallback in this case. */ 150 debug output. Use a fallback in this case. */
150 if (ap->a.a_u8_string == NULL) 151 if (ap->a.a_u8_string == NULL)
151 { 152 {
152 static const uint8_t u8_null_string[] = 153 static const uint8_t u8_null_string[] =
153 { '(', 'N', 'U', 'L', 'L', ')', 0 }; 154 { '(', 'N', 'U', 'L', 'L', ')', 0 };
154 ap->a.a_u8_string = u8_null_string; 155 ap->a.a_u8_string = u8_null_string;
155 } 156 }
156 break; 157 break;
157 case TYPE_U16_STRING: 158 case TYPE_U16_STRING:
158 ap->a.a_u16_string = va_arg (args, const uint16_t *); 159 ap->a.a_u16_string = va_arg (args, const uint16_t *);
159 /* A null pointer is an invalid argument for "%lU", but in practice 160 /* A null pointer is an invalid argument for "%lU", but in practice
160 it occurs quite frequently in printf statements that produce 161 it occurs quite frequently in printf statements that produce
161 debug output. Use a fallback in this case. */ 162 debug output. Use a fallback in this case. */
162 if (ap->a.a_u16_string == NULL) 163 if (ap->a.a_u16_string == NULL)
163 { 164 {
164 static const uint16_t u16_null_string[] = 165 static const uint16_t u16_null_string[] =
165 { '(', 'N', 'U', 'L', 'L', ')', 0 }; 166 { '(', 'N', 'U', 'L', 'L', ')', 0 };
166 ap->a.a_u16_string = u16_null_string; 167 ap->a.a_u16_string = u16_null_string;
167 } 168 }
168 break; 169 break;
169 case TYPE_U32_STRING: 170 case TYPE_U32_STRING:
170 ap->a.a_u32_string = va_arg (args, const uint32_t *); 171 ap->a.a_u32_string = va_arg (args, const uint32_t *);
171 /* A null pointer is an invalid argument for "%llU", but in practice 172 /* A null pointer is an invalid argument for "%llU", but in practice
172 it occurs quite frequently in printf statements that produce 173 it occurs quite frequently in printf statements that produce
173 debug output. Use a fallback in this case. */ 174 debug output. Use a fallback in this case. */
174 if (ap->a.a_u32_string == NULL) 175 if (ap->a.a_u32_string == NULL)
175 { 176 {
176 static const uint32_t u32_null_string[] = 177 static const uint32_t u32_null_string[] =
177 { '(', 'N', 'U', 'L', 'L', ')', 0 }; 178 { '(', 'N', 'U', 'L', 'L', ')', 0 };
178 ap->a.a_u32_string = u32_null_string; 179 ap->a.a_u32_string = u32_null_string;
179 } 180 }
180 break; 181 break;
181#endif 182#endif
182 default: 183 default:
183 /* Unknown type. */ 184 /* Unknown type. */
184 return -1; 185 return -1;
185 } 186 }
186 return 0; 187 return 0;
187} 188}
diff --git a/gl/printf-args.h b/gl/printf-args.h
index 67cb990c..2536ebaf 100644
--- a/gl/printf-args.h
+++ b/gl/printf-args.h
@@ -1,5 +1,6 @@
1/* Decomposed printf argument list. 1/* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2006-2007, 2009-2010 Free Software
3 Foundation, Inc.
3 4
4 This program is free software; you can redistribute it and/or modify 5 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 it under the terms of the GNU General Public License as published by
@@ -93,42 +94,42 @@ typedef struct
93 arg_type type; 94 arg_type type;
94 union 95 union
95 { 96 {
96 signed char a_schar; 97 signed char a_schar;
97 unsigned char a_uchar; 98 unsigned char a_uchar;
98 short a_short; 99 short a_short;
99 unsigned short a_ushort; 100 unsigned short a_ushort;
100 int a_int; 101 int a_int;
101 unsigned int a_uint; 102 unsigned int a_uint;
102 long int a_longint; 103 long int a_longint;
103 unsigned long int a_ulongint; 104 unsigned long int a_ulongint;
104#if HAVE_LONG_LONG_INT 105#if HAVE_LONG_LONG_INT
105 long long int a_longlongint; 106 long long int a_longlongint;
106 unsigned long long int a_ulonglongint; 107 unsigned long long int a_ulonglongint;
107#endif 108#endif
108 float a_float; 109 float a_float;
109 double a_double; 110 double a_double;
110 long double a_longdouble; 111 long double a_longdouble;
111 int a_char; 112 int a_char;
112#if HAVE_WINT_T 113#if HAVE_WINT_T
113 wint_t a_wide_char; 114 wint_t a_wide_char;
114#endif 115#endif
115 const char* a_string; 116 const char* a_string;
116#if HAVE_WCHAR_T 117#if HAVE_WCHAR_T
117 const wchar_t* a_wide_string; 118 const wchar_t* a_wide_string;
118#endif 119#endif
119 void* a_pointer; 120 void* a_pointer;
120 signed char * a_count_schar_pointer; 121 signed char * a_count_schar_pointer;
121 short * a_count_short_pointer; 122 short * a_count_short_pointer;
122 int * a_count_int_pointer; 123 int * a_count_int_pointer;
123 long int * a_count_longint_pointer; 124 long int * a_count_longint_pointer;
124#if HAVE_LONG_LONG_INT 125#if HAVE_LONG_LONG_INT
125 long long int * a_count_longlongint_pointer; 126 long long int * a_count_longlongint_pointer;
126#endif 127#endif
127#if ENABLE_UNISTDIO 128#if ENABLE_UNISTDIO
128 /* The unistdio extensions. */ 129 /* The unistdio extensions. */
129 const uint8_t * a_u8_string; 130 const uint8_t * a_u8_string;
130 const uint16_t * a_u16_string; 131 const uint16_t * a_u16_string;
131 const uint32_t * a_u32_string; 132 const uint32_t * a_u32_string;
132#endif 133#endif
133 } 134 }
134 a; 135 a;
diff --git a/gl/printf-parse.c b/gl/printf-parse.c
index 28b9bd41..f612beb5 100644
--- a/gl/printf-parse.c
+++ b/gl/printf-parse.c
@@ -1,5 +1,5 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc. 2 Copyright (C) 1999-2000, 2002-2003, 2006-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -80,10 +80,10 @@ STATIC
80int 80int
81PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) 81PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
82{ 82{
83 const CHAR_T *cp = format; /* pointer into format */ 83 const CHAR_T *cp = format; /* pointer into format */
84 size_t arg_posn = 0; /* number of regular arguments consumed */ 84 size_t arg_posn = 0; /* number of regular arguments consumed */
85 size_t d_allocated; /* allocated elements of d->dir */ 85 size_t d_allocated; /* allocated elements of d->dir */
86 size_t a_allocated; /* allocated elements of a->arg */ 86 size_t a_allocated; /* allocated elements of a->arg */
87 size_t max_width_length = 0; 87 size_t max_width_length = 0;
88 size_t max_precision_length = 0; 88 size_t max_precision_length = 0;
89 89
@@ -99,501 +99,501 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
99 a->arg = NULL; 99 a->arg = NULL;
100 100
101#define REGISTER_ARG(_index_,_type_) \ 101#define REGISTER_ARG(_index_,_type_) \
102 { \ 102 { \
103 size_t n = (_index_); \ 103 size_t n = (_index_); \
104 if (n >= a_allocated) \ 104 if (n >= a_allocated) \
105 { \ 105 { \
106 size_t memory_size; \ 106 size_t memory_size; \
107 argument *memory; \ 107 argument *memory; \
108 \ 108 \
109 a_allocated = xtimes (a_allocated, 2); \ 109 a_allocated = xtimes (a_allocated, 2); \
110 if (a_allocated <= n) \ 110 if (a_allocated <= n) \
111 a_allocated = xsum (n, 1); \ 111 a_allocated = xsum (n, 1); \
112 memory_size = xtimes (a_allocated, sizeof (argument)); \ 112 memory_size = xtimes (a_allocated, sizeof (argument)); \
113 if (size_overflow_p (memory_size)) \ 113 if (size_overflow_p (memory_size)) \
114 /* Overflow, would lead to out of memory. */ \ 114 /* Overflow, would lead to out of memory. */ \
115 goto out_of_memory; \ 115 goto out_of_memory; \
116 memory = (argument *) (a->arg \ 116 memory = (argument *) (a->arg \
117 ? realloc (a->arg, memory_size) \ 117 ? realloc (a->arg, memory_size) \
118 : malloc (memory_size)); \ 118 : malloc (memory_size)); \
119 if (memory == NULL) \ 119 if (memory == NULL) \
120 /* Out of memory. */ \ 120 /* Out of memory. */ \
121 goto out_of_memory; \ 121 goto out_of_memory; \
122 a->arg = memory; \ 122 a->arg = memory; \
123 } \ 123 } \
124 while (a->count <= n) \ 124 while (a->count <= n) \
125 a->arg[a->count++].type = TYPE_NONE; \ 125 a->arg[a->count++].type = TYPE_NONE; \
126 if (a->arg[n].type == TYPE_NONE) \ 126 if (a->arg[n].type == TYPE_NONE) \
127 a->arg[n].type = (_type_); \ 127 a->arg[n].type = (_type_); \
128 else if (a->arg[n].type != (_type_)) \ 128 else if (a->arg[n].type != (_type_)) \
129 /* Ambiguous type for positional argument. */ \ 129 /* Ambiguous type for positional argument. */ \
130 goto error; \ 130 goto error; \
131 } 131 }
132 132
133 while (*cp != '\0') 133 while (*cp != '\0')
134 { 134 {
135 CHAR_T c = *cp++; 135 CHAR_T c = *cp++;
136 if (c == '%') 136 if (c == '%')
137 { 137 {
138 size_t arg_index = ARG_NONE; 138 size_t arg_index = ARG_NONE;
139 DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ 139 DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
140 140
141 /* Initialize the next directive. */ 141 /* Initialize the next directive. */
142 dp->dir_start = cp - 1; 142 dp->dir_start = cp - 1;
143 dp->flags = 0; 143 dp->flags = 0;
144 dp->width_start = NULL; 144 dp->width_start = NULL;
145 dp->width_end = NULL; 145 dp->width_end = NULL;
146 dp->width_arg_index = ARG_NONE; 146 dp->width_arg_index = ARG_NONE;
147 dp->precision_start = NULL; 147 dp->precision_start = NULL;
148 dp->precision_end = NULL; 148 dp->precision_end = NULL;
149 dp->precision_arg_index = ARG_NONE; 149 dp->precision_arg_index = ARG_NONE;
150 dp->arg_index = ARG_NONE; 150 dp->arg_index = ARG_NONE;
151 151
152 /* Test for positional argument. */ 152 /* Test for positional argument. */
153 if (*cp >= '0' && *cp <= '9') 153 if (*cp >= '0' && *cp <= '9')
154 { 154 {
155 const CHAR_T *np; 155 const CHAR_T *np;
156 156
157 for (np = cp; *np >= '0' && *np <= '9'; np++) 157 for (np = cp; *np >= '0' && *np <= '9'; np++)
158 ; 158 ;
159 if (*np == '$') 159 if (*np == '$')
160 { 160 {
161 size_t n = 0; 161 size_t n = 0;
162 162
163 for (np = cp; *np >= '0' && *np <= '9'; np++) 163 for (np = cp; *np >= '0' && *np <= '9'; np++)
164 n = xsum (xtimes (n, 10), *np - '0'); 164 n = xsum (xtimes (n, 10), *np - '0');
165 if (n == 0) 165 if (n == 0)
166 /* Positional argument 0. */ 166 /* Positional argument 0. */
167 goto error; 167 goto error;
168 if (size_overflow_p (n)) 168 if (size_overflow_p (n))
169 /* n too large, would lead to out of memory later. */ 169 /* n too large, would lead to out of memory later. */
170 goto error; 170 goto error;
171 arg_index = n - 1; 171 arg_index = n - 1;
172 cp = np + 1; 172 cp = np + 1;
173 } 173 }
174 } 174 }
175 175
176 /* Read the flags. */ 176 /* Read the flags. */
177 for (;;) 177 for (;;)
178 { 178 {
179 if (*cp == '\'') 179 if (*cp == '\'')
180 { 180 {
181 dp->flags |= FLAG_GROUP; 181 dp->flags |= FLAG_GROUP;
182 cp++; 182 cp++;
183 } 183 }
184 else if (*cp == '-') 184 else if (*cp == '-')
185 { 185 {
186 dp->flags |= FLAG_LEFT; 186 dp->flags |= FLAG_LEFT;
187 cp++; 187 cp++;
188 } 188 }
189 else if (*cp == '+') 189 else if (*cp == '+')
190 { 190 {
191 dp->flags |= FLAG_SHOWSIGN; 191 dp->flags |= FLAG_SHOWSIGN;
192 cp++; 192 cp++;
193 } 193 }
194 else if (*cp == ' ') 194 else if (*cp == ' ')
195 { 195 {
196 dp->flags |= FLAG_SPACE; 196 dp->flags |= FLAG_SPACE;
197 cp++; 197 cp++;
198 } 198 }
199 else if (*cp == '#') 199 else if (*cp == '#')
200 { 200 {
201 dp->flags |= FLAG_ALT; 201 dp->flags |= FLAG_ALT;
202 cp++; 202 cp++;
203 } 203 }
204 else if (*cp == '0') 204 else if (*cp == '0')
205 { 205 {
206 dp->flags |= FLAG_ZERO; 206 dp->flags |= FLAG_ZERO;
207 cp++; 207 cp++;
208 } 208 }
209 else 209 else
210 break; 210 break;
211 } 211 }
212 212
213 /* Parse the field width. */ 213 /* Parse the field width. */
214 if (*cp == '*') 214 if (*cp == '*')
215 { 215 {
216 dp->width_start = cp; 216 dp->width_start = cp;
217 cp++; 217 cp++;
218 dp->width_end = cp; 218 dp->width_end = cp;
219 if (max_width_length < 1) 219 if (max_width_length < 1)
220 max_width_length = 1; 220 max_width_length = 1;
221 221
222 /* Test for positional argument. */ 222 /* Test for positional argument. */
223 if (*cp >= '0' && *cp <= '9') 223 if (*cp >= '0' && *cp <= '9')
224 { 224 {
225 const CHAR_T *np; 225 const CHAR_T *np;
226 226
227 for (np = cp; *np >= '0' && *np <= '9'; np++) 227 for (np = cp; *np >= '0' && *np <= '9'; np++)
228 ; 228 ;
229 if (*np == '$') 229 if (*np == '$')
230 { 230 {
231 size_t n = 0; 231 size_t n = 0;
232 232
233 for (np = cp; *np >= '0' && *np <= '9'; np++) 233 for (np = cp; *np >= '0' && *np <= '9'; np++)
234 n = xsum (xtimes (n, 10), *np - '0'); 234 n = xsum (xtimes (n, 10), *np - '0');
235 if (n == 0) 235 if (n == 0)
236 /* Positional argument 0. */ 236 /* Positional argument 0. */
237 goto error; 237 goto error;
238 if (size_overflow_p (n)) 238 if (size_overflow_p (n))
239 /* n too large, would lead to out of memory later. */ 239 /* n too large, would lead to out of memory later. */
240 goto error; 240 goto error;
241 dp->width_arg_index = n - 1; 241 dp->width_arg_index = n - 1;
242 cp = np + 1; 242 cp = np + 1;
243 } 243 }
244 } 244 }
245 if (dp->width_arg_index == ARG_NONE) 245 if (dp->width_arg_index == ARG_NONE)
246 { 246 {
247 dp->width_arg_index = arg_posn++; 247 dp->width_arg_index = arg_posn++;
248 if (dp->width_arg_index == ARG_NONE) 248 if (dp->width_arg_index == ARG_NONE)
249 /* arg_posn wrapped around. */ 249 /* arg_posn wrapped around. */
250 goto error; 250 goto error;
251 } 251 }
252 REGISTER_ARG (dp->width_arg_index, TYPE_INT); 252 REGISTER_ARG (dp->width_arg_index, TYPE_INT);
253 } 253 }
254 else if (*cp >= '0' && *cp <= '9') 254 else if (*cp >= '0' && *cp <= '9')
255 { 255 {
256 size_t width_length; 256 size_t width_length;
257 257
258 dp->width_start = cp; 258 dp->width_start = cp;
259 for (; *cp >= '0' && *cp <= '9'; cp++) 259 for (; *cp >= '0' && *cp <= '9'; cp++)
260 ; 260 ;
261 dp->width_end = cp; 261 dp->width_end = cp;
262 width_length = dp->width_end - dp->width_start; 262 width_length = dp->width_end - dp->width_start;
263 if (max_width_length < width_length) 263 if (max_width_length < width_length)
264 max_width_length = width_length; 264 max_width_length = width_length;
265 } 265 }
266 266
267 /* Parse the precision. */ 267 /* Parse the precision. */
268 if (*cp == '.') 268 if (*cp == '.')
269 { 269 {
270 cp++; 270 cp++;
271 if (*cp == '*') 271 if (*cp == '*')
272 { 272 {
273 dp->precision_start = cp - 1; 273 dp->precision_start = cp - 1;
274 cp++; 274 cp++;
275 dp->precision_end = cp; 275 dp->precision_end = cp;
276 if (max_precision_length < 2) 276 if (max_precision_length < 2)
277 max_precision_length = 2; 277 max_precision_length = 2;
278 278
279 /* Test for positional argument. */ 279 /* Test for positional argument. */
280 if (*cp >= '0' && *cp <= '9') 280 if (*cp >= '0' && *cp <= '9')
281 { 281 {
282 const CHAR_T *np; 282 const CHAR_T *np;
283 283
284 for (np = cp; *np >= '0' && *np <= '9'; np++) 284 for (np = cp; *np >= '0' && *np <= '9'; np++)
285 ; 285 ;
286 if (*np == '$') 286 if (*np == '$')
287 { 287 {
288 size_t n = 0; 288 size_t n = 0;
289 289
290 for (np = cp; *np >= '0' && *np <= '9'; np++) 290 for (np = cp; *np >= '0' && *np <= '9'; np++)
291 n = xsum (xtimes (n, 10), *np - '0'); 291 n = xsum (xtimes (n, 10), *np - '0');
292 if (n == 0) 292 if (n == 0)
293 /* Positional argument 0. */ 293 /* Positional argument 0. */
294 goto error; 294 goto error;
295 if (size_overflow_p (n)) 295 if (size_overflow_p (n))
296 /* n too large, would lead to out of memory 296 /* n too large, would lead to out of memory
297 later. */ 297 later. */
298 goto error; 298 goto error;
299 dp->precision_arg_index = n - 1; 299 dp->precision_arg_index = n - 1;
300 cp = np + 1; 300 cp = np + 1;
301 } 301 }
302 } 302 }
303 if (dp->precision_arg_index == ARG_NONE) 303 if (dp->precision_arg_index == ARG_NONE)
304 { 304 {
305 dp->precision_arg_index = arg_posn++; 305 dp->precision_arg_index = arg_posn++;
306 if (dp->precision_arg_index == ARG_NONE) 306 if (dp->precision_arg_index == ARG_NONE)
307 /* arg_posn wrapped around. */ 307 /* arg_posn wrapped around. */
308 goto error; 308 goto error;
309 } 309 }
310 REGISTER_ARG (dp->precision_arg_index, TYPE_INT); 310 REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
311 } 311 }
312 else 312 else
313 { 313 {
314 size_t precision_length; 314 size_t precision_length;
315 315
316 dp->precision_start = cp - 1; 316 dp->precision_start = cp - 1;
317 for (; *cp >= '0' && *cp <= '9'; cp++) 317 for (; *cp >= '0' && *cp <= '9'; cp++)
318 ; 318 ;
319 dp->precision_end = cp; 319 dp->precision_end = cp;
320 precision_length = dp->precision_end - dp->precision_start; 320 precision_length = dp->precision_end - dp->precision_start;
321 if (max_precision_length < precision_length) 321 if (max_precision_length < precision_length)
322 max_precision_length = precision_length; 322 max_precision_length = precision_length;
323 } 323 }
324 } 324 }
325 325
326 { 326 {
327 arg_type type; 327 arg_type type;
328 328
329 /* Parse argument type/size specifiers. */ 329 /* Parse argument type/size specifiers. */
330 { 330 {
331 int flags = 0; 331 int flags = 0;
332 332
333 for (;;) 333 for (;;)
334 { 334 {
335 if (*cp == 'h') 335 if (*cp == 'h')
336 { 336 {
337 flags |= (1 << (flags & 1)); 337 flags |= (1 << (flags & 1));
338 cp++; 338 cp++;
339 } 339 }
340 else if (*cp == 'L') 340 else if (*cp == 'L')
341 { 341 {
342 flags |= 4; 342 flags |= 4;
343 cp++; 343 cp++;
344 } 344 }
345 else if (*cp == 'l') 345 else if (*cp == 'l')
346 { 346 {
347 flags += 8; 347 flags += 8;
348 cp++; 348 cp++;
349 } 349 }
350 else if (*cp == 'j') 350 else if (*cp == 'j')
351 { 351 {
352 if (sizeof (intmax_t) > sizeof (long)) 352 if (sizeof (intmax_t) > sizeof (long))
353 { 353 {
354 /* intmax_t = long long */ 354 /* intmax_t = long long */
355 flags += 16; 355 flags += 16;
356 } 356 }
357 else if (sizeof (intmax_t) > sizeof (int)) 357 else if (sizeof (intmax_t) > sizeof (int))
358 { 358 {
359 /* intmax_t = long */ 359 /* intmax_t = long */
360 flags += 8; 360 flags += 8;
361 } 361 }
362 cp++; 362 cp++;
363 } 363 }
364 else if (*cp == 'z' || *cp == 'Z') 364 else if (*cp == 'z' || *cp == 'Z')
365 { 365 {
366 /* 'z' is standardized in ISO C 99, but glibc uses 'Z' 366 /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
367 because the warning facility in gcc-2.95.2 understands 367 because the warning facility in gcc-2.95.2 understands
368 only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ 368 only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
369 if (sizeof (size_t) > sizeof (long)) 369 if (sizeof (size_t) > sizeof (long))
370 { 370 {
371 /* size_t = long long */ 371 /* size_t = long long */
372 flags += 16; 372 flags += 16;
373 } 373 }
374 else if (sizeof (size_t) > sizeof (int)) 374 else if (sizeof (size_t) > sizeof (int))
375 { 375 {
376 /* size_t = long */ 376 /* size_t = long */
377 flags += 8; 377 flags += 8;
378 } 378 }
379 cp++; 379 cp++;
380 } 380 }
381 else if (*cp == 't') 381 else if (*cp == 't')
382 { 382 {
383 if (sizeof (ptrdiff_t) > sizeof (long)) 383 if (sizeof (ptrdiff_t) > sizeof (long))
384 { 384 {
385 /* ptrdiff_t = long long */ 385 /* ptrdiff_t = long long */
386 flags += 16; 386 flags += 16;
387 } 387 }
388 else if (sizeof (ptrdiff_t) > sizeof (int)) 388 else if (sizeof (ptrdiff_t) > sizeof (int))
389 { 389 {
390 /* ptrdiff_t = long */ 390 /* ptrdiff_t = long */
391 flags += 8; 391 flags += 8;
392 } 392 }
393 cp++; 393 cp++;
394 } 394 }
395#if defined __APPLE__ && defined __MACH__ 395#if defined __APPLE__ && defined __MACH__
396 /* On MacOS X 10.3, PRIdMAX is defined as "qd". 396 /* On MacOS X 10.3, PRIdMAX is defined as "qd".
397 We cannot change it to "lld" because PRIdMAX must also 397 We cannot change it to "lld" because PRIdMAX must also
398 be understood by the system's printf routines. */ 398 be understood by the system's printf routines. */
399 else if (*cp == 'q') 399 else if (*cp == 'q')
400 { 400 {
401 if (64 / 8 > sizeof (long)) 401 if (64 / 8 > sizeof (long))
402 { 402 {
403 /* int64_t = long long */ 403 /* int64_t = long long */
404 flags += 16; 404 flags += 16;
405 } 405 }
406 else 406 else
407 { 407 {
408 /* int64_t = long */ 408 /* int64_t = long */
409 flags += 8; 409 flags += 8;
410 } 410 }
411 cp++; 411 cp++;
412 } 412 }
413#endif 413#endif
414#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 414#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
415 /* On native Win32, PRIdMAX is defined as "I64d". 415 /* On native Win32, PRIdMAX is defined as "I64d".
416 We cannot change it to "lld" because PRIdMAX must also 416 We cannot change it to "lld" because PRIdMAX must also
417 be understood by the system's printf routines. */ 417 be understood by the system's printf routines. */
418 else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') 418 else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
419 { 419 {
420 if (64 / 8 > sizeof (long)) 420 if (64 / 8 > sizeof (long))
421 { 421 {
422 /* __int64 = long long */ 422 /* __int64 = long long */
423 flags += 16; 423 flags += 16;
424 } 424 }
425 else 425 else
426 { 426 {
427 /* __int64 = long */ 427 /* __int64 = long */
428 flags += 8; 428 flags += 8;
429 } 429 }
430 cp += 3; 430 cp += 3;
431 } 431 }
432#endif 432#endif
433 else 433 else
434 break; 434 break;
435 } 435 }
436 436
437 /* Read the conversion character. */ 437 /* Read the conversion character. */
438 c = *cp++; 438 c = *cp++;
439 switch (c) 439 switch (c)
440 { 440 {
441 case 'd': case 'i': 441 case 'd': case 'i':
442#if HAVE_LONG_LONG_INT 442#if HAVE_LONG_LONG_INT
443 /* If 'long long' exists and is larger than 'long': */ 443 /* If 'long long' exists and is larger than 'long': */
444 if (flags >= 16 || (flags & 4)) 444 if (flags >= 16 || (flags & 4))
445 type = TYPE_LONGLONGINT; 445 type = TYPE_LONGLONGINT;
446 else 446 else
447#endif 447#endif
448 /* If 'long long' exists and is the same as 'long', we parse 448 /* If 'long long' exists and is the same as 'long', we parse
449 "lld" into TYPE_LONGINT. */ 449 "lld" into TYPE_LONGINT. */
450 if (flags >= 8) 450 if (flags >= 8)
451 type = TYPE_LONGINT; 451 type = TYPE_LONGINT;
452 else if (flags & 2) 452 else if (flags & 2)
453 type = TYPE_SCHAR; 453 type = TYPE_SCHAR;
454 else if (flags & 1) 454 else if (flags & 1)
455 type = TYPE_SHORT; 455 type = TYPE_SHORT;
456 else 456 else
457 type = TYPE_INT; 457 type = TYPE_INT;
458 break; 458 break;
459 case 'o': case 'u': case 'x': case 'X': 459 case 'o': case 'u': case 'x': case 'X':
460#if HAVE_LONG_LONG_INT 460#if HAVE_LONG_LONG_INT
461 /* If 'long long' exists and is larger than 'long': */ 461 /* If 'long long' exists and is larger than 'long': */
462 if (flags >= 16 || (flags & 4)) 462 if (flags >= 16 || (flags & 4))
463 type = TYPE_ULONGLONGINT; 463 type = TYPE_ULONGLONGINT;
464 else 464 else
465#endif 465#endif
466 /* If 'unsigned long long' exists and is the same as 466 /* If 'unsigned long long' exists and is the same as
467 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ 467 'unsigned long', we parse "llu" into TYPE_ULONGINT. */
468 if (flags >= 8) 468 if (flags >= 8)
469 type = TYPE_ULONGINT; 469 type = TYPE_ULONGINT;
470 else if (flags & 2) 470 else if (flags & 2)
471 type = TYPE_UCHAR; 471 type = TYPE_UCHAR;
472 else if (flags & 1) 472 else if (flags & 1)
473 type = TYPE_USHORT; 473 type = TYPE_USHORT;
474 else 474 else
475 type = TYPE_UINT; 475 type = TYPE_UINT;
476 break; 476 break;
477 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': 477 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
478 case 'a': case 'A': 478 case 'a': case 'A':
479 if (flags >= 16 || (flags & 4)) 479 if (flags >= 16 || (flags & 4))
480 type = TYPE_LONGDOUBLE; 480 type = TYPE_LONGDOUBLE;
481 else 481 else
482 type = TYPE_DOUBLE; 482 type = TYPE_DOUBLE;
483 break; 483 break;
484 case 'c': 484 case 'c':
485 if (flags >= 8) 485 if (flags >= 8)
486#if HAVE_WINT_T 486#if HAVE_WINT_T
487 type = TYPE_WIDE_CHAR; 487 type = TYPE_WIDE_CHAR;
488#else 488#else
489 goto error; 489 goto error;
490#endif 490#endif
491 else 491 else
492 type = TYPE_CHAR; 492 type = TYPE_CHAR;
493 break; 493 break;
494#if HAVE_WINT_T 494#if HAVE_WINT_T
495 case 'C': 495 case 'C':
496 type = TYPE_WIDE_CHAR; 496 type = TYPE_WIDE_CHAR;
497 c = 'c'; 497 c = 'c';
498 break; 498 break;
499#endif 499#endif
500 case 's': 500 case 's':
501 if (flags >= 8) 501 if (flags >= 8)
502#if HAVE_WCHAR_T 502#if HAVE_WCHAR_T
503 type = TYPE_WIDE_STRING; 503 type = TYPE_WIDE_STRING;
504#else 504#else
505 goto error; 505 goto error;
506#endif 506#endif
507 else 507 else
508 type = TYPE_STRING; 508 type = TYPE_STRING;
509 break; 509 break;
510#if HAVE_WCHAR_T 510#if HAVE_WCHAR_T
511 case 'S': 511 case 'S':
512 type = TYPE_WIDE_STRING; 512 type = TYPE_WIDE_STRING;
513 c = 's'; 513 c = 's';
514 break; 514 break;
515#endif 515#endif
516 case 'p': 516 case 'p':
517 type = TYPE_POINTER; 517 type = TYPE_POINTER;
518 break; 518 break;
519 case 'n': 519 case 'n':
520#if HAVE_LONG_LONG_INT 520#if HAVE_LONG_LONG_INT
521 /* If 'long long' exists and is larger than 'long': */ 521 /* If 'long long' exists and is larger than 'long': */
522 if (flags >= 16 || (flags & 4)) 522 if (flags >= 16 || (flags & 4))
523 type = TYPE_COUNT_LONGLONGINT_POINTER; 523 type = TYPE_COUNT_LONGLONGINT_POINTER;
524 else 524 else
525#endif 525#endif
526 /* If 'long long' exists and is the same as 'long', we parse 526 /* If 'long long' exists and is the same as 'long', we parse
527 "lln" into TYPE_COUNT_LONGINT_POINTER. */ 527 "lln" into TYPE_COUNT_LONGINT_POINTER. */
528 if (flags >= 8) 528 if (flags >= 8)
529 type = TYPE_COUNT_LONGINT_POINTER; 529 type = TYPE_COUNT_LONGINT_POINTER;
530 else if (flags & 2) 530 else if (flags & 2)
531 type = TYPE_COUNT_SCHAR_POINTER; 531 type = TYPE_COUNT_SCHAR_POINTER;
532 else if (flags & 1) 532 else if (flags & 1)
533 type = TYPE_COUNT_SHORT_POINTER; 533 type = TYPE_COUNT_SHORT_POINTER;
534 else 534 else
535 type = TYPE_COUNT_INT_POINTER; 535 type = TYPE_COUNT_INT_POINTER;
536 break; 536 break;
537#if ENABLE_UNISTDIO 537#if ENABLE_UNISTDIO
538 /* The unistdio extensions. */ 538 /* The unistdio extensions. */
539 case 'U': 539 case 'U':
540 if (flags >= 16) 540 if (flags >= 16)
541 type = TYPE_U32_STRING; 541 type = TYPE_U32_STRING;
542 else if (flags >= 8) 542 else if (flags >= 8)
543 type = TYPE_U16_STRING; 543 type = TYPE_U16_STRING;
544 else 544 else
545 type = TYPE_U8_STRING; 545 type = TYPE_U8_STRING;
546 break; 546 break;
547#endif 547#endif
548 case '%': 548 case '%':
549 type = TYPE_NONE; 549 type = TYPE_NONE;
550 break; 550 break;
551 default: 551 default:
552 /* Unknown conversion character. */ 552 /* Unknown conversion character. */
553 goto error; 553 goto error;
554 } 554 }
555 } 555 }
556 556
557 if (type != TYPE_NONE) 557 if (type != TYPE_NONE)
558 { 558 {
559 dp->arg_index = arg_index; 559 dp->arg_index = arg_index;
560 if (dp->arg_index == ARG_NONE) 560 if (dp->arg_index == ARG_NONE)
561 { 561 {
562 dp->arg_index = arg_posn++; 562 dp->arg_index = arg_posn++;
563 if (dp->arg_index == ARG_NONE) 563 if (dp->arg_index == ARG_NONE)
564 /* arg_posn wrapped around. */ 564 /* arg_posn wrapped around. */
565 goto error; 565 goto error;
566 } 566 }
567 REGISTER_ARG (dp->arg_index, type); 567 REGISTER_ARG (dp->arg_index, type);
568 } 568 }
569 dp->conversion = c; 569 dp->conversion = c;
570 dp->dir_end = cp; 570 dp->dir_end = cp;
571 } 571 }
572 572
573 d->count++; 573 d->count++;
574 if (d->count >= d_allocated) 574 if (d->count >= d_allocated)
575 { 575 {
576 size_t memory_size; 576 size_t memory_size;
577 DIRECTIVE *memory; 577 DIRECTIVE *memory;
578 578
579 d_allocated = xtimes (d_allocated, 2); 579 d_allocated = xtimes (d_allocated, 2);
580 memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); 580 memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
581 if (size_overflow_p (memory_size)) 581 if (size_overflow_p (memory_size))
582 /* Overflow, would lead to out of memory. */ 582 /* Overflow, would lead to out of memory. */
583 goto out_of_memory; 583 goto out_of_memory;
584 memory = (DIRECTIVE *) realloc (d->dir, memory_size); 584 memory = (DIRECTIVE *) realloc (d->dir, memory_size);
585 if (memory == NULL) 585 if (memory == NULL)
586 /* Out of memory. */ 586 /* Out of memory. */
587 goto out_of_memory; 587 goto out_of_memory;
588 d->dir = memory; 588 d->dir = memory;
589 } 589 }
590 } 590 }
591#if CHAR_T_ONLY_ASCII 591#if CHAR_T_ONLY_ASCII
592 else if (!c_isascii (c)) 592 else if (!c_isascii (c))
593 { 593 {
594 /* Non-ASCII character. Not supported. */ 594 /* Non-ASCII character. Not supported. */
595 goto error; 595 goto error;
596 } 596 }
597#endif 597#endif
598 } 598 }
599 d->dir[d->count].dir_start = cp; 599 d->dir[d->count].dir_start = cp;
diff --git a/gl/printf-parse.h b/gl/printf-parse.h
index e5d68d75..0f2b7082 100644
--- a/gl/printf-parse.h
+++ b/gl/printf-parse.h
@@ -1,5 +1,6 @@
1/* Parse printf format string. 1/* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2009-2010 Free Software
3 Foundation, Inc.
3 4
4 This program is free software; you can redistribute it and/or modify 5 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 it under the terms of the GNU General Public License as published by
@@ -26,15 +27,15 @@
26 27
27 28
28/* Flags */ 29/* Flags */
29#define FLAG_GROUP 1 /* ' flag */ 30#define FLAG_GROUP 1 /* ' flag */
30#define FLAG_LEFT 2 /* - flag */ 31#define FLAG_LEFT 2 /* - flag */
31#define FLAG_SHOWSIGN 4 /* + flag */ 32#define FLAG_SHOWSIGN 4 /* + flag */
32#define FLAG_SPACE 8 /* space flag */ 33#define FLAG_SPACE 8 /* space flag */
33#define FLAG_ALT 16 /* # flag */ 34#define FLAG_ALT 16 /* # flag */
34#define FLAG_ZERO 32 35#define FLAG_ZERO 32
35 36
36/* arg_index value indicating that no argument is consumed. */ 37/* arg_index value indicating that no argument is consumed. */
37#define ARG_NONE (~(size_t)0) 38#define ARG_NONE (~(size_t)0)
38 39
39/* xxx_directive: A parsed directive. 40/* xxx_directive: A parsed directive.
40 xxx_directives: A parsed format string. */ 41 xxx_directives: A parsed format string. */
@@ -163,10 +164,10 @@ extern int
163 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a); 164 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
164extern int 165extern int
165 u16_printf_parse (const uint16_t *format, u16_directives *d, 166 u16_printf_parse (const uint16_t *format, u16_directives *d,
166 arguments *a); 167 arguments *a);
167extern int 168extern int
168 u32_printf_parse (const uint32_t *format, u32_directives *d, 169 u32_printf_parse (const uint32_t *format, u32_directives *d,
169 arguments *a); 170 arguments *a);
170#else 171#else
171# ifdef STATIC 172# ifdef STATIC
172STATIC 173STATIC
diff --git a/gl/ref-add.sin b/gl/ref-add.sin
index 222d7529..dbb61df3 100644
--- a/gl/ref-add.sin
+++ b/gl/ref-add.sin
@@ -1,6 +1,6 @@
1# Add this package to a list of references stored in a text file. 1# Add this package to a list of references stored in a text file.
2# 2#
3# Copyright (C) 2000 Free Software Foundation, Inc. 3# Copyright (C) 2000, 2009, 2010 Free Software Foundation, Inc.
4# 4#
5# This program is free software; you can redistribute it and/or modify 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 6# it under the terms of the GNU General Public License as published by
diff --git a/gl/ref-del.sin b/gl/ref-del.sin
index 1bf073e1..4c31a6ea 100644
--- a/gl/ref-del.sin
+++ b/gl/ref-del.sin
@@ -1,6 +1,6 @@
1# Remove this package from a list of references stored in a text file. 1# Remove this package from a list of references stored in a text file.
2# 2#
3# Copyright (C) 2000 Free Software Foundation, Inc. 3# Copyright (C) 2000, 2009, 2010 Free Software Foundation, Inc.
4# 4#
5# This program is free software; you can redistribute it and/or modify 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 6# it under the terms of the GNU General Public License as published by
diff --git a/gl/regcomp.c b/gl/regcomp.c
index b114b4d1..86ca02b0 100644
--- a/gl/regcomp.c
+++ b/gl/regcomp.c
@@ -1,6 +1,6 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3 Free Software Foundation, Inc. 3 Software Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
6 6
@@ -383,7 +383,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
383 applies to multibyte character sets; for single byte character 383 applies to multibyte character sets; for single byte character
384 sets, the SIMPLE_BRACKET again suffices. */ 384 sets, the SIMPLE_BRACKET again suffices. */
385 if (dfa->mb_cur_max > 1 385 if (dfa->mb_cur_max > 1
386 && (cset->nchar_classes || cset->non_match 386 && (cset->nchar_classes || cset->non_match || cset->nranges
387# ifdef _LIBC 387# ifdef _LIBC
388 || cset->nequiv_classes 388 || cset->nequiv_classes
389# endif /* _LIBC */ 389# endif /* _LIBC */
@@ -636,7 +636,7 @@ free_dfa_content (re_dfa_t *dfa)
636 re_dfastate_t *state = entry->array[j]; 636 re_dfastate_t *state = entry->array[j];
637 free_state (state); 637 free_state (state);
638 } 638 }
639 re_free (entry->array); 639 re_free (entry->array);
640 } 640 }
641 re_free (dfa->state_table); 641 re_free (dfa->state_table);
642#ifdef RE_ENABLE_I18N 642#ifdef RE_ENABLE_I18N
@@ -850,6 +850,9 @@ static reg_errcode_t
850init_dfa (re_dfa_t *dfa, size_t pat_len) 850init_dfa (re_dfa_t *dfa, size_t pat_len)
851{ 851{
852 __re_size_t table_size; 852 __re_size_t table_size;
853#ifndef _LIBC
854 char *codeset_name;
855#endif
853#ifdef RE_ENABLE_I18N 856#ifdef RE_ENABLE_I18N
854 size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t)); 857 size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
855#else 858#else
@@ -893,7 +896,9 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
893 dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII) 896 dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
894 != 0); 897 != 0);
895#else 898#else
896 if (strcmp (locale_charset (), "UTF-8") == 0) 899 codeset_name = nl_langinfo (CODESET);
900 if (strcasecmp (codeset_name, "UTF-8") == 0
901 || strcasecmp (codeset_name, "UTF8") == 0)
897 dfa->is_utf8 = 1; 902 dfa->is_utf8 = 1;
898 903
899 /* We check exhaustively in the loop below if this charset is a 904 /* We check exhaustively in the loop below if this charset is a
@@ -1016,7 +1021,10 @@ create_initial_state (re_dfa_t *dfa)
1016 Idx dest_idx = dfa->edests[node_idx].elems[0]; 1021 Idx dest_idx = dfa->edests[node_idx].elems[0];
1017 if (!re_node_set_contains (&init_nodes, dest_idx)) 1022 if (!re_node_set_contains (&init_nodes, dest_idx))
1018 { 1023 {
1019 re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx); 1024 reg_errcode_t merge_err
1025 = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx);
1026 if (merge_err != REG_NOERROR)
1027 return merge_err;
1020 i = 0; 1028 i = 0;
1021 } 1029 }
1022 } 1030 }
@@ -1085,8 +1093,8 @@ optimize_utf8 (re_dfa_t *dfa)
1085 } 1093 }
1086 break; 1094 break;
1087 case OP_PERIOD: 1095 case OP_PERIOD:
1088 has_period = true; 1096 has_period = true;
1089 break; 1097 break;
1090 case OP_BACK_REF: 1098 case OP_BACK_REF:
1091 case OP_ALT: 1099 case OP_ALT:
1092 case END_OF_RE: 1100 case END_OF_RE:
@@ -1187,7 +1195,7 @@ analyze (regex_t *preg)
1187 { 1195 {
1188 dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len); 1196 dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
1189 if (BE (dfa->inveclosures == NULL, 0)) 1197 if (BE (dfa->inveclosures == NULL, 0))
1190 return REG_ESPACE; 1198 return REG_ESPACE;
1191 ret = calc_inveclosure (dfa); 1199 ret = calc_inveclosure (dfa);
1192 } 1200 }
1193 1201
@@ -1209,16 +1217,16 @@ postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
1209 if that's the only child). */ 1217 if that's the only child). */
1210 while (node->left || node->right) 1218 while (node->left || node->right)
1211 if (node->left) 1219 if (node->left)
1212 node = node->left; 1220 node = node->left;
1213 else 1221 else
1214 node = node->right; 1222 node = node->right;
1215 1223
1216 do 1224 do
1217 { 1225 {
1218 reg_errcode_t err = fn (extra, node); 1226 reg_errcode_t err = fn (extra, node);
1219 if (BE (err != REG_NOERROR, 0)) 1227 if (BE (err != REG_NOERROR, 0))
1220 return err; 1228 return err;
1221 if (node->parent == NULL) 1229 if (node->parent == NULL)
1222 return REG_NOERROR; 1230 return REG_NOERROR;
1223 prev = node; 1231 prev = node;
1224 node = node->parent; 1232 node = node->parent;
@@ -1252,7 +1260,7 @@ preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
1252 prev = node; 1260 prev = node;
1253 node = node->parent; 1261 node = node->parent;
1254 if (!node) 1262 if (!node)
1255 return REG_NOERROR; 1263 return REG_NOERROR;
1256 } 1264 }
1257 node = node->right; 1265 node = node->right;
1258 } 1266 }
@@ -1275,13 +1283,13 @@ optimize_subexps (void *extra, bin_tree_t *node)
1275 } 1283 }
1276 1284
1277 else if (node->token.type == SUBEXP 1285 else if (node->token.type == SUBEXP
1278 && node->left && node->left->token.type == SUBEXP) 1286 && node->left && node->left->token.type == SUBEXP)
1279 { 1287 {
1280 Idx other_idx = node->left->token.opr.idx; 1288 Idx other_idx = node->left->token.opr.idx;
1281 1289
1282 node->left = node->left->left; 1290 node->left = node->left->left;
1283 if (node->left) 1291 if (node->left)
1284 node->left->parent = node; 1292 node->left->parent = node;
1285 1293
1286 dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx]; 1294 dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
1287 if (other_idx < BITSET_WORD_BITS) 1295 if (other_idx < BITSET_WORD_BITS)
@@ -1366,9 +1374,9 @@ calc_first (void *extra, bin_tree_t *node)
1366 node->first = node; 1374 node->first = node;
1367 node->node_idx = re_dfa_add_node (dfa, node->token); 1375 node->node_idx = re_dfa_add_node (dfa, node->token);
1368 if (BE (node->node_idx == REG_MISSING, 0)) 1376 if (BE (node->node_idx == REG_MISSING, 0))
1369 return REG_ESPACE; 1377 return REG_ESPACE;
1370 if (node->token.type == ANCHOR) 1378 if (node->token.type == ANCHOR)
1371 dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type; 1379 dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type;
1372 } 1380 }
1373 return REG_NOERROR; 1381 return REG_NOERROR;
1374} 1382}
@@ -1390,7 +1398,7 @@ calc_next (void *extra, bin_tree_t *node)
1390 if (node->left) 1398 if (node->left)
1391 node->left->next = node->next; 1399 node->left->next = node->next;
1392 if (node->right) 1400 if (node->right)
1393 node->right->next = node->next; 1401 node->right->next = node->next;
1394 break; 1402 break;
1395 } 1403 }
1396 return REG_NOERROR; 1404 return REG_NOERROR;
@@ -1441,7 +1449,7 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1441 case OP_BACK_REF: 1449 case OP_BACK_REF:
1442 dfa->nexts[idx] = node->next->node_idx; 1450 dfa->nexts[idx] = node->next->node_idx;
1443 if (node->token.type == OP_BACK_REF) 1451 if (node->token.type == OP_BACK_REF)
1444 re_node_set_init_1 (dfa->edests + idx, dfa->nexts[idx]); 1452 err = re_node_set_init_1 (dfa->edests + idx, dfa->nexts[idx]);
1445 break; 1453 break;
1446 1454
1447 default: 1455 default:
@@ -1498,7 +1506,6 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1498 destination. */ 1506 destination. */
1499 org_dest = dfa->edests[org_node].elems[0]; 1507 org_dest = dfa->edests[org_node].elems[0];
1500 re_node_set_empty (dfa->edests + clone_node); 1508 re_node_set_empty (dfa->edests + clone_node);
1501 clone_dest = search_duplicated_node (dfa, org_dest, constraint);
1502 /* If the node is root_node itself, it means the epsilon closure 1509 /* If the node is root_node itself, it means the epsilon closure
1503 has a loop. Then tie it to the destination of the root_node. */ 1510 has a loop. Then tie it to the destination of the root_node. */
1504 if (org_node == root_node && clone_node != org_node) 1511 if (org_node == root_node && clone_node != org_node)
@@ -1542,7 +1549,7 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1542 } 1549 }
1543 else 1550 else
1544 { 1551 {
1545 /* There is a duplicated node which satisfy the constraint, 1552 /* There is a duplicated node which satisfies the constraint,
1546 use it to avoid infinite loop. */ 1553 use it to avoid infinite loop. */
1547 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1554 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1548 if (BE (! ok, 0)) 1555 if (BE (! ok, 0))
@@ -1674,10 +1681,9 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1674{ 1681{
1675 reg_errcode_t err; 1682 reg_errcode_t err;
1676 Idx i; 1683 Idx i;
1677 bool incomplete;
1678 bool ok;
1679 re_node_set eclosure; 1684 re_node_set eclosure;
1680 incomplete = false; 1685 bool ok;
1686 bool incomplete = false;
1681 err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1); 1687 err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
1682 if (BE (err != REG_NOERROR, 0)) 1688 if (BE (err != REG_NOERROR, 0))
1683 return err; 1689 return err;
@@ -1722,7 +1728,9 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1722 else 1728 else
1723 eclosure_elem = dfa->eclosures[edest]; 1729 eclosure_elem = dfa->eclosures[edest];
1724 /* Merge the epsilon closure of `edest'. */ 1730 /* Merge the epsilon closure of `edest'. */
1725 re_node_set_merge (&eclosure, &eclosure_elem); 1731 err = re_node_set_merge (&eclosure, &eclosure_elem);
1732 if (BE (err != REG_NOERROR, 0))
1733 return err;
1726 /* If the epsilon closure of `edest' is incomplete, 1734 /* If the epsilon closure of `edest' is incomplete,
1727 the epsilon closure of this node is also incomplete. */ 1735 the epsilon closure of this node is also incomplete. */
1728 if (dfa->eclosures[edest].nelem == 0) 1736 if (dfa->eclosures[edest].nelem == 0)
@@ -1732,7 +1740,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1732 } 1740 }
1733 } 1741 }
1734 1742
1735 /* Epsilon closures include itself. */ 1743 /* An epsilon closure includes itself. */
1736 ok = re_node_set_insert (&eclosure, node); 1744 ok = re_node_set_insert (&eclosure, node);
1737 if (BE (! ok, 0)) 1745 if (BE (! ok, 0))
1738 return REG_ESPACE; 1746 return REG_ESPACE;
@@ -2319,7 +2327,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2319 && dfa->word_ops_used == 0) 2327 && dfa->word_ops_used == 0)
2320 init_word_char (dfa); 2328 init_word_char (dfa);
2321 if (token->opr.ctx_type == WORD_DELIM 2329 if (token->opr.ctx_type == WORD_DELIM
2322 || token->opr.ctx_type == NOT_WORD_DELIM) 2330 || token->opr.ctx_type == NOT_WORD_DELIM)
2323 { 2331 {
2324 bin_tree_t *tree_first, *tree_last; 2332 bin_tree_t *tree_first, *tree_last;
2325 if (token->opr.ctx_type == WORD_DELIM) 2333 if (token->opr.ctx_type == WORD_DELIM)
@@ -2327,13 +2335,13 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2327 token->opr.ctx_type = WORD_FIRST; 2335 token->opr.ctx_type = WORD_FIRST;
2328 tree_first = create_token_tree (dfa, NULL, NULL, token); 2336 tree_first = create_token_tree (dfa, NULL, NULL, token);
2329 token->opr.ctx_type = WORD_LAST; 2337 token->opr.ctx_type = WORD_LAST;
2330 } 2338 }
2331 else 2339 else
2332 { 2340 {
2333 token->opr.ctx_type = INSIDE_WORD; 2341 token->opr.ctx_type = INSIDE_WORD;
2334 tree_first = create_token_tree (dfa, NULL, NULL, token); 2342 tree_first = create_token_tree (dfa, NULL, NULL, token);
2335 token->opr.ctx_type = INSIDE_NOTWORD; 2343 token->opr.ctx_type = INSIDE_NOTWORD;
2336 } 2344 }
2337 tree_last = create_token_tree (dfa, NULL, NULL, token); 2345 tree_last = create_token_tree (dfa, NULL, NULL, token);
2338 tree = create_tree (dfa, tree_first, tree_last, OP_ALT); 2346 tree = create_tree (dfa, tree_first, tree_last, OP_ALT);
2339 if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0)) 2347 if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0))
@@ -2444,7 +2452,7 @@ parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2444 { 2452 {
2445 tree = parse_reg_exp (regexp, preg, token, syntax, nest, err); 2453 tree = parse_reg_exp (regexp, preg, token, syntax, nest, err);
2446 if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0)) 2454 if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0))
2447 *err = REG_EPAREN; 2455 *err = REG_EPAREN;
2448 if (BE (*err != REG_NOERROR, 0)) 2456 if (BE (*err != REG_NOERROR, 0))
2449 return NULL; 2457 return NULL;
2450 } 2458 }
@@ -2515,7 +2523,8 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2515 return elem; 2523 return elem;
2516 } 2524 }
2517 2525
2518 if (BE (end != REG_MISSING && start > end, 0)) 2526 if (BE ((end != REG_MISSING && start > end)
2527 || token->type != OP_CLOSE_DUP_NUM, 0))
2519 { 2528 {
2520 /* First number greater than second. */ 2529 /* First number greater than second. */
2521 *err = REG_BADBR; 2530 *err = REG_BADBR;
@@ -2568,10 +2577,14 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2568 if (BE (tree == NULL, 0)) 2577 if (BE (tree == NULL, 0))
2569 goto parse_dup_op_espace; 2578 goto parse_dup_op_espace;
2570 2579
2580/* From gnulib's "intprops.h":
2581 True if the arithmetic type T is signed. */
2582#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
2583
2571 /* This loop is actually executed only when end != REG_MISSING, 2584 /* This loop is actually executed only when end != REG_MISSING,
2572 to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have 2585 to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
2573 already created the start+1-th copy. */ 2586 already created the start+1-th copy. */
2574 if ((Idx) -1 < 0 || end != REG_MISSING) 2587 if (TYPE_SIGNED (Idx) || end != REG_MISSING)
2575 for (i = start + 2; i <= end; ++i) 2588 for (i = start + 2; i <= end; ++i)
2576 { 2589 {
2577 elem = duplicate_tree (elem, dfa); 2590 elem = duplicate_tree (elem, dfa);
@@ -2609,11 +2622,17 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2609static reg_errcode_t 2622static reg_errcode_t
2610internal_function 2623internal_function
2611# ifdef RE_ENABLE_I18N 2624# ifdef RE_ENABLE_I18N
2612build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, 2625build_range_exp (const reg_syntax_t syntax,
2613 bracket_elem_t *start_elem, bracket_elem_t *end_elem) 2626 bitset_t sbcset,
2627 re_charset_t *mbcset,
2628 Idx *range_alloc,
2629 const bracket_elem_t *start_elem,
2630 const bracket_elem_t *end_elem)
2614# else /* not RE_ENABLE_I18N */ 2631# else /* not RE_ENABLE_I18N */
2615build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem, 2632build_range_exp (const reg_syntax_t syntax,
2616 bracket_elem_t *end_elem) 2633 bitset_t sbcset,
2634 const bracket_elem_t *start_elem,
2635 const bracket_elem_t *end_elem)
2617# endif /* not RE_ENABLE_I18N */ 2636# endif /* not RE_ENABLE_I18N */
2618{ 2637{
2619 unsigned int start_ch, end_ch; 2638 unsigned int start_ch, end_ch;
@@ -2652,7 +2671,9 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
2652 return REG_ECOLLATE; 2671 return REG_ECOLLATE;
2653 cmp_buf[0] = start_wc; 2672 cmp_buf[0] = start_wc;
2654 cmp_buf[4] = end_wc; 2673 cmp_buf[4] = end_wc;
2655 if (wcscoll (cmp_buf, cmp_buf + 4) > 0) 2674
2675 if (BE ((syntax & RE_NO_EMPTY_RANGES)
2676 && wcscoll (cmp_buf, cmp_buf + 4) > 0, 0))
2656 return REG_ERANGE; 2677 return REG_ERANGE;
2657 2678
2658 /* Got valid collation sequence values, add them as a new entry. 2679 /* Got valid collation sequence values, add them as a new entry.
@@ -2662,9 +2683,9 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
2662 no MBCSET if dfa->mb_cur_max == 1. */ 2683 no MBCSET if dfa->mb_cur_max == 1. */
2663 if (mbcset) 2684 if (mbcset)
2664 { 2685 {
2665 /* Check the space of the arrays. */ 2686 /* Check the space of the arrays. */
2666 if (BE (*range_alloc == mbcset->nranges, 0)) 2687 if (BE (*range_alloc == mbcset->nranges, 0))
2667 { 2688 {
2668 /* There is not enough space, need realloc. */ 2689 /* There is not enough space, need realloc. */
2669 wchar_t *new_array_start, *new_array_end; 2690 wchar_t *new_array_start, *new_array_end;
2670 Idx new_nranges; 2691 Idx new_nranges;
@@ -2674,9 +2695,9 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
2674 /* Use realloc since mbcset->range_starts and mbcset->range_ends 2695 /* Use realloc since mbcset->range_starts and mbcset->range_ends
2675 are NULL if *range_alloc == 0. */ 2696 are NULL if *range_alloc == 0. */
2676 new_array_start = re_realloc (mbcset->range_starts, wchar_t, 2697 new_array_start = re_realloc (mbcset->range_starts, wchar_t,
2677 new_nranges); 2698 new_nranges);
2678 new_array_end = re_realloc (mbcset->range_ends, wchar_t, 2699 new_array_end = re_realloc (mbcset->range_ends, wchar_t,
2679 new_nranges); 2700 new_nranges);
2680 2701
2681 if (BE (new_array_start == NULL || new_array_end == NULL, 0)) 2702 if (BE (new_array_start == NULL || new_array_end == NULL, 0))
2682 return REG_ESPACE; 2703 return REG_ESPACE;
@@ -2684,10 +2705,10 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
2684 mbcset->range_starts = new_array_start; 2705 mbcset->range_starts = new_array_start;
2685 mbcset->range_ends = new_array_end; 2706 mbcset->range_ends = new_array_end;
2686 *range_alloc = new_nranges; 2707 *range_alloc = new_nranges;
2687 } 2708 }
2688 2709
2689 mbcset->range_starts[mbcset->nranges] = start_wc; 2710 mbcset->range_starts[mbcset->nranges] = start_wc;
2690 mbcset->range_ends[mbcset->nranges++] = end_wc; 2711 mbcset->range_ends[mbcset->nranges++] = end_wc;
2691 } 2712 }
2692 2713
2693 /* Build the table for single byte characters. */ 2714 /* Build the table for single byte characters. */
@@ -2799,7 +2820,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2799 return elem; 2820 return elem;
2800 } 2821 }
2801 2822
2802 /* Local function for parse_bracket_exp used in _LIBC environement. 2823 /* Local function for parse_bracket_exp used in _LIBC environment.
2803 Look up the collation sequence value of BR_ELEM. 2824 Look up the collation sequence value of BR_ELEM.
2804 Return the value if succeeded, UINT_MAX otherwise. */ 2825 Return the value if succeeded, UINT_MAX otherwise. */
2805 2826
@@ -2823,7 +2844,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2823 } 2844 }
2824 else if (br_elem->type == MB_CHAR) 2845 else if (br_elem->type == MB_CHAR)
2825 { 2846 {
2826 return __collseq_table_lookup (collseqwc, br_elem->opr.wch); 2847 if (nrules != 0)
2848 return __collseq_table_lookup (collseqwc, br_elem->opr.wch);
2827 } 2849 }
2828 else if (br_elem->type == COLL_SYM) 2850 else if (br_elem->type == COLL_SYM)
2829 { 2851 {
@@ -2904,8 +2926,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2904 build below suffices. */ 2926 build below suffices. */
2905 if (nrules > 0 || dfa->mb_cur_max > 1) 2927 if (nrules > 0 || dfa->mb_cur_max > 1)
2906 { 2928 {
2907 /* Check the space of the arrays. */ 2929 /* Check the space of the arrays. */
2908 if (BE (*range_alloc == mbcset->nranges, 0)) 2930 if (BE (*range_alloc == mbcset->nranges, 0))
2909 { 2931 {
2910 /* There is not enough space, need realloc. */ 2932 /* There is not enough space, need realloc. */
2911 uint32_t *new_array_start; 2933 uint32_t *new_array_start;
@@ -2917,18 +2939,18 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2917 new_array_start = re_realloc (mbcset->range_starts, uint32_t, 2939 new_array_start = re_realloc (mbcset->range_starts, uint32_t,
2918 new_nranges); 2940 new_nranges);
2919 new_array_end = re_realloc (mbcset->range_ends, uint32_t, 2941 new_array_end = re_realloc (mbcset->range_ends, uint32_t,
2920 new_nranges); 2942 new_nranges);
2921 2943
2922 if (BE (new_array_start == NULL || new_array_end == NULL, 0)) 2944 if (BE (new_array_start == NULL || new_array_end == NULL, 0))
2923 return REG_ESPACE; 2945 return REG_ESPACE;
2924 2946
2925 mbcset->range_starts = new_array_start; 2947 mbcset->range_starts = new_array_start;
2926 mbcset->range_ends = new_array_end; 2948 mbcset->range_ends = new_array_end;
2927 *range_alloc = new_nranges; 2949 *range_alloc = new_nranges;
2928 } 2950 }
2929 2951
2930 mbcset->range_starts[mbcset->nranges] = start_collseq; 2952 mbcset->range_starts[mbcset->nranges] = start_collseq;
2931 mbcset->range_ends[mbcset->nranges++] = end_collseq; 2953 mbcset->range_ends[mbcset->nranges++] = end_collseq;
2932 } 2954 }
2933 2955
2934 /* Build the table for single byte characters. */ 2956 /* Build the table for single byte characters. */
@@ -3154,11 +3176,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3154 &start_elem, &end_elem); 3176 &start_elem, &end_elem);
3155#else 3177#else
3156# ifdef RE_ENABLE_I18N 3178# ifdef RE_ENABLE_I18N
3157 *err = build_range_exp (sbcset, 3179 *err = build_range_exp (syntax, sbcset,
3158 dfa->mb_cur_max > 1 ? mbcset : NULL, 3180 dfa->mb_cur_max > 1 ? mbcset : NULL,
3159 &range_alloc, &start_elem, &end_elem); 3181 &range_alloc, &start_elem, &end_elem);
3160# else 3182# else
3161 *err = build_range_exp (sbcset, &start_elem, &end_elem); 3183 *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
3162# endif 3184# endif
3163#endif /* RE_ENABLE_I18N */ 3185#endif /* RE_ENABLE_I18N */
3164 if (BE (*err != REG_NOERROR, 0)) 3186 if (BE (*err != REG_NOERROR, 0))
@@ -3262,17 +3284,17 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3262 of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */ 3284 of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */
3263 if (sbc_idx < BITSET_WORDS) 3285 if (sbc_idx < BITSET_WORDS)
3264 { 3286 {
3265 /* Build a tree for simple bracket. */ 3287 /* Build a tree for simple bracket. */
3266 br_token.type = SIMPLE_BRACKET; 3288 br_token.type = SIMPLE_BRACKET;
3267 br_token.opr.sbcset = sbcset; 3289 br_token.opr.sbcset = sbcset;
3268 work_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3290 work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3269 if (BE (work_tree == NULL, 0)) 3291 if (BE (work_tree == NULL, 0))
3270 goto parse_bracket_exp_espace; 3292 goto parse_bracket_exp_espace;
3271 3293
3272 /* Then join them by ALT node. */ 3294 /* Then join them by ALT node. */
3273 work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT); 3295 work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT);
3274 if (BE (work_tree == NULL, 0)) 3296 if (BE (work_tree == NULL, 0))
3275 goto parse_bracket_exp_espace; 3297 goto parse_bracket_exp_espace;
3276 } 3298 }
3277 else 3299 else
3278 { 3300 {
@@ -3291,7 +3313,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3291 br_token.opr.sbcset = sbcset; 3313 br_token.opr.sbcset = sbcset;
3292 work_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3314 work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3293 if (BE (work_tree == NULL, 0)) 3315 if (BE (work_tree == NULL, 0))
3294 goto parse_bracket_exp_espace; 3316 goto parse_bracket_exp_espace;
3295 } 3317 }
3296 return work_tree; 3318 return work_tree;
3297 3319
@@ -3430,7 +3452,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3430 3452
3431 /* Build single byte matcing table for this equivalence class. */ 3453 /* Build single byte matcing table for this equivalence class. */
3432 char_buf[1] = (unsigned char) '\0'; 3454 char_buf[1] = (unsigned char) '\0';
3433 len = weights[idx1]; 3455 len = weights[idx1 & 0xffffff];
3434 for (ch = 0; ch < SBC_MAX; ++ch) 3456 for (ch = 0; ch < SBC_MAX; ++ch)
3435 { 3457 {
3436 char_buf[0] = ch; 3458 char_buf[0] = ch;
@@ -3442,11 +3464,15 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3442 if (idx2 == 0) 3464 if (idx2 == 0)
3443 /* This isn't a valid character. */ 3465 /* This isn't a valid character. */
3444 continue; 3466 continue;
3445 if (len == weights[idx2]) 3467 /* Compare only if the length matches and the collation rule
3468 index is the same. */
3469 if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24))
3446 { 3470 {
3447 int cnt = 0; 3471 int cnt = 0;
3472
3448 while (cnt <= len && 3473 while (cnt <= len &&
3449 weights[idx1 + 1 + cnt] == weights[idx2 + 1 + cnt]) 3474 weights[(idx1 & 0xffffff) + 1 + cnt]
3475 == weights[(idx2 & 0xffffff) + 1 + cnt])
3450 ++cnt; 3476 ++cnt;
3451 3477
3452 if (cnt > len) 3478 if (cnt > len)
@@ -3842,7 +3868,7 @@ duplicate_tree (const bin_tree_t *root, re_dfa_t *dfa)
3842 node = node->parent; 3868 node = node->parent;
3843 dup_node = dup_node->parent; 3869 dup_node = dup_node->parent;
3844 if (!node) 3870 if (!node)
3845 return dup_root; 3871 return dup_root;
3846 } 3872 }
3847 node = node->right; 3873 node = node->right;
3848 p_new = &dup_node->right; 3874 p_new = &dup_node->right;
diff --git a/gl/regex.c b/gl/regex.c
index ee36378a..ba0eebee 100644
--- a/gl/regex.c
+++ b/gl/regex.c
@@ -1,5 +1,6 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2003, 2005, 2006, 2009, 2010 Free Software Foundation,
3 Inc.
3 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
5 6
diff --git a/gl/regex.h b/gl/regex.h
index a5312832..d7426c76 100644
--- a/gl/regex.h
+++ b/gl/regex.h
@@ -1,7 +1,8 @@
1/* Definitions for data structures and routines for the regular 1/* Definitions for data structures and routines for the regular
2 expression library. 2 expression library.
3 Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006 3 Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc. 4 2000, 2001, 2002, 2003, 2005, 2006, 2009, 2010 Free Software Foundation,
5 Inc.
5 This file is part of the GNU C Library. 6 This file is part of the GNU C Library.
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
diff --git a/gl/regex_internal.c b/gl/regex_internal.c
index 7acec79d..17eafaa9 100644
--- a/gl/regex_internal.c
+++ b/gl/regex_internal.c
@@ -1,6 +1,6 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3 Free Software Foundation, Inc. 3 Software Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
6 6
@@ -36,7 +36,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
36 re_string_reconstruct before using the object. */ 36 re_string_reconstruct before using the object. */
37 37
38static reg_errcode_t 38static reg_errcode_t
39internal_function 39internal_function __attribute_warn_unused_result__
40re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, 40re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
41 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) 41 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
42{ 42{
@@ -64,7 +64,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
64/* This function allocate the buffers, and initialize them. */ 64/* This function allocate the buffers, and initialize them. */
65 65
66static reg_errcode_t 66static reg_errcode_t
67internal_function 67internal_function __attribute_warn_unused_result__
68re_string_construct (re_string_t *pstr, const char *str, Idx len, 68re_string_construct (re_string_t *pstr, const char *str, Idx len,
69 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) 69 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
70{ 70{
@@ -127,7 +127,7 @@ re_string_construct (re_string_t *pstr, const char *str, Idx len,
127/* Helper functions for re_string_allocate, and re_string_construct. */ 127/* Helper functions for re_string_allocate, and re_string_construct. */
128 128
129static reg_errcode_t 129static reg_errcode_t
130internal_function 130internal_function __attribute_warn_unused_result__
131re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) 131re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
132{ 132{
133#ifdef RE_ENABLE_I18N 133#ifdef RE_ENABLE_I18N
@@ -267,7 +267,7 @@ build_wcs_buffer (re_string_t *pstr)
267 but for REG_ICASE. */ 267 but for REG_ICASE. */
268 268
269static reg_errcode_t 269static reg_errcode_t
270internal_function 270internal_function __attribute_warn_unused_result__
271build_wcs_upper_buffer (re_string_t *pstr) 271build_wcs_upper_buffer (re_string_t *pstr)
272{ 272{
273 mbstate_t prev_st; 273 mbstate_t prev_st;
@@ -430,8 +430,8 @@ build_wcs_upper_buffer (re_string_t *pstr)
430 src_idx += mbclen; 430 src_idx += mbclen;
431 continue; 431 continue;
432 } 432 }
433 else 433 else
434 memcpy (pstr->mbs + byte_idx, p, mbclen); 434 memcpy (pstr->mbs + byte_idx, p, mbclen);
435 } 435 }
436 else 436 else
437 memcpy (pstr->mbs + byte_idx, p, mbclen); 437 memcpy (pstr->mbs + byte_idx, p, mbclen);
@@ -569,7 +569,7 @@ re_string_translate_buffer (re_string_t *pstr)
569 convert to upper case in case of REG_ICASE, apply translation. */ 569 convert to upper case in case of REG_ICASE, apply translation. */
570 570
571static reg_errcode_t 571static reg_errcode_t
572internal_function 572internal_function __attribute_warn_unused_result__
573re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) 573re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
574{ 574{
575 Idx offset; 575 Idx offset;
@@ -964,7 +964,7 @@ re_string_context_at (const re_string_t *input, Idx idx, int eflags)
964/* Functions for set operation. */ 964/* Functions for set operation. */
965 965
966static reg_errcode_t 966static reg_errcode_t
967internal_function 967internal_function __attribute_warn_unused_result__
968re_node_set_alloc (re_node_set *set, Idx size) 968re_node_set_alloc (re_node_set *set, Idx size)
969{ 969{
970 set->alloc = size; 970 set->alloc = size;
@@ -976,7 +976,7 @@ re_node_set_alloc (re_node_set *set, Idx size)
976} 976}
977 977
978static reg_errcode_t 978static reg_errcode_t
979internal_function 979internal_function __attribute_warn_unused_result__
980re_node_set_init_1 (re_node_set *set, Idx elem) 980re_node_set_init_1 (re_node_set *set, Idx elem)
981{ 981{
982 set->alloc = 1; 982 set->alloc = 1;
@@ -992,7 +992,7 @@ re_node_set_init_1 (re_node_set *set, Idx elem)
992} 992}
993 993
994static reg_errcode_t 994static reg_errcode_t
995internal_function 995internal_function __attribute_warn_unused_result__
996re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2) 996re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
997{ 997{
998 set->alloc = 2; 998 set->alloc = 2;
@@ -1022,7 +1022,7 @@ re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
1022} 1022}
1023 1023
1024static reg_errcode_t 1024static reg_errcode_t
1025internal_function 1025internal_function __attribute_warn_unused_result__
1026re_node_set_init_copy (re_node_set *dest, const re_node_set *src) 1026re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1027{ 1027{
1028 dest->nelem = src->nelem; 1028 dest->nelem = src->nelem;
@@ -1047,7 +1047,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1047 Note: We assume dest->elems is NULL, when dest->alloc is 0. */ 1047 Note: We assume dest->elems is NULL, when dest->alloc is 0. */
1048 1048
1049static reg_errcode_t 1049static reg_errcode_t
1050internal_function 1050internal_function __attribute_warn_unused_result__
1051re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, 1051re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1052 const re_node_set *src2) 1052 const re_node_set *src2)
1053{ 1053{
@@ -1062,7 +1062,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1062 Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; 1062 Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
1063 Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc); 1063 Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
1064 if (BE (new_elems == NULL, 0)) 1064 if (BE (new_elems == NULL, 0))
1065 return REG_ESPACE; 1065 return REG_ESPACE;
1066 dest->elems = new_elems; 1066 dest->elems = new_elems;
1067 dest->alloc = new_alloc; 1067 dest->alloc = new_alloc;
1068 } 1068 }
@@ -1112,20 +1112,20 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1112 if (delta > 0 && REG_VALID_INDEX (id)) 1112 if (delta > 0 && REG_VALID_INDEX (id))
1113 for (;;) 1113 for (;;)
1114 { 1114 {
1115 if (dest->elems[is] > dest->elems[id]) 1115 if (dest->elems[is] > dest->elems[id])
1116 { 1116 {
1117 /* Copy from the top. */ 1117 /* Copy from the top. */
1118 dest->elems[id + delta--] = dest->elems[is--]; 1118 dest->elems[id + delta--] = dest->elems[is--];
1119 if (delta == 0) 1119 if (delta == 0)
1120 break; 1120 break;
1121 } 1121 }
1122 else 1122 else
1123 { 1123 {
1124 /* Slide from the bottom. */ 1124 /* Slide from the bottom. */
1125 dest->elems[id + delta] = dest->elems[id]; 1125 dest->elems[id + delta] = dest->elems[id];
1126 if (! REG_VALID_INDEX (--id)) 1126 if (! REG_VALID_INDEX (--id))
1127 break; 1127 break;
1128 } 1128 }
1129 } 1129 }
1130 1130
1131 /* Copy remaining SRC elements. */ 1131 /* Copy remaining SRC elements. */
@@ -1138,7 +1138,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1138 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */ 1138 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1139 1139
1140static reg_errcode_t 1140static reg_errcode_t
1141internal_function 1141internal_function __attribute_warn_unused_result__
1142re_node_set_init_union (re_node_set *dest, const re_node_set *src1, 1142re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1143 const re_node_set *src2) 1143 const re_node_set *src2)
1144{ 1144{
@@ -1191,7 +1191,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1191 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */ 1191 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1192 1192
1193static reg_errcode_t 1193static reg_errcode_t
1194internal_function 1194internal_function __attribute_warn_unused_result__
1195re_node_set_merge (re_node_set *dest, const re_node_set *src) 1195re_node_set_merge (re_node_set *dest, const re_node_set *src)
1196{ 1196{
1197 Idx is, id, sbase, delta; 1197 Idx is, id, sbase, delta;
@@ -1221,11 +1221,11 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1221 REG_VALID_INDEX (is) && REG_VALID_INDEX (id); ) 1221 REG_VALID_INDEX (is) && REG_VALID_INDEX (id); )
1222 { 1222 {
1223 if (dest->elems[id] == src->elems[is]) 1223 if (dest->elems[id] == src->elems[is])
1224 is--, id--; 1224 is--, id--;
1225 else if (dest->elems[id] < src->elems[is]) 1225 else if (dest->elems[id] < src->elems[is])
1226 dest->elems[--sbase] = src->elems[is--]; 1226 dest->elems[--sbase] = src->elems[is--];
1227 else /* if (dest->elems[id] > src->elems[is]) */ 1227 else /* if (dest->elems[id] > src->elems[is]) */
1228 --id; 1228 --id;
1229 } 1229 }
1230 1230
1231 if (REG_VALID_INDEX (is)) 1231 if (REG_VALID_INDEX (is))
@@ -1247,21 +1247,21 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1247 for (;;) 1247 for (;;)
1248 { 1248 {
1249 if (dest->elems[is] > dest->elems[id]) 1249 if (dest->elems[is] > dest->elems[id])
1250 { 1250 {
1251 /* Copy from the top. */ 1251 /* Copy from the top. */
1252 dest->elems[id + delta--] = dest->elems[is--]; 1252 dest->elems[id + delta--] = dest->elems[is--];
1253 if (delta == 0) 1253 if (delta == 0)
1254 break; 1254 break;
1255 } 1255 }
1256 else 1256 else
1257 { 1257 {
1258 /* Slide from the bottom. */ 1258 /* Slide from the bottom. */
1259 dest->elems[id + delta] = dest->elems[id]; 1259 dest->elems[id + delta] = dest->elems[id];
1260 if (! REG_VALID_INDEX (--id)) 1260 if (! REG_VALID_INDEX (--id))
1261 { 1261 {
1262 /* Copy remaining SRC elements. */ 1262 /* Copy remaining SRC elements. */
1263 memcpy (dest->elems, dest->elems + sbase, 1263 memcpy (dest->elems, dest->elems + sbase,
1264 delta * sizeof (Idx)); 1264 delta * sizeof (Idx));
1265 break; 1265 break;
1266 } 1266 }
1267 } 1267 }
@@ -1275,7 +1275,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1275 Return true if successful. */ 1275 Return true if successful. */
1276 1276
1277static bool 1277static bool
1278internal_function 1278internal_function __attribute_warn_unused_result__
1279re_node_set_insert (re_node_set *set, Idx elem) 1279re_node_set_insert (re_node_set *set, Idx elem)
1280{ 1280{
1281 Idx idx; 1281 Idx idx;
@@ -1308,12 +1308,12 @@ re_node_set_insert (re_node_set *set, Idx elem)
1308 { 1308 {
1309 idx = 0; 1309 idx = 0;
1310 for (idx = set->nelem; idx > 0; idx--) 1310 for (idx = set->nelem; idx > 0; idx--)
1311 set->elems[idx] = set->elems[idx - 1]; 1311 set->elems[idx] = set->elems[idx - 1];
1312 } 1312 }
1313 else 1313 else
1314 { 1314 {
1315 for (idx = set->nelem; set->elems[idx - 1] > elem; idx--) 1315 for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
1316 set->elems[idx] = set->elems[idx - 1]; 1316 set->elems[idx] = set->elems[idx - 1];
1317 } 1317 }
1318 1318
1319 /* Insert the new element. */ 1319 /* Insert the new element. */
@@ -1327,7 +1327,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1327 Return true if successful. */ 1327 Return true if successful. */
1328 1328
1329static bool 1329static bool
1330internal_function 1330internal_function __attribute_warn_unused_result__
1331re_node_set_insert_last (re_node_set *set, Idx elem) 1331re_node_set_insert_last (re_node_set *set, Idx elem)
1332{ 1332{
1333 /* Realloc if we need. */ 1333 /* Realloc if we need. */
@@ -1473,7 +1473,7 @@ calc_state_hash (const re_node_set *nodes, unsigned int context)
1473 optimization. */ 1473 optimization. */
1474 1474
1475static re_dfastate_t * 1475static re_dfastate_t *
1476internal_function 1476internal_function __attribute_warn_unused_result__
1477re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, 1477re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1478 const re_node_set *nodes) 1478 const re_node_set *nodes)
1479{ 1479{
@@ -1521,7 +1521,7 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1521 optimization. */ 1521 optimization. */
1522 1522
1523static re_dfastate_t * 1523static re_dfastate_t *
1524internal_function 1524internal_function __attribute_warn_unused_result__
1525re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, 1525re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1526 const re_node_set *nodes, unsigned int context) 1526 const re_node_set *nodes, unsigned int context)
1527{ 1527{
@@ -1562,6 +1562,7 @@ re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1562 indicates the error code if failed. */ 1562 indicates the error code if failed. */
1563 1563
1564static reg_errcode_t 1564static reg_errcode_t
1565__attribute_warn_unused_result__
1565register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, 1566register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
1566 re_hashval_t hash) 1567 re_hashval_t hash)
1567{ 1568{
@@ -1616,7 +1617,7 @@ free_state (re_dfastate_t *state)
1616 Return the new state if succeeded, otherwise return NULL. */ 1617 Return the new state if succeeded, otherwise return NULL. */
1617 1618
1618static re_dfastate_t * 1619static re_dfastate_t *
1619internal_function 1620internal_function __attribute_warn_unused_result__
1620create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1621create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1621 re_hashval_t hash) 1622 re_hashval_t hash)
1622{ 1623{
@@ -1666,7 +1667,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1666 Return the new state if succeeded, otherwise return NULL. */ 1667 Return the new state if succeeded, otherwise return NULL. */
1667 1668
1668static re_dfastate_t * 1669static re_dfastate_t *
1669internal_function 1670internal_function __attribute_warn_unused_result__
1670create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1671create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1671 unsigned int context, re_hashval_t hash) 1672 unsigned int context, re_hashval_t hash)
1672{ 1673{
@@ -1715,7 +1716,9 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1715 free_state (newstate); 1716 free_state (newstate);
1716 return NULL; 1717 return NULL;
1717 } 1718 }
1718 re_node_set_init_copy (newstate->entrance_nodes, nodes); 1719 if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
1720 != REG_NOERROR)
1721 return NULL;
1719 nctx_nodes = 0; 1722 nctx_nodes = 0;
1720 newstate->has_constraint = 1; 1723 newstate->has_constraint = 1;
1721 } 1724 }
diff --git a/gl/regex_internal.h b/gl/regex_internal.h
index dc322ec5..2cb8c4d0 100644
--- a/gl/regex_internal.h
+++ b/gl/regex_internal.h
@@ -1,6 +1,6 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3 Free Software Foundation, Inc. 3 Software Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
6 6
@@ -28,9 +28,8 @@
28#include <stdlib.h> 28#include <stdlib.h>
29#include <string.h> 29#include <string.h>
30 30
31#ifdef _LIBC 31#include <langinfo.h>
32# include <langinfo.h> 32#ifndef _LIBC
33#else
34# include "localcharset.h" 33# include "localcharset.h"
35#endif 34#endif
36#if defined HAVE_LOCALE_H || defined _LIBC 35#if defined HAVE_LOCALE_H || defined _LIBC
@@ -852,4 +851,21 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
852} 851}
853#endif /* RE_ENABLE_I18N */ 852#endif /* RE_ENABLE_I18N */
854 853
854#ifndef __GNUC_PREREQ
855# if defined __GNUC__ && defined __GNUC_MINOR__
856# define __GNUC_PREREQ(maj, min) \
857 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
858# else
859# define __GNUC_PREREQ(maj, min) 0
860# endif
861#endif
862
863#if __GNUC_PREREQ (3,4)
864# undef __attribute_warn_unused_result__
865# define __attribute_warn_unused_result__ \
866 __attribute__ ((__warn_unused_result__))
867#else
868# define __attribute_warn_unused_result__ /* empty */
869#endif
870
855#endif /* _REGEX_INTERNAL_H */ 871#endif /* _REGEX_INTERNAL_H */
diff --git a/gl/regexec.c b/gl/regexec.c
index 5452ef78..dc449ce5 100644
--- a/gl/regexec.c
+++ b/gl/regexec.c
@@ -1,6 +1,6 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3 Free Software Foundation, Inc. 3 Software Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
6 6
@@ -637,7 +637,7 @@ re_exec (s)
637 (0 <= LAST_START && LAST_START <= LENGTH) */ 637 (0 <= LAST_START && LAST_START <= LENGTH) */
638 638
639static reg_errcode_t 639static reg_errcode_t
640internal_function 640internal_function __attribute_warn_unused_result__
641re_search_internal (const regex_t *preg, 641re_search_internal (const regex_t *preg,
642 const char *string, Idx length, 642 const char *string, Idx length,
643 Idx start, Idx last_start, Idx stop, 643 Idx start, Idx last_start, Idx stop,
@@ -833,10 +833,10 @@ re_search_internal (const regex_t *preg,
833 break; 833 break;
834 match_first += incr; 834 match_first += incr;
835 if (match_first < left_lim || match_first > right_lim) 835 if (match_first < left_lim || match_first > right_lim)
836 { 836 {
837 err = REG_NOMATCH; 837 err = REG_NOMATCH;
838 goto free_return; 838 goto free_return;
839 } 839 }
840 } 840 }
841 break; 841 break;
842 } 842 }
@@ -953,14 +953,14 @@ re_search_internal (const regex_t *preg,
953 } 953 }
954 954
955 if (dfa->subexp_map) 955 if (dfa->subexp_map)
956 for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++) 956 for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++)
957 if (dfa->subexp_map[reg_idx] != reg_idx) 957 if (dfa->subexp_map[reg_idx] != reg_idx)
958 { 958 {
959 pmatch[reg_idx + 1].rm_so 959 pmatch[reg_idx + 1].rm_so
960 = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so; 960 = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so;
961 pmatch[reg_idx + 1].rm_eo 961 pmatch[reg_idx + 1].rm_eo
962 = pmatch[dfa->subexp_map[reg_idx] + 1].rm_eo; 962 = pmatch[dfa->subexp_map[reg_idx] + 1].rm_eo;
963 } 963 }
964 } 964 }
965 965
966 free_return: 966 free_return:
@@ -972,7 +972,7 @@ re_search_internal (const regex_t *preg,
972} 972}
973 973
974static reg_errcode_t 974static reg_errcode_t
975internal_function 975internal_function __attribute_warn_unused_result__
976prune_impossible_nodes (re_match_context_t *mctx) 976prune_impossible_nodes (re_match_context_t *mctx)
977{ 977{
978 const re_dfa_t *const dfa = mctx->dfa; 978 const re_dfa_t *const dfa = mctx->dfa;
@@ -1110,7 +1110,7 @@ acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1110 index of the buffer. */ 1110 index of the buffer. */
1111 1111
1112static Idx 1112static Idx
1113internal_function 1113internal_function __attribute_warn_unused_result__
1114check_matching (re_match_context_t *mctx, bool fl_longest_match, 1114check_matching (re_match_context_t *mctx, bool fl_longest_match,
1115 Idx *p_match_first) 1115 Idx *p_match_first)
1116{ 1116{
@@ -1149,7 +1149,7 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1149 { 1149 {
1150 err = transit_state_bkref (mctx, &cur_state->nodes); 1150 err = transit_state_bkref (mctx, &cur_state->nodes);
1151 if (BE (err != REG_NOERROR, 0)) 1151 if (BE (err != REG_NOERROR, 0))
1152 return err; 1152 return err;
1153 } 1153 }
1154 } 1154 }
1155 } 1155 }
@@ -1176,16 +1176,16 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1176 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; 1176 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
1177 1177
1178 if (BE (next_char_idx >= mctx->input.bufs_len, 0) 1178 if (BE (next_char_idx >= mctx->input.bufs_len, 0)
1179 || (BE (next_char_idx >= mctx->input.valid_len, 0) 1179 || (BE (next_char_idx >= mctx->input.valid_len, 0)
1180 && mctx->input.valid_len < mctx->input.len)) 1180 && mctx->input.valid_len < mctx->input.len))
1181 { 1181 {
1182 err = extend_buffers (mctx); 1182 err = extend_buffers (mctx);
1183 if (BE (err != REG_NOERROR, 0)) 1183 if (BE (err != REG_NOERROR, 0))
1184 { 1184 {
1185 assert (err == REG_ESPACE); 1185 assert (err == REG_ESPACE);
1186 return REG_ERROR; 1186 return REG_ERROR;
1187 } 1187 }
1188 } 1188 }
1189 1189
1190 cur_state = transit_state (&err, mctx, cur_state); 1190 cur_state = transit_state (&err, mctx, cur_state);
1191 if (mctx->state_log != NULL) 1191 if (mctx->state_log != NULL)
@@ -1309,17 +1309,17 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1309 if (dest_node == REG_MISSING) 1309 if (dest_node == REG_MISSING)
1310 dest_node = candidate; 1310 dest_node = candidate;
1311 1311
1312 else 1312 else
1313 { 1313 {
1314 /* In order to avoid infinite loop like "(a*)*", return the second 1314 /* In order to avoid infinite loop like "(a*)*", return the second
1315 epsilon-transition if the first was already considered. */ 1315 epsilon-transition if the first was already considered. */
1316 if (re_node_set_contains (eps_via_nodes, dest_node)) 1316 if (re_node_set_contains (eps_via_nodes, dest_node))
1317 return candidate; 1317 return candidate;
1318 1318
1319 /* Otherwise, push the second epsilon-transition on the fail stack. */ 1319 /* Otherwise, push the second epsilon-transition on the fail stack. */
1320 else if (fs != NULL 1320 else if (fs != NULL
1321 && push_fail_stack (fs, *pidx, candidate, nregs, regs, 1321 && push_fail_stack (fs, *pidx, candidate, nregs, regs,
1322 eps_via_nodes)) 1322 eps_via_nodes))
1323 return REG_ERROR; 1323 return REG_ERROR;
1324 1324
1325 /* We know we are going to exit. */ 1325 /* We know we are going to exit. */
@@ -1385,7 +1385,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1385} 1385}
1386 1386
1387static reg_errcode_t 1387static reg_errcode_t
1388internal_function 1388internal_function __attribute_warn_unused_result__
1389push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, 1389push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
1390 Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes) 1390 Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
1391{ 1391{
@@ -1432,7 +1432,7 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
1432 pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */ 1432 pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */
1433 1433
1434static reg_errcode_t 1434static reg_errcode_t
1435internal_function 1435internal_function __attribute_warn_unused_result__
1436set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, 1436set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1437 regmatch_t *pmatch, bool fl_backtrack) 1437 regmatch_t *pmatch, bool fl_backtrack)
1438{ 1438{
@@ -1667,7 +1667,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1667 if (mctx->state_log[str_idx]) 1667 if (mctx->state_log[str_idx])
1668 { 1668 {
1669 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); 1669 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest);
1670 if (BE (err != REG_NOERROR, 0)) 1670 if (BE (err != REG_NOERROR, 0))
1671 goto free_return; 1671 goto free_return;
1672 } 1672 }
1673 1673
@@ -1686,7 +1686,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1686} 1686}
1687 1687
1688static reg_errcode_t 1688static reg_errcode_t
1689internal_function 1689internal_function __attribute_warn_unused_result__
1690build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, 1690build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1691 Idx str_idx, re_node_set *cur_dest) 1691 Idx str_idx, re_node_set *cur_dest)
1692{ 1692{
@@ -1848,7 +1848,7 @@ update_cur_sifted_state (const re_match_context_t *mctx,
1848} 1848}
1849 1849
1850static reg_errcode_t 1850static reg_errcode_t
1851internal_function 1851internal_function __attribute_warn_unused_result__
1852add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, 1852add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1853 const re_node_set *candidates) 1853 const re_node_set *candidates)
1854{ 1854{
@@ -1863,10 +1863,14 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1863 { 1863 {
1864 err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem); 1864 err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
1865 if (BE (err != REG_NOERROR, 0)) 1865 if (BE (err != REG_NOERROR, 0))
1866 return REG_ESPACE; 1866 return REG_ESPACE;
1867 for (i = 0; i < dest_nodes->nelem; i++) 1867 for (i = 0; i < dest_nodes->nelem; i++)
1868 re_node_set_merge (&state->inveclosure, 1868 {
1869 dfa->inveclosures + dest_nodes->elems[i]); 1869 err = re_node_set_merge (&state->inveclosure,
1870 dfa->inveclosures + dest_nodes->elems[i]);
1871 if (BE (err != REG_NOERROR, 0))
1872 return REG_ESPACE;
1873 }
1870 } 1874 }
1871 return re_node_set_add_intersect (dest_nodes, candidates, 1875 return re_node_set_add_intersect (dest_nodes, candidates,
1872 &state->inveclosure); 1876 &state->inveclosure);
@@ -1978,7 +1982,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
1978 { 1982 {
1979 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx; 1983 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
1980 do 1984 do
1981 { 1985 {
1982 Idx dst; 1986 Idx dst;
1983 int cpos; 1987 int cpos;
1984 1988
@@ -2000,9 +2004,9 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
2000 if (dst == from_node) 2004 if (dst == from_node)
2001 { 2005 {
2002 if (boundaries & 1) 2006 if (boundaries & 1)
2003 return -1; 2007 return -1;
2004 else /* if (boundaries & 2) */ 2008 else /* if (boundaries & 2) */
2005 return 0; 2009 return 0;
2006 } 2010 }
2007 2011
2008 cpos = 2012 cpos =
@@ -2016,7 +2020,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
2016 if (subexp_idx < BITSET_WORD_BITS) 2020 if (subexp_idx < BITSET_WORD_BITS)
2017 ent->eps_reachable_subexps_map 2021 ent->eps_reachable_subexps_map
2018 &= ~((bitset_word_t) 1 << subexp_idx); 2022 &= ~((bitset_word_t) 1 << subexp_idx);
2019 } 2023 }
2020 while (ent++->more); 2024 while (ent++->more);
2021 } 2025 }
2022 break; 2026 break;
@@ -2158,7 +2162,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2158} 2162}
2159 2163
2160static reg_errcode_t 2164static reg_errcode_t
2161internal_function 2165internal_function __attribute_warn_unused_result__
2162sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, 2166sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2163 Idx str_idx, const re_node_set *candidates) 2167 Idx str_idx, const re_node_set *candidates)
2164{ 2168{
@@ -2241,7 +2245,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2241 re_node_set_remove (&local_sctx.limits, enabled_idx); 2245 re_node_set_remove (&local_sctx.limits, enabled_idx);
2242 2246
2243 /* mctx->bkref_ents may have changed, reload the pointer. */ 2247 /* mctx->bkref_ents may have changed, reload the pointer. */
2244 entry = mctx->bkref_ents + enabled_idx; 2248 entry = mctx->bkref_ents + enabled_idx;
2245 } 2249 }
2246 while (enabled_idx++, entry++->more); 2250 while (enabled_idx++, entry++->more);
2247 } 2251 }
@@ -2288,7 +2292,7 @@ sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
2288 update the destination of STATE_LOG. */ 2292 update the destination of STATE_LOG. */
2289 2293
2290static re_dfastate_t * 2294static re_dfastate_t *
2291internal_function 2295internal_function __attribute_warn_unused_result__
2292transit_state (reg_errcode_t *err, re_match_context_t *mctx, 2296transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2293 re_dfastate_t *state) 2297 re_dfastate_t *state)
2294{ 2298{
@@ -2322,7 +2326,7 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2322 2326
2323 trtable = state->word_trtable; 2327 trtable = state->word_trtable;
2324 if (BE (trtable != NULL, 1)) 2328 if (BE (trtable != NULL, 1))
2325 { 2329 {
2326 unsigned int context; 2330 unsigned int context;
2327 context 2331 context
2328 = re_string_context_at (&mctx->input, 2332 = re_string_context_at (&mctx->input,
@@ -2368,21 +2372,21 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2368 unsigned int context; 2372 unsigned int context;
2369 re_node_set next_nodes, *log_nodes, *table_nodes = NULL; 2373 re_node_set next_nodes, *log_nodes, *table_nodes = NULL;
2370 /* If (state_log[cur_idx] != 0), it implies that cur_idx is 2374 /* If (state_log[cur_idx] != 0), it implies that cur_idx is
2371 the destination of a multibyte char/collating element/ 2375 the destination of a multibyte char/collating element/
2372 back reference. Then the next state is the union set of 2376 back reference. Then the next state is the union set of
2373 these destinations and the results of the transition table. */ 2377 these destinations and the results of the transition table. */
2374 pstate = mctx->state_log[cur_idx]; 2378 pstate = mctx->state_log[cur_idx];
2375 log_nodes = pstate->entrance_nodes; 2379 log_nodes = pstate->entrance_nodes;
2376 if (next_state != NULL) 2380 if (next_state != NULL)
2377 { 2381 {
2378 table_nodes = next_state->entrance_nodes; 2382 table_nodes = next_state->entrance_nodes;
2379 *err = re_node_set_init_union (&next_nodes, table_nodes, 2383 *err = re_node_set_init_union (&next_nodes, table_nodes,
2380 log_nodes); 2384 log_nodes);
2381 if (BE (*err != REG_NOERROR, 0)) 2385 if (BE (*err != REG_NOERROR, 0))
2382 return NULL; 2386 return NULL;
2383 } 2387 }
2384 else 2388 else
2385 next_nodes = *log_nodes; 2389 next_nodes = *log_nodes;
2386 /* Note: We already add the nodes of the initial state, 2390 /* Note: We already add the nodes of the initial state,
2387 then we don't need to add them here. */ 2391 then we don't need to add them here. */
2388 2392
@@ -2390,12 +2394,12 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2390 re_string_cur_idx (&mctx->input) - 1, 2394 re_string_cur_idx (&mctx->input) - 1,
2391 mctx->eflags); 2395 mctx->eflags);
2392 next_state = mctx->state_log[cur_idx] 2396 next_state = mctx->state_log[cur_idx]
2393 = re_acquire_state_context (err, dfa, &next_nodes, context); 2397 = re_acquire_state_context (err, dfa, &next_nodes, context);
2394 /* We don't need to check errors here, since the return value of 2398 /* We don't need to check errors here, since the return value of
2395 this function is next_state and ERR is already set. */ 2399 this function is next_state and ERR is already set. */
2396 2400
2397 if (table_nodes != NULL) 2401 if (table_nodes != NULL)
2398 re_node_set_free (&next_nodes); 2402 re_node_set_free (&next_nodes);
2399 } 2403 }
2400 2404
2401 if (BE (dfa->nbackref, 0) && next_state != NULL) 2405 if (BE (dfa->nbackref, 0) && next_state != NULL)
@@ -2436,9 +2440,9 @@ find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
2436 2440
2437 do 2441 do
2438 { 2442 {
2439 if (++cur_str_idx > max) 2443 if (++cur_str_idx > max)
2440 return NULL; 2444 return NULL;
2441 re_string_skip_bytes (&mctx->input, 1); 2445 re_string_skip_bytes (&mctx->input, 1);
2442 } 2446 }
2443 while (mctx->state_log[cur_str_idx] == NULL); 2447 while (mctx->state_log[cur_str_idx] == NULL);
2444 2448
@@ -2546,7 +2550,7 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2546 re_dfastate_t *dest_state; 2550 re_dfastate_t *dest_state;
2547 2551
2548 if (!dfa->nodes[cur_node_idx].accept_mb) 2552 if (!dfa->nodes[cur_node_idx].accept_mb)
2549 continue; 2553 continue;
2550 2554
2551 if (dfa->nodes[cur_node_idx].constraint) 2555 if (dfa->nodes[cur_node_idx].constraint)
2552 { 2556 {
@@ -2714,7 +2718,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2714 delay these checking for prune_impossible_nodes(). */ 2718 delay these checking for prune_impossible_nodes(). */
2715 2719
2716static reg_errcode_t 2720static reg_errcode_t
2717internal_function 2721internal_function __attribute_warn_unused_result__
2718get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) 2722get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2719{ 2723{
2720 const re_dfa_t *const dfa = mctx->dfa; 2724 const re_dfa_t *const dfa = mctx->dfa;
@@ -2727,7 +2731,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2727 const struct re_backref_cache_entry *entry 2731 const struct re_backref_cache_entry *entry
2728 = mctx->bkref_ents + cache_idx; 2732 = mctx->bkref_ents + cache_idx;
2729 do 2733 do
2730 if (entry->node == bkref_node) 2734 if (entry->node == bkref_node)
2731 return REG_NOERROR; /* We already checked it. */ 2735 return REG_NOERROR; /* We already checked it. */
2732 while (entry++->more); 2736 while (entry++->more);
2733 } 2737 }
@@ -2915,7 +2919,7 @@ find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
2915 Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */ 2919 Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */
2916 2920
2917static reg_errcode_t 2921static reg_errcode_t
2918internal_function 2922internal_function __attribute_warn_unused_result__
2919check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, 2923check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2920 Idx top_str, Idx last_node, Idx last_str, int type) 2924 Idx top_str, Idx last_node, Idx last_str, int type)
2921{ 2925{
@@ -3077,7 +3081,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3077 Can't we unify them? */ 3081 Can't we unify them? */
3078 3082
3079static reg_errcode_t 3083static reg_errcode_t
3080internal_function 3084internal_function __attribute_warn_unused_result__
3081check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, 3085check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3082 re_node_set *cur_nodes, re_node_set *next_nodes) 3086 re_node_set *cur_nodes, re_node_set *next_nodes)
3083{ 3087{
@@ -3211,7 +3215,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3211 problematic append it to DST_NODES. */ 3215 problematic append it to DST_NODES. */
3212 3216
3213static reg_errcode_t 3217static reg_errcode_t
3214internal_function 3218internal_function __attribute_warn_unused_result__
3215check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, 3219check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3216 Idx target, Idx ex_subexp, int type) 3220 Idx target, Idx ex_subexp, int type)
3217{ 3221{
@@ -3256,7 +3260,7 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3256 in MCTX->BKREF_ENTS. */ 3260 in MCTX->BKREF_ENTS. */
3257 3261
3258static reg_errcode_t 3262static reg_errcode_t
3259internal_function 3263internal_function __attribute_warn_unused_result__
3260expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, 3264expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3261 Idx cur_str, Idx subexp_num, int type) 3265 Idx cur_str, Idx subexp_num, int type)
3262{ 3266{
@@ -3622,7 +3626,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3622 } 3626 }
3623#ifdef RE_ENABLE_I18N 3627#ifdef RE_ENABLE_I18N
3624 else if (type == OP_UTF8_PERIOD) 3628 else if (type == OP_UTF8_PERIOD)
3625 { 3629 {
3626 if (ASCII_CHARS % BITSET_WORD_BITS == 0) 3630 if (ASCII_CHARS % BITSET_WORD_BITS == 0)
3627 memset (accepts, -1, ASCII_CHARS / CHAR_BIT); 3631 memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
3628 else 3632 else
@@ -3631,7 +3635,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3631 bitset_clear (accepts, '\n'); 3635 bitset_clear (accepts, '\n');
3632 if (dfa->syntax & RE_DOT_NOT_NULL) 3636 if (dfa->syntax & RE_DOT_NOT_NULL)
3633 bitset_clear (accepts, '\0'); 3637 bitset_clear (accepts, '\0');
3634 } 3638 }
3635#endif 3639#endif
3636 else 3640 else
3637 continue; 3641 continue;
@@ -3836,7 +3840,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3836 if (node->type == OP_PERIOD) 3840 if (node->type == OP_PERIOD)
3837 { 3841 {
3838 if (char_len <= 1) 3842 if (char_len <= 1)
3839 return 0; 3843 return 0;
3840 /* FIXME: I don't think this if is needed, as both '\n' 3844 /* FIXME: I don't think this if is needed, as both '\n'
3841 and '\0' are char_len == 1. */ 3845 and '\0' are char_len == 1. */
3842 /* '.' accepts any one character except the following two cases. */ 3846 /* '.' accepts any one character except the following two cases. */
@@ -3949,15 +3953,20 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3949 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB); 3953 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
3950 indirect = (const int32_t *) 3954 indirect = (const int32_t *)
3951 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB); 3955 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
3952 idx = findidx (&cp); 3956 int32_t idx = findidx (&cp);
3953 if (idx > 0) 3957 if (idx > 0)
3954 for (i = 0; i < cset->nequiv_classes; ++i) 3958 for (i = 0; i < cset->nequiv_classes; ++i)
3955 { 3959 {
3956 int32_t equiv_class_idx = cset->equiv_classes[i]; 3960 int32_t equiv_class_idx = cset->equiv_classes[i];
3957 size_t weight_len = weights[idx]; 3961 size_t weight_len = weights[idx & 0xffffff];
3958 if (weight_len == weights[equiv_class_idx]) 3962 if (weight_len == weights[equiv_class_idx & 0xffffff]
3963 && (idx >> 24) == (equiv_class_idx >> 24))
3959 { 3964 {
3960 Idx cnt = 0; 3965 Idx cnt = 0;
3966
3967 idx &= 0xffffff;
3968 equiv_class_idx &= 0xffffff;
3969
3961 while (cnt <= weight_len 3970 while (cnt <= weight_len
3962 && (weights[equiv_class_idx + 1 + cnt] 3971 && (weights[equiv_class_idx + 1 + cnt]
3963 == weights[idx + 1 + cnt])) 3972 == weights[idx + 1 + cnt]))
@@ -4123,7 +4132,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
4123/* Extend the buffers, if the buffers have run out. */ 4132/* Extend the buffers, if the buffers have run out. */
4124 4133
4125static reg_errcode_t 4134static reg_errcode_t
4126internal_function 4135internal_function __attribute_warn_unused_result__
4127extend_buffers (re_match_context_t *mctx) 4136extend_buffers (re_match_context_t *mctx)
4128{ 4137{
4129 reg_errcode_t ret; 4138 reg_errcode_t ret;
@@ -4186,7 +4195,7 @@ extend_buffers (re_match_context_t *mctx)
4186/* Initialize MCTX. */ 4195/* Initialize MCTX. */
4187 4196
4188static reg_errcode_t 4197static reg_errcode_t
4189internal_function 4198internal_function __attribute_warn_unused_result__
4190match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) 4199match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
4191{ 4200{
4192 mctx->eflags = eflags; 4201 mctx->eflags = eflags;
@@ -4266,7 +4275,7 @@ match_ctx_free (re_match_context_t *mctx)
4266*/ 4275*/
4267 4276
4268static reg_errcode_t 4277static reg_errcode_t
4269internal_function 4278internal_function __attribute_warn_unused_result__
4270match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, 4279match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
4271 Idx to) 4280 Idx to)
4272{ 4281{
@@ -4338,7 +4347,7 @@ search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
4338 at STR_IDX. */ 4347 at STR_IDX. */
4339 4348
4340static reg_errcode_t 4349static reg_errcode_t
4341internal_function 4350internal_function __attribute_warn_unused_result__
4342match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) 4351match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
4343{ 4352{
4344#ifdef DEBUG 4353#ifdef DEBUG
diff --git a/gl/safe-read.c b/gl/safe-read.c
index 0cb1edee..855be677 100644
--- a/gl/safe-read.c
+++ b/gl/safe-read.c
@@ -1,7 +1,7 @@
1/* An interface to read and write that retries after interrupts. 1/* An interface to read and write that retries after interrupts.
2 2
3 Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free 3 Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2010 Free Software
4 Software Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 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 7 it under the terms of the GNU General Public License as published by
@@ -66,12 +66,12 @@ safe_rw (int fd, void const *buf, size_t count)
66 ssize_t result = rw (fd, buf, count); 66 ssize_t result = rw (fd, buf, count);
67 67
68 if (0 <= result) 68 if (0 <= result)
69 return result; 69 return result;
70 else if (IS_EINTR (errno)) 70 else if (IS_EINTR (errno))
71 continue; 71 continue;
72 else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count) 72 else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
73 count = BUGGY_READ_MAXIMUM; 73 count = BUGGY_READ_MAXIMUM;
74 else 74 else
75 return result; 75 return result;
76 } 76 }
77} 77}
diff --git a/gl/safe-read.h b/gl/safe-read.h
index ba191713..1f15b018 100644
--- a/gl/safe-read.h
+++ b/gl/safe-read.h
@@ -1,5 +1,5 @@
1/* An interface to read() that retries after interrupts. 1/* An interface to read() that retries after interrupts.
2 Copyright (C) 2002, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/safe-write.c b/gl/safe-write.c
index b644f7cf..a2c3b4df 100644
--- a/gl/safe-write.c
+++ b/gl/safe-write.c
@@ -1,5 +1,5 @@
1/* An interface to write that retries after interrupts. 1/* An interface to write that retries after interrupts.
2 Copyright (C) 2002 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/safe-write.h b/gl/safe-write.h
index da036a97..185f6603 100644
--- a/gl/safe-write.h
+++ b/gl/safe-write.h
@@ -1,5 +1,5 @@
1/* An interface to write() that retries after interrupts. 1/* An interface to write() that retries after interrupts.
2 Copyright (C) 2002 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/size_max.h b/gl/size_max.h
index 2ccc5f08..56d5a9b1 100644
--- a/gl/size_max.h
+++ b/gl/size_max.h
@@ -1,5 +1,5 @@
1/* size_max.h -- declare SIZE_MAX through system headers 1/* size_max.h -- declare SIZE_MAX through system headers
2 Copyright (C) 2005-2006 Free Software Foundation, Inc. 2 Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
3 Written by Simon Josefsson. 3 Written by Simon Josefsson.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
diff --git a/gl/snprintf.c b/gl/snprintf.c
index dafbda81..810ca14b 100644
--- a/gl/snprintf.c
+++ b/gl/snprintf.c
@@ -1,5 +1,5 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2006-2010 Free Software Foundation, Inc.
3 Written by Simon Josefsson and Paul Eggert. 3 Written by Simon Josefsson and Paul Eggert.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
@@ -53,11 +53,11 @@ snprintf (char *str, size_t size, const char *format, ...)
53 if (output != str) 53 if (output != str)
54 { 54 {
55 if (size) 55 if (size)
56 { 56 {
57 size_t pruned_len = (len < size ? len : size - 1); 57 size_t pruned_len = (len < size ? len : size - 1);
58 memcpy (str, output, pruned_len); 58 memcpy (str, output, pruned_len);
59 str[pruned_len] = '\0'; 59 str[pruned_len] = '\0';
60 } 60 }
61 61
62 free (output); 62 free (output);
63 } 63 }
diff --git a/gl/sockets.c b/gl/sockets.c
new file mode 100644
index 00000000..b946c7e6
--- /dev/null
+++ b/gl/sockets.c
@@ -0,0 +1,118 @@
1/* sockets.c --- wrappers for Windows socket functions
2
3 Copyright (C) 2008-2010 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 Simon Josefsson */
19
20#include <config.h>
21
22/* Specification. */
23#include "sockets.h"
24
25#if WINDOWS_SOCKETS
26
27/* This includes winsock2.h on MinGW. */
28# include <sys/socket.h>
29
30# include "close-hook.h"
31
32/* Get set_winsock_errno, FD_TO_SOCKET etc. */
33# include "w32sock.h"
34
35static int
36close_fd_maybe_socket (int fd, const struct close_hook *remaining_list)
37{
38 SOCKET sock;
39 WSANETWORKEVENTS ev;
40
41 /* Test whether fd refers to a socket. */
42 sock = FD_TO_SOCKET (fd);
43 ev.lNetworkEvents = 0xDEADBEEF;
44 WSAEnumNetworkEvents (sock, NULL, &ev);
45 if (ev.lNetworkEvents != 0xDEADBEEF)
46 {
47 /* fd refers to a socket. */
48 /* FIXME: other applications, like squid, use an undocumented
49 _free_osfhnd free function. But this is not enough: The 'osfile'
50 flags for fd also needs to be cleared, but it is hard to access it.
51 Instead, here we just close twice the file descriptor. */
52 if (closesocket (sock))
53 {
54 set_winsock_errno ();
55 return -1;
56 }
57 else
58 {
59 /* This call frees the file descriptor and does a
60 CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */
61 _close (fd);
62 return 0;
63 }
64 }
65 else
66 /* Some other type of file descriptor. */
67 return execute_close_hooks (fd, remaining_list);
68}
69
70static struct close_hook close_sockets_hook;
71
72static int initialized_sockets_version /* = 0 */;
73
74#endif /* WINDOWS_SOCKETS */
75
76int
77gl_sockets_startup (int version _GL_UNUSED)
78{
79#if WINDOWS_SOCKETS
80 if (version > initialized_sockets_version)
81 {
82 WSADATA data;
83 int err;
84
85 err = WSAStartup (version, &data);
86 if (err != 0)
87 return 1;
88
89 if (data.wVersion < version)
90 return 2;
91
92 if (initialized_sockets_version == 0)
93 register_close_hook (close_fd_maybe_socket, &close_sockets_hook);
94
95 initialized_sockets_version = version;
96 }
97#endif
98
99 return 0;
100}
101
102int
103gl_sockets_cleanup (void)
104{
105#if WINDOWS_SOCKETS
106 int err;
107
108 initialized_sockets_version = 0;
109
110 unregister_close_hook (&close_sockets_hook);
111
112 err = WSACleanup ();
113 if (err != 0)
114 return 1;
115#endif
116
117 return 0;
118}
diff --git a/gl/sockets.h b/gl/sockets.h
new file mode 100644
index 00000000..921bf6f7
--- /dev/null
+++ b/gl/sockets.h
@@ -0,0 +1,51 @@
1/* sockets.h - wrappers for Windows socket functions
2
3 Copyright (C) 2008, 2009, 2010 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 Simon Josefsson */
19
20#ifndef SOCKETS_H
21# define SOCKETS_H 1
22
23#define SOCKETS_1_0 0x100 /* don't use - does not work on Windows XP */
24#define SOCKETS_1_1 0x101
25#define SOCKETS_2_0 0x200 /* don't use - does not work on Windows XP */
26#define SOCKETS_2_1 0x201
27#define SOCKETS_2_2 0x202
28
29int gl_sockets_startup (int version);
30int gl_sockets_cleanup (void);
31
32/* This function is useful it you create a socket using gnulib's
33 Winsock wrappers but needs to pass on the socket handle to some
34 other library that only accepts sockets. */
35#if WINDOWS_SOCKETS
36
37#include <sys/socket.h>
38
39static inline SOCKET
40gl_fd_to_handle (int fd)
41{
42 return _get_osfhandle (fd);
43}
44
45#else
46
47#define gl_fd_to_handle(x) (x)
48
49#endif /* WINDOWS_SOCKETS */
50
51#endif /* SOCKETS_H */
diff --git a/gl/stat.c b/gl/stat.c
new file mode 100644
index 00000000..875317bf
--- /dev/null
+++ b/gl/stat.c
@@ -0,0 +1,104 @@
1/* Work around platform bugs in stat.
2 Copyright (C) 2009, 2010 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/* Get the original definition of stat. It might be defined as a macro. */
22#define __need_system_sys_stat_h
23#include <sys/types.h>
24#include <sys/stat.h>
25#undef __need_system_sys_stat_h
26
27static inline int
28orig_stat (const char *filename, struct stat *buf)
29{
30 return stat (filename, buf);
31}
32
33/* Specification. */
34#include <sys/stat.h>
35
36#include <errno.h>
37#include <limits.h>
38#include <stdbool.h>
39#include <string.h>
40
41/* Store information about NAME into ST. Work around bugs with
42 trailing slashes. Mingw has other bugs (such as st_ino always
43 being 0 on success) which this wrapper does not work around. But
44 at least this implementation provides the ability to emulate fchdir
45 correctly. */
46
47int
48rpl_stat (char const *name, struct stat *st)
49{
50 int result = orig_stat (name, st);
51#if REPLACE_FUNC_STAT_FILE
52 /* Solaris 9 mistakenly succeeds when given a non-directory with a
53 trailing slash. */
54 if (result == 0 && !S_ISDIR (st->st_mode))
55 {
56 size_t len = strlen (name);
57 if (ISSLASH (name[len - 1]))
58 {
59 errno = ENOTDIR;
60 return -1;
61 }
62 }
63#endif /* REPLACE_FUNC_STAT_FILE */
64#if REPLACE_FUNC_STAT_DIR
65 if (result == -1 && errno == ENOENT)
66 {
67 /* Due to mingw's oddities, there are some directories (like
68 c:\) where stat() only succeeds with a trailing slash, and
69 other directories (like c:\windows) where stat() only
70 succeeds without a trailing slash. But we want the two to be
71 synonymous, since chdir() manages either style. Likewise, Mingw also
72 reports ENOENT for names longer than PATH_MAX, when we want
73 ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
74 Fortunately, mingw PATH_MAX is small enough for stack
75 allocation. */
76 char fixed_name[PATH_MAX + 1] = {0};
77 size_t len = strlen (name);
78 bool check_dir = false;
79 if (PATH_MAX <= len)
80 errno = ENAMETOOLONG;
81 else if (len)
82 {
83 strcpy (fixed_name, name);
84 if (ISSLASH (fixed_name[len - 1]))
85 {
86 check_dir = true;
87 while (len && ISSLASH (fixed_name[len - 1]))
88 fixed_name[--len] = '\0';
89 if (!len)
90 fixed_name[0] = '/';
91 }
92 else
93 fixed_name[len++] = '/';
94 result = orig_stat (fixed_name, st);
95 if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
96 {
97 result = -1;
98 errno = ENOTDIR;
99 }
100 }
101 }
102#endif /* REPLACE_FUNC_STAT_DIR */
103 return result;
104}
diff --git a/gl/stdbool.in.h b/gl/stdbool.in.h
index cffa0ab2..e2312ecb 100644
--- a/gl/stdbool.in.h
+++ b/gl/stdbool.in.h
@@ -1,4 +1,4 @@
1/* Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. 1/* Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc.
2 Written by Bruno Haible <haible@clisp.cons.org>, 2001. 2 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
diff --git a/gl/stddef.in.h b/gl/stddef.in.h
new file mode 100644
index 00000000..08778a23
--- /dev/null
+++ b/gl/stddef.in.h
@@ -0,0 +1,86 @@
1/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
2
3 Copyright (C) 2009, 2010 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, or (at your option)
8 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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19/* Written by Eric Blake. */
20
21/*
22 * POSIX 2008 <stddef.h> for platforms that have issues.
23 * <http://www.opengroup.org/susv3xbd/stddef.h.html>
24 */
25
26#if __GNUC__ >= 3
27@PRAGMA_SYSTEM_HEADER@
28#endif
29
30#if defined __need_wchar_t || defined __need_size_t \
31 || defined __need_ptrdiff_t || defined __need_NULL \
32 || defined __need_wint_t
33/* Special invocation convention inside gcc header files. In
34 particular, gcc provides a version of <stddef.h> that blindly
35 redefines NULL even when __need_wint_t was defined, even though
36 wint_t is not normally provided by <stddef.h>. Hence, we must
37 remember if special invocation has ever been used to obtain wint_t,
38 in which case we need to clean up NULL yet again. */
39
40# if !(defined _GL_STDDEF_H && defined _GL_STDDEF_WINT_T)
41# ifdef __need_wint_t
42# undef _GL_STDDEF_H
43# define _GL_STDDEF_WINT_T
44# endif
45# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
46# endif
47
48#else
49/* Normal invocation convention. */
50
51# ifndef _GL_STDDEF_H
52
53/* The include_next requires a split double-inclusion guard. */
54
55# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
56
57# ifndef _GL_STDDEF_H
58# define _GL_STDDEF_H
59
60/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
61#if @REPLACE_NULL@
62# undef NULL
63# ifdef __cplusplus
64 /* ISO C++ says that the macro NULL must expand to an integer constant
65 expression, hence '((void *) 0)' is not allowed in C++. */
66# if __GNUG__ >= 3
67 /* GNU C++ has a __null macro that behaves like an integer ('int' or
68 'long') but has the same size as a pointer. Use that, to avoid
69 warnings. */
70# define NULL __null
71# else
72# define NULL 0L
73# endif
74# else
75# define NULL ((void *) 0)
76# endif
77#endif
78
79/* Some platforms lack wchar_t. */
80#if !@HAVE_WCHAR_T@
81# define wchar_t int
82#endif
83
84# endif /* _GL_STDDEF_H */
85# endif /* _GL_STDDEF_H */
86#endif /* __need_XXX */
diff --git a/gl/stdint.in.h b/gl/stdint.in.h
index 53aa34a8..5da5f178 100644
--- a/gl/stdint.in.h
+++ b/gl/stdint.in.h
@@ -1,4 +1,4 @@
1/* Copyright (C) 2001-2002, 2004-2009 Free Software Foundation, Inc. 1/* Copyright (C) 2001-2002, 2004-2010 Free Software Foundation, Inc.
2 Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. 2 Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
3 This file is part of gnulib. 3 This file is part of gnulib.
4 4
@@ -23,6 +23,10 @@
23 23
24#ifndef _GL_STDINT_H 24#ifndef _GL_STDINT_H
25 25
26#if __GNUC__ >= 3
27@PRAGMA_SYSTEM_HEADER@
28#endif
29
26/* When including a system file that in turn includes <inttypes.h>, 30/* When including a system file that in turn includes <inttypes.h>,
27 use the system <inttypes.h>, not our substitute. This avoids 31 use the system <inttypes.h>, not our substitute. This avoids
28 problems with (for example) VMS, whose <sys/bitypes.h> includes 32 problems with (for example) VMS, whose <sys/bitypes.h> includes
@@ -49,9 +53,6 @@
49 in <inttypes.h> would reinclude us, skipping our contents because 53 in <inttypes.h> would reinclude us, skipping our contents because
50 _GL_STDINT_H is defined. 54 _GL_STDINT_H is defined.
51 The include_next requires a split double-inclusion guard. */ 55 The include_next requires a split double-inclusion guard. */
52# if __GNUC__ >= 3
53@PRAGMA_SYSTEM_HEADER@
54# endif
55# @INCLUDE_NEXT@ @NEXT_STDINT_H@ 56# @INCLUDE_NEXT@ @NEXT_STDINT_H@
56#endif 57#endif
57 58
@@ -102,8 +103,8 @@
102 ((signed) \ 103 ((signed) \
103 ? ~ _STDINT_MIN (signed, bits, zero) \ 104 ? ~ _STDINT_MIN (signed, bits, zero) \
104 : /* The expression for the unsigned case. The subtraction of (signed) \ 105 : /* The expression for the unsigned case. The subtraction of (signed) \
105 is a nop in the unsigned case and avoids "signed integer overflow" \ 106 is a nop in the unsigned case and avoids "signed integer overflow" \
106 warnings in the signed case. */ \ 107 warnings in the signed case. */ \
107 ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1) 108 ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
108 109
109/* 7.18.1.1. Exact-width integer types */ 110/* 7.18.1.1. Exact-width integer types */
@@ -454,10 +455,10 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) -
454#undef SIG_ATOMIC_MAX 455#undef SIG_ATOMIC_MAX
455#define SIG_ATOMIC_MIN \ 456#define SIG_ATOMIC_MIN \
456 _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ 457 _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
457 0@SIG_ATOMIC_T_SUFFIX@) 458 0@SIG_ATOMIC_T_SUFFIX@)
458#define SIG_ATOMIC_MAX \ 459#define SIG_ATOMIC_MAX \
459 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ 460 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
460 0@SIG_ATOMIC_T_SUFFIX@) 461 0@SIG_ATOMIC_T_SUFFIX@)
461 462
462 463
463/* size_t limit */ 464/* size_t limit */
diff --git a/gl/stdio-write.c b/gl/stdio-write.c
index f1d0fcb7..f7da9e42 100644
--- a/gl/stdio-write.c
+++ b/gl/stdio-write.c
@@ -1,5 +1,5 @@
1/* POSIX compatible FILE stream write function. 1/* POSIX compatible FILE stream write function.
2 Copyright (C) 2008 Free Software Foundation, Inc. 2 Copyright (C) 2008-2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
@@ -39,30 +39,31 @@
39# include <windows.h> 39# include <windows.h>
40 40
41# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \ 41# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
42 if (ferror (stream)) \ 42 if (ferror (stream)) \
43 return (EXPRESSION); \ 43 return (EXPRESSION); \
44 else \ 44 else \
45 { \ 45 { \
46 RETTYPE ret; \ 46 RETTYPE ret; \
47 SetLastError (0); \ 47 SetLastError (0); \
48 ret = (EXPRESSION); \ 48 ret = (EXPRESSION); \
49 if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream)) \ 49 if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream)) \
50 { \ 50 { \
51 int fd = fileno (stream); \ 51 int fd = fileno (stream); \
52 if (fd >= 0 \ 52 if (fd >= 0 \
53 && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\ 53 && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\
54 { \ 54 { \
55 /* Try to raise signal SIGPIPE. */ \ 55 /* Try to raise signal SIGPIPE. */ \
56 raise (SIGPIPE); \ 56 raise (SIGPIPE); \
57 /* If it is currently blocked or ignored, change errno from \ 57 /* If it is currently blocked or ignored, change errno from \
58 EINVAL to EPIPE. */ \ 58 EINVAL to EPIPE. */ \
59 errno = EPIPE; \ 59 errno = EPIPE; \
60 } \ 60 } \
61 } \ 61 } \
62 return ret; \ 62 return ret; \
63 } 63 }
64 64
65# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */ 65# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
66# if !DEPENDS_ON_LIBINTL /* avoid collision with intl/printf.c */
66int 67int
67printf (const char *format, ...) 68printf (const char *format, ...)
68{ 69{
@@ -75,6 +76,7 @@ printf (const char *format, ...)
75 76
76 return retval; 77 return retval;
77} 78}
79# endif
78# endif 80# endif
79 81
80# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */ 82# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
@@ -92,7 +94,7 @@ fprintf (FILE *stream, const char *format, ...)
92} 94}
93# endif 95# endif
94 96
95# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vprintf.c */ 97# if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
96int 98int
97vprintf (const char *format, va_list args) 99vprintf (const char *format, va_list args)
98{ 100{
@@ -100,7 +102,7 @@ vprintf (const char *format, va_list args)
100} 102}
101# endif 103# endif
102 104
103# if !REPLACE_VPRINTF_POSIX /* avoid collision with vfprintf.c */ 105# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
104int 106int
105vfprintf (FILE *stream, const char *format, va_list args) 107vfprintf (FILE *stream, const char *format, va_list args)
106#undef vfprintf 108#undef vfprintf
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index cb273d76..dcb8ee57 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <stdio.h>. 1/* A GNU-like <stdio.h>.
2 2
3 Copyright (C) 2004, 2007-2008 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2007-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -36,489 +36,1022 @@
36#ifndef _GL_STDIO_H 36#ifndef _GL_STDIO_H
37#define _GL_STDIO_H 37#define _GL_STDIO_H
38 38
39/* Get va_list. Needed on many systems, including glibc 2.8. */
39#include <stdarg.h> 40#include <stdarg.h>
41
40#include <stddef.h> 42#include <stddef.h>
41 43
42#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \ 44/* Get off_t and ssize_t. Needed on many systems, including glibc 2.8. */
43 || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \ 45#include <sys/types.h>
44 || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
45 || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
46/* Get off_t and ssize_t. */
47# include <sys/types.h>
48#endif
49 46
50#ifndef __attribute__ 47#ifndef __attribute__
51/* This feature is available in gcc versions 2.5 and later. */ 48/* The __attribute__ feature is available in gcc versions 2.5 and later.
52# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) 49 The __-protected variants of the attributes 'format' and 'printf' are
53# define __attribute__(Spec) /* empty */ 50 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
54# endif 51 We enable __attribute__ only if these are supported too, because
55/* The __-protected variants of `format' and `printf' attributes 52 gnulib and libintl do '#define printf __printf__' when they override
56 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 53 the 'printf' function. */
57# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 54# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
58# define __format__ format 55# define __attribute__(Spec) /* empty */
59# define __printf__ printf
60# endif 56# endif
61#endif 57#endif
62 58
63 59
64/* The definition of GL_LINK_WARNING is copied here. */ 60/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
65 61
62/* The definition of _GL_ARG_NONNULL is copied here. */
66 63
67#ifdef __cplusplus 64/* The definition of _GL_WARN_ON_USE is copied here. */
68extern "C" {
69#endif
70 65
71 66
72#if @GNULIB_FPRINTF_POSIX@ 67#if @GNULIB_DPRINTF@
73# if @REPLACE_FPRINTF@ 68# if @REPLACE_DPRINTF@
74# define fprintf rpl_fprintf 69# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
75extern int fprintf (FILE *fp, const char *format, ...) 70# define dprintf rpl_dprintf
76 __attribute__ ((__format__ (__printf__, 2, 3))); 71# endif
72_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...)
73 __attribute__ ((__format__ (__printf__, 2, 3)))
74 _GL_ARG_NONNULL ((2)));
75_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...));
76# else
77# if !@HAVE_DPRINTF@
78_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...)
79 __attribute__ ((__format__ (__printf__, 2, 3)))
80 _GL_ARG_NONNULL ((2)));
81# endif
82_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...));
77# endif 83# endif
78#elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 84_GL_CXXALIASWARN (dprintf);
79# define fprintf rpl_fprintf
80extern int fprintf (FILE *fp, const char *format, ...)
81 __attribute__ ((__format__ (__printf__, 2, 3)));
82#elif defined GNULIB_POSIXCHECK 85#elif defined GNULIB_POSIXCHECK
83# undef fprintf 86# undef dprintf
84# define fprintf \ 87# if HAVE_RAW_DECL_DPRINTF
85 (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \ 88_GL_WARN_ON_USE (dprintf, "dprintf is unportable - "
86 "use gnulib module fprintf-posix for portable " \ 89 "use gnulib module dprintf for portability");
87 "POSIX compliance"), \ 90# endif
88 fprintf) 91#endif
89#endif 92
90 93#if @GNULIB_FCLOSE@
91#if @GNULIB_VFPRINTF_POSIX@ 94/* Close STREAM and its underlying file descriptor. */
92# if @REPLACE_VFPRINTF@ 95# if @REPLACE_FCLOSE@
93# define vfprintf rpl_vfprintf 96# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
94extern int vfprintf (FILE *fp, const char *format, va_list args) 97# define fclose rpl_fclose
95 __attribute__ ((__format__ (__printf__, 2, 0))); 98# endif
96# endif 99_GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
97#elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 100_GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
98# define vfprintf rpl_vfprintf 101# else
99extern int vfprintf (FILE *fp, const char *format, va_list args) 102_GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
100 __attribute__ ((__format__ (__printf__, 2, 0))); 103# endif
104_GL_CXXALIASWARN (fclose);
101#elif defined GNULIB_POSIXCHECK 105#elif defined GNULIB_POSIXCHECK
102# undef vfprintf 106# undef fclose
103# define vfprintf(s,f,a) \ 107/* Assume fclose is always declared. */
104 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \ 108_GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
105 "use gnulib module vfprintf-posix for portable " \ 109 "use gnulib module fclose for portable POSIX compliance");
106 "POSIX compliance"), \
107 vfprintf (s, f, a))
108#endif 110#endif
109 111
110#if @GNULIB_PRINTF_POSIX@ 112#if @GNULIB_FFLUSH@
111# if @REPLACE_PRINTF@ 113/* Flush all pending data on STREAM according to POSIX rules. Both
112/* Don't break __attribute__((format(printf,M,N))). */ 114 output and seekable input streams are supported.
113# define printf __printf__ 115 Note! LOSS OF DATA can occur if fflush is applied on an input stream
114extern int printf (const char *format, ...) 116 that is _not_seekable_ or on an update stream that is _not_seekable_
115 __attribute__ ((__format__ (__printf__, 1, 2))); 117 and in which the most recent operation was input. Seekability can
118 be tested with lseek(fileno(fp),0,SEEK_CUR). */
119# if @REPLACE_FFLUSH@
120# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121# define fflush rpl_fflush
122# endif
123_GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream));
124_GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
125# else
126_GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
116# endif 127# endif
117#elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 128_GL_CXXALIASWARN (fflush);
118/* Don't break __attribute__((format(printf,M,N))). */
119# define printf __printf__
120extern int printf (const char *format, ...)
121 __attribute__ ((__format__ (__printf__, 1, 2)));
122#elif defined GNULIB_POSIXCHECK 129#elif defined GNULIB_POSIXCHECK
123# undef printf 130# undef fflush
124# define printf \ 131/* Assume fflush is always declared. */
125 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \ 132_GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - "
126 "use gnulib module printf-posix for portable " \ 133 "use gnulib module fflush for portable POSIX compliance");
127 "POSIX compliance"), \ 134#endif
128 printf) 135
129/* Don't break __attribute__((format(printf,M,N))). */ 136/* It is very rare that the developer ever has full control of stdin,
130# define format(kind,m,n) format (__##kind##__, m, n) 137 so any use of gets warrants an unconditional warning. Assume it is
131# define __format__(kind,m,n) __format__ (__##kind##__, m, n) 138 always declared, since it is required by C89. */
132# define ____printf____ __printf__ 139#undef gets
133# define ____scanf____ __scanf__ 140_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
134# define ____strftime____ __strftime__ 141
135# define ____strfmon____ __strfmon__ 142#if @GNULIB_FOPEN@
136#endif 143# if @REPLACE_FOPEN@
137 144# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
138#if @GNULIB_VPRINTF_POSIX@ 145# undef fopen
139# if @REPLACE_VPRINTF@ 146# define fopen rpl_fopen
140# define vprintf rpl_vprintf 147# endif
141extern int vprintf (const char *format, va_list args) 148_GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode)
142 __attribute__ ((__format__ (__printf__, 1, 0))); 149 _GL_ARG_NONNULL ((1, 2)));
143# endif 150_GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode));
144#elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 151# else
145# define vprintf rpl_vprintf 152_GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode));
146extern int vprintf (const char *format, va_list args) 153# endif
147 __attribute__ ((__format__ (__printf__, 1, 0))); 154_GL_CXXALIASWARN (fopen);
148#elif defined GNULIB_POSIXCHECK 155#elif defined GNULIB_POSIXCHECK
149# undef vprintf 156# undef fopen
150# define vprintf(f,a) \ 157/* Assume fopen is always declared. */
151 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \ 158_GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - "
152 "use gnulib module vprintf-posix for portable " \ 159 "use gnulib module fopen for portability");
153 "POSIX compliance"), \
154 vprintf (f, a))
155#endif 160#endif
156 161
157#if @GNULIB_SNPRINTF@ 162#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
158# if @REPLACE_SNPRINTF@ 163# if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
159# define snprintf rpl_snprintf 164 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
165# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
166# define fprintf rpl_fprintf
167# endif
168# define GNULIB_overrides_fprintf 1
169_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...)
170 __attribute__ ((__format__ (__printf__, 2, 3)))
171 _GL_ARG_NONNULL ((1, 2)));
172_GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...));
173# else
174_GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...));
175# endif
176_GL_CXXALIASWARN (fprintf);
177#endif
178#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
179# if !GNULIB_overrides_fprintf
180# undef fprintf
160# endif 181# endif
161# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@ 182/* Assume fprintf is always declared. */
162extern int snprintf (char *str, size_t size, const char *format, ...) 183_GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - "
163 __attribute__ ((__format__ (__printf__, 3, 4))); 184 "use gnulib module fprintf-posix for portable "
185 "POSIX compliance");
186#endif
187
188#if @GNULIB_FPURGE@
189/* Discard all pending buffered I/O data on STREAM.
190 STREAM must not be wide-character oriented.
191 When discarding pending output, the file position is set back to where it
192 was before the write calls. When discarding pending input, the file
193 position is advanced to match the end of the previously read input.
194 Return 0 if successful. Upon error, return -1 and set errno. */
195# if @REPLACE_FPURGE@
196# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
197# define fpurge rpl_fpurge
198# endif
199_GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
200_GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream));
201# else
202# if !@HAVE_DECL_FPURGE@
203_GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1)));
204# endif
205_GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream));
164# endif 206# endif
207_GL_CXXALIASWARN (fpurge);
165#elif defined GNULIB_POSIXCHECK 208#elif defined GNULIB_POSIXCHECK
166# undef snprintf 209# undef fpurge
167# define snprintf \ 210# if HAVE_RAW_DECL_FPURGE
168 (GL_LINK_WARNING ("snprintf is unportable - " \ 211_GL_WARN_ON_USE (fpurge, "fpurge is not always present - "
169 "use gnulib module snprintf for portability"), \ 212 "use gnulib module fpurge for portability");
170 snprintf) 213# endif
171#endif 214#endif
172 215
173#if @GNULIB_VSNPRINTF@ 216#if @GNULIB_FPUTC@
174# if @REPLACE_VSNPRINTF@ 217# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
175# define vsnprintf rpl_vsnprintf 218# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
219# undef fputc
220# define fputc rpl_fputc
221# endif
222_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
223_GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
224# else
225_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
176# endif 226# endif
177# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@ 227_GL_CXXALIASWARN (fputc);
178extern int vsnprintf (char *str, size_t size, const char *format, va_list args) 228#endif
179 __attribute__ ((__format__ (__printf__, 3, 0))); 229
230#if @GNULIB_FPUTS@
231# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
232# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
233# undef fputs
234# define fputs rpl_fputs
235# endif
236_GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream)
237 _GL_ARG_NONNULL ((1, 2)));
238_GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream));
239# else
240_GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream));
180# endif 241# endif
181#elif defined GNULIB_POSIXCHECK 242_GL_CXXALIASWARN (fputs);
182# undef vsnprintf
183# define vsnprintf(b,s,f,a) \
184 (GL_LINK_WARNING ("vsnprintf is unportable - " \
185 "use gnulib module vsnprintf for portability"), \
186 vsnprintf (b, s, f, a))
187#endif 243#endif
188 244
189#if @GNULIB_SPRINTF_POSIX@ 245#if @GNULIB_FREOPEN@
190# if @REPLACE_SPRINTF@ 246# if @REPLACE_FREOPEN@
191# define sprintf rpl_sprintf 247# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
192extern int sprintf (char *str, const char *format, ...) 248# undef freopen
193 __attribute__ ((__format__ (__printf__, 2, 3))); 249# define freopen rpl_freopen
250# endif
251_GL_FUNCDECL_RPL (freopen, FILE *,
252 (const char *filename, const char *mode, FILE *stream)
253 _GL_ARG_NONNULL ((2, 3)));
254_GL_CXXALIAS_RPL (freopen, FILE *,
255 (const char *filename, const char *mode, FILE *stream));
256# else
257_GL_CXXALIAS_SYS (freopen, FILE *,
258 (const char *filename, const char *mode, FILE *stream));
194# endif 259# endif
260_GL_CXXALIASWARN (freopen);
195#elif defined GNULIB_POSIXCHECK 261#elif defined GNULIB_POSIXCHECK
196# undef sprintf 262# undef freopen
197# define sprintf \ 263/* Assume freopen is always declared. */
198 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \ 264_GL_WARN_ON_USE (freopen, "freopen on Win32 platforms is not POSIX compatible - "
199 "use gnulib module sprintf-posix for portable " \ 265 "use gnulib module freopen for portability");
200 "POSIX compliance"), \
201 sprintf)
202#endif 266#endif
203 267
204#if @GNULIB_VSPRINTF_POSIX@ 268
205# if @REPLACE_VSPRINTF@ 269/* Set up the following warnings, based on which modules are in use.
206# define vsprintf rpl_vsprintf 270 GNU Coding Standards discourage the use of fseek, since it imposes
207extern int vsprintf (char *str, const char *format, va_list args) 271 an arbitrary limitation on some 32-bit hosts. Remember that the
208 __attribute__ ((__format__ (__printf__, 2, 0))); 272 fseek module depends on the fseeko module, so we only have three
273 cases to consider:
274
275 1. The developer is not using either module. Issue a warning under
276 GNULIB_POSIXCHECK for both functions, to remind them that both
277 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
278 impact on this warning.
279
280 2. The developer is using both modules. They may be unaware of the
281 arbitrary limitations of fseek, so issue a warning under
282 GNULIB_POSIXCHECK. On the other hand, they may be using both
283 modules intentionally, so the developer can define
284 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
285 is safe, to silence the warning.
286
287 3. The developer is using the fseeko module, but not fseek. Gnulib
288 guarantees that fseek will still work around platform bugs in that
289 case, but we presume that the developer is aware of the pitfalls of
290 fseek and was trying to avoid it, so issue a warning even when
291 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
292 defined to silence the warning in particular compilation units.
293 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
294 fseek gets defined as a macro, it is recommended that the developer
295 uses the fseek module, even if he is not calling the fseek function.
296
297 Most gnulib clients that perform stream operations should fall into
298 category 3. */
299
300#if @GNULIB_FSEEK@
301# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
302# define _GL_FSEEK_WARN /* Category 2, above. */
303# undef fseek
304# endif
305# if @REPLACE_FSEEK@
306# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
307# undef fseek
308# define fseek rpl_fseek
309# endif
310_GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence)
311 _GL_ARG_NONNULL ((1)));
312_GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
313# else
314_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
315# endif
316_GL_CXXALIASWARN (fseek);
317#endif
318
319#if @GNULIB_FSEEKO@
320# if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
321# define _GL_FSEEK_WARN /* Category 3, above. */
322# undef fseek
323# endif
324# if @REPLACE_FSEEKO@
325/* Provide an fseeko function that is aware of a preceding fflush(), and which
326 detects pipes. */
327# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
328# undef fseeko
329# define fseeko rpl_fseeko
330# endif
331_GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)
332 _GL_ARG_NONNULL ((1)));
333_GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence));
334# else
335# if ! @HAVE_FSEEKO@
336_GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)
337 _GL_ARG_NONNULL ((1)));
338# endif
339_GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence));
340# endif
341_GL_CXXALIASWARN (fseeko);
342# if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@
343 /* Provide an fseek function that is consistent with fseeko. */
344 /* In order to avoid that fseek gets defined as a macro here, the
345 developer can request the 'fseek' module. */
346# undef fseek
347# define fseek rpl_fseek
348static inline int _GL_ARG_NONNULL ((1))
349rpl_fseek (FILE *fp, long offset, int whence)
350{
351# if @REPLACE_FSEEKO@
352 return rpl_fseeko (fp, offset, whence);
353# else
354 return fseeko (fp, offset, whence);
355# endif
356}
209# endif 357# endif
210#elif defined GNULIB_POSIXCHECK 358#elif defined GNULIB_POSIXCHECK
211# undef vsprintf 359# define _GL_FSEEK_WARN /* Category 1, above. */
212# define vsprintf(b,f,a) \ 360# undef fseek
213 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \ 361# undef fseeko
214 "use gnulib module vsprintf-posix for portable " \ 362# if HAVE_RAW_DECL_FSEEKO
215 "POSIX compliance"), \ 363_GL_WARN_ON_USE (fseeko, "fseeko is unportable - "
216 vsprintf (b, f, a)) 364 "use gnulib module fseeko for portability");
365# endif
217#endif 366#endif
218 367
219#if @GNULIB_DPRINTF@ 368#ifdef _GL_FSEEK_WARN
220# if @REPLACE_DPRINTF@ 369# undef _GL_FSEEK_WARN
221# define dprintf rpl_dprintf 370/* Here, either fseek is undefined (but C89 guarantees that it is
371 declared), or it is defined as rpl_fseek (declared above). */
372_GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB "
373 "on 32-bit platforms - "
374 "use fseeko function for handling of large files");
375#endif
376
377
378/* ftell, ftello. See the comments on fseek/fseeko. */
379
380#if @GNULIB_FTELL@
381# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
382# define _GL_FTELL_WARN /* Category 2, above. */
383# undef ftell
384# endif
385# if @REPLACE_FTELL@
386# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
387# undef ftell
388# define ftell rpl_ftell
389# endif
390_GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1)));
391_GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
392# else
393_GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
394# endif
395_GL_CXXALIASWARN (ftell);
396#endif
397
398#if @GNULIB_FTELLO@
399# if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
400# define _GL_FTELL_WARN /* Category 3, above. */
401# undef ftell
402# endif
403# if @REPLACE_FTELLO@
404# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
405# undef ftello
406# define ftello rpl_ftello
407# endif
408_GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
409_GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp));
410# else
411# if ! @HAVE_FTELLO@
412_GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1)));
413# endif
414_GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp));
222# endif 415# endif
223# if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@ 416_GL_CXXALIASWARN (ftello);
224extern int dprintf (int fd, const char *format, ...) 417# if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@
225 __attribute__ ((__format__ (__printf__, 2, 3))); 418 /* Provide an ftell function that is consistent with ftello. */
419 /* In order to avoid that ftell gets defined as a macro here, the
420 developer can request the 'ftell' module. */
421# undef ftell
422# define ftell rpl_ftell
423static inline long _GL_ARG_NONNULL ((1))
424rpl_ftell (FILE *f)
425{
426# if @REPLACE_FTELLO@
427 return rpl_ftello (f);
428# else
429 return ftello (f);
430# endif
431}
226# endif 432# endif
227#elif defined GNULIB_POSIXCHECK 433#elif defined GNULIB_POSIXCHECK
228# undef dprintf 434# define _GL_FTELL_WARN /* Category 1, above. */
229# define dprintf(d,f,a) \ 435# undef ftell
230 (GL_LINK_WARNING ("dprintf is unportable - " \ 436# undef ftello
231 "use gnulib module dprintf for portability"), \ 437# if HAVE_RAW_DECL_FTELLO
232 dprintf (d, f, a)) 438_GL_WARN_ON_USE (ftello, "ftello is unportable - "
439 "use gnulib module ftello for portability");
440# endif
233#endif 441#endif
234 442
235#if @GNULIB_VDPRINTF@ 443#ifdef _GL_FTELL_WARN
236# if @REPLACE_VDPRINTF@ 444# undef _GL_FTELL_WARN
237# define vdprintf rpl_vdprintf 445/* Here, either ftell is undefined (but C89 guarantees that it is
446 declared), or it is defined as rpl_ftell (declared above). */
447_GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
448 "on 32-bit platforms - "
449 "use ftello function for handling of large files");
450#endif
451
452
453#if @GNULIB_FWRITE@
454# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
455# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
456# undef fwrite
457# define fwrite rpl_fwrite
458# endif
459_GL_FUNCDECL_RPL (fwrite, size_t,
460 (const void *ptr, size_t s, size_t n, FILE *stream)
461 _GL_ARG_NONNULL ((1, 4)));
462_GL_CXXALIAS_RPL (fwrite, size_t,
463 (const void *ptr, size_t s, size_t n, FILE *stream));
464# else
465_GL_CXXALIAS_SYS (fwrite, size_t,
466 (const void *ptr, size_t s, size_t n, FILE *stream));
238# endif 467# endif
239# if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@ 468_GL_CXXALIASWARN (fwrite);
240extern int vdprintf (int fd, const char *format, va_list args) 469#endif
241 __attribute__ ((__format__ (__printf__, 2, 0))); 470
471#if @GNULIB_GETDELIM@
472/* Read input, up to (and including) the next occurrence of DELIMITER, from
473 STREAM, store it in *LINEPTR (and NUL-terminate it).
474 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
475 bytes of space. It is realloc'd as necessary.
476 Return the number of bytes read and stored at *LINEPTR (not including the
477 NUL terminator), or -1 on error or EOF. */
478# if @REPLACE_GETDELIM@
479# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
480# undef getdelim
481# define getdelim rpl_getdelim
482# endif
483_GL_FUNCDECL_RPL (getdelim, ssize_t,
484 (char **lineptr, size_t *linesize, int delimiter,
485 FILE *stream)
486 _GL_ARG_NONNULL ((1, 2, 4)));
487_GL_CXXALIAS_RPL (getdelim, ssize_t,
488 (char **lineptr, size_t *linesize, int delimiter,
489 FILE *stream));
490# else
491# if !@HAVE_DECL_GETDELIM@
492_GL_FUNCDECL_SYS (getdelim, ssize_t,
493 (char **lineptr, size_t *linesize, int delimiter,
494 FILE *stream)
495 _GL_ARG_NONNULL ((1, 2, 4)));
496# endif
497_GL_CXXALIAS_SYS (getdelim, ssize_t,
498 (char **lineptr, size_t *linesize, int delimiter,
499 FILE *stream));
242# endif 500# endif
501_GL_CXXALIASWARN (getdelim);
243#elif defined GNULIB_POSIXCHECK 502#elif defined GNULIB_POSIXCHECK
244# undef vdprintf 503# undef getdelim
245# define vdprintf(d,f,a) \ 504# if HAVE_RAW_DECL_GETDELIM
246 (GL_LINK_WARNING ("vdprintf is unportable - " \ 505_GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
247 "use gnulib module vdprintf for portability"), \ 506 "use gnulib module getdelim for portability");
248 vdprintf (d, f, a)) 507# endif
249#endif 508#endif
250 509
251#if @GNULIB_VASPRINTF@ 510#if @GNULIB_GETLINE@
252# if @REPLACE_VASPRINTF@ 511/* Read a line, up to (and including) the next newline, from STREAM, store it
253# define asprintf rpl_asprintf 512 in *LINEPTR (and NUL-terminate it).
254# define vasprintf rpl_vasprintf 513 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
514 bytes of space. It is realloc'd as necessary.
515 Return the number of bytes read and stored at *LINEPTR (not including the
516 NUL terminator), or -1 on error or EOF. */
517# if @REPLACE_GETLINE@
518# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
519# undef getline
520# define getline rpl_getline
521# endif
522_GL_FUNCDECL_RPL (getline, ssize_t,
523 (char **lineptr, size_t *linesize, FILE *stream)
524 _GL_ARG_NONNULL ((1, 2, 3)));
525_GL_CXXALIAS_RPL (getline, ssize_t,
526 (char **lineptr, size_t *linesize, FILE *stream));
527# else
528# if !@HAVE_DECL_GETLINE@
529_GL_FUNCDECL_SYS (getline, ssize_t,
530 (char **lineptr, size_t *linesize, FILE *stream)
531 _GL_ARG_NONNULL ((1, 2, 3)));
532# endif
533_GL_CXXALIAS_SYS (getline, ssize_t,
534 (char **lineptr, size_t *linesize, FILE *stream));
535# endif
536# if @HAVE_DECL_GETLINE@
537_GL_CXXALIASWARN (getline);
255# endif 538# endif
256# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@ 539#elif defined GNULIB_POSIXCHECK
257 /* Write formatted output to a string dynamically allocated with malloc(). 540# undef getline
258 If the memory allocation succeeds, store the address of the string in 541# if HAVE_RAW_DECL_GETLINE
259 *RESULT and return the number of resulting bytes, excluding the trailing 542_GL_WARN_ON_USE (getline, "getline is unportable - "
260 NUL. Upon memory allocation error, or some other error, return -1. */ 543 "use gnulib module getline for portability");
261 extern int asprintf (char **result, const char *format, ...)
262 __attribute__ ((__format__ (__printf__, 2, 3)));
263 extern int vasprintf (char **result, const char *format, va_list args)
264 __attribute__ ((__format__ (__printf__, 2, 0)));
265# endif 544# endif
266#endif 545#endif
267 546
268#if @GNULIB_OBSTACK_PRINTF@ 547#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
548struct obstack;
549/* Grow an obstack with formatted output. Return the number of
550 bytes added to OBS. No trailing nul byte is added, and the
551 object should be closed with obstack_finish before use. Upon
552 memory allocation error, call obstack_alloc_failed_handler. Upon
553 other error, return -1. */
269# if @REPLACE_OBSTACK_PRINTF@ 554# if @REPLACE_OBSTACK_PRINTF@
270# define obstack_printf rpl_osbtack_printf 555# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
271# define obstack_vprintf rpl_obstack_vprintf 556# define obstack_printf rpl_obstack_printf
557# endif
558_GL_FUNCDECL_RPL (obstack_printf, int,
559 (struct obstack *obs, const char *format, ...)
560 __attribute__ ((__format__ (__printf__, 2, 3)))
561 _GL_ARG_NONNULL ((1, 2)));
562_GL_CXXALIAS_RPL (obstack_printf, int,
563 (struct obstack *obs, const char *format, ...));
564# else
565# if !@HAVE_DECL_OBSTACK_PRINTF@
566_GL_FUNCDECL_SYS (obstack_printf, int,
567 (struct obstack *obs, const char *format, ...)
568 __attribute__ ((__format__ (__printf__, 2, 3)))
569 _GL_ARG_NONNULL ((1, 2)));
570# endif
571_GL_CXXALIAS_SYS (obstack_printf, int,
572 (struct obstack *obs, const char *format, ...));
272# endif 573# endif
273# if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@ 574_GL_CXXALIASWARN (obstack_printf);
274 struct obstack; 575# if @REPLACE_OBSTACK_PRINTF@
275 /* Grow an obstack with formatted output. Return the number of 576# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
276 bytes added to OBS. No trailing nul byte is added, and the 577# define obstack_vprintf rpl_obstack_vprintf
277 object should be closed with obstack_finish before use. Upon 578# endif
278 memory allocation error, call obstack_alloc_failed_handler. Upon 579_GL_FUNCDECL_RPL (obstack_vprintf, int,
279 other error, return -1. */ 580 (struct obstack *obs, const char *format, va_list args)
280 extern int obstack_printf (struct obstack *obs, const char *format, ...) 581 __attribute__ ((__format__ (__printf__, 2, 0)))
281 __attribute__ ((__format__ (__printf__, 2, 3))); 582 _GL_ARG_NONNULL ((1, 2)));
282 extern int obstack_vprintf (struct obstack *obs, const char *format, 583_GL_CXXALIAS_RPL (obstack_vprintf, int,
283 va_list args) 584 (struct obstack *obs, const char *format, va_list args));
284 __attribute__ ((__format__ (__printf__, 2, 0))); 585# else
586# if !@HAVE_DECL_OBSTACK_PRINTF@
587_GL_FUNCDECL_SYS (obstack_vprintf, int,
588 (struct obstack *obs, const char *format, va_list args)
589 __attribute__ ((__format__ (__printf__, 2, 0)))
590 _GL_ARG_NONNULL ((1, 2)));
591# endif
592_GL_CXXALIAS_SYS (obstack_vprintf, int,
593 (struct obstack *obs, const char *format, va_list args));
285# endif 594# endif
595_GL_CXXALIASWARN (obstack_vprintf);
286#endif 596#endif
287 597
288#if @GNULIB_FOPEN@ 598#if @GNULIB_PERROR@
289# if @REPLACE_FOPEN@ 599/* Print a message to standard error, describing the value of ERRNO,
290# undef fopen 600 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
291# define fopen rpl_fopen 601 and terminated with a newline. */
292extern FILE * fopen (const char *filename, const char *mode); 602# if @REPLACE_PERROR@
603# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
604# define perror rpl_perror
605# endif
606_GL_FUNCDECL_RPL (perror, void, (const char *string));
607_GL_CXXALIAS_RPL (perror, void, (const char *string));
608# else
609_GL_CXXALIAS_SYS (perror, void, (const char *string));
293# endif 610# endif
611_GL_CXXALIASWARN (perror);
294#elif defined GNULIB_POSIXCHECK 612#elif defined GNULIB_POSIXCHECK
295# undef fopen 613# undef perror
296# define fopen(f,m) \ 614/* Assume perror is always declared. */
297 (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \ 615_GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
298 "use gnulib module fopen for portability"), \ 616 "use gnulib module perror for portability");
299 fopen (f, m))
300#endif 617#endif
301 618
302#if @GNULIB_FREOPEN@ 619#if @GNULIB_POPEN@
303# if @REPLACE_FREOPEN@ 620# if @REPLACE_POPEN@
304# undef freopen 621# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
305# define freopen rpl_freopen 622# undef popen
306extern FILE * freopen (const char *filename, const char *mode, FILE *stream); 623# define popen rpl_popen
624# endif
625_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
626 _GL_ARG_NONNULL ((1, 2)));
627_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
628# else
629_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
307# endif 630# endif
631_GL_CXXALIASWARN (popen);
308#elif defined GNULIB_POSIXCHECK 632#elif defined GNULIB_POSIXCHECK
309# undef freopen 633# undef popen
310# define freopen(f,m,s) \ 634# if HAVE_RAW_DECL_POPEN
311 (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \ 635_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
312 "use gnulib module freopen for portability"), \ 636 "use gnulib module popen or pipe for more portability");
313 freopen (f, m, s)) 637# endif
314#endif 638#endif
315 639
316#if @GNULIB_FSEEKO@ 640#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
317# if @REPLACE_FSEEKO@ 641# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
318/* Provide fseek, fseeko functions that are aware of a preceding 642 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
319 fflush(), and which detect pipes. */ 643# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
320# define fseeko rpl_fseeko 644/* Don't break __attribute__((format(printf,M,N))). */
321extern int fseeko (FILE *fp, off_t offset, int whence); 645# define printf __printf__
322# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence) 646# endif
647# define GNULIB_overrides_printf 1
648_GL_FUNCDECL_RPL_1 (__printf__, int,
649 (const char *format, ...)
650 __attribute__ ((__format__ (__printf__, 1, 2)))
651 _GL_ARG_NONNULL ((1)));
652_GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
653# else
654_GL_CXXALIAS_SYS (printf, int, (const char *format, ...));
323# endif 655# endif
324#elif defined GNULIB_POSIXCHECK 656_GL_CXXALIASWARN (printf);
325# undef fseeko 657#endif
326# define fseeko(f,o,w) \ 658#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
327 (GL_LINK_WARNING ("fseeko is unportable - " \ 659# if !GNULIB_overrides_printf
328 "use gnulib module fseeko for portability"), \ 660# undef printf
329 fseeko (f, o, w)) 661# endif
662/* Assume printf is always declared. */
663_GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - "
664 "use gnulib module printf-posix for portable "
665 "POSIX compliance");
330#endif 666#endif
331 667
332#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@ 668#if @GNULIB_PUTC@
333extern int rpl_fseek (FILE *fp, long offset, int whence); 669# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
334# undef fseek 670# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
335# if defined GNULIB_POSIXCHECK 671# undef putc
336# define fseek(f,o,w) \ 672# define putc rpl_fputc
337 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \ 673# endif
338 "on 32-bit platforms - " \ 674_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2)));
339 "use fseeko function for handling of large files"), \ 675_GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
340 rpl_fseek (f, o, w))
341# else 676# else
342# define fseek rpl_fseek 677_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
343# endif 678# endif
344#elif defined GNULIB_POSIXCHECK 679_GL_CXXALIASWARN (putc);
345# ifndef fseek 680#endif
346# define fseek(f,o,w) \ 681
347 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \ 682#if @GNULIB_PUTCHAR@
348 "on 32-bit platforms - " \ 683# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
349 "use fseeko function for handling of large files"), \ 684# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
350 fseek (f, o, w)) 685# undef putchar
686# define putchar rpl_putchar
687# endif
688_GL_FUNCDECL_RPL (putchar, int, (int c));
689_GL_CXXALIAS_RPL (putchar, int, (int c));
690# else
691_GL_CXXALIAS_SYS (putchar, int, (int c));
351# endif 692# endif
693_GL_CXXALIASWARN (putchar);
352#endif 694#endif
353 695
354#if @GNULIB_FTELLO@ 696#if @GNULIB_PUTS@
355# if @REPLACE_FTELLO@ 697# if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
356# define ftello rpl_ftello 698# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
357extern off_t ftello (FILE *fp); 699# undef puts
358# define ftell(fp) ftello (fp) 700# define puts rpl_puts
701# endif
702_GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1)));
703_GL_CXXALIAS_RPL (puts, int, (const char *string));
704# else
705_GL_CXXALIAS_SYS (puts, int, (const char *string));
359# endif 706# endif
360#elif defined GNULIB_POSIXCHECK 707_GL_CXXALIASWARN (puts);
361# undef ftello
362# define ftello(f) \
363 (GL_LINK_WARNING ("ftello is unportable - " \
364 "use gnulib module ftello for portability"), \
365 ftello (f))
366#endif 708#endif
367 709
368#if @GNULIB_FTELL@ && @REPLACE_FTELL@ 710#if @GNULIB_REMOVE@
369extern long rpl_ftell (FILE *fp); 711# if @REPLACE_REMOVE@
370# undef ftell 712# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
371# if GNULIB_POSIXCHECK 713# undef remove
372# define ftell(f) \ 714# define remove rpl_remove
373 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \ 715# endif
374 "on 32-bit platforms - " \ 716_GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1)));
375 "use ftello function for handling of large files"), \ 717_GL_CXXALIAS_RPL (remove, int, (const char *name));
376 rpl_ftell (f))
377# else 718# else
378# define ftell rpl_ftell 719_GL_CXXALIAS_SYS (remove, int, (const char *name));
379# endif 720# endif
721_GL_CXXALIASWARN (remove);
380#elif defined GNULIB_POSIXCHECK 722#elif defined GNULIB_POSIXCHECK
381# ifndef ftell 723# undef remove
382# define ftell(f) \ 724/* Assume remove is always declared. */
383 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \ 725_GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - "
384 "on 32-bit platforms - " \ 726 "use gnulib module remove for more portability");
385 "use ftello function for handling of large files"), \
386 ftell (f))
387# endif
388#endif 727#endif
389 728
390#if @GNULIB_FFLUSH@ 729#if @GNULIB_RENAME@
391# if @REPLACE_FFLUSH@ 730# if @REPLACE_RENAME@
392# define fflush rpl_fflush 731# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
393 /* Flush all pending data on STREAM according to POSIX rules. Both 732# undef rename
394 output and seekable input streams are supported. 733# define rename rpl_rename
395 Note! LOSS OF DATA can occur if fflush is applied on an input stream 734# endif
396 that is _not_seekable_ or on an update stream that is _not_seekable_ 735_GL_FUNCDECL_RPL (rename, int,
397 and in which the most recent operation was input. Seekability can 736 (const char *old_filename, const char *new_filename)
398 be tested with lseek(fileno(fp),0,SEEK_CUR). */ 737 _GL_ARG_NONNULL ((1, 2)));
399 extern int fflush (FILE *gl_stream); 738_GL_CXXALIAS_RPL (rename, int,
739 (const char *old_filename, const char *new_filename));
740# else
741_GL_CXXALIAS_SYS (rename, int,
742 (const char *old_filename, const char *new_filename));
400# endif 743# endif
744_GL_CXXALIASWARN (rename);
401#elif defined GNULIB_POSIXCHECK 745#elif defined GNULIB_POSIXCHECK
402# undef fflush 746# undef rename
403# define fflush(f) \ 747/* Assume rename is always declared. */
404 (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \ 748_GL_WARN_ON_USE (rename, "rename is buggy on some platforms - "
405 "use gnulib module fflush for portable " \ 749 "use gnulib module rename for more portability");
406 "POSIX compliance"), \
407 fflush (f))
408#endif 750#endif
409 751
410#if @GNULIB_FCLOSE@ 752#if @GNULIB_RENAMEAT@
411# if @REPLACE_FCLOSE@ 753# if @REPLACE_RENAMEAT@
412# define fclose rpl_fclose 754# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
413 /* Close STREAM and its underlying file descriptor. */ 755# undef renameat
414extern int fclose (FILE *stream); 756# define renameat rpl_renameat
757# endif
758_GL_FUNCDECL_RPL (renameat, int,
759 (int fd1, char const *file1, int fd2, char const *file2)
760 _GL_ARG_NONNULL ((2, 4)));
761_GL_CXXALIAS_RPL (renameat, int,
762 (int fd1, char const *file1, int fd2, char const *file2));
763# else
764# if !@HAVE_RENAMEAT@
765_GL_FUNCDECL_SYS (renameat, int,
766 (int fd1, char const *file1, int fd2, char const *file2)
767 _GL_ARG_NONNULL ((2, 4)));
768# endif
769_GL_CXXALIAS_SYS (renameat, int,
770 (int fd1, char const *file1, int fd2, char const *file2));
415# endif 771# endif
772_GL_CXXALIASWARN (renameat);
416#elif defined GNULIB_POSIXCHECK 773#elif defined GNULIB_POSIXCHECK
417# undef fclose 774# undef renameat
418# define fclose(f) \ 775# if HAVE_RAW_DECL_RENAMEAT
419 (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \ 776_GL_WARN_ON_USE (renameat, "renameat is not portable - "
420 "use gnulib module fclose for portable " \ 777 "use gnulib module renameat for portability");
421 "POSIX compliance"), \ 778# endif
422 fclose (f))
423#endif 779#endif
424 780
425#if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 781#if @GNULIB_SNPRINTF@
426# undef fputc 782# if @REPLACE_SNPRINTF@
427# define fputc rpl_fputc 783# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
428extern int fputc (int c, FILE *stream); 784# define snprintf rpl_snprintf
785# endif
786_GL_FUNCDECL_RPL (snprintf, int,
787 (char *str, size_t size, const char *format, ...)
788 __attribute__ ((__format__ (__printf__, 3, 4)))
789 _GL_ARG_NONNULL ((3)));
790_GL_CXXALIAS_RPL (snprintf, int,
791 (char *str, size_t size, const char *format, ...));
792# else
793# if !@HAVE_DECL_SNPRINTF@
794_GL_FUNCDECL_SYS (snprintf, int,
795 (char *str, size_t size, const char *format, ...)
796 __attribute__ ((__format__ (__printf__, 3, 4)))
797 _GL_ARG_NONNULL ((3)));
798# endif
799_GL_CXXALIAS_SYS (snprintf, int,
800 (char *str, size_t size, const char *format, ...));
801# endif
802_GL_CXXALIASWARN (snprintf);
803#elif defined GNULIB_POSIXCHECK
804# undef snprintf
805# if HAVE_RAW_DECL_SNPRINTF
806_GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
807 "use gnulib module snprintf for portability");
808# endif
429#endif 809#endif
430 810
431#if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 811/* Some people would argue that sprintf should be handled like gets
432# undef putc 812 (for example, OpenBSD issues a link warning for both functions),
433# define putc rpl_fputc 813 since both can cause security holes due to buffer overruns.
434extern int putc (int c, FILE *stream); 814 However, we believe that sprintf can be used safely, and is more
435#endif 815 efficient than snprintf in those safe cases; and as proof of our
816 belief, we use sprintf in several gnulib modules. So this header
817 intentionally avoids adding a warning to sprintf except when
818 GNULIB_POSIXCHECK is defined. */
436 819
437#if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 820#if @GNULIB_SPRINTF_POSIX@
438# undef putchar 821# if @REPLACE_SPRINTF@
439# define putchar rpl_putchar 822# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
440extern int putchar (int c); 823# define sprintf rpl_sprintf
824# endif
825_GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...)
826 __attribute__ ((__format__ (__printf__, 2, 3)))
827 _GL_ARG_NONNULL ((1, 2)));
828_GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...));
829# else
830_GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...));
831# endif
832_GL_CXXALIASWARN (sprintf);
833#elif defined GNULIB_POSIXCHECK
834# undef sprintf
835/* Assume sprintf is always declared. */
836_GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
837 "use gnulib module sprintf-posix for portable "
838 "POSIX compliance");
441#endif 839#endif
442 840
443#if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 841#if @GNULIB_TMPFILE@
444# undef fputs 842# if @REPLACE_TMPFILE@
445# define fputs rpl_fputs 843# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
446extern int fputs (const char *string, FILE *stream); 844# define tmpfile rpl_tmpfile
845# endif
846_GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
847_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
848# else
849_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
850# endif
851_GL_CXXALIASWARN (tmpfile);
852#elif defined GNULIB_POSIXCHECK
853# undef tmpfile
854# if HAVE_RAW_DECL_TMPFILE
855_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
856 "use gnulib module tmpfile for portability");
857# endif
447#endif 858#endif
448 859
449#if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 860#if @GNULIB_VASPRINTF@
450# undef puts 861/* Write formatted output to a string dynamically allocated with malloc().
451# define puts rpl_puts 862 If the memory allocation succeeds, store the address of the string in
452extern int puts (const char *string); 863 *RESULT and return the number of resulting bytes, excluding the trailing
864 NUL. Upon memory allocation error, or some other error, return -1. */
865# if @REPLACE_VASPRINTF@
866# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
867# define asprintf rpl_asprintf
868# endif
869_GL_FUNCDECL_RPL (asprintf, int,
870 (char **result, const char *format, ...)
871 __attribute__ ((__format__ (__printf__, 2, 3)))
872 _GL_ARG_NONNULL ((1, 2)));
873_GL_CXXALIAS_RPL (asprintf, int,
874 (char **result, const char *format, ...));
875# else
876# if !@HAVE_VASPRINTF@
877_GL_FUNCDECL_SYS (asprintf, int,
878 (char **result, const char *format, ...)
879 __attribute__ ((__format__ (__printf__, 2, 3)))
880 _GL_ARG_NONNULL ((1, 2)));
881# endif
882_GL_CXXALIAS_SYS (asprintf, int,
883 (char **result, const char *format, ...));
884# endif
885_GL_CXXALIASWARN (asprintf);
886# if @REPLACE_VASPRINTF@
887# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
888# define vasprintf rpl_vasprintf
889# endif
890_GL_FUNCDECL_RPL (vasprintf, int,
891 (char **result, const char *format, va_list args)
892 __attribute__ ((__format__ (__printf__, 2, 0)))
893 _GL_ARG_NONNULL ((1, 2)));
894_GL_CXXALIAS_RPL (vasprintf, int,
895 (char **result, const char *format, va_list args));
896# else
897# if !@HAVE_VASPRINTF@
898_GL_FUNCDECL_SYS (vasprintf, int,
899 (char **result, const char *format, va_list args)
900 __attribute__ ((__format__ (__printf__, 2, 0)))
901 _GL_ARG_NONNULL ((1, 2)));
902# endif
903_GL_CXXALIAS_SYS (vasprintf, int,
904 (char **result, const char *format, va_list args));
905# endif
906_GL_CXXALIASWARN (vasprintf);
453#endif 907#endif
454 908
455#if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ 909#if @GNULIB_VDPRINTF@
456# undef fwrite 910# if @REPLACE_VDPRINTF@
457# define fwrite rpl_fwrite 911# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
458extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream); 912# define vdprintf rpl_vdprintf
913# endif
914_GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args)
915 __attribute__ ((__format__ (__printf__, 2, 0)))
916 _GL_ARG_NONNULL ((2)));
917_GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args));
918# else
919# if !@HAVE_VDPRINTF@
920_GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args)
921 __attribute__ ((__format__ (__printf__, 2, 0)))
922 _GL_ARG_NONNULL ((2)));
923# endif
924/* Need to cast, because on Solaris, the third parameter will likely be
925 __va_list args. */
926_GL_CXXALIAS_SYS_CAST (vdprintf, int,
927 (int fd, const char *format, va_list args));
928# endif
929_GL_CXXALIASWARN (vdprintf);
930#elif defined GNULIB_POSIXCHECK
931# undef vdprintf
932# if HAVE_RAW_DECL_VDPRINTF
933_GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
934 "use gnulib module vdprintf for portability");
935# endif
459#endif 936#endif
460 937
461#if @GNULIB_GETDELIM@ 938#if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
462# if !@HAVE_DECL_GETDELIM@ 939# if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
463/* Read input, up to (and including) the next occurrence of DELIMITER, from 940 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
464 STREAM, store it in *LINEPTR (and NUL-terminate it). 941# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
465 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE 942# define vfprintf rpl_vfprintf
466 bytes of space. It is realloc'd as necessary. 943# endif
467 Return the number of bytes read and stored at *LINEPTR (not including the 944# define GNULIB_overrides_vfprintf 1
468 NUL terminator), or -1 on error or EOF. */ 945_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)
469extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter, 946 __attribute__ ((__format__ (__printf__, 2, 0)))
470 FILE *stream); 947 _GL_ARG_NONNULL ((1, 2)));
948_GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args));
949# else
950/* Need to cast, because on Solaris, the third parameter is
951 __va_list args
952 and GCC's fixincludes did not change this to __gnuc_va_list. */
953_GL_CXXALIAS_SYS_CAST (vfprintf, int,
954 (FILE *fp, const char *format, va_list args));
471# endif 955# endif
472#elif defined GNULIB_POSIXCHECK 956_GL_CXXALIASWARN (vfprintf);
473# undef getdelim 957#endif
474# define getdelim(l, s, d, f) \ 958#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
475 (GL_LINK_WARNING ("getdelim is unportable - " \ 959# if !GNULIB_overrides_vfprintf
476 "use gnulib module getdelim for portability"), \ 960# undef vfprintf
477 getdelim (l, s, d, f)) 961# endif
962/* Assume vfprintf is always declared. */
963_GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
964 "use gnulib module vfprintf-posix for portable "
965 "POSIX compliance");
478#endif 966#endif
479 967
480#if @GNULIB_GETLINE@ 968#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
481# if @REPLACE_GETLINE@ 969# if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
482# undef getline 970 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@)
483# define getline rpl_getline 971# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
972# define vprintf rpl_vprintf
973# endif
974# define GNULIB_overrides_vprintf 1
975_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args)
976 __attribute__ ((__format__ (__printf__, 1, 0)))
977 _GL_ARG_NONNULL ((1)));
978_GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args));
979# else
980/* Need to cast, because on Solaris, the second parameter is
981 __va_list args
982 and GCC's fixincludes did not change this to __gnuc_va_list. */
983_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));
484# endif 984# endif
485# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@ 985_GL_CXXALIASWARN (vprintf);
486/* Read a line, up to (and including) the next newline, from STREAM, store it 986#endif
487 in *LINEPTR (and NUL-terminate it). 987#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
488 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE 988# if !GNULIB_overrides_vprintf
489 bytes of space. It is realloc'd as necessary. 989# undef vprintf
490 Return the number of bytes read and stored at *LINEPTR (not including the
491 NUL terminator), or -1 on error or EOF. */
492extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
493# endif 990# endif
494#elif defined GNULIB_POSIXCHECK 991/* Assume vprintf is always declared. */
495# undef getline 992_GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
496# define getline(l, s, f) \ 993 "use gnulib module vprintf-posix for portable "
497 (GL_LINK_WARNING ("getline is unportable - " \ 994 "POSIX compliance");
498 "use gnulib module getline for portability"), \
499 getline (l, s, f))
500#endif 995#endif
501 996
502#if @GNULIB_PERROR@ 997#if @GNULIB_VSNPRINTF@
503# if @REPLACE_PERROR@ 998# if @REPLACE_VSNPRINTF@
504# define perror rpl_perror 999# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
505/* Print a message to standard error, describing the value of ERRNO, 1000# define vsnprintf rpl_vsnprintf
506 (if STRING is not NULL and not empty) prefixed with STRING and ": ", 1001# endif
507 and terminated with a newline. */ 1002_GL_FUNCDECL_RPL (vsnprintf, int,
508extern void perror (const char *string); 1003 (char *str, size_t size, const char *format, va_list args)
1004 __attribute__ ((__format__ (__printf__, 3, 0)))
1005 _GL_ARG_NONNULL ((3)));
1006_GL_CXXALIAS_RPL (vsnprintf, int,
1007 (char *str, size_t size, const char *format, va_list args));
1008# else
1009# if !@HAVE_DECL_VSNPRINTF@
1010_GL_FUNCDECL_SYS (vsnprintf, int,
1011 (char *str, size_t size, const char *format, va_list args)
1012 __attribute__ ((__format__ (__printf__, 3, 0)))
1013 _GL_ARG_NONNULL ((3)));
1014# endif
1015_GL_CXXALIAS_SYS (vsnprintf, int,
1016 (char *str, size_t size, const char *format, va_list args));
509# endif 1017# endif
1018_GL_CXXALIASWARN (vsnprintf);
510#elif defined GNULIB_POSIXCHECK 1019#elif defined GNULIB_POSIXCHECK
511# undef perror 1020# undef vsnprintf
512# define perror(s) \ 1021# if HAVE_RAW_DECL_VSNPRINTF
513 (GL_LINK_WARNING ("perror is not always POSIX compliant - " \ 1022_GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
514 "use gnulib module perror for portability"), \ 1023 "use gnulib module vsnprintf for portability");
515 perror (s)) 1024# endif
516#endif 1025#endif
517 1026
518#ifdef __cplusplus 1027#if @GNULIB_VSPRINTF_POSIX@
519} 1028# if @REPLACE_VSPRINTF@
1029# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1030# define vsprintf rpl_vsprintf
1031# endif
1032_GL_FUNCDECL_RPL (vsprintf, int,
1033 (char *str, const char *format, va_list args)
1034 __attribute__ ((__format__ (__printf__, 2, 0)))
1035 _GL_ARG_NONNULL ((1, 2)));
1036_GL_CXXALIAS_RPL (vsprintf, int,
1037 (char *str, const char *format, va_list args));
1038# else
1039/* Need to cast, because on Solaris, the third parameter is
1040 __va_list args
1041 and GCC's fixincludes did not change this to __gnuc_va_list. */
1042_GL_CXXALIAS_SYS_CAST (vsprintf, int,
1043 (char *str, const char *format, va_list args));
1044# endif
1045_GL_CXXALIASWARN (vsprintf);
1046#elif defined GNULIB_POSIXCHECK
1047# undef vsprintf
1048/* Assume vsprintf is always declared. */
1049_GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
1050 "use gnulib module vsprintf-posix for portable "
1051 "POSIX compliance");
520#endif 1052#endif
521 1053
1054
522#endif /* _GL_STDIO_H */ 1055#endif /* _GL_STDIO_H */
523#endif /* _GL_STDIO_H */ 1056#endif /* _GL_STDIO_H */
524#endif 1057#endif
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index f99767f6..d74c2518 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <stdlib.h>. 1/* A GNU-like <stdlib.h>.
2 2
3 Copyright (C) 1995, 2001-2004, 2006-2009 Free Software Foundation, Inc. 3 Copyright (C) 1995, 2001-2004, 2006-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -35,9 +35,11 @@
35#ifndef _GL_STDLIB_H 35#ifndef _GL_STDLIB_H
36#define _GL_STDLIB_H 36#define _GL_STDLIB_H
37 37
38/* NetBSD 5.0 mis-defines NULL. */
39#include <stddef.h>
38 40
39/* Solaris declares getloadavg() in <sys/loadavg.h>. */ 41/* Solaris declares getloadavg() in <sys/loadavg.h>. */
40#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@ 42#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@
41# include <sys/loadavg.h> 43# include <sys/loadavg.h>
42#endif 44#endif
43 45
@@ -47,24 +49,36 @@
47# include <random.h> 49# include <random.h>
48#endif 50#endif
49 51
50#if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@ 52#if !@HAVE_STRUCT_RANDOM_DATA@ || (@GNULIB_RANDOM_R@ && !@HAVE_RANDOM_R@) \
53 || defined GNULIB_POSIXCHECK
51# include <stdint.h> 54# include <stdint.h>
52#endif 55#endif
53 56
54#if !@HAVE_STRUCT_RANDOM_DATA@ 57#if !@HAVE_STRUCT_RANDOM_DATA@
55struct random_data 58struct random_data
56{ 59{
57 int32_t *fptr; /* Front pointer. */ 60 int32_t *fptr; /* Front pointer. */
58 int32_t *rptr; /* Rear pointer. */ 61 int32_t *rptr; /* Rear pointer. */
59 int32_t *state; /* Array of state values. */ 62 int32_t *state; /* Array of state values. */
60 int rand_type; /* Type of random number generator. */ 63 int rand_type; /* Type of random number generator. */
61 int rand_deg; /* Degree of random number generator. */ 64 int rand_deg; /* Degree of random number generator. */
62 int rand_sep; /* Distance between front and rear. */ 65 int rand_sep; /* Distance between front and rear. */
63 int32_t *end_ptr; /* Pointer behind state table. */ 66 int32_t *end_ptr; /* Pointer behind state table. */
64}; 67};
65#endif 68#endif
66 69
67/* The definition of GL_LINK_WARNING is copied here. */ 70#if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
71/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
72/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
73/* But avoid namespace pollution on glibc systems and native Windows. */
74# include <unistd.h>
75#endif
76
77/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
78
79/* The definition of _GL_ARG_NONNULL is copied here. */
80
81/* The definition of _GL_WARN_ON_USE is copied here. */
68 82
69 83
70/* Some systems do not define EXIT_*, despite otherwise supporting C89. */ 84/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
@@ -81,88 +95,84 @@ struct random_data
81#endif 95#endif
82 96
83 97
84#ifdef __cplusplus 98#if @GNULIB_ATOLL@
85extern "C" { 99/* Parse a signed decimal integer.
86#endif 100 Returns the value of the integer. Errors are not detected. */
87 101# if !@HAVE_ATOLL@
88 102_GL_FUNCDECL_SYS (atoll, long long, (const char *string) _GL_ARG_NONNULL ((1)));
89#if @GNULIB_MALLOC_POSIX@
90# if !@HAVE_MALLOC_POSIX@
91# undef malloc
92# define malloc rpl_malloc
93extern void * malloc (size_t size);
94# endif 103# endif
104_GL_CXXALIAS_SYS (atoll, long long, (const char *string));
105_GL_CXXALIASWARN (atoll);
95#elif defined GNULIB_POSIXCHECK 106#elif defined GNULIB_POSIXCHECK
96# undef malloc 107# undef atoll
97# define malloc(s) \ 108# if HAVE_RAW_DECL_ATOLL
98 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \ 109_GL_WARN_ON_USE (atoll, "atoll is unportable - "
99 "use gnulib module malloc-posix for portability"), \ 110 "use gnulib module atoll for portability");
100 malloc (s))
101#endif
102
103
104#if @GNULIB_REALLOC_POSIX@
105# if !@HAVE_REALLOC_POSIX@
106# undef realloc
107# define realloc rpl_realloc
108extern void * realloc (void *ptr, size_t size);
109# endif 111# endif
110#elif defined GNULIB_POSIXCHECK
111# undef realloc
112# define realloc(p,s) \
113 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
114 "use gnulib module realloc-posix for portability"), \
115 realloc (p, s))
116#endif 112#endif
117 113
118
119#if @GNULIB_CALLOC_POSIX@ 114#if @GNULIB_CALLOC_POSIX@
120# if !@HAVE_CALLOC_POSIX@ 115# if !@HAVE_CALLOC_POSIX@
121# undef calloc 116# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
122# define calloc rpl_calloc 117# undef calloc
123extern void * calloc (size_t nmemb, size_t size); 118# define calloc rpl_calloc
119# endif
120_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size));
121_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size));
122# else
123_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size));
124# endif 124# endif
125_GL_CXXALIASWARN (calloc);
125#elif defined GNULIB_POSIXCHECK 126#elif defined GNULIB_POSIXCHECK
126# undef calloc 127# undef calloc
127# define calloc(n,s) \ 128/* Assume calloc is always declared. */
128 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \ 129_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
129 "use gnulib module calloc-posix for portability"), \ 130 "use gnulib module calloc-posix for portability");
130 calloc (n, s))
131#endif 131#endif
132 132
133 133#if @GNULIB_CANONICALIZE_FILE_NAME@
134#if @GNULIB_ATOLL@ 134# if @REPLACE_CANONICALIZE_FILE_NAME@
135# if !@HAVE_ATOLL@ 135# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
136/* Parse a signed decimal integer. 136# define canonicalize_file_name rpl_canonicalize_file_name
137 Returns the value of the integer. Errors are not detected. */ 137# endif
138extern long long atoll (const char *string); 138_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name)
139 _GL_ARG_NONNULL ((1)));
140_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name));
141# else
142# if !@HAVE_CANONICALIZE_FILE_NAME@
143_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name)
144 _GL_ARG_NONNULL ((1)));
145# endif
146_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name));
139# endif 147# endif
148_GL_CXXALIASWARN (canonicalize_file_name);
140#elif defined GNULIB_POSIXCHECK 149#elif defined GNULIB_POSIXCHECK
141# undef atoll 150# undef canonicalize_file_name
142# define atoll(s) \ 151# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
143 (GL_LINK_WARNING ("atoll is unportable - " \ 152_GL_WARN_ON_USE (canonicalize_file_name, "canonicalize_file_name is unportable - "
144 "use gnulib module atoll for portability"), \ 153 "use gnulib module canonicalize-lgpl for portability");
145 atoll (s)) 154# endif
146#endif 155#endif
147 156
148
149#if @GNULIB_GETLOADAVG@ 157#if @GNULIB_GETLOADAVG@
150# if !@HAVE_DECL_GETLOADAVG@
151/* Store max(NELEM,3) load average numbers in LOADAVG[]. 158/* Store max(NELEM,3) load average numbers in LOADAVG[].
152 The three numbers are the load average of the last 1 minute, the last 5 159 The three numbers are the load average of the last 1 minute, the last 5
153 minutes, and the last 15 minutes, respectively. 160 minutes, and the last 15 minutes, respectively.
154 LOADAVG is an array of NELEM numbers. */ 161 LOADAVG is an array of NELEM numbers. */
155extern int getloadavg (double loadavg[], int nelem); 162# if !@HAVE_DECL_GETLOADAVG@
163_GL_FUNCDECL_SYS (getloadavg, int, (double loadavg[], int nelem)
164 _GL_ARG_NONNULL ((1)));
156# endif 165# endif
166_GL_CXXALIAS_SYS (getloadavg, int, (double loadavg[], int nelem));
167_GL_CXXALIASWARN (getloadavg);
157#elif defined GNULIB_POSIXCHECK 168#elif defined GNULIB_POSIXCHECK
158# undef getloadavg 169# undef getloadavg
159# define getloadavg(l,n) \ 170# if HAVE_RAW_DECL_GETLOADAVG
160 (GL_LINK_WARNING ("getloadavg is not portable - " \ 171_GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - "
161 "use gnulib module getloadavg for portability"), \ 172 "use gnulib module getloadavg for portability");
162 getloadavg (l, n)) 173# endif
163#endif 174#endif
164 175
165
166#if @GNULIB_GETSUBOPT@ 176#if @GNULIB_GETSUBOPT@
167/* Assuming *OPTIONP is a comma separated list of elements of the form 177/* Assuming *OPTIONP is a comma separated list of elements of the form
168 "token" or "token=value", getsubopt parses the first of these elements. 178 "token" or "token=value", getsubopt parses the first of these elements.
@@ -176,37 +186,133 @@ extern int getloadavg (double loadavg[], int nelem);
176 For more details see the POSIX:2001 specification. 186 For more details see the POSIX:2001 specification.
177 http://www.opengroup.org/susv3xsh/getsubopt.html */ 187 http://www.opengroup.org/susv3xsh/getsubopt.html */
178# if !@HAVE_GETSUBOPT@ 188# if !@HAVE_GETSUBOPT@
179extern int getsubopt (char **optionp, char *const *tokens, char **valuep); 189_GL_FUNCDECL_SYS (getsubopt, int,
190 (char **optionp, char *const *tokens, char **valuep)
191 _GL_ARG_NONNULL ((1, 2, 3)));
180# endif 192# endif
193_GL_CXXALIAS_SYS (getsubopt, int,
194 (char **optionp, char *const *tokens, char **valuep));
195_GL_CXXALIASWARN (getsubopt);
181#elif defined GNULIB_POSIXCHECK 196#elif defined GNULIB_POSIXCHECK
182# undef getsubopt 197# undef getsubopt
183# define getsubopt(o,t,v) \ 198# if HAVE_RAW_DECL_GETSUBOPT
184 (GL_LINK_WARNING ("getsubopt is unportable - " \ 199_GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - "
185 "use gnulib module getsubopt for portability"), \ 200 "use gnulib module getsubopt for portability");
186 getsubopt (o, t, v)) 201# endif
202#endif
203
204#if @GNULIB_GRANTPT@
205/* Change the ownership and access permission of the slave side of the
206 pseudo-terminal whose master side is specified by FD. */
207# if !@HAVE_GRANTPT@
208_GL_FUNCDECL_SYS (grantpt, int, (int fd));
209# endif
210_GL_CXXALIAS_SYS (grantpt, int, (int fd));
211_GL_CXXALIASWARN (grantpt);
212#elif defined GNULIB_POSIXCHECK
213# undef grantpt
214# if HAVE_RAW_DECL_GRANTPT
215_GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
216 "use gnulib module grantpt for portability");
217# endif
187#endif 218#endif
188 219
220#if @GNULIB_MALLOC_POSIX@
221# if !@HAVE_MALLOC_POSIX@
222# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
223# undef malloc
224# define malloc rpl_malloc
225# endif
226_GL_FUNCDECL_RPL (malloc, void *, (size_t size));
227_GL_CXXALIAS_RPL (malloc, void *, (size_t size));
228# else
229_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
230# endif
231_GL_CXXALIASWARN (malloc);
232#elif defined GNULIB_POSIXCHECK
233# undef malloc
234/* Assume malloc is always declared. */
235_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
236 "use gnulib module malloc-posix for portability");
237#endif
189 238
190#if @GNULIB_MKDTEMP@ 239#if @GNULIB_MKDTEMP@
191# if !@HAVE_MKDTEMP@
192/* Create a unique temporary directory from TEMPLATE. 240/* Create a unique temporary directory from TEMPLATE.
193 The last six characters of TEMPLATE must be "XXXXXX"; 241 The last six characters of TEMPLATE must be "XXXXXX";
194 they are replaced with a string that makes the directory name unique. 242 they are replaced with a string that makes the directory name unique.
195 Returns TEMPLATE, or a null pointer if it cannot get a unique name. 243 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
196 The directory is created mode 700. */ 244 The directory is created mode 700. */
197extern char * mkdtemp (char * /*template*/); 245# if !@HAVE_MKDTEMP@
246_GL_FUNCDECL_SYS (mkdtemp, char *, (char * /*template*/) _GL_ARG_NONNULL ((1)));
198# endif 247# endif
248_GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/));
249_GL_CXXALIASWARN (mkdtemp);
199#elif defined GNULIB_POSIXCHECK 250#elif defined GNULIB_POSIXCHECK
200# undef mkdtemp 251# undef mkdtemp
201# define mkdtemp(t) \ 252# if HAVE_RAW_DECL_MKDTEMP
202 (GL_LINK_WARNING ("mkdtemp is unportable - " \ 253_GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - "
203 "use gnulib module mkdtemp for portability"), \ 254 "use gnulib module mkdtemp for portability");
204 mkdtemp (t)) 255# endif
205#endif 256#endif
206 257
258#if @GNULIB_MKOSTEMP@
259/* Create a unique temporary file from TEMPLATE.
260 The last six characters of TEMPLATE must be "XXXXXX";
261 they are replaced with a string that makes the file name unique.
262 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
263 and O_TEXT, O_BINARY (defined in "binary-io.h").
264 The file is then created, with the specified flags, ensuring it didn't exist
265 before.
266 The file is created read-write (mask at least 0600 & ~umask), but it may be
267 world-readable and world-writable (mask 0666 & ~umask), depending on the
268 implementation.
269 Returns the open file descriptor if successful, otherwise -1 and errno
270 set. */
271# if !@HAVE_MKOSTEMP@
272_GL_FUNCDECL_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)
273 _GL_ARG_NONNULL ((1)));
274# endif
275_GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/));
276_GL_CXXALIASWARN (mkostemp);
277#elif defined GNULIB_POSIXCHECK
278# undef mkostemp
279# if HAVE_RAW_DECL_MKOSTEMP
280_GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - "
281 "use gnulib module mkostemp for portability");
282# endif
283#endif
284
285#if @GNULIB_MKOSTEMPS@
286/* Create a unique temporary file from TEMPLATE.
287 The last six characters of TEMPLATE before a suffix of length
288 SUFFIXLEN must be "XXXXXX";
289 they are replaced with a string that makes the file name unique.
290 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
291 and O_TEXT, O_BINARY (defined in "binary-io.h").
292 The file is then created, with the specified flags, ensuring it didn't exist
293 before.
294 The file is created read-write (mask at least 0600 & ~umask), but it may be
295 world-readable and world-writable (mask 0666 & ~umask), depending on the
296 implementation.
297 Returns the open file descriptor if successful, otherwise -1 and errno
298 set. */
299# if !@HAVE_MKOSTEMPS@
300_GL_FUNCDECL_SYS (mkostemps, int,
301 (char * /*template*/, int /*suffixlen*/, int /*flags*/)
302 _GL_ARG_NONNULL ((1)));
303# endif
304_GL_CXXALIAS_SYS (mkostemps, int,
305 (char * /*template*/, int /*suffixlen*/, int /*flags*/));
306_GL_CXXALIASWARN (mkostemps);
307#elif defined GNULIB_POSIXCHECK
308# undef mkostemps
309# if HAVE_RAW_DECL_MKOSTEMPS
310_GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - "
311 "use gnulib module mkostemps for portability");
312# endif
313#endif
207 314
208#if @GNULIB_MKSTEMP@ 315#if @GNULIB_MKSTEMP@
209# if @REPLACE_MKSTEMP@
210/* Create a unique temporary file from TEMPLATE. 316/* Create a unique temporary file from TEMPLATE.
211 The last six characters of TEMPLATE must be "XXXXXX"; 317 The last six characters of TEMPLATE must be "XXXXXX";
212 they are replaced with a string that makes the file name unique. 318 they are replaced with a string that makes the file name unique.
@@ -216,124 +322,276 @@ extern char * mkdtemp (char * /*template*/);
216 implementation. 322 implementation.
217 Returns the open file descriptor if successful, otherwise -1 and errno 323 Returns the open file descriptor if successful, otherwise -1 and errno
218 set. */ 324 set. */
219# define mkstemp rpl_mkstemp 325# if @REPLACE_MKSTEMP@
220extern int mkstemp (char * /*template*/); 326# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
327# define mkstemp rpl_mkstemp
328# endif
329_GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
330_GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/));
221# else 331# else
222/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ 332# if ! @HAVE_MKSTEMP@
223# include <unistd.h> 333_GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1)));
334# endif
335_GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/));
224# endif 336# endif
337_GL_CXXALIASWARN (mkstemp);
225#elif defined GNULIB_POSIXCHECK 338#elif defined GNULIB_POSIXCHECK
226# undef mkstemp 339# undef mkstemp
227# define mkstemp(t) \ 340# if HAVE_RAW_DECL_MKSTEMP
228 (GL_LINK_WARNING ("mkstemp is unportable - " \ 341_GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - "
229 "use gnulib module mkstemp for portability"), \ 342 "use gnulib module mkstemp for portability");
230 mkstemp (t)) 343# endif
231#endif 344#endif
232 345
346#if @GNULIB_MKSTEMPS@
347/* Create a unique temporary file from TEMPLATE.
348 The last six characters of TEMPLATE prior to a suffix of length
349 SUFFIXLEN must be "XXXXXX";
350 they are replaced with a string that makes the file name unique.
351 The file is then created, ensuring it didn't exist before.
352 The file is created read-write (mask at least 0600 & ~umask), but it may be
353 world-readable and world-writable (mask 0666 & ~umask), depending on the
354 implementation.
355 Returns the open file descriptor if successful, otherwise -1 and errno
356 set. */
357# if !@HAVE_MKSTEMPS@
358_GL_FUNCDECL_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)
359 _GL_ARG_NONNULL ((1)));
360# endif
361_GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/));
362_GL_CXXALIASWARN (mkstemps);
363#elif defined GNULIB_POSIXCHECK
364# undef mkstemps
365# if HAVE_RAW_DECL_MKSTEMPS
366_GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
367 "use gnulib module mkstemps for portability");
368# endif
369#endif
370
371#if @GNULIB_PTSNAME@
372/* Return the pathname of the pseudo-terminal slave associated with
373 the master FD is open on, or NULL on errors. */
374# if !@HAVE_PTSNAME@
375_GL_FUNCDECL_SYS (ptsname, char *, (int fd));
376# endif
377_GL_CXXALIAS_SYS (ptsname, char *, (int fd));
378_GL_CXXALIASWARN (ptsname);
379#elif defined GNULIB_POSIXCHECK
380# undef ptsname
381# if HAVE_RAW_DECL_PTSNAME
382_GL_WARN_ON_USE (ptsname, "ptsname is not portable - "
383 "use gnulib module ptsname for portability");
384# endif
385#endif
233 386
234#if @GNULIB_PUTENV@ 387#if @GNULIB_PUTENV@
235# if @REPLACE_PUTENV@ 388# if @REPLACE_PUTENV@
236# undef putenv 389# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
237# define putenv rpl_putenv 390# undef putenv
238extern int putenv (char *string); 391# define putenv rpl_putenv
392# endif
393_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1)));
394_GL_CXXALIAS_RPL (putenv, int, (char *string));
395# else
396_GL_CXXALIAS_SYS (putenv, int, (char *string));
239# endif 397# endif
398_GL_CXXALIASWARN (putenv);
240#endif 399#endif
241 400
242 401
243#if @GNULIB_RANDOM_R@ 402#if @GNULIB_RANDOM_R@
244# if !@HAVE_RANDOM_R@ 403# if !@HAVE_RANDOM_R@
245
246# ifndef RAND_MAX 404# ifndef RAND_MAX
247# define RAND_MAX 2147483647 405# define RAND_MAX 2147483647
248# endif 406# endif
407# endif
408#endif
249 409
250int srandom_r (unsigned int seed, struct random_data *rand_state); 410#if @GNULIB_RANDOM_R@
251int initstate_r (unsigned int seed, char *buf, size_t buf_size, 411# if !@HAVE_RANDOM_R@
252 struct random_data *rand_state); 412_GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result)
253int setstate_r (char *arg_state, struct random_data *rand_state); 413 _GL_ARG_NONNULL ((1, 2)));
254int random_r (struct random_data *buf, int32_t *result);
255# endif 414# endif
415_GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result));
416_GL_CXXALIASWARN (random_r);
256#elif defined GNULIB_POSIXCHECK 417#elif defined GNULIB_POSIXCHECK
257# undef random_r 418# undef random_r
258# define random_r(b,r) \ 419# if HAVE_RAW_DECL_RANDOM_R
259 (GL_LINK_WARNING ("random_r is unportable - " \ 420_GL_WARN_ON_USE (random_r, "random_r is unportable - "
260 "use gnulib module random_r for portability"), \ 421 "use gnulib module random_r for portability");
261 random_r (b,r)) 422# endif
262# undef initstate_r 423#endif
263# define initstate_r(s,b,sz,r) \ 424
264 (GL_LINK_WARNING ("initstate_r is unportable - " \ 425#if @GNULIB_RANDOM_R@
265 "use gnulib module random_r for portability"), \ 426# if !@HAVE_RANDOM_R@
266 initstate_r (s,b,sz,r)) 427_GL_FUNCDECL_SYS (srandom_r, int,
428 (unsigned int seed, struct random_data *rand_state)
429 _GL_ARG_NONNULL ((2)));
430# endif
431_GL_CXXALIAS_SYS (srandom_r, int,
432 (unsigned int seed, struct random_data *rand_state));
433_GL_CXXALIASWARN (srandom_r);
434#elif defined GNULIB_POSIXCHECK
267# undef srandom_r 435# undef srandom_r
268# define srandom_r(s,r) \ 436# if HAVE_RAW_DECL_SRANDOM_R
269 (GL_LINK_WARNING ("srandom_r is unportable - " \ 437_GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - "
270 "use gnulib module random_r for portability"), \ 438 "use gnulib module random_r for portability");
271 srandom_r (s,r)) 439# endif
440#endif
441
442#if @GNULIB_RANDOM_R@
443# if !@HAVE_RANDOM_R@
444_GL_FUNCDECL_SYS (initstate_r, int,
445 (unsigned int seed, char *buf, size_t buf_size,
446 struct random_data *rand_state)
447 _GL_ARG_NONNULL ((2, 4)));
448# endif
449_GL_CXXALIAS_SYS (initstate_r, int,
450 (unsigned int seed, char *buf, size_t buf_size,
451 struct random_data *rand_state));
452_GL_CXXALIASWARN (initstate_r);
453#elif defined GNULIB_POSIXCHECK
454# undef initstate_r
455# if HAVE_RAW_DECL_INITSTATE_R
456_GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - "
457 "use gnulib module random_r for portability");
458# endif
459#endif
460
461#if @GNULIB_RANDOM_R@
462# if !@HAVE_RANDOM_R@
463_GL_FUNCDECL_SYS (setstate_r, int,
464 (char *arg_state, struct random_data *rand_state)
465 _GL_ARG_NONNULL ((1, 2)));
466# endif
467_GL_CXXALIAS_SYS (setstate_r, int,
468 (char *arg_state, struct random_data *rand_state));
469_GL_CXXALIASWARN (setstate_r);
470#elif defined GNULIB_POSIXCHECK
272# undef setstate_r 471# undef setstate_r
273# define setstate_r(a,r) \ 472# if HAVE_RAW_DECL_SETSTATE_R
274 (GL_LINK_WARNING ("setstate_r is unportable - " \ 473_GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
275 "use gnulib module random_r for portability"), \ 474 "use gnulib module random_r for portability");
276 setstate_r (a,r)) 475# endif
277#endif 476#endif
278 477
279 478
479#if @GNULIB_REALLOC_POSIX@
480# if !@HAVE_REALLOC_POSIX@
481# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
482# undef realloc
483# define realloc rpl_realloc
484# endif
485_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size));
486_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
487# else
488_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
489# endif
490_GL_CXXALIASWARN (realloc);
491#elif defined GNULIB_POSIXCHECK
492# undef realloc
493/* Assume realloc is always declared. */
494_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
495 "use gnulib module realloc-posix for portability");
496#endif
497
498#if @GNULIB_REALPATH@
499# if @REPLACE_REALPATH@
500# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
501# define realpath rpl_realpath
502# endif
503_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved)
504 _GL_ARG_NONNULL ((1)));
505_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved));
506# else
507# if !@HAVE_REALPATH@
508_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved)
509 _GL_ARG_NONNULL ((1)));
510# endif
511_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved));
512# endif
513_GL_CXXALIASWARN (realpath);
514#elif defined GNULIB_POSIXCHECK
515# undef realpath
516# if HAVE_RAW_DECL_REALPATH
517_GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module "
518 "canonicalize or canonicalize-lgpl for portability");
519# endif
520#endif
521
280#if @GNULIB_RPMATCH@ 522#if @GNULIB_RPMATCH@
281# if !@HAVE_RPMATCH@
282/* Test a user response to a question. 523/* Test a user response to a question.
283 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */ 524 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
284extern int rpmatch (const char *response); 525# if !@HAVE_RPMATCH@
526_GL_FUNCDECL_SYS (rpmatch, int, (const char *response) _GL_ARG_NONNULL ((1)));
285# endif 527# endif
528_GL_CXXALIAS_SYS (rpmatch, int, (const char *response));
529_GL_CXXALIASWARN (rpmatch);
286#elif defined GNULIB_POSIXCHECK 530#elif defined GNULIB_POSIXCHECK
287# undef rpmatch 531# undef rpmatch
288# define rpmatch(r) \ 532# if HAVE_RAW_DECL_RPMATCH
289 (GL_LINK_WARNING ("rpmatch is unportable - " \ 533_GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - "
290 "use gnulib module rpmatch for portability"), \ 534 "use gnulib module rpmatch for portability");
291 rpmatch (r)) 535# endif
292#endif 536#endif
293 537
294
295#if @GNULIB_SETENV@ 538#if @GNULIB_SETENV@
296# if !@HAVE_SETENV@
297/* Set NAME to VALUE in the environment. 539/* Set NAME to VALUE in the environment.
298 If REPLACE is nonzero, overwrite an existing value. */ 540 If REPLACE is nonzero, overwrite an existing value. */
299extern int setenv (const char *name, const char *value, int replace); 541# if @REPLACE_SETENV@
300# endif 542# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
301#endif 543# undef setenv
302 544# define setenv rpl_setenv
303
304#if @GNULIB_UNSETENV@
305# if @HAVE_UNSETENV@
306# if @VOID_UNSETENV@
307/* On some systems, unsetenv() returns void.
308 This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
309# define unsetenv(name) ((unsetenv)(name), 0)
310# endif 545# endif
546_GL_FUNCDECL_RPL (setenv, int,
547 (const char *name, const char *value, int replace)
548 _GL_ARG_NONNULL ((1)));
549_GL_CXXALIAS_RPL (setenv, int,
550 (const char *name, const char *value, int replace));
311# else 551# else
312/* Remove the variable NAME from the environment. */ 552# if !@HAVE_SETENV@
313extern int unsetenv (const char *name); 553_GL_FUNCDECL_SYS (setenv, int,
554 (const char *name, const char *value, int replace)
555 _GL_ARG_NONNULL ((1)));
556# endif
557_GL_CXXALIAS_SYS (setenv, int,
558 (const char *name, const char *value, int replace));
559# endif
560_GL_CXXALIASWARN (setenv);
561#elif defined GNULIB_POSIXCHECK
562# undef setenv
563# if HAVE_RAW_DECL_SETENV
564_GL_WARN_ON_USE (setenv, "setenv is unportable - "
565 "use gnulib module setenv for portability");
314# endif 566# endif
315#endif 567#endif
316 568
317
318#if @GNULIB_STRTOD@ 569#if @GNULIB_STRTOD@
319# if @REPLACE_STRTOD@
320# define strtod rpl_strtod
321# endif
322# if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
323 /* Parse a double from STRING, updating ENDP if appropriate. */ 570 /* Parse a double from STRING, updating ENDP if appropriate. */
324extern double strtod (const char *str, char **endp); 571# if @REPLACE_STRTOD@
572# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
573# define strtod rpl_strtod
574# endif
575_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp)
576 _GL_ARG_NONNULL ((1)));
577_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp));
578# else
579# if !@HAVE_STRTOD@
580_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp)
581 _GL_ARG_NONNULL ((1)));
582# endif
583_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp));
325# endif 584# endif
585_GL_CXXALIASWARN (strtod);
326#elif defined GNULIB_POSIXCHECK 586#elif defined GNULIB_POSIXCHECK
327# undef strtod 587# undef strtod
328# define strtod(s, e) \ 588# if HAVE_RAW_DECL_STRTOD
329 (GL_LINK_WARNING ("strtod is unportable - " \ 589_GL_WARN_ON_USE (strtod, "strtod is unportable - "
330 "use gnulib module strtod for portability"), \ 590 "use gnulib module strtod for portability");
331 strtod (s, e)) 591# endif
332#endif 592#endif
333 593
334
335#if @GNULIB_STRTOLL@ 594#if @GNULIB_STRTOLL@
336# if !@HAVE_STRTOLL@
337/* Parse a signed integer whose textual representation starts at STRING. 595/* Parse a signed integer whose textual representation starts at STRING.
338 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, 596 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
339 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix 597 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
@@ -342,19 +600,23 @@ extern double strtod (const char *str, char **endp);
342 stored in *ENDPTR. 600 stored in *ENDPTR.
343 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set 601 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
344 to ERANGE. */ 602 to ERANGE. */
345extern long long strtoll (const char *string, char **endptr, int base); 603# if !@HAVE_STRTOLL@
604_GL_FUNCDECL_SYS (strtoll, long long,
605 (const char *string, char **endptr, int base)
606 _GL_ARG_NONNULL ((1)));
346# endif 607# endif
608_GL_CXXALIAS_SYS (strtoll, long long,
609 (const char *string, char **endptr, int base));
610_GL_CXXALIASWARN (strtoll);
347#elif defined GNULIB_POSIXCHECK 611#elif defined GNULIB_POSIXCHECK
348# undef strtoll 612# undef strtoll
349# define strtoll(s,e,b) \ 613# if HAVE_RAW_DECL_STRTOLL
350 (GL_LINK_WARNING ("strtoll is unportable - " \ 614_GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
351 "use gnulib module strtoll for portability"), \ 615 "use gnulib module strtoll for portability");
352 strtoll (s, e, b)) 616# endif
353#endif 617#endif
354 618
355
356#if @GNULIB_STRTOULL@ 619#if @GNULIB_STRTOULL@
357# if !@HAVE_STRTOULL@
358/* Parse an unsigned integer whose textual representation starts at STRING. 620/* Parse an unsigned integer whose textual representation starts at STRING.
359 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, 621 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
360 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix 622 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
@@ -363,21 +625,63 @@ extern long long strtoll (const char *string, char **endptr, int base);
363 stored in *ENDPTR. 625 stored in *ENDPTR.
364 Upon overflow, the return value is ULLONG_MAX, and errno is set to 626 Upon overflow, the return value is ULLONG_MAX, and errno is set to
365 ERANGE. */ 627 ERANGE. */
366extern unsigned long long strtoull (const char *string, char **endptr, int base); 628# if !@HAVE_STRTOULL@
629_GL_FUNCDECL_SYS (strtoull, unsigned long long,
630 (const char *string, char **endptr, int base)
631 _GL_ARG_NONNULL ((1)));
367# endif 632# endif
633_GL_CXXALIAS_SYS (strtoull, unsigned long long,
634 (const char *string, char **endptr, int base));
635_GL_CXXALIASWARN (strtoull);
368#elif defined GNULIB_POSIXCHECK 636#elif defined GNULIB_POSIXCHECK
369# undef strtoull 637# undef strtoull
370# define strtoull(s,e,b) \ 638# if HAVE_RAW_DECL_STRTOULL
371 (GL_LINK_WARNING ("strtoull is unportable - " \ 639_GL_WARN_ON_USE (strtoull, "strtoull is unportable - "
372 "use gnulib module strtoull for portability"), \ 640 "use gnulib module strtoull for portability");
373 strtoull (s, e, b)) 641# endif
374#endif 642#endif
375 643
644#if @GNULIB_UNLOCKPT@
645/* Unlock the slave side of the pseudo-terminal whose master side is specified
646 by FD, so that it can be opened. */
647# if !@HAVE_UNLOCKPT@
648_GL_FUNCDECL_SYS (unlockpt, int, (int fd));
649# endif
650_GL_CXXALIAS_SYS (unlockpt, int, (int fd));
651_GL_CXXALIASWARN (unlockpt);
652#elif defined GNULIB_POSIXCHECK
653# undef unlockpt
654# if HAVE_RAW_DECL_UNLOCKPT
655_GL_WARN_ON_USE (ptsname, "unlockpt is not portable - "
656 "use gnulib module unlockpt for portability");
657# endif
658#endif
376 659
377#ifdef __cplusplus 660#if @GNULIB_UNSETENV@
378} 661/* Remove the variable NAME from the environment. */
662# if @REPLACE_UNSETENV@
663# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
664# undef unsetenv
665# define unsetenv rpl_unsetenv
666# endif
667_GL_FUNCDECL_RPL (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1)));
668_GL_CXXALIAS_RPL (unsetenv, int, (const char *name));
669# else
670# if !@HAVE_UNSETENV@
671_GL_FUNCDECL_SYS (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1)));
672# endif
673_GL_CXXALIAS_SYS (unsetenv, int, (const char *name));
674# endif
675_GL_CXXALIASWARN (unsetenv);
676#elif defined GNULIB_POSIXCHECK
677# undef unsetenv
678# if HAVE_RAW_DECL_UNSETENV
679_GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
680 "use gnulib module unsetenv for portability");
681# endif
379#endif 682#endif
380 683
684
381#endif /* _GL_STDLIB_H */ 685#endif /* _GL_STDLIB_H */
382#endif /* _GL_STDLIB_H */ 686#endif /* _GL_STDLIB_H */
383#endif 687#endif
diff --git a/gl/str-two-way.h b/gl/str-two-way.h
new file mode 100644
index 00000000..c08f60ef
--- /dev/null
+++ b/gl/str-two-way.h
@@ -0,0 +1,429 @@
1/* Byte-wise substring search, using the Two-Way algorithm.
2 Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Eric Blake <ebb9@byu.net>, 2008.
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, or (at your option)
9 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 along
17 with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20/* Before including this file, you need to include <config.h> and
21 <string.h>, and define:
22 RESULT_TYPE A macro that expands to the return type.
23 AVAILABLE(h, h_l, j, n_l)
24 A macro that returns nonzero if there are
25 at least N_L bytes left starting at H[J].
26 H is 'unsigned char *', H_L, J, and N_L
27 are 'size_t'; H_L is an lvalue. For
28 NUL-terminated searches, H_L can be
29 modified each iteration to avoid having
30 to compute the end of H up front.
31
32 For case-insensitivity, you may optionally define:
33 CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L
34 characters of P1 and P2 are equal.
35 CANON_ELEMENT(c) A macro that canonicalizes an element right after
36 it has been fetched from one of the two strings.
37 The argument is an 'unsigned char'; the result
38 must be an 'unsigned char' as well.
39
40 This file undefines the macros documented above, and defines
41 LONG_NEEDLE_THRESHOLD.
42*/
43
44#include <limits.h>
45#include <stdint.h>
46
47/* We use the Two-Way string matching algorithm, which guarantees
48 linear complexity with constant space. Additionally, for long
49 needles, we also use a bad character shift table similar to the
50 Boyer-Moore algorithm to achieve improved (potentially sub-linear)
51 performance.
52
53 See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
54 and http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm
55*/
56
57/* Point at which computing a bad-byte shift table is likely to be
58 worthwhile. Small needles should not compute a table, since it
59 adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a
60 speedup no greater than a factor of NEEDLE_LEN. The larger the
61 needle, the better the potential performance gain. On the other
62 hand, on non-POSIX systems with CHAR_BIT larger than eight, the
63 memory required for the table is prohibitive. */
64#if CHAR_BIT < 10
65# define LONG_NEEDLE_THRESHOLD 32U
66#else
67# define LONG_NEEDLE_THRESHOLD SIZE_MAX
68#endif
69
70#ifndef MAX
71# define MAX(a, b) ((a < b) ? (b) : (a))
72#endif
73
74#ifndef CANON_ELEMENT
75# define CANON_ELEMENT(c) c
76#endif
77#ifndef CMP_FUNC
78# define CMP_FUNC memcmp
79#endif
80
81/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
82 Return the index of the first byte in the right half, and set
83 *PERIOD to the global period of the right half.
84
85 The global period of a string is the smallest index (possibly its
86 length) at which all remaining bytes in the string are repetitions
87 of the prefix (the last repetition may be a subset of the prefix).
88
89 When NEEDLE is factored into two halves, a local period is the
90 length of the smallest word that shares a suffix with the left half
91 and shares a prefix with the right half. All factorizations of a
92 non-empty NEEDLE have a local period of at least 1 and no greater
93 than NEEDLE_LEN.
94
95 A critical factorization has the property that the local period
96 equals the global period. All strings have at least one critical
97 factorization with the left half smaller than the global period.
98
99 Given an ordered alphabet, a critical factorization can be computed
100 in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
101 larger of two ordered maximal suffixes. The ordered maximal
102 suffixes are determined by lexicographic comparison of
103 periodicity. */
104static size_t
105critical_factorization (const unsigned char *needle, size_t needle_len,
106 size_t *period)
107{
108 /* Index of last byte of left half, or SIZE_MAX. */
109 size_t max_suffix, max_suffix_rev;
110 size_t j; /* Index into NEEDLE for current candidate suffix. */
111 size_t k; /* Offset into current period. */
112 size_t p; /* Intermediate period. */
113 unsigned char a, b; /* Current comparison bytes. */
114
115 /* Invariants:
116 0 <= j < NEEDLE_LEN - 1
117 -1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
118 min(max_suffix, max_suffix_rev) < global period of NEEDLE
119 1 <= p <= global period of NEEDLE
120 p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
121 1 <= k <= p
122 */
123
124 /* Perform lexicographic search. */
125 max_suffix = SIZE_MAX;
126 j = 0;
127 k = p = 1;
128 while (j + k < needle_len)
129 {
130 a = CANON_ELEMENT (needle[j + k]);
131 b = CANON_ELEMENT (needle[max_suffix + k]);
132 if (a < b)
133 {
134 /* Suffix is smaller, period is entire prefix so far. */
135 j += k;
136 k = 1;
137 p = j - max_suffix;
138 }
139 else if (a == b)
140 {
141 /* Advance through repetition of the current period. */
142 if (k != p)
143 ++k;
144 else
145 {
146 j += p;
147 k = 1;
148 }
149 }
150 else /* b < a */
151 {
152 /* Suffix is larger, start over from current location. */
153 max_suffix = j++;
154 k = p = 1;
155 }
156 }
157 *period = p;
158
159 /* Perform reverse lexicographic search. */
160 max_suffix_rev = SIZE_MAX;
161 j = 0;
162 k = p = 1;
163 while (j + k < needle_len)
164 {
165 a = CANON_ELEMENT (needle[j + k]);
166 b = CANON_ELEMENT (needle[max_suffix_rev + k]);
167 if (b < a)
168 {
169 /* Suffix is smaller, period is entire prefix so far. */
170 j += k;
171 k = 1;
172 p = j - max_suffix_rev;
173 }
174 else if (a == b)
175 {
176 /* Advance through repetition of the current period. */
177 if (k != p)
178 ++k;
179 else
180 {
181 j += p;
182 k = 1;
183 }
184 }
185 else /* a < b */
186 {
187 /* Suffix is larger, start over from current location. */
188 max_suffix_rev = j++;
189 k = p = 1;
190 }
191 }
192
193 /* Choose the longer suffix. Return the first byte of the right
194 half, rather than the last byte of the left half. */
195 if (max_suffix_rev + 1 < max_suffix + 1)
196 return max_suffix + 1;
197 *period = p;
198 return max_suffix_rev + 1;
199}
200
201/* Return the first location of non-empty NEEDLE within HAYSTACK, or
202 NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
203 method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD.
204 Performance is guaranteed to be linear, with an initialization cost
205 of 2 * NEEDLE_LEN comparisons.
206
207 If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
208 most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
209 If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
210 HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
211static RETURN_TYPE
212two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
213 const unsigned char *needle, size_t needle_len)
214{
215 size_t i; /* Index into current byte of NEEDLE. */
216 size_t j; /* Index into current window of HAYSTACK. */
217 size_t period; /* The period of the right half of needle. */
218 size_t suffix; /* The index of the right half of needle. */
219
220 /* Factor the needle into two halves, such that the left half is
221 smaller than the global period, and the right half is
222 periodic (with a period as large as NEEDLE_LEN - suffix). */
223 suffix = critical_factorization (needle, needle_len, &period);
224
225 /* Perform the search. Each iteration compares the right half
226 first. */
227 if (CMP_FUNC (needle, needle + period, suffix) == 0)
228 {
229 /* Entire needle is periodic; a mismatch can only advance by the
230 period, so use memory to avoid rescanning known occurrences
231 of the period. */
232 size_t memory = 0;
233 j = 0;
234 while (AVAILABLE (haystack, haystack_len, j, needle_len))
235 {
236 /* Scan for matches in right half. */
237 i = MAX (suffix, memory);
238 while (i < needle_len && (CANON_ELEMENT (needle[i])
239 == CANON_ELEMENT (haystack[i + j])))
240 ++i;
241 if (needle_len <= i)
242 {
243 /* Scan for matches in left half. */
244 i = suffix - 1;
245 while (memory < i + 1 && (CANON_ELEMENT (needle[i])
246 == CANON_ELEMENT (haystack[i + j])))
247 --i;
248 if (i + 1 < memory + 1)
249 return (RETURN_TYPE) (haystack + j);
250 /* No match, so remember how many repetitions of period
251 on the right half were scanned. */
252 j += period;
253 memory = needle_len - period;
254 }
255 else
256 {
257 j += i - suffix + 1;
258 memory = 0;
259 }
260 }
261 }
262 else
263 {
264 /* The two halves of needle are distinct; no extra memory is
265 required, and any mismatch results in a maximal shift. */
266 period = MAX (suffix, needle_len - suffix) + 1;
267 j = 0;
268 while (AVAILABLE (haystack, haystack_len, j, needle_len))
269 {
270 /* Scan for matches in right half. */
271 i = suffix;
272 while (i < needle_len && (CANON_ELEMENT (needle[i])
273 == CANON_ELEMENT (haystack[i + j])))
274 ++i;
275 if (needle_len <= i)
276 {
277 /* Scan for matches in left half. */
278 i = suffix - 1;
279 while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
280 == CANON_ELEMENT (haystack[i + j])))
281 --i;
282 if (i == SIZE_MAX)
283 return (RETURN_TYPE) (haystack + j);
284 j += period;
285 }
286 else
287 j += i - suffix + 1;
288 }
289 }
290 return NULL;
291}
292
293/* Return the first location of non-empty NEEDLE within HAYSTACK, or
294 NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
295 method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN.
296 Performance is guaranteed to be linear, with an initialization cost
297 of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations.
298
299 If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
300 most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching,
301 and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible.
302 If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
303 HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
304 sublinear performance is not possible. */
305static RETURN_TYPE
306two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
307 const unsigned char *needle, size_t needle_len)
308{
309 size_t i; /* Index into current byte of NEEDLE. */
310 size_t j; /* Index into current window of HAYSTACK. */
311 size_t period; /* The period of the right half of needle. */
312 size_t suffix; /* The index of the right half of needle. */
313 size_t shift_table[1U << CHAR_BIT]; /* See below. */
314
315 /* Factor the needle into two halves, such that the left half is
316 smaller than the global period, and the right half is
317 periodic (with a period as large as NEEDLE_LEN - suffix). */
318 suffix = critical_factorization (needle, needle_len, &period);
319
320 /* Populate shift_table. For each possible byte value c,
321 shift_table[c] is the distance from the last occurrence of c to
322 the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
323 shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */
324 for (i = 0; i < 1U << CHAR_BIT; i++)
325 shift_table[i] = needle_len;
326 for (i = 0; i < needle_len; i++)
327 shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
328
329 /* Perform the search. Each iteration compares the right half
330 first. */
331 if (CMP_FUNC (needle, needle + period, suffix) == 0)
332 {
333 /* Entire needle is periodic; a mismatch can only advance by the
334 period, so use memory to avoid rescanning known occurrences
335 of the period. */
336 size_t memory = 0;
337 size_t shift;
338 j = 0;
339 while (AVAILABLE (haystack, haystack_len, j, needle_len))
340 {
341 /* Check the last byte first; if it does not match, then
342 shift to the next possible match location. */
343 shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
344 if (0 < shift)
345 {
346 if (memory && shift < period)
347 {
348 /* Since needle is periodic, but the last period has
349 a byte out of place, there can be no match until
350 after the mismatch. */
351 shift = needle_len - period;
352 memory = 0;
353 }
354 j += shift;
355 continue;
356 }
357 /* Scan for matches in right half. The last byte has
358 already been matched, by virtue of the shift table. */
359 i = MAX (suffix, memory);
360 while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
361 == CANON_ELEMENT (haystack[i + j])))
362 ++i;
363 if (needle_len - 1 <= i)
364 {
365 /* Scan for matches in left half. */
366 i = suffix - 1;
367 while (memory < i + 1 && (CANON_ELEMENT (needle[i])
368 == CANON_ELEMENT (haystack[i + j])))
369 --i;
370 if (i + 1 < memory + 1)
371 return (RETURN_TYPE) (haystack + j);
372 /* No match, so remember how many repetitions of period
373 on the right half were scanned. */
374 j += period;
375 memory = needle_len - period;
376 }
377 else
378 {
379 j += i - suffix + 1;
380 memory = 0;
381 }
382 }
383 }
384 else
385 {
386 /* The two halves of needle are distinct; no extra memory is
387 required, and any mismatch results in a maximal shift. */
388 size_t shift;
389 period = MAX (suffix, needle_len - suffix) + 1;
390 j = 0;
391 while (AVAILABLE (haystack, haystack_len, j, needle_len))
392 {
393 /* Check the last byte first; if it does not match, then
394 shift to the next possible match location. */
395 shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
396 if (0 < shift)
397 {
398 j += shift;
399 continue;
400 }
401 /* Scan for matches in right half. The last byte has
402 already been matched, by virtue of the shift table. */
403 i = suffix;
404 while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
405 == CANON_ELEMENT (haystack[i + j])))
406 ++i;
407 if (needle_len - 1 <= i)
408 {
409 /* Scan for matches in left half. */
410 i = suffix - 1;
411 while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
412 == CANON_ELEMENT (haystack[i + j])))
413 --i;
414 if (i == SIZE_MAX)
415 return (RETURN_TYPE) (haystack + j);
416 j += period;
417 }
418 else
419 j += i - suffix + 1;
420 }
421 }
422 return NULL;
423}
424
425#undef AVAILABLE
426#undef CANON_ELEMENT
427#undef CMP_FUNC
428#undef MAX
429#undef RETURN_TYPE
diff --git a/gl/strdup.c b/gl/strdup.c
index bebe5c8f..4b1794ec 100644
--- a/gl/strdup.c
+++ b/gl/strdup.c
@@ -1,5 +1,5 @@
1/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006, 2007 Free 1/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006, 2007, 2009,
2 Software Foundation, Inc. 2 2010 Free Software Foundation, Inc.
3 3
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 5
diff --git a/gl/streq.h b/gl/streq.h
index 80df9163..aa65bb8e 100644
--- a/gl/streq.h
+++ b/gl/streq.h
@@ -1,5 +1,5 @@
1/* Optimized string comparison. 1/* Optimized string comparison.
2 Copyright (C) 2001-2002, 2007 Free Software Foundation, Inc. 2 Copyright (C) 2001-2002, 2007, 2009-2010 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify it 4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published 5 under the terms of the GNU General Public License as published
diff --git a/gl/strerror.c b/gl/strerror.c
index 798d8540..b0df7784 100644
--- a/gl/strerror.c
+++ b/gl/strerror.c
@@ -1,6 +1,6 @@
1/* strerror.c --- POSIX compatible system error routine 1/* strerror.c --- POSIX compatible system error routine
2 2
3 Copyright (C) 2007-2009 Free Software Foundation, Inc. 3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -313,7 +313,13 @@ rpl_strerror (int n)
313 break; 313 break;
314# endif 314# endif
315 315
316# if GNULIB_defined_ 316# if GNULIB_defined_ESTALE
317 case ESTALE:
318 msg = "Stale NFS file handle";
319 break;
320# endif
321
322# if GNULIB_defined_ECANCELED
317 case ECANCELED: 323 case ECANCELED:
318 msg = "Operation canceled"; 324 msg = "Operation canceled";
319 break; 325 break;
@@ -328,10 +334,10 @@ rpl_strerror (int n)
328 334
329 if (result == NULL || result[0] == '\0') 335 if (result == NULL || result[0] == '\0')
330 { 336 {
331 static char const fmt[] = "Unknown error (%d)"; 337 static char const fmt[] = "Unknown error (%d)";
332 static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)]; 338 static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)];
333 sprintf (msg_buf, fmt, n); 339 sprintf (msg_buf, fmt, n);
334 return msg_buf; 340 return msg_buf;
335 } 341 }
336 342
337 return result; 343 return result;
diff --git a/gl/string.in.h b/gl/string.in.h
index f021a3ed..eb8d7588 100644
--- a/gl/string.in.h
+++ b/gl/string.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <string.h>. 1/* A GNU-like <string.h>.
2 2
3 Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc. 3 Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -28,6 +28,13 @@
28#ifndef _GL_STRING_H 28#ifndef _GL_STRING_H
29#define _GL_STRING_H 29#define _GL_STRING_H
30 30
31/* NetBSD 5.0 mis-defines NULL. */
32#include <stddef.h>
33
34/* MirBSD defines mbslen as a macro. */
35#if @GNULIB_MBSLEN@ && defined __MirBSD__
36# include <wchar.h>
37#endif
31 38
32#ifndef __attribute__ 39#ifndef __attribute__
33/* This feature is available in gcc versions 2.5 and later. */ 40/* This feature is available in gcc versions 2.5 and later. */
@@ -41,60 +48,132 @@
41#endif 48#endif
42 49
43 50
44/* The definition of GL_LINK_WARNING is copied here. */ 51/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
45 52
46 53/* The definition of _GL_ARG_NONNULL is copied here. */
47#ifdef __cplusplus 54
48extern "C" { 55/* The definition of _GL_WARN_ON_USE is copied here. */
56
57
58/* Return the first instance of C within N bytes of S, or NULL. */
59#if @GNULIB_MEMCHR@
60# if @REPLACE_MEMCHR@
61# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
62# define memchr rpl_memchr
63# endif
64_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
65 __attribute__ ((__pure__))
66 _GL_ARG_NONNULL ((1)));
67_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
68# else
69# if ! @HAVE_MEMCHR@
70_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
71 __attribute__ ((__pure__))
72 _GL_ARG_NONNULL ((1)));
73# endif
74 /* On some systems, this function is defined as an overloaded function:
75 extern "C" { const void * std::memchr (const void *, int, size_t); }
76 extern "C++" { void * std::memchr (void *, int, size_t); } */
77_GL_CXXALIAS_SYS_CAST2 (memchr,
78 void *, (void const *__s, int __c, size_t __n),
79 void const *, (void const *__s, int __c, size_t __n));
80# endif
81# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
82 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
83_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
84_GL_CXXALIASWARN1 (memchr, void const *,
85 (void const *__s, int __c, size_t __n));
86# else
87_GL_CXXALIASWARN (memchr);
88# endif
89#elif defined GNULIB_POSIXCHECK
90# undef memchr
91/* Assume memchr is always declared. */
92_GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
93 "use gnulib module memchr for portability" );
49#endif 94#endif
50 95
51
52/* Return the first occurrence of NEEDLE in HAYSTACK. */ 96/* Return the first occurrence of NEEDLE in HAYSTACK. */
53#if @GNULIB_MEMMEM@ 97#if @GNULIB_MEMMEM@
54# if @REPLACE_MEMMEM@ 98# if @REPLACE_MEMMEM@
55# define memmem rpl_memmem 99# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
56# endif 100# define memmem rpl_memmem
57# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ 101# endif
58extern void *memmem (void const *__haystack, size_t __haystack_len, 102_GL_FUNCDECL_RPL (memmem, void *,
59 void const *__needle, size_t __needle_len) 103 (void const *__haystack, size_t __haystack_len,
60 __attribute__ ((__pure__)); 104 void const *__needle, size_t __needle_len)
105 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
106_GL_CXXALIAS_RPL (memmem, void *,
107 (void const *__haystack, size_t __haystack_len,
108 void const *__needle, size_t __needle_len));
109# else
110# if ! @HAVE_DECL_MEMMEM@
111_GL_FUNCDECL_SYS (memmem, void *,
112 (void const *__haystack, size_t __haystack_len,
113 void const *__needle, size_t __needle_len)
114 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
115# endif
116_GL_CXXALIAS_SYS (memmem, void *,
117 (void const *__haystack, size_t __haystack_len,
118 void const *__needle, size_t __needle_len));
61# endif 119# endif
120_GL_CXXALIASWARN (memmem);
62#elif defined GNULIB_POSIXCHECK 121#elif defined GNULIB_POSIXCHECK
63# undef memmem 122# undef memmem
64# define memmem(a,al,b,bl) \ 123# if HAVE_RAW_DECL_MEMMEM
65 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \ 124_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
66 "use gnulib module memmem-simple for portability, " \ 125 "use gnulib module memmem-simple for portability, "
67 "and module memmem for speed" ), \ 126 "and module memmem for speed" );
68 memmem (a, al, b, bl)) 127# endif
69#endif 128#endif
70 129
71/* Copy N bytes of SRC to DEST, return pointer to bytes after the 130/* Copy N bytes of SRC to DEST, return pointer to bytes after the
72 last written byte. */ 131 last written byte. */
73#if @GNULIB_MEMPCPY@ 132#if @GNULIB_MEMPCPY@
74# if ! @HAVE_MEMPCPY@ 133# if ! @HAVE_MEMPCPY@
75extern void *mempcpy (void *restrict __dest, void const *restrict __src, 134_GL_FUNCDECL_SYS (mempcpy, void *,
76 size_t __n); 135 (void *restrict __dest, void const *restrict __src,
136 size_t __n)
137 _GL_ARG_NONNULL ((1, 2)));
77# endif 138# endif
139_GL_CXXALIAS_SYS (mempcpy, void *,
140 (void *restrict __dest, void const *restrict __src,
141 size_t __n));
142_GL_CXXALIASWARN (mempcpy);
78#elif defined GNULIB_POSIXCHECK 143#elif defined GNULIB_POSIXCHECK
79# undef mempcpy 144# undef mempcpy
80# define mempcpy(a,b,n) \ 145# if HAVE_RAW_DECL_MEMPCPY
81 (GL_LINK_WARNING ("mempcpy is unportable - " \ 146_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
82 "use gnulib module mempcpy for portability"), \ 147 "use gnulib module mempcpy for portability");
83 mempcpy (a, b, n)) 148# endif
84#endif 149#endif
85 150
86/* Search backwards through a block for a byte (specified as an int). */ 151/* Search backwards through a block for a byte (specified as an int). */
87#if @GNULIB_MEMRCHR@ 152#if @GNULIB_MEMRCHR@
88# if ! @HAVE_DECL_MEMRCHR@ 153# if ! @HAVE_DECL_MEMRCHR@
89extern void *memrchr (void const *, int, size_t) 154_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
90 __attribute__ ((__pure__)); 155 __attribute__ ((__pure__))
156 _GL_ARG_NONNULL ((1)));
157# endif
158 /* On some systems, this function is defined as an overloaded function:
159 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
160 extern "C++" { void * std::memrchr (void *, int, size_t); } */
161_GL_CXXALIAS_SYS_CAST2 (memrchr,
162 void *, (void const *, int, size_t),
163 void const *, (void const *, int, size_t));
164# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
165 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
166_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
167_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
168# else
169_GL_CXXALIASWARN (memrchr);
91# endif 170# endif
92#elif defined GNULIB_POSIXCHECK 171#elif defined GNULIB_POSIXCHECK
93# undef memrchr 172# undef memrchr
94# define memrchr(a,b,c) \ 173# if HAVE_RAW_DECL_MEMRCHR
95 (GL_LINK_WARNING ("memrchr is unportable - " \ 174_GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
96 "use gnulib module memrchr for portability"), \ 175 "use gnulib module memrchr for portability");
97 memrchr (a, b, c)) 176# endif
98#endif 177#endif
99 178
100/* Find the first occurrence of C in S. More efficient than 179/* Find the first occurrence of C in S. More efficient than
@@ -102,103 +181,191 @@ extern void *memrchr (void const *, int, size_t)
102 occur within N bytes. */ 181 occur within N bytes. */
103#if @GNULIB_RAWMEMCHR@ 182#if @GNULIB_RAWMEMCHR@
104# if ! @HAVE_RAWMEMCHR@ 183# if ! @HAVE_RAWMEMCHR@
105extern void *rawmemchr (void const *__s, int __c_in) 184_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
106 __attribute__ ((__pure__)); 185 __attribute__ ((__pure__))
186 _GL_ARG_NONNULL ((1)));
187# endif
188 /* On some systems, this function is defined as an overloaded function:
189 extern "C++" { const void * std::rawmemchr (const void *, int); }
190 extern "C++" { void * std::rawmemchr (void *, int); } */
191_GL_CXXALIAS_SYS_CAST2 (rawmemchr,
192 void *, (void const *__s, int __c_in),
193 void const *, (void const *__s, int __c_in));
194# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
195 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
196_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
197_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
198# else
199_GL_CXXALIASWARN (rawmemchr);
107# endif 200# endif
108#elif defined GNULIB_POSIXCHECK 201#elif defined GNULIB_POSIXCHECK
109# undef rawmemchr 202# undef rawmemchr
110# define rawmemchr(a,b) \ 203# if HAVE_RAW_DECL_RAWMEMCHR
111 (GL_LINK_WARNING ("rawmemchr is unportable - " \ 204_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
112 "use gnulib module rawmemchr for portability"), \ 205 "use gnulib module rawmemchr for portability");
113 rawmemchr (a, b)) 206# endif
114#endif 207#endif
115 208
116/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ 209/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
117#if @GNULIB_STPCPY@ 210#if @GNULIB_STPCPY@
118# if ! @HAVE_STPCPY@ 211# if ! @HAVE_STPCPY@
119extern char *stpcpy (char *restrict __dst, char const *restrict __src); 212_GL_FUNCDECL_SYS (stpcpy, char *,
213 (char *restrict __dst, char const *restrict __src)
214 _GL_ARG_NONNULL ((1, 2)));
120# endif 215# endif
216_GL_CXXALIAS_SYS (stpcpy, char *,
217 (char *restrict __dst, char const *restrict __src));
218_GL_CXXALIASWARN (stpcpy);
121#elif defined GNULIB_POSIXCHECK 219#elif defined GNULIB_POSIXCHECK
122# undef stpcpy 220# undef stpcpy
123# define stpcpy(a,b) \ 221# if HAVE_RAW_DECL_STPCPY
124 (GL_LINK_WARNING ("stpcpy is unportable - " \ 222_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
125 "use gnulib module stpcpy for portability"), \ 223 "use gnulib module stpcpy for portability");
126 stpcpy (a, b)) 224# endif
127#endif 225#endif
128 226
129/* Copy no more than N bytes of SRC to DST, returning a pointer past the 227/* Copy no more than N bytes of SRC to DST, returning a pointer past the
130 last non-NUL byte written into DST. */ 228 last non-NUL byte written into DST. */
131#if @GNULIB_STPNCPY@ 229#if @GNULIB_STPNCPY@
132# if ! @HAVE_STPNCPY@ 230# if @REPLACE_STPNCPY@
133# define stpncpy gnu_stpncpy 231# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
134extern char *stpncpy (char *restrict __dst, char const *restrict __src, 232# define stpncpy rpl_stpncpy
135 size_t __n); 233# endif
234_GL_FUNCDECL_RPL (stpncpy, char *,
235 (char *restrict __dst, char const *restrict __src,
236 size_t __n)
237 _GL_ARG_NONNULL ((1, 2)));
238_GL_CXXALIAS_RPL (stpncpy, char *,
239 (char *restrict __dst, char const *restrict __src,
240 size_t __n));
241# else
242# if ! @HAVE_STPNCPY@
243_GL_FUNCDECL_SYS (stpncpy, char *,
244 (char *restrict __dst, char const *restrict __src,
245 size_t __n)
246 _GL_ARG_NONNULL ((1, 2)));
247# endif
248_GL_CXXALIAS_SYS (stpncpy, char *,
249 (char *restrict __dst, char const *restrict __src,
250 size_t __n));
136# endif 251# endif
252_GL_CXXALIASWARN (stpncpy);
137#elif defined GNULIB_POSIXCHECK 253#elif defined GNULIB_POSIXCHECK
138# undef stpncpy 254# undef stpncpy
139# define stpncpy(a,b,n) \ 255# if HAVE_RAW_DECL_STPNCPY
140 (GL_LINK_WARNING ("stpncpy is unportable - " \ 256_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
141 "use gnulib module stpncpy for portability"), \ 257 "use gnulib module stpncpy for portability");
142 stpncpy (a, b, n)) 258# endif
143#endif 259#endif
144 260
145#if defined GNULIB_POSIXCHECK 261#if defined GNULIB_POSIXCHECK
146/* strchr() does not work with multibyte strings if the locale encoding is 262/* strchr() does not work with multibyte strings if the locale encoding is
147 GB18030 and the character to be searched is a digit. */ 263 GB18030 and the character to be searched is a digit. */
148# undef strchr 264# undef strchr
149# define strchr(s,c) \ 265/* Assume strchr is always declared. */
150 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \ 266_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
151 "in some multibyte locales - " \ 267 "in some multibyte locales - "
152 "use mbschr if you care about internationalization"), \ 268 "use mbschr if you care about internationalization");
153 strchr (s, c))
154#endif 269#endif
155 270
156/* Find the first occurrence of C in S or the final NUL byte. */ 271/* Find the first occurrence of C in S or the final NUL byte. */
157#if @GNULIB_STRCHRNUL@ 272#if @GNULIB_STRCHRNUL@
158# if ! @HAVE_STRCHRNUL@ 273# if ! @HAVE_STRCHRNUL@
159extern char *strchrnul (char const *__s, int __c_in) 274_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
160 __attribute__ ((__pure__)); 275 __attribute__ ((__pure__))
276 _GL_ARG_NONNULL ((1)));
277# endif
278 /* On some systems, this function is defined as an overloaded function:
279 extern "C++" { const char * std::strchrnul (const char *, int); }
280 extern "C++" { char * std::strchrnul (char *, int); } */
281_GL_CXXALIAS_SYS_CAST2 (strchrnul,
282 char *, (char const *__s, int __c_in),
283 char const *, (char const *__s, int __c_in));
284# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
285 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
286_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
287_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
288# else
289_GL_CXXALIASWARN (strchrnul);
161# endif 290# endif
162#elif defined GNULIB_POSIXCHECK 291#elif defined GNULIB_POSIXCHECK
163# undef strchrnul 292# undef strchrnul
164# define strchrnul(a,b) \ 293# if HAVE_RAW_DECL_STRCHRNUL
165 (GL_LINK_WARNING ("strchrnul is unportable - " \ 294_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
166 "use gnulib module strchrnul for portability"), \ 295 "use gnulib module strchrnul for portability");
167 strchrnul (a, b)) 296# endif
168#endif 297#endif
169 298
170/* Duplicate S, returning an identical malloc'd string. */ 299/* Duplicate S, returning an identical malloc'd string. */
171#if @GNULIB_STRDUP@ 300#if @GNULIB_STRDUP@
172# if @REPLACE_STRDUP@ 301# if @REPLACE_STRDUP@
173# undef strdup 302# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
174# define strdup rpl_strdup 303# undef strdup
175# endif 304# define strdup rpl_strdup
176# if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@ 305# endif
177extern char *strdup (char const *__s); 306_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
307_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
308# else
309# if !(@HAVE_DECL_STRDUP@ || defined strdup)
310_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
311# endif
312_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
178# endif 313# endif
314_GL_CXXALIASWARN (strdup);
179#elif defined GNULIB_POSIXCHECK 315#elif defined GNULIB_POSIXCHECK
180# undef strdup 316# undef strdup
181# define strdup(a) \ 317# if HAVE_RAW_DECL_STRDUP
182 (GL_LINK_WARNING ("strdup is unportable - " \ 318_GL_WARN_ON_USE (strdup, "strdup is unportable - "
183 "use gnulib module strdup for portability"), \ 319 "use gnulib module strdup for portability");
184 strdup (a)) 320# endif
321#endif
322
323/* Append no more than N characters from SRC onto DEST. */
324#if @GNULIB_STRNCAT@
325# if @REPLACE_STRNCAT@
326# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
327# undef strncat
328# define strncat rpl_strncat
329# endif
330_GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
331 _GL_ARG_NONNULL ((1, 2)));
332_GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
333# else
334_GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
335# endif
336_GL_CXXALIASWARN (strncat);
337#elif defined GNULIB_POSIXCHECK
338# undef strncat
339# if HAVE_RAW_DECL_STRNCAT
340_GL_WARN_ON_USE (strncat, "strncat is unportable - "
341 "use gnulib module strncat for portability");
342# endif
185#endif 343#endif
186 344
187/* Return a newly allocated copy of at most N bytes of STRING. */ 345/* Return a newly allocated copy of at most N bytes of STRING. */
188#if @GNULIB_STRNDUP@ 346#if @GNULIB_STRNDUP@
189# if ! @HAVE_STRNDUP@ 347# if @REPLACE_STRNDUP@
190# undef strndup 348# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191# define strndup rpl_strndup 349# undef strndup
192# endif 350# define strndup rpl_strndup
193# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ 351# endif
194extern char *strndup (char const *__string, size_t __n); 352_GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
353 _GL_ARG_NONNULL ((1)));
354_GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
355# else
356# if ! @HAVE_DECL_STRNDUP@
357_GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
358 _GL_ARG_NONNULL ((1)));
359# endif
360_GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
195# endif 361# endif
362_GL_CXXALIASWARN (strndup);
196#elif defined GNULIB_POSIXCHECK 363#elif defined GNULIB_POSIXCHECK
197# undef strndup 364# undef strndup
198# define strndup(a,n) \ 365# if HAVE_RAW_DECL_STRNDUP
199 (GL_LINK_WARNING ("strndup is unportable - " \ 366_GL_WARN_ON_USE (strndup, "strndup is unportable - "
200 "use gnulib module strndup for portability"), \ 367 "use gnulib module strndup for portability");
201 strndup (a, n)) 368# endif
202#endif 369#endif
203 370
204/* Find the length (number of bytes) of STRING, but scan at most 371/* Find the length (number of bytes) of STRING, but scan at most
@@ -206,15 +373,18 @@ extern char *strndup (char const *__string, size_t __n);
206 return MAXLEN. */ 373 return MAXLEN. */
207#if @GNULIB_STRNLEN@ 374#if @GNULIB_STRNLEN@
208# if ! @HAVE_DECL_STRNLEN@ 375# if ! @HAVE_DECL_STRNLEN@
209extern size_t strnlen (char const *__string, size_t __maxlen) 376_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
210 __attribute__ ((__pure__)); 377 __attribute__ ((__pure__))
378 _GL_ARG_NONNULL ((1)));
211# endif 379# endif
380_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
381_GL_CXXALIASWARN (strnlen);
212#elif defined GNULIB_POSIXCHECK 382#elif defined GNULIB_POSIXCHECK
213# undef strnlen 383# undef strnlen
214# define strnlen(a,n) \ 384# if HAVE_RAW_DECL_STRNLEN
215 (GL_LINK_WARNING ("strnlen is unportable - " \ 385_GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
216 "use gnulib module strnlen for portability"), \ 386 "use gnulib module strnlen for portability");
217 strnlen (a, n)) 387# endif
218#endif 388#endif
219 389
220#if defined GNULIB_POSIXCHECK 390#if defined GNULIB_POSIXCHECK
@@ -223,18 +393,32 @@ extern size_t strnlen (char const *__string, size_t __maxlen)
223 locale encoding is GB18030 and one of the characters to be searched is a 393 locale encoding is GB18030 and one of the characters to be searched is a
224 digit. */ 394 digit. */
225# undef strcspn 395# undef strcspn
226# define strcspn(s,a) \ 396/* Assume strcspn is always declared. */
227 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \ 397_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
228 "in multibyte locales - " \ 398 "in multibyte locales - "
229 "use mbscspn if you care about internationalization"), \ 399 "use mbscspn if you care about internationalization");
230 strcspn (s, a))
231#endif 400#endif
232 401
233/* Find the first occurrence in S of any character in ACCEPT. */ 402/* Find the first occurrence in S of any character in ACCEPT. */
234#if @GNULIB_STRPBRK@ 403#if @GNULIB_STRPBRK@
235# if ! @HAVE_STRPBRK@ 404# if ! @HAVE_STRPBRK@
236extern char *strpbrk (char const *__s, char const *__accept) 405_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
237 __attribute__ ((__pure__)); 406 __attribute__ ((__pure__))
407 _GL_ARG_NONNULL ((1, 2)));
408# endif
409 /* On some systems, this function is defined as an overloaded function:
410 extern "C" { const char * strpbrk (const char *, const char *); }
411 extern "C++" { char * strpbrk (char *, const char *); } */
412_GL_CXXALIAS_SYS_CAST2 (strpbrk,
413 char *, (char const *__s, char const *__accept),
414 const char *, (char const *__s, char const *__accept));
415# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
416 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
417_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
418_GL_CXXALIASWARN1 (strpbrk, char const *,
419 (char const *__s, char const *__accept));
420# else
421_GL_CXXALIASWARN (strpbrk);
238# endif 422# endif
239# if defined GNULIB_POSIXCHECK 423# if defined GNULIB_POSIXCHECK
240/* strpbrk() assumes the second argument is a list of single-byte characters. 424/* strpbrk() assumes the second argument is a list of single-byte characters.
@@ -242,40 +426,36 @@ extern char *strpbrk (char const *__s, char const *__accept)
242 locale encoding is GB18030 and one of the characters to be searched is a 426 locale encoding is GB18030 and one of the characters to be searched is a
243 digit. */ 427 digit. */
244# undef strpbrk 428# undef strpbrk
245# define strpbrk(s,a) \ 429_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
246 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \ 430 "in multibyte locales - "
247 "in multibyte locales - " \ 431 "use mbspbrk if you care about internationalization");
248 "use mbspbrk if you care about internationalization"), \
249 strpbrk (s, a))
250# endif 432# endif
251#elif defined GNULIB_POSIXCHECK 433#elif defined GNULIB_POSIXCHECK
252# undef strpbrk 434# undef strpbrk
253# define strpbrk(s,a) \ 435# if HAVE_RAW_DECL_STRPBRK
254 (GL_LINK_WARNING ("strpbrk is unportable - " \ 436_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
255 "use gnulib module strpbrk for portability"), \ 437 "use gnulib module strpbrk for portability");
256 strpbrk (s, a)) 438# endif
257#endif 439#endif
258 440
259#if defined GNULIB_POSIXCHECK 441#if defined GNULIB_POSIXCHECK
260/* strspn() assumes the second argument is a list of single-byte characters. 442/* strspn() assumes the second argument is a list of single-byte characters.
261 Even in this simple case, it cannot work with multibyte strings. */ 443 Even in this simple case, it cannot work with multibyte strings. */
262# undef strspn 444# undef strspn
263# define strspn(s,a) \ 445/* Assume strspn is always declared. */
264 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \ 446_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
265 "in multibyte locales - " \ 447 "in multibyte locales - "
266 "use mbsspn if you care about internationalization"), \ 448 "use mbsspn if you care about internationalization");
267 strspn (s, a))
268#endif 449#endif
269 450
270#if defined GNULIB_POSIXCHECK 451#if defined GNULIB_POSIXCHECK
271/* strrchr() does not work with multibyte strings if the locale encoding is 452/* strrchr() does not work with multibyte strings if the locale encoding is
272 GB18030 and the character to be searched is a digit. */ 453 GB18030 and the character to be searched is a digit. */
273# undef strrchr 454# undef strrchr
274# define strrchr(s,c) \ 455/* Assume strrchr is always declared. */
275 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \ 456_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
276 "in some multibyte locales - " \ 457 "in some multibyte locales - "
277 "use mbsrchr if you care about internationalization"), \ 458 "use mbsrchr if you care about internationalization");
278 strrchr (s, c))
279#endif 459#endif
280 460
281/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. 461/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
@@ -296,29 +476,51 @@ extern char *strpbrk (char const *__s, char const *__accept)
296 See also strtok_r(). */ 476 See also strtok_r(). */
297#if @GNULIB_STRSEP@ 477#if @GNULIB_STRSEP@
298# if ! @HAVE_STRSEP@ 478# if ! @HAVE_STRSEP@
299extern char *strsep (char **restrict __stringp, char const *restrict __delim); 479_GL_FUNCDECL_SYS (strsep, char *,
480 (char **restrict __stringp, char const *restrict __delim)
481 _GL_ARG_NONNULL ((1, 2)));
300# endif 482# endif
483_GL_CXXALIAS_SYS (strsep, char *,
484 (char **restrict __stringp, char const *restrict __delim));
485_GL_CXXALIASWARN (strsep);
301# if defined GNULIB_POSIXCHECK 486# if defined GNULIB_POSIXCHECK
302# undef strsep 487# undef strsep
303# define strsep(s,d) \ 488_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
304 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \ 489 "in multibyte locales - "
305 "in multibyte locales - " \ 490 "use mbssep if you care about internationalization");
306 "use mbssep if you care about internationalization"), \
307 strsep (s, d))
308# endif 491# endif
309#elif defined GNULIB_POSIXCHECK 492#elif defined GNULIB_POSIXCHECK
310# undef strsep 493# undef strsep
311# define strsep(s,d) \ 494# if HAVE_RAW_DECL_STRSEP
312 (GL_LINK_WARNING ("strsep is unportable - " \ 495_GL_WARN_ON_USE (strsep, "strsep is unportable - "
313 "use gnulib module strsep for portability"), \ 496 "use gnulib module strsep for portability");
314 strsep (s, d)) 497# endif
315#endif 498#endif
316 499
317#if @GNULIB_STRSTR@ 500#if @GNULIB_STRSTR@
318# if @REPLACE_STRSTR@ 501# if @REPLACE_STRSTR@
319# define strstr rpl_strstr 502# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
320char *strstr (const char *haystack, const char *needle) 503# define strstr rpl_strstr
321 __attribute__ ((__pure__)); 504# endif
505_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
506 __attribute__ ((__pure__))
507 _GL_ARG_NONNULL ((1, 2)));
508_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
509# else
510 /* On some systems, this function is defined as an overloaded function:
511 extern "C++" { const char * strstr (const char *, const char *); }
512 extern "C++" { char * strstr (char *, const char *); } */
513_GL_CXXALIAS_SYS_CAST2 (strstr,
514 char *, (const char *haystack, const char *needle),
515 const char *, (const char *haystack, const char *needle));
516# endif
517# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
518 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
519_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
520_GL_CXXALIASWARN1 (strstr, const char *,
521 (const char *haystack, const char *needle));
522# else
523_GL_CXXALIASWARN (strstr);
322# endif 524# endif
323#elif defined GNULIB_POSIXCHECK 525#elif defined GNULIB_POSIXCHECK
324/* strstr() does not work with multibyte strings if the locale encoding is 526/* strstr() does not work with multibyte strings if the locale encoding is
@@ -326,48 +528,70 @@ char *strstr (const char *haystack, const char *needle)
326 POSIX says that it operates on "strings", and "string" in POSIX is defined 528 POSIX says that it operates on "strings", and "string" in POSIX is defined
327 as a sequence of bytes, not of characters. */ 529 as a sequence of bytes, not of characters. */
328# undef strstr 530# undef strstr
329# define strstr(a,b) \ 531/* Assume strstr is always declared. */
330 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \ 532_GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
331 "work correctly on character strings in most " \ 533 "work correctly on character strings in most "
332 "multibyte locales - " \ 534 "multibyte locales - "
333 "use mbsstr if you care about internationalization, " \ 535 "use mbsstr if you care about internationalization, "
334 "or use strstr if you care about speed"), \ 536 "or use strstr if you care about speed");
335 strstr (a, b))
336#endif 537#endif
337 538
338/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive 539/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
339 comparison. */ 540 comparison. */
340#if @GNULIB_STRCASESTR@ 541#if @GNULIB_STRCASESTR@
341# if @REPLACE_STRCASESTR@ 542# if @REPLACE_STRCASESTR@
342# define strcasestr rpl_strcasestr 543# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
544# define strcasestr rpl_strcasestr
545# endif
546_GL_FUNCDECL_RPL (strcasestr, char *,
547 (const char *haystack, const char *needle)
548 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
549_GL_CXXALIAS_RPL (strcasestr, char *,
550 (const char *haystack, const char *needle));
551# else
552# if ! @HAVE_STRCASESTR@
553_GL_FUNCDECL_SYS (strcasestr, char *,
554 (const char *haystack, const char *needle)
555 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
556# endif
557 /* On some systems, this function is defined as an overloaded function:
558 extern "C++" { const char * strcasestr (const char *, const char *); }
559 extern "C++" { char * strcasestr (char *, const char *); } */
560_GL_CXXALIAS_SYS_CAST2 (strcasestr,
561 char *, (const char *haystack, const char *needle),
562 const char *, (const char *haystack, const char *needle));
343# endif 563# endif
344# if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@ 564# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
345extern char *strcasestr (const char *haystack, const char *needle) 565 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
346 __attribute__ ((__pure__)); 566_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
567_GL_CXXALIASWARN1 (strcasestr, const char *,
568 (const char *haystack, const char *needle));
569# else
570_GL_CXXALIASWARN (strcasestr);
347# endif 571# endif
348#elif defined GNULIB_POSIXCHECK 572#elif defined GNULIB_POSIXCHECK
349/* strcasestr() does not work with multibyte strings: 573/* strcasestr() does not work with multibyte strings:
350 It is a glibc extension, and glibc implements it only for unibyte 574 It is a glibc extension, and glibc implements it only for unibyte
351 locales. */ 575 locales. */
352# undef strcasestr 576# undef strcasestr
353# define strcasestr(a,b) \ 577# if HAVE_RAW_DECL_STRCASESTR
354 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \ 578_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
355 "in multibyte locales - " \ 579 "strings in multibyte locales - "
356 "use mbscasestr if you care about " \ 580 "use mbscasestr if you care about "
357 "internationalization, or use c-strcasestr if you want " \ 581 "internationalization, or use c-strcasestr if you want "
358 "a locale independent function"), \ 582 "a locale independent function");
359 strcasestr (a, b)) 583# endif
360#endif 584#endif
361 585
362/* Parse S into tokens separated by characters in DELIM. 586/* Parse S into tokens separated by characters in DELIM.
363 If S is NULL, the saved pointer in SAVE_PTR is used as 587 If S is NULL, the saved pointer in SAVE_PTR is used as
364 the next starting point. For example: 588 the next starting point. For example:
365 char s[] = "-abc-=-def"; 589 char s[] = "-abc-=-def";
366 char *sp; 590 char *sp;
367 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" 591 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
368 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL 592 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
369 x = strtok_r(NULL, "=", &sp); // x = NULL 593 x = strtok_r(NULL, "=", &sp); // x = NULL
370 // s = "abc\0-def\0" 594 // s = "abc\0-def\0"
371 595
372 This is a variant of strtok() that is multithread-safe. 596 This is a variant of strtok() that is multithread-safe.
373 597
@@ -382,24 +606,44 @@ extern char *strcasestr (const char *haystack, const char *needle)
382 606
383 See also strsep(). */ 607 See also strsep(). */
384#if @GNULIB_STRTOK_R@ 608#if @GNULIB_STRTOK_R@
385# if ! @HAVE_DECL_STRTOK_R@ 609# if @REPLACE_STRTOK_R@
386extern char *strtok_r (char *restrict s, char const *restrict delim, 610# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
387 char **restrict save_ptr); 611# undef strtok_r
612# define strtok_r rpl_strtok_r
613# endif
614_GL_FUNCDECL_RPL (strtok_r, char *,
615 (char *restrict s, char const *restrict delim,
616 char **restrict save_ptr)
617 _GL_ARG_NONNULL ((2, 3)));
618_GL_CXXALIAS_RPL (strtok_r, char *,
619 (char *restrict s, char const *restrict delim,
620 char **restrict save_ptr));
621# else
622# if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
623# undef strtok_r
624# endif
625# if ! @HAVE_DECL_STRTOK_R@
626_GL_FUNCDECL_SYS (strtok_r, char *,
627 (char *restrict s, char const *restrict delim,
628 char **restrict save_ptr)
629 _GL_ARG_NONNULL ((2, 3)));
630# endif
631_GL_CXXALIAS_SYS (strtok_r, char *,
632 (char *restrict s, char const *restrict delim,
633 char **restrict save_ptr));
388# endif 634# endif
635_GL_CXXALIASWARN (strtok_r);
389# if defined GNULIB_POSIXCHECK 636# if defined GNULIB_POSIXCHECK
390# undef strtok_r 637_GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
391# define strtok_r(s,d,p) \ 638 "strings in multibyte locales - "
392 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \ 639 "use mbstok_r if you care about internationalization");
393 "in multibyte locales - " \
394 "use mbstok_r if you care about internationalization"), \
395 strtok_r (s, d, p))
396# endif 640# endif
397#elif defined GNULIB_POSIXCHECK 641#elif defined GNULIB_POSIXCHECK
398# undef strtok_r 642# undef strtok_r
399# define strtok_r(s,d,p) \ 643# if HAVE_RAW_DECL_STRTOK_R
400 (GL_LINK_WARNING ("strtok_r is unportable - " \ 644_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
401 "use gnulib module strtok_r for portability"), \ 645 "use gnulib module strtok_r for portability");
402 strtok_r (s, d, p)) 646# endif
403#endif 647#endif
404 648
405 649
@@ -409,13 +653,27 @@ extern char *strtok_r (char *restrict s, char const *restrict delim,
409#if @GNULIB_MBSLEN@ 653#if @GNULIB_MBSLEN@
410/* Return the number of multibyte characters in the character string STRING. 654/* Return the number of multibyte characters in the character string STRING.
411 This considers multibyte characters, unlike strlen, which counts bytes. */ 655 This considers multibyte characters, unlike strlen, which counts bytes. */
412extern size_t mbslen (const char *string); 656# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
657# undef mbslen
658# endif
659# if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
660# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
661# define mbslen rpl_mbslen
662# endif
663_GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
664_GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
665# else
666_GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
667_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
668# endif
669_GL_CXXALIASWARN (mbslen);
413#endif 670#endif
414 671
415#if @GNULIB_MBSNLEN@ 672#if @GNULIB_MBSNLEN@
416/* Return the number of multibyte characters in the character string starting 673/* Return the number of multibyte characters in the character string starting
417 at STRING and ending at STRING + LEN. */ 674 at STRING and ending at STRING + LEN. */
418extern size_t mbsnlen (const char *string, size_t len); 675_GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
676 _GL_ARG_NONNULL ((1));
419#endif 677#endif
420 678
421#if @GNULIB_MBSCHR@ 679#if @GNULIB_MBSCHR@
@@ -423,8 +681,19 @@ extern size_t mbsnlen (const char *string, size_t len);
423 and return a pointer to it. Return NULL if C is not found in STRING. 681 and return a pointer to it. Return NULL if C is not found in STRING.
424 Unlike strchr(), this function works correctly in multibyte locales with 682 Unlike strchr(), this function works correctly in multibyte locales with
425 encodings such as GB18030. */ 683 encodings such as GB18030. */
426# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ 684# if defined __hpux
427extern char * mbschr (const char *string, int c); 685# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
686# define mbschr rpl_mbschr /* avoid collision with HP-UX function */
687# endif
688_GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
689 _GL_ARG_NONNULL ((1)));
690_GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
691# else
692_GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
693 _GL_ARG_NONNULL ((1)));
694_GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
695# endif
696_GL_CXXALIASWARN (mbschr);
428#endif 697#endif
429 698
430#if @GNULIB_MBSRCHR@ 699#if @GNULIB_MBSRCHR@
@@ -432,8 +701,19 @@ extern char * mbschr (const char *string, int c);
432 and return a pointer to it. Return NULL if C is not found in STRING. 701 and return a pointer to it. Return NULL if C is not found in STRING.
433 Unlike strrchr(), this function works correctly in multibyte locales with 702 Unlike strrchr(), this function works correctly in multibyte locales with
434 encodings such as GB18030. */ 703 encodings such as GB18030. */
435# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ 704# if defined __hpux
436extern char * mbsrchr (const char *string, int c); 705# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
706# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
707# endif
708_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
709 _GL_ARG_NONNULL ((1)));
710_GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
711# else
712_GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
713 _GL_ARG_NONNULL ((1)));
714_GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
715# endif
716_GL_CXXALIASWARN (mbsrchr);
437#endif 717#endif
438 718
439#if @GNULIB_MBSSTR@ 719#if @GNULIB_MBSSTR@
@@ -441,7 +721,8 @@ extern char * mbsrchr (const char *string, int c);
441 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. 721 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
442 Unlike strstr(), this function works correctly in multibyte locales with 722 Unlike strstr(), this function works correctly in multibyte locales with
443 encodings different from UTF-8. */ 723 encodings different from UTF-8. */
444extern char * mbsstr (const char *haystack, const char *needle); 724_GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
725 _GL_ARG_NONNULL ((1, 2));
445#endif 726#endif
446 727
447#if @GNULIB_MBSCASECMP@ 728#if @GNULIB_MBSCASECMP@
@@ -451,7 +732,8 @@ extern char * mbsstr (const char *haystack, const char *needle);
451 Note: This function may, in multibyte locales, return 0 for strings of 732 Note: This function may, in multibyte locales, return 0 for strings of
452 different lengths! 733 different lengths!
453 Unlike strcasecmp(), this function works correctly in multibyte locales. */ 734 Unlike strcasecmp(), this function works correctly in multibyte locales. */
454extern int mbscasecmp (const char *s1, const char *s2); 735_GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
736 _GL_ARG_NONNULL ((1, 2));
455#endif 737#endif
456 738
457#if @GNULIB_MBSNCASECMP@ 739#if @GNULIB_MBSNCASECMP@
@@ -464,7 +746,8 @@ extern int mbscasecmp (const char *s1, const char *s2);
464 of different lengths! 746 of different lengths!
465 Unlike strncasecmp(), this function works correctly in multibyte locales. 747 Unlike strncasecmp(), this function works correctly in multibyte locales.
466 But beware that N is not a byte count but a character count! */ 748 But beware that N is not a byte count but a character count! */
467extern int mbsncasecmp (const char *s1, const char *s2, size_t n); 749_GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
750 _GL_ARG_NONNULL ((1, 2));
468#endif 751#endif
469 752
470#if @GNULIB_MBSPCASECMP@ 753#if @GNULIB_MBSPCASECMP@
@@ -477,7 +760,8 @@ extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
477 smaller length than PREFIX! 760 smaller length than PREFIX!
478 Unlike strncasecmp(), this function works correctly in multibyte 761 Unlike strncasecmp(), this function works correctly in multibyte
479 locales. */ 762 locales. */
480extern char * mbspcasecmp (const char *string, const char *prefix); 763_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
764 _GL_ARG_NONNULL ((1, 2));
481#endif 765#endif
482 766
483#if @GNULIB_MBSCASESTR@ 767#if @GNULIB_MBSCASESTR@
@@ -486,7 +770,8 @@ extern char * mbspcasecmp (const char *string, const char *prefix);
486 Note: This function may, in multibyte locales, return success even if 770 Note: This function may, in multibyte locales, return success even if
487 strlen (haystack) < strlen (needle) ! 771 strlen (haystack) < strlen (needle) !
488 Unlike strcasestr(), this function works correctly in multibyte locales. */ 772 Unlike strcasestr(), this function works correctly in multibyte locales. */
489extern char * mbscasestr (const char *haystack, const char *needle); 773_GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
774 _GL_ARG_NONNULL ((1, 2));
490#endif 775#endif
491 776
492#if @GNULIB_MBSCSPN@ 777#if @GNULIB_MBSCSPN@
@@ -495,7 +780,8 @@ extern char * mbscasestr (const char *haystack, const char *needle);
495 beginning of the string to this occurrence, or to the end of the string 780 beginning of the string to this occurrence, or to the end of the string
496 if none exists. 781 if none exists.
497 Unlike strcspn(), this function works correctly in multibyte locales. */ 782 Unlike strcspn(), this function works correctly in multibyte locales. */
498extern size_t mbscspn (const char *string, const char *accept); 783_GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
784 _GL_ARG_NONNULL ((1, 2));
499#endif 785#endif
500 786
501#if @GNULIB_MBSPBRK@ 787#if @GNULIB_MBSPBRK@
@@ -503,8 +789,19 @@ extern size_t mbscspn (const char *string, const char *accept);
503 in the character string ACCEPT. Return the pointer to it, or NULL if none 789 in the character string ACCEPT. Return the pointer to it, or NULL if none
504 exists. 790 exists.
505 Unlike strpbrk(), this function works correctly in multibyte locales. */ 791 Unlike strpbrk(), this function works correctly in multibyte locales. */
506# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ 792# if defined __hpux
507extern char * mbspbrk (const char *string, const char *accept); 793# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
794# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
795# endif
796_GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
797 _GL_ARG_NONNULL ((1, 2)));
798_GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
799# else
800_GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
801 _GL_ARG_NONNULL ((1, 2)));
802_GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
803# endif
804_GL_CXXALIASWARN (mbspbrk);
508#endif 805#endif
509 806
510#if @GNULIB_MBSSPN@ 807#if @GNULIB_MBSSPN@
@@ -513,7 +810,8 @@ extern char * mbspbrk (const char *string, const char *accept);
513 beginning of the string to this occurrence, or to the end of the string 810 beginning of the string to this occurrence, or to the end of the string
514 if none exists. 811 if none exists.
515 Unlike strspn(), this function works correctly in multibyte locales. */ 812 Unlike strspn(), this function works correctly in multibyte locales. */
516extern size_t mbsspn (const char *string, const char *reject); 813_GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
814 _GL_ARG_NONNULL ((1, 2));
517#endif 815#endif
518 816
519#if @GNULIB_MBSSEP@ 817#if @GNULIB_MBSSEP@
@@ -531,7 +829,8 @@ extern size_t mbsspn (const char *string, const char *reject);
531 Caveat: The identity of the delimiting character is lost. 829 Caveat: The identity of the delimiting character is lost.
532 830
533 See also mbstok_r(). */ 831 See also mbstok_r(). */
534extern char * mbssep (char **stringp, const char *delim); 832_GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
833 _GL_ARG_NONNULL ((1, 2));
535#endif 834#endif
536 835
537#if @GNULIB_MBSTOK_R@ 836#if @GNULIB_MBSTOK_R@
@@ -539,67 +838,81 @@ extern char * mbssep (char **stringp, const char *delim);
539 the character string DELIM. 838 the character string DELIM.
540 If STRING is NULL, the saved pointer in SAVE_PTR is used as 839 If STRING is NULL, the saved pointer in SAVE_PTR is used as
541 the next starting point. For example: 840 the next starting point. For example:
542 char s[] = "-abc-=-def"; 841 char s[] = "-abc-=-def";
543 char *sp; 842 char *sp;
544 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" 843 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
545 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL 844 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
546 x = mbstok_r(NULL, "=", &sp); // x = NULL 845 x = mbstok_r(NULL, "=", &sp); // x = NULL
547 // s = "abc\0-def\0" 846 // s = "abc\0-def\0"
548 847
549 Caveat: It modifies the original string. 848 Caveat: It modifies the original string.
550 Caveat: These functions cannot be used on constant strings. 849 Caveat: These functions cannot be used on constant strings.
551 Caveat: The identity of the delimiting character is lost. 850 Caveat: The identity of the delimiting character is lost.
552 851
553 See also mbssep(). */ 852 See also mbssep(). */
554extern char * mbstok_r (char *string, const char *delim, char **save_ptr); 853_GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
854 _GL_ARG_NONNULL ((2, 3));
555#endif 855#endif
556 856
557/* Map any int, typically from errno, into an error message. */ 857/* Map any int, typically from errno, into an error message. */
558#if @GNULIB_STRERROR@ 858#if @GNULIB_STRERROR@
559# if @REPLACE_STRERROR@ 859# if @REPLACE_STRERROR@
560# undef strerror 860# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
561# define strerror rpl_strerror 861# undef strerror
562extern char *strerror (int); 862# define strerror rpl_strerror
863# endif
864_GL_FUNCDECL_RPL (strerror, char *, (int));
865_GL_CXXALIAS_RPL (strerror, char *, (int));
866# else
867_GL_CXXALIAS_SYS (strerror, char *, (int));
563# endif 868# endif
869_GL_CXXALIASWARN (strerror);
564#elif defined GNULIB_POSIXCHECK 870#elif defined GNULIB_POSIXCHECK
565# undef strerror 871# undef strerror
566# define strerror(e) \ 872/* Assume strerror is always declared. */
567 (GL_LINK_WARNING ("strerror is unportable - " \ 873_GL_WARN_ON_USE (strerror, "strerror is unportable - "
568 "use gnulib module strerror to guarantee non-NULL result"), \ 874 "use gnulib module strerror to guarantee non-NULL result");
569 strerror (e))
570#endif 875#endif
571 876
572#if @GNULIB_STRSIGNAL@ 877#if @GNULIB_STRSIGNAL@
573# if @REPLACE_STRSIGNAL@ 878# if @REPLACE_STRSIGNAL@
574# define strsignal rpl_strsignal 879# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
575# endif 880# define strsignal rpl_strsignal
576# if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@ 881# endif
577extern char *strsignal (int __sig); 882_GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
883_GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
884# else
885# if ! @HAVE_DECL_STRSIGNAL@
886_GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
887# endif
888/* Need to cast, because on Cygwin 1.5.x systems, the return type is
889 'const char *'. */
890_GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
578# endif 891# endif
892_GL_CXXALIASWARN (strsignal);
579#elif defined GNULIB_POSIXCHECK 893#elif defined GNULIB_POSIXCHECK
580# undef strsignal 894# undef strsignal
581# define strsignal(a) \ 895# if HAVE_RAW_DECL_STRSIGNAL
582 (GL_LINK_WARNING ("strsignal is unportable - " \ 896_GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
583 "use gnulib module strsignal for portability"), \ 897 "use gnulib module strsignal for portability");
584 strsignal (a)) 898# endif
585#endif 899#endif
586 900
587#if @GNULIB_STRVERSCMP@ 901#if @GNULIB_STRVERSCMP@
588# if !@HAVE_STRVERSCMP@ 902# if !@HAVE_STRVERSCMP@
589extern int strverscmp (const char *, const char *); 903_GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
904 _GL_ARG_NONNULL ((1, 2)));
590# endif 905# endif
906_GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
907_GL_CXXALIASWARN (strverscmp);
591#elif defined GNULIB_POSIXCHECK 908#elif defined GNULIB_POSIXCHECK
592# undef strverscmp 909# undef strverscmp
593# define strverscmp(a, b) \ 910# if HAVE_RAW_DECL_STRVERSCMP
594 (GL_LINK_WARNING ("strverscmp is unportable - " \ 911_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
595 "use gnulib module strverscmp for portability"), \ 912 "use gnulib module strverscmp for portability");
596 strverscmp (a, b)) 913# endif
597#endif 914#endif
598 915
599 916
600#ifdef __cplusplus
601}
602#endif
603
604#endif /* _GL_STRING_H */ 917#endif /* _GL_STRING_H */
605#endif /* _GL_STRING_H */ 918#endif /* _GL_STRING_H */
diff --git a/gl/stripslash.c b/gl/stripslash.c
index 40844102..3a5996fd 100644
--- a/gl/stripslash.c
+++ b/gl/stripslash.c
@@ -1,6 +1,7 @@
1/* stripslash.c -- remove redundant trailing slashes from a file name 1/* stripslash.c -- remove redundant trailing slashes from a file name
2 2
3 Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc. 3 Copyright (C) 1990, 2001, 2003-2006, 2009-2010 Free Software Foundation,
4 Inc.
4 5
5 This program is free software: you can redistribute it and/or modify 6 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 it under the terms of the GNU General Public License as published by
diff --git a/gl/strndup.c b/gl/strndup.c
index 507e9c06..3de3dbc5 100644
--- a/gl/strndup.c
+++ b/gl/strndup.c
@@ -1,7 +1,7 @@
1/* A replacement function, for systems that lack strndup. 1/* A replacement function, for systems that lack strndup.
2 2
3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007 3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
4 Free Software Foundation, Inc. 4 2010 Free Software Foundation, Inc.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
diff --git a/gl/strnlen.c b/gl/strnlen.c
index 93d1ac14..f1ec356d 100644
--- a/gl/strnlen.c
+++ b/gl/strnlen.c
@@ -1,5 +1,5 @@
1/* Find the length of STRING, but scan at most MAXLEN characters. 1/* Find the length of STRING, but scan at most MAXLEN characters.
2 Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. 2 Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3 Written by Simon Josefsson. 3 Written by Simon Josefsson.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
diff --git a/gl/strstr.c b/gl/strstr.c
new file mode 100644
index 00000000..ae184ff7
--- /dev/null
+++ b/gl/strstr.c
@@ -0,0 +1,83 @@
1/* Copyright (C) 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000, 2004, 2007,
2 2008, 2009, 2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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, or (at your option)
8 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 along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19/* This particular implementation was written by Eric Blake, 2008. */
20
21#ifndef _LIBC
22# include <config.h>
23#endif
24
25/* Specification of strstr. */
26#include <string.h>
27
28#include <stdbool.h>
29
30#ifndef _LIBC
31# define __builtin_expect(expr, val) (expr)
32#endif
33
34#define RETURN_TYPE char *
35#define AVAILABLE(h, h_l, j, n_l) \
36 (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
37 && ((h_l) = (j) + (n_l)))
38#include "str-two-way.h"
39
40/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK
41 if NEEDLE is empty, otherwise NULL if NEEDLE is not found in
42 HAYSTACK. */
43char *
44strstr (const char *haystack_start, const char *needle_start)
45{
46 const char *haystack = haystack_start;
47 const char *needle = needle_start;
48 size_t needle_len; /* Length of NEEDLE. */
49 size_t haystack_len; /* Known minimum length of HAYSTACK. */
50 bool ok = true; /* True if NEEDLE is prefix of HAYSTACK. */
51
52 /* Determine length of NEEDLE, and in the process, make sure
53 HAYSTACK is at least as long (no point processing all of a long
54 NEEDLE if HAYSTACK is too short). */
55 while (*haystack && *needle)
56 ok &= *haystack++ == *needle++;
57 if (*needle)
58 return NULL;
59 if (ok)
60 return (char *) haystack_start;
61
62 /* Reduce the size of haystack using strchr, since it has a smaller
63 linear coefficient than the Two-Way algorithm. */
64 needle_len = needle - needle_start;
65 haystack = strchr (haystack_start + 1, *needle_start);
66 if (!haystack || __builtin_expect (needle_len == 1, 0))
67 return (char *) haystack;
68 needle -= needle_len;
69 haystack_len = (haystack > haystack_start + needle_len ? 1
70 : needle_len + haystack_start - haystack);
71
72 /* Perform the search. Abstract memory is considered to be an array
73 of 'unsigned char' values, not an array of 'char' values. See
74 ISO C 99 section 6.2.6.1. */
75 if (needle_len < LONG_NEEDLE_THRESHOLD)
76 return two_way_short_needle ((const unsigned char *) haystack,
77 haystack_len,
78 (const unsigned char *) needle, needle_len);
79 return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
80 (const unsigned char *) needle, needle_len);
81}
82
83#undef LONG_NEEDLE_THRESHOLD
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index dadd56ac..fc105e63 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -1,6 +1,6 @@
1/* Provide a sys/socket header file for systems lacking it (read: MinGW) 1/* Provide a sys/socket header file for systems lacking it (read: MinGW)
2 and for systems where it is incomplete. 2 and for systems where it is incomplete.
3 Copyright (C) 2005-2009 Free Software Foundation, Inc. 3 Copyright (C) 2005-2010 Free Software Foundation, Inc.
4 Written by Simon Josefsson. 4 Written by Simon Josefsson.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
@@ -23,13 +23,27 @@
23 It is intended to provide definitions and prototypes needed by an 23 It is intended to provide definitions and prototypes needed by an
24 application. */ 24 application. */
25 25
26#if __GNUC__ >= 3
27@PRAGMA_SYSTEM_HEADER@
28#endif
29
30#if defined _GL_ALREADY_INCLUDING_SYS_SOCKET_H
31/* Special invocation convention:
32 - On Cygwin 1.5.x we have a sequence of nested includes
33 <sys/socket.h> -> <cygwin/socket.h> -> <asm/socket.h> -> <cygwin/if.h>,
34 and the latter includes <sys/socket.h>. In this situation, the functions
35 are not yet declared, therefore we cannot provide the C++ aliases. */
36
37#@INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
38
39#else
40/* Normal invocation convention. */
41
26#ifndef _GL_SYS_SOCKET_H 42#ifndef _GL_SYS_SOCKET_H
27 43
28#if @HAVE_SYS_SOCKET_H@ 44#if @HAVE_SYS_SOCKET_H@
29 45
30# if __GNUC__ >= 3 46# define _GL_ALREADY_INCLUDING_SYS_SOCKET_H
31@PRAGMA_SYSTEM_HEADER@
32# endif
33 47
34/* On many platforms, <sys/socket.h> assumes prior inclusion of 48/* On many platforms, <sys/socket.h> assumes prior inclusion of
35 <sys/types.h>. */ 49 <sys/types.h>. */
@@ -38,11 +52,23 @@
38/* The include_next requires a split double-inclusion guard. */ 52/* The include_next requires a split double-inclusion guard. */
39# @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@ 53# @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
40 54
55# undef _GL_ALREADY_INCLUDING_SYS_SOCKET_H
56
41#endif 57#endif
42 58
43#ifndef _GL_SYS_SOCKET_H 59#ifndef _GL_SYS_SOCKET_H
44#define _GL_SYS_SOCKET_H 60#define _GL_SYS_SOCKET_H
45 61
62/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
63
64/* The definition of _GL_ARG_NONNULL is copied here. */
65
66/* The definition of _GL_WARN_ON_USE is copied here. */
67
68#if !@HAVE_SA_FAMILY_T@
69typedef unsigned short sa_family_t;
70#endif
71
46#if !@HAVE_STRUCT_SOCKADDR_STORAGE@ 72#if !@HAVE_STRUCT_SOCKADDR_STORAGE@
47# include <alignof.h> 73# include <alignof.h>
48/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on 74/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
@@ -50,10 +76,10 @@
50# define __ss_aligntype unsigned long int 76# define __ss_aligntype unsigned long int
51# define _SS_SIZE 256 77# define _SS_SIZE 256
52# define _SS_PADSIZE \ 78# define _SS_PADSIZE \
53 (_SS_SIZE - ((sizeof (sa_family_t) >= alignof (__ss_aligntype) \ 79 (_SS_SIZE - ((sizeof (sa_family_t) >= alignof (__ss_aligntype) \
54 ? sizeof (sa_family_t) \ 80 ? sizeof (sa_family_t) \
55 : alignof (__ss_aligntype)) \ 81 : alignof (__ss_aligntype)) \
56 + sizeof (__ss_aligntype))) 82 + sizeof (__ss_aligntype)))
57 83
58struct sockaddr_storage 84struct sockaddr_storage
59{ 85{
@@ -120,8 +146,6 @@ struct sockaddr_storage
120# define SHUT_RDWR SD_BOTH 146# define SHUT_RDWR SD_BOTH
121# endif 147# endif
122 148
123/* The definition of GL_LINK_WARNING is copied here. */
124
125# if @HAVE_WINSOCK2_H@ 149# if @HAVE_WINSOCK2_H@
126/* Include headers needed by the emulation code. */ 150/* Include headers needed by the emulation code. */
127# include <sys/types.h> 151# include <sys/types.h>
@@ -131,11 +155,9 @@ typedef int socklen_t;
131 155
132# endif 156# endif
133 157
134# ifdef __cplusplus 158#endif
135extern "C" {
136# endif
137 159
138# if @HAVE_WINSOCK2_H@ 160#if @HAVE_WINSOCK2_H@
139 161
140/* Re-define FD_ISSET to avoid a WSA call while we are not using 162/* Re-define FD_ISSET to avoid a WSA call while we are not using
141 network sockets. */ 163 network sockets. */
@@ -153,271 +175,454 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
153 return 0; 175 return 0;
154} 176}
155 177
156# undef FD_ISSET 178# undef FD_ISSET
157# define FD_ISSET(fd, set) rpl_fd_isset(fd, set) 179# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
158 180
159# endif 181#endif
160 182
161/* Wrap everything else to use libc file descriptors for sockets. */ 183/* Wrap everything else to use libc file descriptors for sockets. */
162 184
163# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H 185#if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
186# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
164# undef close 187# undef close
165# define close close_used_without_including_unistd_h 188# define close close_used_without_including_unistd_h
189# else
190 _GL_WARN_ON_USE (close,
191 "close() used without including <unistd.h>");
166# endif 192# endif
193#endif
167 194
168# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H 195#if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
196# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
169# undef gethostname 197# undef gethostname
170# define gethostname gethostname_used_without_including_unistd_h 198# define gethostname gethostname_used_without_including_unistd_h
199# else
200 _GL_WARN_ON_USE (gethostname,
201 "gethostname() used without including <unistd.h>");
171# endif 202# endif
203#endif
172 204
173# if @GNULIB_SOCKET@ 205#if @GNULIB_SOCKET@
174# if @HAVE_WINSOCK2_H@ 206# if @HAVE_WINSOCK2_H@
207# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
175# undef socket 208# undef socket
176# define socket rpl_socket 209# define socket rpl_socket
177extern int rpl_socket (int, int, int protocol);
178# endif 210# endif
179# elif @HAVE_WINSOCK2_H@ 211_GL_FUNCDECL_RPL (socket, int, (int domain, int type, int protocol));
180# undef socket 212_GL_CXXALIAS_RPL (socket, int, (int domain, int type, int protocol));
181# define socket socket_used_without_requesting_gnulib_module_socket 213# else
182# elif defined GNULIB_POSIXCHECK 214_GL_CXXALIAS_SYS (socket, int, (int domain, int type, int protocol));
183# undef socket 215# endif
184# define socket(d,t,p) \ 216_GL_CXXALIASWARN (socket);
185 (GL_LINK_WARNING ("socket is not always POSIX compliant - " \ 217#elif @HAVE_WINSOCK2_H@
186 "use gnulib module socket for portability"), \ 218# undef socket
187 socket (d, t, p)) 219# define socket socket_used_without_requesting_gnulib_module_socket
188# endif 220#elif defined GNULIB_POSIXCHECK
189 221# undef socket
190# if @GNULIB_CONNECT@ 222# if HAVE_RAW_DECL_SOCKET
191# if @HAVE_WINSOCK2_H@ 223_GL_WARN_ON_USE (socket, "socket is not always POSIX compliant - "
224 "use gnulib module socket for portability");
225# endif
226#endif
227
228#if @GNULIB_CONNECT@
229# if @HAVE_WINSOCK2_H@
230# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
192# undef connect 231# undef connect
193# define connect rpl_connect 232# define connect rpl_connect
194extern int rpl_connect (int, struct sockaddr *, int);
195# endif 233# endif
196# elif @HAVE_WINSOCK2_H@ 234_GL_FUNCDECL_RPL (connect, int,
197# undef connect 235 (int fd, const struct sockaddr *addr, socklen_t addrlen)
198# define connect socket_used_without_requesting_gnulib_module_connect 236 _GL_ARG_NONNULL ((2)));
199# elif defined GNULIB_POSIXCHECK 237_GL_CXXALIAS_RPL (connect, int,
200# undef connect 238 (int fd, const struct sockaddr *addr, socklen_t addrlen));
201# define connect(s,a,l) \ 239# else
202 (GL_LINK_WARNING ("connect is not always POSIX compliant - " \ 240_GL_CXXALIAS_SYS (connect, int,
203 "use gnulib module connect for portability"), \ 241 (int fd, const struct sockaddr *addr, socklen_t addrlen));
204 connect (s, a, l)) 242# endif
205# endif 243_GL_CXXALIASWARN (connect);
206 244#elif @HAVE_WINSOCK2_H@
207# if @GNULIB_ACCEPT@ 245# undef connect
208# if @HAVE_WINSOCK2_H@ 246# define connect socket_used_without_requesting_gnulib_module_connect
247#elif defined GNULIB_POSIXCHECK
248# undef connect
249# if HAVE_RAW_DECL_CONNECT
250_GL_WARN_ON_USE (connect, "connect is not always POSIX compliant - "
251 "use gnulib module connect for portability");
252# endif
253#endif
254
255#if @GNULIB_ACCEPT@
256# if @HAVE_WINSOCK2_H@
257# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
209# undef accept 258# undef accept
210# define accept rpl_accept 259# define accept rpl_accept
211extern int rpl_accept (int, struct sockaddr *, int *);
212# endif 260# endif
213# elif @HAVE_WINSOCK2_H@ 261_GL_FUNCDECL_RPL (accept, int,
214# undef accept 262 (int fd, struct sockaddr *addr, socklen_t *addrlen));
215# define accept accept_used_without_requesting_gnulib_module_accept 263_GL_CXXALIAS_RPL (accept, int,
216# elif defined GNULIB_POSIXCHECK 264 (int fd, struct sockaddr *addr, socklen_t *addrlen));
217# undef accept 265# else
218# define accept(s,a,l) \ 266/* Need to cast, because on Solaris 10 systems, the third parameter is
219 (GL_LINK_WARNING ("accept is not always POSIX compliant - " \ 267 void *addrlen. */
220 "use gnulib module accept for portability"), \ 268_GL_CXXALIAS_SYS_CAST (accept, int,
221 accept (s, a, l)) 269 (int fd, struct sockaddr *addr, socklen_t *addrlen));
222# endif 270# endif
223 271_GL_CXXALIASWARN (accept);
224# if @GNULIB_BIND@ 272#elif @HAVE_WINSOCK2_H@
225# if @HAVE_WINSOCK2_H@ 273# undef accept
274# define accept accept_used_without_requesting_gnulib_module_accept
275#elif defined GNULIB_POSIXCHECK
276# undef accept
277# if HAVE_RAW_DECL_ACCEPT
278_GL_WARN_ON_USE (accept, "accept is not always POSIX compliant - "
279 "use gnulib module accept for portability");
280# endif
281#endif
282
283#if @GNULIB_BIND@
284# if @HAVE_WINSOCK2_H@
285# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
226# undef bind 286# undef bind
227# define bind rpl_bind 287# define bind rpl_bind
228extern int rpl_bind (int, struct sockaddr *, int);
229# endif 288# endif
230# elif @HAVE_WINSOCK2_H@ 289_GL_FUNCDECL_RPL (bind, int,
231# undef bind 290 (int fd, const struct sockaddr *addr, socklen_t addrlen)
232# define bind bind_used_without_requesting_gnulib_module_bind 291 _GL_ARG_NONNULL ((2)));
233# elif defined GNULIB_POSIXCHECK 292_GL_CXXALIAS_RPL (bind, int,
234# undef bind 293 (int fd, const struct sockaddr *addr, socklen_t addrlen));
235# define bind(s,a,l) \ 294# else
236 (GL_LINK_WARNING ("bind is not always POSIX compliant - " \ 295_GL_CXXALIAS_SYS (bind, int,
237 "use gnulib module bind for portability"), \ 296 (int fd, const struct sockaddr *addr, socklen_t addrlen));
238 bind (s, a, l)) 297# endif
239# endif 298_GL_CXXALIASWARN (bind);
240 299#elif @HAVE_WINSOCK2_H@
241# if @GNULIB_GETPEERNAME@ 300# undef bind
242# if @HAVE_WINSOCK2_H@ 301# define bind bind_used_without_requesting_gnulib_module_bind
302#elif defined GNULIB_POSIXCHECK
303# undef bind
304# if HAVE_RAW_DECL_BIND
305_GL_WARN_ON_USE (bind, "bind is not always POSIX compliant - "
306 "use gnulib module bind for portability");
307# endif
308#endif
309
310#if @GNULIB_GETPEERNAME@
311# if @HAVE_WINSOCK2_H@
312# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
243# undef getpeername 313# undef getpeername
244# define getpeername rpl_getpeername 314# define getpeername rpl_getpeername
245extern int rpl_getpeername (int, struct sockaddr *, int *);
246# endif 315# endif
247# elif @HAVE_WINSOCK2_H@ 316_GL_FUNCDECL_RPL (getpeername, int,
248# undef getpeername 317 (int fd, struct sockaddr *addr, socklen_t *addrlen)
249# define getpeername getpeername_used_without_requesting_gnulib_module_getpeername 318 _GL_ARG_NONNULL ((2, 3)));
250# elif defined GNULIB_POSIXCHECK 319_GL_CXXALIAS_RPL (getpeername, int,
251# undef getpeername 320 (int fd, struct sockaddr *addr, socklen_t *addrlen));
252# define getpeername(s,a,l) \ 321# else
253 (GL_LINK_WARNING ("getpeername is not always POSIX compliant - " \ 322/* Need to cast, because on Solaris 10 systems, the third parameter is
254 "use gnulib module getpeername for portability"), \ 323 void *addrlen. */
255 getpeername (s, a, l)) 324_GL_CXXALIAS_SYS_CAST (getpeername, int,
256# endif 325 (int fd, struct sockaddr *addr, socklen_t *addrlen));
257 326# endif
258# if @GNULIB_GETSOCKNAME@ 327_GL_CXXALIASWARN (getpeername);
259# if @HAVE_WINSOCK2_H@ 328#elif @HAVE_WINSOCK2_H@
329# undef getpeername
330# define getpeername getpeername_used_without_requesting_gnulib_module_getpeername
331#elif defined GNULIB_POSIXCHECK
332# undef getpeername
333# if HAVE_RAW_DECL_GETPEERNAME
334_GL_WARN_ON_USE (getpeername, "getpeername is not always POSIX compliant - "
335 "use gnulib module getpeername for portability");
336# endif
337#endif
338
339#if @GNULIB_GETSOCKNAME@
340# if @HAVE_WINSOCK2_H@
341# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
260# undef getsockname 342# undef getsockname
261# define getsockname rpl_getsockname 343# define getsockname rpl_getsockname
262extern int rpl_getsockname (int, struct sockaddr *, int *);
263# endif 344# endif
264# elif @HAVE_WINSOCK2_H@ 345_GL_FUNCDECL_RPL (getsockname, int,
265# undef getsockname 346 (int fd, struct sockaddr *addr, socklen_t *addrlen)
266# define getsockname getsockname_used_without_requesting_gnulib_module_getsockname 347 _GL_ARG_NONNULL ((2, 3)));
267# elif defined GNULIB_POSIXCHECK 348_GL_CXXALIAS_RPL (getsockname, int,
268# undef getsockname 349 (int fd, struct sockaddr *addr, socklen_t *addrlen));
269# define getsockname(s,a,l) \ 350# else
270 (GL_LINK_WARNING ("getsockname is not always POSIX compliant - " \ 351/* Need to cast, because on Solaris 10 systems, the third parameter is
271 "use gnulib module getsockname for portability"), \ 352 void *addrlen. */
272 getsockname (s, a, l)) 353_GL_CXXALIAS_SYS_CAST (getsockname, int,
273# endif 354 (int fd, struct sockaddr *addr, socklen_t *addrlen));
274 355# endif
275# if @GNULIB_GETSOCKOPT@ 356_GL_CXXALIASWARN (getsockname);
276# if @HAVE_WINSOCK2_H@ 357#elif @HAVE_WINSOCK2_H@
358# undef getsockname
359# define getsockname getsockname_used_without_requesting_gnulib_module_getsockname
360#elif defined GNULIB_POSIXCHECK
361# undef getsockname
362# if HAVE_RAW_DECL_GETSOCKNAME
363_GL_WARN_ON_USE (getsockname, "getsockname is not always POSIX compliant - "
364 "use gnulib module getsockname for portability");
365# endif
366#endif
367
368#if @GNULIB_GETSOCKOPT@
369# if @HAVE_WINSOCK2_H@
370# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
277# undef getsockopt 371# undef getsockopt
278# define getsockopt rpl_getsockopt 372# define getsockopt rpl_getsockopt
279extern int rpl_getsockopt (int, int, int, void *, socklen_t *);
280# endif 373# endif
281# elif @HAVE_WINSOCK2_H@ 374_GL_FUNCDECL_RPL (getsockopt, int, (int fd, int level, int optname,
282# undef getsockopt 375 void *optval, socklen_t *optlen)
283# define getsockopt getsockopt_used_without_requesting_gnulib_module_getsockopt 376 _GL_ARG_NONNULL ((4, 5)));
284# elif defined GNULIB_POSIXCHECK 377_GL_CXXALIAS_RPL (getsockopt, int, (int fd, int level, int optname,
285# undef getsockopt 378 void *optval, socklen_t *optlen));
286# define getsockopt(s,lvl,o,v,l) \ 379# else
287 (GL_LINK_WARNING ("getsockopt is not always POSIX compliant - " \ 380/* Need to cast, because on Solaris 10 systems, the fifth parameter is
288 "use gnulib module getsockopt for portability"), \ 381 void *optlen. */
289 getsockopt (s, lvl, o, v, l)) 382_GL_CXXALIAS_SYS_CAST (getsockopt, int, (int fd, int level, int optname,
290# endif 383 void *optval, socklen_t *optlen));
291 384# endif
292# if @GNULIB_LISTEN@ 385_GL_CXXALIASWARN (getsockopt);
293# if @HAVE_WINSOCK2_H@ 386#elif @HAVE_WINSOCK2_H@
387# undef getsockopt
388# define getsockopt getsockopt_used_without_requesting_gnulib_module_getsockopt
389#elif defined GNULIB_POSIXCHECK
390# undef getsockopt
391# if HAVE_RAW_DECL_GETSOCKOPT
392_GL_WARN_ON_USE (getsockopt, "getsockopt is not always POSIX compliant - "
393 "use gnulib module getsockopt for portability");
394# endif
395#endif
396
397#if @GNULIB_LISTEN@
398# if @HAVE_WINSOCK2_H@
399# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
294# undef listen 400# undef listen
295# define listen rpl_listen 401# define listen rpl_listen
296extern int rpl_listen (int, int);
297# endif 402# endif
298# elif @HAVE_WINSOCK2_H@ 403_GL_FUNCDECL_RPL (listen, int, (int fd, int backlog));
299# undef listen 404_GL_CXXALIAS_RPL (listen, int, (int fd, int backlog));
300# define listen listen_used_without_requesting_gnulib_module_listen 405# else
301# elif defined GNULIB_POSIXCHECK 406_GL_CXXALIAS_SYS (listen, int, (int fd, int backlog));
302# undef listen 407# endif
303# define listen(s,b) \ 408_GL_CXXALIASWARN (listen);
304 (GL_LINK_WARNING ("listen is not always POSIX compliant - " \ 409#elif @HAVE_WINSOCK2_H@
305 "use gnulib module listen for portability"), \ 410# undef listen
306 listen (s, b)) 411# define listen listen_used_without_requesting_gnulib_module_listen
307# endif 412#elif defined GNULIB_POSIXCHECK
308 413# undef listen
309# if @GNULIB_RECV@ 414# if HAVE_RAW_DECL_LISTEN
310# if @HAVE_WINSOCK2_H@ 415_GL_WARN_ON_USE (listen, "listen is not always POSIX compliant - "
416 "use gnulib module listen for portability");
417# endif
418#endif
419
420#if @GNULIB_RECV@
421# if @HAVE_WINSOCK2_H@
422# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311# undef recv 423# undef recv
312# define recv rpl_recv 424# define recv rpl_recv
313extern int rpl_recv (int, void *, int, int);
314# endif 425# endif
315# elif @HAVE_WINSOCK2_H@ 426_GL_FUNCDECL_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)
316# undef recv 427 _GL_ARG_NONNULL ((2)));
317# define recv recv_used_without_requesting_gnulib_module_recv 428_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
318# elif defined GNULIB_POSIXCHECK 429# else
319# undef recv 430_GL_CXXALIAS_SYS (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
320# define recv(s,b,n,f) \ 431# endif
321 (GL_LINK_WARNING ("recv is not always POSIX compliant - " \ 432_GL_CXXALIASWARN (recv);
322 "use gnulib module recv for portability"), \ 433#elif @HAVE_WINSOCK2_H@
323 recv (s, b, n, f)) 434# undef recv
324# endif 435# define recv recv_used_without_requesting_gnulib_module_recv
325 436#elif defined GNULIB_POSIXCHECK
326# if @GNULIB_SEND@ 437# undef recv
327# if @HAVE_WINSOCK2_H@ 438# if HAVE_RAW_DECL_RECV
439_GL_WARN_ON_USE (recv, "recv is not always POSIX compliant - "
440 "use gnulib module recv for portability");
441# endif
442#endif
443
444#if @GNULIB_SEND@
445# if @HAVE_WINSOCK2_H@
446# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
328# undef send 447# undef send
329# define send rpl_send 448# define send rpl_send
330extern int rpl_send (int, const void *, int, int);
331# endif 449# endif
332# elif @HAVE_WINSOCK2_H@ 450_GL_FUNCDECL_RPL (send, ssize_t,
333# undef send 451 (int fd, const void *buf, size_t len, int flags)
334# define send send_used_without_requesting_gnulib_module_send 452 _GL_ARG_NONNULL ((2)));
335# elif defined GNULIB_POSIXCHECK 453_GL_CXXALIAS_RPL (send, ssize_t,
336# undef send 454 (int fd, const void *buf, size_t len, int flags));
337# define send(s,b,n,f) \ 455# else
338 (GL_LINK_WARNING ("send is not always POSIX compliant - " \ 456_GL_CXXALIAS_SYS (send, ssize_t,
339 "use gnulib module send for portability"), \ 457 (int fd, const void *buf, size_t len, int flags));
340 send (s, b, n, f)) 458# endif
341# endif 459_GL_CXXALIASWARN (send);
342 460#elif @HAVE_WINSOCK2_H@
343# if @GNULIB_RECVFROM@ 461# undef send
344# if @HAVE_WINSOCK2_H@ 462# define send send_used_without_requesting_gnulib_module_send
463#elif defined GNULIB_POSIXCHECK
464# undef send
465# if HAVE_RAW_DECL_SEND
466_GL_WARN_ON_USE (send, "send is not always POSIX compliant - "
467 "use gnulib module send for portability");
468# endif
469#endif
470
471#if @GNULIB_RECVFROM@
472# if @HAVE_WINSOCK2_H@
473# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
345# undef recvfrom 474# undef recvfrom
346# define recvfrom rpl_recvfrom 475# define recvfrom rpl_recvfrom
347extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *);
348# endif 476# endif
349# elif @HAVE_WINSOCK2_H@ 477_GL_FUNCDECL_RPL (recvfrom, ssize_t,
350# undef recvfrom 478 (int fd, void *buf, size_t len, int flags,
351# define recvfrom recvfrom_used_without_requesting_gnulib_module_recvfrom 479 struct sockaddr *from, socklen_t *fromlen)
352# elif defined GNULIB_POSIXCHECK 480 _GL_ARG_NONNULL ((2)));
353# undef recvfrom 481_GL_CXXALIAS_RPL (recvfrom, ssize_t,
354# define recvfrom(s,b,n,f,a,l) \ 482 (int fd, void *buf, size_t len, int flags,
355 (GL_LINK_WARNING ("recvfrom is not always POSIX compliant - " \ 483 struct sockaddr *from, socklen_t *fromlen));
356 "use gnulib module recvfrom for portability"), \ 484# else
357 recvfrom (s, b, n, f, a, l)) 485/* Need to cast, because on Solaris 10 systems, the sixth parameter is
358# endif 486 void *fromlen. */
359 487_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t,
360# if @GNULIB_SENDTO@ 488 (int fd, void *buf, size_t len, int flags,
361# if @HAVE_WINSOCK2_H@ 489 struct sockaddr *from, socklen_t *fromlen));
490# endif
491_GL_CXXALIASWARN (recvfrom);
492#elif @HAVE_WINSOCK2_H@
493# undef recvfrom
494# define recvfrom recvfrom_used_without_requesting_gnulib_module_recvfrom
495#elif defined GNULIB_POSIXCHECK
496# undef recvfrom
497# if HAVE_RAW_DECL_RECVFROM
498_GL_WARN_ON_USE (recvfrom, "recvfrom is not always POSIX compliant - "
499 "use gnulib module recvfrom for portability");
500# endif
501#endif
502
503#if @GNULIB_SENDTO@
504# if @HAVE_WINSOCK2_H@
505# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
362# undef sendto 506# undef sendto
363# define sendto rpl_sendto 507# define sendto rpl_sendto
364extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int);
365# endif 508# endif
366# elif @HAVE_WINSOCK2_H@ 509_GL_FUNCDECL_RPL (sendto, ssize_t,
367# undef sendto 510 (int fd, const void *buf, size_t len, int flags,
368# define sendto sendto_used_without_requesting_gnulib_module_sendto 511 const struct sockaddr *to, socklen_t tolen)
369# elif defined GNULIB_POSIXCHECK 512 _GL_ARG_NONNULL ((2)));
370# undef sendto 513_GL_CXXALIAS_RPL (sendto, ssize_t,
371# define sendto(s,b,n,f,a,l) \ 514 (int fd, const void *buf, size_t len, int flags,
372 (GL_LINK_WARNING ("sendto is not always POSIX compliant - " \ 515 const struct sockaddr *to, socklen_t tolen));
373 "use gnulib module sendto for portability"), \ 516# else
374 sendto (s, b, n, f, a, l)) 517_GL_CXXALIAS_SYS (sendto, ssize_t,
375# endif 518 (int fd, const void *buf, size_t len, int flags,
376 519 const struct sockaddr *to, socklen_t tolen));
377# if @GNULIB_SETSOCKOPT@ 520# endif
378# if @HAVE_WINSOCK2_H@ 521_GL_CXXALIASWARN (sendto);
522#elif @HAVE_WINSOCK2_H@
523# undef sendto
524# define sendto sendto_used_without_requesting_gnulib_module_sendto
525#elif defined GNULIB_POSIXCHECK
526# undef sendto
527# if HAVE_RAW_DECL_SENDTO
528_GL_WARN_ON_USE (sendto, "sendto is not always POSIX compliant - "
529 "use gnulib module sendto for portability");
530# endif
531#endif
532
533#if @GNULIB_SETSOCKOPT@
534# if @HAVE_WINSOCK2_H@
535# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
379# undef setsockopt 536# undef setsockopt
380# define setsockopt rpl_setsockopt 537# define setsockopt rpl_setsockopt
381extern int rpl_setsockopt (int, int, int, const void *, socklen_t);
382# endif 538# endif
383# elif @HAVE_WINSOCK2_H@ 539_GL_FUNCDECL_RPL (setsockopt, int, (int fd, int level, int optname,
384# undef setsockopt 540 const void * optval, socklen_t optlen)
385# define setsockopt setsockopt_used_without_requesting_gnulib_module_setsockopt 541 _GL_ARG_NONNULL ((4)));
386# elif defined GNULIB_POSIXCHECK 542_GL_CXXALIAS_RPL (setsockopt, int, (int fd, int level, int optname,
387# undef setsockopt 543 const void * optval, socklen_t optlen));
388# define setsockopt(s,lvl,o,v,l) \ 544# else
389 (GL_LINK_WARNING ("setsockopt is not always POSIX compliant - " \ 545_GL_CXXALIAS_SYS (setsockopt, int, (int fd, int level, int optname,
390 "use gnulib module setsockopt for portability"), \ 546 const void * optval, socklen_t optlen));
391 setsockopt (s, lvl, o, v, l)) 547# endif
392# endif 548_GL_CXXALIASWARN (setsockopt);
393 549#elif @HAVE_WINSOCK2_H@
394# if @GNULIB_SHUTDOWN@ 550# undef setsockopt
395# if @HAVE_WINSOCK2_H@ 551# define setsockopt setsockopt_used_without_requesting_gnulib_module_setsockopt
552#elif defined GNULIB_POSIXCHECK
553# undef setsockopt
554# if HAVE_RAW_DECL_SETSOCKOPT
555_GL_WARN_ON_USE (setsockopt, "setsockopt is not always POSIX compliant - "
556 "use gnulib module setsockopt for portability");
557# endif
558#endif
559
560#if @GNULIB_SHUTDOWN@
561# if @HAVE_WINSOCK2_H@
562# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
396# undef shutdown 563# undef shutdown
397# define shutdown rpl_shutdown 564# define shutdown rpl_shutdown
398extern int rpl_shutdown (int, int);
399# endif 565# endif
400# elif @HAVE_WINSOCK2_H@ 566_GL_FUNCDECL_RPL (shutdown, int, (int fd, int how));
401# undef shutdown 567_GL_CXXALIAS_RPL (shutdown, int, (int fd, int how));
402# define shutdown shutdown_used_without_requesting_gnulib_module_shutdown 568# else
403# elif defined GNULIB_POSIXCHECK 569_GL_CXXALIAS_SYS (shutdown, int, (int fd, int how));
404# undef shutdown 570# endif
405# define shutdown(s,h) \ 571_GL_CXXALIASWARN (shutdown);
406 (GL_LINK_WARNING ("shutdown is not always POSIX compliant - " \ 572#elif @HAVE_WINSOCK2_H@
407 "use gnulib module shutdown for portability"), \ 573# undef shutdown
408 shutdown (s, h)) 574# define shutdown shutdown_used_without_requesting_gnulib_module_shutdown
575#elif defined GNULIB_POSIXCHECK
576# undef shutdown
577# if HAVE_RAW_DECL_SHUTDOWN
578_GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX compliant - "
579 "use gnulib module shutdown for portability");
409# endif 580# endif
581#endif
410 582
411# if @HAVE_WINSOCK2_H@ 583#if @HAVE_WINSOCK2_H@
584# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
412# undef select 585# undef select
413# define select select_used_without_including_sys_select_h 586# define select select_used_without_including_sys_select_h
587# else
588 _GL_WARN_ON_USE (select,
589 "select() used without including <sys/select.h>");
414# endif 590# endif
591#endif
415 592
416# ifdef __cplusplus 593#if @GNULIB_ACCEPT4@
417} 594/* Accept a connection on a socket, with specific opening flags.
595 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
596 and O_TEXT, O_BINARY (defined in "binary-io.h").
597 See also the Linux man page at
598 <http://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */
599# if @HAVE_ACCEPT4@
600# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
601# define accept4 rpl_accept4
602# endif
603_GL_FUNCDECL_RPL (accept4, int,
604 (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
605 int flags));
606_GL_CXXALIAS_RPL (accept4, int,
607 (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
608 int flags));
609# else
610_GL_FUNCDECL_SYS (accept4, int,
611 (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
612 int flags));
613_GL_CXXALIAS_SYS (accept4, int,
614 (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
615 int flags));
418# endif 616# endif
419 617_GL_CXXALIASWARN (accept4);
420#endif /* HAVE_SYS_SOCKET_H */ 618#elif defined GNULIB_POSIXCHECK
619# undef accept4
620# if HAVE_RAW_DECL_ACCEPT4
621_GL_WARN_ON_USE (accept4, "accept4 is unportable - "
622 "use gnulib module accept4 for portability");
623# endif
624#endif
421 625
422#endif /* _GL_SYS_SOCKET_H */ 626#endif /* _GL_SYS_SOCKET_H */
423#endif /* _GL_SYS_SOCKET_H */ 627#endif /* _GL_SYS_SOCKET_H */
628#endif
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
new file mode 100644
index 00000000..a64bf029
--- /dev/null
+++ b/gl/sys_stat.in.h
@@ -0,0 +1,638 @@
1/* Provide a more complete sys/stat header file.
2 Copyright (C) 2005-2010 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, or (at your option)
7 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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
19
20/* This file is supposed to be used on platforms where <sys/stat.h> is
21 incomplete. It is intended to provide definitions and prototypes
22 needed by an application. Start with what the system provides. */
23
24#if __GNUC__ >= 3
25@PRAGMA_SYSTEM_HEADER@
26#endif
27
28#if defined __need_system_sys_stat_h
29/* Special invocation convention. */
30
31#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
32
33#else
34/* Normal invocation convention. */
35
36#ifndef _GL_SYS_STAT_H
37
38/* Get nlink_t. */
39#include <sys/types.h>
40
41/* Get struct timespec. */
42#include <time.h>
43
44/* The include_next requires a split double-inclusion guard. */
45#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
46
47#ifndef _GL_SYS_STAT_H
48#define _GL_SYS_STAT_H
49
50/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
51
52/* The definition of _GL_ARG_NONNULL is copied here. */
53
54/* The definition of _GL_WARN_ON_USE is copied here. */
55
56/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
57 headers that may declare mkdir(). */
58#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
59# include <io.h>
60#endif
61
62#ifndef S_IFMT
63# define S_IFMT 0170000
64#endif
65
66#if STAT_MACROS_BROKEN
67# undef S_ISBLK
68# undef S_ISCHR
69# undef S_ISDIR
70# undef S_ISFIFO
71# undef S_ISLNK
72# undef S_ISNAM
73# undef S_ISMPB
74# undef S_ISMPC
75# undef S_ISNWK
76# undef S_ISREG
77# undef S_ISSOCK
78#endif
79
80#ifndef S_ISBLK
81# ifdef S_IFBLK
82# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
83# else
84# define S_ISBLK(m) 0
85# endif
86#endif
87
88#ifndef S_ISCHR
89# ifdef S_IFCHR
90# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
91# else
92# define S_ISCHR(m) 0
93# endif
94#endif
95
96#ifndef S_ISDIR
97# ifdef S_IFDIR
98# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
99# else
100# define S_ISDIR(m) 0
101# endif
102#endif
103
104#ifndef S_ISDOOR /* Solaris 2.5 and up */
105# define S_ISDOOR(m) 0
106#endif
107
108#ifndef S_ISFIFO
109# ifdef S_IFIFO
110# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
111# else
112# define S_ISFIFO(m) 0
113# endif
114#endif
115
116#ifndef S_ISLNK
117# ifdef S_IFLNK
118# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
119# else
120# define S_ISLNK(m) 0
121# endif
122#endif
123
124#ifndef S_ISMPB /* V7 */
125# ifdef S_IFMPB
126# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
127# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
128# else
129# define S_ISMPB(m) 0
130# define S_ISMPC(m) 0
131# endif
132#endif
133
134#ifndef S_ISNAM /* Xenix */
135# ifdef S_IFNAM
136# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
137# else
138# define S_ISNAM(m) 0
139# endif
140#endif
141
142#ifndef S_ISNWK /* HP/UX */
143# ifdef S_IFNWK
144# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
145# else
146# define S_ISNWK(m) 0
147# endif
148#endif
149
150#ifndef S_ISPORT /* Solaris 10 and up */
151# define S_ISPORT(m) 0
152#endif
153
154#ifndef S_ISREG
155# ifdef S_IFREG
156# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
157# else
158# define S_ISREG(m) 0
159# endif
160#endif
161
162#ifndef S_ISSOCK
163# ifdef S_IFSOCK
164# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
165# else
166# define S_ISSOCK(m) 0
167# endif
168#endif
169
170
171#ifndef S_TYPEISMQ
172# define S_TYPEISMQ(p) 0
173#endif
174
175#ifndef S_TYPEISTMO
176# define S_TYPEISTMO(p) 0
177#endif
178
179
180#ifndef S_TYPEISSEM
181# ifdef S_INSEM
182# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
183# else
184# define S_TYPEISSEM(p) 0
185# endif
186#endif
187
188#ifndef S_TYPEISSHM
189# ifdef S_INSHD
190# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
191# else
192# define S_TYPEISSHM(p) 0
193# endif
194#endif
195
196/* high performance ("contiguous data") */
197#ifndef S_ISCTG
198# define S_ISCTG(p) 0
199#endif
200
201/* Cray DMF (data migration facility): off line, with data */
202#ifndef S_ISOFD
203# define S_ISOFD(p) 0
204#endif
205
206/* Cray DMF (data migration facility): off line, with no data */
207#ifndef S_ISOFL
208# define S_ISOFL(p) 0
209#endif
210
211/* 4.4BSD whiteout */
212#ifndef S_ISWHT
213# define S_ISWHT(m) 0
214#endif
215
216/* If any of the following are undefined,
217 define them to their de facto standard values. */
218#if !S_ISUID
219# define S_ISUID 04000
220#endif
221#if !S_ISGID
222# define S_ISGID 02000
223#endif
224
225/* S_ISVTX is a common extension to POSIX. */
226#ifndef S_ISVTX
227# define S_ISVTX 01000
228#endif
229
230#if !S_IRUSR && S_IREAD
231# define S_IRUSR S_IREAD
232#endif
233#if !S_IRUSR
234# define S_IRUSR 00400
235#endif
236#if !S_IRGRP
237# define S_IRGRP (S_IRUSR >> 3)
238#endif
239#if !S_IROTH
240# define S_IROTH (S_IRUSR >> 6)
241#endif
242
243#if !S_IWUSR && S_IWRITE
244# define S_IWUSR S_IWRITE
245#endif
246#if !S_IWUSR
247# define S_IWUSR 00200
248#endif
249#if !S_IWGRP
250# define S_IWGRP (S_IWUSR >> 3)
251#endif
252#if !S_IWOTH
253# define S_IWOTH (S_IWUSR >> 6)
254#endif
255
256#if !S_IXUSR && S_IEXEC
257# define S_IXUSR S_IEXEC
258#endif
259#if !S_IXUSR
260# define S_IXUSR 00100
261#endif
262#if !S_IXGRP
263# define S_IXGRP (S_IXUSR >> 3)
264#endif
265#if !S_IXOTH
266# define S_IXOTH (S_IXUSR >> 6)
267#endif
268
269#if !S_IRWXU
270# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
271#endif
272#if !S_IRWXG
273# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
274#endif
275#if !S_IRWXO
276# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
277#endif
278
279/* S_IXUGO is a common extension to POSIX. */
280#if !S_IXUGO
281# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
282#endif
283
284#ifndef S_IRWXUGO
285# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
286#endif
287
288/* Macros for futimens and utimensat. */
289#ifndef UTIME_NOW
290# define UTIME_NOW (-1)
291# define UTIME_OMIT (-2)
292#endif
293
294
295#if @GNULIB_FCHMODAT@
296# if !@HAVE_FCHMODAT@
297_GL_FUNCDECL_SYS (fchmodat, int,
298 (int fd, char const *file, mode_t mode, int flag)
299 _GL_ARG_NONNULL ((2)));
300# endif
301_GL_CXXALIAS_SYS (fchmodat, int,
302 (int fd, char const *file, mode_t mode, int flag));
303_GL_CXXALIASWARN (fchmodat);
304#elif defined GNULIB_POSIXCHECK
305# undef fchmodat
306# if HAVE_RAW_DECL_FCHMODAT
307_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
308 "use gnulib module openat for portability");
309# endif
310#endif
311
312
313#if @REPLACE_FSTAT@
314# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
315# define fstat rpl_fstat
316# endif
317_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
318_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
319#else
320_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
321#endif
322_GL_CXXALIASWARN (fstat);
323
324
325#if @GNULIB_FSTATAT@
326# if @REPLACE_FSTATAT@
327# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
328# undef fstatat
329# define fstatat rpl_fstatat
330# endif
331_GL_FUNCDECL_RPL (fstatat, int,
332 (int fd, char const *name, struct stat *st, int flags)
333 _GL_ARG_NONNULL ((2, 3)));
334_GL_CXXALIAS_RPL (fstatat, int,
335 (int fd, char const *name, struct stat *st, int flags));
336# else
337# if !@HAVE_FSTATAT@
338_GL_FUNCDECL_SYS (fstatat, int,
339 (int fd, char const *name, struct stat *st, int flags)
340 _GL_ARG_NONNULL ((2, 3)));
341# endif
342_GL_CXXALIAS_SYS (fstatat, int,
343 (int fd, char const *name, struct stat *st, int flags));
344# endif
345_GL_CXXALIASWARN (fstatat);
346#elif defined GNULIB_POSIXCHECK
347# undef fstatat
348# if HAVE_RAW_DECL_FSTATAT
349_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
350 "use gnulib module openat for portability");
351# endif
352#endif
353
354
355#if @GNULIB_FUTIMENS@
356# if @REPLACE_FUTIMENS@
357# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
358# undef futimens
359# define futimens rpl_futimens
360# endif
361_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
362_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
363# else
364# if !@HAVE_FUTIMENS@
365_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
366# endif
367_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
368# endif
369_GL_CXXALIASWARN (futimens);
370#elif defined GNULIB_POSIXCHECK
371# undef futimens
372# if HAVE_RAW_DECL_FUTIMENS
373_GL_WARN_ON_USE (futimens, "futimens is not portable - "
374 "use gnulib module futimens for portability");
375# endif
376#endif
377
378
379#if @GNULIB_LCHMOD@
380/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
381 denotes a symbolic link. */
382# if !@HAVE_LCHMOD@
383/* The lchmod replacement follows symbolic links. Callers should take
384 this into account; lchmod should be applied only to arguments that
385 are known to not be symbolic links. On hosts that lack lchmod,
386 this can lead to race conditions between the check and the
387 invocation of lchmod, but we know of no workarounds that are
388 reliable in general. You might try requesting support for lchmod
389 from your operating system supplier. */
390# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
391# define lchmod chmod
392# endif
393/* Need to cast, because on mingw, the second parameter of chmod is
394 int mode. */
395_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
396 (const char *filename, mode_t mode));
397# else
398# if 0 /* assume already declared */
399_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
400 _GL_ARG_NONNULL ((1)));
401# endif
402_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
403# endif
404# if @HAVE_LCHMOD@
405_GL_CXXALIASWARN (lchmod);
406# endif
407#elif defined GNULIB_POSIXCHECK
408# undef lchmod
409# if HAVE_RAW_DECL_LCHMOD
410_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
411 "use gnulib module lchmod for portability");
412# endif
413#endif
414
415
416#if @GNULIB_LSTAT@
417# if ! @HAVE_LSTAT@
418/* mingw does not support symlinks, therefore it does not have lstat. But
419 without links, stat does just fine. */
420# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
421# define lstat stat
422# endif
423_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
424# elif @REPLACE_LSTAT@
425# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
426# undef lstat
427# define lstat rpl_lstat
428# endif
429_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
430 _GL_ARG_NONNULL ((1, 2)));
431_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
432# else
433_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
434# endif
435# if @HAVE_LSTAT@
436_GL_CXXALIASWARN (lstat);
437# endif
438#elif defined GNULIB_POSIXCHECK
439# undef lstat
440# if HAVE_RAW_DECL_LSTAT
441_GL_WARN_ON_USE (lstat, "lstat is unportable - "
442 "use gnulib module lstat for portability");
443# endif
444#endif
445
446
447#if @REPLACE_MKDIR@
448# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
449# undef mkdir
450# define mkdir rpl_mkdir
451# endif
452_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
453 _GL_ARG_NONNULL ((1)));
454_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
455#else
456/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
457 Additionally, it declares _mkdir (and depending on compile flags, an
458 alias mkdir), only in the nonstandard <io.h>, which is included above. */
459# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
460
461static inline int
462rpl_mkdir (char const *name, mode_t mode)
463{
464 return _mkdir (name);
465}
466
467# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
468# define mkdir rpl_mkdir
469# endif
470_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
471# else
472_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
473# endif
474#endif
475_GL_CXXALIASWARN (mkdir);
476
477
478#if @GNULIB_MKDIRAT@
479# if !@HAVE_MKDIRAT@
480_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
481 _GL_ARG_NONNULL ((2)));
482# endif
483_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
484_GL_CXXALIASWARN (mkdirat);
485#elif defined GNULIB_POSIXCHECK
486# undef mkdirat
487# if HAVE_RAW_DECL_MKDIRAT
488_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
489 "use gnulib module openat for portability");
490# endif
491#endif
492
493
494#if @GNULIB_MKFIFO@
495# if @REPLACE_MKFIFO@
496# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
497# undef mkfifo
498# define mkfifo rpl_mkfifo
499# endif
500_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
501 _GL_ARG_NONNULL ((1)));
502_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
503# else
504# if !@HAVE_MKFIFO@
505_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
506 _GL_ARG_NONNULL ((1)));
507# endif
508_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
509# endif
510_GL_CXXALIASWARN (mkfifo);
511#elif defined GNULIB_POSIXCHECK
512# undef mkfifo
513# if HAVE_RAW_DECL_MKFIFO
514_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
515 "use gnulib module mkfifo for portability");
516# endif
517#endif
518
519
520#if @GNULIB_MKFIFOAT@
521# if !@HAVE_MKFIFOAT@
522_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
523 _GL_ARG_NONNULL ((2)));
524# endif
525_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
526_GL_CXXALIASWARN (mkfifoat);
527#elif defined GNULIB_POSIXCHECK
528# undef mkfifoat
529# if HAVE_RAW_DECL_MKFIFOAT
530_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
531 "use gnulib module mkfifoat for portability");
532# endif
533#endif
534
535
536#if @GNULIB_MKNOD@
537# if @REPLACE_MKNOD@
538# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
539# undef mknod
540# define mknod rpl_mknod
541# endif
542_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
543 _GL_ARG_NONNULL ((1)));
544_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
545# else
546# if !@HAVE_MKNOD@
547_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
548 _GL_ARG_NONNULL ((1)));
549# endif
550_GL_CXXALIAS_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev));
551# endif
552_GL_CXXALIASWARN (mknod);
553#elif defined GNULIB_POSIXCHECK
554# undef mknod
555# if HAVE_RAW_DECL_MKNOD
556_GL_WARN_ON_USE (mknod, "mknod is not portable - "
557 "use gnulib module mknod for portability");
558# endif
559#endif
560
561
562#if @GNULIB_MKNODAT@
563# if !@HAVE_MKNODAT@
564_GL_FUNCDECL_SYS (mknodat, int,
565 (int fd, char const *file, mode_t mode, dev_t dev)
566 _GL_ARG_NONNULL ((2)));
567# endif
568_GL_CXXALIAS_SYS (mknodat, int,
569 (int fd, char const *file, mode_t mode, dev_t dev));
570_GL_CXXALIASWARN (mknodat);
571#elif defined GNULIB_POSIXCHECK
572# undef mknodat
573# if HAVE_RAW_DECL_MKNODAT
574_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
575 "use gnulib module mkfifoat for portability");
576# endif
577#endif
578
579
580#if @GNULIB_STAT@
581# if @REPLACE_STAT@
582/* We can't use the object-like #define stat rpl_stat, because of
583 struct stat. This means that rpl_stat will not be used if the user
584 does (stat)(a,b). Oh well. */
585# undef stat
586# ifdef _LARGE_FILES
587 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
588 so we have to replace stat64() instead of stat(). */
589# define stat stat64
590# undef stat64
591# define stat64(name, st) rpl_stat (name, st)
592# else /* !_LARGE_FILES */
593# define stat(name, st) rpl_stat (name, st)
594# endif /* !_LARGE_FILES */
595_GL_EXTERN_C int stat (const char *name, struct stat *buf) _GL_ARG_NONNULL ((1, 2));
596# endif
597#elif defined GNULIB_POSIXCHECK
598# undef stat
599# if HAVE_RAW_DECL_STAT
600_GL_WARN_ON_USE (stat, "stat is unportable - "
601 "use gnulib module stat for portability");
602# endif
603#endif
604
605
606#if @GNULIB_UTIMENSAT@
607# if @REPLACE_UTIMENSAT@
608# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
609# undef utimensat
610# define utimensat rpl_utimensat
611# endif
612_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
613 struct timespec const times[2], int flag)
614 _GL_ARG_NONNULL ((2)));
615_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
616 struct timespec const times[2], int flag));
617# else
618# if !@HAVE_UTIMENSAT@
619_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
620 struct timespec const times[2], int flag)
621 _GL_ARG_NONNULL ((2)));
622# endif
623_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
624 struct timespec const times[2], int flag));
625# endif
626_GL_CXXALIASWARN (utimensat);
627#elif defined GNULIB_POSIXCHECK
628# undef utimensat
629# if HAVE_RAW_DECL_UTIMENSAT
630_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
631 "use gnulib module utimensat for portability");
632# endif
633#endif
634
635
636#endif /* _GL_SYS_STAT_H */
637#endif /* _GL_SYS_STAT_H */
638#endif
diff --git a/gl/time.in.h b/gl/time.in.h
index dec37e85..8e364feb 100644
--- a/gl/time.in.h
+++ b/gl/time.in.h
@@ -1,6 +1,6 @@
1/* A more-standard <time.h>. 1/* A more-standard <time.h>.
2 2
3 Copyright (C) 2007-2008 Free Software Foundation, Inc. 3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -37,9 +37,14 @@
37 37
38# @INCLUDE_NEXT@ @NEXT_TIME_H@ 38# @INCLUDE_NEXT@ @NEXT_TIME_H@
39 39
40# ifdef __cplusplus 40/* NetBSD 5.0 mis-defines NULL. */
41extern "C" { 41# include <stddef.h>
42# endif 42
43/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
44
45/* The definition of _GL_ARG_NONNULL is copied here. */
46
47/* The definition of _GL_WARN_ON_USE is copied here. */
43 48
44/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). 49/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
45 Or they define it with the wrong member names or define it in <sys/time.h> 50 Or they define it with the wrong member names or define it in <sys/time.h>
@@ -48,6 +53,11 @@ extern "C" {
48# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ 53# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
49# include <sys/time.h> 54# include <sys/time.h>
50# else 55# else
56
57# ifdef __cplusplus
58extern "C" {
59# endif
60
51# undef timespec 61# undef timespec
52# define timespec rpl_timespec 62# define timespec rpl_timespec
53struct timespec 63struct timespec
@@ -55,64 +65,155 @@ struct timespec
55 time_t tv_sec; 65 time_t tv_sec;
56 long int tv_nsec; 66 long int tv_nsec;
57}; 67};
68
69# ifdef __cplusplus
70}
71# endif
72
58# endif 73# endif
59# endif 74# endif
60 75
61/* Sleep for at least RQTP seconds unless interrupted, If interrupted, 76/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
62 return -1 and store the remaining time into RMTP. See 77 return -1 and store the remaining time into RMTP. See
63 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ 78 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
64# if @REPLACE_NANOSLEEP@ 79# if @GNULIB_NANOSLEEP@
65# define nanosleep rpl_nanosleep 80# if @REPLACE_NANOSLEEP@
66int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp); 81# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
82# define nanosleep rpl_nanosleep
83# endif
84_GL_FUNCDECL_RPL (nanosleep, int,
85 (struct timespec const *__rqtp, struct timespec *__rmtp)
86 _GL_ARG_NONNULL ((1)));
87_GL_CXXALIAS_RPL (nanosleep, int,
88 (struct timespec const *__rqtp, struct timespec *__rmtp));
89# else
90# if ! @HAVE_NANOSLEEP@
91_GL_FUNCDECL_SYS (nanosleep, int,
92 (struct timespec const *__rqtp, struct timespec *__rmtp)
93 _GL_ARG_NONNULL ((1)));
94# endif
95_GL_CXXALIAS_SYS (nanosleep, int,
96 (struct timespec const *__rqtp, struct timespec *__rmtp));
97# endif
98_GL_CXXALIASWARN (nanosleep);
99# endif
100
101/* Return the 'time_t' representation of TP and normalize TP. */
102# if @GNULIB_MKTIME@
103# if @REPLACE_MKTIME@
104# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
105# define mktime rpl_mktime
106# endif
107_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
108_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
109# else
110_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
111# endif
112_GL_CXXALIASWARN (mktime);
67# endif 113# endif
68 114
69/* Convert TIMER to RESULT, assuming local time and UTC respectively. See 115/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
70 <http://www.opengroup.org/susv3xsh/localtime_r.html> and 116 <http://www.opengroup.org/susv3xsh/localtime_r.html> and
71 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ 117 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
72# if @REPLACE_LOCALTIME_R@ 118# if @GNULIB_TIME_R@
73# undef localtime_r 119# if @REPLACE_LOCALTIME_R@
74# define localtime_r rpl_localtime_r 120# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
75# undef gmtime_r 121# undef localtime_r
76# define gmtime_r rpl_gmtime_r 122# define localtime_r rpl_localtime_r
77struct tm *localtime_r (time_t const *restrict __timer, 123# endif
78 struct tm *restrict __result); 124_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
79struct tm *gmtime_r (time_t const *restrict __timer, 125 struct tm *restrict __result)
80 struct tm *restrict __result); 126 _GL_ARG_NONNULL ((1, 2)));
127_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
128 struct tm *restrict __result));
129# else
130# if ! @HAVE_LOCALTIME_R@
131_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
132 struct tm *restrict __result)
133 _GL_ARG_NONNULL ((1, 2)));
134# endif
135_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
136 struct tm *restrict __result));
137# endif
138_GL_CXXALIASWARN (localtime_r);
139# if @REPLACE_LOCALTIME_R@
140# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
141# undef gmtime_r
142# define gmtime_r rpl_gmtime_r
143# endif
144_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
145 struct tm *restrict __result)
146 _GL_ARG_NONNULL ((1, 2)));
147_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
148 struct tm *restrict __result));
149# else
150# if ! @HAVE_LOCALTIME_R@
151_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
152 struct tm *restrict __result)
153 _GL_ARG_NONNULL ((1, 2)));
154# endif
155_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
156 struct tm *restrict __result));
157# endif
158_GL_CXXALIASWARN (gmtime_r);
81# endif 159# endif
82 160
83/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store 161/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
84 the resulting broken-down time into TM. See 162 the resulting broken-down time into TM. See
85 <http://www.opengroup.org/susv3xsh/strptime.html>. */ 163 <http://www.opengroup.org/susv3xsh/strptime.html>. */
86# if @REPLACE_STRPTIME@ 164# if @GNULIB_STRPTIME@
87# undef strptime 165# if ! @HAVE_STRPTIME@
88# define strptime rpl_strptime 166_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
89char *strptime (char const *restrict __buf, char const *restrict __format, 167 char const *restrict __format,
90 struct tm *restrict __tm); 168 struct tm *restrict __tm)
169 _GL_ARG_NONNULL ((1, 2, 3)));
170# endif
171_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
172 char const *restrict __format,
173 struct tm *restrict __tm));
174_GL_CXXALIASWARN (strptime);
91# endif 175# endif
92 176
93/* Convert TM to a time_t value, assuming UTC. */ 177/* Convert TM to a time_t value, assuming UTC. */
94# if @REPLACE_TIMEGM@ 178# if @GNULIB_TIMEGM@
95# undef timegm 179# if @REPLACE_TIMEGM@
96# define timegm rpl_timegm 180# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
97time_t timegm (struct tm *__tm); 181# undef timegm
182# define timegm rpl_timegm
183# endif
184_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
185_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
186# else
187# if ! @HAVE_TIMEGM@
188_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
189# endif
190_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
191# endif
192_GL_CXXALIASWARN (timegm);
98# endif 193# endif
99 194
100/* Encourage applications to avoid unsafe functions that can overrun 195/* Encourage applications to avoid unsafe functions that can overrun
101 buffers when given outlandish struct tm values. Portable 196 buffers when given outlandish struct tm values. Portable
102 applications should use strftime (or even sprintf) instead. */ 197 applications should use strftime (or even sprintf) instead. */
103# if GNULIB_PORTCHECK 198# if defined GNULIB_POSIXCHECK
104# undef asctime 199# undef asctime
105# define asctime eschew_asctime 200_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
201 "better use strftime (or even sprintf) instead");
202# endif
203# if defined GNULIB_POSIXCHECK
106# undef asctime_r 204# undef asctime_r
107# define asctime_r eschew_asctime_r 205_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
206 "better use strftime (or even sprintf) instead");
207# endif
208# if defined GNULIB_POSIXCHECK
108# undef ctime 209# undef ctime
109# define ctime eschew_ctime 210_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
110# undef ctime_r 211 "better use strftime (or even sprintf) instead");
111# define ctime_r eschew_ctime_r
112# endif 212# endif
113 213# if defined GNULIB_POSIXCHECK
114# ifdef __cplusplus 214# undef ctime_r
115} 215_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
216 "better use strftime (or even sprintf) instead");
116# endif 217# endif
117 218
118#endif 219#endif
diff --git a/gl/time_r.c b/gl/time_r.c
index d610e7fe..3b2b3e94 100644
--- a/gl/time_r.c
+++ b/gl/time_r.c
@@ -1,6 +1,6 @@
1/* Reentrant time functions like localtime_r. 1/* Reentrant time functions like localtime_r.
2 2
3 Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2006-2007, 2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -22,8 +22,6 @@
22 22
23#include <time.h> 23#include <time.h>
24 24
25#include <string.h>
26
27static struct tm * 25static struct tm *
28copy_tm_result (struct tm *dest, struct tm const *src) 26copy_tm_result (struct tm *dest, struct tm const *src)
29{ 27{
diff --git a/gl/timegm.c b/gl/timegm.c
index 057f6459..e484dddf 100644
--- a/gl/timegm.c
+++ b/gl/timegm.c
@@ -1,6 +1,6 @@
1/* Convert UTC calendar time to simple time. Like mktime but assumes UTC. 1/* Convert UTC calendar time to simple time. Like mktime but assumes UTC.
2 2
3 Copyright (C) 1994, 1997, 2003, 2004, 2006, 2007 Free Software 3 Copyright (C) 1994, 1997, 2003, 2004, 2006, 2007, 2009, 2010 Free Software
4 Foundation, Inc. This file is part of the GNU C Library. 4 Foundation, Inc. This file is part of the GNU C Library.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
@@ -27,9 +27,7 @@
27# undef __gmtime_r 27# undef __gmtime_r
28# define __gmtime_r gmtime_r 28# define __gmtime_r gmtime_r
29# define __mktime_internal mktime_internal 29# define __mktime_internal mktime_internal
30time_t __mktime_internal (struct tm *, 30# include "mktime-internal.h"
31 struct tm * (*) (time_t const *, struct tm *),
32 time_t *);
33#endif 31#endif
34 32
35time_t 33time_t
diff --git a/gl/unistd--.h b/gl/unistd--.h
index 1a7fd785..5283d2c5 100644
--- a/gl/unistd--.h
+++ b/gl/unistd--.h
@@ -1,6 +1,6 @@
1/* Like unistd.h, but redefine some names to avoid glitches. 1/* Like unistd.h, but redefine some names to avoid glitches.
2 2
3 Copyright (C) 2005 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -25,3 +25,8 @@
25 25
26#undef pipe 26#undef pipe
27#define pipe pipe_safer 27#define pipe pipe_safer
28
29#if GNULIB_PIPE2_SAFER
30# undef pipe2
31# define pipe2 pipe2_safer
32#endif
diff --git a/gl/unistd-safer.h b/gl/unistd-safer.h
index 033e857d..190f1086 100644
--- a/gl/unistd-safer.h
+++ b/gl/unistd-safer.h
@@ -1,6 +1,6 @@
1/* Invoke unistd-like functions, but avoid some glitches. 1/* Invoke unistd-like functions, but avoid some glitches.
2 2
3 Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. 3 Copyright (C) 2001, 2003, 2005, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -15,8 +15,17 @@
15 You should have received a copy of the GNU General Public License 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/>. */ 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 17
18/* Written by Paul Eggert. */ 18/* Written by Paul Eggert and Eric Blake. */
19 19
20int dup_safer (int); 20int dup_safer (int);
21int fd_safer (int); 21int fd_safer (int);
22int pipe_safer (int[2]); 22int pipe_safer (int[2]);
23
24#if GNULIB_FD_SAFER_FLAG
25int dup_safer_flag (int, int);
26int fd_safer_flag (int, int);
27#endif
28
29#if GNULIB_PIPE2_SAFER
30int pipe2_safer (int[2], int);
31#endif
diff --git a/gl/unistd.in.h b/gl/unistd.in.h
index fa8d84a3..45fc5dcf 100644
--- a/gl/unistd.in.h
+++ b/gl/unistd.in.h
@@ -1,5 +1,5 @@
1/* Substitute for and wrapper around <unistd.h>. 1/* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2009 Free Software Foundation, Inc. 2 Copyright (C) 2003-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -15,77 +15,171 @@
15 along with this program; if not, write to the Free Software Foundation, 15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 17
18#ifndef _GL_UNISTD_H
19
20#if __GNUC__ >= 3 18#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@ 19@PRAGMA_SYSTEM_HEADER@
22#endif 20#endif
23 21
22/* Special invocation convention:
23 - On mingw, several headers, including <winsock2.h>, include <unistd.h>,
24 but we need to ensure that both the system <unistd.h> and <winsock2.h>
25 are completely included before we replace gethostname. */
26#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
27 && !defined _GL_WINSOCK2_H_WITNESS && defined _WINSOCK2_H
28/* <unistd.h> is being indirectly included for the first time from
29 <winsock2.h>; avoid declaring any overrides. */
30# if @HAVE_UNISTD_H@
31# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
32# else
33# error unexpected; report this to bug-gnulib@gnu.org
34# endif
35# define _GL_WINSOCK2_H_WITNESS
36
37/* Normal invocation. */
38#elif !defined _GL_UNISTD_H
39
24/* The include_next requires a split double-inclusion guard. */ 40/* The include_next requires a split double-inclusion guard. */
25#if @HAVE_UNISTD_H@ 41#if @HAVE_UNISTD_H@
26# @INCLUDE_NEXT@ @NEXT_UNISTD_H@ 42# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
27#endif 43#endif
28 44
29#ifndef _GL_UNISTD_H 45/* Get all possible declarations of gethostname(). */
46#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
47 && !defined _GL_INCLUDING_WINSOCK2_H
48# define _GL_INCLUDING_WINSOCK2_H
49# include <winsock2.h>
50# undef _GL_INCLUDING_WINSOCK2_H
51#endif
52
53#if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
30#define _GL_UNISTD_H 54#define _GL_UNISTD_H
31 55
56/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
57#include <stddef.h>
58
32/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */ 59/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
33#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) 60/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
61/* But avoid namespace pollution on glibc systems. */
62#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
63 || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \
64 && ! defined __GLIBC__
34# include <stdio.h> 65# include <stdio.h>
35#endif 66#endif
36 67
68/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
69/* But avoid namespace pollution on glibc systems. */
70#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__
71# include <fcntl.h>
72#endif
73
37/* mingw fails to declare _exit in <unistd.h>. */ 74/* mingw fails to declare _exit in <unistd.h>. */
38/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */ 75/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
39#include <stdlib.h> 76/* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
77/* But avoid namespace pollution on glibc systems. */
78#ifndef __GLIBC__
79# include <stdlib.h>
80#endif
40 81
41#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@ 82/* mingw declares getcwd in <io.h>, not in <unistd.h>. */
83#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
84 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
85# include <io.h>
86#endif
87
88#if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
89 || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK)
42/* Get ssize_t. */ 90/* Get ssize_t. */
43# include <sys/types.h> 91# include <sys/types.h>
44#endif 92#endif
45 93
94/* Get getopt(), optarg, optind, opterr, optopt.
95 But avoid namespace pollution on glibc systems. */
96#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
97# include <getopt.h>
98#endif
99
100/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
101
102/* The definition of _GL_ARG_NONNULL is copied here. */
103
104/* The definition of _GL_WARN_ON_USE is copied here. */
105
106
46#if @GNULIB_GETHOSTNAME@ 107#if @GNULIB_GETHOSTNAME@
47/* Get all possible declarations of gethostname(). */ 108/* Get all possible declarations of gethostname(). */
48# if @UNISTD_H_HAVE_WINSOCK2_H@ 109# if @UNISTD_H_HAVE_WINSOCK2_H@
49# include <winsock2.h>
50# if !defined _GL_SYS_SOCKET_H 110# if !defined _GL_SYS_SOCKET_H
51# undef socket 111# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
52# define socket socket_used_without_including_sys_socket_h 112# undef socket
53# undef connect 113# define socket socket_used_without_including_sys_socket_h
54# define connect connect_used_without_including_sys_socket_h 114# undef connect
55# undef accept 115# define connect connect_used_without_including_sys_socket_h
56# define accept accept_used_without_including_sys_socket_h 116# undef accept
57# undef bind 117# define accept accept_used_without_including_sys_socket_h
58# define bind bind_used_without_including_sys_socket_h 118# undef bind
59# undef getpeername 119# define bind bind_used_without_including_sys_socket_h
60# define getpeername getpeername_used_without_including_sys_socket_h 120# undef getpeername
61# undef getsockname 121# define getpeername getpeername_used_without_including_sys_socket_h
62# define getsockname getsockname_used_without_including_sys_socket_h 122# undef getsockname
63# undef getsockopt 123# define getsockname getsockname_used_without_including_sys_socket_h
64# define getsockopt getsockopt_used_without_including_sys_socket_h 124# undef getsockopt
65# undef listen 125# define getsockopt getsockopt_used_without_including_sys_socket_h
66# define listen listen_used_without_including_sys_socket_h 126# undef listen
67# undef recv 127# define listen listen_used_without_including_sys_socket_h
68# define recv recv_used_without_including_sys_socket_h 128# undef recv
69# undef send 129# define recv recv_used_without_including_sys_socket_h
70# define send send_used_without_including_sys_socket_h 130# undef send
71# undef recvfrom 131# define send send_used_without_including_sys_socket_h
72# define recvfrom recvfrom_used_without_including_sys_socket_h 132# undef recvfrom
73# undef sendto 133# define recvfrom recvfrom_used_without_including_sys_socket_h
74# define sendto sendto_used_without_including_sys_socket_h 134# undef sendto
75# undef setsockopt 135# define sendto sendto_used_without_including_sys_socket_h
76# define setsockopt setsockopt_used_without_including_sys_socket_h 136# undef setsockopt
77# undef shutdown 137# define setsockopt setsockopt_used_without_including_sys_socket_h
78# define shutdown shutdown_used_without_including_sys_socket_h 138# undef shutdown
139# define shutdown shutdown_used_without_including_sys_socket_h
140# else
141 _GL_WARN_ON_USE (socket,
142 "socket() used without including <sys/socket.h>");
143 _GL_WARN_ON_USE (connect,
144 "connect() used without including <sys/socket.h>");
145 _GL_WARN_ON_USE (accept,
146 "accept() used without including <sys/socket.h>");
147 _GL_WARN_ON_USE (bind,
148 "bind() used without including <sys/socket.h>");
149 _GL_WARN_ON_USE (getpeername,
150 "getpeername() used without including <sys/socket.h>");
151 _GL_WARN_ON_USE (getsockname,
152 "getsockname() used without including <sys/socket.h>");
153 _GL_WARN_ON_USE (getsockopt,
154 "getsockopt() used without including <sys/socket.h>");
155 _GL_WARN_ON_USE (listen,
156 "listen() used without including <sys/socket.h>");
157 _GL_WARN_ON_USE (recv,
158 "recv() used without including <sys/socket.h>");
159 _GL_WARN_ON_USE (send,
160 "send() used without including <sys/socket.h>");
161 _GL_WARN_ON_USE (recvfrom,
162 "recvfrom() used without including <sys/socket.h>");
163 _GL_WARN_ON_USE (sendto,
164 "sendto() used without including <sys/socket.h>");
165 _GL_WARN_ON_USE (setsockopt,
166 "setsockopt() used without including <sys/socket.h>");
167 _GL_WARN_ON_USE (shutdown,
168 "shutdown() used without including <sys/socket.h>");
169# endif
79# endif 170# endif
80# if !defined _GL_SYS_SELECT_H 171# if !defined _GL_SYS_SELECT_H
81# undef select 172# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
82# define select select_used_without_including_sys_select_h 173# undef select
174# define select select_used_without_including_sys_select_h
175# else
176 _GL_WARN_ON_USE (select,
177 "select() used without including <sys/select.h>");
178# endif
83# endif 179# endif
84# endif 180# endif
85#endif 181#endif
86 182
87/* The definition of GL_LINK_WARNING is copied here. */
88
89 183
90/* OS/2 EMX lacks these macros. */ 184/* OS/2 EMX lacks these macros. */
91#ifndef STDIN_FILENO 185#ifndef STDIN_FILENO
@@ -98,72 +192,147 @@
98# define STDERR_FILENO 2 192# define STDERR_FILENO 2
99#endif 193#endif
100 194
195/* Ensure *_OK macros exist. */
196#ifndef F_OK
197# define F_OK 0
198# define X_OK 1
199# define W_OK 2
200# define R_OK 4
201#endif
202
203
101/* Declare overridden functions. */ 204/* Declare overridden functions. */
102 205
103#ifdef __cplusplus 206
104extern "C" { 207#if defined GNULIB_POSIXCHECK
208/* The access() function is a security risk. */
209_GL_WARN_ON_USE (access, "the access function is a security risk - "
210 "use the gnulib module faccessat instead");
105#endif 211#endif
106 212
107 213
108#if @GNULIB_CHOWN@ 214#if @GNULIB_CHOWN@
109# if @REPLACE_CHOWN@
110# ifndef REPLACE_CHOWN
111# define REPLACE_CHOWN 1
112# endif
113# if REPLACE_CHOWN
114/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE 215/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
115 to GID (if GID is not -1). Follow symbolic links. 216 to GID (if GID is not -1). Follow symbolic links.
116 Return 0 if successful, otherwise -1 and errno set. 217 Return 0 if successful, otherwise -1 and errno set.
117 See the POSIX:2001 specification 218 See the POSIX:2001 specification
118 <http://www.opengroup.org/susv3xsh/chown.html>. */ 219 <http://www.opengroup.org/susv3xsh/chown.html>. */
220# if @REPLACE_CHOWN@
221# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
222# undef chown
119# define chown rpl_chown 223# define chown rpl_chown
120extern int chown (const char *file, uid_t uid, gid_t gid);
121# endif 224# endif
225_GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
226 _GL_ARG_NONNULL ((1)));
227_GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
228# else
229# if !@HAVE_CHOWN@
230_GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
231 _GL_ARG_NONNULL ((1)));
232# endif
233_GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
122# endif 234# endif
235_GL_CXXALIASWARN (chown);
123#elif defined GNULIB_POSIXCHECK 236#elif defined GNULIB_POSIXCHECK
124# undef chown 237# undef chown
125# define chown(f,u,g) \ 238# if HAVE_RAW_DECL_CHOWN
126 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \ 239_GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
127 "doesn't treat a uid or gid of -1 on some systems - " \ 240 "doesn't treat a uid or gid of -1 on some systems - "
128 "use gnulib module chown for portability"), \ 241 "use gnulib module chown for portability");
129 chown (f, u, g)) 242# endif
130#endif 243#endif
131 244
132 245
133#if @GNULIB_CLOSE@ 246#if @GNULIB_CLOSE@
134# if @REPLACE_CLOSE@ 247# if @REPLACE_CLOSE@
135/* Automatically included by modules that need a replacement for close. */ 248/* Automatically included by modules that need a replacement for close. */
136# undef close 249# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
137# define close rpl_close 250# undef close
138extern int close (int); 251# define close rpl_close
252# endif
253_GL_FUNCDECL_RPL (close, int, (int fd));
254_GL_CXXALIAS_RPL (close, int, (int fd));
255# else
256_GL_CXXALIAS_SYS (close, int, (int fd));
139# endif 257# endif
140#elif @UNISTD_H_HAVE_WINSOCK2_H@ 258_GL_CXXALIASWARN (close);
259#elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
141# undef close 260# undef close
142# define close close_used_without_requesting_gnulib_module_close 261# define close close_used_without_requesting_gnulib_module_close
143#elif defined GNULIB_POSIXCHECK 262#elif defined GNULIB_POSIXCHECK
144# undef close 263# undef close
145# define close(f) \ 264/* Assume close is always declared. */
146 (GL_LINK_WARNING ("close does not portably work on sockets - " \ 265_GL_WARN_ON_USE (close, "close does not portably work on sockets - "
147 "use gnulib module close for portability"), \ 266 "use gnulib module close for portability");
148 close (f)) 267#endif
268
269
270#if @REPLACE_DUP@
271# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
272# define dup rpl_dup
273# endif
274_GL_FUNCDECL_RPL (dup, int, (int oldfd));
275_GL_CXXALIAS_RPL (dup, int, (int oldfd));
276#else
277_GL_CXXALIAS_SYS (dup, int, (int oldfd));
149#endif 278#endif
279_GL_CXXALIASWARN (dup);
150 280
151 281
152#if @GNULIB_DUP2@ 282#if @GNULIB_DUP2@
153# if !@HAVE_DUP2@
154/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if 283/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
155 NEWFD = OLDFD, otherwise close NEWFD first if it is open. 284 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
156 Return 0 if successful, otherwise -1 and errno set. 285 Return newfd if successful, otherwise -1 and errno set.
157 See the POSIX:2001 specification 286 See the POSIX:2001 specification
158 <http://www.opengroup.org/susv3xsh/dup2.html>. */ 287 <http://www.opengroup.org/susv3xsh/dup2.html>. */
159extern int dup2 (int oldfd, int newfd); 288# if @REPLACE_DUP2@
289# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
290# define dup2 rpl_dup2
291# endif
292_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
293_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
294# else
295# if !@HAVE_DUP2@
296_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
297# endif
298_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
160# endif 299# endif
300_GL_CXXALIASWARN (dup2);
161#elif defined GNULIB_POSIXCHECK 301#elif defined GNULIB_POSIXCHECK
162# undef dup2 302# undef dup2
163# define dup2(o,n) \ 303# if HAVE_RAW_DECL_DUP2
164 (GL_LINK_WARNING ("dup2 is unportable - " \ 304_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
165 "use gnulib module dup2 for portability"), \ 305 "use gnulib module dup2 for portability");
166 dup2 (o, n)) 306# endif
307#endif
308
309
310#if @GNULIB_DUP3@
311/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
312 specified flags.
313 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
314 and O_TEXT, O_BINARY (defined in "binary-io.h").
315 Close NEWFD first if it is open.
316 Return newfd if successful, otherwise -1 and errno set.
317 See the Linux man page at
318 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
319# if @HAVE_DUP3@
320# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
321# define dup3 rpl_dup3
322# endif
323_GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
324_GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
325# else
326_GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
327_GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
328# endif
329_GL_CXXALIASWARN (dup3);
330#elif defined GNULIB_POSIXCHECK
331# undef dup3
332# if HAVE_RAW_DECL_DUP3
333_GL_WARN_ON_USE (dup3, "dup3 is unportable - "
334 "use gnulib module dup3 for portability");
335# endif
167#endif 336#endif
168 337
169 338
@@ -175,55 +344,126 @@ extern int dup2 (int oldfd, int newfd);
175# include <crt_externs.h> 344# include <crt_externs.h>
176# define environ (*_NSGetEnviron ()) 345# define environ (*_NSGetEnviron ())
177# else 346# else
347# ifdef __cplusplus
348extern "C" {
349# endif
178extern char **environ; 350extern char **environ;
351# ifdef __cplusplus
352}
353# endif
179# endif 354# endif
180# endif 355# endif
181#elif defined GNULIB_POSIXCHECK 356#elif defined GNULIB_POSIXCHECK
182# undef environ 357# if HAVE_RAW_DECL_ENVIRON
183# define environ \ 358static inline char ***
184 (GL_LINK_WARNING ("environ is unportable - " \ 359rpl_environ (void)
185 "use gnulib module environ for portability"), \ 360{
186 environ) 361 return &environ;
362}
363_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
364 "use gnulib module environ for portability");
365# undef environ
366# define environ (*rpl_environ ())
367# endif
187#endif 368#endif
188 369
189 370
190#if @GNULIB_EUIDACCESS@ 371#if @GNULIB_EUIDACCESS@
191# if !@HAVE_EUIDACCESS@ 372/* Like access(), except that it uses the effective user id and group id of
192/* Like access(), except that is uses the effective user id and group id of
193 the current process. */ 373 the current process. */
194extern int euidaccess (const char *filename, int mode); 374# if !@HAVE_EUIDACCESS@
375_GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
376 _GL_ARG_NONNULL ((1)));
377# endif
378_GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
379_GL_CXXALIASWARN (euidaccess);
380# if defined GNULIB_POSIXCHECK
381/* Like access(), this function is a security risk. */
382_GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
383 "use the gnulib module faccessat instead");
195# endif 384# endif
196#elif defined GNULIB_POSIXCHECK 385#elif defined GNULIB_POSIXCHECK
197# undef euidaccess 386# undef euidaccess
198# define euidaccess(f,m) \ 387# if HAVE_RAW_DECL_EUIDACCESS
199 (GL_LINK_WARNING ("euidaccess is unportable - " \ 388_GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
200 "use gnulib module euidaccess for portability"), \ 389 "use gnulib module euidaccess for portability");
201 euidaccess (f, m)) 390# endif
202#endif 391#endif
203 392
204 393
205#if @GNULIB_FCHDIR@ 394#if @GNULIB_FACCESSAT@
206# if @REPLACE_FCHDIR@ 395# if !@HAVE_FACCESSAT@
396_GL_FUNCDECL_SYS (faccessat, int,
397 (int fd, char const *file, int mode, int flag)
398 _GL_ARG_NONNULL ((2)));
399# endif
400_GL_CXXALIAS_SYS (faccessat, int,
401 (int fd, char const *file, int mode, int flag));
402_GL_CXXALIASWARN (faccessat);
403#elif defined GNULIB_POSIXCHECK
404# undef faccessat
405# if HAVE_RAW_DECL_FACCESSAT
406_GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
407 "use gnulib module faccessat for portability");
408# endif
409#endif
207 410
411
412#if @GNULIB_FCHDIR@
208/* Change the process' current working directory to the directory on which 413/* Change the process' current working directory to the directory on which
209 the given file descriptor is open. 414 the given file descriptor is open.
210 Return 0 if successful, otherwise -1 and errno set. 415 Return 0 if successful, otherwise -1 and errno set.
211 See the POSIX:2001 specification 416 See the POSIX:2001 specification
212 <http://www.opengroup.org/susv3xsh/fchdir.html>. */ 417 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
213extern int fchdir (int /*fd*/); 418# if ! @HAVE_FCHDIR@
419_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
214 420
215# define dup rpl_dup 421/* Gnulib internal hooks needed to maintain the fchdir metadata. */
216extern int dup (int); 422_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
217# define dup2 rpl_dup2 423 _GL_ARG_NONNULL ((2));
218extern int dup2 (int, int); 424_GL_EXTERN_C void _gl_unregister_fd (int fd);
425_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
426_GL_EXTERN_C const char *_gl_directory_name (int fd);
219 427
220# endif 428# endif
429_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
430_GL_CXXALIASWARN (fchdir);
221#elif defined GNULIB_POSIXCHECK 431#elif defined GNULIB_POSIXCHECK
222# undef fchdir 432# undef fchdir
223# define fchdir(f) \ 433# if HAVE_RAW_DECL_FCHDIR
224 (GL_LINK_WARNING ("fchdir is unportable - " \ 434_GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
225 "use gnulib module fchdir for portability"), \ 435 "use gnulib module fchdir for portability");
226 fchdir (f)) 436# endif
437#endif
438
439
440#if @GNULIB_FCHOWNAT@
441# if @REPLACE_FCHOWNAT@
442# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
443# undef fchownat
444# define fchownat rpl_fchownat
445# endif
446_GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
447 uid_t owner, gid_t group, int flag)
448 _GL_ARG_NONNULL ((2)));
449_GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
450 uid_t owner, gid_t group, int flag));
451# else
452# if !@HAVE_FCHOWNAT@
453_GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
454 uid_t owner, gid_t group, int flag)
455 _GL_ARG_NONNULL ((2)));
456# endif
457_GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
458 uid_t owner, gid_t group, int flag));
459# endif
460_GL_CXXALIASWARN (fchownat);
461#elif defined GNULIB_POSIXCHECK
462# undef fchownat
463# if HAVE_RAW_DECL_FCHOWNAT
464_GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
465 "use gnulib module openat for portability");
466# endif
227#endif 467#endif
228 468
229 469
@@ -233,39 +473,39 @@ extern int dup2 (int, int);
233 See POSIX:2001 specification 473 See POSIX:2001 specification
234 <http://www.opengroup.org/susv3xsh/fsync.html>. */ 474 <http://www.opengroup.org/susv3xsh/fsync.html>. */
235# if !@HAVE_FSYNC@ 475# if !@HAVE_FSYNC@
236extern int fsync (int fd); 476_GL_FUNCDECL_SYS (fsync, int, (int fd));
237# endif 477# endif
478_GL_CXXALIAS_SYS (fsync, int, (int fd));
479_GL_CXXALIASWARN (fsync);
238#elif defined GNULIB_POSIXCHECK 480#elif defined GNULIB_POSIXCHECK
239# undef fsync 481# undef fsync
240# define fsync(fd) \ 482# if HAVE_RAW_DECL_FSYNC
241 (GL_LINK_WARNING ("fsync is unportable - " \ 483_GL_WARN_ON_USE (fsync, "fsync is unportable - "
242 "use gnulib module fsync for portability"), \ 484 "use gnulib module fsync for portability");
243 fsync (fd)) 485# endif
244#endif 486#endif
245 487
246 488
247#if @GNULIB_FTRUNCATE@ 489#if @GNULIB_FTRUNCATE@
248# if !@HAVE_FTRUNCATE@
249/* Change the size of the file to which FD is opened to become equal to LENGTH. 490/* Change the size of the file to which FD is opened to become equal to LENGTH.
250 Return 0 if successful, otherwise -1 and errno set. 491 Return 0 if successful, otherwise -1 and errno set.
251 See the POSIX:2001 specification 492 See the POSIX:2001 specification
252 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */ 493 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
253extern int ftruncate (int fd, off_t length); 494# if !@HAVE_FTRUNCATE@
495_GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
254# endif 496# endif
497_GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
498_GL_CXXALIASWARN (ftruncate);
255#elif defined GNULIB_POSIXCHECK 499#elif defined GNULIB_POSIXCHECK
256# undef ftruncate 500# undef ftruncate
257# define ftruncate(f,l) \ 501# if HAVE_RAW_DECL_FTRUNCATE
258 (GL_LINK_WARNING ("ftruncate is unportable - " \ 502_GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
259 "use gnulib module ftruncate for portability"), \ 503 "use gnulib module ftruncate for portability");
260 ftruncate (f, l)) 504# endif
261#endif 505#endif
262 506
263 507
264#if @GNULIB_GETCWD@ 508#if @GNULIB_GETCWD@
265/* Include the headers that might declare getcwd so that they will not
266 cause confusion if included after this file. */
267# include <stdlib.h>
268# if @REPLACE_GETCWD@
269/* Get the name of the current working directory, and put it in SIZE bytes 509/* Get the name of the current working directory, and put it in SIZE bytes
270 of BUF. 510 of BUF.
271 Return BUF if successful, or NULL if the directory couldn't be determined 511 Return BUF if successful, or NULL if the directory couldn't be determined
@@ -276,15 +516,24 @@ extern int ftruncate (int fd, off_t length);
276 extension: If BUF is NULL, an array is allocated with 'malloc'; the array 516 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
277 is SIZE bytes long, unless SIZE == 0, in which case it is as big as 517 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
278 necessary. */ 518 necessary. */
279# define getcwd rpl_getcwd 519# if @REPLACE_GETCWD@
280extern char * getcwd (char *buf, size_t size); 520# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
521# define getcwd rpl_getcwd
522# endif
523_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
524_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
525# else
526/* Need to cast, because on mingw, the second parameter is
527 int size. */
528_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
281# endif 529# endif
530_GL_CXXALIASWARN (getcwd);
282#elif defined GNULIB_POSIXCHECK 531#elif defined GNULIB_POSIXCHECK
283# undef getcwd 532# undef getcwd
284# define getcwd(b,s) \ 533# if HAVE_RAW_DECL_GETCWD
285 (GL_LINK_WARNING ("getcwd is unportable - " \ 534_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
286 "use gnulib module getcwd for portability"), \ 535 "use gnulib module getcwd for portability");
287 getcwd (b, s)) 536# endif
288#endif 537#endif
289 538
290 539
@@ -300,28 +549,65 @@ extern char * getcwd (char *buf, size_t size);
300 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1. 549 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
301 Return 0 if successful, otherwise set errno and return -1. */ 550 Return 0 if successful, otherwise set errno and return -1. */
302# if !@HAVE_GETDOMAINNAME@ 551# if !@HAVE_GETDOMAINNAME@
303extern int getdomainname(char *name, size_t len); 552_GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
553 _GL_ARG_NONNULL ((1)));
304# endif 554# endif
555/* Need to cast, because on MacOS X 10.5 systems, the second parameter is
556 int len. */
557_GL_CXXALIAS_SYS_CAST (getdomainname, int, (char *name, size_t len));
558_GL_CXXALIASWARN (getdomainname);
305#elif defined GNULIB_POSIXCHECK 559#elif defined GNULIB_POSIXCHECK
306# undef getdomainname 560# undef getdomainname
307# define getdomainname(n,l) \ 561# if HAVE_RAW_DECL_GETDOMAINNAME
308 (GL_LINK_WARNING ("getdomainname is unportable - " \ 562_GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
309 "use gnulib module getdomainname for portability"), \ 563 "use gnulib module getdomainname for portability");
310 getdomainname (n, l)) 564# endif
311#endif 565#endif
312 566
313 567
314#if @GNULIB_GETDTABLESIZE@ 568#if @GNULIB_GETDTABLESIZE@
569/* Return the maximum number of file descriptors in the current process.
570 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
315# if !@HAVE_GETDTABLESIZE@ 571# if !@HAVE_GETDTABLESIZE@
316/* Return the maximum number of file descriptors in the current process. */ 572_GL_FUNCDECL_SYS (getdtablesize, int, (void));
317extern int getdtablesize (void);
318# endif 573# endif
574_GL_CXXALIAS_SYS (getdtablesize, int, (void));
575_GL_CXXALIASWARN (getdtablesize);
319#elif defined GNULIB_POSIXCHECK 576#elif defined GNULIB_POSIXCHECK
320# undef getdtablesize 577# undef getdtablesize
321# define getdtablesize() \ 578# if HAVE_RAW_DECL_GETDTABLESIZE
322 (GL_LINK_WARNING ("getdtablesize is unportable - " \ 579_GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
323 "use gnulib module getdtablesize for portability"), \ 580 "use gnulib module getdtablesize for portability");
324 getdtablesize ()) 581# endif
582#endif
583
584
585#if @GNULIB_GETGROUPS@
586/* Return the supplemental groups that the current process belongs to.
587 It is unspecified whether the effective group id is in the list.
588 If N is 0, return the group count; otherwise, N describes how many
589 entries are available in GROUPS. Return -1 and set errno if N is
590 not 0 and not large enough. Fails with ENOSYS on some systems. */
591# if @REPLACE_GETGROUPS@
592# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
593# undef getgroups
594# define getgroups rpl_getgroups
595# endif
596_GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
597_GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
598# else
599# if !@HAVE_GETGROUPS@
600_GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
601# endif
602_GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
603# endif
604_GL_CXXALIASWARN (getgroups);
605#elif defined GNULIB_POSIXCHECK
606# undef getgroups
607# if HAVE_RAW_DECL_GETGROUPS
608_GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
609 "use gnulib module getgroups for portability");
610# endif
325#endif 611#endif
326 612
327 613
@@ -334,21 +620,57 @@ extern int getdtablesize (void);
334 If the host name is longer than LEN, set errno = EINVAL and return -1. 620 If the host name is longer than LEN, set errno = EINVAL and return -1.
335 Return 0 if successful, otherwise set errno and return -1. */ 621 Return 0 if successful, otherwise set errno and return -1. */
336# if @UNISTD_H_HAVE_WINSOCK2_H@ 622# if @UNISTD_H_HAVE_WINSOCK2_H@
337# undef gethostname 623# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
338# define gethostname rpl_gethostname 624# undef gethostname
339# endif 625# define gethostname rpl_gethostname
340# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@ 626# endif
341extern int gethostname(char *name, size_t len); 627_GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
628 _GL_ARG_NONNULL ((1)));
629_GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
630# else
631# if !@HAVE_GETHOSTNAME@
632_GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
633 _GL_ARG_NONNULL ((1)));
634# endif
635/* Need to cast, because on Solaris 10 systems, the second parameter is
636 int len. */
637_GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
342# endif 638# endif
639_GL_CXXALIASWARN (gethostname);
343#elif @UNISTD_H_HAVE_WINSOCK2_H@ 640#elif @UNISTD_H_HAVE_WINSOCK2_H@
344# undef gethostname 641# undef gethostname
345# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname 642# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
346#elif defined GNULIB_POSIXCHECK 643#elif defined GNULIB_POSIXCHECK
347# undef gethostname 644# undef gethostname
348# define gethostname(n,l) \ 645# if HAVE_RAW_DECL_GETHOSTNAME
349 (GL_LINK_WARNING ("gethostname is unportable - " \ 646_GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
350 "use gnulib module gethostname for portability"), \ 647 "use gnulib module gethostname for portability");
351 gethostname (n, l)) 648# endif
649#endif
650
651
652#if @GNULIB_GETLOGIN@
653/* Returns the user's login name, or NULL if it cannot be found. Upon error,
654 returns NULL with errno set.
655
656 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
657
658 Most programs don't need to use this function, because the information is
659 available through environment variables:
660 ${LOGNAME-$USER} on Unix platforms,
661 $USERNAME on native Windows platforms.
662 */
663# if !@HAVE_GETLOGIN@
664_GL_FUNCDECL_SYS (getlogin, char *, (void));
665# endif
666_GL_CXXALIAS_SYS (getlogin, char *, (void));
667_GL_CXXALIASWARN (getlogin);
668#elif defined GNULIB_POSIXCHECK
669# undef getlogin
670# if HAVE_RAW_DECL_GETLOGIN
671_GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
672 "use gnulib module getlogin for portability");
673# endif
352#endif 674#endif
353 675
354 676
@@ -361,124 +683,184 @@ extern int gethostname(char *name, size_t len);
361 provided (this case is hopefully rare but is left open by the POSIX spec). 683 provided (this case is hopefully rare but is left open by the POSIX spec).
362 684
363 See <http://www.opengroup.org/susv3xsh/getlogin.html>. 685 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
686
687 Most programs don't need to use this function, because the information is
688 available through environment variables:
689 ${LOGNAME-$USER} on Unix platforms,
690 $USERNAME on native Windows platforms.
364 */ 691 */
365# if !@HAVE_DECL_GETLOGIN_R@ 692# if !@HAVE_DECL_GETLOGIN_R@
366# include <stddef.h> 693_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
367extern int getlogin_r (char *name, size_t size); 694 _GL_ARG_NONNULL ((1)));
368# endif 695# endif
696/* Need to cast, because on Solaris 10 systems, the second argument is
697 int size. */
698_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
699_GL_CXXALIASWARN (getlogin_r);
369#elif defined GNULIB_POSIXCHECK 700#elif defined GNULIB_POSIXCHECK
370# undef getlogin_r 701# undef getlogin_r
371# define getlogin_r(n,s) \ 702# if HAVE_RAW_DECL_GETLOGIN_R
372 (GL_LINK_WARNING ("getlogin_r is unportable - " \ 703_GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
373 "use gnulib module getlogin_r for portability"), \ 704 "use gnulib module getlogin_r for portability");
374 getlogin_r (n, s)) 705# endif
375#endif 706#endif
376 707
377 708
378#if @GNULIB_GETPAGESIZE@ 709#if @GNULIB_GETPAGESIZE@
379# if @REPLACE_GETPAGESIZE@ 710# if @REPLACE_GETPAGESIZE@
380# define getpagesize rpl_getpagesize 711# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
381extern int getpagesize (void); 712# define getpagesize rpl_getpagesize
382# elif !@HAVE_GETPAGESIZE@
383/* This is for POSIX systems. */
384# if !defined getpagesize && defined _SC_PAGESIZE
385# if ! (defined __VMS && __VMS_VER < 70000000)
386# define getpagesize() sysconf (_SC_PAGESIZE)
387# endif
388# endif 713# endif
714_GL_FUNCDECL_RPL (getpagesize, int, (void));
715_GL_CXXALIAS_RPL (getpagesize, int, (void));
716# else
717# if !@HAVE_GETPAGESIZE@
718# if !defined getpagesize
719/* This is for POSIX systems. */
720# if !defined _gl_getpagesize && defined _SC_PAGESIZE
721# if ! (defined __VMS && __VMS_VER < 70000000)
722# define _gl_getpagesize() sysconf (_SC_PAGESIZE)
723# endif
724# endif
389/* This is for older VMS. */ 725/* This is for older VMS. */
390# if !defined getpagesize && defined __VMS 726# if !defined _gl_getpagesize && defined __VMS
391# ifdef __ALPHA 727# ifdef __ALPHA
392# define getpagesize() 8192 728# define _gl_getpagesize() 8192
393# else 729# else
394# define getpagesize() 512 730# define _gl_getpagesize() 512
395# endif 731# endif
396# endif 732# endif
397/* This is for BeOS. */ 733/* This is for BeOS. */
398# if !defined getpagesize && @HAVE_OS_H@ 734# if !defined _gl_getpagesize && @HAVE_OS_H@
399# include <OS.h> 735# include <OS.h>
400# if defined B_PAGE_SIZE 736# if defined B_PAGE_SIZE
401# define getpagesize() B_PAGE_SIZE 737# define _gl_getpagesize() B_PAGE_SIZE
402# endif 738# endif
403# endif 739# endif
404/* This is for AmigaOS4.0. */ 740/* This is for AmigaOS4.0. */
405# if !defined getpagesize && defined __amigaos4__ 741# if !defined _gl_getpagesize && defined __amigaos4__
406# define getpagesize() 2048 742# define _gl_getpagesize() 2048
407# endif 743# endif
408/* This is for older Unix systems. */ 744/* This is for older Unix systems. */
409# if !defined getpagesize && @HAVE_SYS_PARAM_H@ 745# if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
410# include <sys/param.h> 746# include <sys/param.h>
411# ifdef EXEC_PAGESIZE 747# ifdef EXEC_PAGESIZE
412# define getpagesize() EXEC_PAGESIZE 748# define _gl_getpagesize() EXEC_PAGESIZE
413# else 749# else
414# ifdef NBPG 750# ifdef NBPG
415# ifndef CLSIZE 751# ifndef CLSIZE
416# define CLSIZE 1 752# define CLSIZE 1
753# endif
754# define _gl_getpagesize() (NBPG * CLSIZE)
755# else
756# ifdef NBPC
757# define _gl_getpagesize() NBPC
758# endif
759# endif
417# endif 760# endif
418# define getpagesize() (NBPG * CLSIZE) 761# endif
762# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
763# define getpagesize() _gl_getpagesize ()
419# else 764# else
420# ifdef NBPC 765static inline int
421# define getpagesize() NBPC 766getpagesize ()
422# endif 767{
768 return _gl_getpagesize ();
769}
423# endif 770# endif
424# endif 771# endif
425# endif 772# endif
773/* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
774_GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
775# endif
776# if @HAVE_DECL_GETPAGESIZE@
777_GL_CXXALIASWARN (getpagesize);
426# endif 778# endif
427#elif defined GNULIB_POSIXCHECK 779#elif defined GNULIB_POSIXCHECK
428# undef getpagesize 780# undef getpagesize
429# define getpagesize() \ 781# if HAVE_RAW_DECL_GETPAGESIZE
430 (GL_LINK_WARNING ("getpagesize is unportable - " \ 782_GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
431 "use gnulib module getpagesize for portability"), \ 783 "use gnulib module getpagesize for portability");
432 getpagesize ()) 784# endif
433#endif 785#endif
434 786
435 787
436#if @GNULIB_GETUSERSHELL@ 788#if @GNULIB_GETUSERSHELL@
437# if !@HAVE_GETUSERSHELL@
438/* Return the next valid login shell on the system, or NULL when the end of 789/* Return the next valid login shell on the system, or NULL when the end of
439 the list has been reached. */ 790 the list has been reached. */
440extern char *getusershell (void); 791# if !@HAVE_DECL_GETUSERSHELL@
792_GL_FUNCDECL_SYS (getusershell, char *, (void));
793# endif
794_GL_CXXALIAS_SYS (getusershell, char *, (void));
795_GL_CXXALIASWARN (getusershell);
796#elif defined GNULIB_POSIXCHECK
797# undef getusershell
798# if HAVE_RAW_DECL_GETUSERSHELL
799_GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
800 "use gnulib module getusershell for portability");
801# endif
802#endif
803
804#if @GNULIB_GETUSERSHELL@
441/* Rewind to pointer that is advanced at each getusershell() call. */ 805/* Rewind to pointer that is advanced at each getusershell() call. */
442extern void setusershell (void); 806# if !@HAVE_DECL_GETUSERSHELL@
807_GL_FUNCDECL_SYS (setusershell, void, (void));
808# endif
809_GL_CXXALIAS_SYS (setusershell, void, (void));
810_GL_CXXALIASWARN (setusershell);
811#elif defined GNULIB_POSIXCHECK
812# undef setusershell
813# if HAVE_RAW_DECL_SETUSERSHELL
814_GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
815 "use gnulib module getusershell for portability");
816# endif
817#endif
818
819#if @GNULIB_GETUSERSHELL@
443/* Free the pointer that is advanced at each getusershell() call and 820/* Free the pointer that is advanced at each getusershell() call and
444 associated resources. */ 821 associated resources. */
445extern void endusershell (void); 822# if !@HAVE_DECL_GETUSERSHELL@
823_GL_FUNCDECL_SYS (endusershell, void, (void));
446# endif 824# endif
825_GL_CXXALIAS_SYS (endusershell, void, (void));
826_GL_CXXALIASWARN (endusershell);
447#elif defined GNULIB_POSIXCHECK 827#elif defined GNULIB_POSIXCHECK
448# undef getusershell
449# define getusershell() \
450 (GL_LINK_WARNING ("getusershell is unportable - " \
451 "use gnulib module getusershell for portability"), \
452 getusershell ())
453# undef setusershell
454# define setusershell() \
455 (GL_LINK_WARNING ("setusershell is unportable - " \
456 "use gnulib module getusershell for portability"), \
457 setusershell ())
458# undef endusershell 828# undef endusershell
459# define endusershell() \ 829# if HAVE_RAW_DECL_ENDUSERSHELL
460 (GL_LINK_WARNING ("endusershell is unportable - " \ 830_GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
461 "use gnulib module getusershell for portability"), \ 831 "use gnulib module getusershell for portability");
462 endusershell ()) 832# endif
463#endif 833#endif
464 834
465 835
466#if @GNULIB_LCHOWN@ 836#if @GNULIB_LCHOWN@
467# if @REPLACE_LCHOWN@
468/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE 837/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
469 to GID (if GID is not -1). Do not follow symbolic links. 838 to GID (if GID is not -1). Do not follow symbolic links.
470 Return 0 if successful, otherwise -1 and errno set. 839 Return 0 if successful, otherwise -1 and errno set.
471 See the POSIX:2001 specification 840 See the POSIX:2001 specification
472 <http://www.opengroup.org/susv3xsh/lchown.html>. */ 841 <http://www.opengroup.org/susv3xsh/lchown.html>. */
473# define lchown rpl_lchown 842# if @REPLACE_LCHOWN@
474extern int lchown (char const *file, uid_t owner, gid_t group); 843# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
844# undef lchown
845# define lchown rpl_lchown
846# endif
847_GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
848 _GL_ARG_NONNULL ((1)));
849_GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
850# else
851# if !@HAVE_LCHOWN@
852_GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
853 _GL_ARG_NONNULL ((1)));
854# endif
855_GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
475# endif 856# endif
857_GL_CXXALIASWARN (lchown);
476#elif defined GNULIB_POSIXCHECK 858#elif defined GNULIB_POSIXCHECK
477# undef lchown 859# undef lchown
478# define lchown(f,u,g) \ 860# if HAVE_RAW_DECL_LCHOWN
479 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \ 861_GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
480 "systems - use gnulib module lchown for portability"), \ 862 "use gnulib module lchown for portability");
481 lchown (f, u, g)) 863# endif
482#endif 864#endif
483 865
484 866
@@ -487,33 +869,150 @@ extern int lchown (char const *file, uid_t owner, gid_t group);
487 Return 0 if successful, otherwise -1 and errno set. 869 Return 0 if successful, otherwise -1 and errno set.
488 See POSIX:2001 specification 870 See POSIX:2001 specification
489 <http://www.opengroup.org/susv3xsh/link.html>. */ 871 <http://www.opengroup.org/susv3xsh/link.html>. */
490# if !@HAVE_LINK@ 872# if @REPLACE_LINK@
491extern int link (const char *path1, const char *path2); 873# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
874# define link rpl_link
875# endif
876_GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
877 _GL_ARG_NONNULL ((1, 2)));
878_GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
879# else
880# if !@HAVE_LINK@
881_GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
882 _GL_ARG_NONNULL ((1, 2)));
883# endif
884_GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
492# endif 885# endif
886_GL_CXXALIASWARN (link);
493#elif defined GNULIB_POSIXCHECK 887#elif defined GNULIB_POSIXCHECK
494# undef link 888# undef link
495# define link(path1,path2) \ 889# if HAVE_RAW_DECL_LINK
496 (GL_LINK_WARNING ("link is unportable - " \ 890_GL_WARN_ON_USE (link, "link is unportable - "
497 "use gnulib module link for portability"), \ 891 "use gnulib module link for portability");
498 link (path1, path2)) 892# endif
893#endif
894
895
896#if @GNULIB_LINKAT@
897/* Create a new hard link for an existing file, relative to two
898 directories. FLAG controls whether symlinks are followed.
899 Return 0 if successful, otherwise -1 and errno set. */
900# if @REPLACE_LINKAT@
901# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
902# undef linkat
903# define linkat rpl_linkat
904# endif
905_GL_FUNCDECL_RPL (linkat, int,
906 (int fd1, const char *path1, int fd2, const char *path2,
907 int flag)
908 _GL_ARG_NONNULL ((2, 4)));
909_GL_CXXALIAS_RPL (linkat, int,
910 (int fd1, const char *path1, int fd2, const char *path2,
911 int flag));
912# else
913# if !@HAVE_LINKAT@
914_GL_FUNCDECL_SYS (linkat, int,
915 (int fd1, const char *path1, int fd2, const char *path2,
916 int flag)
917 _GL_ARG_NONNULL ((2, 4)));
918# endif
919_GL_CXXALIAS_SYS (linkat, int,
920 (int fd1, const char *path1, int fd2, const char *path2,
921 int flag));
922# endif
923_GL_CXXALIASWARN (linkat);
924#elif defined GNULIB_POSIXCHECK
925# undef linkat
926# if HAVE_RAW_DECL_LINKAT
927_GL_WARN_ON_USE (linkat, "linkat is unportable - "
928 "use gnulib module linkat for portability");
929# endif
499#endif 930#endif
500 931
501 932
502#if @GNULIB_LSEEK@ 933#if @GNULIB_LSEEK@
503# if @REPLACE_LSEEK@
504/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. 934/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
505 Return the new offset if successful, otherwise -1 and errno set. 935 Return the new offset if successful, otherwise -1 and errno set.
506 See the POSIX:2001 specification 936 See the POSIX:2001 specification
507 <http://www.opengroup.org/susv3xsh/lseek.html>. */ 937 <http://www.opengroup.org/susv3xsh/lseek.html>. */
508# define lseek rpl_lseek 938# if @REPLACE_LSEEK@
509 extern off_t lseek (int fd, off_t offset, int whence); 939# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
940# define lseek rpl_lseek
941# endif
942_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
943_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
944# else
945_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
510# endif 946# endif
947_GL_CXXALIASWARN (lseek);
511#elif defined GNULIB_POSIXCHECK 948#elif defined GNULIB_POSIXCHECK
512# undef lseek 949# undef lseek
513# define lseek(f,o,w) \ 950# if HAVE_RAW_DECL_LSEEK
514 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \ 951_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
515 "systems - use gnulib module lseek for portability"), \ 952 "systems - use gnulib module lseek for portability");
516 lseek (f, o, w)) 953# endif
954#endif
955
956
957#if @GNULIB_PIPE2@
958/* Create a pipe, applying the given flags when opening the read-end of the
959 pipe and the write-end of the pipe.
960 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
961 and O_TEXT, O_BINARY (defined in "binary-io.h").
962 Store the read-end as fd[0] and the write-end as fd[1].
963 Return 0 upon success, or -1 with errno set upon failure.
964 See also the Linux man page at
965 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
966# if @HAVE_PIPE2@
967# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
968# define pipe2 rpl_pipe2
969# endif
970_GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
971_GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
972# else
973_GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
974_GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
975# endif
976_GL_CXXALIASWARN (pipe2);
977#elif defined GNULIB_POSIXCHECK
978# undef pipe2
979# if HAVE_RAW_DECL_PIPE2
980_GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
981 "use gnulib module pipe2 for portability");
982# endif
983#endif
984
985
986#if @GNULIB_PREAD@
987/* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
988 Return the number of bytes placed into BUF if successful, otherwise
989 set errno and return -1. 0 indicates EOF. See the POSIX:2001
990 specification <http://www.opengroup.org/susv3xsh/pread.html>. */
991# if @REPLACE_PREAD@
992# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
993# define pread rpl_pread
994# endif
995_GL_FUNCDECL_RPL (pread, ssize_t,
996 (int fd, void *buf, size_t bufsize, off_t offset)
997 _GL_ARG_NONNULL ((2)));
998_GL_CXXALIAS_RPL (pread, ssize_t,
999 (int fd, void *buf, size_t bufsize, off_t offset));
1000# else
1001# if !@HAVE_PREAD@
1002_GL_FUNCDECL_SYS (pread, ssize_t,
1003 (int fd, void *buf, size_t bufsize, off_t offset)
1004 _GL_ARG_NONNULL ((2)));
1005# endif
1006_GL_CXXALIAS_SYS (pread, ssize_t,
1007 (int fd, void *buf, size_t bufsize, off_t offset));
1008# endif
1009_GL_CXXALIASWARN (pread);
1010#elif defined GNULIB_POSIXCHECK
1011# undef pread
1012# if HAVE_RAW_DECL_PREAD
1013_GL_WARN_ON_USE (pread, "pread is unportable - "
1014 "use gnulib module pread for portability");
1015# endif
517#endif 1016#endif
518 1017
519 1018
@@ -523,16 +1022,70 @@ extern int link (const char *path1, const char *path2);
523 successful, otherwise -1 and errno set. 1022 successful, otherwise -1 and errno set.
524 See the POSIX:2001 specification 1023 See the POSIX:2001 specification
525 <http://www.opengroup.org/susv3xsh/readlink.html>. */ 1024 <http://www.opengroup.org/susv3xsh/readlink.html>. */
526# if !@HAVE_READLINK@ 1025# if @REPLACE_READLINK@
527# include <stddef.h> 1026# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
528extern int readlink (const char *file, char *buf, size_t bufsize); 1027# define readlink rpl_readlink
1028# endif
1029_GL_FUNCDECL_RPL (readlink, ssize_t,
1030 (const char *file, char *buf, size_t bufsize)
1031 _GL_ARG_NONNULL ((1, 2)));
1032_GL_CXXALIAS_RPL (readlink, ssize_t,
1033 (const char *file, char *buf, size_t bufsize));
1034# else
1035# if !@HAVE_READLINK@
1036_GL_FUNCDECL_SYS (readlink, ssize_t,
1037 (const char *file, char *buf, size_t bufsize)
1038 _GL_ARG_NONNULL ((1, 2)));
1039# endif
1040_GL_CXXALIAS_SYS (readlink, ssize_t,
1041 (const char *file, char *buf, size_t bufsize));
529# endif 1042# endif
1043_GL_CXXALIASWARN (readlink);
530#elif defined GNULIB_POSIXCHECK 1044#elif defined GNULIB_POSIXCHECK
531# undef readlink 1045# undef readlink
532# define readlink(f,b,s) \ 1046# if HAVE_RAW_DECL_READLINK
533 (GL_LINK_WARNING ("readlink is unportable - " \ 1047_GL_WARN_ON_USE (readlink, "readlink is unportable - "
534 "use gnulib module readlink for portability"), \ 1048 "use gnulib module readlink for portability");
535 readlink (f, b, s)) 1049# endif
1050#endif
1051
1052
1053#if @GNULIB_READLINKAT@
1054# if !@HAVE_READLINKAT@
1055_GL_FUNCDECL_SYS (readlinkat, ssize_t,
1056 (int fd, char const *file, char *buf, size_t len)
1057 _GL_ARG_NONNULL ((2, 3)));
1058# endif
1059_GL_CXXALIAS_SYS (readlinkat, ssize_t,
1060 (int fd, char const *file, char *buf, size_t len));
1061_GL_CXXALIASWARN (readlinkat);
1062#elif defined GNULIB_POSIXCHECK
1063# undef readlinkat
1064# if HAVE_RAW_DECL_READLINKAT
1065_GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1066 "use gnulib module symlinkat for portability");
1067# endif
1068#endif
1069
1070
1071#if @GNULIB_RMDIR@
1072/* Remove the directory DIR. */
1073# if @REPLACE_RMDIR@
1074# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1075# define rmdir rpl_rmdir
1076# endif
1077_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1078_GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1079# else
1080_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1081# endif
1082_GL_CXXALIASWARN (rmdir);
1083#elif defined GNULIB_POSIXCHECK
1084# undef rmdir
1085# if HAVE_RAW_DECL_RMDIR
1086_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1087 "use gnulib module rmdir for portability");
1088# endif
536#endif 1089#endif
537 1090
538 1091
@@ -541,36 +1094,183 @@ extern int readlink (const char *file, char *buf, size_t bufsize);
541 Returns the number of seconds left to sleep. 1094 Returns the number of seconds left to sleep.
542 See the POSIX:2001 specification 1095 See the POSIX:2001 specification
543 <http://www.opengroup.org/susv3xsh/sleep.html>. */ 1096 <http://www.opengroup.org/susv3xsh/sleep.html>. */
544# if !@HAVE_SLEEP@ 1097# if @REPLACE_SLEEP@
545extern unsigned int sleep (unsigned int n); 1098# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1099# undef sleep
1100# define sleep rpl_sleep
1101# endif
1102_GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1103_GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1104# else
1105# if !@HAVE_SLEEP@
1106_GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1107# endif
1108_GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
546# endif 1109# endif
1110_GL_CXXALIASWARN (sleep);
547#elif defined GNULIB_POSIXCHECK 1111#elif defined GNULIB_POSIXCHECK
548# undef sleep 1112# undef sleep
549# define sleep(n) \ 1113# if HAVE_RAW_DECL_SLEEP
550 (GL_LINK_WARNING ("sleep is unportable - " \ 1114_GL_WARN_ON_USE (sleep, "sleep is unportable - "
551 "use gnulib module sleep for portability"), \ 1115 "use gnulib module sleep for portability");
552 sleep (n)) 1116# endif
553#endif 1117#endif
554 1118
555 1119
556#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@ 1120#if @GNULIB_SYMLINK@
557/* Write up to COUNT bytes starting at BUF to file descriptor FD. 1121# if @REPLACE_SYMLINK@
558 See the POSIX:2001 specification 1122# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
559 <http://www.opengroup.org/susv3xsh/write.html>. */ 1123# undef symlink
560# undef write 1124# define symlink rpl_symlink
561# define write rpl_write 1125# endif
562extern ssize_t write (int fd, const void *buf, size_t count); 1126_GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1127 _GL_ARG_NONNULL ((1, 2)));
1128_GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1129# else
1130# if !@HAVE_SYMLINK@
1131_GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1132 _GL_ARG_NONNULL ((1, 2)));
1133# endif
1134_GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1135# endif
1136_GL_CXXALIASWARN (symlink);
1137#elif defined GNULIB_POSIXCHECK
1138# undef symlink
1139# if HAVE_RAW_DECL_SYMLINK
1140_GL_WARN_ON_USE (symlink, "symlink is not portable - "
1141 "use gnulib module symlink for portability");
1142# endif
563#endif 1143#endif
564 1144
565 1145
566#ifdef FCHDIR_REPLACEMENT 1146#if @GNULIB_SYMLINKAT@
567/* gnulib internal function. */ 1147# if !@HAVE_SYMLINKAT@
568extern void _gl_unregister_fd (int fd); 1148_GL_FUNCDECL_SYS (symlinkat, int,
1149 (char const *contents, int fd, char const *file)
1150 _GL_ARG_NONNULL ((1, 3)));
1151# endif
1152_GL_CXXALIAS_SYS (symlinkat, int,
1153 (char const *contents, int fd, char const *file));
1154_GL_CXXALIASWARN (symlinkat);
1155#elif defined GNULIB_POSIXCHECK
1156# undef symlinkat
1157# if HAVE_RAW_DECL_SYMLINKAT
1158_GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1159 "use gnulib module symlinkat for portability");
1160# endif
569#endif 1161#endif
570 1162
571 1163
572#ifdef __cplusplus 1164#if @GNULIB_TTYNAME_R@
573} 1165/* Store at most BUFLEN characters of the pathname of the terminal FD is
1166 open on in BUF. Return 0 on success, otherwise an error number. */
1167# if !@HAVE_TTYNAME_R@
1168_GL_FUNCDECL_SYS (ttyname_r, int,
1169 (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1170# endif
1171_GL_CXXALIAS_SYS (ttyname_r, int,
1172 (int fd, char *buf, size_t buflen));
1173_GL_CXXALIASWARN (ttyname_r);
1174#elif defined GNULIB_POSIXCHECK
1175# undef ttyname_r
1176# if HAVE_RAW_DECL_TTYNAME_R
1177_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1178 "use gnulib module ttyname_r for portability");
1179# endif
1180#endif
1181
1182
1183#if @GNULIB_UNLINK@
1184# if @REPLACE_UNLINK@
1185# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1186# undef unlink
1187# define unlink rpl_unlink
1188# endif
1189_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1190_GL_CXXALIAS_RPL (unlink, int, (char const *file));
1191# else
1192_GL_CXXALIAS_SYS (unlink, int, (char const *file));
1193# endif
1194_GL_CXXALIASWARN (unlink);
1195#elif defined GNULIB_POSIXCHECK
1196# undef unlink
1197# if HAVE_RAW_DECL_UNLINK
1198_GL_WARN_ON_USE (unlink, "unlink is not portable - "
1199 "use gnulib module unlink for portability");
1200# endif
1201#endif
1202
1203
1204#if @GNULIB_UNLINKAT@
1205# if @REPLACE_UNLINKAT@
1206# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1207# undef unlinkat
1208# define unlinkat rpl_unlinkat
1209# endif
1210_GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1211 _GL_ARG_NONNULL ((2)));
1212_GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1213# else
1214# if !@HAVE_UNLINKAT@
1215_GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1216 _GL_ARG_NONNULL ((2)));
1217# endif
1218_GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1219# endif
1220_GL_CXXALIASWARN (unlinkat);
1221#elif defined GNULIB_POSIXCHECK
1222# undef unlinkat
1223# if HAVE_RAW_DECL_UNLINKAT
1224_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1225 "use gnulib module openat for portability");
1226# endif
1227#endif
1228
1229
1230#if @GNULIB_USLEEP@
1231/* Pause the execution of the current thread for N microseconds.
1232 Returns 0 on completion, or -1 on range error.
1233 See the POSIX:2001 specification
1234 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1235# if @REPLACE_USLEEP@
1236# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1237# undef usleep
1238# define usleep rpl_usleep
1239# endif
1240_GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1241_GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1242# else
1243# if !@HAVE_USLEEP@
1244_GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1245# endif
1246_GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1247# endif
1248_GL_CXXALIASWARN (usleep);
1249#elif defined GNULIB_POSIXCHECK
1250# undef usleep
1251# if HAVE_RAW_DECL_USLEEP
1252_GL_WARN_ON_USE (usleep, "usleep is unportable - "
1253 "use gnulib module usleep for portability");
1254# endif
1255#endif
1256
1257
1258#if @GNULIB_WRITE@
1259/* Write up to COUNT bytes starting at BUF to file descriptor FD.
1260 See the POSIX:2001 specification
1261 <http://www.opengroup.org/susv3xsh/write.html>. */
1262# if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
1263# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1264# undef write
1265# define write rpl_write
1266# endif
1267_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1268 _GL_ARG_NONNULL ((2)));
1269_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1270# else
1271_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1272# endif
1273_GL_CXXALIASWARN (write);
574#endif 1274#endif
575 1275
576 1276
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 7ac9f436..99d921e9 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -1,5 +1,5 @@
1/* vsprintf with automatic memory allocation. 1/* vsprintf with automatic memory allocation.
2 Copyright (C) 1999, 2002-2009 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -67,13 +67,13 @@
67# endif 67# endif
68#endif 68#endif
69 69
70#include <locale.h> /* localeconv() */ 70#include <locale.h> /* localeconv() */
71#include <stdio.h> /* snprintf(), sprintf() */ 71#include <stdio.h> /* snprintf(), sprintf() */
72#include <stdlib.h> /* abort(), malloc(), realloc(), free() */ 72#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
73#include <string.h> /* memcpy(), strlen() */ 73#include <string.h> /* memcpy(), strlen() */
74#include <errno.h> /* errno */ 74#include <errno.h> /* errno */
75#include <limits.h> /* CHAR_BIT */ 75#include <limits.h> /* CHAR_BIT */
76#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */ 76#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
77#if HAVE_NL_LANGINFO 77#if HAVE_NL_LANGINFO
78# include <langinfo.h> 78# include <langinfo.h>
79#endif 79#endif
@@ -257,14 +257,14 @@ local_wcsnlen (const wchar_t *s, size_t maxlen)
257# ifndef decimal_point_char_defined 257# ifndef decimal_point_char_defined
258# define decimal_point_char_defined 1 258# define decimal_point_char_defined 1
259static char 259static char
260decimal_point_char () 260decimal_point_char (void)
261{ 261{
262 const char *point; 262 const char *point;
263 /* Determine it in a multithread-safe way. We know nl_langinfo is 263 /* Determine it in a multithread-safe way. We know nl_langinfo is
264 multithread-safe on glibc systems, but is not required to be multithread- 264 multithread-safe on glibc systems and MacOS X systems, but is not required
265 safe by POSIX. sprintf(), however, is multithread-safe. localeconv() 265 to be multithread-safe by POSIX. sprintf(), however, is multithread-safe.
266 is rarely multithread-safe. */ 266 localeconv() is rarely multithread-safe. */
267# if HAVE_NL_LANGINFO && __GLIBC__ 267# if HAVE_NL_LANGINFO && (__GLIBC__ || (defined __APPLE__ && defined __MACH__))
268 point = nl_langinfo (RADIXCHAR); 268 point = nl_langinfo (RADIXCHAR);
269# elif 1 269# elif 1
270 char pointbuf[5]; 270 char pointbuf[5];
@@ -364,26 +364,26 @@ multiply (mpn_t src1, mpn_t src2, mpn_t *dest)
364 dlen = len1 + len2; 364 dlen = len1 + len2;
365 dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); 365 dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t));
366 if (dp == NULL) 366 if (dp == NULL)
367 return NULL; 367 return NULL;
368 for (k = len2; k > 0; ) 368 for (k = len2; k > 0; )
369 dp[--k] = 0; 369 dp[--k] = 0;
370 for (i = 0; i < len1; i++) 370 for (i = 0; i < len1; i++)
371 { 371 {
372 mp_limb_t digit1 = p1[i]; 372 mp_limb_t digit1 = p1[i];
373 mp_twolimb_t carry = 0; 373 mp_twolimb_t carry = 0;
374 for (j = 0; j < len2; j++) 374 for (j = 0; j < len2; j++)
375 { 375 {
376 mp_limb_t digit2 = p2[j]; 376 mp_limb_t digit2 = p2[j];
377 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; 377 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
378 carry += dp[i + j]; 378 carry += dp[i + j];
379 dp[i + j] = (mp_limb_t) carry; 379 dp[i + j] = (mp_limb_t) carry;
380 carry = carry >> GMP_LIMB_BITS; 380 carry = carry >> GMP_LIMB_BITS;
381 } 381 }
382 dp[i + len2] = (mp_limb_t) carry; 382 dp[i + len2] = (mp_limb_t) carry;
383 } 383 }
384 /* Normalise. */ 384 /* Normalise. */
385 while (dlen > 0 && dp[dlen - 1] == 0) 385 while (dlen > 0 && dp[dlen - 1] == 0)
386 dlen--; 386 dlen--;
387 dest->nlimbs = dlen; 387 dest->nlimbs = dlen;
388 dest->limbs = dp; 388 dest->limbs = dp;
389 } 389 }
@@ -477,12 +477,12 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
477 for (;;) 477 for (;;)
478 { 478 {
479 if (b_len == 0) 479 if (b_len == 0)
480 /* Division by zero. */ 480 /* Division by zero. */
481 abort (); 481 abort ();
482 if (b_ptr[b_len - 1] == 0) 482 if (b_ptr[b_len - 1] == 0)
483 b_len--; 483 b_len--;
484 else 484 else
485 break; 485 break;
486 } 486 }
487 487
488 /* Here m = a_len >= 0 and n = b_len > 0. */ 488 /* Here m = a_len >= 0 and n = b_len > 0. */
@@ -499,261 +499,261 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
499 else if (b_len == 1) 499 else if (b_len == 1)
500 { 500 {
501 /* n=1: single precision division. 501 /* n=1: single precision division.
502 beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ 502 beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */
503 r_ptr = roomptr; 503 r_ptr = roomptr;
504 q_ptr = roomptr + 1; 504 q_ptr = roomptr + 1;
505 { 505 {
506 mp_limb_t den = b_ptr[0]; 506 mp_limb_t den = b_ptr[0];
507 mp_limb_t remainder = 0; 507 mp_limb_t remainder = 0;
508 const mp_limb_t *sourceptr = a_ptr + a_len; 508 const mp_limb_t *sourceptr = a_ptr + a_len;
509 mp_limb_t *destptr = q_ptr + a_len; 509 mp_limb_t *destptr = q_ptr + a_len;
510 size_t count; 510 size_t count;
511 for (count = a_len; count > 0; count--) 511 for (count = a_len; count > 0; count--)
512 { 512 {
513 mp_twolimb_t num = 513 mp_twolimb_t num =
514 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; 514 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr;
515 *--destptr = num / den; 515 *--destptr = num / den;
516 remainder = num % den; 516 remainder = num % den;
517 } 517 }
518 /* Normalise and store r. */ 518 /* Normalise and store r. */
519 if (remainder > 0) 519 if (remainder > 0)
520 { 520 {
521 r_ptr[0] = remainder; 521 r_ptr[0] = remainder;
522 r_len = 1; 522 r_len = 1;
523 } 523 }
524 else 524 else
525 r_len = 0; 525 r_len = 0;
526 /* Normalise q. */ 526 /* Normalise q. */
527 q_len = a_len; 527 q_len = a_len;
528 if (q_ptr[q_len - 1] == 0) 528 if (q_ptr[q_len - 1] == 0)
529 q_len--; 529 q_len--;
530 } 530 }
531 } 531 }
532 else 532 else
533 { 533 {
534 /* n>1: multiple precision division. 534 /* n>1: multiple precision division.
535 beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> 535 beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==>
536 beta^(m-n-1) <= a/b < beta^(m-n+1). */ 536 beta^(m-n-1) <= a/b < beta^(m-n+1). */
537 /* Determine s. */ 537 /* Determine s. */
538 size_t s; 538 size_t s;
539 { 539 {
540 mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ 540 mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
541 s = 31; 541 s = 31;
542 if (msd >= 0x10000) 542 if (msd >= 0x10000)
543 { 543 {
544 msd = msd >> 16; 544 msd = msd >> 16;
545 s -= 16; 545 s -= 16;
546 } 546 }
547 if (msd >= 0x100) 547 if (msd >= 0x100)
548 { 548 {
549 msd = msd >> 8; 549 msd = msd >> 8;
550 s -= 8; 550 s -= 8;
551 } 551 }
552 if (msd >= 0x10) 552 if (msd >= 0x10)
553 { 553 {
554 msd = msd >> 4; 554 msd = msd >> 4;
555 s -= 4; 555 s -= 4;
556 } 556 }
557 if (msd >= 0x4) 557 if (msd >= 0x4)
558 { 558 {
559 msd = msd >> 2; 559 msd = msd >> 2;
560 s -= 2; 560 s -= 2;
561 } 561 }
562 if (msd >= 0x2) 562 if (msd >= 0x2)
563 { 563 {
564 msd = msd >> 1; 564 msd = msd >> 1;
565 s -= 1; 565 s -= 1;
566 } 566 }
567 } 567 }
568 /* 0 <= s < GMP_LIMB_BITS. 568 /* 0 <= s < GMP_LIMB_BITS.
569 Copy b, shifting it left by s bits. */ 569 Copy b, shifting it left by s bits. */
570 if (s > 0) 570 if (s > 0)
571 { 571 {
572 tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); 572 tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t));
573 if (tmp_roomptr == NULL) 573 if (tmp_roomptr == NULL)
574 { 574 {
575 free (roomptr); 575 free (roomptr);
576 return NULL; 576 return NULL;
577 } 577 }
578 { 578 {
579 const mp_limb_t *sourceptr = b_ptr; 579 const mp_limb_t *sourceptr = b_ptr;
580 mp_limb_t *destptr = tmp_roomptr; 580 mp_limb_t *destptr = tmp_roomptr;
581 mp_twolimb_t accu = 0; 581 mp_twolimb_t accu = 0;
582 size_t count; 582 size_t count;
583 for (count = b_len; count > 0; count--) 583 for (count = b_len; count > 0; count--)
584 { 584 {
585 accu += (mp_twolimb_t) *sourceptr++ << s; 585 accu += (mp_twolimb_t) *sourceptr++ << s;
586 *destptr++ = (mp_limb_t) accu; 586 *destptr++ = (mp_limb_t) accu;
587 accu = accu >> GMP_LIMB_BITS; 587 accu = accu >> GMP_LIMB_BITS;
588 } 588 }
589 /* accu must be zero, since that was how s was determined. */ 589 /* accu must be zero, since that was how s was determined. */
590 if (accu != 0) 590 if (accu != 0)
591 abort (); 591 abort ();
592 } 592 }
593 b_ptr = tmp_roomptr; 593 b_ptr = tmp_roomptr;
594 } 594 }
595 /* Copy a, shifting it left by s bits, yields r. 595 /* Copy a, shifting it left by s bits, yields r.
596 Memory layout: 596 Memory layout:
597 At the beginning: r = roomptr[0..a_len], 597 At the beginning: r = roomptr[0..a_len],
598 at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ 598 at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */
599 r_ptr = roomptr; 599 r_ptr = roomptr;
600 if (s == 0) 600 if (s == 0)
601 { 601 {
602 memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); 602 memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
603 r_ptr[a_len] = 0; 603 r_ptr[a_len] = 0;
604 } 604 }
605 else 605 else
606 { 606 {
607 const mp_limb_t *sourceptr = a_ptr; 607 const mp_limb_t *sourceptr = a_ptr;
608 mp_limb_t *destptr = r_ptr; 608 mp_limb_t *destptr = r_ptr;
609 mp_twolimb_t accu = 0; 609 mp_twolimb_t accu = 0;
610 size_t count; 610 size_t count;
611 for (count = a_len; count > 0; count--) 611 for (count = a_len; count > 0; count--)
612 { 612 {
613 accu += (mp_twolimb_t) *sourceptr++ << s; 613 accu += (mp_twolimb_t) *sourceptr++ << s;
614 *destptr++ = (mp_limb_t) accu; 614 *destptr++ = (mp_limb_t) accu;
615 accu = accu >> GMP_LIMB_BITS; 615 accu = accu >> GMP_LIMB_BITS;
616 } 616 }
617 *destptr++ = (mp_limb_t) accu; 617 *destptr++ = (mp_limb_t) accu;
618 } 618 }
619 q_ptr = roomptr + b_len; 619 q_ptr = roomptr + b_len;
620 q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ 620 q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */
621 { 621 {
622 size_t j = a_len - b_len; /* m-n */ 622 size_t j = a_len - b_len; /* m-n */
623 mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ 623 mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */
624 mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ 624 mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */
625 mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ 625 mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */
626 ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; 626 ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd;
627 /* Division loop, traversed m-n+1 times. 627 /* Division loop, traversed m-n+1 times.
628 j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ 628 j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */
629 for (;;) 629 for (;;)
630 { 630 {
631 mp_limb_t q_star; 631 mp_limb_t q_star;
632 mp_limb_t c1; 632 mp_limb_t c1;
633 if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ 633 if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */
634 { 634 {
635 /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ 635 /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */
636 mp_twolimb_t num = 636 mp_twolimb_t num =
637 ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) 637 ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS)
638 | r_ptr[j + b_len - 1]; 638 | r_ptr[j + b_len - 1];
639 q_star = num / b_msd; 639 q_star = num / b_msd;
640 c1 = num % b_msd; 640 c1 = num % b_msd;
641 } 641 }
642 else 642 else
643 { 643 {
644 /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ 644 /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */
645 q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ 645 q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */
646 /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta 646 /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta
647 <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta 647 <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta
648 <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) 648 <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta)
649 {<= beta !}. 649 {<= beta !}.
650 If yes, jump directly to the subtraction loop. 650 If yes, jump directly to the subtraction loop.
651 (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta 651 (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta
652 <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ 652 <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */
653 if (r_ptr[j + b_len] > b_msd 653 if (r_ptr[j + b_len] > b_msd
654 || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) 654 || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd)
655 /* r[j+n] >= b[n-1]+1 or 655 /* r[j+n] >= b[n-1]+1 or
656 r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a 656 r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a
657 carry. */ 657 carry. */
658 goto subtract; 658 goto subtract;
659 } 659 }
660 /* q_star = q*, 660 /* q_star = q*,
661 c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, <beta). */ 661 c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, <beta). */
662 { 662 {
663 mp_twolimb_t c2 = /* c1*beta+r[j+n-2] */ 663 mp_twolimb_t c2 = /* c1*beta+r[j+n-2] */
664 ((mp_twolimb_t) c1 << GMP_LIMB_BITS) | r_ptr[j + b_len - 2]; 664 ((mp_twolimb_t) c1 << GMP_LIMB_BITS) | r_ptr[j + b_len - 2];
665 mp_twolimb_t c3 = /* b[n-2] * q* */ 665 mp_twolimb_t c3 = /* b[n-2] * q* */
666 (mp_twolimb_t) b_2msd * (mp_twolimb_t) q_star; 666 (mp_twolimb_t) b_2msd * (mp_twolimb_t) q_star;
667 /* While c2 < c3, increase c2 and decrease c3. 667 /* While c2 < c3, increase c2 and decrease c3.
668 Consider c3-c2. While it is > 0, decrease it by 668 Consider c3-c2. While it is > 0, decrease it by
669 b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 669 b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2
670 this can happen only twice. */ 670 this can happen only twice. */
671 if (c3 > c2) 671 if (c3 > c2)
672 { 672 {
673 q_star = q_star - 1; /* q* := q* - 1 */ 673 q_star = q_star - 1; /* q* := q* - 1 */
674 if (c3 - c2 > b_msdd) 674 if (c3 - c2 > b_msdd)
675 q_star = q_star - 1; /* q* := q* - 1 */ 675 q_star = q_star - 1; /* q* := q* - 1 */
676 } 676 }
677 } 677 }
678 if (q_star > 0) 678 if (q_star > 0)
679 subtract: 679 subtract:
680 { 680 {
681 /* Subtract r := r - b * q* * beta^j. */ 681 /* Subtract r := r - b * q* * beta^j. */
682 mp_limb_t cr; 682 mp_limb_t cr;
683 { 683 {
684 const mp_limb_t *sourceptr = b_ptr; 684 const mp_limb_t *sourceptr = b_ptr;
685 mp_limb_t *destptr = r_ptr + j; 685 mp_limb_t *destptr = r_ptr + j;
686 mp_twolimb_t carry = 0; 686 mp_twolimb_t carry = 0;
687 size_t count; 687 size_t count;
688 for (count = b_len; count > 0; count--) 688 for (count = b_len; count > 0; count--)
689 { 689 {
690 /* Here 0 <= carry <= q*. */ 690 /* Here 0 <= carry <= q*. */
691 carry = 691 carry =
692 carry 692 carry
693 + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ 693 + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++
694 + (mp_limb_t) ~(*destptr); 694 + (mp_limb_t) ~(*destptr);
695 /* Here 0 <= carry <= beta*q* + beta-1. */ 695 /* Here 0 <= carry <= beta*q* + beta-1. */
696 *destptr++ = ~(mp_limb_t) carry; 696 *destptr++ = ~(mp_limb_t) carry;
697 carry = carry >> GMP_LIMB_BITS; /* <= q* */ 697 carry = carry >> GMP_LIMB_BITS; /* <= q* */
698 } 698 }
699 cr = (mp_limb_t) carry; 699 cr = (mp_limb_t) carry;
700 } 700 }
701 /* Subtract cr from r_ptr[j + b_len], then forget about 701 /* Subtract cr from r_ptr[j + b_len], then forget about
702 r_ptr[j + b_len]. */ 702 r_ptr[j + b_len]. */
703 if (cr > r_ptr[j + b_len]) 703 if (cr > r_ptr[j + b_len])
704 { 704 {
705 /* Subtraction gave a carry. */ 705 /* Subtraction gave a carry. */
706 q_star = q_star - 1; /* q* := q* - 1 */ 706 q_star = q_star - 1; /* q* := q* - 1 */
707 /* Add b back. */ 707 /* Add b back. */
708 { 708 {
709 const mp_limb_t *sourceptr = b_ptr; 709 const mp_limb_t *sourceptr = b_ptr;
710 mp_limb_t *destptr = r_ptr + j; 710 mp_limb_t *destptr = r_ptr + j;
711 mp_limb_t carry = 0; 711 mp_limb_t carry = 0;
712 size_t count; 712 size_t count;
713 for (count = b_len; count > 0; count--) 713 for (count = b_len; count > 0; count--)
714 { 714 {
715 mp_limb_t source1 = *sourceptr++; 715 mp_limb_t source1 = *sourceptr++;
716 mp_limb_t source2 = *destptr; 716 mp_limb_t source2 = *destptr;
717 *destptr++ = source1 + source2 + carry; 717 *destptr++ = source1 + source2 + carry;
718 carry = 718 carry =
719 (carry 719 (carry
720 ? source1 >= (mp_limb_t) ~source2 720 ? source1 >= (mp_limb_t) ~source2
721 : source1 > (mp_limb_t) ~source2); 721 : source1 > (mp_limb_t) ~source2);
722 } 722 }
723 } 723 }
724 /* Forget about the carry and about r[j+n]. */ 724 /* Forget about the carry and about r[j+n]. */
725 } 725 }
726 } 726 }
727 /* q* is determined. Store it as q[j]. */ 727 /* q* is determined. Store it as q[j]. */
728 q_ptr[j] = q_star; 728 q_ptr[j] = q_star;
729 if (j == 0) 729 if (j == 0)
730 break; 730 break;
731 j--; 731 j--;
732 } 732 }
733 } 733 }
734 r_len = b_len; 734 r_len = b_len;
735 /* Normalise q. */ 735 /* Normalise q. */
736 if (q_ptr[q_len - 1] == 0) 736 if (q_ptr[q_len - 1] == 0)
737 q_len--; 737 q_len--;
738# if 0 /* Not needed here, since we need r only to compare it with b/2, and 738# if 0 /* Not needed here, since we need r only to compare it with b/2, and
739 b is shifted left by s bits. */ 739 b is shifted left by s bits. */
740 /* Shift r right by s bits. */ 740 /* Shift r right by s bits. */
741 if (s > 0) 741 if (s > 0)
742 { 742 {
743 mp_limb_t ptr = r_ptr + r_len; 743 mp_limb_t ptr = r_ptr + r_len;
744 mp_twolimb_t accu = 0; 744 mp_twolimb_t accu = 0;
745 size_t count; 745 size_t count;
746 for (count = r_len; count > 0; count--) 746 for (count = r_len; count > 0; count--)
747 { 747 {
748 accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; 748 accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS;
749 accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); 749 accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s);
750 *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); 750 *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS);
751 } 751 }
752 } 752 }
753# endif 753# endif
754 /* Normalise r. */ 754 /* Normalise r. */
755 while (r_len > 0 && r_ptr[r_len - 1] == 0) 755 while (r_len > 0 && r_ptr[r_len - 1] == 0)
756 r_len--; 756 r_len--;
757 } 757 }
758 /* Compare r << 1 with b. */ 758 /* Compare r << 1 with b. */
759 if (r_len > b_len) 759 if (r_len > b_len)
@@ -762,17 +762,17 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
762 size_t i; 762 size_t i;
763 for (i = b_len;;) 763 for (i = b_len;;)
764 { 764 {
765 mp_limb_t r_i = 765 mp_limb_t r_i =
766 (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) 766 (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0)
767 | (i < r_len ? r_ptr[i] << 1 : 0); 767 | (i < r_len ? r_ptr[i] << 1 : 0);
768 mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); 768 mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0);
769 if (r_i > b_i) 769 if (r_i > b_i)
770 goto increment_q; 770 goto increment_q;
771 if (r_i < b_i) 771 if (r_i < b_i)
772 goto keep_q; 772 goto keep_q;
773 if (i == 0) 773 if (i == 0)
774 break; 774 break;
775 i--; 775 i--;
776 } 776 }
777 } 777 }
778 if (q_len > 0 && ((q_ptr[0] & 1) != 0)) 778 if (q_len > 0 && ((q_ptr[0] & 1) != 0))
@@ -781,8 +781,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
781 { 781 {
782 size_t i; 782 size_t i;
783 for (i = 0; i < q_len; i++) 783 for (i = 0; i < q_len; i++)
784 if (++(q_ptr[i]) != 0) 784 if (++(q_ptr[i]) != 0)
785 goto keep_q; 785 goto keep_q;
786 q_ptr[q_len++] = 1; 786 q_ptr[q_len++] = 1;
787 } 787 }
788 keep_q: 788 keep_q:
@@ -811,36 +811,36 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
811 { 811 {
812 char *d_ptr = c_ptr; 812 char *d_ptr = c_ptr;
813 for (; extra_zeroes > 0; extra_zeroes--) 813 for (; extra_zeroes > 0; extra_zeroes--)
814 *d_ptr++ = '0'; 814 *d_ptr++ = '0';
815 while (a_len > 0) 815 while (a_len > 0)
816 { 816 {
817 /* Divide a by 10^9, in-place. */ 817 /* Divide a by 10^9, in-place. */
818 mp_limb_t remainder = 0; 818 mp_limb_t remainder = 0;
819 mp_limb_t *ptr = a_ptr + a_len; 819 mp_limb_t *ptr = a_ptr + a_len;
820 size_t count; 820 size_t count;
821 for (count = a_len; count > 0; count--) 821 for (count = a_len; count > 0; count--)
822 { 822 {
823 mp_twolimb_t num = 823 mp_twolimb_t num =
824 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; 824 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr;
825 *ptr = num / 1000000000; 825 *ptr = num / 1000000000;
826 remainder = num % 1000000000; 826 remainder = num % 1000000000;
827 } 827 }
828 /* Store the remainder as 9 decimal digits. */ 828 /* Store the remainder as 9 decimal digits. */
829 for (count = 9; count > 0; count--) 829 for (count = 9; count > 0; count--)
830 { 830 {
831 *d_ptr++ = '0' + (remainder % 10); 831 *d_ptr++ = '0' + (remainder % 10);
832 remainder = remainder / 10; 832 remainder = remainder / 10;
833 } 833 }
834 /* Normalize a. */ 834 /* Normalize a. */
835 if (a_ptr[a_len - 1] == 0) 835 if (a_ptr[a_len - 1] == 0)
836 a_len--; 836 a_len--;
837 } 837 }
838 /* Remove leading zeroes. */ 838 /* Remove leading zeroes. */
839 while (d_ptr > c_ptr && d_ptr[-1] == '0') 839 while (d_ptr > c_ptr && d_ptr[-1] == '0')
840 d_ptr--; 840 d_ptr--;
841 /* But keep at least one zero. */ 841 /* But keep at least one zero. */
842 if (d_ptr == c_ptr) 842 if (d_ptr == c_ptr)
843 *d_ptr++ = '0'; 843 *d_ptr++ = '0';
844 /* Terminate the string. */ 844 /* Terminate the string. */
845 *d_ptr = '\0'; 845 *d_ptr = '\0';
846 } 846 }
@@ -885,12 +885,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
885 hi = (int) y; 885 hi = (int) y;
886 y -= hi; 886 y -= hi;
887 if (!(y >= 0.0L && y < 1.0L)) 887 if (!(y >= 0.0L && y < 1.0L))
888 abort (); 888 abort ();
889 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); 889 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
890 lo = (int) y; 890 lo = (int) y;
891 y -= lo; 891 y -= lo;
892 if (!(y >= 0.0L && y < 1.0L)) 892 if (!(y >= 0.0L && y < 1.0L))
893 abort (); 893 abort ();
894 m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; 894 m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
895 } 895 }
896# else 896# else
@@ -900,7 +900,7 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
900 d = (int) y; 900 d = (int) y;
901 y -= d; 901 y -= d;
902 if (!(y >= 0.0L && y < 1.0L)) 902 if (!(y >= 0.0L && y < 1.0L))
903 abort (); 903 abort ();
904 m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; 904 m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d;
905 } 905 }
906# endif 906# endif
@@ -912,12 +912,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
912 hi = (int) y; 912 hi = (int) y;
913 y -= hi; 913 y -= hi;
914 if (!(y >= 0.0L && y < 1.0L)) 914 if (!(y >= 0.0L && y < 1.0L))
915 abort (); 915 abort ();
916 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); 916 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
917 lo = (int) y; 917 lo = (int) y;
918 y -= lo; 918 y -= lo;
919 if (!(y >= 0.0L && y < 1.0L)) 919 if (!(y >= 0.0L && y < 1.0L))
920 abort (); 920 abort ();
921 m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; 921 m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
922 } 922 }
923#if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess 923#if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
@@ -973,12 +973,12 @@ decode_double (double x, int *ep, mpn_t *mp)
973 hi = (int) y; 973 hi = (int) y;
974 y -= hi; 974 y -= hi;
975 if (!(y >= 0.0 && y < 1.0)) 975 if (!(y >= 0.0 && y < 1.0))
976 abort (); 976 abort ();
977 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); 977 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
978 lo = (int) y; 978 lo = (int) y;
979 y -= lo; 979 y -= lo;
980 if (!(y >= 0.0 && y < 1.0)) 980 if (!(y >= 0.0 && y < 1.0))
981 abort (); 981 abort ();
982 m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; 982 m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
983 } 983 }
984# else 984# else
@@ -988,7 +988,7 @@ decode_double (double x, int *ep, mpn_t *mp)
988 d = (int) y; 988 d = (int) y;
989 y -= d; 989 y -= d;
990 if (!(y >= 0.0 && y < 1.0)) 990 if (!(y >= 0.0 && y < 1.0))
991 abort (); 991 abort ();
992 m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; 992 m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d;
993 } 993 }
994# endif 994# endif
@@ -1000,12 +1000,12 @@ decode_double (double x, int *ep, mpn_t *mp)
1000 hi = (int) y; 1000 hi = (int) y;
1001 y -= hi; 1001 y -= hi;
1002 if (!(y >= 0.0 && y < 1.0)) 1002 if (!(y >= 0.0 && y < 1.0))
1003 abort (); 1003 abort ();
1004 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); 1004 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
1005 lo = (int) y; 1005 lo = (int) y;
1006 y -= lo; 1006 y -= lo;
1007 if (!(y >= 0.0 && y < 1.0)) 1007 if (!(y >= 0.0 && y < 1.0))
1008 abort (); 1008 abort ();
1009 m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; 1009 m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
1010 } 1010 }
1011 if (!(y == 0.0)) 1011 if (!(y == 0.0))
@@ -1063,8 +1063,8 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
1063 abs_n = (n >= 0 ? n : -n); 1063 abs_n = (n >= 0 ? n : -n);
1064 abs_s = (s >= 0 ? s : -s); 1064 abs_s = (s >= 0 ? s : -s);
1065 pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 1065 pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1
1066 + abs_s / GMP_LIMB_BITS + 1) 1066 + abs_s / GMP_LIMB_BITS + 1)
1067 * sizeof (mp_limb_t)); 1067 * sizeof (mp_limb_t));
1068 if (pow5_ptr == NULL) 1068 if (pow5_ptr == NULL)
1069 { 1069 {
1070 free (memory); 1070 free (memory);
@@ -1077,26 +1077,26 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
1077 if (abs_n > 0) 1077 if (abs_n > 0)
1078 { 1078 {
1079 static mp_limb_t const small_pow5[13 + 1] = 1079 static mp_limb_t const small_pow5[13 + 1] =
1080 { 1080 {
1081 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 1081 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625,
1082 48828125, 244140625, 1220703125 1082 48828125, 244140625, 1220703125
1083 }; 1083 };
1084 unsigned int n13; 1084 unsigned int n13;
1085 for (n13 = 0; n13 <= abs_n; n13 += 13) 1085 for (n13 = 0; n13 <= abs_n; n13 += 13)
1086 { 1086 {
1087 mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; 1087 mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13];
1088 size_t j; 1088 size_t j;
1089 mp_twolimb_t carry = 0; 1089 mp_twolimb_t carry = 0;
1090 for (j = 0; j < pow5_len; j++) 1090 for (j = 0; j < pow5_len; j++)
1091 { 1091 {
1092 mp_limb_t digit2 = pow5_ptr[j]; 1092 mp_limb_t digit2 = pow5_ptr[j];
1093 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; 1093 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
1094 pow5_ptr[j] = (mp_limb_t) carry; 1094 pow5_ptr[j] = (mp_limb_t) carry;
1095 carry = carry >> GMP_LIMB_BITS; 1095 carry = carry >> GMP_LIMB_BITS;
1096 } 1096 }
1097 if (carry > 0) 1097 if (carry > 0)
1098 pow5_ptr[pow5_len++] = (mp_limb_t) carry; 1098 pow5_ptr[pow5_len++] = (mp_limb_t) carry;
1099 } 1099 }
1100 } 1100 }
1101 s_limbs = abs_s / GMP_LIMB_BITS; 1101 s_limbs = abs_s / GMP_LIMB_BITS;
1102 s_bits = abs_s % GMP_LIMB_BITS; 1102 s_bits = abs_s % GMP_LIMB_BITS;
@@ -1104,129 +1104,129 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
1104 { 1104 {
1105 /* Multiply with 2^|s|. */ 1105 /* Multiply with 2^|s|. */
1106 if (s_bits > 0) 1106 if (s_bits > 0)
1107 { 1107 {
1108 mp_limb_t *ptr = pow5_ptr; 1108 mp_limb_t *ptr = pow5_ptr;
1109 mp_twolimb_t accu = 0; 1109 mp_twolimb_t accu = 0;
1110 size_t count; 1110 size_t count;
1111 for (count = pow5_len; count > 0; count--) 1111 for (count = pow5_len; count > 0; count--)
1112 { 1112 {
1113 accu += (mp_twolimb_t) *ptr << s_bits; 1113 accu += (mp_twolimb_t) *ptr << s_bits;
1114 *ptr++ = (mp_limb_t) accu; 1114 *ptr++ = (mp_limb_t) accu;
1115 accu = accu >> GMP_LIMB_BITS; 1115 accu = accu >> GMP_LIMB_BITS;
1116 } 1116 }
1117 if (accu > 0) 1117 if (accu > 0)
1118 { 1118 {
1119 *ptr = (mp_limb_t) accu; 1119 *ptr = (mp_limb_t) accu;
1120 pow5_len++; 1120 pow5_len++;
1121 } 1121 }
1122 } 1122 }
1123 if (s_limbs > 0) 1123 if (s_limbs > 0)
1124 { 1124 {
1125 size_t count; 1125 size_t count;
1126 for (count = pow5_len; count > 0;) 1126 for (count = pow5_len; count > 0;)
1127 { 1127 {
1128 count--; 1128 count--;
1129 pow5_ptr[s_limbs + count] = pow5_ptr[count]; 1129 pow5_ptr[s_limbs + count] = pow5_ptr[count];
1130 } 1130 }
1131 for (count = s_limbs; count > 0;) 1131 for (count = s_limbs; count > 0;)
1132 { 1132 {
1133 count--; 1133 count--;
1134 pow5_ptr[count] = 0; 1134 pow5_ptr[count] = 0;
1135 } 1135 }
1136 pow5_len += s_limbs; 1136 pow5_len += s_limbs;
1137 } 1137 }
1138 pow5.limbs = pow5_ptr; 1138 pow5.limbs = pow5_ptr;
1139 pow5.nlimbs = pow5_len; 1139 pow5.nlimbs = pow5_len;
1140 if (n >= 0) 1140 if (n >= 0)
1141 { 1141 {
1142 /* Multiply m with pow5. No division needed. */ 1142 /* Multiply m with pow5. No division needed. */
1143 z_memory = multiply (m, pow5, &z); 1143 z_memory = multiply (m, pow5, &z);
1144 } 1144 }
1145 else 1145 else
1146 { 1146 {
1147 /* Divide m by pow5 and round. */ 1147 /* Divide m by pow5 and round. */
1148 z_memory = divide (m, pow5, &z); 1148 z_memory = divide (m, pow5, &z);
1149 } 1149 }
1150 } 1150 }
1151 else 1151 else
1152 { 1152 {
1153 pow5.limbs = pow5_ptr; 1153 pow5.limbs = pow5_ptr;
1154 pow5.nlimbs = pow5_len; 1154 pow5.nlimbs = pow5_len;
1155 if (n >= 0) 1155 if (n >= 0)
1156 { 1156 {
1157 /* n >= 0, s < 0. 1157 /* n >= 0, s < 0.
1158 Multiply m with pow5, then divide by 2^|s|. */ 1158 Multiply m with pow5, then divide by 2^|s|. */
1159 mpn_t numerator; 1159 mpn_t numerator;
1160 mpn_t denominator; 1160 mpn_t denominator;
1161 void *tmp_memory; 1161 void *tmp_memory;
1162 tmp_memory = multiply (m, pow5, &numerator); 1162 tmp_memory = multiply (m, pow5, &numerator);
1163 if (tmp_memory == NULL) 1163 if (tmp_memory == NULL)
1164 { 1164 {
1165 free (pow5_ptr); 1165 free (pow5_ptr);
1166 free (memory); 1166 free (memory);
1167 return NULL; 1167 return NULL;
1168 } 1168 }
1169 /* Construct 2^|s|. */ 1169 /* Construct 2^|s|. */
1170 { 1170 {
1171 mp_limb_t *ptr = pow5_ptr + pow5_len; 1171 mp_limb_t *ptr = pow5_ptr + pow5_len;
1172 size_t i; 1172 size_t i;
1173 for (i = 0; i < s_limbs; i++) 1173 for (i = 0; i < s_limbs; i++)
1174 ptr[i] = 0; 1174 ptr[i] = 0;
1175 ptr[s_limbs] = (mp_limb_t) 1 << s_bits; 1175 ptr[s_limbs] = (mp_limb_t) 1 << s_bits;
1176 denominator.limbs = ptr; 1176 denominator.limbs = ptr;
1177 denominator.nlimbs = s_limbs + 1; 1177 denominator.nlimbs = s_limbs + 1;
1178 } 1178 }
1179 z_memory = divide (numerator, denominator, &z); 1179 z_memory = divide (numerator, denominator, &z);
1180 free (tmp_memory); 1180 free (tmp_memory);
1181 } 1181 }
1182 else 1182 else
1183 { 1183 {
1184 /* n < 0, s > 0. 1184 /* n < 0, s > 0.
1185 Multiply m with 2^s, then divide by pow5. */ 1185 Multiply m with 2^s, then divide by pow5. */
1186 mpn_t numerator; 1186 mpn_t numerator;
1187 mp_limb_t *num_ptr; 1187 mp_limb_t *num_ptr;
1188 num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) 1188 num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1)
1189 * sizeof (mp_limb_t)); 1189 * sizeof (mp_limb_t));
1190 if (num_ptr == NULL) 1190 if (num_ptr == NULL)
1191 { 1191 {
1192 free (pow5_ptr); 1192 free (pow5_ptr);
1193 free (memory); 1193 free (memory);
1194 return NULL; 1194 return NULL;
1195 } 1195 }
1196 { 1196 {
1197 mp_limb_t *destptr = num_ptr; 1197 mp_limb_t *destptr = num_ptr;
1198 { 1198 {
1199 size_t i; 1199 size_t i;
1200 for (i = 0; i < s_limbs; i++) 1200 for (i = 0; i < s_limbs; i++)
1201 *destptr++ = 0; 1201 *destptr++ = 0;
1202 } 1202 }
1203 if (s_bits > 0) 1203 if (s_bits > 0)
1204 { 1204 {
1205 const mp_limb_t *sourceptr = m.limbs; 1205 const mp_limb_t *sourceptr = m.limbs;
1206 mp_twolimb_t accu = 0; 1206 mp_twolimb_t accu = 0;
1207 size_t count; 1207 size_t count;
1208 for (count = m.nlimbs; count > 0; count--) 1208 for (count = m.nlimbs; count > 0; count--)
1209 { 1209 {
1210 accu += (mp_twolimb_t) *sourceptr++ << s_bits; 1210 accu += (mp_twolimb_t) *sourceptr++ << s_bits;
1211 *destptr++ = (mp_limb_t) accu; 1211 *destptr++ = (mp_limb_t) accu;
1212 accu = accu >> GMP_LIMB_BITS; 1212 accu = accu >> GMP_LIMB_BITS;
1213 } 1213 }
1214 if (accu > 0) 1214 if (accu > 0)
1215 *destptr++ = (mp_limb_t) accu; 1215 *destptr++ = (mp_limb_t) accu;
1216 } 1216 }
1217 else 1217 else
1218 { 1218 {
1219 const mp_limb_t *sourceptr = m.limbs; 1219 const mp_limb_t *sourceptr = m.limbs;
1220 size_t count; 1220 size_t count;
1221 for (count = m.nlimbs; count > 0; count--) 1221 for (count = m.nlimbs; count > 0; count--)
1222 *destptr++ = *sourceptr++; 1222 *destptr++ = *sourceptr++;
1223 } 1223 }
1224 numerator.limbs = num_ptr; 1224 numerator.limbs = num_ptr;
1225 numerator.nlimbs = destptr - num_ptr; 1225 numerator.nlimbs = destptr - num_ptr;
1226 } 1226 }
1227 z_memory = divide (numerator, pow5, &z); 1227 z_memory = divide (numerator, pow5, &z);
1228 free (num_ptr); 1228 free (num_ptr);
1229 } 1229 }
1230 } 1230 }
1231 free (pow5_ptr); 1231 free (pow5_ptr);
1232 free (memory); 1232 free (memory);
@@ -1298,35 +1298,35 @@ floorlog10l (long double x)
1298 if (y < 0.5L) 1298 if (y < 0.5L)
1299 { 1299 {
1300 while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) 1300 while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
1301 { 1301 {
1302 y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); 1302 y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
1303 exp -= GMP_LIMB_BITS; 1303 exp -= GMP_LIMB_BITS;
1304 } 1304 }
1305 if (y < (1.0L / (1 << 16))) 1305 if (y < (1.0L / (1 << 16)))
1306 { 1306 {
1307 y *= 1.0L * (1 << 16); 1307 y *= 1.0L * (1 << 16);
1308 exp -= 16; 1308 exp -= 16;
1309 } 1309 }
1310 if (y < (1.0L / (1 << 8))) 1310 if (y < (1.0L / (1 << 8)))
1311 { 1311 {
1312 y *= 1.0L * (1 << 8); 1312 y *= 1.0L * (1 << 8);
1313 exp -= 8; 1313 exp -= 8;
1314 } 1314 }
1315 if (y < (1.0L / (1 << 4))) 1315 if (y < (1.0L / (1 << 4)))
1316 { 1316 {
1317 y *= 1.0L * (1 << 4); 1317 y *= 1.0L * (1 << 4);
1318 exp -= 4; 1318 exp -= 4;
1319 } 1319 }
1320 if (y < (1.0L / (1 << 2))) 1320 if (y < (1.0L / (1 << 2)))
1321 { 1321 {
1322 y *= 1.0L * (1 << 2); 1322 y *= 1.0L * (1 << 2);
1323 exp -= 2; 1323 exp -= 2;
1324 } 1324 }
1325 if (y < (1.0L / (1 << 1))) 1325 if (y < (1.0L / (1 << 1)))
1326 { 1326 {
1327 y *= 1.0L * (1 << 1); 1327 y *= 1.0L * (1 << 1);
1328 exp -= 1; 1328 exp -= 1;
1329 } 1329 }
1330 } 1330 }
1331 if (!(y >= 0.5L && y < 1.0L)) 1331 if (!(y >= 0.5L && y < 1.0L))
1332 abort (); 1332 abort ();
@@ -1389,35 +1389,35 @@ floorlog10 (double x)
1389 if (y < 0.5) 1389 if (y < 0.5)
1390 { 1390 {
1391 while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) 1391 while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
1392 { 1392 {
1393 y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); 1393 y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
1394 exp -= GMP_LIMB_BITS; 1394 exp -= GMP_LIMB_BITS;
1395 } 1395 }
1396 if (y < (1.0 / (1 << 16))) 1396 if (y < (1.0 / (1 << 16)))
1397 { 1397 {
1398 y *= 1.0 * (1 << 16); 1398 y *= 1.0 * (1 << 16);
1399 exp -= 16; 1399 exp -= 16;
1400 } 1400 }
1401 if (y < (1.0 / (1 << 8))) 1401 if (y < (1.0 / (1 << 8)))
1402 { 1402 {
1403 y *= 1.0 * (1 << 8); 1403 y *= 1.0 * (1 << 8);
1404 exp -= 8; 1404 exp -= 8;
1405 } 1405 }
1406 if (y < (1.0 / (1 << 4))) 1406 if (y < (1.0 / (1 << 4)))
1407 { 1407 {
1408 y *= 1.0 * (1 << 4); 1408 y *= 1.0 * (1 << 4);
1409 exp -= 4; 1409 exp -= 4;
1410 } 1410 }
1411 if (y < (1.0 / (1 << 2))) 1411 if (y < (1.0 / (1 << 2)))
1412 { 1412 {
1413 y *= 1.0 * (1 << 2); 1413 y *= 1.0 * (1 << 2);
1414 exp -= 2; 1414 exp -= 2;
1415 } 1415 }
1416 if (y < (1.0 / (1 << 1))) 1416 if (y < (1.0 / (1 << 1)))
1417 { 1417 {
1418 y *= 1.0 * (1 << 1); 1418 y *= 1.0 * (1 << 1);
1419 exp -= 1; 1419 exp -= 1;
1420 } 1420 }
1421 } 1421 }
1422 if (!(y >= 0.5 && y < 1.0)) 1422 if (!(y >= 0.5 && y < 1.0))
1423 abort (); 1423 abort ();
@@ -1476,7 +1476,7 @@ is_borderline (const char *digits, size_t precision)
1476 1476
1477DCHAR_T * 1477DCHAR_T *
1478VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, 1478VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1479 const FCHAR_T *format, va_list args) 1479 const FCHAR_T *format, va_list args)
1480{ 1480{
1481 DIRECTIVES d; 1481 DIRECTIVES d;
1482 arguments a; 1482 arguments a;
@@ -1486,8 +1486,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1486 return NULL; 1486 return NULL;
1487 1487
1488#define CLEANUP() \ 1488#define CLEANUP() \
1489 free (d.dir); \ 1489 free (d.dir); \
1490 if (a.arg) \ 1490 if (a.arg) \
1491 free (a.arg); 1491 free (a.arg);
1492 1492
1493 if (PRINTF_FETCHARGS (args, &a) < 0) 1493 if (PRINTF_FETCHARGS (args, &a) < 0)
@@ -1516,30 +1516,30 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1516#if HAVE_ALLOCA 1516#if HAVE_ALLOCA
1517 if (buf_neededlength < 4000 / sizeof (TCHAR_T)) 1517 if (buf_neededlength < 4000 / sizeof (TCHAR_T))
1518 { 1518 {
1519 buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); 1519 buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T));
1520 buf_malloced = NULL; 1520 buf_malloced = NULL;
1521 } 1521 }
1522 else 1522 else
1523#endif 1523#endif
1524 { 1524 {
1525 size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); 1525 size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T));
1526 if (size_overflow_p (buf_memsize)) 1526 if (size_overflow_p (buf_memsize))
1527 goto out_of_memory_1; 1527 goto out_of_memory_1;
1528 buf = (TCHAR_T *) malloc (buf_memsize); 1528 buf = (TCHAR_T *) malloc (buf_memsize);
1529 if (buf == NULL) 1529 if (buf == NULL)
1530 goto out_of_memory_1; 1530 goto out_of_memory_1;
1531 buf_malloced = buf; 1531 buf_malloced = buf;
1532 } 1532 }
1533 1533
1534 if (resultbuf != NULL) 1534 if (resultbuf != NULL)
1535 { 1535 {
1536 result = resultbuf; 1536 result = resultbuf;
1537 allocated = *lengthp; 1537 allocated = *lengthp;
1538 } 1538 }
1539 else 1539 else
1540 { 1540 {
1541 result = NULL; 1541 result = NULL;
1542 allocated = 0; 1542 allocated = 0;
1543 } 1543 }
1544 length = 0; 1544 length = 0;
1545 /* Invariants: 1545 /* Invariants:
@@ -1549,3881 +1549,3881 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1549 /* Ensures that allocated >= needed. Aborts through a jump to 1549 /* Ensures that allocated >= needed. Aborts through a jump to
1550 out_of_memory if needed is SIZE_MAX or otherwise too big. */ 1550 out_of_memory if needed is SIZE_MAX or otherwise too big. */
1551#define ENSURE_ALLOCATION(needed) \ 1551#define ENSURE_ALLOCATION(needed) \
1552 if ((needed) > allocated) \ 1552 if ((needed) > allocated) \
1553 { \ 1553 { \
1554 size_t memory_size; \ 1554 size_t memory_size; \
1555 DCHAR_T *memory; \ 1555 DCHAR_T *memory; \
1556 \ 1556 \
1557 allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ 1557 allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \
1558 if ((needed) > allocated) \ 1558 if ((needed) > allocated) \
1559 allocated = (needed); \ 1559 allocated = (needed); \
1560 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ 1560 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
1561 if (size_overflow_p (memory_size)) \ 1561 if (size_overflow_p (memory_size)) \
1562 goto out_of_memory; \ 1562 goto out_of_memory; \
1563 if (result == resultbuf || result == NULL) \ 1563 if (result == resultbuf || result == NULL) \
1564 memory = (DCHAR_T *) malloc (memory_size); \ 1564 memory = (DCHAR_T *) malloc (memory_size); \
1565 else \ 1565 else \
1566 memory = (DCHAR_T *) realloc (result, memory_size); \ 1566 memory = (DCHAR_T *) realloc (result, memory_size); \
1567 if (memory == NULL) \ 1567 if (memory == NULL) \
1568 goto out_of_memory; \ 1568 goto out_of_memory; \
1569 if (result == resultbuf && length > 0) \ 1569 if (result == resultbuf && length > 0) \
1570 DCHAR_CPY (memory, result, length); \ 1570 DCHAR_CPY (memory, result, length); \
1571 result = memory; \ 1571 result = memory; \
1572 } 1572 }
1573 1573
1574 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) 1574 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
1575 { 1575 {
1576 if (cp != dp->dir_start) 1576 if (cp != dp->dir_start)
1577 { 1577 {
1578 size_t n = dp->dir_start - cp; 1578 size_t n = dp->dir_start - cp;
1579 size_t augmented_length = xsum (length, n); 1579 size_t augmented_length = xsum (length, n);
1580 1580
1581 ENSURE_ALLOCATION (augmented_length); 1581 ENSURE_ALLOCATION (augmented_length);
1582 /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we 1582 /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we
1583 need that the format string contains only ASCII characters 1583 need that the format string contains only ASCII characters
1584 if FCHAR_T and DCHAR_T are not the same type. */ 1584 if FCHAR_T and DCHAR_T are not the same type. */
1585 if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) 1585 if (sizeof (FCHAR_T) == sizeof (DCHAR_T))
1586 { 1586 {
1587 DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); 1587 DCHAR_CPY (result + length, (const DCHAR_T *) cp, n);
1588 length = augmented_length; 1588 length = augmented_length;
1589 } 1589 }
1590 else 1590 else
1591 { 1591 {
1592 do 1592 do
1593 result[length++] = (unsigned char) *cp++; 1593 result[length++] = (unsigned char) *cp++;
1594 while (--n > 0); 1594 while (--n > 0);
1595 } 1595 }
1596 } 1596 }
1597 if (i == d.count) 1597 if (i == d.count)
1598 break; 1598 break;
1599 1599
1600 /* Execute a single directive. */ 1600 /* Execute a single directive. */
1601 if (dp->conversion == '%') 1601 if (dp->conversion == '%')
1602 { 1602 {
1603 size_t augmented_length; 1603 size_t augmented_length;
1604 1604
1605 if (!(dp->arg_index == ARG_NONE)) 1605 if (!(dp->arg_index == ARG_NONE))
1606 abort (); 1606 abort ();
1607 augmented_length = xsum (length, 1); 1607 augmented_length = xsum (length, 1);
1608 ENSURE_ALLOCATION (augmented_length); 1608 ENSURE_ALLOCATION (augmented_length);
1609 result[length] = '%'; 1609 result[length] = '%';
1610 length = augmented_length; 1610 length = augmented_length;
1611 } 1611 }
1612 else 1612 else
1613 { 1613 {
1614 if (!(dp->arg_index != ARG_NONE)) 1614 if (!(dp->arg_index != ARG_NONE))
1615 abort (); 1615 abort ();
1616 1616
1617 if (dp->conversion == 'n') 1617 if (dp->conversion == 'n')
1618 { 1618 {
1619 switch (a.arg[dp->arg_index].type) 1619 switch (a.arg[dp->arg_index].type)
1620 { 1620 {
1621 case TYPE_COUNT_SCHAR_POINTER: 1621 case TYPE_COUNT_SCHAR_POINTER:
1622 *a.arg[dp->arg_index].a.a_count_schar_pointer = length; 1622 *a.arg[dp->arg_index].a.a_count_schar_pointer = length;
1623 break; 1623 break;
1624 case TYPE_COUNT_SHORT_POINTER: 1624 case TYPE_COUNT_SHORT_POINTER:
1625 *a.arg[dp->arg_index].a.a_count_short_pointer = length; 1625 *a.arg[dp->arg_index].a.a_count_short_pointer = length;
1626 break; 1626 break;
1627 case TYPE_COUNT_INT_POINTER: 1627 case TYPE_COUNT_INT_POINTER:
1628 *a.arg[dp->arg_index].a.a_count_int_pointer = length; 1628 *a.arg[dp->arg_index].a.a_count_int_pointer = length;
1629 break; 1629 break;
1630 case TYPE_COUNT_LONGINT_POINTER: 1630 case TYPE_COUNT_LONGINT_POINTER:
1631 *a.arg[dp->arg_index].a.a_count_longint_pointer = length; 1631 *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
1632 break; 1632 break;
1633#if HAVE_LONG_LONG_INT 1633#if HAVE_LONG_LONG_INT
1634 case TYPE_COUNT_LONGLONGINT_POINTER: 1634 case TYPE_COUNT_LONGLONGINT_POINTER:
1635 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; 1635 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
1636 break; 1636 break;
1637#endif 1637#endif
1638 default: 1638 default:
1639 abort (); 1639 abort ();
1640 } 1640 }
1641 } 1641 }
1642#if ENABLE_UNISTDIO 1642#if ENABLE_UNISTDIO
1643 /* The unistdio extensions. */ 1643 /* The unistdio extensions. */
1644 else if (dp->conversion == 'U') 1644 else if (dp->conversion == 'U')
1645 { 1645 {
1646 arg_type type = a.arg[dp->arg_index].type; 1646 arg_type type = a.arg[dp->arg_index].type;
1647 int flags = dp->flags; 1647 int flags = dp->flags;
1648 int has_width; 1648 int has_width;
1649 size_t width; 1649 size_t width;
1650 int has_precision; 1650 int has_precision;
1651 size_t precision; 1651 size_t precision;
1652 1652
1653 has_width = 0; 1653 has_width = 0;
1654 width = 0; 1654 width = 0;
1655 if (dp->width_start != dp->width_end) 1655 if (dp->width_start != dp->width_end)
1656 { 1656 {
1657 if (dp->width_arg_index != ARG_NONE) 1657 if (dp->width_arg_index != ARG_NONE)
1658 { 1658 {
1659 int arg; 1659 int arg;
1660 1660
1661 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 1661 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
1662 abort (); 1662 abort ();
1663 arg = a.arg[dp->width_arg_index].a.a_int; 1663 arg = a.arg[dp->width_arg_index].a.a_int;
1664 if (arg < 0) 1664 if (arg < 0)
1665 { 1665 {
1666 /* "A negative field width is taken as a '-' flag 1666 /* "A negative field width is taken as a '-' flag
1667 followed by a positive field width." */ 1667 followed by a positive field width." */
1668 flags |= FLAG_LEFT; 1668 flags |= FLAG_LEFT;
1669 width = (unsigned int) (-arg); 1669 width = (unsigned int) (-arg);
1670 } 1670 }
1671 else 1671 else
1672 width = arg; 1672 width = arg;
1673 } 1673 }
1674 else 1674 else
1675 { 1675 {
1676 const FCHAR_T *digitp = dp->width_start; 1676 const FCHAR_T *digitp = dp->width_start;
1677 1677
1678 do 1678 do
1679 width = xsum (xtimes (width, 10), *digitp++ - '0'); 1679 width = xsum (xtimes (width, 10), *digitp++ - '0');
1680 while (digitp != dp->width_end); 1680 while (digitp != dp->width_end);
1681 } 1681 }
1682 has_width = 1; 1682 has_width = 1;
1683 } 1683 }
1684 1684
1685 has_precision = 0; 1685 has_precision = 0;
1686 precision = 0; 1686 precision = 0;
1687 if (dp->precision_start != dp->precision_end) 1687 if (dp->precision_start != dp->precision_end)
1688 { 1688 {
1689 if (dp->precision_arg_index != ARG_NONE) 1689 if (dp->precision_arg_index != ARG_NONE)
1690 { 1690 {
1691 int arg; 1691 int arg;
1692 1692
1693 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 1693 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
1694 abort (); 1694 abort ();
1695 arg = a.arg[dp->precision_arg_index].a.a_int; 1695 arg = a.arg[dp->precision_arg_index].a.a_int;
1696 /* "A negative precision is taken as if the precision 1696 /* "A negative precision is taken as if the precision
1697 were omitted." */ 1697 were omitted." */
1698 if (arg >= 0) 1698 if (arg >= 0)
1699 { 1699 {
1700 precision = arg; 1700 precision = arg;
1701 has_precision = 1; 1701 has_precision = 1;
1702 } 1702 }
1703 } 1703 }
1704 else 1704 else
1705 { 1705 {
1706 const FCHAR_T *digitp = dp->precision_start + 1; 1706 const FCHAR_T *digitp = dp->precision_start + 1;
1707 1707
1708 precision = 0; 1708 precision = 0;
1709 while (digitp != dp->precision_end) 1709 while (digitp != dp->precision_end)
1710 precision = xsum (xtimes (precision, 10), *digitp++ - '0'); 1710 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
1711 has_precision = 1; 1711 has_precision = 1;
1712 } 1712 }
1713 } 1713 }
1714 1714
1715 switch (type) 1715 switch (type)
1716 { 1716 {
1717 case TYPE_U8_STRING: 1717 case TYPE_U8_STRING:
1718 { 1718 {
1719 const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; 1719 const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string;
1720 const uint8_t *arg_end; 1720 const uint8_t *arg_end;
1721 size_t characters; 1721 size_t characters;
1722 1722
1723 if (has_precision) 1723 if (has_precision)
1724 { 1724 {
1725 /* Use only PRECISION characters, from the left. */ 1725 /* Use only PRECISION characters, from the left. */
1726 arg_end = arg; 1726 arg_end = arg;
1727 characters = 0; 1727 characters = 0;
1728 for (; precision > 0; precision--) 1728 for (; precision > 0; precision--)
1729 { 1729 {
1730 int count = u8_strmblen (arg_end); 1730 int count = u8_strmblen (arg_end);
1731 if (count == 0) 1731 if (count == 0)
1732 break; 1732 break;
1733 if (count < 0) 1733 if (count < 0)
1734 { 1734 {
1735 if (!(result == resultbuf || result == NULL)) 1735 if (!(result == resultbuf || result == NULL))
1736 free (result); 1736 free (result);
1737 if (buf_malloced != NULL) 1737 if (buf_malloced != NULL)
1738 free (buf_malloced); 1738 free (buf_malloced);
1739 CLEANUP (); 1739 CLEANUP ();
1740 errno = EILSEQ; 1740 errno = EILSEQ;
1741 return NULL; 1741 return NULL;
1742 } 1742 }
1743 arg_end += count; 1743 arg_end += count;
1744 characters++; 1744 characters++;
1745 } 1745 }
1746 } 1746 }
1747 else if (has_width) 1747 else if (has_width)
1748 { 1748 {
1749 /* Use the entire string, and count the number of 1749 /* Use the entire string, and count the number of
1750 characters. */ 1750 characters. */
1751 arg_end = arg; 1751 arg_end = arg;
1752 characters = 0; 1752 characters = 0;
1753 for (;;) 1753 for (;;)
1754 { 1754 {
1755 int count = u8_strmblen (arg_end); 1755 int count = u8_strmblen (arg_end);
1756 if (count == 0) 1756 if (count == 0)
1757 break; 1757 break;
1758 if (count < 0) 1758 if (count < 0)
1759 { 1759 {
1760 if (!(result == resultbuf || result == NULL)) 1760 if (!(result == resultbuf || result == NULL))
1761 free (result); 1761 free (result);
1762 if (buf_malloced != NULL) 1762 if (buf_malloced != NULL)
1763 free (buf_malloced); 1763 free (buf_malloced);
1764 CLEANUP (); 1764 CLEANUP ();
1765 errno = EILSEQ; 1765 errno = EILSEQ;
1766 return NULL; 1766 return NULL;
1767 } 1767 }
1768 arg_end += count; 1768 arg_end += count;
1769 characters++; 1769 characters++;
1770 } 1770 }
1771 } 1771 }
1772 else 1772 else
1773 { 1773 {
1774 /* Use the entire string. */ 1774 /* Use the entire string. */
1775 arg_end = arg + u8_strlen (arg); 1775 arg_end = arg + u8_strlen (arg);
1776 /* The number of characters doesn't matter. */ 1776 /* The number of characters doesn't matter. */
1777 characters = 0; 1777 characters = 0;
1778 } 1778 }
1779 1779
1780 if (has_width && width > characters 1780 if (has_width && width > characters
1781 && !(dp->flags & FLAG_LEFT)) 1781 && !(dp->flags & FLAG_LEFT))
1782 { 1782 {
1783 size_t n = width - characters; 1783 size_t n = width - characters;
1784 ENSURE_ALLOCATION (xsum (length, n)); 1784 ENSURE_ALLOCATION (xsum (length, n));
1785 DCHAR_SET (result + length, ' ', n); 1785 DCHAR_SET (result + length, ' ', n);
1786 length += n; 1786 length += n;
1787 } 1787 }
1788 1788
1789# if DCHAR_IS_UINT8_T 1789# if DCHAR_IS_UINT8_T
1790 { 1790 {
1791 size_t n = arg_end - arg; 1791 size_t n = arg_end - arg;
1792 ENSURE_ALLOCATION (xsum (length, n)); 1792 ENSURE_ALLOCATION (xsum (length, n));
1793 DCHAR_CPY (result + length, arg, n); 1793 DCHAR_CPY (result + length, arg, n);
1794 length += n; 1794 length += n;
1795 } 1795 }
1796# else 1796# else
1797 { /* Convert. */ 1797 { /* Convert. */
1798 DCHAR_T *converted = result + length; 1798 DCHAR_T *converted = result + length;
1799 size_t converted_len = allocated - length; 1799 size_t converted_len = allocated - length;
1800# if DCHAR_IS_TCHAR 1800# if DCHAR_IS_TCHAR
1801 /* Convert from UTF-8 to locale encoding. */ 1801 /* Convert from UTF-8 to locale encoding. */
1802 converted = 1802 converted =
1803 u8_conv_to_encoding (locale_charset (), 1803 u8_conv_to_encoding (locale_charset (),
1804 iconveh_question_mark, 1804 iconveh_question_mark,
1805 arg, arg_end - arg, NULL, 1805 arg, arg_end - arg, NULL,
1806 converted, &converted_len); 1806 converted, &converted_len);
1807# else 1807# else
1808 /* Convert from UTF-8 to UTF-16/UTF-32. */ 1808 /* Convert from UTF-8 to UTF-16/UTF-32. */
1809 converted = 1809 converted =
1810 U8_TO_DCHAR (arg, arg_end - arg, 1810 U8_TO_DCHAR (arg, arg_end - arg,
1811 converted, &converted_len); 1811 converted, &converted_len);
1812# endif 1812# endif
1813 if (converted == NULL) 1813 if (converted == NULL)
1814 { 1814 {
1815 int saved_errno = errno; 1815 int saved_errno = errno;
1816 if (!(result == resultbuf || result == NULL)) 1816 if (!(result == resultbuf || result == NULL))
1817 free (result); 1817 free (result);
1818 if (buf_malloced != NULL) 1818 if (buf_malloced != NULL)
1819 free (buf_malloced); 1819 free (buf_malloced);
1820 CLEANUP (); 1820 CLEANUP ();
1821 errno = saved_errno; 1821 errno = saved_errno;
1822 return NULL; 1822 return NULL;
1823 } 1823 }
1824 if (converted != result + length) 1824 if (converted != result + length)
1825 { 1825 {
1826 ENSURE_ALLOCATION (xsum (length, converted_len)); 1826 ENSURE_ALLOCATION (xsum (length, converted_len));
1827 DCHAR_CPY (result + length, converted, converted_len); 1827 DCHAR_CPY (result + length, converted, converted_len);
1828 free (converted); 1828 free (converted);
1829 } 1829 }
1830 length += converted_len; 1830 length += converted_len;
1831 } 1831 }
1832# endif 1832# endif
1833 1833
1834 if (has_width && width > characters 1834 if (has_width && width > characters
1835 && (dp->flags & FLAG_LEFT)) 1835 && (dp->flags & FLAG_LEFT))
1836 { 1836 {
1837 size_t n = width - characters; 1837 size_t n = width - characters;
1838 ENSURE_ALLOCATION (xsum (length, n)); 1838 ENSURE_ALLOCATION (xsum (length, n));
1839 DCHAR_SET (result + length, ' ', n); 1839 DCHAR_SET (result + length, ' ', n);
1840 length += n; 1840 length += n;
1841 } 1841 }
1842 } 1842 }
1843 break; 1843 break;
1844 1844
1845 case TYPE_U16_STRING: 1845 case TYPE_U16_STRING:
1846 { 1846 {
1847 const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; 1847 const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string;
1848 const uint16_t *arg_end; 1848 const uint16_t *arg_end;
1849 size_t characters; 1849 size_t characters;
1850 1850
1851 if (has_precision) 1851 if (has_precision)
1852 { 1852 {
1853 /* Use only PRECISION characters, from the left. */ 1853 /* Use only PRECISION characters, from the left. */
1854 arg_end = arg; 1854 arg_end = arg;
1855 characters = 0; 1855 characters = 0;
1856 for (; precision > 0; precision--) 1856 for (; precision > 0; precision--)
1857 { 1857 {
1858 int count = u16_strmblen (arg_end); 1858 int count = u16_strmblen (arg_end);
1859 if (count == 0) 1859 if (count == 0)
1860 break; 1860 break;
1861 if (count < 0) 1861 if (count < 0)
1862 { 1862 {
1863 if (!(result == resultbuf || result == NULL)) 1863 if (!(result == resultbuf || result == NULL))
1864 free (result); 1864 free (result);
1865 if (buf_malloced != NULL) 1865 if (buf_malloced != NULL)
1866 free (buf_malloced); 1866 free (buf_malloced);
1867 CLEANUP (); 1867 CLEANUP ();
1868 errno = EILSEQ; 1868 errno = EILSEQ;
1869 return NULL; 1869 return NULL;
1870 } 1870 }
1871 arg_end += count; 1871 arg_end += count;
1872 characters++; 1872 characters++;
1873 } 1873 }
1874 } 1874 }
1875 else if (has_width) 1875 else if (has_width)
1876 { 1876 {
1877 /* Use the entire string, and count the number of 1877 /* Use the entire string, and count the number of
1878 characters. */ 1878 characters. */
1879 arg_end = arg; 1879 arg_end = arg;
1880 characters = 0; 1880 characters = 0;
1881 for (;;) 1881 for (;;)
1882 { 1882 {
1883 int count = u16_strmblen (arg_end); 1883 int count = u16_strmblen (arg_end);
1884 if (count == 0) 1884 if (count == 0)
1885 break; 1885 break;
1886 if (count < 0) 1886 if (count < 0)
1887 { 1887 {
1888 if (!(result == resultbuf || result == NULL)) 1888 if (!(result == resultbuf || result == NULL))
1889 free (result); 1889 free (result);
1890 if (buf_malloced != NULL) 1890 if (buf_malloced != NULL)
1891 free (buf_malloced); 1891 free (buf_malloced);
1892 CLEANUP (); 1892 CLEANUP ();
1893 errno = EILSEQ; 1893 errno = EILSEQ;
1894 return NULL; 1894 return NULL;
1895 } 1895 }
1896 arg_end += count; 1896 arg_end += count;
1897 characters++; 1897 characters++;
1898 } 1898 }
1899 } 1899 }
1900 else 1900 else
1901 { 1901 {
1902 /* Use the entire string. */ 1902 /* Use the entire string. */
1903 arg_end = arg + u16_strlen (arg); 1903 arg_end = arg + u16_strlen (arg);
1904 /* The number of characters doesn't matter. */ 1904 /* The number of characters doesn't matter. */
1905 characters = 0; 1905 characters = 0;
1906 } 1906 }
1907 1907
1908 if (has_width && width > characters 1908 if (has_width && width > characters
1909 && !(dp->flags & FLAG_LEFT)) 1909 && !(dp->flags & FLAG_LEFT))
1910 { 1910 {
1911 size_t n = width - characters; 1911 size_t n = width - characters;
1912 ENSURE_ALLOCATION (xsum (length, n)); 1912 ENSURE_ALLOCATION (xsum (length, n));
1913 DCHAR_SET (result + length, ' ', n); 1913 DCHAR_SET (result + length, ' ', n);
1914 length += n; 1914 length += n;
1915 } 1915 }
1916 1916
1917# if DCHAR_IS_UINT16_T 1917# if DCHAR_IS_UINT16_T
1918 { 1918 {
1919 size_t n = arg_end - arg; 1919 size_t n = arg_end - arg;
1920 ENSURE_ALLOCATION (xsum (length, n)); 1920 ENSURE_ALLOCATION (xsum (length, n));
1921 DCHAR_CPY (result + length, arg, n); 1921 DCHAR_CPY (result + length, arg, n);
1922 length += n; 1922 length += n;
1923 } 1923 }
1924# else 1924# else
1925 { /* Convert. */ 1925 { /* Convert. */
1926 DCHAR_T *converted = result + length; 1926 DCHAR_T *converted = result + length;
1927 size_t converted_len = allocated - length; 1927 size_t converted_len = allocated - length;
1928# if DCHAR_IS_TCHAR 1928# if DCHAR_IS_TCHAR
1929 /* Convert from UTF-16 to locale encoding. */ 1929 /* Convert from UTF-16 to locale encoding. */
1930 converted = 1930 converted =
1931 u16_conv_to_encoding (locale_charset (), 1931 u16_conv_to_encoding (locale_charset (),
1932 iconveh_question_mark, 1932 iconveh_question_mark,
1933 arg, arg_end - arg, NULL, 1933 arg, arg_end - arg, NULL,
1934 converted, &converted_len); 1934 converted, &converted_len);
1935# else 1935# else
1936 /* Convert from UTF-16 to UTF-8/UTF-32. */ 1936 /* Convert from UTF-16 to UTF-8/UTF-32. */
1937 converted = 1937 converted =
1938 U16_TO_DCHAR (arg, arg_end - arg, 1938 U16_TO_DCHAR (arg, arg_end - arg,
1939 converted, &converted_len); 1939 converted, &converted_len);
1940# endif 1940# endif
1941 if (converted == NULL) 1941 if (converted == NULL)
1942 { 1942 {
1943 int saved_errno = errno; 1943 int saved_errno = errno;
1944 if (!(result == resultbuf || result == NULL)) 1944 if (!(result == resultbuf || result == NULL))
1945 free (result); 1945 free (result);
1946 if (buf_malloced != NULL) 1946 if (buf_malloced != NULL)
1947 free (buf_malloced); 1947 free (buf_malloced);
1948 CLEANUP (); 1948 CLEANUP ();
1949 errno = saved_errno; 1949 errno = saved_errno;
1950 return NULL; 1950 return NULL;
1951 } 1951 }
1952 if (converted != result + length) 1952 if (converted != result + length)
1953 { 1953 {
1954 ENSURE_ALLOCATION (xsum (length, converted_len)); 1954 ENSURE_ALLOCATION (xsum (length, converted_len));
1955 DCHAR_CPY (result + length, converted, converted_len); 1955 DCHAR_CPY (result + length, converted, converted_len);
1956 free (converted); 1956 free (converted);
1957 } 1957 }
1958 length += converted_len; 1958 length += converted_len;
1959 } 1959 }
1960# endif 1960# endif
1961 1961
1962 if (has_width && width > characters 1962 if (has_width && width > characters
1963 && (dp->flags & FLAG_LEFT)) 1963 && (dp->flags & FLAG_LEFT))
1964 { 1964 {
1965 size_t n = width - characters; 1965 size_t n = width - characters;
1966 ENSURE_ALLOCATION (xsum (length, n)); 1966 ENSURE_ALLOCATION (xsum (length, n));
1967 DCHAR_SET (result + length, ' ', n); 1967 DCHAR_SET (result + length, ' ', n);
1968 length += n; 1968 length += n;
1969 } 1969 }
1970 } 1970 }
1971 break; 1971 break;
1972 1972
1973 case TYPE_U32_STRING: 1973 case TYPE_U32_STRING:
1974 { 1974 {
1975 const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; 1975 const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string;
1976 const uint32_t *arg_end; 1976 const uint32_t *arg_end;
1977 size_t characters; 1977 size_t characters;
1978 1978
1979 if (has_precision) 1979 if (has_precision)
1980 { 1980 {
1981 /* Use only PRECISION characters, from the left. */ 1981 /* Use only PRECISION characters, from the left. */
1982 arg_end = arg; 1982 arg_end = arg;
1983 characters = 0; 1983 characters = 0;
1984 for (; precision > 0; precision--) 1984 for (; precision > 0; precision--)
1985 { 1985 {
1986 int count = u32_strmblen (arg_end); 1986 int count = u32_strmblen (arg_end);
1987 if (count == 0) 1987 if (count == 0)
1988 break; 1988 break;
1989 if (count < 0) 1989 if (count < 0)
1990 { 1990 {
1991 if (!(result == resultbuf || result == NULL)) 1991 if (!(result == resultbuf || result == NULL))
1992 free (result); 1992 free (result);
1993 if (buf_malloced != NULL) 1993 if (buf_malloced != NULL)
1994 free (buf_malloced); 1994 free (buf_malloced);
1995 CLEANUP (); 1995 CLEANUP ();
1996 errno = EILSEQ; 1996 errno = EILSEQ;
1997 return NULL; 1997 return NULL;
1998 } 1998 }
1999 arg_end += count; 1999 arg_end += count;
2000 characters++; 2000 characters++;
2001 } 2001 }
2002 } 2002 }
2003 else if (has_width) 2003 else if (has_width)
2004 { 2004 {
2005 /* Use the entire string, and count the number of 2005 /* Use the entire string, and count the number of
2006 characters. */ 2006 characters. */
2007 arg_end = arg; 2007 arg_end = arg;
2008 characters = 0; 2008 characters = 0;
2009 for (;;) 2009 for (;;)
2010 { 2010 {
2011 int count = u32_strmblen (arg_end); 2011 int count = u32_strmblen (arg_end);
2012 if (count == 0) 2012 if (count == 0)
2013 break; 2013 break;
2014 if (count < 0) 2014 if (count < 0)
2015 { 2015 {
2016 if (!(result == resultbuf || result == NULL)) 2016 if (!(result == resultbuf || result == NULL))
2017 free (result); 2017 free (result);
2018 if (buf_malloced != NULL) 2018 if (buf_malloced != NULL)
2019 free (buf_malloced); 2019 free (buf_malloced);
2020 CLEANUP (); 2020 CLEANUP ();
2021 errno = EILSEQ; 2021 errno = EILSEQ;
2022 return NULL; 2022 return NULL;
2023 } 2023 }
2024 arg_end += count; 2024 arg_end += count;
2025 characters++; 2025 characters++;
2026 } 2026 }
2027 } 2027 }
2028 else 2028 else
2029 { 2029 {
2030 /* Use the entire string. */ 2030 /* Use the entire string. */
2031 arg_end = arg + u32_strlen (arg); 2031 arg_end = arg + u32_strlen (arg);
2032 /* The number of characters doesn't matter. */ 2032 /* The number of characters doesn't matter. */
2033 characters = 0; 2033 characters = 0;
2034 } 2034 }
2035 2035
2036 if (has_width && width > characters 2036 if (has_width && width > characters
2037 && !(dp->flags & FLAG_LEFT)) 2037 && !(dp->flags & FLAG_LEFT))
2038 { 2038 {
2039 size_t n = width - characters; 2039 size_t n = width - characters;
2040 ENSURE_ALLOCATION (xsum (length, n)); 2040 ENSURE_ALLOCATION (xsum (length, n));
2041 DCHAR_SET (result + length, ' ', n); 2041 DCHAR_SET (result + length, ' ', n);
2042 length += n; 2042 length += n;
2043 } 2043 }
2044 2044
2045# if DCHAR_IS_UINT32_T 2045# if DCHAR_IS_UINT32_T
2046 { 2046 {
2047 size_t n = arg_end - arg; 2047 size_t n = arg_end - arg;
2048 ENSURE_ALLOCATION (xsum (length, n)); 2048 ENSURE_ALLOCATION (xsum (length, n));
2049 DCHAR_CPY (result + length, arg, n); 2049 DCHAR_CPY (result + length, arg, n);
2050 length += n; 2050 length += n;
2051 } 2051 }
2052# else 2052# else
2053 { /* Convert. */ 2053 { /* Convert. */
2054 DCHAR_T *converted = result + length; 2054 DCHAR_T *converted = result + length;
2055 size_t converted_len = allocated - length; 2055 size_t converted_len = allocated - length;
2056# if DCHAR_IS_TCHAR 2056# if DCHAR_IS_TCHAR
2057 /* Convert from UTF-32 to locale encoding. */ 2057 /* Convert from UTF-32 to locale encoding. */
2058 converted = 2058 converted =
2059 u32_conv_to_encoding (locale_charset (), 2059 u32_conv_to_encoding (locale_charset (),
2060 iconveh_question_mark, 2060 iconveh_question_mark,
2061 arg, arg_end - arg, NULL, 2061 arg, arg_end - arg, NULL,
2062 converted, &converted_len); 2062 converted, &converted_len);
2063# else 2063# else
2064 /* Convert from UTF-32 to UTF-8/UTF-16. */ 2064 /* Convert from UTF-32 to UTF-8/UTF-16. */
2065 converted = 2065 converted =
2066 U32_TO_DCHAR (arg, arg_end - arg, 2066 U32_TO_DCHAR (arg, arg_end - arg,
2067 converted, &converted_len); 2067 converted, &converted_len);
2068# endif 2068# endif
2069 if (converted == NULL) 2069 if (converted == NULL)
2070 { 2070 {
2071 int saved_errno = errno; 2071 int saved_errno = errno;
2072 if (!(result == resultbuf || result == NULL)) 2072 if (!(result == resultbuf || result == NULL))
2073 free (result); 2073 free (result);
2074 if (buf_malloced != NULL) 2074 if (buf_malloced != NULL)
2075 free (buf_malloced); 2075 free (buf_malloced);
2076 CLEANUP (); 2076 CLEANUP ();
2077 errno = saved_errno; 2077 errno = saved_errno;
2078 return NULL; 2078 return NULL;
2079 } 2079 }
2080 if (converted != result + length) 2080 if (converted != result + length)
2081 { 2081 {
2082 ENSURE_ALLOCATION (xsum (length, converted_len)); 2082 ENSURE_ALLOCATION (xsum (length, converted_len));
2083 DCHAR_CPY (result + length, converted, converted_len); 2083 DCHAR_CPY (result + length, converted, converted_len);
2084 free (converted); 2084 free (converted);
2085 } 2085 }
2086 length += converted_len; 2086 length += converted_len;
2087 } 2087 }
2088# endif 2088# endif
2089 2089
2090 if (has_width && width > characters 2090 if (has_width && width > characters
2091 && (dp->flags & FLAG_LEFT)) 2091 && (dp->flags & FLAG_LEFT))
2092 { 2092 {
2093 size_t n = width - characters; 2093 size_t n = width - characters;
2094 ENSURE_ALLOCATION (xsum (length, n)); 2094 ENSURE_ALLOCATION (xsum (length, n));
2095 DCHAR_SET (result + length, ' ', n); 2095 DCHAR_SET (result + length, ' ', n);
2096 length += n; 2096 length += n;
2097 } 2097 }
2098 } 2098 }
2099 break; 2099 break;
2100 2100
2101 default: 2101 default:
2102 abort (); 2102 abort ();
2103 } 2103 }
2104 } 2104 }
2105#endif 2105#endif
2106#if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T 2106#if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T
2107 else if (dp->conversion == 's' 2107 else if (dp->conversion == 's'
2108# if WIDE_CHAR_VERSION 2108# if WIDE_CHAR_VERSION
2109 && a.arg[dp->arg_index].type != TYPE_WIDE_STRING 2109 && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
2110# else 2110# else
2111 && a.arg[dp->arg_index].type == TYPE_WIDE_STRING 2111 && a.arg[dp->arg_index].type == TYPE_WIDE_STRING
2112# endif 2112# endif
2113 ) 2113 )
2114 { 2114 {
2115 /* The normal handling of the 's' directive below requires 2115 /* The normal handling of the 's' directive below requires
2116 allocating a temporary buffer. The determination of its 2116 allocating a temporary buffer. The determination of its
2117 length (tmp_length), in the case when a precision is 2117 length (tmp_length), in the case when a precision is
2118 specified, below requires a conversion between a char[] 2118 specified, below requires a conversion between a char[]
2119 string and a wchar_t[] wide string. It could be done, but 2119 string and a wchar_t[] wide string. It could be done, but
2120 we have no guarantee that the implementation of sprintf will 2120 we have no guarantee that the implementation of sprintf will
2121 use the exactly same algorithm. Without this guarantee, it 2121 use the exactly same algorithm. Without this guarantee, it
2122 is possible to have buffer overrun bugs. In order to avoid 2122 is possible to have buffer overrun bugs. In order to avoid
2123 such bugs, we implement the entire processing of the 's' 2123 such bugs, we implement the entire processing of the 's'
2124 directive ourselves. */ 2124 directive ourselves. */
2125 int flags = dp->flags; 2125 int flags = dp->flags;
2126 int has_width; 2126 int has_width;
2127 size_t width; 2127 size_t width;
2128 int has_precision; 2128 int has_precision;
2129 size_t precision; 2129 size_t precision;
2130 2130
2131 has_width = 0; 2131 has_width = 0;
2132 width = 0; 2132 width = 0;
2133 if (dp->width_start != dp->width_end) 2133 if (dp->width_start != dp->width_end)
2134 { 2134 {
2135 if (dp->width_arg_index != ARG_NONE) 2135 if (dp->width_arg_index != ARG_NONE)
2136 { 2136 {
2137 int arg; 2137 int arg;
2138 2138
2139 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 2139 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2140 abort (); 2140 abort ();
2141 arg = a.arg[dp->width_arg_index].a.a_int; 2141 arg = a.arg[dp->width_arg_index].a.a_int;
2142 if (arg < 0) 2142 if (arg < 0)
2143 { 2143 {
2144 /* "A negative field width is taken as a '-' flag 2144 /* "A negative field width is taken as a '-' flag
2145 followed by a positive field width." */ 2145 followed by a positive field width." */
2146 flags |= FLAG_LEFT; 2146 flags |= FLAG_LEFT;
2147 width = (unsigned int) (-arg); 2147 width = (unsigned int) (-arg);
2148 } 2148 }
2149 else 2149 else
2150 width = arg; 2150 width = arg;
2151 } 2151 }
2152 else 2152 else
2153 { 2153 {
2154 const FCHAR_T *digitp = dp->width_start; 2154 const FCHAR_T *digitp = dp->width_start;
2155 2155
2156 do 2156 do
2157 width = xsum (xtimes (width, 10), *digitp++ - '0'); 2157 width = xsum (xtimes (width, 10), *digitp++ - '0');
2158 while (digitp != dp->width_end); 2158 while (digitp != dp->width_end);
2159 } 2159 }
2160 has_width = 1; 2160 has_width = 1;
2161 } 2161 }
2162 2162
2163 has_precision = 0; 2163 has_precision = 0;
2164 precision = 6; 2164 precision = 6;
2165 if (dp->precision_start != dp->precision_end) 2165 if (dp->precision_start != dp->precision_end)
2166 { 2166 {
2167 if (dp->precision_arg_index != ARG_NONE) 2167 if (dp->precision_arg_index != ARG_NONE)
2168 { 2168 {
2169 int arg; 2169 int arg;
2170 2170
2171 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 2171 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
2172 abort (); 2172 abort ();
2173 arg = a.arg[dp->precision_arg_index].a.a_int; 2173 arg = a.arg[dp->precision_arg_index].a.a_int;
2174 /* "A negative precision is taken as if the precision 2174 /* "A negative precision is taken as if the precision
2175 were omitted." */ 2175 were omitted." */
2176 if (arg >= 0) 2176 if (arg >= 0)
2177 { 2177 {
2178 precision = arg; 2178 precision = arg;
2179 has_precision = 1; 2179 has_precision = 1;
2180 } 2180 }
2181 } 2181 }
2182 else 2182 else
2183 { 2183 {
2184 const FCHAR_T *digitp = dp->precision_start + 1; 2184 const FCHAR_T *digitp = dp->precision_start + 1;
2185 2185
2186 precision = 0; 2186 precision = 0;
2187 while (digitp != dp->precision_end) 2187 while (digitp != dp->precision_end)
2188 precision = xsum (xtimes (precision, 10), *digitp++ - '0'); 2188 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
2189 has_precision = 1; 2189 has_precision = 1;
2190 } 2190 }
2191 } 2191 }
2192 2192
2193# if WIDE_CHAR_VERSION 2193# if WIDE_CHAR_VERSION
2194 /* %s in vasnwprintf. See the specification of fwprintf. */ 2194 /* %s in vasnwprintf. See the specification of fwprintf. */
2195 { 2195 {
2196 const char *arg = a.arg[dp->arg_index].a.a_string; 2196 const char *arg = a.arg[dp->arg_index].a.a_string;
2197 const char *arg_end; 2197 const char *arg_end;
2198 size_t characters; 2198 size_t characters;
2199 2199
2200 if (has_precision) 2200 if (has_precision)
2201 { 2201 {
2202 /* Use only as many bytes as needed to produce PRECISION 2202 /* Use only as many bytes as needed to produce PRECISION
2203 wide characters, from the left. */ 2203 wide characters, from the left. */
2204# if HAVE_MBRTOWC 2204# if HAVE_MBRTOWC
2205 mbstate_t state; 2205 mbstate_t state;
2206 memset (&state, '\0', sizeof (mbstate_t)); 2206 memset (&state, '\0', sizeof (mbstate_t));
2207# endif 2207# endif
2208 arg_end = arg; 2208 arg_end = arg;
2209 characters = 0; 2209 characters = 0;
2210 for (; precision > 0; precision--) 2210 for (; precision > 0; precision--)
2211 { 2211 {
2212 int count; 2212 int count;
2213# if HAVE_MBRTOWC 2213# if HAVE_MBRTOWC
2214 count = mbrlen (arg_end, MB_CUR_MAX, &state); 2214 count = mbrlen (arg_end, MB_CUR_MAX, &state);
2215# else 2215# else
2216 count = mblen (arg_end, MB_CUR_MAX); 2216 count = mblen (arg_end, MB_CUR_MAX);
2217# endif 2217# endif
2218 if (count == 0) 2218 if (count == 0)
2219 /* Found the terminating NUL. */ 2219 /* Found the terminating NUL. */
2220 break; 2220 break;
2221 if (count < 0) 2221 if (count < 0)
2222 { 2222 {
2223 /* Invalid or incomplete multibyte character. */ 2223 /* Invalid or incomplete multibyte character. */
2224 if (!(result == resultbuf || result == NULL)) 2224 if (!(result == resultbuf || result == NULL))
2225 free (result); 2225 free (result);
2226 if (buf_malloced != NULL) 2226 if (buf_malloced != NULL)
2227 free (buf_malloced); 2227 free (buf_malloced);
2228 CLEANUP (); 2228 CLEANUP ();
2229 errno = EILSEQ; 2229 errno = EILSEQ;
2230 return NULL; 2230 return NULL;
2231 } 2231 }
2232 arg_end += count; 2232 arg_end += count;
2233 characters++; 2233 characters++;
2234 } 2234 }
2235 } 2235 }
2236 else if (has_width) 2236 else if (has_width)
2237 { 2237 {
2238 /* Use the entire string, and count the number of wide 2238 /* Use the entire string, and count the number of wide
2239 characters. */ 2239 characters. */
2240# if HAVE_MBRTOWC 2240# if HAVE_MBRTOWC
2241 mbstate_t state; 2241 mbstate_t state;
2242 memset (&state, '\0', sizeof (mbstate_t)); 2242 memset (&state, '\0', sizeof (mbstate_t));
2243# endif 2243# endif
2244 arg_end = arg; 2244 arg_end = arg;
2245 characters = 0; 2245 characters = 0;
2246 for (;;) 2246 for (;;)
2247 { 2247 {
2248 int count; 2248 int count;
2249# if HAVE_MBRTOWC 2249# if HAVE_MBRTOWC
2250 count = mbrlen (arg_end, MB_CUR_MAX, &state); 2250 count = mbrlen (arg_end, MB_CUR_MAX, &state);
2251# else 2251# else
2252 count = mblen (arg_end, MB_CUR_MAX); 2252 count = mblen (arg_end, MB_CUR_MAX);
2253# endif 2253# endif
2254 if (count == 0) 2254 if (count == 0)
2255 /* Found the terminating NUL. */ 2255 /* Found the terminating NUL. */
2256 break; 2256 break;
2257 if (count < 0) 2257 if (count < 0)
2258 { 2258 {
2259 /* Invalid or incomplete multibyte character. */ 2259 /* Invalid or incomplete multibyte character. */
2260 if (!(result == resultbuf || result == NULL)) 2260 if (!(result == resultbuf || result == NULL))
2261 free (result); 2261 free (result);
2262 if (buf_malloced != NULL) 2262 if (buf_malloced != NULL)
2263 free (buf_malloced); 2263 free (buf_malloced);
2264 CLEANUP (); 2264 CLEANUP ();
2265 errno = EILSEQ; 2265 errno = EILSEQ;
2266 return NULL; 2266 return NULL;
2267 } 2267 }
2268 arg_end += count; 2268 arg_end += count;
2269 characters++; 2269 characters++;
2270 } 2270 }
2271 } 2271 }
2272 else 2272 else
2273 { 2273 {
2274 /* Use the entire string. */ 2274 /* Use the entire string. */
2275 arg_end = arg + strlen (arg); 2275 arg_end = arg + strlen (arg);
2276 /* The number of characters doesn't matter. */ 2276 /* The number of characters doesn't matter. */
2277 characters = 0; 2277 characters = 0;
2278 } 2278 }
2279 2279
2280 if (has_width && width > characters 2280 if (has_width && width > characters
2281 && !(dp->flags & FLAG_LEFT)) 2281 && !(dp->flags & FLAG_LEFT))
2282 { 2282 {
2283 size_t n = width - characters; 2283 size_t n = width - characters;
2284 ENSURE_ALLOCATION (xsum (length, n)); 2284 ENSURE_ALLOCATION (xsum (length, n));
2285 DCHAR_SET (result + length, ' ', n); 2285 DCHAR_SET (result + length, ' ', n);
2286 length += n; 2286 length += n;
2287 } 2287 }
2288 2288
2289 if (has_precision || has_width) 2289 if (has_precision || has_width)
2290 { 2290 {
2291 /* We know the number of wide characters in advance. */ 2291 /* We know the number of wide characters in advance. */
2292 size_t remaining; 2292 size_t remaining;
2293# if HAVE_MBRTOWC 2293# if HAVE_MBRTOWC
2294 mbstate_t state; 2294 mbstate_t state;
2295 memset (&state, '\0', sizeof (mbstate_t)); 2295 memset (&state, '\0', sizeof (mbstate_t));
2296# endif 2296# endif
2297 ENSURE_ALLOCATION (xsum (length, characters)); 2297 ENSURE_ALLOCATION (xsum (length, characters));
2298 for (remaining = characters; remaining > 0; remaining--) 2298 for (remaining = characters; remaining > 0; remaining--)
2299 { 2299 {
2300 wchar_t wc; 2300 wchar_t wc;
2301 int count; 2301 int count;
2302# if HAVE_MBRTOWC 2302# if HAVE_MBRTOWC
2303 count = mbrtowc (&wc, arg, arg_end - arg, &state); 2303 count = mbrtowc (&wc, arg, arg_end - arg, &state);
2304# else 2304# else
2305 count = mbtowc (&wc, arg, arg_end - arg); 2305 count = mbtowc (&wc, arg, arg_end - arg);
2306# endif 2306# endif
2307 if (count <= 0) 2307 if (count <= 0)
2308 /* mbrtowc not consistent with mbrlen, or mbtowc 2308 /* mbrtowc not consistent with mbrlen, or mbtowc
2309 not consistent with mblen. */ 2309 not consistent with mblen. */
2310 abort (); 2310 abort ();
2311 result[length++] = wc; 2311 result[length++] = wc;
2312 arg += count; 2312 arg += count;
2313 } 2313 }
2314 if (!(arg == arg_end)) 2314 if (!(arg == arg_end))
2315 abort (); 2315 abort ();
2316 } 2316 }
2317 else 2317 else
2318 { 2318 {
2319# if HAVE_MBRTOWC 2319# if HAVE_MBRTOWC
2320 mbstate_t state; 2320 mbstate_t state;
2321 memset (&state, '\0', sizeof (mbstate_t)); 2321 memset (&state, '\0', sizeof (mbstate_t));
2322# endif 2322# endif
2323 while (arg < arg_end) 2323 while (arg < arg_end)
2324 { 2324 {
2325 wchar_t wc; 2325 wchar_t wc;
2326 int count; 2326 int count;
2327# if HAVE_MBRTOWC 2327# if HAVE_MBRTOWC
2328 count = mbrtowc (&wc, arg, arg_end - arg, &state); 2328 count = mbrtowc (&wc, arg, arg_end - arg, &state);
2329# else 2329# else
2330 count = mbtowc (&wc, arg, arg_end - arg); 2330 count = mbtowc (&wc, arg, arg_end - arg);
2331# endif 2331# endif
2332 if (count <= 0) 2332 if (count <= 0)
2333 /* mbrtowc not consistent with mbrlen, or mbtowc 2333 /* mbrtowc not consistent with mbrlen, or mbtowc
2334 not consistent with mblen. */ 2334 not consistent with mblen. */
2335 abort (); 2335 abort ();
2336 ENSURE_ALLOCATION (xsum (length, 1)); 2336 ENSURE_ALLOCATION (xsum (length, 1));
2337 result[length++] = wc; 2337 result[length++] = wc;
2338 arg += count; 2338 arg += count;
2339 } 2339 }
2340 } 2340 }
2341 2341
2342 if (has_width && width > characters 2342 if (has_width && width > characters
2343 && (dp->flags & FLAG_LEFT)) 2343 && (dp->flags & FLAG_LEFT))
2344 { 2344 {
2345 size_t n = width - characters; 2345 size_t n = width - characters;
2346 ENSURE_ALLOCATION (xsum (length, n)); 2346 ENSURE_ALLOCATION (xsum (length, n));
2347 DCHAR_SET (result + length, ' ', n); 2347 DCHAR_SET (result + length, ' ', n);
2348 length += n; 2348 length += n;
2349 } 2349 }
2350 } 2350 }
2351# else 2351# else
2352 /* %ls in vasnprintf. See the specification of fprintf. */ 2352 /* %ls in vasnprintf. See the specification of fprintf. */
2353 { 2353 {
2354 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; 2354 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
2355 const wchar_t *arg_end; 2355 const wchar_t *arg_end;
2356 size_t characters; 2356 size_t characters;
2357# if !DCHAR_IS_TCHAR 2357# if !DCHAR_IS_TCHAR
2358 /* This code assumes that TCHAR_T is 'char'. */ 2358 /* This code assumes that TCHAR_T is 'char'. */
2359 typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; 2359 typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1];
2360 TCHAR_T *tmpsrc; 2360 TCHAR_T *tmpsrc;
2361 DCHAR_T *tmpdst; 2361 DCHAR_T *tmpdst;
2362 size_t tmpdst_len; 2362 size_t tmpdst_len;
2363# endif 2363# endif
2364 size_t w; 2364 size_t w;
2365 2365
2366 if (has_precision) 2366 if (has_precision)
2367 { 2367 {
2368 /* Use only as many wide characters as needed to produce 2368 /* Use only as many wide characters as needed to produce
2369 at most PRECISION bytes, from the left. */ 2369 at most PRECISION bytes, from the left. */
2370# if HAVE_WCRTOMB 2370# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2371 mbstate_t state; 2371 mbstate_t state;
2372 memset (&state, '\0', sizeof (mbstate_t)); 2372 memset (&state, '\0', sizeof (mbstate_t));
2373# endif 2373# endif
2374 arg_end = arg; 2374 arg_end = arg;
2375 characters = 0; 2375 characters = 0;
2376 while (precision > 0) 2376 while (precision > 0)
2377 { 2377 {
2378 char buf[64]; /* Assume MB_CUR_MAX <= 64. */ 2378 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2379 int count; 2379 int count;
2380 2380
2381 if (*arg_end == 0) 2381 if (*arg_end == 0)
2382 /* Found the terminating null wide character. */ 2382 /* Found the terminating null wide character. */
2383 break; 2383 break;
2384# if HAVE_WCRTOMB 2384# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2385 count = wcrtomb (buf, *arg_end, &state); 2385 count = wcrtomb (cbuf, *arg_end, &state);
2386# else 2386# else
2387 count = wctomb (buf, *arg_end); 2387 count = wctomb (cbuf, *arg_end);
2388# endif 2388# endif
2389 if (count < 0) 2389 if (count < 0)
2390 { 2390 {
2391 /* Cannot convert. */ 2391 /* Cannot convert. */
2392 if (!(result == resultbuf || result == NULL)) 2392 if (!(result == resultbuf || result == NULL))
2393 free (result); 2393 free (result);
2394 if (buf_malloced != NULL) 2394 if (buf_malloced != NULL)
2395 free (buf_malloced); 2395 free (buf_malloced);
2396 CLEANUP (); 2396 CLEANUP ();
2397 errno = EILSEQ; 2397 errno = EILSEQ;
2398 return NULL; 2398 return NULL;
2399 } 2399 }
2400 if (precision < count) 2400 if (precision < count)
2401 break; 2401 break;
2402 arg_end++; 2402 arg_end++;
2403 characters += count; 2403 characters += count;
2404 precision -= count; 2404 precision -= count;
2405 } 2405 }
2406 } 2406 }
2407# if DCHAR_IS_TCHAR 2407# if DCHAR_IS_TCHAR
2408 else if (has_width) 2408 else if (has_width)
2409# else 2409# else
2410 else 2410 else
2411# endif 2411# endif
2412 { 2412 {
2413 /* Use the entire string, and count the number of 2413 /* Use the entire string, and count the number of
2414 bytes. */ 2414 bytes. */
2415# if HAVE_WCRTOMB 2415# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2416 mbstate_t state; 2416 mbstate_t state;
2417 memset (&state, '\0', sizeof (mbstate_t)); 2417 memset (&state, '\0', sizeof (mbstate_t));
2418# endif 2418# endif
2419 arg_end = arg; 2419 arg_end = arg;
2420 characters = 0; 2420 characters = 0;
2421 for (;;) 2421 for (;;)
2422 { 2422 {
2423 char buf[64]; /* Assume MB_CUR_MAX <= 64. */ 2423 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2424 int count; 2424 int count;
2425 2425
2426 if (*arg_end == 0) 2426 if (*arg_end == 0)
2427 /* Found the terminating null wide character. */ 2427 /* Found the terminating null wide character. */
2428 break; 2428 break;
2429# if HAVE_WCRTOMB 2429# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2430 count = wcrtomb (buf, *arg_end, &state); 2430 count = wcrtomb (cbuf, *arg_end, &state);
2431# else 2431# else
2432 count = wctomb (buf, *arg_end); 2432 count = wctomb (cbuf, *arg_end);
2433# endif 2433# endif
2434 if (count < 0) 2434 if (count < 0)
2435 { 2435 {
2436 /* Cannot convert. */ 2436 /* Cannot convert. */
2437 if (!(result == resultbuf || result == NULL)) 2437 if (!(result == resultbuf || result == NULL))
2438 free (result); 2438 free (result);
2439 if (buf_malloced != NULL) 2439 if (buf_malloced != NULL)
2440 free (buf_malloced); 2440 free (buf_malloced);
2441 CLEANUP (); 2441 CLEANUP ();
2442 errno = EILSEQ; 2442 errno = EILSEQ;
2443 return NULL; 2443 return NULL;
2444 } 2444 }
2445 arg_end++; 2445 arg_end++;
2446 characters += count; 2446 characters += count;
2447 } 2447 }
2448 } 2448 }
2449# if DCHAR_IS_TCHAR 2449# if DCHAR_IS_TCHAR
2450 else 2450 else
2451 { 2451 {
2452 /* Use the entire string. */ 2452 /* Use the entire string. */
2453 arg_end = arg + local_wcslen (arg); 2453 arg_end = arg + local_wcslen (arg);
2454 /* The number of bytes doesn't matter. */ 2454 /* The number of bytes doesn't matter. */
2455 characters = 0; 2455 characters = 0;
2456 } 2456 }
2457# endif 2457# endif
2458 2458
2459# if !DCHAR_IS_TCHAR 2459# if !DCHAR_IS_TCHAR
2460 /* Convert the string into a piece of temporary memory. */ 2460 /* Convert the string into a piece of temporary memory. */
2461 tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); 2461 tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T));
2462 if (tmpsrc == NULL) 2462 if (tmpsrc == NULL)
2463 goto out_of_memory; 2463 goto out_of_memory;
2464 { 2464 {
2465 TCHAR_T *tmpptr = tmpsrc; 2465 TCHAR_T *tmpptr = tmpsrc;
2466 size_t remaining; 2466 size_t remaining;
2467# if HAVE_WCRTOMB 2467# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2468 mbstate_t state; 2468 mbstate_t state;
2469 memset (&state, '\0', sizeof (mbstate_t)); 2469 memset (&state, '\0', sizeof (mbstate_t));
2470# endif 2470# endif
2471 for (remaining = characters; remaining > 0; ) 2471 for (remaining = characters; remaining > 0; )
2472 { 2472 {
2473 char buf[64]; /* Assume MB_CUR_MAX <= 64. */ 2473 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2474 int count; 2474 int count;
2475 2475
2476 if (*arg == 0) 2476 if (*arg == 0)
2477 abort (); 2477 abort ();
2478# if HAVE_WCRTOMB 2478# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2479 count = wcrtomb (buf, *arg, &state); 2479 count = wcrtomb (cbuf, *arg, &state);
2480# else 2480# else
2481 count = wctomb (buf, *arg); 2481 count = wctomb (cbuf, *arg);
2482# endif 2482# endif
2483 if (count <= 0) 2483 if (count <= 0)
2484 /* Inconsistency. */ 2484 /* Inconsistency. */
2485 abort (); 2485 abort ();
2486 memcpy (tmpptr, buf, count); 2486 memcpy (tmpptr, cbuf, count);
2487 tmpptr += count; 2487 tmpptr += count;
2488 arg++; 2488 arg++;
2489 remaining -= count; 2489 remaining -= count;
2490 } 2490 }
2491 if (!(arg == arg_end)) 2491 if (!(arg == arg_end))
2492 abort (); 2492 abort ();
2493 } 2493 }
2494 2494
2495 /* Convert from TCHAR_T[] to DCHAR_T[]. */ 2495 /* Convert from TCHAR_T[] to DCHAR_T[]. */
2496 tmpdst = 2496 tmpdst =
2497 DCHAR_CONV_FROM_ENCODING (locale_charset (), 2497 DCHAR_CONV_FROM_ENCODING (locale_charset (),
2498 iconveh_question_mark, 2498 iconveh_question_mark,
2499 tmpsrc, characters, 2499 tmpsrc, characters,
2500 NULL, 2500 NULL,
2501 NULL, &tmpdst_len); 2501 NULL, &tmpdst_len);
2502 if (tmpdst == NULL) 2502 if (tmpdst == NULL)
2503 { 2503 {
2504 int saved_errno = errno; 2504 int saved_errno = errno;
2505 free (tmpsrc); 2505 free (tmpsrc);
2506 if (!(result == resultbuf || result == NULL)) 2506 if (!(result == resultbuf || result == NULL))
2507 free (result); 2507 free (result);
2508 if (buf_malloced != NULL) 2508 if (buf_malloced != NULL)
2509 free (buf_malloced); 2509 free (buf_malloced);
2510 CLEANUP (); 2510 CLEANUP ();
2511 errno = saved_errno; 2511 errno = saved_errno;
2512 return NULL; 2512 return NULL;
2513 } 2513 }
2514 free (tmpsrc); 2514 free (tmpsrc);
2515# endif 2515# endif
2516 2516
2517 if (has_width) 2517 if (has_width)
2518 { 2518 {
2519# if ENABLE_UNISTDIO 2519# if ENABLE_UNISTDIO
2520 /* Outside POSIX, it's preferrable to compare the width 2520 /* Outside POSIX, it's preferrable to compare the width
2521 against the number of _characters_ of the converted 2521 against the number of _characters_ of the converted
2522 value. */ 2522 value. */
2523 w = DCHAR_MBSNLEN (result + length, characters); 2523 w = DCHAR_MBSNLEN (result + length, characters);
2524# else 2524# else
2525 /* The width is compared against the number of _bytes_ 2525 /* The width is compared against the number of _bytes_
2526 of the converted value, says POSIX. */ 2526 of the converted value, says POSIX. */
2527 w = characters; 2527 w = characters;
2528# endif 2528# endif
2529 } 2529 }
2530 else 2530 else
2531 /* w doesn't matter. */ 2531 /* w doesn't matter. */
2532 w = 0; 2532 w = 0;
2533 2533
2534 if (has_width && width > w 2534 if (has_width && width > w
2535 && !(dp->flags & FLAG_LEFT)) 2535 && !(dp->flags & FLAG_LEFT))
2536 { 2536 {
2537 size_t n = width - w; 2537 size_t n = width - w;
2538 ENSURE_ALLOCATION (xsum (length, n)); 2538 ENSURE_ALLOCATION (xsum (length, n));
2539 DCHAR_SET (result + length, ' ', n); 2539 DCHAR_SET (result + length, ' ', n);
2540 length += n; 2540 length += n;
2541 } 2541 }
2542 2542
2543# if DCHAR_IS_TCHAR 2543# if DCHAR_IS_TCHAR
2544 if (has_precision || has_width) 2544 if (has_precision || has_width)
2545 { 2545 {
2546 /* We know the number of bytes in advance. */ 2546 /* We know the number of bytes in advance. */
2547 size_t remaining; 2547 size_t remaining;
2548# if HAVE_WCRTOMB 2548# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2549 mbstate_t state; 2549 mbstate_t state;
2550 memset (&state, '\0', sizeof (mbstate_t)); 2550 memset (&state, '\0', sizeof (mbstate_t));
2551# endif 2551# endif
2552 ENSURE_ALLOCATION (xsum (length, characters)); 2552 ENSURE_ALLOCATION (xsum (length, characters));
2553 for (remaining = characters; remaining > 0; ) 2553 for (remaining = characters; remaining > 0; )
2554 { 2554 {
2555 char buf[64]; /* Assume MB_CUR_MAX <= 64. */ 2555 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2556 int count; 2556 int count;
2557 2557
2558 if (*arg == 0) 2558 if (*arg == 0)
2559 abort (); 2559 abort ();
2560# if HAVE_WCRTOMB 2560# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2561 count = wcrtomb (buf, *arg, &state); 2561 count = wcrtomb (cbuf, *arg, &state);
2562# else 2562# else
2563 count = wctomb (buf, *arg); 2563 count = wctomb (cbuf, *arg);
2564# endif 2564# endif
2565 if (count <= 0) 2565 if (count <= 0)
2566 /* Inconsistency. */ 2566 /* Inconsistency. */
2567 abort (); 2567 abort ();
2568 memcpy (result + length, buf, count); 2568 memcpy (result + length, cbuf, count);
2569 length += count; 2569 length += count;
2570 arg++; 2570 arg++;
2571 remaining -= count; 2571 remaining -= count;
2572 } 2572 }
2573 if (!(arg == arg_end)) 2573 if (!(arg == arg_end))
2574 abort (); 2574 abort ();
2575 } 2575 }
2576 else 2576 else
2577 { 2577 {
2578# if HAVE_WCRTOMB 2578# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2579 mbstate_t state; 2579 mbstate_t state;
2580 memset (&state, '\0', sizeof (mbstate_t)); 2580 memset (&state, '\0', sizeof (mbstate_t));
2581# endif 2581# endif
2582 while (arg < arg_end) 2582 while (arg < arg_end)
2583 { 2583 {
2584 char buf[64]; /* Assume MB_CUR_MAX <= 64. */ 2584 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2585 int count; 2585 int count;
2586 2586
2587 if (*arg == 0) 2587 if (*arg == 0)
2588 abort (); 2588 abort ();
2589# if HAVE_WCRTOMB 2589# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2590 count = wcrtomb (buf, *arg, &state); 2590 count = wcrtomb (cbuf, *arg, &state);
2591# else 2591# else
2592 count = wctomb (buf, *arg); 2592 count = wctomb (cbuf, *arg);
2593# endif 2593# endif
2594 if (count <= 0) 2594 if (count <= 0)
2595 /* Inconsistency. */ 2595 /* Inconsistency. */
2596 abort (); 2596 abort ();
2597 ENSURE_ALLOCATION (xsum (length, count)); 2597 ENSURE_ALLOCATION (xsum (length, count));
2598 memcpy (result + length, buf, count); 2598 memcpy (result + length, cbuf, count);
2599 length += count; 2599 length += count;
2600 arg++; 2600 arg++;
2601 } 2601 }
2602 } 2602 }
2603# else 2603# else
2604 ENSURE_ALLOCATION (xsum (length, tmpdst_len)); 2604 ENSURE_ALLOCATION (xsum (length, tmpdst_len));
2605 DCHAR_CPY (result + length, tmpdst, tmpdst_len); 2605 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
2606 free (tmpdst); 2606 free (tmpdst);
2607 length += tmpdst_len; 2607 length += tmpdst_len;
2608# endif 2608# endif
2609 2609
2610 if (has_width && width > w 2610 if (has_width && width > w
2611 && (dp->flags & FLAG_LEFT)) 2611 && (dp->flags & FLAG_LEFT))
2612 { 2612 {
2613 size_t n = width - w; 2613 size_t n = width - w;
2614 ENSURE_ALLOCATION (xsum (length, n)); 2614 ENSURE_ALLOCATION (xsum (length, n));
2615 DCHAR_SET (result + length, ' ', n); 2615 DCHAR_SET (result + length, ' ', n);
2616 length += n; 2616 length += n;
2617 } 2617 }
2618 } 2618 }
2619 } 2619 }
2620# endif 2620# endif
2621#endif 2621#endif
2622#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL 2622#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
2623 else if ((dp->conversion == 'a' || dp->conversion == 'A') 2623 else if ((dp->conversion == 'a' || dp->conversion == 'A')
2624# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) 2624# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
2625 && (0 2625 && (0
2626# if NEED_PRINTF_DOUBLE 2626# if NEED_PRINTF_DOUBLE
2627 || a.arg[dp->arg_index].type == TYPE_DOUBLE 2627 || a.arg[dp->arg_index].type == TYPE_DOUBLE
2628# endif 2628# endif
2629# if NEED_PRINTF_LONG_DOUBLE 2629# if NEED_PRINTF_LONG_DOUBLE
2630 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE 2630 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
2631# endif 2631# endif
2632 ) 2632 )
2633# endif 2633# endif
2634 ) 2634 )
2635 { 2635 {
2636 arg_type type = a.arg[dp->arg_index].type; 2636 arg_type type = a.arg[dp->arg_index].type;
2637 int flags = dp->flags; 2637 int flags = dp->flags;
2638 int has_width; 2638 int has_width;
2639 size_t width; 2639 size_t width;
2640 int has_precision; 2640 int has_precision;
2641 size_t precision; 2641 size_t precision;
2642 size_t tmp_length; 2642 size_t tmp_length;
2643 DCHAR_T tmpbuf[700]; 2643 DCHAR_T tmpbuf[700];
2644 DCHAR_T *tmp; 2644 DCHAR_T *tmp;
2645 DCHAR_T *pad_ptr; 2645 DCHAR_T *pad_ptr;
2646 DCHAR_T *p; 2646 DCHAR_T *p;
2647 2647
2648 has_width = 0; 2648 has_width = 0;
2649 width = 0; 2649 width = 0;
2650 if (dp->width_start != dp->width_end) 2650 if (dp->width_start != dp->width_end)
2651 { 2651 {
2652 if (dp->width_arg_index != ARG_NONE) 2652 if (dp->width_arg_index != ARG_NONE)
2653 { 2653 {
2654 int arg; 2654 int arg;
2655 2655
2656 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 2656 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2657 abort (); 2657 abort ();
2658 arg = a.arg[dp->width_arg_index].a.a_int; 2658 arg = a.arg[dp->width_arg_index].a.a_int;
2659 if (arg < 0) 2659 if (arg < 0)
2660 { 2660 {
2661 /* "A negative field width is taken as a '-' flag 2661 /* "A negative field width is taken as a '-' flag
2662 followed by a positive field width." */ 2662 followed by a positive field width." */
2663 flags |= FLAG_LEFT; 2663 flags |= FLAG_LEFT;
2664 width = (unsigned int) (-arg); 2664 width = (unsigned int) (-arg);
2665 } 2665 }
2666 else 2666 else
2667 width = arg; 2667 width = arg;
2668 } 2668 }
2669 else 2669 else
2670 { 2670 {
2671 const FCHAR_T *digitp = dp->width_start; 2671 const FCHAR_T *digitp = dp->width_start;
2672 2672
2673 do 2673 do
2674 width = xsum (xtimes (width, 10), *digitp++ - '0'); 2674 width = xsum (xtimes (width, 10), *digitp++ - '0');
2675 while (digitp != dp->width_end); 2675 while (digitp != dp->width_end);
2676 } 2676 }
2677 has_width = 1; 2677 has_width = 1;
2678 } 2678 }
2679 2679
2680 has_precision = 0; 2680 has_precision = 0;
2681 precision = 0; 2681 precision = 0;
2682 if (dp->precision_start != dp->precision_end) 2682 if (dp->precision_start != dp->precision_end)
2683 { 2683 {
2684 if (dp->precision_arg_index != ARG_NONE) 2684 if (dp->precision_arg_index != ARG_NONE)
2685 { 2685 {
2686 int arg; 2686 int arg;
2687 2687
2688 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 2688 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
2689 abort (); 2689 abort ();
2690 arg = a.arg[dp->precision_arg_index].a.a_int; 2690 arg = a.arg[dp->precision_arg_index].a.a_int;
2691 /* "A negative precision is taken as if the precision 2691 /* "A negative precision is taken as if the precision
2692 were omitted." */ 2692 were omitted." */
2693 if (arg >= 0) 2693 if (arg >= 0)
2694 { 2694 {
2695 precision = arg; 2695 precision = arg;
2696 has_precision = 1; 2696 has_precision = 1;
2697 } 2697 }
2698 } 2698 }
2699 else 2699 else
2700 { 2700 {
2701 const FCHAR_T *digitp = dp->precision_start + 1; 2701 const FCHAR_T *digitp = dp->precision_start + 1;
2702 2702
2703 precision = 0; 2703 precision = 0;
2704 while (digitp != dp->precision_end) 2704 while (digitp != dp->precision_end)
2705 precision = xsum (xtimes (precision, 10), *digitp++ - '0'); 2705 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
2706 has_precision = 1; 2706 has_precision = 1;
2707 } 2707 }
2708 } 2708 }
2709 2709
2710 /* Allocate a temporary buffer of sufficient size. */ 2710 /* Allocate a temporary buffer of sufficient size. */
2711 if (type == TYPE_LONGDOUBLE) 2711 if (type == TYPE_LONGDOUBLE)
2712 tmp_length = 2712 tmp_length =
2713 (unsigned int) ((LDBL_DIG + 1) 2713 (unsigned int) ((LDBL_DIG + 1)
2714 * 0.831 /* decimal -> hexadecimal */ 2714 * 0.831 /* decimal -> hexadecimal */
2715 ) 2715 )
2716 + 1; /* turn floor into ceil */ 2716 + 1; /* turn floor into ceil */
2717 else 2717 else
2718 tmp_length = 2718 tmp_length =
2719 (unsigned int) ((DBL_DIG + 1) 2719 (unsigned int) ((DBL_DIG + 1)
2720 * 0.831 /* decimal -> hexadecimal */ 2720 * 0.831 /* decimal -> hexadecimal */
2721 ) 2721 )
2722 + 1; /* turn floor into ceil */ 2722 + 1; /* turn floor into ceil */
2723 if (tmp_length < precision) 2723 if (tmp_length < precision)
2724 tmp_length = precision; 2724 tmp_length = precision;
2725 /* Account for sign, decimal point etc. */ 2725 /* Account for sign, decimal point etc. */
2726 tmp_length = xsum (tmp_length, 12); 2726 tmp_length = xsum (tmp_length, 12);
2727 2727
2728 if (tmp_length < width) 2728 if (tmp_length < width)
2729 tmp_length = width; 2729 tmp_length = width;
2730 2730
2731 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ 2731 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
2732 2732
2733 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) 2733 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
2734 tmp = tmpbuf; 2734 tmp = tmpbuf;
2735 else 2735 else
2736 { 2736 {
2737 size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); 2737 size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
2738 2738
2739 if (size_overflow_p (tmp_memsize)) 2739 if (size_overflow_p (tmp_memsize))
2740 /* Overflow, would lead to out of memory. */ 2740 /* Overflow, would lead to out of memory. */
2741 goto out_of_memory; 2741 goto out_of_memory;
2742 tmp = (DCHAR_T *) malloc (tmp_memsize); 2742 tmp = (DCHAR_T *) malloc (tmp_memsize);
2743 if (tmp == NULL) 2743 if (tmp == NULL)
2744 /* Out of memory. */ 2744 /* Out of memory. */
2745 goto out_of_memory; 2745 goto out_of_memory;
2746 } 2746 }
2747 2747
2748 pad_ptr = NULL; 2748 pad_ptr = NULL;
2749 p = tmp; 2749 p = tmp;
2750 if (type == TYPE_LONGDOUBLE) 2750 if (type == TYPE_LONGDOUBLE)
2751 { 2751 {
2752# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE 2752# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE
2753 long double arg = a.arg[dp->arg_index].a.a_longdouble; 2753 long double arg = a.arg[dp->arg_index].a.a_longdouble;
2754 2754
2755 if (isnanl (arg)) 2755 if (isnanl (arg))
2756 { 2756 {
2757 if (dp->conversion == 'A') 2757 if (dp->conversion == 'A')
2758 { 2758 {
2759 *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; 2759 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
2760 } 2760 }
2761 else 2761 else
2762 { 2762 {
2763 *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; 2763 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
2764 } 2764 }
2765 } 2765 }
2766 else 2766 else
2767 { 2767 {
2768 int sign = 0; 2768 int sign = 0;
2769 DECL_LONG_DOUBLE_ROUNDING 2769 DECL_LONG_DOUBLE_ROUNDING
2770 2770
2771 BEGIN_LONG_DOUBLE_ROUNDING (); 2771 BEGIN_LONG_DOUBLE_ROUNDING ();
2772 2772
2773 if (signbit (arg)) /* arg < 0.0L or negative zero */ 2773 if (signbit (arg)) /* arg < 0.0L or negative zero */
2774 { 2774 {
2775 sign = -1; 2775 sign = -1;
2776 arg = -arg; 2776 arg = -arg;
2777 } 2777 }
2778 2778
2779 if (sign < 0) 2779 if (sign < 0)
2780 *p++ = '-'; 2780 *p++ = '-';
2781 else if (flags & FLAG_SHOWSIGN) 2781 else if (flags & FLAG_SHOWSIGN)
2782 *p++ = '+'; 2782 *p++ = '+';
2783 else if (flags & FLAG_SPACE) 2783 else if (flags & FLAG_SPACE)
2784 *p++ = ' '; 2784 *p++ = ' ';
2785 2785
2786 if (arg > 0.0L && arg + arg == arg) 2786 if (arg > 0.0L && arg + arg == arg)
2787 { 2787 {
2788 if (dp->conversion == 'A') 2788 if (dp->conversion == 'A')
2789 { 2789 {
2790 *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; 2790 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
2791 } 2791 }
2792 else 2792 else
2793 { 2793 {
2794 *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; 2794 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
2795 } 2795 }
2796 } 2796 }
2797 else 2797 else
2798 { 2798 {
2799 int exponent; 2799 int exponent;
2800 long double mantissa; 2800 long double mantissa;
2801 2801
2802 if (arg > 0.0L) 2802 if (arg > 0.0L)
2803 mantissa = printf_frexpl (arg, &exponent); 2803 mantissa = printf_frexpl (arg, &exponent);
2804 else 2804 else
2805 { 2805 {
2806 exponent = 0; 2806 exponent = 0;
2807 mantissa = 0.0L; 2807 mantissa = 0.0L;
2808 } 2808 }
2809 2809
2810 if (has_precision 2810 if (has_precision
2811 && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) 2811 && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1)
2812 { 2812 {
2813 /* Round the mantissa. */ 2813 /* Round the mantissa. */
2814 long double tail = mantissa; 2814 long double tail = mantissa;
2815 size_t q; 2815 size_t q;
2816 2816
2817 for (q = precision; ; q--) 2817 for (q = precision; ; q--)
2818 { 2818 {
2819 int digit = (int) tail; 2819 int digit = (int) tail;
2820 tail -= digit; 2820 tail -= digit;
2821 if (q == 0) 2821 if (q == 0)
2822 { 2822 {
2823 if (digit & 1 ? tail >= 0.5L : tail > 0.5L) 2823 if (digit & 1 ? tail >= 0.5L : tail > 0.5L)
2824 tail = 1 - tail; 2824 tail = 1 - tail;
2825 else 2825 else
2826 tail = - tail; 2826 tail = - tail;
2827 break; 2827 break;
2828 } 2828 }
2829 tail *= 16.0L; 2829 tail *= 16.0L;
2830 } 2830 }
2831 if (tail != 0.0L) 2831 if (tail != 0.0L)
2832 for (q = precision; q > 0; q--) 2832 for (q = precision; q > 0; q--)
2833 tail *= 0.0625L; 2833 tail *= 0.0625L;
2834 mantissa += tail; 2834 mantissa += tail;
2835 } 2835 }
2836 2836
2837 *p++ = '0'; 2837 *p++ = '0';
2838 *p++ = dp->conversion - 'A' + 'X'; 2838 *p++ = dp->conversion - 'A' + 'X';
2839 pad_ptr = p; 2839 pad_ptr = p;
2840 { 2840 {
2841 int digit; 2841 int digit;
2842 2842
2843 digit = (int) mantissa; 2843 digit = (int) mantissa;
2844 mantissa -= digit; 2844 mantissa -= digit;
2845 *p++ = '0' + digit; 2845 *p++ = '0' + digit;
2846 if ((flags & FLAG_ALT) 2846 if ((flags & FLAG_ALT)
2847 || mantissa > 0.0L || precision > 0) 2847 || mantissa > 0.0L || precision > 0)
2848 { 2848 {
2849 *p++ = decimal_point_char (); 2849 *p++ = decimal_point_char ();
2850 /* This loop terminates because we assume 2850 /* This loop terminates because we assume
2851 that FLT_RADIX is a power of 2. */ 2851 that FLT_RADIX is a power of 2. */
2852 while (mantissa > 0.0L) 2852 while (mantissa > 0.0L)
2853 { 2853 {
2854 mantissa *= 16.0L; 2854 mantissa *= 16.0L;
2855 digit = (int) mantissa; 2855 digit = (int) mantissa;
2856 mantissa -= digit; 2856 mantissa -= digit;
2857 *p++ = digit 2857 *p++ = digit
2858 + (digit < 10 2858 + (digit < 10
2859 ? '0' 2859 ? '0'
2860 : dp->conversion - 10); 2860 : dp->conversion - 10);
2861 if (precision > 0) 2861 if (precision > 0)
2862 precision--; 2862 precision--;
2863 } 2863 }
2864 while (precision > 0) 2864 while (precision > 0)
2865 { 2865 {
2866 *p++ = '0'; 2866 *p++ = '0';
2867 precision--; 2867 precision--;
2868 } 2868 }
2869 } 2869 }
2870 } 2870 }
2871 *p++ = dp->conversion - 'A' + 'P'; 2871 *p++ = dp->conversion - 'A' + 'P';
2872# if WIDE_CHAR_VERSION 2872# if WIDE_CHAR_VERSION
2873 { 2873 {
2874 static const wchar_t decimal_format[] = 2874 static const wchar_t decimal_format[] =
2875 { '%', '+', 'd', '\0' }; 2875 { '%', '+', 'd', '\0' };
2876 SNPRINTF (p, 6 + 1, decimal_format, exponent); 2876 SNPRINTF (p, 6 + 1, decimal_format, exponent);
2877 } 2877 }
2878 while (*p != '\0') 2878 while (*p != '\0')
2879 p++; 2879 p++;
2880# else 2880# else
2881 if (sizeof (DCHAR_T) == 1) 2881 if (sizeof (DCHAR_T) == 1)
2882 { 2882 {
2883 sprintf ((char *) p, "%+d", exponent); 2883 sprintf ((char *) p, "%+d", exponent);
2884 while (*p != '\0') 2884 while (*p != '\0')
2885 p++; 2885 p++;
2886 } 2886 }
2887 else 2887 else
2888 { 2888 {
2889 char expbuf[6 + 1]; 2889 char expbuf[6 + 1];
2890 const char *ep; 2890 const char *ep;
2891 sprintf (expbuf, "%+d", exponent); 2891 sprintf (expbuf, "%+d", exponent);
2892 for (ep = expbuf; (*p = *ep) != '\0'; ep++) 2892 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
2893 p++; 2893 p++;
2894 } 2894 }
2895# endif 2895# endif
2896 } 2896 }
2897 2897
2898 END_LONG_DOUBLE_ROUNDING (); 2898 END_LONG_DOUBLE_ROUNDING ();
2899 } 2899 }
2900# else 2900# else
2901 abort (); 2901 abort ();
2902# endif 2902# endif
2903 } 2903 }
2904 else 2904 else
2905 { 2905 {
2906# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE 2906# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE
2907 double arg = a.arg[dp->arg_index].a.a_double; 2907 double arg = a.arg[dp->arg_index].a.a_double;
2908 2908
2909 if (isnand (arg)) 2909 if (isnand (arg))
2910 { 2910 {
2911 if (dp->conversion == 'A') 2911 if (dp->conversion == 'A')
2912 { 2912 {
2913 *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; 2913 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
2914 } 2914 }
2915 else 2915 else
2916 { 2916 {
2917 *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; 2917 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
2918 } 2918 }
2919 } 2919 }
2920 else 2920 else
2921 { 2921 {
2922 int sign = 0; 2922 int sign = 0;
2923 2923
2924 if (signbit (arg)) /* arg < 0.0 or negative zero */ 2924 if (signbit (arg)) /* arg < 0.0 or negative zero */
2925 { 2925 {
2926 sign = -1; 2926 sign = -1;
2927 arg = -arg; 2927 arg = -arg;
2928 } 2928 }
2929 2929
2930 if (sign < 0) 2930 if (sign < 0)
2931 *p++ = '-'; 2931 *p++ = '-';
2932 else if (flags & FLAG_SHOWSIGN) 2932 else if (flags & FLAG_SHOWSIGN)
2933 *p++ = '+'; 2933 *p++ = '+';
2934 else if (flags & FLAG_SPACE) 2934 else if (flags & FLAG_SPACE)
2935 *p++ = ' '; 2935 *p++ = ' ';
2936 2936
2937 if (arg > 0.0 && arg + arg == arg) 2937 if (arg > 0.0 && arg + arg == arg)
2938 { 2938 {
2939 if (dp->conversion == 'A') 2939 if (dp->conversion == 'A')
2940 { 2940 {
2941 *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; 2941 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
2942 } 2942 }
2943 else 2943 else
2944 { 2944 {
2945 *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; 2945 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
2946 } 2946 }
2947 } 2947 }
2948 else 2948 else
2949 { 2949 {
2950 int exponent; 2950 int exponent;
2951 double mantissa; 2951 double mantissa;
2952 2952
2953 if (arg > 0.0) 2953 if (arg > 0.0)
2954 mantissa = printf_frexp (arg, &exponent); 2954 mantissa = printf_frexp (arg, &exponent);
2955 else 2955 else
2956 { 2956 {
2957 exponent = 0; 2957 exponent = 0;
2958 mantissa = 0.0; 2958 mantissa = 0.0;
2959 } 2959 }
2960 2960
2961 if (has_precision 2961 if (has_precision
2962 && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) 2962 && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1)
2963 { 2963 {
2964 /* Round the mantissa. */ 2964 /* Round the mantissa. */
2965 double tail = mantissa; 2965 double tail = mantissa;
2966 size_t q; 2966 size_t q;
2967 2967
2968 for (q = precision; ; q--) 2968 for (q = precision; ; q--)
2969 { 2969 {
2970 int digit = (int) tail; 2970 int digit = (int) tail;
2971 tail -= digit; 2971 tail -= digit;
2972 if (q == 0) 2972 if (q == 0)
2973 { 2973 {
2974 if (digit & 1 ? tail >= 0.5 : tail > 0.5) 2974 if (digit & 1 ? tail >= 0.5 : tail > 0.5)
2975 tail = 1 - tail; 2975 tail = 1 - tail;
2976 else 2976 else
2977 tail = - tail; 2977 tail = - tail;
2978 break; 2978 break;
2979 } 2979 }
2980 tail *= 16.0; 2980 tail *= 16.0;
2981 } 2981 }
2982 if (tail != 0.0) 2982 if (tail != 0.0)
2983 for (q = precision; q > 0; q--) 2983 for (q = precision; q > 0; q--)
2984 tail *= 0.0625; 2984 tail *= 0.0625;
2985 mantissa += tail; 2985 mantissa += tail;
2986 } 2986 }
2987 2987
2988 *p++ = '0'; 2988 *p++ = '0';
2989 *p++ = dp->conversion - 'A' + 'X'; 2989 *p++ = dp->conversion - 'A' + 'X';
2990 pad_ptr = p; 2990 pad_ptr = p;
2991 { 2991 {
2992 int digit; 2992 int digit;
2993 2993
2994 digit = (int) mantissa; 2994 digit = (int) mantissa;
2995 mantissa -= digit; 2995 mantissa -= digit;
2996 *p++ = '0' + digit; 2996 *p++ = '0' + digit;
2997 if ((flags & FLAG_ALT) 2997 if ((flags & FLAG_ALT)
2998 || mantissa > 0.0 || precision > 0) 2998 || mantissa > 0.0 || precision > 0)
2999 { 2999 {
3000 *p++ = decimal_point_char (); 3000 *p++ = decimal_point_char ();
3001 /* This loop terminates because we assume 3001 /* This loop terminates because we assume
3002 that FLT_RADIX is a power of 2. */ 3002 that FLT_RADIX is a power of 2. */
3003 while (mantissa > 0.0) 3003 while (mantissa > 0.0)
3004 { 3004 {
3005 mantissa *= 16.0; 3005 mantissa *= 16.0;
3006 digit = (int) mantissa; 3006 digit = (int) mantissa;
3007 mantissa -= digit; 3007 mantissa -= digit;
3008 *p++ = digit 3008 *p++ = digit
3009 + (digit < 10 3009 + (digit < 10
3010 ? '0' 3010 ? '0'
3011 : dp->conversion - 10); 3011 : dp->conversion - 10);
3012 if (precision > 0) 3012 if (precision > 0)
3013 precision--; 3013 precision--;
3014 } 3014 }
3015 while (precision > 0) 3015 while (precision > 0)
3016 { 3016 {
3017 *p++ = '0'; 3017 *p++ = '0';
3018 precision--; 3018 precision--;
3019 } 3019 }
3020 } 3020 }
3021 } 3021 }
3022 *p++ = dp->conversion - 'A' + 'P'; 3022 *p++ = dp->conversion - 'A' + 'P';
3023# if WIDE_CHAR_VERSION 3023# if WIDE_CHAR_VERSION
3024 { 3024 {
3025 static const wchar_t decimal_format[] = 3025 static const wchar_t decimal_format[] =
3026 { '%', '+', 'd', '\0' }; 3026 { '%', '+', 'd', '\0' };
3027 SNPRINTF (p, 6 + 1, decimal_format, exponent); 3027 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3028 } 3028 }
3029 while (*p != '\0') 3029 while (*p != '\0')
3030 p++; 3030 p++;
3031# else 3031# else
3032 if (sizeof (DCHAR_T) == 1) 3032 if (sizeof (DCHAR_T) == 1)
3033 { 3033 {
3034 sprintf ((char *) p, "%+d", exponent); 3034 sprintf ((char *) p, "%+d", exponent);
3035 while (*p != '\0') 3035 while (*p != '\0')
3036 p++; 3036 p++;
3037 } 3037 }
3038 else 3038 else
3039 { 3039 {
3040 char expbuf[6 + 1]; 3040 char expbuf[6 + 1];
3041 const char *ep; 3041 const char *ep;
3042 sprintf (expbuf, "%+d", exponent); 3042 sprintf (expbuf, "%+d", exponent);
3043 for (ep = expbuf; (*p = *ep) != '\0'; ep++) 3043 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3044 p++; 3044 p++;
3045 } 3045 }
3046# endif 3046# endif
3047 } 3047 }
3048 } 3048 }
3049# else 3049# else
3050 abort (); 3050 abort ();
3051# endif 3051# endif
3052 } 3052 }
3053 /* The generated string now extends from tmp to p, with the 3053 /* The generated string now extends from tmp to p, with the
3054 zero padding insertion point being at pad_ptr. */ 3054 zero padding insertion point being at pad_ptr. */
3055 if (has_width && p - tmp < width) 3055 if (has_width && p - tmp < width)
3056 { 3056 {
3057 size_t pad = width - (p - tmp); 3057 size_t pad = width - (p - tmp);
3058 DCHAR_T *end = p + pad; 3058 DCHAR_T *end = p + pad;
3059 3059
3060 if (flags & FLAG_LEFT) 3060 if (flags & FLAG_LEFT)
3061 { 3061 {
3062 /* Pad with spaces on the right. */ 3062 /* Pad with spaces on the right. */
3063 for (; pad > 0; pad--) 3063 for (; pad > 0; pad--)
3064 *p++ = ' '; 3064 *p++ = ' ';
3065 } 3065 }
3066 else if ((flags & FLAG_ZERO) && pad_ptr != NULL) 3066 else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
3067 { 3067 {
3068 /* Pad with zeroes. */ 3068 /* Pad with zeroes. */
3069 DCHAR_T *q = end; 3069 DCHAR_T *q = end;
3070 3070
3071 while (p > pad_ptr) 3071 while (p > pad_ptr)
3072 *--q = *--p; 3072 *--q = *--p;
3073 for (; pad > 0; pad--) 3073 for (; pad > 0; pad--)
3074 *p++ = '0'; 3074 *p++ = '0';
3075 } 3075 }
3076 else 3076 else
3077 { 3077 {
3078 /* Pad with spaces on the left. */ 3078 /* Pad with spaces on the left. */
3079 DCHAR_T *q = end; 3079 DCHAR_T *q = end;
3080 3080
3081 while (p > tmp) 3081 while (p > tmp)
3082 *--q = *--p; 3082 *--q = *--p;
3083 for (; pad > 0; pad--) 3083 for (; pad > 0; pad--)
3084 *p++ = ' '; 3084 *p++ = ' ';
3085 } 3085 }
3086 3086
3087 p = end; 3087 p = end;
3088 } 3088 }
3089 3089
3090 { 3090 {
3091 size_t count = p - tmp; 3091 size_t count = p - tmp;
3092 3092
3093 if (count >= tmp_length) 3093 if (count >= tmp_length)
3094 /* tmp_length was incorrectly calculated - fix the 3094 /* tmp_length was incorrectly calculated - fix the
3095 code above! */ 3095 code above! */
3096 abort (); 3096 abort ();
3097 3097
3098 /* Make room for the result. */ 3098 /* Make room for the result. */
3099 if (count >= allocated - length) 3099 if (count >= allocated - length)
3100 { 3100 {
3101 size_t n = xsum (length, count); 3101 size_t n = xsum (length, count);
3102 3102
3103 ENSURE_ALLOCATION (n); 3103 ENSURE_ALLOCATION (n);
3104 } 3104 }
3105 3105
3106 /* Append the result. */ 3106 /* Append the result. */
3107 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 3107 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
3108 if (tmp != tmpbuf) 3108 if (tmp != tmpbuf)
3109 free (tmp); 3109 free (tmp);
3110 length += count; 3110 length += count;
3111 } 3111 }
3112 } 3112 }
3113#endif 3113#endif
3114#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL 3114#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
3115 else if ((dp->conversion == 'f' || dp->conversion == 'F' 3115 else if ((dp->conversion == 'f' || dp->conversion == 'F'
3116 || dp->conversion == 'e' || dp->conversion == 'E' 3116 || dp->conversion == 'e' || dp->conversion == 'E'
3117 || dp->conversion == 'g' || dp->conversion == 'G' 3117 || dp->conversion == 'g' || dp->conversion == 'G'
3118 || dp->conversion == 'a' || dp->conversion == 'A') 3118 || dp->conversion == 'a' || dp->conversion == 'A')
3119 && (0 3119 && (0
3120# if NEED_PRINTF_DOUBLE 3120# if NEED_PRINTF_DOUBLE
3121 || a.arg[dp->arg_index].type == TYPE_DOUBLE 3121 || a.arg[dp->arg_index].type == TYPE_DOUBLE
3122# elif NEED_PRINTF_INFINITE_DOUBLE 3122# elif NEED_PRINTF_INFINITE_DOUBLE
3123 || (a.arg[dp->arg_index].type == TYPE_DOUBLE 3123 || (a.arg[dp->arg_index].type == TYPE_DOUBLE
3124 /* The systems (mingw) which produce wrong output 3124 /* The systems (mingw) which produce wrong output
3125 for Inf, -Inf, and NaN also do so for -0.0. 3125 for Inf, -Inf, and NaN also do so for -0.0.
3126 Therefore we treat this case here as well. */ 3126 Therefore we treat this case here as well. */
3127 && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) 3127 && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double))
3128# endif 3128# endif
3129# if NEED_PRINTF_LONG_DOUBLE 3129# if NEED_PRINTF_LONG_DOUBLE
3130 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE 3130 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
3131# elif NEED_PRINTF_INFINITE_LONG_DOUBLE 3131# elif NEED_PRINTF_INFINITE_LONG_DOUBLE
3132 || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE 3132 || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
3133 /* Some systems produce wrong output for Inf, 3133 /* Some systems produce wrong output for Inf,
3134 -Inf, and NaN. Some systems in this category 3134 -Inf, and NaN. Some systems in this category
3135 (IRIX 5.3) also do so for -0.0. Therefore we 3135 (IRIX 5.3) also do so for -0.0. Therefore we
3136 treat this case here as well. */ 3136 treat this case here as well. */
3137 && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) 3137 && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble))
3138# endif 3138# endif
3139 )) 3139 ))
3140 { 3140 {
3141# if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) 3141# if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE)
3142 arg_type type = a.arg[dp->arg_index].type; 3142 arg_type type = a.arg[dp->arg_index].type;
3143# endif 3143# endif
3144 int flags = dp->flags; 3144 int flags = dp->flags;
3145 int has_width; 3145 int has_width;
3146 size_t width; 3146 size_t width;
3147 int has_precision; 3147 int has_precision;
3148 size_t precision; 3148 size_t precision;
3149 size_t tmp_length; 3149 size_t tmp_length;
3150 DCHAR_T tmpbuf[700]; 3150 DCHAR_T tmpbuf[700];
3151 DCHAR_T *tmp; 3151 DCHAR_T *tmp;
3152 DCHAR_T *pad_ptr; 3152 DCHAR_T *pad_ptr;
3153 DCHAR_T *p; 3153 DCHAR_T *p;
3154 3154
3155 has_width = 0; 3155 has_width = 0;
3156 width = 0; 3156 width = 0;
3157 if (dp->width_start != dp->width_end) 3157 if (dp->width_start != dp->width_end)
3158 { 3158 {
3159 if (dp->width_arg_index != ARG_NONE) 3159 if (dp->width_arg_index != ARG_NONE)
3160 { 3160 {
3161 int arg; 3161 int arg;
3162 3162
3163 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 3163 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
3164 abort (); 3164 abort ();
3165 arg = a.arg[dp->width_arg_index].a.a_int; 3165 arg = a.arg[dp->width_arg_index].a.a_int;
3166 if (arg < 0) 3166 if (arg < 0)
3167 { 3167 {
3168 /* "A negative field width is taken as a '-' flag 3168 /* "A negative field width is taken as a '-' flag
3169 followed by a positive field width." */ 3169 followed by a positive field width." */
3170 flags |= FLAG_LEFT; 3170 flags |= FLAG_LEFT;
3171 width = (unsigned int) (-arg); 3171 width = (unsigned int) (-arg);
3172 } 3172 }
3173 else 3173 else
3174 width = arg; 3174 width = arg;
3175 } 3175 }
3176 else 3176 else
3177 { 3177 {
3178 const FCHAR_T *digitp = dp->width_start; 3178 const FCHAR_T *digitp = dp->width_start;
3179 3179
3180 do 3180 do
3181 width = xsum (xtimes (width, 10), *digitp++ - '0'); 3181 width = xsum (xtimes (width, 10), *digitp++ - '0');
3182 while (digitp != dp->width_end); 3182 while (digitp != dp->width_end);
3183 } 3183 }
3184 has_width = 1; 3184 has_width = 1;
3185 } 3185 }
3186 3186
3187 has_precision = 0; 3187 has_precision = 0;
3188 precision = 0; 3188 precision = 0;
3189 if (dp->precision_start != dp->precision_end) 3189 if (dp->precision_start != dp->precision_end)
3190 { 3190 {
3191 if (dp->precision_arg_index != ARG_NONE) 3191 if (dp->precision_arg_index != ARG_NONE)
3192 { 3192 {
3193 int arg; 3193 int arg;
3194 3194
3195 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 3195 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
3196 abort (); 3196 abort ();
3197 arg = a.arg[dp->precision_arg_index].a.a_int; 3197 arg = a.arg[dp->precision_arg_index].a.a_int;
3198 /* "A negative precision is taken as if the precision 3198 /* "A negative precision is taken as if the precision
3199 were omitted." */ 3199 were omitted." */
3200 if (arg >= 0) 3200 if (arg >= 0)
3201 { 3201 {
3202 precision = arg; 3202 precision = arg;
3203 has_precision = 1; 3203 has_precision = 1;
3204 } 3204 }
3205 } 3205 }
3206 else 3206 else
3207 { 3207 {
3208 const FCHAR_T *digitp = dp->precision_start + 1; 3208 const FCHAR_T *digitp = dp->precision_start + 1;
3209 3209
3210 precision = 0; 3210 precision = 0;
3211 while (digitp != dp->precision_end) 3211 while (digitp != dp->precision_end)
3212 precision = xsum (xtimes (precision, 10), *digitp++ - '0'); 3212 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
3213 has_precision = 1; 3213 has_precision = 1;
3214 } 3214 }
3215 } 3215 }
3216 3216
3217 /* POSIX specifies the default precision to be 6 for %f, %F, 3217 /* POSIX specifies the default precision to be 6 for %f, %F,
3218 %e, %E, but not for %g, %G. Implementations appear to use 3218 %e, %E, but not for %g, %G. Implementations appear to use
3219 the same default precision also for %g, %G. But for %a, %A, 3219 the same default precision also for %g, %G. But for %a, %A,
3220 the default precision is 0. */ 3220 the default precision is 0. */
3221 if (!has_precision) 3221 if (!has_precision)
3222 if (!(dp->conversion == 'a' || dp->conversion == 'A')) 3222 if (!(dp->conversion == 'a' || dp->conversion == 'A'))
3223 precision = 6; 3223 precision = 6;
3224 3224
3225 /* Allocate a temporary buffer of sufficient size. */ 3225 /* Allocate a temporary buffer of sufficient size. */
3226# if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE 3226# if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE
3227 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); 3227 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1);
3228# elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE 3228# elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE
3229 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); 3229 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0);
3230# elif NEED_PRINTF_LONG_DOUBLE 3230# elif NEED_PRINTF_LONG_DOUBLE
3231 tmp_length = LDBL_DIG + 1; 3231 tmp_length = LDBL_DIG + 1;
3232# elif NEED_PRINTF_DOUBLE 3232# elif NEED_PRINTF_DOUBLE
3233 tmp_length = DBL_DIG + 1; 3233 tmp_length = DBL_DIG + 1;
3234# else 3234# else
3235 tmp_length = 0; 3235 tmp_length = 0;
3236# endif 3236# endif
3237 if (tmp_length < precision) 3237 if (tmp_length < precision)
3238 tmp_length = precision; 3238 tmp_length = precision;
3239# if NEED_PRINTF_LONG_DOUBLE 3239# if NEED_PRINTF_LONG_DOUBLE
3240# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE 3240# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
3241 if (type == TYPE_LONGDOUBLE) 3241 if (type == TYPE_LONGDOUBLE)
3242# endif 3242# endif
3243 if (dp->conversion == 'f' || dp->conversion == 'F') 3243 if (dp->conversion == 'f' || dp->conversion == 'F')
3244 { 3244 {
3245 long double arg = a.arg[dp->arg_index].a.a_longdouble; 3245 long double arg = a.arg[dp->arg_index].a.a_longdouble;
3246 if (!(isnanl (arg) || arg + arg == arg)) 3246 if (!(isnanl (arg) || arg + arg == arg))
3247 { 3247 {
3248 /* arg is finite and nonzero. */ 3248 /* arg is finite and nonzero. */
3249 int exponent = floorlog10l (arg < 0 ? -arg : arg); 3249 int exponent = floorlog10l (arg < 0 ? -arg : arg);
3250 if (exponent >= 0 && tmp_length < exponent + precision) 3250 if (exponent >= 0 && tmp_length < exponent + precision)
3251 tmp_length = exponent + precision; 3251 tmp_length = exponent + precision;
3252 } 3252 }
3253 } 3253 }
3254# endif 3254# endif
3255# if NEED_PRINTF_DOUBLE 3255# if NEED_PRINTF_DOUBLE
3256# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE 3256# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
3257 if (type == TYPE_DOUBLE) 3257 if (type == TYPE_DOUBLE)
3258# endif 3258# endif
3259 if (dp->conversion == 'f' || dp->conversion == 'F') 3259 if (dp->conversion == 'f' || dp->conversion == 'F')
3260 { 3260 {
3261 double arg = a.arg[dp->arg_index].a.a_double; 3261 double arg = a.arg[dp->arg_index].a.a_double;
3262 if (!(isnand (arg) || arg + arg == arg)) 3262 if (!(isnand (arg) || arg + arg == arg))
3263 { 3263 {
3264 /* arg is finite and nonzero. */ 3264 /* arg is finite and nonzero. */
3265 int exponent = floorlog10 (arg < 0 ? -arg : arg); 3265 int exponent = floorlog10 (arg < 0 ? -arg : arg);
3266 if (exponent >= 0 && tmp_length < exponent + precision) 3266 if (exponent >= 0 && tmp_length < exponent + precision)
3267 tmp_length = exponent + precision; 3267 tmp_length = exponent + precision;
3268 } 3268 }
3269 } 3269 }
3270# endif 3270# endif
3271 /* Account for sign, decimal point etc. */ 3271 /* Account for sign, decimal point etc. */
3272 tmp_length = xsum (tmp_length, 12); 3272 tmp_length = xsum (tmp_length, 12);
3273 3273
3274 if (tmp_length < width) 3274 if (tmp_length < width)
3275 tmp_length = width; 3275 tmp_length = width;
3276 3276
3277 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ 3277 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
3278 3278
3279 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) 3279 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
3280 tmp = tmpbuf; 3280 tmp = tmpbuf;
3281 else 3281 else
3282 { 3282 {
3283 size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); 3283 size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
3284 3284
3285 if (size_overflow_p (tmp_memsize)) 3285 if (size_overflow_p (tmp_memsize))
3286 /* Overflow, would lead to out of memory. */ 3286 /* Overflow, would lead to out of memory. */
3287 goto out_of_memory; 3287 goto out_of_memory;
3288 tmp = (DCHAR_T *) malloc (tmp_memsize); 3288 tmp = (DCHAR_T *) malloc (tmp_memsize);
3289 if (tmp == NULL) 3289 if (tmp == NULL)
3290 /* Out of memory. */ 3290 /* Out of memory. */
3291 goto out_of_memory; 3291 goto out_of_memory;
3292 } 3292 }
3293 3293
3294 pad_ptr = NULL; 3294 pad_ptr = NULL;
3295 p = tmp; 3295 p = tmp;
3296 3296
3297# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE 3297# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
3298# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE 3298# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
3299 if (type == TYPE_LONGDOUBLE) 3299 if (type == TYPE_LONGDOUBLE)
3300# endif 3300# endif
3301 { 3301 {
3302 long double arg = a.arg[dp->arg_index].a.a_longdouble; 3302 long double arg = a.arg[dp->arg_index].a.a_longdouble;
3303 3303
3304 if (isnanl (arg)) 3304 if (isnanl (arg))
3305 { 3305 {
3306 if (dp->conversion >= 'A' && dp->conversion <= 'Z') 3306 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
3307 { 3307 {
3308 *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; 3308 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
3309 } 3309 }
3310 else 3310 else
3311 { 3311 {
3312 *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; 3312 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
3313 } 3313 }
3314 } 3314 }
3315 else 3315 else
3316 { 3316 {
3317 int sign = 0; 3317 int sign = 0;
3318 DECL_LONG_DOUBLE_ROUNDING 3318 DECL_LONG_DOUBLE_ROUNDING
3319 3319
3320 BEGIN_LONG_DOUBLE_ROUNDING (); 3320 BEGIN_LONG_DOUBLE_ROUNDING ();
3321 3321
3322 if (signbit (arg)) /* arg < 0.0L or negative zero */ 3322 if (signbit (arg)) /* arg < 0.0L or negative zero */
3323 { 3323 {
3324 sign = -1; 3324 sign = -1;
3325 arg = -arg; 3325 arg = -arg;
3326 } 3326 }
3327 3327
3328 if (sign < 0) 3328 if (sign < 0)
3329 *p++ = '-'; 3329 *p++ = '-';
3330 else if (flags & FLAG_SHOWSIGN) 3330 else if (flags & FLAG_SHOWSIGN)
3331 *p++ = '+'; 3331 *p++ = '+';
3332 else if (flags & FLAG_SPACE) 3332 else if (flags & FLAG_SPACE)
3333 *p++ = ' '; 3333 *p++ = ' ';
3334 3334
3335 if (arg > 0.0L && arg + arg == arg) 3335 if (arg > 0.0L && arg + arg == arg)
3336 { 3336 {
3337 if (dp->conversion >= 'A' && dp->conversion <= 'Z') 3337 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
3338 { 3338 {
3339 *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; 3339 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
3340 } 3340 }
3341 else 3341 else
3342 { 3342 {
3343 *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; 3343 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
3344 } 3344 }
3345 } 3345 }
3346 else 3346 else
3347 { 3347 {
3348# if NEED_PRINTF_LONG_DOUBLE 3348# if NEED_PRINTF_LONG_DOUBLE
3349 pad_ptr = p; 3349 pad_ptr = p;
3350 3350
3351 if (dp->conversion == 'f' || dp->conversion == 'F') 3351 if (dp->conversion == 'f' || dp->conversion == 'F')
3352 { 3352 {
3353 char *digits; 3353 char *digits;
3354 size_t ndigits; 3354 size_t ndigits;
3355 3355
3356 digits = 3356 digits =
3357 scale10_round_decimal_long_double (arg, precision); 3357 scale10_round_decimal_long_double (arg, precision);
3358 if (digits == NULL) 3358 if (digits == NULL)
3359 { 3359 {
3360 END_LONG_DOUBLE_ROUNDING (); 3360 END_LONG_DOUBLE_ROUNDING ();
3361 goto out_of_memory; 3361 goto out_of_memory;
3362 } 3362 }
3363 ndigits = strlen (digits); 3363 ndigits = strlen (digits);
3364 3364
3365 if (ndigits > precision) 3365 if (ndigits > precision)
3366 do 3366 do
3367 { 3367 {
3368 --ndigits; 3368 --ndigits;
3369 *p++ = digits[ndigits]; 3369 *p++ = digits[ndigits];
3370 } 3370 }
3371 while (ndigits > precision); 3371 while (ndigits > precision);
3372 else 3372 else
3373 *p++ = '0'; 3373 *p++ = '0';
3374 /* Here ndigits <= precision. */ 3374 /* Here ndigits <= precision. */
3375 if ((flags & FLAG_ALT) || precision > 0) 3375 if ((flags & FLAG_ALT) || precision > 0)
3376 { 3376 {
3377 *p++ = decimal_point_char (); 3377 *p++ = decimal_point_char ();
3378 for (; precision > ndigits; precision--) 3378 for (; precision > ndigits; precision--)
3379 *p++ = '0'; 3379 *p++ = '0';
3380 while (ndigits > 0) 3380 while (ndigits > 0)
3381 { 3381 {
3382 --ndigits; 3382 --ndigits;
3383 *p++ = digits[ndigits]; 3383 *p++ = digits[ndigits];
3384 } 3384 }
3385 } 3385 }
3386 3386
3387 free (digits); 3387 free (digits);
3388 } 3388 }
3389 else if (dp->conversion == 'e' || dp->conversion == 'E') 3389 else if (dp->conversion == 'e' || dp->conversion == 'E')
3390 { 3390 {
3391 int exponent; 3391 int exponent;
3392 3392
3393 if (arg == 0.0L) 3393 if (arg == 0.0L)
3394 { 3394 {
3395 exponent = 0; 3395 exponent = 0;
3396 *p++ = '0'; 3396 *p++ = '0';
3397 if ((flags & FLAG_ALT) || precision > 0) 3397 if ((flags & FLAG_ALT) || precision > 0)
3398 { 3398 {
3399 *p++ = decimal_point_char (); 3399 *p++ = decimal_point_char ();
3400 for (; precision > 0; precision--) 3400 for (; precision > 0; precision--)
3401 *p++ = '0'; 3401 *p++ = '0';
3402 } 3402 }
3403 } 3403 }
3404 else 3404 else
3405 { 3405 {
3406 /* arg > 0.0L. */ 3406 /* arg > 0.0L. */
3407 int adjusted; 3407 int adjusted;
3408 char *digits; 3408 char *digits;
3409 size_t ndigits; 3409 size_t ndigits;
3410 3410
3411 exponent = floorlog10l (arg); 3411 exponent = floorlog10l (arg);
3412 adjusted = 0; 3412 adjusted = 0;
3413 for (;;) 3413 for (;;)
3414 { 3414 {
3415 digits = 3415 digits =
3416 scale10_round_decimal_long_double (arg, 3416 scale10_round_decimal_long_double (arg,
3417 (int)precision - exponent); 3417 (int)precision - exponent);
3418 if (digits == NULL) 3418 if (digits == NULL)
3419 { 3419 {
3420 END_LONG_DOUBLE_ROUNDING (); 3420 END_LONG_DOUBLE_ROUNDING ();
3421 goto out_of_memory; 3421 goto out_of_memory;
3422 } 3422 }
3423 ndigits = strlen (digits); 3423 ndigits = strlen (digits);
3424 3424
3425 if (ndigits == precision + 1) 3425 if (ndigits == precision + 1)
3426 break; 3426 break;
3427 if (ndigits < precision 3427 if (ndigits < precision
3428 || ndigits > precision + 2) 3428 || ndigits > precision + 2)
3429 /* The exponent was not guessed 3429 /* The exponent was not guessed
3430 precisely enough. */ 3430 precisely enough. */
3431 abort (); 3431 abort ();
3432 if (adjusted) 3432 if (adjusted)
3433 /* None of two values of exponent is 3433 /* None of two values of exponent is
3434 the right one. Prevent an endless 3434 the right one. Prevent an endless
3435 loop. */ 3435 loop. */
3436 abort (); 3436 abort ();
3437 free (digits); 3437 free (digits);
3438 if (ndigits == precision) 3438 if (ndigits == precision)
3439 exponent -= 1; 3439 exponent -= 1;
3440 else 3440 else
3441 exponent += 1; 3441 exponent += 1;
3442 adjusted = 1; 3442 adjusted = 1;
3443 } 3443 }
3444 /* Here ndigits = precision+1. */ 3444 /* Here ndigits = precision+1. */
3445 if (is_borderline (digits, precision)) 3445 if (is_borderline (digits, precision))
3446 { 3446 {
3447 /* Maybe the exponent guess was too high 3447 /* Maybe the exponent guess was too high
3448 and a smaller exponent can be reached 3448 and a smaller exponent can be reached
3449 by turning a 10...0 into 9...9x. */ 3449 by turning a 10...0 into 9...9x. */
3450 char *digits2 = 3450 char *digits2 =
3451 scale10_round_decimal_long_double (arg, 3451 scale10_round_decimal_long_double (arg,
3452 (int)precision - exponent + 1); 3452 (int)precision - exponent + 1);
3453 if (digits2 == NULL) 3453 if (digits2 == NULL)
3454 { 3454 {
3455 free (digits); 3455 free (digits);
3456 END_LONG_DOUBLE_ROUNDING (); 3456 END_LONG_DOUBLE_ROUNDING ();
3457 goto out_of_memory; 3457 goto out_of_memory;
3458 } 3458 }
3459 if (strlen (digits2) == precision + 1) 3459 if (strlen (digits2) == precision + 1)
3460 { 3460 {
3461 free (digits); 3461 free (digits);
3462 digits = digits2; 3462 digits = digits2;
3463 exponent -= 1; 3463 exponent -= 1;
3464 } 3464 }
3465 else 3465 else
3466 free (digits2); 3466 free (digits2);
3467 } 3467 }
3468 /* Here ndigits = precision+1. */ 3468 /* Here ndigits = precision+1. */
3469 3469
3470 *p++ = digits[--ndigits]; 3470 *p++ = digits[--ndigits];
3471 if ((flags & FLAG_ALT) || precision > 0) 3471 if ((flags & FLAG_ALT) || precision > 0)
3472 { 3472 {
3473 *p++ = decimal_point_char (); 3473 *p++ = decimal_point_char ();
3474 while (ndigits > 0) 3474 while (ndigits > 0)
3475 { 3475 {
3476 --ndigits; 3476 --ndigits;
3477 *p++ = digits[ndigits]; 3477 *p++ = digits[ndigits];
3478 } 3478 }
3479 } 3479 }
3480 3480
3481 free (digits); 3481 free (digits);
3482 } 3482 }
3483 3483
3484 *p++ = dp->conversion; /* 'e' or 'E' */ 3484 *p++ = dp->conversion; /* 'e' or 'E' */
3485# if WIDE_CHAR_VERSION 3485# if WIDE_CHAR_VERSION
3486 { 3486 {
3487 static const wchar_t decimal_format[] = 3487 static const wchar_t decimal_format[] =
3488 { '%', '+', '.', '2', 'd', '\0' }; 3488 { '%', '+', '.', '2', 'd', '\0' };
3489 SNPRINTF (p, 6 + 1, decimal_format, exponent); 3489 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3490 } 3490 }
3491 while (*p != '\0') 3491 while (*p != '\0')
3492 p++; 3492 p++;
3493# else 3493# else
3494 if (sizeof (DCHAR_T) == 1) 3494 if (sizeof (DCHAR_T) == 1)
3495 { 3495 {
3496 sprintf ((char *) p, "%+.2d", exponent); 3496 sprintf ((char *) p, "%+.2d", exponent);
3497 while (*p != '\0') 3497 while (*p != '\0')
3498 p++; 3498 p++;
3499 } 3499 }
3500 else 3500 else
3501 { 3501 {
3502 char expbuf[6 + 1]; 3502 char expbuf[6 + 1];
3503 const char *ep; 3503 const char *ep;
3504 sprintf (expbuf, "%+.2d", exponent); 3504 sprintf (expbuf, "%+.2d", exponent);
3505 for (ep = expbuf; (*p = *ep) != '\0'; ep++) 3505 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3506 p++; 3506 p++;
3507 } 3507 }
3508# endif 3508# endif
3509 } 3509 }
3510 else if (dp->conversion == 'g' || dp->conversion == 'G') 3510 else if (dp->conversion == 'g' || dp->conversion == 'G')
3511 { 3511 {
3512 if (precision == 0) 3512 if (precision == 0)
3513 precision = 1; 3513 precision = 1;
3514 /* precision >= 1. */ 3514 /* precision >= 1. */
3515 3515
3516 if (arg == 0.0L) 3516 if (arg == 0.0L)
3517 /* The exponent is 0, >= -4, < precision. 3517 /* The exponent is 0, >= -4, < precision.
3518 Use fixed-point notation. */ 3518 Use fixed-point notation. */
3519 { 3519 {
3520 size_t ndigits = precision; 3520 size_t ndigits = precision;
3521 /* Number of trailing zeroes that have to be 3521 /* Number of trailing zeroes that have to be
3522 dropped. */ 3522 dropped. */
3523 size_t nzeroes = 3523 size_t nzeroes =
3524 (flags & FLAG_ALT ? 0 : precision - 1); 3524 (flags & FLAG_ALT ? 0 : precision - 1);
3525 3525
3526 --ndigits; 3526 --ndigits;
3527 *p++ = '0'; 3527 *p++ = '0';
3528 if ((flags & FLAG_ALT) || ndigits > nzeroes) 3528 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3529 { 3529 {
3530 *p++ = decimal_point_char (); 3530 *p++ = decimal_point_char ();
3531 while (ndigits > nzeroes) 3531 while (ndigits > nzeroes)
3532 { 3532 {
3533 --ndigits; 3533 --ndigits;
3534 *p++ = '0'; 3534 *p++ = '0';
3535 } 3535 }
3536 } 3536 }
3537 } 3537 }
3538 else 3538 else
3539 { 3539 {
3540 /* arg > 0.0L. */ 3540 /* arg > 0.0L. */
3541 int exponent; 3541 int exponent;
3542 int adjusted; 3542 int adjusted;
3543 char *digits; 3543 char *digits;
3544 size_t ndigits; 3544 size_t ndigits;
3545 size_t nzeroes; 3545 size_t nzeroes;
3546 3546
3547 exponent = floorlog10l (arg); 3547 exponent = floorlog10l (arg);
3548 adjusted = 0; 3548 adjusted = 0;
3549 for (;;) 3549 for (;;)
3550 { 3550 {
3551 digits = 3551 digits =
3552 scale10_round_decimal_long_double (arg, 3552 scale10_round_decimal_long_double (arg,
3553 (int)(precision - 1) - exponent); 3553 (int)(precision - 1) - exponent);
3554 if (digits == NULL) 3554 if (digits == NULL)
3555 { 3555 {
3556 END_LONG_DOUBLE_ROUNDING (); 3556 END_LONG_DOUBLE_ROUNDING ();
3557 goto out_of_memory; 3557 goto out_of_memory;
3558 } 3558 }
3559 ndigits = strlen (digits); 3559 ndigits = strlen (digits);
3560 3560
3561 if (ndigits == precision) 3561 if (ndigits == precision)
3562 break; 3562 break;
3563 if (ndigits < precision - 1 3563 if (ndigits < precision - 1
3564 || ndigits > precision + 1) 3564 || ndigits > precision + 1)
3565 /* The exponent was not guessed 3565 /* The exponent was not guessed
3566 precisely enough. */ 3566 precisely enough. */
3567 abort (); 3567 abort ();
3568 if (adjusted) 3568 if (adjusted)
3569 /* None of two values of exponent is 3569 /* None of two values of exponent is
3570 the right one. Prevent an endless 3570 the right one. Prevent an endless
3571 loop. */ 3571 loop. */
3572 abort (); 3572 abort ();
3573 free (digits); 3573 free (digits);
3574 if (ndigits < precision) 3574 if (ndigits < precision)
3575 exponent -= 1; 3575 exponent -= 1;
3576 else 3576 else
3577 exponent += 1; 3577 exponent += 1;
3578 adjusted = 1; 3578 adjusted = 1;
3579 } 3579 }
3580 /* Here ndigits = precision. */ 3580 /* Here ndigits = precision. */
3581 if (is_borderline (digits, precision - 1)) 3581 if (is_borderline (digits, precision - 1))
3582 { 3582 {
3583 /* Maybe the exponent guess was too high 3583 /* Maybe the exponent guess was too high
3584 and a smaller exponent can be reached 3584 and a smaller exponent can be reached
3585 by turning a 10...0 into 9...9x. */ 3585 by turning a 10...0 into 9...9x. */
3586 char *digits2 = 3586 char *digits2 =
3587 scale10_round_decimal_long_double (arg, 3587 scale10_round_decimal_long_double (arg,
3588 (int)(precision - 1) - exponent + 1); 3588 (int)(precision - 1) - exponent + 1);
3589 if (digits2 == NULL) 3589 if (digits2 == NULL)
3590 { 3590 {
3591 free (digits); 3591 free (digits);
3592 END_LONG_DOUBLE_ROUNDING (); 3592 END_LONG_DOUBLE_ROUNDING ();
3593 goto out_of_memory; 3593 goto out_of_memory;
3594 } 3594 }
3595 if (strlen (digits2) == precision) 3595 if (strlen (digits2) == precision)
3596 { 3596 {
3597 free (digits); 3597 free (digits);
3598 digits = digits2; 3598 digits = digits2;
3599 exponent -= 1; 3599 exponent -= 1;
3600 } 3600 }
3601 else 3601 else
3602 free (digits2); 3602 free (digits2);
3603 } 3603 }
3604 /* Here ndigits = precision. */ 3604 /* Here ndigits = precision. */
3605 3605
3606 /* Determine the number of trailing zeroes 3606 /* Determine the number of trailing zeroes
3607 that have to be dropped. */ 3607 that have to be dropped. */
3608 nzeroes = 0; 3608 nzeroes = 0;
3609 if ((flags & FLAG_ALT) == 0) 3609 if ((flags & FLAG_ALT) == 0)
3610 while (nzeroes < ndigits 3610 while (nzeroes < ndigits
3611 && digits[nzeroes] == '0') 3611 && digits[nzeroes] == '0')
3612 nzeroes++; 3612 nzeroes++;
3613 3613
3614 /* The exponent is now determined. */ 3614 /* The exponent is now determined. */
3615 if (exponent >= -4 3615 if (exponent >= -4
3616 && exponent < (long)precision) 3616 && exponent < (long)precision)
3617 { 3617 {
3618 /* Fixed-point notation: 3618 /* Fixed-point notation:
3619 max(exponent,0)+1 digits, then the 3619 max(exponent,0)+1 digits, then the
3620 decimal point, then the remaining 3620 decimal point, then the remaining
3621 digits without trailing zeroes. */ 3621 digits without trailing zeroes. */
3622 if (exponent >= 0) 3622 if (exponent >= 0)
3623 { 3623 {
3624 size_t count = exponent + 1; 3624 size_t count = exponent + 1;
3625 /* Note: count <= precision = ndigits. */ 3625 /* Note: count <= precision = ndigits. */
3626 for (; count > 0; count--) 3626 for (; count > 0; count--)
3627 *p++ = digits[--ndigits]; 3627 *p++ = digits[--ndigits];
3628 if ((flags & FLAG_ALT) || ndigits > nzeroes) 3628 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3629 { 3629 {
3630 *p++ = decimal_point_char (); 3630 *p++ = decimal_point_char ();
3631 while (ndigits > nzeroes) 3631 while (ndigits > nzeroes)
3632 { 3632 {
3633 --ndigits; 3633 --ndigits;
3634 *p++ = digits[ndigits]; 3634 *p++ = digits[ndigits];
3635 } 3635 }
3636 } 3636 }
3637 } 3637 }
3638 else 3638 else
3639 { 3639 {
3640 size_t count = -exponent - 1; 3640 size_t count = -exponent - 1;
3641 *p++ = '0'; 3641 *p++ = '0';
3642 *p++ = decimal_point_char (); 3642 *p++ = decimal_point_char ();
3643 for (; count > 0; count--) 3643 for (; count > 0; count--)
3644 *p++ = '0'; 3644 *p++ = '0';
3645 while (ndigits > nzeroes) 3645 while (ndigits > nzeroes)
3646 { 3646 {
3647 --ndigits; 3647 --ndigits;
3648 *p++ = digits[ndigits]; 3648 *p++ = digits[ndigits];
3649 } 3649 }
3650 } 3650 }
3651 } 3651 }
3652 else 3652 else
3653 { 3653 {
3654 /* Exponential notation. */ 3654 /* Exponential notation. */
3655 *p++ = digits[--ndigits]; 3655 *p++ = digits[--ndigits];
3656 if ((flags & FLAG_ALT) || ndigits > nzeroes) 3656 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3657 { 3657 {
3658 *p++ = decimal_point_char (); 3658 *p++ = decimal_point_char ();
3659 while (ndigits > nzeroes) 3659 while (ndigits > nzeroes)
3660 { 3660 {
3661 --ndigits; 3661 --ndigits;
3662 *p++ = digits[ndigits]; 3662 *p++ = digits[ndigits];
3663 } 3663 }
3664 } 3664 }
3665 *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ 3665 *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
3666# if WIDE_CHAR_VERSION 3666# if WIDE_CHAR_VERSION
3667 { 3667 {
3668 static const wchar_t decimal_format[] = 3668 static const wchar_t decimal_format[] =
3669 { '%', '+', '.', '2', 'd', '\0' }; 3669 { '%', '+', '.', '2', 'd', '\0' };
3670 SNPRINTF (p, 6 + 1, decimal_format, exponent); 3670 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3671 } 3671 }
3672 while (*p != '\0') 3672 while (*p != '\0')
3673 p++; 3673 p++;
3674# else 3674# else
3675 if (sizeof (DCHAR_T) == 1) 3675 if (sizeof (DCHAR_T) == 1)
3676 { 3676 {
3677 sprintf ((char *) p, "%+.2d", exponent); 3677 sprintf ((char *) p, "%+.2d", exponent);
3678 while (*p != '\0') 3678 while (*p != '\0')
3679 p++; 3679 p++;
3680 } 3680 }
3681 else 3681 else
3682 { 3682 {
3683 char expbuf[6 + 1]; 3683 char expbuf[6 + 1];
3684 const char *ep; 3684 const char *ep;
3685 sprintf (expbuf, "%+.2d", exponent); 3685 sprintf (expbuf, "%+.2d", exponent);
3686 for (ep = expbuf; (*p = *ep) != '\0'; ep++) 3686 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3687 p++; 3687 p++;
3688 } 3688 }
3689# endif 3689# endif
3690 } 3690 }
3691 3691
3692 free (digits); 3692 free (digits);
3693 } 3693 }
3694 } 3694 }
3695 else 3695 else
3696 abort (); 3696 abort ();
3697# else 3697# else
3698 /* arg is finite. */ 3698 /* arg is finite. */
3699 if (!(arg == 0.0L)) 3699 if (!(arg == 0.0L))
3700 abort (); 3700 abort ();
3701 3701
3702 pad_ptr = p; 3702 pad_ptr = p;
3703 3703
3704 if (dp->conversion == 'f' || dp->conversion == 'F') 3704 if (dp->conversion == 'f' || dp->conversion == 'F')
3705 { 3705 {
3706 *p++ = '0'; 3706 *p++ = '0';
3707 if ((flags & FLAG_ALT) || precision > 0) 3707 if ((flags & FLAG_ALT) || precision > 0)
3708 { 3708 {
3709 *p++ = decimal_point_char (); 3709 *p++ = decimal_point_char ();
3710 for (; precision > 0; precision--) 3710 for (; precision > 0; precision--)
3711 *p++ = '0'; 3711 *p++ = '0';
3712 } 3712 }
3713 } 3713 }
3714 else if (dp->conversion == 'e' || dp->conversion == 'E') 3714 else if (dp->conversion == 'e' || dp->conversion == 'E')
3715 { 3715 {
3716 *p++ = '0'; 3716 *p++ = '0';
3717 if ((flags & FLAG_ALT) || precision > 0) 3717 if ((flags & FLAG_ALT) || precision > 0)
3718 { 3718 {
3719 *p++ = decimal_point_char (); 3719 *p++ = decimal_point_char ();
3720 for (; precision > 0; precision--) 3720 for (; precision > 0; precision--)
3721 *p++ = '0'; 3721 *p++ = '0';
3722 } 3722 }
3723 *p++ = dp->conversion; /* 'e' or 'E' */ 3723 *p++ = dp->conversion; /* 'e' or 'E' */
3724 *p++ = '+'; 3724 *p++ = '+';
3725 *p++ = '0'; 3725 *p++ = '0';
3726 *p++ = '0'; 3726 *p++ = '0';
3727 } 3727 }
3728 else if (dp->conversion == 'g' || dp->conversion == 'G') 3728 else if (dp->conversion == 'g' || dp->conversion == 'G')
3729 { 3729 {
3730 *p++ = '0'; 3730 *p++ = '0';
3731 if (flags & FLAG_ALT) 3731 if (flags & FLAG_ALT)
3732 { 3732 {
3733 size_t ndigits = 3733 size_t ndigits =
3734 (precision > 0 ? precision - 1 : 0); 3734 (precision > 0 ? precision - 1 : 0);
3735 *p++ = decimal_point_char (); 3735 *p++ = decimal_point_char ();
3736 for (; ndigits > 0; --ndigits) 3736 for (; ndigits > 0; --ndigits)
3737 *p++ = '0'; 3737 *p++ = '0';
3738 } 3738 }
3739 } 3739 }
3740 else if (dp->conversion == 'a' || dp->conversion == 'A') 3740 else if (dp->conversion == 'a' || dp->conversion == 'A')
3741 { 3741 {
3742 *p++ = '0'; 3742 *p++ = '0';
3743 *p++ = dp->conversion - 'A' + 'X'; 3743 *p++ = dp->conversion - 'A' + 'X';
3744 pad_ptr = p; 3744 pad_ptr = p;
3745 *p++ = '0'; 3745 *p++ = '0';
3746 if ((flags & FLAG_ALT) || precision > 0) 3746 if ((flags & FLAG_ALT) || precision > 0)
3747 { 3747 {
3748 *p++ = decimal_point_char (); 3748 *p++ = decimal_point_char ();
3749 for (; precision > 0; precision--) 3749 for (; precision > 0; precision--)
3750 *p++ = '0'; 3750 *p++ = '0';
3751 } 3751 }
3752 *p++ = dp->conversion - 'A' + 'P'; 3752 *p++ = dp->conversion - 'A' + 'P';
3753 *p++ = '+'; 3753 *p++ = '+';
3754 *p++ = '0'; 3754 *p++ = '0';
3755 } 3755 }
3756 else 3756 else
3757 abort (); 3757 abort ();
3758# endif 3758# endif
3759 } 3759 }
3760 3760
3761 END_LONG_DOUBLE_ROUNDING (); 3761 END_LONG_DOUBLE_ROUNDING ();
3762 } 3762 }
3763 } 3763 }
3764# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE 3764# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
3765 else 3765 else
3766# endif 3766# endif
3767# endif 3767# endif
3768# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE 3768# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
3769 { 3769 {
3770 double arg = a.arg[dp->arg_index].a.a_double; 3770 double arg = a.arg[dp->arg_index].a.a_double;
3771 3771
3772 if (isnand (arg)) 3772 if (isnand (arg))
3773 { 3773 {
3774 if (dp->conversion >= 'A' && dp->conversion <= 'Z') 3774 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
3775 { 3775 {
3776 *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; 3776 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
3777 } 3777 }
3778 else 3778 else
3779 { 3779 {
3780 *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; 3780 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
3781 } 3781 }
3782 } 3782 }
3783 else 3783 else
3784 { 3784 {
3785 int sign = 0; 3785 int sign = 0;
3786 3786
3787 if (signbit (arg)) /* arg < 0.0 or negative zero */ 3787 if (signbit (arg)) /* arg < 0.0 or negative zero */
3788 { 3788 {
3789 sign = -1; 3789 sign = -1;
3790 arg = -arg; 3790 arg = -arg;
3791 } 3791 }
3792 3792
3793 if (sign < 0) 3793 if (sign < 0)
3794 *p++ = '-'; 3794 *p++ = '-';
3795 else if (flags & FLAG_SHOWSIGN) 3795 else if (flags & FLAG_SHOWSIGN)
3796 *p++ = '+'; 3796 *p++ = '+';
3797 else if (flags & FLAG_SPACE) 3797 else if (flags & FLAG_SPACE)
3798 *p++ = ' '; 3798 *p++ = ' ';
3799 3799
3800 if (arg > 0.0 && arg + arg == arg) 3800 if (arg > 0.0 && arg + arg == arg)
3801 { 3801 {
3802 if (dp->conversion >= 'A' && dp->conversion <= 'Z') 3802 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
3803 { 3803 {
3804 *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; 3804 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
3805 } 3805 }
3806 else 3806 else
3807 { 3807 {
3808 *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; 3808 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
3809 } 3809 }
3810 } 3810 }
3811 else 3811 else
3812 { 3812 {
3813# if NEED_PRINTF_DOUBLE 3813# if NEED_PRINTF_DOUBLE
3814 pad_ptr = p; 3814 pad_ptr = p;
3815 3815
3816 if (dp->conversion == 'f' || dp->conversion == 'F') 3816 if (dp->conversion == 'f' || dp->conversion == 'F')
3817 { 3817 {
3818 char *digits; 3818 char *digits;
3819 size_t ndigits; 3819 size_t ndigits;
3820 3820
3821 digits = 3821 digits =
3822 scale10_round_decimal_double (arg, precision); 3822 scale10_round_decimal_double (arg, precision);
3823 if (digits == NULL) 3823 if (digits == NULL)
3824 goto out_of_memory; 3824 goto out_of_memory;
3825 ndigits = strlen (digits); 3825 ndigits = strlen (digits);
3826 3826
3827 if (ndigits > precision) 3827 if (ndigits > precision)
3828 do 3828 do
3829 { 3829 {
3830 --ndigits; 3830 --ndigits;
3831 *p++ = digits[ndigits]; 3831 *p++ = digits[ndigits];
3832 } 3832 }
3833 while (ndigits > precision); 3833 while (ndigits > precision);
3834 else 3834 else
3835 *p++ = '0'; 3835 *p++ = '0';
3836 /* Here ndigits <= precision. */ 3836 /* Here ndigits <= precision. */
3837 if ((flags & FLAG_ALT) || precision > 0) 3837 if ((flags & FLAG_ALT) || precision > 0)
3838 { 3838 {
3839 *p++ = decimal_point_char (); 3839 *p++ = decimal_point_char ();
3840 for (; precision > ndigits; precision--) 3840 for (; precision > ndigits; precision--)
3841 *p++ = '0'; 3841 *p++ = '0';
3842 while (ndigits > 0) 3842 while (ndigits > 0)
3843 { 3843 {
3844 --ndigits; 3844 --ndigits;
3845 *p++ = digits[ndigits]; 3845 *p++ = digits[ndigits];
3846 } 3846 }
3847 } 3847 }
3848 3848
3849 free (digits); 3849 free (digits);
3850 } 3850 }
3851 else if (dp->conversion == 'e' || dp->conversion == 'E') 3851 else if (dp->conversion == 'e' || dp->conversion == 'E')
3852 { 3852 {
3853 int exponent; 3853 int exponent;
3854 3854
3855 if (arg == 0.0) 3855 if (arg == 0.0)
3856 { 3856 {
3857 exponent = 0; 3857 exponent = 0;
3858 *p++ = '0'; 3858 *p++ = '0';
3859 if ((flags & FLAG_ALT) || precision > 0) 3859 if ((flags & FLAG_ALT) || precision > 0)
3860 { 3860 {
3861 *p++ = decimal_point_char (); 3861 *p++ = decimal_point_char ();
3862 for (; precision > 0; precision--) 3862 for (; precision > 0; precision--)
3863 *p++ = '0'; 3863 *p++ = '0';
3864 } 3864 }
3865 } 3865 }
3866 else 3866 else
3867 { 3867 {
3868 /* arg > 0.0. */ 3868 /* arg > 0.0. */
3869 int adjusted; 3869 int adjusted;
3870 char *digits; 3870 char *digits;
3871 size_t ndigits; 3871 size_t ndigits;
3872 3872
3873 exponent = floorlog10 (arg); 3873 exponent = floorlog10 (arg);
3874 adjusted = 0; 3874 adjusted = 0;
3875 for (;;) 3875 for (;;)
3876 { 3876 {
3877 digits = 3877 digits =
3878 scale10_round_decimal_double (arg, 3878 scale10_round_decimal_double (arg,
3879 (int)precision - exponent); 3879 (int)precision - exponent);
3880 if (digits == NULL) 3880 if (digits == NULL)
3881 goto out_of_memory; 3881 goto out_of_memory;
3882 ndigits = strlen (digits); 3882 ndigits = strlen (digits);
3883 3883
3884 if (ndigits == precision + 1) 3884 if (ndigits == precision + 1)
3885 break; 3885 break;
3886 if (ndigits < precision 3886 if (ndigits < precision
3887 || ndigits > precision + 2) 3887 || ndigits > precision + 2)
3888 /* The exponent was not guessed 3888 /* The exponent was not guessed
3889 precisely enough. */ 3889 precisely enough. */
3890 abort (); 3890 abort ();
3891 if (adjusted) 3891 if (adjusted)
3892 /* None of two values of exponent is 3892 /* None of two values of exponent is
3893 the right one. Prevent an endless 3893 the right one. Prevent an endless
3894 loop. */ 3894 loop. */
3895 abort (); 3895 abort ();
3896 free (digits); 3896 free (digits);
3897 if (ndigits == precision) 3897 if (ndigits == precision)
3898 exponent -= 1; 3898 exponent -= 1;
3899 else 3899 else
3900 exponent += 1; 3900 exponent += 1;
3901 adjusted = 1; 3901 adjusted = 1;
3902 } 3902 }
3903 /* Here ndigits = precision+1. */ 3903 /* Here ndigits = precision+1. */
3904 if (is_borderline (digits, precision)) 3904 if (is_borderline (digits, precision))
3905 { 3905 {
3906 /* Maybe the exponent guess was too high 3906 /* Maybe the exponent guess was too high
3907 and a smaller exponent can be reached 3907 and a smaller exponent can be reached
3908 by turning a 10...0 into 9...9x. */ 3908 by turning a 10...0 into 9...9x. */
3909 char *digits2 = 3909 char *digits2 =
3910 scale10_round_decimal_double (arg, 3910 scale10_round_decimal_double (arg,
3911 (int)precision - exponent + 1); 3911 (int)precision - exponent + 1);
3912 if (digits2 == NULL) 3912 if (digits2 == NULL)
3913 { 3913 {
3914 free (digits); 3914 free (digits);
3915 goto out_of_memory; 3915 goto out_of_memory;
3916 } 3916 }
3917 if (strlen (digits2) == precision + 1) 3917 if (strlen (digits2) == precision + 1)
3918 { 3918 {
3919 free (digits); 3919 free (digits);
3920 digits = digits2; 3920 digits = digits2;
3921 exponent -= 1; 3921 exponent -= 1;
3922 } 3922 }
3923 else 3923 else
3924 free (digits2); 3924 free (digits2);
3925 } 3925 }
3926 /* Here ndigits = precision+1. */ 3926 /* Here ndigits = precision+1. */
3927 3927
3928 *p++ = digits[--ndigits]; 3928 *p++ = digits[--ndigits];
3929 if ((flags & FLAG_ALT) || precision > 0) 3929 if ((flags & FLAG_ALT) || precision > 0)
3930 { 3930 {
3931 *p++ = decimal_point_char (); 3931 *p++ = decimal_point_char ();
3932 while (ndigits > 0) 3932 while (ndigits > 0)
3933 { 3933 {
3934 --ndigits; 3934 --ndigits;
3935 *p++ = digits[ndigits]; 3935 *p++ = digits[ndigits];
3936 } 3936 }
3937 } 3937 }
3938 3938
3939 free (digits); 3939 free (digits);
3940 } 3940 }
3941 3941
3942 *p++ = dp->conversion; /* 'e' or 'E' */ 3942 *p++ = dp->conversion; /* 'e' or 'E' */
3943# if WIDE_CHAR_VERSION 3943# if WIDE_CHAR_VERSION
3944 { 3944 {
3945 static const wchar_t decimal_format[] = 3945 static const wchar_t decimal_format[] =
3946 /* Produce the same number of exponent digits 3946 /* Produce the same number of exponent digits
3947 as the native printf implementation. */ 3947 as the native printf implementation. */
3948# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 3948# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3949 { '%', '+', '.', '3', 'd', '\0' }; 3949 { '%', '+', '.', '3', 'd', '\0' };
3950# else 3950# else
3951 { '%', '+', '.', '2', 'd', '\0' }; 3951 { '%', '+', '.', '2', 'd', '\0' };
3952# endif 3952# endif
3953 SNPRINTF (p, 6 + 1, decimal_format, exponent); 3953 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3954 } 3954 }
3955 while (*p != '\0') 3955 while (*p != '\0')
3956 p++; 3956 p++;
3957# else 3957# else
3958 { 3958 {
3959 static const char decimal_format[] = 3959 static const char decimal_format[] =
3960 /* Produce the same number of exponent digits 3960 /* Produce the same number of exponent digits
3961 as the native printf implementation. */ 3961 as the native printf implementation. */
3962# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 3962# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3963 "%+.3d"; 3963 "%+.3d";
3964# else 3964# else
3965 "%+.2d"; 3965 "%+.2d";
3966# endif 3966# endif
3967 if (sizeof (DCHAR_T) == 1) 3967 if (sizeof (DCHAR_T) == 1)
3968 { 3968 {
3969 sprintf ((char *) p, decimal_format, exponent); 3969 sprintf ((char *) p, decimal_format, exponent);
3970 while (*p != '\0') 3970 while (*p != '\0')
3971 p++; 3971 p++;
3972 } 3972 }
3973 else 3973 else
3974 { 3974 {
3975 char expbuf[6 + 1]; 3975 char expbuf[6 + 1];
3976 const char *ep; 3976 const char *ep;
3977 sprintf (expbuf, decimal_format, exponent); 3977 sprintf (expbuf, decimal_format, exponent);
3978 for (ep = expbuf; (*p = *ep) != '\0'; ep++) 3978 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3979 p++; 3979 p++;
3980 } 3980 }
3981 } 3981 }
3982# endif 3982# endif
3983 } 3983 }
3984 else if (dp->conversion == 'g' || dp->conversion == 'G') 3984 else if (dp->conversion == 'g' || dp->conversion == 'G')
3985 { 3985 {
3986 if (precision == 0) 3986 if (precision == 0)
3987 precision = 1; 3987 precision = 1;
3988 /* precision >= 1. */ 3988 /* precision >= 1. */
3989 3989
3990 if (arg == 0.0) 3990 if (arg == 0.0)
3991 /* The exponent is 0, >= -4, < precision. 3991 /* The exponent is 0, >= -4, < precision.
3992 Use fixed-point notation. */ 3992 Use fixed-point notation. */
3993 { 3993 {
3994 size_t ndigits = precision; 3994 size_t ndigits = precision;
3995 /* Number of trailing zeroes that have to be 3995 /* Number of trailing zeroes that have to be
3996 dropped. */ 3996 dropped. */
3997 size_t nzeroes = 3997 size_t nzeroes =
3998 (flags & FLAG_ALT ? 0 : precision - 1); 3998 (flags & FLAG_ALT ? 0 : precision - 1);
3999 3999
4000 --ndigits; 4000 --ndigits;
4001 *p++ = '0'; 4001 *p++ = '0';
4002 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4002 if ((flags & FLAG_ALT) || ndigits > nzeroes)
4003 { 4003 {
4004 *p++ = decimal_point_char (); 4004 *p++ = decimal_point_char ();
4005 while (ndigits > nzeroes) 4005 while (ndigits > nzeroes)
4006 { 4006 {
4007 --ndigits; 4007 --ndigits;
4008 *p++ = '0'; 4008 *p++ = '0';
4009 } 4009 }
4010 } 4010 }
4011 } 4011 }
4012 else 4012 else
4013 { 4013 {
4014 /* arg > 0.0. */ 4014 /* arg > 0.0. */
4015 int exponent; 4015 int exponent;
4016 int adjusted; 4016 int adjusted;
4017 char *digits; 4017 char *digits;
4018 size_t ndigits; 4018 size_t ndigits;
4019 size_t nzeroes; 4019 size_t nzeroes;
4020 4020
4021 exponent = floorlog10 (arg); 4021 exponent = floorlog10 (arg);
4022 adjusted = 0; 4022 adjusted = 0;
4023 for (;;) 4023 for (;;)
4024 { 4024 {
4025 digits = 4025 digits =
4026 scale10_round_decimal_double (arg, 4026 scale10_round_decimal_double (arg,
4027 (int)(precision - 1) - exponent); 4027 (int)(precision - 1) - exponent);
4028 if (digits == NULL) 4028 if (digits == NULL)
4029 goto out_of_memory; 4029 goto out_of_memory;
4030 ndigits = strlen (digits); 4030 ndigits = strlen (digits);
4031 4031
4032 if (ndigits == precision) 4032 if (ndigits == precision)
4033 break; 4033 break;
4034 if (ndigits < precision - 1 4034 if (ndigits < precision - 1
4035 || ndigits > precision + 1) 4035 || ndigits > precision + 1)
4036 /* The exponent was not guessed 4036 /* The exponent was not guessed
4037 precisely enough. */ 4037 precisely enough. */
4038 abort (); 4038 abort ();
4039 if (adjusted) 4039 if (adjusted)
4040 /* None of two values of exponent is 4040 /* None of two values of exponent is
4041 the right one. Prevent an endless 4041 the right one. Prevent an endless
4042 loop. */ 4042 loop. */
4043 abort (); 4043 abort ();
4044 free (digits); 4044 free (digits);
4045 if (ndigits < precision) 4045 if (ndigits < precision)
4046 exponent -= 1; 4046 exponent -= 1;
4047 else 4047 else
4048 exponent += 1; 4048 exponent += 1;
4049 adjusted = 1; 4049 adjusted = 1;
4050 } 4050 }
4051 /* Here ndigits = precision. */ 4051 /* Here ndigits = precision. */
4052 if (is_borderline (digits, precision - 1)) 4052 if (is_borderline (digits, precision - 1))
4053 { 4053 {
4054 /* Maybe the exponent guess was too high 4054 /* Maybe the exponent guess was too high
4055 and a smaller exponent can be reached 4055 and a smaller exponent can be reached
4056 by turning a 10...0 into 9...9x. */ 4056 by turning a 10...0 into 9...9x. */
4057 char *digits2 = 4057 char *digits2 =
4058 scale10_round_decimal_double (arg, 4058 scale10_round_decimal_double (arg,
4059 (int)(precision - 1) - exponent + 1); 4059 (int)(precision - 1) - exponent + 1);
4060 if (digits2 == NULL) 4060 if (digits2 == NULL)
4061 { 4061 {
4062 free (digits); 4062 free (digits);
4063 goto out_of_memory; 4063 goto out_of_memory;
4064 } 4064 }
4065 if (strlen (digits2) == precision) 4065 if (strlen (digits2) == precision)
4066 { 4066 {
4067 free (digits); 4067 free (digits);
4068 digits = digits2; 4068 digits = digits2;
4069 exponent -= 1; 4069 exponent -= 1;
4070 } 4070 }
4071 else 4071 else
4072 free (digits2); 4072 free (digits2);
4073 } 4073 }
4074 /* Here ndigits = precision. */ 4074 /* Here ndigits = precision. */
4075 4075
4076 /* Determine the number of trailing zeroes 4076 /* Determine the number of trailing zeroes
4077 that have to be dropped. */ 4077 that have to be dropped. */
4078 nzeroes = 0; 4078 nzeroes = 0;
4079 if ((flags & FLAG_ALT) == 0) 4079 if ((flags & FLAG_ALT) == 0)
4080 while (nzeroes < ndigits 4080 while (nzeroes < ndigits
4081 && digits[nzeroes] == '0') 4081 && digits[nzeroes] == '0')
4082 nzeroes++; 4082 nzeroes++;
4083 4083
4084 /* The exponent is now determined. */ 4084 /* The exponent is now determined. */
4085 if (exponent >= -4 4085 if (exponent >= -4
4086 && exponent < (long)precision) 4086 && exponent < (long)precision)
4087 { 4087 {
4088 /* Fixed-point notation: 4088 /* Fixed-point notation:
4089 max(exponent,0)+1 digits, then the 4089 max(exponent,0)+1 digits, then the
4090 decimal point, then the remaining 4090 decimal point, then the remaining
4091 digits without trailing zeroes. */ 4091 digits without trailing zeroes. */
4092 if (exponent >= 0) 4092 if (exponent >= 0)
4093 { 4093 {
4094 size_t count = exponent + 1; 4094 size_t count = exponent + 1;
4095 /* Note: count <= precision = ndigits. */ 4095 /* Note: count <= precision = ndigits. */
4096 for (; count > 0; count--) 4096 for (; count > 0; count--)
4097 *p++ = digits[--ndigits]; 4097 *p++ = digits[--ndigits];
4098 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4098 if ((flags & FLAG_ALT) || ndigits > nzeroes)
4099 { 4099 {
4100 *p++ = decimal_point_char (); 4100 *p++ = decimal_point_char ();
4101 while (ndigits > nzeroes) 4101 while (ndigits > nzeroes)
4102 { 4102 {
4103 --ndigits; 4103 --ndigits;
4104 *p++ = digits[ndigits]; 4104 *p++ = digits[ndigits];
4105 } 4105 }
4106 } 4106 }
4107 } 4107 }
4108 else 4108 else
4109 { 4109 {
4110 size_t count = -exponent - 1; 4110 size_t count = -exponent - 1;
4111 *p++ = '0'; 4111 *p++ = '0';
4112 *p++ = decimal_point_char (); 4112 *p++ = decimal_point_char ();
4113 for (; count > 0; count--) 4113 for (; count > 0; count--)
4114 *p++ = '0'; 4114 *p++ = '0';
4115 while (ndigits > nzeroes) 4115 while (ndigits > nzeroes)
4116 { 4116 {
4117 --ndigits; 4117 --ndigits;
4118 *p++ = digits[ndigits]; 4118 *p++ = digits[ndigits];
4119 } 4119 }
4120 } 4120 }
4121 } 4121 }
4122 else 4122 else
4123 { 4123 {
4124 /* Exponential notation. */ 4124 /* Exponential notation. */
4125 *p++ = digits[--ndigits]; 4125 *p++ = digits[--ndigits];
4126 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4126 if ((flags & FLAG_ALT) || ndigits > nzeroes)
4127 { 4127 {
4128 *p++ = decimal_point_char (); 4128 *p++ = decimal_point_char ();
4129 while (ndigits > nzeroes) 4129 while (ndigits > nzeroes)
4130 { 4130 {
4131 --ndigits; 4131 --ndigits;
4132 *p++ = digits[ndigits]; 4132 *p++ = digits[ndigits];
4133 } 4133 }
4134 } 4134 }
4135 *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ 4135 *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
4136# if WIDE_CHAR_VERSION 4136# if WIDE_CHAR_VERSION
4137 { 4137 {
4138 static const wchar_t decimal_format[] = 4138 static const wchar_t decimal_format[] =
4139 /* Produce the same number of exponent digits 4139 /* Produce the same number of exponent digits
4140 as the native printf implementation. */ 4140 as the native printf implementation. */
4141# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4141# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
4142 { '%', '+', '.', '3', 'd', '\0' }; 4142 { '%', '+', '.', '3', 'd', '\0' };
4143# else 4143# else
4144 { '%', '+', '.', '2', 'd', '\0' }; 4144 { '%', '+', '.', '2', 'd', '\0' };
4145# endif 4145# endif
4146 SNPRINTF (p, 6 + 1, decimal_format, exponent); 4146 SNPRINTF (p, 6 + 1, decimal_format, exponent);
4147 } 4147 }
4148 while (*p != '\0') 4148 while (*p != '\0')
4149 p++; 4149 p++;
4150# else 4150# else
4151 { 4151 {
4152 static const char decimal_format[] = 4152 static const char decimal_format[] =
4153 /* Produce the same number of exponent digits 4153 /* Produce the same number of exponent digits
4154 as the native printf implementation. */ 4154 as the native printf implementation. */
4155# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4155# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
4156 "%+.3d"; 4156 "%+.3d";
4157# else 4157# else
4158 "%+.2d"; 4158 "%+.2d";
4159# endif 4159# endif
4160 if (sizeof (DCHAR_T) == 1) 4160 if (sizeof (DCHAR_T) == 1)
4161 { 4161 {
4162 sprintf ((char *) p, decimal_format, exponent); 4162 sprintf ((char *) p, decimal_format, exponent);
4163 while (*p != '\0') 4163 while (*p != '\0')
4164 p++; 4164 p++;
4165 } 4165 }
4166 else 4166 else
4167 { 4167 {
4168 char expbuf[6 + 1]; 4168 char expbuf[6 + 1];
4169 const char *ep; 4169 const char *ep;
4170 sprintf (expbuf, decimal_format, exponent); 4170 sprintf (expbuf, decimal_format, exponent);
4171 for (ep = expbuf; (*p = *ep) != '\0'; ep++) 4171 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
4172 p++; 4172 p++;
4173 } 4173 }
4174 } 4174 }
4175# endif 4175# endif
4176 } 4176 }
4177 4177
4178 free (digits); 4178 free (digits);
4179 } 4179 }
4180 } 4180 }
4181 else 4181 else
4182 abort (); 4182 abort ();
4183# else 4183# else
4184 /* arg is finite. */ 4184 /* arg is finite. */
4185 if (!(arg == 0.0)) 4185 if (!(arg == 0.0))
4186 abort (); 4186 abort ();
4187 4187
4188 pad_ptr = p; 4188 pad_ptr = p;
4189 4189
4190 if (dp->conversion == 'f' || dp->conversion == 'F') 4190 if (dp->conversion == 'f' || dp->conversion == 'F')
4191 { 4191 {
4192 *p++ = '0'; 4192 *p++ = '0';
4193 if ((flags & FLAG_ALT) || precision > 0) 4193 if ((flags & FLAG_ALT) || precision > 0)
4194 { 4194 {
4195 *p++ = decimal_point_char (); 4195 *p++ = decimal_point_char ();
4196 for (; precision > 0; precision--) 4196 for (; precision > 0; precision--)
4197 *p++ = '0'; 4197 *p++ = '0';
4198 } 4198 }
4199 } 4199 }
4200 else if (dp->conversion == 'e' || dp->conversion == 'E') 4200 else if (dp->conversion == 'e' || dp->conversion == 'E')
4201 { 4201 {
4202 *p++ = '0'; 4202 *p++ = '0';
4203 if ((flags & FLAG_ALT) || precision > 0) 4203 if ((flags & FLAG_ALT) || precision > 0)
4204 { 4204 {
4205 *p++ = decimal_point_char (); 4205 *p++ = decimal_point_char ();
4206 for (; precision > 0; precision--) 4206 for (; precision > 0; precision--)
4207 *p++ = '0'; 4207 *p++ = '0';
4208 } 4208 }
4209 *p++ = dp->conversion; /* 'e' or 'E' */ 4209 *p++ = dp->conversion; /* 'e' or 'E' */
4210 *p++ = '+'; 4210 *p++ = '+';
4211 /* Produce the same number of exponent digits as 4211 /* Produce the same number of exponent digits as
4212 the native printf implementation. */ 4212 the native printf implementation. */
4213# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4213# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
4214 *p++ = '0'; 4214 *p++ = '0';
4215# endif 4215# endif
4216 *p++ = '0'; 4216 *p++ = '0';
4217 *p++ = '0'; 4217 *p++ = '0';
4218 } 4218 }
4219 else if (dp->conversion == 'g' || dp->conversion == 'G') 4219 else if (dp->conversion == 'g' || dp->conversion == 'G')
4220 { 4220 {
4221 *p++ = '0'; 4221 *p++ = '0';
4222 if (flags & FLAG_ALT) 4222 if (flags & FLAG_ALT)
4223 { 4223 {
4224 size_t ndigits = 4224 size_t ndigits =
4225 (precision > 0 ? precision - 1 : 0); 4225 (precision > 0 ? precision - 1 : 0);
4226 *p++ = decimal_point_char (); 4226 *p++ = decimal_point_char ();
4227 for (; ndigits > 0; --ndigits) 4227 for (; ndigits > 0; --ndigits)
4228 *p++ = '0'; 4228 *p++ = '0';
4229 } 4229 }
4230 } 4230 }
4231 else 4231 else
4232 abort (); 4232 abort ();
4233# endif 4233# endif
4234 } 4234 }
4235 } 4235 }
4236 } 4236 }
4237# endif 4237# endif
4238 4238
4239 /* The generated string now extends from tmp to p, with the 4239 /* The generated string now extends from tmp to p, with the
4240 zero padding insertion point being at pad_ptr. */ 4240 zero padding insertion point being at pad_ptr. */
4241 if (has_width && p - tmp < width) 4241 if (has_width && p - tmp < width)
4242 { 4242 {
4243 size_t pad = width - (p - tmp); 4243 size_t pad = width - (p - tmp);
4244 DCHAR_T *end = p + pad; 4244 DCHAR_T *end = p + pad;
4245 4245
4246 if (flags & FLAG_LEFT) 4246 if (flags & FLAG_LEFT)
4247 { 4247 {
4248 /* Pad with spaces on the right. */ 4248 /* Pad with spaces on the right. */
4249 for (; pad > 0; pad--) 4249 for (; pad > 0; pad--)
4250 *p++ = ' '; 4250 *p++ = ' ';
4251 } 4251 }
4252 else if ((flags & FLAG_ZERO) && pad_ptr != NULL) 4252 else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
4253 { 4253 {
4254 /* Pad with zeroes. */ 4254 /* Pad with zeroes. */
4255 DCHAR_T *q = end; 4255 DCHAR_T *q = end;
4256 4256
4257 while (p > pad_ptr) 4257 while (p > pad_ptr)
4258 *--q = *--p; 4258 *--q = *--p;
4259 for (; pad > 0; pad--) 4259 for (; pad > 0; pad--)
4260 *p++ = '0'; 4260 *p++ = '0';
4261 } 4261 }
4262 else 4262 else
4263 { 4263 {
4264 /* Pad with spaces on the left. */ 4264 /* Pad with spaces on the left. */
4265 DCHAR_T *q = end; 4265 DCHAR_T *q = end;
4266 4266
4267 while (p > tmp) 4267 while (p > tmp)
4268 *--q = *--p; 4268 *--q = *--p;
4269 for (; pad > 0; pad--) 4269 for (; pad > 0; pad--)
4270 *p++ = ' '; 4270 *p++ = ' ';
4271 } 4271 }
4272 4272
4273 p = end; 4273 p = end;
4274 } 4274 }
4275 4275
4276 { 4276 {
4277 size_t count = p - tmp; 4277 size_t count = p - tmp;
4278 4278
4279 if (count >= tmp_length) 4279 if (count >= tmp_length)
4280 /* tmp_length was incorrectly calculated - fix the 4280 /* tmp_length was incorrectly calculated - fix the
4281 code above! */ 4281 code above! */
4282 abort (); 4282 abort ();
4283 4283
4284 /* Make room for the result. */ 4284 /* Make room for the result. */
4285 if (count >= allocated - length) 4285 if (count >= allocated - length)
4286 { 4286 {
4287 size_t n = xsum (length, count); 4287 size_t n = xsum (length, count);
4288 4288
4289 ENSURE_ALLOCATION (n); 4289 ENSURE_ALLOCATION (n);
4290 } 4290 }
4291 4291
4292 /* Append the result. */ 4292 /* Append the result. */
4293 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 4293 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
4294 if (tmp != tmpbuf) 4294 if (tmp != tmpbuf)
4295 free (tmp); 4295 free (tmp);
4296 length += count; 4296 length += count;
4297 } 4297 }
4298 } 4298 }
4299#endif 4299#endif
4300 else 4300 else
4301 { 4301 {
4302 arg_type type = a.arg[dp->arg_index].type; 4302 arg_type type = a.arg[dp->arg_index].type;
4303 int flags = dp->flags; 4303 int flags = dp->flags;
4304#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION 4304#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4305 int has_width; 4305 int has_width;
4306 size_t width; 4306 size_t width;
4307#endif 4307#endif
4308#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION 4308#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
4309 int has_precision; 4309 int has_precision;
4310 size_t precision; 4310 size_t precision;
4311#endif 4311#endif
4312#if NEED_PRINTF_UNBOUNDED_PRECISION 4312#if NEED_PRINTF_UNBOUNDED_PRECISION
4313 int prec_ourselves; 4313 int prec_ourselves;
4314#else 4314#else
4315# define prec_ourselves 0 4315# define prec_ourselves 0
4316#endif 4316#endif
4317#if NEED_PRINTF_FLAG_LEFTADJUST 4317#if NEED_PRINTF_FLAG_LEFTADJUST
4318# define pad_ourselves 1 4318# define pad_ourselves 1
4319#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION 4319#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4320 int pad_ourselves; 4320 int pad_ourselves;
4321#else 4321#else
4322# define pad_ourselves 0 4322# define pad_ourselves 0
4323#endif 4323#endif
4324 TCHAR_T *fbp; 4324 TCHAR_T *fbp;
4325 unsigned int prefix_count; 4325 unsigned int prefix_count;
4326 int prefixes[2] IF_LINT (= { 0 }); 4326 int prefixes[2] IF_LINT (= { 0 });
4327#if !USE_SNPRINTF 4327#if !USE_SNPRINTF
4328 size_t tmp_length; 4328 size_t tmp_length;
4329 TCHAR_T tmpbuf[700]; 4329 TCHAR_T tmpbuf[700];
4330 TCHAR_T *tmp; 4330 TCHAR_T *tmp;
4331#endif 4331#endif
4332 4332
4333#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION 4333#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4334 has_width = 0; 4334 has_width = 0;
4335 width = 0; 4335 width = 0;
4336 if (dp->width_start != dp->width_end) 4336 if (dp->width_start != dp->width_end)
4337 { 4337 {
4338 if (dp->width_arg_index != ARG_NONE) 4338 if (dp->width_arg_index != ARG_NONE)
4339 { 4339 {
4340 int arg; 4340 int arg;
4341 4341
4342 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 4342 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
4343 abort (); 4343 abort ();
4344 arg = a.arg[dp->width_arg_index].a.a_int; 4344 arg = a.arg[dp->width_arg_index].a.a_int;
4345 if (arg < 0) 4345 if (arg < 0)
4346 { 4346 {
4347 /* "A negative field width is taken as a '-' flag 4347 /* "A negative field width is taken as a '-' flag
4348 followed by a positive field width." */ 4348 followed by a positive field width." */
4349 flags |= FLAG_LEFT; 4349 flags |= FLAG_LEFT;
4350 width = (unsigned int) (-arg); 4350 width = (unsigned int) (-arg);
4351 } 4351 }
4352 else 4352 else
4353 width = arg; 4353 width = arg;
4354 } 4354 }
4355 else 4355 else
4356 { 4356 {
4357 const FCHAR_T *digitp = dp->width_start; 4357 const FCHAR_T *digitp = dp->width_start;
4358 4358
4359 do 4359 do
4360 width = xsum (xtimes (width, 10), *digitp++ - '0'); 4360 width = xsum (xtimes (width, 10), *digitp++ - '0');
4361 while (digitp != dp->width_end); 4361 while (digitp != dp->width_end);
4362 } 4362 }
4363 has_width = 1; 4363 has_width = 1;
4364 } 4364 }
4365#endif 4365#endif
4366 4366
4367#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION 4367#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
4368 has_precision = 0; 4368 has_precision = 0;
4369 precision = 6; 4369 precision = 6;
4370 if (dp->precision_start != dp->precision_end) 4370 if (dp->precision_start != dp->precision_end)
4371 { 4371 {
4372 if (dp->precision_arg_index != ARG_NONE) 4372 if (dp->precision_arg_index != ARG_NONE)
4373 { 4373 {
4374 int arg; 4374 int arg;
4375 4375
4376 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 4376 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
4377 abort (); 4377 abort ();
4378 arg = a.arg[dp->precision_arg_index].a.a_int; 4378 arg = a.arg[dp->precision_arg_index].a.a_int;
4379 /* "A negative precision is taken as if the precision 4379 /* "A negative precision is taken as if the precision
4380 were omitted." */ 4380 were omitted." */
4381 if (arg >= 0) 4381 if (arg >= 0)
4382 { 4382 {
4383 precision = arg; 4383 precision = arg;
4384 has_precision = 1; 4384 has_precision = 1;
4385 } 4385 }
4386 } 4386 }
4387 else 4387 else
4388 { 4388 {
4389 const FCHAR_T *digitp = dp->precision_start + 1; 4389 const FCHAR_T *digitp = dp->precision_start + 1;
4390 4390
4391 precision = 0; 4391 precision = 0;
4392 while (digitp != dp->precision_end) 4392 while (digitp != dp->precision_end)
4393 precision = xsum (xtimes (precision, 10), *digitp++ - '0'); 4393 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
4394 has_precision = 1; 4394 has_precision = 1;
4395 } 4395 }
4396 } 4396 }
4397#endif 4397#endif
4398 4398
4399 /* Decide whether to handle the precision ourselves. */ 4399 /* Decide whether to handle the precision ourselves. */
4400#if NEED_PRINTF_UNBOUNDED_PRECISION 4400#if NEED_PRINTF_UNBOUNDED_PRECISION
4401 switch (dp->conversion) 4401 switch (dp->conversion)
4402 { 4402 {
4403 case 'd': case 'i': case 'u': 4403 case 'd': case 'i': case 'u':
4404 case 'o': 4404 case 'o':
4405 case 'x': case 'X': case 'p': 4405 case 'x': case 'X': case 'p':
4406 prec_ourselves = has_precision && (precision > 0); 4406 prec_ourselves = has_precision && (precision > 0);
4407 break; 4407 break;
4408 default: 4408 default:
4409 prec_ourselves = 0; 4409 prec_ourselves = 0;
4410 break; 4410 break;
4411 } 4411 }
4412#endif 4412#endif
4413 4413
4414 /* Decide whether to perform the padding ourselves. */ 4414 /* Decide whether to perform the padding ourselves. */
4415#if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION) 4415#if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION)
4416 switch (dp->conversion) 4416 switch (dp->conversion)
4417 { 4417 {
4418# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO 4418# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
4419 /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need 4419 /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need
4420 to perform the padding after this conversion. Functions 4420 to perform the padding after this conversion. Functions
4421 with unistdio extensions perform the padding based on 4421 with unistdio extensions perform the padding based on
4422 character count rather than element count. */ 4422 character count rather than element count. */
4423 case 'c': case 's': 4423 case 'c': case 's':
4424# endif 4424# endif
4425# if NEED_PRINTF_FLAG_ZERO 4425# if NEED_PRINTF_FLAG_ZERO
4426 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': 4426 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
4427 case 'a': case 'A': 4427 case 'a': case 'A':
4428# endif 4428# endif
4429 pad_ourselves = 1; 4429 pad_ourselves = 1;
4430 break; 4430 break;
4431 default: 4431 default:
4432 pad_ourselves = prec_ourselves; 4432 pad_ourselves = prec_ourselves;
4433 break; 4433 break;
4434 } 4434 }
4435#endif 4435#endif
4436 4436
4437#if !USE_SNPRINTF 4437#if !USE_SNPRINTF
4438 /* Allocate a temporary buffer of sufficient size for calling 4438 /* Allocate a temporary buffer of sufficient size for calling
4439 sprintf. */ 4439 sprintf. */
4440 { 4440 {
4441 switch (dp->conversion) 4441 switch (dp->conversion)
4442 { 4442 {
4443 4443
4444 case 'd': case 'i': case 'u': 4444 case 'd': case 'i': case 'u':
4445# if HAVE_LONG_LONG_INT 4445# if HAVE_LONG_LONG_INT
4446 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 4446 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
4447 tmp_length = 4447 tmp_length =
4448 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 4448 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
4449 * 0.30103 /* binary -> decimal */ 4449 * 0.30103 /* binary -> decimal */
4450 ) 4450 )
4451 + 1; /* turn floor into ceil */ 4451 + 1; /* turn floor into ceil */
4452 else 4452 else
4453# endif 4453# endif
4454 if (type == TYPE_LONGINT || type == TYPE_ULONGINT) 4454 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
4455 tmp_length = 4455 tmp_length =
4456 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 4456 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
4457 * 0.30103 /* binary -> decimal */ 4457 * 0.30103 /* binary -> decimal */
4458 ) 4458 )
4459 + 1; /* turn floor into ceil */ 4459 + 1; /* turn floor into ceil */
4460 else 4460 else
4461 tmp_length = 4461 tmp_length =
4462 (unsigned int) (sizeof (unsigned int) * CHAR_BIT 4462 (unsigned int) (sizeof (unsigned int) * CHAR_BIT
4463 * 0.30103 /* binary -> decimal */ 4463 * 0.30103 /* binary -> decimal */
4464 ) 4464 )
4465 + 1; /* turn floor into ceil */ 4465 + 1; /* turn floor into ceil */
4466 if (tmp_length < precision) 4466 if (tmp_length < precision)
4467 tmp_length = precision; 4467 tmp_length = precision;
4468 /* Multiply by 2, as an estimate for FLAG_GROUP. */ 4468 /* Multiply by 2, as an estimate for FLAG_GROUP. */
4469 tmp_length = xsum (tmp_length, tmp_length); 4469 tmp_length = xsum (tmp_length, tmp_length);
4470 /* Add 1, to account for a leading sign. */ 4470 /* Add 1, to account for a leading sign. */
4471 tmp_length = xsum (tmp_length, 1); 4471 tmp_length = xsum (tmp_length, 1);
4472 break; 4472 break;
4473 4473
4474 case 'o': 4474 case 'o':
4475# if HAVE_LONG_LONG_INT 4475# if HAVE_LONG_LONG_INT
4476 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 4476 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
4477 tmp_length = 4477 tmp_length =
4478 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 4478 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
4479 * 0.333334 /* binary -> octal */ 4479 * 0.333334 /* binary -> octal */
4480 ) 4480 )
4481 + 1; /* turn floor into ceil */ 4481 + 1; /* turn floor into ceil */
4482 else 4482 else
4483# endif 4483# endif
4484 if (type == TYPE_LONGINT || type == TYPE_ULONGINT) 4484 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
4485 tmp_length = 4485 tmp_length =
4486 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 4486 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
4487 * 0.333334 /* binary -> octal */ 4487 * 0.333334 /* binary -> octal */
4488 ) 4488 )
4489 + 1; /* turn floor into ceil */ 4489 + 1; /* turn floor into ceil */
4490 else 4490 else
4491 tmp_length = 4491 tmp_length =
4492 (unsigned int) (sizeof (unsigned int) * CHAR_BIT 4492 (unsigned int) (sizeof (unsigned int) * CHAR_BIT
4493 * 0.333334 /* binary -> octal */ 4493 * 0.333334 /* binary -> octal */
4494 ) 4494 )
4495 + 1; /* turn floor into ceil */ 4495 + 1; /* turn floor into ceil */
4496 if (tmp_length < precision) 4496 if (tmp_length < precision)
4497 tmp_length = precision; 4497 tmp_length = precision;
4498 /* Add 1, to account for a leading sign. */ 4498 /* Add 1, to account for a leading sign. */
4499 tmp_length = xsum (tmp_length, 1); 4499 tmp_length = xsum (tmp_length, 1);
4500 break; 4500 break;
4501 4501
4502 case 'x': case 'X': 4502 case 'x': case 'X':
4503# if HAVE_LONG_LONG_INT 4503# if HAVE_LONG_LONG_INT
4504 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 4504 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
4505 tmp_length = 4505 tmp_length =
4506 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 4506 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
4507 * 0.25 /* binary -> hexadecimal */ 4507 * 0.25 /* binary -> hexadecimal */
4508 ) 4508 )
4509 + 1; /* turn floor into ceil */ 4509 + 1; /* turn floor into ceil */
4510 else 4510 else
4511# endif 4511# endif
4512 if (type == TYPE_LONGINT || type == TYPE_ULONGINT) 4512 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
4513 tmp_length = 4513 tmp_length =
4514 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 4514 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
4515 * 0.25 /* binary -> hexadecimal */ 4515 * 0.25 /* binary -> hexadecimal */
4516 ) 4516 )
4517 + 1; /* turn floor into ceil */ 4517 + 1; /* turn floor into ceil */
4518 else 4518 else
4519 tmp_length = 4519 tmp_length =
4520 (unsigned int) (sizeof (unsigned int) * CHAR_BIT 4520 (unsigned int) (sizeof (unsigned int) * CHAR_BIT
4521 * 0.25 /* binary -> hexadecimal */ 4521 * 0.25 /* binary -> hexadecimal */
4522 ) 4522 )
4523 + 1; /* turn floor into ceil */ 4523 + 1; /* turn floor into ceil */
4524 if (tmp_length < precision) 4524 if (tmp_length < precision)
4525 tmp_length = precision; 4525 tmp_length = precision;
4526 /* Add 2, to account for a leading sign or alternate form. */ 4526 /* Add 2, to account for a leading sign or alternate form. */
4527 tmp_length = xsum (tmp_length, 2); 4527 tmp_length = xsum (tmp_length, 2);
4528 break; 4528 break;
4529 4529
4530 case 'f': case 'F': 4530 case 'f': case 'F':
4531 if (type == TYPE_LONGDOUBLE) 4531 if (type == TYPE_LONGDOUBLE)
4532 tmp_length = 4532 tmp_length =
4533 (unsigned int) (LDBL_MAX_EXP 4533 (unsigned int) (LDBL_MAX_EXP
4534 * 0.30103 /* binary -> decimal */ 4534 * 0.30103 /* binary -> decimal */
4535 * 2 /* estimate for FLAG_GROUP */ 4535 * 2 /* estimate for FLAG_GROUP */
4536 ) 4536 )
4537 + 1 /* turn floor into ceil */ 4537 + 1 /* turn floor into ceil */
4538 + 10; /* sign, decimal point etc. */ 4538 + 10; /* sign, decimal point etc. */
4539 else 4539 else
4540 tmp_length = 4540 tmp_length =
4541 (unsigned int) (DBL_MAX_EXP 4541 (unsigned int) (DBL_MAX_EXP
4542 * 0.30103 /* binary -> decimal */ 4542 * 0.30103 /* binary -> decimal */
4543 * 2 /* estimate for FLAG_GROUP */ 4543 * 2 /* estimate for FLAG_GROUP */
4544 ) 4544 )
4545 + 1 /* turn floor into ceil */ 4545 + 1 /* turn floor into ceil */
4546 + 10; /* sign, decimal point etc. */ 4546 + 10; /* sign, decimal point etc. */
4547 tmp_length = xsum (tmp_length, precision); 4547 tmp_length = xsum (tmp_length, precision);
4548 break; 4548 break;
4549 4549
4550 case 'e': case 'E': case 'g': case 'G': 4550 case 'e': case 'E': case 'g': case 'G':
4551 tmp_length = 4551 tmp_length =
4552 12; /* sign, decimal point, exponent etc. */ 4552 12; /* sign, decimal point, exponent etc. */
4553 tmp_length = xsum (tmp_length, precision); 4553 tmp_length = xsum (tmp_length, precision);
4554 break; 4554 break;
4555 4555
4556 case 'a': case 'A': 4556 case 'a': case 'A':
4557 if (type == TYPE_LONGDOUBLE) 4557 if (type == TYPE_LONGDOUBLE)
4558 tmp_length = 4558 tmp_length =
4559 (unsigned int) (LDBL_DIG 4559 (unsigned int) (LDBL_DIG
4560 * 0.831 /* decimal -> hexadecimal */ 4560 * 0.831 /* decimal -> hexadecimal */
4561 ) 4561 )
4562 + 1; /* turn floor into ceil */ 4562 + 1; /* turn floor into ceil */
4563 else 4563 else
4564 tmp_length = 4564 tmp_length =
4565 (unsigned int) (DBL_DIG 4565 (unsigned int) (DBL_DIG
4566 * 0.831 /* decimal -> hexadecimal */ 4566 * 0.831 /* decimal -> hexadecimal */
4567 ) 4567 )
4568 + 1; /* turn floor into ceil */ 4568 + 1; /* turn floor into ceil */
4569 if (tmp_length < precision) 4569 if (tmp_length < precision)
4570 tmp_length = precision; 4570 tmp_length = precision;
4571 /* Account for sign, decimal point etc. */ 4571 /* Account for sign, decimal point etc. */
4572 tmp_length = xsum (tmp_length, 12); 4572 tmp_length = xsum (tmp_length, 12);
4573 break; 4573 break;
4574 4574
4575 case 'c': 4575 case 'c':
4576# if HAVE_WINT_T && !WIDE_CHAR_VERSION 4576# if HAVE_WINT_T && !WIDE_CHAR_VERSION
4577 if (type == TYPE_WIDE_CHAR) 4577 if (type == TYPE_WIDE_CHAR)
4578 tmp_length = MB_CUR_MAX; 4578 tmp_length = MB_CUR_MAX;
4579 else 4579 else
4580# endif 4580# endif
4581 tmp_length = 1; 4581 tmp_length = 1;
4582 break; 4582 break;
4583 4583
4584 case 's': 4584 case 's':
4585# if HAVE_WCHAR_T 4585# if HAVE_WCHAR_T
4586 if (type == TYPE_WIDE_STRING) 4586 if (type == TYPE_WIDE_STRING)
4587 { 4587 {
4588# if WIDE_CHAR_VERSION 4588# if WIDE_CHAR_VERSION
4589 /* ISO C says about %ls in fwprintf: 4589 /* ISO C says about %ls in fwprintf:
4590 "If the precision is not specified or is greater 4590 "If the precision is not specified or is greater
4591 than the size of the array, the array shall 4591 than the size of the array, the array shall
4592 contain a null wide character." 4592 contain a null wide character."
4593 So if there is a precision, we must not use 4593 So if there is a precision, we must not use
4594 wcslen. */ 4594 wcslen. */
4595 const wchar_t *arg = 4595 const wchar_t *arg =
4596 a.arg[dp->arg_index].a.a_wide_string; 4596 a.arg[dp->arg_index].a.a_wide_string;
4597 4597
4598 if (has_precision) 4598 if (has_precision)
4599 tmp_length = local_wcsnlen (arg, precision); 4599 tmp_length = local_wcsnlen (arg, precision);
4600 else 4600 else
4601 tmp_length = local_wcslen (arg); 4601 tmp_length = local_wcslen (arg);
4602# else 4602# else
4603 /* ISO C says about %ls in fprintf: 4603 /* ISO C says about %ls in fprintf:
4604 "If a precision is specified, no more than that 4604 "If a precision is specified, no more than that
4605 many bytes are written (including shift 4605 many bytes are written (including shift
4606 sequences, if any), and the array shall contain 4606 sequences, if any), and the array shall contain
4607 a null wide character if, to equal the 4607 a null wide character if, to equal the
4608 multibyte character sequence length given by 4608 multibyte character sequence length given by
4609 the precision, the function would need to 4609 the precision, the function would need to
4610 access a wide character one past the end of the 4610 access a wide character one past the end of the
4611 array." 4611 array."
4612 So if there is a precision, we must not use 4612 So if there is a precision, we must not use
4613 wcslen. */ 4613 wcslen. */
4614 /* This case has already been handled above. */ 4614 /* This case has already been handled above. */
4615 abort (); 4615 abort ();
4616# endif 4616# endif
4617 } 4617 }
4618 else 4618 else
4619# endif 4619# endif
4620 { 4620 {
4621# if WIDE_CHAR_VERSION 4621# if WIDE_CHAR_VERSION
4622 /* ISO C says about %s in fwprintf: 4622 /* ISO C says about %s in fwprintf:
4623 "If the precision is not specified or is greater 4623 "If the precision is not specified or is greater
4624 than the size of the converted array, the 4624 than the size of the converted array, the
4625 converted array shall contain a null wide 4625 converted array shall contain a null wide
4626 character." 4626 character."
4627 So if there is a precision, we must not use 4627 So if there is a precision, we must not use
4628 strlen. */ 4628 strlen. */
4629 /* This case has already been handled above. */ 4629 /* This case has already been handled above. */
4630 abort (); 4630 abort ();
4631# else 4631# else
4632 /* ISO C says about %s in fprintf: 4632 /* ISO C says about %s in fprintf:
4633 "If the precision is not specified or greater 4633 "If the precision is not specified or greater
4634 than the size of the array, the array shall 4634 than the size of the array, the array shall
4635 contain a null character." 4635 contain a null character."
4636 So if there is a precision, we must not use 4636 So if there is a precision, we must not use
4637 strlen. */ 4637 strlen. */
4638 const char *arg = a.arg[dp->arg_index].a.a_string; 4638 const char *arg = a.arg[dp->arg_index].a.a_string;
4639 4639
4640 if (has_precision) 4640 if (has_precision)
4641 tmp_length = local_strnlen (arg, precision); 4641 tmp_length = local_strnlen (arg, precision);
4642 else 4642 else
4643 tmp_length = strlen (arg); 4643 tmp_length = strlen (arg);
4644# endif 4644# endif
4645 } 4645 }
4646 break; 4646 break;
4647 4647
4648 case 'p': 4648 case 'p':
4649 tmp_length = 4649 tmp_length =
4650 (unsigned int) (sizeof (void *) * CHAR_BIT 4650 (unsigned int) (sizeof (void *) * CHAR_BIT
4651 * 0.25 /* binary -> hexadecimal */ 4651 * 0.25 /* binary -> hexadecimal */
4652 ) 4652 )
4653 + 1 /* turn floor into ceil */ 4653 + 1 /* turn floor into ceil */
4654 + 2; /* account for leading 0x */ 4654 + 2; /* account for leading 0x */
4655 break; 4655 break;
4656 4656
4657 default: 4657 default:
4658 abort (); 4658 abort ();
4659 } 4659 }
4660 4660
4661 if (!pad_ourselves) 4661 if (!pad_ourselves)
4662 { 4662 {
4663# if ENABLE_UNISTDIO 4663# if ENABLE_UNISTDIO
4664 /* Padding considers the number of characters, therefore 4664 /* Padding considers the number of characters, therefore
4665 the number of elements after padding may be 4665 the number of elements after padding may be
4666 > max (tmp_length, width) 4666 > max (tmp_length, width)
4667 but is certainly 4667 but is certainly
4668 <= tmp_length + width. */ 4668 <= tmp_length + width. */
4669 tmp_length = xsum (tmp_length, width); 4669 tmp_length = xsum (tmp_length, width);
4670# else 4670# else
4671 /* Padding considers the number of elements, 4671 /* Padding considers the number of elements,
4672 says POSIX. */ 4672 says POSIX. */
4673 if (tmp_length < width) 4673 if (tmp_length < width)
4674 tmp_length = width; 4674 tmp_length = width;
4675# endif 4675# endif
4676 } 4676 }
4677 4677
4678 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ 4678 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
4679 } 4679 }
4680 4680
4681 if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) 4681 if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T))
4682 tmp = tmpbuf; 4682 tmp = tmpbuf;
4683 else 4683 else
4684 { 4684 {
4685 size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); 4685 size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T));
4686 4686
4687 if (size_overflow_p (tmp_memsize)) 4687 if (size_overflow_p (tmp_memsize))
4688 /* Overflow, would lead to out of memory. */ 4688 /* Overflow, would lead to out of memory. */
4689 goto out_of_memory; 4689 goto out_of_memory;
4690 tmp = (TCHAR_T *) malloc (tmp_memsize); 4690 tmp = (TCHAR_T *) malloc (tmp_memsize);
4691 if (tmp == NULL) 4691 if (tmp == NULL)
4692 /* Out of memory. */ 4692 /* Out of memory. */
4693 goto out_of_memory; 4693 goto out_of_memory;
4694 } 4694 }
4695#endif 4695#endif
4696 4696
4697 /* Construct the format string for calling snprintf or 4697 /* Construct the format string for calling snprintf or
4698 sprintf. */ 4698 sprintf. */
4699 fbp = buf; 4699 fbp = buf;
4700 *fbp++ = '%'; 4700 *fbp++ = '%';
4701#if NEED_PRINTF_FLAG_GROUPING 4701#if NEED_PRINTF_FLAG_GROUPING
4702 /* The underlying implementation doesn't support the ' flag. 4702 /* The underlying implementation doesn't support the ' flag.
4703 Produce no grouping characters in this case; this is 4703 Produce no grouping characters in this case; this is
4704 acceptable because the grouping is locale dependent. */ 4704 acceptable because the grouping is locale dependent. */
4705#else 4705#else
4706 if (flags & FLAG_GROUP) 4706 if (flags & FLAG_GROUP)
4707 *fbp++ = '\''; 4707 *fbp++ = '\'';
4708#endif 4708#endif
4709 if (flags & FLAG_LEFT) 4709 if (flags & FLAG_LEFT)
4710 *fbp++ = '-'; 4710 *fbp++ = '-';
4711 if (flags & FLAG_SHOWSIGN) 4711 if (flags & FLAG_SHOWSIGN)
4712 *fbp++ = '+'; 4712 *fbp++ = '+';
4713 if (flags & FLAG_SPACE) 4713 if (flags & FLAG_SPACE)
4714 *fbp++ = ' '; 4714 *fbp++ = ' ';
4715 if (flags & FLAG_ALT) 4715 if (flags & FLAG_ALT)
4716 *fbp++ = '#'; 4716 *fbp++ = '#';
4717 if (!pad_ourselves) 4717 if (!pad_ourselves)
4718 { 4718 {
4719 if (flags & FLAG_ZERO) 4719 if (flags & FLAG_ZERO)
4720 *fbp++ = '0'; 4720 *fbp++ = '0';
4721 if (dp->width_start != dp->width_end) 4721 if (dp->width_start != dp->width_end)
4722 { 4722 {
4723 size_t n = dp->width_end - dp->width_start; 4723 size_t n = dp->width_end - dp->width_start;
4724 /* The width specification is known to consist only 4724 /* The width specification is known to consist only
4725 of standard ASCII characters. */ 4725 of standard ASCII characters. */
4726 if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) 4726 if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
4727 { 4727 {
4728 memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); 4728 memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T));
4729 fbp += n; 4729 fbp += n;
4730 } 4730 }
4731 else 4731 else
4732 { 4732 {
4733 const FCHAR_T *mp = dp->width_start; 4733 const FCHAR_T *mp = dp->width_start;
4734 do 4734 do
4735 *fbp++ = (unsigned char) *mp++; 4735 *fbp++ = (unsigned char) *mp++;
4736 while (--n > 0); 4736 while (--n > 0);
4737 } 4737 }
4738 } 4738 }
4739 } 4739 }
4740 if (!prec_ourselves) 4740 if (!prec_ourselves)
4741 { 4741 {
4742 if (dp->precision_start != dp->precision_end) 4742 if (dp->precision_start != dp->precision_end)
4743 { 4743 {
4744 size_t n = dp->precision_end - dp->precision_start; 4744 size_t n = dp->precision_end - dp->precision_start;
4745 /* The precision specification is known to consist only 4745 /* The precision specification is known to consist only
4746 of standard ASCII characters. */ 4746 of standard ASCII characters. */
4747 if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) 4747 if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
4748 { 4748 {
4749 memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); 4749 memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T));
4750 fbp += n; 4750 fbp += n;
4751 } 4751 }
4752 else 4752 else
4753 { 4753 {
4754 const FCHAR_T *mp = dp->precision_start; 4754 const FCHAR_T *mp = dp->precision_start;
4755 do 4755 do
4756 *fbp++ = (unsigned char) *mp++; 4756 *fbp++ = (unsigned char) *mp++;
4757 while (--n > 0); 4757 while (--n > 0);
4758 } 4758 }
4759 } 4759 }
4760 } 4760 }
4761 4761
4762 switch (type) 4762 switch (type)
4763 { 4763 {
4764#if HAVE_LONG_LONG_INT 4764#if HAVE_LONG_LONG_INT
4765 case TYPE_LONGLONGINT: 4765 case TYPE_LONGLONGINT:
4766 case TYPE_ULONGLONGINT: 4766 case TYPE_ULONGLONGINT:
4767# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4767# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
4768 *fbp++ = 'I'; 4768 *fbp++ = 'I';
4769 *fbp++ = '6'; 4769 *fbp++ = '6';
4770 *fbp++ = '4'; 4770 *fbp++ = '4';
4771 break; 4771 break;
4772# else 4772# else
4773 *fbp++ = 'l'; 4773 *fbp++ = 'l';
4774 /*FALLTHROUGH*/ 4774 /*FALLTHROUGH*/
4775# endif 4775# endif
4776#endif 4776#endif
4777 case TYPE_LONGINT: 4777 case TYPE_LONGINT:
4778 case TYPE_ULONGINT: 4778 case TYPE_ULONGINT:
4779#if HAVE_WINT_T 4779#if HAVE_WINT_T
4780 case TYPE_WIDE_CHAR: 4780 case TYPE_WIDE_CHAR:
4781#endif 4781#endif
4782#if HAVE_WCHAR_T 4782#if HAVE_WCHAR_T
4783 case TYPE_WIDE_STRING: 4783 case TYPE_WIDE_STRING:
4784#endif 4784#endif
4785 *fbp++ = 'l'; 4785 *fbp++ = 'l';
4786 break; 4786 break;
4787 case TYPE_LONGDOUBLE: 4787 case TYPE_LONGDOUBLE:
4788 *fbp++ = 'L'; 4788 *fbp++ = 'L';
4789 break; 4789 break;
4790 default: 4790 default:
4791 break; 4791 break;
4792 } 4792 }
4793#if NEED_PRINTF_DIRECTIVE_F 4793#if NEED_PRINTF_DIRECTIVE_F
4794 if (dp->conversion == 'F') 4794 if (dp->conversion == 'F')
4795 *fbp = 'f'; 4795 *fbp = 'f';
4796 else 4796 else
4797#endif 4797#endif
4798 *fbp = dp->conversion; 4798 *fbp = dp->conversion;
4799#if USE_SNPRINTF 4799#if USE_SNPRINTF
4800# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) 4800# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
4801 fbp[1] = '%'; 4801 fbp[1] = '%';
4802 fbp[2] = 'n'; 4802 fbp[2] = 'n';
4803 fbp[3] = '\0'; 4803 fbp[3] = '\0';
4804# else 4804# else
4805 /* On glibc2 systems from glibc >= 2.3 - probably also older 4805 /* On glibc2 systems from glibc >= 2.3 - probably also older
4806 ones - we know that snprintf's returns value conforms to 4806 ones - we know that snprintf's returns value conforms to
4807 ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. 4807 ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes.
4808 Therefore we can avoid using %n in this situation. 4808 Therefore we can avoid using %n in this situation.
4809 On glibc2 systems from 2004-10-18 or newer, the use of %n 4809 On glibc2 systems from 2004-10-18 or newer, the use of %n
4810 in format strings in writable memory may crash the program 4810 in format strings in writable memory may crash the program
4811 (if compiled with _FORTIFY_SOURCE=2), so we should avoid it 4811 (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
4812 in this situation. */ 4812 in this situation. */
4813 /* On native Win32 systems (such as mingw), we can avoid using 4813 /* On native Win32 systems (such as mingw), we can avoid using
4814 %n because: 4814 %n because:
4815 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, 4815 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
4816 snprintf does not write more than the specified number 4816 snprintf does not write more than the specified number
4817 of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes 4817 of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes
4818 '4', '5', '6' into buf, not '4', '5', '\0'.) 4818 '4', '5', '6' into buf, not '4', '5', '\0'.)
4819 - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf 4819 - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf
4820 allows us to recognize the case of an insufficient 4820 allows us to recognize the case of an insufficient
4821 buffer size: it returns -1 in this case. 4821 buffer size: it returns -1 in this case.
4822 On native Win32 systems (such as mingw) where the OS is 4822 On native Win32 systems (such as mingw) where the OS is
4823 Windows Vista, the use of %n in format strings by default 4823 Windows Vista, the use of %n in format strings by default
4824 crashes the program. See 4824 crashes the program. See
4825 <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and 4825 <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
4826 <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx> 4826 <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx>
4827 So we should avoid %n in this situation. */ 4827 So we should avoid %n in this situation. */
4828 fbp[1] = '\0'; 4828 fbp[1] = '\0';
4829# endif 4829# endif
4830#else 4830#else
4831 fbp[1] = '\0'; 4831 fbp[1] = '\0';
4832#endif 4832#endif
4833 4833
4834 /* Construct the arguments for calling snprintf or sprintf. */ 4834 /* Construct the arguments for calling snprintf or sprintf. */
4835 prefix_count = 0; 4835 prefix_count = 0;
4836 if (!pad_ourselves && dp->width_arg_index != ARG_NONE) 4836 if (!pad_ourselves && dp->width_arg_index != ARG_NONE)
4837 { 4837 {
4838 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 4838 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
4839 abort (); 4839 abort ();
4840 prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; 4840 prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int;
4841 } 4841 }
4842 if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) 4842 if (!prec_ourselves && dp->precision_arg_index != ARG_NONE)
4843 { 4843 {
4844 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 4844 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
4845 abort (); 4845 abort ();
4846 prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; 4846 prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int;
4847 } 4847 }
4848 4848
4849#if USE_SNPRINTF 4849#if USE_SNPRINTF
4850 /* The SNPRINTF result is appended after result[0..length]. 4850 /* The SNPRINTF result is appended after result[0..length].
4851 The latter is an array of DCHAR_T; SNPRINTF appends an 4851 The latter is an array of DCHAR_T; SNPRINTF appends an
4852 array of TCHAR_T to it. This is possible because 4852 array of TCHAR_T to it. This is possible because
4853 sizeof (TCHAR_T) divides sizeof (DCHAR_T) and 4853 sizeof (TCHAR_T) divides sizeof (DCHAR_T) and
4854 alignof (TCHAR_T) <= alignof (DCHAR_T). */ 4854 alignof (TCHAR_T) <= alignof (DCHAR_T). */
4855# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) 4855# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T))
4856 /* Ensure that maxlen below will be >= 2. Needed on BeOS, 4856 /* Ensure that maxlen below will be >= 2. Needed on BeOS,
4857 where an snprintf() with maxlen==1 acts like sprintf(). */ 4857 where an snprintf() with maxlen==1 acts like sprintf(). */
4858 ENSURE_ALLOCATION (xsum (length, 4858 ENSURE_ALLOCATION (xsum (length,
4859 (2 + TCHARS_PER_DCHAR - 1) 4859 (2 + TCHARS_PER_DCHAR - 1)
4860 / TCHARS_PER_DCHAR)); 4860 / TCHARS_PER_DCHAR));
4861 /* Prepare checking whether snprintf returns the count 4861 /* Prepare checking whether snprintf returns the count
4862 via %n. */ 4862 via %n. */
4863 *(TCHAR_T *) (result + length) = '\0'; 4863 *(TCHAR_T *) (result + length) = '\0';
4864#endif 4864#endif
4865 4865
4866 for (;;) 4866 for (;;)
4867 { 4867 {
4868 int count = -1; 4868 int count = -1;
4869 4869
4870#if USE_SNPRINTF 4870#if USE_SNPRINTF
4871 int retcount = 0; 4871 int retcount = 0;
4872 size_t maxlen = allocated - length; 4872 size_t maxlen = allocated - length;
4873 /* SNPRINTF can fail if its second argument is 4873 /* SNPRINTF can fail if its second argument is
4874 > INT_MAX. */ 4874 > INT_MAX. */
4875 if (maxlen > INT_MAX / TCHARS_PER_DCHAR) 4875 if (maxlen > INT_MAX / TCHARS_PER_DCHAR)
4876 maxlen = INT_MAX / TCHARS_PER_DCHAR; 4876 maxlen = INT_MAX / TCHARS_PER_DCHAR;
4877 maxlen = maxlen * TCHARS_PER_DCHAR; 4877 maxlen = maxlen * TCHARS_PER_DCHAR;
4878# define SNPRINTF_BUF(arg) \ 4878# define SNPRINTF_BUF(arg) \
4879 switch (prefix_count) \ 4879 switch (prefix_count) \
4880 { \ 4880 { \
4881 case 0: \ 4881 case 0: \
4882 retcount = SNPRINTF ((TCHAR_T *) (result + length), \ 4882 retcount = SNPRINTF ((TCHAR_T *) (result + length), \
4883 maxlen, buf, \ 4883 maxlen, buf, \
4884 arg, &count); \ 4884 arg, &count); \
4885 break; \ 4885 break; \
4886 case 1: \ 4886 case 1: \
4887 retcount = SNPRINTF ((TCHAR_T *) (result + length), \ 4887 retcount = SNPRINTF ((TCHAR_T *) (result + length), \
4888 maxlen, buf, \ 4888 maxlen, buf, \
4889 prefixes[0], arg, &count); \ 4889 prefixes[0], arg, &count); \
4890 break; \ 4890 break; \
4891 case 2: \ 4891 case 2: \
4892 retcount = SNPRINTF ((TCHAR_T *) (result + length), \ 4892 retcount = SNPRINTF ((TCHAR_T *) (result + length), \
4893 maxlen, buf, \ 4893 maxlen, buf, \
4894 prefixes[0], prefixes[1], arg, \ 4894 prefixes[0], prefixes[1], arg, \
4895 &count); \ 4895 &count); \
4896 break; \ 4896 break; \
4897 default: \ 4897 default: \
4898 abort (); \ 4898 abort (); \
4899 } 4899 }
4900#else 4900#else
4901# define SNPRINTF_BUF(arg) \ 4901# define SNPRINTF_BUF(arg) \
4902 switch (prefix_count) \ 4902 switch (prefix_count) \
4903 { \ 4903 { \
4904 case 0: \ 4904 case 0: \
4905 count = sprintf (tmp, buf, arg); \ 4905 count = sprintf (tmp, buf, arg); \
4906 break; \ 4906 break; \
4907 case 1: \ 4907 case 1: \
4908 count = sprintf (tmp, buf, prefixes[0], arg); \ 4908 count = sprintf (tmp, buf, prefixes[0], arg); \
4909 break; \ 4909 break; \
4910 case 2: \ 4910 case 2: \
4911 count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ 4911 count = sprintf (tmp, buf, prefixes[0], prefixes[1],\
4912 arg); \ 4912 arg); \
4913 break; \ 4913 break; \
4914 default: \ 4914 default: \
4915 abort (); \ 4915 abort (); \
4916 } 4916 }
4917#endif 4917#endif
4918 4918
4919 switch (type) 4919 switch (type)
4920 { 4920 {
4921 case TYPE_SCHAR: 4921 case TYPE_SCHAR:
4922 { 4922 {
4923 int arg = a.arg[dp->arg_index].a.a_schar; 4923 int arg = a.arg[dp->arg_index].a.a_schar;
4924 SNPRINTF_BUF (arg); 4924 SNPRINTF_BUF (arg);
4925 } 4925 }
4926 break; 4926 break;
4927 case TYPE_UCHAR: 4927 case TYPE_UCHAR:
4928 { 4928 {
4929 unsigned int arg = a.arg[dp->arg_index].a.a_uchar; 4929 unsigned int arg = a.arg[dp->arg_index].a.a_uchar;
4930 SNPRINTF_BUF (arg); 4930 SNPRINTF_BUF (arg);
4931 } 4931 }
4932 break; 4932 break;
4933 case TYPE_SHORT: 4933 case TYPE_SHORT:
4934 { 4934 {
4935 int arg = a.arg[dp->arg_index].a.a_short; 4935 int arg = a.arg[dp->arg_index].a.a_short;
4936 SNPRINTF_BUF (arg); 4936 SNPRINTF_BUF (arg);
4937 } 4937 }
4938 break; 4938 break;
4939 case TYPE_USHORT: 4939 case TYPE_USHORT:
4940 { 4940 {
4941 unsigned int arg = a.arg[dp->arg_index].a.a_ushort; 4941 unsigned int arg = a.arg[dp->arg_index].a.a_ushort;
4942 SNPRINTF_BUF (arg); 4942 SNPRINTF_BUF (arg);
4943 } 4943 }
4944 break; 4944 break;
4945 case TYPE_INT: 4945 case TYPE_INT:
4946 { 4946 {
4947 int arg = a.arg[dp->arg_index].a.a_int; 4947 int arg = a.arg[dp->arg_index].a.a_int;
4948 SNPRINTF_BUF (arg); 4948 SNPRINTF_BUF (arg);
4949 } 4949 }
4950 break; 4950 break;
4951 case TYPE_UINT: 4951 case TYPE_UINT:
4952 { 4952 {
4953 unsigned int arg = a.arg[dp->arg_index].a.a_uint; 4953 unsigned int arg = a.arg[dp->arg_index].a.a_uint;
4954 SNPRINTF_BUF (arg); 4954 SNPRINTF_BUF (arg);
4955 } 4955 }
4956 break; 4956 break;
4957 case TYPE_LONGINT: 4957 case TYPE_LONGINT:
4958 { 4958 {
4959 long int arg = a.arg[dp->arg_index].a.a_longint; 4959 long int arg = a.arg[dp->arg_index].a.a_longint;
4960 SNPRINTF_BUF (arg); 4960 SNPRINTF_BUF (arg);
4961 } 4961 }
4962 break; 4962 break;
4963 case TYPE_ULONGINT: 4963 case TYPE_ULONGINT:
4964 { 4964 {
4965 unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; 4965 unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint;
4966 SNPRINTF_BUF (arg); 4966 SNPRINTF_BUF (arg);
4967 } 4967 }
4968 break; 4968 break;
4969#if HAVE_LONG_LONG_INT 4969#if HAVE_LONG_LONG_INT
4970 case TYPE_LONGLONGINT: 4970 case TYPE_LONGLONGINT:
4971 { 4971 {
4972 long long int arg = a.arg[dp->arg_index].a.a_longlongint; 4972 long long int arg = a.arg[dp->arg_index].a.a_longlongint;
4973 SNPRINTF_BUF (arg); 4973 SNPRINTF_BUF (arg);
4974 } 4974 }
4975 break; 4975 break;
4976 case TYPE_ULONGLONGINT: 4976 case TYPE_ULONGLONGINT:
4977 { 4977 {
4978 unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; 4978 unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint;
4979 SNPRINTF_BUF (arg); 4979 SNPRINTF_BUF (arg);
4980 } 4980 }
4981 break; 4981 break;
4982#endif 4982#endif
4983 case TYPE_DOUBLE: 4983 case TYPE_DOUBLE:
4984 { 4984 {
4985 double arg = a.arg[dp->arg_index].a.a_double; 4985 double arg = a.arg[dp->arg_index].a.a_double;
4986 SNPRINTF_BUF (arg); 4986 SNPRINTF_BUF (arg);
4987 } 4987 }
4988 break; 4988 break;
4989 case TYPE_LONGDOUBLE: 4989 case TYPE_LONGDOUBLE:
4990 { 4990 {
4991 long double arg = a.arg[dp->arg_index].a.a_longdouble; 4991 long double arg = a.arg[dp->arg_index].a.a_longdouble;
4992 SNPRINTF_BUF (arg); 4992 SNPRINTF_BUF (arg);
4993 } 4993 }
4994 break; 4994 break;
4995 case TYPE_CHAR: 4995 case TYPE_CHAR:
4996 { 4996 {
4997 int arg = a.arg[dp->arg_index].a.a_char; 4997 int arg = a.arg[dp->arg_index].a.a_char;
4998 SNPRINTF_BUF (arg); 4998 SNPRINTF_BUF (arg);
4999 } 4999 }
5000 break; 5000 break;
5001#if HAVE_WINT_T 5001#if HAVE_WINT_T
5002 case TYPE_WIDE_CHAR: 5002 case TYPE_WIDE_CHAR:
5003 { 5003 {
5004 wint_t arg = a.arg[dp->arg_index].a.a_wide_char; 5004 wint_t arg = a.arg[dp->arg_index].a.a_wide_char;
5005 SNPRINTF_BUF (arg); 5005 SNPRINTF_BUF (arg);
5006 } 5006 }
5007 break; 5007 break;
5008#endif 5008#endif
5009 case TYPE_STRING: 5009 case TYPE_STRING:
5010 { 5010 {
5011 const char *arg = a.arg[dp->arg_index].a.a_string; 5011 const char *arg = a.arg[dp->arg_index].a.a_string;
5012 SNPRINTF_BUF (arg); 5012 SNPRINTF_BUF (arg);
5013 } 5013 }
5014 break; 5014 break;
5015#if HAVE_WCHAR_T 5015#if HAVE_WCHAR_T
5016 case TYPE_WIDE_STRING: 5016 case TYPE_WIDE_STRING:
5017 { 5017 {
5018 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; 5018 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
5019 SNPRINTF_BUF (arg); 5019 SNPRINTF_BUF (arg);
5020 } 5020 }
5021 break; 5021 break;
5022#endif 5022#endif
5023 case TYPE_POINTER: 5023 case TYPE_POINTER:
5024 { 5024 {
5025 void *arg = a.arg[dp->arg_index].a.a_pointer; 5025 void *arg = a.arg[dp->arg_index].a.a_pointer;
5026 SNPRINTF_BUF (arg); 5026 SNPRINTF_BUF (arg);
5027 } 5027 }
5028 break; 5028 break;
5029 default: 5029 default:
5030 abort (); 5030 abort ();
5031 } 5031 }
5032 5032
5033#if USE_SNPRINTF 5033#if USE_SNPRINTF
5034 /* Portability: Not all implementations of snprintf() 5034 /* Portability: Not all implementations of snprintf()
5035 are ISO C 99 compliant. Determine the number of 5035 are ISO C 99 compliant. Determine the number of
5036 bytes that snprintf() has produced or would have 5036 bytes that snprintf() has produced or would have
5037 produced. */ 5037 produced. */
5038 if (count >= 0) 5038 if (count >= 0)
5039 { 5039 {
5040 /* Verify that snprintf() has NUL-terminated its 5040 /* Verify that snprintf() has NUL-terminated its
5041 result. */ 5041 result. */
5042 if (count < maxlen 5042 if (count < maxlen
5043 && ((TCHAR_T *) (result + length)) [count] != '\0') 5043 && ((TCHAR_T *) (result + length)) [count] != '\0')
5044 abort (); 5044 abort ();
5045 /* Portability hack. */ 5045 /* Portability hack. */
5046 if (retcount > count) 5046 if (retcount > count)
5047 count = retcount; 5047 count = retcount;
5048 } 5048 }
5049 else 5049 else
5050 { 5050 {
5051 /* snprintf() doesn't understand the '%n' 5051 /* snprintf() doesn't understand the '%n'
5052 directive. */ 5052 directive. */
5053 if (fbp[1] != '\0') 5053 if (fbp[1] != '\0')
5054 { 5054 {
5055 /* Don't use the '%n' directive; instead, look 5055 /* Don't use the '%n' directive; instead, look
5056 at the snprintf() return value. */ 5056 at the snprintf() return value. */
5057 fbp[1] = '\0'; 5057 fbp[1] = '\0';
5058 continue; 5058 continue;
5059 } 5059 }
5060 else 5060 else
5061 { 5061 {
5062 /* Look at the snprintf() return value. */ 5062 /* Look at the snprintf() return value. */
5063 if (retcount < 0) 5063 if (retcount < 0)
5064 { 5064 {
5065 /* HP-UX 10.20 snprintf() is doubly deficient: 5065 /* HP-UX 10.20 snprintf() is doubly deficient:
5066 It doesn't understand the '%n' directive, 5066 It doesn't understand the '%n' directive,
5067 *and* it returns -1 (rather than the length 5067 *and* it returns -1 (rather than the length
5068 that would have been required) when the 5068 that would have been required) when the
5069 buffer is too small. */ 5069 buffer is too small. */
5070 size_t bigger_need = 5070 size_t bigger_need =
5071 xsum (xtimes (allocated, 2), 12); 5071 xsum (xtimes (allocated, 2), 12);
5072 ENSURE_ALLOCATION (bigger_need); 5072 ENSURE_ALLOCATION (bigger_need);
5073 continue; 5073 continue;
5074 } 5074 }
5075 else 5075 else
5076 count = retcount; 5076 count = retcount;
5077 } 5077 }
5078 } 5078 }
5079#endif 5079#endif
5080 5080
5081 /* Attempt to handle failure. */ 5081 /* Attempt to handle failure. */
5082 if (count < 0) 5082 if (count < 0)
5083 { 5083 {
5084 if (!(result == resultbuf || result == NULL)) 5084 if (!(result == resultbuf || result == NULL))
5085 free (result); 5085 free (result);
5086 if (buf_malloced != NULL) 5086 if (buf_malloced != NULL)
5087 free (buf_malloced); 5087 free (buf_malloced);
5088 CLEANUP (); 5088 CLEANUP ();
5089 errno = EINVAL; 5089 errno = EINVAL;
5090 return NULL; 5090 return NULL;
5091 } 5091 }
5092 5092
5093#if USE_SNPRINTF 5093#if USE_SNPRINTF
5094 /* Handle overflow of the allocated buffer. 5094 /* Handle overflow of the allocated buffer.
5095 If such an overflow occurs, a C99 compliant snprintf() 5095 If such an overflow occurs, a C99 compliant snprintf()
5096 returns a count >= maxlen. However, a non-compliant 5096 returns a count >= maxlen. However, a non-compliant
5097 snprintf() function returns only count = maxlen - 1. To 5097 snprintf() function returns only count = maxlen - 1. To
5098 cover both cases, test whether count >= maxlen - 1. */ 5098 cover both cases, test whether count >= maxlen - 1. */
5099 if ((unsigned int) count + 1 >= maxlen) 5099 if ((unsigned int) count + 1 >= maxlen)
5100 { 5100 {
5101 /* If maxlen already has attained its allowed maximum, 5101 /* If maxlen already has attained its allowed maximum,
5102 allocating more memory will not increase maxlen. 5102 allocating more memory will not increase maxlen.
5103 Instead of looping, bail out. */ 5103 Instead of looping, bail out. */
5104 if (maxlen == INT_MAX / TCHARS_PER_DCHAR) 5104 if (maxlen == INT_MAX / TCHARS_PER_DCHAR)
5105 goto overflow; 5105 goto overflow;
5106 else 5106 else
5107 { 5107 {
5108 /* Need at least (count + 1) * sizeof (TCHAR_T) 5108 /* Need at least (count + 1) * sizeof (TCHAR_T)
5109 bytes. (The +1 is for the trailing NUL.) 5109 bytes. (The +1 is for the trailing NUL.)
5110 But ask for (count + 2) * sizeof (TCHAR_T) 5110 But ask for (count + 2) * sizeof (TCHAR_T)
5111 bytes, so that in the next round, we likely get 5111 bytes, so that in the next round, we likely get
5112 maxlen > (unsigned int) count + 1 5112 maxlen > (unsigned int) count + 1
5113 and so we don't get here again. 5113 and so we don't get here again.
5114 And allocate proportionally, to avoid looping 5114 And allocate proportionally, to avoid looping
5115 eternally if snprintf() reports a too small 5115 eternally if snprintf() reports a too small
5116 count. */ 5116 count. */
5117 size_t n = 5117 size_t n =
5118 xmax (xsum (length, 5118 xmax (xsum (length,
5119 ((unsigned int) count + 2 5119 ((unsigned int) count + 2
5120 + TCHARS_PER_DCHAR - 1) 5120 + TCHARS_PER_DCHAR - 1)
5121 / TCHARS_PER_DCHAR), 5121 / TCHARS_PER_DCHAR),
5122 xtimes (allocated, 2)); 5122 xtimes (allocated, 2));
5123 5123
5124 ENSURE_ALLOCATION (n); 5124 ENSURE_ALLOCATION (n);
5125 continue; 5125 continue;
5126 } 5126 }
5127 } 5127 }
5128#endif 5128#endif
5129 5129
5130#if NEED_PRINTF_UNBOUNDED_PRECISION 5130#if NEED_PRINTF_UNBOUNDED_PRECISION
5131 if (prec_ourselves) 5131 if (prec_ourselves)
5132 { 5132 {
5133 /* Handle the precision. */ 5133 /* Handle the precision. */
5134 TCHAR_T *prec_ptr = 5134 TCHAR_T *prec_ptr =
5135# if USE_SNPRINTF 5135# if USE_SNPRINTF
5136 (TCHAR_T *) (result + length); 5136 (TCHAR_T *) (result + length);
5137# else 5137# else
5138 tmp; 5138 tmp;
5139# endif 5139# endif
5140 size_t prefix_count; 5140 size_t prefix_count;
5141 size_t move; 5141 size_t move;
5142 5142
5143 prefix_count = 0; 5143 prefix_count = 0;
5144 /* Put the additional zeroes after the sign. */ 5144 /* Put the additional zeroes after the sign. */
5145 if (count >= 1 5145 if (count >= 1
5146 && (*prec_ptr == '-' || *prec_ptr == '+' 5146 && (*prec_ptr == '-' || *prec_ptr == '+'
5147 || *prec_ptr == ' ')) 5147 || *prec_ptr == ' '))
5148 prefix_count = 1; 5148 prefix_count = 1;
5149 /* Put the additional zeroes after the 0x prefix if 5149 /* Put the additional zeroes after the 0x prefix if
5150 (flags & FLAG_ALT) || (dp->conversion == 'p'). */ 5150 (flags & FLAG_ALT) || (dp->conversion == 'p'). */
5151 else if (count >= 2 5151 else if (count >= 2
5152 && prec_ptr[0] == '0' 5152 && prec_ptr[0] == '0'
5153 && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) 5153 && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X'))
5154 prefix_count = 2; 5154 prefix_count = 2;
5155 5155
5156 move = count - prefix_count; 5156 move = count - prefix_count;
5157 if (precision > move) 5157 if (precision > move)
5158 { 5158 {
5159 /* Insert zeroes. */ 5159 /* Insert zeroes. */
5160 size_t insert = precision - move; 5160 size_t insert = precision - move;
5161 TCHAR_T *prec_end; 5161 TCHAR_T *prec_end;
5162 5162
5163# if USE_SNPRINTF 5163# if USE_SNPRINTF
5164 size_t n = 5164 size_t n =
5165 xsum (length, 5165 xsum (length,
5166 (count + insert + TCHARS_PER_DCHAR - 1) 5166 (count + insert + TCHARS_PER_DCHAR - 1)
5167 / TCHARS_PER_DCHAR); 5167 / TCHARS_PER_DCHAR);
5168 length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; 5168 length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
5169 ENSURE_ALLOCATION (n); 5169 ENSURE_ALLOCATION (n);
5170 length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; 5170 length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
5171 prec_ptr = (TCHAR_T *) (result + length); 5171 prec_ptr = (TCHAR_T *) (result + length);
5172# endif 5172# endif
5173 5173
5174 prec_end = prec_ptr + count; 5174 prec_end = prec_ptr + count;
5175 prec_ptr += prefix_count; 5175 prec_ptr += prefix_count;
5176 5176
5177 while (prec_end > prec_ptr) 5177 while (prec_end > prec_ptr)
5178 { 5178 {
5179 prec_end--; 5179 prec_end--;
5180 prec_end[insert] = prec_end[0]; 5180 prec_end[insert] = prec_end[0];
5181 } 5181 }
5182 5182
5183 prec_end += insert; 5183 prec_end += insert;
5184 do 5184 do
5185 *--prec_end = '0'; 5185 *--prec_end = '0';
5186 while (prec_end > prec_ptr); 5186 while (prec_end > prec_ptr);
5187 5187
5188 count += insert; 5188 count += insert;
5189 } 5189 }
5190 } 5190 }
5191#endif 5191#endif
5192 5192
5193#if !USE_SNPRINTF 5193#if !USE_SNPRINTF
5194 if (count >= tmp_length) 5194 if (count >= tmp_length)
5195 /* tmp_length was incorrectly calculated - fix the 5195 /* tmp_length was incorrectly calculated - fix the
5196 code above! */ 5196 code above! */
5197 abort (); 5197 abort ();
5198#endif 5198#endif
5199 5199
5200#if !DCHAR_IS_TCHAR 5200#if !DCHAR_IS_TCHAR
5201 /* Convert from TCHAR_T[] to DCHAR_T[]. */ 5201 /* Convert from TCHAR_T[] to DCHAR_T[]. */
5202 if (dp->conversion == 'c' || dp->conversion == 's') 5202 if (dp->conversion == 'c' || dp->conversion == 's')
5203 { 5203 {
5204 /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING 5204 /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING
5205 TYPE_WIDE_STRING. 5205 TYPE_WIDE_STRING.
5206 The result string is not certainly ASCII. */ 5206 The result string is not certainly ASCII. */
5207 const TCHAR_T *tmpsrc; 5207 const TCHAR_T *tmpsrc;
5208 DCHAR_T *tmpdst; 5208 DCHAR_T *tmpdst;
5209 size_t tmpdst_len; 5209 size_t tmpdst_len;
5210 /* This code assumes that TCHAR_T is 'char'. */ 5210 /* This code assumes that TCHAR_T is 'char'. */
5211 typedef int TCHAR_T_verify 5211 typedef int TCHAR_T_verify
5212 [2 * (sizeof (TCHAR_T) == 1) - 1]; 5212 [2 * (sizeof (TCHAR_T) == 1) - 1];
5213# if USE_SNPRINTF 5213# if USE_SNPRINTF
5214 tmpsrc = (TCHAR_T *) (result + length); 5214 tmpsrc = (TCHAR_T *) (result + length);
5215# else 5215# else
5216 tmpsrc = tmp; 5216 tmpsrc = tmp;
5217# endif 5217# endif
5218 tmpdst = 5218 tmpdst =
5219 DCHAR_CONV_FROM_ENCODING (locale_charset (), 5219 DCHAR_CONV_FROM_ENCODING (locale_charset (),
5220 iconveh_question_mark, 5220 iconveh_question_mark,
5221 tmpsrc, count, 5221 tmpsrc, count,
5222 NULL, 5222 NULL,
5223 NULL, &tmpdst_len); 5223 NULL, &tmpdst_len);
5224 if (tmpdst == NULL) 5224 if (tmpdst == NULL)
5225 { 5225 {
5226 int saved_errno = errno; 5226 int saved_errno = errno;
5227 if (!(result == resultbuf || result == NULL)) 5227 if (!(result == resultbuf || result == NULL))
5228 free (result); 5228 free (result);
5229 if (buf_malloced != NULL) 5229 if (buf_malloced != NULL)
5230 free (buf_malloced); 5230 free (buf_malloced);
5231 CLEANUP (); 5231 CLEANUP ();
5232 errno = saved_errno; 5232 errno = saved_errno;
5233 return NULL; 5233 return NULL;
5234 } 5234 }
5235 ENSURE_ALLOCATION (xsum (length, tmpdst_len)); 5235 ENSURE_ALLOCATION (xsum (length, tmpdst_len));
5236 DCHAR_CPY (result + length, tmpdst, tmpdst_len); 5236 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
5237 free (tmpdst); 5237 free (tmpdst);
5238 count = tmpdst_len; 5238 count = tmpdst_len;
5239 } 5239 }
5240 else 5240 else
5241 { 5241 {
5242 /* The result string is ASCII. 5242 /* The result string is ASCII.
5243 Simple 1:1 conversion. */ 5243 Simple 1:1 conversion. */
5244# if USE_SNPRINTF 5244# if USE_SNPRINTF
5245 /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a 5245 /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a
5246 no-op conversion, in-place on the array starting 5246 no-op conversion, in-place on the array starting
5247 at (result + length). */ 5247 at (result + length). */
5248 if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) 5248 if (sizeof (DCHAR_T) != sizeof (TCHAR_T))
5249# endif 5249# endif
5250 { 5250 {
5251 const TCHAR_T *tmpsrc; 5251 const TCHAR_T *tmpsrc;
5252 DCHAR_T *tmpdst; 5252 DCHAR_T *tmpdst;
5253 size_t n; 5253 size_t n;
5254 5254
5255# if USE_SNPRINTF 5255# if USE_SNPRINTF
5256 if (result == resultbuf) 5256 if (result == resultbuf)
5257 { 5257 {
5258 tmpsrc = (TCHAR_T *) (result + length); 5258 tmpsrc = (TCHAR_T *) (result + length);
5259 /* ENSURE_ALLOCATION will not move tmpsrc 5259 /* ENSURE_ALLOCATION will not move tmpsrc
5260 (because it's part of resultbuf). */ 5260 (because it's part of resultbuf). */
5261 ENSURE_ALLOCATION (xsum (length, count)); 5261 ENSURE_ALLOCATION (xsum (length, count));
5262 } 5262 }
5263 else 5263 else
5264 { 5264 {
5265 /* ENSURE_ALLOCATION will move the array 5265 /* ENSURE_ALLOCATION will move the array
5266 (because it uses realloc(). */ 5266 (because it uses realloc(). */
5267 ENSURE_ALLOCATION (xsum (length, count)); 5267 ENSURE_ALLOCATION (xsum (length, count));
5268 tmpsrc = (TCHAR_T *) (result + length); 5268 tmpsrc = (TCHAR_T *) (result + length);
5269 } 5269 }
5270# else 5270# else
5271 tmpsrc = tmp; 5271 tmpsrc = tmp;
5272 ENSURE_ALLOCATION (xsum (length, count)); 5272 ENSURE_ALLOCATION (xsum (length, count));
5273# endif 5273# endif
5274 tmpdst = result + length; 5274 tmpdst = result + length;
5275 /* Copy backwards, because of overlapping. */ 5275 /* Copy backwards, because of overlapping. */
5276 tmpsrc += count; 5276 tmpsrc += count;
5277 tmpdst += count; 5277 tmpdst += count;
5278 for (n = count; n > 0; n--) 5278 for (n = count; n > 0; n--)
5279 *--tmpdst = (unsigned char) *--tmpsrc; 5279 *--tmpdst = (unsigned char) *--tmpsrc;
5280 } 5280 }
5281 } 5281 }
5282#endif 5282#endif
5283 5283
5284#if DCHAR_IS_TCHAR && !USE_SNPRINTF 5284#if DCHAR_IS_TCHAR && !USE_SNPRINTF
5285 /* Make room for the result. */ 5285 /* Make room for the result. */
5286 if (count > allocated - length) 5286 if (count > allocated - length)
5287 { 5287 {
5288 /* Need at least count elements. But allocate 5288 /* Need at least count elements. But allocate
5289 proportionally. */ 5289 proportionally. */
5290 size_t n = 5290 size_t n =
5291 xmax (xsum (length, count), xtimes (allocated, 2)); 5291 xmax (xsum (length, count), xtimes (allocated, 2));
5292 5292
5293 ENSURE_ALLOCATION (n); 5293 ENSURE_ALLOCATION (n);
5294 } 5294 }
5295#endif 5295#endif
5296 5296
5297 /* Here count <= allocated - length. */ 5297 /* Here count <= allocated - length. */
5298 5298
5299 /* Perform padding. */ 5299 /* Perform padding. */
5300#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION 5300#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
5301 if (pad_ourselves && has_width) 5301 if (pad_ourselves && has_width)
5302 { 5302 {
5303 size_t w; 5303 size_t w;
5304# if ENABLE_UNISTDIO 5304# if ENABLE_UNISTDIO
5305 /* Outside POSIX, it's preferrable to compare the width 5305 /* Outside POSIX, it's preferrable to compare the width
5306 against the number of _characters_ of the converted 5306 against the number of _characters_ of the converted
5307 value. */ 5307 value. */
5308 w = DCHAR_MBSNLEN (result + length, count); 5308 w = DCHAR_MBSNLEN (result + length, count);
5309# else 5309# else
5310 /* The width is compared against the number of _bytes_ 5310 /* The width is compared against the number of _bytes_
5311 of the converted value, says POSIX. */ 5311 of the converted value, says POSIX. */
5312 w = count; 5312 w = count;
5313# endif 5313# endif
5314 if (w < width) 5314 if (w < width)
5315 { 5315 {
5316 size_t pad = width - w; 5316 size_t pad = width - w;
5317 5317
5318 /* Make room for the result. */ 5318 /* Make room for the result. */
5319 if (xsum (count, pad) > allocated - length) 5319 if (xsum (count, pad) > allocated - length)
5320 { 5320 {
5321 /* Need at least count + pad elements. But 5321 /* Need at least count + pad elements. But
5322 allocate proportionally. */ 5322 allocate proportionally. */
5323 size_t n = 5323 size_t n =
5324 xmax (xsum3 (length, count, pad), 5324 xmax (xsum3 (length, count, pad),
5325 xtimes (allocated, 2)); 5325 xtimes (allocated, 2));
5326 5326
5327# if USE_SNPRINTF 5327# if USE_SNPRINTF
5328 length += count; 5328 length += count;
5329 ENSURE_ALLOCATION (n); 5329 ENSURE_ALLOCATION (n);
5330 length -= count; 5330 length -= count;
5331# else 5331# else
5332 ENSURE_ALLOCATION (n); 5332 ENSURE_ALLOCATION (n);
5333# endif 5333# endif
5334 } 5334 }
5335 /* Here count + pad <= allocated - length. */ 5335 /* Here count + pad <= allocated - length. */
5336 5336
5337 { 5337 {
5338# if !DCHAR_IS_TCHAR || USE_SNPRINTF 5338# if !DCHAR_IS_TCHAR || USE_SNPRINTF
5339 DCHAR_T * const rp = result + length; 5339 DCHAR_T * const rp = result + length;
5340# else 5340# else
5341 DCHAR_T * const rp = tmp; 5341 DCHAR_T * const rp = tmp;
5342# endif 5342# endif
5343 DCHAR_T *p = rp + count; 5343 DCHAR_T *p = rp + count;
5344 DCHAR_T *end = p + pad; 5344 DCHAR_T *end = p + pad;
5345 DCHAR_T *pad_ptr; 5345 DCHAR_T *pad_ptr;
5346# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO 5346# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
5347 if (dp->conversion == 'c' 5347 if (dp->conversion == 'c'
5348 || dp->conversion == 's') 5348 || dp->conversion == 's')
5349 /* No zero-padding for string directives. */ 5349 /* No zero-padding for string directives. */
5350 pad_ptr = NULL; 5350 pad_ptr = NULL;
5351 else 5351 else
5352# endif 5352# endif
5353 { 5353 {
5354 pad_ptr = (*rp == '-' ? rp + 1 : rp); 5354 pad_ptr = (*rp == '-' ? rp + 1 : rp);
5355 /* No zero-padding of "inf" and "nan". */ 5355 /* No zero-padding of "inf" and "nan". */
5356 if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') 5356 if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z')
5357 || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) 5357 || (*pad_ptr >= 'a' && *pad_ptr <= 'z'))
5358 pad_ptr = NULL; 5358 pad_ptr = NULL;
5359 } 5359 }
5360 /* The generated string now extends from rp to p, 5360 /* The generated string now extends from rp to p,
5361 with the zero padding insertion point being at 5361 with the zero padding insertion point being at
5362 pad_ptr. */ 5362 pad_ptr. */
5363 5363
5364 count = count + pad; /* = end - rp */ 5364 count = count + pad; /* = end - rp */
5365 5365
5366 if (flags & FLAG_LEFT) 5366 if (flags & FLAG_LEFT)
5367 { 5367 {
5368 /* Pad with spaces on the right. */ 5368 /* Pad with spaces on the right. */
5369 for (; pad > 0; pad--) 5369 for (; pad > 0; pad--)
5370 *p++ = ' '; 5370 *p++ = ' ';
5371 } 5371 }
5372 else if ((flags & FLAG_ZERO) && pad_ptr != NULL) 5372 else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
5373 { 5373 {
5374 /* Pad with zeroes. */ 5374 /* Pad with zeroes. */
5375 DCHAR_T *q = end; 5375 DCHAR_T *q = end;
5376 5376
5377 while (p > pad_ptr) 5377 while (p > pad_ptr)
5378 *--q = *--p; 5378 *--q = *--p;
5379 for (; pad > 0; pad--) 5379 for (; pad > 0; pad--)
5380 *p++ = '0'; 5380 *p++ = '0';
5381 } 5381 }
5382 else 5382 else
5383 { 5383 {
5384 /* Pad with spaces on the left. */ 5384 /* Pad with spaces on the left. */
5385 DCHAR_T *q = end; 5385 DCHAR_T *q = end;
5386 5386
5387 while (p > rp) 5387 while (p > rp)
5388 *--q = *--p; 5388 *--q = *--p;
5389 for (; pad > 0; pad--) 5389 for (; pad > 0; pad--)
5390 *p++ = ' '; 5390 *p++ = ' ';
5391 } 5391 }
5392 } 5392 }
5393 } 5393 }
5394 } 5394 }
5395#endif 5395#endif
5396 5396
5397 /* Here still count <= allocated - length. */ 5397 /* Here still count <= allocated - length. */
5398 5398
5399#if !DCHAR_IS_TCHAR || USE_SNPRINTF 5399#if !DCHAR_IS_TCHAR || USE_SNPRINTF
5400 /* The snprintf() result did fit. */ 5400 /* The snprintf() result did fit. */
5401#else 5401#else
5402 /* Append the sprintf() result. */ 5402 /* Append the sprintf() result. */
5403 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 5403 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
5404#endif 5404#endif
5405#if !USE_SNPRINTF 5405#if !USE_SNPRINTF
5406 if (tmp != tmpbuf) 5406 if (tmp != tmpbuf)
5407 free (tmp); 5407 free (tmp);
5408#endif 5408#endif
5409 5409
5410#if NEED_PRINTF_DIRECTIVE_F 5410#if NEED_PRINTF_DIRECTIVE_F
5411 if (dp->conversion == 'F') 5411 if (dp->conversion == 'F')
5412 { 5412 {
5413 /* Convert the %f result to upper case for %F. */ 5413 /* Convert the %f result to upper case for %F. */
5414 DCHAR_T *rp = result + length; 5414 DCHAR_T *rp = result + length;
5415 size_t rc; 5415 size_t rc;
5416 for (rc = count; rc > 0; rc--, rp++) 5416 for (rc = count; rc > 0; rc--, rp++)
5417 if (*rp >= 'a' && *rp <= 'z') 5417 if (*rp >= 'a' && *rp <= 'z')
5418 *rp = *rp - 'a' + 'A'; 5418 *rp = *rp - 'a' + 'A';
5419 } 5419 }
5420#endif 5420#endif
5421 5421
5422 length += count; 5422 length += count;
5423 break; 5423 break;
5424 } 5424 }
5425 } 5425 }
5426 } 5426 }
5427 } 5427 }
5428 5428
5429 /* Add the final NUL. */ 5429 /* Add the final NUL. */
@@ -5432,12 +5432,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5432 5432
5433 if (result != resultbuf && length + 1 < allocated) 5433 if (result != resultbuf && length + 1 < allocated)
5434 { 5434 {
5435 /* Shrink the allocated memory if possible. */ 5435 /* Shrink the allocated memory if possible. */
5436 DCHAR_T *memory; 5436 DCHAR_T *memory;
5437 5437
5438 memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); 5438 memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T));
5439 if (memory != NULL) 5439 if (memory != NULL)
5440 result = memory; 5440 result = memory;
5441 } 5441 }
5442 5442
5443 if (buf_malloced != NULL) 5443 if (buf_malloced != NULL)
@@ -5476,6 +5476,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5476#undef TCHARS_PER_DCHAR 5476#undef TCHARS_PER_DCHAR
5477#undef SNPRINTF 5477#undef SNPRINTF
5478#undef USE_SNPRINTF 5478#undef USE_SNPRINTF
5479#undef DCHAR_SET
5479#undef DCHAR_CPY 5480#undef DCHAR_CPY
5480#undef PRINTF_PARSE 5481#undef PRINTF_PARSE
5481#undef DIRECTIVES 5482#undef DIRECTIVES
diff --git a/gl/vasnprintf.h b/gl/vasnprintf.h
index b9a3d6ed..a689bad2 100644
--- a/gl/vasnprintf.h
+++ b/gl/vasnprintf.h
@@ -1,5 +1,5 @@
1/* vsprintf with automatic memory allocation. 1/* vsprintf with automatic memory allocation.
2 Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc. 2 Copyright (C) 2002-2004, 2007-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
@@ -25,15 +25,14 @@
25#include <stddef.h> 25#include <stddef.h>
26 26
27#ifndef __attribute__ 27#ifndef __attribute__
28/* This feature is available in gcc versions 2.5 and later. */ 28/* The __attribute__ feature is available in gcc versions 2.5 and later.
29# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) 29 The __-protected variants of the attributes 'format' and 'printf' are
30# define __attribute__(Spec) /* empty */ 30 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
31# endif 31 We enable __attribute__ only if these are supported too, because
32/* The __-protected variants of `format' and `printf' attributes 32 gnulib and libintl do '#define printf __printf__' when they override
33 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 33 the 'printf' function. */
34# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 34# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
35# define __format__ format 35# define __attribute__(Spec) /* empty */
36# define __printf__ printf
37# endif 36# endif
38#endif 37#endif
39 38
diff --git a/gl/vasprintf.c b/gl/vasprintf.c
index d1b81373..46486f3d 100644
--- a/gl/vasprintf.c
+++ b/gl/vasprintf.c
@@ -1,5 +1,5 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006-2008 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002, 2006-2010 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 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 5 it under the terms of the GNU General Public License as published by
diff --git a/gl/verify.h b/gl/verify.h
index fac53f6f..bcd3f5a0 100644
--- a/gl/verify.h
+++ b/gl/verify.h
@@ -1,6 +1,6 @@
1/* Compile-time assert-like macros. 1/* Compile-time assert-like macros.
2 2
3 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -110,8 +110,8 @@
110 110
111 #if 4 <= __GNUC__ 111 #if 4 <= __GNUC__
112 # define verify(R) \ 112 # define verify(R) \
113 extern int (* verify_function__ (void)) \ 113 extern int (* verify_function__ (void)) \
114 [__builtin_constant_p (R) && (R) ? 1 : -1] 114 [__builtin_constant_p (R) && (R) ? 1 : -1]
115 #endif 115 #endif
116 116
117 * In C++, any struct definition inside sizeof is invalid. 117 * In C++, any struct definition inside sizeof is invalid.
diff --git a/gl/vsnprintf.c b/gl/vsnprintf.c
index 02af2520..d447cc2d 100644
--- a/gl/vsnprintf.c
+++ b/gl/vsnprintf.c
@@ -1,5 +1,5 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2006-2010 Free Software Foundation, Inc.
3 Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. 3 Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
@@ -52,11 +52,11 @@ vsnprintf (char *str, size_t size, const char *format, va_list args)
52 if (output != str) 52 if (output != str)
53 { 53 {
54 if (size) 54 if (size)
55 { 55 {
56 size_t pruned_len = (len < size ? len : size - 1); 56 size_t pruned_len = (len < size ? len : size - 1);
57 memcpy (str, output, pruned_len); 57 memcpy (str, output, pruned_len);
58 str[pruned_len] = '\0'; 58 str[pruned_len] = '\0';
59 } 59 }
60 60
61 free (output); 61 free (output);
62 } 62 }
diff --git a/gl/w32sock.h b/gl/w32sock.h
new file mode 100644
index 00000000..b472bd05
--- /dev/null
+++ b/gl/w32sock.h
@@ -0,0 +1,61 @@
1/* w32sock.h --- internal auxilliary functions for Windows socket functions
2
3 Copyright (C) 2008, 2009, 2010 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 Paolo Bonzini */
19
20#include <errno.h>
21
22/* Get O_RDWR and O_BINARY. */
23#include <fcntl.h>
24
25/* Get _get_osfhandle() and _open_osfhandle(). */
26#include <io.h>
27
28#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd)))
29#define SOCKET_TO_FD(fh) (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
30
31static inline void
32set_winsock_errno (void)
33{
34 int err = WSAGetLastError ();
35
36 /* Map some WSAE* errors to the runtime library's error codes. */
37 switch (err)
38 {
39 case WSA_INVALID_HANDLE:
40 errno = EBADF;
41 break;
42 case WSA_NOT_ENOUGH_MEMORY:
43 errno = ENOMEM;
44 break;
45 case WSA_INVALID_PARAMETER:
46 errno = EINVAL;
47 break;
48 case WSAEWOULDBLOCK:
49 errno = EWOULDBLOCK;
50 break;
51 case WSAENAMETOOLONG:
52 errno = ENAMETOOLONG;
53 break;
54 case WSAENOTEMPTY:
55 errno = ENOTEMPTY;
56 break;
57 default:
58 errno = (err > 10000 && err < 10025) ? err - 10000 : err;
59 break;
60 }
61}
diff --git a/gl/wchar.in.h b/gl/wchar.in.h
index cc5baad3..dd41d353 100644
--- a/gl/wchar.in.h
+++ b/gl/wchar.in.h
@@ -1,6 +1,6 @@
1/* A substitute for ISO C99 <wchar.h>, for platforms that have issues. 1/* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
2 2
3 Copyright (C) 2007-2009 Free Software Foundation, Inc. 3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -30,9 +30,9 @@
30@PRAGMA_SYSTEM_HEADER@ 30@PRAGMA_SYSTEM_HEADER@
31#endif 31#endif
32 32
33#if defined __need_mbstate_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H 33#if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H
34/* Special invocation convention: 34/* Special invocation convention:
35 - Inside uClibc header files. 35 - Inside glibc and uClibc header files.
36 - On HP-UX 11.00 we have a sequence of nested includes 36 - On HP-UX 11.00 we have a sequence of nested includes
37 <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>, 37 <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
38 once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h> 38 once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
@@ -55,10 +55,13 @@
55/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 55/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
56 <wchar.h>. 56 <wchar.h>.
57 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 57 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
58 included before <wchar.h>. */ 58 included before <wchar.h>.
59#include <stddef.h> 59 But avoid namespace pollution on glibc systems. */
60#include <stdio.h> 60#ifndef __GLIBC__
61#include <time.h> 61# include <stddef.h>
62# include <stdio.h>
63# include <time.h>
64#endif
62 65
63/* Include the original <wchar.h> if it exists. 66/* Include the original <wchar.h> if it exists.
64 Some builds of uClibc lack it. */ 67 Some builds of uClibc lack it. */
@@ -72,19 +75,23 @@
72#ifndef _GL_WCHAR_H 75#ifndef _GL_WCHAR_H
73#define _GL_WCHAR_H 76#define _GL_WCHAR_H
74 77
75/* The definition of GL_LINK_WARNING is copied here. */ 78/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
76 79
77#ifdef __cplusplus 80/* The definition of _GL_ARG_NONNULL is copied here. */
78extern "C" {
79#endif
80 81
82/* The definition of _GL_WARN_ON_USE is copied here. */
81 83
82/* Define wint_t. (Also done in wctype.in.h.) */ 84
85/* Define wint_t and WEOF. (Also done in wctype.in.h.) */
83#if !@HAVE_WINT_T@ && !defined wint_t 86#if !@HAVE_WINT_T@ && !defined wint_t
84# define wint_t int 87# define wint_t int
85# ifndef WEOF 88# ifndef WEOF
86# define WEOF -1 89# define WEOF -1
87# endif 90# endif
91#else
92# ifndef WEOF
93# define WEOF ((wint_t) -1)
94# endif
88#endif 95#endif
89 96
90 97
@@ -102,209 +109,320 @@ typedef int rpl_mbstate_t;
102/* Convert a single-byte character to a wide character. */ 109/* Convert a single-byte character to a wide character. */
103#if @GNULIB_BTOWC@ 110#if @GNULIB_BTOWC@
104# if @REPLACE_BTOWC@ 111# if @REPLACE_BTOWC@
105# undef btowc 112# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
106# define btowc rpl_btowc 113# undef btowc
107# endif 114# define btowc rpl_btowc
108# if !@HAVE_BTOWC@ || @REPLACE_BTOWC@ 115# endif
109extern wint_t btowc (int c); 116_GL_FUNCDECL_RPL (btowc, wint_t, (int c));
117_GL_CXXALIAS_RPL (btowc, wint_t, (int c));
118# else
119# if !@HAVE_BTOWC@
120_GL_FUNCDECL_SYS (btowc, wint_t, (int c));
121# endif
122_GL_CXXALIAS_SYS (btowc, wint_t, (int c));
110# endif 123# endif
124_GL_CXXALIASWARN (btowc);
111#elif defined GNULIB_POSIXCHECK 125#elif defined GNULIB_POSIXCHECK
112# undef btowc 126# undef btowc
113# define btowc(c) \ 127# if HAVE_RAW_DECL_BTOWC
114 (GL_LINK_WARNING ("btowc is unportable - " \ 128_GL_WARN_ON_USE (btowc, "btowc is unportable - "
115 "use gnulib module btowc for portability"), \ 129 "use gnulib module btowc for portability");
116 btowc (c)) 130# endif
117#endif 131#endif
118 132
119 133
120/* Convert a wide character to a single-byte character. */ 134/* Convert a wide character to a single-byte character. */
121#if @GNULIB_WCTOB@ 135#if @GNULIB_WCTOB@
122# if @REPLACE_WCTOB@ 136# if @REPLACE_WCTOB@
123# undef wctob 137# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
124# define wctob rpl_wctob 138# undef wctob
125# endif 139# define wctob rpl_wctob
126# if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@ 140# endif
141_GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
142_GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
143# else
144# if !defined wctob && !@HAVE_DECL_WCTOB@
127/* wctob is provided by gnulib, or wctob exists but is not declared. */ 145/* wctob is provided by gnulib, or wctob exists but is not declared. */
128extern int wctob (wint_t wc); 146_GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
147# endif
148_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
129# endif 149# endif
150_GL_CXXALIASWARN (wctob);
130#elif defined GNULIB_POSIXCHECK 151#elif defined GNULIB_POSIXCHECK
131# undef wctob 152# undef wctob
132# define wctob(w) \ 153# if HAVE_RAW_DECL_WCTOB
133 (GL_LINK_WARNING ("wctob is unportable - " \ 154_GL_WARN_ON_USE (wctob, "wctob is unportable - "
134 "use gnulib module wctob for portability"), \ 155 "use gnulib module wctob for portability");
135 wctob (w)) 156# endif
136#endif 157#endif
137 158
138 159
139/* Test whether *PS is in the initial state. */ 160/* Test whether *PS is in the initial state. */
140#if @GNULIB_MBSINIT@ 161#if @GNULIB_MBSINIT@
141# if @REPLACE_MBSINIT@ 162# if @REPLACE_MBSINIT@
142# undef mbsinit 163# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
143# define mbsinit rpl_mbsinit 164# undef mbsinit
144# endif 165# define mbsinit rpl_mbsinit
145# if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@ 166# endif
146extern int mbsinit (const mbstate_t *ps); 167_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
168_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
169# else
170# if !@HAVE_MBSINIT@
171_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
172# endif
173_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
147# endif 174# endif
175_GL_CXXALIASWARN (mbsinit);
148#elif defined GNULIB_POSIXCHECK 176#elif defined GNULIB_POSIXCHECK
149# undef mbsinit 177# undef mbsinit
150# define mbsinit(p) \ 178# if HAVE_RAW_DECL_MBSINIT
151 (GL_LINK_WARNING ("mbsinit is unportable - " \ 179_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
152 "use gnulib module mbsinit for portability"), \ 180 "use gnulib module mbsinit for portability");
153 mbsinit (p)) 181# endif
154#endif 182#endif
155 183
156 184
157/* Convert a multibyte character to a wide character. */ 185/* Convert a multibyte character to a wide character. */
158#if @GNULIB_MBRTOWC@ 186#if @GNULIB_MBRTOWC@
159# if @REPLACE_MBRTOWC@ 187# if @REPLACE_MBRTOWC@
160# undef mbrtowc 188# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
161# define mbrtowc rpl_mbrtowc 189# undef mbrtowc
162# endif 190# define mbrtowc rpl_mbrtowc
163# if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@ 191# endif
164extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps); 192_GL_FUNCDECL_RPL (mbrtowc, size_t,
193 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
194_GL_CXXALIAS_RPL (mbrtowc, size_t,
195 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
196# else
197# if !@HAVE_MBRTOWC@
198_GL_FUNCDECL_SYS (mbrtowc, size_t,
199 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
200# endif
201_GL_CXXALIAS_SYS (mbrtowc, size_t,
202 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
165# endif 203# endif
204_GL_CXXALIASWARN (mbrtowc);
166#elif defined GNULIB_POSIXCHECK 205#elif defined GNULIB_POSIXCHECK
167# undef mbrtowc 206# undef mbrtowc
168# define mbrtowc(w,s,n,p) \ 207# if HAVE_RAW_DECL_MBRTOWC
169 (GL_LINK_WARNING ("mbrtowc is unportable - " \ 208_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
170 "use gnulib module mbrtowc for portability"), \ 209 "use gnulib module mbrtowc for portability");
171 mbrtowc (w, s, n, p)) 210# endif
172#endif 211#endif
173 212
174 213
175/* Recognize a multibyte character. */ 214/* Recognize a multibyte character. */
176#if @GNULIB_MBRLEN@ 215#if @GNULIB_MBRLEN@
177# if @REPLACE_MBRLEN@ 216# if @REPLACE_MBRLEN@
178# undef mbrlen 217# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
179# define mbrlen rpl_mbrlen 218# undef mbrlen
180# endif 219# define mbrlen rpl_mbrlen
181# if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@ 220# endif
182extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps); 221_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
222_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
223# else
224# if !@HAVE_MBRLEN@
225_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
226# endif
227_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
183# endif 228# endif
229_GL_CXXALIASWARN (mbrlen);
184#elif defined GNULIB_POSIXCHECK 230#elif defined GNULIB_POSIXCHECK
185# undef mbrlen 231# undef mbrlen
186# define mbrlen(s,n,p) \ 232# if HAVE_RAW_DECL_MBRLEN
187 (GL_LINK_WARNING ("mbrlen is unportable - " \ 233_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
188 "use gnulib module mbrlen for portability"), \ 234 "use gnulib module mbrlen for portability");
189 mbrlen (s, n, p)) 235# endif
190#endif 236#endif
191 237
192 238
193/* Convert a string to a wide string. */ 239/* Convert a string to a wide string. */
194#if @GNULIB_MBSRTOWCS@ 240#if @GNULIB_MBSRTOWCS@
195# if @REPLACE_MBSRTOWCS@ 241# if @REPLACE_MBSRTOWCS@
196# undef mbsrtowcs 242# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
197# define mbsrtowcs rpl_mbsrtowcs 243# undef mbsrtowcs
198# endif 244# define mbsrtowcs rpl_mbsrtowcs
199# if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@ 245# endif
200extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps); 246_GL_FUNCDECL_RPL (mbsrtowcs, size_t,
247 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
248 _GL_ARG_NONNULL ((2)));
249_GL_CXXALIAS_RPL (mbsrtowcs, size_t,
250 (wchar_t *dest, const char **srcp, size_t len,
251 mbstate_t *ps));
252# else
253# if !@HAVE_MBSRTOWCS@
254_GL_FUNCDECL_SYS (mbsrtowcs, size_t,
255 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
256 _GL_ARG_NONNULL ((2)));
257# endif
258_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
259 (wchar_t *dest, const char **srcp, size_t len,
260 mbstate_t *ps));
201# endif 261# endif
262_GL_CXXALIASWARN (mbsrtowcs);
202#elif defined GNULIB_POSIXCHECK 263#elif defined GNULIB_POSIXCHECK
203# undef mbsrtowcs 264# undef mbsrtowcs
204# define mbsrtowcs(d,s,l,p) \ 265# if HAVE_RAW_DECL_MBSRTOWCS
205 (GL_LINK_WARNING ("mbsrtowcs is unportable - " \ 266_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
206 "use gnulib module mbsrtowcs for portability"), \ 267 "use gnulib module mbsrtowcs for portability");
207 mbsrtowcs (d, s, l, p)) 268# endif
208#endif 269#endif
209 270
210 271
211/* Convert a string to a wide string. */ 272/* Convert a string to a wide string. */
212#if @GNULIB_MBSNRTOWCS@ 273#if @GNULIB_MBSNRTOWCS@
213# if @REPLACE_MBSNRTOWCS@ 274# if @REPLACE_MBSNRTOWCS@
214# undef mbsnrtowcs 275# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
215# define mbsnrtowcs rpl_mbsnrtowcs 276# undef mbsnrtowcs
216# endif 277# define mbsnrtowcs rpl_mbsnrtowcs
217# if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@ 278# endif
218extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps); 279_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
280 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
281 mbstate_t *ps)
282 _GL_ARG_NONNULL ((2)));
283_GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
284 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
285 mbstate_t *ps));
286# else
287# if !@HAVE_MBSNRTOWCS@
288_GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
289 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
290 mbstate_t *ps)
291 _GL_ARG_NONNULL ((2)));
292# endif
293_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
294 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
295 mbstate_t *ps));
219# endif 296# endif
297_GL_CXXALIASWARN (mbsnrtowcs);
220#elif defined GNULIB_POSIXCHECK 298#elif defined GNULIB_POSIXCHECK
221# undef mbsnrtowcs 299# undef mbsnrtowcs
222# define mbsnrtowcs(d,s,n,l,p) \ 300# if HAVE_RAW_DECL_MBSNRTOWCS
223 (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \ 301_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
224 "use gnulib module mbsnrtowcs for portability"), \ 302 "use gnulib module mbsnrtowcs for portability");
225 mbsnrtowcs (d, s, n, l, p)) 303# endif
226#endif 304#endif
227 305
228 306
229/* Convert a wide character to a multibyte character. */ 307/* Convert a wide character to a multibyte character. */
230#if @GNULIB_WCRTOMB@ 308#if @GNULIB_WCRTOMB@
231# if @REPLACE_WCRTOMB@ 309# if @REPLACE_WCRTOMB@
232# undef wcrtomb 310# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
233# define wcrtomb rpl_wcrtomb 311# undef wcrtomb
234# endif 312# define wcrtomb rpl_wcrtomb
235# if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@ 313# endif
236extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps); 314_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
315_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
316# else
317# if !@HAVE_WCRTOMB@
318_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
319# endif
320_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
237# endif 321# endif
322_GL_CXXALIASWARN (wcrtomb);
238#elif defined GNULIB_POSIXCHECK 323#elif defined GNULIB_POSIXCHECK
239# undef wcrtomb 324# undef wcrtomb
240# define wcrtomb(s,w,p) \ 325# if HAVE_RAW_DECL_WCRTOMB
241 (GL_LINK_WARNING ("wcrtomb is unportable - " \ 326_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
242 "use gnulib module wcrtomb for portability"), \ 327 "use gnulib module wcrtomb for portability");
243 wcrtomb (s, w, p)) 328# endif
244#endif 329#endif
245 330
246 331
247/* Convert a wide string to a string. */ 332/* Convert a wide string to a string. */
248#if @GNULIB_WCSRTOMBS@ 333#if @GNULIB_WCSRTOMBS@
249# if @REPLACE_WCSRTOMBS@ 334# if @REPLACE_WCSRTOMBS@
250# undef wcsrtombs 335# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
251# define wcsrtombs rpl_wcsrtombs 336# undef wcsrtombs
252# endif 337# define wcsrtombs rpl_wcsrtombs
253# if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@ 338# endif
254extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps); 339_GL_FUNCDECL_RPL (wcsrtombs, size_t,
340 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
341 _GL_ARG_NONNULL ((2)));
342_GL_CXXALIAS_RPL (wcsrtombs, size_t,
343 (char *dest, const wchar_t **srcp, size_t len,
344 mbstate_t *ps));
345# else
346# if !@HAVE_WCSRTOMBS@
347_GL_FUNCDECL_SYS (wcsrtombs, size_t,
348 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
349 _GL_ARG_NONNULL ((2)));
350# endif
351_GL_CXXALIAS_SYS (wcsrtombs, size_t,
352 (char *dest, const wchar_t **srcp, size_t len,
353 mbstate_t *ps));
255# endif 354# endif
355_GL_CXXALIASWARN (wcsrtombs);
256#elif defined GNULIB_POSIXCHECK 356#elif defined GNULIB_POSIXCHECK
257# undef wcsrtombs 357# undef wcsrtombs
258# define wcsrtombs(d,s,l,p) \ 358# if HAVE_RAW_DECL_WCSRTOMBS
259 (GL_LINK_WARNING ("wcsrtombs is unportable - " \ 359_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
260 "use gnulib module wcsrtombs for portability"), \ 360 "use gnulib module wcsrtombs for portability");
261 wcsrtombs (d, s, l, p)) 361# endif
262#endif 362#endif
263 363
264 364
265/* Convert a wide string to a string. */ 365/* Convert a wide string to a string. */
266#if @GNULIB_WCSNRTOMBS@ 366#if @GNULIB_WCSNRTOMBS@
267# if @REPLACE_WCSNRTOMBS@ 367# if @REPLACE_WCSNRTOMBS@
268# undef wcsnrtombs 368# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
269# define wcsnrtombs rpl_wcsnrtombs 369# undef wcsnrtombs
270# endif 370# define wcsnrtombs rpl_wcsnrtombs
271# if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@ 371# endif
272extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps); 372_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
373 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
374 mbstate_t *ps)
375 _GL_ARG_NONNULL ((2)));
376_GL_CXXALIAS_RPL (wcsnrtombs, size_t,
377 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
378 mbstate_t *ps));
379# else
380# if !@HAVE_WCSNRTOMBS@
381_GL_FUNCDECL_SYS (wcsnrtombs, size_t,
382 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
383 mbstate_t *ps)
384 _GL_ARG_NONNULL ((2)));
385# endif
386_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
387 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
388 mbstate_t *ps));
273# endif 389# endif
390_GL_CXXALIASWARN (wcsnrtombs);
274#elif defined GNULIB_POSIXCHECK 391#elif defined GNULIB_POSIXCHECK
275# undef wcsnrtombs 392# undef wcsnrtombs
276# define wcsnrtombs(d,s,n,l,p) \ 393# if HAVE_RAW_DECL_WCSNRTOMBS
277 (GL_LINK_WARNING ("wcsnrtombs is unportable - " \ 394_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
278 "use gnulib module wcsnrtombs for portability"), \ 395 "use gnulib module wcsnrtombs for portability");
279 wcsnrtombs (d, s, n, l, p)) 396# endif
280#endif 397#endif
281 398
282 399
283/* Return the number of screen columns needed for WC. */ 400/* Return the number of screen columns needed for WC. */
284#if @GNULIB_WCWIDTH@ 401#if @GNULIB_WCWIDTH@
285# if @REPLACE_WCWIDTH@ 402# if @REPLACE_WCWIDTH@
286# undef wcwidth 403# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
287# define wcwidth rpl_wcwidth 404# undef wcwidth
288extern int wcwidth (wchar_t); 405# define wcwidth rpl_wcwidth
406# endif
407_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
408_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
289# else 409# else
290# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@ 410# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
291/* wcwidth exists but is not declared. */ 411/* wcwidth exists but is not declared. */
292extern int wcwidth (int /* actually wchar_t */); 412_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
293# endif 413# endif
414_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
294# endif 415# endif
416_GL_CXXALIASWARN (wcwidth);
295#elif defined GNULIB_POSIXCHECK 417#elif defined GNULIB_POSIXCHECK
296# undef wcwidth 418# undef wcwidth
297# define wcwidth(w) \ 419# if HAVE_RAW_DECL_WCWIDTH
298 (GL_LINK_WARNING ("wcwidth is unportable - " \ 420_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
299 "use gnulib module wcwidth for portability"), \ 421 "use gnulib module wcwidth for portability");
300 wcwidth (w)) 422# endif
301#endif 423#endif
302 424
303 425
304#ifdef __cplusplus
305}
306#endif
307
308#endif /* _GL_WCHAR_H */ 426#endif /* _GL_WCHAR_H */
309#endif /* _GL_WCHAR_H */ 427#endif /* _GL_WCHAR_H */
310#endif 428#endif
diff --git a/gl/wcrtomb.c b/gl/wcrtomb.c
index 79df99f2..e7345f69 100644
--- a/gl/wcrtomb.c
+++ b/gl/wcrtomb.c
@@ -1,5 +1,5 @@
1/* Convert wide character to multibyte character. 1/* Convert wide character to multibyte character.
2 Copyright (C) 2008 Free Software Foundation, Inc. 2 Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
@@ -43,11 +43,11 @@ wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
43 int ret = wctomb (s, wc); 43 int ret = wctomb (s, wc);
44 44
45 if (ret >= 0) 45 if (ret >= 0)
46 return ret; 46 return ret;
47 else 47 else
48 { 48 {
49 errno = EILSEQ; 49 errno = EILSEQ;
50 return (size_t)(-1); 50 return (size_t)(-1);
51 } 51 }
52 } 52 }
53} 53}
diff --git a/gl/wctype.in.h b/gl/wctype.in.h
index f008d8ff..0f0859c3 100644
--- a/gl/wctype.in.h
+++ b/gl/wctype.in.h
@@ -1,6 +1,6 @@
1/* A substitute for ISO C99 <wctype.h>, for platforms that lack it. 1/* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2 2
3 Copyright (C) 2006-2008 Free Software Foundation, Inc. 3 Copyright (C) 2006-2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
@@ -54,17 +54,27 @@
54#ifndef _GL_WCTYPE_H 54#ifndef _GL_WCTYPE_H
55#define _GL_WCTYPE_H 55#define _GL_WCTYPE_H
56 56
57/* Define wint_t. (Also done in wchar.in.h.) */ 57/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
58
59/* The definition of _GL_WARN_ON_USE is copied here. */
60
61/* Define wint_t and WEOF. (Also done in wchar.in.h.) */
58#if !@HAVE_WINT_T@ && !defined wint_t 62#if !@HAVE_WINT_T@ && !defined wint_t
59# define wint_t int 63# define wint_t int
60# ifndef WEOF 64# ifndef WEOF
61# define WEOF -1 65# define WEOF -1
62# endif 66# endif
67#else
68# ifndef WEOF
69# define WEOF ((wint_t) -1)
70# endif
63#endif 71#endif
64 72
73
65/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions. 74/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
66 Linux libc5 has <wctype.h> and the functions but they are broken. 75 Linux libc5 has <wctype.h> and the functions but they are broken.
67 Assume all 12 functions are implemented the same way, or not at all. */ 76 Assume all 11 functions (all isw* except iswblank) are implemented the
77 same way, or not at all. */
68#if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@ 78#if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
69 79
70/* IRIX 5.3 has macros but no functions, its isw* macros refer to an 80/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
@@ -72,21 +82,24 @@
72 refer to system functions like _iswctype that are not in the 82 refer to system functions like _iswctype that are not in the
73 standard C library. Rather than try to get ancient buggy 83 standard C library. Rather than try to get ancient buggy
74 implementations like this to work, just disable them. */ 84 implementations like this to work, just disable them. */
75# undef iswalnum 85# undef iswalnum
76# undef iswalpha 86# undef iswalpha
77# undef iswblank 87# undef iswblank
78# undef iswcntrl 88# undef iswcntrl
79# undef iswdigit 89# undef iswdigit
80# undef iswgraph 90# undef iswgraph
81# undef iswlower 91# undef iswlower
82# undef iswprint 92# undef iswprint
83# undef iswpunct 93# undef iswpunct
84# undef iswspace 94# undef iswspace
85# undef iswupper 95# undef iswupper
86# undef iswxdigit 96# undef iswxdigit
97# undef towlower
98# undef towupper
87 99
88/* Linux libc5 has <wctype.h> and the functions but they are broken. */ 100/* Linux libc5 has <wctype.h> and the functions but they are broken. */
89# if @REPLACE_ISWCNTRL@ 101# if @REPLACE_ISWCNTRL@
102# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
90# define iswalnum rpl_iswalnum 103# define iswalnum rpl_iswalnum
91# define iswalpha rpl_iswalpha 104# define iswalpha rpl_iswalpha
92# define iswblank rpl_iswblank 105# define iswblank rpl_iswblank
@@ -99,86 +112,266 @@
99# define iswspace rpl_iswspace 112# define iswspace rpl_iswspace
100# define iswupper rpl_iswupper 113# define iswupper rpl_iswupper
101# define iswxdigit rpl_iswxdigit 114# define iswxdigit rpl_iswxdigit
115# define towlower rpl_towlower
116# define towupper rpl_towupper
102# endif 117# endif
118# endif
103 119
104static inline int 120static inline int
105iswalnum (wint_t wc) 121# if @REPLACE_ISWCNTRL@
122rpl_iswalnum
123# else
124iswalnum
125# endif
126 (wint_t wc)
106{ 127{
107 return ((wc >= '0' && wc <= '9') 128 return ((wc >= '0' && wc <= '9')
108 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); 129 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
109} 130}
110 131
111static inline int 132static inline int
112iswalpha (wint_t wc) 133# if @REPLACE_ISWCNTRL@
134rpl_iswalpha
135# else
136iswalpha
137# endif
138 (wint_t wc)
113{ 139{
114 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; 140 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
115} 141}
116 142
117static inline int 143static inline int
118iswblank (wint_t wc) 144# if @REPLACE_ISWCNTRL@
145rpl_iswblank
146# else
147iswblank
148# endif
149 (wint_t wc)
119{ 150{
120 return wc == ' ' || wc == '\t'; 151 return wc == ' ' || wc == '\t';
121} 152}
122 153
123static inline int 154static inline int
124iswcntrl (wint_t wc) 155# if @REPLACE_ISWCNTRL@
156rpl_iswcntrl
157# else
158iswcntrl
159# endif
160 (wint_t wc)
125{ 161{
126 return (wc & ~0x1f) == 0 || wc == 0x7f; 162 return (wc & ~0x1f) == 0 || wc == 0x7f;
127} 163}
128 164
129static inline int 165static inline int
130iswdigit (wint_t wc) 166# if @REPLACE_ISWCNTRL@
167rpl_iswdigit
168# else
169iswdigit
170# endif
171 (wint_t wc)
131{ 172{
132 return wc >= '0' && wc <= '9'; 173 return wc >= '0' && wc <= '9';
133} 174}
134 175
135static inline int 176static inline int
136iswgraph (wint_t wc) 177# if @REPLACE_ISWCNTRL@
178rpl_iswgraph
179# else
180iswgraph
181# endif
182 (wint_t wc)
137{ 183{
138 return wc >= '!' && wc <= '~'; 184 return wc >= '!' && wc <= '~';
139} 185}
140 186
141static inline int 187static inline int
142iswlower (wint_t wc) 188# if @REPLACE_ISWCNTRL@
189rpl_iswlower
190# else
191iswlower
192# endif
193 (wint_t wc)
143{ 194{
144 return wc >= 'a' && wc <= 'z'; 195 return wc >= 'a' && wc <= 'z';
145} 196}
146 197
147static inline int 198static inline int
148iswprint (wint_t wc) 199# if @REPLACE_ISWCNTRL@
200rpl_iswprint
201# else
202iswprint
203# endif
204 (wint_t wc)
149{ 205{
150 return wc >= ' ' && wc <= '~'; 206 return wc >= ' ' && wc <= '~';
151} 207}
152 208
153static inline int 209static inline int
154iswpunct (wint_t wc) 210# if @REPLACE_ISWCNTRL@
211rpl_iswpunct
212# else
213iswpunct
214# endif
215 (wint_t wc)
155{ 216{
156 return (wc >= '!' && wc <= '~' 217 return (wc >= '!' && wc <= '~'
157 && !((wc >= '0' && wc <= '9') 218 && !((wc >= '0' && wc <= '9')
158 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); 219 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
159} 220}
160 221
161static inline int 222static inline int
162iswspace (wint_t wc) 223# if @REPLACE_ISWCNTRL@
224rpl_iswspace
225# else
226iswspace
227# endif
228 (wint_t wc)
163{ 229{
164 return (wc == ' ' || wc == '\t' 230 return (wc == ' ' || wc == '\t'
165 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); 231 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
166} 232}
167 233
168static inline int 234static inline int
169iswupper (wint_t wc) 235# if @REPLACE_ISWCNTRL@
236rpl_iswupper
237# else
238iswupper
239# endif
240 (wint_t wc)
170{ 241{
171 return wc >= 'A' && wc <= 'Z'; 242 return wc >= 'A' && wc <= 'Z';
172} 243}
173 244
174static inline int 245static inline int
175iswxdigit (wint_t wc) 246# if @REPLACE_ISWCNTRL@
247rpl_iswxdigit
248# else
249iswxdigit
250# endif
251 (wint_t wc)
176{ 252{
177 return ((wc >= '0' && wc <= '9') 253 return ((wc >= '0' && wc <= '9')
178 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); 254 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
179} 255}
180 256
181# endif /* ! HAVE_ISWCNTRL */ 257static inline wint_t
258# if @REPLACE_ISWCNTRL@
259rpl_towlower
260# else
261towlower
262# endif
263 (wint_t wc)
264{
265 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
266}
267
268static inline wint_t
269# if @REPLACE_ISWCNTRL@
270rpl_towupper
271# else
272towupper
273# endif
274 (wint_t wc)
275{
276 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
277}
278
279#elif ! @HAVE_ISWBLANK@
280/* Only the iswblank function is missing. */
281
282static inline int
283iswblank (wint_t wc)
284{
285 return wc == ' ' || wc == '\t';
286}
287
288#endif
289
290#if defined __MINGW32__
291
292/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
293 The functions towlower and towupper are implemented in the MSVCRT library
294 to take a wchar_t argument and return a wchar_t result. mingw declares
295 these functions to take a wint_t argument and return a wint_t result.
296 This means that:
297 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
298 function will look only at the lower 16 bits. This is allowed according
299 to POSIX.
300 2. The return value is returned in the lower 16 bits of the result register.
301 The upper 16 bits are random: whatever happened to be in that part of the
302 result register. We need to fix this by adding a zero-extend from
303 wchar_t to wint_t after the call. */
304
305static inline wint_t
306rpl_towlower (wint_t wc)
307{
308 return (wint_t) (wchar_t) towlower (wc);
309}
310# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311# define towlower rpl_towlower
312# endif
313
314static inline wint_t
315rpl_towupper (wint_t wc)
316{
317 return (wint_t) (wchar_t) towupper (wc);
318}
319# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
320# define towupper rpl_towupper
321# endif
322
323#endif /* __MINGW32__ */
324
325#if @REPLACE_ISWCNTRL@
326_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
327_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
328_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
329_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
330_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
331_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
332_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
333_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
334_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
335_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
336_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
337_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
338#else
339_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
340_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
341_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
342_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
343_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
344_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
345_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
346_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
347_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
348_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
349_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
350_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
351#endif
352_GL_CXXALIASWARN (iswalnum);
353_GL_CXXALIASWARN (iswalpha);
354_GL_CXXALIASWARN (iswblank);
355_GL_CXXALIASWARN (iswcntrl);
356_GL_CXXALIASWARN (iswdigit);
357_GL_CXXALIASWARN (iswgraph);
358_GL_CXXALIASWARN (iswlower);
359_GL_CXXALIASWARN (iswprint);
360_GL_CXXALIASWARN (iswpunct);
361_GL_CXXALIASWARN (iswspace);
362_GL_CXXALIASWARN (iswupper);
363_GL_CXXALIASWARN (iswxdigit);
364
365#if @REPLACE_ISWCNTRL@ || defined __MINGW32__
366_GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
367_GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
368#else
369_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
370_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
371#endif
372_GL_CXXALIASWARN (towlower);
373_GL_CXXALIASWARN (towupper);
374
182 375
183#endif /* _GL_WCTYPE_H */ 376#endif /* _GL_WCTYPE_H */
184#endif /* _GL_WCTYPE_H */ 377#endif /* _GL_WCTYPE_H */
diff --git a/gl/write.c b/gl/write.c
index 250b5cc8..3a98f24f 100644
--- a/gl/write.c
+++ b/gl/write.c
@@ -1,5 +1,5 @@
1/* POSIX compatible write() function. 1/* POSIX compatible write() function.
2 Copyright (C) 2008 Free Software Foundation, Inc. 2 Copyright (C) 2008-2010 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
@@ -46,14 +46,14 @@ rpl_write (int fd, const void *buf, size_t count)
46 if (ret < 0) 46 if (ret < 0)
47 { 47 {
48 if (GetLastError () == ERROR_NO_DATA 48 if (GetLastError () == ERROR_NO_DATA
49 && GetFileType (_get_osfhandle (fd)) == FILE_TYPE_PIPE) 49 && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)
50 { 50 {
51 /* Try to raise signal SIGPIPE. */ 51 /* Try to raise signal SIGPIPE. */
52 raise (SIGPIPE); 52 raise (SIGPIPE);
53 /* If it is currently blocked or ignored, change errno from EINVAL 53 /* If it is currently blocked or ignored, change errno from EINVAL
54 to EPIPE. */ 54 to EPIPE. */
55 errno = EPIPE; 55 errno = EPIPE;
56 } 56 }
57 } 57 }
58 return ret; 58 return ret;
59} 59}
diff --git a/gl/xalloc-die.c b/gl/xalloc-die.c
index 0a0694fc..4b220403 100644
--- a/gl/xalloc-die.c
+++ b/gl/xalloc-die.c
@@ -1,7 +1,7 @@
1/* Report a memory allocation failure and exit. 1/* Report a memory allocation failure and exit.
2 2
3 Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free 3 Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006, 2009, 2010
4 Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 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 7 it under the terms of the GNU General Public License as published by
diff --git a/gl/xalloc.h b/gl/xalloc.h
index 57a13e0a..6122cc58 100644
--- a/gl/xalloc.h
+++ b/gl/xalloc.h
@@ -1,7 +1,8 @@
1/* xalloc.h -- malloc with out-of-memory checking 1/* xalloc.h -- malloc with out-of-memory checking
2 2
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 1999, 2000, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. 4 2000, 2003, 2004, 2006, 2007, 2008, 2009, 2010 Free Software Foundation,
5 Inc.
5 6
6 This program is free software: you can redistribute it and/or modify 7 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 it under the terms of the GNU General Public License as published by
@@ -105,10 +106,10 @@ char *xstrdup (char const *str) ATTRIBUTE_MALLOC;
105# if HAVE_INLINE 106# if HAVE_INLINE
106# define static_inline static inline 107# define static_inline static inline
107# else 108# else
108 void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC; 109void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
109 void *xnrealloc (void *p, size_t n, size_t s); 110void *xnrealloc (void *p, size_t n, size_t s);
110 void *x2nrealloc (void *p, size_t *pn, size_t s); 111void *x2nrealloc (void *p, size_t *pn, size_t s);
111 char *xcharalloc (size_t n) ATTRIBUTE_MALLOC; 112char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;
112# endif 113# endif
113 114
114# ifdef static_inline 115# ifdef static_inline
@@ -161,9 +162,9 @@ xnrealloc (void *p, size_t n, size_t s)
161 void 162 void
162 append_int (int value) 163 append_int (int value)
163 { 164 {
164 if (used == allocated) 165 if (used == allocated)
165 p = x2nrealloc (p, &allocated, sizeof *p); 166 p = x2nrealloc (p, &allocated, sizeof *p);
166 p[used++] = value; 167 p[used++] = value;
167 } 168 }
168 169
169 This causes x2nrealloc to allocate a block of some nonzero size the 170 This causes x2nrealloc to allocate a block of some nonzero size the
@@ -181,12 +182,12 @@ xnrealloc (void *p, size_t n, size_t s)
181 void 182 void
182 append_int (int value) 183 append_int (int value)
183 { 184 {
184 if (used == allocated) 185 if (used == allocated)
185 { 186 {
186 p = x2nrealloc (p, &allocated1, sizeof *p); 187 p = x2nrealloc (p, &allocated1, sizeof *p);
187 allocated = allocated1; 188 allocated = allocated1;
188 } 189 }
189 p[used++] = value; 190 p[used++] = value;
190 } 191 }
191 192
192 */ 193 */
@@ -199,25 +200,25 @@ x2nrealloc (void *p, size_t *pn, size_t s)
199 if (! p) 200 if (! p)
200 { 201 {
201 if (! n) 202 if (! n)
202 { 203 {
203 /* The approximate size to use for initial small allocation 204 /* The approximate size to use for initial small allocation
204 requests, when the invoking code specifies an old size of 205 requests, when the invoking code specifies an old size of
205 zero. 64 bytes is the largest "small" request for the 206 zero. 64 bytes is the largest "small" request for the
206 GNU C library malloc. */ 207 GNU C library malloc. */
207 enum { DEFAULT_MXFAST = 64 }; 208 enum { DEFAULT_MXFAST = 64 };
208 209
209 n = DEFAULT_MXFAST / s; 210 n = DEFAULT_MXFAST / s;
210 n += !n; 211 n += !n;
211 } 212 }
212 } 213 }
213 else 214 else
214 { 215 {
215 /* Set N = ceil (1.5 * N) so that progress is made if N == 1. 216 /* Set N = ceil (1.5 * N) so that progress is made if N == 1.
216 Check for overflow, so that N * S stays in size_t range. 217 Check for overflow, so that N * S stays in size_t range.
217 The check is slightly conservative, but an exact check isn't 218 The check is slightly conservative, but an exact check isn't
218 worth the trouble. */ 219 worth the trouble. */
219 if ((size_t) -1 / 3 * 2 / s <= n) 220 if ((size_t) -1 / 3 * 2 / s <= n)
220 xalloc_die (); 221 xalloc_die ();
221 n += (n + 1) / 2; 222 n += (n + 1) / 2;
222 } 223 }
223 224
diff --git a/gl/xmalloc.c b/gl/xmalloc.c
index 585fb4b1..ecce5296 100644
--- a/gl/xmalloc.c
+++ b/gl/xmalloc.c
@@ -1,8 +1,8 @@
1/* xmalloc.c -- malloc with out of memory checking 1/* xmalloc.c -- malloc with out of memory checking
2 2
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2008-2009 Free Software Foundation, 4 2000, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Free Software
5 Inc. 5 Foundation, Inc.
6 6
7 This program is free software: you can redistribute it and/or modify 7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
diff --git a/gl/xsize.h b/gl/xsize.h
index 284cf7f6..fbd63290 100644
--- a/gl/xsize.h
+++ b/gl/xsize.h
@@ -1,6 +1,6 @@
1/* xsize.h -- Checked size_t computations. 1/* xsize.h -- Checked size_t computations.
2 2
3 Copyright (C) 2003, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2008, 2009, 2010 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/xstrndup.c b/gl/xstrndup.c
index 37488cd9..414f9f4f 100644
--- a/gl/xstrndup.c
+++ b/gl/xstrndup.c
@@ -1,6 +1,6 @@
1/* Duplicate a bounded initial segment of a string, with out-of-memory 1/* Duplicate a bounded initial segment of a string, with out-of-memory
2 checking. 2 checking.
3 Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/gl/xstrndup.h b/gl/xstrndup.h
index 4882e394..009fdb08 100644
--- a/gl/xstrndup.h
+++ b/gl/xstrndup.h
@@ -1,6 +1,6 @@
1/* Duplicate a bounded initial segment of a string, with out-of-memory 1/* Duplicate a bounded initial segment of a string, with out-of-memory
2 checking. 2 checking.
3 Copyright (C) 2003 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published by
diff --git a/tools/setup b/tools/setup
index 1afe4f15..6da3f674 100755
--- a/tools/setup
+++ b/tools/setup
@@ -23,6 +23,10 @@ if test -d $HOME/share/aclocal ; then
23 extra="-I $HOME/share/aclocal" 23 extra="-I $HOME/share/aclocal"
24fi 24fi
25 25
26# This file will be automagically re-generated of present - still looks
27# better than having a versioned file change based on automake version
28touch build-aux/mkinstalldirs
29
26aclocal -I gl/m4 -I m4 $extra 30aclocal -I gl/m4 -I m4 $extra
27#libtoolize --force --copy 31#libtoolize --force --copy
28autoheader 32autoheader