summaryrefslogtreecommitdiffstats
path: root/gl
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-02-12 11:07:18 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-02-12 11:07:18 (GMT)
commitbd7029a99b0c2974265c6665638ef14a052f42ab (patch)
treef5661ba73366d81ef6e91f889ea7fec5ebe07b6b /gl
parentf99612320d6eda67644c07be04bb21aa4d7789db (diff)
downloadmonitoring-plugins-bd7029a99b0c2974265c6665638ef14a052f42ab.tar.gz
Sync to latest Gnulib
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1925 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'gl')
-rw-r--r--gl/Makefile.am516
-rw-r--r--gl/alloca.c2
-rw-r--r--gl/alloca.in.h (renamed from gl/alloca_.h)10
-rw-r--r--gl/asnprintf.c2
-rw-r--r--gl/asprintf.c10
-rw-r--r--gl/basename.c9
-rw-r--r--gl/c-strtod.c9
-rw-r--r--gl/cloexec.c9
-rwxr-xr-xgl/config.charset649
-rw-r--r--gl/creat-safer.c9
-rw-r--r--gl/dirname.c9
-rw-r--r--gl/dirname.h9
-rw-r--r--gl/dup-safer.c9
-rw-r--r--gl/error.c14
-rw-r--r--gl/error.h15
-rw-r--r--gl/exit.h32
-rw-r--r--gl/exitfail.c15
-rw-r--r--gl/exitfail.h10
-rw-r--r--gl/fcntl--.h9
-rw-r--r--gl/fcntl-safer.h9
-rw-r--r--gl/fd-safer.c9
-rw-r--r--gl/float+.h148
-rw-r--r--gl/float.in.h58
-rw-r--r--gl/fsusage.c9
-rw-r--r--gl/fsusage.h9
-rw-r--r--gl/full-read.c9
-rw-r--r--gl/full-read.h8
-rw-r--r--gl/full-write.c9
-rw-r--r--gl/full-write.h9
-rw-r--r--gl/gai_strerror.c3
-rw-r--r--gl/getaddrinfo.c13
-rw-r--r--gl/getaddrinfo.h2
-rw-r--r--gl/gethostname.c13
-rw-r--r--gl/getloadavg.c46
-rw-r--r--gl/getopt.c11
-rw-r--r--gl/getopt.in.h (renamed from gl/getopt_.h)17
-rw-r--r--gl/getopt1.c11
-rw-r--r--gl/getopt_int.h11
-rw-r--r--gl/gettext.h2
-rw-r--r--gl/inet_ntop.c2
-rw-r--r--gl/inet_ntop.h2
-rw-r--r--gl/intprops.h9
-rw-r--r--gl/localcharset.c460
-rw-r--r--gl/localcharset.h41
-rw-r--r--gl/m4/absolute-header.m411
-rw-r--r--gl/m4/alloca.m48
-rw-r--r--gl/m4/extensions.m452
-rw-r--r--gl/m4/float_h.m419
-rw-r--r--gl/m4/fsusage.m410
-rw-r--r--gl/m4/getaddrinfo.m458
-rw-r--r--gl/m4/getloadavg.m44
-rw-r--r--gl/m4/gettext.m442
-rw-r--r--gl/m4/gnulib-cache.m44
-rw-r--r--gl/m4/gnulib-common.m445
-rw-r--r--gl/m4/gnulib-comp.m4213
-rw-r--r--gl/m4/iconv.m487
-rw-r--r--gl/m4/include_next.m4107
-rw-r--r--gl/m4/intdiv0.m446
-rw-r--r--gl/m4/intl.m436
-rw-r--r--gl/m4/intlmacosx.m451
-rw-r--r--gl/m4/intmax_t.m412
-rw-r--r--gl/m4/lib-link.m42
-rw-r--r--gl/m4/localcharset.m416
-rw-r--r--gl/m4/lock.m411
-rw-r--r--gl/m4/longdouble.m431
-rw-r--r--gl/m4/longlong.m478
-rw-r--r--gl/m4/malloc.m441
-rw-r--r--gl/m4/mbchar.m414
-rw-r--r--gl/m4/mbiter.m417
-rw-r--r--gl/m4/mbrtowc.m431
-rw-r--r--gl/m4/memchr.m418
-rw-r--r--gl/m4/minmax.m441
-rw-r--r--gl/m4/netinet_in_h.m426
-rw-r--r--gl/m4/po.m425
-rw-r--r--gl/m4/printf-posix.m46
-rw-r--r--gl/m4/regex.m480
-rw-r--r--gl/m4/snprintf.m424
-rw-r--r--gl/m4/socklen.m48
-rw-r--r--gl/m4/stdint.m470
-rw-r--r--gl/m4/stdio_h.m485
-rw-r--r--gl/m4/stdlib_h.m442
-rw-r--r--gl/m4/strcase.m439
-rw-r--r--gl/m4/strdup.m411
-rw-r--r--gl/m4/strerror.m447
-rw-r--r--gl/m4/string_h.m487
-rw-r--r--gl/m4/strndup.m413
-rw-r--r--gl/m4/strnlen.m418
-rw-r--r--gl/m4/sys_socket_h.m448
-rw-r--r--gl/m4/uintmax_t.m48
-rw-r--r--gl/m4/ulonglong.m448
-rw-r--r--gl/m4/unistd_h.m471
-rw-r--r--gl/m4/vasnprintf.m4232
-rw-r--r--gl/m4/vasprintf.m430
-rw-r--r--gl/m4/vsnprintf.m424
-rw-r--r--gl/m4/wchar.m439
-rw-r--r--gl/m4/wctype.m415
-rw-r--r--gl/m4/wcwidth.m430
-rw-r--r--gl/m4/wint_t.m42
-rw-r--r--gl/malloc.c32
-rw-r--r--gl/mbchar.c36
-rw-r--r--gl/mbchar.h353
-rw-r--r--gl/mbuiter.h203
-rw-r--r--gl/memchr.c201
-rw-r--r--gl/minmax.h60
-rw-r--r--gl/mountlist.c15
-rw-r--r--gl/mountlist.h9
-rw-r--r--gl/netinet_in.in.h (renamed from gl/strnlen1.h)35
-rw-r--r--gl/open-safer.c9
-rw-r--r--gl/pipe-safer.c9
-rw-r--r--gl/printf-args.c68
-rw-r--r--gl/printf-args.h52
-rw-r--r--gl/printf-parse.c162
-rw-r--r--gl/printf-parse.h117
-rw-r--r--gl/ref-add.sin30
-rw-r--r--gl/ref-del.sin25
-rw-r--r--gl/regcomp.c56
-rw-r--r--gl/regex.c2
-rw-r--r--gl/regex.h52
-rw-r--r--gl/regex_internal.c9
-rw-r--r--gl/regex_internal.h15
-rw-r--r--gl/regexec.c17
-rw-r--r--gl/safe-read.c9
-rw-r--r--gl/safe-read.h9
-rw-r--r--gl/safe-write.c9
-rw-r--r--gl/safe-write.h9
-rw-r--r--gl/size_max.h2
-rw-r--r--gl/snprintf.c9
-rw-r--r--gl/snprintf.h29
-rw-r--r--gl/stdbool.in.h (renamed from gl/stdbool_.h)20
-rw-r--r--gl/stdint.in.h (renamed from gl/stdint_.h)89
-rw-r--r--gl/stdio.in.h382
-rw-r--r--gl/stdlib.in.h208
-rw-r--r--gl/strcase.h56
-rw-r--r--gl/strcasecmp.c103
-rw-r--r--gl/strdup.c10
-rw-r--r--gl/strdup.h39
-rw-r--r--gl/strerror.c49
-rw-r--r--gl/string.in.h569
-rw-r--r--gl/stripslash.c9
-rw-r--r--gl/strncasecmp.c63
-rw-r--r--gl/strndup.c10
-rw-r--r--gl/strndup.h32
-rw-r--r--gl/strnlen.c6
-rw-r--r--gl/strnlen.h32
-rw-r--r--gl/strnlen1.c36
-rw-r--r--gl/sys_socket.in.h (renamed from gl/socket_.h)85
-rw-r--r--gl/unistd--.h9
-rw-r--r--gl/unistd-safer.h9
-rw-r--r--gl/unistd.in.h320
-rw-r--r--gl/unistd_.h52
-rw-r--r--gl/vasnprintf.c4143
-rw-r--r--gl/vasnprintf.h14
-rw-r--r--gl/vasprintf.c10
-rw-r--r--gl/vasprintf.h63
-rw-r--r--gl/vsnprintf.c9
-rw-r--r--gl/vsnprintf.h31
-rw-r--r--gl/wchar.in.h (renamed from gl/wchar_.h)50
-rw-r--r--gl/wctype.in.h (renamed from gl/wctype_.h)21
-rw-r--r--gl/wcwidth.h57
-rw-r--r--gl/xalloc-die.c9
-rw-r--r--gl/xalloc.h29
-rw-r--r--gl/xmalloc.c9
-rw-r--r--gl/xsize.h2
-rw-r--r--gl/xstrndup.c13
-rw-r--r--gl/xstrndup.h9
165 files changed, 9881 insertions, 2919 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 67c9872..92c675e 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -9,7 +9,7 @@
9# the same distribution terms as the rest of that program. 9# the same distribution terms as the rest of that program.
10# 10#
11# Generated by gnulib-tool. 11# Generated by gnulib-tool.
12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=. --no-libtool --macro-prefix=gl dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf 12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=build-aux --no-libtool --macro-prefix=gl dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf
13 13
14AUTOMAKE_OPTIONS = 1.5 gnits 14AUTOMAKE_OPTIONS = 1.5 gnits
15 15
@@ -34,6 +34,15 @@ libgnu_a_LIBADD = $(gl_LIBOBJS)
34libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 34libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
35EXTRA_libgnu_a_SOURCES = 35EXTRA_libgnu_a_SOURCES =
36 36
37## begin gnulib module absolute-header
38
39# Use this preprocessor expression to decide whether #include_next works.
40# Do not rely on a 'configure'-time test for this, since the expression
41# might appear in an installed header, which is used by some other compiler.
42HAVE_INCLUDE_NEXT = (__GNUC__ || 60000000 <= __DECC_VER)
43
44## end gnulib module absolute-header
45
37## begin gnulib module alloca 46## begin gnulib module alloca
38 47
39 48
@@ -51,14 +60,14 @@ BUILT_SOURCES += $(ALLOCA_H)
51 60
52# We need the following in order to create <alloca.h> when the system 61# We need the following in order to create <alloca.h> when the system
53# doesn't have one that works with the given compiler. 62# doesn't have one that works with the given compiler.
54alloca.h: alloca_.h 63alloca.h: alloca.in.h
55 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 64 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
56 cat $(srcdir)/alloca_.h; \ 65 cat $(srcdir)/alloca.in.h; \
57 } > $@-t 66 } > $@-t
58 mv -f $@-t $@ 67 mv -f $@-t $@
59MOSTLYCLEANFILES += alloca.h alloca.h-t 68MOSTLYCLEANFILES += alloca.h alloca.h-t
60 69
61EXTRA_DIST += alloca_.h 70EXTRA_DIST += alloca.in.h
62 71
63## end gnulib module alloca-opt 72## end gnulib module alloca-opt
64 73
@@ -69,7 +78,7 @@ BUILT_SOURCES += $(ARPA_INET_H)
69# We need the following in order to create <arpa/inet.h> when the system 78# We need the following in order to create <arpa/inet.h> when the system
70# doesn't have one. 79# doesn't have one.
71arpa/inet.h: 80arpa/inet.h:
72 test -d arpa || mkdir arpa 81 @MKDIR_P@ arpa
73 rm -f $@-t $@ 82 rm -f $@-t $@
74 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 83 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
75 echo '#include <sys/socket.h>'; \ 84 echo '#include <sys/socket.h>'; \
@@ -98,6 +107,62 @@ EXTRA_libgnu_a_SOURCES += cloexec.c
98 107
99## end gnulib module cloexec 108## end gnulib module cloexec
100 109
110## begin gnulib module configmake
111
112# Retrieve values of the variables through 'configure' followed by
113# 'make', not directly through 'configure', so that a user who
114# sets some of these variables consistently on the 'make' command
115# line gets correct results.
116#
117# One advantage of this approach, compared to the classical
118# approach of adding -DLIBDIR=\"$(libdir)\" etc. to AM_CPPFLAGS,
119# is that it protects against the use of undefined variables.
120# If, say, $(libdir) is not set in the Makefile, LIBDIR is not
121# defined by this module, and code using LIBDIR gives a
122# compilation error.
123#
124# Another advantage is that 'make' output is shorter.
125#
126# Listed in the same order as the GNU makefile conventions.
127# The Automake-defined pkg* macros are appended, in the order
128# listed in the Automake 1.10a+ documentation.
129configmake.h: Makefile
130 rm -f $@-t $@
131 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
132 echo '#define PREFIX "$(prefix)"'; \
133 echo '#define EXEC_PREFIX "$(exec_prefix)"'; \
134 echo '#define BINDIR "$(bindir)"'; \
135 echo '#define SBINDIR "$(sbindir)"'; \
136 echo '#define LIBEXECDIR "$(libexecdir)"'; \
137 echo '#define DATAROOTDIR "$(datarootdir)"'; \
138 echo '#define DATADIR "$(datadir)"'; \
139 echo '#define SYSCONFDIR "$(sysconfdir)"'; \
140 echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \
141 echo '#define LOCALSTATEDIR "$(localstatedir)"'; \
142 echo '#define INCLUDEDIR "$(includedir)"'; \
143 echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \
144 echo '#define DOCDIR "$(docdir)"'; \
145 echo '#define INFODIR "$(infodir)"'; \
146 echo '#define HTMLDIR "$(htmldir)"'; \
147 echo '#define DVIDIR "$(dvidir)"'; \
148 echo '#define PDFDIR "$(pdfdir)"'; \
149 echo '#define PSDIR "$(psdir)"'; \
150 echo '#define LIBDIR "$(libdir)"'; \
151 echo '#define LISPDIR "$(lispdir)"'; \
152 echo '#define LOCALEDIR "$(localedir)"'; \
153 echo '#define MANDIR "$(mandir)"'; \
154 echo '#define MANEXT "$(manext)"'; \
155 echo '#define PKGDATADIR "$(pkgdatadir)"'; \
156 echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \
157 echo '#define PKGLIBDIR "$(pkglibdir)"'; \
158 echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \
159 } | sed '/""/d' > $@-t
160 mv $@-t $@
161BUILT_SOURCES += configmake.h
162CLEANFILES += configmake.h configmake.h-t
163
164## end gnulib module configmake
165
101## begin gnulib module dirname 166## begin gnulib module dirname
102 167
103 168
@@ -116,12 +181,6 @@ EXTRA_libgnu_a_SOURCES += error.c
116 181
117## end gnulib module error 182## end gnulib module error
118 183
119## begin gnulib module exit
120
121libgnu_a_SOURCES += exit.h
122
123## end gnulib module exit
124
125## begin gnulib module exitfail 184## begin gnulib module exitfail
126 185
127 186
@@ -140,6 +199,26 @@ EXTRA_libgnu_a_SOURCES += creat-safer.c open-safer.c
140 199
141## end gnulib module fcntl-safer 200## end gnulib module fcntl-safer
142 201
202## begin gnulib module float
203
204BUILT_SOURCES += $(FLOAT_H)
205
206# We need the following in order to create <float.h> when the system
207# doesn't have one that works with the given compiler.
208float.h: float.in.h
209 rm -f $@-t $@
210 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
211 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
212 -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \
213 < $(srcdir)/float.in.h; \
214 } > $@-t
215 mv $@-t $@
216MOSTLYCLEANFILES += float.h float.h-t
217
218EXTRA_DIST += float.in.h
219
220## end gnulib module float
221
143## begin gnulib module fsusage 222## begin gnulib module fsusage
144 223
145 224
@@ -194,14 +273,14 @@ BUILT_SOURCES += $(GETOPT_H)
194 273
195# We need the following in order to create <getopt.h> when the system 274# We need the following in order to create <getopt.h> when the system
196# doesn't have one that works with the given compiler. 275# doesn't have one that works with the given compiler.
197getopt.h: getopt_.h 276getopt.h: getopt.in.h
198 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 277 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
199 cat $(srcdir)/getopt_.h; \ 278 cat $(srcdir)/getopt.in.h; \
200 } > $@-t 279 } > $@-t
201 mv -f $@-t $@ 280 mv -f $@-t $@
202MOSTLYCLEANFILES += getopt.h getopt.h-t 281MOSTLYCLEANFILES += getopt.h getopt.h-t
203 282
204EXTRA_DIST += getopt.c getopt1.c getopt_.h getopt_int.h 283EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h
205 284
206EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c 285EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c
207 286
@@ -219,6 +298,8 @@ EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c
219# "gettextize --intl". 298# "gettextize --intl".
220AM_CPPFLAGS += -I$(top_builddir)/intl 299AM_CPPFLAGS += -I$(top_builddir)/intl
221 300
301EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
302
222## end gnulib module gettext 303## end gnulib module gettext
223 304
224## begin gnulib module gettext-h 305## begin gnulib module gettext-h
@@ -227,6 +308,13 @@ libgnu_a_SOURCES += gettext.h
227 308
228## end gnulib module gettext-h 309## end gnulib module gettext-h
229 310
311## begin gnulib module havelib
312
313
314EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
315
316## end gnulib module havelib
317
230## begin gnulib module inet_ntop 318## begin gnulib module inet_ntop
231 319
232 320
@@ -243,44 +331,89 @@ EXTRA_DIST += intprops.h
243 331
244## end gnulib module intprops 332## end gnulib module intprops
245 333
246## begin gnulib module malloc 334## begin gnulib module link-warning
247 335
248 336LINK_WARNING_H=$(top_srcdir)/build-aux/link-warning.h
249EXTRA_DIST += malloc.c 337
250 338EXTRA_DIST += $(top_srcdir)/build-aux/link-warning.h
251EXTRA_libgnu_a_SOURCES += malloc.c 339
252 340## end gnulib module link-warning
253## end gnulib module malloc 341
254 342## begin gnulib module localcharset
255## begin gnulib module mbchar 343
344libgnu_a_SOURCES += localcharset.h localcharset.c
345
346# We need the following in order to install a simple file in $(libdir)
347# which is shared with other installed packages. We use a list of referencing
348# packages so that "make uninstall" will remove the file if and only if it
349# is not used by another installed package.
350# On systems with glibc-2.1 or newer, the file is redundant, therefore we
351# avoid installing it.
352
353all-local: charset.alias ref-add.sed ref-del.sed
354
355charset_alias = $(DESTDIR)$(libdir)/charset.alias
356charset_tmp = $(DESTDIR)$(libdir)/charset.tmp
357install-exec-local: all-local
358 test $(GLIBC21) != no || $(mkinstalldirs) $(DESTDIR)$(libdir)
359 if test -f $(charset_alias); then \
360 sed -f ref-add.sed $(charset_alias) > $(charset_tmp) ; \
361 $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
362 rm -f $(charset_tmp) ; \
363 else \
364 if test $(GLIBC21) = no; then \
365 sed -f ref-add.sed charset.alias > $(charset_tmp) ; \
366 $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
367 rm -f $(charset_tmp) ; \
368 fi ; \
369 fi
370
371uninstall-local: all-local
372 if test -f $(charset_alias); then \
373 sed -f ref-del.sed $(charset_alias) > $(charset_tmp); \
374 if grep '^# Packages using this file: $$' $(charset_tmp) \
375 > /dev/null; then \
376 rm -f $(charset_alias); \
377 else \
378 $(INSTALL_DATA) $(charset_tmp) $(charset_alias); \
379 fi; \
380 rm -f $(charset_tmp); \
381 fi
256 382
383charset.alias: config.charset
384 rm -f t-$@ $@
385 $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@
386 mv t-$@ $@
257 387
258EXTRA_DIST += mbchar.c mbchar.h 388SUFFIXES += .sed .sin
389.sin.sed:
390 rm -f t-$@ $@
391 sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@
392 mv t-$@ $@
259 393
260EXTRA_libgnu_a_SOURCES += mbchar.c 394CLEANFILES += charset.alias ref-add.sed ref-del.sed
261 395
262## end gnulib module mbchar 396EXTRA_DIST += config.charset ref-add.sin ref-del.sin
263 397
264## begin gnulib module mbuiter 398## end gnulib module localcharset
265 399
266libgnu_a_SOURCES += mbuiter.h 400## begin gnulib module malloc
267 401
268## end gnulib module mbuiter
269 402
270## begin gnulib module memchr 403EXTRA_DIST += malloc.c
271 404
405EXTRA_libgnu_a_SOURCES += malloc.c
272 406
273EXTRA_DIST += memchr.c 407## end gnulib module malloc
274 408
275EXTRA_libgnu_a_SOURCES += memchr.c 409## begin gnulib module malloc-posix
276 410
277## end gnulib module memchr
278 411
279## begin gnulib module minmax 412EXTRA_DIST += malloc.c
280 413
281libgnu_a_SOURCES += minmax.h 414EXTRA_libgnu_a_SOURCES += malloc.c
282 415
283## end gnulib module minmax 416## end gnulib module malloc-posix
284 417
285## begin gnulib module mountlist 418## begin gnulib module mountlist
286 419
@@ -297,16 +430,21 @@ BUILT_SOURCES += $(NETINET_IN_H)
297 430
298# We need the following in order to create <netinet/in.h> when the system 431# We need the following in order to create <netinet/in.h> when the system
299# doesn't have one. 432# doesn't have one.
300netinet/in.h: 433netinet/in.h: netinet_in.in.h
301 test -d netinet || mkdir netinet 434 @MKDIR_P@ netinet
302 rm -f $@-t $@ 435 rm -f $@-t $@
303 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 436 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
304 echo '#include <sys/socket.h>'; \ 437 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
438 -e 's|@''NEXT_NETINET_IN_H''@|$(NEXT_NETINET_IN_H)|g' \
439 -e 's|@''HAVE_NETINET_IN_H''@|$(HAVE_NETINET_IN_H)|g' \
440 < $(srcdir)/netinet_in.in.h; \
305 } > $@-t 441 } > $@-t
306 mv $@-t $@ 442 mv $@-t $@
307MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t 443MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t
308MOSTLYCLEANDIRS += netinet 444MOSTLYCLEANDIRS += netinet
309 445
446EXTRA_DIST += netinet_in.in.h
447
310## end gnulib module netinet_in 448## end gnulib module netinet_in
311 449
312## begin gnulib module regex 450## begin gnulib module regex
@@ -345,7 +483,7 @@ libgnu_a_SOURCES += size_max.h
345## begin gnulib module snprintf 483## begin gnulib module snprintf
346 484
347 485
348EXTRA_DIST += snprintf.c snprintf.h 486EXTRA_DIST += snprintf.c
349 487
350EXTRA_libgnu_a_SOURCES += snprintf.c 488EXTRA_libgnu_a_SOURCES += snprintf.c
351 489
@@ -357,15 +495,15 @@ BUILT_SOURCES += $(STDBOOL_H)
357 495
358# We need the following in order to create <stdbool.h> when the system 496# We need the following in order to create <stdbool.h> when the system
359# doesn't have one that works. 497# doesn't have one that works.
360stdbool.h: stdbool_.h 498stdbool.h: stdbool.in.h
361 rm -f $@-t $@ 499 rm -f $@-t $@
362 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 500 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
363 sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool_.h; \ 501 sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \
364 } > $@-t 502 } > $@-t
365 mv $@-t $@ 503 mv $@-t $@
366MOSTLYCLEANFILES += stdbool.h stdbool.h-t 504MOSTLYCLEANFILES += stdbool.h stdbool.h-t
367 505
368EXTRA_DIST += stdbool_.h 506EXTRA_DIST += stdbool.in.h
369 507
370## end gnulib module stdbool 508## end gnulib module stdbool
371 509
@@ -375,11 +513,12 @@ BUILT_SOURCES += $(STDINT_H)
375 513
376# We need the following in order to create <stdint.h> when the system 514# We need the following in order to create <stdint.h> when the system
377# doesn't have one that works with the given compiler. 515# doesn't have one that works with the given compiler.
378stdint.h: stdint_.h 516stdint.h: stdint.in.h
379 rm -f $@-t $@ 517 rm -f $@-t $@
380 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 518 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
381 sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ 519 sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
382 -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \ 520 -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
521 -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \
383 -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ 522 -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
384 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ 523 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
385 -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ 524 -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
@@ -399,37 +538,210 @@ stdint.h: stdint_.h
399 -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ 538 -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
400 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ 539 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
401 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ 540 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
402 < $(srcdir)/stdint_.h; \ 541 < $(srcdir)/stdint.in.h; \
403 } > $@-t 542 } > $@-t
404 mv $@-t $@ 543 mv $@-t $@
405MOSTLYCLEANFILES += stdint.h stdint.h-t 544MOSTLYCLEANFILES += stdint.h stdint.h-t
406 545
407EXTRA_DIST += stdint_.h 546EXTRA_DIST += stdint.in.h
408 547
409## end gnulib module stdint 548## end gnulib module stdint
410 549
411## begin gnulib module strcase 550## begin gnulib module stdio
551
552BUILT_SOURCES += stdio.h
553
554# We need the following in order to create <stdio.h> when the system
555# doesn't have one that works with the given compiler.
556stdio.h: stdio.in.h
557 rm -f $@-t $@
558 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
559 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
560 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
561 -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
562 -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \
563 -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
564 -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
565 -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
566 -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
567 -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
568 -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
569 -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
570 -e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \
571 -e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \
572 -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
573 -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
574 -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
575 -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
576 -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
577 -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \
578 -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \
579 -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
580 -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
581 -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \
582 -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \
583 -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
584 -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
585 -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
586 -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
587 -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
588 -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
589 -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
590 -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
591 -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
592 -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \
593 -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
594 -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \
595 -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
596 -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
597 -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
598 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
599 -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
600 -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \
601 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
602 < $(srcdir)/stdio.in.h; \
603 } > $@-t
604 mv $@-t $@
605MOSTLYCLEANFILES += stdio.h stdio.h-t
606
607EXTRA_DIST += stdio.in.h
608
609## end gnulib module stdio
412 610
611## begin gnulib module stdlib
413 612
414EXTRA_DIST += strcase.h strcasecmp.c strncasecmp.c 613BUILT_SOURCES += stdlib.h
614
615# We need the following in order to create <stdlib.h> when the system
616# doesn't have one that works with the given compiler.
617stdlib.h: stdlib.in.h
618 rm -f $@-t $@
619 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
620 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
621 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
622 -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
623 -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
624 -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
625 -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
626 -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
627 -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
628 -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
629 -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
630 -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
631 -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
632 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
633 -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
634 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
635 -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
636 -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
637 -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
638 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
639 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
640 -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \
641 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
642 < $(srcdir)/stdlib.in.h; \
643 } > $@-t
644 mv $@-t $@
645MOSTLYCLEANFILES += stdlib.h stdlib.h-t
415 646
416EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c 647EXTRA_DIST += stdlib.in.h
417 648
418## end gnulib module strcase 649## end gnulib module stdlib
419 650
420## begin gnulib module strdup 651## begin gnulib module strdup
421 652
422 653
423EXTRA_DIST += strdup.c strdup.h 654EXTRA_DIST += strdup.c
424 655
425EXTRA_libgnu_a_SOURCES += strdup.c 656EXTRA_libgnu_a_SOURCES += strdup.c
426 657
427## end gnulib module strdup 658## end gnulib module strdup
428 659
660## begin gnulib module strerror
661
662
663EXTRA_DIST += strerror.c
664
665EXTRA_libgnu_a_SOURCES += strerror.c
666
667## end gnulib module strerror
668
669## begin gnulib module string
670
671BUILT_SOURCES += string.h
672
673# We need the following in order to create <string.h> when the system
674# doesn't have one that works with the given compiler.
675string.h: string.in.h
676 rm -f $@-t $@
677 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
678 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
679 -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \
680 -e 's|@''GNULIB_MBSLEN''@|$(GNULIB_MBSLEN)|g' \
681 -e 's|@''GNULIB_MBSNLEN''@|$(GNULIB_MBSNLEN)|g' \
682 -e 's|@''GNULIB_MBSCHR''@|$(GNULIB_MBSCHR)|g' \
683 -e 's|@''GNULIB_MBSRCHR''@|$(GNULIB_MBSRCHR)|g' \
684 -e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \
685 -e 's|@''GNULIB_MBSCASECMP''@|$(GNULIB_MBSCASECMP)|g' \
686 -e 's|@''GNULIB_MBSNCASECMP''@|$(GNULIB_MBSNCASECMP)|g' \
687 -e 's|@''GNULIB_MBSPCASECMP''@|$(GNULIB_MBSPCASECMP)|g' \
688 -e 's|@''GNULIB_MBSCASESTR''@|$(GNULIB_MBSCASESTR)|g' \
689 -e 's|@''GNULIB_MBSCSPN''@|$(GNULIB_MBSCSPN)|g' \
690 -e 's|@''GNULIB_MBSPBRK''@|$(GNULIB_MBSPBRK)|g' \
691 -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \
692 -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \
693 -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \
694 -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \
695 -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \
696 -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \
697 -e 's|@''GNULIB_STPCPY''@|$(GNULIB_STPCPY)|g' \
698 -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \
699 -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \
700 -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \
701 -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \
702 -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \
703 -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \
704 -e 's|@''GNULIB_STRSEP''@|$(GNULIB_STRSEP)|g' \
705 -e 's|@''GNULIB_STRSTR''@|$(GNULIB_STRSTR)|g' \
706 -e 's|@''GNULIB_STRCASESTR''@|$(GNULIB_STRCASESTR)|g' \
707 -e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \
708 -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \
709 -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \
710 -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
711 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
712 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
713 -e 's|@''HAVE_STPCPY''@|$(HAVE_STPCPY)|g' \
714 -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \
715 -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \
716 -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \
717 -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \
718 -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \
719 -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \
720 -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \
721 -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \
722 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \
723 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
724 -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \
725 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
726 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
727 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
728 -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
729 -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
730 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \
731 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
732 < $(srcdir)/string.in.h; \
733 } > $@-t
734 mv $@-t $@
735MOSTLYCLEANFILES += string.h string.h-t
736
737EXTRA_DIST += string.in.h
738
739## end gnulib module string
740
429## begin gnulib module strndup 741## begin gnulib module strndup
430 742
431 743
432EXTRA_DIST += strndup.c strndup.h 744EXTRA_DIST += strndup.c
433 745
434EXTRA_libgnu_a_SOURCES += strndup.c 746EXTRA_libgnu_a_SOURCES += strndup.c
435 747
@@ -438,53 +750,79 @@ EXTRA_libgnu_a_SOURCES += strndup.c
438## begin gnulib module strnlen 750## begin gnulib module strnlen
439 751
440 752
441EXTRA_DIST += strnlen.c strnlen.h 753EXTRA_DIST += strnlen.c
442 754
443EXTRA_libgnu_a_SOURCES += strnlen.c 755EXTRA_libgnu_a_SOURCES += strnlen.c
444 756
445## end gnulib module strnlen 757## end gnulib module strnlen
446 758
447## begin gnulib module strnlen1
448
449libgnu_a_SOURCES += strnlen1.h strnlen1.c
450
451## end gnulib module strnlen1
452
453## begin gnulib module sys_socket 759## begin gnulib module sys_socket
454 760
455BUILT_SOURCES += $(SYS_SOCKET_H) 761BUILT_SOURCES += $(SYS_SOCKET_H)
456 762
457# We need the following in order to create <sys/socket.h> when the system 763# We need the following in order to create <sys/socket.h> when the system
458# doesn't have one that works with the given compiler. 764# doesn't have one that works with the given compiler.
459sys/socket.h: socket_.h 765sys/socket.h: sys_socket.in.h
460 @MKDIR_P@ sys 766 @MKDIR_P@ sys
461 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 767 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
462 cat $(srcdir)/socket_.h; \ 768 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
769 -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \
770 -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
771 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
772 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
773 < $(srcdir)/sys_socket.in.h; \
463 } > $@-t 774 } > $@-t
464 mv -f $@-t $@ 775 mv -f $@-t $@
465MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t 776MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
466MOSTLYCLEANDIRS += sys 777MOSTLYCLEANDIRS += sys
467 778
468EXTRA_DIST += socket_.h 779EXTRA_DIST += sys_socket.in.h
469 780
470## end gnulib module sys_socket 781## end gnulib module sys_socket
471 782
472## begin gnulib module unistd 783## begin gnulib module unistd
473 784
474BUILT_SOURCES += $(UNISTD_H) 785BUILT_SOURCES += unistd.h
475 786
476# We need the following in order to create an empty placeholder for 787# We need the following in order to create an empty placeholder for
477# <unistd.h> when the system doesn't have one. 788# <unistd.h> when the system doesn't have one.
478unistd.h: unistd_.h 789unistd.h: unistd.in.h
479 rm -f $@-t $@ 790 rm -f $@-t $@
480 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 791 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
481 sed -e 's|@''ABSOLUTE_UNISTD_H''@|$(ABSOLUTE_UNISTD_H)|g' \ 792 sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
482 < $(srcdir)/unistd_.h; \ 793 -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
794 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
795 -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \
796 -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
797 -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
798 -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
799 -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
800 -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
801 -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
802 -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
803 -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
804 -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
805 -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
806 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
807 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
808 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
809 -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
810 -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
811 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
812 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
813 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
814 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
815 -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
816 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
817 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
818 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
819 -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
820 < $(srcdir)/unistd.in.h; \
483 } > $@-t 821 } > $@-t
484 mv $@-t $@ 822 mv $@-t $@
485MOSTLYCLEANFILES += unistd.h unistd.h-t 823MOSTLYCLEANFILES += unistd.h unistd.h-t
486 824
487EXTRA_DIST += unistd_.h 825EXTRA_DIST += unistd.in.h
488 826
489## end gnulib module unistd 827## end gnulib module unistd
490 828
@@ -500,7 +838,7 @@ EXTRA_libgnu_a_SOURCES += dup-safer.c fd-safer.c pipe-safer.c
500## begin gnulib module vasnprintf 838## begin gnulib module vasnprintf
501 839
502 840
503EXTRA_DIST += asnprintf.c printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h 841EXTRA_DIST += asnprintf.c float+.h printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h
504 842
505EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c 843EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c
506 844
@@ -509,7 +847,7 @@ EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c
509## begin gnulib module vasprintf 847## begin gnulib module vasprintf
510 848
511 849
512EXTRA_DIST += asprintf.c vasprintf.c vasprintf.h 850EXTRA_DIST += asprintf.c vasprintf.c
513 851
514EXTRA_libgnu_a_SOURCES += asprintf.c vasprintf.c 852EXTRA_libgnu_a_SOURCES += asprintf.c vasprintf.c
515 853
@@ -518,7 +856,7 @@ EXTRA_libgnu_a_SOURCES += asprintf.c vasprintf.c
518## begin gnulib module vsnprintf 856## begin gnulib module vsnprintf
519 857
520 858
521EXTRA_DIST += vsnprintf.c vsnprintf.h 859EXTRA_DIST += vsnprintf.c
522 860
523EXTRA_libgnu_a_SOURCES += vsnprintf.c 861EXTRA_libgnu_a_SOURCES += vsnprintf.c
524 862
@@ -530,16 +868,22 @@ BUILT_SOURCES += $(WCHAR_H)
530 868
531# We need the following in order to create <wchar.h> when the system 869# We need the following in order to create <wchar.h> when the system
532# version does not work standalone. 870# version does not work standalone.
533wchar.h: wchar_.h 871wchar.h: wchar.in.h
534 rm -f $@-t $@ 872 rm -f $@-t $@
535 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 873 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
536 sed -e 's|@''ABSOLUTE_WCHAR_H''@|$(ABSOLUTE_WCHAR_H)|g' \ 874 sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
537 < $(srcdir)/wchar_.h; \ 875 -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
876 -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
877 -e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \
878 -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
879 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
880 -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
881 < $(srcdir)/wchar.in.h; \
538 } > $@-t 882 } > $@-t
539 mv $@-t $@ 883 mv $@-t $@
540MOSTLYCLEANFILES += wchar.h wchar.h-t 884MOSTLYCLEANFILES += wchar.h wchar.h-t
541 885
542EXTRA_DIST += wchar_.h 886EXTRA_DIST += wchar.in.h
543 887
544## end gnulib module wchar 888## end gnulib module wchar
545 889
@@ -549,28 +893,23 @@ BUILT_SOURCES += $(WCTYPE_H)
549 893
550# We need the following in order to create <wctype.h> when the system 894# We need the following in order to create <wctype.h> when the system
551# doesn't have one that works with the given compiler. 895# doesn't have one that works with the given compiler.
552wctype.h: wctype_.h 896wctype.h: wctype.in.h
553 rm -f $@-t $@ 897 rm -f $@-t $@
554 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 898 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
555 sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ 899 sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \
556 -e 's|@''ABSOLUTE_WCTYPE_H''@|$(ABSOLUTE_WCTYPE_H)|g' \ 900 -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
557 -e 's/@''HAVE_WCTYPE_CTMP_BUG''@/$(HAVE_WCTYPE_CTMP_BUG)/g' \ 901 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
902 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \
558 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ 903 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
559 < $(srcdir)/wctype_.h; \ 904 < $(srcdir)/wctype.in.h; \
560 } > $@-t 905 } > $@-t
561 mv $@-t $@ 906 mv $@-t $@
562MOSTLYCLEANFILES += wctype.h wctype.h-t 907MOSTLYCLEANFILES += wctype.h wctype.h-t
563 908
564EXTRA_DIST += wctype_.h 909EXTRA_DIST += wctype.in.h
565 910
566## end gnulib module wctype 911## end gnulib module wctype
567 912
568## begin gnulib module wcwidth
569
570libgnu_a_SOURCES += wcwidth.h
571
572## end gnulib module wcwidth
573
574## begin gnulib module xalloc 913## begin gnulib module xalloc
575 914
576 915
@@ -604,4 +943,5 @@ mostlyclean-local: mostlyclean-generic
604 if test -n "$$dir" && test -d $$dir; then \ 943 if test -n "$$dir" && test -d $$dir; then \
605 echo "rmdir $$dir"; rmdir $$dir; \ 944 echo "rmdir $$dir"; rmdir $$dir; \
606 fi; \ 945 fi; \
607 done 946 done; \
947 :
diff --git a/gl/alloca.c b/gl/alloca.c
index 3a1f4e2..ff1cb7e 100644
--- a/gl/alloca.c
+++ b/gl/alloca.c
@@ -486,4 +486,4 @@ i00afunc (long address)
486# endif /* CRAY */ 486# endif /* CRAY */
487 487
488# endif /* no alloca */ 488# endif /* no alloca */
489#endif /* not GCC version 2 */ 489#endif /* not GCC version 3 */
diff --git a/gl/alloca_.h b/gl/alloca.in.h
index dd0b3e9..8278288 100644
--- a/gl/alloca_.h
+++ b/gl/alloca.in.h
@@ -1,11 +1,11 @@
1/* Memory allocation on the stack. 1/* Memory allocation on the stack.
2 2
3 Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software 3 Copyright (C) 1995, 1999, 2001-2004, 2006-2007 Free Software
4 Foundation, Inc. 4 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 7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your option) 8 by the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
@@ -20,8 +20,8 @@
20 20
21/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H 21/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
22 means there is a real alloca function. */ 22 means there is a real alloca function. */
23#ifndef _GNULIB_ALLOCA_H 23#ifndef _GL_ALLOCA_H
24# define _GNULIB_ALLOCA_H 24#define _GL_ALLOCA_H
25 25
26/* alloca (N) returns a pointer to N bytes of memory 26/* alloca (N) returns a pointer to N bytes of memory
27 allocated on the stack, which will last until the function returns. 27 allocated on the stack, which will last until the function returns.
@@ -51,4 +51,4 @@ void *alloca (size_t);
51# endif 51# endif
52#endif 52#endif
53 53
54#endif /* _GNULIB_ALLOCA_H */ 54#endif /* _GL_ALLOCA_H */
diff --git a/gl/asnprintf.c b/gl/asnprintf.c
index 26c3988..bf2abf3 100644
--- a/gl/asnprintf.c
+++ b/gl/asnprintf.c
@@ -3,7 +3,7 @@
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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
diff --git a/gl/asprintf.c b/gl/asprintf.c
index 29ac6cf..0bbecf8 100644
--- a/gl/asprintf.c
+++ b/gl/asprintf.c
@@ -1,9 +1,9 @@
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-2007 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -18,7 +18,11 @@
18#include <config.h> 18#include <config.h>
19 19
20/* Specification. */ 20/* Specification. */
21#include "vasprintf.h" 21#ifdef IN_LIBASPRINTF
22# include "vasprintf.h"
23#else
24# include <stdio.h>
25#endif
22 26
23#include <stdarg.h> 27#include <stdarg.h>
24 28
diff --git a/gl/basename.c b/gl/basename.c
index fbe17ff..426ed40 100644
--- a/gl/basename.c
+++ b/gl/basename.c
@@ -3,10 +3,10 @@
3 Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free 3 Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free
4 Software Foundation, Inc. 4 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
diff --git a/gl/c-strtod.c b/gl/c-strtod.c
index 2234ed0..95624cc 100644
--- a/gl/c-strtod.c
+++ b/gl/c-strtod.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2004, 2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/cloexec.c b/gl/cloexec.c
index 6480006..ff8105b 100644
--- a/gl/cloexec.c
+++ b/gl/cloexec.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 1991, 2004, 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 1991, 2004, 2005, 2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 17
19 The code is taken from glibc/manual/llio.texi */ 18 The code is taken from glibc/manual/llio.texi */
20 19
diff --git a/gl/config.charset b/gl/config.charset
new file mode 100755
index 0000000..c233788
--- /dev/null
+++ b/gl/config.charset
@@ -0,0 +1,649 @@
1#! /bin/sh
2# Output a system dependent table of character encoding aliases.
3#
4# Copyright (C) 2000-2004, 2006-2007 Free Software 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, 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# The table consists of lines of the form
21# ALIAS CANONICAL
22#
23# ALIAS is the (system dependent) result of "nl_langinfo (CODESET)".
24# ALIAS is compared in a case sensitive way.
25#
26# CANONICAL is the GNU canonical name for this character encoding.
27# It must be an encoding supported by libiconv. Support by GNU libc is
28# also desirable. CANONICAL is case insensitive. Usually an upper case
29# MIME charset name is preferred.
30# The current list of GNU canonical charset names is as follows.
31#
32# name MIME? used by which systems
33# ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin
34# ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin
35# ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin
36# ISO-8859-3 Y glibc solaris
37# ISO-8859-4 Y osf solaris freebsd netbsd openbsd darwin
38# ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin
39# ISO-8859-6 Y glibc aix hpux solaris
40# ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd openbsd darwin
41# ISO-8859-8 Y glibc aix hpux osf solaris
42# ISO-8859-9 Y glibc aix hpux irix osf solaris darwin
43# ISO-8859-13 glibc netbsd openbsd darwin
44# ISO-8859-14 glibc
45# ISO-8859-15 glibc aix osf solaris freebsd netbsd openbsd darwin
46# KOI8-R Y glibc solaris freebsd netbsd openbsd darwin
47# KOI8-U Y glibc freebsd netbsd openbsd darwin
48# KOI8-T glibc
49# CP437 dos
50# CP775 dos
51# CP850 aix osf dos
52# CP852 dos
53# CP855 dos
54# CP856 aix
55# CP857 dos
56# CP861 dos
57# CP862 dos
58# CP864 dos
59# CP865 dos
60# CP866 freebsd netbsd openbsd darwin dos
61# CP869 dos
62# CP874 woe32 dos
63# CP922 aix
64# CP932 aix woe32 dos
65# CP943 aix
66# CP949 osf woe32 dos
67# CP950 woe32 dos
68# CP1046 aix
69# CP1124 aix
70# CP1125 dos
71# CP1129 aix
72# CP1250 woe32
73# CP1251 glibc solaris netbsd openbsd darwin woe32
74# CP1252 aix woe32
75# CP1253 woe32
76# CP1254 woe32
77# CP1255 glibc woe32
78# CP1256 woe32
79# CP1257 woe32
80# GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin
81# EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin
82# EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin
83# EUC-TW glibc aix hpux irix osf solaris netbsd
84# BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin
85# BIG5-HKSCS glibc solaris
86# GBK glibc aix osf solaris woe32 dos
87# GB18030 glibc solaris netbsd
88# SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin
89# JOHAB glibc solaris woe32
90# TIS-620 glibc aix hpux osf solaris
91# VISCII Y glibc
92# TCVN5712-1 glibc
93# GEORGIAN-PS glibc
94# HP-ROMAN8 hpux
95# HP-ARABIC8 hpux
96# HP-GREEK8 hpux
97# HP-HEBREW8 hpux
98# HP-TURKISH8 hpux
99# HP-KANA8 hpux
100# DEC-KANJI osf
101# DEC-HANYU osf
102# UTF-8 Y glibc aix hpux osf solaris netbsd darwin
103#
104# Note: Names which are not marked as being a MIME name should not be used in
105# Internet protocols for information interchange (mail, news, etc.).
106#
107# Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
108# must understand both names and treat them as equivalent.
109#
110# The first argument passed to this file is the canonical host specification,
111# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
112# or
113# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
114
115host="$1"
116os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'`
117echo "# This file contains a table of character encoding aliases,"
118echo "# suitable for operating system '${os}'."
119echo "# It was automatically generated from config.charset."
120# List of references, updated during installation:
121echo "# Packages using this file: "
122case "$os" in
123 linux-gnulibc1*)
124 # Linux libc5 doesn't have nl_langinfo(CODESET); therefore
125 # localcharset.c falls back to using the full locale name
126 # from the environment variables.
127 echo "C ASCII"
128 echo "POSIX ASCII"
129 for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \
130 en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \
131 en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \
132 es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \
133 et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \
134 fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \
135 it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \
136 sv_FI sv_SE; do
137 echo "$l ISO-8859-1"
138 echo "$l.iso-8859-1 ISO-8859-1"
139 echo "$l.iso-8859-15 ISO-8859-15"
140 echo "$l.iso-8859-15@euro ISO-8859-15"
141 echo "$l@euro ISO-8859-15"
142 echo "$l.cp-437 CP437"
143 echo "$l.cp-850 CP850"
144 echo "$l.cp-1252 CP1252"
145 echo "$l.cp-1252@euro CP1252"
146 #echo "$l.atari-st ATARI-ST" # not a commonly used encoding
147 echo "$l.utf-8 UTF-8"
148 echo "$l.utf-8@euro UTF-8"
149 done
150 for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \
151 sl_SI sr sr_CS sr_YU; do
152 echo "$l ISO-8859-2"
153 echo "$l.iso-8859-2 ISO-8859-2"
154 echo "$l.cp-852 CP852"
155 echo "$l.cp-1250 CP1250"
156 echo "$l.utf-8 UTF-8"
157 done
158 for l in mk mk_MK ru ru_RU; do
159 echo "$l ISO-8859-5"
160 echo "$l.iso-8859-5 ISO-8859-5"
161 echo "$l.koi8-r KOI8-R"
162 echo "$l.cp-866 CP866"
163 echo "$l.cp-1251 CP1251"
164 echo "$l.utf-8 UTF-8"
165 done
166 for l in ar ar_SA; do
167 echo "$l ISO-8859-6"
168 echo "$l.iso-8859-6 ISO-8859-6"
169 echo "$l.cp-864 CP864"
170 #echo "$l.cp-868 CP868" # not a commonly used encoding
171 echo "$l.cp-1256 CP1256"
172 echo "$l.utf-8 UTF-8"
173 done
174 for l in el el_GR gr gr_GR; do
175 echo "$l ISO-8859-7"
176 echo "$l.iso-8859-7 ISO-8859-7"
177 echo "$l.cp-869 CP869"
178 echo "$l.cp-1253 CP1253"
179 echo "$l.cp-1253@euro CP1253"
180 echo "$l.utf-8 UTF-8"
181 echo "$l.utf-8@euro UTF-8"
182 done
183 for l in he he_IL iw iw_IL; do
184 echo "$l ISO-8859-8"
185 echo "$l.iso-8859-8 ISO-8859-8"
186 echo "$l.cp-862 CP862"
187 echo "$l.cp-1255 CP1255"
188 echo "$l.utf-8 UTF-8"
189 done
190 for l in tr tr_TR; do
191 echo "$l ISO-8859-9"
192 echo "$l.iso-8859-9 ISO-8859-9"
193 echo "$l.cp-857 CP857"
194 echo "$l.cp-1254 CP1254"
195 echo "$l.utf-8 UTF-8"
196 done
197 for l in lt lt_LT lv lv_LV; do
198 #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name
199 echo "$l ISO-8859-13"
200 done
201 for l in ru_UA uk uk_UA; do
202 echo "$l KOI8-U"
203 done
204 for l in zh zh_CN; do
205 #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name
206 echo "$l GB2312"
207 done
208 for l in ja ja_JP ja_JP.EUC; do
209 echo "$l EUC-JP"
210 done
211 for l in ko ko_KR; do
212 echo "$l EUC-KR"
213 done
214 for l in th th_TH; do
215 echo "$l TIS-620"
216 done
217 for l in fa fa_IR; do
218 #echo "$l ISIRI-3342" # a broken encoding
219 echo "$l.utf-8 UTF-8"
220 done
221 ;;
222 linux* | *-gnu*)
223 # With glibc-2.1 or newer, we don't need any canonicalization,
224 # because glibc has iconv and both glibc and libiconv support all
225 # GNU canonical names directly. Therefore, the Makefile does not
226 # need to install the alias file at all.
227 # The following applies only to glibc-2.0.x and older libcs.
228 echo "ISO_646.IRV:1983 ASCII"
229 ;;
230 aix*)
231 echo "ISO8859-1 ISO-8859-1"
232 echo "ISO8859-2 ISO-8859-2"
233 echo "ISO8859-5 ISO-8859-5"
234 echo "ISO8859-6 ISO-8859-6"
235 echo "ISO8859-7 ISO-8859-7"
236 echo "ISO8859-8 ISO-8859-8"
237 echo "ISO8859-9 ISO-8859-9"
238 echo "ISO8859-15 ISO-8859-15"
239 echo "IBM-850 CP850"
240 echo "IBM-856 CP856"
241 echo "IBM-921 ISO-8859-13"
242 echo "IBM-922 CP922"
243 echo "IBM-932 CP932"
244 echo "IBM-943 CP943"
245 echo "IBM-1046 CP1046"
246 echo "IBM-1124 CP1124"
247 echo "IBM-1129 CP1129"
248 echo "IBM-1252 CP1252"
249 echo "IBM-eucCN GB2312"
250 echo "IBM-eucJP EUC-JP"
251 echo "IBM-eucKR EUC-KR"
252 echo "IBM-eucTW EUC-TW"
253 echo "big5 BIG5"
254 echo "GBK GBK"
255 echo "TIS-620 TIS-620"
256 echo "UTF-8 UTF-8"
257 ;;
258 hpux*)
259 echo "iso88591 ISO-8859-1"
260 echo "iso88592 ISO-8859-2"
261 echo "iso88595 ISO-8859-5"
262 echo "iso88596 ISO-8859-6"
263 echo "iso88597 ISO-8859-7"
264 echo "iso88598 ISO-8859-8"
265 echo "iso88599 ISO-8859-9"
266 echo "iso885915 ISO-8859-15"
267 echo "roman8 HP-ROMAN8"
268 echo "arabic8 HP-ARABIC8"
269 echo "greek8 HP-GREEK8"
270 echo "hebrew8 HP-HEBREW8"
271 echo "turkish8 HP-TURKISH8"
272 echo "kana8 HP-KANA8"
273 echo "tis620 TIS-620"
274 echo "big5 BIG5"
275 echo "eucJP EUC-JP"
276 echo "eucKR EUC-KR"
277 echo "eucTW EUC-TW"
278 echo "hp15CN GB2312"
279 #echo "ccdc ?" # what is this?
280 echo "SJIS SHIFT_JIS"
281 echo "utf8 UTF-8"
282 ;;
283 irix*)
284 echo "ISO8859-1 ISO-8859-1"
285 echo "ISO8859-2 ISO-8859-2"
286 echo "ISO8859-5 ISO-8859-5"
287 echo "ISO8859-7 ISO-8859-7"
288 echo "ISO8859-9 ISO-8859-9"
289 echo "eucCN GB2312"
290 echo "eucJP EUC-JP"
291 echo "eucKR EUC-KR"
292 echo "eucTW EUC-TW"
293 ;;
294 osf*)
295 echo "ISO8859-1 ISO-8859-1"
296 echo "ISO8859-2 ISO-8859-2"
297 echo "ISO8859-4 ISO-8859-4"
298 echo "ISO8859-5 ISO-8859-5"
299 echo "ISO8859-7 ISO-8859-7"
300 echo "ISO8859-8 ISO-8859-8"
301 echo "ISO8859-9 ISO-8859-9"
302 echo "ISO8859-15 ISO-8859-15"
303 echo "cp850 CP850"
304 echo "big5 BIG5"
305 echo "dechanyu DEC-HANYU"
306 echo "dechanzi GB2312"
307 echo "deckanji DEC-KANJI"
308 echo "deckorean EUC-KR"
309 echo "eucJP EUC-JP"
310 echo "eucKR EUC-KR"
311 echo "eucTW EUC-TW"
312 echo "GBK GBK"
313 echo "KSC5601 CP949"
314 echo "sdeckanji EUC-JP"
315 echo "SJIS SHIFT_JIS"
316 echo "TACTIS TIS-620"
317 echo "UTF-8 UTF-8"
318 ;;
319 solaris*)
320 echo "646 ASCII"
321 echo "ISO8859-1 ISO-8859-1"
322 echo "ISO8859-2 ISO-8859-2"
323 echo "ISO8859-3 ISO-8859-3"
324 echo "ISO8859-4 ISO-8859-4"
325 echo "ISO8859-5 ISO-8859-5"
326 echo "ISO8859-6 ISO-8859-6"
327 echo "ISO8859-7 ISO-8859-7"
328 echo "ISO8859-8 ISO-8859-8"
329 echo "ISO8859-9 ISO-8859-9"
330 echo "ISO8859-15 ISO-8859-15"
331 echo "koi8-r KOI8-R"
332 echo "ansi-1251 CP1251"
333 echo "BIG5 BIG5"
334 echo "Big5-HKSCS BIG5-HKSCS"
335 echo "gb2312 GB2312"
336 echo "GBK GBK"
337 echo "GB18030 GB18030"
338 echo "cns11643 EUC-TW"
339 echo "5601 EUC-KR"
340 echo "ko_KR.johap92 JOHAB"
341 echo "eucJP EUC-JP"
342 echo "PCK SHIFT_JIS"
343 echo "TIS620.2533 TIS-620"
344 #echo "sun_eu_greek ?" # what is this?
345 echo "UTF-8 UTF-8"
346 ;;
347 freebsd* | os2*)
348 # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
349 # localcharset.c falls back to using the full locale name
350 # from the environment variables.
351 # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
352 # reuse FreeBSD's locale data for OS/2.
353 echo "C ASCII"
354 echo "US-ASCII ASCII"
355 for l in la_LN lt_LN; do
356 echo "$l.ASCII ASCII"
357 done
358 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
359 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \
360 lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do
361 echo "$l.ISO_8859-1 ISO-8859-1"
362 echo "$l.DIS_8859-15 ISO-8859-15"
363 done
364 for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do
365 echo "$l.ISO_8859-2 ISO-8859-2"
366 done
367 for l in la_LN lt_LT; do
368 echo "$l.ISO_8859-4 ISO-8859-4"
369 done
370 for l in ru_RU ru_SU; do
371 echo "$l.KOI8-R KOI8-R"
372 echo "$l.ISO_8859-5 ISO-8859-5"
373 echo "$l.CP866 CP866"
374 done
375 echo "uk_UA.KOI8-U KOI8-U"
376 echo "zh_TW.BIG5 BIG5"
377 echo "zh_TW.Big5 BIG5"
378 echo "zh_CN.EUC GB2312"
379 echo "ja_JP.EUC EUC-JP"
380 echo "ja_JP.SJIS SHIFT_JIS"
381 echo "ja_JP.Shift_JIS SHIFT_JIS"
382 echo "ko_KR.EUC EUC-KR"
383 ;;
384 netbsd*)
385 echo "646 ASCII"
386 echo "ISO8859-1 ISO-8859-1"
387 echo "ISO8859-2 ISO-8859-2"
388 echo "ISO8859-4 ISO-8859-4"
389 echo "ISO8859-5 ISO-8859-5"
390 echo "ISO8859-7 ISO-8859-7"
391 echo "ISO8859-13 ISO-8859-13"
392 echo "ISO8859-15 ISO-8859-15"
393 echo "eucCN GB2312"
394 echo "eucJP EUC-JP"
395 echo "eucKR EUC-KR"
396 echo "eucTW EUC-TW"
397 echo "BIG5 BIG5"
398 echo "SJIS SHIFT_JIS"
399 ;;
400 openbsd*)
401 echo "646 ASCII"
402 echo "ISO8859-1 ISO-8859-1"
403 echo "ISO8859-2 ISO-8859-2"
404 echo "ISO8859-4 ISO-8859-4"
405 echo "ISO8859-5 ISO-8859-5"
406 echo "ISO8859-7 ISO-8859-7"
407 echo "ISO8859-13 ISO-8859-13"
408 echo "ISO8859-15 ISO-8859-15"
409 ;;
410 darwin[56]*)
411 # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore
412 # localcharset.c falls back to using the full locale name
413 # from the environment variables.
414 echo "C ASCII"
415 for l in en_AU en_CA en_GB en_US la_LN; do
416 echo "$l.US-ASCII ASCII"
417 done
418 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
419 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \
420 nl_NL no_NO pt_PT sv_SE; do
421 echo "$l ISO-8859-1"
422 echo "$l.ISO8859-1 ISO-8859-1"
423 echo "$l.ISO8859-15 ISO-8859-15"
424 done
425 for l in la_LN; do
426 echo "$l.ISO8859-1 ISO-8859-1"
427 echo "$l.ISO8859-15 ISO-8859-15"
428 done
429 for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do
430 echo "$l.ISO8859-2 ISO-8859-2"
431 done
432 for l in la_LN lt_LT; do
433 echo "$l.ISO8859-4 ISO-8859-4"
434 done
435 for l in ru_RU; do
436 echo "$l.KOI8-R KOI8-R"
437 echo "$l.ISO8859-5 ISO-8859-5"
438 echo "$l.CP866 CP866"
439 done
440 for l in bg_BG; do
441 echo "$l.CP1251 CP1251"
442 done
443 echo "uk_UA.KOI8-U KOI8-U"
444 echo "zh_TW.BIG5 BIG5"
445 echo "zh_TW.Big5 BIG5"
446 echo "zh_CN.EUC GB2312"
447 echo "ja_JP.EUC EUC-JP"
448 echo "ja_JP.SJIS SHIFT_JIS"
449 echo "ko_KR.EUC EUC-KR"
450 ;;
451 darwin*)
452 # Darwin 7.5 has nl_langinfo(CODESET), but it is useless:
453 # - It returns the empty string when LANG is set to a locale of the
454 # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
455 # LC_CTYPE file.
456 # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
457 # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
458 # - The documentation says:
459 # "... all code that calls BSD system routines should ensure
460 # that the const *char parameters of these routines are in UTF-8
461 # encoding. All BSD system functions expect their string
462 # parameters to be in UTF-8 encoding and nothing else."
463 # It also says
464 # "An additional caveat is that string parameters for files,
465 # paths, and other file-system entities must be in canonical
466 # UTF-8. In a canonical UTF-8 Unicode string, all decomposable
467 # characters are decomposed ..."
468 # but this is not true: You can pass non-decomposed UTF-8 strings
469 # to file system functions, and it is the OS which will convert
470 # them to decomposed UTF-8 before accessing the file system.
471 # - The Apple Terminal application displays UTF-8 by default.
472 # - However, other applications are free to use different encodings:
473 # - xterm uses ISO-8859-1 by default.
474 # - TextEdit uses MacRoman by default.
475 # We prefer UTF-8 over decomposed UTF-8-MAC because one should
476 # minimize the use of decomposed Unicode. Unfortunately, through the
477 # Darwin file system, decomposed UTF-8 strings are leaked into user
478 # space nevertheless.
479 echo "* UTF-8"
480 ;;
481 beos*)
482 # BeOS has a single locale, and it has UTF-8 encoding.
483 echo "* UTF-8"
484 ;;
485 msdosdjgpp*)
486 # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore
487 # localcharset.c falls back to using the full locale name
488 # from the environment variables.
489 echo "#"
490 echo "# The encodings given here may not all be correct."
491 echo "# If you find that the encoding given for your language and"
492 echo "# country is not the one your DOS machine actually uses, just"
493 echo "# correct it in this file, and send a mail to"
494 echo "# Juan Manuel Guerrero <juan.guerrero@gmx.de>"
495 echo "# and Bruno Haible <bruno@clisp.org>."
496 echo "#"
497 echo "C ASCII"
498 # ISO-8859-1 languages
499 echo "ca CP850"
500 echo "ca_ES CP850"
501 echo "da CP865" # not CP850 ??
502 echo "da_DK CP865" # not CP850 ??
503 echo "de CP850"
504 echo "de_AT CP850"
505 echo "de_CH CP850"
506 echo "de_DE CP850"
507 echo "en CP850"
508 echo "en_AU CP850" # not CP437 ??
509 echo "en_CA CP850"
510 echo "en_GB CP850"
511 echo "en_NZ CP437"
512 echo "en_US CP437"
513 echo "en_ZA CP850" # not CP437 ??
514 echo "es CP850"
515 echo "es_AR CP850"
516 echo "es_BO CP850"
517 echo "es_CL CP850"
518 echo "es_CO CP850"
519 echo "es_CR CP850"
520 echo "es_CU CP850"
521 echo "es_DO CP850"
522 echo "es_EC CP850"
523 echo "es_ES CP850"
524 echo "es_GT CP850"
525 echo "es_HN CP850"
526 echo "es_MX CP850"
527 echo "es_NI CP850"
528 echo "es_PA CP850"
529 echo "es_PY CP850"
530 echo "es_PE CP850"
531 echo "es_SV CP850"
532 echo "es_UY CP850"
533 echo "es_VE CP850"
534 echo "et CP850"
535 echo "et_EE CP850"
536 echo "eu CP850"
537 echo "eu_ES CP850"
538 echo "fi CP850"
539 echo "fi_FI CP850"
540 echo "fr CP850"
541 echo "fr_BE CP850"
542 echo "fr_CA CP850"
543 echo "fr_CH CP850"
544 echo "fr_FR CP850"
545 echo "ga CP850"
546 echo "ga_IE CP850"
547 echo "gd CP850"
548 echo "gd_GB CP850"
549 echo "gl CP850"
550 echo "gl_ES CP850"
551 echo "id CP850" # not CP437 ??
552 echo "id_ID CP850" # not CP437 ??
553 echo "is CP861" # not CP850 ??
554 echo "is_IS CP861" # not CP850 ??
555 echo "it CP850"
556 echo "it_CH CP850"
557 echo "it_IT CP850"
558 echo "lt CP775"
559 echo "lt_LT CP775"
560 echo "lv CP775"
561 echo "lv_LV CP775"
562 echo "nb CP865" # not CP850 ??
563 echo "nb_NO CP865" # not CP850 ??
564 echo "nl CP850"
565 echo "nl_BE CP850"
566 echo "nl_NL CP850"
567 echo "nn CP865" # not CP850 ??
568 echo "nn_NO CP865" # not CP850 ??
569 echo "no CP865" # not CP850 ??
570 echo "no_NO CP865" # not CP850 ??
571 echo "pt CP850"
572 echo "pt_BR CP850"
573 echo "pt_PT CP850"
574 echo "sv CP850"
575 echo "sv_SE CP850"
576 # ISO-8859-2 languages
577 echo "cs CP852"
578 echo "cs_CZ CP852"
579 echo "hr CP852"
580 echo "hr_HR CP852"
581 echo "hu CP852"
582 echo "hu_HU CP852"
583 echo "pl CP852"
584 echo "pl_PL CP852"
585 echo "ro CP852"
586 echo "ro_RO CP852"
587 echo "sk CP852"
588 echo "sk_SK CP852"
589 echo "sl CP852"
590 echo "sl_SI CP852"
591 echo "sq CP852"
592 echo "sq_AL CP852"
593 echo "sr CP852" # CP852 or CP866 or CP855 ??
594 echo "sr_CS CP852" # CP852 or CP866 or CP855 ??
595 echo "sr_YU CP852" # CP852 or CP866 or CP855 ??
596 # ISO-8859-3 languages
597 echo "mt CP850"
598 echo "mt_MT CP850"
599 # ISO-8859-5 languages
600 echo "be CP866"
601 echo "be_BE CP866"
602 echo "bg CP866" # not CP855 ??
603 echo "bg_BG CP866" # not CP855 ??
604 echo "mk CP866" # not CP855 ??
605 echo "mk_MK CP866" # not CP855 ??
606 echo "ru CP866"
607 echo "ru_RU CP866"
608 echo "uk CP1125"
609 echo "uk_UA CP1125"
610 # ISO-8859-6 languages
611 echo "ar CP864"
612 echo "ar_AE CP864"
613 echo "ar_DZ CP864"
614 echo "ar_EG CP864"
615 echo "ar_IQ CP864"
616 echo "ar_IR CP864"
617 echo "ar_JO CP864"
618 echo "ar_KW CP864"
619 echo "ar_MA CP864"
620 echo "ar_OM CP864"
621 echo "ar_QA CP864"
622 echo "ar_SA CP864"
623 echo "ar_SY CP864"
624 # ISO-8859-7 languages
625 echo "el CP869"
626 echo "el_GR CP869"
627 # ISO-8859-8 languages
628 echo "he CP862"
629 echo "he_IL CP862"
630 # ISO-8859-9 languages
631 echo "tr CP857"
632 echo "tr_TR CP857"
633 # Japanese
634 echo "ja CP932"
635 echo "ja_JP CP932"
636 # Chinese
637 echo "zh_CN GBK"
638 echo "zh_TW CP950" # not CP938 ??
639 # Korean
640 echo "kr CP949" # not CP934 ??
641 echo "kr_KR CP949" # not CP934 ??
642 # Thai
643 echo "th CP874"
644 echo "th_TH CP874"
645 # Other
646 echo "eo CP850"
647 echo "eo_EO CP850"
648 ;;
649esac
diff --git a/gl/creat-safer.c b/gl/creat-safer.c
index f4a2e59..fc314ba 100644
--- a/gl/creat-safer.c
+++ b/gl/creat-safer.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Jim Meyering. */ 18/* Written by Jim Meyering. */
20 19
diff --git a/gl/dirname.c b/gl/dirname.c
index 16552c6..c27e5b5 100644
--- a/gl/dirname.c
+++ b/gl/dirname.c
@@ -3,10 +3,10 @@
3 Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software 3 Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 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
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
diff --git a/gl/dirname.h b/gl/dirname.h
index 91e7ed3..f592350 100644
--- a/gl/dirname.h
+++ b/gl/dirname.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc. 3 Copyright (C) 1998, 2001, 2003-2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19#ifndef DIRNAME_H_ 18#ifndef DIRNAME_H_
20# define DIRNAME_H_ 1 19# define DIRNAME_H_ 1
diff --git a/gl/dup-safer.c b/gl/dup-safer.c
index 7b12b61..a690851 100644
--- a/gl/dup-safer.c
+++ b/gl/dup-safer.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2001, 2004, 2005, 2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/error.c b/gl/error.c
index cf86343..3177bd5 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -1,20 +1,19 @@
1/* Error handler for noninteractive utilities 1/* Error handler for noninteractive utilities
2 Copyright (C) 1990-1998, 2000-2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 1990-1998, 2000-2007 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
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License along 15 You should have received a copy of the GNU General Public License
16 with this program; if not, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ 18/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
20 19
@@ -31,6 +30,7 @@
31 30
32#if !_LIBC && ENABLE_NLS 31#if !_LIBC && ENABLE_NLS
33# include "gettext.h" 32# include "gettext.h"
33# define _(msgid) gettext (msgid)
34#endif 34#endif
35 35
36#ifdef _LIBC 36#ifdef _LIBC
diff --git a/gl/error.h b/gl/error.h
index 5a5f247..6d49681 100644
--- a/gl/error.h
+++ b/gl/error.h
@@ -1,27 +1,26 @@
1/* Declaration for error-reporting function 1/* Declaration for error-reporting function
2 Copyright (C) 1995, 1996, 1997, 2003, 2006 Free Software Foundation, Inc. 2 Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008 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
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License along 15 You should have received a copy of the GNU General Public License
16 with this program; if not, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19#ifndef _ERROR_H 18#ifndef _ERROR_H
20#define _ERROR_H 1 19#define _ERROR_H 1
21 20
22#ifndef __attribute__ 21#ifndef __attribute__
23/* This feature is available in gcc versions 2.5 and later. */ 22/* This feature is available in gcc versions 2.5 and later. */
24# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ 23# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
25# define __attribute__(Spec) /* empty */ 24# define __attribute__(Spec) /* empty */
26# endif 25# endif
27/* The __-protected variants of `format' and `printf' attributes 26/* The __-protected variants of `format' and `printf' attributes
diff --git a/gl/exit.h b/gl/exit.h
deleted file mode 100644
index e8f7738..0000000
--- a/gl/exit.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* exit() function.
2 Copyright (C) 1995, 2001 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 2, 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#ifndef _EXIT_H
19#define _EXIT_H
20
21/* Get exit() declaration. */
22#include <stdlib.h>
23
24/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
25#ifndef EXIT_SUCCESS
26# define EXIT_SUCCESS 0
27#endif
28#ifndef EXIT_FAILURE
29# define EXIT_FAILURE 1
30#endif
31
32#endif /* _EXIT_H */
diff --git a/gl/exitfail.c b/gl/exitfail.c
index 97abc67..6d1fe4a 100644
--- a/gl/exitfail.c
+++ b/gl/exitfail.c
@@ -1,11 +1,11 @@
1/* Failure exit status 1/* Failure exit status
2 2
3 Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2002, 2003, 2005, 2006, 2007 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,13 +13,12 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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; see the file COPYING. 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 If not, write to the Free Software Foundation,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 17
20#include <config.h> 18#include <config.h>
21 19
22#include "exitfail.h" 20#include "exitfail.h"
23#include "exit.h" 21
22#include <stdlib.h>
24 23
25int volatile exit_failure = EXIT_FAILURE; 24int volatile exit_failure = EXIT_FAILURE;
diff --git a/gl/exitfail.h b/gl/exitfail.h
index e46cf9c..713f259 100644
--- a/gl/exitfail.h
+++ b/gl/exitfail.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2002 Free Software Foundation, Inc. 3 Copyright (C) 2002 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,6 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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; see the file COPYING. 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 If not, write to the Free Software Foundation,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 17
20extern int volatile exit_failure; 18extern int volatile exit_failure;
diff --git a/gl/fcntl--.h b/gl/fcntl--.h
index 51b869e..5a6a879 100644
--- a/gl/fcntl--.h
+++ b/gl/fcntl--.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2005 Free Software Foundation, Inc. 3 Copyright (C) 2005 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/fcntl-safer.h b/gl/fcntl-safer.h
index cab6aab..99f3865 100644
--- a/gl/fcntl-safer.h
+++ b/gl/fcntl-safer.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2005 Free Software Foundation, Inc. 3 Copyright (C) 2005 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/fd-safer.c b/gl/fd-safer.c
index 256bfa4..df38c8f 100644
--- a/gl/fd-safer.c
+++ b/gl/fd-safer.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/float+.h b/gl/float+.h
new file mode 100644
index 0000000..240fe36
--- /dev/null
+++ b/gl/float+.h
@@ -0,0 +1,148 @@
1/* Supplemental information about the floating-point formats.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
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#ifndef _FLOATPLUS_H
20#define _FLOATPLUS_H
21
22#include <float.h>
23#include <limits.h>
24
25/* Number of bits in the mantissa of a floating-point number, including the
26 "hidden bit". */
27#if FLT_RADIX == 2
28# define FLT_MANT_BIT FLT_MANT_DIG
29# define DBL_MANT_BIT DBL_MANT_DIG
30# define LDBL_MANT_BIT LDBL_MANT_DIG
31#elif FLT_RADIX == 4
32# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
33# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
34# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
35#elif FLT_RADIX == 16
36# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
37# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
38# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
39#endif
40
41/* Bit mask that can be used to mask the exponent, as an unsigned number. */
42#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
43#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
44#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
45
46/* Number of bits used for the exponent of a floating-point number, including
47 the exponent's sign. */
48#define FLT_EXP_BIT \
49 (FLT_EXP_MASK < 0x100 ? 8 : \
50 FLT_EXP_MASK < 0x200 ? 9 : \
51 FLT_EXP_MASK < 0x400 ? 10 : \
52 FLT_EXP_MASK < 0x800 ? 11 : \
53 FLT_EXP_MASK < 0x1000 ? 12 : \
54 FLT_EXP_MASK < 0x2000 ? 13 : \
55 FLT_EXP_MASK < 0x4000 ? 14 : \
56 FLT_EXP_MASK < 0x8000 ? 15 : \
57 FLT_EXP_MASK < 0x10000 ? 16 : \
58 FLT_EXP_MASK < 0x20000 ? 17 : \
59 FLT_EXP_MASK < 0x40000 ? 18 : \
60 FLT_EXP_MASK < 0x80000 ? 19 : \
61 FLT_EXP_MASK < 0x100000 ? 20 : \
62 FLT_EXP_MASK < 0x200000 ? 21 : \
63 FLT_EXP_MASK < 0x400000 ? 22 : \
64 FLT_EXP_MASK < 0x800000 ? 23 : \
65 FLT_EXP_MASK < 0x1000000 ? 24 : \
66 FLT_EXP_MASK < 0x2000000 ? 25 : \
67 FLT_EXP_MASK < 0x4000000 ? 26 : \
68 FLT_EXP_MASK < 0x8000000 ? 27 : \
69 FLT_EXP_MASK < 0x10000000 ? 28 : \
70 FLT_EXP_MASK < 0x20000000 ? 29 : \
71 FLT_EXP_MASK < 0x40000000 ? 30 : \
72 FLT_EXP_MASK <= 0x7fffffff ? 31 : \
73 32)
74#define DBL_EXP_BIT \
75 (DBL_EXP_MASK < 0x100 ? 8 : \
76 DBL_EXP_MASK < 0x200 ? 9 : \
77 DBL_EXP_MASK < 0x400 ? 10 : \
78 DBL_EXP_MASK < 0x800 ? 11 : \
79 DBL_EXP_MASK < 0x1000 ? 12 : \
80 DBL_EXP_MASK < 0x2000 ? 13 : \
81 DBL_EXP_MASK < 0x4000 ? 14 : \
82 DBL_EXP_MASK < 0x8000 ? 15 : \
83 DBL_EXP_MASK < 0x10000 ? 16 : \
84 DBL_EXP_MASK < 0x20000 ? 17 : \
85 DBL_EXP_MASK < 0x40000 ? 18 : \
86 DBL_EXP_MASK < 0x80000 ? 19 : \
87 DBL_EXP_MASK < 0x100000 ? 20 : \
88 DBL_EXP_MASK < 0x200000 ? 21 : \
89 DBL_EXP_MASK < 0x400000 ? 22 : \
90 DBL_EXP_MASK < 0x800000 ? 23 : \
91 DBL_EXP_MASK < 0x1000000 ? 24 : \
92 DBL_EXP_MASK < 0x2000000 ? 25 : \
93 DBL_EXP_MASK < 0x4000000 ? 26 : \
94 DBL_EXP_MASK < 0x8000000 ? 27 : \
95 DBL_EXP_MASK < 0x10000000 ? 28 : \
96 DBL_EXP_MASK < 0x20000000 ? 29 : \
97 DBL_EXP_MASK < 0x40000000 ? 30 : \
98 DBL_EXP_MASK <= 0x7fffffff ? 31 : \
99 32)
100#define LDBL_EXP_BIT \
101 (LDBL_EXP_MASK < 0x100 ? 8 : \
102 LDBL_EXP_MASK < 0x200 ? 9 : \
103 LDBL_EXP_MASK < 0x400 ? 10 : \
104 LDBL_EXP_MASK < 0x800 ? 11 : \
105 LDBL_EXP_MASK < 0x1000 ? 12 : \
106 LDBL_EXP_MASK < 0x2000 ? 13 : \
107 LDBL_EXP_MASK < 0x4000 ? 14 : \
108 LDBL_EXP_MASK < 0x8000 ? 15 : \
109 LDBL_EXP_MASK < 0x10000 ? 16 : \
110 LDBL_EXP_MASK < 0x20000 ? 17 : \
111 LDBL_EXP_MASK < 0x40000 ? 18 : \
112 LDBL_EXP_MASK < 0x80000 ? 19 : \
113 LDBL_EXP_MASK < 0x100000 ? 20 : \
114 LDBL_EXP_MASK < 0x200000 ? 21 : \
115 LDBL_EXP_MASK < 0x400000 ? 22 : \
116 LDBL_EXP_MASK < 0x800000 ? 23 : \
117 LDBL_EXP_MASK < 0x1000000 ? 24 : \
118 LDBL_EXP_MASK < 0x2000000 ? 25 : \
119 LDBL_EXP_MASK < 0x4000000 ? 26 : \
120 LDBL_EXP_MASK < 0x8000000 ? 27 : \
121 LDBL_EXP_MASK < 0x10000000 ? 28 : \
122 LDBL_EXP_MASK < 0x20000000 ? 29 : \
123 LDBL_EXP_MASK < 0x40000000 ? 30 : \
124 LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
125 32)
126
127/* Number of bits used for a floating-point number: the mantissa (not
128 counting the "hidden bit", since it may or may not be explicit), the
129 exponent, and the sign. */
130#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
131#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
132#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
133
134/* Number of bytes used for a floating-point number.
135 This can be smaller than the 'sizeof'. For example, on i386 systems,
136 'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
137 LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
138 sizeof (long double) = 12 or = 16. */
139#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
140#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
141#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
142
143/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
144typedef int verify_sizeof_flt[2 * (SIZEOF_FLT <= sizeof (float)) - 1];
145typedef int verify_sizeof_dbl[2 * (SIZEOF_DBL <= sizeof (double)) - 1];
146typedef int verify_sizeof_ldbl[2 * (SIZEOF_LDBL <= sizeof (long double)) - 1];
147
148#endif /* _FLOATPLUS_H */
diff --git a/gl/float.in.h b/gl/float.in.h
new file mode 100644
index 0000000..2504032
--- /dev/null
+++ b/gl/float.in.h
@@ -0,0 +1,58 @@
1/* A correct <float.h>.
2
3 Copyright (C) 2007 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#ifndef _GL_FLOAT_H
19
20/* The include_next requires a split double-inclusion guard. */
21#@INCLUDE_NEXT@ @NEXT_FLOAT_H@
22
23#ifndef _GL_FLOAT_H
24#define _GL_FLOAT_H
25
26/* 'long double' properties. */
27#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
28/* Number of mantissa units, in base FLT_RADIX. */
29# undef LDBL_MANT_DIG
30# define LDBL_MANT_DIG 64
31/* Number of decimal digits that is sufficient for representing a number. */
32# undef LDBL_DIG
33# define LDBL_DIG 18
34/* x-1 where x is the smallest representable number > 1. */
35# undef LDBL_EPSILON
36# define LDBL_EPSILON 1.0842021724855044340E-19L
37/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
38# undef LDBL_MIN_EXP
39# define LDBL_MIN_EXP (-16381)
40/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
41# undef LDBL_MAX_EXP
42# define LDBL_MAX_EXP 16384
43/* Minimum positive normalized number. */
44# undef LDBL_MIN
45# define LDBL_MIN 3.3621031431120935063E-4932L
46/* Maximum representable finite number. */
47# undef LDBL_MAX
48# define LDBL_MAX 1.1897314953572317650E+4932L
49/* Minimum e such that 10^e is in the range of normalized numbers. */
50# undef LDBL_MIN_10_EXP
51# define LDBL_MIN_10_EXP (-4931)
52/* Maximum e such that 10^e is in the range of representable finite numbers. */
53# undef LDBL_MAX_10_EXP
54# define LDBL_MAX_10_EXP 4932
55#endif
56
57#endif /* _GL_FLOAT_H */
58#endif /* _GL_FLOAT_H */
diff --git a/gl/fsusage.c b/gl/fsusage.c
index 337bf53..23d40ea 100644
--- a/gl/fsusage.c
+++ b/gl/fsusage.c
@@ -3,10 +3,10 @@
3 Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005, 2006 3 Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005, 2006
4 Free 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
diff --git a/gl/fsusage.h b/gl/fsusage.h
index 7fa9f8d..b32abe1 100644
--- a/gl/fsusage.h
+++ b/gl/fsusage.h
@@ -3,10 +3,10 @@
3 Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005, 2006 Free Software 3 Copyright (C) 1991, 1992, 1997, 2003, 2004, 2005, 2006 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
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20/* Space usage statistics for a file system. Blocks are 512-byte. */ 19/* Space usage statistics for a file system. Blocks are 512-byte. */
21 20
diff --git a/gl/full-read.c b/gl/full-read.c
index 8c3472a..fb7212b 100644
--- a/gl/full-read.c
+++ b/gl/full-read.c
@@ -1,10 +1,10 @@
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 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3 of the License, or
7 any later version. 7 (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 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, 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 16
18#define FULL_READ 17#define FULL_READ
19#include "full-write.c" 18#include "full-write.c"
diff --git a/gl/full-read.h b/gl/full-read.h
index 05d83a7..a341ee0 100644
--- a/gl/full-read.h
+++ b/gl/full-read.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2002 Free Software Foundation, Inc. 3 Copyright (C) 2002 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,7 +14,7 @@
14 14
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, read to the Free Software Foundation, 16 along with this program; if not, read to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 18
19#include <stddef.h> 19#include <stddef.h>
20 20
diff --git a/gl/full-write.c b/gl/full-write.c
index cc16872..51f2d38 100644
--- a/gl/full-write.c
+++ b/gl/full-write.c
@@ -3,10 +3,10 @@
3 Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3 Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006 Free Software Foundation, Inc. 4 2004, 2005, 2006 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
diff --git a/gl/full-write.h b/gl/full-write.h
index d20d2fe..9a80146 100644
--- a/gl/full-write.h
+++ b/gl/full-write.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2002-2003 Free Software Foundation, Inc. 3 Copyright (C) 2002-2003 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19#include <stddef.h> 18#include <stddef.h>
20 19
diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c
index 7f0e034..9e4abbe 100644
--- a/gl/gai_strerror.c
+++ b/gl/gai_strerror.c
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -52,6 +52,7 @@ values[] =
52 { EAI_SERVICE, N_("Servname not supported for ai_socktype") }, 52 { EAI_SERVICE, N_("Servname not supported for ai_socktype") },
53 { EAI_SOCKTYPE, N_("ai_socktype not supported") }, 53 { EAI_SOCKTYPE, N_("ai_socktype not supported") },
54 { EAI_SYSTEM, N_("System error") }, 54 { EAI_SYSTEM, N_("System error") },
55 { EAI_OVERFLOW, N_("Argument buffer too small") },
55#ifdef __USE_GNU 56#ifdef __USE_GNU
56 { EAI_INPROGRESS, N_("Processing request in progress") }, 57 { EAI_INPROGRESS, N_("Processing request in progress") },
57 { EAI_CANCELED, N_("Request canceled") }, 58 { EAI_CANCELED, N_("Request canceled") },
diff --git a/gl/getaddrinfo.c b/gl/getaddrinfo.c
index f523f76..04f0ac2 100644
--- a/gl/getaddrinfo.c
+++ b/gl/getaddrinfo.c
@@ -1,11 +1,11 @@
1/* Get address information (partial implementation). 1/* Get address information (partial implementation).
2 Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software 2 Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 Contributed by Simon Josefsson <simon@josefsson.org>. 4 Contributed by Simon Josefsson <simon@josefsson.org>.
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
@@ -28,9 +28,12 @@
28/* Get calloc. */ 28/* Get calloc. */
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31/* Get memcpy. */ 31/* Get memcpy, strdup. */
32#include <string.h> 32#include <string.h>
33 33
34/* Get snprintf. */
35#include <stdio.h>
36
34#include <stdbool.h> 37#include <stdbool.h>
35 38
36#include "gettext.h" 39#include "gettext.h"
@@ -38,8 +41,6 @@
38#define N_(String) String 41#define N_(String) String
39 42
40#include "inet_ntop.h" 43#include "inet_ntop.h"
41#include "snprintf.h"
42#include "strdup.h"
43 44
44/* BeOS has AF_INET, but not PF_INET. */ 45/* BeOS has AF_INET, but not PF_INET. */
45#ifndef PF_INET 46#ifndef PF_INET
@@ -178,7 +179,7 @@ getaddrinfo (const char *restrict nodename,
178 const char *proto = 179 const char *proto =
179 (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; 180 (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
180 181
181 if (!(hints->ai_flags & AI_NUMERICSERV)) 182 if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV))
182 /* FIXME: Use getservbyname_r if available. */ 183 /* FIXME: Use getservbyname_r if available. */
183 se = getservbyname (servname, proto); 184 se = getservbyname (servname, proto);
184 185
diff --git a/gl/getaddrinfo.h b/gl/getaddrinfo.h
index b4ef242..050b793 100644
--- a/gl/getaddrinfo.h
+++ b/gl/getaddrinfo.h
@@ -5,7 +5,7 @@
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
diff --git a/gl/gethostname.c b/gl/gethostname.c
index eedc40e..169dd4e 100644
--- a/gl/gethostname.c
+++ b/gl/gethostname.c
@@ -1,11 +1,11 @@
1/* gethostname emulation for SysV and POSIX.1. 1/* gethostname emulation for SysV and POSIX.1.
2 2
3 Copyright (C) 1992, 2003, 2006 Free Software Foundation, Inc. 3 Copyright (C) 1992, 2003, 2006, 2008 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* David MacKenzie <djm@gnu.ai.mit.edu> */ 18/* David MacKenzie <djm@gnu.ai.mit.edu> */
20 19
@@ -24,6 +23,8 @@
24# include <sys/utsname.h> 23# include <sys/utsname.h>
25#endif 24#endif
26 25
26#include <string.h>
27
27/* Put up to LEN chars of the host name into NAME. 28/* Put up to LEN chars of the host name into NAME.
28 Null terminate it if the name is shorter than LEN. 29 Null terminate it if the name is shorter than LEN.
29 Return 0 if ok, -1 if error. */ 30 Return 0 if ok, -1 if error. */
diff --git a/gl/getloadavg.c b/gl/getloadavg.c
index cfa6273..5faa8fa 100644
--- a/gl/getloadavg.c
+++ b/gl/getloadavg.c
@@ -1,16 +1,16 @@
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, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994,
4 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006 Free Software 4 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software
5 Foundation, Inc. 5 Foundation, Inc.
6 6
7 NOTE: The canonical source of this file is maintained with gnulib. 7 NOTE: The canonical source of this file is maintained with gnulib.
8 Bugs can be reported to bug-gnulib@gnu.org. 8 Bugs can be reported to bug-gnulib@gnu.org.
9 9
10 This program is free software; you can redistribute it and/or modify 10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by 11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option) 12 the Free Software Foundation; either version 3 of the License, or
13 any later version. 13 (at your option) any later version.
14 14
15 This program is distributed in the hope that it will be useful, 15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +18,7 @@
18 GNU General Public License for more details. 18 GNU General Public License for more details.
19 19
20 You should have received a copy of the GNU General Public License 20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 USA. */
24 22
25/* Compile-time symbols that this file uses: 23/* Compile-time symbols that this file uses:
26 24
@@ -32,6 +30,8 @@
32 If that isn't an option, then just put 30 If that isn't an option, then just put
33 AC_CHECK_FUNCS(pstat_getdynamic) in your 31 AC_CHECK_FUNCS(pstat_getdynamic) in your
34 configure.in file. 32 configure.in file.
33 HAVE_LIBPERFSTAT Define this if your system has the
34 perfstat_cpu_total function in libperfstat (AIX).
35 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. 35 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist.
36 KERNEL_FILE Name of the kernel file to nlist. 36 KERNEL_FILE Name of the kernel file to nlist.
37 LDAV_CVT() Scale the load average from the kernel. 37 LDAV_CVT() Scale the load average from the kernel.
@@ -188,6 +188,8 @@
188# include <sys/socket.h> 188# include <sys/socket.h>
189# include <net/route.h> 189# include <net/route.h>
190# include <sys/table.h> 190# include <sys/table.h>
191/* Tru64 4.0D's table.h redefines sys */
192# undef sys
191# endif 193# endif
192 194
193# if defined (__osf__) && (defined (mips) || defined (__mips__)) 195# if defined (__osf__) && (defined (mips) || defined (__mips__))
@@ -254,7 +256,7 @@
254# define LOAD_AVE_TYPE long 256# define LOAD_AVE_TYPE long
255# endif 257# endif
256 258
257# ifdef _AIX 259# if defined _AIX && ! defined HAVE_LIBPERFSTAT
258# define LOAD_AVE_TYPE long 260# define LOAD_AVE_TYPE long
259# endif 261# endif
260 262
@@ -309,7 +311,7 @@
309# define FSCALE 100.0 311# define FSCALE 100.0
310# endif 312# endif
311 313
312# ifdef _AIX 314# if defined _AIX && !defined HAVE_LIBPERFSTAT
313# define FSCALE 65536.0 315# define FSCALE 65536.0
314# endif 316# endif
315 317
@@ -347,7 +349,7 @@
347# define LDAV_SYMBOL "_Loadavg" 349# define LDAV_SYMBOL "_Loadavg"
348# endif 350# endif
349 351
350# if !defined (LDAV_SYMBOL) && ((defined (hpux) && !defined (hp9000s300)) || defined (_SEQUENT_) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) 352# if !defined (LDAV_SYMBOL) && ((defined (hpux) && !defined (hp9000s300)) || defined (_SEQUENT_) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)) || (defined (_AIX) && !defined(HAVE_LIBPERFSTAT)))
351# define LDAV_SYMBOL "avenrun" 353# define LDAV_SYMBOL "avenrun"
352# endif 354# endif
353 355
@@ -404,6 +406,14 @@
404 406
405# endif /* LOAD_AVE_TYPE */ 407# endif /* LOAD_AVE_TYPE */
406 408
409# if defined HAVE_LIBPERFSTAT
410# include <libperfstat.h>
411# include <sys/proc.h>
412# ifndef SBITS
413# define SBITS 16
414# endif
415# endif
416
407# if defined (__GNU__) && !defined (NeXT) 417# if defined (__GNU__) && !defined (NeXT)
408/* Note that NeXT Openstep defines __GNU__ even though it should not. */ 418/* Note that NeXT Openstep defines __GNU__ even though it should not. */
409/* GNU system acts much like NeXT, for load average purposes, 419/* GNU system acts much like NeXT, for load average purposes,
@@ -568,6 +578,22 @@ getloadavg (double loadavg[], int nelem)
568 578
569# endif /* hpux && HAVE_PSTAT_GETDYNAMIC */ 579# endif /* hpux && HAVE_PSTAT_GETDYNAMIC */
570 580
581# if ! defined LDAV_DONE && defined HAVE_LIBPERFSTAT
582# define LDAV_DONE
583# undef LOAD_AVE_TYPE
584/* Use perfstat_cpu_total because we don't have to be root. */
585 {
586 perfstat_cpu_total_t cpu_stats;
587 int result = perfstat_cpu_total (NULL, &cpu_stats, sizeof cpu_stats, 1);
588 if (result == -1)
589 return result;
590 loadavg[0] = cpu_stats.loadavg[0] / (double)(1 << SBITS);
591 loadavg[1] = cpu_stats.loadavg[1] / (double)(1 << SBITS);
592 loadavg[2] = cpu_stats.loadavg[2] / (double)(1 << SBITS);
593 elem = 3;
594 }
595# endif
596
571# if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) 597# if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__))
572# define LDAV_DONE 598# define LDAV_DONE
573# undef LOAD_AVE_TYPE 599# undef LOAD_AVE_TYPE
diff --git a/gl/getopt.c b/gl/getopt.c
index 3580ad8..3c23601 100644
--- a/gl/getopt.c
+++ b/gl/getopt.c
@@ -6,19 +6,18 @@
6 Free Software Foundation, Inc. 6 Free Software 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
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option) 11 the Free Software Foundation; either version 3 of the License, or
12 any later version. 12 (at your option) any later version.
13 13
14 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18 18
19 You should have received a copy of the GNU General Public License along 19 You should have received a copy of the GNU General Public License
20 with this program; if not, write to the Free Software Foundation, 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 21
23#ifndef _LIBC 22#ifndef _LIBC
24# include <config.h> 23# include <config.h>
diff --git a/gl/getopt_.h b/gl/getopt.in.h
index 27fce3d..d2d3e6e 100644
--- a/gl/getopt_.h
+++ b/gl/getopt.in.h
@@ -1,21 +1,20 @@
1/* Declarations for getopt. 1/* Declarations for getopt.
2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006 2 Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007
3 Free Software Foundation, Inc. 3 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
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License along 16 You should have received a copy of the GNU General Public License
17 with this program; if not, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#ifndef _GETOPT_H 19#ifndef _GETOPT_H
21 20
@@ -101,7 +100,7 @@
101# endif 100# endif
102#endif 101#endif
103 102
104#ifdef __cplusplus 103#ifdef __cplusplus
105extern "C" { 104extern "C" {
106#endif 105#endif
107 106
@@ -216,7 +215,7 @@ extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
216 215
217#endif 216#endif
218 217
219#ifdef __cplusplus 218#ifdef __cplusplus
220} 219}
221#endif 220#endif
222 221
diff --git a/gl/getopt1.c b/gl/getopt1.c
index cc0746e..d6a3ecf 100644
--- a/gl/getopt1.c
+++ b/gl/getopt1.c
@@ -3,19 +3,18 @@
3 Free Software Foundation, Inc. 3 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
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License along 16 You should have received a copy of the GNU General Public License
17 with this program; if not, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#ifdef _LIBC 19#ifdef _LIBC
21# include <getopt.h> 20# include <getopt.h>
diff --git a/gl/getopt_int.h b/gl/getopt_int.h
index 401579f..3c6628b 100644
--- a/gl/getopt_int.h
+++ b/gl/getopt_int.h
@@ -3,19 +3,18 @@
3 Free Software Foundation, Inc. 3 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
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License along 16 You should have received a copy of the GNU General Public License
17 with this program; if not, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#ifndef _GETOPT_INT_H 19#ifndef _GETOPT_INT_H
21#define _GETOPT_INT_H 1 20#define _GETOPT_INT_H 1
diff --git a/gl/gettext.h b/gl/gettext.h
index 9d76ec9..763dd3c 100644
--- a/gl/gettext.h
+++ b/gl/gettext.h
@@ -3,7 +3,7 @@
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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c
index 537b59f..3e266a2 100644
--- a/gl/inet_ntop.c
+++ b/gl/inet_ntop.c
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
diff --git a/gl/inet_ntop.h b/gl/inet_ntop.h
index bd1e085..2897bb4 100644
--- a/gl/inet_ntop.h
+++ b/gl/inet_ntop.h
@@ -3,7 +3,7 @@
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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
diff --git a/gl/intprops.h b/gl/intprops.h
index 34f971c..002161e 100644
--- a/gl/intprops.h
+++ b/gl/intprops.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 3 Copyright (C) 2001, 2002, 2003, 2004, 2005 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/localcharset.c b/gl/localcharset.c
new file mode 100644
index 0000000..4f31948
--- /dev/null
+++ b/gl/localcharset.c
@@ -0,0 +1,460 @@
1/* Determine a canonical name for the current locale's character encoding.
2
3 Copyright (C) 2000-2006 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 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/* Written by Bruno Haible <bruno@clisp.org>. */
20
21#include <config.h>
22
23/* Specification. */
24#include "localcharset.h"
25
26#include <stddef.h>
27#include <stdio.h>
28#include <string.h>
29#include <stdlib.h>
30
31#if defined _WIN32 || defined __WIN32__
32# define WIN32_NATIVE
33#endif
34
35#if defined __EMX__
36/* Assume EMX program runs on OS/2, even if compiled under DOS. */
37# define OS2
38#endif
39
40#if !defined WIN32_NATIVE
41# if HAVE_LANGINFO_CODESET
42# include <langinfo.h>
43# else
44# if 0 /* see comment below */
45# include <locale.h>
46# endif
47# endif
48# ifdef __CYGWIN__
49# define WIN32_LEAN_AND_MEAN
50# include <windows.h>
51# endif
52#elif defined WIN32_NATIVE
53# define WIN32_LEAN_AND_MEAN
54# include <windows.h>
55#endif
56#if defined OS2
57# define INCL_DOS
58# include <os2.h>
59#endif
60
61#if ENABLE_RELOCATABLE
62# include "relocatable.h"
63#else
64# define relocate(pathname) (pathname)
65#endif
66
67/* Get LIBDIR. */
68#ifndef LIBDIR
69# include "configmake.h"
70#endif
71
72#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
73 /* Win32, Cygwin, OS/2, DOS */
74# define ISSLASH(C) ((C) == '/' || (C) == '\\')
75#endif
76
77#ifndef DIRECTORY_SEPARATOR
78# define DIRECTORY_SEPARATOR '/'
79#endif
80
81#ifndef ISSLASH
82# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
83#endif
84
85#if HAVE_DECL_GETC_UNLOCKED
86# undef getc
87# define getc getc_unlocked
88#endif
89
90/* The following static variable is declared 'volatile' to avoid a
91 possible multithread problem in the function get_charset_aliases. If we
92 are running in a threaded environment, and if two threads initialize
93 'charset_aliases' simultaneously, both will produce the same value,
94 and everything will be ok if the two assignments to 'charset_aliases'
95 are atomic. But I don't know what will happen if the two assignments mix. */
96#if __STDC__ != 1
97# define volatile /* empty */
98#endif
99/* Pointer to the contents of the charset.alias file, if it has already been
100 read, else NULL. Its format is:
101 ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */
102static const char * volatile charset_aliases;
103
104/* Return a pointer to the contents of the charset.alias file. */
105static const char *
106get_charset_aliases (void)
107{
108 const char *cp;
109
110 cp = charset_aliases;
111 if (cp == NULL)
112 {
113#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
114 FILE *fp;
115 const char *dir;
116 const char *base = "charset.alias";
117 char *file_name;
118
119 /* Make it possible to override the charset.alias location. This is
120 necessary for running the testsuite before "make install". */
121 dir = getenv ("CHARSETALIASDIR");
122 if (dir == NULL || dir[0] == '\0')
123 dir = relocate (LIBDIR);
124
125 /* Concatenate dir and base into freshly allocated file_name. */
126 {
127 size_t dir_len = strlen (dir);
128 size_t base_len = strlen (base);
129 int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
130 file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
131 if (file_name != NULL)
132 {
133 memcpy (file_name, dir, dir_len);
134 if (add_slash)
135 file_name[dir_len] = DIRECTORY_SEPARATOR;
136 memcpy (file_name + dir_len + add_slash, base, base_len + 1);
137 }
138 }
139
140 if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL)
141 /* Out of memory or file not found, treat it as empty. */
142 cp = "";
143 else
144 {
145 /* Parse the file's contents. */
146 char *res_ptr = NULL;
147 size_t res_size = 0;
148
149 for (;;)
150 {
151 int c;
152 char buf1[50+1];
153 char buf2[50+1];
154 size_t l1, l2;
155 char *old_res_ptr;
156
157 c = getc (fp);
158 if (c == EOF)
159 break;
160 if (c == '\n' || c == ' ' || c == '\t')
161 continue;
162 if (c == '#')
163 {
164 /* Skip comment, to end of line. */
165 do
166 c = getc (fp);
167 while (!(c == EOF || c == '\n'));
168 if (c == EOF)
169 break;
170 continue;
171 }
172 ungetc (c, fp);
173 if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
174 break;
175 l1 = strlen (buf1);
176 l2 = strlen (buf2);
177 old_res_ptr = res_ptr;
178 if (res_size == 0)
179 {
180 res_size = l1 + 1 + l2 + 1;
181 res_ptr = (char *) malloc (res_size + 1);
182 }
183 else
184 {
185 res_size += l1 + 1 + l2 + 1;
186 res_ptr = (char *) realloc (res_ptr, res_size + 1);
187 }
188 if (res_ptr == NULL)
189 {
190 /* Out of memory. */
191 res_size = 0;
192 if (old_res_ptr != NULL)
193 free (old_res_ptr);
194 break;
195 }
196 strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
197 strcpy (res_ptr + res_size - (l2 + 1), buf2);
198 }
199 fclose (fp);
200 if (res_size == 0)
201 cp = "";
202 else
203 {
204 *(res_ptr + res_size) = '\0';
205 cp = res_ptr;
206 }
207 }
208
209 if (file_name != NULL)
210 free (file_name);
211
212#else
213
214# if defined VMS
215 /* To avoid the troubles of an extra file charset.alias_vms in the
216 sources of many GNU packages, simply inline the aliases here. */
217 /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
218 "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
219 section 10.7 "Handling Different Character Sets". */
220 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
221 "ISO8859-2" "\0" "ISO-8859-2" "\0"
222 "ISO8859-5" "\0" "ISO-8859-5" "\0"
223 "ISO8859-7" "\0" "ISO-8859-7" "\0"
224 "ISO8859-8" "\0" "ISO-8859-8" "\0"
225 "ISO8859-9" "\0" "ISO-8859-9" "\0"
226 /* Japanese */
227 "eucJP" "\0" "EUC-JP" "\0"
228 "SJIS" "\0" "SHIFT_JIS" "\0"
229 "DECKANJI" "\0" "DEC-KANJI" "\0"
230 "SDECKANJI" "\0" "EUC-JP" "\0"
231 /* Chinese */
232 "eucTW" "\0" "EUC-TW" "\0"
233 "DECHANYU" "\0" "DEC-HANYU" "\0"
234 "DECHANZI" "\0" "GB2312" "\0"
235 /* Korean */
236 "DECKOREAN" "\0" "EUC-KR" "\0";
237# endif
238
239# if defined WIN32_NATIVE || defined __CYGWIN__
240 /* To avoid the troubles of installing a separate file in the same
241 directory as the DLL and of retrieving the DLL's directory at
242 runtime, simply inline the aliases here. */
243
244 cp = "CP936" "\0" "GBK" "\0"
245 "CP1361" "\0" "JOHAB" "\0"
246 "CP20127" "\0" "ASCII" "\0"
247 "CP20866" "\0" "KOI8-R" "\0"
248 "CP20936" "\0" "GB2312" "\0"
249 "CP21866" "\0" "KOI8-RU" "\0"
250 "CP28591" "\0" "ISO-8859-1" "\0"
251 "CP28592" "\0" "ISO-8859-2" "\0"
252 "CP28593" "\0" "ISO-8859-3" "\0"
253 "CP28594" "\0" "ISO-8859-4" "\0"
254 "CP28595" "\0" "ISO-8859-5" "\0"
255 "CP28596" "\0" "ISO-8859-6" "\0"
256 "CP28597" "\0" "ISO-8859-7" "\0"
257 "CP28598" "\0" "ISO-8859-8" "\0"
258 "CP28599" "\0" "ISO-8859-9" "\0"
259 "CP28605" "\0" "ISO-8859-15" "\0"
260 "CP38598" "\0" "ISO-8859-8" "\0"
261 "CP51932" "\0" "EUC-JP" "\0"
262 "CP51936" "\0" "GB2312" "\0"
263 "CP51949" "\0" "EUC-KR" "\0"
264 "CP51950" "\0" "EUC-TW" "\0"
265 "CP54936" "\0" "GB18030" "\0"
266 "CP65001" "\0" "UTF-8" "\0";
267# endif
268#endif
269
270 charset_aliases = cp;
271 }
272
273 return cp;
274}
275
276/* Determine the current locale's character encoding, and canonicalize it
277 into one of the canonical names listed in config.charset.
278 The result must not be freed; it is statically allocated.
279 If the canonical name cannot be determined, the result is a non-canonical
280 name. */
281
282#ifdef STATIC
283STATIC
284#endif
285const char *
286locale_charset (void)
287{
288 const char *codeset;
289 const char *aliases;
290
291#if !(defined WIN32_NATIVE || defined OS2)
292
293# if HAVE_LANGINFO_CODESET
294
295 /* Most systems support nl_langinfo (CODESET) nowadays. */
296 codeset = nl_langinfo (CODESET);
297
298# ifdef __CYGWIN__
299 /* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always
300 returns "US-ASCII". As long as this is not fixed, return the suffix
301 of the locale name from the environment variables (if present) or
302 the codepage as a number. */
303 if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
304 {
305 const char *locale;
306 static char buf[2 + 10 + 1];
307
308 locale = getenv ("LC_ALL");
309 if (locale == NULL || locale[0] == '\0')
310 {
311 locale = getenv ("LC_CTYPE");
312 if (locale == NULL || locale[0] == '\0')
313 locale = getenv ("LANG");
314 }
315 if (locale != NULL && locale[0] != '\0')
316 {
317 /* If the locale name contains an encoding after the dot, return
318 it. */
319 const char *dot = strchr (locale, '.');
320
321 if (dot != NULL)
322 {
323 const char *modifier;
324
325 dot++;
326 /* Look for the possible @... trailer and remove it, if any. */
327 modifier = strchr (dot, '@');
328 if (modifier == NULL)
329 return dot;
330 if (modifier - dot < sizeof (buf))
331 {
332 memcpy (buf, dot, modifier - dot);
333 buf [modifier - dot] = '\0';
334 return buf;
335 }
336 }
337 }
338
339 /* Woe32 has a function returning the locale's codepage as a number. */
340 sprintf (buf, "CP%u", GetACP ());
341 codeset = buf;
342 }
343# endif
344
345# else
346
347 /* On old systems which lack it, use setlocale or getenv. */
348 const char *locale = NULL;
349
350 /* But most old systems don't have a complete set of locales. Some
351 (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't
352 use setlocale here; it would return "C" when it doesn't support the
353 locale name the user has set. */
354# if 0
355 locale = setlocale (LC_CTYPE, NULL);
356# endif
357 if (locale == NULL || locale[0] == '\0')
358 {
359 locale = getenv ("LC_ALL");
360 if (locale == NULL || locale[0] == '\0')
361 {
362 locale = getenv ("LC_CTYPE");
363 if (locale == NULL || locale[0] == '\0')
364 locale = getenv ("LANG");
365 }
366 }
367
368 /* On some old systems, one used to set locale = "iso8859_1". On others,
369 you set it to "language_COUNTRY.charset". In any case, we resolve it
370 through the charset.alias file. */
371 codeset = locale;
372
373# endif
374
375#elif defined WIN32_NATIVE
376
377 static char buf[2 + 10 + 1];
378
379 /* Woe32 has a function returning the locale's codepage as a number. */
380 sprintf (buf, "CP%u", GetACP ());
381 codeset = buf;
382
383#elif defined OS2
384
385 const char *locale;
386 static char buf[2 + 10 + 1];
387 ULONG cp[3];
388 ULONG cplen;
389
390 /* Allow user to override the codeset, as set in the operating system,
391 with standard language environment variables. */
392 locale = getenv ("LC_ALL");
393 if (locale == NULL || locale[0] == '\0')
394 {
395 locale = getenv ("LC_CTYPE");
396 if (locale == NULL || locale[0] == '\0')
397 locale = getenv ("LANG");
398 }
399 if (locale != NULL && locale[0] != '\0')
400 {
401 /* If the locale name contains an encoding after the dot, return it. */
402 const char *dot = strchr (locale, '.');
403
404 if (dot != NULL)
405 {
406 const char *modifier;
407
408 dot++;
409 /* Look for the possible @... trailer and remove it, if any. */
410 modifier = strchr (dot, '@');
411 if (modifier == NULL)
412 return dot;
413 if (modifier - dot < sizeof (buf))
414 {
415 memcpy (buf, dot, modifier - dot);
416 buf [modifier - dot] = '\0';
417 return buf;
418 }
419 }
420
421 /* Resolve through the charset.alias file. */
422 codeset = locale;
423 }
424 else
425 {
426 /* OS/2 has a function returning the locale's codepage as a number. */
427 if (DosQueryCp (sizeof (cp), cp, &cplen))
428 codeset = "";
429 else
430 {
431 sprintf (buf, "CP%u", cp[0]);
432 codeset = buf;
433 }
434 }
435
436#endif
437
438 if (codeset == NULL)
439 /* The canonical name cannot be determined. */
440 codeset = "";
441
442 /* Resolve alias. */
443 for (aliases = get_charset_aliases ();
444 *aliases != '\0';
445 aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
446 if (strcmp (codeset, aliases) == 0
447 || (aliases[0] == '*' && aliases[1] == '\0'))
448 {
449 codeset = aliases + strlen (aliases) + 1;
450 break;
451 }
452
453 /* Don't return an empty string. GNU libc and GNU libiconv interpret
454 the empty string as denoting "the locale's character encoding",
455 thus GNU libiconv would call this function a second time. */
456 if (codeset[0] == '\0')
457 codeset = "ASCII";
458
459 return codeset;
460}
diff --git a/gl/localcharset.h b/gl/localcharset.h
new file mode 100644
index 0000000..b9a3013
--- /dev/null
+++ b/gl/localcharset.h
@@ -0,0 +1,41 @@
1/* Determine a canonical name for the current locale's character encoding.
2 Copyright (C) 2000-2003 Free Software Foundation, Inc.
3 This file is part of the GNU CHARSET 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#ifndef _LOCALCHARSET_H
20#define _LOCALCHARSET_H
21
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27
28/* Determine the current locale's character encoding, and canonicalize it
29 into one of the canonical names listed in config.charset.
30 The result must not be freed; it is statically allocated.
31 If the canonical name cannot be determined, the result is a non-canonical
32 name. */
33extern const char * locale_charset (void);
34
35
36#ifdef __cplusplus
37}
38#endif
39
40
41#endif /* _LOCALCHARSET_H */
diff --git a/gl/m4/absolute-header.m4 b/gl/m4/absolute-header.m4
index c649df0..5b7a2fc 100644
--- a/gl/m4/absolute-header.m4
+++ b/gl/m4/absolute-header.m4
@@ -1,5 +1,5 @@
1# absolute-header.m4 serial 6 1# absolute-header.m4 serial 7
2dnl Copyright (C) 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2007 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.
@@ -32,7 +32,12 @@ dnl eval is necessary to expand ac_cpp.
32dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell. 32dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
33 AS_VAR_SET(gl_absolute_header, 33 AS_VAR_SET(gl_absolute_header,
34[`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | 34[`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
35sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#;s#^/[^/]#//&#;p;q;}'`]) 35sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
36 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
37 s#^/[^/]#//&#
38 p
39 q
40}'`])
36 fi 41 fi
37 AS_VAR_POPDEF([ac_header_exists])dnl 42 AS_VAR_POPDEF([ac_header_exists])dnl
38 ])dnl 43 ])dnl
diff --git a/gl/m4/alloca.m4 b/gl/m4/alloca.m4
index eb62e0e..95f54a6 100644
--- a/gl/m4/alloca.m4
+++ b/gl/m4/alloca.m4
@@ -1,5 +1,5 @@
1# alloca.m4 serial 7 1# alloca.m4 serial 8
2dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2006, 2007 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.
@@ -39,10 +39,6 @@ AC_DEFUN([gl_FUNC_ALLOCA],
39 ALLOCA_H=alloca.h 39 ALLOCA_H=alloca.h
40 fi 40 fi
41 AC_SUBST([ALLOCA_H]) 41 AC_SUBST([ALLOCA_H])
42
43 AC_DEFINE(HAVE_ALLOCA_H, 1,
44 [Define HAVE_ALLOCA_H for backward compatibility with older code
45 that includes <alloca.h> only if HAVE_ALLOCA_H is defined.])
46]) 42])
47 43
48# Prerequisites of lib/alloca.c. 44# Prerequisites of lib/alloca.c.
diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4
index 143a9e5..bcbb3ce 100644
--- a/gl/m4/extensions.m4
+++ b/gl/m4/extensions.m4
@@ -1,14 +1,14 @@
1# serial 4 -*- Autoconf -*- 1# serial 5 -*- 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 Free Software Foundation, Inc. 4# Copyright (C) 2003, 2006, 2007 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.
8 8
9# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS 9# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS
10# Autoconf. Perhaps we can remove this once we can assume Autoconf 10# Autoconf. Perhaps we can remove this once we can assume Autoconf
11# 2.61 or later everywhere, but since CVS Autoconf mutates rapidly 11# 2.62 or later everywhere, but since CVS Autoconf mutates rapidly
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
@@ -16,26 +16,48 @@
16# ------------------------ 16# ------------------------
17# Enable extensions on systems that normally disable them, 17# Enable extensions on systems that normally disable them,
18# typically due to standards-conformance issues. 18# typically due to standards-conformance issues.
19# Remember that #undef in AH_VERBATIM gets replaced with #define by
20# AC_DEFINE. The goal here is to define all known feature-enabling
21# macros, then, if reports of conflicts are made, disable macros that
22# cause problems on some platforms (such as __EXTENSIONS__).
19AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], 23AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
20[ 24[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
21 AC_BEFORE([$0], [AC_COMPILE_IFELSE]) 25AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
22 AC_BEFORE([$0], [AC_RUN_IFELSE])
23 26
24 AC_REQUIRE([AC_GNU_SOURCE]) 27 AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
25 AC_REQUIRE([AC_AIX]) 28 if test "$MINIX" = yes; then
26 AC_REQUIRE([AC_MINIX]) 29 AC_DEFINE([_POSIX_SOURCE], [1],
30 [Define to 1 if you need to in order for `stat' and other
31 things to work.])
32 AC_DEFINE([_POSIX_1_SOURCE], [2],
33 [Define to 2 if the system does not provide POSIX.1 features
34 except with this defined.])
35 AC_DEFINE([_MINIX], [1],
36 [Define to 1 if on MINIX.])
37 fi
27 38
28 AH_VERBATIM([__EXTENSIONS__], 39 AH_VERBATIM([__EXTENSIONS__],
29[/* Enable extensions on Solaris. */ 40[/* Enable extensions on AIX 3, Interix. */
30#ifndef __EXTENSIONS__ 41#ifndef _ALL_SOURCE
31# undef __EXTENSIONS__ 42# undef _ALL_SOURCE
43#endif
44/* Enable GNU extensions on systems that have them. */
45#ifndef _GNU_SOURCE
46# undef _GNU_SOURCE
32#endif 47#endif
48/* Enable threading extensions on Solaris. */
33#ifndef _POSIX_PTHREAD_SEMANTICS 49#ifndef _POSIX_PTHREAD_SEMANTICS
34# undef _POSIX_PTHREAD_SEMANTICS 50# undef _POSIX_PTHREAD_SEMANTICS
35#endif 51#endif
52/* Enable extensions on HP NonStop. */
36#ifndef _TANDEM_SOURCE 53#ifndef _TANDEM_SOURCE
37# undef _TANDEM_SOURCE 54# undef _TANDEM_SOURCE
38#endif]) 55#endif
56/* Enable general extensions on Solaris. */
57#ifndef __EXTENSIONS__
58# undef __EXTENSIONS__
59#endif
60])
39 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], 61 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
40 [ac_cv_safe_to_define___extensions__], 62 [ac_cv_safe_to_define___extensions__],
41 [AC_COMPILE_IFELSE( 63 [AC_COMPILE_IFELSE(
@@ -46,9 +68,11 @@ AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
46 [ac_cv_safe_to_define___extensions__=no])]) 68 [ac_cv_safe_to_define___extensions__=no])])
47 test $ac_cv_safe_to_define___extensions__ = yes && 69 test $ac_cv_safe_to_define___extensions__ = yes &&
48 AC_DEFINE([__EXTENSIONS__]) 70 AC_DEFINE([__EXTENSIONS__])
71 AC_DEFINE([_ALL_SOURCE])
72 AC_DEFINE([_GNU_SOURCE])
49 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) 73 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
50 AC_DEFINE([_TANDEM_SOURCE]) 74 AC_DEFINE([_TANDEM_SOURCE])
51]) 75])# AC_USE_SYSTEM_EXTENSIONS
52 76
53# gl_USE_SYSTEM_EXTENSIONS 77# gl_USE_SYSTEM_EXTENSIONS
54# ------------------------ 78# ------------------------
diff --git a/gl/m4/float_h.m4 b/gl/m4/float_h.m4
new file mode 100644
index 0000000..d36e3a4
--- /dev/null
+++ b/gl/m4/float_h.m4
@@ -0,0 +1,19 @@
1# float_h.m4 serial 3
2dnl Copyright (C) 2007 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_FLOAT_H],
8[
9 AC_REQUIRE([AC_PROG_CC])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 FLOAT_H=
12 case "$host_os" in
13 beos* | openbsd*)
14 FLOAT_H=float.h
15 gl_CHECK_NEXT_HEADERS([float.h])
16 ;;
17 esac
18 AC_SUBST([FLOAT_H])
19])
diff --git a/gl/m4/fsusage.m4 b/gl/m4/fsusage.m4
index 08bf06c..18eedbc 100644
--- a/gl/m4/fsusage.m4
+++ b/gl/m4/fsusage.m4
@@ -1,8 +1,7 @@
1#serial 22 1#serial 23
2# Obtaining file system usage information. 2# Obtaining file system usage information.
3 3
4# Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software 4# Copyright (C) 1997, 1998, 2000, 2001, 2003-2007 Free Software Foundation, Inc.
5# Foundation, Inc.
6# 5#
7# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
8# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
@@ -55,6 +54,11 @@ one of the corresponding file systems is hard-mounted, but not available.
55statvfs in GNU libc on BeOS operates differently: it only makes a system 54statvfs in GNU libc on BeOS operates differently: it only makes a system
56call. 55call.
57#endif 56#endif
57
58#ifdef __osf__
59"Do not use Tru64's statvfs implementation"
60#endif
61
58#include <sys/statvfs.h>], 62#include <sys/statvfs.h>],
59 [struct statvfs fsd; statvfs (0, &fsd);], 63 [struct statvfs fsd; statvfs (0, &fsd);],
60 fu_cv_sys_stat_statvfs=yes, 64 fu_cv_sys_stat_statvfs=yes,
diff --git a/gl/m4/getaddrinfo.m4 b/gl/m4/getaddrinfo.m4
index db285d9..5d36c19 100644
--- a/gl/m4/getaddrinfo.m4
+++ b/gl/m4/getaddrinfo.m4
@@ -1,15 +1,31 @@
1# getaddrinfo.m4 serial 11 1# getaddrinfo.m4 serial 15
2dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2005, 2006, 2007 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_GETADDRINFO], 7AC_DEFUN([gl_GETADDRINFO],
8[ 8[
9 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
9 AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo]) 10 AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
10 11
12 AC_CHECK_HEADERS_ONCE(netdb.h)
13
11 AC_SEARCH_LIBS(getaddrinfo, [nsl socket]) 14 AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
12 AC_CHECK_FUNCS(getaddrinfo,, [ 15 AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
16 AC_TRY_LINK([
17#include <sys/types.h>
18#ifdef HAVE_SYS_SOCKET_H
19#include <sys/socket.h>
20#endif
21#ifdef HAVE_NETDB_H
22#include <netdb.h>
23#endif
24#include <stddef.h>
25], [getaddrinfo("", "", NULL, NULL);],
26 [gl_cv_func_getaddrinfo=yes],
27 [gl_cv_func_getaddrinfo=no])])
28 if test $gl_cv_func_getaddrinfo = no; then
13 AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32, 29 AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
14 gl_cv_w32_getaddrinfo, [ 30 gl_cv_w32_getaddrinfo, [
15 gl_cv_w32_getaddrinfo=no 31 gl_cv_w32_getaddrinfo=no
@@ -19,21 +35,46 @@ AC_DEFUN([gl_GETADDRINFO],
19#ifdef HAVE_WS2TCPIP_H 35#ifdef HAVE_WS2TCPIP_H
20#include <ws2tcpip.h> 36#include <ws2tcpip.h>
21#endif 37#endif
22], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes) 38#include <stddef.h>
39], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
23 LIBS="$am_save_LIBS"]) 40 LIBS="$am_save_LIBS"])
24 if test "$gl_cv_w32_getaddrinfo" = "yes"; then 41 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
25 LIBS="$LIBS -lws2_32" 42 LIBS="$LIBS -lws2_32"
26 else 43 else
27 AC_LIBOBJ(getaddrinfo) 44 AC_LIBOBJ(getaddrinfo)
28 fi 45 fi
29 ]) 46 fi
47
48 # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
49 # inline function declared in ws2tcpip.h, so we need to get that
50 # header included somehow.
51 AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
52 gl_cv_func_gai_strerror, [
53 AC_TRY_LINK([
54#include <sys/types.h>
55#ifdef HAVE_SYS_SOCKET_H
56#include <sys/socket.h>
57#endif
58#ifdef HAVE_NETDB_H
59#include <netdb.h>
60#endif
61#ifdef HAVE_WS2TCPIP_H
62#include <ws2tcpip.h>
63#endif
64#include <stddef.h>
65], [gai_strerror (NULL);],
66 [gl_cv_func_gai_strerror=yes],
67 [gl_cv_func_gai_strerror=no])])
68 if test $gl_cv_func_gai_strerror = no; then
69 AC_LIBOBJ(gai_strerror)
70 fi
30 71
31 AC_REPLACE_FUNCS(gai_strerror)
32 gl_PREREQ_GETADDRINFO 72 gl_PREREQ_GETADDRINFO
33]) 73])
34 74
35# Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c. 75# Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
36AC_DEFUN([gl_PREREQ_GETADDRINFO], [ 76AC_DEFUN([gl_PREREQ_GETADDRINFO], [
77 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
37 AC_SEARCH_LIBS(gethostbyname, [inet nsl]) 78 AC_SEARCH_LIBS(gethostbyname, [inet nsl])
38 AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet]) 79 AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
39 AC_CHECK_FUNCS(gethostbyname,, [ 80 AC_CHECK_FUNCS(gethostbyname,, [
@@ -46,7 +87,8 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
46#ifdef HAVE_WINSOCK2_H 87#ifdef HAVE_WINSOCK2_H
47#include <winsock2.h> 88#include <winsock2.h>
48#endif 89#endif
49], [gethostbyname(0);], gl_cv_w32_gethostbyname=yes) 90#include <stddef.h>
91], [gethostbyname(NULL);], gl_cv_w32_gethostbyname=yes)
50 LIBS="$am_save_LIBS"]) 92 LIBS="$am_save_LIBS"])
51 if test "$gl_cv_w32_gethostbyname" = "yes"; then 93 if test "$gl_cv_w32_gethostbyname" = "yes"; then
52 LIBS="$LIBS -lws2_32" 94 LIBS="$LIBS -lws2_32"
@@ -56,7 +98,7 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
56 AC_REQUIRE([gl_SOCKET_FAMILIES]) 98 AC_REQUIRE([gl_SOCKET_FAMILIES])
57 AC_REQUIRE([gl_HEADER_SYS_SOCKET]) 99 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
58 AC_REQUIRE([AC_C_INLINE]) 100 AC_REQUIRE([AC_C_INLINE])
59 AC_REQUIRE([AC_GNU_SOURCE]) 101 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
60 AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h) 102 AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
61 AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[ 103 AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
62 /* sys/types.h is not needed according to POSIX, but the 104 /* sys/types.h is not needed according to POSIX, but the
diff --git a/gl/m4/getloadavg.m4 b/gl/m4/getloadavg.m4
index 8243729..c1547c7 100644
--- a/gl/m4/getloadavg.m4
+++ b/gl/m4/getloadavg.m4
@@ -31,6 +31,10 @@ AC_CHECK_FUNCS(pstat_getdynamic)
31AC_CHECK_LIB(kstat, kstat_open) 31AC_CHECK_LIB(kstat, kstat_open)
32test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes 32test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
33 33
34# AIX has libperfstat which does not require root
35AC_CHECK_LIB(perfstat, perfstat_cpu_total)
36test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
37
34# Some systems with -lutil have (and need) -lkvm as well, some do not. 38# Some systems with -lutil have (and need) -lkvm as well, some do not.
35# On Solaris, -lkvm requires nlist from -lelf, so check that first 39# On Solaris, -lkvm requires nlist from -lelf, so check that first
36# to get the right answer into the cache. 40# to get the right answer into the cache.
diff --git a/gl/m4/gettext.m4 b/gl/m4/gettext.m4
index 91c345e..c9ae1f7 100644
--- a/gl/m4/gettext.m4
+++ b/gl/m4/gettext.m4
@@ -1,5 +1,5 @@
1# gettext.m4 serial 59 (gettext-0.16.1) 1# gettext.m4 serial 60 (gettext-0.17)
2dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2007 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.
@@ -362,44 +362,6 @@ return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_a
362]) 362])
363 363
364 364
365dnl Checks for special options needed on MacOS X.
366dnl Defines INTL_MACOSX_LIBS.
367AC_DEFUN([gt_INTL_MACOSX],
368[
369 dnl Check for API introduced in MacOS X 10.2.
370 AC_CACHE_CHECK([for CFPreferencesCopyAppValue],
371 gt_cv_func_CFPreferencesCopyAppValue,
372 [gt_save_LIBS="$LIBS"
373 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
374 AC_TRY_LINK([#include <CoreFoundation/CFPreferences.h>],
375 [CFPreferencesCopyAppValue(NULL, NULL)],
376 [gt_cv_func_CFPreferencesCopyAppValue=yes],
377 [gt_cv_func_CFPreferencesCopyAppValue=no])
378 LIBS="$gt_save_LIBS"])
379 if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
380 AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1,
381 [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
382 fi
383 dnl Check for API introduced in MacOS X 10.3.
384 AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent,
385 [gt_save_LIBS="$LIBS"
386 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
387 AC_TRY_LINK([#include <CoreFoundation/CFLocale.h>], [CFLocaleCopyCurrent();],
388 [gt_cv_func_CFLocaleCopyCurrent=yes],
389 [gt_cv_func_CFLocaleCopyCurrent=no])
390 LIBS="$gt_save_LIBS"])
391 if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
392 AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1,
393 [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.])
394 fi
395 INTL_MACOSX_LIBS=
396 if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
397 INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
398 fi
399 AC_SUBST([INTL_MACOSX_LIBS])
400])
401
402
403dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. 365dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
404m4_define([gt_NEEDS_INIT], 366m4_define([gt_NEEDS_INIT],
405[ 367[
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index e78c860..6da4d65 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
15 15
16 16
17# Specification in the form of a command-line invocation: 17# Specification in the form of a command-line invocation:
18# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=. --no-libtool --macro-prefix=gl dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf 18# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=build-aux --no-libtool --macro-prefix=gl dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf
19 19
20# Specification in the form of a few gnulib-tool.m4 macro invocations: 20# Specification in the form of a few gnulib-tool.m4 macro invocations:
21gl_LOCAL_DIR([]) 21gl_LOCAL_DIR([])
@@ -23,8 +23,10 @@ gl_MODULES([dirname fsusage getaddrinfo gethostname getloadavg getopt gettext mo
23gl_AVOID([]) 23gl_AVOID([])
24gl_SOURCE_BASE([gl]) 24gl_SOURCE_BASE([gl])
25gl_M4_BASE([gl/m4]) 25gl_M4_BASE([gl/m4])
26gl_PO_BASE([])
26gl_DOC_BASE([doc]) 27gl_DOC_BASE([doc])
27gl_TESTS_BASE([tests]) 28gl_TESTS_BASE([tests])
28gl_LIB([libgnu]) 29gl_LIB([libgnu])
29gl_MAKEFILE_NAME([]) 30gl_MAKEFILE_NAME([])
30gl_MACRO_PREFIX([gl]) 31gl_MACRO_PREFIX([gl])
32gl_PO_DOMAIN([])
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index 5398010..9336d72 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
1# gnulib-common.m4 serial 2 1# gnulib-common.m4 serial 3
2dnl Copyright (C) 2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2007 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,
@@ -20,3 +20,46 @@ m4_ifdef([AC_PROG_MKDIR_P], [], [
20 [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake 20 [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
21 MKDIR_P='$(mkdir_p)' 21 MKDIR_P='$(mkdir_p)'
22 AC_SUBST([MKDIR_P])])]) 22 AC_SUBST([MKDIR_P])])])
23
24# AC_C_RESTRICT
25# This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61,
26# so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++
27# works.
28# This definition can be removed once autoconf >= 2.62 can be assumed.
29AC_DEFUN([AC_C_RESTRICT],
30[AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
31 [ac_cv_c_restrict=no
32 # The order here caters to the fact that C++ does not require restrict.
33 for ac_kw in __restrict __restrict__ _Restrict restrict; do
34 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
35 [[typedef int * int_ptr;
36 int foo (int_ptr $ac_kw ip) {
37 return ip[0];
38 }]],
39 [[int s[1];
40 int * $ac_kw t = s;
41 t[0] = 0;
42 return foo(t)]])],
43 [ac_cv_c_restrict=$ac_kw])
44 test "$ac_cv_c_restrict" != no && break
45 done
46 ])
47 AH_VERBATIM([restrict],
48[/* Define to the equivalent of the C99 'restrict' keyword, or to
49 nothing if this is not supported. Do not define if restrict is
50 supported directly. */
51#undef restrict
52/* Work around a bug in Sun C++: it does not support _Restrict, even
53 though the corresponding Sun C compiler does, which causes
54 "#define restrict _Restrict" in the previous line. Perhaps some future
55 version of Sun C++ will work with _Restrict; if so, it'll probably
56 define __RESTRICT, just as Sun C does. */
57#if defined __SUNPRO_CC && !defined __RESTRICT
58# define _Restrict
59#endif])
60 case $ac_cv_c_restrict in
61 restrict) ;;
62 no) AC_DEFINE([restrict], []) ;;
63 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
64 esac
65])
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index ed4da7d..a17e36a 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -27,78 +27,94 @@ AC_DEFUN([gl_EARLY],
27 AC_REQUIRE([AC_PROG_RANLIB]) 27 AC_REQUIRE([AC_PROG_RANLIB])
28 AC_REQUIRE([AC_GNU_SOURCE]) 28 AC_REQUIRE([AC_GNU_SOURCE])
29 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 29 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
30 AC_REQUIRE([gl_LOCK_EARLY])
31]) 30])
32 31
33# This macro should be invoked from ./configure.in, in the section 32# This macro should be invoked from ./configure.in, in the section
34# "Check for header files, types and library functions". 33# "Check for header files, types and library functions".
35AC_DEFUN([gl_INIT], 34AC_DEFUN([gl_INIT],
36[ 35[
37 m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ]))
38 m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS]))
39 m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES]))
40 AM_CONDITIONAL([GL_COND_LIBTOOL], [false]) 36 AM_CONDITIONAL([GL_COND_LIBTOOL], [false])
41 gl_cond_libtool=false 37 gl_cond_libtool=false
42 gl_libdeps= 38 gl_libdeps=
43 gl_ltlibdeps= 39 gl_ltlibdeps=
40 m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ]))
41 m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS]))
42 m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES]))
44 gl_source_base='gl' 43 gl_source_base='gl'
45 gl_FUNC_ALLOCA 44 gl_FUNC_ALLOCA
46 gl_HEADER_ARPA_INET 45 gl_HEADER_ARPA_INET
46 AC_PROG_MKDIR_P
47 gl_C_STRTOD 47 gl_C_STRTOD
48 gl_CLOEXEC 48 gl_CLOEXEC
49 gl_DIRNAME 49 gl_DIRNAME
50 gl_DOUBLE_SLASH_ROOT 50 gl_DOUBLE_SLASH_ROOT
51 gl_ERROR 51 gl_ERROR
52 m4_ifdef([AM_XGETTEXT_OPTION],
53 [AM_XGETTEXT_OPTION([--flag=error:3:c-format])
54 AM_XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
52 gl_EXITFAIL 55 gl_EXITFAIL
53 dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac.
54 gl_FCNTL_SAFER 56 gl_FCNTL_SAFER
55 gl_MODULE_INDICATOR([fcntl-safer]) 57 gl_MODULE_INDICATOR([fcntl-safer])
58 gl_FLOAT_H
56 gl_FSUSAGE 59 gl_FSUSAGE
57 gl_GETADDRINFO 60 gl_GETADDRINFO
58 gl_FUNC_GETHOSTNAME 61 gl_FUNC_GETHOSTNAME
59 gl_GETLOADAVG([$gl_source_base]) 62 gl_GETLOADAVG([$gl_source_base])
60 gl_GETOPT 63 gl_GETOPT
61 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. 64 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac.
62 AM_GNU_GETTEXT_VERSION([0.15]) 65 AM_GNU_GETTEXT_VERSION([0.17])
66 AC_SUBST([LIBINTL])
67 AC_SUBST([LTLIBINTL])
63 gl_INET_NTOP 68 gl_INET_NTOP
64 gl_INLINE 69 gl_INLINE
70 gl_LOCALCHARSET
71 LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(top_builddir)/$gl_source_base\""
72 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
65 AC_FUNC_MALLOC 73 AC_FUNC_MALLOC
66 gl_MBCHAR 74 AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.])
67 gl_MBITER 75 gl_FUNC_MALLOC_POSIX
68 gl_FUNC_MEMCHR 76 gl_STDLIB_MODULE_INDICATOR([malloc-posix])
69 gl_MINMAX
70 gl_MOUNTLIST 77 gl_MOUNTLIST
71 gl_HEADER_NETINET_IN 78 gl_HEADER_NETINET_IN
79 AC_PROG_MKDIR_P
72 gl_REGEX 80 gl_REGEX
73 gl_SAFE_READ 81 gl_SAFE_READ
74 gl_SAFE_WRITE 82 gl_SAFE_WRITE
75 gl_SIZE_MAX 83 gl_SIZE_MAX
76 gl_FUNC_SNPRINTF 84 gl_FUNC_SNPRINTF
85 gl_STDIO_MODULE_INDICATOR([snprintf])
77 gl_TYPE_SOCKLEN_T 86 gl_TYPE_SOCKLEN_T
78 gt_TYPE_SSIZE_T 87 gt_TYPE_SSIZE_T
79 AM_STDBOOL_H 88 AM_STDBOOL_H
80 gl_STDINT_H 89 gl_STDINT_H
81 gl_STRCASE 90 gl_STDIO_H
91 gl_STDLIB_H
82 gl_FUNC_STRDUP 92 gl_FUNC_STRDUP
93 gl_STRING_MODULE_INDICATOR([strdup])
94 gl_FUNC_STRERROR
95 gl_STRING_MODULE_INDICATOR([strerror])
96 gl_HEADER_STRING_H
83 gl_FUNC_STRNDUP 97 gl_FUNC_STRNDUP
98 gl_STRING_MODULE_INDICATOR([strndup])
84 gl_FUNC_STRNLEN 99 gl_FUNC_STRNLEN
100 gl_STRING_MODULE_INDICATOR([strnlen])
85 gl_HEADER_SYS_SOCKET 101 gl_HEADER_SYS_SOCKET
86 AC_PROG_MKDIR_P 102 AC_PROG_MKDIR_P
87 gl_HEADER_UNISTD 103 gl_UNISTD_H
88 gl_UNISTD_SAFER 104 gl_UNISTD_SAFER
89 gl_FUNC_VASNPRINTF 105 gl_FUNC_VASNPRINTF
90 gl_FUNC_VASPRINTF 106 gl_FUNC_VASPRINTF
107 gl_STDIO_MODULE_INDICATOR([vasprintf])
108 m4_ifdef([AM_XGETTEXT_OPTION],
109 [AM_XGETTEXT_OPTION([--flag=asprintf:2:c-format])
110 AM_XGETTEXT_OPTION([--flag=vasprintf:2:c-format])])
91 gl_FUNC_VSNPRINTF 111 gl_FUNC_VSNPRINTF
112 gl_STDIO_MODULE_INDICATOR([vsnprintf])
92 gl_WCHAR_H 113 gl_WCHAR_H
93 gl_WCTYPE_H 114 gl_WCTYPE_H
94 gl_FUNC_WCWIDTH
95 gl_XALLOC 115 gl_XALLOC
96 gl_XSIZE 116 gl_XSIZE
97 gl_XSTRNDUP 117 gl_XSTRNDUP
98 LIBGNU_LIBDEPS="$gl_libdeps"
99 AC_SUBST([LIBGNU_LIBDEPS])
100 LIBGNU_LTLIBDEPS="$gl_ltlibdeps"
101 AC_SUBST([LIBGNU_LTLIBDEPS])
102 m4_popdef([AC_LIBSOURCES]) 118 m4_popdef([AC_LIBSOURCES])
103 m4_popdef([AC_REPLACE_FUNCS]) 119 m4_popdef([AC_REPLACE_FUNCS])
104 m4_popdef([AC_LIBOBJ]) 120 m4_popdef([AC_LIBOBJ])
@@ -116,29 +132,112 @@ AC_DEFUN([gl_INIT],
116 AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) 132 AC_SUBST([gl_LIBOBJS], [$gl_libobjs])
117 AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) 133 AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs])
118 ]) 134 ])
135 gltests_libdeps=
136 gltests_ltlibdeps=
137 m4_pushdef([AC_LIBOBJ], m4_defn([gltests_LIBOBJ]))
138 m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gltests_REPLACE_FUNCS]))
139 m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES]))
140 gl_source_base='tests'
141 m4_popdef([AC_LIBSOURCES])
142 m4_popdef([AC_REPLACE_FUNCS])
143 m4_popdef([AC_LIBOBJ])
144 AC_CONFIG_COMMANDS_PRE([
145 gltests_libobjs=
146 gltests_ltlibobjs=
147 if test -n "$gltests_LIBOBJS"; then
148 # Remove the extension.
149 sed_drop_objext='s/\.o$//;s/\.obj$//'
150 for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do
151 gltests_libobjs="$gltests_libobjs $i.$ac_objext"
152 gltests_ltlibobjs="$gltests_ltlibobjs $i.lo"
153 done
154 fi
155 AC_SUBST([gltests_LIBOBJS], [$gltests_libobjs])
156 AC_SUBST([gltests_LTLIBOBJS], [$gltests_ltlibobjs])
157 ])
158 LIBGNU_LIBDEPS="$gl_libdeps"
159 AC_SUBST([LIBGNU_LIBDEPS])
160 LIBGNU_LTLIBDEPS="$gl_ltlibdeps"
161 AC_SUBST([LIBGNU_LTLIBDEPS])
119]) 162])
120 163
121# Like AC_LIBOBJ, except that the module name goes 164# Like AC_LIBOBJ, except that the module name goes
122# into gl_LIBOBJS instead of into LIBOBJS. 165# into gl_LIBOBJS instead of into LIBOBJS.
123AC_DEFUN([gl_LIBOBJ], 166AC_DEFUN([gl_LIBOBJ], [
124 [gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext"]) 167 AS_LITERAL_IF([$1], [gl_LIBSOURCES([$1.c])])dnl
168 gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext"
169])
170
171# m4_foreach_w is provided by autoconf-2.59c and later.
172# This definition is to accommodate developers using versions
173# of autoconf older than that.
174m4_ifndef([m4_foreach_w],
175 [m4_define([m4_foreach_w],
176 [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
125 177
126# Like AC_REPLACE_FUNCS, except that the module name goes 178# Like AC_REPLACE_FUNCS, except that the module name goes
127# into gl_LIBOBJS instead of into LIBOBJS. 179# into gl_LIBOBJS instead of into LIBOBJS.
128AC_DEFUN([gl_REPLACE_FUNCS], 180AC_DEFUN([gl_REPLACE_FUNCS], [
129 [AC_CHECK_FUNCS([$1], , [gl_LIBOBJ($ac_func)])]) 181 m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl
182 AC_CHECK_FUNCS([$1], , [gl_LIBOBJ($ac_func)])
183])
184
185# Like AC_LIBSOURCES, except the directory where the source file is
186# expected is derived from the gnulib-tool parametrization,
187# and alloca is special cased (for the alloca-opt module).
188# We could also entirely rely on EXTRA_lib..._SOURCES.
189AC_DEFUN([gl_LIBSOURCES], [
190 m4_foreach([_gl_NAME], [$1], [
191 m4_if(_gl_NAME, [alloca.c], [], [
192 m4_syscmd([test -r gl/]_gl_NAME[ || test ! -d gl])dnl
193 m4_if(m4_sysval, [0], [],
194 [AC_FATAL([missing gl/]_gl_NAME)])
195 ])
196 ])
197])
198
199# Like AC_LIBOBJ, except that the module name goes
200# into gltests_LIBOBJS instead of into LIBOBJS.
201AC_DEFUN([gltests_LIBOBJ], [
202 AS_LITERAL_IF([$1], [gltests_LIBSOURCES([$1.c])])dnl
203 gltests_LIBOBJS="$gltests_LIBOBJS $1.$ac_objext"
204])
205
206# m4_foreach_w is provided by autoconf-2.59c and later.
207# This definition is to accommodate developers using versions
208# of autoconf older than that.
209m4_ifndef([m4_foreach_w],
210 [m4_define([m4_foreach_w],
211 [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
130 212
131# Like AC_LIBSOURCES, except that it does nothing. 213# Like AC_REPLACE_FUNCS, except that the module name goes
132# We rely on EXTRA_lib..._SOURCES instead. 214# into gltests_LIBOBJS instead of into LIBOBJS.
133AC_DEFUN([gl_LIBSOURCES], 215AC_DEFUN([gltests_REPLACE_FUNCS], [
134 []) 216 m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl
217 AC_CHECK_FUNCS([$1], , [gltests_LIBOBJ($ac_func)])
218])
219
220# Like AC_LIBSOURCES, except the directory where the source file is
221# expected is derived from the gnulib-tool parametrization,
222# and alloca is special cased (for the alloca-opt module).
223# We could also entirely rely on EXTRA_lib..._SOURCES.
224AC_DEFUN([gltests_LIBSOURCES], [
225 m4_foreach([_gl_NAME], [$1], [
226 m4_if(_gl_NAME, [alloca.c], [], [
227 m4_syscmd([test -r tests/]_gl_NAME[ || test ! -d tests])dnl
228 m4_if(m4_sysval, [0], [],
229 [AC_FATAL([missing tests/]_gl_NAME)])
230 ])
231 ])
232])
135 233
136# This macro records the list of files which have been installed by 234# This macro records the list of files which have been installed by
137# gnulib-tool and may be removed by future gnulib-tool invocations. 235# gnulib-tool and may be removed by future gnulib-tool invocations.
138AC_DEFUN([gl_FILE_LIST], [ 236AC_DEFUN([gl_FILE_LIST], [
139 build-aux/config.rpath 237 build-aux/config.rpath
238 build-aux/link-warning.h
140 lib/alloca.c 239 lib/alloca.c
141 lib/alloca_.h 240 lib/alloca.in.h
142 lib/asnprintf.c 241 lib/asnprintf.c
143 lib/asprintf.c 242 lib/asprintf.c
144 lib/basename.c 243 lib/basename.c
@@ -146,18 +245,20 @@ AC_DEFUN([gl_FILE_LIST], [
146 lib/c-strtod.h 245 lib/c-strtod.h
147 lib/cloexec.c 246 lib/cloexec.c
148 lib/cloexec.h 247 lib/cloexec.h
248 lib/config.charset
149 lib/creat-safer.c 249 lib/creat-safer.c
150 lib/dirname.c 250 lib/dirname.c
151 lib/dirname.h 251 lib/dirname.h
152 lib/dup-safer.c 252 lib/dup-safer.c
153 lib/error.c 253 lib/error.c
154 lib/error.h 254 lib/error.h
155 lib/exit.h
156 lib/exitfail.c 255 lib/exitfail.c
157 lib/exitfail.h 256 lib/exitfail.h
158 lib/fcntl--.h 257 lib/fcntl--.h
159 lib/fcntl-safer.h 258 lib/fcntl-safer.h
160 lib/fd-safer.c 259 lib/fd-safer.c
260 lib/float+.h
261 lib/float.in.h
161 lib/fsusage.c 262 lib/fsusage.c
162 lib/fsusage.h 263 lib/fsusage.h
163 lib/full-read.c 264 lib/full-read.c
@@ -170,27 +271,27 @@ AC_DEFUN([gl_FILE_LIST], [
170 lib/gethostname.c 271 lib/gethostname.c
171 lib/getloadavg.c 272 lib/getloadavg.c
172 lib/getopt.c 273 lib/getopt.c
274 lib/getopt.in.h
173 lib/getopt1.c 275 lib/getopt1.c
174 lib/getopt_.h
175 lib/getopt_int.h 276 lib/getopt_int.h
176 lib/gettext.h 277 lib/gettext.h
177 lib/inet_ntop.c 278 lib/inet_ntop.c
178 lib/inet_ntop.h 279 lib/inet_ntop.h
179 lib/intprops.h 280 lib/intprops.h
281 lib/localcharset.c
282 lib/localcharset.h
180 lib/malloc.c 283 lib/malloc.c
181 lib/mbchar.c
182 lib/mbchar.h
183 lib/mbuiter.h
184 lib/memchr.c
185 lib/minmax.h
186 lib/mountlist.c 284 lib/mountlist.c
187 lib/mountlist.h 285 lib/mountlist.h
286 lib/netinet_in.in.h
188 lib/open-safer.c 287 lib/open-safer.c
189 lib/pipe-safer.c 288 lib/pipe-safer.c
190 lib/printf-args.c 289 lib/printf-args.c
191 lib/printf-args.h 290 lib/printf-args.h
192 lib/printf-parse.c 291 lib/printf-parse.c
193 lib/printf-parse.h 292 lib/printf-parse.h
293 lib/ref-add.sin
294 lib/ref-del.sin
194 lib/regcomp.c 295 lib/regcomp.c
195 lib/regex.c 296 lib/regex.c
196 lib/regex.h 297 lib/regex.h
@@ -203,34 +304,26 @@ AC_DEFUN([gl_FILE_LIST], [
203 lib/safe-write.h 304 lib/safe-write.h
204 lib/size_max.h 305 lib/size_max.h
205 lib/snprintf.c 306 lib/snprintf.c
206 lib/snprintf.h 307 lib/stdbool.in.h
207 lib/socket_.h 308 lib/stdint.in.h
208 lib/stdbool_.h 309 lib/stdio.in.h
209 lib/stdint_.h 310 lib/stdlib.in.h
210 lib/strcase.h
211 lib/strcasecmp.c
212 lib/strdup.c 311 lib/strdup.c
213 lib/strdup.h 312 lib/strerror.c
313 lib/string.in.h
214 lib/stripslash.c 314 lib/stripslash.c
215 lib/strncasecmp.c
216 lib/strndup.c 315 lib/strndup.c
217 lib/strndup.h
218 lib/strnlen.c 316 lib/strnlen.c
219 lib/strnlen.h 317 lib/sys_socket.in.h
220 lib/strnlen1.c
221 lib/strnlen1.h
222 lib/unistd--.h 318 lib/unistd--.h
223 lib/unistd-safer.h 319 lib/unistd-safer.h
224 lib/unistd_.h 320 lib/unistd.in.h
225 lib/vasnprintf.c 321 lib/vasnprintf.c
226 lib/vasnprintf.h 322 lib/vasnprintf.h
227 lib/vasprintf.c 323 lib/vasprintf.c
228 lib/vasprintf.h
229 lib/vsnprintf.c 324 lib/vsnprintf.c
230 lib/vsnprintf.h 325 lib/wchar.in.h
231 lib/wchar_.h 326 lib/wctype.in.h
232 lib/wctype_.h
233 lib/wcwidth.h
234 lib/xalloc-die.c 327 lib/xalloc-die.c
235 lib/xalloc.h 328 lib/xalloc.h
236 lib/xmalloc.c 329 lib/xmalloc.c
@@ -251,6 +344,7 @@ AC_DEFUN([gl_FILE_LIST], [
251 m4/exitfail.m4 344 m4/exitfail.m4
252 m4/extensions.m4 345 m4/extensions.m4
253 m4/fcntl-safer.m4 346 m4/fcntl-safer.m4
347 m4/float_h.m4
254 m4/fstypename.m4 348 m4/fstypename.m4
255 m4/fsusage.m4 349 m4/fsusage.m4
256 m4/getaddrinfo.m4 350 m4/getaddrinfo.m4
@@ -262,11 +356,13 @@ AC_DEFUN([gl_FILE_LIST], [
262 m4/glibc21.m4 356 m4/glibc21.m4
263 m4/gnulib-common.m4 357 m4/gnulib-common.m4
264 m4/iconv.m4 358 m4/iconv.m4
359 m4/include_next.m4
265 m4/inet_ntop.m4 360 m4/inet_ntop.m4
266 m4/inline.m4 361 m4/inline.m4
267 m4/intdiv0.m4 362 m4/intdiv0.m4
268 m4/intl.m4 363 m4/intl.m4
269 m4/intldir.m4 364 m4/intldir.m4
365 m4/intlmacosx.m4
270 m4/intmax.m4 366 m4/intmax.m4
271 m4/intmax_t.m4 367 m4/intmax_t.m4
272 m4/inttypes-pri.m4 368 m4/inttypes-pri.m4
@@ -275,15 +371,11 @@ AC_DEFUN([gl_FILE_LIST], [
275 m4/lib-ld.m4 371 m4/lib-ld.m4
276 m4/lib-link.m4 372 m4/lib-link.m4
277 m4/lib-prefix.m4 373 m4/lib-prefix.m4
374 m4/localcharset.m4
278 m4/lock.m4 375 m4/lock.m4
279 m4/longdouble.m4
280 m4/longlong.m4 376 m4/longlong.m4
281 m4/ls-mntd-fs.m4 377 m4/ls-mntd-fs.m4
282 m4/mbchar.m4 378 m4/malloc.m4
283 m4/mbiter.m4
284 m4/mbrtowc.m4
285 m4/memchr.m4
286 m4/minmax.m4
287 m4/mountlist.m4 379 m4/mountlist.m4
288 m4/netinet_in_h.m4 380 m4/netinet_in_h.m4
289 m4/nls.m4 381 m4/nls.m4
@@ -302,13 +394,15 @@ AC_DEFUN([gl_FILE_LIST], [
302 m4/stdbool.m4 394 m4/stdbool.m4
303 m4/stdint.m4 395 m4/stdint.m4
304 m4/stdint_h.m4 396 m4/stdint_h.m4
305 m4/strcase.m4 397 m4/stdio_h.m4
398 m4/stdlib_h.m4
306 m4/strdup.m4 399 m4/strdup.m4
400 m4/strerror.m4
401 m4/string_h.m4
307 m4/strndup.m4 402 m4/strndup.m4
308 m4/strnlen.m4 403 m4/strnlen.m4
309 m4/sys_socket_h.m4 404 m4/sys_socket_h.m4
310 m4/uintmax_t.m4 405 m4/uintmax_t.m4
311 m4/ulonglong.m4
312 m4/unistd-safer.m4 406 m4/unistd-safer.m4
313 m4/unistd_h.m4 407 m4/unistd_h.m4
314 m4/vasnprintf.m4 408 m4/vasnprintf.m4
@@ -318,7 +412,6 @@ AC_DEFUN([gl_FILE_LIST], [
318 m4/wchar.m4 412 m4/wchar.m4
319 m4/wchar_t.m4 413 m4/wchar_t.m4
320 m4/wctype.m4 414 m4/wctype.m4
321 m4/wcwidth.m4
322 m4/wint_t.m4 415 m4/wint_t.m4
323 m4/xalloc.m4 416 m4/xalloc.m4
324 m4/xsize.m4 417 m4/xsize.m4
diff --git a/gl/m4/iconv.m4 b/gl/m4/iconv.m4
index 654c415..66bc76f 100644
--- a/gl/m4/iconv.m4
+++ b/gl/m4/iconv.m4
@@ -1,5 +1,5 @@
1# iconv.m4 serial AM4 (gettext-0.11.3) 1# iconv.m4 serial AM6 (gettext-0.17)
2dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2007 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.
@@ -21,6 +21,7 @@ AC_DEFUN([AM_ICONV_LINK],
21[ 21[
22 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and 22 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
23 dnl those with the standalone portable GNU libiconv installed). 23 dnl those with the standalone portable GNU libiconv installed).
24 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24 25
25 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 26 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
26 dnl accordingly. 27 dnl accordingly.
@@ -33,7 +34,7 @@ AC_DEFUN([AM_ICONV_LINK],
33 am_save_CPPFLAGS="$CPPFLAGS" 34 am_save_CPPFLAGS="$CPPFLAGS"
34 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) 35 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
35 36
36 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [ 37 AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [
37 am_cv_func_iconv="no, consider installing GNU libiconv" 38 am_cv_func_iconv="no, consider installing GNU libiconv"
38 am_cv_lib_iconv=no 39 am_cv_lib_iconv=no
39 AC_TRY_LINK([#include <stdlib.h> 40 AC_TRY_LINK([#include <stdlib.h>
@@ -56,7 +57,85 @@ AC_DEFUN([AM_ICONV_LINK],
56 fi 57 fi
57 ]) 58 ])
58 if test "$am_cv_func_iconv" = yes; then 59 if test "$am_cv_func_iconv" = yes; then
59 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.]) 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.
62 am_save_LIBS="$LIBS"
63 if test $am_cv_lib_iconv = yes; then
64 LIBS="$LIBS $LIBICONV"
65 fi
66 AC_TRY_RUN([
67#include <iconv.h>
68#include <string.h>
69int main ()
70{
71 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
72 returns. */
73 {
74 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
75 if (cd_utf8_to_88591 != (iconv_t)(-1))
76 {
77 static const char input[] = "\342\202\254"; /* EURO SIGN */
78 char buf[10];
79 const char *inptr = input;
80 size_t inbytesleft = strlen (input);
81 char *outptr = buf;
82 size_t outbytesleft = sizeof (buf);
83 size_t res = iconv (cd_utf8_to_88591,
84 (char **) &inptr, &inbytesleft,
85 &outptr, &outbytesleft);
86 if (res == 0)
87 return 1;
88 }
89 }
90#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. */
92 {
93 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
94 if (cd_88591_to_utf8 != (iconv_t)(-1))
95 {
96 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
97 char buf[50];
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_88591_to_utf8,
103 (char **) &inptr, &inbytesleft,
104 &outptr, &outbytesleft);
105 if ((int)res > 0)
106 return 1;
107 }
108 }
109#endif
110 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
111 provided. */
112 if (/* Try standardized names. */
113 iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
114 /* Try IRIX, OSF/1 names. */
115 && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
116 /* Try AIX names. */
117 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
118 /* Try HP-UX names. */
119 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
120 return 1;
121 return 0;
122}], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
123 [case "$host_os" in
124 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
125 *) am_cv_func_iconv_works="guessing yes" ;;
126 esac])
127 LIBS="$am_save_LIBS"
128 ])
129 case "$am_cv_func_iconv_works" in
130 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
131 *) am_func_iconv=yes ;;
132 esac
133 else
134 am_func_iconv=no am_cv_lib_iconv=no
135 fi
136 if test "$am_func_iconv" = yes; then
137 AC_DEFINE(HAVE_ICONV, 1,
138 [Define if you have the iconv() function and it works.])
60 fi 139 fi
61 if test "$am_cv_lib_iconv" = yes; then 140 if test "$am_cv_lib_iconv" = yes; then
62 AC_MSG_CHECKING([how to link with libiconv]) 141 AC_MSG_CHECKING([how to link with libiconv])
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4
new file mode 100644
index 0000000..7ce472b
--- /dev/null
+++ b/gl/m4/include_next.m4
@@ -0,0 +1,107 @@
1# include_next.m4 serial 4
2dnl Copyright (C) 2006, 2007 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 Paul Eggert and Derek Price.
8
9AC_DEFUN([gl_INCLUDE_NEXT],
10[
11 AC_LANG_PREPROC_REQUIRE()
12 AC_CACHE_CHECK([whether the preprocessor supports include_next],
13 [gl_cv_have_include_next],
14 [rm -rf conftestd1 conftestd2
15 mkdir conftestd1 conftestd2
16 cat <<EOF > conftestd1/conftest.h
17#define DEFINED_IN_CONFTESTD1
18#include_next <conftest.h>
19#ifdef DEFINED_IN_CONFTESTD2
20int foo;
21#else
22#error "include_next doesn't work"
23#endif
24EOF
25 cat <<EOF > conftestd2/conftest.h
26#ifndef DEFINED_IN_CONFTESTD1
27#error "include_next test doesn't work"
28#endif
29#define DEFINED_IN_CONFTESTD2
30EOF
31 save_CPPFLAGS="$CPPFLAGS"
32 CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2"
33 AC_COMPILE_IFELSE([#include <conftest.h>],
34 [gl_cv_have_include_next=yes],
35 [gl_cv_have_include_next=no])
36 CPPFLAGS="$save_CPPFLAGS"
37 rm -rf conftestd1 conftestd2
38 ])
39 if test $gl_cv_have_include_next = yes; then
40
41 dnl FIXME: Remove HAVE_INCLUDE_NEXT and update everything that uses it
42 dnl to use @INCLUDE_NEXT@ instead.
43 AC_DEFINE([HAVE_INCLUDE_NEXT], 1,
44 [Define if your compiler supports the #include_next directive.])
45
46 INCLUDE_NEXT=include_next
47 else
48 INCLUDE_NEXT=include
49 fi
50 AC_SUBST([INCLUDE_NEXT])
51])
52
53# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
54# ------------------------------------------
55# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
56# '<foo.h>'; otherwise define it to be
57# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
58# That way, a header file with the following line:
59# #@INCLUDE_NEXT@ @NEXT_FOO_H@
60# behaves (after sed substitution) as if it contained
61# #include_next <foo.h>
62# even if the compiler does not support include_next.
63# The three "///" are to pacify Sun C 5.8, which otherwise would say
64# "warning: #include of /usr/include/... may be non-portable".
65# Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
66AC_DEFUN([gl_CHECK_NEXT_HEADERS],
67[
68 AC_REQUIRE([gl_INCLUDE_NEXT])
69 AC_CHECK_HEADERS_ONCE([$1])
70
71 AC_FOREACH([gl_HEADER_NAME], [$1],
72 [AS_VAR_PUSHDEF([gl_next_header],
73 [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
74 if test $gl_cv_have_include_next = yes; then
75 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
76 else
77 AC_CACHE_CHECK(
78 [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
79 m4_quote(m4_defn([gl_next_header])),
80 [AS_VAR_PUSHDEF([gl_header_exists],
81 [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
82 if test AS_VAR_GET(gl_header_exists) = yes; then
83 AC_LANG_CONFTEST(
84 [AC_LANG_SOURCE(
85 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
86 )])
87 dnl eval is necessary to expand ac_cpp.
88 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
89 dnl so use subshell.
90 AS_VAR_SET([gl_next_header],
91 ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
92 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
93 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
94 s#^/[^/]#//&#
95 p
96 q
97 }'`'"'])
98 else
99 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
100 fi
101 AS_VAR_POPDEF([gl_header_exists])])
102 fi
103 AC_SUBST(
104 AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
105 [AS_VAR_GET([gl_next_header])])
106 AS_VAR_POPDEF([gl_next_header])])
107])
diff --git a/gl/m4/intdiv0.m4 b/gl/m4/intdiv0.m4
index b8d7817..8c8a670 100644
--- a/gl/m4/intdiv0.m4
+++ b/gl/m4/intdiv0.m4
@@ -1,5 +1,5 @@
1# intdiv0.m4 serial 1 (gettext-0.11.3) 1# intdiv0.m4 serial 2 (gettext-0.17)
2dnl Copyright (C) 2002 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2007 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.
@@ -14,16 +14,27 @@ AC_DEFUN([gt_INTDIV0],
14 AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], 14 AC_CACHE_CHECK([whether integer division by zero raises SIGFPE],
15 gt_cv_int_divbyzero_sigfpe, 15 gt_cv_int_divbyzero_sigfpe,
16 [ 16 [
17 AC_TRY_RUN([ 17 gt_cv_int_divbyzero_sigfpe=
18changequote(,)dnl
19 case "$host_os" in
20 macos* | darwin[6-9]* | darwin[1-9][0-9]*)
21 # On MacOS X 10.2 or newer, just assume the same as when cross-
22 # compiling. If we were to perform the real test, 1 Crash Report
23 # dialog window would pop up.
24 case "$host_cpu" in
25 i[34567]86 | x86_64)
26 gt_cv_int_divbyzero_sigfpe="guessing yes" ;;
27 esac
28 ;;
29 esac
30changequote([,])dnl
31 if test -z "$gt_cv_int_divbyzero_sigfpe"; then
32 AC_TRY_RUN([
18#include <stdlib.h> 33#include <stdlib.h>
19#include <signal.h> 34#include <signal.h>
20 35
21static void 36static void
22#ifdef __cplusplus
23sigfpe_handler (int sig) 37sigfpe_handler (int sig)
24#else
25sigfpe_handler (sig) int sig;
26#endif
27{ 38{
28 /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ 39 /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */
29 exit (sig != SIGFPE); 40 exit (sig != SIGFPE);
@@ -51,15 +62,18 @@ int main ()
51 exit (1); 62 exit (1);
52} 63}
53], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, 64], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no,
54 [ 65 [
55 # Guess based on the CPU. 66 # Guess based on the CPU.
56 case "$host_cpu" in 67changequote(,)dnl
57 alpha* | i[34567]86 | m68k | s390*) 68 case "$host_cpu" in
58 gt_cv_int_divbyzero_sigfpe="guessing yes";; 69 alpha* | i[34567]86 | x86_64 | m68k | s390*)
59 *) 70 gt_cv_int_divbyzero_sigfpe="guessing yes";;
60 gt_cv_int_divbyzero_sigfpe="guessing no";; 71 *)
61 esac 72 gt_cv_int_divbyzero_sigfpe="guessing no";;
62 ]) 73 esac
74changequote([,])dnl
75 ])
76 fi
63 ]) 77 ])
64 case "$gt_cv_int_divbyzero_sigfpe" in 78 case "$gt_cv_int_divbyzero_sigfpe" in
65 *yes) value=1;; 79 *yes) value=1;;
diff --git a/gl/m4/intl.m4 b/gl/m4/intl.m4
index dcefb11..934408b 100644
--- a/gl/m4/intl.m4
+++ b/gl/m4/intl.m4
@@ -1,5 +1,5 @@
1# intl.m4 serial 3 (gettext-0.16) 1# intl.m4 serial 8 (gettext-0.17)
2dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2007 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.
@@ -33,7 +33,6 @@ AC_DEFUN([AM_INTL_SUBDIR],
33 AC_REQUIRE([gl_VISIBILITY])dnl 33 AC_REQUIRE([gl_VISIBILITY])dnl
34 AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl 34 AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl
35 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl 35 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl
36 AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl
37 AC_REQUIRE([gt_TYPE_WCHAR_T])dnl 36 AC_REQUIRE([gt_TYPE_WCHAR_T])dnl
38 AC_REQUIRE([gt_TYPE_WINT_T])dnl 37 AC_REQUIRE([gt_TYPE_WINT_T])dnl
39 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 38 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
@@ -98,7 +97,7 @@ AC_DEFUN([AM_INTL_SUBDIR],
98 dnl exported variables _also_ in the static library. 97 dnl exported variables _also_ in the static library.
99 if test "$enable_shared" = yes; then 98 if test "$enable_shared" = yes; then
100 case "$host_os" in 99 case "$host_os" in
101 cygwin*) is_woe32dll=yes ;; 100 mingw* | cygwin*) is_woe32dll=yes ;;
102 *) is_woe32dll=no ;; 101 *) is_woe32dll=no ;;
103 esac 102 esac
104 else 103 else
@@ -107,6 +106,31 @@ AC_DEFUN([AM_INTL_SUBDIR],
107 WOE32DLL=$is_woe32dll 106 WOE32DLL=$is_woe32dll
108 AC_SUBST([WOE32DLL]) 107 AC_SUBST([WOE32DLL])
109 108
109 dnl On mingw and Cygwin, we can activate special Makefile rules which add
110 dnl version information to the shared libraries and executables.
111 case "$host_os" in
112 mingw* | cygwin*) is_woe32=yes ;;
113 *) is_woe32=no ;;
114 esac
115 WOE32=$is_woe32
116 AC_SUBST([WOE32])
117 if test $WOE32 = yes; then
118 dnl Check for a program that compiles Windows resource files.
119 AC_CHECK_TOOL([WINDRES], [windres])
120 fi
121
122 dnl Determine whether when creating a library, "-lc" should be passed to
123 dnl libtool or not. On many platforms, it is required for the libtool option
124 dnl -no-undefined to work. On HP-UX, however, the -lc - stored by libtool
125 dnl in the *.la files - makes it impossible to create multithreaded programs,
126 dnl because libtool also reorders the -lc to come before the -pthread, and
127 dnl this disables pthread_create() <http://docs.hp.com/en/1896/pthreads.html>.
128 case "$host_os" in
129 hpux*) LTLIBC="" ;;
130 *) LTLIBC="-lc" ;;
131 esac
132 AC_SUBST([LTLIBC])
133
110 dnl Rename some macros and functions used for locking. 134 dnl Rename some macros and functions used for locking.
111 AH_BOTTOM([ 135 AH_BOTTOM([
112#define __libc_lock_t gl_lock_t 136#define __libc_lock_t gl_lock_t
@@ -197,7 +221,9 @@ AC_DEFUN([gt_INTL_SUBDIR_CORE],
197 AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name, 221 AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name,
198 [AC_TRY_LINK([#include <langinfo.h> 222 [AC_TRY_LINK([#include <langinfo.h>
199#include <locale.h>], 223#include <locale.h>],
200 [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES));], 224 [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES));
225 return !cs;
226 ],
201 gt_cv_nl_locale_name=yes, 227 gt_cv_nl_locale_name=yes,
202 gt_cv_nl_locale_name=no) 228 gt_cv_nl_locale_name=no)
203 ]) 229 ])
diff --git a/gl/m4/intlmacosx.m4 b/gl/m4/intlmacosx.m4
new file mode 100644
index 0000000..d3f0d90
--- /dev/null
+++ b/gl/m4/intlmacosx.m4
@@ -0,0 +1,51 @@
1# intlmacosx.m4 serial 1 (gettext-0.17)
2dnl Copyright (C) 2004-2007 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.
6dnl
7dnl This file can can be used in projects which are not available under
8dnl the GNU General Public License or the GNU Library General Public
9dnl License but which still want to provide support for the GNU gettext
10dnl functionality.
11dnl Please note that the actual code of the GNU gettext library is covered
12dnl by the GNU Library General Public License, and the rest of the GNU
13dnl gettext package package is covered by the GNU General Public License.
14dnl They are *not* in the public domain.
15
16dnl Checks for special options needed on MacOS X.
17dnl Defines INTL_MACOSX_LIBS.
18AC_DEFUN([gt_INTL_MACOSX],
19[
20 dnl Check for API introduced in MacOS X 10.2.
21 AC_CACHE_CHECK([for CFPreferencesCopyAppValue],
22 gt_cv_func_CFPreferencesCopyAppValue,
23 [gt_save_LIBS="$LIBS"
24 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
25 AC_TRY_LINK([#include <CoreFoundation/CFPreferences.h>],
26 [CFPreferencesCopyAppValue(NULL, NULL)],
27 [gt_cv_func_CFPreferencesCopyAppValue=yes],
28 [gt_cv_func_CFPreferencesCopyAppValue=no])
29 LIBS="$gt_save_LIBS"])
30 if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
31 AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1,
32 [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
33 fi
34 dnl Check for API introduced in MacOS X 10.3.
35 AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent,
36 [gt_save_LIBS="$LIBS"
37 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
38 AC_TRY_LINK([#include <CoreFoundation/CFLocale.h>], [CFLocaleCopyCurrent();],
39 [gt_cv_func_CFLocaleCopyCurrent=yes],
40 [gt_cv_func_CFLocaleCopyCurrent=no])
41 LIBS="$gt_save_LIBS"])
42 if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
43 AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1,
44 [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.])
45 fi
46 INTL_MACOSX_LIBS=
47 if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
48 INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
49 fi
50 AC_SUBST([INTL_MACOSX_LIBS])
51])
diff --git a/gl/m4/intmax_t.m4 b/gl/m4/intmax_t.m4
index 17c7b0a..50ae35d 100644
--- a/gl/m4/intmax_t.m4
+++ b/gl/m4/intmax_t.m4
@@ -1,5 +1,5 @@
1# intmax_t.m4 serial 5 1# intmax_t.m4 serial 6
2dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2006-2007 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,8 +18,8 @@ AC_DEFUN([gl_AC_TYPE_INTMAX_T],
18 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 18 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
19 AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 19 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
20 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then 20 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
21 AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) 21 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
22 test $ac_cv_type_long_long = yes \ 22 test $ac_cv_type_long_long_int = yes \
23 && ac_type='long long' \ 23 && ac_type='long long' \
24 || ac_type='long' 24 || ac_type='long'
25 AC_DEFINE_UNQUOTED(intmax_t, $ac_type, 25 AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
@@ -51,8 +51,8 @@ AC_DEFUN([gt_AC_TYPE_INTMAX_T],
51 AC_DEFINE(HAVE_INTMAX_T, 1, 51 AC_DEFINE(HAVE_INTMAX_T, 1,
52 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) 52 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
53 else 53 else
54 AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) 54 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
55 test $ac_cv_type_long_long = yes \ 55 test $ac_cv_type_long_long_int = yes \
56 && ac_type='long long' \ 56 && ac_type='long long' \
57 || ac_type='long' 57 || ac_type='long'
58 AC_DEFINE_UNQUOTED(intmax_t, $ac_type, 58 AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4
index f157d98..e3d26fc 100644
--- a/gl/m4/lib-link.m4
+++ b/gl/m4/lib-link.m4
@@ -1,4 +1,4 @@
1# lib-link.m4 serial 13 (gettext-0.16.2) 1# lib-link.m4 serial 13 (gettext-0.17)
2dnl Copyright (C) 2001-2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2007 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,
diff --git a/gl/m4/localcharset.m4 b/gl/m4/localcharset.m4
new file mode 100644
index 0000000..b2b7733
--- /dev/null
+++ b/gl/m4/localcharset.m4
@@ -0,0 +1,16 @@
1# localcharset.m4 serial 5
2dnl Copyright (C) 2002, 2004, 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_LOCALCHARSET],
8[
9 dnl Prerequisites of lib/localcharset.c.
10 AC_REQUIRE([AM_LANGINFO_CODESET])
11 AC_CHECK_DECLS_ONCE(getc_unlocked)
12
13 dnl Prerequisites of the lib/Makefile.am snippet.
14 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_REQUIRE([gl_GLIBC21])
16])
diff --git a/gl/m4/lock.m4 b/gl/m4/lock.m4
index 0224f2f..9111933 100644
--- a/gl/m4/lock.m4
+++ b/gl/m4/lock.m4
@@ -1,5 +1,5 @@
1# lock.m4 serial 6 (gettext-0.16) 1# lock.m4 serial 7 (gettext-0.17)
2dnl Copyright (C) 2005-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2007 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.
@@ -35,7 +35,12 @@ AC_DEFUN([gl_LOCK_EARLY_BODY],
35 AC_BEFORE([$0], [gl_ARGP])dnl 35 AC_BEFORE([$0], [gl_ARGP])dnl
36 36
37 AC_REQUIRE([AC_CANONICAL_HOST]) 37 AC_REQUIRE([AC_CANONICAL_HOST])
38 AC_REQUIRE([AC_GNU_SOURCE]) dnl needed for pthread_rwlock_t on glibc systems 38 dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems.
39 dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
40 dnl AC_GNU_SOURCE.
41 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
42 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
43 [AC_REQUIRE([AC_GNU_SOURCE])])
39 dnl Check for multithreading. 44 dnl Check for multithreading.
40 AC_ARG_ENABLE(threads, 45 AC_ARG_ENABLE(threads,
41AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) 46AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API])
diff --git a/gl/m4/longdouble.m4 b/gl/m4/longdouble.m4
deleted file mode 100644
index 25590f4..0000000
--- a/gl/m4/longdouble.m4
+++ /dev/null
@@ -1,31 +0,0 @@
1# longdouble.m4 serial 2 (gettext-0.15)
2dnl Copyright (C) 2002-2003, 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
7dnl From Bruno Haible.
8dnl Test whether the compiler supports the 'long double' type.
9dnl Prerequisite: AC_PROG_CC
10
11dnl This file is only needed in autoconf <= 2.59. Newer versions of autoconf
12dnl have a macro AC_TYPE_LONG_DOUBLE with identical semantics.
13
14AC_DEFUN([gt_TYPE_LONGDOUBLE],
15[
16 AC_CACHE_CHECK([for long double], gt_cv_c_long_double,
17 [if test "$GCC" = yes; then
18 gt_cv_c_long_double=yes
19 else
20 AC_TRY_COMPILE([
21 /* The Stardent Vistra knows sizeof(long double), but does not support it. */
22 long double foo = 0.0;
23 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
24 int array [2*(sizeof(long double) >= sizeof(double)) - 1];
25 ], ,
26 gt_cv_c_long_double=yes, gt_cv_c_long_double=no)
27 fi])
28 if test $gt_cv_c_long_double = yes; then
29 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the 'long double' type.])
30 fi
31])
diff --git a/gl/m4/longlong.m4 b/gl/m4/longlong.m4
index 1f9e862..15bf9da 100644
--- a/gl/m4/longlong.m4
+++ b/gl/m4/longlong.m4
@@ -1,5 +1,5 @@
1# longlong.m4 serial 10 1# longlong.m4 serial 13
2dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 1999-2007 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,8 +7,8 @@ dnl with or without modifications, as long as this notice is preserved.
7dnl From Paul Eggert. 7dnl From Paul Eggert.
8 8
9# Define HAVE_LONG_LONG_INT if 'long long int' works. 9# Define HAVE_LONG_LONG_INT if 'long long int' works.
10# This fixes a bug in Autoconf 2.60, but can be removed once we 10# This fixes a bug in Autoconf 2.61, but can be removed once we
11# assume 2.61 everywhere. 11# assume 2.62 everywhere.
12 12
13# Note: If the type 'long long int' exists but is only 32 bits large 13# Note: If the type 'long long int' exists but is only 32 bits large
14# (as on some very old compilers), HAVE_LONG_LONG_INT will not be 14# (as on some very old compilers), HAVE_LONG_LONG_INT will not be
@@ -18,20 +18,11 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT],
18[ 18[
19 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], 19 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
20 [AC_LINK_IFELSE( 20 [AC_LINK_IFELSE(
21 [AC_LANG_PROGRAM( 21 [_AC_TYPE_LONG_LONG_SNIPPET],
22 [[long long int ll = 9223372036854775807ll;
23 long long int nll = -9223372036854775807LL;
24 typedef int a[((-9223372036854775807LL < 0
25 && 0 < 9223372036854775807ll)
26 ? 1 : -1)];
27 int i = 63;]],
28 [[long long int llmax = 9223372036854775807ll;
29 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
30 | (llmax / ll) | (llmax % ll));]])],
31 [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.
32 dnl If cross compiling, assume the bug isn't important, since 23 dnl If cross compiling, assume the bug isn't important, since
33 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.
34 AC_RUN_IFELSE( 25 AC_RUN_IFELSE(
35 [AC_LANG_PROGRAM( 26 [AC_LANG_PROGRAM(
36 [[@%:@include <limits.h> 27 [[@%:@include <limits.h>
37 @%:@ifndef LLONG_MAX 28 @%:@ifndef LLONG_MAX
@@ -60,13 +51,56 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT],
60 fi 51 fi
61]) 52])
62 53
63# This macro is obsolescent and should go away soon. 54# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
64AC_DEFUN([gl_AC_TYPE_LONG_LONG], 55# This fixes a bug in Autoconf 2.61, but can be removed once we
56# assume 2.62 everywhere.
57
58# Note: If the type 'unsigned long long int' exists but is only 32 bits
59# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
60# will not be defined. In this case you can treat 'unsigned long long int'
61# like 'unsigned long int'.
62
63AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
65[ 64[
66 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 65 AC_CACHE_CHECK([for unsigned long long int],
67 ac_cv_type_long_long=$ac_cv_type_long_long_int 66 [ac_cv_type_unsigned_long_long_int],
68 if test $ac_cv_type_long_long = yes; then 67 [AC_LINK_IFELSE(
69 AC_DEFINE(HAVE_LONG_LONG, 1, 68 [_AC_TYPE_LONG_LONG_SNIPPET],
70 [Define if you have the 'long long' type.]) 69 [ac_cv_type_unsigned_long_long_int=yes],
70 [ac_cv_type_unsigned_long_long_int=no])])
71 if test $ac_cv_type_unsigned_long_long_int = yes; then
72 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1,
73 [Define to 1 if the system has the type `unsigned long long int'.])
71 fi 74 fi
72]) 75])
76
77# Expands to a C program that can be used to test for simultaneous support
78# of 'long long' and 'unsigned long long'. We don't want to say that
79# 'long long' is available if 'unsigned long long' is not, or vice versa,
80# because too many programs rely on the symmetry between signed and unsigned
81# integer types (excluding 'bool').
82AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
83[
84 AC_LANG_PROGRAM(
85 [[/* For now, do not test the preprocessor; as of 2007 there are too many
86 implementations with broken preprocessors. Perhaps this can
87 be revisited in 2012. In the meantime, code should not expect
88 #if to work with literals wider than 32 bits. */
89 /* Test literals. */
90 long long int ll = 9223372036854775807ll;
91 long long int nll = -9223372036854775807LL;
92 unsigned long long int ull = 18446744073709551615ULL;
93 /* Test constant expressions. */
94 typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
95 ? 1 : -1)];
96 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
97 ? 1 : -1)];
98 int i = 63;]],
99 [[/* Test availability of runtime routines for shift and division. */
100 long long int llmax = 9223372036854775807ll;
101 unsigned long long int ullmax = 18446744073709551615ull;
102 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
103 | (llmax / ll) | (llmax % ll)
104 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
105 | (ullmax / ull) | (ullmax % ull));]])
106])
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4
new file mode 100644
index 0000000..764f2a9
--- /dev/null
+++ b/gl/m4/malloc.m4
@@ -0,0 +1,41 @@
1# malloc.m4 serial 8
2dnl Copyright (C) 2007 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_FUNC_MALLOC_POSIX
8# --------------------
9# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
10# fails), and replace malloc if it is not.
11AC_DEFUN([gl_FUNC_MALLOC_POSIX],
12[
13 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
14 if test $gl_cv_func_malloc_posix = yes; then
15 HAVE_MALLOC_POSIX=1
16 AC_DEFINE([HAVE_MALLOC_POSIX], 1,
17 [Define if the 'malloc' function is POSIX compliant.])
18 else
19 AC_LIBOBJ([malloc])
20 HAVE_MALLOC_POSIX=0
21 fi
22 AC_SUBST([HAVE_MALLOC_POSIX])
23])
24
25# Test whether malloc, realloc, calloc are POSIX compliant,
26# Set gl_cv_func_malloc_posix to yes or no accordingly.
27AC_DEFUN([gl_CHECK_MALLOC_POSIX],
28[
29 AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
30 [gl_cv_func_malloc_posix],
31 [
32 dnl It is too dangerous to try to allocate a large amount of memory:
33 dnl some systems go to their knees when you do that. So assume that
34 dnl all Unix implementations of the function are POSIX compliant.
35 AC_TRY_COMPILE([],
36 [#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
37 choke me
38 #endif
39 ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no])
40 ])
41])
diff --git a/gl/m4/mbchar.m4 b/gl/m4/mbchar.m4
deleted file mode 100644
index 5380941..0000000
--- a/gl/m4/mbchar.m4
+++ /dev/null
@@ -1,14 +0,0 @@
1# mbchar.m4 serial 5
2dnl Copyright (C) 2005-2007 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 autoconf tests required for use of mbchar.m4
8dnl From Bruno Haible.
9
10AC_DEFUN([gl_MBCHAR],
11[
12 AC_REQUIRE([AC_GNU_SOURCE])
13 AC_LIBOBJ([mbchar])
14])
diff --git a/gl/m4/mbiter.m4 b/gl/m4/mbiter.m4
deleted file mode 100644
index 7d51af1..0000000
--- a/gl/m4/mbiter.m4
+++ /dev/null
@@ -1,17 +0,0 @@
1# mbiter.m4 serial 2
2dnl Copyright (C) 2005 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 autoconf tests required for use of mbiter.h
8dnl From Bruno Haible.
9
10AC_DEFUN([gl_MBITER],
11[
12 AC_REQUIRE([AC_TYPE_MBSTATE_T])
13 dnl The following line is that so the user can test HAVE_MBRTOWC before
14 dnl #include "mbiter.h" or "mbuiter.h".
15 AC_REQUIRE([gl_FUNC_MBRTOWC])
16 :
17])
diff --git a/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4
deleted file mode 100644
index a3bd911..0000000
--- a/gl/m4/mbrtowc.m4
+++ /dev/null
@@ -1,31 +0,0 @@
1# mbrtowc.m4 serial 8
2dnl Copyright (C) 2001-2002, 2004-2005 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 Paul Eggert
8
9dnl This file can be removed, and gl_FUNC_MBRTOWC replaced with
10dnl AC_FUNC_MBRTOWC, when autoconf 2.60 can be assumed everywhere.
11
12AC_DEFUN([gl_FUNC_MBRTOWC],
13[
14 dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
15 AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
16 gl_cv_func_mbrtowc,
17 [AC_LINK_IFELSE(
18 [AC_LANG_PROGRAM(
19 [[#include <wchar.h>]],
20 [[wchar_t wc;
21 char const s[] = "";
22 size_t n = 1;
23 mbstate_t state;
24 return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
25 gl_cv_func_mbrtowc=yes,
26 gl_cv_func_mbrtowc=no)])
27 if test $gl_cv_func_mbrtowc = yes; then
28 AC_DEFINE([HAVE_MBRTOWC], 1,
29 [Define to 1 if mbrtowc and mbstate_t are properly declared.])
30 fi
31])
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4
deleted file mode 100644
index 91b8636..0000000
--- a/gl/m4/memchr.m4
+++ /dev/null
@@ -1,18 +0,0 @@
1# memchr.m4 serial 4
2dnl Copyright (C) 2002, 2003, 2004 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_MEMCHR],
8[
9 AC_REPLACE_FUNCS(memchr)
10 if test $ac_cv_func_memchr = no; then
11 gl_PREREQ_MEMCHR
12 fi
13])
14
15# Prerequisites of lib/memchr.c.
16AC_DEFUN([gl_PREREQ_MEMCHR], [
17 AC_CHECK_HEADERS(bp-sym.h)
18])
diff --git a/gl/m4/minmax.m4 b/gl/m4/minmax.m4
deleted file mode 100644
index bbd1ba0..0000000
--- a/gl/m4/minmax.m4
+++ /dev/null
@@ -1,41 +0,0 @@
1# minmax.m4 serial 2
2dnl Copyright (C) 2005 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_PREREQ(2.52)
8
9AC_DEFUN([gl_MINMAX],
10[
11 AC_REQUIRE([gl_PREREQ_MINMAX])
12])
13
14# Prerequisites of lib/minmax.h.
15AC_DEFUN([gl_PREREQ_MINMAX],
16[
17 gl_MINMAX_IN_HEADER([limits.h])
18 gl_MINMAX_IN_HEADER([sys/param.h])
19])
20
21dnl gl_MINMAX_IN_HEADER(HEADER)
22dnl The parameter has to be a literal header name; it cannot be macro,
23dnl nor a shell variable. (Because autoheader collects only AC_DEFINE
24dnl invocations with a literal macro name.)
25AC_DEFUN([gl_MINMAX_IN_HEADER],
26[
27 m4_pushdef([header], AS_TR_SH([$1]))
28 m4_pushdef([HEADER], AS_TR_CPP([$1]))
29 AC_CACHE_CHECK([whether <$1> defines MIN and MAX],
30 [gl_cv_minmax_in_]header,
31 [AC_TRY_COMPILE([#include <$1>
32int x = MIN (42, 17);], [],
33 [gl_cv_minmax_in_]header[=yes],
34 [gl_cv_minmax_in_]header[=no])])
35 if test $gl_cv_minmax_in_[]header = yes; then
36 AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
37 [Define to 1 if <$1> defines the MIN and MAX macros.])
38 fi
39 m4_popdef([HEADER])
40 m4_popdef([header])
41])
diff --git a/gl/m4/netinet_in_h.m4 b/gl/m4/netinet_in_h.m4
index d73531a..096be74 100644
--- a/gl/m4/netinet_in_h.m4
+++ b/gl/m4/netinet_in_h.m4
@@ -1,18 +1,30 @@
1# netinet_in_h.m4 serial 1 1# netinet_in_h.m4 serial 3
2dnl Copyright (C) 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2007 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
7dnl Written by Simon Josefsson
8
9AC_DEFUN([gl_HEADER_NETINET_IN], 7AC_DEFUN([gl_HEADER_NETINET_IN],
10[ 8[
11 AC_CHECK_HEADERS_ONCE([netinet/in.h]) 9 AC_CACHE_CHECK([whether <netinet/in.h> is self-contained],
12 if test $ac_cv_header_netinet_in_h = yes; then 10 [gl_cv_header_netinet_in_h_selfcontained],
11 [
12 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netinet/in.h>], [])],
13 [gl_cv_header_netinet_in_h_selfcontained=yes],
14 [gl_cv_header_netinet_in_h_selfcontained=no])
15 ])
16 if test $gl_cv_header_netinet_in_h_selfcontained = yes; then
13 NETINET_IN_H='' 17 NETINET_IN_H=''
14 else 18 else
15 NETINET_IN_H='netinet/in.h' 19 NETINET_IN_H='netinet/in.h'
20 AC_CHECK_HEADERS([netinet/in.h])
21 gl_CHECK_NEXT_HEADERS([netinet/in.h])
22 if test $ac_cv_header_netinet_in_h = yes; then
23 HAVE_NETINET_IN_H=1
24 else
25 HAVE_NETINET_IN_H=0
26 fi
27 AC_SUBST([HAVE_NETINET_IN_H])
16 fi 28 fi
17 AC_SUBST(NETINET_IN_H) 29 AC_SUBST([NETINET_IN_H])
18]) 30])
diff --git a/gl/m4/po.m4 b/gl/m4/po.m4
index 00133ef..0734762 100644
--- a/gl/m4/po.m4
+++ b/gl/m4/po.m4
@@ -1,5 +1,5 @@
1# po.m4 serial 13 (gettext-0.15) 1# po.m4 serial 15 (gettext-0.17)
2dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2007 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.
@@ -27,6 +27,10 @@ AC_DEFUN([AM_PO_SUBDIRS],
27 AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake 27 AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
28 AC_REQUIRE([AM_NLS])dnl 28 AC_REQUIRE([AM_NLS])dnl
29 29
30 dnl Release version of the gettext macros. This is used to ensure that
31 dnl the gettext macros and po/Makefile.in.in are in sync.
32 AC_SUBST([GETTEXT_MACRO_VERSION], [0.17])
33
30 dnl Perform the following tests also if --disable-nls has been given, 34 dnl Perform the following tests also if --disable-nls has been given,
31 dnl because they are needed for "make dist" to work. 35 dnl because they are needed for "make dist" to work.
32 36
@@ -84,6 +88,10 @@ changequote([,])dnl
84 test -n "$localedir" || localedir='${datadir}/locale' 88 test -n "$localedir" || localedir='${datadir}/locale'
85 AC_SUBST([localedir]) 89 AC_SUBST([localedir])
86 90
91 dnl Support for AM_XGETTEXT_OPTION.
92 test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS=
93 AC_SUBST([XGETTEXT_EXTRA_OPTIONS])
94
87 AC_CONFIG_COMMANDS([po-directories], [[ 95 AC_CONFIG_COMMANDS([po-directories], [[
88 for ac_file in $CONFIG_FILES; do 96 for ac_file in $CONFIG_FILES; do
89 # Support "outfile[:infile[:infile...]]" 97 # Support "outfile[:infile[:infile...]]"
@@ -426,3 +434,16 @@ EOF
426 fi 434 fi
427 mv "$ac_file.tmp" "$ac_file" 435 mv "$ac_file.tmp" "$ac_file"
428]) 436])
437
438dnl Initializes the accumulator used by AM_XGETTEXT_OPTION.
439AC_DEFUN([AM_XGETTEXT_OPTION_INIT],
440[
441 XGETTEXT_EXTRA_OPTIONS=
442])
443
444dnl Registers an option to be passed to xgettext in the po subdirectory.
445AC_DEFUN([AM_XGETTEXT_OPTION],
446[
447 AC_REQUIRE([AM_XGETTEXT_OPTION_INIT])
448 XGETTEXT_EXTRA_OPTIONS="$XGETTEXT_EXTRA_OPTIONS $1"
449])
diff --git a/gl/m4/printf-posix.m4 b/gl/m4/printf-posix.m4
index af10170..14ba612 100644
--- a/gl/m4/printf-posix.m4
+++ b/gl/m4/printf-posix.m4
@@ -1,5 +1,5 @@
1# printf-posix.m4 serial 2 (gettext-0.13.1) 1# printf-posix.m4 serial 3 (gettext-0.17)
2dnl Copyright (C) 2003 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007 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.
@@ -28,7 +28,7 @@ int main ()
28}], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no, 28}], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no,
29 [ 29 [
30 AC_EGREP_CPP(notposix, [ 30 AC_EGREP_CPP(notposix, [
31#if defined __NetBSD__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ 31#if defined __NetBSD__ || defined __BEOS__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__
32 notposix 32 notposix
33#endif 33#endif
34 ], gt_cv_func_printf_posix="guessing no", 34 ], gt_cv_func_printf_posix="guessing no",
diff --git a/gl/m4/regex.m4 b/gl/m4/regex.m4
index 25da645..7da6efe 100644
--- a/gl/m4/regex.m4
+++ b/gl/m4/regex.m4
@@ -1,4 +1,4 @@
1#serial 42 1#serial 48
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,
4# 2006, 2007 Free Software Foundation, Inc. 4# 2006, 2007 Free Software Foundation, Inc.
@@ -18,9 +18,12 @@ AC_DEFUN([gl_REGEX],
18 18
19 AC_ARG_WITH([included-regex], 19 AC_ARG_WITH([included-regex],
20 [AC_HELP_STRING([--without-included-regex], 20 [AC_HELP_STRING([--without-included-regex],
21 [don't compile regex; this is the default on 21 [don't compile regex; this is the default on 32-bit
22 systems with recent-enough versions of the GNU C 22 systems with recent-enough versions of the GNU C
23 Library (use with caution on other systems)])]) 23 Library (use with caution on other systems).
24 On systems with 64-bit ptrdiff_t and 32-bit int,
25 --with-included-regex is the default, in case
26 regex functions operate on very long strings (>2GB)])])
24 27
25 case $with_included_regex in #( 28 case $with_included_regex in #(
26 yes|no) ac_use_included_regex=$with_included_regex 29 yes|no) ac_use_included_regex=$with_included_regex
@@ -29,8 +32,7 @@ AC_DEFUN([gl_REGEX],
29 # If the system regex support is good enough that it passes the 32 # 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. 33 # 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 34 # If cross compiling, assume the test would fail and use the included
32 # regex.c. The first failing regular expression is from `Spencer ere 35 # regex.c.
33 # test #75' in grep-2.3.
34 AC_CACHE_CHECK([for working re_compile_pattern], 36 AC_CACHE_CHECK([for working re_compile_pattern],
35 [gl_cv_func_re_compile_pattern_working], 37 [gl_cv_func_re_compile_pattern_working],
36 [AC_RUN_IFELSE( 38 [AC_RUN_IFELSE(
@@ -74,68 +76,91 @@ AC_DEFUN([gl_REGEX],
74 } 76 }
75 #endif 77 #endif
76 78
79 /* This test is from glibc bug 3957, reported by Andrew Mackey. */
80 re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
81 memset (&regex, 0, sizeof regex);
82 s = re_compile_pattern ("a[^x]b", 6, &regex);
83 if (s)
84 return 1;
85
86 /* This should fail, but succeeds for glibc-2.5. */
87 if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
88 return 1;
89
90 /* This regular expression is from Spencer ere test number 75
91 in grep-2.3. */
77 re_set_syntax (RE_SYNTAX_POSIX_EGREP); 92 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
78 memset (&regex, 0, sizeof (regex)); 93 memset (&regex, 0, sizeof regex);
79 for (i = 0; i <= UCHAR_MAX; i++) 94 for (i = 0; i <= UCHAR_MAX; i++)
80 folded_chars[i] = i; 95 folded_chars[i] = i;
81 regex.translate = folded_chars; 96 regex.translate = folded_chars;
82 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex); 97 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
83 /* This should fail with _Invalid character class name_ error. */ 98 /* This should fail with _Invalid character class name_ error. */
84 if (!s) 99 if (!s)
85 exit (1); 100 return 1;
86 101
87 /* This should succeed, but does not for e.g. glibc-2.1.3. */ 102 /* This should succeed, but does not for glibc-2.1.3. */
88 memset (&regex, 0, sizeof (regex)); 103 memset (&regex, 0, sizeof regex);
89 s = re_compile_pattern ("{1", 2, &regex); 104 s = re_compile_pattern ("{1", 2, &regex);
90 105
91 if (s) 106 if (s)
92 exit (1); 107 return 1;
93 108
94 /* The following example is derived from a problem report 109 /* The following example is derived from a problem report
95 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ 110 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
96 memset (&regex, 0, sizeof (regex)); 111 memset (&regex, 0, sizeof regex);
97 s = re_compile_pattern ("[an\371]*n", 7, &regex); 112 s = re_compile_pattern ("[an\371]*n", 7, &regex);
98 if (s) 113 if (s)
99 exit (1); 114 return 1;
100 115
101 /* This should match, but does not for e.g. glibc-2.2.1. */ 116 /* This should match, but does not for glibc-2.2.1. */
102 if (re_match (&regex, "an", 2, 0, &regs) != 2) 117 if (re_match (&regex, "an", 2, 0, &regs) != 2)
103 exit (1); 118 return 1;
104 119
105 memset (&regex, 0, sizeof (regex)); 120 memset (&regex, 0, sizeof regex);
106 s = re_compile_pattern ("x", 1, &regex); 121 s = re_compile_pattern ("x", 1, &regex);
107 if (s) 122 if (s)
108 exit (1); 123 return 1;
109 124
110 /* The version of regex.c in e.g. GNU libc-2.2.93 did not 125 /* glibc-2.2.93 does not work with a negative RANGE argument. */
111 work with a negative RANGE argument. */
112 if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1) 126 if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
113 exit (1); 127 return 1;
114 128
115 /* The version of regex.c in older versions of gnulib 129 /* The version of regex.c in older versions of gnulib
116 ignored RE_ICASE. Detect that problem too. */ 130 ignored RE_ICASE. Detect that problem too. */
117 memset (&regex, 0, sizeof (regex));
118 re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); 131 re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
132 memset (&regex, 0, sizeof regex);
119 s = re_compile_pattern ("x", 1, &regex); 133 s = re_compile_pattern ("x", 1, &regex);
120 if (s) 134 if (s)
121 exit (1); 135 return 1;
122 136
123 if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0) 137 if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
124 exit (1); 138 return 1;
139
140 /* Catch a bug reported by Vin Shelton in
141 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
142 */
143 re_set_syntax (RE_SYNTAX_POSIX_BASIC
144 & ~RE_CONTEXT_INVALID_DUP
145 & ~RE_NO_EMPTY_RANGES);
146 memset (&regex, 0, sizeof regex);
147 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
148 if (s)
149 return 1;
125 150
126 /* REG_STARTEND was added to glibc on 2004-01-15. 151 /* REG_STARTEND was added to glibc on 2004-01-15.
127 Reject older versions. */ 152 Reject older versions. */
128 if (! REG_STARTEND) 153 if (! REG_STARTEND)
129 exit (1); 154 return 1;
130 155
131 /* Reject hosts whose regoff_t values are too narrow. 156 /* Reject hosts whose regoff_t values are too narrow.
132 These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t 157 These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
133 and 32-bit int. */ 158 and 32-bit int. */
134 if (sizeof (regoff_t) < sizeof (ptrdiff_t) 159 if (sizeof (regoff_t) < sizeof (ptrdiff_t)
135 || sizeof (regoff_t) < sizeof (ssize_t)) 160 || sizeof (regoff_t) < sizeof (ssize_t))
136 exit (1); 161 return 1;
137 162
138 exit (0);]])], 163 return 0;]])],
139 [gl_cv_func_re_compile_pattern_working=yes], 164 [gl_cv_func_re_compile_pattern_working=yes],
140 [gl_cv_func_re_compile_pattern_working=no], 165 [gl_cv_func_re_compile_pattern_working=no],
141 dnl When crosscompiling, assume it is not working. 166 dnl When crosscompiling, assume it is not working.
@@ -190,9 +215,8 @@ AC_DEFUN([gl_REGEX],
190# Prerequisites of lib/regex.c and lib/regex_internal.c. 215# Prerequisites of lib/regex.c and lib/regex_internal.c.
191AC_DEFUN([gl_PREREQ_REGEX], 216AC_DEFUN([gl_PREREQ_REGEX],
192[ 217[
193 AC_REQUIRE([AC_GNU_SOURCE]) 218 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
194 AC_REQUIRE([AC_C_RESTRICT]) 219 AC_REQUIRE([AC_C_RESTRICT])
195 AC_REQUIRE([AM_LANGINFO_CODESET]) 220 AC_CHECK_FUNCS_ONCE([isblank iswctype mbrtowc wcrtomb wcscoll])
196 AC_CHECK_FUNCS_ONCE([iswctype mbrtowc mempcpy wcrtomb wcscoll])
197 AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>]) 221 AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
198]) 222])
diff --git a/gl/m4/snprintf.m4 b/gl/m4/snprintf.m4
index 432e037..f21200d 100644
--- a/gl/m4/snprintf.m4
+++ b/gl/m4/snprintf.m4
@@ -1,13 +1,29 @@
1# snprintf.m4 serial 2 1# snprintf.m4 serial 4
2dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2003, 2004, 2007 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_FUNC_SNPRINTF], 7AC_DEFUN([gl_FUNC_SNPRINTF],
8[ 8[
9 AC_REPLACE_FUNCS(snprintf) 9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_CHECK_DECLS_ONCE(snprintf) 10 AC_CHECK_FUNCS([snprintf])
11 if test $ac_cv_func_snprintf = no; then
12 gl_REPLACE_SNPRINTF
13 fi
14 AC_CHECK_DECLS_ONCE([snprintf])
15 if test $ac_cv_have_decl_snprintf = no; then
16 HAVE_DECL_SNPRINTF=0
17 fi
18])
19
20AC_DEFUN([gl_REPLACE_SNPRINTF],
21[
22 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
23 AC_LIBOBJ([snprintf])
24 if test $ac_cv_func_snprintf = yes; then
25 REPLACE_SNPRINTF=1
26 fi
11 gl_PREREQ_SNPRINTF 27 gl_PREREQ_SNPRINTF
12]) 28])
13 29
diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4
index 5e3765a..b755757 100644
--- a/gl/m4/socklen.m4
+++ b/gl/m4/socklen.m4
@@ -1,5 +1,5 @@
1# socklen.m4 serial 4 1# socklen.m4 serial 6
2dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2006, 2007 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,14 +12,14 @@ dnl types for the argument to getsockopt, getpeername, etc. So we
12dnl have to test to find something that will work. 12dnl have to test to find something that will work.
13 13
14dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find 14dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
15dnl it there first. That file is included by gnulib's socket_.h, which 15dnl it there first. That file is included by gnulib's sys_socket.in.h, which
16dnl all users of this module should include. Cygwin must not include 16dnl all users of this module should include. Cygwin must not include
17dnl ws2tcpip.h. 17dnl ws2tcpip.h.
18AC_DEFUN([gl_TYPE_SOCKLEN_T], 18AC_DEFUN([gl_TYPE_SOCKLEN_T],
19 [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl 19 [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl
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_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=
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4
index 1a4b4a6..bb6c34f 100644
--- a/gl/m4/stdint.m4
+++ b/gl/m4/stdint.m4
@@ -1,5 +1,5 @@
1# stdint.m4 serial 22 1# stdint.m4 serial 29
2dnl Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2007 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.
@@ -45,32 +45,32 @@ AC_DEFUN([gl_STDINT_H],
45 fi 45 fi
46 AC_SUBST([HAVE_SYS_TYPES_H]) 46 AC_SUBST([HAVE_SYS_TYPES_H])
47 47
48 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_stdint_h. 48 gl_CHECK_NEXT_HEADERS([stdint.h])
49 if test $ac_cv_header_stdint_h = yes; then 49 if test $ac_cv_header_stdint_h = yes; then
50 gl_ABSOLUTE_HEADER([stdint.h])
51 ABSOLUTE_STDINT_H=\"$gl_cv_absolute_stdint_h\"
52 HAVE_STDINT_H=1 50 HAVE_STDINT_H=1
53 else 51 else
54 ABSOLUTE_STDINT_H=\"no/such/file/stdint.h\"
55 HAVE_STDINT_H=0 52 HAVE_STDINT_H=0
56 fi 53 fi
57 AC_SUBST([ABSOLUTE_STDINT_H])
58 AC_SUBST([HAVE_STDINT_H]) 54 AC_SUBST([HAVE_STDINT_H])
59 55
60 dnl Now see whether we need a substitute <stdint.h>. Use 56 dnl Now see whether we need a substitute <stdint.h>.
61 dnl ABSOLUTE_STDINT_H, not <stdint.h>, so that it also works during
62 dnl a "config.status --recheck" if a stdint.h has been
63 dnl created in the build directory.
64 if test $ac_cv_header_stdint_h = yes; then 57 if test $ac_cv_header_stdint_h = yes; then
65 AC_CACHE_CHECK([whether stdint.h conforms to C99], 58 AC_CACHE_CHECK([whether stdint.h conforms to C99],
66 [gl_cv_header_working_stdint_h], 59 [gl_cv_header_working_stdint_h],
67 [gl_cv_header_working_stdint_h=no 60 [gl_cv_header_working_stdint_h=no
68 AC_COMPILE_IFELSE([ 61 AC_COMPILE_IFELSE([
69 AC_LANG_PROGRAM([[ 62 AC_LANG_PROGRAM([[
70#include <stddef.h>
71#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ 63#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
72#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ 64#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
73#include ABSOLUTE_STDINT_H 65#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
66#include <stdint.h>
67/* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */
68#if !(defined WCHAR_MIN && defined WCHAR_MAX)
69#error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>"
70#endif
71]
72gl_STDINT_INCLUDES
73[
74#ifdef INT8_MAX 74#ifdef INT8_MAX
75int8_t a1 = INT8_MAX; 75int8_t a1 = INT8_MAX;
76int8_t a1min = INT8_MIN; 76int8_t a1min = INT8_MIN;
@@ -142,12 +142,32 @@ uintptr_t h = UINTPTR_MAX;
142#endif 142#endif
143intmax_t i = INTMAX_MAX; 143intmax_t i = INTMAX_MAX;
144uintmax_t j = UINTMAX_MAX; 144uintmax_t j = UINTMAX_MAX;
145
146#include <limits.h> /* for CHAR_BIT */
147#define TYPE_MINIMUM(t) \
148 ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
149#define TYPE_MAXIMUM(t) \
150 ((t) ((t) 0 < (t) -1 ? (t) -1 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
145struct s { 151struct s {
146 int check_PTRDIFF: PTRDIFF_MIN < 0 && 0 < PTRDIFF_MAX ? 1 : -1; 152 int check_PTRDIFF:
147 int check_SIG_ATOMIC: SIG_ATOMIC_MIN <= 0 && 0 < SIG_ATOMIC_MAX ? 1 : -1; 153 PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t)
148 int check_SIZE: 0 < SIZE_MAX ? 1 : -1; 154 && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t)
149 int check_WCHAR: WCHAR_MIN <= 0 && 0 < WCHAR_MAX ? 1 : -1; 155 ? 1 : -1;
150 int check_WINT: WINT_MIN <= 0 && 0 < WINT_MAX ? 1 : -1; 156 /* Detect bug in FreeBSD 6.0 / ia64. */
157 int check_SIG_ATOMIC:
158 SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t)
159 && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t)
160 ? 1 : -1;
161 int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1;
162 int check_WCHAR:
163 WCHAR_MIN == TYPE_MINIMUM (wchar_t)
164 && WCHAR_MAX == TYPE_MAXIMUM (wchar_t)
165 ? 1 : -1;
166 /* Detect bug in mingw. */
167 int check_WINT:
168 WINT_MIN == TYPE_MINIMUM (wint_t)
169 && WINT_MAX == TYPE_MAXIMUM (wint_t)
170 ? 1 : -1;
151 171
152 /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ 172 /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */
153 int check_UINT8_C: 173 int check_UINT8_C:
@@ -202,6 +222,10 @@ struct s {
202 fi 222 fi
203 AC_SUBST([HAVE_SYS_BITYPES_H]) 223 AC_SUBST([HAVE_SYS_BITYPES_H])
204 224
225 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
226 dnl character support).
227 AC_CHECK_HEADERS_ONCE([wchar.h])
228
205 gl_STDINT_TYPE_PROPERTIES 229 gl_STDINT_TYPE_PROPERTIES
206 STDINT_H=stdint.h 230 STDINT_H=stdint.h
207 fi 231 fi
@@ -337,14 +361,16 @@ AC_DEFUN([gl_STDINT_INCLUDES],
337 included before <wchar.h>. */ 361 included before <wchar.h>. */
338 #include <stddef.h> 362 #include <stddef.h>
339 #include <signal.h> 363 #include <signal.h>
340 #include <stdio.h> 364 #if HAVE_WCHAR_H
341 #include <time.h> 365 # include <stdio.h>
342 #include <wchar.h> 366 # include <time.h>
367 # include <wchar.h>
368 #endif
343]]) 369]])
344 370
345dnl gl_STDINT_TYPE_PROPERTIES 371dnl gl_STDINT_TYPE_PROPERTIES
346dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t 372dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t
347dnl of interest to stdint_.h. 373dnl of interest to stdint.in.h.
348AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], 374AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
349[ 375[
350 gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], 376 gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t],
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
new file mode 100644
index 0000000..a40d418
--- /dev/null
+++ b/gl/m4/stdio_h.m4
@@ -0,0 +1,85 @@
1# stdio_h.m4 serial 9
2dnl Copyright (C) 2007 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_STDIO_H],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 gl_CHECK_NEXT_HEADERS([stdio.h])
11])
12
13AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
14[
15 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
16 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
17 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
18])
19
20AC_DEFUN([gl_STDIO_H_DEFAULTS],
21[
22 GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX])
23 GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX])
24 GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
25 GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX])
26 GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
27 GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX])
28 GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
29 GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
30 GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF])
31 GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN])
32 GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN])
33 GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK])
34 GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO])
35 GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL])
36 GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
37 GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
38 GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM])
39 GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE])
40 dnl Assume proper GNU behavior unless another module says otherwise.
41 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
42 REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF])
43 REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF])
44 REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
45 REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
46 HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF])
47 REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
48 HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
49 REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
50 REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])
51 HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
52 REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
53 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
54 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
55 HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
56 REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
57 REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
58 HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
59 REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
60 REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
61 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
62 HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
63 HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
64 REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
65])
66
67dnl Code shared by fseeko and ftello. Determine if large files are supported,
68dnl but stdin does not start as a large file by default.
69AC_DEFUN([gl_STDIN_LARGE_OFFSET],
70 [
71 AC_CACHE_CHECK([whether stdin defaults to large file offsets],
72 [gl_cv_var_stdin_large_offset],
73 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
74[#if defined __SL64 && defined __SCLE /* cygwin */
75 /* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making
76 fseeko/ftello needlessly fail. This bug was fixed in 1.5.25, and
77 it is easier to do a version check than building a runtime test. */
78# include <cygwin/version.h>
79# if CYGWIN_VERSION_DLL_COMBINED < CYGWIN_VERSION_DLL_MAKE_COMBINED (1005, 25)
80 choke me
81# endif
82#endif])],
83 [gl_cv_var_stdin_large_offset=yes],
84 [gl_cv_var_stdin_large_offset=no])])
85])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
new file mode 100644
index 0000000..fe4ce12
--- /dev/null
+++ b/gl/m4/stdlib_h.m4
@@ -0,0 +1,42 @@
1# stdlib_h.m4 serial 5
2dnl Copyright (C) 2007 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_STDLIB_H],
8[
9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10 gl_CHECK_NEXT_HEADERS([stdlib.h])
11])
12
13AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
14[
15 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
16 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
17 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
18])
19
20AC_DEFUN([gl_STDLIB_H_DEFAULTS],
21[
22 GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX])
23 GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
24 GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
25 GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT])
26 GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
27 GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
28 GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
29 GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
30 GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
31 dnl Assume proper GNU behavior unless another module says otherwise.
32 HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX])
33 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
34 HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
35 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
36 HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
37 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
38 HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV])
39 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
40 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
41 VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV])
42])
diff --git a/gl/m4/strcase.m4 b/gl/m4/strcase.m4
deleted file mode 100644
index ae82790..0000000
--- a/gl/m4/strcase.m4
+++ /dev/null
@@ -1,39 +0,0 @@
1# strcase.m4 serial 4
2dnl Copyright (C) 2002, 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_STRCASE],
8[
9 gl_FUNC_STRCASECMP
10 gl_FUNC_STRNCASECMP
11])
12
13AC_DEFUN([gl_FUNC_STRCASECMP],
14[
15 dnl No known system has a strcasecmp() function that works correctly in
16 dnl multibyte locales. Therefore we use our version always.
17 AC_LIBOBJ(strcasecmp)
18 gl_PREREQ_STRCASECMP
19])
20
21AC_DEFUN([gl_FUNC_STRNCASECMP],
22[
23 AC_REPLACE_FUNCS(strncasecmp)
24 AC_CHECK_DECLS(strncasecmp)
25 if test $ac_cv_func_strncasecmp = no; then
26 gl_PREREQ_STRNCASECMP
27 fi
28])
29
30# Prerequisites of lib/strcasecmp.c.
31AC_DEFUN([gl_PREREQ_STRCASECMP], [
32 AC_REQUIRE([gl_FUNC_MBRTOWC])
33 :
34])
35
36# Prerequisites of lib/strncasecmp.c.
37AC_DEFUN([gl_PREREQ_STRNCASECMP], [
38 :
39])
diff --git a/gl/m4/strdup.m4 b/gl/m4/strdup.m4
index f7786e9..8796e9e 100644
--- a/gl/m4/strdup.m4
+++ b/gl/m4/strdup.m4
@@ -1,13 +1,20 @@
1# strdup.m4 serial 7 1# strdup.m4 serial 9
2dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 2
3dnl Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software
4dnl Foundation, Inc.
5
3dnl This file is free software; the Free Software Foundation 6dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 7dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 8dnl with or without modifications, as long as this notice is preserved.
6 9
7AC_DEFUN([gl_FUNC_STRDUP], 10AC_DEFUN([gl_FUNC_STRDUP],
8[ 11[
12 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
9 AC_REPLACE_FUNCS(strdup) 13 AC_REPLACE_FUNCS(strdup)
10 AC_CHECK_DECLS_ONCE(strdup) 14 AC_CHECK_DECLS_ONCE(strdup)
15 if test $ac_cv_have_decl_strdup = no; then
16 HAVE_DECL_STRDUP=0
17 fi
11 gl_PREREQ_STRDUP 18 gl_PREREQ_STRDUP
12]) 19])
13 20
diff --git a/gl/m4/strerror.m4 b/gl/m4/strerror.m4
new file mode 100644
index 0000000..eb7d45a
--- /dev/null
+++ b/gl/m4/strerror.m4
@@ -0,0 +1,47 @@
1# strerror.m4 serial 7
2dnl Copyright (C) 2002, 2007 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_STRERROR],
8[
9 AC_REQUIRE([gl_FUNC_STRERROR_SEPARATE])
10 if test $gl_cv_func_working_strerror = no; then
11 AC_LIBOBJ([strerror])
12 AC_DEFINE_UNQUOTED([REPLACE_STRERROR], [$REPLACE_STRERROR],
13 [Define this to 1 if strerror is broken.])
14 fi
15])
16
17# Like gl_FUNC_STRERROR, except prepare for separate compilation (no AC_LIBOBJ).
18AC_DEFUN([gl_FUNC_STRERROR_SEPARATE],
19[
20 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
21 AC_CACHE_CHECK([for working strerror function],
22 [gl_cv_func_working_strerror],
23 [AC_RUN_IFELSE(
24 [AC_LANG_PROGRAM(
25 [#include <string.h>
26 ],
27 [return !*strerror (-2);])],
28 [gl_cv_func_working_strerror=yes],
29 [gl_cv_func_working_strerror=no],
30 [dnl Assume crossbuild works if it compiles.
31 AC_COMPILE_IFELSE(
32 [AC_LANG_PROGRAM(
33 [#include <string.h>
34 ],
35 [return !*strerror (-2);])],
36 [gl_cv_func_working_strerror=yes],
37 [gl_cv_func_working_strerror=no])])])
38 if test $gl_cv_func_working_strerror = no ; then
39 REPLACE_STRERROR=1
40 gl_PREREQ_STRERROR
41 fi
42])
43
44# Prerequisites of lib/strerror.c.
45AC_DEFUN([gl_PREREQ_STRERROR], [
46 AC_CHECK_DECLS([strerror])
47])
diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4
new file mode 100644
index 0000000..766d7e9
--- /dev/null
+++ b/gl/m4/string_h.m4
@@ -0,0 +1,87 @@
1# Configure a GNU-like replacement for <string.h>.
2
3# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved.
7
8# serial 4
9
10# Written by Paul Eggert.
11
12AC_DEFUN([gl_HEADER_STRING_H],
13[
14 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
15 dnl once only, before all statements that occur in other macros.
16 AC_REQUIRE([gl_HEADER_STRING_H_BODY])
17])
18
19AC_DEFUN([gl_HEADER_STRING_H_BODY],
20[
21 AC_REQUIRE([AC_C_RESTRICT])
22 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
23 gl_CHECK_NEXT_HEADERS([string.h])
24])
25
26AC_DEFUN([gl_STRING_MODULE_INDICATOR],
27[
28 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
29 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
30 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
31])
32
33AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
34[
35 GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM])
36 GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY])
37 GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR])
38 GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY])
39 GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY])
40 GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL])
41 GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP])
42 GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP])
43 GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN])
44 GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK])
45 GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP])
46 GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR])
47 GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR])
48 GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R])
49 GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN])
50 GNULIB_MBSNLEN=0; AC_SUBST([GNULIB_MBSNLEN])
51 GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR])
52 GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR])
53 GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR])
54 GNULIB_MBSCASECMP=0; AC_SUBST([GNULIB_MBSCASECMP])
55 GNULIB_MBSNCASECMP=0; AC_SUBST([GNULIB_MBSNCASECMP])
56 GNULIB_MBSPCASECMP=0; AC_SUBST([GNULIB_MBSPCASECMP])
57 GNULIB_MBSCASESTR=0; AC_SUBST([GNULIB_MBSCASESTR])
58 GNULIB_MBSCSPN=0; AC_SUBST([GNULIB_MBSCSPN])
59 GNULIB_MBSPBRK=0; AC_SUBST([GNULIB_MBSPBRK])
60 GNULIB_MBSSPN=0; AC_SUBST([GNULIB_MBSSPN])
61 GNULIB_MBSSEP=0; AC_SUBST([GNULIB_MBSSEP])
62 GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R])
63 GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR])
64 GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL])
65 dnl Assume proper GNU behavior unless another module says otherwise.
66 HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM])
67 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY])
68 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR])
69 HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY])
70 HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY])
71 HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL])
72 HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP])
73 HAVE_STRNDUP=1; AC_SUBST([HAVE_STRNDUP])
74 HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP])
75 HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN])
76 HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK])
77 HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP])
78 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR])
79 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R])
80 HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR])
81 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL])
82 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
83 REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL])
84 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM])
85 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR])
86 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR])
87])
diff --git a/gl/m4/strndup.m4 b/gl/m4/strndup.m4
index dd5780b..f7934ef 100644
--- a/gl/m4/strndup.m4
+++ b/gl/m4/strndup.m4
@@ -1,5 +1,5 @@
1# strndup.m4 serial 11 1# strndup.m4 serial 14
2dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2007 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,15 +7,19 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_FUNC_STRNDUP], 7AC_DEFUN([gl_FUNC_STRNDUP],
8[ 8[
9 dnl Persuade glibc <string.h> to declare strndup(). 9 dnl Persuade glibc <string.h> to declare strndup().
10 AC_REQUIRE([AC_GNU_SOURCE]) 10 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11 11
12 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
12 AC_CHECK_DECLS_ONCE([strndup]) 13 AC_CHECK_DECLS_ONCE([strndup])
14 if test $ac_cv_have_decl_strndup = no; then
15 HAVE_DECL_STRNDUP=0
16 fi
13 17
14 # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. 18 # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
15 AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup, 19 AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup,
16 [AC_RUN_IFELSE([ 20 [AC_RUN_IFELSE([
17 AC_LANG_PROGRAM([#include <string.h> 21 AC_LANG_PROGRAM([#include <string.h>
18 #include <stdlib.h>], [[ 22 #include <stdlib.h>], [[
19#ifndef HAVE_DECL_STRNDUP 23#ifndef HAVE_DECL_STRNDUP
20 extern char *strndup (const char *, size_t); 24 extern char *strndup (const char *, size_t);
21#endif 25#endif
@@ -39,6 +43,7 @@ AC_DEFUN([gl_FUNC_STRNDUP],
39 AC_DEFINE([HAVE_STRNDUP], 1, 43 AC_DEFINE([HAVE_STRNDUP], 1,
40 [Define if you have the strndup() function and it works.]) 44 [Define if you have the strndup() function and it works.])
41 else 45 else
46 HAVE_STRNDUP=0
42 AC_LIBOBJ([strndup]) 47 AC_LIBOBJ([strndup])
43 gl_PREREQ_STRNDUP 48 gl_PREREQ_STRNDUP
44 fi 49 fi
diff --git a/gl/m4/strnlen.m4 b/gl/m4/strnlen.m4
index 0213a8a..d8307ed 100644
--- a/gl/m4/strnlen.m4
+++ b/gl/m4/strnlen.m4
@@ -1,5 +1,5 @@
1# strnlen.m4 serial 6 1# strnlen.m4 serial 9
2dnl Copyright (C) 2002-2003, 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2005-2007 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,11 +7,17 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_FUNC_STRNLEN], 7AC_DEFUN([gl_FUNC_STRNLEN],
8[ 8[
9 dnl Persuade glibc <string.h> to declare strnlen(). 9 dnl Persuade glibc <string.h> to declare strnlen().
10 AC_REQUIRE([AC_GNU_SOURCE]) 10 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11
12 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
13 AC_CHECK_DECLS_ONCE([strnlen])
14 if test $ac_cv_have_decl_strnlen = no; then
15 HAVE_DECL_STRNLEN=0
16 fi
11 17
12 AC_FUNC_STRNLEN 18 AC_FUNC_STRNLEN
13 if test $ac_cv_func_strnlen_working = no; then 19 if test $ac_cv_func_strnlen_working = no; then
14 # This is necessary because automake-1.6.1 doens't understand 20 # This is necessary because automake-1.6.1 doesn't understand
15 # that the above use of AC_FUNC_STRNLEN means we may have to use 21 # that the above use of AC_FUNC_STRNLEN means we may have to use
16 # lib/strnlen.c. 22 # lib/strnlen.c.
17 #AC_LIBOBJ(strnlen) 23 #AC_LIBOBJ(strnlen)
@@ -22,6 +28,4 @@ AC_DEFUN([gl_FUNC_STRNLEN],
22]) 28])
23 29
24# Prerequisites of lib/strnlen.c. 30# Prerequisites of lib/strnlen.c.
25AC_DEFUN([gl_PREREQ_STRNLEN], [ 31AC_DEFUN([gl_PREREQ_STRNLEN], [:])
26 AC_CHECK_DECLS_ONCE(strnlen)
27])
diff --git a/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4
index d3e45b4..d9659c2 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 2 1# sys_socket_h.m4 serial 4
2dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2006, 2007 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,16 +8,44 @@ dnl From Simon Josefsson.
8 8
9AC_DEFUN([gl_HEADER_SYS_SOCKET], 9AC_DEFUN([gl_HEADER_SYS_SOCKET],
10[ 10[
11 AC_CHECK_HEADERS_ONCE([sys/socket.h]) 11 AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
12 if test $ac_cv_header_sys_socket_h = yes; then 12 [gl_cv_header_sys_socket_h_selfcontained],
13 [
14 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/socket.h>], [])],
15 [gl_cv_header_sys_socket_h_selfcontained=yes],
16 [gl_cv_header_sys_socket_h_selfcontained=no])
17 ])
18 if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
13 SYS_SOCKET_H='' 19 SYS_SOCKET_H=''
14 else 20 else
15 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
16 dnl the check for those headers unconditional; yet cygwin reports
17 dnl that the headers are present but cannot be compiled (since on
18 dnl cygwin, all socket information should come from sys/socket.h).
19 AC_CHECK_HEADERS([winsock2.h ws2tcpip.h])
20 SYS_SOCKET_H='sys/socket.h' 21 SYS_SOCKET_H='sys/socket.h'
22
23 gl_CHECK_NEXT_HEADERS([sys/socket.h])
24 if test $ac_cv_header_sys_socket_h = yes; then
25 HAVE_SYS_SOCKET_H=1
26 HAVE_WINSOCK2_H=0
27 HAVE_WS2TCPIP_H=0
28 else
29 HAVE_SYS_SOCKET_H=0
30 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
31 dnl the check for those headers unconditional; yet cygwin reports
32 dnl that the headers are present but cannot be compiled (since on
33 dnl cygwin, all socket information should come from sys/socket.h).
34 AC_CHECK_HEADERS([winsock2.h ws2tcpip.h])
35 if test $ac_cv_header_winsock2_h = yes; then
36 HAVE_WINSOCK2_H=1
37 else
38 HAVE_WINSOCK2_H=0
39 fi
40 if test $ac_cv_header_ws2tcpip_h = yes; then
41 HAVE_WS2TCPIP_H=1
42 else
43 HAVE_WS2TCPIP_H=0
44 fi
45 fi
46 AC_SUBST([HAVE_SYS_SOCKET_H])
47 AC_SUBST([HAVE_WINSOCK2_H])
48 AC_SUBST([HAVE_WS2TCPIP_H])
21 fi 49 fi
22 AC_SUBST(SYS_SOCKET_H) 50 AC_SUBST([SYS_SOCKET_H])
23]) 51])
diff --git a/gl/m4/uintmax_t.m4 b/gl/m4/uintmax_t.m4
index bf83ed7..641c489 100644
--- a/gl/m4/uintmax_t.m4
+++ b/gl/m4/uintmax_t.m4
@@ -1,5 +1,5 @@
1# uintmax_t.m4 serial 9 1# uintmax_t.m4 serial 10
2dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2007 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,8 +16,8 @@ AC_DEFUN([gl_AC_TYPE_UINTMAX_T],
16 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 16 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
17 AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 17 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
18 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then 18 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
19 AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG]) 19 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
20 test $ac_cv_type_unsigned_long_long = yes \ 20 test $ac_cv_type_unsigned_long_long_int = yes \
21 && ac_type='unsigned long long' \ 21 && ac_type='unsigned long long' \
22 || ac_type='unsigned long' 22 || ac_type='unsigned long'
23 AC_DEFINE_UNQUOTED(uintmax_t, $ac_type, 23 AC_DEFINE_UNQUOTED(uintmax_t, $ac_type,
diff --git a/gl/m4/ulonglong.m4 b/gl/m4/ulonglong.m4
deleted file mode 100644
index 9fae98e..0000000
--- a/gl/m4/ulonglong.m4
+++ /dev/null
@@ -1,48 +0,0 @@
1# ulonglong.m4 serial 6
2dnl Copyright (C) 1999-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
7dnl From Paul Eggert.
8
9# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
10# This fixes a bug in Autoconf 2.60, but can be removed once we
11# assume 2.61 everywhere.
12
13# Note: If the type 'unsigned long long int' exists but is only 32 bits
14# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
15# will not be defined. In this case you can treat 'unsigned long long int'
16# like 'unsigned long int'.
17
18AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
19[
20 AC_CACHE_CHECK([for unsigned long long int],
21 [ac_cv_type_unsigned_long_long_int],
22 [AC_LINK_IFELSE(
23 [AC_LANG_PROGRAM(
24 [[unsigned long long int ull = 18446744073709551615ULL;
25 typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1
26 ? 1 : -1)];
27 int i = 63;]],
28 [[unsigned long long int ullmax = 18446744073709551615ull;
29 return (ull << 63 | ull >> 63 | ull << i | ull >> i
30 | ullmax / ull | ullmax % ull);]])],
31 [ac_cv_type_unsigned_long_long_int=yes],
32 [ac_cv_type_unsigned_long_long_int=no])])
33 if test $ac_cv_type_unsigned_long_long_int = yes; then
34 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1,
35 [Define to 1 if the system has the type `unsigned long long int'.])
36 fi
37])
38
39# This macro is obsolescent and should go away soon.
40AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG],
41[
42 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
43 ac_cv_type_unsigned_long_long=$ac_cv_type_unsigned_long_long_int
44 if test $ac_cv_type_unsigned_long_long = yes; then
45 AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1,
46 [Define if you have the 'unsigned long long' type.])
47 fi
48])
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4
index 9d499df..4b8857c 100644
--- a/gl/m4/unistd_h.m4
+++ b/gl/m4/unistd_h.m4
@@ -1,32 +1,61 @@
1# unistd_h.m4 serial 3 1# unistd_h.m4 serial 10
2dnl Copyright (C) 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2007 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
7dnl Written by Simon Josefsson 7dnl Written by Simon Josefsson, Bruno Haible.
8 8
9AC_DEFUN([gl_HEADER_UNISTD], 9AC_DEFUN([gl_UNISTD_H],
10[ 10[
11 AC_CHECK_HEADERS([unistd.h], [ 11 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
12 UNISTD_H='' 12 dnl once only, before all statements that occur in other macros.
13 ], [ 13 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
14 UNISTD_H='unistd.h' 14
15 ]) 15 gl_CHECK_NEXT_HEADERS([unistd.h])
16 AC_SUBST(UNISTD_H)
17 dnl This module decides to build unistd.h if it is missing.
18 dnl The fchdir module decides to build unistd.h if fchdir() is missing.
19 dnl Therefore check for the prerequisites of lib/unistd.h always.
20 gl_PREREQ_UNISTD
21])
22 16
23dnl Prerequisites of lib/unistd.h.
24AC_DEFUN([gl_PREREQ_UNISTD],
25[
26 AC_CHECK_HEADERS_ONCE([unistd.h]) 17 AC_CHECK_HEADERS_ONCE([unistd.h])
27 if test $ac_cv_header_unistd_h = yes; then 18 if test $ac_cv_header_unistd_h = yes; then
28 gl_ABSOLUTE_HEADER([unistd.h]) 19 HAVE_UNISTD_H=1
29 ABSOLUTE_UNISTD_H=\"$gl_cv_absolute_unistd_h\" 20 else
21 HAVE_UNISTD_H=0
30 fi 22 fi
31 AC_SUBST([ABSOLUTE_UNISTD_H]) 23 AC_SUBST([HAVE_UNISTD_H])
24])
25
26AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
27[
28 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
29 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
30 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
31])
32
33AC_DEFUN([gl_UNISTD_H_DEFAULTS],
34[
35 GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
36 GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2])
37 GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR])
38 GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
39 GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
40 GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
41 GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE])
42 GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN])
43 GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
44 GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
45 GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
46 dnl Assume proper GNU behavior unless another module says otherwise.
47 HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
48 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
49 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
50 HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
51 HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
52 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
53 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H])
54 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H])
55 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
56 REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR])
57 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
58 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
59 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
60 REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
32]) 61])
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index 72c9a13..c4d3f4f 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,5 +1,5 @@
1# vasnprintf.m4 serial 7 1# vasnprintf.m4 serial 24
2dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2006-2008 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,23 +7,33 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_FUNC_VASNPRINTF], 7AC_DEFUN([gl_FUNC_VASNPRINTF],
8[ 8[
9 AC_REQUIRE([gl_EOVERFLOW]) 9 AC_REQUIRE([gl_EOVERFLOW])
10 AC_REPLACE_FUNCS(vasnprintf) 10 AC_CHECK_FUNCS_ONCE([vasnprintf])
11 if test $ac_cv_func_vasnprintf = no; then 11 if test $ac_cv_func_vasnprintf = no; then
12 AC_LIBOBJ(printf-args) 12 gl_REPLACE_VASNPRINTF
13 AC_LIBOBJ(printf-parse)
14 AC_LIBOBJ(asnprintf)
15 gl_PREREQ_PRINTF_ARGS
16 gl_PREREQ_PRINTF_PARSE
17 gl_PREREQ_VASNPRINTF
18 gl_PREREQ_ASNPRINTF
19 fi 13 fi
20]) 14])
21 15
16AC_DEFUN([gl_REPLACE_VASNPRINTF],
17[
18 AC_CHECK_FUNCS_ONCE([vasnprintf])
19 AC_LIBOBJ([vasnprintf])
20 AC_LIBOBJ([printf-args])
21 AC_LIBOBJ([printf-parse])
22 AC_LIBOBJ([asnprintf])
23 if test $ac_cv_func_vasnprintf = yes; then
24 AC_DEFINE([REPLACE_VASNPRINTF], 1,
25 [Define if vasnprintf exists but is overridden by gnulib.])
26 fi
27 gl_PREREQ_PRINTF_ARGS
28 gl_PREREQ_PRINTF_PARSE
29 gl_PREREQ_VASNPRINTF
30 gl_PREREQ_ASNPRINTF
31])
32
22# Prequisites of lib/printf-args.h, lib/printf-args.c. 33# Prequisites of lib/printf-args.h, lib/printf-args.c.
23AC_DEFUN([gl_PREREQ_PRINTF_ARGS], 34AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
24[ 35[
25 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 36 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
26 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
27 AC_REQUIRE([gt_TYPE_WCHAR_T]) 37 AC_REQUIRE([gt_TYPE_WCHAR_T])
28 AC_REQUIRE([gt_TYPE_WINT_T]) 38 AC_REQUIRE([gt_TYPE_WINT_T])
29]) 39])
@@ -32,11 +42,13 @@ AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
32AC_DEFUN([gl_PREREQ_PRINTF_PARSE], 42AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
33[ 43[
34 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 44 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
35 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
36 AC_REQUIRE([gt_TYPE_WCHAR_T]) 45 AC_REQUIRE([gt_TYPE_WCHAR_T])
37 AC_REQUIRE([gt_TYPE_WINT_T]) 46 AC_REQUIRE([gt_TYPE_WINT_T])
38 AC_REQUIRE([AC_TYPE_SIZE_T]) 47 AC_REQUIRE([AC_TYPE_SIZE_T])
39 AC_CHECK_TYPES(ptrdiff_t) 48 AC_CHECK_TYPE([ptrdiff_t], ,
49 [AC_DEFINE([ptrdiff_t], [long],
50 [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
51 ])
40 AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) 52 AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
41]) 53])
42 54
@@ -45,10 +57,202 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF],
45[ 57[
46 AC_REQUIRE([AC_FUNC_ALLOCA]) 58 AC_REQUIRE([AC_FUNC_ALLOCA])
47 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 59 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
48 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
49 AC_REQUIRE([gt_TYPE_WCHAR_T]) 60 AC_REQUIRE([gt_TYPE_WCHAR_T])
50 AC_REQUIRE([gt_TYPE_WINT_T]) 61 AC_REQUIRE([gt_TYPE_WINT_T])
51 AC_CHECK_FUNCS(snprintf wcslen) 62 AC_CHECK_FUNCS(snprintf wcslen)
63 dnl Use the _snprintf function only if it is declared (because on NetBSD it
64 dnl is defined as a weak alias of snprintf; we prefer to use the latter).
65 AC_CHECK_DECLS([_snprintf], , , [#include <stdio.h>])
66])
67
68# Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
69# arguments.
70AC_DEFUN([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
71[
72 AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
73 case "$gl_cv_func_printf_long_double" in
74 *yes)
75 ;;
76 *)
77 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1,
78 [Define if the vasnprintf implementation needs special code for
79 'long double' arguments.])
80 ;;
81 esac
82])
83
84# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
85# arguments.
86AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
87[
88 AC_REQUIRE([gl_PRINTF_INFINITE])
89 case "$gl_cv_func_printf_infinite" in
90 *yes)
91 ;;
92 *)
93 AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], 1,
94 [Define if the vasnprintf implementation needs special code for
95 infinite 'double' arguments.])
96 ;;
97 esac
98])
99
100# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double'
101# arguments.
102AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
103[
104 AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
105 dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if
106 dnl NEED_PRINTF_LONG_DOUBLE is already set.
107 AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE])
108 case "$gl_cv_func_printf_long_double" in
109 *yes)
110 case "$gl_cv_func_printf_infinite_long_double" in
111 *yes)
112 ;;
113 *)
114 AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], 1,
115 [Define if the vasnprintf implementation needs special code for
116 infinite 'long double' arguments.])
117 ;;
118 esac
119 ;;
120 esac
121])
122
123# Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
124AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
125[
126 AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
127 case "$gl_cv_func_printf_directive_a" in
128 *yes)
129 ;;
130 *)
131 AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1,
132 [Define if the vasnprintf implementation needs special code for
133 the 'a' and 'A' directives.])
134 AC_CHECK_FUNCS([nl_langinfo])
135 ;;
136 esac
137])
138
139# Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive.
140AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
141[
142 AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
143 case "$gl_cv_func_printf_directive_f" in
144 *yes)
145 ;;
146 *)
147 AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], 1,
148 [Define if the vasnprintf implementation needs special code for
149 the 'F' directive.])
150 ;;
151 esac
152])
153
154# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
155AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
156[
157 AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
158 case "$gl_cv_func_printf_flag_grouping" in
159 *yes)
160 ;;
161 *)
162 AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], 1,
163 [Define if the vasnprintf implementation needs special code for the
164 ' flag.])
165 ;;
166 esac
167])
168
169# Extra prerequisites of lib/vasnprintf.c for supporting the '-' flag.
170AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST],
171[
172 AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
173 case "$gl_cv_func_printf_flag_leftadjust" in
174 *yes)
175 ;;
176 *)
177 AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], 1,
178 [Define if the vasnprintf implementation needs special code for the
179 '-' flag.])
180 ;;
181 esac
182])
183
184# Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag.
185AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
186[
187 AC_REQUIRE([gl_PRINTF_FLAG_ZERO])
188 case "$gl_cv_func_printf_flag_zero" in
189 *yes)
190 ;;
191 *)
192 AC_DEFINE([NEED_PRINTF_FLAG_ZERO], 1,
193 [Define if the vasnprintf implementation needs special code for the
194 0 flag.])
195 ;;
196 esac
197])
198
199# Extra prerequisites of lib/vasnprintf.c for supporting large precisions.
200AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
201[
202 AC_REQUIRE([gl_PRINTF_PRECISION])
203 case "$gl_cv_func_printf_precision" in
204 *yes)
205 ;;
206 *)
207 AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], 1,
208 [Define if the vasnprintf implementation needs special code for
209 supporting large precisions without arbitrary bounds.])
210 AC_DEFINE([NEED_PRINTF_DOUBLE], 1,
211 [Define if the vasnprintf implementation needs special code for
212 'double' arguments.])
213 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1,
214 [Define if the vasnprintf implementation needs special code for
215 'long double' arguments.])
216 ;;
217 esac
218])
219
220# Extra prerequisites of lib/vasnprintf.c for surviving out-of-memory
221# conditions.
222AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
223[
224 AC_REQUIRE([gl_PRINTF_ENOMEM])
225 case "$gl_cv_func_printf_enomem" in
226 *yes)
227 ;;
228 *)
229 AC_DEFINE([NEED_PRINTF_ENOMEM], 1,
230 [Define if the vasnprintf implementation needs special code for
231 surviving out-of-memory conditions.])
232 AC_DEFINE([NEED_PRINTF_DOUBLE], 1,
233 [Define if the vasnprintf implementation needs special code for
234 'double' arguments.])
235 AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1,
236 [Define if the vasnprintf implementation needs special code for
237 'long double' arguments.])
238 ;;
239 esac
240])
241
242# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
243AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
244[
245 AC_REQUIRE([gl_PREREQ_VASNPRINTF])
246 gl_PREREQ_VASNPRINTF_LONG_DOUBLE
247 gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
248 gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
249 gl_PREREQ_VASNPRINTF_DIRECTIVE_A
250 gl_PREREQ_VASNPRINTF_DIRECTIVE_F
251 gl_PREREQ_VASNPRINTF_FLAG_GROUPING
252 gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
253 gl_PREREQ_VASNPRINTF_FLAG_ZERO
254 gl_PREREQ_VASNPRINTF_PRECISION
255 gl_PREREQ_VASNPRINTF_ENOMEM
52]) 256])
53 257
54# Prerequisites of lib/asnprintf.c. 258# Prerequisites of lib/asnprintf.c.
diff --git a/gl/m4/vasprintf.m4 b/gl/m4/vasprintf.m4
index 18ca632..074b03c 100644
--- a/gl/m4/vasprintf.m4
+++ b/gl/m4/vasprintf.m4
@@ -1,25 +1,37 @@
1# vasprintf.m4 serial 2 1# vasprintf.m4 serial 6
2dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2006-2007 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_FUNC_VASPRINTF], 7AC_DEFUN([gl_FUNC_VASPRINTF],
8[ 8[
9 AC_REPLACE_FUNCS(vasprintf) 9 AC_CHECK_FUNCS([vasprintf])
10 if test $ac_cv_func_vasprintf = no; then 10 if test $ac_cv_func_vasprintf = no; then
11 AC_LIBOBJ(asprintf) 11 gl_REPLACE_VASPRINTF
12 gl_PREREQ_VASPRINTF_H
13 gl_PREREQ_VASPRINTF
14 gl_PREREQ_ASPRINTF
15 fi 12 fi
16]) 13])
17 14
18# Prerequisites of lib/vasprintf.h. 15AC_DEFUN([gl_REPLACE_VASPRINTF],
16[
17 AC_LIBOBJ([vasprintf])
18 AC_LIBOBJ([asprintf])
19 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
20 if test $ac_cv_func_vasprintf = yes; then
21 REPLACE_VASPRINTF=1
22 else
23 HAVE_VASPRINTF=0
24 fi
25 gl_PREREQ_VASPRINTF_H
26 gl_PREREQ_VASPRINTF
27 gl_PREREQ_ASPRINTF
28])
29
30# Prerequisites of the vasprintf portion of lib/stdio.h.
19AC_DEFUN([gl_PREREQ_VASPRINTF_H], 31AC_DEFUN([gl_PREREQ_VASPRINTF_H],
20[ 32[
21 dnl Persuade glibc <stdio.h> to declare asprintf() and vasprintf(). 33 dnl Persuade glibc <stdio.h> to declare asprintf() and vasprintf().
22 AC_REQUIRE([AC_GNU_SOURCE]) 34 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
23]) 35])
24 36
25# Prerequisites of lib/vasprintf.c. 37# Prerequisites of lib/vasprintf.c.
diff --git a/gl/m4/vsnprintf.m4 b/gl/m4/vsnprintf.m4
index cb8a9b1..accc79f 100644
--- a/gl/m4/vsnprintf.m4
+++ b/gl/m4/vsnprintf.m4
@@ -1,13 +1,29 @@
1# vsnprintf.m4 serial 2 1# vsnprintf.m4 serial 4
2dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2003, 2004, 2007 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_FUNC_VSNPRINTF], 7AC_DEFUN([gl_FUNC_VSNPRINTF],
8[ 8[
9 AC_REPLACE_FUNCS(vsnprintf) 9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_CHECK_DECLS_ONCE(vsnprintf) 10 AC_CHECK_FUNCS([vsnprintf])
11 if test $ac_cv_func_vsnprintf = no; then
12 gl_REPLACE_VSNPRINTF
13 fi
14 AC_CHECK_DECLS_ONCE([vsnprintf])
15 if test $ac_cv_have_decl_vsnprintf = no; then
16 HAVE_DECL_VSNPRINTF=0
17 fi
18])
19
20AC_DEFUN([gl_REPLACE_VSNPRINTF],
21[
22 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
23 AC_LIBOBJ([vsnprintf])
24 if test $ac_cv_func_vsnprintf = yes; then
25 REPLACE_VSNPRINTF=1
26 fi
11 gl_PREREQ_VSNPRINTF 27 gl_PREREQ_VSNPRINTF
12]) 28])
13 29
diff --git a/gl/m4/wchar.m4 b/gl/m4/wchar.m4
index 068f22d..70b1248 100644
--- a/gl/m4/wchar.m4
+++ b/gl/m4/wchar.m4
@@ -7,23 +7,48 @@ dnl 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 1 10# wchar.m4 serial 4
11 11
12AC_DEFUN([gl_WCHAR_H], 12AC_DEFUN([gl_WCHAR_H],
13[ 13[
14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
14 AC_CACHE_CHECK([whether <wchar.h> is standalone], 15 AC_CACHE_CHECK([whether <wchar.h> is standalone],
15 [gl_cv_header_wchar_h_standalone], 16 [gl_cv_header_wchar_h_standalone],
16 [AC_COMPILE_IFELSE([[#include <wchar.h> 17 [AC_COMPILE_IFELSE([[#include <wchar.h>
17wchar_t w;]], 18wchar_t w;]],
18 [gl_cv_header_wchar_h_standalone=yes], 19 [gl_cv_header_wchar_h_standalone=yes],
19 [gl_cv_header_wchar_h_standalone=no])]) 20 [gl_cv_header_wchar_h_standalone=no])])
20 if test $gl_cv_header_wchar_h_standalone = yes; then 21 if test $gl_cv_header_wchar_h_standalone != yes; then
21 WCHAR_H=
22 else
23 gl_ABSOLUTE_HEADER([wchar.h])
24 ABSOLUTE_WCHAR_H=\"$gl_cv_absolute_wchar_h\"
25 WCHAR_H=wchar.h 22 WCHAR_H=wchar.h
26 fi 23 fi
27 AC_SUBST([ABSOLUTE_WCHAR_H]) 24
25 dnl Prepare for creating substitute <wchar.h>.
26 dnl Do it always: WCHAR_H may be empty here but can be set later.
27 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
28 dnl character support).
29 AC_CHECK_HEADERS_ONCE([wchar.h])
30 if test $ac_cv_header_wchar_h = yes; then
31 HAVE_WCHAR_H=1
32 else
33 HAVE_WCHAR_H=0
34 fi
35 AC_SUBST([HAVE_WCHAR_H])
36 gl_CHECK_NEXT_HEADERS([wchar.h])
37])
38
39AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
40[
41 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
42 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
43 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
44])
45
46AC_DEFUN([gl_WCHAR_H_DEFAULTS],
47[
48 GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
49 dnl Assume proper GNU behavior unless another module says otherwise.
50 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
51 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
52 WCHAR_H=
28 AC_SUBST([WCHAR_H]) 53 AC_SUBST([WCHAR_H])
29]) 54])
diff --git a/gl/m4/wctype.m4 b/gl/m4/wctype.m4
index 62994c6..7483c4f 100644
--- a/gl/m4/wctype.m4
+++ b/gl/m4/wctype.m4
@@ -10,6 +10,12 @@ dnl Written by Paul Eggert.
10AC_DEFUN([gl_WCTYPE_H], 10AC_DEFUN([gl_WCTYPE_H],
11[ 11[
12 AC_CHECK_FUNCS_ONCE([iswcntrl]) 12 AC_CHECK_FUNCS_ONCE([iswcntrl])
13 if test $ac_cv_func_iswcntrl = yes; then
14 HAVE_ISWCNTRL=1
15 else
16 HAVE_ISWCNTRL=0
17 fi
18 AC_SUBST([HAVE_ISWCNTRL])
13 AC_CHECK_HEADERS_ONCE([wctype.h]) 19 AC_CHECK_HEADERS_ONCE([wctype.h])
14 AC_REQUIRE([AC_C_INLINE]) 20 AC_REQUIRE([AC_C_INLINE])
15 21
@@ -23,19 +29,16 @@ AC_DEFUN([gl_WCTYPE_H],
23 29
24 WCTYPE_H=wctype.h 30 WCTYPE_H=wctype.h
25 if test $ac_cv_header_wctype_h = yes; then 31 if test $ac_cv_header_wctype_h = yes; then
26 if test "$ac_cv_func_iswcntrl" = yes; then 32 if test $ac_cv_func_iswcntrl = yes; then
27 WCTYPE_H= 33 WCTYPE_H=
28 fi 34 fi
29 dnl Compute ABSOLUTE_WCTYPE_H even if WCTYPE_H is empty, 35 dnl Compute NEXT_WCTYPE_H even if WCTYPE_H is empty,
30 dnl for the benefit of builds from non-distclean directories. 36 dnl for the benefit of builds from non-distclean directories.
31 gl_ABSOLUTE_HEADER([wctype.h]) 37 gl_CHECK_NEXT_HEADERS([wctype.h])
32 ABSOLUTE_WCTYPE_H=\"$gl_cv_absolute_wctype_h\"
33 HAVE_WCTYPE_H=1 38 HAVE_WCTYPE_H=1
34 else 39 else
35 ABSOLUTE_WCTYPE_H=\"no/such/file/wctype.h\"
36 HAVE_WCTYPE_H=0 40 HAVE_WCTYPE_H=0
37 fi 41 fi
38 AC_SUBST([ABSOLUTE_WCTYPE_H])
39 AC_SUBST([HAVE_WCTYPE_H]) 42 AC_SUBST([HAVE_WCTYPE_H])
40 AC_SUBST([WCTYPE_H]) 43 AC_SUBST([WCTYPE_H])
41]) 44])
diff --git a/gl/m4/wcwidth.m4 b/gl/m4/wcwidth.m4
deleted file mode 100644
index b483499..0000000
--- a/gl/m4/wcwidth.m4
+++ /dev/null
@@ -1,30 +0,0 @@
1# wcwidth.m4 serial 8
2dnl Copyright (C) 2006, 2007 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_WCWIDTH],
8[
9 dnl Persuade glibc <wchar.h> to declare wcwidth().
10 AC_REQUIRE([AC_GNU_SOURCE])
11
12 AC_REQUIRE([AC_C_INLINE])
13 AC_REQUIRE([gt_TYPE_WCHAR_T])
14 AC_REQUIRE([gt_TYPE_WINT_T])
15
16 AC_CHECK_HEADERS_ONCE([wchar.h])
17 AC_CHECK_FUNCS_ONCE([wcwidth])
18
19 AC_CHECK_DECLS([wcwidth], [], [], [
20/* AIX 3.2.5 declares wcwidth in <string.h>. */
21#include <string.h>
22/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
23 <wchar.h>.
24 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
25 before <wchar.h>. */
26#include <stddef.h>
27#include <stdio.h>
28#include <time.h>
29#include <wchar.h>
30])])
diff --git a/gl/m4/wint_t.m4 b/gl/m4/wint_t.m4
index 3706c04..af5ed93 100644
--- a/gl/m4/wint_t.m4
+++ b/gl/m4/wint_t.m4
@@ -1,4 +1,4 @@
1# wint_t.m4 serial 2 (gettext-0.12) 1# wint_t.m4 serial 2 (gettext-0.17)
2dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007 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,
diff --git a/gl/malloc.c b/gl/malloc.c
index d4dae3e..f2f6663 100644
--- a/gl/malloc.c
+++ b/gl/malloc.c
@@ -1,10 +1,10 @@
1/* malloc() function that is glibc compatible. 1/* malloc() function that is glibc compatible.
2 2
3 Copyright (C) 1997, 1998, 2006 Free Software Foundation, Inc. 3 Copyright (C) 1997, 1998, 2006, 2007 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -16,20 +16,42 @@
16 along with this program; if not, write to the Free Software Foundation, 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. */ 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 18
19/* written by Jim Meyering */ 19/* written by Jim Meyering and Bruno Haible */
20 20
21#include <config.h> 21#include <config.h>
22#undef malloc 22/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
23#ifdef malloc
24# define NEED_MALLOC_GNU
25# undef malloc
26#endif
23 27
28/* Specification. */
24#include <stdlib.h> 29#include <stdlib.h>
25 30
31#include <errno.h>
32
33/* Call the system's malloc below. */
34#undef malloc
35
26/* Allocate an N-byte block of memory from the heap. 36/* Allocate an N-byte block of memory from the heap.
27 If N is zero, allocate a 1-byte block. */ 37 If N is zero, allocate a 1-byte block. */
28 38
29void * 39void *
30rpl_malloc (size_t n) 40rpl_malloc (size_t n)
31{ 41{
42 void *result;
43
44#ifdef NEED_MALLOC_GNU
32 if (n == 0) 45 if (n == 0)
33 n = 1; 46 n = 1;
34 return malloc (n); 47#endif
48
49 result = malloc (n);
50
51#if !HAVE_MALLOC_POSIX
52 if (result == NULL)
53 errno = ENOMEM;
54#endif
55
56 return result;
35} 57}
diff --git a/gl/mbchar.c b/gl/mbchar.c
deleted file mode 100644
index 95373f5..0000000
--- a/gl/mbchar.c
+++ /dev/null
@@ -1,36 +0,0 @@
1/* Copyright (C) 2001, 2006 Free Software Foundation, Inc.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17
18#include <config.h>
19
20#include <limits.h>
21
22#include "mbchar.h"
23
24#if IS_BASIC_ASCII
25
26/* Bit table of characters in the ISO C "basic character set". */
27const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] =
28{
29 0x00001a00, /* '\t' '\v' '\f' */
30 0xffffffef, /* ' '...'#' '%'...'?' */
31 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */
32 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */
33 /* The remaining bits are 0. */
34};
35
36#endif /* IS_BASIC_ASCII */
diff --git a/gl/mbchar.h b/gl/mbchar.h
deleted file mode 100644
index f3e28ef..0000000
--- a/gl/mbchar.h
+++ /dev/null
@@ -1,353 +0,0 @@
1/* Multibyte character data type.
2 Copyright (C) 2001, 2005-2006 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 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18/* Written by Bruno Haible <bruno@clisp.org>. */
19
20/* A multibyte character is a short subsequence of a char* string,
21 representing a single wide character.
22
23 We use multibyte characters instead of wide characters because of
24 the following goals:
25 1) correct multibyte handling, i.e. operate according to the LC_CTYPE
26 locale,
27 2) ease of maintenance, i.e. the maintainer needs not know all details
28 of the ISO C 99 standard,
29 3) don't fail grossly if the input is not in the encoding set by the
30 locale, because often different encodings are in use in the same
31 countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...),
32 4) fast in the case of ASCII characters,
33 5) portability, i.e. don't make unportable assumptions about wchar_t.
34
35 Multibyte characters are only accessed through the mb* macros.
36
37 mb_ptr (mbc)
38 return a pointer to the beginning of the multibyte sequence.
39
40 mb_len (mbc)
41 returns the number of bytes occupied by the multibyte sequence.
42 Always > 0.
43
44 mb_iseq (mbc, sc)
45 returns true if mbc is the standard ASCII character sc.
46
47 mb_isnul (mbc)
48 returns true if mbc is the nul character.
49
50 mb_cmp (mbc1, mbc2)
51 returns a positive, zero, or negative value depending on whether mbc1
52 sorts after, same or before mbc2.
53
54 mb_casecmp (mbc1, mbc2)
55 returns a positive, zero, or negative value depending on whether mbc1
56 sorts after, same or before mbc2, modulo upper/lowercase conversion.
57
58 mb_equal (mbc1, mbc2)
59 returns true if mbc1 and mbc2 are equal.
60
61 mb_caseequal (mbc1, mbc2)
62 returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion.
63
64 mb_isalnum (mbc)
65 returns true if mbc is alphanumeric.
66
67 mb_isalpha (mbc)
68 returns true if mbc is alphabetic.
69
70 mb_isascii(mbc)
71 returns true if mbc is plain ASCII.
72
73 mb_isblank (mbc)
74 returns true if mbc is a blank.
75
76 mb_iscntrl (mbc)
77 returns true if mbc is a control character.
78
79 mb_isdigit (mbc)
80 returns true if mbc is a decimal digit.
81
82 mb_isgraph (mbc)
83 returns true if mbc is a graphic character.
84
85 mb_islower (mbc)
86 returns true if mbc is lowercase.
87
88 mb_isprint (mbc)
89 returns true if mbc is a printable character.
90
91 mb_ispunct (mbc)
92 returns true if mbc is a punctuation character.
93
94 mb_isspace (mbc)
95 returns true if mbc is a space character.
96
97 mb_isupper (mbc)
98 returns true if mbc is uppercase.
99
100 mb_isxdigit (mbc)
101 returns true if mbc is a hexadecimal digit.
102
103 mb_width (mbc)
104 returns the number of columns on the output device occupied by mbc.
105 Always >= 0.
106
107 mb_putc (mbc, stream)
108 outputs mbc on stream, a byte oriented FILE stream opened for output.
109
110 mb_setascii (&mbc, sc)
111 assigns the standard ASCII character sc to mbc.
112
113 mb_copy (&destmbc, &srcmbc)
114 copies srcmbc to destmbc.
115
116 Here are the function prototypes of the macros.
117
118 extern const char * mb_ptr (const mbchar_t mbc);
119 extern size_t mb_len (const mbchar_t mbc);
120 extern bool mb_iseq (const mbchar_t mbc, char sc);
121 extern bool mb_isnul (const mbchar_t mbc);
122 extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2);
123 extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2);
124 extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2);
125 extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2);
126 extern bool mb_isalnum (const mbchar_t mbc);
127 extern bool mb_isalpha (const mbchar_t mbc);
128 extern bool mb_isascii (const mbchar_t mbc);
129 extern bool mb_isblank (const mbchar_t mbc);
130 extern bool mb_iscntrl (const mbchar_t mbc);
131 extern bool mb_isdigit (const mbchar_t mbc);
132 extern bool mb_isgraph (const mbchar_t mbc);
133 extern bool mb_islower (const mbchar_t mbc);
134 extern bool mb_isprint (const mbchar_t mbc);
135 extern bool mb_ispunct (const mbchar_t mbc);
136 extern bool mb_isspace (const mbchar_t mbc);
137 extern bool mb_isupper (const mbchar_t mbc);
138 extern bool mb_isxdigit (const mbchar_t mbc);
139 extern int mb_width (const mbchar_t mbc);
140 extern void mb_putc (const mbchar_t mbc, FILE *stream);
141 extern void mb_setascii (mbchar_t *new, char sc);
142 extern void mb_copy (mbchar_t *new, const mbchar_t *old);
143 */
144
145#ifndef _MBCHAR_H
146#define _MBCHAR_H 1
147
148#include <stdbool.h>
149#include <string.h>
150
151/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
152 <wchar.h>.
153 BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
154 <wchar.h>. */
155#include <stdio.h>
156#include <time.h>
157#include <wchar.h>
158#include <wctype.h>
159
160#include "wcwidth.h"
161
162#define MBCHAR_BUF_SIZE 24
163
164struct mbchar
165{
166 const char *ptr; /* pointer to current character */
167 size_t bytes; /* number of bytes of current character, > 0 */
168 bool wc_valid; /* true if wc is a valid wide character */
169 wchar_t wc; /* if wc_valid: the current character */
170 char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */
171};
172
173/* EOF (not a real character) is represented with bytes = 0 and
174 wc_valid = false. */
175
176typedef struct mbchar mbchar_t;
177
178/* Access the current character. */
179#define mb_ptr(mbc) ((mbc).ptr)
180#define mb_len(mbc) ((mbc).bytes)
181
182/* Comparison of characters. */
183#define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc))
184#define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0)
185#define mb_cmp(mbc1, mbc2) \
186 ((mbc1).wc_valid \
187 ? ((mbc2).wc_valid \
188 ? (int) (mbc1).wc - (int) (mbc2).wc \
189 : -1) \
190 : ((mbc2).wc_valid \
191 ? 1 \
192 : (mbc1).bytes == (mbc2).bytes \
193 ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \
194 : (mbc1).bytes < (mbc2).bytes \
195 ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \
196 : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1)))
197#define mb_casecmp(mbc1, mbc2) \
198 ((mbc1).wc_valid \
199 ? ((mbc2).wc_valid \
200 ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \
201 : -1) \
202 : ((mbc2).wc_valid \
203 ? 1 \
204 : (mbc1).bytes == (mbc2).bytes \
205 ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \
206 : (mbc1).bytes < (mbc2).bytes \
207 ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \
208 : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1)))
209#define mb_equal(mbc1, mbc2) \
210 ((mbc1).wc_valid && (mbc2).wc_valid \
211 ? (mbc1).wc == (mbc2).wc \
212 : (mbc1).bytes == (mbc2).bytes \
213 && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0)
214#define mb_caseequal(mbc1, mbc2) \
215 ((mbc1).wc_valid && (mbc2).wc_valid \
216 ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \
217 : (mbc1).bytes == (mbc2).bytes \
218 && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0)
219
220/* <ctype.h>, <wctype.h> classification. */
221#define mb_isascii(mbc) \
222 ((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127)
223#define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc))
224#define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc))
225#define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc))
226#define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc))
227#define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc))
228#define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc))
229#define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc))
230#define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc))
231#define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc))
232#define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc))
233#define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc))
234#define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc))
235
236/* Extra <wchar.h> function. */
237
238/* Unprintable characters appear as a small box of width 1. */
239#define MB_UNPRINTABLE_WIDTH 1
240
241static inline int
242mb_width_aux (wint_t wc)
243{
244 int w = wcwidth (wc);
245 /* For unprintable characters, arbitrarily return 0 for control characters
246 and MB_UNPRINTABLE_WIDTH otherwise. */
247 return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH);
248}
249
250#define mb_width(mbc) \
251 ((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH)
252
253/* Output. */
254#define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream))
255
256/* Assignment. */
257#define mb_setascii(mbc, sc) \
258 ((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \
259 (mbc)->wc = (mbc)->buf[0] = (sc))
260
261/* Copying a character. */
262static inline void
263mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc)
264{
265 if (old_mbc->ptr == &old_mbc->buf[0])
266 {
267 memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes);
268 new_mbc->ptr = &new_mbc->buf[0];
269 }
270 else
271 new_mbc->ptr = old_mbc->ptr;
272 new_mbc->bytes = old_mbc->bytes;
273 if ((new_mbc->wc_valid = old_mbc->wc_valid))
274 new_mbc->wc = old_mbc->wc;
275}
276
277
278/* is_basic(c) tests whether the single-byte character c is in the
279 ISO C "basic character set".
280 This is a convenience function, and is in this file only to share code
281 between mbiter_multi.h and mbfile_multi.h. */
282#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
283 && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
284 && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
285 && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
286 && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
287 && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
288 && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
289 && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
290 && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
291 && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
292 && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
293 && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
294 && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
295 && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
296 && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
297 && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
298 && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
299 && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
300 && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
301 && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
302 && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
303 && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
304 && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
305/* The character set is ISO-646, not EBCDIC. */
306# define IS_BASIC_ASCII 1
307
308extern const unsigned int is_basic_table[];
309
310static inline bool
311is_basic (char c)
312{
313 return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31))
314 & 1;
315}
316
317#else
318
319static inline bool
320is_basic (char c)
321{
322 switch (c)
323 {
324 case '\t': case '\v': case '\f':
325 case ' ': case '!': case '"': case '#': case '%':
326 case '&': case '\'': case '(': case ')': case '*':
327 case '+': case ',': case '-': case '.': case '/':
328 case '0': case '1': case '2': case '3': case '4':
329 case '5': case '6': case '7': case '8': case '9':
330 case ':': case ';': case '<': case '=': case '>':
331 case '?':
332 case 'A': case 'B': case 'C': case 'D': case 'E':
333 case 'F': case 'G': case 'H': case 'I': case 'J':
334 case 'K': case 'L': case 'M': case 'N': case 'O':
335 case 'P': case 'Q': case 'R': case 'S': case 'T':
336 case 'U': case 'V': case 'W': case 'X': case 'Y':
337 case 'Z':
338 case '[': case '\\': case ']': case '^': case '_':
339 case 'a': case 'b': case 'c': case 'd': case 'e':
340 case 'f': case 'g': case 'h': case 'i': case 'j':
341 case 'k': case 'l': case 'm': case 'n': case 'o':
342 case 'p': case 'q': case 'r': case 's': case 't':
343 case 'u': case 'v': case 'w': case 'x': case 'y':
344 case 'z': case '{': case '|': case '}': case '~':
345 return 1;
346 default:
347 return 0;
348 }
349}
350
351#endif
352
353#endif /* _MBCHAR_H */
diff --git a/gl/mbuiter.h b/gl/mbuiter.h
deleted file mode 100644
index 9da3a6c..0000000
--- a/gl/mbuiter.h
+++ /dev/null
@@ -1,203 +0,0 @@
1/* Iterating through multibyte strings: macros for multi-byte encodings.
2 Copyright (C) 2001, 2005 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 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18/* Written by Bruno Haible <bruno@clisp.org>. */
19
20/* The macros in this file implement forward iteration through a
21 multi-byte string, without knowing its length a-priori.
22
23 With these macros, an iteration loop that looks like
24
25 char *iter;
26 for (iter = buf; *iter != '\0'; iter++)
27 {
28 do_something (*iter);
29 }
30
31 becomes
32
33 mbui_iterator_t iter;
34 for (mbui_init (iter, buf); mbui_avail (iter); mbui_advance (iter))
35 {
36 do_something (mbui_cur_ptr (iter), mb_len (mbui_cur (iter)));
37 }
38
39 The benefit of these macros over plain use of mbrtowc is:
40 - Handling of invalid multibyte sequences is possible without
41 making the code more complicated, while still preserving the
42 invalid multibyte sequences.
43
44 Compared to mbiter.h, the macros here don't need to know the string's
45 length a-priori. The downside is that at each step, the look-ahead
46 that guards against overrunning the terminating '\0' is more expensive.
47 The mbui_* macros are therefore suitable when there is a high probability
48 that only the first few multibyte characters need to be inspected.
49 Whereas the mbi_* macros are better if usually the iteration runs
50 through the entire string.
51
52 mbui_iterator_t
53 is a type usable for variable declarations.
54
55 mbui_init (iter, startptr)
56 initializes the iterator, starting at startptr.
57
58 mbui_avail (iter)
59 returns true if there are more multibyte chracters available before
60 the end of string is reached. In this case, mbui_cur (iter) is
61 initialized to the next multibyte chracter.
62
63 mbui_advance (iter)
64 advances the iterator by one multibyte character.
65
66 mbui_cur (iter)
67 returns the current multibyte character, of type mbchar_t. All the
68 macros defined in mbchar.h can be used on it.
69
70 mbui_cur_ptr (iter)
71 return a pointer to the beginning of the current multibyte character.
72
73 mbui_reloc (iter, ptrdiff)
74 relocates iterator when the string is moved by ptrdiff bytes.
75
76 Here are the function prototypes of the macros.
77
78 extern void mbui_init (mbui_iterator_t iter, const char *startptr);
79 extern bool mbui_avail (mbui_iterator_t iter);
80 extern void mbui_advance (mbui_iterator_t iter);
81 extern mbchar_t mbui_cur (mbui_iterator_t iter);
82 extern const char * mbui_cur_ptr (mbui_iterator_t iter);
83 extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff);
84 */
85
86#ifndef _MBUITER_H
87#define _MBUITER_H 1
88
89#include <assert.h>
90#include <stdbool.h>
91#include <stdlib.h>
92
93/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
94 <wchar.h>.
95 BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
96 <wchar.h>. */
97#include <stdio.h>
98#include <time.h>
99#include <wchar.h>
100
101#include "mbchar.h"
102#include "strnlen1.h"
103
104struct mbuiter_multi
105{
106 bool in_shift; /* true if next byte may not be interpreted as ASCII */
107 mbstate_t state; /* if in_shift: current shift state */
108 bool next_done; /* true if mbui_avail has already filled the following */
109 struct mbchar cur; /* the current character:
110 const char *cur.ptr pointer to current character
111 The following are only valid after mbui_avail.
112 size_t cur.bytes number of bytes of current character
113 bool cur.wc_valid true if wc is a valid wide character
114 wchar_t cur.wc if wc_valid: the current character
115 */
116};
117
118static inline void
119mbuiter_multi_next (struct mbuiter_multi *iter)
120{
121 if (iter->next_done)
122 return;
123 if (iter->in_shift)
124 goto with_shift;
125 /* Handle most ASCII characters quickly, without calling mbrtowc(). */
126 if (is_basic (*iter->cur.ptr))
127 {
128 /* These characters are part of the basic character set. ISO C 99
129 guarantees that their wide character code is identical to their
130 char code. */
131 iter->cur.bytes = 1;
132 iter->cur.wc = *iter->cur.ptr;
133 iter->cur.wc_valid = true;
134 }
135 else
136 {
137 assert (mbsinit (&iter->state));
138 iter->in_shift = true;
139 with_shift:
140 iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr,
141 strnlen1 (iter->cur.ptr, MB_CUR_MAX),
142 &iter->state);
143 if (iter->cur.bytes == (size_t) -1)
144 {
145 /* An invalid multibyte sequence was encountered. */
146 iter->cur.bytes = 1;
147 iter->cur.wc_valid = false;
148 /* Whether to set iter->in_shift = false and reset iter->state
149 or not is not very important; the string is bogus anyway. */
150 }
151 else if (iter->cur.bytes == (size_t) -2)
152 {
153 /* An incomplete multibyte character at the end. */
154 iter->cur.bytes = strlen (iter->cur.ptr);
155 iter->cur.wc_valid = false;
156 /* Whether to set iter->in_shift = false and reset iter->state
157 or not is not important; the string end is reached anyway. */
158 }
159 else
160 {
161 if (iter->cur.bytes == 0)
162 {
163 /* A null wide character was encountered. */
164 iter->cur.bytes = 1;
165 assert (*iter->cur.ptr == '\0');
166 assert (iter->cur.wc == 0);
167 }
168 iter->cur.wc_valid = true;
169
170 /* When in the initial state, we can go back treating ASCII
171 characters more quickly. */
172 if (mbsinit (&iter->state))
173 iter->in_shift = false;
174 }
175 }
176 iter->next_done = true;
177}
178
179static inline void
180mbuiter_multi_reloc (struct mbuiter_multi *iter, ptrdiff_t ptrdiff)
181{
182 iter->cur.ptr += ptrdiff;
183}
184
185/* Iteration macros. */
186typedef struct mbuiter_multi mbui_iterator_t;
187#define mbui_init(iter, startptr) \
188 ((iter).cur.ptr = (startptr), \
189 (iter).in_shift = false, memset (&(iter).state, '\0', sizeof (mbstate_t)), \
190 (iter).next_done = false)
191#define mbui_avail(iter) \
192 (mbuiter_multi_next (&(iter)), !mb_isnul ((iter).cur))
193#define mbui_advance(iter) \
194 ((iter).cur.ptr += (iter).cur.bytes, (iter).next_done = false)
195
196/* Access to the current character. */
197#define mbui_cur(iter) (iter).cur
198#define mbui_cur_ptr(iter) (iter).cur.ptr
199
200/* Relocation. */
201#define mbui_reloc(iter, ptrdiff) mbuiter_multi_reloc (&iter, ptrdiff)
202
203#endif /* _MBUITER_H */
diff --git a/gl/memchr.c b/gl/memchr.c
deleted file mode 100644
index d44ad6d..0000000
--- a/gl/memchr.c
+++ /dev/null
@@ -1,201 +0,0 @@
1/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006 Free
2 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 2, or (at your option) 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, write to the Free Software Foundation,
25Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
26
27#ifndef _LIBC
28# include <config.h>
29#endif
30
31#include <string.h>
32
33#include <stddef.h>
34
35#if defined _LIBC
36# include <memcopy.h>
37#else
38# define reg_char char
39#endif
40
41#include <limits.h>
42
43#if HAVE_BP_SYM_H || defined _LIBC
44# include <bp-sym.h>
45#else
46# define BP_SYM(sym) sym
47#endif
48
49#undef memchr
50#undef __memchr
51
52/* Search no more than N bytes of S for C. */
53void *
54__memchr (void const *s, int c_in, size_t n)
55{
56 const unsigned char *char_ptr;
57 const unsigned long int *longword_ptr;
58 unsigned long int longword, magic_bits, charmask;
59 unsigned reg_char c;
60 int i;
61
62 c = (unsigned char) c_in;
63
64 /* Handle the first few characters by reading one character at a time.
65 Do this until CHAR_PTR is aligned on a longword boundary. */
66 for (char_ptr = (const unsigned char *) s;
67 n > 0 && (size_t) char_ptr % sizeof longword != 0;
68 --n, ++char_ptr)
69 if (*char_ptr == c)
70 return (void *) char_ptr;
71
72 /* All these elucidatory comments refer to 4-byte longwords,
73 but the theory applies equally well to any size longwords. */
74
75 longword_ptr = (const unsigned long int *) char_ptr;
76
77 /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
78 the "holes." Note that there is a hole just to the left of
79 each byte, with an extra at the end:
80
81 bits: 01111110 11111110 11111110 11111111
82 bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
83
84 The 1-bits make sure that carries propagate to the next 0-bit.
85 The 0-bits provide holes for carries to fall into. */
86
87 /* Set MAGIC_BITS to be this pattern of 1 and 0 bits.
88 Set CHARMASK to be a longword, each of whose bytes is C. */
89
90 magic_bits = 0xfefefefe;
91 charmask = c | (c << 8);
92 charmask |= charmask << 16;
93#if 0xffffffffU < ULONG_MAX
94 magic_bits |= magic_bits << 32;
95 charmask |= charmask << 32;
96 if (8 < sizeof longword)
97 for (i = 64; i < sizeof longword * 8; i *= 2)
98 {
99 magic_bits |= magic_bits << i;
100 charmask |= charmask << i;
101 }
102#endif
103 magic_bits = (ULONG_MAX >> 1) & (magic_bits | 1);
104
105 /* Instead of the traditional loop which tests each character,
106 we will test a longword at a time. The tricky part is testing
107 if *any of the four* bytes in the longword in question are zero. */
108 while (n >= sizeof longword)
109 {
110 /* We tentatively exit the loop if adding MAGIC_BITS to
111 LONGWORD fails to change any of the hole bits of LONGWORD.
112
113 1) Is this safe? Will it catch all the zero bytes?
114 Suppose there is a byte with all zeros. Any carry bits
115 propagating from its left will fall into the hole at its
116 least significant bit and stop. Since there will be no
117 carry from its most significant bit, the LSB of the
118 byte to the left will be unchanged, and the zero will be
119 detected.
120
121 2) Is this worthwhile? Will it ignore everything except
122 zero bytes? Suppose every byte of LONGWORD has a bit set
123 somewhere. There will be a carry into bit 8. If bit 8
124 is set, this will carry into bit 16. If bit 8 is clear,
125 one of bits 9-15 must be set, so there will be a carry
126 into bit 16. Similarly, there will be a carry into bit
127 24. If one of bits 24-30 is set, there will be a carry
128 into bit 31, so all of the hole bits will be changed.
129
130 The one misfire occurs when bits 24-30 are clear and bit
131 31 is set; in this case, the hole at bit 31 is not
132 changed. If we had access to the processor carry flag,
133 we could close this loophole by putting the fourth hole
134 at bit 32!
135
136 So it ignores everything except 128's, when they're aligned
137 properly.
138
139 3) But wait! Aren't we looking for C, not zero?
140 Good point. So what we do is XOR LONGWORD with a longword,
141 each of whose bytes is C. This turns each byte that is C
142 into a zero. */
143
144 longword = *longword_ptr++ ^ charmask;
145
146 /* Add MAGIC_BITS to LONGWORD. */
147 if ((((longword + magic_bits)
148
149 /* Set those bits that were unchanged by the addition. */
150 ^ ~longword)
151
152 /* Look at only the hole bits. If any of the hole bits
153 are unchanged, most likely one of the bytes was a
154 zero. */
155 & ~magic_bits) != 0)
156 {
157 /* Which of the bytes was C? If none of them were, it was
158 a misfire; continue the search. */
159
160 const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);
161
162 if (cp[0] == c)
163 return (void *) cp;
164 if (cp[1] == c)
165 return (void *) &cp[1];
166 if (cp[2] == c)
167 return (void *) &cp[2];
168 if (cp[3] == c)
169 return (void *) &cp[3];
170 if (4 < sizeof longword && cp[4] == c)
171 return (void *) &cp[4];
172 if (5 < sizeof longword && cp[5] == c)
173 return (void *) &cp[5];
174 if (6 < sizeof longword && cp[6] == c)
175 return (void *) &cp[6];
176 if (7 < sizeof longword && cp[7] == c)
177 return (void *) &cp[7];
178 if (8 < sizeof longword)
179 for (i = 8; i < sizeof longword; i++)
180 if (cp[i] == c)
181 return (void *) &cp[i];
182 }
183
184 n -= sizeof longword;
185 }
186
187 char_ptr = (const unsigned char *) longword_ptr;
188
189 while (n-- > 0)
190 {
191 if (*char_ptr == c)
192 return (void *) char_ptr;
193 else
194 ++char_ptr;
195 }
196
197 return 0;
198}
199#ifdef weak_alias
200weak_alias (__memchr, BP_SYM (memchr))
201#endif
diff --git a/gl/minmax.h b/gl/minmax.h
deleted file mode 100644
index 975ea76..0000000
--- a/gl/minmax.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/* MIN, MAX macros.
2 Copyright (C) 1995, 1998, 2001, 2003, 2005 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 2, 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#ifndef _MINMAX_H
19#define _MINMAX_H
20
21/* Note: MIN, MAX are also defined in <sys/param.h> on some systems
22 (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about
23 MIN, MAX macro redefinitions on some systems; the workaround is to
24 #include this file as the last one among the #include list. */
25
26/* Before we define the following symbols we get the <limits.h> file
27 since otherwise we get redefinitions on some systems if <limits.h> is
28 included after this file. Likewise for <sys/param.h>.
29 If more than one of these system headers define MIN and MAX, pick just
30 one of the headers (because the definitions most likely are the same). */
31#if HAVE_MINMAX_IN_LIMITS_H
32# include <limits.h>
33#elif HAVE_MINMAX_IN_SYS_PARAM_H
34# include <sys/param.h>
35#endif
36
37/* Note: MIN and MAX should be used with two arguments of the
38 same type. They might not return the minimum and maximum of their two
39 arguments, if the arguments have different types or have unusual
40 floating-point values. For example, on a typical host with 32-bit 'int',
41 64-bit 'long long', and 64-bit IEEE 754 'double' types:
42
43 MAX (-1, 2147483648) returns 4294967295.
44 MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
45 MAX (NaN, 0.0) returns 0.0.
46 MAX (+0.0, -0.0) returns -0.0.
47
48 and in each case the answer is in some sense bogus. */
49
50/* MAX(a,b) returns the maximum of A and B. */
51#ifndef MAX
52# define MAX(a,b) ((a) > (b) ? (a) : (b))
53#endif
54
55/* MIN(a,b) returns the minimum of A and B. */
56#ifndef MIN
57# define MIN(a,b) ((a) < (b) ? (a) : (b))
58#endif
59
60#endif /* _MINMAX_H */
diff --git a/gl/mountlist.c b/gl/mountlist.c
index bb01f91..4c975c6 100644
--- a/gl/mountlist.c
+++ b/gl/mountlist.c
@@ -1,12 +1,12 @@
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, 1998, 1999, 2000, 2001, 2002, 2003, 3 Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006 Free Software Foundation, Inc. 4 2004, 2005, 2006, 2007 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
@@ -28,10 +27,6 @@
28 27
29#include "xalloc.h" 28#include "xalloc.h"
30 29
31#ifndef strstr
32char *strstr ();
33#endif
34
35#include <errno.h> 30#include <errno.h>
36 31
37#include <fcntl.h> 32#include <fcntl.h>
diff --git a/gl/mountlist.h b/gl/mountlist.h
index 7f5a6f7..e54bb49 100644
--- a/gl/mountlist.h
+++ b/gl/mountlist.h
@@ -3,10 +3,10 @@
3 Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003, 2004, 2005 3 Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003, 2004, 2005
4 Free 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#ifndef MOUNTLIST_H_ 19#ifndef MOUNTLIST_H_
21# define MOUNTLIST_H_ 20# define MOUNTLIST_H_
diff --git a/gl/strnlen1.h b/gl/netinet_in.in.h
index 7ce7d0c..c45e53b 100644
--- a/gl/strnlen1.h
+++ b/gl/netinet_in.in.h
@@ -1,9 +1,9 @@
1/* Find the length of STRING + 1, but scan at most MAXLEN bytes. 1/* Substitute for <netinet/in.h>.
2 Copyright (C) 2005 Free Software Foundation, Inc. 2 Copyright (C) 2007 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -15,26 +15,29 @@
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 _STRNLEN1_H 18#ifndef _GL_NETINET_IN_H
19#define _STRNLEN1_H
20 19
21#include <stddef.h> 20#if @HAVE_NETINET_IN_H@
22 21
22/* On many platforms, <netinet/in.h> assumes prior inclusion of
23 <sys/types.h>. */
24# include <sys/types.h>
25
26/* The include_next requires a split double-inclusion guard. */
27# @INCLUDE_NEXT@ @NEXT_NETINET_IN_H@
23 28
24#ifdef __cplusplus
25extern "C" {
26#endif 29#endif
27 30
31#ifndef _GL_NETINET_IN_H
32#define _GL_NETINET_IN_H
28 33
29/* Find the length of STRING + 1, but scan at most MAXLEN bytes. 34#if !@HAVE_NETINET_IN_H@
30 If no '\0' terminator is found in that many characters, return MAXLEN. */
31/* This is the same as strnlen (string, maxlen - 1) + 1. */
32extern size_t strnlen1 (const char *string, size_t maxlen);
33 35
36/* A platform that lacks <netinet/in.h>. */
34 37
35#ifdef __cplusplus 38# include <sys/socket.h>
36}
37#endif
38 39
40#endif
39 41
40#endif /* _STRNLEN1_H */ 42#endif /* _GL_NETINET_IN_H */
43#endif /* _GL_NETINET_IN_H */
diff --git a/gl/open-safer.c b/gl/open-safer.c
index 04a72eb..ce493d5 100644
--- a/gl/open-safer.c
+++ b/gl/open-safer.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/pipe-safer.c b/gl/pipe-safer.c
index e4431b3..0fc6850 100644
--- a/gl/pipe-safer.c
+++ b/gl/pipe-safer.c
@@ -1,10 +1,10 @@
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 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3 of the License, or
7 any later version. 7 (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 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, 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 16
18/* Written by Jim Meyering. */ 17/* Written by Jim Meyering. */
19 18
diff --git a/gl/printf-args.c b/gl/printf-args.c
index 358801c..871c720 100644
--- a/gl/printf-args.c
+++ b/gl/printf-args.c
@@ -1,9 +1,9 @@
1/* Decomposed printf argument list. 1/* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2005-2006 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2005-2007 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -15,16 +15,25 @@
15 with this program; if not, write to the Free Software Foundation, 15 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#include <config.h> 18/* This file can be parametrized with the following macros:
19 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
20 PRINTF_FETCHARGS Name of the function to be defined.
21 STATIC Set to 'static' to declare the function static. */
22
23#ifndef PRINTF_FETCHARGS
24# include <config.h>
25#endif
19 26
20/* Specification. */ 27/* Specification. */
21#include "printf-args.h" 28#ifndef PRINTF_FETCHARGS
29# include "printf-args.h"
30#endif
22 31
23#ifdef STATIC 32#ifdef STATIC
24STATIC 33STATIC
25#endif 34#endif
26int 35int
27printf_fetchargs (va_list args, arguments *a) 36PRINTF_FETCHARGS (va_list args, arguments *a)
28{ 37{
29 size_t i; 38 size_t i;
30 argument *ap; 39 argument *ap;
@@ -56,7 +65,7 @@ printf_fetchargs (va_list args, arguments *a)
56 case TYPE_ULONGINT: 65 case TYPE_ULONGINT:
57 ap->a.a_ulongint = va_arg (args, unsigned long int); 66 ap->a.a_ulongint = va_arg (args, unsigned long int);
58 break; 67 break;
59#ifdef HAVE_LONG_LONG_INT 68#if HAVE_LONG_LONG_INT
60 case TYPE_LONGLONGINT: 69 case TYPE_LONGLONGINT:
61 ap->a.a_longlongint = va_arg (args, long long int); 70 ap->a.a_longlongint = va_arg (args, long long int);
62 break; 71 break;
@@ -67,15 +76,13 @@ printf_fetchargs (va_list args, arguments *a)
67 case TYPE_DOUBLE: 76 case TYPE_DOUBLE:
68 ap->a.a_double = va_arg (args, double); 77 ap->a.a_double = va_arg (args, double);
69 break; 78 break;
70#ifdef HAVE_LONG_DOUBLE
71 case TYPE_LONGDOUBLE: 79 case TYPE_LONGDOUBLE:
72 ap->a.a_longdouble = va_arg (args, long double); 80 ap->a.a_longdouble = va_arg (args, long double);
73 break; 81 break;
74#endif
75 case TYPE_CHAR: 82 case TYPE_CHAR:
76 ap->a.a_char = va_arg (args, int); 83 ap->a.a_char = va_arg (args, int);
77 break; 84 break;
78#ifdef HAVE_WINT_T 85#if HAVE_WINT_T
79 case TYPE_WIDE_CHAR: 86 case TYPE_WIDE_CHAR:
80 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by 87 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
81 default argument promotions", this is not the case in mingw32, 88 default argument promotions", this is not the case in mingw32,
@@ -94,7 +101,7 @@ printf_fetchargs (va_list args, arguments *a)
94 if (ap->a.a_string == NULL) 101 if (ap->a.a_string == NULL)
95 ap->a.a_string = "(NULL)"; 102 ap->a.a_string = "(NULL)";
96 break; 103 break;
97#ifdef HAVE_WCHAR_T 104#if HAVE_WCHAR_T
98 case TYPE_WIDE_STRING: 105 case TYPE_WIDE_STRING:
99 ap->a.a_wide_string = va_arg (args, const wchar_t *); 106 ap->a.a_wide_string = va_arg (args, const wchar_t *);
100 /* A null pointer is an invalid argument for "%ls", but in practice 107 /* A null pointer is an invalid argument for "%ls", but in practice
@@ -128,11 +135,50 @@ printf_fetchargs (va_list args, arguments *a)
128 case TYPE_COUNT_LONGINT_POINTER: 135 case TYPE_COUNT_LONGINT_POINTER:
129 ap->a.a_count_longint_pointer = va_arg (args, long int *); 136 ap->a.a_count_longint_pointer = va_arg (args, long int *);
130 break; 137 break;
131#ifdef HAVE_LONG_LONG_INT 138#if HAVE_LONG_LONG_INT
132 case TYPE_COUNT_LONGLONGINT_POINTER: 139 case TYPE_COUNT_LONGLONGINT_POINTER:
133 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); 140 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
134 break; 141 break;
135#endif 142#endif
143#if ENABLE_UNISTDIO
144 /* The unistdio extensions. */
145 case TYPE_U8_STRING:
146 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 it occurs quite frequently in printf statements that produce
149 debug output. Use a fallback in this case. */
150 if (ap->a.a_u8_string == NULL)
151 {
152 static const uint8_t u8_null_string[] =
153 { '(', 'N', 'U', 'L', 'L', ')', 0 };
154 ap->a.a_u8_string = u8_null_string;
155 }
156 break;
157 case TYPE_U16_STRING:
158 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 it occurs quite frequently in printf statements that produce
161 debug output. Use a fallback in this case. */
162 if (ap->a.a_u16_string == NULL)
163 {
164 static const uint16_t u16_null_string[] =
165 { '(', 'N', 'U', 'L', 'L', ')', 0 };
166 ap->a.a_u16_string = u16_null_string;
167 }
168 break;
169 case TYPE_U32_STRING:
170 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 it occurs quite frequently in printf statements that produce
173 debug output. Use a fallback in this case. */
174 if (ap->a.a_u32_string == NULL)
175 {
176 static const uint32_t u32_null_string[] =
177 { '(', 'N', 'U', 'L', 'L', ')', 0 };
178 ap->a.a_u32_string = u32_null_string;
179 }
180 break;
181#endif
136 default: 182 default:
137 /* Unknown type. */ 183 /* Unknown type. */
138 return -1; 184 return -1;
diff --git a/gl/printf-args.h b/gl/printf-args.h
index 5759da0..67cb990 100644
--- a/gl/printf-args.h
+++ b/gl/printf-args.h
@@ -1,9 +1,9 @@
1/* Decomposed printf argument list. 1/* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2006 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2006-2007 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -18,16 +18,26 @@
18#ifndef _PRINTF_ARGS_H 18#ifndef _PRINTF_ARGS_H
19#define _PRINTF_ARGS_H 19#define _PRINTF_ARGS_H
20 20
21/* This file can be parametrized with the following macros:
22 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
23 PRINTF_FETCHARGS Name of the function to be declared.
24 STATIC Set to 'static' to declare the function static. */
25
26/* Default parameters. */
27#ifndef PRINTF_FETCHARGS
28# define PRINTF_FETCHARGS printf_fetchargs
29#endif
30
21/* Get size_t. */ 31/* Get size_t. */
22#include <stddef.h> 32#include <stddef.h>
23 33
24/* Get wchar_t. */ 34/* Get wchar_t. */
25#ifdef HAVE_WCHAR_T 35#if HAVE_WCHAR_T
26# include <stddef.h> 36# include <stddef.h>
27#endif 37#endif
28 38
29/* Get wint_t. */ 39/* Get wint_t. */
30#ifdef HAVE_WINT_T 40#if HAVE_WINT_T
31# include <wchar.h> 41# include <wchar.h>
32#endif 42#endif
33 43
@@ -47,20 +57,18 @@ typedef enum
47 TYPE_UINT, 57 TYPE_UINT,
48 TYPE_LONGINT, 58 TYPE_LONGINT,
49 TYPE_ULONGINT, 59 TYPE_ULONGINT,
50#ifdef HAVE_LONG_LONG_INT 60#if HAVE_LONG_LONG_INT
51 TYPE_LONGLONGINT, 61 TYPE_LONGLONGINT,
52 TYPE_ULONGLONGINT, 62 TYPE_ULONGLONGINT,
53#endif 63#endif
54 TYPE_DOUBLE, 64 TYPE_DOUBLE,
55#ifdef HAVE_LONG_DOUBLE
56 TYPE_LONGDOUBLE, 65 TYPE_LONGDOUBLE,
57#endif
58 TYPE_CHAR, 66 TYPE_CHAR,
59#ifdef HAVE_WINT_T 67#if HAVE_WINT_T
60 TYPE_WIDE_CHAR, 68 TYPE_WIDE_CHAR,
61#endif 69#endif
62 TYPE_STRING, 70 TYPE_STRING,
63#ifdef HAVE_WCHAR_T 71#if HAVE_WCHAR_T
64 TYPE_WIDE_STRING, 72 TYPE_WIDE_STRING,
65#endif 73#endif
66 TYPE_POINTER, 74 TYPE_POINTER,
@@ -68,9 +76,15 @@ typedef enum
68 TYPE_COUNT_SHORT_POINTER, 76 TYPE_COUNT_SHORT_POINTER,
69 TYPE_COUNT_INT_POINTER, 77 TYPE_COUNT_INT_POINTER,
70 TYPE_COUNT_LONGINT_POINTER 78 TYPE_COUNT_LONGINT_POINTER
71#ifdef HAVE_LONG_LONG_INT 79#if HAVE_LONG_LONG_INT
72, TYPE_COUNT_LONGLONGINT_POINTER 80, TYPE_COUNT_LONGLONGINT_POINTER
73#endif 81#endif
82#if ENABLE_UNISTDIO
83 /* The unistdio extensions. */
84, TYPE_U8_STRING
85, TYPE_U16_STRING
86, TYPE_U32_STRING
87#endif
74} arg_type; 88} arg_type;
75 89
76/* Polymorphic argument */ 90/* Polymorphic argument */
@@ -87,21 +101,19 @@ typedef struct
87 unsigned int a_uint; 101 unsigned int a_uint;
88 long int a_longint; 102 long int a_longint;
89 unsigned long int a_ulongint; 103 unsigned long int a_ulongint;
90#ifdef HAVE_LONG_LONG_INT 104#if HAVE_LONG_LONG_INT
91 long long int a_longlongint; 105 long long int a_longlongint;
92 unsigned long long int a_ulonglongint; 106 unsigned long long int a_ulonglongint;
93#endif 107#endif
94 float a_float; 108 float a_float;
95 double a_double; 109 double a_double;
96#ifdef HAVE_LONG_DOUBLE
97 long double a_longdouble; 110 long double a_longdouble;
98#endif
99 int a_char; 111 int a_char;
100#ifdef HAVE_WINT_T 112#if HAVE_WINT_T
101 wint_t a_wide_char; 113 wint_t a_wide_char;
102#endif 114#endif
103 const char* a_string; 115 const char* a_string;
104#ifdef HAVE_WCHAR_T 116#if HAVE_WCHAR_T
105 const wchar_t* a_wide_string; 117 const wchar_t* a_wide_string;
106#endif 118#endif
107 void* a_pointer; 119 void* a_pointer;
@@ -109,9 +121,15 @@ typedef struct
109 short * a_count_short_pointer; 121 short * a_count_short_pointer;
110 int * a_count_int_pointer; 122 int * a_count_int_pointer;
111 long int * a_count_longint_pointer; 123 long int * a_count_longint_pointer;
112#ifdef HAVE_LONG_LONG_INT 124#if HAVE_LONG_LONG_INT
113 long long int * a_count_longlongint_pointer; 125 long long int * a_count_longlongint_pointer;
114#endif 126#endif
127#if ENABLE_UNISTDIO
128 /* The unistdio extensions. */
129 const uint8_t * a_u8_string;
130 const uint16_t * a_u16_string;
131 const uint32_t * a_u32_string;
132#endif
115 } 133 }
116 a; 134 a;
117} 135}
@@ -131,6 +149,6 @@ STATIC
131#else 149#else
132extern 150extern
133#endif 151#endif
134int printf_fetchargs (va_list args, arguments *a); 152int PRINTF_FETCHARGS (va_list args, arguments *a);
135 153
136#endif /* _PRINTF_ARGS_H */ 154#endif /* _PRINTF_ARGS_H */
diff --git a/gl/printf-parse.c b/gl/printf-parse.c
index 9a86f77..28b9bd4 100644
--- a/gl/printf-parse.c
+++ b/gl/printf-parse.c
@@ -1,9 +1,9 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999-2000, 2002-2003, 2006 Free Software Foundation, Inc. 2 Copyright (C) 1999-2000, 2002-2003, 2006-2008 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -15,42 +15,63 @@
15 with this program; if not, write to the Free Software Foundation, 15 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#include <config.h> 18/* This file can be parametrized with the following macros:
19 CHAR_T The element type of the format string.
20 CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
21 in the format string are ASCII.
22 DIRECTIVE Structure denoting a format directive.
23 Depends on CHAR_T.
24 DIRECTIVES Structure denoting the set of format directives of a
25 format string. Depends on CHAR_T.
26 PRINTF_PARSE Function that parses a format string.
27 Depends on CHAR_T.
28 STATIC Set to 'static' to declare the function static.
29 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
30
31#ifndef PRINTF_PARSE
32# include <config.h>
33#endif
19 34
20/* Specification. */ 35/* Specification. */
21#if WIDE_CHAR_VERSION 36#ifndef PRINTF_PARSE
22# include "wprintf-parse.h"
23#else
24# include "printf-parse.h" 37# include "printf-parse.h"
25#endif 38#endif
26 39
40/* Default parameters. */
41#ifndef PRINTF_PARSE
42# define PRINTF_PARSE printf_parse
43# define CHAR_T char
44# define DIRECTIVE char_directive
45# define DIRECTIVES char_directives
46#endif
47
27/* Get size_t, NULL. */ 48/* Get size_t, NULL. */
28#include <stddef.h> 49#include <stddef.h>
29 50
30/* Get intmax_t. */ 51/* Get intmax_t. */
31#if HAVE_STDINT_H_WITH_UINTMAX 52#if defined IN_LIBINTL || defined IN_LIBASPRINTF
53# if HAVE_STDINT_H_WITH_UINTMAX
54# include <stdint.h>
55# endif
56# if HAVE_INTTYPES_H_WITH_UINTMAX
57# include <inttypes.h>
58# endif
59#else
32# include <stdint.h> 60# include <stdint.h>
33#endif 61#endif
34#if HAVE_INTTYPES_H_WITH_UINTMAX
35# include <inttypes.h>
36#endif
37 62
38/* malloc(), realloc(), free(). */ 63/* malloc(), realloc(), free(). */
39#include <stdlib.h> 64#include <stdlib.h>
40 65
66/* errno. */
67#include <errno.h>
68
41/* Checked size_t computations. */ 69/* Checked size_t computations. */
42#include "xsize.h" 70#include "xsize.h"
43 71
44#if WIDE_CHAR_VERSION 72#if CHAR_T_ONLY_ASCII
45# define PRINTF_PARSE wprintf_parse 73/* c_isascii(). */
46# define CHAR_T wchar_t 74# include "c-ctype.h"
47# define DIRECTIVE wchar_t_directive
48# define DIRECTIVES wchar_t_directives
49#else
50# define PRINTF_PARSE printf_parse
51# define CHAR_T char
52# define DIRECTIVE char_directive
53# define DIRECTIVES char_directives
54#endif 75#endif
55 76
56#ifdef STATIC 77#ifdef STATIC
@@ -71,7 +92,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
71 d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); 92 d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
72 if (d->dir == NULL) 93 if (d->dir == NULL)
73 /* Out of memory. */ 94 /* Out of memory. */
74 return -1; 95 goto out_of_memory_1;
75 96
76 a->count = 0; 97 a->count = 0;
77 a_allocated = 0; 98 a_allocated = 0;
@@ -91,13 +112,13 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
91 memory_size = xtimes (a_allocated, sizeof (argument)); \ 112 memory_size = xtimes (a_allocated, sizeof (argument)); \
92 if (size_overflow_p (memory_size)) \ 113 if (size_overflow_p (memory_size)) \
93 /* Overflow, would lead to out of memory. */ \ 114 /* Overflow, would lead to out of memory. */ \
94 goto error; \ 115 goto out_of_memory; \
95 memory = (argument *) (a->arg \ 116 memory = (argument *) (a->arg \
96 ? realloc (a->arg, memory_size) \ 117 ? realloc (a->arg, memory_size) \
97 : malloc (memory_size)); \ 118 : malloc (memory_size)); \
98 if (memory == NULL) \ 119 if (memory == NULL) \
99 /* Out of memory. */ \ 120 /* Out of memory. */ \
100 goto error; \ 121 goto out_of_memory; \
101 a->arg = memory; \ 122 a->arg = memory; \
102 } \ 123 } \
103 while (a->count <= n) \ 124 while (a->count <= n) \
@@ -115,7 +136,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
115 if (c == '%') 136 if (c == '%')
116 { 137 {
117 size_t arg_index = ARG_NONE; 138 size_t arg_index = ARG_NONE;
118 DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ 139 DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
119 140
120 /* Initialize the next directive. */ 141 /* Initialize the next directive. */
121 dp->dir_start = cp - 1; 142 dp->dir_start = cp - 1;
@@ -326,7 +347,6 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
326 flags += 8; 347 flags += 8;
327 cp++; 348 cp++;
328 } 349 }
329#ifdef HAVE_INTMAX_T
330 else if (*cp == 'j') 350 else if (*cp == 'j')
331 { 351 {
332 if (sizeof (intmax_t) > sizeof (long)) 352 if (sizeof (intmax_t) > sizeof (long))
@@ -341,7 +361,6 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
341 } 361 }
342 cp++; 362 cp++;
343 } 363 }
344#endif
345 else if (*cp == 'z' || *cp == 'Z') 364 else if (*cp == 'z' || *cp == 'Z')
346 { 365 {
347 /* 'z' is standardized in ISO C 99, but glibc uses 'Z' 366 /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
@@ -373,6 +392,44 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
373 } 392 }
374 cp++; 393 cp++;
375 } 394 }
395#if defined __APPLE__ && defined __MACH__
396 /* On MacOS X 10.3, PRIdMAX is defined as "qd".
397 We cannot change it to "lld" because PRIdMAX must also
398 be understood by the system's printf routines. */
399 else if (*cp == 'q')
400 {
401 if (64 / 8 > sizeof (long))
402 {
403 /* int64_t = long long */
404 flags += 16;
405 }
406 else
407 {
408 /* int64_t = long */
409 flags += 8;
410 }
411 cp++;
412 }
413#endif
414#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
415 /* On native Win32, PRIdMAX is defined as "I64d".
416 We cannot change it to "lld" because PRIdMAX must also
417 be understood by the system's printf routines. */
418 else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
419 {
420 if (64 / 8 > sizeof (long))
421 {
422 /* __int64 = long long */
423 flags += 16;
424 }
425 else
426 {
427 /* __int64 = long */
428 flags += 8;
429 }
430 cp += 3;
431 }
432#endif
376 else 433 else
377 break; 434 break;
378 } 435 }
@@ -382,7 +439,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
382 switch (c) 439 switch (c)
383 { 440 {
384 case 'd': case 'i': 441 case 'd': case 'i':
385#ifdef HAVE_LONG_LONG_INT 442#if HAVE_LONG_LONG_INT
386 /* If 'long long' exists and is larger than 'long': */ 443 /* If 'long long' exists and is larger than 'long': */
387 if (flags >= 16 || (flags & 4)) 444 if (flags >= 16 || (flags & 4))
388 type = TYPE_LONGLONGINT; 445 type = TYPE_LONGLONGINT;
@@ -400,7 +457,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
400 type = TYPE_INT; 457 type = TYPE_INT;
401 break; 458 break;
402 case 'o': case 'u': case 'x': case 'X': 459 case 'o': case 'u': case 'x': case 'X':
403#ifdef HAVE_LONG_LONG_INT 460#if HAVE_LONG_LONG_INT
404 /* If 'long long' exists and is larger than 'long': */ 461 /* If 'long long' exists and is larger than 'long': */
405 if (flags >= 16 || (flags & 4)) 462 if (flags >= 16 || (flags & 4))
406 type = TYPE_ULONGLONGINT; 463 type = TYPE_ULONGLONGINT;
@@ -419,16 +476,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
419 break; 476 break;
420 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':
421 case 'a': case 'A': 478 case 'a': case 'A':
422#ifdef HAVE_LONG_DOUBLE
423 if (flags >= 16 || (flags & 4)) 479 if (flags >= 16 || (flags & 4))
424 type = TYPE_LONGDOUBLE; 480 type = TYPE_LONGDOUBLE;
425 else 481 else
426#endif 482 type = TYPE_DOUBLE;
427 type = TYPE_DOUBLE;
428 break; 483 break;
429 case 'c': 484 case 'c':
430 if (flags >= 8) 485 if (flags >= 8)
431#ifdef HAVE_WINT_T 486#if HAVE_WINT_T
432 type = TYPE_WIDE_CHAR; 487 type = TYPE_WIDE_CHAR;
433#else 488#else
434 goto error; 489 goto error;
@@ -436,7 +491,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
436 else 491 else
437 type = TYPE_CHAR; 492 type = TYPE_CHAR;
438 break; 493 break;
439#ifdef HAVE_WINT_T 494#if HAVE_WINT_T
440 case 'C': 495 case 'C':
441 type = TYPE_WIDE_CHAR; 496 type = TYPE_WIDE_CHAR;
442 c = 'c'; 497 c = 'c';
@@ -444,7 +499,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
444#endif 499#endif
445 case 's': 500 case 's':
446 if (flags >= 8) 501 if (flags >= 8)
447#ifdef HAVE_WCHAR_T 502#if HAVE_WCHAR_T
448 type = TYPE_WIDE_STRING; 503 type = TYPE_WIDE_STRING;
449#else 504#else
450 goto error; 505 goto error;
@@ -452,7 +507,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
452 else 507 else
453 type = TYPE_STRING; 508 type = TYPE_STRING;
454 break; 509 break;
455#ifdef HAVE_WCHAR_T 510#if HAVE_WCHAR_T
456 case 'S': 511 case 'S':
457 type = TYPE_WIDE_STRING; 512 type = TYPE_WIDE_STRING;
458 c = 's'; 513 c = 's';
@@ -462,7 +517,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
462 type = TYPE_POINTER; 517 type = TYPE_POINTER;
463 break; 518 break;
464 case 'n': 519 case 'n':
465#ifdef HAVE_LONG_LONG_INT 520#if HAVE_LONG_LONG_INT
466 /* If 'long long' exists and is larger than 'long': */ 521 /* If 'long long' exists and is larger than 'long': */
467 if (flags >= 16 || (flags & 4)) 522 if (flags >= 16 || (flags & 4))
468 type = TYPE_COUNT_LONGLONGINT_POINTER; 523 type = TYPE_COUNT_LONGLONGINT_POINTER;
@@ -479,6 +534,17 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
479 else 534 else
480 type = TYPE_COUNT_INT_POINTER; 535 type = TYPE_COUNT_INT_POINTER;
481 break; 536 break;
537#if ENABLE_UNISTDIO
538 /* The unistdio extensions. */
539 case 'U':
540 if (flags >= 16)
541 type = TYPE_U32_STRING;
542 else if (flags >= 8)
543 type = TYPE_U16_STRING;
544 else
545 type = TYPE_U8_STRING;
546 break;
547#endif
482 case '%': 548 case '%':
483 type = TYPE_NONE; 549 type = TYPE_NONE;
484 break; 550 break;
@@ -514,14 +580,21 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
514 memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); 580 memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
515 if (size_overflow_p (memory_size)) 581 if (size_overflow_p (memory_size))
516 /* Overflow, would lead to out of memory. */ 582 /* Overflow, would lead to out of memory. */
517 goto error; 583 goto out_of_memory;
518 memory = (DIRECTIVE *) realloc (d->dir, memory_size); 584 memory = (DIRECTIVE *) realloc (d->dir, memory_size);
519 if (memory == NULL) 585 if (memory == NULL)
520 /* Out of memory. */ 586 /* Out of memory. */
521 goto error; 587 goto out_of_memory;
522 d->dir = memory; 588 d->dir = memory;
523 } 589 }
524 } 590 }
591#if CHAR_T_ONLY_ASCII
592 else if (!c_isascii (c))
593 {
594 /* Non-ASCII character. Not supported. */
595 goto error;
596 }
597#endif
525 } 598 }
526 d->dir[d->count].dir_start = cp; 599 d->dir[d->count].dir_start = cp;
527 600
@@ -534,10 +607,21 @@ error:
534 free (a->arg); 607 free (a->arg);
535 if (d->dir) 608 if (d->dir)
536 free (d->dir); 609 free (d->dir);
610 errno = EINVAL;
611 return -1;
612
613out_of_memory:
614 if (a->arg)
615 free (a->arg);
616 if (d->dir)
617 free (d->dir);
618out_of_memory_1:
619 errno = ENOMEM;
537 return -1; 620 return -1;
538} 621}
539 622
623#undef PRINTF_PARSE
540#undef DIRECTIVES 624#undef DIRECTIVES
541#undef DIRECTIVE 625#undef DIRECTIVE
626#undef CHAR_T_ONLY_ASCII
542#undef CHAR_T 627#undef CHAR_T
543#undef PRINTF_PARSE
diff --git a/gl/printf-parse.h b/gl/printf-parse.h
index 82a0d37..e5d68d7 100644
--- a/gl/printf-parse.h
+++ b/gl/printf-parse.h
@@ -1,9 +1,9 @@
1/* Parse printf format string. 1/* Parse printf format string.
2 Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2005, 2007 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -18,6 +18,10 @@
18#ifndef _PRINTF_PARSE_H 18#ifndef _PRINTF_PARSE_H
19#define _PRINTF_PARSE_H 19#define _PRINTF_PARSE_H
20 20
21/* This file can be parametrized with the following macros:
22 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
23 STATIC Set to 'static' to declare the function static. */
24
21#include "printf-args.h" 25#include "printf-args.h"
22 26
23 27
@@ -32,6 +36,9 @@
32/* arg_index value indicating that no argument is consumed. */ 36/* arg_index value indicating that no argument is consumed. */
33#define ARG_NONE (~(size_t)0) 37#define ARG_NONE (~(size_t)0)
34 38
39/* xxx_directive: A parsed directive.
40 xxx_directives: A parsed format string. */
41
35/* A parsed directive. */ 42/* A parsed directive. */
36typedef struct 43typedef struct
37{ 44{
@@ -44,7 +51,7 @@ typedef struct
44 const char* precision_start; 51 const char* precision_start;
45 const char* precision_end; 52 const char* precision_end;
46 size_t precision_arg_index; 53 size_t precision_arg_index;
47 char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ 54 char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
48 size_t arg_index; 55 size_t arg_index;
49} 56}
50char_directive; 57char_directive;
@@ -59,16 +66,114 @@ typedef struct
59} 66}
60char_directives; 67char_directives;
61 68
69#if ENABLE_UNISTDIO
70
71/* A parsed directive. */
72typedef struct
73{
74 const uint8_t* dir_start;
75 const uint8_t* dir_end;
76 int flags;
77 const uint8_t* width_start;
78 const uint8_t* width_end;
79 size_t width_arg_index;
80 const uint8_t* precision_start;
81 const uint8_t* precision_end;
82 size_t precision_arg_index;
83 uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
84 size_t arg_index;
85}
86u8_directive;
87
88/* A parsed format string. */
89typedef struct
90{
91 size_t count;
92 u8_directive *dir;
93 size_t max_width_length;
94 size_t max_precision_length;
95}
96u8_directives;
97
98/* A parsed directive. */
99typedef struct
100{
101 const uint16_t* dir_start;
102 const uint16_t* dir_end;
103 int flags;
104 const uint16_t* width_start;
105 const uint16_t* width_end;
106 size_t width_arg_index;
107 const uint16_t* precision_start;
108 const uint16_t* precision_end;
109 size_t precision_arg_index;
110 uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
111 size_t arg_index;
112}
113u16_directive;
114
115/* A parsed format string. */
116typedef struct
117{
118 size_t count;
119 u16_directive *dir;
120 size_t max_width_length;
121 size_t max_precision_length;
122}
123u16_directives;
124
125/* A parsed directive. */
126typedef struct
127{
128 const uint32_t* dir_start;
129 const uint32_t* dir_end;
130 int flags;
131 const uint32_t* width_start;
132 const uint32_t* width_end;
133 size_t width_arg_index;
134 const uint32_t* precision_start;
135 const uint32_t* precision_end;
136 size_t precision_arg_index;
137 uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
138 size_t arg_index;
139}
140u32_directive;
141
142/* A parsed format string. */
143typedef struct
144{
145 size_t count;
146 u32_directive *dir;
147 size_t max_width_length;
148 size_t max_precision_length;
149}
150u32_directives;
151
152#endif
153
62 154
63/* Parses the format string. Fills in the number N of directives, and fills 155/* Parses the format string. Fills in the number N of directives, and fills
64 in directives[0], ..., directives[N-1], and sets directives[N].dir_start 156 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
65 to the end of the format string. Also fills in the arg_type fields of the 157 to the end of the format string. Also fills in the arg_type fields of the
66 arguments and the needed count of arguments. */ 158 arguments and the needed count of arguments. */
67#ifdef STATIC 159#if ENABLE_UNISTDIO
68STATIC 160extern int
161 ulc_printf_parse (const char *format, char_directives *d, arguments *a);
162extern int
163 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
164extern int
165 u16_printf_parse (const uint16_t *format, u16_directives *d,
166 arguments *a);
167extern int
168 u32_printf_parse (const uint32_t *format, u32_directives *d,
169 arguments *a);
69#else 170#else
171# ifdef STATIC
172STATIC
173# else
70extern 174extern
71#endif 175# endif
72int printf_parse (const char *format, char_directives *d, arguments *a); 176int printf_parse (const char *format, char_directives *d, arguments *a);
177#endif
73 178
74#endif /* _PRINTF_PARSE_H */ 179#endif /* _PRINTF_PARSE_H */
diff --git a/gl/ref-add.sin b/gl/ref-add.sin
new file mode 100644
index 0000000..222d752
--- /dev/null
+++ b/gl/ref-add.sin
@@ -0,0 +1,30 @@
1# Add this package to a list of references stored in a text file.
2#
3# Copyright (C) 2000 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 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# Written by Bruno Haible <haible@clisp.cons.org>.
20#
21/^# Packages using this file: / {
22 s/# Packages using this file://
23 ta
24 :a
25 s/ @PACKAGE@ / @PACKAGE@ /
26 tb
27 s/ $/ @PACKAGE@ /
28 :b
29 s/^/# Packages using this file:/
30}
diff --git a/gl/ref-del.sin b/gl/ref-del.sin
new file mode 100644
index 0000000..1bf073e
--- /dev/null
+++ b/gl/ref-del.sin
@@ -0,0 +1,25 @@
1# Remove this package from a list of references stored in a text file.
2#
3# Copyright (C) 2000 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 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# Written by Bruno Haible <haible@clisp.cons.org>.
20#
21/^# Packages using this file: / {
22 s/# Packages using this file://
23 s/ @PACKAGE@ / /
24 s/^/# Packages using this file:/
25}
diff --git a/gl/regcomp.c b/gl/regcomp.c
index 8df6bb8..8827e03 100644
--- a/gl/regcomp.c
+++ b/gl/regcomp.c
@@ -1,11 +1,11 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc. 2 Copyright (C) 2002,2003,2004,2005,2006,2007 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 Isamu Hasegawa <isamu@yamato.ibm.com>. 4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
@@ -451,8 +451,8 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
451 451
452int 452int
453regcomp (preg, pattern, cflags) 453regcomp (preg, pattern, cflags)
454 regex_t *__restrict preg; 454 regex_t *_Restrict_ preg;
455 const char *__restrict pattern; 455 const char *_Restrict_ pattern;
456 int cflags; 456 int cflags;
457{ 457{
458 reg_errcode_t ret; 458 reg_errcode_t ret;
@@ -515,13 +515,13 @@ weak_alias (__regcomp, regcomp)
515size_t 515size_t
516regerror (errcode, preg, errbuf, errbuf_size) 516regerror (errcode, preg, errbuf, errbuf_size)
517 int errcode; 517 int errcode;
518 const regex_t *__restrict preg; 518 const regex_t *_Restrict_ preg;
519 char *__restrict errbuf; 519 char *_Restrict_ errbuf;
520 size_t errbuf_size; 520 size_t errbuf_size;
521#else /* size_t might promote */ 521#else /* size_t might promote */
522size_t 522size_t
523regerror (int errcode, const regex_t *__restrict preg, 523regerror (int errcode, const regex_t *_Restrict_ preg,
524 char *__restrict errbuf, size_t errbuf_size) 524 char *_Restrict_ errbuf, size_t errbuf_size)
525#endif 525#endif
526{ 526{
527 const char *msg; 527 const char *msg;
@@ -542,17 +542,13 @@ regerror (int errcode, const regex_t *__restrict preg,
542 542
543 if (BE (errbuf_size != 0, 1)) 543 if (BE (errbuf_size != 0, 1))
544 { 544 {
545 size_t cpy_size = msg_size;
545 if (BE (msg_size > errbuf_size, 0)) 546 if (BE (msg_size > errbuf_size, 0))
546 { 547 {
547#if defined HAVE_MEMPCPY || defined _LIBC 548 cpy_size = errbuf_size - 1;
548 *((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; 549 errbuf[cpy_size] = '\0';
549#else
550 memcpy (errbuf, msg, errbuf_size - 1);
551 errbuf[errbuf_size - 1] = 0;
552#endif
553 } 550 }
554 else 551 memcpy (errbuf, msg, cpy_size);
555 memcpy (errbuf, msg, msg_size);
556 } 552 }
557 553
558 return msg_size; 554 return msg_size;
@@ -833,9 +829,6 @@ static reg_errcode_t
833init_dfa (re_dfa_t *dfa, size_t pat_len) 829init_dfa (re_dfa_t *dfa, size_t pat_len)
834{ 830{
835 __re_size_t table_size; 831 __re_size_t table_size;
836#ifndef _LIBC
837 char *codeset_name;
838#endif
839#ifdef RE_ENABLE_I18N 832#ifdef RE_ENABLE_I18N
840 size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t)); 833 size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
841#else 834#else
@@ -879,22 +872,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
879 dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII) 872 dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
880 != 0); 873 != 0);
881#else 874#else
882# ifdef HAVE_LANGINFO_CODESET 875 if (strcmp (locale_charset (), "UTF-8") == 0)
883 codeset_name = nl_langinfo (CODESET);
884# else
885 codeset_name = getenv ("LC_ALL");
886 if (codeset_name == NULL || codeset_name[0] == '\0')
887 codeset_name = getenv ("LC_CTYPE");
888 if (codeset_name == NULL || codeset_name[0] == '\0')
889 codeset_name = getenv ("LANG");
890 if (codeset_name == NULL)
891 codeset_name = "";
892 else if (strchr (codeset_name, '.') != NULL)
893 codeset_name = strchr (codeset_name, '.') + 1;
894# endif
895
896 if (strcasecmp (codeset_name, "UTF-8") == 0
897 || strcasecmp (codeset_name, "UTF8") == 0)
898 dfa->is_utf8 = 1; 876 dfa->is_utf8 = 1;
899 877
900 /* We check exhaustively in the loop below if this charset is a 878 /* We check exhaustively in the loop below if this charset is a
@@ -1071,7 +1049,7 @@ optimize_utf8 (re_dfa_t *dfa)
1071 mb_chars = true; 1049 mb_chars = true;
1072 break; 1050 break;
1073 case ANCHOR: 1051 case ANCHOR:
1074 switch (dfa->nodes[node].opr.idx) 1052 switch (dfa->nodes[node].opr.ctx_type)
1075 { 1053 {
1076 case LINE_FIRST: 1054 case LINE_FIRST:
1077 case LINE_LAST: 1055 case LINE_LAST:
@@ -3074,7 +3052,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3074#endif /* not RE_ENABLE_I18N */ 3052#endif /* not RE_ENABLE_I18N */
3075 non_match = true; 3053 non_match = true;
3076 if (syntax & RE_HAT_LISTS_NOT_NEWLINE) 3054 if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
3077 bitset_set (sbcset, '\0'); 3055 bitset_set (sbcset, '\n');
3078 re_string_skip_bytes (regexp, token_len); /* Skip a token. */ 3056 re_string_skip_bytes (regexp, token_len); /* Skip a token. */
3079 token_len = peek_token_bracket (token, regexp, syntax); 3057 token_len = peek_token_bracket (token, regexp, syntax);
3080 if (BE (token->type == END_OF_RE, 0)) 3058 if (BE (token->type == END_OF_RE, 0))
@@ -3605,10 +3583,6 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3605 if (non_match) 3583 if (non_match)
3606 { 3584 {
3607#ifdef RE_ENABLE_I18N 3585#ifdef RE_ENABLE_I18N
3608 /*
3609 if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
3610 bitset_set(cset->sbcset, '\0');
3611 */
3612 mbcset->non_match = 1; 3586 mbcset->non_match = 1;
3613#endif /* not RE_ENABLE_I18N */ 3587#endif /* not RE_ENABLE_I18N */
3614 } 3588 }
diff --git a/gl/regex.c b/gl/regex.c
index d4eb726..ee36378 100644
--- a/gl/regex.c
+++ b/gl/regex.c
@@ -5,7 +5,7 @@
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
diff --git a/gl/regex.h b/gl/regex.h
index 6885ebd..a531283 100644
--- a/gl/regex.h
+++ b/gl/regex.h
@@ -6,7 +6,7 @@
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
9 the Free Software Foundation; either version 2, or (at your option) 9 the Free Software Foundation; either version 3, or (at your option)
10 any later version. 10 any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
@@ -625,41 +625,45 @@ extern int re_exec (const char *);
625#endif 625#endif
626 626
627/* GCC 2.95 and later have "__restrict"; C99 compilers have 627/* GCC 2.95 and later have "__restrict"; C99 compilers have
628 "restrict", and "configure" may have defined "restrict". */ 628 "restrict", and "configure" may have defined "restrict".
629#ifndef __restrict 629 Other compilers use __restrict, __restrict__, and _Restrict, and
630# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) 630 'configure' might #define 'restrict' to those words, so pick a
631# if defined restrict || 199901L <= __STDC_VERSION__ 631 different name. */
632# define __restrict restrict 632#ifndef _Restrict_
633# else 633# if 199901L <= __STDC_VERSION__
634# define __restrict 634# define _Restrict_ restrict
635# endif 635# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
636# define _Restrict_ __restrict
637# else
638# define _Restrict_
636# endif 639# endif
637#endif 640#endif
638/* gcc 3.1 and up support the [restrict] syntax. Don't trust 641/* gcc 3.1 and up support the [restrict] syntax. Don't trust
639 sys/cdefs.h's definition of __restrict_arr, though, as it 642 sys/cdefs.h's definition of __restrict_arr, though, as it
640 mishandles gcc -ansi -pedantic. */ 643 mishandles gcc -ansi -pedantic. */
641#undef __restrict_arr 644#ifndef _Restrict_arr_
642#if ((199901L <= __STDC_VERSION__ \ 645# if ((199901L <= __STDC_VERSION__ \
643 || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ 646 || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
644 && !__STRICT_ANSI__)) \ 647 && !__STRICT_ANSI__)) \
645 && !defined __GNUG__) 648 && !defined __GNUG__)
646# define __restrict_arr __restrict 649# define _Restrict_arr_ _Restrict_
647#else 650# else
648# define __restrict_arr 651# define _Restrict_arr_
652# endif
649#endif 653#endif
650 654
651/* POSIX compatibility. */ 655/* POSIX compatibility. */
652extern int regcomp (regex_t *__restrict __preg, 656extern int regcomp (regex_t *_Restrict_ __preg,
653 const char *__restrict __pattern, 657 const char *_Restrict_ __pattern,
654 int __cflags); 658 int __cflags);
655 659
656extern int regexec (const regex_t *__restrict __preg, 660extern int regexec (const regex_t *_Restrict_ __preg,
657 const char *__restrict __string, size_t __nmatch, 661 const char *_Restrict_ __string, size_t __nmatch,
658 regmatch_t __pmatch[__restrict_arr], 662 regmatch_t __pmatch[_Restrict_arr_],
659 int __eflags); 663 int __eflags);
660 664
661extern size_t regerror (int __errcode, const regex_t *__restrict __preg, 665extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
662 char *__restrict __errbuf, size_t __errbuf_size); 666 char *_Restrict_ __errbuf, size_t __errbuf_size);
663 667
664extern void regfree (regex_t *__preg); 668extern void regfree (regex_t *__preg);
665 669
diff --git a/gl/regex_internal.c b/gl/regex_internal.c
index 78e16f3..cf3bf1b 100644
--- a/gl/regex_internal.c
+++ b/gl/regex_internal.c
@@ -1,11 +1,12 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 5 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
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
8 the Free Software Foundation; either version 2, or (at your option) 9 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 10 any later version.
10 11
11 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
@@ -706,7 +707,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
706 707
707 if (pstr->is_utf8) 708 if (pstr->is_utf8)
708 { 709 {
709 const unsigned char *raw, *p, *q, *end; 710 const unsigned char *raw, *p, *end;
710 711
711 /* Special case UTF-8. Multi-byte chars start with any 712 /* Special case UTF-8. Multi-byte chars start with any
712 byte other than 0x80 - 0xbf. */ 713 byte other than 0x80 - 0xbf. */
@@ -735,13 +736,11 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
735 unsigned char buf[6]; 736 unsigned char buf[6];
736 size_t mbclen; 737 size_t mbclen;
737 738
738 q = p;
739 if (BE (pstr->trans != NULL, 0)) 739 if (BE (pstr->trans != NULL, 0))
740 { 740 {
741 int i = mlen < 6 ? mlen : 6; 741 int i = mlen < 6 ? mlen : 6;
742 while (--i >= 0) 742 while (--i >= 0)
743 buf[i] = pstr->trans[p[i]]; 743 buf[i] = pstr->trans[p[i]];
744 q = buf;
745 } 744 }
746 /* XXX Don't use mbrtowc, we know which conversion 745 /* XXX Don't use mbrtowc, we know which conversion
747 to use (UTF-8 -> UCS4). */ 746 to use (UTF-8 -> UCS4). */
diff --git a/gl/regex_internal.h b/gl/regex_internal.h
index b0f7e65..f96291d 100644
--- a/gl/regex_internal.h
+++ b/gl/regex_internal.h
@@ -5,7 +5,7 @@
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
@@ -27,12 +27,10 @@
27#include <stdlib.h> 27#include <stdlib.h>
28#include <string.h> 28#include <string.h>
29 29
30#ifndef _LIBC 30#ifdef _LIBC
31# include "strcase.h"
32#endif
33
34#if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
35# include <langinfo.h> 31# include <langinfo.h>
32#else
33# include "localcharset.h"
36#endif 34#endif
37#if defined HAVE_LOCALE_H || defined _LIBC 35#if defined HAVE_LOCALE_H || defined _LIBC
38# include <locale.h> 36# include <locale.h>
@@ -50,7 +48,7 @@
50#endif 48#endif
51 49
52/* In case that the system doesn't have isblank(). */ 50/* In case that the system doesn't have isblank(). */
53#if !defined _LIBC && !HAVE_DECL_ISBLANK && !defined isblank 51#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
54# define isblank(ch) ((ch) == ' ' || (ch) == '\t') 52# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
55#endif 53#endif
56 54
@@ -116,9 +114,6 @@
116# define __wctype wctype 114# define __wctype wctype
117# define __iswctype iswctype 115# define __iswctype iswctype
118# define __btowc btowc 116# define __btowc btowc
119# ifndef __mempcpy
120# define __mempcpy mempcpy
121# endif
122# define __wcrtomb wcrtomb 117# define __wcrtomb wcrtomb
123# define __regfree regfree 118# define __regfree regfree
124# define attribute_hidden 119# define attribute_hidden
diff --git a/gl/regexec.c b/gl/regexec.c
index 7c186aa..ac6c258 100644
--- a/gl/regexec.c
+++ b/gl/regexec.c
@@ -1,11 +1,12 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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
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
8 the Free Software Foundation; either version 2, or (at your option) 9 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 10 any later version.
10 11
11 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
@@ -221,10 +222,10 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx)
221 222
222int 223int
223regexec (preg, string, nmatch, pmatch, eflags) 224regexec (preg, string, nmatch, pmatch, eflags)
224 const regex_t *__restrict preg; 225 const regex_t *_Restrict_ preg;
225 const char *__restrict string; 226 const char *_Restrict_ string;
226 size_t nmatch; 227 size_t nmatch;
227 regmatch_t pmatch[]; 228 regmatch_t pmatch[_Restrict_arr_];
228 int eflags; 229 int eflags;
229{ 230{
230 reg_errcode_t err; 231 reg_errcode_t err;
@@ -267,8 +268,8 @@ __typeof__ (__regexec) __compat_regexec;
267 268
268int 269int
269attribute_compat_text_section 270attribute_compat_text_section
270__compat_regexec (const regex_t *__restrict preg, 271__compat_regexec (const regex_t *_Restrict_ preg,
271 const char *__restrict string, size_t nmatch, 272 const char *_Restrict_ string, size_t nmatch,
272 regmatch_t pmatch[], int eflags) 273 regmatch_t pmatch[], int eflags)
273{ 274{
274 return regexec (preg, string, nmatch, pmatch, 275 return regexec (preg, string, nmatch, pmatch,
@@ -2338,7 +2339,7 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2338} 2339}
2339 2340
2340/* Update the state_log if we need */ 2341/* Update the state_log if we need */
2341re_dfastate_t * 2342static re_dfastate_t *
2342internal_function 2343internal_function
2343merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, 2344merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2344 re_dfastate_t *next_state) 2345 re_dfastate_t *next_state)
diff --git a/gl/safe-read.c b/gl/safe-read.c
index b7bf1d5..0cb1ede 100644
--- a/gl/safe-read.c
+++ b/gl/safe-read.c
@@ -3,10 +3,10 @@
3 Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free 3 Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free
4 Software Foundation, Inc. 4 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
diff --git a/gl/safe-read.h b/gl/safe-read.h
index 3451955..ba19171 100644
--- a/gl/safe-read.h
+++ b/gl/safe-read.h
@@ -1,10 +1,10 @@
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 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3 of the License, or
7 any later version. 7 (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 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, 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 16
18#include <stddef.h> 17#include <stddef.h>
19 18
diff --git a/gl/safe-write.c b/gl/safe-write.c
index 4c375a6..b644f7c 100644
--- a/gl/safe-write.c
+++ b/gl/safe-write.c
@@ -1,10 +1,10 @@
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 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3 of the License, or
7 any later version. 7 (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 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, 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 16
18#define SAFE_WRITE 17#define SAFE_WRITE
19#include "safe-read.c" 18#include "safe-read.c"
diff --git a/gl/safe-write.h b/gl/safe-write.h
index c194636..da036a9 100644
--- a/gl/safe-write.h
+++ b/gl/safe-write.h
@@ -1,10 +1,10 @@
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 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3 of the License, or
7 any later version. 7 (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 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, 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 16
18#include <stddef.h> 17#include <stddef.h>
19 18
diff --git a/gl/size_max.h b/gl/size_max.h
index ed0bc13..2ccc5f0 100644
--- a/gl/size_max.h
+++ b/gl/size_max.h
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
diff --git a/gl/snprintf.c b/gl/snprintf.c
index db1ca9a..960cfdb 100644
--- a/gl/snprintf.c
+++ b/gl/snprintf.c
@@ -1,10 +1,10 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 2004, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2006-2007 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
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -18,7 +18,8 @@
18 18
19#include <config.h> 19#include <config.h>
20 20
21#include "snprintf.h" 21/* Specification. */
22#include <stdio.h>
22 23
23#include <errno.h> 24#include <errno.h>
24#include <limits.h> 25#include <limits.h>
@@ -37,7 +38,7 @@
37 additional length SIZE limit how much is written into STR. Returns 38 additional length SIZE limit how much is written into STR. Returns
38 string length of formatted string (which may be larger than SIZE). 39 string length of formatted string (which may be larger than SIZE).
39 STR may be NULL, in which case nothing will be written. On error, 40 STR may be NULL, in which case nothing will be written. On error,
40 return a negative value. */ 41 return a negative value. */
41int 42int
42snprintf (char *str, size_t size, const char *format, ...) 43snprintf (char *str, size_t size, const char *format, ...)
43{ 44{
diff --git a/gl/snprintf.h b/gl/snprintf.h
deleted file mode 100644
index 5032b9e..0000000
--- a/gl/snprintf.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/* Formatted output to strings.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
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 2, 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#ifndef SNPRINTF_H
20#define SNPRINTF_H
21
22/* Get snprintf declaration, if available. */
23#include <stdio.h>
24
25#if defined HAVE_DECL_SNPRINTF && !HAVE_DECL_SNPRINTF
26int snprintf (char *str, size_t size, const char *format, ...);
27#endif
28
29#endif /* SNPRINTF_H */
diff --git a/gl/stdbool_.h b/gl/stdbool.in.h
index efa80ba..171d70a 100644
--- a/gl/stdbool_.h
+++ b/gl/stdbool.in.h
@@ -1,9 +1,9 @@
1/* Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. 1/* Copyright (C) 2001, 2002, 2003, 2006, 2007 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
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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -15,8 +15,8 @@
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 _STDBOOL_H 18#ifndef _GL_STDBOOL_H
19#define _STDBOOL_H 19#define _GL_STDBOOL_H
20 20
21/* ISO C 99 <stdbool.h> for platforms that lack it. */ 21/* ISO C 99 <stdbool.h> for platforms that lack it. */
22 22
@@ -41,6 +41,9 @@
41 41
42 - You cannot assume that _Bool is a typedef; it might be a macro. 42 - You cannot assume that _Bool is a typedef; it might be a macro.
43 43
44 - Bit-fields of type 'bool' are not supported. Portable code
45 should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
46
44 - In C99, casts and automatic conversions to '_Bool' or 'bool' are 47 - In C99, casts and automatic conversions to '_Bool' or 'bool' are
45 performed in such a way that every nonzero value gets converted 48 performed in such a way that every nonzero value gets converted
46 to 'true', and zero gets converted to 'false'. This doesn't work 49 to 'true', and zero gets converted to 'false'. This doesn't work
@@ -94,10 +97,11 @@ typedef bool _Bool;
94 "warning: _Bool is a keyword in ISO C99". 97 "warning: _Bool is a keyword in ISO C99".
95 Use of an enum type, with IRIX cc, leads to a stupid 98 Use of an enum type, with IRIX cc, leads to a stupid
96 "warning(1185): enumerated type mixed with another type". 99 "warning(1185): enumerated type mixed with another type".
97 The only benefit of the enum type, debuggability, is not important 100 Even the existence of an enum type, without a typedef,
98 with these compilers. So use 'signed char' and no typedef. */ 101 "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
102 The only benefit of the enum, debuggability, is not important
103 with these compilers. So use 'signed char' and no enum. */
99# define _Bool signed char 104# define _Bool signed char
100enum { false = 0, true = 1 };
101# else 105# else
102 /* With this compiler, trust the _Bool type if the compiler has it. */ 106 /* With this compiler, trust the _Bool type if the compiler has it. */
103# if !@HAVE__BOOL@ 107# if !@HAVE__BOOL@
@@ -112,4 +116,4 @@ typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
112#define true 1 116#define true 1
113#define __bool_true_false_are_defined 1 117#define __bool_true_false_are_defined 1
114 118
115#endif /* _STDBOOL_H */ 119#endif /* _GL_STDBOOL_H */
diff --git a/gl/stdint_.h b/gl/stdint.in.h
index 64ec8c5..67baceb 100644
--- a/gl/stdint_.h
+++ b/gl/stdint.in.h
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -16,14 +16,19 @@
16 along with this program; if not, write to the Free Software Foundation, 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. */ 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 18
19#ifndef _GL_STDINT_H
20#define _GL_STDINT_H
21
22/* 19/*
23 * ISO C 99 <stdint.h> for platforms that lack it. 20 * ISO C 99 <stdint.h> for platforms that lack it.
24 * <http://www.opengroup.org/susv3xbd/stdint.h.html> 21 * <http://www.opengroup.org/susv3xbd/stdint.h.html>
25 */ 22 */
26 23
24#ifndef _GL_STDINT_H
25
26/* When including a system file that in turn includes <inttypes.h>,
27 use the system <inttypes.h>, not our substitute. This avoids
28 problems with (for example) VMS, whose <sys/bitypes.h> includes
29 <inttypes.h>. */
30#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
31
27/* Get those types that are already defined in other system include 32/* Get those types that are already defined in other system include
28 files, so that we can "#define int8_t signed char" below without 33 files, so that we can "#define int8_t signed char" below without
29 worrying about a later system include file containing a "typedef 34 worrying about a later system include file containing a "typedef
@@ -42,16 +47,20 @@
42 /* Other systems may have an incomplete or buggy <stdint.h>. 47 /* Other systems may have an incomplete or buggy <stdint.h>.
43 Include it before <inttypes.h>, since any "#include <stdint.h>" 48 Include it before <inttypes.h>, since any "#include <stdint.h>"
44 in <inttypes.h> would reinclude us, skipping our contents because 49 in <inttypes.h> would reinclude us, skipping our contents because
45 _GL_STDINT_H is defined. */ 50 _GL_STDINT_H is defined.
46# include @ABSOLUTE_STDINT_H@ 51 The include_next requires a split double-inclusion guard. */
52# @INCLUDE_NEXT@ @NEXT_STDINT_H@
47#endif 53#endif
48 54
55#if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
56#define _GL_STDINT_H
57
49/* <sys/types.h> defines some of the stdint.h types as well, on glibc, 58/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
50 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>). 59 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
51 AIX 5.2 <sys/types.h> isn't needed and causes troubles. 60 AIX 5.2 <sys/types.h> isn't needed and causes troubles.
52 MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but 61 MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
53 relies on the system <stdint.h> definitions, so include 62 relies on the system <stdint.h> definitions, so include
54 <sys/types.h> after @ABSOLUTE_STDINT_H@. */ 63 <sys/types.h> after @NEXT_STDINT_H@. */
55#if @HAVE_SYS_TYPES_H@ && ! defined _AIX 64#if @HAVE_SYS_TYPES_H@ && ! defined _AIX
56# include <sys/types.h> 65# include <sys/types.h>
57#endif 66#endif
@@ -63,9 +72,7 @@
63 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines 72 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
64 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. 73 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
65 <inttypes.h> also defines intptr_t and uintptr_t. */ 74 <inttypes.h> also defines intptr_t and uintptr_t. */
66# define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
67# include <inttypes.h> 75# include <inttypes.h>
68# undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
69#elif @HAVE_SYS_INTTYPES_H@ 76#elif @HAVE_SYS_INTTYPES_H@
70 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and 77 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
71 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ 78 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
@@ -88,6 +95,8 @@
88 95
89#endif 96#endif
90 97
98#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
99
91/* Minimum and maximum values for a integer type under the usual assumption. 100/* Minimum and maximum values for a integer type under the usual assumption.
92 Return an unspecified value if BITS == 0, adding a check to pacify 101 Return an unspecified value if BITS == 0, adding a check to pacify
93 picky compilers. */ 102 picky compilers. */
@@ -98,7 +107,10 @@
98#define _STDINT_MAX(signed, bits, zero) \ 107#define _STDINT_MAX(signed, bits, zero) \
99 ((signed) \ 108 ((signed) \
100 ? ~ _STDINT_MIN (signed, bits, zero) \ 109 ? ~ _STDINT_MIN (signed, bits, zero) \
101 : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1) 110 : /* The expression for the unsigned case. The subtraction of (signed) \
111 is a nop in the unsigned case and avoids "signed integer overflow" \
112 warnings in the signed case. */ \
113 ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
102 114
103/* 7.18.1.1. Exact-width integer types */ 115/* 7.18.1.1. Exact-width integer types */
104 116
@@ -120,22 +132,34 @@
120#define int32_t int 132#define int32_t int
121#define uint32_t unsigned int 133#define uint32_t unsigned int
122 134
123#undef int64_t 135/* Do not undefine int64_t if gnulib is not being used with 64-bit
136 types, since otherwise it breaks platforms like Tandem/NSK. */
124#if LONG_MAX >> 31 >> 31 == 1 137#if LONG_MAX >> 31 >> 31 == 1
138# undef int64_t
125# define int64_t long int 139# define int64_t long int
140# define GL_INT64_T
126#elif defined _MSC_VER 141#elif defined _MSC_VER
142# undef int64_t
127# define int64_t __int64 143# define int64_t __int64
144# define GL_INT64_T
128#elif @HAVE_LONG_LONG_INT@ 145#elif @HAVE_LONG_LONG_INT@
146# undef int64_t
129# define int64_t long long int 147# define int64_t long long int
148# define GL_INT64_T
130#endif 149#endif
131 150
132#undef uint64_t
133#if ULONG_MAX >> 31 >> 31 >> 1 == 1 151#if ULONG_MAX >> 31 >> 31 >> 1 == 1
152# undef uint64_t
134# define uint64_t unsigned long int 153# define uint64_t unsigned long int
154# define GL_UINT64_T
135#elif defined _MSC_VER 155#elif defined _MSC_VER
156# undef uint64_t
136# define uint64_t unsigned __int64 157# define uint64_t unsigned __int64
158# define GL_UINT64_T
137#elif @HAVE_UNSIGNED_LONG_LONG_INT@ 159#elif @HAVE_UNSIGNED_LONG_LONG_INT@
160# undef uint64_t
138# define uint64_t unsigned long long int 161# define uint64_t unsigned long long int
162# define GL_UINT64_T
139#endif 163#endif
140 164
141/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */ 165/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
@@ -164,10 +188,10 @@
164#define uint_least16_t uint16_t 188#define uint_least16_t uint16_t
165#define int_least32_t int32_t 189#define int_least32_t int32_t
166#define uint_least32_t uint32_t 190#define uint_least32_t uint32_t
167#ifdef int64_t 191#ifdef GL_INT64_T
168# define int_least64_t int64_t 192# define int_least64_t int64_t
169#endif 193#endif
170#ifdef uint64_t 194#ifdef GL_UINT64_T
171# define uint_least64_t uint64_t 195# define uint_least64_t uint64_t
172#endif 196#endif
173 197
@@ -195,10 +219,10 @@
195#define uint_fast16_t unsigned int_fast16_t 219#define uint_fast16_t unsigned int_fast16_t
196#define int_fast32_t long int 220#define int_fast32_t long int
197#define uint_fast32_t unsigned int_fast32_t 221#define uint_fast32_t unsigned int_fast32_t
198#ifdef int64_t 222#ifdef GL_INT64_T
199# define int_fast64_t int64_t 223# define int_fast64_t int64_t
200#endif 224#endif
201#ifdef uint64_t 225#ifdef GL_UINT64_T
202# define uint_fast64_t uint64_t 226# define uint_fast64_t uint64_t
203#endif 227#endif
204 228
@@ -217,7 +241,7 @@
217#undef intmax_t 241#undef intmax_t
218#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 242#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
219# define intmax_t long long int 243# define intmax_t long long int
220#elif defined int64_t 244#elif defined GL_INT64_T
221# define intmax_t int64_t 245# define intmax_t int64_t
222#else 246#else
223# define intmax_t long int 247# define intmax_t long int
@@ -226,12 +250,17 @@
226#undef uintmax_t 250#undef uintmax_t
227#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 251#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
228# define uintmax_t unsigned long long int 252# define uintmax_t unsigned long long int
229#elif defined uint64_t 253#elif defined GL_UINT64_T
230# define uintmax_t uint64_t 254# define uintmax_t uint64_t
231#else 255#else
232# define uintmax_t unsigned long int 256# define uintmax_t unsigned long int
233#endif 257#endif
234 258
259/* Verify that intmax_t and uintmax_t have the same size. Too much code
260 breaks if this is not the case. If this check fails, the reason is likely
261 to be found in the autoconf macros. */
262typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - 1];
263
235/* 7.18.2. Limits of specified-width integer types */ 264/* 7.18.2. Limits of specified-width integer types */
236 265
237#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS 266#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS
@@ -264,13 +293,15 @@
264 293
265#undef INT64_MIN 294#undef INT64_MIN
266#undef INT64_MAX 295#undef INT64_MAX
267#ifdef int64_t 296#ifdef GL_INT64_T
268# define INT64_MIN (~ INT64_MAX) 297/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
298 evaluates the latter incorrectly in preprocessor expressions. */
299# define INT64_MIN (- INTMAX_C (1) << 63)
269# define INT64_MAX INTMAX_C (9223372036854775807) 300# define INT64_MAX INTMAX_C (9223372036854775807)
270#endif 301#endif
271 302
272#undef UINT64_MAX 303#undef UINT64_MAX
273#ifdef uint64_t 304#ifdef GL_UINT64_T
274# define UINT64_MAX UINTMAX_C (18446744073709551615) 305# define UINT64_MAX UINTMAX_C (18446744073709551615)
275#endif 306#endif
276 307
@@ -303,13 +334,13 @@
303 334
304#undef INT_LEAST64_MIN 335#undef INT_LEAST64_MIN
305#undef INT_LEAST64_MAX 336#undef INT_LEAST64_MAX
306#ifdef int64_t 337#ifdef GL_INT64_T
307# define INT_LEAST64_MIN INT64_MIN 338# define INT_LEAST64_MIN INT64_MIN
308# define INT_LEAST64_MAX INT64_MAX 339# define INT_LEAST64_MAX INT64_MAX
309#endif 340#endif
310 341
311#undef UINT_LEAST64_MAX 342#undef UINT_LEAST64_MAX
312#ifdef uint64_t 343#ifdef GL_UINT64_T
313# define UINT_LEAST64_MAX UINT64_MAX 344# define UINT_LEAST64_MAX UINT64_MAX
314#endif 345#endif
315 346
@@ -342,13 +373,13 @@
342 373
343#undef INT_FAST64_MIN 374#undef INT_FAST64_MIN
344#undef INT_FAST64_MAX 375#undef INT_FAST64_MAX
345#ifdef int64_t 376#ifdef GL_INT64_T
346# define INT_FAST64_MIN INT64_MIN 377# define INT_FAST64_MIN INT64_MIN
347# define INT_FAST64_MAX INT64_MAX 378# define INT_FAST64_MAX INT64_MAX
348#endif 379#endif
349 380
350#undef UINT_FAST64_MAX 381#undef UINT_FAST64_MAX
351#ifdef uint64_t 382#ifdef GL_UINT64_T
352# define UINT_FAST64_MAX UINT64_MAX 383# define UINT_FAST64_MAX UINT64_MAX
353#endif 384#endif
354 385
@@ -365,10 +396,11 @@
365 396
366#undef INTMAX_MIN 397#undef INTMAX_MIN
367#undef INTMAX_MAX 398#undef INTMAX_MAX
368#define INTMAX_MIN (~ INTMAX_MAX)
369#ifdef INT64_MAX 399#ifdef INT64_MAX
400# define INTMAX_MIN INT64_MIN
370# define INTMAX_MAX INT64_MAX 401# define INTMAX_MAX INT64_MAX
371#else 402#else
403# define INTMAX_MIN INT32_MIN
372# define INTMAX_MAX INT32_MAX 404# define INTMAX_MAX INT32_MAX
373#endif 405#endif
374 406
@@ -469,7 +501,7 @@
469#undef INTMAX_C 501#undef INTMAX_C
470#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 502#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
471# define INTMAX_C(x) x##LL 503# define INTMAX_C(x) x##LL
472#elif defined int64_t 504#elif defined GL_INT64_T
473# define INTMAX_C(x) INT64_C(x) 505# define INTMAX_C(x) INT64_C(x)
474#else 506#else
475# define INTMAX_C(x) x##L 507# define INTMAX_C(x) x##L
@@ -478,7 +510,7 @@
478#undef UINTMAX_C 510#undef UINTMAX_C
479#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 511#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
480# define UINTMAX_C(x) x##ULL 512# define UINTMAX_C(x) x##ULL
481#elif defined uint64_t 513#elif defined GL_UINT64_T
482# define UINTMAX_C(x) UINT64_C(x) 514# define UINTMAX_C(x) UINT64_C(x)
483#else 515#else
484# define UINTMAX_C(x) x##UL 516# define UINTMAX_C(x) x##UL
@@ -487,3 +519,4 @@
487#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ 519#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
488 520
489#endif /* _GL_STDINT_H */ 521#endif /* _GL_STDINT_H */
522#endif /* !defined _GL_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
new file mode 100644
index 0000000..434fa8e
--- /dev/null
+++ b/gl/stdio.in.h
@@ -0,0 +1,382 @@
1/* A GNU-like <stdio.h>.
2
3 Copyright (C) 2004, 2007-2008 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#if defined __need_FILE || defined __need___FILE
20/* Special invocation convention inside glibc header files. */
21
22#@INCLUDE_NEXT@ @NEXT_STDIO_H@
23
24#else
25/* Normal invocation convention. */
26
27#ifndef _GL_STDIO_H
28
29/* The include_next requires a split double-inclusion guard. */
30#@INCLUDE_NEXT@ @NEXT_STDIO_H@
31
32#ifndef _GL_STDIO_H
33#define _GL_STDIO_H
34
35#include <stdarg.h>
36#include <stddef.h>
37
38#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
39 || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
40 || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
41 || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
42/* Get off_t and ssize_t. */
43# include <sys/types.h>
44#endif
45
46#ifndef __attribute__
47/* This feature is available in gcc versions 2.5 and later. */
48# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
49# define __attribute__(Spec) /* empty */
50# endif
51/* The __-protected variants of `format' and `printf' attributes
52 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
53# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
54# define __format__ format
55# define __printf__ printf
56# endif
57#endif
58
59
60/* The definition of GL_LINK_WARNING is copied here. */
61
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67
68#if @GNULIB_FPRINTF_POSIX@
69# if @REPLACE_FPRINTF@
70# define fprintf rpl_fprintf
71extern int fprintf (FILE *fp, const char *format, ...)
72 __attribute__ ((__format__ (__printf__, 2, 3)));
73# endif
74#elif defined GNULIB_POSIXCHECK
75# undef fprintf
76# define fprintf \
77 (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
78 "use gnulib module fprintf-posix for portable " \
79 "POSIX compliance"), \
80 fprintf)
81#endif
82
83#if @GNULIB_VFPRINTF_POSIX@
84# if @REPLACE_VFPRINTF@
85# define vfprintf rpl_vfprintf
86extern int vfprintf (FILE *fp, const char *format, va_list args)
87 __attribute__ ((__format__ (__printf__, 2, 0)));
88# endif
89#elif defined GNULIB_POSIXCHECK
90# undef vfprintf
91# define vfprintf(s,f,a) \
92 (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
93 "use gnulib module vfprintf-posix for portable " \
94 "POSIX compliance"), \
95 vfprintf (s, f, a))
96#endif
97
98#if @GNULIB_PRINTF_POSIX@
99# if @REPLACE_PRINTF@
100/* Don't break __attribute__((format(printf,M,N))). */
101# define printf __printf__
102extern int printf (const char *format, ...)
103 __attribute__ ((__format__ (__printf__, 1, 2)));
104# endif
105#elif defined GNULIB_POSIXCHECK
106# undef printf
107# define printf \
108 (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
109 "use gnulib module printf-posix for portable " \
110 "POSIX compliance"), \
111 printf)
112/* Don't break __attribute__((format(printf,M,N))). */
113# define format(kind,m,n) format (__##kind##__, m, n)
114# define __format__(kind,m,n) __format__ (__##kind##__, m, n)
115# define ____printf____ __printf__
116# define ____scanf____ __scanf__
117# define ____strftime____ __strftime__
118# define ____strfmon____ __strfmon__
119#endif
120
121#if @GNULIB_VPRINTF_POSIX@
122# if @REPLACE_VPRINTF@
123# define vprintf rpl_vprintf
124extern int vprintf (const char *format, va_list args)
125 __attribute__ ((__format__ (__printf__, 1, 0)));
126# endif
127#elif defined GNULIB_POSIXCHECK
128# undef vprintf
129# define vprintf(f,a) \
130 (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
131 "use gnulib module vprintf-posix for portable " \
132 "POSIX compliance"), \
133 vprintf (f, a))
134#endif
135
136#if @GNULIB_SNPRINTF@
137# if @REPLACE_SNPRINTF@
138# define snprintf rpl_snprintf
139# endif
140# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
141extern int snprintf (char *str, size_t size, const char *format, ...)
142 __attribute__ ((__format__ (__printf__, 3, 4)));
143# endif
144#elif defined GNULIB_POSIXCHECK
145# undef snprintf
146# define snprintf \
147 (GL_LINK_WARNING ("snprintf is unportable - " \
148 "use gnulib module snprintf for portability"), \
149 snprintf)
150#endif
151
152#if @GNULIB_VSNPRINTF@
153# if @REPLACE_VSNPRINTF@
154# define vsnprintf rpl_vsnprintf
155# endif
156# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
157extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
158 __attribute__ ((__format__ (__printf__, 3, 0)));
159# endif
160#elif defined GNULIB_POSIXCHECK
161# undef vsnprintf
162# define vsnprintf(b,s,f,a) \
163 (GL_LINK_WARNING ("vsnprintf is unportable - " \
164 "use gnulib module vsnprintf for portability"), \
165 vsnprintf (b, s, f, a))
166#endif
167
168#if @GNULIB_SPRINTF_POSIX@
169# if @REPLACE_SPRINTF@
170# define sprintf rpl_sprintf
171extern int sprintf (char *str, const char *format, ...)
172 __attribute__ ((__format__ (__printf__, 2, 3)));
173# endif
174#elif defined GNULIB_POSIXCHECK
175# undef sprintf
176# define sprintf \
177 (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
178 "use gnulib module sprintf-posix for portable " \
179 "POSIX compliance"), \
180 sprintf)
181#endif
182
183#if @GNULIB_VSPRINTF_POSIX@
184# if @REPLACE_VSPRINTF@
185# define vsprintf rpl_vsprintf
186extern int vsprintf (char *str, const char *format, va_list args)
187 __attribute__ ((__format__ (__printf__, 2, 0)));
188# endif
189#elif defined GNULIB_POSIXCHECK
190# undef vsprintf
191# define vsprintf(b,f,a) \
192 (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
193 "use gnulib module vsprintf-posix for portable " \
194 "POSIX compliance"), \
195 vsprintf (b, f, a))
196#endif
197
198#if @GNULIB_VASPRINTF@
199# if @REPLACE_VASPRINTF@
200# define asprintf rpl_asprintf
201# define vasprintf rpl_vasprintf
202# endif
203# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
204 /* Write formatted output to a string dynamically allocated with malloc().
205 If the memory allocation succeeds, store the address of the string in
206 *RESULT and return the number of resulting bytes, excluding the trailing
207 NUL. Upon memory allocation error, or some other error, return -1. */
208 extern int asprintf (char **result, const char *format, ...)
209 __attribute__ ((__format__ (__printf__, 2, 3)));
210 extern int vasprintf (char **result, const char *format, va_list args)
211 __attribute__ ((__format__ (__printf__, 2, 0)));
212# endif
213#endif
214
215#if @GNULIB_FOPEN@
216# if @REPLACE_FOPEN@
217# define fopen rpl_fopen
218extern FILE * fopen (const char *filename, const char *mode);
219# endif
220#elif defined GNULIB_POSIXCHECK
221# undef fopen
222# define fopen(f,m) \
223 (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
224 "use gnulib module fopen for portability"), \
225 fopen (f, m))
226#endif
227
228#if @GNULIB_FREOPEN@
229# if @REPLACE_FREOPEN@
230# define freopen rpl_freopen
231extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
232# endif
233#elif defined GNULIB_POSIXCHECK
234# undef freopen
235# define freopen(f,m,s) \
236 (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
237 "use gnulib module freopen for portability"), \
238 freopen (f, m, s))
239#endif
240
241#if @GNULIB_FSEEKO@
242# if @REPLACE_FSEEKO@
243/* Provide fseek, fseeko functions that are aware of a preceding
244 fflush(), and which detect pipes. */
245# define fseeko rpl_fseeko
246extern int fseeko (FILE *fp, off_t offset, int whence);
247# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
248# endif
249#elif defined GNULIB_POSIXCHECK
250# undef fseeko
251# define fseeko(f,o,w) \
252 (GL_LINK_WARNING ("fseeko is unportable - " \
253 "use gnulib module fseeko for portability"), \
254 fseeko (f, o, w))
255#endif
256
257#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
258extern int rpl_fseek (FILE *fp, long offset, int whence);
259# undef fseek
260# if defined GNULIB_POSIXCHECK
261# define fseek(f,o,w) \
262 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
263 "on 32-bit platforms - " \
264 "use fseeko function for handling of large files"), \
265 rpl_fseek (f, o, w))
266# else
267# define fseek rpl_fseek
268# endif
269#elif defined GNULIB_POSIXCHECK
270# ifndef fseek
271# define fseek(f,o,w) \
272 (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
273 "on 32-bit platforms - " \
274 "use fseeko function for handling of large files"), \
275 fseek (f, o, w))
276# endif
277#endif
278
279#if @GNULIB_FTELLO@
280# if @REPLACE_FTELLO@
281# define ftello rpl_ftello
282extern off_t ftello (FILE *fp);
283# define ftell(fp) ftello (fp)
284# endif
285#elif defined GNULIB_POSIXCHECK
286# undef ftello
287# define ftello(f) \
288 (GL_LINK_WARNING ("ftello is unportable - " \
289 "use gnulib module ftello for portability"), \
290 ftello (f))
291#endif
292
293#if @GNULIB_FTELL@ && @REPLACE_FTELL@
294extern long rpl_ftell (FILE *fp);
295# undef ftell
296# if GNULIB_POSIXCHECK
297# define ftell(f) \
298 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
299 "on 32-bit platforms - " \
300 "use ftello function for handling of large files"), \
301 rpl_ftell (f))
302# else
303# define ftell rpl_ftell
304# endif
305#elif defined GNULIB_POSIXCHECK
306# ifndef ftell
307# define ftell(f) \
308 (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
309 "on 32-bit platforms - " \
310 "use ftello function for handling of large files"), \
311 ftell (f))
312# endif
313#endif
314
315#if @GNULIB_FFLUSH@
316# if @REPLACE_FFLUSH@
317# define fflush rpl_fflush
318 /* Flush all pending data on STREAM according to POSIX rules. Both
319 output and seekable input streams are supported.
320 Note! LOSS OF DATA can occur if fflush is applied on an input stream
321 that is _not_seekable_ or on an update stream that is _not_seekable_
322 and in which the most recent operation was input. Seekability can
323 be tested with lseek(fileno(fp),0,SEEK_CUR). */
324 extern int fflush (FILE *gl_stream);
325# endif
326#elif defined GNULIB_POSIXCHECK
327# undef fflush
328# define fflush(f) \
329 (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
330 "use gnulib module fflush for portable " \
331 "POSIX compliance"), \
332 fflush (f))
333#endif
334
335#if @GNULIB_GETDELIM@
336# if !@HAVE_DECL_GETDELIM@
337/* Read input, up to (and including) the next occurrence of DELIMITER, from
338 STREAM, store it in *LINEPTR (and NUL-terminate it).
339 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
340 bytes of space. It is realloc'd as necessary.
341 Return the number of bytes read and stored at *LINEPTR (not including the
342 NUL terminator), or -1 on error or EOF. */
343extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
344 FILE *stream);
345# endif
346#elif defined GNULIB_POSIXCHECK
347# undef getdelim
348# define getdelim(l, s, d, f) \
349 (GL_LINK_WARNING ("getdelim is unportable - " \
350 "use gnulib module getdelim for portability"), \
351 getdelim (l, s, d, f))
352#endif
353
354#if @GNULIB_GETLINE@
355# if @REPLACE_GETLINE@
356# undef getline
357# define getline rpl_getline
358# endif
359# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
360/* Read a line, up to (and including) the next newline, from STREAM, store it
361 in *LINEPTR (and NUL-terminate it).
362 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
363 bytes of space. It is realloc'd as necessary.
364 Return the number of bytes read and stored at *LINEPTR (not including the
365 NUL terminator), or -1 on error or EOF. */
366extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
367# endif
368#elif defined GNULIB_POSIXCHECK
369# undef getline
370# define getline(l, s, f) \
371 (GL_LINK_WARNING ("getline is unportable - " \
372 "use gnulib module getline for portability"), \
373 getline (l, s, f))
374#endif
375
376#ifdef __cplusplus
377}
378#endif
379
380#endif /* _GL_STDIO_H */
381#endif /* _GL_STDIO_H */
382#endif
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
new file mode 100644
index 0000000..100ff52
--- /dev/null
+++ b/gl/stdlib.in.h
@@ -0,0 +1,208 @@
1/* A GNU-like <stdlib.h>.
2
3 Copyright (C) 1995, 2001-2004, 2006-2007 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#if defined __need_malloc_and_calloc
19/* Special invocation convention inside glibc header files. */
20
21#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
22
23#else
24/* Normal invocation convention. */
25
26#ifndef _GL_STDLIB_H
27
28/* The include_next requires a split double-inclusion guard. */
29#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
30
31#ifndef _GL_STDLIB_H
32#define _GL_STDLIB_H
33
34
35/* The definition of GL_LINK_WARNING is copied here. */
36
37
38/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
39#ifndef EXIT_SUCCESS
40# define EXIT_SUCCESS 0
41#endif
42/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
43 with proper operation of xargs. */
44#ifndef EXIT_FAILURE
45# define EXIT_FAILURE 1
46#elif EXIT_FAILURE != 1
47# undef EXIT_FAILURE
48# define EXIT_FAILURE 1
49#endif
50
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56
57#if @GNULIB_MALLOC_POSIX@
58# if !@HAVE_MALLOC_POSIX@
59# undef malloc
60# define malloc rpl_malloc
61extern void * malloc (size_t size);
62# endif
63#elif defined GNULIB_POSIXCHECK
64# undef malloc
65# define malloc(s) \
66 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
67 "use gnulib module malloc-posix for portability"), \
68 malloc (s))
69#endif
70
71
72#if @GNULIB_REALLOC_POSIX@
73# if !@HAVE_REALLOC_POSIX@
74# undef realloc
75# define realloc rpl_realloc
76extern void * realloc (void *ptr, size_t size);
77# endif
78#elif defined GNULIB_POSIXCHECK
79# undef realloc
80# define realloc(p,s) \
81 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
82 "use gnulib module realloc-posix for portability"), \
83 realloc (p, s))
84#endif
85
86
87#if @GNULIB_CALLOC_POSIX@
88# if !@HAVE_CALLOC_POSIX@
89# undef calloc
90# define calloc rpl_calloc
91extern void * calloc (size_t nmemb, size_t size);
92# endif
93#elif defined GNULIB_POSIXCHECK
94# undef calloc
95# define calloc(n,s) \
96 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
97 "use gnulib module calloc-posix for portability"), \
98 calloc (n, s))
99#endif
100
101
102#if @GNULIB_GETSUBOPT@
103/* Assuming *OPTIONP is a comma separated list of elements of the form
104 "token" or "token=value", getsubopt parses the first of these elements.
105 If the first element refers to a "token" that is member of the given
106 NULL-terminated array of tokens:
107 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
108 the first option and the comma, sets *VALUEP to the value of the
109 element (or NULL if it doesn't contain an "=" sign),
110 - It returns the index of the "token" in the given array of tokens.
111 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
112 For more details see the POSIX:2001 specification.
113 http://www.opengroup.org/susv3xsh/getsubopt.html */
114# if !@HAVE_GETSUBOPT@
115extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
116# endif
117#elif defined GNULIB_POSIXCHECK
118# undef getsubopt
119# define getsubopt(o,t,v) \
120 (GL_LINK_WARNING ("getsubopt is unportable - " \
121 "use gnulib module getsubopt for portability"), \
122 getsubopt (o, t, v))
123#endif
124
125
126#if @GNULIB_MKDTEMP@
127# if !@HAVE_MKDTEMP@
128/* Create a unique temporary directory from TEMPLATE.
129 The last six characters of TEMPLATE must be "XXXXXX";
130 they are replaced with a string that makes the directory name unique.
131 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
132 The directory is created mode 700. */
133extern char * mkdtemp (char * /*template*/);
134# endif
135#elif defined GNULIB_POSIXCHECK
136# undef mkdtemp
137# define mkdtemp(t) \
138 (GL_LINK_WARNING ("mkdtemp is unportable - " \
139 "use gnulib module mkdtemp for portability"), \
140 mkdtemp (t))
141#endif
142
143
144#if @GNULIB_MKSTEMP@
145# if @REPLACE_MKSTEMP@
146/* Create a unique temporary file from TEMPLATE.
147 The last six characters of TEMPLATE must be "XXXXXX";
148 they are replaced with a string that makes the file name unique.
149 The file is then created, ensuring it didn't exist before.
150 The file is created read-write (mask at least 0600 & ~umask), but it may be
151 world-readable and world-writable (mask 0666 & ~umask), depending on the
152 implementation.
153 Returns the open file descriptor if successful, otherwise -1 and errno
154 set. */
155# define mkstemp rpl_mkstemp
156extern int mkstemp (char * /*template*/);
157# else
158/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
159# include <unistd.h>
160# endif
161#elif defined GNULIB_POSIXCHECK
162# undef mkstemp
163# define mkstemp(t) \
164 (GL_LINK_WARNING ("mkstemp is unportable - " \
165 "use gnulib module mkstemp for portability"), \
166 mkstemp (t))
167#endif
168
169
170#if @GNULIB_PUTENV@
171# if @REPLACE_PUTENV@
172# undef putenv
173# define putenv rpl_putenv
174extern int putenv (char *string);
175# endif
176#endif
177
178
179#if @GNULIB_SETENV@
180# if !@HAVE_SETENV@
181/* Set NAME to VALUE in the environment.
182 If REPLACE is nonzero, overwrite an existing value. */
183extern int setenv (const char *name, const char *value, int replace);
184# endif
185#endif
186
187
188#if @GNULIB_UNSETENV@
189# if @HAVE_UNSETENV@
190# if @VOID_UNSETENV@
191/* On some systems, unsetenv() returns void.
192 This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
193# define unsetenv(name) ((unsetenv)(name), 0)
194# endif
195# else
196/* Remove the variable NAME from the environment. */
197extern int unsetenv (const char *name);
198# endif
199#endif
200
201
202#ifdef __cplusplus
203}
204#endif
205
206#endif /* _GL_STDLIB_H */
207#endif /* _GL_STDLIB_H */
208#endif
diff --git a/gl/strcase.h b/gl/strcase.h
deleted file mode 100644
index 07d4c9a..0000000
--- a/gl/strcase.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/* Case-insensitive string comparison functions.
2 Copyright (C) 1995-1996, 2001, 2003, 2005-2006 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 2, 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#ifndef _STRCASE_H
19#define _STRCASE_H
20
21#include <stddef.h>
22/* Include header files with a possibly conflicting declarations of strcasecmp
23 before we define it as a macro, so that they will be no-ops if included
24 after strcasecmp is defined as a macro. */
25#include <string.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31
32/* No known system has a strcasecmp() function that works correctly in
33 multibyte locales. Therefore we use our version always. */
34#define strcasecmp rpl_strcasecmp
35/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
36 greater than zero if S1 is lexicographically less than, equal to or greater
37 than S2.
38 Note: This function may, in multibyte locales, return 0 for strings of
39 different lengths! */
40extern int strcasecmp (const char *s1, const char *s2);
41
42/* Compare no more than N characters of strings S1 and S2, ignoring case,
43 returning less than, equal to or greater than zero if S1 is
44 lexicographically less than, equal to or greater than S2.
45 Note: This function can not work correctly in multibyte locales. */
46#if ! HAVE_DECL_STRNCASECMP
47extern int strncasecmp (const char *s1, const char *s2, size_t n);
48#endif
49
50
51#ifdef __cplusplus
52}
53#endif
54
55
56#endif /* _STRCASE_H */
diff --git a/gl/strcasecmp.c b/gl/strcasecmp.c
deleted file mode 100644
index 99d5dd2..0000000
--- a/gl/strcasecmp.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/* Case-insensitive string comparison function.
2 Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2005,
4 based on earlier glibc code.
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 2, 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
17 along 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#include <config.h>
21
22/* Specification. */
23#include "strcase.h"
24
25#include <ctype.h>
26#include <limits.h>
27
28#if HAVE_MBRTOWC
29# include "mbuiter.h"
30#endif
31
32#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
33
34/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
35 greater than zero if S1 is lexicographically less than, equal to or greater
36 than S2.
37 Note: This function may, in multibyte locales, return 0 for strings of
38 different lengths! */
39int
40strcasecmp (const char *s1, const char *s2)
41{
42 if (s1 == s2)
43 return 0;
44
45 /* Be careful not to look at the entire extent of s1 or s2 until needed.
46 This is useful because when two strings differ, the difference is
47 most often already in the very few first characters. */
48#if HAVE_MBRTOWC
49 if (MB_CUR_MAX > 1)
50 {
51 mbui_iterator_t iter1;
52 mbui_iterator_t iter2;
53
54 mbui_init (iter1, s1);
55 mbui_init (iter2, s2);
56
57 while (mbui_avail (iter1) && mbui_avail (iter2))
58 {
59 int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2));
60
61 if (cmp != 0)
62 return cmp;
63
64 mbui_advance (iter1);
65 mbui_advance (iter2);
66 }
67 if (mbui_avail (iter1))
68 /* s2 terminated before s1. */
69 return 1;
70 if (mbui_avail (iter2))
71 /* s1 terminated before s2. */
72 return -1;
73 return 0;
74 }
75 else
76#endif
77 {
78 const unsigned char *p1 = (const unsigned char *) s1;
79 const unsigned char *p2 = (const unsigned char *) s2;
80 unsigned char c1, c2;
81
82 do
83 {
84 c1 = TOLOWER (*p1);
85 c2 = TOLOWER (*p2);
86
87 if (c1 == '\0')
88 break;
89
90 ++p1;
91 ++p2;
92 }
93 while (c1 == c2);
94
95 if (UCHAR_MAX <= INT_MAX)
96 return c1 - c2;
97 else
98 /* On machines where 'char' and 'int' are types of the same size, the
99 difference of two 'unsigned char' values - including the sign bit -
100 doesn't fit in an 'int'. */
101 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
102 }
103}
diff --git a/gl/strdup.c b/gl/strdup.c
index 17d40d6..bebe5c8 100644
--- a/gl/strdup.c
+++ b/gl/strdup.c
@@ -1,11 +1,11 @@
1/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006 Free 1/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006, 2007 Free
2 Software Foundation, Inc. 2 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
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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 9 any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
@@ -19,13 +19,13 @@
19 19
20#ifndef _LIBC 20#ifndef _LIBC
21# include <config.h> 21# include <config.h>
22/* Get specification. */
23# include "strdup.h"
24#endif 22#endif
25 23
26#include <stdlib.h> 24/* Get specification. */
27#include <string.h> 25#include <string.h>
28 26
27#include <stdlib.h>
28
29#undef __strdup 29#undef __strdup
30#ifdef _LIBC 30#ifdef _LIBC
31# undef strdup 31# undef strdup
diff --git a/gl/strdup.h b/gl/strdup.h
deleted file mode 100644
index 73e66e3..0000000
--- a/gl/strdup.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/* strdup.h -- duplicate a string
2 Copyright (C) 2004, 2006 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 2, 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#ifndef STRDUP_H_
19#define STRDUP_H_
20
21/* Get strdup declaration, if available. */
22#include <string.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
29#if defined HAVE_DECL_STRDUP && !HAVE_DECL_STRDUP && !defined strdup
30/* Duplicate S, returning an identical malloc'd string. */
31extern char *strdup (const char *s);
32#endif
33
34
35#ifdef __cplusplus
36}
37#endif
38
39#endif /* STRDUP_H_ */
diff --git a/gl/strerror.c b/gl/strerror.c
new file mode 100644
index 0000000..9fe437d
--- /dev/null
+++ b/gl/strerror.c
@@ -0,0 +1,49 @@
1/* strerror.c --- POSIX compatible system error routine
2
3 Copyright (C) 2007 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20#include <string.h>
21
22#if REPLACE_STRERROR
23
24# include <stdio.h>
25
26# include "intprops.h"
27
28# undef strerror
29# if ! HAVE_DECL_STRERROR
30# define strerror(n) NULL
31# endif
32
33char *
34rpl_strerror (int n)
35{
36 char *result = strerror (n);
37
38 if (result == NULL || result[0] == '\0')
39 {
40 static char const fmt[] = "Unknown error (%d)";
41 static char mesg[sizeof fmt + INT_STRLEN_BOUND (n)];
42 sprintf (mesg, fmt, n);
43 return mesg;
44 }
45
46 return result;
47}
48
49#endif
diff --git a/gl/string.in.h b/gl/string.in.h
new file mode 100644
index 0000000..5c7597c
--- /dev/null
+++ b/gl/string.in.h
@@ -0,0 +1,569 @@
1/* A GNU-like <string.h>.
2
3 Copyright (C) 1995-1996, 2001-2008 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#ifndef _GL_STRING_H
20
21/* The include_next requires a split double-inclusion guard. */
22#@INCLUDE_NEXT@ @NEXT_STRING_H@
23
24#ifndef _GL_STRING_H
25#define _GL_STRING_H
26
27
28#ifndef __attribute__
29/* This feature is available in gcc versions 2.5 and later. */
30# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
31# define __attribute__(Spec) /* empty */
32# endif
33/* The attribute __pure__ was added in gcc 2.96. */
34# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
35# define __pure__ /* empty */
36# endif
37#endif
38
39
40/* The definition of GL_LINK_WARNING is copied here. */
41
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47
48/* Return the first occurrence of NEEDLE in HAYSTACK. */
49#if @GNULIB_MEMMEM@
50# if @REPLACE_MEMMEM@
51# define memmem rpl_memmem
52# endif
53# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
54extern void *memmem (void const *__haystack, size_t __haystack_len,
55 void const *__needle, size_t __needle_len)
56 __attribute__ ((__pure__));
57# endif
58#elif defined GNULIB_POSIXCHECK
59# undef memmem
60# define memmem(a,al,b,bl) \
61 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
62 "use gnulib module memmem-simple for portability, " \
63 "and module memmem for speed" ), \
64 memmem (a, al, b, bl))
65#endif
66
67/* Copy N bytes of SRC to DEST, return pointer to bytes after the
68 last written byte. */
69#if @GNULIB_MEMPCPY@
70# if ! @HAVE_MEMPCPY@
71extern void *mempcpy (void *restrict __dest, void const *restrict __src,
72 size_t __n);
73# endif
74#elif defined GNULIB_POSIXCHECK
75# undef mempcpy
76# define mempcpy(a,b,n) \
77 (GL_LINK_WARNING ("mempcpy is unportable - " \
78 "use gnulib module mempcpy for portability"), \
79 mempcpy (a, b, n))
80#endif
81
82/* Search backwards through a block for a byte (specified as an int). */
83#if @GNULIB_MEMRCHR@
84# if ! @HAVE_DECL_MEMRCHR@
85extern void *memrchr (void const *, int, size_t)
86 __attribute__ ((__pure__));
87# endif
88#elif defined GNULIB_POSIXCHECK
89# undef memrchr
90# define memrchr(a,b,c) \
91 (GL_LINK_WARNING ("memrchr is unportable - " \
92 "use gnulib module memrchr for portability"), \
93 memrchr (a, b, c))
94#endif
95
96/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
97#if @GNULIB_STPCPY@
98# if ! @HAVE_STPCPY@
99extern char *stpcpy (char *restrict __dst, char const *restrict __src);
100# endif
101#elif defined GNULIB_POSIXCHECK
102# undef stpcpy
103# define stpcpy(a,b) \
104 (GL_LINK_WARNING ("stpcpy is unportable - " \
105 "use gnulib module stpcpy for portability"), \
106 stpcpy (a, b))
107#endif
108
109/* Copy no more than N bytes of SRC to DST, returning a pointer past the
110 last non-NUL byte written into DST. */
111#if @GNULIB_STPNCPY@
112# if ! @HAVE_STPNCPY@
113# define stpncpy gnu_stpncpy
114extern char *stpncpy (char *restrict __dst, char const *restrict __src,
115 size_t __n);
116# endif
117#elif defined GNULIB_POSIXCHECK
118# undef stpncpy
119# define stpncpy(a,b,n) \
120 (GL_LINK_WARNING ("stpncpy is unportable - " \
121 "use gnulib module stpncpy for portability"), \
122 stpncpy (a, b, n))
123#endif
124
125#if defined GNULIB_POSIXCHECK
126/* strchr() does not work with multibyte strings if the locale encoding is
127 GB18030 and the character to be searched is a digit. */
128# undef strchr
129# define strchr(s,c) \
130 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
131 "in some multibyte locales - " \
132 "use mbschr if you care about internationalization"), \
133 strchr (s, c))
134#endif
135
136/* Find the first occurrence of C in S or the final NUL byte. */
137#if @GNULIB_STRCHRNUL@
138# if ! @HAVE_STRCHRNUL@
139extern char *strchrnul (char const *__s, int __c_in)
140 __attribute__ ((__pure__));
141# endif
142#elif defined GNULIB_POSIXCHECK
143# undef strchrnul
144# define strchrnul(a,b) \
145 (GL_LINK_WARNING ("strchrnul is unportable - " \
146 "use gnulib module strchrnul for portability"), \
147 strchrnul (a, b))
148#endif
149
150/* Duplicate S, returning an identical malloc'd string. */
151#if @GNULIB_STRDUP@
152# if ! @HAVE_DECL_STRDUP@ && ! defined strdup
153extern char *strdup (char const *__s);
154# endif
155#elif defined GNULIB_POSIXCHECK
156# undef strdup
157# define strdup(a) \
158 (GL_LINK_WARNING ("strdup is unportable - " \
159 "use gnulib module strdup for portability"), \
160 strdup (a))
161#endif
162
163/* Return a newly allocated copy of at most N bytes of STRING. */
164#if @GNULIB_STRNDUP@
165# if ! @HAVE_STRNDUP@
166# undef strndup
167# define strndup rpl_strndup
168# endif
169# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
170extern char *strndup (char const *__string, size_t __n);
171# endif
172#elif defined GNULIB_POSIXCHECK
173# undef strndup
174# define strndup(a,n) \
175 (GL_LINK_WARNING ("strndup is unportable - " \
176 "use gnulib module strndup for portability"), \
177 strndup (a, n))
178#endif
179
180/* Find the length (number of bytes) of STRING, but scan at most
181 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
182 return MAXLEN. */
183#if @GNULIB_STRNLEN@
184# if ! @HAVE_DECL_STRNLEN@
185extern size_t strnlen (char const *__string, size_t __maxlen)
186 __attribute__ ((__pure__));
187# endif
188#elif defined GNULIB_POSIXCHECK
189# undef strnlen
190# define strnlen(a,n) \
191 (GL_LINK_WARNING ("strnlen is unportable - " \
192 "use gnulib module strnlen for portability"), \
193 strnlen (a, n))
194#endif
195
196#if defined GNULIB_POSIXCHECK
197/* strcspn() assumes the second argument is a list of single-byte characters.
198 Even in this simple case, it does not work with multibyte strings if the
199 locale encoding is GB18030 and one of the characters to be searched is a
200 digit. */
201# undef strcspn
202# define strcspn(s,a) \
203 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
204 "in multibyte locales - " \
205 "use mbscspn if you care about internationalization"), \
206 strcspn (s, a))
207#endif
208
209/* Find the first occurrence in S of any character in ACCEPT. */
210#if @GNULIB_STRPBRK@
211# if ! @HAVE_STRPBRK@
212extern char *strpbrk (char const *__s, char const *__accept)
213 __attribute__ ((__pure__));
214# endif
215# if defined GNULIB_POSIXCHECK
216/* strpbrk() assumes the second argument is a list of single-byte characters.
217 Even in this simple case, it does not work with multibyte strings if the
218 locale encoding is GB18030 and one of the characters to be searched is a
219 digit. */
220# undef strpbrk
221# define strpbrk(s,a) \
222 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
223 "in multibyte locales - " \
224 "use mbspbrk if you care about internationalization"), \
225 strpbrk (s, a))
226# endif
227#elif defined GNULIB_POSIXCHECK
228# undef strpbrk
229# define strpbrk(s,a) \
230 (GL_LINK_WARNING ("strpbrk is unportable - " \
231 "use gnulib module strpbrk for portability"), \
232 strpbrk (s, a))
233#endif
234
235#if defined GNULIB_POSIXCHECK
236/* strspn() assumes the second argument is a list of single-byte characters.
237 Even in this simple case, it cannot work with multibyte strings. */
238# undef strspn
239# define strspn(s,a) \
240 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
241 "in multibyte locales - " \
242 "use mbsspn if you care about internationalization"), \
243 strspn (s, a))
244#endif
245
246#if defined GNULIB_POSIXCHECK
247/* strrchr() does not work with multibyte strings if the locale encoding is
248 GB18030 and the character to be searched is a digit. */
249# undef strrchr
250# define strrchr(s,c) \
251 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
252 "in some multibyte locales - " \
253 "use mbsrchr if you care about internationalization"), \
254 strrchr (s, c))
255#endif
256
257/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
258 If one is found, overwrite it with a NUL, and advance *STRINGP
259 to point to the next char after it. Otherwise, set *STRINGP to NULL.
260 If *STRINGP was already NULL, nothing happens.
261 Return the old value of *STRINGP.
262
263 This is a variant of strtok() that is multithread-safe and supports
264 empty fields.
265
266 Caveat: It modifies the original string.
267 Caveat: These functions cannot be used on constant strings.
268 Caveat: The identity of the delimiting character is lost.
269 Caveat: It doesn't work with multibyte strings unless all of the delimiter
270 characters are ASCII characters < 0x30.
271
272 See also strtok_r(). */
273#if @GNULIB_STRSEP@
274# if ! @HAVE_STRSEP@
275extern char *strsep (char **restrict __stringp, char const *restrict __delim);
276# endif
277# if defined GNULIB_POSIXCHECK
278# undef strsep
279# define strsep(s,d) \
280 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
281 "in multibyte locales - " \
282 "use mbssep if you care about internationalization"), \
283 strsep (s, d))
284# endif
285#elif defined GNULIB_POSIXCHECK
286# undef strsep
287# define strsep(s,d) \
288 (GL_LINK_WARNING ("strsep is unportable - " \
289 "use gnulib module strsep for portability"), \
290 strsep (s, d))
291#endif
292
293#if @GNULIB_STRSTR@
294# if @REPLACE_STRSTR@
295# define strstr rpl_strstr
296char *strstr (const char *haystack, const char *needle)
297 __attribute__ ((__pure__));
298# endif
299#elif defined GNULIB_POSIXCHECK
300/* strstr() does not work with multibyte strings if the locale encoding is
301 different from UTF-8:
302 POSIX says that it operates on "strings", and "string" in POSIX is defined
303 as a sequence of bytes, not of characters. */
304# undef strstr
305# define strstr(a,b) \
306 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
307 "work correctly on character strings in most " \
308 "multibyte locales - " \
309 "use mbsstr if you care about internationalization, " \
310 "or use strstr if you care about speed"), \
311 strstr (a, b))
312#endif
313
314/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
315 comparison. */
316#if @GNULIB_STRCASESTR@
317# if @REPLACE_STRCASESTR@
318# define strcasestr rpl_strcasestr
319# endif
320# if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
321extern char *strcasestr (const char *haystack, const char *needle)
322 __attribute__ ((__pure__));
323# endif
324#elif defined GNULIB_POSIXCHECK
325/* strcasestr() does not work with multibyte strings:
326 It is a glibc extension, and glibc implements it only for unibyte
327 locales. */
328# undef strcasestr
329# define strcasestr(a,b) \
330 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
331 "in multibyte locales - " \
332 "use mbscasestr if you care about " \
333 "internationalization, or use c-strcasestr if you want " \
334 "a locale independent function"), \
335 strcasestr (a, b))
336#endif
337
338/* Parse S into tokens separated by characters in DELIM.
339 If S is NULL, the saved pointer in SAVE_PTR is used as
340 the next starting point. For example:
341 char s[] = "-abc-=-def";
342 char *sp;
343 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
344 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
345 x = strtok_r(NULL, "=", &sp); // x = NULL
346 // s = "abc\0-def\0"
347
348 This is a variant of strtok() that is multithread-safe.
349
350 For the POSIX documentation for this function, see:
351 http://www.opengroup.org/susv3xsh/strtok.html
352
353 Caveat: It modifies the original string.
354 Caveat: These functions cannot be used on constant strings.
355 Caveat: The identity of the delimiting character is lost.
356 Caveat: It doesn't work with multibyte strings unless all of the delimiter
357 characters are ASCII characters < 0x30.
358
359 See also strsep(). */
360#if @GNULIB_STRTOK_R@
361# if ! @HAVE_DECL_STRTOK_R@
362extern char *strtok_r (char *restrict s, char const *restrict delim,
363 char **restrict save_ptr);
364# endif
365# if defined GNULIB_POSIXCHECK
366# undef strtok_r
367# define strtok_r(s,d,p) \
368 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
369 "in multibyte locales - " \
370 "use mbstok_r if you care about internationalization"), \
371 strtok_r (s, d, p))
372# endif
373#elif defined GNULIB_POSIXCHECK
374# undef strtok_r
375# define strtok_r(s,d,p) \
376 (GL_LINK_WARNING ("strtok_r is unportable - " \
377 "use gnulib module strtok_r for portability"), \
378 strtok_r (s, d, p))
379#endif
380
381
382/* The following functions are not specified by POSIX. They are gnulib
383 extensions. */
384
385#if @GNULIB_MBSLEN@
386/* Return the number of multibyte characters in the character string STRING.
387 This considers multibyte characters, unlike strlen, which counts bytes. */
388extern size_t mbslen (const char *string);
389#endif
390
391#if @GNULIB_MBSNLEN@
392/* Return the number of multibyte characters in the character string starting
393 at STRING and ending at STRING + LEN. */
394extern size_t mbsnlen (const char *string, size_t len);
395#endif
396
397#if @GNULIB_MBSCHR@
398/* Locate the first single-byte character C in the character string STRING,
399 and return a pointer to it. Return NULL if C is not found in STRING.
400 Unlike strchr(), this function works correctly in multibyte locales with
401 encodings such as GB18030. */
402# define mbschr rpl_mbschr /* avoid collision with HP-UX function */
403extern char * mbschr (const char *string, int c);
404#endif
405
406#if @GNULIB_MBSRCHR@
407/* Locate the last single-byte character C in the character string STRING,
408 and return a pointer to it. Return NULL if C is not found in STRING.
409 Unlike strrchr(), this function works correctly in multibyte locales with
410 encodings such as GB18030. */
411# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
412extern char * mbsrchr (const char *string, int c);
413#endif
414
415#if @GNULIB_MBSSTR@
416/* Find the first occurrence of the character string NEEDLE in the character
417 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
418 Unlike strstr(), this function works correctly in multibyte locales with
419 encodings different from UTF-8. */
420extern char * mbsstr (const char *haystack, const char *needle);
421#endif
422
423#if @GNULIB_MBSCASECMP@
424/* Compare the character strings S1 and S2, ignoring case, returning less than,
425 equal to or greater than zero if S1 is lexicographically less than, equal to
426 or greater than S2.
427 Note: This function may, in multibyte locales, return 0 for strings of
428 different lengths!
429 Unlike strcasecmp(), this function works correctly in multibyte locales. */
430extern int mbscasecmp (const char *s1, const char *s2);
431#endif
432
433#if @GNULIB_MBSNCASECMP@
434/* Compare the initial segment of the character string S1 consisting of at most
435 N characters with the initial segment of the character string S2 consisting
436 of at most N characters, ignoring case, returning less than, equal to or
437 greater than zero if the initial segment of S1 is lexicographically less
438 than, equal to or greater than the initial segment of S2.
439 Note: This function may, in multibyte locales, return 0 for initial segments
440 of different lengths!
441 Unlike strncasecmp(), this function works correctly in multibyte locales.
442 But beware that N is not a byte count but a character count! */
443extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
444#endif
445
446#if @GNULIB_MBSPCASECMP@
447/* Compare the initial segment of the character string STRING consisting of
448 at most mbslen (PREFIX) characters with the character string PREFIX,
449 ignoring case, returning less than, equal to or greater than zero if this
450 initial segment is lexicographically less than, equal to or greater than
451 PREFIX.
452 Note: This function may, in multibyte locales, return 0 if STRING is of
453 smaller length than PREFIX!
454 Unlike strncasecmp(), this function works correctly in multibyte
455 locales. */
456extern char * mbspcasecmp (const char *string, const char *prefix);
457#endif
458
459#if @GNULIB_MBSCASESTR@
460/* Find the first occurrence of the character string NEEDLE in the character
461 string HAYSTACK, using case-insensitive comparison.
462 Note: This function may, in multibyte locales, return success even if
463 strlen (haystack) < strlen (needle) !
464 Unlike strcasestr(), this function works correctly in multibyte locales. */
465extern char * mbscasestr (const char *haystack, const char *needle);
466#endif
467
468#if @GNULIB_MBSCSPN@
469/* Find the first occurrence in the character string STRING of any character
470 in the character string ACCEPT. Return the number of bytes from the
471 beginning of the string to this occurrence, or to the end of the string
472 if none exists.
473 Unlike strcspn(), this function works correctly in multibyte locales. */
474extern size_t mbscspn (const char *string, const char *accept);
475#endif
476
477#if @GNULIB_MBSPBRK@
478/* Find the first occurrence in the character string STRING of any character
479 in the character string ACCEPT. Return the pointer to it, or NULL if none
480 exists.
481 Unlike strpbrk(), this function works correctly in multibyte locales. */
482# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
483extern char * mbspbrk (const char *string, const char *accept);
484#endif
485
486#if @GNULIB_MBSSPN@
487/* Find the first occurrence in the character string STRING of any character
488 not in the character string REJECT. Return the number of bytes from the
489 beginning of the string to this occurrence, or to the end of the string
490 if none exists.
491 Unlike strspn(), this function works correctly in multibyte locales. */
492extern size_t mbsspn (const char *string, const char *reject);
493#endif
494
495#if @GNULIB_MBSSEP@
496/* Search the next delimiter (multibyte character listed in the character
497 string DELIM) starting at the character string *STRINGP.
498 If one is found, overwrite it with a NUL, and advance *STRINGP to point
499 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
500 If *STRINGP was already NULL, nothing happens.
501 Return the old value of *STRINGP.
502
503 This is a variant of mbstok_r() that supports empty fields.
504
505 Caveat: It modifies the original string.
506 Caveat: These functions cannot be used on constant strings.
507 Caveat: The identity of the delimiting character is lost.
508
509 See also mbstok_r(). */
510extern char * mbssep (char **stringp, const char *delim);
511#endif
512
513#if @GNULIB_MBSTOK_R@
514/* Parse the character string STRING into tokens separated by characters in
515 the character string DELIM.
516 If STRING is NULL, the saved pointer in SAVE_PTR is used as
517 the next starting point. For example:
518 char s[] = "-abc-=-def";
519 char *sp;
520 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
521 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
522 x = mbstok_r(NULL, "=", &sp); // x = NULL
523 // s = "abc\0-def\0"
524
525 Caveat: It modifies the original string.
526 Caveat: These functions cannot be used on constant strings.
527 Caveat: The identity of the delimiting character is lost.
528
529 See also mbssep(). */
530extern char * mbstok_r (char *string, const char *delim, char **save_ptr);
531#endif
532
533/* Map any int, typically from errno, into an error message. */
534#if @GNULIB_STRERROR@
535# if @REPLACE_STRERROR@
536# undef strerror
537# define strerror rpl_strerror
538extern char *strerror (int);
539# endif
540#elif defined GNULIB_POSIXCHECK
541# undef strerror
542# define strerror(e) \
543 (GL_LINK_WARNING ("strerror is unportable - " \
544 "use gnulib module strerror to guarantee non-NULL result"), \
545 strerror (e))
546#endif
547
548#if @GNULIB_STRSIGNAL@
549# if @REPLACE_STRSIGNAL@
550# define strsignal rpl_strsignal
551# endif
552# if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
553extern char *strsignal (int __sig);
554# endif
555#elif defined GNULIB_POSIXCHECK
556# undef strsignal
557# define strsignal(a) \
558 (GL_LINK_WARNING ("strsignal is unportable - " \
559 "use gnulib module strsignal for portability"), \
560 strsignal (a))
561#endif
562
563
564#ifdef __cplusplus
565}
566#endif
567
568#endif /* _GL_STRING_H */
569#endif /* _GL_STRING_H */
diff --git a/gl/stripslash.c b/gl/stripslash.c
index 342d497..4084410 100644
--- a/gl/stripslash.c
+++ b/gl/stripslash.c
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc. 3 Copyright (C) 1990, 2001, 2003-2006 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19#include <config.h> 18#include <config.h>
20 19
diff --git a/gl/strncasecmp.c b/gl/strncasecmp.c
deleted file mode 100644
index f59b953..0000000
--- a/gl/strncasecmp.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/* strncasecmp.c -- case insensitive string comparator
2 Copyright (C) 1998-1999, 2005-2006 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 2, 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#include <config.h>
19
20/* Specification. */
21#include "strcase.h"
22
23#include <ctype.h>
24#include <limits.h>
25
26#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
27
28/* Compare no more than N bytes of strings S1 and S2,
29 ignoring case, returning less than, equal to or
30 greater than zero if S1 is lexicographically less
31 than, equal to or greater than S2. */
32
33int
34strncasecmp (const char *s1, const char *s2, size_t n)
35{
36 register const unsigned char *p1 = (const unsigned char *) s1;
37 register const unsigned char *p2 = (const unsigned char *) s2;
38 unsigned char c1, c2;
39
40 if (p1 == p2 || n == 0)
41 return 0;
42
43 do
44 {
45 c1 = TOLOWER (*p1);
46 c2 = TOLOWER (*p2);
47
48 if (--n == 0 || c1 == '\0')
49 break;
50
51 ++p1;
52 ++p2;
53 }
54 while (c1 == c2);
55
56 if (UCHAR_MAX <= INT_MAX)
57 return c1 - c2;
58 else
59 /* On machines where 'char' and 'int' are types of the same size, the
60 difference of two 'unsigned char' values - including the sign bit -
61 doesn't fit in an 'int'. */
62 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
63}
diff --git a/gl/strndup.c b/gl/strndup.c
index 290f494..507e9c0 100644
--- a/gl/strndup.c
+++ b/gl/strndup.c
@@ -1,11 +1,11 @@
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 Free 3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
4 Software Foundation, Inc. 4 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
8 Free Software Foundation; either version 2, or (at your option) any 8 Free Software Foundation; either version 3, or (at your option) any
9 later version. 9 later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
@@ -18,12 +18,10 @@
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 19
20#include <config.h> 20#include <config.h>
21#include "strndup.h"
22 21
23#include <stdlib.h>
24#include <string.h> 22#include <string.h>
25 23
26#include "strnlen.h" 24#include <stdlib.h>
27 25
28char * 26char *
29strndup (char const *s, size_t n) 27strndup (char const *s, size_t n)
diff --git a/gl/strndup.h b/gl/strndup.h
deleted file mode 100644
index b983dd2..0000000
--- a/gl/strndup.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* Duplicate a size-bounded string.
2 Copyright (C) 2003, 2006 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 2, 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/* Get size_t. */
19#include <stddef.h>
20/* If HAVE_STRNDUP, get the strndup declaration.
21 If !HAVE_STRNDUP, include <string.h> now so that it doesn't cause
22 trouble if included later. */
23#include <string.h>
24
25#if !HAVE_STRNDUP
26# undef strndup
27# define strndup rpl_strndup
28# if !HAVE_DECL_STRNDUP /* Don't risk conflicting declarations. */
29/* Return a newly allocated copy of at most N bytes of STRING. */
30extern char *strndup (const char *string, size_t n);
31# endif
32#endif
diff --git a/gl/strnlen.c b/gl/strnlen.c
index 593fd1b..93d1ac1 100644
--- a/gl/strnlen.c
+++ b/gl/strnlen.c
@@ -1,10 +1,10 @@
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 Free Software Foundation, Inc. 2 Copyright (C) 2005, 2006, 2007 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
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -18,7 +18,7 @@
18 18
19#include <config.h> 19#include <config.h>
20 20
21#include "strnlen.h" 21#include <string.h>
22 22
23/* Find the length of STRING, but scan at most MAXLEN characters. 23/* Find the length of STRING, but scan at most MAXLEN characters.
24 If no '\0' terminator is found in that many characters, return MAXLEN. */ 24 If no '\0' terminator is found in that many characters, return MAXLEN. */
diff --git a/gl/strnlen.h b/gl/strnlen.h
deleted file mode 100644
index ba74dba..0000000
--- a/gl/strnlen.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* Find the length of STRING, but scan at most MAXLEN characters.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
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 2, 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#ifndef STRNLEN_H
20#define STRNLEN_H
21
22/* Get strnlen declaration, if available. */
23#include <string.h>
24
25#if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
26/* Find the length (number of bytes) of STRING, but scan at most
27 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
28 return MAXLEN. */
29extern size_t strnlen(const char *string, size_t maxlen);
30#endif
31
32#endif /* STRNLEN_H */
diff --git a/gl/strnlen1.c b/gl/strnlen1.c
deleted file mode 100644
index 422ed9e..0000000
--- a/gl/strnlen1.c
+++ /dev/null
@@ -1,36 +0,0 @@
1/* Find the length of STRING + 1, but scan at most MAXLEN bytes.
2 Copyright (C) 2005-2006 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 2, 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#include <config.h>
19
20/* Specification. */
21#include "strnlen1.h"
22
23#include <string.h>
24
25/* Find the length of STRING + 1, but scan at most MAXLEN bytes.
26 If no '\0' terminator is found in that many characters, return MAXLEN. */
27/* This is the same as strnlen (string, maxlen - 1) + 1. */
28size_t
29strnlen1 (const char *string, size_t maxlen)
30{
31 const char *end = (const char *) memchr (string, '\0', maxlen);
32 if (end != NULL)
33 return end - string + 1;
34 else
35 return maxlen;
36}
diff --git a/gl/socket_.h b/gl/sys_socket.in.h
index 8b28b5e..5e0b097 100644
--- a/gl/socket_.h
+++ b/gl/sys_socket.in.h
@@ -1,10 +1,10 @@
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 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2005, 2006, 2007 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
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -16,12 +16,30 @@
16 along with this program; if not, write to the Free Software Foundation, 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. */ 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 18
19#ifndef _SYS_SOCKET_H 19/* This file is supposed to be used on platforms that lack <sys/socket.h>
20#define _SYS_SOCKET_H 20 and on platforms where <sys/socket.h> cannot be included standalone.
21 It is intended to provide definitions and prototypes needed by an
22 application. */
21 23
22/* This file is supposed to be used on platforms that lack 24#ifndef _GL_SYS_SOCKET_H
23 sys/socket.h. It is intended to provide definitions and prototypes 25
24 needed by an application. 26#if @HAVE_SYS_SOCKET_H@
27
28/* On many platforms, <sys/socket.h> assumes prior inclusion of
29 <sys/types.h>. */
30# include <sys/types.h>
31
32/* The include_next requires a split double-inclusion guard. */
33# @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
34
35#endif
36
37#ifndef _GL_SYS_SOCKET_H
38#define _GL_SYS_SOCKET_H
39
40#if !@HAVE_SYS_SOCKET_H@
41
42/* A platform that lacks <sys/socket.h>.
25 43
26 Currently only MinGW is supported. See the gnulib manual regarding 44 Currently only MinGW is supported. See the gnulib manual regarding
27 Windows sockets. MinGW has the header files winsock2.h and 45 Windows sockets. MinGW has the header files winsock2.h and
@@ -39,32 +57,35 @@
39 releases. */ 57 releases. */
40 58
41 59
42#if HAVE_WINSOCK2_H 60# if @HAVE_WINSOCK2_H@
43# include <winsock2.h> 61# include <winsock2.h>
44#endif 62# endif
45#if HAVE_WS2TCPIP_H 63# if @HAVE_WS2TCPIP_H@
46# include <ws2tcpip.h> 64# include <ws2tcpip.h>
47#endif 65# endif
48 66
49/* For shutdown(). */ 67/* For shutdown(). */
50#if !defined SHUT_RD && defined SD_RECEIVE 68# if !defined SHUT_RD && defined SD_RECEIVE
51# define SHUT_RD SD_RECEIVE 69# define SHUT_RD SD_RECEIVE
52#endif 70# endif
53#if !defined SHUT_WR && defined SD_SEND 71# if !defined SHUT_WR && defined SD_SEND
54# define SHUT_WR SD_SEND 72# define SHUT_WR SD_SEND
55#endif 73# endif
56#if !defined SHUT_RDWR && defined SD_BOTH 74# if !defined SHUT_RDWR && defined SD_BOTH
57# define SHUT_RDWR SD_BOTH 75# define SHUT_RDWR SD_BOTH
58#endif 76# endif
59 77
60#if defined _WIN32 || defined __WIN32__ 78# if defined _WIN32 || defined __WIN32__
61# define ENOTSOCK WSAENOTSOCK 79# define ENOTSOCK WSAENOTSOCK
62# define EADDRINUSE WSAEADDRINUSE 80# define EADDRINUSE WSAEADDRINUSE
63# define ENETRESET WSAENETRESET 81# define ENETRESET WSAENETRESET
64# define ECONNABORTED WSAECONNABORTED 82# define ECONNABORTED WSAECONNABORTED
65# define ECONNRESET WSAECONNRESET 83# define ECONNRESET WSAECONNRESET
66# define ENOTCONN WSAENOTCONN 84# define ENOTCONN WSAENOTCONN
67# define ESHUTDOWN WSAESHUTDOWN 85# define ESHUTDOWN WSAESHUTDOWN
68#endif 86# endif
87
88#endif /* HAVE_SYS_SOCKET_H */
69 89
70#endif /* _SYS_SOCKET_H */ 90#endif /* _GL_SYS_SOCKET_H */
91#endif /* _GL_SYS_SOCKET_H */
diff --git a/gl/unistd--.h b/gl/unistd--.h
index 1fe6ce8..1a7fd78 100644
--- a/gl/unistd--.h
+++ b/gl/unistd--.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2005 Free Software Foundation, Inc. 3 Copyright (C) 2005 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/unistd-safer.h b/gl/unistd-safer.h
index f95999d..033e857 100644
--- a/gl/unistd-safer.h
+++ b/gl/unistd-safer.h
@@ -2,10 +2,10 @@
2 2
3 Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. 3 Copyright (C) 2001, 2003, 2005 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
20 19
diff --git a/gl/unistd.in.h b/gl/unistd.in.h
new file mode 100644
index 0000000..a5dc04c
--- /dev/null
+++ b/gl/unistd.in.h
@@ -0,0 +1,320 @@
1/* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2004-2007 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#ifndef _GL_UNISTD_H
19
20/* The include_next requires a split double-inclusion guard. */
21#if @HAVE_UNISTD_H@
22# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
23#endif
24
25#ifndef _GL_UNISTD_H
26#define _GL_UNISTD_H
27
28/* mingw doesn't define the SEEK_* macros in <unistd.h>. */
29#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
30# include <stdio.h>
31#endif
32
33/* mingw fails to declare _exit in <unistd.h>. */
34#include <stdlib.h>
35
36/* The definition of GL_LINK_WARNING is copied here. */
37
38
39/* Declare overridden functions. */
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45
46#if @GNULIB_CHOWN@
47# if @REPLACE_CHOWN@
48# ifndef REPLACE_CHOWN
49# define REPLACE_CHOWN 1
50# endif
51# if REPLACE_CHOWN
52/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
53 to GID (if GID is not -1). Follow symbolic links.
54 Return 0 if successful, otherwise -1 and errno set.
55 See the POSIX:2001 specification
56 <http://www.opengroup.org/susv3xsh/chown.html>. */
57# define chown rpl_chown
58extern int chown (const char *file, uid_t uid, gid_t gid);
59# endif
60# endif
61#elif defined GNULIB_POSIXCHECK
62# undef chown
63# define chown(f,u,g) \
64 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
65 "doesn't treat a uid or gid of -1 on some systems - " \
66 "use gnulib module chown for portability"), \
67 chown (f, u, g))
68#endif
69
70
71#if @GNULIB_DUP2@
72# if !@HAVE_DUP2@
73/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
74 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
75 Return 0 if successful, otherwise -1 and errno set.
76 See the POSIX:2001 specification
77 <http://www.opengroup.org/susv3xsh/dup2.html>. */
78extern int dup2 (int oldfd, int newfd);
79# endif
80#elif defined GNULIB_POSIXCHECK
81# undef dup2
82# define dup2(o,n) \
83 (GL_LINK_WARNING ("dup2 is unportable - " \
84 "use gnulib module dup2 for portability"), \
85 dup2 (o, n))
86#endif
87
88
89#if @GNULIB_FCHDIR@
90# if @REPLACE_FCHDIR@
91
92/* Change the process' current working directory to the directory on which
93 the given file descriptor is open.
94 Return 0 if successful, otherwise -1 and errno set.
95 See the POSIX:2001 specification
96 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
97extern int fchdir (int /*fd*/);
98
99# define close rpl_close
100extern int close (int);
101# define dup rpl_dup
102extern int dup (int);
103# define dup2 rpl_dup2
104extern int dup2 (int, int);
105
106# endif
107#elif defined GNULIB_POSIXCHECK
108# undef fchdir
109# define fchdir(f) \
110 (GL_LINK_WARNING ("fchdir is unportable - " \
111 "use gnulib module fchdir for portability"), \
112 fchdir (f))
113#endif
114
115
116#if @GNULIB_FTRUNCATE@
117# if !@HAVE_FTRUNCATE@
118/* Change the size of the file to which FD is opened to become equal to LENGTH.
119 Return 0 if successful, otherwise -1 and errno set.
120 See the POSIX:2001 specification
121 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
122extern int ftruncate (int fd, off_t length);
123# endif
124#elif defined GNULIB_POSIXCHECK
125# undef ftruncate
126# define ftruncate(f,l) \
127 (GL_LINK_WARNING ("ftruncate is unportable - " \
128 "use gnulib module ftruncate for portability"), \
129 ftruncate (f, l))
130#endif
131
132
133#if @GNULIB_GETCWD@
134/* Include the headers that might declare getcwd so that they will not
135 cause confusion if included after this file. */
136# include <stdlib.h>
137# if @REPLACE_GETCWD@
138/* Get the name of the current working directory, and put it in SIZE bytes
139 of BUF.
140 Return BUF if successful, or NULL if the directory couldn't be determined
141 or SIZE was too small.
142 See the POSIX:2001 specification
143 <http://www.opengroup.org/susv3xsh/getcwd.html>.
144 Additionally, the gnulib module 'getcwd' guarantees the following GNU
145 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
146 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
147 necessary. */
148# define getcwd rpl_getcwd
149extern char * getcwd (char *buf, size_t size);
150# endif
151#elif defined GNULIB_POSIXCHECK
152# undef getcwd
153# define getcwd(b,s) \
154 (GL_LINK_WARNING ("getcwd is unportable - " \
155 "use gnulib module getcwd for portability"), \
156 getcwd (b, s))
157#endif
158
159
160#if @GNULIB_GETLOGIN_R@
161/* Copies the user's login name to NAME.
162 The array pointed to by NAME has room for SIZE bytes.
163
164 Returns 0 if successful. Upon error, an error number is returned, or -1 in
165 the case that the login name cannot be found but no specific error is
166 provided (this case is hopefully rare but is left open by the POSIX spec).
167
168 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
169 */
170# if !@HAVE_DECL_GETLOGIN_R@
171# include <stddef.h>
172extern int getlogin_r (char *name, size_t size);
173# endif
174#elif defined GNULIB_POSIXCHECK
175# undef getlogin_r
176# define getlogin_r(n,s) \
177 (GL_LINK_WARNING ("getlogin_r is unportable - " \
178 "use gnulib module getlogin_r for portability"), \
179 getlogin_r (n, s))
180#endif
181
182
183#if @GNULIB_GETPAGESIZE@
184# if @REPLACE_GETPAGESIZE@
185# define getpagesize rpl_getpagesize
186extern int getpagesize (void);
187# elif !@HAVE_GETPAGESIZE@
188/* This is for POSIX systems. */
189# if !defined getpagesize && defined _SC_PAGESIZE
190# if ! (defined __VMS && __VMS_VER < 70000000)
191# define getpagesize() sysconf (_SC_PAGESIZE)
192# endif
193# endif
194/* This is for older VMS. */
195# if !defined getpagesize && defined __VMS
196# ifdef __ALPHA
197# define getpagesize() 8192
198# else
199# define getpagesize() 512
200# endif
201# endif
202/* This is for BeOS. */
203# if !defined getpagesize && @HAVE_OS_H@
204# include <OS.h>
205# if defined B_PAGE_SIZE
206# define getpagesize() B_PAGE_SIZE
207# endif
208# endif
209/* This is for AmigaOS4.0. */
210# if !defined getpagesize && defined __amigaos4__
211# define getpagesize() 2048
212# endif
213/* This is for older Unix systems. */
214# if !defined getpagesize && @HAVE_SYS_PARAM_H@
215# include <sys/param.h>
216# ifdef EXEC_PAGESIZE
217# define getpagesize() EXEC_PAGESIZE
218# else
219# ifdef NBPG
220# ifndef CLSIZE
221# define CLSIZE 1
222# endif
223# define getpagesize() (NBPG * CLSIZE)
224# else
225# ifdef NBPC
226# define getpagesize() NBPC
227# endif
228# endif
229# endif
230# endif
231# endif
232#elif defined GNULIB_POSIXCHECK
233# undef getpagesize
234# define getpagesize() \
235 (GL_LINK_WARNING ("getpagesize is unportable - " \
236 "use gnulib module getpagesize for portability"), \
237 getpagesize ())
238#endif
239
240
241#if @GNULIB_LCHOWN@
242# if @REPLACE_LCHOWN@
243/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
244 to GID (if GID is not -1). Do not follow symbolic links.
245 Return 0 if successful, otherwise -1 and errno set.
246 See the POSIX:2001 specification
247 <http://www.opengroup.org/susv3xsh/lchown.html>. */
248# define lchown rpl_lchown
249extern int lchown (char const *file, uid_t owner, gid_t group);
250# endif
251#elif defined GNULIB_POSIXCHECK
252# undef lchown
253# define lchown(f,u,g) \
254 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
255 "systems - use gnulib module lchown for portability"), \
256 lchown (f, u, g))
257#endif
258
259
260#if @GNULIB_LSEEK@
261# if @REPLACE_LSEEK@
262/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
263 Return the new offset if successful, otherwise -1 and errno set.
264 See the POSIX:2001 specification
265 <http://www.opengroup.org/susv3xsh/lseek.html>. */
266# define lseek rpl_lseek
267 extern off_t lseek (int fd, off_t offset, int whence);
268# endif
269#elif defined GNULIB_POSIXCHECK
270# undef lseek
271# define lseek(f,o,w) \
272 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
273 "systems - use gnulib module lseek for portability"), \
274 lseek (f, o, w))
275#endif
276
277
278#if @GNULIB_READLINK@
279/* Read the contents of the symbolic link FILE and place the first BUFSIZE
280 bytes of it into BUF. Return the number of bytes placed into BUF if
281 successful, otherwise -1 and errno set.
282 See the POSIX:2001 specification
283 <http://www.opengroup.org/susv3xsh/readlink.html>. */
284# if !@HAVE_READLINK@
285# include <stddef.h>
286extern int readlink (const char *file, char *buf, size_t bufsize);
287# endif
288#elif defined GNULIB_POSIXCHECK
289# undef readlink
290# define readlink(f,b,s) \
291 (GL_LINK_WARNING ("readlink is unportable - " \
292 "use gnulib module readlink for portability"), \
293 readlink (f, b, s))
294#endif
295
296
297#if @GNULIB_SLEEP@
298/* Pause the execution of the current thread for N seconds.
299 Returns the number of seconds left to sleep.
300 See the POSIX:2001 specification
301 <http://www.opengroup.org/susv3xsh/sleep.html>. */
302# if !@HAVE_SLEEP@
303extern unsigned int sleep (unsigned int n);
304# endif
305#elif defined GNULIB_POSIXCHECK
306# undef sleep
307# define sleep(n) \
308 (GL_LINK_WARNING ("sleep is unportable - " \
309 "use gnulib module sleep for portability"), \
310 sleep (n))
311#endif
312
313
314#ifdef __cplusplus
315}
316#endif
317
318
319#endif /* _GL_UNISTD_H */
320#endif /* _GL_UNISTD_H */
diff --git a/gl/unistd_.h b/gl/unistd_.h
deleted file mode 100644
index 36fa673..0000000
--- a/gl/unistd_.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2006 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 2, 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#ifndef _GL_UNISTD_H
19#define _GL_UNISTD_H
20
21#if HAVE_UNISTD_H
22# include @ABSOLUTE_UNISTD_H@
23#endif
24
25
26/* Declare overridden functions. */
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#ifdef FCHDIR_REPLACEMENT
33
34/* Change the process' current working directory to the directory on which
35 the given file descriptor is open. */
36extern int fchdir (int /*fd*/);
37
38# define close rpl_close
39extern int close (int);
40# define dup rpl_dup
41extern int dup (int);
42# define dup2 rpl_dup2
43extern int dup2 (int, int);
44
45#endif
46
47#ifdef __cplusplus
48}
49#endif
50
51
52#endif /* _GL_UNISTD_H */
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 0fe2aad..d5b4028 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -1,9 +1,9 @@
1/* vsprintf with automatic memory allocation. 1/* vsprintf with automatic memory allocation.
2 Copyright (C) 1999, 2002-2006 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2008 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -15,6 +15,35 @@
15 with this program; if not, write to the Free Software Foundation, 15 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/* This file can be parametrized with the following macros:
19 VASNPRINTF The name of the function being defined.
20 FCHAR_T The element type of the format string.
21 DCHAR_T The element type of the destination (result) string.
22 FCHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
23 in the format string are ASCII. MUST be set if
24 FCHAR_T and DCHAR_T are not the same type.
25 DIRECTIVE Structure denoting a format directive.
26 Depends on FCHAR_T.
27 DIRECTIVES Structure denoting the set of format directives of a
28 format string. Depends on FCHAR_T.
29 PRINTF_PARSE Function that parses a format string.
30 Depends on FCHAR_T.
31 DCHAR_CPY memcpy like function for DCHAR_T[] arrays.
32 DCHAR_SET memset like function for DCHAR_T[] arrays.
33 DCHAR_MBSNLEN mbsnlen like function for DCHAR_T[] arrays.
34 SNPRINTF The system's snprintf (or similar) function.
35 This may be either snprintf or swprintf.
36 TCHAR_T The element type of the argument and result string
37 of the said SNPRINTF function. This may be either
38 char or wchar_t. The code exploits that
39 sizeof (TCHAR_T) | sizeof (DCHAR_T) and
40 alignof (TCHAR_T) <= alignof (DCHAR_T).
41 DCHAR_IS_TCHAR Set to 1 if DCHAR_T and TCHAR_T are the same type.
42 DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[].
43 DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t.
44 DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t.
45 DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */
46
18/* Tell glibc's <stdio.h> to provide a prototype for snprintf(). 47/* Tell glibc's <stdio.h> to provide a prototype for snprintf().
19 This must come before <config.h> because <config.h> may include 48 This must come before <config.h> because <config.h> may include
20 <features.h>, and once <features.h> has been included, it's too late. */ 49 <features.h>, and once <features.h> has been included, it's too late. */
@@ -22,35 +51,79 @@
22# define _GNU_SOURCE 1 51# define _GNU_SOURCE 1
23#endif 52#endif
24 53
25#include <config.h> 54#ifndef VASNPRINTF
55# include <config.h>
56#endif
26#ifndef IN_LIBINTL 57#ifndef IN_LIBINTL
27# include <alloca.h> 58# include <alloca.h>
28#endif 59#endif
29 60
30/* Specification. */ 61/* Specification. */
31#if WIDE_CHAR_VERSION 62#ifndef VASNPRINTF
32# include "vasnwprintf.h" 63# if WIDE_CHAR_VERSION
33#else 64# include "vasnwprintf.h"
34# include "vasnprintf.h" 65# else
66# include "vasnprintf.h"
67# endif
35#endif 68#endif
36 69
70#include <locale.h> /* localeconv() */
37#include <stdio.h> /* snprintf(), sprintf() */ 71#include <stdio.h> /* snprintf(), sprintf() */
38#include <stdlib.h> /* abort(), malloc(), realloc(), free() */ 72#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
39#include <string.h> /* memcpy(), strlen() */ 73#include <string.h> /* memcpy(), strlen() */
40#include <errno.h> /* errno */ 74#include <errno.h> /* errno */
41#include <limits.h> /* CHAR_BIT */ 75#include <limits.h> /* CHAR_BIT */
42#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */ 76#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
43#if WIDE_CHAR_VERSION 77#if HAVE_NL_LANGINFO
44# include "wprintf-parse.h" 78# include <langinfo.h>
45#else 79#endif
46# include "printf-parse.h" 80#ifndef VASNPRINTF
81# if WIDE_CHAR_VERSION
82# include "wprintf-parse.h"
83# else
84# include "printf-parse.h"
85# endif
47#endif 86#endif
48 87
49/* Checked size_t computations. */ 88/* Checked size_t computations. */
50#include "xsize.h" 89#include "xsize.h"
51 90
52#ifdef HAVE_WCHAR_T 91#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
53# ifdef HAVE_WCSLEN 92# include <math.h>
93# include "float+.h"
94#endif
95
96#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
97# include <math.h>
98# include "isnand.h"
99#endif
100
101#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL
102# include <math.h>
103# include "isnanl-nolibm.h"
104# include "fpucw.h"
105#endif
106
107#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
108# include <math.h>
109# include "isnand.h"
110# include "printf-frexp.h"
111#endif
112
113#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
114# include <math.h>
115# include "isnanl-nolibm.h"
116# include "printf-frexpl.h"
117# include "fpucw.h"
118#endif
119
120/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */
121#ifndef EOVERFLOW
122# define EOVERFLOW E2BIG
123#endif
124
125#if HAVE_WCHAR_T
126# if HAVE_WCSLEN
54# define local_wcslen wcslen 127# define local_wcslen wcslen
55# else 128# else
56 /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid 129 /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
@@ -72,12 +145,32 @@ local_wcslen (const wchar_t *s)
72# endif 145# endif
73#endif 146#endif
74 147
148/* Default parameters. */
149#ifndef VASNPRINTF
150# if WIDE_CHAR_VERSION
151# define VASNPRINTF vasnwprintf
152# define FCHAR_T wchar_t
153# define DCHAR_T wchar_t
154# define TCHAR_T wchar_t
155# define DCHAR_IS_TCHAR 1
156# define DIRECTIVE wchar_t_directive
157# define DIRECTIVES wchar_t_directives
158# define PRINTF_PARSE wprintf_parse
159# define DCHAR_CPY wmemcpy
160# else
161# define VASNPRINTF vasnprintf
162# define FCHAR_T char
163# define DCHAR_T char
164# define TCHAR_T char
165# define DCHAR_IS_TCHAR 1
166# define DIRECTIVE char_directive
167# define DIRECTIVES char_directives
168# define PRINTF_PARSE printf_parse
169# define DCHAR_CPY memcpy
170# endif
171#endif
75#if WIDE_CHAR_VERSION 172#if WIDE_CHAR_VERSION
76# define VASNPRINTF vasnwprintf 173 /* TCHAR_T is wchar_t. */
77# define CHAR_T wchar_t
78# define DIRECTIVE wchar_t_directive
79# define DIRECTIVES wchar_t_directives
80# define PRINTF_PARSE wprintf_parse
81# define USE_SNPRINTF 1 174# define USE_SNPRINTF 1
82# if HAVE_DECL__SNWPRINTF 175# if HAVE_DECL__SNWPRINTF
83 /* On Windows, the function swprintf() has a different signature than 176 /* On Windows, the function swprintf() has a different signature than
@@ -88,39 +181,1253 @@ local_wcslen (const wchar_t *s)
88# define SNPRINTF swprintf 181# define SNPRINTF swprintf
89# endif 182# endif
90#else 183#else
91# define VASNPRINTF vasnprintf 184 /* TCHAR_T is char. */
92# define CHAR_T char 185# /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'.
93# define DIRECTIVE char_directive 186 But don't use it on BeOS, since BeOS snprintf produces no output if the
94# define DIRECTIVES char_directives 187 size argument is >= 0x3000000. */
95# define PRINTF_PARSE printf_parse 188# if (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) && !defined __BEOS__
96# define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) 189# define USE_SNPRINTF 1
190# else
191# define USE_SNPRINTF 0
192# endif
97# if HAVE_DECL__SNPRINTF 193# if HAVE_DECL__SNPRINTF
98 /* Windows. */ 194 /* Windows. */
99# define SNPRINTF _snprintf 195# define SNPRINTF _snprintf
100# else 196# else
101 /* Unix. */ 197 /* Unix. */
102# define SNPRINTF snprintf 198# define SNPRINTF snprintf
199 /* Here we need to call the native snprintf, not rpl_snprintf. */
200# undef snprintf
103# endif 201# endif
104#endif 202#endif
203/* Here we need to call the native sprintf, not rpl_sprintf. */
204#undef sprintf
105 205
106CHAR_T * 206#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
107VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args) 207/* Determine the decimal-point character according to the current locale. */
208# ifndef decimal_point_char_defined
209# define decimal_point_char_defined 1
210static char
211decimal_point_char ()
108{ 212{
109 DIRECTIVES d; 213 const char *point;
110 arguments a; 214 /* Determine it in a multithread-safe way. We know nl_langinfo is
215 multithread-safe on glibc systems, but is not required to be multithread-
216 safe by POSIX. sprintf(), however, is multithread-safe. localeconv()
217 is rarely multithread-safe. */
218# if HAVE_NL_LANGINFO && __GLIBC__
219 point = nl_langinfo (RADIXCHAR);
220# elif 1
221 char pointbuf[5];
222 sprintf (pointbuf, "%#.0f", 1.0);
223 point = &pointbuf[1];
224# else
225 point = localeconv () -> decimal_point;
226# endif
227 /* The decimal point is always a single byte: either '.' or ','. */
228 return (point[0] != '\0' ? point[0] : '.');
229}
230# endif
231#endif
111 232
112 if (PRINTF_PARSE (format, &d, &a) < 0) 233#if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE && !defined IN_LIBINTL
234
235/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */
236static int
237is_infinite_or_zero (double x)
238{
239 return isnand (x) || x + x == x;
240}
241
242#endif
243
244#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
245
246/* Equivalent to !isfinite(x), but does not require libm. */
247static int
248is_infinitel (long double x)
249{
250 return isnanl (x) || (x + x == x && x != 0.0L);
251}
252
253#endif
254
255#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
256
257/* Converting 'long double' to decimal without rare rounding bugs requires
258 real bignums. We use the naming conventions of GNU gmp, but vastly simpler
259 (and slower) algorithms. */
260
261typedef unsigned int mp_limb_t;
262# define GMP_LIMB_BITS 32
263typedef int mp_limb_verify[2 * (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS) - 1];
264
265typedef unsigned long long mp_twolimb_t;
266# define GMP_TWOLIMB_BITS 64
267typedef int mp_twolimb_verify[2 * (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS) - 1];
268
269/* Representation of a bignum >= 0. */
270typedef struct
271{
272 size_t nlimbs;
273 mp_limb_t *limbs; /* Bits in little-endian order, allocated with malloc(). */
274} mpn_t;
275
276/* Compute the product of two bignums >= 0.
277 Return the allocated memory in case of success, NULL in case of memory
278 allocation failure. */
279static void *
280multiply (mpn_t src1, mpn_t src2, mpn_t *dest)
281{
282 const mp_limb_t *p1;
283 const mp_limb_t *p2;
284 size_t len1;
285 size_t len2;
286
287 if (src1.nlimbs <= src2.nlimbs)
113 { 288 {
114 errno = EINVAL; 289 len1 = src1.nlimbs;
290 p1 = src1.limbs;
291 len2 = src2.nlimbs;
292 p2 = src2.limbs;
293 }
294 else
295 {
296 len1 = src2.nlimbs;
297 p1 = src2.limbs;
298 len2 = src1.nlimbs;
299 p2 = src1.limbs;
300 }
301 /* Now 0 <= len1 <= len2. */
302 if (len1 == 0)
303 {
304 /* src1 or src2 is zero. */
305 dest->nlimbs = 0;
306 dest->limbs = (mp_limb_t *) malloc (1);
307 }
308 else
309 {
310 /* Here 1 <= len1 <= len2. */
311 size_t dlen;
312 mp_limb_t *dp;
313 size_t k, i, j;
314
315 dlen = len1 + len2;
316 dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t));
317 if (dp == NULL)
318 return NULL;
319 for (k = len2; k > 0; )
320 dp[--k] = 0;
321 for (i = 0; i < len1; i++)
322 {
323 mp_limb_t digit1 = p1[i];
324 mp_twolimb_t carry = 0;
325 for (j = 0; j < len2; j++)
326 {
327 mp_limb_t digit2 = p2[j];
328 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
329 carry += dp[i + j];
330 dp[i + j] = (mp_limb_t) carry;
331 carry = carry >> GMP_LIMB_BITS;
332 }
333 dp[i + len2] = (mp_limb_t) carry;
334 }
335 /* Normalise. */
336 while (dlen > 0 && dp[dlen - 1] == 0)
337 dlen--;
338 dest->nlimbs = dlen;
339 dest->limbs = dp;
340 }
341 return dest->limbs;
342}
343
344/* Compute the quotient of a bignum a >= 0 and a bignum b > 0.
345 a is written as a = q * b + r with 0 <= r < b. q is the quotient, r
346 the remainder.
347 Finally, round-to-even is performed: If r > b/2 or if r = b/2 and q is odd,
348 q is incremented.
349 Return the allocated memory in case of success, NULL in case of memory
350 allocation failure. */
351static void *
352divide (mpn_t a, mpn_t b, mpn_t *q)
353{
354 /* Algorithm:
355 First normalise a and b: a=[a[m-1],...,a[0]], b=[b[n-1],...,b[0]]
356 with m>=0 and n>0 (in base beta = 2^GMP_LIMB_BITS).
357 If m<n, then q:=0 and r:=a.
358 If m>=n=1, perform a single-precision division:
359 r:=0, j:=m,
360 while j>0 do
361 {Here (q[m-1]*beta^(m-1)+...+q[j]*beta^j) * b[0] + r*beta^j =
362 = a[m-1]*beta^(m-1)+...+a[j]*beta^j und 0<=r<b[0]<beta}
363 j:=j-1, r:=r*beta+a[j], q[j]:=floor(r/b[0]), r:=r-b[0]*q[j].
364 Normalise [q[m-1],...,q[0]], yields q.
365 If m>=n>1, perform a multiple-precision division:
366 We have a/b < beta^(m-n+1).
367 s:=intDsize-1-(hightest bit in b[n-1]), 0<=s<intDsize.
368 Shift a and b left by s bits, copying them. r:=a.
369 r=[r[m],...,r[0]], b=[b[n-1],...,b[0]] with b[n-1]>=beta/2.
370 For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).}
371 Compute q* :
372 q* := floor((r[j+n]*beta+r[j+n-1])/b[n-1]).
373 In case of overflow (q* >= beta) set q* := beta-1.
374 Compute c2 := ((r[j+n]*beta+r[j+n-1]) - q* * b[n-1])*beta + r[j+n-2]
375 and c3 := b[n-2] * q*.
376 {We have 0 <= c2 < 2*beta^2, even 0 <= c2 < beta^2 if no overflow
377 occurred. Furthermore 0 <= c3 < beta^2.
378 If there was overflow and
379 r[j+n]*beta+r[j+n-1] - q* * b[n-1] >= beta, i.e. c2 >= beta^2,
380 the next test can be skipped.}
381 While c3 > c2, {Here 0 <= c2 < c3 < beta^2}
382 Put q* := q* - 1, c2 := c2 + b[n-1]*beta, c3 := c3 - b[n-2].
383 If q* > 0:
384 Put r := r - b * q* * beta^j. In detail:
385 [r[n+j],...,r[j]] := [r[n+j],...,r[j]] - q* * [b[n-1],...,b[0]].
386 hence: u:=0, for i:=0 to n-1 do
387 u := u + q* * b[i],
388 r[j+i]:=r[j+i]-(u mod beta) (+ beta, if carry),
389 u:=u div beta (+ 1, if carry in subtraction)
390 r[n+j]:=r[n+j]-u.
391 {Since always u = (q* * [b[i-1],...,b[0]] div beta^i) + 1
392 < q* + 1 <= beta,
393 the carry u does not overflow.}
394 If a negative carry occurs, put q* := q* - 1
395 and [r[n+j],...,r[j]] := [r[n+j],...,r[j]] + [0,b[n-1],...,b[0]].
396 Set q[j] := q*.
397 Normalise [q[m-n],..,q[0]]; this yields the quotient q.
398 Shift [r[n-1],...,r[0]] right by s bits and normalise; this yields the
399 rest r.
400 The room for q[j] can be allocated at the memory location of r[n+j].
401 Finally, round-to-even:
402 Shift r left by 1 bit.
403 If r > b or if r = b and q[0] is odd, q := q+1.
404 */
405 const mp_limb_t *a_ptr = a.limbs;
406 size_t a_len = a.nlimbs;
407 const mp_limb_t *b_ptr = b.limbs;
408 size_t b_len = b.nlimbs;
409 mp_limb_t *roomptr;
410 mp_limb_t *tmp_roomptr = NULL;
411 mp_limb_t *q_ptr;
412 size_t q_len;
413 mp_limb_t *r_ptr;
414 size_t r_len;
415
416 /* Allocate room for a_len+2 digits.
417 (Need a_len+1 digits for the real division and 1 more digit for the
418 final rounding of q.) */
419 roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t));
420 if (roomptr == NULL)
421 return NULL;
422
423 /* Normalise a. */
424 while (a_len > 0 && a_ptr[a_len - 1] == 0)
425 a_len--;
426
427 /* Normalise b. */
428 for (;;)
429 {
430 if (b_len == 0)
431 /* Division by zero. */
432 abort ();
433 if (b_ptr[b_len - 1] == 0)
434 b_len--;
435 else
436 break;
437 }
438
439 /* Here m = a_len >= 0 and n = b_len > 0. */
440
441 if (a_len < b_len)
442 {
443 /* m<n: trivial case. q=0, r := copy of a. */
444 r_ptr = roomptr;
445 r_len = a_len;
446 memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
447 q_ptr = roomptr + a_len;
448 q_len = 0;
449 }
450 else if (b_len == 1)
451 {
452 /* n=1: single precision division.
453 beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */
454 r_ptr = roomptr;
455 q_ptr = roomptr + 1;
456 {
457 mp_limb_t den = b_ptr[0];
458 mp_limb_t remainder = 0;
459 const mp_limb_t *sourceptr = a_ptr + a_len;
460 mp_limb_t *destptr = q_ptr + a_len;
461 size_t count;
462 for (count = a_len; count > 0; count--)
463 {
464 mp_twolimb_t num =
465 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr;
466 *--destptr = num / den;
467 remainder = num % den;
468 }
469 /* Normalise and store r. */
470 if (remainder > 0)
471 {
472 r_ptr[0] = remainder;
473 r_len = 1;
474 }
475 else
476 r_len = 0;
477 /* Normalise q. */
478 q_len = a_len;
479 if (q_ptr[q_len - 1] == 0)
480 q_len--;
481 }
482 }
483 else
484 {
485 /* n>1: multiple precision division.
486 beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==>
487 beta^(m-n-1) <= a/b < beta^(m-n+1). */
488 /* Determine s. */
489 size_t s;
490 {
491 mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
492 s = 31;
493 if (msd >= 0x10000)
494 {
495 msd = msd >> 16;
496 s -= 16;
497 }
498 if (msd >= 0x100)
499 {
500 msd = msd >> 8;
501 s -= 8;
502 }
503 if (msd >= 0x10)
504 {
505 msd = msd >> 4;
506 s -= 4;
507 }
508 if (msd >= 0x4)
509 {
510 msd = msd >> 2;
511 s -= 2;
512 }
513 if (msd >= 0x2)
514 {
515 msd = msd >> 1;
516 s -= 1;
517 }
518 }
519 /* 0 <= s < GMP_LIMB_BITS.
520 Copy b, shifting it left by s bits. */
521 if (s > 0)
522 {
523 tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t));
524 if (tmp_roomptr == NULL)
525 {
526 free (roomptr);
527 return NULL;
528 }
529 {
530 const mp_limb_t *sourceptr = b_ptr;
531 mp_limb_t *destptr = tmp_roomptr;
532 mp_twolimb_t accu = 0;
533 size_t count;
534 for (count = b_len; count > 0; count--)
535 {
536 accu += (mp_twolimb_t) *sourceptr++ << s;
537 *destptr++ = (mp_limb_t) accu;
538 accu = accu >> GMP_LIMB_BITS;
539 }
540 /* accu must be zero, since that was how s was determined. */
541 if (accu != 0)
542 abort ();
543 }
544 b_ptr = tmp_roomptr;
545 }
546 /* Copy a, shifting it left by s bits, yields r.
547 Memory layout:
548 At the beginning: r = roomptr[0..a_len],
549 at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */
550 r_ptr = roomptr;
551 if (s == 0)
552 {
553 memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
554 r_ptr[a_len] = 0;
555 }
556 else
557 {
558 const mp_limb_t *sourceptr = a_ptr;
559 mp_limb_t *destptr = r_ptr;
560 mp_twolimb_t accu = 0;
561 size_t count;
562 for (count = a_len; count > 0; count--)
563 {
564 accu += (mp_twolimb_t) *sourceptr++ << s;
565 *destptr++ = (mp_limb_t) accu;
566 accu = accu >> GMP_LIMB_BITS;
567 }
568 *destptr++ = (mp_limb_t) accu;
569 }
570 q_ptr = roomptr + b_len;
571 q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */
572 {
573 size_t j = a_len - b_len; /* m-n */
574 mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */
575 mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */
576 mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */
577 ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd;
578 /* Division loop, traversed m-n+1 times.
579 j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */
580 for (;;)
581 {
582 mp_limb_t q_star;
583 mp_limb_t c1;
584 if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */
585 {
586 /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */
587 mp_twolimb_t num =
588 ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS)
589 | r_ptr[j + b_len - 1];
590 q_star = num / b_msd;
591 c1 = num % b_msd;
592 }
593 else
594 {
595 /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */
596 q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */
597 /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta
598 <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta
599 <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta)
600 {<= beta !}.
601 If yes, jump directly to the subtraction loop.
602 (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta
603 <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */
604 if (r_ptr[j + b_len] > b_msd
605 || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd)
606 /* r[j+n] >= b[n-1]+1 or
607 r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a
608 carry. */
609 goto subtract;
610 }
611 /* q_star = q*,
612 c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, <beta). */
613 {
614 mp_twolimb_t c2 = /* c1*beta+r[j+n-2] */
615 ((mp_twolimb_t) c1 << GMP_LIMB_BITS) | r_ptr[j + b_len - 2];
616 mp_twolimb_t c3 = /* b[n-2] * q* */
617 (mp_twolimb_t) b_2msd * (mp_twolimb_t) q_star;
618 /* While c2 < c3, increase c2 and decrease c3.
619 Consider c3-c2. While it is > 0, decrease it by
620 b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2
621 this can happen only twice. */
622 if (c3 > c2)
623 {
624 q_star = q_star - 1; /* q* := q* - 1 */
625 if (c3 - c2 > b_msdd)
626 q_star = q_star - 1; /* q* := q* - 1 */
627 }
628 }
629 if (q_star > 0)
630 subtract:
631 {
632 /* Subtract r := r - b * q* * beta^j. */
633 mp_limb_t cr;
634 {
635 const mp_limb_t *sourceptr = b_ptr;
636 mp_limb_t *destptr = r_ptr + j;
637 mp_twolimb_t carry = 0;
638 size_t count;
639 for (count = b_len; count > 0; count--)
640 {
641 /* Here 0 <= carry <= q*. */
642 carry =
643 carry
644 + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++
645 + (mp_limb_t) ~(*destptr);
646 /* Here 0 <= carry <= beta*q* + beta-1. */
647 *destptr++ = ~(mp_limb_t) carry;
648 carry = carry >> GMP_LIMB_BITS; /* <= q* */
649 }
650 cr = (mp_limb_t) carry;
651 }
652 /* Subtract cr from r_ptr[j + b_len], then forget about
653 r_ptr[j + b_len]. */
654 if (cr > r_ptr[j + b_len])
655 {
656 /* Subtraction gave a carry. */
657 q_star = q_star - 1; /* q* := q* - 1 */
658 /* Add b back. */
659 {
660 const mp_limb_t *sourceptr = b_ptr;
661 mp_limb_t *destptr = r_ptr + j;
662 mp_limb_t carry = 0;
663 size_t count;
664 for (count = b_len; count > 0; count--)
665 {
666 mp_limb_t source1 = *sourceptr++;
667 mp_limb_t source2 = *destptr;
668 *destptr++ = source1 + source2 + carry;
669 carry =
670 (carry
671 ? source1 >= (mp_limb_t) ~source2
672 : source1 > (mp_limb_t) ~source2);
673 }
674 }
675 /* Forget about the carry and about r[j+n]. */
676 }
677 }
678 /* q* is determined. Store it as q[j]. */
679 q_ptr[j] = q_star;
680 if (j == 0)
681 break;
682 j--;
683 }
684 }
685 r_len = b_len;
686 /* Normalise q. */
687 if (q_ptr[q_len - 1] == 0)
688 q_len--;
689# if 0 /* Not needed here, since we need r only to compare it with b/2, and
690 b is shifted left by s bits. */
691 /* Shift r right by s bits. */
692 if (s > 0)
693 {
694 mp_limb_t ptr = r_ptr + r_len;
695 mp_twolimb_t accu = 0;
696 size_t count;
697 for (count = r_len; count > 0; count--)
698 {
699 accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS;
700 accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s);
701 *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS);
702 }
703 }
704# endif
705 /* Normalise r. */
706 while (r_len > 0 && r_ptr[r_len - 1] == 0)
707 r_len--;
708 }
709 /* Compare r << 1 with b. */
710 if (r_len > b_len)
711 goto increment_q;
712 {
713 size_t i;
714 for (i = b_len;;)
715 {
716 mp_limb_t r_i =
717 (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0)
718 | (i < r_len ? r_ptr[i] << 1 : 0);
719 mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0);
720 if (r_i > b_i)
721 goto increment_q;
722 if (r_i < b_i)
723 goto keep_q;
724 if (i == 0)
725 break;
726 i--;
727 }
728 }
729 if (q_len > 0 && ((q_ptr[0] & 1) != 0))
730 /* q is odd. */
731 increment_q:
732 {
733 size_t i;
734 for (i = 0; i < q_len; i++)
735 if (++(q_ptr[i]) != 0)
736 goto keep_q;
737 q_ptr[q_len++] = 1;
738 }
739 keep_q:
740 if (tmp_roomptr != NULL)
741 free (tmp_roomptr);
742 q->limbs = q_ptr;
743 q->nlimbs = q_len;
744 return roomptr;
745}
746
747/* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal
748 representation.
749 Destroys the contents of a.
750 Return the allocated memory - containing the decimal digits in low-to-high
751 order, terminated with a NUL character - in case of success, NULL in case
752 of memory allocation failure. */
753static char *
754convert_to_decimal (mpn_t a, size_t extra_zeroes)
755{
756 mp_limb_t *a_ptr = a.limbs;
757 size_t a_len = a.nlimbs;
758 /* 0.03345 is slightly larger than log(2)/(9*log(10)). */
759 size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1);
760 char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes));
761 if (c_ptr != NULL)
762 {
763 char *d_ptr = c_ptr;
764 for (; extra_zeroes > 0; extra_zeroes--)
765 *d_ptr++ = '0';
766 while (a_len > 0)
767 {
768 /* Divide a by 10^9, in-place. */
769 mp_limb_t remainder = 0;
770 mp_limb_t *ptr = a_ptr + a_len;
771 size_t count;
772 for (count = a_len; count > 0; count--)
773 {
774 mp_twolimb_t num =
775 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr;
776 *ptr = num / 1000000000;
777 remainder = num % 1000000000;
778 }
779 /* Store the remainder as 9 decimal digits. */
780 for (count = 9; count > 0; count--)
781 {
782 *d_ptr++ = '0' + (remainder % 10);
783 remainder = remainder / 10;
784 }
785 /* Normalize a. */
786 if (a_ptr[a_len - 1] == 0)
787 a_len--;
788 }
789 /* Remove leading zeroes. */
790 while (d_ptr > c_ptr && d_ptr[-1] == '0')
791 d_ptr--;
792 /* But keep at least one zero. */
793 if (d_ptr == c_ptr)
794 *d_ptr++ = '0';
795 /* Terminate the string. */
796 *d_ptr = '\0';
797 }
798 return c_ptr;
799}
800
801# if NEED_PRINTF_LONG_DOUBLE
802
803/* Assuming x is finite and >= 0:
804 write x as x = 2^e * m, where m is a bignum.
805 Return the allocated memory in case of success, NULL in case of memory
806 allocation failure. */
807static void *
808decode_long_double (long double x, int *ep, mpn_t *mp)
809{
810 mpn_t m;
811 int exp;
812 long double y;
813 size_t i;
814
815 /* Allocate memory for result. */
816 m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
817 m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
818 if (m.limbs == NULL)
819 return NULL;
820 /* Split into exponential part and mantissa. */
821 y = frexpl (x, &exp);
822 if (!(y >= 0.0L && y < 1.0L))
823 abort ();
824 /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * LDBL_MANT_BIT), and the
825 latter is an integer. */
826 /* Convert the mantissa (y * LDBL_MANT_BIT) to a sequence of limbs.
827 I'm not sure whether it's safe to cast a 'long double' value between
828 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
829 'long double' values between 0 and 2^16 (to 'unsigned int' or 'int',
830 doesn't matter). */
831# if (LDBL_MANT_BIT % GMP_LIMB_BITS) != 0
832# if (LDBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2
833 {
834 mp_limb_t hi, lo;
835 y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % (GMP_LIMB_BITS / 2));
836 hi = (int) y;
837 y -= hi;
838 if (!(y >= 0.0L && y < 1.0L))
839 abort ();
840 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
841 lo = (int) y;
842 y -= lo;
843 if (!(y >= 0.0L && y < 1.0L))
844 abort ();
845 m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
846 }
847# else
848 {
849 mp_limb_t d;
850 y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % GMP_LIMB_BITS);
851 d = (int) y;
852 y -= d;
853 if (!(y >= 0.0L && y < 1.0L))
854 abort ();
855 m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d;
856 }
857# endif
858# endif
859 for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
860 {
861 mp_limb_t hi, lo;
862 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
863 hi = (int) y;
864 y -= hi;
865 if (!(y >= 0.0L && y < 1.0L))
866 abort ();
867 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
868 lo = (int) y;
869 y -= lo;
870 if (!(y >= 0.0L && y < 1.0L))
871 abort ();
872 m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
873 }
874#if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
875 precision. */
876 if (!(y == 0.0L))
877 abort ();
878#endif
879 /* Normalise. */
880 while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
881 m.nlimbs--;
882 *mp = m;
883 *ep = exp - LDBL_MANT_BIT;
884 return m.limbs;
885}
886
887# endif
888
889# if NEED_PRINTF_DOUBLE
890
891/* Assuming x is finite and >= 0:
892 write x as x = 2^e * m, where m is a bignum.
893 Return the allocated memory in case of success, NULL in case of memory
894 allocation failure. */
895static void *
896decode_double (double x, int *ep, mpn_t *mp)
897{
898 mpn_t m;
899 int exp;
900 double y;
901 size_t i;
902
903 /* Allocate memory for result. */
904 m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
905 m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
906 if (m.limbs == NULL)
907 return NULL;
908 /* Split into exponential part and mantissa. */
909 y = frexp (x, &exp);
910 if (!(y >= 0.0 && y < 1.0))
911 abort ();
912 /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * DBL_MANT_BIT), and the
913 latter is an integer. */
914 /* Convert the mantissa (y * DBL_MANT_BIT) to a sequence of limbs.
915 I'm not sure whether it's safe to cast a 'double' value between
916 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
917 'double' values between 0 and 2^16 (to 'unsigned int' or 'int',
918 doesn't matter). */
919# if (DBL_MANT_BIT % GMP_LIMB_BITS) != 0
920# if (DBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2
921 {
922 mp_limb_t hi, lo;
923 y *= (mp_limb_t) 1 << (DBL_MANT_BIT % (GMP_LIMB_BITS / 2));
924 hi = (int) y;
925 y -= hi;
926 if (!(y >= 0.0 && y < 1.0))
927 abort ();
928 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
929 lo = (int) y;
930 y -= lo;
931 if (!(y >= 0.0 && y < 1.0))
932 abort ();
933 m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
934 }
935# else
936 {
937 mp_limb_t d;
938 y *= (mp_limb_t) 1 << (DBL_MANT_BIT % GMP_LIMB_BITS);
939 d = (int) y;
940 y -= d;
941 if (!(y >= 0.0 && y < 1.0))
942 abort ();
943 m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d;
944 }
945# endif
946# endif
947 for (i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
948 {
949 mp_limb_t hi, lo;
950 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
951 hi = (int) y;
952 y -= hi;
953 if (!(y >= 0.0 && y < 1.0))
954 abort ();
955 y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
956 lo = (int) y;
957 y -= lo;
958 if (!(y >= 0.0 && y < 1.0))
959 abort ();
960 m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
961 }
962 if (!(y == 0.0))
963 abort ();
964 /* Normalise. */
965 while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
966 m.nlimbs--;
967 *mp = m;
968 *ep = exp - DBL_MANT_BIT;
969 return m.limbs;
970}
971
972# endif
973
974/* Assuming x = 2^e * m is finite and >= 0, and n is an integer:
975 Returns the decimal representation of round (x * 10^n).
976 Return the allocated memory - containing the decimal digits in low-to-high
977 order, terminated with a NUL character - in case of success, NULL in case
978 of memory allocation failure. */
979static char *
980scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
981{
982 int s;
983 size_t extra_zeroes;
984 unsigned int abs_n;
985 unsigned int abs_s;
986 mp_limb_t *pow5_ptr;
987 size_t pow5_len;
988 unsigned int s_limbs;
989 unsigned int s_bits;
990 mpn_t pow5;
991 mpn_t z;
992 void *z_memory;
993 char *digits;
994
995 if (memory == NULL)
996 return NULL;
997 /* x = 2^e * m, hence
998 y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m)
999 = round (2^s * 5^n * m). */
1000 s = e + n;
1001 extra_zeroes = 0;
1002 /* Factor out a common power of 10 if possible. */
1003 if (s > 0 && n > 0)
1004 {
1005 extra_zeroes = (s < n ? s : n);
1006 s -= extra_zeroes;
1007 n -= extra_zeroes;
1008 }
1009 /* Here y = round (2^s * 5^n * m) * 10^extra_zeroes.
1010 Before converting to decimal, we need to compute
1011 z = round (2^s * 5^n * m). */
1012 /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same
1013 sign. 2.322 is slightly larger than log(5)/log(2). */
1014 abs_n = (n >= 0 ? n : -n);
1015 abs_s = (s >= 0 ? s : -s);
1016 pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1
1017 + abs_s / GMP_LIMB_BITS + 1)
1018 * sizeof (mp_limb_t));
1019 if (pow5_ptr == NULL)
1020 {
1021 free (memory);
115 return NULL; 1022 return NULL;
116 } 1023 }
1024 /* Initialize with 1. */
1025 pow5_ptr[0] = 1;
1026 pow5_len = 1;
1027 /* Multiply with 5^|n|. */
1028 if (abs_n > 0)
1029 {
1030 static mp_limb_t const small_pow5[13 + 1] =
1031 {
1032 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625,
1033 48828125, 244140625, 1220703125
1034 };
1035 unsigned int n13;
1036 for (n13 = 0; n13 <= abs_n; n13 += 13)
1037 {
1038 mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13];
1039 size_t j;
1040 mp_twolimb_t carry = 0;
1041 for (j = 0; j < pow5_len; j++)
1042 {
1043 mp_limb_t digit2 = pow5_ptr[j];
1044 carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
1045 pow5_ptr[j] = (mp_limb_t) carry;
1046 carry = carry >> GMP_LIMB_BITS;
1047 }
1048 if (carry > 0)
1049 pow5_ptr[pow5_len++] = (mp_limb_t) carry;
1050 }
1051 }
1052 s_limbs = abs_s / GMP_LIMB_BITS;
1053 s_bits = abs_s % GMP_LIMB_BITS;
1054 if (n >= 0 ? s >= 0 : s <= 0)
1055 {
1056 /* Multiply with 2^|s|. */
1057 if (s_bits > 0)
1058 {
1059 mp_limb_t *ptr = pow5_ptr;
1060 mp_twolimb_t accu = 0;
1061 size_t count;
1062 for (count = pow5_len; count > 0; count--)
1063 {
1064 accu += (mp_twolimb_t) *ptr << s_bits;
1065 *ptr++ = (mp_limb_t) accu;
1066 accu = accu >> GMP_LIMB_BITS;
1067 }
1068 if (accu > 0)
1069 {
1070 *ptr = (mp_limb_t) accu;
1071 pow5_len++;
1072 }
1073 }
1074 if (s_limbs > 0)
1075 {
1076 size_t count;
1077 for (count = pow5_len; count > 0;)
1078 {
1079 count--;
1080 pow5_ptr[s_limbs + count] = pow5_ptr[count];
1081 }
1082 for (count = s_limbs; count > 0;)
1083 {
1084 count--;
1085 pow5_ptr[count] = 0;
1086 }
1087 pow5_len += s_limbs;
1088 }
1089 pow5.limbs = pow5_ptr;
1090 pow5.nlimbs = pow5_len;
1091 if (n >= 0)
1092 {
1093 /* Multiply m with pow5. No division needed. */
1094 z_memory = multiply (m, pow5, &z);
1095 }
1096 else
1097 {
1098 /* Divide m by pow5 and round. */
1099 z_memory = divide (m, pow5, &z);
1100 }
1101 }
1102 else
1103 {
1104 pow5.limbs = pow5_ptr;
1105 pow5.nlimbs = pow5_len;
1106 if (n >= 0)
1107 {
1108 /* n >= 0, s < 0.
1109 Multiply m with pow5, then divide by 2^|s|. */
1110 mpn_t numerator;
1111 mpn_t denominator;
1112 void *tmp_memory;
1113 tmp_memory = multiply (m, pow5, &numerator);
1114 if (tmp_memory == NULL)
1115 {
1116 free (pow5_ptr);
1117 free (memory);
1118 return NULL;
1119 }
1120 /* Construct 2^|s|. */
1121 {
1122 mp_limb_t *ptr = pow5_ptr + pow5_len;
1123 size_t i;
1124 for (i = 0; i < s_limbs; i++)
1125 ptr[i] = 0;
1126 ptr[s_limbs] = (mp_limb_t) 1 << s_bits;
1127 denominator.limbs = ptr;
1128 denominator.nlimbs = s_limbs + 1;
1129 }
1130 z_memory = divide (numerator, denominator, &z);
1131 free (tmp_memory);
1132 }
1133 else
1134 {
1135 /* n < 0, s > 0.
1136 Multiply m with 2^s, then divide by pow5. */
1137 mpn_t numerator;
1138 mp_limb_t *num_ptr;
1139 num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1)
1140 * sizeof (mp_limb_t));
1141 if (num_ptr == NULL)
1142 {
1143 free (pow5_ptr);
1144 free (memory);
1145 return NULL;
1146 }
1147 {
1148 mp_limb_t *destptr = num_ptr;
1149 {
1150 size_t i;
1151 for (i = 0; i < s_limbs; i++)
1152 *destptr++ = 0;
1153 }
1154 if (s_bits > 0)
1155 {
1156 const mp_limb_t *sourceptr = m.limbs;
1157 mp_twolimb_t accu = 0;
1158 size_t count;
1159 for (count = m.nlimbs; count > 0; count--)
1160 {
1161 accu += (mp_twolimb_t) *sourceptr++ << s_bits;
1162 *destptr++ = (mp_limb_t) accu;
1163 accu = accu >> GMP_LIMB_BITS;
1164 }
1165 if (accu > 0)
1166 *destptr++ = (mp_limb_t) accu;
1167 }
1168 else
1169 {
1170 const mp_limb_t *sourceptr = m.limbs;
1171 size_t count;
1172 for (count = m.nlimbs; count > 0; count--)
1173 *destptr++ = *sourceptr++;
1174 }
1175 numerator.limbs = num_ptr;
1176 numerator.nlimbs = destptr - num_ptr;
1177 }
1178 z_memory = divide (numerator, pow5, &z);
1179 free (num_ptr);
1180 }
1181 }
1182 free (pow5_ptr);
1183 free (memory);
1184
1185 /* Here y = round (x * 10^n) = z * 10^extra_zeroes. */
1186
1187 if (z_memory == NULL)
1188 return NULL;
1189 digits = convert_to_decimal (z, extra_zeroes);
1190 free (z_memory);
1191 return digits;
1192}
1193
1194# if NEED_PRINTF_LONG_DOUBLE
1195
1196/* Assuming x is finite and >= 0, and n is an integer:
1197 Returns the decimal representation of round (x * 10^n).
1198 Return the allocated memory - containing the decimal digits in low-to-high
1199 order, terminated with a NUL character - in case of success, NULL in case
1200 of memory allocation failure. */
1201static char *
1202scale10_round_decimal_long_double (long double x, int n)
1203{
1204 int e;
1205 mpn_t m;
1206 void *memory = decode_long_double (x, &e, &m);
1207 return scale10_round_decimal_decoded (e, m, memory, n);
1208}
1209
1210# endif
1211
1212# if NEED_PRINTF_DOUBLE
1213
1214/* Assuming x is finite and >= 0, and n is an integer:
1215 Returns the decimal representation of round (x * 10^n).
1216 Return the allocated memory - containing the decimal digits in low-to-high
1217 order, terminated with a NUL character - in case of success, NULL in case
1218 of memory allocation failure. */
1219static char *
1220scale10_round_decimal_double (double x, int n)
1221{
1222 int e;
1223 mpn_t m;
1224 void *memory = decode_double (x, &e, &m);
1225 return scale10_round_decimal_decoded (e, m, memory, n);
1226}
1227
1228# endif
1229
1230# if NEED_PRINTF_LONG_DOUBLE
1231
1232/* Assuming x is finite and > 0:
1233 Return an approximation for n with 10^n <= x < 10^(n+1).
1234 The approximation is usually the right n, but may be off by 1 sometimes. */
1235static int
1236floorlog10l (long double x)
1237{
1238 int exp;
1239 long double y;
1240 double z;
1241 double l;
1242
1243 /* Split into exponential part and mantissa. */
1244 y = frexpl (x, &exp);
1245 if (!(y >= 0.0L && y < 1.0L))
1246 abort ();
1247 if (y == 0.0L)
1248 return INT_MIN;
1249 if (y < 0.5L)
1250 {
1251 while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
1252 {
1253 y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
1254 exp -= GMP_LIMB_BITS;
1255 }
1256 if (y < (1.0L / (1 << 16)))
1257 {
1258 y *= 1.0L * (1 << 16);
1259 exp -= 16;
1260 }
1261 if (y < (1.0L / (1 << 8)))
1262 {
1263 y *= 1.0L * (1 << 8);
1264 exp -= 8;
1265 }
1266 if (y < (1.0L / (1 << 4)))
1267 {
1268 y *= 1.0L * (1 << 4);
1269 exp -= 4;
1270 }
1271 if (y < (1.0L / (1 << 2)))
1272 {
1273 y *= 1.0L * (1 << 2);
1274 exp -= 2;
1275 }
1276 if (y < (1.0L / (1 << 1)))
1277 {
1278 y *= 1.0L * (1 << 1);
1279 exp -= 1;
1280 }
1281 }
1282 if (!(y >= 0.5L && y < 1.0L))
1283 abort ();
1284 /* Compute an approximation for l = log2(x) = exp + log2(y). */
1285 l = exp;
1286 z = y;
1287 if (z < 0.70710678118654752444)
1288 {
1289 z *= 1.4142135623730950488;
1290 l -= 0.5;
1291 }
1292 if (z < 0.8408964152537145431)
1293 {
1294 z *= 1.1892071150027210667;
1295 l -= 0.25;
1296 }
1297 if (z < 0.91700404320467123175)
1298 {
1299 z *= 1.0905077326652576592;
1300 l -= 0.125;
1301 }
1302 if (z < 0.9576032806985736469)
1303 {
1304 z *= 1.0442737824274138403;
1305 l -= 0.0625;
1306 }
1307 /* Now 0.95 <= z <= 1.01. */
1308 z = 1 - z;
1309 /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ...
1310 Four terms are enough to get an approximation with error < 10^-7. */
1311 l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
1312 /* Finally multiply with log(2)/log(10), yields an approximation for
1313 log10(x). */
1314 l *= 0.30102999566398119523;
1315 /* Round down to the next integer. */
1316 return (int) l + (l < 0 ? -1 : 0);
1317}
1318
1319# endif
1320
1321# if NEED_PRINTF_DOUBLE
1322
1323/* Assuming x is finite and > 0:
1324 Return an approximation for n with 10^n <= x < 10^(n+1).
1325 The approximation is usually the right n, but may be off by 1 sometimes. */
1326static int
1327floorlog10 (double x)
1328{
1329 int exp;
1330 double y;
1331 double z;
1332 double l;
1333
1334 /* Split into exponential part and mantissa. */
1335 y = frexp (x, &exp);
1336 if (!(y >= 0.0 && y < 1.0))
1337 abort ();
1338 if (y == 0.0)
1339 return INT_MIN;
1340 if (y < 0.5)
1341 {
1342 while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
1343 {
1344 y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
1345 exp -= GMP_LIMB_BITS;
1346 }
1347 if (y < (1.0 / (1 << 16)))
1348 {
1349 y *= 1.0 * (1 << 16);
1350 exp -= 16;
1351 }
1352 if (y < (1.0 / (1 << 8)))
1353 {
1354 y *= 1.0 * (1 << 8);
1355 exp -= 8;
1356 }
1357 if (y < (1.0 / (1 << 4)))
1358 {
1359 y *= 1.0 * (1 << 4);
1360 exp -= 4;
1361 }
1362 if (y < (1.0 / (1 << 2)))
1363 {
1364 y *= 1.0 * (1 << 2);
1365 exp -= 2;
1366 }
1367 if (y < (1.0 / (1 << 1)))
1368 {
1369 y *= 1.0 * (1 << 1);
1370 exp -= 1;
1371 }
1372 }
1373 if (!(y >= 0.5 && y < 1.0))
1374 abort ();
1375 /* Compute an approximation for l = log2(x) = exp + log2(y). */
1376 l = exp;
1377 z = y;
1378 if (z < 0.70710678118654752444)
1379 {
1380 z *= 1.4142135623730950488;
1381 l -= 0.5;
1382 }
1383 if (z < 0.8408964152537145431)
1384 {
1385 z *= 1.1892071150027210667;
1386 l -= 0.25;
1387 }
1388 if (z < 0.91700404320467123175)
1389 {
1390 z *= 1.0905077326652576592;
1391 l -= 0.125;
1392 }
1393 if (z < 0.9576032806985736469)
1394 {
1395 z *= 1.0442737824274138403;
1396 l -= 0.0625;
1397 }
1398 /* Now 0.95 <= z <= 1.01. */
1399 z = 1 - z;
1400 /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ...
1401 Four terms are enough to get an approximation with error < 10^-7. */
1402 l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
1403 /* Finally multiply with log(2)/log(10), yields an approximation for
1404 log10(x). */
1405 l *= 0.30102999566398119523;
1406 /* Round down to the next integer. */
1407 return (int) l + (l < 0 ? -1 : 0);
1408}
1409
1410# endif
1411
1412#endif
1413
1414DCHAR_T *
1415VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1416 const FCHAR_T *format, va_list args)
1417{
1418 DIRECTIVES d;
1419 arguments a;
1420
1421 if (PRINTF_PARSE (format, &d, &a) < 0)
1422 /* errno is already set. */
1423 return NULL;
117 1424
118#define CLEANUP() \ 1425#define CLEANUP() \
119 free (d.dir); \ 1426 free (d.dir); \
120 if (a.arg) \ 1427 if (a.arg) \
121 free (a.arg); 1428 free (a.arg);
122 1429
123 if (printf_fetchargs (args, &a) < 0) 1430 if (PRINTF_FETCHARGS (args, &a) < 0)
124 { 1431 {
125 CLEANUP (); 1432 CLEANUP ();
126 errno = EINVAL; 1433 errno = EINVAL;
@@ -129,13 +1436,13 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
129 1436
130 { 1437 {
131 size_t buf_neededlength; 1438 size_t buf_neededlength;
132 CHAR_T *buf; 1439 TCHAR_T *buf;
133 CHAR_T *buf_malloced; 1440 TCHAR_T *buf_malloced;
134 const CHAR_T *cp; 1441 const FCHAR_T *cp;
135 size_t i; 1442 size_t i;
136 DIRECTIVE *dp; 1443 DIRECTIVE *dp;
137 /* Output string accumulator. */ 1444 /* Output string accumulator. */
138 CHAR_T *result; 1445 DCHAR_T *result;
139 size_t allocated; 1446 size_t allocated;
140 size_t length; 1447 size_t length;
141 1448
@@ -144,18 +1451,18 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
144 buf_neededlength = 1451 buf_neededlength =
145 xsum4 (7, d.max_width_length, d.max_precision_length, 6); 1452 xsum4 (7, d.max_width_length, d.max_precision_length, 6);
146#if HAVE_ALLOCA 1453#if HAVE_ALLOCA
147 if (buf_neededlength < 4000 / sizeof (CHAR_T)) 1454 if (buf_neededlength < 4000 / sizeof (TCHAR_T))
148 { 1455 {
149 buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T)); 1456 buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T));
150 buf_malloced = NULL; 1457 buf_malloced = NULL;
151 } 1458 }
152 else 1459 else
153#endif 1460#endif
154 { 1461 {
155 size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T)); 1462 size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T));
156 if (size_overflow_p (buf_memsize)) 1463 if (size_overflow_p (buf_memsize))
157 goto out_of_memory_1; 1464 goto out_of_memory_1;
158 buf = (CHAR_T *) malloc (buf_memsize); 1465 buf = (TCHAR_T *) malloc (buf_memsize);
159 if (buf == NULL) 1466 if (buf == NULL)
160 goto out_of_memory_1; 1467 goto out_of_memory_1;
161 buf_malloced = buf; 1468 buf_malloced = buf;
@@ -182,22 +1489,22 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
182 if ((needed) > allocated) \ 1489 if ((needed) > allocated) \
183 { \ 1490 { \
184 size_t memory_size; \ 1491 size_t memory_size; \
185 CHAR_T *memory; \ 1492 DCHAR_T *memory; \
186 \ 1493 \
187 allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ 1494 allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \
188 if ((needed) > allocated) \ 1495 if ((needed) > allocated) \
189 allocated = (needed); \ 1496 allocated = (needed); \
190 memory_size = xtimes (allocated, sizeof (CHAR_T)); \ 1497 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
191 if (size_overflow_p (memory_size)) \ 1498 if (size_overflow_p (memory_size)) \
192 goto out_of_memory; \ 1499 goto out_of_memory; \
193 if (result == resultbuf || result == NULL) \ 1500 if (result == resultbuf || result == NULL) \
194 memory = (CHAR_T *) malloc (memory_size); \ 1501 memory = (DCHAR_T *) malloc (memory_size); \
195 else \ 1502 else \
196 memory = (CHAR_T *) realloc (result, memory_size); \ 1503 memory = (DCHAR_T *) realloc (result, memory_size); \
197 if (memory == NULL) \ 1504 if (memory == NULL) \
198 goto out_of_memory; \ 1505 goto out_of_memory; \
199 if (result == resultbuf && length > 0) \ 1506 if (result == resultbuf && length > 0) \
200 memcpy (memory, result, length * sizeof (CHAR_T)); \ 1507 DCHAR_CPY (memory, result, length); \
201 result = memory; \ 1508 result = memory; \
202 } 1509 }
203 1510
@@ -209,8 +1516,20 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
209 size_t augmented_length = xsum (length, n); 1516 size_t augmented_length = xsum (length, n);
210 1517
211 ENSURE_ALLOCATION (augmented_length); 1518 ENSURE_ALLOCATION (augmented_length);
212 memcpy (result + length, cp, n * sizeof (CHAR_T)); 1519 /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we
213 length = augmented_length; 1520 need that the format string contains only ASCII characters
1521 if FCHAR_T and DCHAR_T are not the same type. */
1522 if (sizeof (FCHAR_T) == sizeof (DCHAR_T))
1523 {
1524 DCHAR_CPY (result + length, (const DCHAR_T *) cp, n);
1525 length = augmented_length;
1526 }
1527 else
1528 {
1529 do
1530 result[length++] = (unsigned char) *cp++;
1531 while (--n > 0);
1532 }
214 } 1533 }
215 if (i == d.count) 1534 if (i == d.count)
216 break; 1535 break;
@@ -248,7 +1567,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
248 case TYPE_COUNT_LONGINT_POINTER: 1567 case TYPE_COUNT_LONGINT_POINTER:
249 *a.arg[dp->arg_index].a.a_count_longint_pointer = length; 1568 *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
250 break; 1569 break;
251#ifdef HAVE_LONG_LONG_INT 1570#if HAVE_LONG_LONG_INT
252 case TYPE_COUNT_LONGLONGINT_POINTER: 1571 case TYPE_COUNT_LONGLONGINT_POINTER:
253 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; 1572 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
254 break; 1573 break;
@@ -257,72 +1576,2100 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
257 abort (); 1576 abort ();
258 } 1577 }
259 } 1578 }
260 else 1579#if ENABLE_UNISTDIO
1580 /* The unistdio extensions. */
1581 else if (dp->conversion == 'U')
261 { 1582 {
262 arg_type type = a.arg[dp->arg_index].type; 1583 arg_type type = a.arg[dp->arg_index].type;
263 CHAR_T *p; 1584 int flags = dp->flags;
264 unsigned int prefix_count; 1585 int has_width;
265 int prefixes[2]; 1586 size_t width;
266#if !USE_SNPRINTF 1587 int has_precision;
267 size_t tmp_length; 1588 size_t precision;
268 CHAR_T tmpbuf[700];
269 CHAR_T *tmp;
270 1589
271 /* Allocate a temporary buffer of sufficient size for calling 1590 has_width = 0;
272 sprintf. */ 1591 width = 0;
273 { 1592 if (dp->width_start != dp->width_end)
274 size_t width; 1593 {
275 size_t precision; 1594 if (dp->width_arg_index != ARG_NONE)
1595 {
1596 int arg;
276 1597
277 width = 0; 1598 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
278 if (dp->width_start != dp->width_end) 1599 abort ();
1600 arg = a.arg[dp->width_arg_index].a.a_int;
1601 if (arg < 0)
1602 {
1603 /* "A negative field width is taken as a '-' flag
1604 followed by a positive field width." */
1605 flags |= FLAG_LEFT;
1606 width = (unsigned int) (-arg);
1607 }
1608 else
1609 width = arg;
1610 }
1611 else
1612 {
1613 const FCHAR_T *digitp = dp->width_start;
1614
1615 do
1616 width = xsum (xtimes (width, 10), *digitp++ - '0');
1617 while (digitp != dp->width_end);
1618 }
1619 has_width = 1;
1620 }
1621
1622 has_precision = 0;
1623 precision = 0;
1624 if (dp->precision_start != dp->precision_end)
1625 {
1626 if (dp->precision_arg_index != ARG_NONE)
1627 {
1628 int arg;
1629
1630 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
1631 abort ();
1632 arg = a.arg[dp->precision_arg_index].a.a_int;
1633 /* "A negative precision is taken as if the precision
1634 were omitted." */
1635 if (arg >= 0)
1636 {
1637 precision = arg;
1638 has_precision = 1;
1639 }
1640 }
1641 else
1642 {
1643 const FCHAR_T *digitp = dp->precision_start + 1;
1644
1645 precision = 0;
1646 while (digitp != dp->precision_end)
1647 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
1648 has_precision = 1;
1649 }
1650 }
1651
1652 switch (type)
1653 {
1654 case TYPE_U8_STRING:
279 { 1655 {
280 if (dp->width_arg_index != ARG_NONE) 1656 const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string;
281 { 1657 const uint8_t *arg_end;
282 int arg; 1658 size_t characters;
283 1659
284 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 1660 if (has_precision)
285 abort (); 1661 {
286 arg = a.arg[dp->width_arg_index].a.a_int; 1662 /* Use only PRECISION characters, from the left. */
287 width = (arg < 0 ? (unsigned int) (-arg) : arg); 1663 arg_end = arg;
1664 characters = 0;
1665 for (; precision > 0; precision--)
1666 {
1667 int count = u8_strmblen (arg_end);
1668 if (count == 0)
1669 break;
1670 if (count < 0)
1671 {
1672 if (!(result == resultbuf || result == NULL))
1673 free (result);
1674 if (buf_malloced != NULL)
1675 free (buf_malloced);
1676 CLEANUP ();
1677 errno = EILSEQ;
1678 return NULL;
1679 }
1680 arg_end += count;
1681 characters++;
1682 }
1683 }
1684 else if (has_width)
1685 {
1686 /* Use the entire string, and count the number of
1687 characters. */
1688 arg_end = arg;
1689 characters = 0;
1690 for (;;)
1691 {
1692 int count = u8_strmblen (arg_end);
1693 if (count == 0)
1694 break;
1695 if (count < 0)
1696 {
1697 if (!(result == resultbuf || result == NULL))
1698 free (result);
1699 if (buf_malloced != NULL)
1700 free (buf_malloced);
1701 CLEANUP ();
1702 errno = EILSEQ;
1703 return NULL;
1704 }
1705 arg_end += count;
1706 characters++;
1707 }
288 } 1708 }
289 else 1709 else
290 { 1710 {
291 const CHAR_T *digitp = dp->width_start; 1711 /* Use the entire string. */
1712 arg_end = arg + u8_strlen (arg);
1713 /* The number of characters doesn't matter. */
1714 characters = 0;
1715 }
292 1716
293 do 1717 if (has_width && width > characters
294 width = xsum (xtimes (width, 10), *digitp++ - '0'); 1718 && !(dp->flags & FLAG_LEFT))
295 while (digitp != dp->width_end); 1719 {
1720 size_t n = width - characters;
1721 ENSURE_ALLOCATION (xsum (length, n));
1722 DCHAR_SET (result + length, ' ', n);
1723 length += n;
1724 }
1725
1726# if DCHAR_IS_UINT8_T
1727 {
1728 size_t n = arg_end - arg;
1729 ENSURE_ALLOCATION (xsum (length, n));
1730 DCHAR_CPY (result + length, arg, n);
1731 length += n;
1732 }
1733# else
1734 { /* Convert. */
1735 DCHAR_T *converted = result + length;
1736 size_t converted_len = allocated - length;
1737# if DCHAR_IS_TCHAR
1738 /* Convert from UTF-8 to locale encoding. */
1739 if (u8_conv_to_encoding (locale_charset (),
1740 iconveh_question_mark,
1741 arg, arg_end - arg, NULL,
1742 &converted, &converted_len)
1743 < 0)
1744# else
1745 /* Convert from UTF-8 to UTF-16/UTF-32. */
1746 converted =
1747 U8_TO_DCHAR (arg, arg_end - arg,
1748 converted, &converted_len);
1749 if (converted == NULL)
1750# endif
1751 {
1752 int saved_errno = errno;
1753 if (!(result == resultbuf || result == NULL))
1754 free (result);
1755 if (buf_malloced != NULL)
1756 free (buf_malloced);
1757 CLEANUP ();
1758 errno = saved_errno;
1759 return NULL;
1760 }
1761 if (converted != result + length)
1762 {
1763 ENSURE_ALLOCATION (xsum (length, converted_len));
1764 DCHAR_CPY (result + length, converted, converted_len);
1765 free (converted);
1766 }
1767 length += converted_len;
1768 }
1769# endif
1770
1771 if (has_width && width > characters
1772 && (dp->flags & FLAG_LEFT))
1773 {
1774 size_t n = width - characters;
1775 ENSURE_ALLOCATION (xsum (length, n));
1776 DCHAR_SET (result + length, ' ', n);
1777 length += n;
296 } 1778 }
297 } 1779 }
1780 break;
298 1781
299 precision = 6; 1782 case TYPE_U16_STRING:
300 if (dp->precision_start != dp->precision_end)
301 { 1783 {
302 if (dp->precision_arg_index != ARG_NONE) 1784 const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string;
1785 const uint16_t *arg_end;
1786 size_t characters;
1787
1788 if (has_precision)
1789 {
1790 /* Use only PRECISION characters, from the left. */
1791 arg_end = arg;
1792 characters = 0;
1793 for (; precision > 0; precision--)
1794 {
1795 int count = u16_strmblen (arg_end);
1796 if (count == 0)
1797 break;
1798 if (count < 0)
1799 {
1800 if (!(result == resultbuf || result == NULL))
1801 free (result);
1802 if (buf_malloced != NULL)
1803 free (buf_malloced);
1804 CLEANUP ();
1805 errno = EILSEQ;
1806 return NULL;
1807 }
1808 arg_end += count;
1809 characters++;
1810 }
1811 }
1812 else if (has_width)
303 { 1813 {
304 int arg; 1814 /* Use the entire string, and count the number of
1815 characters. */
1816 arg_end = arg;
1817 characters = 0;
1818 for (;;)
1819 {
1820 int count = u16_strmblen (arg_end);
1821 if (count == 0)
1822 break;
1823 if (count < 0)
1824 {
1825 if (!(result == resultbuf || result == NULL))
1826 free (result);
1827 if (buf_malloced != NULL)
1828 free (buf_malloced);
1829 CLEANUP ();
1830 errno = EILSEQ;
1831 return NULL;
1832 }
1833 arg_end += count;
1834 characters++;
1835 }
1836 }
1837 else
1838 {
1839 /* Use the entire string. */
1840 arg_end = arg + u16_strlen (arg);
1841 /* The number of characters doesn't matter. */
1842 characters = 0;
1843 }
305 1844
306 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) 1845 if (has_width && width > characters
307 abort (); 1846 && !(dp->flags & FLAG_LEFT))
308 arg = a.arg[dp->precision_arg_index].a.a_int; 1847 {
309 precision = (arg < 0 ? 0 : arg); 1848 size_t n = width - characters;
1849 ENSURE_ALLOCATION (xsum (length, n));
1850 DCHAR_SET (result + length, ' ', n);
1851 length += n;
1852 }
1853
1854# if DCHAR_IS_UINT16_T
1855 {
1856 size_t n = arg_end - arg;
1857 ENSURE_ALLOCATION (xsum (length, n));
1858 DCHAR_CPY (result + length, arg, n);
1859 length += n;
1860 }
1861# else
1862 { /* Convert. */
1863 DCHAR_T *converted = result + length;
1864 size_t converted_len = allocated - length;
1865# if DCHAR_IS_TCHAR
1866 /* Convert from UTF-16 to locale encoding. */
1867 if (u16_conv_to_encoding (locale_charset (),
1868 iconveh_question_mark,
1869 arg, arg_end - arg, NULL,
1870 &converted, &converted_len)
1871 < 0)
1872# else
1873 /* Convert from UTF-16 to UTF-8/UTF-32. */
1874 converted =
1875 U16_TO_DCHAR (arg, arg_end - arg,
1876 converted, &converted_len);
1877 if (converted == NULL)
1878# endif
1879 {
1880 int saved_errno = errno;
1881 if (!(result == resultbuf || result == NULL))
1882 free (result);
1883 if (buf_malloced != NULL)
1884 free (buf_malloced);
1885 CLEANUP ();
1886 errno = saved_errno;
1887 return NULL;
1888 }
1889 if (converted != result + length)
1890 {
1891 ENSURE_ALLOCATION (xsum (length, converted_len));
1892 DCHAR_CPY (result + length, converted, converted_len);
1893 free (converted);
1894 }
1895 length += converted_len;
1896 }
1897# endif
1898
1899 if (has_width && width > characters
1900 && (dp->flags & FLAG_LEFT))
1901 {
1902 size_t n = width - characters;
1903 ENSURE_ALLOCATION (xsum (length, n));
1904 DCHAR_SET (result + length, ' ', n);
1905 length += n;
1906 }
1907 }
1908 break;
1909
1910 case TYPE_U32_STRING:
1911 {
1912 const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string;
1913 const uint32_t *arg_end;
1914 size_t characters;
1915
1916 if (has_precision)
1917 {
1918 /* Use only PRECISION characters, from the left. */
1919 arg_end = arg;
1920 characters = 0;
1921 for (; precision > 0; precision--)
1922 {
1923 int count = u32_strmblen (arg_end);
1924 if (count == 0)
1925 break;
1926 if (count < 0)
1927 {
1928 if (!(result == resultbuf || result == NULL))
1929 free (result);
1930 if (buf_malloced != NULL)
1931 free (buf_malloced);
1932 CLEANUP ();
1933 errno = EILSEQ;
1934 return NULL;
1935 }
1936 arg_end += count;
1937 characters++;
1938 }
1939 }
1940 else if (has_width)
1941 {
1942 /* Use the entire string, and count the number of
1943 characters. */
1944 arg_end = arg;
1945 characters = 0;
1946 for (;;)
1947 {
1948 int count = u32_strmblen (arg_end);
1949 if (count == 0)
1950 break;
1951 if (count < 0)
1952 {
1953 if (!(result == resultbuf || result == NULL))
1954 free (result);
1955 if (buf_malloced != NULL)
1956 free (buf_malloced);
1957 CLEANUP ();
1958 errno = EILSEQ;
1959 return NULL;
1960 }
1961 arg_end += count;
1962 characters++;
1963 }
310 } 1964 }
311 else 1965 else
312 { 1966 {
313 const CHAR_T *digitp = dp->precision_start + 1; 1967 /* Use the entire string. */
1968 arg_end = arg + u32_strlen (arg);
1969 /* The number of characters doesn't matter. */
1970 characters = 0;
1971 }
314 1972
315 precision = 0; 1973 if (has_width && width > characters
316 while (digitp != dp->precision_end) 1974 && !(dp->flags & FLAG_LEFT))
317 precision = xsum (xtimes (precision, 10), *digitp++ - '0'); 1975 {
1976 size_t n = width - characters;
1977 ENSURE_ALLOCATION (xsum (length, n));
1978 DCHAR_SET (result + length, ' ', n);
1979 length += n;
1980 }
1981
1982# if DCHAR_IS_UINT32_T
1983 {
1984 size_t n = arg_end - arg;
1985 ENSURE_ALLOCATION (xsum (length, n));
1986 DCHAR_CPY (result + length, arg, n);
1987 length += n;
1988 }
1989# else
1990 { /* Convert. */
1991 DCHAR_T *converted = result + length;
1992 size_t converted_len = allocated - length;
1993# if DCHAR_IS_TCHAR
1994 /* Convert from UTF-32 to locale encoding. */
1995 if (u32_conv_to_encoding (locale_charset (),
1996 iconveh_question_mark,
1997 arg, arg_end - arg, NULL,
1998 &converted, &converted_len)
1999 < 0)
2000# else
2001 /* Convert from UTF-32 to UTF-8/UTF-16. */
2002 converted =
2003 U32_TO_DCHAR (arg, arg_end - arg,
2004 converted, &converted_len);
2005 if (converted == NULL)
2006# endif
2007 {
2008 int saved_errno = errno;
2009 if (!(result == resultbuf || result == NULL))
2010 free (result);
2011 if (buf_malloced != NULL)
2012 free (buf_malloced);
2013 CLEANUP ();
2014 errno = saved_errno;
2015 return NULL;
2016 }
2017 if (converted != result + length)
2018 {
2019 ENSURE_ALLOCATION (xsum (length, converted_len));
2020 DCHAR_CPY (result + length, converted, converted_len);
2021 free (converted);
2022 }
2023 length += converted_len;
2024 }
2025# endif
2026
2027 if (has_width && width > characters
2028 && (dp->flags & FLAG_LEFT))
2029 {
2030 size_t n = width - characters;
2031 ENSURE_ALLOCATION (xsum (length, n));
2032 DCHAR_SET (result + length, ' ', n);
2033 length += n;
318 } 2034 }
319 } 2035 }
2036 break;
320 2037
2038 default:
2039 abort ();
2040 }
2041 }
2042#endif
2043#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
2044 else if ((dp->conversion == 'a' || dp->conversion == 'A')
2045# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
2046 && (0
2047# if NEED_PRINTF_DOUBLE
2048 || a.arg[dp->arg_index].type == TYPE_DOUBLE
2049# endif
2050# if NEED_PRINTF_LONG_DOUBLE
2051 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
2052# endif
2053 )
2054# endif
2055 )
2056 {
2057 arg_type type = a.arg[dp->arg_index].type;
2058 int flags = dp->flags;
2059 int has_width;
2060 size_t width;
2061 int has_precision;
2062 size_t precision;
2063 size_t tmp_length;
2064 DCHAR_T tmpbuf[700];
2065 DCHAR_T *tmp;
2066 DCHAR_T *pad_ptr;
2067 DCHAR_T *p;
2068
2069 has_width = 0;
2070 width = 0;
2071 if (dp->width_start != dp->width_end)
2072 {
2073 if (dp->width_arg_index != ARG_NONE)
2074 {
2075 int arg;
2076
2077 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2078 abort ();
2079 arg = a.arg[dp->width_arg_index].a.a_int;
2080 if (arg < 0)
2081 {
2082 /* "A negative field width is taken as a '-' flag
2083 followed by a positive field width." */
2084 flags |= FLAG_LEFT;
2085 width = (unsigned int) (-arg);
2086 }
2087 else
2088 width = arg;
2089 }
2090 else
2091 {
2092 const FCHAR_T *digitp = dp->width_start;
2093
2094 do
2095 width = xsum (xtimes (width, 10), *digitp++ - '0');
2096 while (digitp != dp->width_end);
2097 }
2098 has_width = 1;
2099 }
2100
2101 has_precision = 0;
2102 precision = 0;
2103 if (dp->precision_start != dp->precision_end)
2104 {
2105 if (dp->precision_arg_index != ARG_NONE)
2106 {
2107 int arg;
2108
2109 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
2110 abort ();
2111 arg = a.arg[dp->precision_arg_index].a.a_int;
2112 /* "A negative precision is taken as if the precision
2113 were omitted." */
2114 if (arg >= 0)
2115 {
2116 precision = arg;
2117 has_precision = 1;
2118 }
2119 }
2120 else
2121 {
2122 const FCHAR_T *digitp = dp->precision_start + 1;
2123
2124 precision = 0;
2125 while (digitp != dp->precision_end)
2126 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
2127 has_precision = 1;
2128 }
2129 }
2130
2131 /* Allocate a temporary buffer of sufficient size. */
2132 if (type == TYPE_LONGDOUBLE)
2133 tmp_length =
2134 (unsigned int) ((LDBL_DIG + 1)
2135 * 0.831 /* decimal -> hexadecimal */
2136 )
2137 + 1; /* turn floor into ceil */
2138 else
2139 tmp_length =
2140 (unsigned int) ((DBL_DIG + 1)
2141 * 0.831 /* decimal -> hexadecimal */
2142 )
2143 + 1; /* turn floor into ceil */
2144 if (tmp_length < precision)
2145 tmp_length = precision;
2146 /* Account for sign, decimal point etc. */
2147 tmp_length = xsum (tmp_length, 12);
2148
2149 if (tmp_length < width)
2150 tmp_length = width;
2151
2152 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
2153
2154 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
2155 tmp = tmpbuf;
2156 else
2157 {
2158 size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
2159
2160 if (size_overflow_p (tmp_memsize))
2161 /* Overflow, would lead to out of memory. */
2162 goto out_of_memory;
2163 tmp = (DCHAR_T *) malloc (tmp_memsize);
2164 if (tmp == NULL)
2165 /* Out of memory. */
2166 goto out_of_memory;
2167 }
2168
2169 pad_ptr = NULL;
2170 p = tmp;
2171 if (type == TYPE_LONGDOUBLE)
2172 {
2173# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE
2174 long double arg = a.arg[dp->arg_index].a.a_longdouble;
2175
2176 if (isnanl (arg))
2177 {
2178 if (dp->conversion == 'A')
2179 {
2180 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
2181 }
2182 else
2183 {
2184 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
2185 }
2186 }
2187 else
2188 {
2189 int sign = 0;
2190 DECL_LONG_DOUBLE_ROUNDING
2191
2192 BEGIN_LONG_DOUBLE_ROUNDING ();
2193
2194 if (signbit (arg)) /* arg < 0.0L or negative zero */
2195 {
2196 sign = -1;
2197 arg = -arg;
2198 }
2199
2200 if (sign < 0)
2201 *p++ = '-';
2202 else if (flags & FLAG_SHOWSIGN)
2203 *p++ = '+';
2204 else if (flags & FLAG_SPACE)
2205 *p++ = ' ';
2206
2207 if (arg > 0.0L && arg + arg == arg)
2208 {
2209 if (dp->conversion == 'A')
2210 {
2211 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
2212 }
2213 else
2214 {
2215 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
2216 }
2217 }
2218 else
2219 {
2220 int exponent;
2221 long double mantissa;
2222
2223 if (arg > 0.0L)
2224 mantissa = printf_frexpl (arg, &exponent);
2225 else
2226 {
2227 exponent = 0;
2228 mantissa = 0.0L;
2229 }
2230
2231 if (has_precision
2232 && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1)
2233 {
2234 /* Round the mantissa. */
2235 long double tail = mantissa;
2236 size_t q;
2237
2238 for (q = precision; ; q--)
2239 {
2240 int digit = (int) tail;
2241 tail -= digit;
2242 if (q == 0)
2243 {
2244 if (digit & 1 ? tail >= 0.5L : tail > 0.5L)
2245 tail = 1 - tail;
2246 else
2247 tail = - tail;
2248 break;
2249 }
2250 tail *= 16.0L;
2251 }
2252 if (tail != 0.0L)
2253 for (q = precision; q > 0; q--)
2254 tail *= 0.0625L;
2255 mantissa += tail;
2256 }
2257
2258 *p++ = '0';
2259 *p++ = dp->conversion - 'A' + 'X';
2260 pad_ptr = p;
2261 {
2262 int digit;
2263
2264 digit = (int) mantissa;
2265 mantissa -= digit;
2266 *p++ = '0' + digit;
2267 if ((flags & FLAG_ALT)
2268 || mantissa > 0.0L || precision > 0)
2269 {
2270 *p++ = decimal_point_char ();
2271 /* This loop terminates because we assume
2272 that FLT_RADIX is a power of 2. */
2273 while (mantissa > 0.0L)
2274 {
2275 mantissa *= 16.0L;
2276 digit = (int) mantissa;
2277 mantissa -= digit;
2278 *p++ = digit
2279 + (digit < 10
2280 ? '0'
2281 : dp->conversion - 10);
2282 if (precision > 0)
2283 precision--;
2284 }
2285 while (precision > 0)
2286 {
2287 *p++ = '0';
2288 precision--;
2289 }
2290 }
2291 }
2292 *p++ = dp->conversion - 'A' + 'P';
2293# if WIDE_CHAR_VERSION
2294 {
2295 static const wchar_t decimal_format[] =
2296 { '%', '+', 'd', '\0' };
2297 SNPRINTF (p, 6 + 1, decimal_format, exponent);
2298 }
2299 while (*p != '\0')
2300 p++;
2301# else
2302 if (sizeof (DCHAR_T) == 1)
2303 {
2304 sprintf ((char *) p, "%+d", exponent);
2305 while (*p != '\0')
2306 p++;
2307 }
2308 else
2309 {
2310 char expbuf[6 + 1];
2311 const char *ep;
2312 sprintf (expbuf, "%+d", exponent);
2313 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
2314 p++;
2315 }
2316# endif
2317 }
2318
2319 END_LONG_DOUBLE_ROUNDING ();
2320 }
2321# else
2322 abort ();
2323# endif
2324 }
2325 else
2326 {
2327# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE
2328 double arg = a.arg[dp->arg_index].a.a_double;
2329
2330 if (isnand (arg))
2331 {
2332 if (dp->conversion == 'A')
2333 {
2334 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
2335 }
2336 else
2337 {
2338 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
2339 }
2340 }
2341 else
2342 {
2343 int sign = 0;
2344
2345 if (signbit (arg)) /* arg < 0.0 or negative zero */
2346 {
2347 sign = -1;
2348 arg = -arg;
2349 }
2350
2351 if (sign < 0)
2352 *p++ = '-';
2353 else if (flags & FLAG_SHOWSIGN)
2354 *p++ = '+';
2355 else if (flags & FLAG_SPACE)
2356 *p++ = ' ';
2357
2358 if (arg > 0.0 && arg + arg == arg)
2359 {
2360 if (dp->conversion == 'A')
2361 {
2362 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
2363 }
2364 else
2365 {
2366 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
2367 }
2368 }
2369 else
2370 {
2371 int exponent;
2372 double mantissa;
2373
2374 if (arg > 0.0)
2375 mantissa = printf_frexp (arg, &exponent);
2376 else
2377 {
2378 exponent = 0;
2379 mantissa = 0.0;
2380 }
2381
2382 if (has_precision
2383 && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1)
2384 {
2385 /* Round the mantissa. */
2386 double tail = mantissa;
2387 size_t q;
2388
2389 for (q = precision; ; q--)
2390 {
2391 int digit = (int) tail;
2392 tail -= digit;
2393 if (q == 0)
2394 {
2395 if (digit & 1 ? tail >= 0.5 : tail > 0.5)
2396 tail = 1 - tail;
2397 else
2398 tail = - tail;
2399 break;
2400 }
2401 tail *= 16.0;
2402 }
2403 if (tail != 0.0)
2404 for (q = precision; q > 0; q--)
2405 tail *= 0.0625;
2406 mantissa += tail;
2407 }
2408
2409 *p++ = '0';
2410 *p++ = dp->conversion - 'A' + 'X';
2411 pad_ptr = p;
2412 {
2413 int digit;
2414
2415 digit = (int) mantissa;
2416 mantissa -= digit;
2417 *p++ = '0' + digit;
2418 if ((flags & FLAG_ALT)
2419 || mantissa > 0.0 || precision > 0)
2420 {
2421 *p++ = decimal_point_char ();
2422 /* This loop terminates because we assume
2423 that FLT_RADIX is a power of 2. */
2424 while (mantissa > 0.0)
2425 {
2426 mantissa *= 16.0;
2427 digit = (int) mantissa;
2428 mantissa -= digit;
2429 *p++ = digit
2430 + (digit < 10
2431 ? '0'
2432 : dp->conversion - 10);
2433 if (precision > 0)
2434 precision--;
2435 }
2436 while (precision > 0)
2437 {
2438 *p++ = '0';
2439 precision--;
2440 }
2441 }
2442 }
2443 *p++ = dp->conversion - 'A' + 'P';
2444# if WIDE_CHAR_VERSION
2445 {
2446 static const wchar_t decimal_format[] =
2447 { '%', '+', 'd', '\0' };
2448 SNPRINTF (p, 6 + 1, decimal_format, exponent);
2449 }
2450 while (*p != '\0')
2451 p++;
2452# else
2453 if (sizeof (DCHAR_T) == 1)
2454 {
2455 sprintf ((char *) p, "%+d", exponent);
2456 while (*p != '\0')
2457 p++;
2458 }
2459 else
2460 {
2461 char expbuf[6 + 1];
2462 const char *ep;
2463 sprintf (expbuf, "%+d", exponent);
2464 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
2465 p++;
2466 }
2467# endif
2468 }
2469 }
2470# else
2471 abort ();
2472# endif
2473 }
2474 /* The generated string now extends from tmp to p, with the
2475 zero padding insertion point being at pad_ptr. */
2476 if (has_width && p - tmp < width)
2477 {
2478 size_t pad = width - (p - tmp);
2479 DCHAR_T *end = p + pad;
2480
2481 if (flags & FLAG_LEFT)
2482 {
2483 /* Pad with spaces on the right. */
2484 for (; pad > 0; pad--)
2485 *p++ = ' ';
2486 }
2487 else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
2488 {
2489 /* Pad with zeroes. */
2490 DCHAR_T *q = end;
2491
2492 while (p > pad_ptr)
2493 *--q = *--p;
2494 for (; pad > 0; pad--)
2495 *p++ = '0';
2496 }
2497 else
2498 {
2499 /* Pad with spaces on the left. */
2500 DCHAR_T *q = end;
2501
2502 while (p > tmp)
2503 *--q = *--p;
2504 for (; pad > 0; pad--)
2505 *p++ = ' ';
2506 }
2507
2508 p = end;
2509 }
2510
2511 {
2512 size_t count = p - tmp;
2513
2514 if (count >= tmp_length)
2515 /* tmp_length was incorrectly calculated - fix the
2516 code above! */
2517 abort ();
2518
2519 /* Make room for the result. */
2520 if (count >= allocated - length)
2521 {
2522 size_t n = xsum (length, count);
2523
2524 ENSURE_ALLOCATION (n);
2525 }
2526
2527 /* Append the result. */
2528 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
2529 if (tmp != tmpbuf)
2530 free (tmp);
2531 length += count;
2532 }
2533 }
2534#endif
2535#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
2536 else if ((dp->conversion == 'f' || dp->conversion == 'F'
2537 || dp->conversion == 'e' || dp->conversion == 'E'
2538 || dp->conversion == 'g' || dp->conversion == 'G'
2539 || dp->conversion == 'a' || dp->conversion == 'A')
2540 && (0
2541# if NEED_PRINTF_DOUBLE
2542 || a.arg[dp->arg_index].type == TYPE_DOUBLE
2543# elif NEED_PRINTF_INFINITE_DOUBLE
2544 || (a.arg[dp->arg_index].type == TYPE_DOUBLE
2545 /* The systems (mingw) which produce wrong output
2546 for Inf, -Inf, and NaN also do so for -0.0.
2547 Therefore we treat this case here as well. */
2548 && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double))
2549# endif
2550# if NEED_PRINTF_LONG_DOUBLE
2551 || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
2552# elif NEED_PRINTF_INFINITE_LONG_DOUBLE
2553 || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
2554 /* Some systems produce wrong output for Inf,
2555 -Inf, and NaN. */
2556 && is_infinitel (a.arg[dp->arg_index].a.a_longdouble))
2557# endif
2558 ))
2559 {
2560# if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE)
2561 arg_type type = a.arg[dp->arg_index].type;
2562# endif
2563 int flags = dp->flags;
2564 int has_width;
2565 size_t width;
2566 int has_precision;
2567 size_t precision;
2568 size_t tmp_length;
2569 DCHAR_T tmpbuf[700];
2570 DCHAR_T *tmp;
2571 DCHAR_T *pad_ptr;
2572 DCHAR_T *p;
2573
2574 has_width = 0;
2575 width = 0;
2576 if (dp->width_start != dp->width_end)
2577 {
2578 if (dp->width_arg_index != ARG_NONE)
2579 {
2580 int arg;
2581
2582 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2583 abort ();
2584 arg = a.arg[dp->width_arg_index].a.a_int;
2585 if (arg < 0)
2586 {
2587 /* "A negative field width is taken as a '-' flag
2588 followed by a positive field width." */
2589 flags |= FLAG_LEFT;
2590 width = (unsigned int) (-arg);
2591 }
2592 else
2593 width = arg;
2594 }
2595 else
2596 {
2597 const FCHAR_T *digitp = dp->width_start;
2598
2599 do
2600 width = xsum (xtimes (width, 10), *digitp++ - '0');
2601 while (digitp != dp->width_end);
2602 }
2603 has_width = 1;
2604 }
2605
2606 has_precision = 0;
2607 precision = 0;
2608 if (dp->precision_start != dp->precision_end)
2609 {
2610 if (dp->precision_arg_index != ARG_NONE)
2611 {
2612 int arg;
2613
2614 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
2615 abort ();
2616 arg = a.arg[dp->precision_arg_index].a.a_int;
2617 /* "A negative precision is taken as if the precision
2618 were omitted." */
2619 if (arg >= 0)
2620 {
2621 precision = arg;
2622 has_precision = 1;
2623 }
2624 }
2625 else
2626 {
2627 const FCHAR_T *digitp = dp->precision_start + 1;
2628
2629 precision = 0;
2630 while (digitp != dp->precision_end)
2631 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
2632 has_precision = 1;
2633 }
2634 }
2635
2636 /* POSIX specifies the default precision to be 6 for %f, %F,
2637 %e, %E, but not for %g, %G. Implementations appear to use
2638 the same default precision also for %g, %G. */
2639 if (!has_precision)
2640 precision = 6;
2641
2642 /* Allocate a temporary buffer of sufficient size. */
2643# if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE
2644 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1);
2645# elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE
2646 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0);
2647# elif NEED_PRINTF_LONG_DOUBLE
2648 tmp_length = LDBL_DIG + 1;
2649# elif NEED_PRINTF_DOUBLE
2650 tmp_length = DBL_DIG + 1;
2651# else
2652 tmp_length = 0;
2653# endif
2654 if (tmp_length < precision)
2655 tmp_length = precision;
2656# if NEED_PRINTF_LONG_DOUBLE
2657# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
2658 if (type == TYPE_LONGDOUBLE)
2659# endif
2660 if (dp->conversion == 'f' || dp->conversion == 'F')
2661 {
2662 long double arg = a.arg[dp->arg_index].a.a_longdouble;
2663 if (!(isnanl (arg) || arg + arg == arg))
2664 {
2665 /* arg is finite and nonzero. */
2666 int exponent = floorlog10l (arg < 0 ? -arg : arg);
2667 if (exponent >= 0 && tmp_length < exponent + precision)
2668 tmp_length = exponent + precision;
2669 }
2670 }
2671# endif
2672# if NEED_PRINTF_DOUBLE
2673# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
2674 if (type == TYPE_DOUBLE)
2675# endif
2676 if (dp->conversion == 'f' || dp->conversion == 'F')
2677 {
2678 double arg = a.arg[dp->arg_index].a.a_double;
2679 if (!(isnand (arg) || arg + arg == arg))
2680 {
2681 /* arg is finite and nonzero. */
2682 int exponent = floorlog10 (arg < 0 ? -arg : arg);
2683 if (exponent >= 0 && tmp_length < exponent + precision)
2684 tmp_length = exponent + precision;
2685 }
2686 }
2687# endif
2688 /* Account for sign, decimal point etc. */
2689 tmp_length = xsum (tmp_length, 12);
2690
2691 if (tmp_length < width)
2692 tmp_length = width;
2693
2694 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
2695
2696 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
2697 tmp = tmpbuf;
2698 else
2699 {
2700 size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
2701
2702 if (size_overflow_p (tmp_memsize))
2703 /* Overflow, would lead to out of memory. */
2704 goto out_of_memory;
2705 tmp = (DCHAR_T *) malloc (tmp_memsize);
2706 if (tmp == NULL)
2707 /* Out of memory. */
2708 goto out_of_memory;
2709 }
2710
2711 pad_ptr = NULL;
2712 p = tmp;
2713
2714# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
2715# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
2716 if (type == TYPE_LONGDOUBLE)
2717# endif
2718 {
2719 long double arg = a.arg[dp->arg_index].a.a_longdouble;
2720
2721 if (isnanl (arg))
2722 {
2723 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
2724 {
2725 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
2726 }
2727 else
2728 {
2729 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
2730 }
2731 }
2732 else
2733 {
2734 int sign = 0;
2735 DECL_LONG_DOUBLE_ROUNDING
2736
2737 BEGIN_LONG_DOUBLE_ROUNDING ();
2738
2739 if (signbit (arg)) /* arg < 0.0L or negative zero */
2740 {
2741 sign = -1;
2742 arg = -arg;
2743 }
2744
2745 if (sign < 0)
2746 *p++ = '-';
2747 else if (flags & FLAG_SHOWSIGN)
2748 *p++ = '+';
2749 else if (flags & FLAG_SPACE)
2750 *p++ = ' ';
2751
2752 if (arg > 0.0L && arg + arg == arg)
2753 {
2754 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
2755 {
2756 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
2757 }
2758 else
2759 {
2760 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
2761 }
2762 }
2763 else
2764 {
2765# if NEED_PRINTF_LONG_DOUBLE
2766 pad_ptr = p;
2767
2768 if (dp->conversion == 'f' || dp->conversion == 'F')
2769 {
2770 char *digits;
2771 size_t ndigits;
2772
2773 digits =
2774 scale10_round_decimal_long_double (arg, precision);
2775 if (digits == NULL)
2776 {
2777 END_LONG_DOUBLE_ROUNDING ();
2778 goto out_of_memory;
2779 }
2780 ndigits = strlen (digits);
2781
2782 if (ndigits > precision)
2783 do
2784 {
2785 --ndigits;
2786 *p++ = digits[ndigits];
2787 }
2788 while (ndigits > precision);
2789 else
2790 *p++ = '0';
2791 /* Here ndigits <= precision. */
2792 if ((flags & FLAG_ALT) || precision > 0)
2793 {
2794 *p++ = decimal_point_char ();
2795 for (; precision > ndigits; precision--)
2796 *p++ = '0';
2797 while (ndigits > 0)
2798 {
2799 --ndigits;
2800 *p++ = digits[ndigits];
2801 }
2802 }
2803
2804 free (digits);
2805 }
2806 else if (dp->conversion == 'e' || dp->conversion == 'E')
2807 {
2808 int exponent;
2809
2810 if (arg == 0.0L)
2811 {
2812 exponent = 0;
2813 *p++ = '0';
2814 if ((flags & FLAG_ALT) || precision > 0)
2815 {
2816 *p++ = decimal_point_char ();
2817 for (; precision > 0; precision--)
2818 *p++ = '0';
2819 }
2820 }
2821 else
2822 {
2823 /* arg > 0.0L. */
2824 int adjusted;
2825 char *digits;
2826 size_t ndigits;
2827
2828 exponent = floorlog10l (arg);
2829 adjusted = 0;
2830 for (;;)
2831 {
2832 digits =
2833 scale10_round_decimal_long_double (arg,
2834 (int)precision - exponent);
2835 if (digits == NULL)
2836 {
2837 END_LONG_DOUBLE_ROUNDING ();
2838 goto out_of_memory;
2839 }
2840 ndigits = strlen (digits);
2841
2842 if (ndigits == precision + 1)
2843 break;
2844 if (ndigits < precision
2845 || ndigits > precision + 2)
2846 /* The exponent was not guessed
2847 precisely enough. */
2848 abort ();
2849 if (adjusted)
2850 /* None of two values of exponent is
2851 the right one. Prevent an endless
2852 loop. */
2853 abort ();
2854 free (digits);
2855 if (ndigits == precision)
2856 exponent -= 1;
2857 else
2858 exponent += 1;
2859 adjusted = 1;
2860 }
2861
2862 /* Here ndigits = precision+1. */
2863 *p++ = digits[--ndigits];
2864 if ((flags & FLAG_ALT) || precision > 0)
2865 {
2866 *p++ = decimal_point_char ();
2867 while (ndigits > 0)
2868 {
2869 --ndigits;
2870 *p++ = digits[ndigits];
2871 }
2872 }
2873
2874 free (digits);
2875 }
2876
2877 *p++ = dp->conversion; /* 'e' or 'E' */
2878# if WIDE_CHAR_VERSION
2879 {
2880 static const wchar_t decimal_format[] =
2881 { '%', '+', '.', '2', 'd', '\0' };
2882 SNPRINTF (p, 6 + 1, decimal_format, exponent);
2883 }
2884 while (*p != '\0')
2885 p++;
2886# else
2887 if (sizeof (DCHAR_T) == 1)
2888 {
2889 sprintf ((char *) p, "%+.2d", exponent);
2890 while (*p != '\0')
2891 p++;
2892 }
2893 else
2894 {
2895 char expbuf[6 + 1];
2896 const char *ep;
2897 sprintf (expbuf, "%+.2d", exponent);
2898 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
2899 p++;
2900 }
2901# endif
2902 }
2903 else if (dp->conversion == 'g' || dp->conversion == 'G')
2904 {
2905 if (precision == 0)
2906 precision = 1;
2907 /* precision >= 1. */
2908
2909 if (arg == 0.0L)
2910 /* The exponent is 0, >= -4, < precision.
2911 Use fixed-point notation. */
2912 {
2913 size_t ndigits = precision;
2914 /* Number of trailing zeroes that have to be
2915 dropped. */
2916 size_t nzeroes =
2917 (flags & FLAG_ALT ? 0 : precision - 1);
2918
2919 --ndigits;
2920 *p++ = '0';
2921 if ((flags & FLAG_ALT) || ndigits > nzeroes)
2922 {
2923 *p++ = decimal_point_char ();
2924 while (ndigits > nzeroes)
2925 {
2926 --ndigits;
2927 *p++ = '0';
2928 }
2929 }
2930 }
2931 else
2932 {
2933 /* arg > 0.0L. */
2934 int exponent;
2935 int adjusted;
2936 char *digits;
2937 size_t ndigits;
2938 size_t nzeroes;
2939
2940 exponent = floorlog10l (arg);
2941 adjusted = 0;
2942 for (;;)
2943 {
2944 digits =
2945 scale10_round_decimal_long_double (arg,
2946 (int)(precision - 1) - exponent);
2947 if (digits == NULL)
2948 {
2949 END_LONG_DOUBLE_ROUNDING ();
2950 goto out_of_memory;
2951 }
2952 ndigits = strlen (digits);
2953
2954 if (ndigits == precision)
2955 break;
2956 if (ndigits < precision - 1
2957 || ndigits > precision + 1)
2958 /* The exponent was not guessed
2959 precisely enough. */
2960 abort ();
2961 if (adjusted)
2962 /* None of two values of exponent is
2963 the right one. Prevent an endless
2964 loop. */
2965 abort ();
2966 free (digits);
2967 if (ndigits < precision)
2968 exponent -= 1;
2969 else
2970 exponent += 1;
2971 adjusted = 1;
2972 }
2973 /* Here ndigits = precision. */
2974
2975 /* Determine the number of trailing zeroes
2976 that have to be dropped. */
2977 nzeroes = 0;
2978 if ((flags & FLAG_ALT) == 0)
2979 while (nzeroes < ndigits
2980 && digits[nzeroes] == '0')
2981 nzeroes++;
2982
2983 /* The exponent is now determined. */
2984 if (exponent >= -4
2985 && exponent < (long)precision)
2986 {
2987 /* Fixed-point notation:
2988 max(exponent,0)+1 digits, then the
2989 decimal point, then the remaining
2990 digits without trailing zeroes. */
2991 if (exponent >= 0)
2992 {
2993 size_t count = exponent + 1;
2994 /* Note: count <= precision = ndigits. */
2995 for (; count > 0; count--)
2996 *p++ = digits[--ndigits];
2997 if ((flags & FLAG_ALT) || ndigits > nzeroes)
2998 {
2999 *p++ = decimal_point_char ();
3000 while (ndigits > nzeroes)
3001 {
3002 --ndigits;
3003 *p++ = digits[ndigits];
3004 }
3005 }
3006 }
3007 else
3008 {
3009 size_t count = -exponent - 1;
3010 *p++ = '0';
3011 *p++ = decimal_point_char ();
3012 for (; count > 0; count--)
3013 *p++ = '0';
3014 while (ndigits > nzeroes)
3015 {
3016 --ndigits;
3017 *p++ = digits[ndigits];
3018 }
3019 }
3020 }
3021 else
3022 {
3023 /* Exponential notation. */
3024 *p++ = digits[--ndigits];
3025 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3026 {
3027 *p++ = decimal_point_char ();
3028 while (ndigits > nzeroes)
3029 {
3030 --ndigits;
3031 *p++ = digits[ndigits];
3032 }
3033 }
3034 *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
3035# if WIDE_CHAR_VERSION
3036 {
3037 static const wchar_t decimal_format[] =
3038 { '%', '+', '.', '2', 'd', '\0' };
3039 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3040 }
3041 while (*p != '\0')
3042 p++;
3043# else
3044 if (sizeof (DCHAR_T) == 1)
3045 {
3046 sprintf ((char *) p, "%+.2d", exponent);
3047 while (*p != '\0')
3048 p++;
3049 }
3050 else
3051 {
3052 char expbuf[6 + 1];
3053 const char *ep;
3054 sprintf (expbuf, "%+.2d", exponent);
3055 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3056 p++;
3057 }
3058# endif
3059 }
3060
3061 free (digits);
3062 }
3063 }
3064 else
3065 abort ();
3066# else
3067 /* arg is finite. */
3068 abort ();
3069# endif
3070 }
3071
3072 END_LONG_DOUBLE_ROUNDING ();
3073 }
3074 }
3075# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
3076 else
3077# endif
3078# endif
3079# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
3080 {
3081 double arg = a.arg[dp->arg_index].a.a_double;
3082
3083 if (isnand (arg))
3084 {
3085 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
3086 {
3087 *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
3088 }
3089 else
3090 {
3091 *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
3092 }
3093 }
3094 else
3095 {
3096 int sign = 0;
3097
3098 if (signbit (arg)) /* arg < 0.0 or negative zero */
3099 {
3100 sign = -1;
3101 arg = -arg;
3102 }
3103
3104 if (sign < 0)
3105 *p++ = '-';
3106 else if (flags & FLAG_SHOWSIGN)
3107 *p++ = '+';
3108 else if (flags & FLAG_SPACE)
3109 *p++ = ' ';
3110
3111 if (arg > 0.0 && arg + arg == arg)
3112 {
3113 if (dp->conversion >= 'A' && dp->conversion <= 'Z')
3114 {
3115 *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
3116 }
3117 else
3118 {
3119 *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
3120 }
3121 }
3122 else
3123 {
3124# if NEED_PRINTF_DOUBLE
3125 pad_ptr = p;
3126
3127 if (dp->conversion == 'f' || dp->conversion == 'F')
3128 {
3129 char *digits;
3130 size_t ndigits;
3131
3132 digits =
3133 scale10_round_decimal_double (arg, precision);
3134 if (digits == NULL)
3135 goto out_of_memory;
3136 ndigits = strlen (digits);
3137
3138 if (ndigits > precision)
3139 do
3140 {
3141 --ndigits;
3142 *p++ = digits[ndigits];
3143 }
3144 while (ndigits > precision);
3145 else
3146 *p++ = '0';
3147 /* Here ndigits <= precision. */
3148 if ((flags & FLAG_ALT) || precision > 0)
3149 {
3150 *p++ = decimal_point_char ();
3151 for (; precision > ndigits; precision--)
3152 *p++ = '0';
3153 while (ndigits > 0)
3154 {
3155 --ndigits;
3156 *p++ = digits[ndigits];
3157 }
3158 }
3159
3160 free (digits);
3161 }
3162 else if (dp->conversion == 'e' || dp->conversion == 'E')
3163 {
3164 int exponent;
3165
3166 if (arg == 0.0)
3167 {
3168 exponent = 0;
3169 *p++ = '0';
3170 if ((flags & FLAG_ALT) || precision > 0)
3171 {
3172 *p++ = decimal_point_char ();
3173 for (; precision > 0; precision--)
3174 *p++ = '0';
3175 }
3176 }
3177 else
3178 {
3179 /* arg > 0.0. */
3180 int adjusted;
3181 char *digits;
3182 size_t ndigits;
3183
3184 exponent = floorlog10 (arg);
3185 adjusted = 0;
3186 for (;;)
3187 {
3188 digits =
3189 scale10_round_decimal_double (arg,
3190 (int)precision - exponent);
3191 if (digits == NULL)
3192 goto out_of_memory;
3193 ndigits = strlen (digits);
3194
3195 if (ndigits == precision + 1)
3196 break;
3197 if (ndigits < precision
3198 || ndigits > precision + 2)
3199 /* The exponent was not guessed
3200 precisely enough. */
3201 abort ();
3202 if (adjusted)
3203 /* None of two values of exponent is
3204 the right one. Prevent an endless
3205 loop. */
3206 abort ();
3207 free (digits);
3208 if (ndigits == precision)
3209 exponent -= 1;
3210 else
3211 exponent += 1;
3212 adjusted = 1;
3213 }
3214
3215 /* Here ndigits = precision+1. */
3216 *p++ = digits[--ndigits];
3217 if ((flags & FLAG_ALT) || precision > 0)
3218 {
3219 *p++ = decimal_point_char ();
3220 while (ndigits > 0)
3221 {
3222 --ndigits;
3223 *p++ = digits[ndigits];
3224 }
3225 }
3226
3227 free (digits);
3228 }
3229
3230 *p++ = dp->conversion; /* 'e' or 'E' */
3231# if WIDE_CHAR_VERSION
3232 {
3233 static const wchar_t decimal_format[] =
3234 /* Produce the same number of exponent digits
3235 as the native printf implementation. */
3236# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3237 { '%', '+', '.', '3', 'd', '\0' };
3238# else
3239 { '%', '+', '.', '2', 'd', '\0' };
3240# endif
3241 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3242 }
3243 while (*p != '\0')
3244 p++;
3245# else
3246 {
3247 static const char decimal_format[] =
3248 /* Produce the same number of exponent digits
3249 as the native printf implementation. */
3250# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3251 "%+.3d";
3252# else
3253 "%+.2d";
3254# endif
3255 if (sizeof (DCHAR_T) == 1)
3256 {
3257 sprintf ((char *) p, decimal_format, exponent);
3258 while (*p != '\0')
3259 p++;
3260 }
3261 else
3262 {
3263 char expbuf[6 + 1];
3264 const char *ep;
3265 sprintf (expbuf, decimal_format, exponent);
3266 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3267 p++;
3268 }
3269 }
3270# endif
3271 }
3272 else if (dp->conversion == 'g' || dp->conversion == 'G')
3273 {
3274 if (precision == 0)
3275 precision = 1;
3276 /* precision >= 1. */
3277
3278 if (arg == 0.0)
3279 /* The exponent is 0, >= -4, < precision.
3280 Use fixed-point notation. */
3281 {
3282 size_t ndigits = precision;
3283 /* Number of trailing zeroes that have to be
3284 dropped. */
3285 size_t nzeroes =
3286 (flags & FLAG_ALT ? 0 : precision - 1);
3287
3288 --ndigits;
3289 *p++ = '0';
3290 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3291 {
3292 *p++ = decimal_point_char ();
3293 while (ndigits > nzeroes)
3294 {
3295 --ndigits;
3296 *p++ = '0';
3297 }
3298 }
3299 }
3300 else
3301 {
3302 /* arg > 0.0. */
3303 int exponent;
3304 int adjusted;
3305 char *digits;
3306 size_t ndigits;
3307 size_t nzeroes;
3308
3309 exponent = floorlog10 (arg);
3310 adjusted = 0;
3311 for (;;)
3312 {
3313 digits =
3314 scale10_round_decimal_double (arg,
3315 (int)(precision - 1) - exponent);
3316 if (digits == NULL)
3317 goto out_of_memory;
3318 ndigits = strlen (digits);
3319
3320 if (ndigits == precision)
3321 break;
3322 if (ndigits < precision - 1
3323 || ndigits > precision + 1)
3324 /* The exponent was not guessed
3325 precisely enough. */
3326 abort ();
3327 if (adjusted)
3328 /* None of two values of exponent is
3329 the right one. Prevent an endless
3330 loop. */
3331 abort ();
3332 free (digits);
3333 if (ndigits < precision)
3334 exponent -= 1;
3335 else
3336 exponent += 1;
3337 adjusted = 1;
3338 }
3339 /* Here ndigits = precision. */
3340
3341 /* Determine the number of trailing zeroes
3342 that have to be dropped. */
3343 nzeroes = 0;
3344 if ((flags & FLAG_ALT) == 0)
3345 while (nzeroes < ndigits
3346 && digits[nzeroes] == '0')
3347 nzeroes++;
3348
3349 /* The exponent is now determined. */
3350 if (exponent >= -4
3351 && exponent < (long)precision)
3352 {
3353 /* Fixed-point notation:
3354 max(exponent,0)+1 digits, then the
3355 decimal point, then the remaining
3356 digits without trailing zeroes. */
3357 if (exponent >= 0)
3358 {
3359 size_t count = exponent + 1;
3360 /* Note: count <= precision = ndigits. */
3361 for (; count > 0; count--)
3362 *p++ = digits[--ndigits];
3363 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3364 {
3365 *p++ = decimal_point_char ();
3366 while (ndigits > nzeroes)
3367 {
3368 --ndigits;
3369 *p++ = digits[ndigits];
3370 }
3371 }
3372 }
3373 else
3374 {
3375 size_t count = -exponent - 1;
3376 *p++ = '0';
3377 *p++ = decimal_point_char ();
3378 for (; count > 0; count--)
3379 *p++ = '0';
3380 while (ndigits > nzeroes)
3381 {
3382 --ndigits;
3383 *p++ = digits[ndigits];
3384 }
3385 }
3386 }
3387 else
3388 {
3389 /* Exponential notation. */
3390 *p++ = digits[--ndigits];
3391 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3392 {
3393 *p++ = decimal_point_char ();
3394 while (ndigits > nzeroes)
3395 {
3396 --ndigits;
3397 *p++ = digits[ndigits];
3398 }
3399 }
3400 *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
3401# if WIDE_CHAR_VERSION
3402 {
3403 static const wchar_t decimal_format[] =
3404 /* Produce the same number of exponent digits
3405 as the native printf implementation. */
3406# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3407 { '%', '+', '.', '3', 'd', '\0' };
3408# else
3409 { '%', '+', '.', '2', 'd', '\0' };
3410# endif
3411 SNPRINTF (p, 6 + 1, decimal_format, exponent);
3412 }
3413 while (*p != '\0')
3414 p++;
3415# else
3416 {
3417 static const char decimal_format[] =
3418 /* Produce the same number of exponent digits
3419 as the native printf implementation. */
3420# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3421 "%+.3d";
3422# else
3423 "%+.2d";
3424# endif
3425 if (sizeof (DCHAR_T) == 1)
3426 {
3427 sprintf ((char *) p, decimal_format, exponent);
3428 while (*p != '\0')
3429 p++;
3430 }
3431 else
3432 {
3433 char expbuf[6 + 1];
3434 const char *ep;
3435 sprintf (expbuf, decimal_format, exponent);
3436 for (ep = expbuf; (*p = *ep) != '\0'; ep++)
3437 p++;
3438 }
3439 }
3440# endif
3441 }
3442
3443 free (digits);
3444 }
3445 }
3446 else
3447 abort ();
3448# else
3449 /* arg is finite. */
3450 if (!(arg == 0.0))
3451 abort ();
3452
3453 pad_ptr = p;
3454
3455 if (dp->conversion == 'f' || dp->conversion == 'F')
3456 {
3457 *p++ = '0';
3458 if ((flags & FLAG_ALT) || precision > 0)
3459 {
3460 *p++ = decimal_point_char ();
3461 for (; precision > 0; precision--)
3462 *p++ = '0';
3463 }
3464 }
3465 else if (dp->conversion == 'e' || dp->conversion == 'E')
3466 {
3467 *p++ = '0';
3468 if ((flags & FLAG_ALT) || precision > 0)
3469 {
3470 *p++ = decimal_point_char ();
3471 for (; precision > 0; precision--)
3472 *p++ = '0';
3473 }
3474 *p++ = dp->conversion; /* 'e' or 'E' */
3475 *p++ = '+';
3476 /* Produce the same number of exponent digits as
3477 the native printf implementation. */
3478# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3479 *p++ = '0';
3480# endif
3481 *p++ = '0';
3482 *p++ = '0';
3483 }
3484 else if (dp->conversion == 'g' || dp->conversion == 'G')
3485 {
3486 *p++ = '0';
3487 if (flags & FLAG_ALT)
3488 {
3489 size_t ndigits =
3490 (precision > 0 ? precision - 1 : 0);
3491 *p++ = decimal_point_char ();
3492 for (; ndigits > 0; --ndigits)
3493 *p++ = '0';
3494 }
3495 }
3496 else
3497 abort ();
3498# endif
3499 }
3500 }
3501 }
3502# endif
3503
3504 /* The generated string now extends from tmp to p, with the
3505 zero padding insertion point being at pad_ptr. */
3506 if (has_width && p - tmp < width)
3507 {
3508 size_t pad = width - (p - tmp);
3509 DCHAR_T *end = p + pad;
3510
3511 if (flags & FLAG_LEFT)
3512 {
3513 /* Pad with spaces on the right. */
3514 for (; pad > 0; pad--)
3515 *p++ = ' ';
3516 }
3517 else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
3518 {
3519 /* Pad with zeroes. */
3520 DCHAR_T *q = end;
3521
3522 while (p > pad_ptr)
3523 *--q = *--p;
3524 for (; pad > 0; pad--)
3525 *p++ = '0';
3526 }
3527 else
3528 {
3529 /* Pad with spaces on the left. */
3530 DCHAR_T *q = end;
3531
3532 while (p > tmp)
3533 *--q = *--p;
3534 for (; pad > 0; pad--)
3535 *p++ = ' ';
3536 }
3537
3538 p = end;
3539 }
3540
3541 {
3542 size_t count = p - tmp;
3543
3544 if (count >= tmp_length)
3545 /* tmp_length was incorrectly calculated - fix the
3546 code above! */
3547 abort ();
3548
3549 /* Make room for the result. */
3550 if (count >= allocated - length)
3551 {
3552 size_t n = xsum (length, count);
3553
3554 ENSURE_ALLOCATION (n);
3555 }
3556
3557 /* Append the result. */
3558 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
3559 if (tmp != tmpbuf)
3560 free (tmp);
3561 length += count;
3562 }
3563 }
3564#endif
3565 else
3566 {
3567 arg_type type = a.arg[dp->arg_index].type;
3568 int flags = dp->flags;
3569#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
3570 int has_width;
3571 size_t width;
3572#endif
3573#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
3574 int has_precision;
3575 size_t precision;
3576#endif
3577#if NEED_PRINTF_UNBOUNDED_PRECISION
3578 int prec_ourselves;
3579#else
3580# define prec_ourselves 0
3581#endif
3582#if NEED_PRINTF_FLAG_LEFTADJUST
3583# define pad_ourselves 1
3584#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
3585 int pad_ourselves;
3586#else
3587# define pad_ourselves 0
3588#endif
3589 TCHAR_T *fbp;
3590 unsigned int prefix_count;
3591 int prefixes[2];
3592#if !USE_SNPRINTF
3593 size_t tmp_length;
3594 TCHAR_T tmpbuf[700];
3595 TCHAR_T *tmp;
3596#endif
3597
3598#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
3599 has_width = 0;
3600 width = 0;
3601 if (dp->width_start != dp->width_end)
3602 {
3603 if (dp->width_arg_index != ARG_NONE)
3604 {
3605 int arg;
3606
3607 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
3608 abort ();
3609 arg = a.arg[dp->width_arg_index].a.a_int;
3610 if (arg < 0)
3611 {
3612 /* "A negative field width is taken as a '-' flag
3613 followed by a positive field width." */
3614 flags |= FLAG_LEFT;
3615 width = (unsigned int) (-arg);
3616 }
3617 else
3618 width = arg;
3619 }
3620 else
3621 {
3622 const FCHAR_T *digitp = dp->width_start;
3623
3624 do
3625 width = xsum (xtimes (width, 10), *digitp++ - '0');
3626 while (digitp != dp->width_end);
3627 }
3628 has_width = 1;
3629 }
3630#endif
3631
3632#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
3633 has_precision = 0;
3634 precision = 6;
3635 if (dp->precision_start != dp->precision_end)
3636 {
3637 if (dp->precision_arg_index != ARG_NONE)
3638 {
3639 int arg;
3640
3641 if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
3642 abort ();
3643 arg = a.arg[dp->precision_arg_index].a.a_int;
3644 /* "A negative precision is taken as if the precision
3645 were omitted." */
3646 if (arg >= 0)
3647 {
3648 precision = arg;
3649 has_precision = 1;
3650 }
3651 }
3652 else
3653 {
3654 const FCHAR_T *digitp = dp->precision_start + 1;
3655
3656 precision = 0;
3657 while (digitp != dp->precision_end)
3658 precision = xsum (xtimes (precision, 10), *digitp++ - '0');
3659 has_precision = 1;
3660 }
3661 }
3662#endif
3663
3664#if !USE_SNPRINTF
3665 /* Allocate a temporary buffer of sufficient size for calling
3666 sprintf. */
3667 {
321 switch (dp->conversion) 3668 switch (dp->conversion)
322 { 3669 {
323 3670
324 case 'd': case 'i': case 'u': 3671 case 'd': case 'i': case 'u':
325# ifdef HAVE_LONG_LONG_INT 3672# if HAVE_LONG_LONG_INT
326 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 3673 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
327 tmp_length = 3674 tmp_length =
328 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 3675 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
@@ -352,7 +3699,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
352 break; 3699 break;
353 3700
354 case 'o': 3701 case 'o':
355# ifdef HAVE_LONG_LONG_INT 3702# if HAVE_LONG_LONG_INT
356 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 3703 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
357 tmp_length = 3704 tmp_length =
358 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 3705 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
@@ -380,7 +3727,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
380 break; 3727 break;
381 3728
382 case 'x': case 'X': 3729 case 'x': case 'X':
383# ifdef HAVE_LONG_LONG_INT 3730# if HAVE_LONG_LONG_INT
384 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 3731 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
385 tmp_length = 3732 tmp_length =
386 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 3733 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
@@ -408,7 +3755,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
408 break; 3755 break;
409 3756
410 case 'f': case 'F': 3757 case 'f': case 'F':
411# ifdef HAVE_LONG_DOUBLE
412 if (type == TYPE_LONGDOUBLE) 3758 if (type == TYPE_LONGDOUBLE)
413 tmp_length = 3759 tmp_length =
414 (unsigned int) (LDBL_MAX_EXP 3760 (unsigned int) (LDBL_MAX_EXP
@@ -418,7 +3764,6 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
418 + 1 /* turn floor into ceil */ 3764 + 1 /* turn floor into ceil */
419 + 10; /* sign, decimal point etc. */ 3765 + 10; /* sign, decimal point etc. */
420 else 3766 else
421# endif
422 tmp_length = 3767 tmp_length =
423 (unsigned int) (DBL_MAX_EXP 3768 (unsigned int) (DBL_MAX_EXP
424 * 0.30103 /* binary -> decimal */ 3769 * 0.30103 /* binary -> decimal */
@@ -430,14 +3775,32 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
430 break; 3775 break;
431 3776
432 case 'e': case 'E': case 'g': case 'G': 3777 case 'e': case 'E': case 'g': case 'G':
433 case 'a': case 'A':
434 tmp_length = 3778 tmp_length =
435 12; /* sign, decimal point, exponent etc. */ 3779 12; /* sign, decimal point, exponent etc. */
436 tmp_length = xsum (tmp_length, precision); 3780 tmp_length = xsum (tmp_length, precision);
437 break; 3781 break;
438 3782
3783 case 'a': case 'A':
3784 if (type == TYPE_LONGDOUBLE)
3785 tmp_length =
3786 (unsigned int) (LDBL_DIG
3787 * 0.831 /* decimal -> hexadecimal */
3788 )
3789 + 1; /* turn floor into ceil */
3790 else
3791 tmp_length =
3792 (unsigned int) (DBL_DIG
3793 * 0.831 /* decimal -> hexadecimal */
3794 )
3795 + 1; /* turn floor into ceil */
3796 if (tmp_length < precision)
3797 tmp_length = precision;
3798 /* Account for sign, decimal point etc. */
3799 tmp_length = xsum (tmp_length, 12);
3800 break;
3801
439 case 'c': 3802 case 'c':
440# if defined HAVE_WINT_T && !WIDE_CHAR_VERSION 3803# if HAVE_WINT_T && !WIDE_CHAR_VERSION
441 if (type == TYPE_WIDE_CHAR) 3804 if (type == TYPE_WIDE_CHAR)
442 tmp_length = MB_CUR_MAX; 3805 tmp_length = MB_CUR_MAX;
443 else 3806 else
@@ -446,7 +3809,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
446 break; 3809 break;
447 3810
448 case 's': 3811 case 's':
449# ifdef HAVE_WCHAR_T 3812# if HAVE_WCHAR_T
450 if (type == TYPE_WIDE_STRING) 3813 if (type == TYPE_WIDE_STRING)
451 { 3814 {
452 tmp_length = 3815 tmp_length =
@@ -474,95 +3837,216 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
474 abort (); 3837 abort ();
475 } 3838 }
476 3839
3840# if ENABLE_UNISTDIO
3841 /* Padding considers the number of characters, therefore the
3842 number of elements after padding may be
3843 > max (tmp_length, width)
3844 but is certainly
3845 <= tmp_length + width. */
3846 tmp_length = xsum (tmp_length, width);
3847# else
3848 /* Padding considers the number of elements, says POSIX. */
477 if (tmp_length < width) 3849 if (tmp_length < width)
478 tmp_length = width; 3850 tmp_length = width;
3851# endif
479 3852
480 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ 3853 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
481 } 3854 }
482 3855
483 if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T)) 3856 if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T))
484 tmp = tmpbuf; 3857 tmp = tmpbuf;
485 else 3858 else
486 { 3859 {
487 size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T)); 3860 size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T));
488 3861
489 if (size_overflow_p (tmp_memsize)) 3862 if (size_overflow_p (tmp_memsize))
490 /* Overflow, would lead to out of memory. */ 3863 /* Overflow, would lead to out of memory. */
491 goto out_of_memory; 3864 goto out_of_memory;
492 tmp = (CHAR_T *) malloc (tmp_memsize); 3865 tmp = (TCHAR_T *) malloc (tmp_memsize);
493 if (tmp == NULL) 3866 if (tmp == NULL)
494 /* Out of memory. */ 3867 /* Out of memory. */
495 goto out_of_memory; 3868 goto out_of_memory;
496 } 3869 }
497#endif 3870#endif
498 3871
3872 /* Decide whether to handle the precision ourselves. */
3873#if NEED_PRINTF_UNBOUNDED_PRECISION
3874 switch (dp->conversion)
3875 {
3876 case 'd': case 'i': case 'u':
3877 case 'o':
3878 case 'x': case 'X': case 'p':
3879 prec_ourselves = has_precision && (precision > 0);
3880 break;
3881 default:
3882 prec_ourselves = 0;
3883 break;
3884 }
3885#endif
3886
3887 /* Decide whether to perform the padding ourselves. */
3888#if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION)
3889 switch (dp->conversion)
3890 {
3891# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
3892 /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need
3893 to perform the padding after this conversion. Functions
3894 with unistdio extensions perform the padding based on
3895 character count rather than element count. */
3896 case 'c': case 's':
3897# endif
3898# if NEED_PRINTF_FLAG_ZERO
3899 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
3900 case 'a': case 'A':
3901# endif
3902 pad_ourselves = 1;
3903 break;
3904 default:
3905 pad_ourselves = prec_ourselves;
3906 break;
3907 }
3908#endif
3909
499 /* Construct the format string for calling snprintf or 3910 /* Construct the format string for calling snprintf or
500 sprintf. */ 3911 sprintf. */
501 p = buf; 3912 fbp = buf;
502 *p++ = '%'; 3913 *fbp++ = '%';
503 if (dp->flags & FLAG_GROUP) 3914#if NEED_PRINTF_FLAG_GROUPING
504 *p++ = '\''; 3915 /* The underlying implementation doesn't support the ' flag.
505 if (dp->flags & FLAG_LEFT) 3916 Produce no grouping characters in this case; this is
506 *p++ = '-'; 3917 acceptable because the grouping is locale dependent. */
507 if (dp->flags & FLAG_SHOWSIGN) 3918#else
508 *p++ = '+'; 3919 if (flags & FLAG_GROUP)
509 if (dp->flags & FLAG_SPACE) 3920 *fbp++ = '\'';
510 *p++ = ' '; 3921#endif
511 if (dp->flags & FLAG_ALT) 3922 if (flags & FLAG_LEFT)
512 *p++ = '#'; 3923 *fbp++ = '-';
513 if (dp->flags & FLAG_ZERO) 3924 if (flags & FLAG_SHOWSIGN)
514 *p++ = '0'; 3925 *fbp++ = '+';
515 if (dp->width_start != dp->width_end) 3926 if (flags & FLAG_SPACE)
3927 *fbp++ = ' ';
3928 if (flags & FLAG_ALT)
3929 *fbp++ = '#';
3930 if (!pad_ourselves)
516 { 3931 {
517 size_t n = dp->width_end - dp->width_start; 3932 if (flags & FLAG_ZERO)
518 memcpy (p, dp->width_start, n * sizeof (CHAR_T)); 3933 *fbp++ = '0';
519 p += n; 3934 if (dp->width_start != dp->width_end)
3935 {
3936 size_t n = dp->width_end - dp->width_start;
3937 /* The width specification is known to consist only
3938 of standard ASCII characters. */
3939 if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
3940 {
3941 memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T));
3942 fbp += n;
3943 }
3944 else
3945 {
3946 const FCHAR_T *mp = dp->width_start;
3947 do
3948 *fbp++ = (unsigned char) *mp++;
3949 while (--n > 0);
3950 }
3951 }
520 } 3952 }
521 if (dp->precision_start != dp->precision_end) 3953 if (!prec_ourselves)
522 { 3954 {
523 size_t n = dp->precision_end - dp->precision_start; 3955 if (dp->precision_start != dp->precision_end)
524 memcpy (p, dp->precision_start, n * sizeof (CHAR_T)); 3956 {
525 p += n; 3957 size_t n = dp->precision_end - dp->precision_start;
3958 /* The precision specification is known to consist only
3959 of standard ASCII characters. */
3960 if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
3961 {
3962 memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T));
3963 fbp += n;
3964 }
3965 else
3966 {
3967 const FCHAR_T *mp = dp->precision_start;
3968 do
3969 *fbp++ = (unsigned char) *mp++;
3970 while (--n > 0);
3971 }
3972 }
526 } 3973 }
527 3974
528 switch (type) 3975 switch (type)
529 { 3976 {
530#ifdef HAVE_LONG_LONG_INT 3977#if HAVE_LONG_LONG_INT
531 case TYPE_LONGLONGINT: 3978 case TYPE_LONGLONGINT:
532 case TYPE_ULONGLONGINT: 3979 case TYPE_ULONGLONGINT:
533 *p++ = 'l'; 3980# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3981 *fbp++ = 'I';
3982 *fbp++ = '6';
3983 *fbp++ = '4';
3984 break;
3985# else
3986 *fbp++ = 'l';
534 /*FALLTHROUGH*/ 3987 /*FALLTHROUGH*/
3988# endif
535#endif 3989#endif
536 case TYPE_LONGINT: 3990 case TYPE_LONGINT:
537 case TYPE_ULONGINT: 3991 case TYPE_ULONGINT:
538#ifdef HAVE_WINT_T 3992#if HAVE_WINT_T
539 case TYPE_WIDE_CHAR: 3993 case TYPE_WIDE_CHAR:
540#endif 3994#endif
541#ifdef HAVE_WCHAR_T 3995#if HAVE_WCHAR_T
542 case TYPE_WIDE_STRING: 3996 case TYPE_WIDE_STRING:
543#endif 3997#endif
544 *p++ = 'l'; 3998 *fbp++ = 'l';
545 break; 3999 break;
546#ifdef HAVE_LONG_DOUBLE
547 case TYPE_LONGDOUBLE: 4000 case TYPE_LONGDOUBLE:
548 *p++ = 'L'; 4001 *fbp++ = 'L';
549 break; 4002 break;
550#endif
551 default: 4003 default:
552 break; 4004 break;
553 } 4005 }
554 *p = dp->conversion; 4006#if NEED_PRINTF_DIRECTIVE_F
4007 if (dp->conversion == 'F')
4008 *fbp = 'f';
4009 else
4010#endif
4011 *fbp = dp->conversion;
555#if USE_SNPRINTF 4012#if USE_SNPRINTF
556 p[1] = '%'; 4013# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
557 p[2] = 'n'; 4014 fbp[1] = '%';
558 p[3] = '\0'; 4015 fbp[2] = 'n';
4016 fbp[3] = '\0';
4017# else
4018 /* On glibc2 systems from glibc >= 2.3 - probably also older
4019 ones - we know that snprintf's returns value conforms to
4020 ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes.
4021 Therefore we can avoid using %n in this situation.
4022 On glibc2 systems from 2004-10-18 or newer, the use of %n
4023 in format strings in writable memory may crash the program
4024 (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
4025 in this situation. */
4026 /* On native Win32 systems (such as mingw), we can avoid using
4027 %n because:
4028 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
4029 snprintf does not write more than the specified number
4030 of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes
4031 '4', '5', '6' into buf, not '4', '5', '\0'.)
4032 - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf
4033 allows us to recognize the case of an insufficient
4034 buffer size: it returns -1 in this case.
4035 On native Win32 systems (such as mingw) where the OS is
4036 Windows Vista, the use of %n in format strings by default
4037 crashes the program. See
4038 <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
4039 <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx>
4040 So we should avoid %n in this situation. */
4041 fbp[1] = '\0';
4042# endif
559#else 4043#else
560 p[1] = '\0'; 4044 fbp[1] = '\0';
561#endif 4045#endif
562 4046
563 /* Construct the arguments for calling snprintf or sprintf. */ 4047 /* Construct the arguments for calling snprintf or sprintf. */
564 prefix_count = 0; 4048 prefix_count = 0;
565 if (dp->width_arg_index != ARG_NONE) 4049 if (!pad_ourselves && dp->width_arg_index != ARG_NONE)
566 { 4050 {
567 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 4051 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
568 abort (); 4052 abort ();
@@ -576,36 +4060,50 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
576 } 4060 }
577 4061
578#if USE_SNPRINTF 4062#if USE_SNPRINTF
4063 /* The SNPRINTF result is appended after result[0..length].
4064 The latter is an array of DCHAR_T; SNPRINTF appends an
4065 array of TCHAR_T to it. This is possible because
4066 sizeof (TCHAR_T) divides sizeof (DCHAR_T) and
4067 alignof (TCHAR_T) <= alignof (DCHAR_T). */
4068# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T))
4069 /* Ensure that maxlen below will be >= 2. Needed on BeOS,
4070 where an snprintf() with maxlen==1 acts like sprintf(). */
4071 ENSURE_ALLOCATION (xsum (length,
4072 (2 + TCHARS_PER_DCHAR - 1)
4073 / TCHARS_PER_DCHAR));
579 /* Prepare checking whether snprintf returns the count 4074 /* Prepare checking whether snprintf returns the count
580 via %n. */ 4075 via %n. */
581 ENSURE_ALLOCATION (xsum (length, 1)); 4076 *(TCHAR_T *) (result + length) = '\0';
582 result[length] = '\0';
583#endif 4077#endif
584 4078
585 for (;;) 4079 for (;;)
586 { 4080 {
587 size_t maxlen; 4081 int count = -1;
588 int count;
589 int retcount;
590
591 maxlen = allocated - length;
592 count = -1;
593 retcount = 0;
594 4082
595#if USE_SNPRINTF 4083#if USE_SNPRINTF
4084 int retcount = 0;
4085 size_t maxlen = allocated - length;
4086 /* SNPRINTF can fail if its second argument is
4087 > INT_MAX. */
4088 if (maxlen > INT_MAX / TCHARS_PER_DCHAR)
4089 maxlen = INT_MAX / TCHARS_PER_DCHAR;
4090 maxlen = maxlen * TCHARS_PER_DCHAR;
596# define SNPRINTF_BUF(arg) \ 4091# define SNPRINTF_BUF(arg) \
597 switch (prefix_count) \ 4092 switch (prefix_count) \
598 { \ 4093 { \
599 case 0: \ 4094 case 0: \
600 retcount = SNPRINTF (result + length, maxlen, buf, \ 4095 retcount = SNPRINTF ((TCHAR_T *) (result + length), \
4096 maxlen, buf, \
601 arg, &count); \ 4097 arg, &count); \
602 break; \ 4098 break; \
603 case 1: \ 4099 case 1: \
604 retcount = SNPRINTF (result + length, maxlen, buf, \ 4100 retcount = SNPRINTF ((TCHAR_T *) (result + length), \
4101 maxlen, buf, \
605 prefixes[0], arg, &count); \ 4102 prefixes[0], arg, &count); \
606 break; \ 4103 break; \
607 case 2: \ 4104 case 2: \
608 retcount = SNPRINTF (result + length, maxlen, buf, \ 4105 retcount = SNPRINTF ((TCHAR_T *) (result + length), \
4106 maxlen, buf, \
609 prefixes[0], prefixes[1], arg, \ 4107 prefixes[0], prefixes[1], arg, \
610 &count); \ 4108 &count); \
611 break; \ 4109 break; \
@@ -681,7 +4179,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
681 SNPRINTF_BUF (arg); 4179 SNPRINTF_BUF (arg);
682 } 4180 }
683 break; 4181 break;
684#ifdef HAVE_LONG_LONG_INT 4182#if HAVE_LONG_LONG_INT
685 case TYPE_LONGLONGINT: 4183 case TYPE_LONGLONGINT:
686 { 4184 {
687 long long int arg = a.arg[dp->arg_index].a.a_longlongint; 4185 long long int arg = a.arg[dp->arg_index].a.a_longlongint;
@@ -701,21 +4199,19 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
701 SNPRINTF_BUF (arg); 4199 SNPRINTF_BUF (arg);
702 } 4200 }
703 break; 4201 break;
704#ifdef HAVE_LONG_DOUBLE
705 case TYPE_LONGDOUBLE: 4202 case TYPE_LONGDOUBLE:
706 { 4203 {
707 long double arg = a.arg[dp->arg_index].a.a_longdouble; 4204 long double arg = a.arg[dp->arg_index].a.a_longdouble;
708 SNPRINTF_BUF (arg); 4205 SNPRINTF_BUF (arg);
709 } 4206 }
710 break; 4207 break;
711#endif
712 case TYPE_CHAR: 4208 case TYPE_CHAR:
713 { 4209 {
714 int arg = a.arg[dp->arg_index].a.a_char; 4210 int arg = a.arg[dp->arg_index].a.a_char;
715 SNPRINTF_BUF (arg); 4211 SNPRINTF_BUF (arg);
716 } 4212 }
717 break; 4213 break;
718#ifdef HAVE_WINT_T 4214#if HAVE_WINT_T
719 case TYPE_WIDE_CHAR: 4215 case TYPE_WIDE_CHAR:
720 { 4216 {
721 wint_t arg = a.arg[dp->arg_index].a.a_wide_char; 4217 wint_t arg = a.arg[dp->arg_index].a.a_wide_char;
@@ -729,7 +4225,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
729 SNPRINTF_BUF (arg); 4225 SNPRINTF_BUF (arg);
730 } 4226 }
731 break; 4227 break;
732#ifdef HAVE_WCHAR_T 4228#if HAVE_WCHAR_T
733 case TYPE_WIDE_STRING: 4229 case TYPE_WIDE_STRING:
734 { 4230 {
735 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; 4231 const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
@@ -756,7 +4252,8 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
756 { 4252 {
757 /* Verify that snprintf() has NUL-terminated its 4253 /* Verify that snprintf() has NUL-terminated its
758 result. */ 4254 result. */
759 if (count < maxlen && result[length + count] != '\0') 4255 if (count < maxlen
4256 && ((TCHAR_T *) (result + length)) [count] != '\0')
760 abort (); 4257 abort ();
761 /* Portability hack. */ 4258 /* Portability hack. */
762 if (retcount > count) 4259 if (retcount > count)
@@ -766,11 +4263,11 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
766 { 4263 {
767 /* snprintf() doesn't understand the '%n' 4264 /* snprintf() doesn't understand the '%n'
768 directive. */ 4265 directive. */
769 if (p[1] != '\0') 4266 if (fbp[1] != '\0')
770 { 4267 {
771 /* Don't use the '%n' directive; instead, look 4268 /* Don't use the '%n' directive; instead, look
772 at the snprintf() return value. */ 4269 at the snprintf() return value. */
773 p[1] = '\0'; 4270 fbp[1] = '\0';
774 continue; 4271 continue;
775 } 4272 }
776 else 4273 else
@@ -806,37 +4303,339 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
806 return NULL; 4303 return NULL;
807 } 4304 }
808 4305
809#if !USE_SNPRINTF 4306#if USE_SNPRINTF
4307 /* Handle overflow of the allocated buffer.
4308 If such an overflow occurs, a C99 compliant snprintf()
4309 returns a count >= maxlen. However, a non-compliant
4310 snprintf() function returns only count = maxlen - 1. To
4311 cover both cases, test whether count >= maxlen - 1. */
4312 if ((unsigned int) count + 1 >= maxlen)
4313 {
4314 /* If maxlen already has attained its allowed maximum,
4315 allocating more memory will not increase maxlen.
4316 Instead of looping, bail out. */
4317 if (maxlen == INT_MAX / TCHARS_PER_DCHAR)
4318 goto overflow;
4319 else
4320 {
4321 /* Need at least (count + 1) * sizeof (TCHAR_T)
4322 bytes. (The +1 is for the trailing NUL.)
4323 But ask for (count + 2) * sizeof (TCHAR_T)
4324 bytes, so that in the next round, we likely get
4325 maxlen > (unsigned int) count + 1
4326 and so we don't get here again.
4327 And allocate proportionally, to avoid looping
4328 eternally if snprintf() reports a too small
4329 count. */
4330 size_t n =
4331 xmax (xsum (length,
4332 ((unsigned int) count + 2
4333 + TCHARS_PER_DCHAR - 1)
4334 / TCHARS_PER_DCHAR),
4335 xtimes (allocated, 2));
4336
4337 ENSURE_ALLOCATION (n);
4338 continue;
4339 }
4340 }
4341#endif
4342
4343#if NEED_PRINTF_UNBOUNDED_PRECISION
4344 if (prec_ourselves)
4345 {
4346 /* Handle the precision. */
4347 TCHAR_T *prec_ptr =
4348# if USE_SNPRINTF
4349 (TCHAR_T *) (result + length);
4350# else
4351 tmp;
4352# endif
4353 size_t prefix_count;
4354 size_t move;
4355
4356 prefix_count = 0;
4357 /* Put the additional zeroes after the sign. */
4358 if (count >= 1
4359 && (*prec_ptr == '-' || *prec_ptr == '+'
4360 || *prec_ptr == ' '))
4361 prefix_count = 1;
4362 /* Put the additional zeroes after the 0x prefix if
4363 (flags & FLAG_ALT) || (dp->conversion == 'p'). */
4364 else if (count >= 2
4365 && prec_ptr[0] == '0'
4366 && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X'))
4367 prefix_count = 2;
4368
4369 move = count - prefix_count;
4370 if (precision > move)
4371 {
4372 /* Insert zeroes. */
4373 size_t insert = precision - move;
4374 TCHAR_T *prec_end;
4375
4376# if USE_SNPRINTF
4377 size_t n =
4378 xsum (length,
4379 (count + insert + TCHARS_PER_DCHAR - 1)
4380 / TCHARS_PER_DCHAR);
4381 length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
4382 ENSURE_ALLOCATION (n);
4383 length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
4384 prec_ptr = (TCHAR_T *) (result + length);
4385# endif
4386
4387 prec_end = prec_ptr + count;
4388 prec_ptr += prefix_count;
4389
4390 while (prec_end > prec_ptr)
4391 {
4392 prec_end--;
4393 prec_end[insert] = prec_end[0];
4394 }
4395
4396 prec_end += insert;
4397 do
4398 *--prec_end = '0';
4399 while (prec_end > prec_ptr);
4400
4401 count += insert;
4402 }
4403 }
4404#endif
4405
4406#if !DCHAR_IS_TCHAR
4407# if !USE_SNPRINTF
810 if (count >= tmp_length) 4408 if (count >= tmp_length)
811 /* tmp_length was incorrectly calculated - fix the 4409 /* tmp_length was incorrectly calculated - fix the
812 code above! */ 4410 code above! */
813 abort (); 4411 abort ();
4412# endif
4413
4414 /* Convert from TCHAR_T[] to DCHAR_T[]. */
4415 if (dp->conversion == 'c' || dp->conversion == 's')
4416 {
4417 /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING
4418 TYPE_WIDE_STRING.
4419 The result string is not certainly ASCII. */
4420 const TCHAR_T *tmpsrc;
4421 DCHAR_T *tmpdst;
4422 size_t tmpdst_len;
4423 /* This code assumes that TCHAR_T is 'char'. */
4424 typedef int TCHAR_T_verify
4425 [2 * (sizeof (TCHAR_T) == 1) - 1];
4426# if USE_SNPRINTF
4427 tmpsrc = (TCHAR_T *) (result + length);
4428# else
4429 tmpsrc = tmp;
4430# endif
4431 tmpdst = NULL;
4432 tmpdst_len = 0;
4433 if (DCHAR_CONV_FROM_ENCODING (locale_charset (),
4434 iconveh_question_mark,
4435 tmpsrc, count,
4436 NULL,
4437 &tmpdst, &tmpdst_len)
4438 < 0)
4439 {
4440 int saved_errno = errno;
4441 if (!(result == resultbuf || result == NULL))
4442 free (result);
4443 if (buf_malloced != NULL)
4444 free (buf_malloced);
4445 CLEANUP ();
4446 errno = saved_errno;
4447 return NULL;
4448 }
4449 ENSURE_ALLOCATION (xsum (length, tmpdst_len));
4450 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
4451 free (tmpdst);
4452 count = tmpdst_len;
4453 }
4454 else
4455 {
4456 /* The result string is ASCII.
4457 Simple 1:1 conversion. */
4458# if USE_SNPRINTF
4459 /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a
4460 no-op conversion, in-place on the array starting
4461 at (result + length). */
4462 if (sizeof (DCHAR_T) != sizeof (TCHAR_T))
4463# endif
4464 {
4465 const TCHAR_T *tmpsrc;
4466 DCHAR_T *tmpdst;
4467 size_t n;
4468
4469# if USE_SNPRINTF
4470 if (result == resultbuf)
4471 {
4472 tmpsrc = (TCHAR_T *) (result + length);
4473 /* ENSURE_ALLOCATION will not move tmpsrc
4474 (because it's part of resultbuf). */
4475 ENSURE_ALLOCATION (xsum (length, count));
4476 }
4477 else
4478 {
4479 /* ENSURE_ALLOCATION will move the array
4480 (because it uses realloc(). */
4481 ENSURE_ALLOCATION (xsum (length, count));
4482 tmpsrc = (TCHAR_T *) (result + length);
4483 }
4484# else
4485 tmpsrc = tmp;
4486 ENSURE_ALLOCATION (xsum (length, count));
4487# endif
4488 tmpdst = result + length;
4489 /* Copy backwards, because of overlapping. */
4490 tmpsrc += count;
4491 tmpdst += count;
4492 for (n = count; n > 0; n--)
4493 *--tmpdst = (unsigned char) *--tmpsrc;
4494 }
4495 }
814#endif 4496#endif
815 4497
4498#if DCHAR_IS_TCHAR && !USE_SNPRINTF
816 /* Make room for the result. */ 4499 /* Make room for the result. */
817 if (count >= maxlen) 4500 if (count > allocated - length)
818 { 4501 {
819 /* Need at least count bytes. But allocate 4502 /* Need at least count elements. But allocate
820 proportionally, to avoid looping eternally if 4503 proportionally. */
821 snprintf() reports a too small count. */
822 size_t n = 4504 size_t n =
823 xmax (xsum (length, count), xtimes (allocated, 2)); 4505 xmax (xsum (length, count), xtimes (allocated, 2));
824 4506
825 ENSURE_ALLOCATION (n); 4507 ENSURE_ALLOCATION (n);
826#if USE_SNPRINTF 4508 }
827 continue;
828#endif 4509#endif
4510
4511 /* Here count <= allocated - length. */
4512
4513 /* Perform padding. */
4514#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4515 if (pad_ourselves && has_width)
4516 {
4517 size_t w;
4518# if ENABLE_UNISTDIO
4519 /* Outside POSIX, it's preferrable to compare the width
4520 against the number of _characters_ of the converted
4521 value. */
4522 w = DCHAR_MBSNLEN (result + length, count);
4523# else
4524 /* The width is compared against the number of _bytes_
4525 of the converted value, says POSIX. */
4526 w = count;
4527# endif
4528 if (w < width)
4529 {
4530 size_t pad = width - w;
4531# if USE_SNPRINTF
4532 /* Make room for the result. */
4533 if (xsum (count, pad) > allocated - length)
4534 {
4535 /* Need at least count + pad elements. But
4536 allocate proportionally. */
4537 size_t n =
4538 xmax (xsum3 (length, count, pad),
4539 xtimes (allocated, 2));
4540
4541 length += count;
4542 ENSURE_ALLOCATION (n);
4543 length -= count;
4544 }
4545 /* Here count + pad <= allocated - length. */
4546# endif
4547 {
4548# if !DCHAR_IS_TCHAR || USE_SNPRINTF
4549 DCHAR_T * const rp = result + length;
4550# else
4551 DCHAR_T * const rp = tmp;
4552# endif
4553 DCHAR_T *p = rp + count;
4554 DCHAR_T *end = p + pad;
4555 DCHAR_T *pad_ptr;
4556# if !DCHAR_IS_TCHAR
4557 if (dp->conversion == 'c'
4558 || dp->conversion == 's')
4559 /* No zero-padding for string directives. */
4560 pad_ptr = NULL;
4561 else
4562# endif
4563 {
4564 pad_ptr = (*rp == '-' ? rp + 1 : rp);
4565 /* No zero-padding of "inf" and "nan". */
4566 if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z')
4567 || (*pad_ptr >= 'a' && *pad_ptr <= 'z'))
4568 pad_ptr = NULL;
4569 }
4570 /* The generated string now extends from rp to p,
4571 with the zero padding insertion point being at
4572 pad_ptr. */
4573
4574 count = count + pad; /* = end - rp */
4575
4576 if (flags & FLAG_LEFT)
4577 {
4578 /* Pad with spaces on the right. */
4579 for (; pad > 0; pad--)
4580 *p++ = ' ';
4581 }
4582 else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
4583 {
4584 /* Pad with zeroes. */
4585 DCHAR_T *q = end;
4586
4587 while (p > pad_ptr)
4588 *--q = *--p;
4589 for (; pad > 0; pad--)
4590 *p++ = '0';
4591 }
4592 else
4593 {
4594 /* Pad with spaces on the left. */
4595 DCHAR_T *q = end;
4596
4597 while (p > rp)
4598 *--q = *--p;
4599 for (; pad > 0; pad--)
4600 *p++ = ' ';
4601 }
4602 }
4603 }
829 } 4604 }
4605#endif
830 4606
831#if USE_SNPRINTF 4607#if DCHAR_IS_TCHAR && !USE_SNPRINTF
4608 if (count >= tmp_length)
4609 /* tmp_length was incorrectly calculated - fix the
4610 code above! */
4611 abort ();
4612#endif
4613
4614 /* Here still count <= allocated - length. */
4615
4616#if !DCHAR_IS_TCHAR || USE_SNPRINTF
832 /* The snprintf() result did fit. */ 4617 /* The snprintf() result did fit. */
833#else 4618#else
834 /* Append the sprintf() result. */ 4619 /* Append the sprintf() result. */
835 memcpy (result + length, tmp, count * sizeof (CHAR_T)); 4620 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
4621#endif
4622#if !USE_SNPRINTF
836 if (tmp != tmpbuf) 4623 if (tmp != tmpbuf)
837 free (tmp); 4624 free (tmp);
838#endif 4625#endif
839 4626
4627#if NEED_PRINTF_DIRECTIVE_F
4628 if (dp->conversion == 'F')
4629 {
4630 /* Convert the %f result to upper case for %F. */
4631 DCHAR_T *rp = result + length;
4632 size_t rc;
4633 for (rc = count; rc > 0; rc--, rp++)
4634 if (*rp >= 'a' && *rp <= 'z')
4635 *rp = *rp - 'a' + 'A';
4636 }
4637#endif
4638
840 length += count; 4639 length += count;
841 break; 4640 break;
842 } 4641 }
@@ -851,9 +4650,9 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
851 if (result != resultbuf && length + 1 < allocated) 4650 if (result != resultbuf && length + 1 < allocated)
852 { 4651 {
853 /* Shrink the allocated memory if possible. */ 4652 /* Shrink the allocated memory if possible. */
854 CHAR_T *memory; 4653 DCHAR_T *memory;
855 4654
856 memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T)); 4655 memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T));
857 if (memory != NULL) 4656 if (memory != NULL)
858 result = memory; 4657 result = memory;
859 } 4658 }
@@ -868,6 +4667,17 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
868 not have this limitation. */ 4667 not have this limitation. */
869 return result; 4668 return result;
870 4669
4670#if USE_SNPRINTF
4671 overflow:
4672 if (!(result == resultbuf || result == NULL))
4673 free (result);
4674 if (buf_malloced != NULL)
4675 free (buf_malloced);
4676 CLEANUP ();
4677 errno = EOVERFLOW;
4678 return NULL;
4679#endif
4680
871 out_of_memory: 4681 out_of_memory:
872 if (!(result == resultbuf || result == NULL)) 4682 if (!(result == resultbuf || result == NULL))
873 free (result); 4683 free (result);
@@ -880,10 +4690,15 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
880 } 4690 }
881} 4691}
882 4692
4693#undef TCHARS_PER_DCHAR
883#undef SNPRINTF 4694#undef SNPRINTF
884#undef USE_SNPRINTF 4695#undef USE_SNPRINTF
4696#undef DCHAR_CPY
885#undef PRINTF_PARSE 4697#undef PRINTF_PARSE
886#undef DIRECTIVES 4698#undef DIRECTIVES
887#undef DIRECTIVE 4699#undef DIRECTIVE
888#undef CHAR_T 4700#undef DCHAR_IS_TCHAR
4701#undef TCHAR_T
4702#undef DCHAR_T
4703#undef FCHAR_T
889#undef VASNPRINTF 4704#undef VASNPRINTF
diff --git a/gl/vasnprintf.h b/gl/vasnprintf.h
index 894008c..b9a3d6e 100644
--- a/gl/vasnprintf.h
+++ b/gl/vasnprintf.h
@@ -1,9 +1,9 @@
1/* vsprintf with automatic memory allocation. 1/* vsprintf with automatic memory allocation.
2 Copyright (C) 2002-2004 Free Software Foundation, Inc. 2 Copyright (C) 2002-2004, 2007-2008 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -26,7 +26,7 @@
26 26
27#ifndef __attribute__ 27#ifndef __attribute__
28/* This feature is available in gcc versions 2.5 and later. */ 28/* This feature is available in gcc versions 2.5 and later. */
29# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ 29# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
30# define __attribute__(Spec) /* empty */ 30# define __attribute__(Spec) /* empty */
31# endif 31# endif
32/* The __-protected variants of `format' and `printf' attributes 32/* The __-protected variants of `format' and `printf' attributes
@@ -37,7 +37,7 @@
37# endif 37# endif
38#endif 38#endif
39 39
40#ifdef __cplusplus 40#ifdef __cplusplus
41extern "C" { 41extern "C" {
42#endif 42#endif
43 43
@@ -65,12 +65,16 @@ extern "C" {
65 free (output); 65 free (output);
66 } 66 }
67 */ 67 */
68#if REPLACE_VASNPRINTF
69# define asnprintf rpl_asnprintf
70# define vasnprintf rpl_vasnprintf
71#endif
68extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) 72extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
69 __attribute__ ((__format__ (__printf__, 3, 4))); 73 __attribute__ ((__format__ (__printf__, 3, 4)));
70extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) 74extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
71 __attribute__ ((__format__ (__printf__, 3, 0))); 75 __attribute__ ((__format__ (__printf__, 3, 0)));
72 76
73#ifdef __cplusplus 77#ifdef __cplusplus
74} 78}
75#endif 79#endif
76 80
diff --git a/gl/vasprintf.c b/gl/vasprintf.c
index 8247073..90f64e9 100644
--- a/gl/vasprintf.c
+++ b/gl/vasprintf.c
@@ -1,9 +1,9 @@
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-2007 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
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -18,7 +18,11 @@
18#include <config.h> 18#include <config.h>
19 19
20/* Specification. */ 20/* Specification. */
21#include "vasprintf.h" 21#ifdef IN_LIBASPRINTF
22# include "vasprintf.h"
23#else
24# include <stdio.h>
25#endif
22 26
23#include <errno.h> 27#include <errno.h>
24#include <limits.h> 28#include <limits.h>
diff --git a/gl/vasprintf.h b/gl/vasprintf.h
deleted file mode 100644
index ab5515c..0000000
--- a/gl/vasprintf.h
+++ /dev/null
@@ -1,63 +0,0 @@
1/* vsprintf with automatic memory allocation.
2 Copyright (C) 2002-2003 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 2, 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#ifndef _VASPRINTF_H
19#define _VASPRINTF_H
20
21#if HAVE_VASPRINTF
22
23/* Get asprintf(), vasprintf() declarations. */
24#include <stdio.h>
25
26#else
27
28/* Get va_list. */
29#include <stdarg.h>
30
31#ifndef __attribute__
32/* This feature is available in gcc versions 2.5 and later. */
33# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
34# define __attribute__(Spec) /* empty */
35# endif
36/* The __-protected variants of `format' and `printf' attributes
37 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
38# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
39# define __format__ format
40# define __printf__ printf
41# endif
42#endif
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/* Write formatted output to a string dynamically allocated with malloc().
49 If the memory allocation succeeds, store the address of the string in
50 *RESULT and return the number of resulting bytes, excluding the trailing
51 NUL. Upon memory allocation error, or some other error, return -1. */
52extern int asprintf (char **result, const char *format, ...)
53 __attribute__ ((__format__ (__printf__, 2, 3)));
54extern int vasprintf (char **result, const char *format, va_list args)
55 __attribute__ ((__format__ (__printf__, 2, 0)));
56
57#ifdef __cplusplus
58}
59#endif
60
61#endif
62
63#endif /* _VASPRINTF_H */
diff --git a/gl/vsnprintf.c b/gl/vsnprintf.c
index af567d2..cc8f61f 100644
--- a/gl/vsnprintf.c
+++ b/gl/vsnprintf.c
@@ -1,10 +1,10 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 2004, 2006 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2006-2007 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
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -21,12 +21,11 @@
21#endif 21#endif
22 22
23/* Specification. */ 23/* Specification. */
24#include "vsnprintf.h" 24#include <stdio.h>
25 25
26#include <errno.h> 26#include <errno.h>
27#include <limits.h> 27#include <limits.h>
28#include <stdarg.h> 28#include <stdarg.h>
29#include <stdio.h>
30#include <stdlib.h> 29#include <stdlib.h>
31#include <string.h> 30#include <string.h>
32 31
@@ -41,7 +40,7 @@
41 additional length SIZE limit how much is written into STR. Returns 40 additional length SIZE limit how much is written into STR. Returns
42 string length of formatted string (which may be larger than SIZE). 41 string length of formatted string (which may be larger than SIZE).
43 STR may be NULL, in which case nothing will be written. On error, 42 STR may be NULL, in which case nothing will be written. On error,
44 return a negative value. */ 43 return a negative value. */
45int 44int
46vsnprintf (char *str, size_t size, const char *format, va_list args) 45vsnprintf (char *str, size_t size, const char *format, va_list args)
47{ 46{
diff --git a/gl/vsnprintf.h b/gl/vsnprintf.h
deleted file mode 100644
index f80c77a..0000000
--- a/gl/vsnprintf.h
+++ /dev/null
@@ -1,31 +0,0 @@
1/* Formatted output to strings.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>.
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 2, 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#ifndef VSNPRINTF_H
20#define VSNPRINTF_H
21
22#include <stdarg.h>
23
24/* Get vsnprintf declaration, if available. */
25#include <stdio.h>
26
27#if defined HAVE_DECL_VSNPRINTF && !HAVE_DECL_VSNPRINTF
28int vsnprintf (char *str, size_t size, const char *format, va_list args);
29#endif
30
31#endif /* VSNPRINTF_H */
diff --git a/gl/wchar_.h b/gl/wchar.in.h
index 6813a21..b721572 100644
--- a/gl/wchar_.h
+++ b/gl/wchar.in.h
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -22,11 +22,11 @@
22 * ISO C 99 <wchar.h> for platforms that have issues. 22 * ISO C 99 <wchar.h> for platforms that have issues.
23 * <http://www.opengroup.org/susv3xbd/wchar.h.html> 23 * <http://www.opengroup.org/susv3xbd/wchar.h.html>
24 * 24 *
25 * For now, this just ensures proper prerequisite inclusion order. 25 * For now, this just ensures proper prerequisite inclusion order and
26 * the declaration of wcwidth().
26 */ 27 */
27 28
28#ifndef _GL_WCHAR_H 29#ifndef _GL_WCHAR_H
29#define _GL_WCHAR_H
30 30
31/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 31/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
32 <wchar.h>. 32 <wchar.h>.
@@ -36,7 +36,47 @@
36#include <stdio.h> 36#include <stdio.h>
37#include <time.h> 37#include <time.h>
38 38
39/* Include the original <wchar.h>. */ 39/* Include the original <wchar.h> if it exists.
40#include @ABSOLUTE_WCHAR_H@ 40 Some builds of uClibc lack it. */
41/* The include_next requires a split double-inclusion guard. */
42#if @HAVE_WCHAR_H@
43# @INCLUDE_NEXT@ @NEXT_WCHAR_H@
44#endif
45
46#ifndef _GL_WCHAR_H
47#define _GL_WCHAR_H
48
49/* The definition of GL_LINK_WARNING is copied here. */
50
51#ifdef __cplusplus
52extern "C" {
53#endif
41 54
55
56/* Return the number of screen columns needed for WC. */
57#if @GNULIB_WCWIDTH@
58# if @REPLACE_WCWIDTH@
59# undef wcwidth
60# define wcwidth rpl_wcwidth
61extern int wcwidth (wchar_t);
62# else
63# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
64/* wcwidth exists but is not declared. */
65extern int wcwidth (int /* actually wchar_t */);
66# endif
67# endif
68#elif defined GNULIB_POSIXCHECK
69# undef wcwidth
70# define wcwidth(w) \
71 (GL_LINK_WARNING ("wcwidth is unportable - " \
72 "use gnulib module wcwidth for portability"), \
73 wcwidth (w))
74#endif
75
76
77#ifdef __cplusplus
78}
79#endif
80
81#endif /* _GL_WCHAR_H */
42#endif /* _GL_WCHAR_H */ 82#endif /* _GL_WCHAR_H */
diff --git a/gl/wctype_.h b/gl/wctype.in.h
index 1297c61..a86b5ad 100644
--- a/gl/wctype_.h
+++ b/gl/wctype.in.h
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -27,7 +27,6 @@
27 */ 27 */
28 28
29#ifndef _GL_WCTYPE_H 29#ifndef _GL_WCTYPE_H
30#define _GL_WCTYPE_H
31 30
32#if @HAVE_WINT_T@ 31#if @HAVE_WINT_T@
33/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. 32/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
@@ -39,20 +38,27 @@
39# include <stdio.h> 38# include <stdio.h>
40# include <time.h> 39# include <time.h>
41# include <wchar.h> 40# include <wchar.h>
42typedef wint_t __wctype_wint_t;
43#else
44typedef int __wctype_wint_t;
45#endif 41#endif
46 42
47/* Include the original <wctype.h> if it exists. 43/* Include the original <wctype.h> if it exists.
48 BeOS 5 has the functions but no <wctype.h>. */ 44 BeOS 5 has the functions but no <wctype.h>. */
45/* The include_next requires a split double-inclusion guard. */
49#if @HAVE_WCTYPE_H@ 46#if @HAVE_WCTYPE_H@
50# include @ABSOLUTE_WCTYPE_H@ 47# @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
48#endif
49
50#ifndef _GL_WCTYPE_H
51#define _GL_WCTYPE_H
52
53#if @HAVE_WINT_T@
54typedef wint_t __wctype_wint_t;
55#else
56typedef int __wctype_wint_t;
51#endif 57#endif
52 58
53/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions. 59/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
54 Assume all 12 functions are implemented the same way, or not at all. */ 60 Assume all 12 functions are implemented the same way, or not at all. */
55#if ! HAVE_ISWCNTRL 61#if ! @HAVE_ISWCNTRL@
56 62
57/* IRIX 5.3 has macros but no functions, its isw* macros refer to an 63/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
58 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they 64 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
@@ -152,3 +158,4 @@ iswxdigit (__wctype_wint_t wc)
152# endif /* ! HAVE_ISWCNTRL */ 158# endif /* ! HAVE_ISWCNTRL */
153 159
154#endif /* _GL_WCTYPE_H */ 160#endif /* _GL_WCTYPE_H */
161#endif /* _GL_WCTYPE_H */
diff --git a/gl/wcwidth.h b/gl/wcwidth.h
deleted file mode 100644
index 8ed5ff8..0000000
--- a/gl/wcwidth.h
+++ /dev/null
@@ -1,57 +0,0 @@
1/* Determine the number of screen columns needed for a character.
2 Copyright (C) 2006, 2007 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 2, 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#ifndef _gl_WCWIDTH_H
19#define _gl_WCWIDTH_H
20
21#if HAVE_WCHAR_T
22
23/* Get wcwidth if available, along with wchar_t. */
24# include <wchar.h>
25
26/* Get iswprint. */
27# include <wctype.h>
28
29# ifndef HAVE_DECL_WCWIDTH
30"this configure-time declaration test was not run"
31# endif
32# ifndef wcwidth
33# if !HAVE_WCWIDTH
34
35/* wcwidth doesn't exist, so assume all printable characters have
36 width 1. */
37static inline int
38wcwidth (wchar_t wc)
39{
40 return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
41}
42
43# elif !HAVE_DECL_WCWIDTH
44
45/* wcwidth exists but is not declared. */
46extern
47# ifdef __cplusplus
48"C"
49# endif
50int wcwidth (int /* actually wchar_t */);
51
52# endif
53# endif
54
55#endif /* HAVE_WCHAR_T */
56
57#endif /* _gl_WCWIDTH_H */
diff --git a/gl/xalloc-die.c b/gl/xalloc-die.c
index 090f060..0a0694f 100644
--- a/gl/xalloc-die.c
+++ b/gl/xalloc-die.c
@@ -3,10 +3,10 @@
3 Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free 3 Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free
4 Software Foundation, Inc. 4 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#include <config.h> 19#include <config.h>
21 20
diff --git a/gl/xalloc.h b/gl/xalloc.h
index 17ab514..40dcf4b 100644
--- a/gl/xalloc.h
+++ b/gl/xalloc.h
@@ -1,12 +1,12 @@
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,
4 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc. 4 1999, 2000, 2003, 2004, 2006, 2007, 2008 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
8 the Free Software Foundation; either version 2, or (at your option) 8 the Free Software Foundation; either version 3 of the License, or
9 any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
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, write to the Free Software Foundation, 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 18
20#ifndef XALLOC_H_ 19#ifndef XALLOC_H_
21# define XALLOC_H_ 20# define XALLOC_H_
@@ -29,7 +28,7 @@ extern "C" {
29 28
30 29
31# ifndef __attribute__ 30# ifndef __attribute__
32# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ 31# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
33# define __attribute__(x) 32# define __attribute__(x)
34# endif 33# endif
35# endif 34# endif
@@ -139,10 +138,10 @@ xnrealloc (void *p, size_t n, size_t s)
139 allocating an initial block with a nonzero size, or by allocating a 138 allocating an initial block with a nonzero size, or by allocating a
140 larger block. 139 larger block.
141 140
142 In the following implementation, nonzero sizes are doubled so that 141 In the following implementation, nonzero sizes are increased by a
143 repeated reallocations have O(N log N) overall cost rather than 142 factor of approximately 1.5 so that repeated reallocations have
144 O(N**2) cost, but the specification for this function does not 143 O(N) overall cost rather than O(N**2) cost, but the
145 guarantee that sizes are doubled. 144 specification for this function does not guarantee that rate.
146 145
147 Here is an example of use: 146 Here is an example of use:
148 147
@@ -204,9 +203,13 @@ x2nrealloc (void *p, size_t *pn, size_t s)
204 } 203 }
205 else 204 else
206 { 205 {
207 if (((size_t) -1) / 2 / s < n) 206 /* Set N = ceil (1.5 * N) so that progress is made if N == 1.
207 Check for overflow, so that N * S stays in size_t range.
208 The check is slightly conservative, but an exact check isn't
209 worth the trouble. */
210 if ((size_t) -1 / 3 * 2 / s <= n)
208 xalloc_die (); 211 xalloc_die ();
209 n *= 2; 212 n += (n + 1) / 2;
210 } 213 }
211 214
212 *pn = n; 215 *pn = n;
diff --git a/gl/xmalloc.c b/gl/xmalloc.c
index 318e0dd..3a12345 100644
--- a/gl/xmalloc.c
+++ b/gl/xmalloc.c
@@ -4,10 +4,10 @@
4 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, 4 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
5 Inc. 5 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
9 the Free Software Foundation; either version 2, or (at your option) 9 the Free Software Foundation; either version 3 of the License, or
10 any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,8 +15,7 @@
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation, 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 19
21#include <config.h> 20#include <config.h>
22 21
diff --git a/gl/xsize.h b/gl/xsize.h
index 341fb16..b294d66 100644
--- a/gl/xsize.h
+++ b/gl/xsize.h
@@ -4,7 +4,7 @@
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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
diff --git a/gl/xstrndup.c b/gl/xstrndup.c
index afcbc1a..37488cd 100644
--- a/gl/xstrndup.c
+++ b/gl/xstrndup.c
@@ -1,11 +1,11 @@
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 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2006, 2007 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,15 +13,14 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19#include <config.h> 18#include <config.h>
20 19
21/* Specification. */ 20/* Specification. */
22#include "xstrndup.h" 21#include "xstrndup.h"
23 22
24#include "strndup.h" 23#include <string.h>
25#include "xalloc.h" 24#include "xalloc.h"
26 25
27/* Return a newly allocated copy of at most N bytes of STRING. 26/* Return a newly allocated copy of at most N bytes of STRING.
diff --git a/gl/xstrndup.h b/gl/xstrndup.h
index 88354cf..4882e39 100644
--- a/gl/xstrndup.h
+++ b/gl/xstrndup.h
@@ -2,10 +2,10 @@
2 checking. 2 checking.
3 Copyright (C) 2003 Free Software Foundation, Inc. 3 Copyright (C) 2003 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
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 3 of the License, or
8 any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
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, write to the Free Software Foundation, 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19#include <stddef.h> 18#include <stddef.h>
20 19