summaryrefslogtreecommitdiffstats
path: root/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gl')
-rw-r--r--gl/Makefile.am2392
-rw-r--r--gl/_Noreturn.h50
-rw-r--r--gl/af_alg.c213
-rw-r--r--gl/af_alg.h115
-rw-r--r--gl/alloca.in.h35
-rw-r--r--gl/arg-nonnull.h26
-rw-r--r--gl/arpa_inet.in.h32
-rw-r--r--gl/asnprintf.c18
-rw-r--r--gl/asprintf.c18
-rw-r--r--gl/assert.in.h27
-rw-r--r--gl/attribute.h226
-rw-r--r--gl/base64.c126
-rw-r--r--gl/base64.h41
-rw-r--r--gl/basename-lgpl.c37
-rw-r--r--gl/basename-lgpl.h78
-rw-r--r--gl/basename.c56
-rw-r--r--gl/btowc.c18
-rw-r--r--gl/byteswap.in.h44
-rw-r--r--gl/c++defs.h331
-rw-r--r--gl/calloc.c55
-rw-r--r--gl/cdefs.h707
-rw-r--r--gl/cloexec.c83
-rw-r--r--gl/cloexec.h34
-rw-r--r--gl/close.c75
-rw-r--r--gl/config.charset684
-rw-r--r--gl/dirname-lgpl.c18
-rw-r--r--gl/dirname.c6
-rw-r--r--gl/dirname.h55
-rw-r--r--gl/dosname.h53
-rw-r--r--gl/dup2.c189
-rw-r--r--gl/dynarray.h284
-rw-r--r--gl/errno.in.h22
-rw-r--r--gl/error.c74
-rw-r--r--gl/error.h45
-rw-r--r--gl/exitfail.c18
-rw-r--r--gl/exitfail.h18
-rw-r--r--gl/fcntl.c629
-rw-r--r--gl/fcntl.in.h445
-rw-r--r--gl/fd-hook.c22
-rw-r--r--gl/fd-hook.h22
-rw-r--r--gl/fflush.c233
-rw-r--r--gl/filename.h112
-rw-r--r--gl/float+.h18
-rw-r--r--gl/float.c18
-rw-r--r--gl/float.in.h30
-rw-r--r--gl/floor.c20
-rw-r--r--gl/floorf.c18
-rw-r--r--gl/fopen.c229
-rw-r--r--gl/fpurge.c150
-rw-r--r--gl/freading.c76
-rw-r--r--gl/freading.h54
-rw-r--r--gl/free.c53
-rw-r--r--gl/fseek.c30
-rw-r--r--gl/fseeko.c164
-rw-r--r--gl/fstat.c94
-rw-r--r--gl/fsusage.c123
-rw-r--r--gl/fsusage.h22
-rw-r--r--gl/ftell.c37
-rw-r--r--gl/ftello.c157
-rw-r--r--gl/full-read.c18
-rw-r--r--gl/full-read.h24
-rw-r--r--gl/full-write.c79
-rw-r--r--gl/gai_strerror.c18
-rw-r--r--gl/getaddrinfo.c180
-rw-r--r--gl/getdelim.c147
-rw-r--r--gl/getdtablesize.c124
-rw-r--r--gl/gethostname.c20
-rw-r--r--gl/getline.c27
-rw-r--r--gl/getloadavg.c179
-rw-r--r--gl/getopt-cdefs.in.h66
-rw-r--r--gl/getopt-core.h96
-rw-r--r--gl/getopt-ext.h77
-rw-r--r--gl/getopt-pfx-core.h66
-rw-r--r--gl/getopt-pfx-ext.h70
-rw-r--r--gl/getopt.c1442
-rw-r--r--gl/getopt.in.h242
-rw-r--r--gl/getopt1.c179
-rw-r--r--gl/getopt_int.h91
-rw-r--r--gl/getprogname.c302
-rw-r--r--gl/getprogname.h40
-rw-r--r--gl/gettext.h50
-rw-r--r--gl/gl_openssl.h116
-rw-r--r--gl/glthread/lock.c866
-rw-r--r--gl/glthread/lock.h544
-rw-r--r--gl/glthread/threadlib.c55
-rw-r--r--gl/hard-locale.c35
-rw-r--r--gl/hard-locale.h26
-rw-r--r--gl/ialloc.c21
-rw-r--r--gl/ialloc.h100
-rw-r--r--gl/idpriv-droptemp.c14
-rw-r--r--gl/idpriv.h12
-rw-r--r--gl/idx.h134
-rw-r--r--gl/inet_ntop.c20
-rw-r--r--gl/intprops-internal.h392
-rw-r--r--gl/intprops.h250
-rw-r--r--gl/inttypes.in.h1002
-rw-r--r--gl/itold.c18
-rw-r--r--gl/langinfo.in.h66
-rw-r--r--gl/lc-charset-dispatch.c82
-rw-r--r--gl/lc-charset-dispatch.h40
-rw-r--r--gl/libc-config.h202
-rw-r--r--gl/limits.in.h131
-rw-r--r--gl/localcharset.c1309
-rw-r--r--gl/localcharset.h119
-rw-r--r--gl/locale.in.h121
-rw-r--r--gl/localeconv.c18
-rw-r--r--gl/lseek.c89
-rw-r--r--gl/m4/00gnulib.m491
-rw-r--r--gl/m4/__inline.m422
-rw-r--r--gl/m4/absolute-header.m4100
-rw-r--r--gl/m4/af_alg.m457
-rw-r--r--gl/m4/alloca.m453
-rw-r--r--gl/m4/arpa_inet_h.m435
-rw-r--r--gl/m4/assert_h.m467
-rw-r--r--gl/m4/base64.m42
-rw-r--r--gl/m4/btowc.m433
-rw-r--r--gl/m4/builtin-expect.m449
-rw-r--r--gl/m4/byteswap.m417
-rw-r--r--gl/m4/c-bool.m451
-rw-r--r--gl/m4/calloc.m483
-rw-r--r--gl/m4/close.m435
-rw-r--r--gl/m4/codeset.m43
-rw-r--r--gl/m4/configmake.m450
-rw-r--r--gl/m4/dirname.m419
-rw-r--r--gl/m4/double-slash-root.m42
-rw-r--r--gl/m4/dup2.m4105
-rw-r--r--gl/m4/eealloc.m42
-rw-r--r--gl/m4/environ.m423
-rw-r--r--gl/m4/errno_h.m420
-rw-r--r--gl/m4/error.m48
-rw-r--r--gl/m4/exponentd.m42
-rw-r--r--gl/m4/extensions.m4214
-rw-r--r--gl/m4/extern-inline.m496
-rw-r--r--gl/m4/fcntl-o.m422
-rw-r--r--gl/m4/fcntl.m4151
-rw-r--r--gl/m4/fcntl_h.m470
-rw-r--r--gl/m4/fflush.m4100
-rw-r--r--gl/m4/float_h.m454
-rw-r--r--gl/m4/floorf.m418
-rw-r--r--gl/m4/fopen.m4149
-rw-r--r--gl/m4/fpurge.m473
-rw-r--r--gl/m4/freading.m4 (renamed from gl/m4/sha1.m4)11
-rw-r--r--gl/m4/free.m452
-rw-r--r--gl/m4/fseek.m415
-rw-r--r--gl/m4/fseeko.m477
-rw-r--r--gl/m4/fstat.m440
-rw-r--r--gl/m4/fstypename.m42
-rw-r--r--gl/m4/fsusage.m4363
-rw-r--r--gl/m4/ftell.m415
-rw-r--r--gl/m4/ftello.m4151
-rw-r--r--gl/m4/getaddrinfo.m443
-rw-r--r--gl/m4/getdelim.m4111
-rw-r--r--gl/m4/getdtablesize.m463
-rw-r--r--gl/m4/gethostname.m48
-rw-r--r--gl/m4/getline.m4109
-rw-r--r--gl/m4/getloadavg.m417
-rw-r--r--gl/m4/getopt.m439
-rw-r--r--gl/m4/getprogname.m443
-rw-r--r--gl/m4/gettext.m4401
-rw-r--r--gl/m4/gl-openssl.m476
-rw-r--r--gl/m4/glibc2.m431
-rw-r--r--gl/m4/glibc21.m434
-rw-r--r--gl/m4/gnulib-cache.m444
-rw-r--r--gl/m4/gnulib-common.m41022
-rw-r--r--gl/m4/gnulib-comp.m4885
-rw-r--r--gl/m4/gnulib-tool.m410
-rw-r--r--gl/m4/hostent.m48
-rw-r--r--gl/m4/iconv.m4268
-rw-r--r--gl/m4/idpriv.m42
-rw-r--r--gl/m4/include_next.m490
-rw-r--r--gl/m4/inet_ntop.m416
-rw-r--r--gl/m4/intdiv0.m487
-rw-r--r--gl/m4/intl.m4271
-rw-r--r--gl/m4/intldir.m419
-rw-r--r--gl/m4/intlmacosx.m456
-rw-r--r--gl/m4/intmax.m436
-rw-r--r--gl/m4/intmax_t.m416
-rw-r--r--gl/m4/inttypes-pri.m442
-rw-r--r--gl/m4/inttypes.m4180
-rw-r--r--gl/m4/inttypes_h.m42
-rw-r--r--gl/m4/langinfo_h.m448
-rw-r--r--gl/m4/largefile.m4378
-rw-r--r--gl/m4/lcmessage.m435
-rw-r--r--gl/m4/lib-ld.m4119
-rw-r--r--gl/m4/lib-link.m4777
-rw-r--r--gl/m4/lib-prefix.m4224
-rw-r--r--gl/m4/limits-h.m441
-rw-r--r--gl/m4/localcharset.m410
-rw-r--r--gl/m4/locale-fr.m443
-rw-r--r--gl/m4/locale-ja.m445
-rw-r--r--gl/m4/locale-zh.m445
-rw-r--r--gl/m4/locale_h.m4134
-rw-r--r--gl/m4/localeconv.m42
-rw-r--r--gl/m4/lock.m411
-rw-r--r--gl/m4/longlong.m4113
-rw-r--r--gl/m4/ls-mntd-fs.m4357
-rw-r--r--gl/m4/lseek.m478
-rw-r--r--gl/m4/malloc.m4173
-rw-r--r--gl/m4/malloca.m45
-rw-r--r--gl/m4/math_h.m4560
-rw-r--r--gl/m4/mbrtowc.m4358
-rw-r--r--gl/m4/mbsinit.m415
-rw-r--r--gl/m4/mbstate_t.m413
-rw-r--r--gl/m4/mbtowc.m413
-rw-r--r--gl/m4/memchr.m474
-rw-r--r--gl/m4/minmax.m444
-rw-r--r--gl/m4/mktime.m4142
-rw-r--r--gl/m4/mmap-anon.m48
-rw-r--r--gl/m4/mode_t.m426
-rw-r--r--gl/m4/mountlist.m4331
-rw-r--r--gl/m4/msvc-inval.m42
-rw-r--r--gl/m4/msvc-nothrow.m42
-rw-r--r--gl/m4/multiarch.m469
-rw-r--r--gl/m4/netdb_h.m428
-rw-r--r--gl/m4/netinet_in_h.m410
-rw-r--r--gl/m4/nl_langinfo.m437
-rw-r--r--gl/m4/nls.m432
-rw-r--r--gl/m4/nocrash.m413
-rw-r--r--gl/m4/off_t.m42
-rw-r--r--gl/m4/onceonly.m4104
-rw-r--r--gl/m4/open-cloexec.m421
-rw-r--r--gl/m4/open-slash.m460
-rw-r--r--gl/m4/open.m456
-rw-r--r--gl/m4/pathmax.m442
-rw-r--r--gl/m4/pid_t.m438
-rw-r--r--gl/m4/po.m4453
-rw-r--r--gl/m4/printf-posix.m448
-rw-r--r--gl/m4/printf.m4490
-rw-r--r--gl/m4/progtest.m491
-rw-r--r--gl/m4/pthread_rwlock_rdlock.m4185
-rw-r--r--gl/m4/read.m426
-rw-r--r--gl/m4/realloc.m463
-rw-r--r--gl/m4/reallocarray.m423
-rw-r--r--gl/m4/regex.m4193
-rw-r--r--gl/m4/safe-read.m412
-rw-r--r--gl/m4/servent.m48
-rw-r--r--gl/m4/setenv.m476
-rw-r--r--gl/m4/setlocale_null.m498
-rw-r--r--gl/m4/sha256.m414
-rw-r--r--gl/m4/size_max.m416
-rw-r--r--gl/m4/snprintf.m412
-rw-r--r--gl/m4/socketlib.m438
-rw-r--r--gl/m4/sockets.m42
-rw-r--r--gl/m4/socklen.m417
-rw-r--r--gl/m4/sockpfaf.m423
-rw-r--r--gl/m4/ssize_t.m42
-rw-r--r--gl/m4/stat-time.m483
-rw-r--r--gl/m4/stat.m485
-rw-r--r--gl/m4/std-gnu11.m4829
-rw-r--r--gl/m4/stdalign.m4121
-rw-r--r--gl/m4/stdbool.m4100
-rw-r--r--gl/m4/stddef_h.m481
-rw-r--r--gl/m4/stdint.m4169
-rw-r--r--gl/m4/stdint_h.m42
-rw-r--r--gl/m4/stdio_h.m4229
-rw-r--r--gl/m4/stdlib_h.m4173
-rw-r--r--gl/m4/strcase.m48
-rw-r--r--gl/m4/strcasestr.m461
-rw-r--r--gl/m4/strerror.m430
-rw-r--r--gl/m4/string_h.m4150
-rw-r--r--gl/m4/strings_h.m440
-rw-r--r--gl/m4/strndup.m455
-rw-r--r--gl/m4/strnlen.m430
-rw-r--r--gl/m4/strsep.m46
-rw-r--r--gl/m4/strstr.m467
-rw-r--r--gl/m4/sys_socket_h.m488
-rw-r--r--gl/m4/sys_stat_h.m4129
-rw-r--r--gl/m4/sys_types_h.m450
-rw-r--r--gl/m4/sys_uio_h.m425
-rw-r--r--gl/m4/threadlib.m4667
-rw-r--r--gl/m4/time_h.m4114
-rw-r--r--gl/m4/time_r.m449
-rw-r--r--gl/m4/timegm.m410
-rw-r--r--gl/m4/uintmax_t.m430
-rw-r--r--gl/m4/ungetc.m473
-rw-r--r--gl/m4/unistd_h.m4348
-rw-r--r--gl/m4/unlocked-io.m436
-rw-r--r--gl/m4/vararrays.m472
-rw-r--r--gl/m4/vasnprintf.m417
-rw-r--r--gl/m4/vasprintf.m42
-rw-r--r--gl/m4/visibility.m479
-rw-r--r--gl/m4/vsnprintf.m412
-rw-r--r--gl/m4/warn-on-use.m461
-rw-r--r--gl/m4/wchar_h.m4222
-rw-r--r--gl/m4/wchar_t.m42
-rw-r--r--gl/m4/wcrtomb.m490
-rw-r--r--gl/m4/wctype_h.m499
-rw-r--r--gl/m4/wint_t.m449
-rw-r--r--gl/m4/xalloc.m42
-rw-r--r--gl/m4/xsize.m42
-rw-r--r--gl/m4/xstrndup.m415
-rw-r--r--gl/m4/zzgnulib.m423
-rw-r--r--gl/malloc.c43
-rw-r--r--gl/malloc/dynarray-skeleton.c528
-rw-r--r--gl/malloc/dynarray.h177
-rw-r--r--gl/malloc/dynarray_at_failure.c40
-rw-r--r--gl/malloc/dynarray_emplace_enlarge.c77
-rw-r--r--gl/malloc/dynarray_finalize.c66
-rw-r--r--gl/malloc/dynarray_resize.c68
-rw-r--r--gl/malloc/dynarray_resize_clear.c39
-rw-r--r--gl/malloca.c165
-rw-r--r--gl/malloca.h69
-rw-r--r--gl/malloca.valgrind7
-rw-r--r--gl/math.c19
-rw-r--r--gl/math.in.h722
-rw-r--r--gl/mbrtowc-impl-utf8.h138
-rw-r--r--gl/mbrtowc-impl.h262
-rw-r--r--gl/mbrtowc.c393
-rw-r--r--gl/mbsinit.c52
-rw-r--r--gl/mbtowc-impl.h18
-rw-r--r--gl/mbtowc-lock.c150
-rw-r--r--gl/mbtowc-lock.h125
-rw-r--r--gl/mbtowc.c18
-rw-r--r--gl/memchr.c26
-rw-r--r--gl/memchr.valgrind16
-rw-r--r--gl/minmax.h60
-rw-r--r--gl/mktime-internal.h83
-rw-r--r--gl/mktime.c837
-rw-r--r--gl/mountlist.c486
-rw-r--r--gl/mountlist.h14
-rw-r--r--gl/msvc-inval.c18
-rw-r--r--gl/msvc-inval.h22
-rw-r--r--gl/msvc-nothrow.c22
-rw-r--r--gl/msvc-nothrow.h20
-rw-r--r--gl/netdb.in.h72
-rw-r--r--gl/netinet_in.in.h18
-rw-r--r--gl/nl_langinfo-lock.c150
-rw-r--r--gl/nl_langinfo.c579
-rw-r--r--gl/open.c209
-rw-r--r--gl/pathmax.h83
-rw-r--r--gl/printf-args.c22
-rw-r--r--gl/printf-args.h30
-rw-r--r--gl/printf-parse.c55
-rw-r--r--gl/printf-parse.h18
-rw-r--r--gl/read.c85
-rw-r--r--gl/realloc.c63
-rw-r--r--gl/reallocarray.c38
-rw-r--r--gl/ref-add.sin29
-rw-r--r--gl/ref-del.sin24
-rw-r--r--gl/regcomp.c1364
-rw-r--r--gl/regex.c21
-rw-r--r--gl/regex.h142
-rw-r--r--gl/regex_internal.c394
-rw-r--r--gl/regex_internal.h299
-rw-r--r--gl/regexec.c1169
-rw-r--r--gl/safe-read.c77
-rw-r--r--gl/safe-read.h47
-rw-r--r--gl/setenv.c20
-rw-r--r--gl/setlocale-lock.c150
-rw-r--r--gl/setlocale_null.c411
-rw-r--r--gl/setlocale_null.h82
-rw-r--r--gl/sha1.c426
-rw-r--r--gl/sha1.h91
-rw-r--r--gl/sha256-stream.c145
-rw-r--r--gl/sha256.c432
-rw-r--r--gl/sha256.h121
-rw-r--r--gl/size_max.h18
-rw-r--r--gl/snprintf.c18
-rw-r--r--gl/sockets.c33
-rw-r--r--gl/sockets.h46
-rw-r--r--gl/stat-time.c21
-rw-r--r--gl/stat-time.h251
-rw-r--r--gl/stat-w32.c460
-rw-r--r--gl/stat-w32.h37
-rw-r--r--gl/stat.c438
-rw-r--r--gl/stdalign.in.h78
-rw-r--r--gl/stdbool.in.h132
-rw-r--r--gl/stdckdint.in.h35
-rw-r--r--gl/stddef.in.h111
-rw-r--r--gl/stdint.in.h834
-rw-r--r--gl/stdio-impl.h218
-rw-r--r--gl/stdio-read.c168
-rw-r--r--gl/stdio-write.c206
-rw-r--r--gl/stdio.in.h715
-rw-r--r--gl/stdlib.in.h763
-rw-r--r--gl/str-two-way.h30
-rw-r--r--gl/strcasecmp.c20
-rw-r--r--gl/strcasestr.c19
-rw-r--r--gl/streq.h22
-rw-r--r--gl/strerror-override.c104
-rw-r--r--gl/strerror-override.h21
-rw-r--r--gl/strerror.c24
-rw-r--r--gl/string.in.h467
-rw-r--r--gl/strings.in.h18
-rw-r--r--gl/stripslash.c18
-rw-r--r--gl/strncasecmp.c20
-rw-r--r--gl/strndup.c36
-rw-r--r--gl/strnlen.c30
-rw-r--r--gl/strsep.c18
-rw-r--r--gl/strstr.c24
-rw-r--r--gl/sys-limits.h42
-rw-r--r--gl/sys_socket.c19
-rw-r--r--gl/sys_socket.in.h138
-rw-r--r--gl/sys_stat.in.h954
-rw-r--r--gl/sys_types.in.h77
-rw-r--r--gl/sys_uio.in.h18
-rw-r--r--gl/time.in.h273
-rw-r--r--gl/time_r.c18
-rw-r--r--gl/timegm.c62
-rw-r--r--gl/unistd.c19
-rw-r--r--gl/unistd.in.h997
-rw-r--r--gl/unlocked-io.h136
-rw-r--r--gl/unsetenv.c18
-rw-r--r--gl/vasnprintf.c932
-rw-r--r--gl/vasnprintf.h41
-rw-r--r--gl/vasprintf.c18
-rw-r--r--gl/verify.h191
-rw-r--r--gl/vsnprintf.c18
-rw-r--r--gl/w32sock.h24
-rw-r--r--gl/warn-on-use.h149
-rw-r--r--gl/wchar.in.h571
-rw-r--r--gl/wcrtomb.c49
-rw-r--r--gl/wctype-h.c19
-rw-r--r--gl/wctype.in.h457
-rw-r--r--gl/windows-initguard.h35
-rw-r--r--gl/windows-mutex.c95
-rw-r--r--gl/windows-mutex.h51
-rw-r--r--gl/windows-once.c62
-rw-r--r--gl/windows-once.h47
-rw-r--r--gl/windows-recmutex.c127
-rw-r--r--gl/windows-recmutex.h57
-rw-r--r--gl/windows-rwlock.c377
-rw-r--r--gl/windows-rwlock.h68
-rw-r--r--gl/xalloc-die.c6
-rw-r--r--gl/xalloc-oversized.h79
-rw-r--r--gl/xalloc.h231
-rw-r--r--gl/xmalloc.c306
-rw-r--r--gl/xsize.c18
-rw-r--r--gl/xsize.h44
-rw-r--r--gl/xstrndup.c36
-rw-r--r--gl/xstrndup.h23
431 files changed, 41435 insertions, 18888 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 15135c8..dcebd4a 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -1,10 +1,10 @@
1## DO NOT EDIT! GENERATED AUTOMATICALLY! 1## DO NOT EDIT! GENERATED AUTOMATICALLY!
2## Process this file with automake to produce Makefile.in. 2## Process this file with automake to produce Makefile.in.
3# Copyright (C) 2002-2013 Free Software Foundation, Inc. 3# Copyright (C) 2002-2023 Free Software Foundation, Inc.
4# 4#
5# This file is free software; you can redistribute it and/or modify 5# This file 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 3 of the License, or 7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version. 8# (at your option) any later version.
9# 9#
10# This file is distributed in the hope that it will be useful, 10# This file is distributed in the hope that it will be useful,
@@ -13,7 +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 file. If not, see <http://www.gnu.org/licenses/>. 16# along with this file. If not, see <https://www.gnu.org/licenses/>.
17# 17#
18# As a special exception to the GNU General Public License, 18# As a special exception to the GNU General Public License,
19# this file may be distributed as part of a program that 19# this file may be distributed as part of a program that
@@ -21,9 +21,42 @@
21# the same distribution terms as the rest of that program. 21# the same distribution terms as the rest of that program.
22# 22#
23# Generated by gnulib-tool. 23# Generated by gnulib-tool.
24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname environ floorf fsusage getaddrinfo gethostname getloadavg getopt-gnu gettext idpriv-droptemp mountlist regex setenv strcase strcasestr strsep timegm unsetenv vasprintf vsnprintf 24# Reproduce by:
25 25# gnulib-tool --import \
26AUTOMAKE_OPTIONS = 1.9.6 gnits subdir-objects 26# --lib=libgnu \
27# --source-base=gl \
28# --m4-base=gl/m4 \
29# --doc-base=doc \
30# --tests-base=tests \
31# --aux-dir=build-aux \
32# --no-conditional-dependencies \
33# --no-libtool \
34# --macro-prefix=gl \
35# --no-vc-files \
36# base64 \
37# crypto/sha256 \
38# dirname \
39# environ \
40# floorf \
41# fsusage \
42# getaddrinfo \
43# gethostname \
44# getloadavg \
45# getopt-gnu \
46# gettext-h \
47# idpriv-droptemp \
48# mountlist \
49# regex \
50# setenv \
51# strcase \
52# strcasestr \
53# strsep \
54# timegm \
55# unsetenv \
56# vasprintf \
57# vsnprintf
58
59AUTOMAKE_OPTIONS = 1.14 gnits subdir-objects
27 60
28SUBDIRS = 61SUBDIRS =
29noinst_HEADERS = 62noinst_HEADERS =
@@ -37,6 +70,7 @@ MOSTLYCLEANDIRS =
37CLEANFILES = 70CLEANFILES =
38DISTCLEANFILES = 71DISTCLEANFILES =
39MAINTAINERCLEANFILES = 72MAINTAINERCLEANFILES =
73# No GNU Make output.
40EXTRA_DIST += m4/gnulib-cache.m4 74EXTRA_DIST += m4/gnulib-cache.m4
41 75
42AM_CPPFLAGS = 76AM_CPPFLAGS =
@@ -45,10 +79,20 @@ AM_CFLAGS =
45noinst_LIBRARIES += libgnu.a 79noinst_LIBRARIES += libgnu.a
46 80
47libgnu_a_SOURCES = 81libgnu_a_SOURCES =
82libgnu_a_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
48libgnu_a_LIBADD = $(gl_LIBOBJS) 83libgnu_a_LIBADD = $(gl_LIBOBJS)
49libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 84libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
50EXTRA_libgnu_a_SOURCES = 85EXTRA_libgnu_a_SOURCES =
51 86
87## begin gnulib module absolute-header
88
89# Use this preprocessor expression to decide whether #include_next works.
90# Do not rely on a 'configure'-time test for this, since the expression
91# might appear in an installed header, which is used by some other compiler.
92HAVE_INCLUDE_NEXT = (__GNUC__ || __clang__ || 60000000 <= __DECC_VER)
93
94## end gnulib module absolute-header
95
52## begin gnulib module alloca-opt 96## begin gnulib module alloca-opt
53 97
54BUILT_SOURCES += $(ALLOCA_H) 98BUILT_SOURCES += $(ALLOCA_H)
@@ -57,11 +101,10 @@ BUILT_SOURCES += $(ALLOCA_H)
57# doesn't have one that works with the given compiler. 101# doesn't have one that works with the given compiler.
58if GL_GENERATE_ALLOCA_H 102if GL_GENERATE_ALLOCA_H
59alloca.h: alloca.in.h $(top_builddir)/config.status 103alloca.h: alloca.in.h $(top_builddir)/config.status
60 $(AM_V_GEN)rm -f $@-t $@ && \ 104 $(gl_V_at)$(SED_HEADER_STDOUT) \
61 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 105 -e 's|@''HAVE_ALLOCA_H''@|$(HAVE_ALLOCA_H)|g' \
62 cat $(srcdir)/alloca.in.h; \ 106 $(srcdir)/alloca.in.h > $@-t
63 } > $@-t && \ 107 $(AM_V_at)mv $@-t $@
64 mv -f $@-t $@
65else 108else
66alloca.h: $(top_builddir)/config.status 109alloca.h: $(top_builddir)/config.status
67 rm -f $@ 110 rm -f $@
@@ -79,18 +122,18 @@ BUILT_SOURCES += arpa/inet.h
79# We need the following in order to create <arpa/inet.h> when the system 122# We need the following in order to create <arpa/inet.h> when the system
80# doesn't have one. 123# doesn't have one.
81arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) 124arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
82 $(AM_V_at)$(MKDIR_P) arpa 125 $(AM_V_GEN)$(MKDIR_P) '%reldir%/arpa'
83 $(AM_V_GEN)rm -f $@-t $@ && \ 126 $(AM_V_at)$(SED_HEADER_STDOUT) \
84 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 127 -e 's|@''GUARD_PREFIX''@|GL|g' \
85 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
86 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 128 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
87 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 129 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
88 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 130 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
89 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \ 131 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
90 -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \ 132 -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \
91 -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \ 133 -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \
92 -e 's/@''GNULIB_INET_NTOP''@/$(GNULIB_INET_NTOP)/g' \ 134 -e 's/@''GNULIB_INET_NTOP''@/$(GL_GNULIB_INET_NTOP)/g' \
93 -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \ 135 -e 's/@''GNULIB_INET_PTON''@/$(GL_GNULIB_INET_PTON)/g' \
136 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
94 -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ 137 -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
95 -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ 138 -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
96 -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \ 139 -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \
@@ -98,9 +141,8 @@ arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON
98 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 141 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
99 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 142 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
100 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 143 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
101 < $(srcdir)/arpa_inet.in.h; \ 144 $(srcdir)/arpa_inet.in.h > $@-t
102 } > $@-t && \ 145 $(AM_V_at)mv $@-t $@
103 mv $@-t $@
104MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t 146MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t
105MOSTLYCLEANDIRS += arpa 147MOSTLYCLEANDIRS += arpa
106 148
@@ -108,72 +150,141 @@ EXTRA_DIST += arpa_inet.in.h
108 150
109## end gnulib module arpa_inet 151## end gnulib module arpa_inet
110 152
153## begin gnulib module assert-h
154
155BUILT_SOURCES += $(ASSERT_H)
156
157# We need the following in order to create <assert.h> when the system
158# doesn't have one that works with the given compiler.
159if GL_GENERATE_ASSERT_H
160assert.h: assert.in.h verify.h $(top_builddir)/config.status
161 $(gl_V_at){ $(SED_HEADER_STDOUT) \
162 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
163 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
164 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
165 -e 's|@''NEXT_ASSERT_H''@|$(NEXT_ASSERT_H)|g' \
166 < $(srcdir)/assert.in.h && \
167 sed -e '/@assert.h omit start@/,/@assert.h omit end@/d' \
168 -e 's|_gl_verify|_gl_static_assert|g' \
169 -e 's|_GL_VERIFY|_GL_STATIC_ASSERT|g' \
170 -e 's|_GL\(_STATIC_ASSERT_H\)|_GL\1|g' \
171 < $(srcdir)/verify.h; \
172 } > $@-t
173 $(AM_V_at)mv $@-t $@
174else
175assert.h: $(top_builddir)/config.status
176 rm -f $@
177endif
178MOSTLYCLEANFILES += assert.h assert.h-t
179
180EXTRA_DIST += assert.in.h verify.h
181
182## end gnulib module assert-h
183
184## begin gnulib module attribute
185
186
187EXTRA_DIST += attribute.h
188
189## end gnulib module attribute
190
111## begin gnulib module base64 191## begin gnulib module base64
112 192
113libgnu_a_SOURCES += base64.h base64.c 193libgnu_a_SOURCES += base64.h base64.c
114 194
115## end gnulib module base64 195## end gnulib module base64
116 196
117## begin gnulib module btowc 197## begin gnulib module basename-lgpl
118 198
199libgnu_a_SOURCES += basename-lgpl.c
119 200
120EXTRA_DIST += btowc.c 201EXTRA_DIST += basename-lgpl.h
121 202
122EXTRA_libgnu_a_SOURCES += btowc.c 203## end gnulib module basename-lgpl
204
205## begin gnulib module btowc
206
207if GL_COND_OBJ_BTOWC
208libgnu_a_SOURCES += btowc.c
209endif
123 210
124## end gnulib module btowc 211## end gnulib module btowc
125 212
126## begin gnulib module configmake 213## begin gnulib module byteswap
127 214
128# Listed in the same order as the GNU makefile conventions, and 215BUILT_SOURCES += $(BYTESWAP_H)
129# provided by autoconf 2.59c+. 216
130# The Automake-defined pkg* macros are appended, in the order 217# We need the following in order to create <byteswap.h> when the system
131# listed in the Automake 1.10a+ documentation. 218# doesn't have one.
132configmake.h: Makefile 219if GL_GENERATE_BYTESWAP_H
133 $(AM_V_GEN)rm -f $@-t && \ 220byteswap.h: byteswap.in.h $(top_builddir)/config.status
134 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 221 $(gl_V_at)$(SED_HEADER_TO_AT_t) $(srcdir)/byteswap.in.h
135 echo '#define PREFIX "$(prefix)"'; \ 222 $(AM_V_at)mv $@-t $@
136 echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ 223else
137 echo '#define BINDIR "$(bindir)"'; \ 224byteswap.h: $(top_builddir)/config.status
138 echo '#define SBINDIR "$(sbindir)"'; \ 225 rm -f $@
139 echo '#define LIBEXECDIR "$(libexecdir)"'; \ 226endif
140 echo '#define DATAROOTDIR "$(datarootdir)"'; \ 227MOSTLYCLEANFILES += byteswap.h byteswap.h-t
141 echo '#define DATADIR "$(datadir)"'; \ 228
142 echo '#define SYSCONFDIR "$(sysconfdir)"'; \ 229EXTRA_DIST += byteswap.in.h
143 echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \ 230
144 echo '#define LOCALSTATEDIR "$(localstatedir)"'; \ 231## end gnulib module byteswap
145 echo '#define INCLUDEDIR "$(includedir)"'; \ 232
146 echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \ 233## begin gnulib module calloc-gnu
147 echo '#define DOCDIR "$(docdir)"'; \ 234
148 echo '#define INFODIR "$(infodir)"'; \ 235
149 echo '#define HTMLDIR "$(htmldir)"'; \ 236EXTRA_DIST += calloc.c
150 echo '#define DVIDIR "$(dvidir)"'; \ 237
151 echo '#define PDFDIR "$(pdfdir)"'; \ 238EXTRA_libgnu_a_SOURCES += calloc.c
152 echo '#define PSDIR "$(psdir)"'; \ 239
153 echo '#define LIBDIR "$(libdir)"'; \ 240## end gnulib module calloc-gnu
154 echo '#define LISPDIR "$(lispdir)"'; \ 241
155 echo '#define LOCALEDIR "$(localedir)"'; \ 242## begin gnulib module calloc-posix
156 echo '#define MANDIR "$(mandir)"'; \ 243
157 echo '#define MANEXT "$(manext)"'; \ 244
158 echo '#define PKGDATADIR "$(pkgdatadir)"'; \ 245EXTRA_DIST += calloc.c
159 echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ 246
160 echo '#define PKGLIBDIR "$(pkglibdir)"'; \ 247EXTRA_libgnu_a_SOURCES += calloc.c
161 echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ 248
162 } | sed '/""/d' > $@-t && \ 249## end gnulib module calloc-posix
163 mv -f $@-t $@ 250
164 251## begin gnulib module cloexec
165BUILT_SOURCES += configmake.h 252
166CLEANFILES += configmake.h configmake.h-t 253libgnu_a_SOURCES += cloexec.c
167 254
168## end gnulib module configmake 255EXTRA_DIST += cloexec.h
169 256
170## begin gnulib module crypto/sha1 257## end gnulib module cloexec
171 258
172libgnu_a_SOURCES += sha1.c 259## begin gnulib module close
173 260
174EXTRA_DIST += sha1.h 261if GL_COND_OBJ_CLOSE
175 262libgnu_a_SOURCES += close.c
176## end gnulib module crypto/sha1 263endif
264
265## end gnulib module close
266
267## begin gnulib module crypto/af_alg
268
269libgnu_a_SOURCES += af_alg.c
270
271EXTRA_DIST += af_alg.h sys-limits.h
272
273## end gnulib module crypto/af_alg
274
275## begin gnulib module crypto/sha256
276
277libgnu_a_SOURCES += sha256-stream.c
278
279## end gnulib module crypto/sha256
280
281## begin gnulib module crypto/sha256-buffer
282
283libgnu_a_SOURCES += sha256.c
284
285EXTRA_DIST += gl_openssl.h sha256.h
286
287## end gnulib module crypto/sha256-buffer
177 288
178## begin gnulib module dirname 289## begin gnulib module dirname
179 290
@@ -187,18 +298,19 @@ EXTRA_libgnu_a_SOURCES += stripslash.c
187 298
188## begin gnulib module dirname-lgpl 299## begin gnulib module dirname-lgpl
189 300
190libgnu_a_SOURCES += dirname-lgpl.c basename-lgpl.c stripslash.c 301libgnu_a_SOURCES += dirname-lgpl.c stripslash.c
191 302
192EXTRA_DIST += dirname.h 303EXTRA_DIST += dirname.h
193 304
194## end gnulib module dirname-lgpl 305## end gnulib module dirname-lgpl
195 306
196## begin gnulib module dosname 307## begin gnulib module dup2
197
198 308
199EXTRA_DIST += dosname.h 309if GL_COND_OBJ_DUP2
310libgnu_a_SOURCES += dup2.c
311endif
200 312
201## end gnulib module dosname 313## end gnulib module dup2
202 314
203## begin gnulib module errno 315## begin gnulib module errno
204 316
@@ -208,9 +320,8 @@ BUILT_SOURCES += $(ERRNO_H)
208# doesn't have one that is POSIX compliant. 320# doesn't have one that is POSIX compliant.
209if GL_GENERATE_ERRNO_H 321if GL_GENERATE_ERRNO_H
210errno.h: errno.in.h $(top_builddir)/config.status 322errno.h: errno.in.h $(top_builddir)/config.status
211 $(AM_V_GEN)rm -f $@-t $@ && \ 323 $(gl_V_at)$(SED_HEADER_STDOUT) \
212 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 324 -e 's|@''GUARD_PREFIX''@|GL|g' \
213 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
214 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 325 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
215 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 326 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
216 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 327 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
@@ -221,9 +332,8 @@ errno.h: errno.in.h $(top_builddir)/config.status
221 -e 's|@''ENOLINK_VALUE''@|$(ENOLINK_VALUE)|g' \ 332 -e 's|@''ENOLINK_VALUE''@|$(ENOLINK_VALUE)|g' \
222 -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \ 333 -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \
223 -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \ 334 -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \
224 < $(srcdir)/errno.in.h; \ 335 $(srcdir)/errno.in.h > $@-t
225 } > $@-t && \ 336 $(AM_V_at)mv $@-t $@
226 mv $@-t $@
227else 337else
228errno.h: $(top_builddir)/config.status 338errno.h: $(top_builddir)/config.status
229 rm -f $@ 339 rm -f $@
@@ -236,10 +346,11 @@ EXTRA_DIST += errno.in.h
236 346
237## begin gnulib module error 347## begin gnulib module error
238 348
349if GL_COND_OBJ_ERROR
350libgnu_a_SOURCES += error.c
351endif
239 352
240EXTRA_DIST += error.c error.h 353EXTRA_DIST += error.h
241
242EXTRA_libgnu_a_SOURCES += error.c
243 354
244## end gnulib module error 355## end gnulib module error
245 356
@@ -251,6 +362,51 @@ EXTRA_DIST += exitfail.h
251 362
252## end gnulib module exitfail 363## end gnulib module exitfail
253 364
365## begin gnulib module fcntl
366
367if GL_COND_OBJ_FCNTL
368libgnu_a_SOURCES += fcntl.c
369endif
370
371## end gnulib module fcntl
372
373## begin gnulib module fcntl-h
374
375BUILT_SOURCES += fcntl.h
376
377# We need the following in order to create <fcntl.h> when the system
378# doesn't have one that works with the given compiler.
379fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
380 $(gl_V_at)$(SED_HEADER_STDOUT) \
381 -e 's|@''GUARD_PREFIX''@|GL|g' \
382 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
383 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
384 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
385 -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
386 -e 's/@''GNULIB_CREAT''@/$(GL_GNULIB_CREAT)/g' \
387 -e 's/@''GNULIB_FCNTL''@/$(GL_GNULIB_FCNTL)/g' \
388 -e 's/@''GNULIB_NONBLOCKING''@/$(GL_GNULIB_NONBLOCKING)/g' \
389 -e 's/@''GNULIB_OPEN''@/$(GL_GNULIB_OPEN)/g' \
390 -e 's/@''GNULIB_OPENAT''@/$(GL_GNULIB_OPENAT)/g' \
391 -e 's/@''GNULIB_MDA_CREAT''@/$(GL_GNULIB_MDA_CREAT)/g' \
392 -e 's/@''GNULIB_MDA_OPEN''@/$(GL_GNULIB_MDA_OPEN)/g' \
393 -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
394 -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
395 -e 's|@''REPLACE_CREAT''@|$(REPLACE_CREAT)|g' \
396 -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
397 -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
398 -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
399 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
400 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
401 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
402 $(srcdir)/fcntl.in.h > $@-t
403 $(AM_V_at)mv $@-t $@
404MOSTLYCLEANFILES += fcntl.h fcntl.h-t
405
406EXTRA_DIST += fcntl.in.h
407
408## end gnulib module fcntl-h
409
254## begin gnulib module fd-hook 410## begin gnulib module fd-hook
255 411
256libgnu_a_SOURCES += fd-hook.c 412libgnu_a_SOURCES += fd-hook.c
@@ -259,6 +415,23 @@ EXTRA_DIST += fd-hook.h
259 415
260## end gnulib module fd-hook 416## end gnulib module fd-hook
261 417
418## begin gnulib module fflush
419
420if GL_COND_OBJ_FFLUSH
421libgnu_a_SOURCES += fflush.c
422endif
423
424EXTRA_DIST += stdio-impl.h
425
426## end gnulib module fflush
427
428## begin gnulib module filename
429
430
431EXTRA_DIST += filename.h
432
433## end gnulib module filename
434
262## begin gnulib module float 435## begin gnulib module float
263 436
264BUILT_SOURCES += $(FLOAT_H) 437BUILT_SOURCES += $(FLOAT_H)
@@ -267,127 +440,267 @@ BUILT_SOURCES += $(FLOAT_H)
267# doesn't have one that works with the given compiler. 440# doesn't have one that works with the given compiler.
268if GL_GENERATE_FLOAT_H 441if GL_GENERATE_FLOAT_H
269float.h: float.in.h $(top_builddir)/config.status 442float.h: float.in.h $(top_builddir)/config.status
270 $(AM_V_GEN)rm -f $@-t $@ && \ 443 $(gl_V_at)$(SED_HEADER_STDOUT) \
271 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 444 -e 's|@''GUARD_PREFIX''@|GL|g' \
272 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
273 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 445 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
274 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 446 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
275 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 447 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
276 -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \ 448 -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \
277 -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \ 449 -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
278 < $(srcdir)/float.in.h; \ 450 $(srcdir)/float.in.h > $@-t
279 } > $@-t && \ 451 $(AM_V_at)mv $@-t $@
280 mv $@-t $@
281else 452else
282float.h: $(top_builddir)/config.status 453float.h: $(top_builddir)/config.status
283 rm -f $@ 454 rm -f $@
284endif 455endif
285MOSTLYCLEANFILES += float.h float.h-t 456MOSTLYCLEANFILES += float.h float.h-t
286 457
287EXTRA_DIST += float.c float.in.h itold.c 458if GL_COND_OBJ_FLOAT
459libgnu_a_SOURCES += float.c
460endif
461if GL_COND_OBJ_ITOLD
462libgnu_a_SOURCES += itold.c
463endif
288 464
289EXTRA_libgnu_a_SOURCES += float.c itold.c 465EXTRA_DIST += float.in.h
290 466
291## end gnulib module float 467## end gnulib module float
292 468
293## begin gnulib module floorf 469## begin gnulib module floorf
294 470
471if GL_COND_OBJ_FLOORF
472libgnu_a_SOURCES += floorf.c
473endif
295 474
296EXTRA_DIST += floor.c floorf.c 475EXTRA_DIST += floor.c
297 476
298EXTRA_libgnu_a_SOURCES += floor.c floorf.c 477EXTRA_libgnu_a_SOURCES += floor.c
299 478
300## end gnulib module floorf 479## end gnulib module floorf
301 480
302## begin gnulib module fsusage 481## begin gnulib module fopen
482
303 483
484EXTRA_DIST += fopen.c
304 485
305EXTRA_DIST += fsusage.c fsusage.h 486EXTRA_libgnu_a_SOURCES += fopen.c
306 487
307EXTRA_libgnu_a_SOURCES += fsusage.c 488## end gnulib module fopen
489
490## begin gnulib module fopen-gnu
491
492
493EXTRA_DIST += fopen.c
494
495EXTRA_libgnu_a_SOURCES += fopen.c
496
497## end gnulib module fopen-gnu
498
499## begin gnulib module fpurge
500
501if GL_COND_OBJ_FPURGE
502libgnu_a_SOURCES += fpurge.c
503endif
504
505EXTRA_DIST += stdio-impl.h
506
507## end gnulib module fpurge
508
509## begin gnulib module freading
510
511libgnu_a_SOURCES += freading.c
512
513EXTRA_DIST += freading.h stdio-impl.h
514
515## end gnulib module freading
516
517## begin gnulib module free-posix
518
519if GL_COND_OBJ_FREE
520libgnu_a_SOURCES += free.c
521endif
522
523## end gnulib module free-posix
524
525## begin gnulib module fseek
526
527if GL_COND_OBJ_FSEEK
528libgnu_a_SOURCES += fseek.c
529endif
530
531## end gnulib module fseek
532
533## begin gnulib module fseeko
534
535if GL_COND_OBJ_FSEEKO
536libgnu_a_SOURCES += fseeko.c
537endif
538
539EXTRA_DIST += stdio-impl.h
540
541## end gnulib module fseeko
542
543## begin gnulib module fstat
544
545if GL_COND_OBJ_FSTAT
546libgnu_a_SOURCES += fstat.c
547endif
548
549EXTRA_DIST += stat-w32.c stat-w32.h
550
551EXTRA_libgnu_a_SOURCES += stat-w32.c
552
553## end gnulib module fstat
554
555## begin gnulib module fsusage
556
557if GL_COND_OBJ_FSUSAGE
558libgnu_a_SOURCES += fsusage.c
559endif
560
561EXTRA_DIST += fsusage.h
308 562
309## end gnulib module fsusage 563## end gnulib module fsusage
310 564
311## begin gnulib module full-read 565## begin gnulib module ftell
566
567if GL_COND_OBJ_FTELL
568libgnu_a_SOURCES += ftell.c
569endif
570
571## end gnulib module ftell
312 572
313libgnu_a_SOURCES += full-read.h full-read.c 573## begin gnulib module ftello
314 574
315EXTRA_DIST += full-write.c 575if GL_COND_OBJ_FTELLO
576libgnu_a_SOURCES += ftello.c
577endif
316 578
317EXTRA_libgnu_a_SOURCES += full-write.c 579EXTRA_DIST += stdio-impl.h
318 580
319## end gnulib module full-read 581## end gnulib module ftello
320 582
321## begin gnulib module getaddrinfo 583## begin gnulib module gen-header
322 584
585# In 'sed', replace the pattern space with a "DO NOT EDIT" comment.
586SED_HEADER_NOEDIT = s,.*,/* DO NOT EDIT! GENERATED AUTOMATICALLY! */,
323 587
324EXTRA_DIST += gai_strerror.c getaddrinfo.c 588# '$(SED_HEADER_STDOUT) -e "..."' runs 'sed' but first outputs "DO NOT EDIT".
589SED_HEADER_STDOUT = sed -e 1h -e '1$(SED_HEADER_NOEDIT)' -e 1G
325 590
326EXTRA_libgnu_a_SOURCES += gai_strerror.c getaddrinfo.c 591# '$(SED_HEADER_TO_AT_t) FILE' copies FILE to $@-t, prepending a leading
592# "DO_NOT_EDIT". Although this could be done more simply via:
593# SED_HEADER_TO_AT_t = $(SED_HEADER_STDOUT) > $@-t
594# the -n and 'w' avoid a fork+exec, at least when GNU Make is used.
595SED_HEADER_TO_AT_t = $(SED_HEADER_STDOUT) -n -e 'w $@-t'
596
597# Use $(gl_V_at) instead of $(AM_V_GEN) or $(AM_V_at) on a line that
598gl_V_at = $(AM_V_GEN)
599
600## end gnulib module gen-header
601
602## begin gnulib module getaddrinfo
603
604if GL_COND_OBJ_GETADDRINFO
605libgnu_a_SOURCES += getaddrinfo.c
606endif
607if GL_COND_OBJ_GAI_STRERROR
608libgnu_a_SOURCES += gai_strerror.c
609endif
327 610
328## end gnulib module getaddrinfo 611## end gnulib module getaddrinfo
329 612
330## begin gnulib module gethostname 613## begin gnulib module getdelim
614
615if GL_COND_OBJ_GETDELIM
616libgnu_a_SOURCES += getdelim.c
617endif
618
619## end gnulib module getdelim
620
621## begin gnulib module getdtablesize
331 622
623if GL_COND_OBJ_GETDTABLESIZE
624libgnu_a_SOURCES += getdtablesize.c
625endif
626
627## end gnulib module getdtablesize
628
629## begin gnulib module gethostname
332 630
333EXTRA_DIST += gethostname.c w32sock.h 631if GL_COND_OBJ_GETHOSTNAME
632libgnu_a_SOURCES += gethostname.c
633endif
334 634
335EXTRA_libgnu_a_SOURCES += gethostname.c 635EXTRA_DIST += w32sock.h
336 636
337## end gnulib module gethostname 637## end gnulib module gethostname
338 638
339## begin gnulib module getloadavg 639## begin gnulib module getline
640
641if GL_COND_OBJ_GETLINE
642libgnu_a_SOURCES += getline.c
643endif
340 644
645## end gnulib module getline
341 646
342EXTRA_DIST += getloadavg.c 647## begin gnulib module getloadavg
343 648
344EXTRA_libgnu_a_SOURCES += getloadavg.c 649if GL_COND_OBJ_GETLOADAVG
650libgnu_a_SOURCES += getloadavg.c
651endif
345 652
346## end gnulib module getloadavg 653## end gnulib module getloadavg
347 654
348## begin gnulib module getopt-posix 655## begin gnulib module getopt-posix
349 656
350BUILT_SOURCES += $(GETOPT_H) 657BUILT_SOURCES += $(GETOPT_H) $(GETOPT_CDEFS_H)
351 658
352# We need the following in order to create <getopt.h> when the system 659# We need the following in order to create <getopt.h> when the system
353# doesn't have one that works with the given compiler. 660# doesn't have one that works with the given compiler.
661if GL_GENERATE_GETOPT_H
354getopt.h: getopt.in.h $(top_builddir)/config.status $(ARG_NONNULL_H) 662getopt.h: getopt.in.h $(top_builddir)/config.status $(ARG_NONNULL_H)
355 $(AM_V_GEN)rm -f $@-t $@ && \ 663 $(gl_V_at)$(SED_HEADER_STDOUT) \
356 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 664 -e 's|@''GUARD_PREFIX''@|GL|g' \
357 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
358 -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \ 665 -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \
359 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 666 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
360 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 667 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
361 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 668 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
362 -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \ 669 -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \
363 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 670 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
364 < $(srcdir)/getopt.in.h; \ 671 $(srcdir)/getopt.in.h > $@-t
365 } > $@-t && \ 672 $(AM_V_at)mv $@-t $@
366 mv -f $@-t $@ 673else
367MOSTLYCLEANFILES += getopt.h getopt.h-t 674getopt.h: $(top_builddir)/config.status
675 rm -f $@
676endif
368 677
369EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h 678if GL_GENERATE_GETOPT_CDEFS_H
679getopt-cdefs.h: getopt-cdefs.in.h $(top_builddir)/config.status
680 $(AM_V_GEN)$(SED_HEADER_STDOUT) \
681 -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \
682 $(srcdir)/getopt-cdefs.in.h > $@-t
683 $(AM_V_at)mv $@-t $@
684else
685getopt-cdefs.h: $(top_builddir)/config.status
686 rm -f $@
687endif
370 688
371EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c 689MOSTLYCLEANFILES += getopt.h getopt.h-t getopt-cdefs.h getopt-cdefs.h-t
372 690
373## end gnulib module getopt-posix 691if GL_COND_OBJ_GETOPT
692libgnu_a_SOURCES += getopt.c getopt1.c
693endif
694
695EXTRA_DIST += getopt-cdefs.in.h getopt-core.h getopt-ext.h getopt-pfx-core.h getopt-pfx-ext.h getopt.in.h getopt_int.h
374 696
375## begin gnulib module gettext 697## end gnulib module getopt-posix
376 698
377# If your project uses "gettextize --intl" to put a source-code 699## begin gnulib module getprogname
378# copy of libintl into the package, every Makefile.am needs
379# -I$(top_builddir)/intl, so that <libintl.h> can be found in this directory.
380# Here's one way to do this:
381#AM_CPPFLAGS += -I$(top_builddir)/intl
382# This option has no effect when the user disables NLS (because then
383# the intl directory contains no libintl.h file). This option is not
384# enabled by default because the intl directory might not exist if
385# your project does not use "gettext --intl", and some compilers
386# complain about -I options applied to nonexistent directories.
387 700
388EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath 701libgnu_a_SOURCES += getprogname.h getprogname.c
389 702
390## end gnulib module gettext 703## end gnulib module getprogname
391 704
392## begin gnulib module gettext-h 705## begin gnulib module gettext-h
393 706
@@ -395,12 +708,54 @@ libgnu_a_SOURCES += gettext.h
395 708
396## end gnulib module gettext-h 709## end gnulib module gettext-h
397 710
398## begin gnulib module havelib 711## begin gnulib module glibc-internal/dynarray
712
713BUILT_SOURCES += malloc/dynarray.gl.h malloc/dynarray-skeleton.gl.h
714
715malloc/dynarray.gl.h: malloc/dynarray.h
716 $(AM_V_GEN)$(MKDIR_P) '%reldir%/malloc'
717 $(AM_V_at)$(SED_HEADER_STDOUT) \
718 -e '/libc_hidden_proto/d' \
719 $(srcdir)/malloc/dynarray.h > $@-t
720 $(AM_V_at)mv $@-t $@
721MOSTLYCLEANFILES += malloc/dynarray.gl.h malloc/dynarray.gl.h-t
722
723malloc/dynarray-skeleton.gl.h: malloc/dynarray-skeleton.c
724 $(AM_V_GEN)$(MKDIR_P) '%reldir%/malloc'
725 $(AM_V_at)$(SED_HEADER_STDOUT) \
726 -e 's|<malloc/dynarray\.h>|<malloc/dynarray.gl.h>|g' \
727 -e 's|__attribute_maybe_unused__|_GL_ATTRIBUTE_MAYBE_UNUSED|g' \
728 -e 's|__attribute_nonnull__|_GL_ATTRIBUTE_NONNULL|g' \
729 -e 's|__attribute_warn_unused_result__|_GL_ATTRIBUTE_NODISCARD|g' \
730 -e 's|__glibc_likely|_GL_LIKELY|g' \
731 -e 's|__glibc_unlikely|_GL_UNLIKELY|g' \
732 $(srcdir)/malloc/dynarray-skeleton.c > $@-t
733 $(AM_V_at)mv $@-t $@
734MOSTLYCLEANFILES += malloc/dynarray-skeleton.gl.h malloc/dynarray-skeleton.gl.h-t
735
736libgnu_a_SOURCES += malloc/dynarray_at_failure.c malloc/dynarray_emplace_enlarge.c malloc/dynarray_finalize.c malloc/dynarray_resize.c malloc/dynarray_resize_clear.c
737
738EXTRA_DIST += dynarray.h malloc/dynarray-skeleton.c malloc/dynarray.h
739
740EXTRA_libgnu_a_SOURCES += malloc/dynarray-skeleton.c
741
742## end gnulib module glibc-internal/dynarray
743
744## begin gnulib module hard-locale
745
746libgnu_a_SOURCES += hard-locale.c
399 747
748EXTRA_DIST += hard-locale.h
400 749
401EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath 750## end gnulib module hard-locale
402 751
403## end gnulib module havelib 752## begin gnulib module ialloc
753
754libgnu_a_SOURCES += ialloc.c
755
756EXTRA_DIST += ialloc.h
757
758## end gnulib module ialloc
404 759
405## begin gnulib module idpriv-droptemp 760## begin gnulib module idpriv-droptemp
406 761
@@ -410,22 +765,68 @@ EXTRA_DIST += idpriv.h
410 765
411## end gnulib module idpriv-droptemp 766## end gnulib module idpriv-droptemp
412 767
413## begin gnulib module inet_ntop 768## begin gnulib module idx
769
770libgnu_a_SOURCES += idx.h
414 771
772## end gnulib module idx
415 773
416EXTRA_DIST += inet_ntop.c 774## begin gnulib module inet_ntop
417 775
418EXTRA_libgnu_a_SOURCES += inet_ntop.c 776if GL_COND_OBJ_INET_NTOP
777libgnu_a_SOURCES += inet_ntop.c
778endif
419 779
420## end gnulib module inet_ntop 780## end gnulib module inet_ntop
421 781
422## begin gnulib module intprops 782## begin gnulib module intprops
423 783
424 784
425EXTRA_DIST += intprops.h 785EXTRA_DIST += intprops-internal.h intprops.h
426 786
427## end gnulib module intprops 787## end gnulib module intprops
428 788
789## begin gnulib module inttypes-incomplete
790
791BUILT_SOURCES += inttypes.h
792
793# We need the following in order to create <inttypes.h> when the system
794# doesn't have one that works with the given compiler.
795inttypes.h: inttypes.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
796 $(gl_V_at)$(SED_HEADER_STDOUT) \
797 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
798 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
799 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
800 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
801 -e 's|@''NEXT_INTTYPES_H''@|$(NEXT_INTTYPES_H)|g' \
802 -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
803 -e 's/@''PRIPTR_PREFIX''@/$(PRIPTR_PREFIX)/g' \
804 -e 's/@''GNULIB_IMAXABS''@/$(GL_GNULIB_IMAXABS)/g' \
805 -e 's/@''GNULIB_IMAXDIV''@/$(GL_GNULIB_IMAXDIV)/g' \
806 -e 's/@''GNULIB_STRTOIMAX''@/$(GL_GNULIB_STRTOIMAX)/g' \
807 -e 's/@''GNULIB_STRTOUMAX''@/$(GL_GNULIB_STRTOUMAX)/g' \
808 -e 's/@''HAVE_DECL_IMAXABS''@/$(HAVE_DECL_IMAXABS)/g' \
809 -e 's/@''HAVE_DECL_IMAXDIV''@/$(HAVE_DECL_IMAXDIV)/g' \
810 -e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \
811 -e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \
812 -e 's/@''HAVE_IMAXDIV_T''@/$(HAVE_IMAXDIV_T)/g' \
813 -e 's/@''REPLACE_STRTOIMAX''@/$(REPLACE_STRTOIMAX)/g' \
814 -e 's/@''REPLACE_STRTOUMAX''@/$(REPLACE_STRTOUMAX)/g' \
815 -e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' \
816 -e 's/@''INT64_MAX_EQ_LONG_MAX''@/$(INT64_MAX_EQ_LONG_MAX)/g' \
817 -e 's/@''UINT32_MAX_LT_UINTMAX_MAX''@/$(UINT32_MAX_LT_UINTMAX_MAX)/g' \
818 -e 's/@''UINT64_MAX_EQ_ULONG_MAX''@/$(UINT64_MAX_EQ_ULONG_MAX)/g' \
819 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
820 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
821 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
822 $(srcdir)/inttypes.in.h > $@-t
823 $(AM_V_at)mv $@-t $@
824MOSTLYCLEANFILES += inttypes.h inttypes.h-t
825
826EXTRA_DIST += inttypes.in.h
827
828## end gnulib module inttypes-incomplete
829
429## begin gnulib module langinfo 830## begin gnulib module langinfo
430 831
431BUILT_SOURCES += langinfo.h 832BUILT_SOURCES += langinfo.h
@@ -433,103 +834,69 @@ BUILT_SOURCES += langinfo.h
433# We need the following in order to create an empty placeholder for 834# We need the following in order to create an empty placeholder for
434# <langinfo.h> when the system doesn't have one. 835# <langinfo.h> when the system doesn't have one.
435langinfo.h: langinfo.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) 836langinfo.h: langinfo.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
436 $(AM_V_GEN)rm -f $@-t $@ && \ 837 $(gl_V_at)$(SED_HEADER_STDOUT) \
437 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 838 -e 's|@''GUARD_PREFIX''@|GL|g' \
438 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
439 -e 's|@''HAVE_LANGINFO_H''@|$(HAVE_LANGINFO_H)|g' \ 839 -e 's|@''HAVE_LANGINFO_H''@|$(HAVE_LANGINFO_H)|g' \
440 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 840 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
441 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 841 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
442 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 842 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
443 -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \ 843 -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \
444 -e 's/@''GNULIB_NL_LANGINFO''@/$(GNULIB_NL_LANGINFO)/g' \ 844 -e 's/@''GNULIB_NL_LANGINFO''@/$(GL_GNULIB_NL_LANGINFO)/g' \
445 -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \ 845 -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \
446 -e 's|@''HAVE_LANGINFO_T_FMT_AMPM''@|$(HAVE_LANGINFO_T_FMT_AMPM)|g' \ 846 -e 's|@''HAVE_LANGINFO_T_FMT_AMPM''@|$(HAVE_LANGINFO_T_FMT_AMPM)|g' \
847 -e 's|@''HAVE_LANGINFO_ALTMON''@|$(HAVE_LANGINFO_ALTMON)|g' \
447 -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \ 848 -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \
448 -e 's|@''HAVE_LANGINFO_YESEXPR''@|$(HAVE_LANGINFO_YESEXPR)|g' \ 849 -e 's|@''HAVE_LANGINFO_YESEXPR''@|$(HAVE_LANGINFO_YESEXPR)|g' \
449 -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \ 850 -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \
450 -e 's|@''REPLACE_NL_LANGINFO''@|$(REPLACE_NL_LANGINFO)|g' \ 851 -e 's|@''REPLACE_NL_LANGINFO''@|$(REPLACE_NL_LANGINFO)|g' \
451 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 852 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
452 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 853 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
453 < $(srcdir)/langinfo.in.h; \ 854 $(srcdir)/langinfo.in.h > $@-t
454 } > $@-t && \ 855 $(AM_V_at)mv $@-t $@
455 mv $@-t $@
456MOSTLYCLEANFILES += langinfo.h langinfo.h-t 856MOSTLYCLEANFILES += langinfo.h langinfo.h-t
457 857
458EXTRA_DIST += langinfo.in.h 858EXTRA_DIST += langinfo.in.h
459 859
460## end gnulib module langinfo 860## end gnulib module langinfo
461 861
462## begin gnulib module localcharset 862## begin gnulib module libc-config
463 863
464libgnu_a_SOURCES += localcharset.h localcharset.c
465
466# We need the following in order to install a simple file in $(libdir)
467# which is shared with other installed packages. We use a list of referencing
468# packages so that "make uninstall" will remove the file if and only if it
469# is not used by another installed package.
470# On systems with glibc-2.1 or newer, the file is redundant, therefore we
471# avoid installing it.
472
473all-local: charset.alias ref-add.sed ref-del.sed
474
475charset_alias = $(DESTDIR)$(libdir)/charset.alias
476charset_tmp = $(DESTDIR)$(libdir)/charset.tmp
477install-exec-local: install-exec-localcharset
478install-exec-localcharset: all-local
479 if test $(GLIBC21) = no; then \
480 case '$(host_os)' in \
481 darwin[56]*) \
482 need_charset_alias=true ;; \
483 darwin* | cygwin* | mingw* | pw32* | cegcc*) \
484 need_charset_alias=false ;; \
485 *) \
486 need_charset_alias=true ;; \
487 esac ; \
488 else \
489 need_charset_alias=false ; \
490 fi ; \
491 if $$need_charset_alias; then \
492 $(mkinstalldirs) $(DESTDIR)$(libdir) ; \
493 fi ; \
494 if test -f $(charset_alias); then \
495 sed -f ref-add.sed $(charset_alias) > $(charset_tmp) ; \
496 $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
497 rm -f $(charset_tmp) ; \
498 else \
499 if $$need_charset_alias; then \
500 sed -f ref-add.sed charset.alias > $(charset_tmp) ; \
501 $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
502 rm -f $(charset_tmp) ; \
503 fi ; \
504 fi
505
506uninstall-local: uninstall-localcharset
507uninstall-localcharset: all-local
508 if test -f $(charset_alias); then \
509 sed -f ref-del.sed $(charset_alias) > $(charset_tmp); \
510 if grep '^# Packages using this file: $$' $(charset_tmp) \
511 > /dev/null; then \
512 rm -f $(charset_alias); \
513 else \
514 $(INSTALL_DATA) $(charset_tmp) $(charset_alias); \
515 fi; \
516 rm -f $(charset_tmp); \
517 fi
518 864
519charset.alias: config.charset 865EXTRA_DIST += cdefs.h libc-config.h
520 $(AM_V_GEN)rm -f t-$@ $@ && \
521 $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ && \
522 mv t-$@ $@
523 866
524SUFFIXES += .sed .sin 867## end gnulib module libc-config
525.sin.sed:
526 $(AM_V_GEN)rm -f t-$@ $@ && \
527 sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ && \
528 mv t-$@ $@
529 868
530CLEANFILES += charset.alias ref-add.sed ref-del.sed 869## begin gnulib module limits-h
531 870
532EXTRA_DIST += config.charset ref-add.sin ref-del.sin 871BUILT_SOURCES += $(LIMITS_H)
872
873# We need the following in order to create <limits.h> when the system
874# doesn't have one that is compatible with GNU.
875if GL_GENERATE_LIMITS_H
876limits.h: limits.in.h $(top_builddir)/config.status
877 $(gl_V_at)$(SED_HEADER_STDOUT) \
878 -e 's|@''GUARD_PREFIX''@|GL|g' \
879 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
880 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
881 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
882 -e 's|@''NEXT_LIMITS_H''@|$(NEXT_LIMITS_H)|g' \
883 $(srcdir)/limits.in.h > $@-t
884 $(AM_V_at)mv $@-t $@
885else
886limits.h: $(top_builddir)/config.status
887 rm -f $@
888endif
889MOSTLYCLEANFILES += limits.h limits.h-t
890
891EXTRA_DIST += limits.in.h
892
893## end gnulib module limits-h
894
895## begin gnulib module localcharset
896
897libgnu_a_SOURCES += localcharset.c
898
899EXTRA_DIST += localcharset.h
533 900
534## end gnulib module localcharset 901## end gnulib module localcharset
535 902
@@ -540,28 +907,33 @@ BUILT_SOURCES += locale.h
540# We need the following in order to create <locale.h> when the system 907# We need the following in order to create <locale.h> when the system
541# doesn't have one that provides all definitions. 908# doesn't have one that provides all definitions.
542locale.h: locale.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 909locale.h: locale.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
543 $(AM_V_GEN)rm -f $@-t $@ && \ 910 $(gl_V_at)$(SED_HEADER_STDOUT) \
544 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 911 -e 's|@''GUARD_PREFIX''@|GL|g' \
545 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
546 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 912 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
547 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 913 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
548 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 914 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
549 -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \ 915 -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \
550 -e 's/@''GNULIB_LOCALECONV''@/$(GNULIB_LOCALECONV)/g' \ 916 -e 's/@''GNULIB_LOCALECONV''@/$(GL_GNULIB_LOCALECONV)/g' \
551 -e 's/@''GNULIB_SETLOCALE''@/$(GNULIB_SETLOCALE)/g' \ 917 -e 's/@''GNULIB_SETLOCALE''@/$(GL_GNULIB_SETLOCALE)/g' \
552 -e 's/@''GNULIB_DUPLOCALE''@/$(GNULIB_DUPLOCALE)/g' \ 918 -e 's/@''GNULIB_SETLOCALE_NULL''@/$(GL_GNULIB_SETLOCALE_NULL)/g' \
919 -e 's/@''GNULIB_DUPLOCALE''@/$(GL_GNULIB_DUPLOCALE)/g' \
920 -e 's/@''GNULIB_LOCALENAME''@/$(GL_GNULIB_LOCALENAME)/g' \
921 -e 's|@''HAVE_NEWLOCALE''@|$(HAVE_NEWLOCALE)|g' \
553 -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \ 922 -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \
923 -e 's|@''HAVE_FREELOCALE''@|$(HAVE_FREELOCALE)|g' \
554 -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \ 924 -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
555 -e 's|@''REPLACE_LOCALECONV''@|$(REPLACE_LOCALECONV)|g' \ 925 -e 's|@''REPLACE_LOCALECONV''@|$(REPLACE_LOCALECONV)|g' \
556 -e 's|@''REPLACE_SETLOCALE''@|$(REPLACE_SETLOCALE)|g' \ 926 -e 's|@''REPLACE_SETLOCALE''@|$(REPLACE_SETLOCALE)|g' \
927 -e 's|@''REPLACE_NEWLOCALE''@|$(REPLACE_NEWLOCALE)|g' \
557 -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \ 928 -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \
929 -e 's|@''REPLACE_FREELOCALE''@|$(REPLACE_FREELOCALE)|g' \
558 -e 's|@''REPLACE_STRUCT_LCONV''@|$(REPLACE_STRUCT_LCONV)|g' \ 930 -e 's|@''REPLACE_STRUCT_LCONV''@|$(REPLACE_STRUCT_LCONV)|g' \
931 -e 's|@''LOCALENAME_ENHANCE_LOCALE_FUNCS''@|$(LOCALENAME_ENHANCE_LOCALE_FUNCS)|g' \
559 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 932 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
560 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 933 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
561 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 934 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
562 < $(srcdir)/locale.in.h; \ 935 $(srcdir)/locale.in.h > $@-t
563 } > $@-t && \ 936 $(AM_V_at)mv $@-t $@
564 mv $@-t $@
565MOSTLYCLEANFILES += locale.h locale.h-t 937MOSTLYCLEANFILES += locale.h locale.h-t
566 938
567EXTRA_DIST += locale.in.h 939EXTRA_DIST += locale.in.h
@@ -570,10 +942,9 @@ EXTRA_DIST += locale.in.h
570 942
571## begin gnulib module localeconv 943## begin gnulib module localeconv
572 944
573 945if GL_COND_OBJ_LOCALECONV
574EXTRA_DIST += localeconv.c 946libgnu_a_SOURCES += localeconv.c
575 947endif
576EXTRA_libgnu_a_SOURCES += localeconv.c
577 948
578## end gnulib module localeconv 949## end gnulib module localeconv
579 950
@@ -583,6 +954,14 @@ libgnu_a_SOURCES += glthread/lock.h glthread/lock.c
583 954
584## end gnulib module lock 955## end gnulib module lock
585 956
957## begin gnulib module lseek
958
959if GL_COND_OBJ_LSEEK
960libgnu_a_SOURCES += lseek.c
961endif
962
963## end gnulib module lseek
964
586## begin gnulib module malloc-gnu 965## begin gnulib module malloc-gnu
587 966
588 967
@@ -605,7 +984,7 @@ EXTRA_libgnu_a_SOURCES += malloc.c
605 984
606libgnu_a_SOURCES += malloca.c 985libgnu_a_SOURCES += malloca.c
607 986
608EXTRA_DIST += malloca.h malloca.valgrind 987EXTRA_DIST += malloca.h
609 988
610## end gnulib module malloca 989## end gnulib module malloca
611 990
@@ -617,109 +996,114 @@ libgnu_a_SOURCES += math.c
617# We need the following in order to create <math.h> when the system 996# We need the following in order to create <math.h> when the system
618# doesn't have one that works with the given compiler. 997# doesn't have one that works with the given compiler.
619math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 998math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
620 $(AM_V_GEN)rm -f $@-t $@ && \ 999 $(gl_V_at)$(SED_HEADER_STDOUT) \
621 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1000 -e 's|@''GUARD_PREFIX''@|GL|g' \
622 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
623 -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \ 1001 -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \
624 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1002 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
625 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1003 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
626 -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \ 1004 -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \
627 -e 's/@''GNULIB_ACOSF''@/$(GNULIB_ACOSF)/g' \ 1005 -e 's/@''GNULIB_ACOSF''@/$(GL_GNULIB_ACOSF)/g' \
628 -e 's/@''GNULIB_ACOSL''@/$(GNULIB_ACOSL)/g' \ 1006 -e 's/@''GNULIB_ACOSL''@/$(GL_GNULIB_ACOSL)/g' \
629 -e 's/@''GNULIB_ASINF''@/$(GNULIB_ASINF)/g' \ 1007 -e 's/@''GNULIB_ASINF''@/$(GL_GNULIB_ASINF)/g' \
630 -e 's/@''GNULIB_ASINL''@/$(GNULIB_ASINL)/g' \ 1008 -e 's/@''GNULIB_ASINL''@/$(GL_GNULIB_ASINL)/g' \
631 -e 's/@''GNULIB_ATANF''@/$(GNULIB_ATANF)/g' \ 1009 -e 's/@''GNULIB_ATANF''@/$(GL_GNULIB_ATANF)/g' \
632 -e 's/@''GNULIB_ATANL''@/$(GNULIB_ATANL)/g' \ 1010 -e 's/@''GNULIB_ATANL''@/$(GL_GNULIB_ATANL)/g' \
633 -e 's/@''GNULIB_ATAN2F''@/$(GNULIB_ATAN2F)/g' \ 1011 -e 's/@''GNULIB_ATAN2F''@/$(GL_GNULIB_ATAN2F)/g' \
634 -e 's/@''GNULIB_CBRT''@/$(GNULIB_CBRT)/g' \ 1012 -e 's/@''GNULIB_CBRT''@/$(GL_GNULIB_CBRT)/g' \
635 -e 's/@''GNULIB_CBRTF''@/$(GNULIB_CBRTF)/g' \ 1013 -e 's/@''GNULIB_CBRTF''@/$(GL_GNULIB_CBRTF)/g' \
636 -e 's/@''GNULIB_CBRTL''@/$(GNULIB_CBRTL)/g' \ 1014 -e 's/@''GNULIB_CBRTL''@/$(GL_GNULIB_CBRTL)/g' \
637 -e 's/@''GNULIB_CEIL''@/$(GNULIB_CEIL)/g' \ 1015 -e 's/@''GNULIB_CEIL''@/$(GL_GNULIB_CEIL)/g' \
638 -e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \ 1016 -e 's/@''GNULIB_CEILF''@/$(GL_GNULIB_CEILF)/g' \
639 -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \ 1017 -e 's/@''GNULIB_CEILL''@/$(GL_GNULIB_CEILL)/g' \
640 -e 's/@''GNULIB_COPYSIGN''@/$(GNULIB_COPYSIGN)/g' \ 1018 -e 's/@''GNULIB_COPYSIGN''@/$(GL_GNULIB_COPYSIGN)/g' \
641 -e 's/@''GNULIB_COPYSIGNF''@/$(GNULIB_COPYSIGNF)/g' \ 1019 -e 's/@''GNULIB_COPYSIGNF''@/$(GL_GNULIB_COPYSIGNF)/g' \
642 -e 's/@''GNULIB_COPYSIGNL''@/$(GNULIB_COPYSIGNL)/g' \ 1020 -e 's/@''GNULIB_COPYSIGNL''@/$(GL_GNULIB_COPYSIGNL)/g' \
643 -e 's/@''GNULIB_COSF''@/$(GNULIB_COSF)/g' \ 1021 -e 's/@''GNULIB_COSF''@/$(GL_GNULIB_COSF)/g' \
644 -e 's/@''GNULIB_COSL''@/$(GNULIB_COSL)/g' \ 1022 -e 's/@''GNULIB_COSL''@/$(GL_GNULIB_COSL)/g' \
645 -e 's/@''GNULIB_COSHF''@/$(GNULIB_COSHF)/g' \ 1023 -e 's/@''GNULIB_COSHF''@/$(GL_GNULIB_COSHF)/g' \
646 -e 's/@''GNULIB_EXPF''@/$(GNULIB_EXPF)/g' \ 1024 -e 's/@''GNULIB_EXPF''@/$(GL_GNULIB_EXPF)/g' \
647 -e 's/@''GNULIB_EXPL''@/$(GNULIB_EXPL)/g' \ 1025 -e 's/@''GNULIB_EXPL''@/$(GL_GNULIB_EXPL)/g' \
648 -e 's/@''GNULIB_EXP2''@/$(GNULIB_EXP2)/g' \ 1026 -e 's/@''GNULIB_EXP2''@/$(GL_GNULIB_EXP2)/g' \
649 -e 's/@''GNULIB_EXP2F''@/$(GNULIB_EXP2F)/g' \ 1027 -e 's/@''GNULIB_EXP2F''@/$(GL_GNULIB_EXP2F)/g' \
650 -e 's/@''GNULIB_EXP2L''@/$(GNULIB_EXP2L)/g' \ 1028 -e 's/@''GNULIB_EXP2L''@/$(GL_GNULIB_EXP2L)/g' \
651 -e 's/@''GNULIB_EXPM1''@/$(GNULIB_EXPM1)/g' \ 1029 -e 's/@''GNULIB_EXPM1''@/$(GL_GNULIB_EXPM1)/g' \
652 -e 's/@''GNULIB_EXPM1F''@/$(GNULIB_EXPM1F)/g' \ 1030 -e 's/@''GNULIB_EXPM1F''@/$(GL_GNULIB_EXPM1F)/g' \
653 -e 's/@''GNULIB_EXPM1L''@/$(GNULIB_EXPM1L)/g' \ 1031 -e 's/@''GNULIB_EXPM1L''@/$(GL_GNULIB_EXPM1L)/g' \
654 -e 's/@''GNULIB_FABSF''@/$(GNULIB_FABSF)/g' \ 1032 -e 's/@''GNULIB_FABSF''@/$(GL_GNULIB_FABSF)/g' \
655 -e 's/@''GNULIB_FABSL''@/$(GNULIB_FABSL)/g' \ 1033 -e 's/@''GNULIB_FABSL''@/$(GL_GNULIB_FABSL)/g' \
656 -e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \ 1034 -e 's/@''GNULIB_FLOOR''@/$(GL_GNULIB_FLOOR)/g' \
657 -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \ 1035 -e 's/@''GNULIB_FLOORF''@/$(GL_GNULIB_FLOORF)/g' \
658 -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \ 1036 -e 's/@''GNULIB_FLOORL''@/$(GL_GNULIB_FLOORL)/g' \
659 -e 's/@''GNULIB_FMA''@/$(GNULIB_FMA)/g' \ 1037 -e 's/@''GNULIB_FMA''@/$(GL_GNULIB_FMA)/g' \
660 -e 's/@''GNULIB_FMAF''@/$(GNULIB_FMAF)/g' \ 1038 -e 's/@''GNULIB_FMAF''@/$(GL_GNULIB_FMAF)/g' \
661 -e 's/@''GNULIB_FMAL''@/$(GNULIB_FMAL)/g' \ 1039 -e 's/@''GNULIB_FMAL''@/$(GL_GNULIB_FMAL)/g' \
662 -e 's/@''GNULIB_FMOD''@/$(GNULIB_FMOD)/g' \ 1040 -e 's/@''GNULIB_FMOD''@/$(GL_GNULIB_FMOD)/g' \
663 -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \ 1041 -e 's/@''GNULIB_FMODF''@/$(GL_GNULIB_FMODF)/g' \
664 -e 's/@''GNULIB_FMODL''@/$(GNULIB_FMODL)/g' \ 1042 -e 's/@''GNULIB_FMODL''@/$(GL_GNULIB_FMODL)/g' \
665 -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \ 1043 -e 's/@''GNULIB_FREXPF''@/$(GL_GNULIB_FREXPF)/g' \
666 -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \ 1044 -e 's/@''GNULIB_FREXP''@/$(GL_GNULIB_FREXP)/g' \
667 -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \ 1045 -e 's/@''GNULIB_FREXPL''@/$(GL_GNULIB_FREXPL)/g' \
668 -e 's/@''GNULIB_HYPOT''@/$(GNULIB_HYPOT)/g' \ 1046 -e 's/@''GNULIB_HYPOT''@/$(GL_GNULIB_HYPOT)/g' \
669 -e 's/@''GNULIB_HYPOTF''@/$(GNULIB_HYPOTF)/g' \ 1047 -e 's/@''GNULIB_HYPOTF''@/$(GL_GNULIB_HYPOTF)/g' \
670 -e 's/@''GNULIB_HYPOTL''@/$(GNULIB_HYPOTL)/g' \ 1048 -e 's/@''GNULIB_HYPOTL''@/$(GL_GNULIB_HYPOTL)/g' \
671 < $(srcdir)/math.in.h | \ 1049 < $(srcdir)/math.in.h | \
672 sed -e 's/@''GNULIB_ILOGB''@/$(GNULIB_ILOGB)/g' \ 1050 sed -e 's/@''GNULIB_ILOGB''@/$(GL_GNULIB_ILOGB)/g' \
673 -e 's/@''GNULIB_ILOGBF''@/$(GNULIB_ILOGBF)/g' \ 1051 -e 's/@''GNULIB_ILOGBF''@/$(GL_GNULIB_ILOGBF)/g' \
674 -e 's/@''GNULIB_ILOGBL''@/$(GNULIB_ILOGBL)/g' \ 1052 -e 's/@''GNULIB_ILOGBL''@/$(GL_GNULIB_ILOGBL)/g' \
675 -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \ 1053 -e 's/@''GNULIB_ISFINITE''@/$(GL_GNULIB_ISFINITE)/g' \
676 -e 's/@''GNULIB_ISINF''@/$(GNULIB_ISINF)/g' \ 1054 -e 's/@''GNULIB_ISINF''@/$(GL_GNULIB_ISINF)/g' \
677 -e 's/@''GNULIB_ISNAN''@/$(GNULIB_ISNAN)/g' \ 1055 -e 's/@''GNULIB_ISNAN''@/$(GL_GNULIB_ISNAN)/g' \
678 -e 's/@''GNULIB_ISNANF''@/$(GNULIB_ISNANF)/g' \ 1056 -e 's/@''GNULIB_ISNANF''@/$(GL_GNULIB_ISNANF)/g' \
679 -e 's/@''GNULIB_ISNAND''@/$(GNULIB_ISNAND)/g' \ 1057 -e 's/@''GNULIB_ISNAND''@/$(GL_GNULIB_ISNAND)/g' \
680 -e 's/@''GNULIB_ISNANL''@/$(GNULIB_ISNANL)/g' \ 1058 -e 's/@''GNULIB_ISNANL''@/$(GL_GNULIB_ISNANL)/g' \
681 -e 's/@''GNULIB_LDEXPF''@/$(GNULIB_LDEXPF)/g' \ 1059 -e 's/@''GNULIB_LDEXPF''@/$(GL_GNULIB_LDEXPF)/g' \
682 -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \ 1060 -e 's/@''GNULIB_LDEXPL''@/$(GL_GNULIB_LDEXPL)/g' \
683 -e 's/@''GNULIB_LOG''@/$(GNULIB_LOG)/g' \ 1061 -e 's/@''GNULIB_LOG''@/$(GL_GNULIB_LOG)/g' \
684 -e 's/@''GNULIB_LOGF''@/$(GNULIB_LOGF)/g' \ 1062 -e 's/@''GNULIB_LOGF''@/$(GL_GNULIB_LOGF)/g' \
685 -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ 1063 -e 's/@''GNULIB_LOGL''@/$(GL_GNULIB_LOGL)/g' \
686 -e 's/@''GNULIB_LOG10''@/$(GNULIB_LOG10)/g' \ 1064 -e 's/@''GNULIB_LOG10''@/$(GL_GNULIB_LOG10)/g' \
687 -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ 1065 -e 's/@''GNULIB_LOG10F''@/$(GL_GNULIB_LOG10F)/g' \
688 -e 's/@''GNULIB_LOG10L''@/$(GNULIB_LOG10L)/g' \ 1066 -e 's/@''GNULIB_LOG10L''@/$(GL_GNULIB_LOG10L)/g' \
689 -e 's/@''GNULIB_LOG1P''@/$(GNULIB_LOG1P)/g' \ 1067 -e 's/@''GNULIB_LOG1P''@/$(GL_GNULIB_LOG1P)/g' \
690 -e 's/@''GNULIB_LOG1PF''@/$(GNULIB_LOG1PF)/g' \ 1068 -e 's/@''GNULIB_LOG1PF''@/$(GL_GNULIB_LOG1PF)/g' \
691 -e 's/@''GNULIB_LOG1PL''@/$(GNULIB_LOG1PL)/g' \ 1069 -e 's/@''GNULIB_LOG1PL''@/$(GL_GNULIB_LOG1PL)/g' \
692 -e 's/@''GNULIB_LOG2''@/$(GNULIB_LOG2)/g' \ 1070 -e 's/@''GNULIB_LOG2''@/$(GL_GNULIB_LOG2)/g' \
693 -e 's/@''GNULIB_LOG2F''@/$(GNULIB_LOG2F)/g' \ 1071 -e 's/@''GNULIB_LOG2F''@/$(GL_GNULIB_LOG2F)/g' \
694 -e 's/@''GNULIB_LOG2L''@/$(GNULIB_LOG2L)/g' \ 1072 -e 's/@''GNULIB_LOG2L''@/$(GL_GNULIB_LOG2L)/g' \
695 -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \ 1073 -e 's/@''GNULIB_LOGB''@/$(GL_GNULIB_LOGB)/g' \
696 -e 's/@''GNULIB_LOGBF''@/$(GNULIB_LOGBF)/g' \ 1074 -e 's/@''GNULIB_LOGBF''@/$(GL_GNULIB_LOGBF)/g' \
697 -e 's/@''GNULIB_LOGBL''@/$(GNULIB_LOGBL)/g' \ 1075 -e 's/@''GNULIB_LOGBL''@/$(GL_GNULIB_LOGBL)/g' \
698 -e 's/@''GNULIB_MODF''@/$(GNULIB_MODF)/g' \ 1076 -e 's/@''GNULIB_MODF''@/$(GL_GNULIB_MODF)/g' \
699 -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ 1077 -e 's/@''GNULIB_MODFF''@/$(GL_GNULIB_MODFF)/g' \
700 -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \ 1078 -e 's/@''GNULIB_MODFL''@/$(GL_GNULIB_MODFL)/g' \
701 -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \ 1079 -e 's/@''GNULIB_POWF''@/$(GL_GNULIB_POWF)/g' \
702 -e 's/@''GNULIB_REMAINDER''@/$(GNULIB_REMAINDER)/g' \ 1080 -e 's/@''GNULIB_REMAINDER''@/$(GL_GNULIB_REMAINDER)/g' \
703 -e 's/@''GNULIB_REMAINDERF''@/$(GNULIB_REMAINDERF)/g' \ 1081 -e 's/@''GNULIB_REMAINDERF''@/$(GL_GNULIB_REMAINDERF)/g' \
704 -e 's/@''GNULIB_REMAINDERL''@/$(GNULIB_REMAINDERL)/g' \ 1082 -e 's/@''GNULIB_REMAINDERL''@/$(GL_GNULIB_REMAINDERL)/g' \
705 -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \ 1083 -e 's/@''GNULIB_RINT''@/$(GL_GNULIB_RINT)/g' \
706 -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \ 1084 -e 's/@''GNULIB_RINTF''@/$(GL_GNULIB_RINTF)/g' \
707 -e 's/@''GNULIB_RINTL''@/$(GNULIB_RINTL)/g' \ 1085 -e 's/@''GNULIB_RINTL''@/$(GL_GNULIB_RINTL)/g' \
708 -e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \ 1086 -e 's/@''GNULIB_ROUND''@/$(GL_GNULIB_ROUND)/g' \
709 -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \ 1087 -e 's/@''GNULIB_ROUNDF''@/$(GL_GNULIB_ROUNDF)/g' \
710 -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \ 1088 -e 's/@''GNULIB_ROUNDL''@/$(GL_GNULIB_ROUNDL)/g' \
711 -e 's/@''GNULIB_SIGNBIT''@/$(GNULIB_SIGNBIT)/g' \ 1089 -e 's/@''GNULIB_SIGNBIT''@/$(GL_GNULIB_SIGNBIT)/g' \
712 -e 's/@''GNULIB_SINF''@/$(GNULIB_SINF)/g' \ 1090 -e 's/@''GNULIB_SINF''@/$(GL_GNULIB_SINF)/g' \
713 -e 's/@''GNULIB_SINL''@/$(GNULIB_SINL)/g' \ 1091 -e 's/@''GNULIB_SINL''@/$(GL_GNULIB_SINL)/g' \
714 -e 's/@''GNULIB_SINHF''@/$(GNULIB_SINHF)/g' \ 1092 -e 's/@''GNULIB_SINHF''@/$(GL_GNULIB_SINHF)/g' \
715 -e 's/@''GNULIB_SQRTF''@/$(GNULIB_SQRTF)/g' \ 1093 -e 's/@''GNULIB_SQRTF''@/$(GL_GNULIB_SQRTF)/g' \
716 -e 's/@''GNULIB_SQRTL''@/$(GNULIB_SQRTL)/g' \ 1094 -e 's/@''GNULIB_SQRTL''@/$(GL_GNULIB_SQRTL)/g' \
717 -e 's/@''GNULIB_TANF''@/$(GNULIB_TANF)/g' \ 1095 -e 's/@''GNULIB_TANF''@/$(GL_GNULIB_TANF)/g' \
718 -e 's/@''GNULIB_TANL''@/$(GNULIB_TANL)/g' \ 1096 -e 's/@''GNULIB_TANL''@/$(GL_GNULIB_TANL)/g' \
719 -e 's/@''GNULIB_TANHF''@/$(GNULIB_TANHF)/g' \ 1097 -e 's/@''GNULIB_TANHF''@/$(GL_GNULIB_TANHF)/g' \
720 -e 's/@''GNULIB_TRUNC''@/$(GNULIB_TRUNC)/g' \ 1098 -e 's/@''GNULIB_TRUNC''@/$(GL_GNULIB_TRUNC)/g' \
721 -e 's/@''GNULIB_TRUNCF''@/$(GNULIB_TRUNCF)/g' \ 1099 -e 's/@''GNULIB_TRUNCF''@/$(GL_GNULIB_TRUNCF)/g' \
722 -e 's/@''GNULIB_TRUNCL''@/$(GNULIB_TRUNCL)/g' \ 1100 -e 's/@''GNULIB_TRUNCL''@/$(GL_GNULIB_TRUNCL)/g' \
1101 -e 's/@''GNULIB_MDA_J0''@/$(GL_GNULIB_MDA_J0)/g' \
1102 -e 's/@''GNULIB_MDA_J1''@/$(GL_GNULIB_MDA_J1)/g' \
1103 -e 's/@''GNULIB_MDA_JN''@/$(GL_GNULIB_MDA_JN)/g' \
1104 -e 's/@''GNULIB_MDA_Y0''@/$(GL_GNULIB_MDA_Y0)/g' \
1105 -e 's/@''GNULIB_MDA_Y1''@/$(GL_GNULIB_MDA_Y1)/g' \
1106 -e 's/@''GNULIB_MDA_YN''@/$(GL_GNULIB_MDA_YN)/g' \
723 | \ 1107 | \
724 sed -e 's|@''HAVE_ACOSF''@|$(HAVE_ACOSF)|g' \ 1108 sed -e 's|@''HAVE_ACOSF''@|$(HAVE_ACOSF)|g' \
725 -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \ 1109 -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \
@@ -818,13 +1202,22 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
818 -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \ 1202 -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \
819 -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ 1203 -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \
820 | \ 1204 | \
821 sed -e 's|@''REPLACE_CBRTF''@|$(REPLACE_CBRTF)|g' \ 1205 sed -e 's|@''REPLACE_ACOSF''@|$(REPLACE_ACOSF)|g' \
1206 -e 's|@''REPLACE_ASINF''@|$(REPLACE_ASINF)|g' \
1207 -e 's|@''REPLACE_ATANF''@|$(REPLACE_ATANF)|g' \
1208 -e 's|@''REPLACE_ATAN2F''@|$(REPLACE_ATAN2F)|g' \
1209 -e 's|@''REPLACE_CBRTF''@|$(REPLACE_CBRTF)|g' \
822 -e 's|@''REPLACE_CBRTL''@|$(REPLACE_CBRTL)|g' \ 1210 -e 's|@''REPLACE_CBRTL''@|$(REPLACE_CBRTL)|g' \
823 -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \ 1211 -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \
824 -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ 1212 -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \
825 -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ 1213 -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \
1214 -e 's|@''REPLACE_COSF''@|$(REPLACE_COSF)|g' \
1215 -e 's|@''REPLACE_COSHF''@|$(REPLACE_COSHF)|g' \
1216 -e 's|@''REPLACE_EXPF''@|$(REPLACE_EXPF)|g' \
1217 -e 's|@''REPLACE_EXPL''@|$(REPLACE_EXPL)|g' \
826 -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \ 1218 -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \
827 -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \ 1219 -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \
1220 -e 's|@''REPLACE_EXPM1L''@|$(REPLACE_EXPM1L)|g' \
828 -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \ 1221 -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \
829 -e 's|@''REPLACE_EXP2L''@|$(REPLACE_EXP2L)|g' \ 1222 -e 's|@''REPLACE_EXP2L''@|$(REPLACE_EXP2L)|g' \
830 -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \ 1223 -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \
@@ -846,6 +1239,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
846 -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \ 1239 -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \
847 -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \ 1240 -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \
848 -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \ 1241 -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \
1242 -e 's|@''REPLACE_ILOGBL''@|$(REPLACE_ILOGBL)|g' \
849 -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \ 1243 -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
850 -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \ 1244 -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
851 -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \ 1245 -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
@@ -873,20 +1267,26 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
873 -e 's|@''REPLACE_REMAINDER''@|$(REPLACE_REMAINDER)|g' \ 1267 -e 's|@''REPLACE_REMAINDER''@|$(REPLACE_REMAINDER)|g' \
874 -e 's|@''REPLACE_REMAINDERF''@|$(REPLACE_REMAINDERF)|g' \ 1268 -e 's|@''REPLACE_REMAINDERF''@|$(REPLACE_REMAINDERF)|g' \
875 -e 's|@''REPLACE_REMAINDERL''@|$(REPLACE_REMAINDERL)|g' \ 1269 -e 's|@''REPLACE_REMAINDERL''@|$(REPLACE_REMAINDERL)|g' \
1270 -e 's|@''REPLACE_RINTL''@|$(REPLACE_RINTL)|g' \
876 -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \ 1271 -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
877 -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \ 1272 -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
878 -e 's|@''REPLACE_ROUNDL''@|$(REPLACE_ROUNDL)|g' \ 1273 -e 's|@''REPLACE_ROUNDL''@|$(REPLACE_ROUNDL)|g' \
879 -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \ 1274 -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \
880 -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ 1275 -e 's|@''REPLACE_SIGNBIT_USING_BUILTINS''@|$(REPLACE_SIGNBIT_USING_BUILTINS)|g' \
1276 -e 's|@''REPLACE_SINF''@|$(REPLACE_SINF)|g' \
1277 -e 's|@''REPLACE_SINHF''@|$(REPLACE_SINHF)|g' \
1278 -e 's|@''REPLACE_SQRTF''@|$(REPLACE_SQRTF)|g' \
881 -e 's|@''REPLACE_SQRTL''@|$(REPLACE_SQRTL)|g' \ 1279 -e 's|@''REPLACE_SQRTL''@|$(REPLACE_SQRTL)|g' \
1280 -e 's|@''REPLACE_TANF''@|$(REPLACE_TANF)|g' \
1281 -e 's|@''REPLACE_TANHF''@|$(REPLACE_TANHF)|g' \
882 -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \ 1282 -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \
883 -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \ 1283 -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \
884 -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ 1284 -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \
885 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 1285 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
886 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 1286 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
887 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 1287 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
888 } > $@-t && \ 1288 > $@-t
889 mv $@-t $@ 1289 $(AM_V_at)mv $@-t $@
890MOSTLYCLEANFILES += math.h math.h-t 1290MOSTLYCLEANFILES += math.h math.h-t
891 1291
892EXTRA_DIST += math.in.h 1292EXTRA_DIST += math.in.h
@@ -895,40 +1295,50 @@ EXTRA_DIST += math.in.h
895 1295
896## begin gnulib module mbrtowc 1296## begin gnulib module mbrtowc
897 1297
1298if GL_COND_OBJ_MBRTOWC
1299libgnu_a_SOURCES += mbrtowc.c
1300endif
898 1301
899EXTRA_DIST += mbrtowc.c 1302EXTRA_DIST += lc-charset-dispatch.c lc-charset-dispatch.h mbrtowc-impl-utf8.h mbrtowc-impl.h mbtowc-lock.c mbtowc-lock.h windows-initguard.h
900 1303
901EXTRA_libgnu_a_SOURCES += mbrtowc.c 1304EXTRA_libgnu_a_SOURCES += lc-charset-dispatch.c mbtowc-lock.c
902 1305
903## end gnulib module mbrtowc 1306## end gnulib module mbrtowc
904 1307
905## begin gnulib module mbsinit 1308## begin gnulib module mbsinit
906 1309
907 1310if GL_COND_OBJ_MBSINIT
908EXTRA_DIST += mbsinit.c 1311libgnu_a_SOURCES += mbsinit.c
909 1312endif
910EXTRA_libgnu_a_SOURCES += mbsinit.c
911 1313
912## end gnulib module mbsinit 1314## end gnulib module mbsinit
913 1315
914## begin gnulib module mbtowc 1316## begin gnulib module mbtowc
915 1317
1318if GL_COND_OBJ_MBTOWC
1319libgnu_a_SOURCES += mbtowc.c
1320endif
916 1321
917EXTRA_DIST += mbtowc-impl.h mbtowc.c 1322EXTRA_DIST += mbtowc-impl.h
918
919EXTRA_libgnu_a_SOURCES += mbtowc.c
920 1323
921## end gnulib module mbtowc 1324## end gnulib module mbtowc
922 1325
923## begin gnulib module memchr 1326## begin gnulib module memchr
924 1327
1328if GL_COND_OBJ_MEMCHR
1329libgnu_a_SOURCES += memchr.c
1330endif
925 1331
926EXTRA_DIST += memchr.c memchr.valgrind 1332EXTRA_DIST += memchr.valgrind
927
928EXTRA_libgnu_a_SOURCES += memchr.c
929 1333
930## end gnulib module memchr 1334## end gnulib module memchr
931 1335
1336## begin gnulib module minmax
1337
1338libgnu_a_SOURCES += minmax.h
1339
1340## end gnulib module minmax
1341
932## begin gnulib module mktime 1342## begin gnulib module mktime
933 1343
934 1344
@@ -949,28 +1359,31 @@ EXTRA_libgnu_a_SOURCES += mktime.c
949 1359
950## begin gnulib module mountlist 1360## begin gnulib module mountlist
951 1361
1362if GL_COND_OBJ_MOUNTLIST
1363libgnu_a_SOURCES += mountlist.c
1364endif
952 1365
953EXTRA_DIST += mountlist.c mountlist.h 1366EXTRA_DIST += mountlist.h
954
955EXTRA_libgnu_a_SOURCES += mountlist.c
956 1367
957## end gnulib module mountlist 1368## end gnulib module mountlist
958 1369
959## begin gnulib module msvc-inval 1370## begin gnulib module msvc-inval
960 1371
1372if GL_COND_OBJ_MSVC_INVAL
1373libgnu_a_SOURCES += msvc-inval.c
1374endif
961 1375
962EXTRA_DIST += msvc-inval.c msvc-inval.h 1376EXTRA_DIST += msvc-inval.h
963
964EXTRA_libgnu_a_SOURCES += msvc-inval.c
965 1377
966## end gnulib module msvc-inval 1378## end gnulib module msvc-inval
967 1379
968## begin gnulib module msvc-nothrow 1380## begin gnulib module msvc-nothrow
969 1381
1382if GL_COND_OBJ_MSVC_NOTHROW
1383libgnu_a_SOURCES += msvc-nothrow.c
1384endif
970 1385
971EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h 1386EXTRA_DIST += msvc-nothrow.h
972
973EXTRA_libgnu_a_SOURCES += msvc-nothrow.c
974 1387
975## end gnulib module msvc-nothrow 1388## end gnulib module msvc-nothrow
976 1389
@@ -981,27 +1394,26 @@ BUILT_SOURCES += netdb.h
981# We need the following in order to create <netdb.h> when the system 1394# We need the following in order to create <netdb.h> when the system
982# doesn't have one that works with the given compiler. 1395# doesn't have one that works with the given compiler.
983netdb.h: netdb.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 1396netdb.h: netdb.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
984 $(AM_V_GEN)rm -f $@-t $@ && \ 1397 $(gl_V_at)$(SED_HEADER_STDOUT) \
985 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1398 -e 's|@''GUARD_PREFIX''@|GL|g' \
986 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
987 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1399 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
988 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1400 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
989 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1401 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
990 -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \ 1402 -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
991 -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \ 1403 -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
992 -e 's/@''GNULIB_GETADDRINFO''@/$(GNULIB_GETADDRINFO)/g' \ 1404 -e 's/@''GNULIB_GETADDRINFO''@/$(GL_GNULIB_GETADDRINFO)/g' \
993 -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \ 1405 -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \
994 -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \ 1406 -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \
995 -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \ 1407 -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
996 -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \ 1408 -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
997 -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \ 1409 -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
998 -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \ 1410 -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \
1411 -e 's|@''REPLACE_GETADDRINFO''@|$(REPLACE_GETADDRINFO)|g' \
999 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 1412 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1000 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 1413 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1001 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 1414 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1002 < $(srcdir)/netdb.in.h; \ 1415 $(srcdir)/netdb.in.h > $@-t
1003 } > $@-t && \ 1416 $(AM_V_at)mv $@-t $@
1004 mv $@-t $@
1005MOSTLYCLEANFILES += netdb.h netdb.h-t 1417MOSTLYCLEANFILES += netdb.h netdb.h-t
1006 1418
1007EXTRA_DIST += netdb.in.h 1419EXTRA_DIST += netdb.in.h
@@ -1016,18 +1428,16 @@ BUILT_SOURCES += $(NETINET_IN_H)
1016# doesn't have one. 1428# doesn't have one.
1017if GL_GENERATE_NETINET_IN_H 1429if GL_GENERATE_NETINET_IN_H
1018netinet/in.h: netinet_in.in.h $(top_builddir)/config.status 1430netinet/in.h: netinet_in.in.h $(top_builddir)/config.status
1019 $(AM_V_at)$(MKDIR_P) netinet 1431 $(AM_V_GEN)$(MKDIR_P) '%reldir%/netinet'
1020 $(AM_V_GEN)rm -f $@-t $@ && \ 1432 $(AM_V_at)$(SED_HEADER_STDOUT) \
1021 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1433 -e 's|@''GUARD_PREFIX''@|GL|g' \
1022 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1023 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1434 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1024 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1435 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1025 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1436 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1026 -e 's|@''NEXT_NETINET_IN_H''@|$(NEXT_NETINET_IN_H)|g' \ 1437 -e 's|@''NEXT_NETINET_IN_H''@|$(NEXT_NETINET_IN_H)|g' \
1027 -e 's|@''HAVE_NETINET_IN_H''@|$(HAVE_NETINET_IN_H)|g' \ 1438 -e 's|@''HAVE_NETINET_IN_H''@|$(HAVE_NETINET_IN_H)|g' \
1028 < $(srcdir)/netinet_in.in.h; \ 1439 $(srcdir)/netinet_in.in.h > $@-t
1029 } > $@-t && \ 1440 $(AM_V_at)mv $@-t $@
1030 mv $@-t $@
1031else 1441else
1032netinet/in.h: $(top_builddir)/config.status 1442netinet/in.h: $(top_builddir)/config.status
1033 rm -f $@ 1443 rm -f $@
@@ -1041,48 +1451,89 @@ EXTRA_DIST += netinet_in.in.h
1041 1451
1042## begin gnulib module nl_langinfo 1452## begin gnulib module nl_langinfo
1043 1453
1454if GL_COND_OBJ_NL_LANGINFO
1455libgnu_a_SOURCES += nl_langinfo.c
1456endif
1457if GL_COND_OBJ_NL_LANGINFO_LOCK
1458libgnu_a_SOURCES += nl_langinfo-lock.c
1459endif
1044 1460
1045EXTRA_DIST += nl_langinfo.c 1461EXTRA_DIST += windows-initguard.h
1046
1047EXTRA_libgnu_a_SOURCES += nl_langinfo.c
1048 1462
1049## end gnulib module nl_langinfo 1463## end gnulib module nl_langinfo
1050 1464
1051## begin gnulib module read 1465## begin gnulib module open
1052 1466
1467if GL_COND_OBJ_OPEN
1468libgnu_a_SOURCES += open.c
1469endif
1053 1470
1054EXTRA_DIST += read.c 1471## end gnulib module open
1055 1472
1056EXTRA_libgnu_a_SOURCES += read.c 1473## begin gnulib module pathmax
1057 1474
1058## end gnulib module read
1059 1475
1060## begin gnulib module regex 1476EXTRA_DIST += pathmax.h
1061 1477
1478## end gnulib module pathmax
1062 1479
1063EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c 1480## begin gnulib module realloc-gnu
1064 1481
1065EXTRA_libgnu_a_SOURCES += regcomp.c regex.c regex_internal.c regexec.c
1066 1482
1067## end gnulib module regex 1483EXTRA_DIST += realloc.c
1068 1484
1069## begin gnulib module safe-read 1485EXTRA_libgnu_a_SOURCES += realloc.c
1070 1486
1071libgnu_a_SOURCES += safe-read.c 1487## end gnulib module realloc-gnu
1072 1488
1073EXTRA_DIST += safe-read.h 1489## begin gnulib module realloc-posix
1074 1490
1075## end gnulib module safe-read
1076 1491
1077## begin gnulib module setenv 1492EXTRA_DIST += realloc.c
1493
1494EXTRA_libgnu_a_SOURCES += realloc.c
1495
1496## end gnulib module realloc-posix
1497
1498## begin gnulib module reallocarray
1499
1500if GL_COND_OBJ_REALLOCARRAY
1501libgnu_a_SOURCES += reallocarray.c
1502endif
1078 1503
1504## end gnulib module reallocarray
1079 1505
1080EXTRA_DIST += setenv.c 1506## begin gnulib module regex
1507
1508if GL_COND_OBJ_REGEX
1509libgnu_a_SOURCES += regex.c
1510endif
1511
1512EXTRA_DIST += regcomp.c regex.h regex_internal.c regex_internal.h regexec.c
1513
1514EXTRA_libgnu_a_SOURCES += regcomp.c regex_internal.c regexec.c
1515
1516## end gnulib module regex
1517
1518## begin gnulib module setenv
1081 1519
1082EXTRA_libgnu_a_SOURCES += setenv.c 1520if GL_COND_OBJ_SETENV
1521libgnu_a_SOURCES += setenv.c
1522endif
1083 1523
1084## end gnulib module setenv 1524## end gnulib module setenv
1085 1525
1526## begin gnulib module setlocale-null
1527
1528libgnu_a_SOURCES += setlocale_null.c
1529if GL_COND_OBJ_SETLOCALE_LOCK
1530libgnu_a_SOURCES += setlocale-lock.c
1531endif
1532
1533EXTRA_DIST += setlocale_null.h windows-initguard.h
1534
1535## end gnulib module setlocale-null
1536
1086## begin gnulib module size_max 1537## begin gnulib module size_max
1087 1538
1088libgnu_a_SOURCES += size_max.h 1539libgnu_a_SOURCES += size_max.h
@@ -1092,81 +1543,48 @@ libgnu_a_SOURCES += size_max.h
1092## begin gnulib module snippet/_Noreturn 1543## begin gnulib module snippet/_Noreturn
1093 1544
1094# Because this Makefile snippet defines a variable used by other 1545# Because this Makefile snippet defines a variable used by other
1095# gnulib Makefile snippets, it must be present in all Makefile.am that 1546# gnulib Makefile snippets, it must be present in all makefiles that
1096# need it. This is ensured by the applicability 'all' defined above. 1547# need it. This is ensured by the applicability 'all' defined above.
1097 1548
1098_NORETURN_H=$(top_srcdir)/build-aux/snippet/_Noreturn.h 1549_NORETURN_H=$(srcdir)/_Noreturn.h
1099 1550
1100EXTRA_DIST += $(top_srcdir)/build-aux/snippet/_Noreturn.h 1551EXTRA_DIST += _Noreturn.h
1101 1552
1102## end gnulib module snippet/_Noreturn 1553## end gnulib module snippet/_Noreturn
1103 1554
1104## begin gnulib module snippet/arg-nonnull 1555## begin gnulib module snippet/arg-nonnull
1105 1556
1106# The BUILT_SOURCES created by this Makefile snippet are not used via #include 1557# Because this Makefile snippet defines a variable used by other
1107# statements but through direct file reference. Therefore this snippet must be 1558# gnulib Makefile snippets, it must be present in all makefiles that
1108# present in all Makefile.am that need it. This is ensured by the applicability 1559# need it. This is ensured by the applicability 'all' defined above.
1109# 'all' defined above.
1110
1111BUILT_SOURCES += arg-nonnull.h
1112# The arg-nonnull.h that gets inserted into generated .h files is the same as
1113# build-aux/snippet/arg-nonnull.h, except that it has the copyright header cut
1114# off.
1115arg-nonnull.h: $(top_srcdir)/build-aux/snippet/arg-nonnull.h
1116 $(AM_V_GEN)rm -f $@-t $@ && \
1117 sed -n -e '/GL_ARG_NONNULL/,$$p' \
1118 < $(top_srcdir)/build-aux/snippet/arg-nonnull.h \
1119 > $@-t && \
1120 mv $@-t $@
1121MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t
1122 1560
1123ARG_NONNULL_H=arg-nonnull.h 1561ARG_NONNULL_H=$(srcdir)/arg-nonnull.h
1124 1562
1125EXTRA_DIST += $(top_srcdir)/build-aux/snippet/arg-nonnull.h 1563EXTRA_DIST += arg-nonnull.h
1126 1564
1127## end gnulib module snippet/arg-nonnull 1565## end gnulib module snippet/arg-nonnull
1128 1566
1129## begin gnulib module snippet/c++defs 1567## begin gnulib module snippet/c++defs
1130 1568
1131# The BUILT_SOURCES created by this Makefile snippet are not used via #include 1569# Because this Makefile snippet defines a variable used by other
1132# statements but through direct file reference. Therefore this snippet must be 1570# gnulib Makefile snippets, it must be present in all makefiles that
1133# present in all Makefile.am that need it. This is ensured by the applicability 1571# need it. This is ensured by the applicability 'all' defined above.
1134# 'all' defined above.
1135
1136BUILT_SOURCES += c++defs.h
1137# The c++defs.h that gets inserted into generated .h files is the same as
1138# build-aux/snippet/c++defs.h, except that it has the copyright header cut off.
1139c++defs.h: $(top_srcdir)/build-aux/snippet/c++defs.h
1140 $(AM_V_GEN)rm -f $@-t $@ && \
1141 sed -n -e '/_GL_CXXDEFS/,$$p' \
1142 < $(top_srcdir)/build-aux/snippet/c++defs.h \
1143 > $@-t && \
1144 mv $@-t $@
1145MOSTLYCLEANFILES += c++defs.h c++defs.h-t
1146 1572
1147CXXDEFS_H=c++defs.h 1573CXXDEFS_H=$(srcdir)/c++defs.h
1148 1574
1149EXTRA_DIST += $(top_srcdir)/build-aux/snippet/c++defs.h 1575EXTRA_DIST += c++defs.h
1150 1576
1151## end gnulib module snippet/c++defs 1577## end gnulib module snippet/c++defs
1152 1578
1153## begin gnulib module snippet/warn-on-use 1579## begin gnulib module snippet/warn-on-use
1154 1580
1155BUILT_SOURCES += warn-on-use.h 1581# Because this Makefile snippet defines a variable used by other
1156# The warn-on-use.h that gets inserted into generated .h files is the same as 1582# gnulib Makefile snippets, it must be present in all makefiles that
1157# build-aux/snippet/warn-on-use.h, except that it has the copyright header cut 1583# need it. This is ensured by the applicability 'all' defined above.
1158# off.
1159warn-on-use.h: $(top_srcdir)/build-aux/snippet/warn-on-use.h
1160 $(AM_V_GEN)rm -f $@-t $@ && \
1161 sed -n -e '/^.ifndef/,$$p' \
1162 < $(top_srcdir)/build-aux/snippet/warn-on-use.h \
1163 > $@-t && \
1164 mv $@-t $@
1165MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t
1166 1584
1167WARN_ON_USE_H=warn-on-use.h 1585WARN_ON_USE_H=$(srcdir)/warn-on-use.h
1168 1586
1169EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h 1587EXTRA_DIST += warn-on-use.h
1170 1588
1171## end gnulib module snippet/warn-on-use 1589## end gnulib module snippet/warn-on-use
1172 1590
@@ -1187,6 +1605,26 @@ EXTRA_DIST += w32sock.h
1187 1605
1188## end gnulib module sockets 1606## end gnulib module sockets
1189 1607
1608## begin gnulib module stat
1609
1610if GL_COND_OBJ_STAT
1611libgnu_a_SOURCES += stat.c
1612endif
1613
1614EXTRA_DIST += stat-w32.c stat-w32.h
1615
1616EXTRA_libgnu_a_SOURCES += stat-w32.c
1617
1618## end gnulib module stat
1619
1620## begin gnulib module stat-time
1621
1622libgnu_a_SOURCES += stat-time.c
1623
1624EXTRA_DIST += stat-time.h
1625
1626## end gnulib module stat-time
1627
1190## begin gnulib module stdalign 1628## begin gnulib module stdalign
1191 1629
1192BUILT_SOURCES += $(STDALIGN_H) 1630BUILT_SOURCES += $(STDALIGN_H)
@@ -1195,11 +1633,8 @@ BUILT_SOURCES += $(STDALIGN_H)
1195# doesn't have one that works. 1633# doesn't have one that works.
1196if GL_GENERATE_STDALIGN_H 1634if GL_GENERATE_STDALIGN_H
1197stdalign.h: stdalign.in.h $(top_builddir)/config.status 1635stdalign.h: stdalign.in.h $(top_builddir)/config.status
1198 $(AM_V_GEN)rm -f $@-t $@ && \ 1636 $(gl_V_at)$(SED_HEADER_TO_AT_t) $(srcdir)/stdalign.in.h
1199 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1637 $(AM_V_at)mv $@-t $@
1200 cat $(srcdir)/stdalign.in.h; \
1201 } > $@-t && \
1202 mv $@-t $@
1203else 1638else
1204stdalign.h: $(top_builddir)/config.status 1639stdalign.h: $(top_builddir)/config.status
1205 rm -f $@ 1640 rm -f $@
@@ -1210,28 +1645,26 @@ EXTRA_DIST += stdalign.in.h
1210 1645
1211## end gnulib module stdalign 1646## end gnulib module stdalign
1212 1647
1213## begin gnulib module stdbool 1648## begin gnulib module stdckdint
1214 1649
1215BUILT_SOURCES += $(STDBOOL_H) 1650BUILT_SOURCES += $(STDCKDINT_H)
1216 1651
1217# We need the following in order to create <stdbool.h> when the system 1652# We need the following in order to create <stdckdint.h> when the system
1218# doesn't have one that works. 1653# doesn't have one that works with the given compiler.
1219if GL_GENERATE_STDBOOL_H 1654if GL_GENERATE_STDCKDINT_H
1220stdbool.h: stdbool.in.h $(top_builddir)/config.status 1655stdckdint.h: stdckdint.in.h $(top_builddir)/config.status
1221 $(AM_V_GEN)rm -f $@-t $@ && \ 1656 $(gl_V_at)$(SED_HEADER_STDOUT) \
1222 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1657 $(srcdir)/stdckdint.in.h > $@-t
1223 sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \ 1658 $(AM_V_at)mv $@-t $@
1224 } > $@-t && \
1225 mv $@-t $@
1226else 1659else
1227stdbool.h: $(top_builddir)/config.status 1660stdckdint.h: $(top_builddir)/config.status
1228 rm -f $@ 1661 rm -f $@
1229endif 1662endif
1230MOSTLYCLEANFILES += stdbool.h stdbool.h-t 1663MOSTLYCLEANFILES += stdckdint.h stdckdint.h-t
1231 1664
1232EXTRA_DIST += stdbool.in.h 1665EXTRA_DIST += intprops-internal.h stdckdint.in.h
1233 1666
1234## end gnulib module stdbool 1667## end gnulib module stdckdint
1235 1668
1236## begin gnulib module stddef 1669## begin gnulib module stddef
1237 1670
@@ -1241,18 +1674,17 @@ BUILT_SOURCES += $(STDDEF_H)
1241# doesn't have one that works with the given compiler. 1674# doesn't have one that works with the given compiler.
1242if GL_GENERATE_STDDEF_H 1675if GL_GENERATE_STDDEF_H
1243stddef.h: stddef.in.h $(top_builddir)/config.status 1676stddef.h: stddef.in.h $(top_builddir)/config.status
1244 $(AM_V_GEN)rm -f $@-t $@ && \ 1677 $(gl_V_at)$(SED_HEADER_STDOUT) \
1245 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1678 -e 's|@''GUARD_PREFIX''@|GL|g' \
1246 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1247 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1679 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1248 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1680 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1249 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1681 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1250 -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \ 1682 -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
1683 -e 's|@''HAVE_MAX_ALIGN_T''@|$(HAVE_MAX_ALIGN_T)|g' \
1251 -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ 1684 -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
1252 -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ 1685 -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \
1253 < $(srcdir)/stddef.in.h; \ 1686 $(srcdir)/stddef.in.h > $@-t
1254 } > $@-t && \ 1687 $(AM_V_at)mv $@-t $@
1255 mv $@-t $@
1256else 1688else
1257stddef.h: $(top_builddir)/config.status 1689stddef.h: $(top_builddir)/config.status
1258 rm -f $@ 1690 rm -f $@
@@ -1271,21 +1703,19 @@ BUILT_SOURCES += $(STDINT_H)
1271# doesn't have one that works with the given compiler. 1703# doesn't have one that works with the given compiler.
1272if GL_GENERATE_STDINT_H 1704if GL_GENERATE_STDINT_H
1273stdint.h: stdint.in.h $(top_builddir)/config.status 1705stdint.h: stdint.in.h $(top_builddir)/config.status
1274 $(AM_V_GEN)rm -f $@-t $@ && \ 1706 $(gl_V_at)$(SED_HEADER_STDOUT) \
1275 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 1707 -e 's|@''GUARD_PREFIX''@|GL|g' \
1276 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1277 -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ 1708 -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
1278 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1709 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1279 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1710 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1280 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1711 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1281 -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \ 1712 -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \
1713 -e 's/@''HAVE_C99_STDINT_H''@/$(HAVE_C99_STDINT_H)/g' \
1282 -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ 1714 -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
1283 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ 1715 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
1284 -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ 1716 -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
1285 -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ 1717 -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
1286 -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \ 1718 -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
1287 -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \
1288 -e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \
1289 -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \ 1719 -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
1290 -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ 1720 -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \
1291 -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ 1721 -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \
@@ -1300,9 +1730,9 @@ stdint.h: stdint.in.h $(top_builddir)/config.status
1300 -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ 1730 -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
1301 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ 1731 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
1302 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ 1732 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
1303 < $(srcdir)/stdint.in.h; \ 1733 -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
1304 } > $@-t && \ 1734 $(srcdir)/stdint.in.h > $@-t
1305 mv $@-t $@ 1735 $(AM_V_at)mv $@-t $@
1306else 1736else
1307stdint.h: $(top_builddir)/config.status 1737stdint.h: $(top_builddir)/config.status
1308 rm -f $@ 1738 rm -f $@
@@ -1320,68 +1750,75 @@ BUILT_SOURCES += stdio.h
1320# We need the following in order to create <stdio.h> when the system 1750# We need the following in order to create <stdio.h> when the system
1321# doesn't have one that works with the given compiler. 1751# doesn't have one that works with the given compiler.
1322stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 1752stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1323 $(AM_V_GEN)rm -f $@-t $@ && \ 1753 $(gl_V_at)$(SED_HEADER_STDOUT) \
1324 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1754 -e 's|@''GUARD_PREFIX''@|GL|g' \
1325 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1326 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1755 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1327 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1756 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1328 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1757 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1329 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \ 1758 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
1330 -e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \ 1759 -e 's/@''GNULIB_DPRINTF''@/$(GL_GNULIB_DPRINTF)/g' \
1331 -e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \ 1760 -e 's/@''GNULIB_FCLOSE''@/$(GL_GNULIB_FCLOSE)/g' \
1332 -e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \ 1761 -e 's/@''GNULIB_FDOPEN''@/$(GL_GNULIB_FDOPEN)/g' \
1333 -e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \ 1762 -e 's/@''GNULIB_FFLUSH''@/$(GL_GNULIB_FFLUSH)/g' \
1334 -e 's/@''GNULIB_FGETC''@/$(GNULIB_FGETC)/g' \ 1763 -e 's/@''GNULIB_FGETC''@/$(GL_GNULIB_FGETC)/g' \
1335 -e 's/@''GNULIB_FGETS''@/$(GNULIB_FGETS)/g' \ 1764 -e 's/@''GNULIB_FGETS''@/$(GL_GNULIB_FGETS)/g' \
1336 -e 's/@''GNULIB_FOPEN''@/$(GNULIB_FOPEN)/g' \ 1765 -e 's/@''GNULIB_FOPEN''@/$(GL_GNULIB_FOPEN)/g' \
1337 -e 's/@''GNULIB_FPRINTF''@/$(GNULIB_FPRINTF)/g' \ 1766 -e 's/@''GNULIB_FOPEN_GNU''@/$(GL_GNULIB_FOPEN_GNU)/g' \
1338 -e 's/@''GNULIB_FPRINTF_POSIX''@/$(GNULIB_FPRINTF_POSIX)/g' \ 1767 -e 's/@''GNULIB_FPRINTF''@/$(GL_GNULIB_FPRINTF)/g' \
1339 -e 's/@''GNULIB_FPURGE''@/$(GNULIB_FPURGE)/g' \ 1768 -e 's/@''GNULIB_FPRINTF_POSIX''@/$(GL_GNULIB_FPRINTF_POSIX)/g' \
1340 -e 's/@''GNULIB_FPUTC''@/$(GNULIB_FPUTC)/g' \ 1769 -e 's/@''GNULIB_FPURGE''@/$(GL_GNULIB_FPURGE)/g' \
1341 -e 's/@''GNULIB_FPUTS''@/$(GNULIB_FPUTS)/g' \ 1770 -e 's/@''GNULIB_FPUTC''@/$(GL_GNULIB_FPUTC)/g' \
1342 -e 's/@''GNULIB_FREAD''@/$(GNULIB_FREAD)/g' \ 1771 -e 's/@''GNULIB_FPUTS''@/$(GL_GNULIB_FPUTS)/g' \
1343 -e 's/@''GNULIB_FREOPEN''@/$(GNULIB_FREOPEN)/g' \ 1772 -e 's/@''GNULIB_FREAD''@/$(GL_GNULIB_FREAD)/g' \
1344 -e 's/@''GNULIB_FSCANF''@/$(GNULIB_FSCANF)/g' \ 1773 -e 's/@''GNULIB_FREOPEN''@/$(GL_GNULIB_FREOPEN)/g' \
1345 -e 's/@''GNULIB_FSEEK''@/$(GNULIB_FSEEK)/g' \ 1774 -e 's/@''GNULIB_FSCANF''@/$(GL_GNULIB_FSCANF)/g' \
1346 -e 's/@''GNULIB_FSEEKO''@/$(GNULIB_FSEEKO)/g' \ 1775 -e 's/@''GNULIB_FSEEK''@/$(GL_GNULIB_FSEEK)/g' \
1347 -e 's/@''GNULIB_FTELL''@/$(GNULIB_FTELL)/g' \ 1776 -e 's/@''GNULIB_FSEEKO''@/$(GL_GNULIB_FSEEKO)/g' \
1348 -e 's/@''GNULIB_FTELLO''@/$(GNULIB_FTELLO)/g' \ 1777 -e 's/@''GNULIB_FTELL''@/$(GL_GNULIB_FTELL)/g' \
1349 -e 's/@''GNULIB_FWRITE''@/$(GNULIB_FWRITE)/g' \ 1778 -e 's/@''GNULIB_FTELLO''@/$(GL_GNULIB_FTELLO)/g' \
1350 -e 's/@''GNULIB_GETC''@/$(GNULIB_GETC)/g' \ 1779 -e 's/@''GNULIB_FWRITE''@/$(GL_GNULIB_FWRITE)/g' \
1351 -e 's/@''GNULIB_GETCHAR''@/$(GNULIB_GETCHAR)/g' \ 1780 -e 's/@''GNULIB_GETC''@/$(GL_GNULIB_GETC)/g' \
1352 -e 's/@''GNULIB_GETDELIM''@/$(GNULIB_GETDELIM)/g' \ 1781 -e 's/@''GNULIB_GETCHAR''@/$(GL_GNULIB_GETCHAR)/g' \
1353 -e 's/@''GNULIB_GETLINE''@/$(GNULIB_GETLINE)/g' \ 1782 -e 's/@''GNULIB_GETDELIM''@/$(GL_GNULIB_GETDELIM)/g' \
1354 -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \ 1783 -e 's/@''GNULIB_GETLINE''@/$(GL_GNULIB_GETLINE)/g' \
1355 -e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \ 1784 -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GL_GNULIB_OBSTACK_PRINTF)/g' \
1356 -e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \ 1785 -e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GL_GNULIB_OBSTACK_PRINTF_POSIX)/g' \
1357 -e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \ 1786 -e 's/@''GNULIB_PCLOSE''@/$(GL_GNULIB_PCLOSE)/g' \
1358 -e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \ 1787 -e 's/@''GNULIB_PERROR''@/$(GL_GNULIB_PERROR)/g' \
1359 -e 's/@''GNULIB_PRINTF''@/$(GNULIB_PRINTF)/g' \ 1788 -e 's/@''GNULIB_POPEN''@/$(GL_GNULIB_POPEN)/g' \
1360 -e 's/@''GNULIB_PRINTF_POSIX''@/$(GNULIB_PRINTF_POSIX)/g' \ 1789 -e 's/@''GNULIB_PRINTF''@/$(GL_GNULIB_PRINTF)/g' \
1361 -e 's/@''GNULIB_PUTC''@/$(GNULIB_PUTC)/g' \ 1790 -e 's/@''GNULIB_PRINTF_POSIX''@/$(GL_GNULIB_PRINTF_POSIX)/g' \
1362 -e 's/@''GNULIB_PUTCHAR''@/$(GNULIB_PUTCHAR)/g' \ 1791 -e 's/@''GNULIB_PUTC''@/$(GL_GNULIB_PUTC)/g' \
1363 -e 's/@''GNULIB_PUTS''@/$(GNULIB_PUTS)/g' \ 1792 -e 's/@''GNULIB_PUTCHAR''@/$(GL_GNULIB_PUTCHAR)/g' \
1364 -e 's/@''GNULIB_REMOVE''@/$(GNULIB_REMOVE)/g' \ 1793 -e 's/@''GNULIB_PUTS''@/$(GL_GNULIB_PUTS)/g' \
1365 -e 's/@''GNULIB_RENAME''@/$(GNULIB_RENAME)/g' \ 1794 -e 's/@''GNULIB_REMOVE''@/$(GL_GNULIB_REMOVE)/g' \
1366 -e 's/@''GNULIB_RENAMEAT''@/$(GNULIB_RENAMEAT)/g' \ 1795 -e 's/@''GNULIB_RENAME''@/$(GL_GNULIB_RENAME)/g' \
1367 -e 's/@''GNULIB_SCANF''@/$(GNULIB_SCANF)/g' \ 1796 -e 's/@''GNULIB_RENAMEAT''@/$(GL_GNULIB_RENAMEAT)/g' \
1368 -e 's/@''GNULIB_SNPRINTF''@/$(GNULIB_SNPRINTF)/g' \ 1797 -e 's/@''GNULIB_SCANF''@/$(GL_GNULIB_SCANF)/g' \
1369 -e 's/@''GNULIB_SPRINTF_POSIX''@/$(GNULIB_SPRINTF_POSIX)/g' \ 1798 -e 's/@''GNULIB_SNPRINTF''@/$(GL_GNULIB_SNPRINTF)/g' \
1370 -e 's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GNULIB_STDIO_H_NONBLOCKING)/g' \ 1799 -e 's/@''GNULIB_SPRINTF_POSIX''@/$(GL_GNULIB_SPRINTF_POSIX)/g' \
1371 -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GNULIB_STDIO_H_SIGPIPE)/g' \ 1800 -e 's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GL_GNULIB_STDIO_H_NONBLOCKING)/g' \
1372 -e 's/@''GNULIB_TMPFILE''@/$(GNULIB_TMPFILE)/g' \ 1801 -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GL_GNULIB_STDIO_H_SIGPIPE)/g' \
1373 -e 's/@''GNULIB_VASPRINTF''@/$(GNULIB_VASPRINTF)/g' \ 1802 -e 's/@''GNULIB_TMPFILE''@/$(GL_GNULIB_TMPFILE)/g' \
1374 -e 's/@''GNULIB_VDPRINTF''@/$(GNULIB_VDPRINTF)/g' \ 1803 -e 's/@''GNULIB_VASPRINTF''@/$(GL_GNULIB_VASPRINTF)/g' \
1375 -e 's/@''GNULIB_VFPRINTF''@/$(GNULIB_VFPRINTF)/g' \ 1804 -e 's/@''GNULIB_VDPRINTF''@/$(GL_GNULIB_VDPRINTF)/g' \
1376 -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GNULIB_VFPRINTF_POSIX)/g' \ 1805 -e 's/@''GNULIB_VFPRINTF''@/$(GL_GNULIB_VFPRINTF)/g' \
1377 -e 's/@''GNULIB_VFSCANF''@/$(GNULIB_VFSCANF)/g' \ 1806 -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GL_GNULIB_VFPRINTF_POSIX)/g' \
1378 -e 's/@''GNULIB_VSCANF''@/$(GNULIB_VSCANF)/g' \ 1807 -e 's/@''GNULIB_VFSCANF''@/$(GL_GNULIB_VFSCANF)/g' \
1379 -e 's/@''GNULIB_VPRINTF''@/$(GNULIB_VPRINTF)/g' \ 1808 -e 's/@''GNULIB_VSCANF''@/$(GL_GNULIB_VSCANF)/g' \
1380 -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GNULIB_VPRINTF_POSIX)/g' \ 1809 -e 's/@''GNULIB_VPRINTF''@/$(GL_GNULIB_VPRINTF)/g' \
1381 -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \ 1810 -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GL_GNULIB_VPRINTF_POSIX)/g' \
1382 -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \ 1811 -e 's/@''GNULIB_VSNPRINTF''@/$(GL_GNULIB_VSNPRINTF)/g' \
1812 -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GL_GNULIB_VSPRINTF_POSIX)/g' \
1813 -e 's/@''GNULIB_MDA_FCLOSEALL''@/$(GL_GNULIB_MDA_FCLOSEALL)/g' \
1814 -e 's/@''GNULIB_MDA_FDOPEN''@/$(GL_GNULIB_MDA_FDOPEN)/g' \
1815 -e 's/@''GNULIB_MDA_FILENO''@/$(GL_GNULIB_MDA_FILENO)/g' \
1816 -e 's/@''GNULIB_MDA_GETW''@/$(GL_GNULIB_MDA_GETW)/g' \
1817 -e 's/@''GNULIB_MDA_PUTW''@/$(GL_GNULIB_MDA_PUTW)/g' \
1818 -e 's/@''GNULIB_MDA_TEMPNAM''@/$(GL_GNULIB_MDA_TEMPNAM)/g' \
1383 < $(srcdir)/stdio.in.h | \ 1819 < $(srcdir)/stdio.in.h | \
1384 sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \ 1820 sed -e 's|@''HAVE_DECL_FCLOSEALL''@|$(HAVE_DECL_FCLOSEALL)|g' \
1821 -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
1385 -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \ 1822 -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \
1386 -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \ 1823 -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \
1387 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ 1824 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
@@ -1402,6 +1839,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
1402 -e 's|@''REPLACE_FDOPEN''@|$(REPLACE_FDOPEN)|g' \ 1839 -e 's|@''REPLACE_FDOPEN''@|$(REPLACE_FDOPEN)|g' \
1403 -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \ 1840 -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
1404 -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \ 1841 -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
1842 -e 's|@''REPLACE_FOPEN_FOR_FOPEN_GNU''@|$(REPLACE_FOPEN_FOR_FOPEN_GNU)|g' \
1405 -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ 1843 -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
1406 -e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \ 1844 -e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \
1407 -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \ 1845 -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \
@@ -1432,11 +1870,18 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
1432 -e 's|@''ASM_SYMBOL_PREFIX''@|$(ASM_SYMBOL_PREFIX)|g' \ 1870 -e 's|@''ASM_SYMBOL_PREFIX''@|$(ASM_SYMBOL_PREFIX)|g' \
1433 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 1871 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1434 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 1872 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1435 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 1873 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1436 } > $@-t && \ 1874 > $@-t
1437 mv $@-t $@ 1875 $(AM_V_at)mv $@-t $@
1438MOSTLYCLEANFILES += stdio.h stdio.h-t 1876MOSTLYCLEANFILES += stdio.h stdio.h-t
1439 1877
1878if GL_COND_OBJ_STDIO_READ
1879libgnu_a_SOURCES += stdio-read.c
1880endif
1881if GL_COND_OBJ_STDIO_WRITE
1882libgnu_a_SOURCES += stdio-write.c
1883endif
1884
1440EXTRA_DIST += stdio.in.h 1885EXTRA_DIST += stdio.in.h
1441 1886
1442## end gnulib module stdio 1887## end gnulib module stdio
@@ -1449,95 +1894,141 @@ BUILT_SOURCES += stdlib.h
1449# doesn't have one that works with the given compiler. 1894# doesn't have one that works with the given compiler.
1450stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ 1895stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
1451 $(_NORETURN_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 1896 $(_NORETURN_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1452 $(AM_V_GEN)rm -f $@-t $@ && \ 1897 $(gl_V_at)$(SED_HEADER_STDOUT) \
1453 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 1898 -e 's|@''GUARD_PREFIX''@|GL|g' \
1454 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1455 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 1899 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1456 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1900 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1457 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1901 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1458 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ 1902 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
1459 -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \ 1903 -e 's/@''GNULIB__EXIT''@/$(GL_GNULIB__EXIT)/g' \
1460 -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \ 1904 -e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GL_GNULIB_ALIGNED_ALLOC)/g' \
1461 -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \ 1905 -e 's/@''GNULIB_ATOLL''@/$(GL_GNULIB_ATOLL)/g' \
1462 -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \ 1906 -e 's/@''GNULIB_CALLOC_GNU''@/$(GL_GNULIB_CALLOC_GNU)/g' \
1463 -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \ 1907 -e 's/@''GNULIB_CALLOC_POSIX''@/$(GL_GNULIB_CALLOC_POSIX)/g' \
1464 -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \ 1908 -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GL_GNULIB_CANONICALIZE_FILE_NAME)/g' \
1465 -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \ 1909 -e 's/@''GNULIB_FREE_POSIX''@/$(GL_GNULIB_FREE_POSIX)/g' \
1466 -e 's/@''GNULIB_MALLOC_POSIX''@/$(GNULIB_MALLOC_POSIX)/g' \ 1910 -e 's/@''GNULIB_GETLOADAVG''@/$(GL_GNULIB_GETLOADAVG)/g' \
1467 -e 's/@''GNULIB_MBTOWC''@/$(GNULIB_MBTOWC)/g' \ 1911 -e 's/@''GNULIB_GETSUBOPT''@/$(GL_GNULIB_GETSUBOPT)/g' \
1468 -e 's/@''GNULIB_MKDTEMP''@/$(GNULIB_MKDTEMP)/g' \ 1912 -e 's/@''GNULIB_GRANTPT''@/$(GL_GNULIB_GRANTPT)/g' \
1469 -e 's/@''GNULIB_MKOSTEMP''@/$(GNULIB_MKOSTEMP)/g' \ 1913 -e 's/@''GNULIB_MALLOC_GNU''@/$(GL_GNULIB_MALLOC_GNU)/g' \
1470 -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \ 1914 -e 's/@''GNULIB_MALLOC_POSIX''@/$(GL_GNULIB_MALLOC_POSIX)/g' \
1471 -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \ 1915 -e 's/@''GNULIB_MBTOWC''@/$(GL_GNULIB_MBTOWC)/g' \
1472 -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \ 1916 -e 's/@''GNULIB_MKDTEMP''@/$(GL_GNULIB_MKDTEMP)/g' \
1473 -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \ 1917 -e 's/@''GNULIB_MKOSTEMP''@/$(GL_GNULIB_MKOSTEMP)/g' \
1474 -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \ 1918 -e 's/@''GNULIB_MKOSTEMPS''@/$(GL_GNULIB_MKOSTEMPS)/g' \
1475 -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \ 1919 -e 's/@''GNULIB_MKSTEMP''@/$(GL_GNULIB_MKSTEMP)/g' \
1476 -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \ 1920 -e 's/@''GNULIB_MKSTEMPS''@/$(GL_GNULIB_MKSTEMPS)/g' \
1477 -e 's/@''GNULIB_RANDOM''@/$(GNULIB_RANDOM)/g' \ 1921 -e 's/@''GNULIB_POSIX_MEMALIGN''@/$(GL_GNULIB_POSIX_MEMALIGN)/g' \
1478 -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \ 1922 -e 's/@''GNULIB_POSIX_OPENPT''@/$(GL_GNULIB_POSIX_OPENPT)/g' \
1479 -e 's/@''GNULIB_REALLOC_POSIX''@/$(GNULIB_REALLOC_POSIX)/g' \ 1923 -e 's/@''GNULIB_PTSNAME''@/$(GL_GNULIB_PTSNAME)/g' \
1480 -e 's/@''GNULIB_REALPATH''@/$(GNULIB_REALPATH)/g' \ 1924 -e 's/@''GNULIB_PTSNAME_R''@/$(GL_GNULIB_PTSNAME_R)/g' \
1481 -e 's/@''GNULIB_RPMATCH''@/$(GNULIB_RPMATCH)/g' \ 1925 -e 's/@''GNULIB_PUTENV''@/$(GL_GNULIB_PUTENV)/g' \
1482 -e 's/@''GNULIB_SECURE_GETENV''@/$(GNULIB_SECURE_GETENV)/g' \ 1926 -e 's/@''GNULIB_QSORT_R''@/$(GL_GNULIB_QSORT_R)/g' \
1483 -e 's/@''GNULIB_SETENV''@/$(GNULIB_SETENV)/g' \ 1927 -e 's/@''GNULIB_RANDOM''@/$(GL_GNULIB_RANDOM)/g' \
1484 -e 's/@''GNULIB_STRTOD''@/$(GNULIB_STRTOD)/g' \ 1928 -e 's/@''GNULIB_RANDOM_R''@/$(GL_GNULIB_RANDOM_R)/g' \
1485 -e 's/@''GNULIB_STRTOLL''@/$(GNULIB_STRTOLL)/g' \ 1929 -e 's/@''GNULIB_REALLOC_GNU''@/$(GL_GNULIB_REALLOC_GNU)/g' \
1486 -e 's/@''GNULIB_STRTOULL''@/$(GNULIB_STRTOULL)/g' \ 1930 -e 's/@''GNULIB_REALLOC_POSIX''@/$(GL_GNULIB_REALLOC_POSIX)/g' \
1487 -e 's/@''GNULIB_SYSTEM_POSIX''@/$(GNULIB_SYSTEM_POSIX)/g' \ 1931 -e 's/@''GNULIB_REALLOCARRAY''@/$(GL_GNULIB_REALLOCARRAY)/g' \
1488 -e 's/@''GNULIB_UNLOCKPT''@/$(GNULIB_UNLOCKPT)/g' \ 1932 -e 's/@''GNULIB_REALPATH''@/$(GL_GNULIB_REALPATH)/g' \
1489 -e 's/@''GNULIB_UNSETENV''@/$(GNULIB_UNSETENV)/g' \ 1933 -e 's/@''GNULIB_RPMATCH''@/$(GL_GNULIB_RPMATCH)/g' \
1490 -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \ 1934 -e 's/@''GNULIB_SECURE_GETENV''@/$(GL_GNULIB_SECURE_GETENV)/g' \
1935 -e 's/@''GNULIB_SETENV''@/$(GL_GNULIB_SETENV)/g' \
1936 -e 's/@''GNULIB_STRTOD''@/$(GL_GNULIB_STRTOD)/g' \
1937 -e 's/@''GNULIB_STRTOL''@/$(GL_GNULIB_STRTOL)/g' \
1938 -e 's/@''GNULIB_STRTOLD''@/$(GL_GNULIB_STRTOLD)/g' \
1939 -e 's/@''GNULIB_STRTOLL''@/$(GL_GNULIB_STRTOLL)/g' \
1940 -e 's/@''GNULIB_STRTOUL''@/$(GL_GNULIB_STRTOUL)/g' \
1941 -e 's/@''GNULIB_STRTOULL''@/$(GL_GNULIB_STRTOULL)/g' \
1942 -e 's/@''GNULIB_SYSTEM_POSIX''@/$(GL_GNULIB_SYSTEM_POSIX)/g' \
1943 -e 's/@''GNULIB_UNLOCKPT''@/$(GL_GNULIB_UNLOCKPT)/g' \
1944 -e 's/@''GNULIB_UNSETENV''@/$(GL_GNULIB_UNSETENV)/g' \
1945 -e 's/@''GNULIB_WCTOMB''@/$(GL_GNULIB_WCTOMB)/g' \
1946 -e 's/@''GNULIB_MDA_ECVT''@/$(GL_GNULIB_MDA_ECVT)/g' \
1947 -e 's/@''GNULIB_MDA_FCVT''@/$(GL_GNULIB_MDA_FCVT)/g' \
1948 -e 's/@''GNULIB_MDA_GCVT''@/$(GL_GNULIB_MDA_GCVT)/g' \
1949 -e 's/@''GNULIB_MDA_MKTEMP''@/$(GL_GNULIB_MDA_MKTEMP)/g' \
1950 -e 's/@''GNULIB_MDA_PUTENV''@/$(GL_GNULIB_MDA_PUTENV)/g' \
1491 < $(srcdir)/stdlib.in.h | \ 1951 < $(srcdir)/stdlib.in.h | \
1492 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ 1952 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
1953 -e 's|@''HAVE_ALIGNED_ALLOC''@|$(HAVE_ALIGNED_ALLOC)|g' \
1493 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 1954 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
1494 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ 1955 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
1956 -e 's|@''HAVE_DECL_ECVT''@|$(HAVE_DECL_ECVT)|g' \
1957 -e 's|@''HAVE_DECL_FCVT''@|$(HAVE_DECL_FCVT)|g' \
1958 -e 's|@''HAVE_DECL_GCVT''@|$(HAVE_DECL_GCVT)|g' \
1495 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ 1959 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
1496 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ 1960 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
1497 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ 1961 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
1962 -e 's|@''HAVE_INITSTATE''@|$(HAVE_INITSTATE)|g' \
1963 -e 's|@''HAVE_DECL_INITSTATE''@|$(HAVE_DECL_INITSTATE)|g' \
1964 -e 's|@''HAVE_MBTOWC''@|$(HAVE_MBTOWC)|g' \
1498 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ 1965 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
1499 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ 1966 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
1500 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ 1967 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
1501 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ 1968 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
1502 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ 1969 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
1970 -e 's|@''HAVE_POSIX_MEMALIGN''@|$(HAVE_POSIX_MEMALIGN)|g' \
1503 -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \ 1971 -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \
1504 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ 1972 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
1505 -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \ 1973 -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \
1974 -e 's|@''HAVE_QSORT_R''@|$(HAVE_QSORT_R)|g' \
1506 -e 's|@''HAVE_RANDOM''@|$(HAVE_RANDOM)|g' \ 1975 -e 's|@''HAVE_RANDOM''@|$(HAVE_RANDOM)|g' \
1507 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ 1976 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
1508 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ 1977 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
1978 -e 's|@''HAVE_REALLOCARRAY''@|$(HAVE_REALLOCARRAY)|g' \
1509 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \ 1979 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
1510 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ 1980 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
1511 -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \ 1981 -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \
1512 -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \ 1982 -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \
1983 -e 's|@''HAVE_SETSTATE''@|$(HAVE_SETSTATE)|g' \
1984 -e 's|@''HAVE_DECL_SETSTATE''@|$(HAVE_DECL_SETSTATE)|g' \
1513 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \ 1985 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
1986 -e 's|@''HAVE_STRTOL''@|$(HAVE_STRTOL)|g' \
1987 -e 's|@''HAVE_STRTOLD''@|$(HAVE_STRTOLD)|g' \
1514 -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \ 1988 -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
1989 -e 's|@''HAVE_STRTOUL''@|$(HAVE_STRTOUL)|g' \
1515 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ 1990 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
1516 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ 1991 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
1517 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ 1992 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
1518 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ 1993 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
1519 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \ 1994 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
1520 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ 1995 -e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \
1996 -e 's|@''REPLACE_CALLOC_FOR_CALLOC_GNU''@|$(REPLACE_CALLOC_FOR_CALLOC_GNU)|g' \
1997 -e 's|@''REPLACE_CALLOC_FOR_CALLOC_POSIX''@|$(REPLACE_CALLOC_FOR_CALLOC_POSIX)|g' \
1521 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ 1998 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
1522 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ 1999 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
2000 -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
2001 -e 's|@''REPLACE_MALLOC_FOR_MALLOC_GNU''@|$(REPLACE_MALLOC_FOR_MALLOC_GNU)|g' \
2002 -e 's|@''REPLACE_MALLOC_FOR_MALLOC_POSIX''@|$(REPLACE_MALLOC_FOR_MALLOC_POSIX)|g' \
1523 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ 2003 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
1524 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 2004 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
2005 -e 's|@''REPLACE_POSIX_MEMALIGN''@|$(REPLACE_POSIX_MEMALIGN)|g' \
1525 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \ 2006 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \
1526 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \ 2007 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
1527 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 2008 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
2009 -e 's|@''REPLACE_QSORT_R''@|$(REPLACE_QSORT_R)|g' \
2010 -e 's|@''REPLACE_RANDOM''@|$(REPLACE_RANDOM)|g' \
1528 -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \ 2011 -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
1529 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \ 2012 -e 's|@''REPLACE_REALLOC_FOR_REALLOC_GNU''@|$(REPLACE_REALLOC_FOR_REALLOC_GNU)|g' \
2013 -e 's|@''REPLACE_REALLOC_FOR_REALLOC_POSIX''@|$(REPLACE_REALLOC_FOR_REALLOC_POSIX)|g' \
2014 -e 's|@''REPLACE_REALLOCARRAY''@|$(REPLACE_REALLOCARRAY)|g' \
1530 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ 2015 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
1531 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ 2016 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
2017 -e 's|@''REPLACE_SETSTATE''@|$(REPLACE_SETSTATE)|g' \
1532 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ 2018 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
2019 -e 's|@''REPLACE_STRTOL''@|$(REPLACE_STRTOL)|g' \
2020 -e 's|@''REPLACE_STRTOLD''@|$(REPLACE_STRTOLD)|g' \
2021 -e 's|@''REPLACE_STRTOLL''@|$(REPLACE_STRTOLL)|g' \
2022 -e 's|@''REPLACE_STRTOUL''@|$(REPLACE_STRTOUL)|g' \
2023 -e 's|@''REPLACE_STRTOULL''@|$(REPLACE_STRTOULL)|g' \
1533 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ 2024 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
1534 -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \ 2025 -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
1535 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2026 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1536 -e '/definition of _Noreturn/r $(_NORETURN_H)' \ 2027 -e '/definition of _Noreturn/r $(_NORETURN_H)' \
1537 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2028 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1538 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 2029 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1539 } > $@-t && \ 2030 > $@-t
1540 mv $@-t $@ 2031 $(AM_V_at)mv $@-t $@
1541MOSTLYCLEANFILES += stdlib.h stdlib.h-t 2032MOSTLYCLEANFILES += stdlib.h stdlib.h-t
1542 2033
1543EXTRA_DIST += stdlib.in.h 2034EXTRA_DIST += stdlib.in.h
@@ -1546,12 +2037,23 @@ EXTRA_DIST += stdlib.in.h
1546 2037
1547## begin gnulib module strcase 2038## begin gnulib module strcase
1548 2039
2040if GL_COND_OBJ_STRCASECMP
2041libgnu_a_SOURCES += strcasecmp.c
2042endif
2043if GL_COND_OBJ_STRNCASECMP
2044libgnu_a_SOURCES += strncasecmp.c
2045endif
2046
2047## end gnulib module strcase
1549 2048
1550EXTRA_DIST += strcasecmp.c strncasecmp.c 2049## begin gnulib module strcasestr
1551 2050
1552EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c
1553 2051
1554## end gnulib module strcase 2052EXTRA_DIST += strcasestr.c
2053
2054EXTRA_libgnu_a_SOURCES += strcasestr.c
2055
2056## end gnulib module strcasestr
1555 2057
1556## begin gnulib module strcasestr-simple 2058## begin gnulib module strcasestr-simple
1557 2059
@@ -1571,19 +2073,19 @@ EXTRA_DIST += streq.h
1571 2073
1572## begin gnulib module strerror 2074## begin gnulib module strerror
1573 2075
1574 2076if GL_COND_OBJ_STRERROR
1575EXTRA_DIST += strerror.c 2077libgnu_a_SOURCES += strerror.c
1576 2078endif
1577EXTRA_libgnu_a_SOURCES += strerror.c
1578 2079
1579## end gnulib module strerror 2080## end gnulib module strerror
1580 2081
1581## begin gnulib module strerror-override 2082## begin gnulib module strerror-override
1582 2083
2084if GL_COND_OBJ_STRERROR_OVERRIDE
2085libgnu_a_SOURCES += strerror-override.c
2086endif
1583 2087
1584EXTRA_DIST += strerror-override.c strerror-override.h 2088EXTRA_DIST += strerror-override.h
1585
1586EXTRA_libgnu_a_SOURCES += strerror-override.c
1587 2089
1588## end gnulib module strerror-override 2090## end gnulib module strerror-override
1589 2091
@@ -1594,58 +2096,66 @@ BUILT_SOURCES += string.h
1594# We need the following in order to create <string.h> when the system 2096# We need the following in order to create <string.h> when the system
1595# doesn't have one that works with the given compiler. 2097# doesn't have one that works with the given compiler.
1596string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 2098string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1597 $(AM_V_GEN)rm -f $@-t $@ && \ 2099 $(gl_V_at)$(SED_HEADER_STDOUT) \
1598 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 2100 -e 's|@''GUARD_PREFIX''@|GL|g' \
1599 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1600 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2101 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1601 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2102 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1602 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2103 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1603 -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \ 2104 -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \
1604 -e 's/@''GNULIB_FFSL''@/$(GNULIB_FFSL)/g' \ 2105 -e 's/@''GNULIB_EXPLICIT_BZERO''@/$(GL_GNULIB_EXPLICIT_BZERO)/g' \
1605 -e 's/@''GNULIB_FFSLL''@/$(GNULIB_FFSLL)/g' \ 2106 -e 's/@''GNULIB_FFSL''@/$(GL_GNULIB_FFSL)/g' \
1606 -e 's/@''GNULIB_MBSLEN''@/$(GNULIB_MBSLEN)/g' \ 2107 -e 's/@''GNULIB_FFSLL''@/$(GL_GNULIB_FFSLL)/g' \
1607 -e 's/@''GNULIB_MBSNLEN''@/$(GNULIB_MBSNLEN)/g' \ 2108 -e 's/@''GNULIB_MBSLEN''@/$(GL_GNULIB_MBSLEN)/g' \
1608 -e 's/@''GNULIB_MBSCHR''@/$(GNULIB_MBSCHR)/g' \ 2109 -e 's/@''GNULIB_MBSNLEN''@/$(GL_GNULIB_MBSNLEN)/g' \
1609 -e 's/@''GNULIB_MBSRCHR''@/$(GNULIB_MBSRCHR)/g' \ 2110 -e 's/@''GNULIB_MBSCHR''@/$(GL_GNULIB_MBSCHR)/g' \
1610 -e 's/@''GNULIB_MBSSTR''@/$(GNULIB_MBSSTR)/g' \ 2111 -e 's/@''GNULIB_MBSRCHR''@/$(GL_GNULIB_MBSRCHR)/g' \
1611 -e 's/@''GNULIB_MBSCASECMP''@/$(GNULIB_MBSCASECMP)/g' \ 2112 -e 's/@''GNULIB_MBSSTR''@/$(GL_GNULIB_MBSSTR)/g' \
1612 -e 's/@''GNULIB_MBSNCASECMP''@/$(GNULIB_MBSNCASECMP)/g' \ 2113 -e 's/@''GNULIB_MBSCASECMP''@/$(GL_GNULIB_MBSCASECMP)/g' \
1613 -e 's/@''GNULIB_MBSPCASECMP''@/$(GNULIB_MBSPCASECMP)/g' \ 2114 -e 's/@''GNULIB_MBSNCASECMP''@/$(GL_GNULIB_MBSNCASECMP)/g' \
1614 -e 's/@''GNULIB_MBSCASESTR''@/$(GNULIB_MBSCASESTR)/g' \ 2115 -e 's/@''GNULIB_MBSPCASECMP''@/$(GL_GNULIB_MBSPCASECMP)/g' \
1615 -e 's/@''GNULIB_MBSCSPN''@/$(GNULIB_MBSCSPN)/g' \ 2116 -e 's/@''GNULIB_MBSCASESTR''@/$(GL_GNULIB_MBSCASESTR)/g' \
1616 -e 's/@''GNULIB_MBSPBRK''@/$(GNULIB_MBSPBRK)/g' \ 2117 -e 's/@''GNULIB_MBSCSPN''@/$(GL_GNULIB_MBSCSPN)/g' \
1617 -e 's/@''GNULIB_MBSSPN''@/$(GNULIB_MBSSPN)/g' \ 2118 -e 's/@''GNULIB_MBSPBRK''@/$(GL_GNULIB_MBSPBRK)/g' \
1618 -e 's/@''GNULIB_MBSSEP''@/$(GNULIB_MBSSEP)/g' \ 2119 -e 's/@''GNULIB_MBSSPN''@/$(GL_GNULIB_MBSSPN)/g' \
1619 -e 's/@''GNULIB_MBSTOK_R''@/$(GNULIB_MBSTOK_R)/g' \ 2120 -e 's/@''GNULIB_MBSSEP''@/$(GL_GNULIB_MBSSEP)/g' \
1620 -e 's/@''GNULIB_MEMCHR''@/$(GNULIB_MEMCHR)/g' \ 2121 -e 's/@''GNULIB_MBSTOK_R''@/$(GL_GNULIB_MBSTOK_R)/g' \
1621 -e 's/@''GNULIB_MEMMEM''@/$(GNULIB_MEMMEM)/g' \ 2122 -e 's/@''GNULIB_MEMCHR''@/$(GL_GNULIB_MEMCHR)/g' \
1622 -e 's/@''GNULIB_MEMPCPY''@/$(GNULIB_MEMPCPY)/g' \ 2123 -e 's/@''GNULIB_MEMMEM''@/$(GL_GNULIB_MEMMEM)/g' \
1623 -e 's/@''GNULIB_MEMRCHR''@/$(GNULIB_MEMRCHR)/g' \ 2124 -e 's/@''GNULIB_MEMPCPY''@/$(GL_GNULIB_MEMPCPY)/g' \
1624 -e 's/@''GNULIB_RAWMEMCHR''@/$(GNULIB_RAWMEMCHR)/g' \ 2125 -e 's/@''GNULIB_MEMRCHR''@/$(GL_GNULIB_MEMRCHR)/g' \
1625 -e 's/@''GNULIB_STPCPY''@/$(GNULIB_STPCPY)/g' \ 2126 -e 's/@''GNULIB_MEMSET_EXPLICIT''@/$(GL_GNULIB_MEMSET_EXPLICIT)/g' \
1626 -e 's/@''GNULIB_STPNCPY''@/$(GNULIB_STPNCPY)/g' \ 2127 -e 's/@''GNULIB_RAWMEMCHR''@/$(GL_GNULIB_RAWMEMCHR)/g' \
1627 -e 's/@''GNULIB_STRCHRNUL''@/$(GNULIB_STRCHRNUL)/g' \ 2128 -e 's/@''GNULIB_STPCPY''@/$(GL_GNULIB_STPCPY)/g' \
1628 -e 's/@''GNULIB_STRDUP''@/$(GNULIB_STRDUP)/g' \ 2129 -e 's/@''GNULIB_STPNCPY''@/$(GL_GNULIB_STPNCPY)/g' \
1629 -e 's/@''GNULIB_STRNCAT''@/$(GNULIB_STRNCAT)/g' \ 2130 -e 's/@''GNULIB_STRCHRNUL''@/$(GL_GNULIB_STRCHRNUL)/g' \
1630 -e 's/@''GNULIB_STRNDUP''@/$(GNULIB_STRNDUP)/g' \ 2131 -e 's/@''GNULIB_STRDUP''@/$(GL_GNULIB_STRDUP)/g' \
1631 -e 's/@''GNULIB_STRNLEN''@/$(GNULIB_STRNLEN)/g' \ 2132 -e 's/@''GNULIB_STRNCAT''@/$(GL_GNULIB_STRNCAT)/g' \
1632 -e 's/@''GNULIB_STRPBRK''@/$(GNULIB_STRPBRK)/g' \ 2133 -e 's/@''GNULIB_STRNDUP''@/$(GL_GNULIB_STRNDUP)/g' \
1633 -e 's/@''GNULIB_STRSEP''@/$(GNULIB_STRSEP)/g' \ 2134 -e 's/@''GNULIB_STRNLEN''@/$(GL_GNULIB_STRNLEN)/g' \
1634 -e 's/@''GNULIB_STRSTR''@/$(GNULIB_STRSTR)/g' \ 2135 -e 's/@''GNULIB_STRPBRK''@/$(GL_GNULIB_STRPBRK)/g' \
1635 -e 's/@''GNULIB_STRCASESTR''@/$(GNULIB_STRCASESTR)/g' \ 2136 -e 's/@''GNULIB_STRSEP''@/$(GL_GNULIB_STRSEP)/g' \
1636 -e 's/@''GNULIB_STRTOK_R''@/$(GNULIB_STRTOK_R)/g' \ 2137 -e 's/@''GNULIB_STRSTR''@/$(GL_GNULIB_STRSTR)/g' \
1637 -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \ 2138 -e 's/@''GNULIB_STRCASESTR''@/$(GL_GNULIB_STRCASESTR)/g' \
1638 -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \ 2139 -e 's/@''GNULIB_STRTOK_R''@/$(GL_GNULIB_STRTOK_R)/g' \
1639 -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \ 2140 -e 's/@''GNULIB_STRERROR''@/$(GL_GNULIB_STRERROR)/g' \
1640 -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \ 2141 -e 's/@''GNULIB_STRERROR_R''@/$(GL_GNULIB_STRERROR_R)/g' \
2142 -e 's/@''GNULIB_STRERRORNAME_NP''@/$(GL_GNULIB_STRERRORNAME_NP)/g' \
2143 -e 's/@''GNULIB_SIGABBREV_NP''@/$(GL_GNULIB_SIGABBREV_NP)/g' \
2144 -e 's/@''GNULIB_SIGDESCR_NP''@/$(GL_GNULIB_SIGDESCR_NP)/g' \
2145 -e 's/@''GNULIB_STRSIGNAL''@/$(GL_GNULIB_STRSIGNAL)/g' \
2146 -e 's/@''GNULIB_STRVERSCMP''@/$(GL_GNULIB_STRVERSCMP)/g' \
2147 -e 's/@''GNULIB_MDA_MEMCCPY''@/$(GL_GNULIB_MDA_MEMCCPY)/g' \
2148 -e 's/@''GNULIB_MDA_STRDUP''@/$(GL_GNULIB_MDA_STRDUP)/g' \
2149 -e 's/@''GNULIB_FREE_POSIX''@/$(GL_GNULIB_FREE_POSIX)/g' \
1641 < $(srcdir)/string.in.h | \ 2150 < $(srcdir)/string.in.h | \
1642 sed -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \ 2151 sed -e 's|@''HAVE_EXPLICIT_BZERO''@|$(HAVE_EXPLICIT_BZERO)|g' \
2152 -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \
1643 -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \ 2153 -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \
1644 -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \ 2154 -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \
1645 -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \
1646 -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ 2155 -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
1647 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ 2156 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
1648 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ 2157 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
2158 -e 's|@''HAVE_MEMSET_EXPLICIT''@|$(HAVE_MEMSET_EXPLICIT)|g' \
1649 -e 's|@''HAVE_RAWMEMCHR''@|$(HAVE_RAWMEMCHR)|g' \ 2159 -e 's|@''HAVE_RAWMEMCHR''@|$(HAVE_RAWMEMCHR)|g' \
1650 -e 's|@''HAVE_STPCPY''@|$(HAVE_STPCPY)|g' \ 2160 -e 's|@''HAVE_STPCPY''@|$(HAVE_STPCPY)|g' \
1651 -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ 2161 -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \
@@ -1658,29 +2168,34 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
1658 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ 2168 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \
1659 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ 2169 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
1660 -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \ 2170 -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \
2171 -e 's|@''HAVE_STRERRORNAME_NP''@|$(HAVE_STRERRORNAME_NP)|g' \
2172 -e 's|@''HAVE_SIGABBREV_NP''@|$(HAVE_SIGABBREV_NP)|g' \
2173 -e 's|@''HAVE_SIGDESCR_NP''@|$(HAVE_SIGDESCR_NP)|g' \
1661 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ 2174 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
1662 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ 2175 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
1663 -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \ 2176 -e 's|@''REPLACE_FFSLL''@|$(REPLACE_FFSLL)|g' \
1664 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ 2177 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
1665 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ 2178 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
1666 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ 2179 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
2180 -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \
1667 -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \ 2181 -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \
1668 -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ 2182 -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \
1669 -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
1670 -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
1671 -e 's|@''REPLACE_STRERROR_R''@|$(REPLACE_STRERROR_R)|g' \
1672 -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ 2183 -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \
1673 -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ 2184 -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \
1674 -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ 2185 -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \
1675 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ 2186 -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
2187 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
1676 -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ 2188 -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \
2189 -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
2190 -e 's|@''REPLACE_STRERROR_R''@|$(REPLACE_STRERROR_R)|g' \
2191 -e 's|@''REPLACE_STRERRORNAME_NP''@|$(REPLACE_STRERRORNAME_NP)|g' \
2192 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \
1677 -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ 2193 -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \
1678 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2194 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1679 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2195 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1680 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 2196 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1681 < $(srcdir)/string.in.h; \ 2197 > $@-t
1682 } > $@-t && \ 2198 $(AM_V_at)mv $@-t $@
1683 mv $@-t $@
1684MOSTLYCLEANFILES += string.h string.h-t 2199MOSTLYCLEANFILES += string.h string.h-t
1685 2200
1686EXTRA_DIST += string.in.h 2201EXTRA_DIST += string.in.h
@@ -1694,54 +2209,33 @@ BUILT_SOURCES += strings.h
1694# We need the following in order to create <strings.h> when the system 2209# We need the following in order to create <strings.h> when the system
1695# doesn't have one that works with the given compiler. 2210# doesn't have one that works with the given compiler.
1696strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) 2211strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
1697 $(AM_V_GEN)rm -f $@-t $@ && \ 2212 $(gl_V_at)$(SED_HEADER_STDOUT) \
1698 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 2213 -e 's|@''GUARD_PREFIX''@|GL|g' \
1699 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1700 -e 's|@''HAVE_STRINGS_H''@|$(HAVE_STRINGS_H)|g' \ 2214 -e 's|@''HAVE_STRINGS_H''@|$(HAVE_STRINGS_H)|g' \
1701 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2215 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1702 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2216 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1703 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2217 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1704 -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \ 2218 -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \
1705 -e 's|@''GNULIB_FFS''@|$(GNULIB_FFS)|g' \ 2219 -e 's/@''GNULIB_FFS''@/$(GL_GNULIB_FFS)/g' \
1706 -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \ 2220 -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \
1707 -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ 2221 -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \
1708 -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ 2222 -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \
1709 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2223 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1710 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2224 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1711 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 2225 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1712 < $(srcdir)/strings.in.h; \ 2226 $(srcdir)/strings.in.h > $@-t
1713 } > $@-t && \ 2227 $(AM_V_at)mv $@-t $@
1714 mv $@-t $@
1715MOSTLYCLEANFILES += strings.h strings.h-t 2228MOSTLYCLEANFILES += strings.h strings.h-t
1716 2229
1717EXTRA_DIST += strings.in.h 2230EXTRA_DIST += strings.in.h
1718 2231
1719## end gnulib module strings 2232## end gnulib module strings
1720 2233
1721## begin gnulib module strndup
1722
1723
1724EXTRA_DIST += strndup.c
1725
1726EXTRA_libgnu_a_SOURCES += strndup.c
1727
1728## end gnulib module strndup
1729
1730## begin gnulib module strnlen
1731
1732
1733EXTRA_DIST += strnlen.c
1734
1735EXTRA_libgnu_a_SOURCES += strnlen.c
1736
1737## end gnulib module strnlen
1738
1739## begin gnulib module strsep 2234## begin gnulib module strsep
1740 2235
1741 2236if GL_COND_OBJ_STRSEP
1742EXTRA_DIST += strsep.c 2237libgnu_a_SOURCES += strsep.c
1743 2238endif
1744EXTRA_libgnu_a_SOURCES += strsep.c
1745 2239
1746## end gnulib module strsep 2240## end gnulib module strsep
1747 2241
@@ -1762,31 +2256,30 @@ libgnu_a_SOURCES += sys_socket.c
1762# We need the following in order to create <sys/socket.h> when the system 2256# We need the following in order to create <sys/socket.h> when the system
1763# doesn't have one that works with the given compiler. 2257# doesn't have one that works with the given compiler.
1764sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) 2258sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
1765 $(AM_V_at)$(MKDIR_P) sys 2259 $(AM_V_GEN)$(MKDIR_P) '%reldir%/sys'
1766 $(AM_V_GEN)rm -f $@-t $@ && \ 2260 $(AM_V_at)$(SED_HEADER_STDOUT) \
1767 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 2261 -e 's|@''GUARD_PREFIX''@|GL|g' \
1768 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1769 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2262 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1770 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2263 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1771 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2264 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1772 -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \ 2265 -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \
1773 -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \ 2266 -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
1774 -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \ 2267 -e 's/@''GNULIB_CLOSE''@/$(GL_GNULIB_CLOSE)/g' \
1775 -e 's/@''GNULIB_SOCKET''@/$(GNULIB_SOCKET)/g' \ 2268 -e 's/@''GNULIB_SOCKET''@/$(GL_GNULIB_SOCKET)/g' \
1776 -e 's/@''GNULIB_CONNECT''@/$(GNULIB_CONNECT)/g' \ 2269 -e 's/@''GNULIB_CONNECT''@/$(GL_GNULIB_CONNECT)/g' \
1777 -e 's/@''GNULIB_ACCEPT''@/$(GNULIB_ACCEPT)/g' \ 2270 -e 's/@''GNULIB_ACCEPT''@/$(GL_GNULIB_ACCEPT)/g' \
1778 -e 's/@''GNULIB_BIND''@/$(GNULIB_BIND)/g' \ 2271 -e 's/@''GNULIB_BIND''@/$(GL_GNULIB_BIND)/g' \
1779 -e 's/@''GNULIB_GETPEERNAME''@/$(GNULIB_GETPEERNAME)/g' \ 2272 -e 's/@''GNULIB_GETPEERNAME''@/$(GL_GNULIB_GETPEERNAME)/g' \
1780 -e 's/@''GNULIB_GETSOCKNAME''@/$(GNULIB_GETSOCKNAME)/g' \ 2273 -e 's/@''GNULIB_GETSOCKNAME''@/$(GL_GNULIB_GETSOCKNAME)/g' \
1781 -e 's/@''GNULIB_GETSOCKOPT''@/$(GNULIB_GETSOCKOPT)/g' \ 2274 -e 's/@''GNULIB_GETSOCKOPT''@/$(GL_GNULIB_GETSOCKOPT)/g' \
1782 -e 's/@''GNULIB_LISTEN''@/$(GNULIB_LISTEN)/g' \ 2275 -e 's/@''GNULIB_LISTEN''@/$(GL_GNULIB_LISTEN)/g' \
1783 -e 's/@''GNULIB_RECV''@/$(GNULIB_RECV)/g' \ 2276 -e 's/@''GNULIB_RECV''@/$(GL_GNULIB_RECV)/g' \
1784 -e 's/@''GNULIB_SEND''@/$(GNULIB_SEND)/g' \ 2277 -e 's/@''GNULIB_SEND''@/$(GL_GNULIB_SEND)/g' \
1785 -e 's/@''GNULIB_RECVFROM''@/$(GNULIB_RECVFROM)/g' \ 2278 -e 's/@''GNULIB_RECVFROM''@/$(GL_GNULIB_RECVFROM)/g' \
1786 -e 's/@''GNULIB_SENDTO''@/$(GNULIB_SENDTO)/g' \ 2279 -e 's/@''GNULIB_SENDTO''@/$(GL_GNULIB_SENDTO)/g' \
1787 -e 's/@''GNULIB_SETSOCKOPT''@/$(GNULIB_SETSOCKOPT)/g' \ 2280 -e 's/@''GNULIB_SETSOCKOPT''@/$(GL_GNULIB_SETSOCKOPT)/g' \
1788 -e 's/@''GNULIB_SHUTDOWN''@/$(GNULIB_SHUTDOWN)/g' \ 2281 -e 's/@''GNULIB_SHUTDOWN''@/$(GL_GNULIB_SHUTDOWN)/g' \
1789 -e 's/@''GNULIB_ACCEPT4''@/$(GNULIB_ACCEPT4)/g' \ 2282 -e 's/@''GNULIB_ACCEPT4''@/$(GL_GNULIB_ACCEPT4)/g' \
1790 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ 2283 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
1791 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \ 2284 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
1792 -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \ 2285 -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
@@ -1796,9 +2289,8 @@ sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_
1796 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2289 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1797 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2290 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1798 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 2291 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1799 < $(srcdir)/sys_socket.in.h; \ 2292 $(srcdir)/sys_socket.in.h > $@-t
1800 } > $@-t && \ 2293 $(AM_V_at)mv $@-t $@
1801 mv -f $@-t $@
1802MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t 2294MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
1803MOSTLYCLEANDIRS += sys 2295MOSTLYCLEANDIRS += sys
1804 2296
@@ -1806,6 +2298,79 @@ EXTRA_DIST += sys_socket.in.h
1806 2298
1807## end gnulib module sys_socket 2299## end gnulib module sys_socket
1808 2300
2301## begin gnulib module sys_stat
2302
2303BUILT_SOURCES += sys/stat.h
2304
2305# We need the following in order to create <sys/stat.h> when the system
2306# has one that is incomplete.
2307sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
2308 $(AM_V_GEN)$(MKDIR_P) '%reldir%/sys'
2309 $(AM_V_at)$(SED_HEADER_STDOUT) \
2310 -e 's|@''GUARD_PREFIX''@|GL|g' \
2311 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
2312 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2313 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2314 -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
2315 -e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \
2316 -e 's|@''WINDOWS_STAT_TIMESPEC''@|$(WINDOWS_STAT_TIMESPEC)|g' \
2317 -e 's/@''GNULIB_CHMOD''@/$(GL_GNULIB_CHMOD)/g' \
2318 -e 's/@''GNULIB_FCHMODAT''@/$(GL_GNULIB_FCHMODAT)/g' \
2319 -e 's/@''GNULIB_FSTAT''@/$(GL_GNULIB_FSTAT)/g' \
2320 -e 's/@''GNULIB_FSTATAT''@/$(GL_GNULIB_FSTATAT)/g' \
2321 -e 's/@''GNULIB_FUTIMENS''@/$(GL_GNULIB_FUTIMENS)/g' \
2322 -e 's/@''GNULIB_GETUMASK''@/$(GL_GNULIB_GETUMASK)/g' \
2323 -e 's/@''GNULIB_LCHMOD''@/$(GL_GNULIB_LCHMOD)/g' \
2324 -e 's/@''GNULIB_LSTAT''@/$(GL_GNULIB_LSTAT)/g' \
2325 -e 's/@''GNULIB_MKDIR''@/$(GL_GNULIB_MKDIR)/g' \
2326 -e 's/@''GNULIB_MKDIRAT''@/$(GL_GNULIB_MKDIRAT)/g' \
2327 -e 's/@''GNULIB_MKFIFO''@/$(GL_GNULIB_MKFIFO)/g' \
2328 -e 's/@''GNULIB_MKFIFOAT''@/$(GL_GNULIB_MKFIFOAT)/g' \
2329 -e 's/@''GNULIB_MKNOD''@/$(GL_GNULIB_MKNOD)/g' \
2330 -e 's/@''GNULIB_MKNODAT''@/$(GL_GNULIB_MKNODAT)/g' \
2331 -e 's/@''GNULIB_STAT''@/$(GL_GNULIB_STAT)/g' \
2332 -e 's/@''GNULIB_UTIMENSAT''@/$(GL_GNULIB_UTIMENSAT)/g' \
2333 -e 's/@''GNULIB_OVERRIDES_STRUCT_STAT''@/$(GL_GNULIB_OVERRIDES_STRUCT_STAT)/g' \
2334 -e 's/@''GNULIB_MDA_CHMOD''@/$(GL_GNULIB_MDA_CHMOD)/g' \
2335 -e 's/@''GNULIB_MDA_MKDIR''@/$(GL_GNULIB_MDA_MKDIR)/g' \
2336 -e 's/@''GNULIB_MDA_UMASK''@/$(GL_GNULIB_MDA_UMASK)/g' \
2337 -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
2338 -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
2339 -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
2340 -e 's|@''HAVE_GETUMASK''@|$(HAVE_GETUMASK)|g' \
2341 -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
2342 -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
2343 -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \
2344 -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \
2345 -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \
2346 -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \
2347 -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \
2348 -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \
2349 -e 's|@''REPLACE_CHMOD''@|$(REPLACE_CHMOD)|g' \
2350 -e 's|@''REPLACE_FCHMODAT''@|$(REPLACE_FCHMODAT)|g' \
2351 -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \
2352 -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \
2353 -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \
2354 -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
2355 -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
2356 -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \
2357 -e 's|@''REPLACE_MKFIFOAT''@|$(REPLACE_MKFIFOAT)|g' \
2358 -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \
2359 -e 's|@''REPLACE_MKNODAT''@|$(REPLACE_MKNODAT)|g' \
2360 -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
2361 -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \
2362 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2363 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
2364 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2365 $(srcdir)/sys_stat.in.h > $@-t
2366 $(AM_V_at)mv $@-t $@
2367MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
2368MOSTLYCLEANDIRS += sys
2369
2370EXTRA_DIST += sys_stat.in.h
2371
2372## end gnulib module sys_stat
2373
1809## begin gnulib module sys_types 2374## begin gnulib module sys_types
1810 2375
1811BUILT_SOURCES += sys/types.h 2376BUILT_SOURCES += sys/types.h
@@ -1813,18 +2378,17 @@ BUILT_SOURCES += sys/types.h
1813# We need the following in order to create <sys/types.h> when the system 2378# We need the following in order to create <sys/types.h> when the system
1814# doesn't have one that works with the given compiler. 2379# doesn't have one that works with the given compiler.
1815sys/types.h: sys_types.in.h $(top_builddir)/config.status 2380sys/types.h: sys_types.in.h $(top_builddir)/config.status
1816 $(AM_V_at)$(MKDIR_P) sys 2381 $(AM_V_GEN)$(MKDIR_P) '%reldir%/sys'
1817 $(AM_V_GEN)rm -f $@-t $@ && \ 2382 $(AM_V_at)$(SED_HEADER_STDOUT) \
1818 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 2383 -e 's|@''GUARD_PREFIX''@|GL|g' \
1819 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1820 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2384 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1821 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2385 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1822 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2386 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1823 -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \ 2387 -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \
1824 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \ 2388 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
1825 < $(srcdir)/sys_types.in.h; \ 2389 -e 's|@''WINDOWS_STAT_INODES''@|$(WINDOWS_STAT_INODES)|g' \
1826 } > $@-t && \ 2390 $(srcdir)/sys_types.in.h > $@-t
1827 mv $@-t $@ 2391 $(AM_V_at)mv $@-t $@
1828MOSTLYCLEANFILES += sys/types.h sys/types.h-t 2392MOSTLYCLEANFILES += sys/types.h sys/types.h-t
1829 2393
1830EXTRA_DIST += sys_types.in.h 2394EXTRA_DIST += sys_types.in.h
@@ -1838,18 +2402,16 @@ BUILT_SOURCES += sys/uio.h
1838# We need the following in order to create <sys/uio.h> when the system 2402# We need the following in order to create <sys/uio.h> when the system
1839# doesn't have one that works with the given compiler. 2403# doesn't have one that works with the given compiler.
1840sys/uio.h: sys_uio.in.h $(top_builddir)/config.status 2404sys/uio.h: sys_uio.in.h $(top_builddir)/config.status
1841 $(AM_V_at)$(MKDIR_P) sys 2405 $(AM_V_GEN)$(MKDIR_P) '%reldir%/sys'
1842 $(AM_V_GEN)rm -f $@-t $@ && \ 2406 $(AM_V_at)$(SED_HEADER_STDOUT) \
1843 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 2407 -e 's|@''GUARD_PREFIX''@|GL|g' \
1844 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1845 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2408 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1846 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2409 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1847 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2410 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1848 -e 's|@''NEXT_SYS_UIO_H''@|$(NEXT_SYS_UIO_H)|g' \ 2411 -e 's|@''NEXT_SYS_UIO_H''@|$(NEXT_SYS_UIO_H)|g' \
1849 -e 's|@''HAVE_SYS_UIO_H''@|$(HAVE_SYS_UIO_H)|g' \ 2412 -e 's|@''HAVE_SYS_UIO_H''@|$(HAVE_SYS_UIO_H)|g' \
1850 < $(srcdir)/sys_uio.in.h; \ 2413 $(srcdir)/sys_uio.in.h > $@-t
1851 } > $@-t && \ 2414 $(AM_V_at)mv $@-t $@
1852 mv -f $@-t $@
1853MOSTLYCLEANFILES += sys/uio.h sys/uio.h-t 2415MOSTLYCLEANFILES += sys/uio.h sys/uio.h-t
1854MOSTLYCLEANDIRS += sys 2416MOSTLYCLEANDIRS += sys
1855 2417
@@ -1861,8 +2423,6 @@ EXTRA_DIST += sys_uio.in.h
1861 2423
1862libgnu_a_SOURCES += glthread/threadlib.c 2424libgnu_a_SOURCES += glthread/threadlib.c
1863 2425
1864EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
1865
1866## end gnulib module threadlib 2426## end gnulib module threadlib
1867 2427
1868## begin gnulib module time 2428## begin gnulib module time
@@ -1872,35 +2432,51 @@ BUILT_SOURCES += time.h
1872# We need the following in order to create <time.h> when the system 2432# We need the following in order to create <time.h> when the system
1873# doesn't have one that works with the given compiler. 2433# doesn't have one that works with the given compiler.
1874time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 2434time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1875 $(AM_V_GEN)rm -f $@-t $@ && \ 2435 $(gl_V_at)$(SED_HEADER_STDOUT) \
1876 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ 2436 -e 's|@''GUARD_PREFIX''@|GL|g' \
1877 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1878 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2437 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1879 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2438 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1880 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2439 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1881 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ 2440 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
1882 -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ 2441 -e 's/@''GNULIB_CTIME''@/$(GL_GNULIB_CTIME)/g' \
1883 -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ 2442 -e 's/@''GNULIB_LOCALTIME''@/$(GL_GNULIB_LOCALTIME)/g' \
1884 -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ 2443 -e 's/@''GNULIB_MKTIME''@/$(GL_GNULIB_MKTIME)/g' \
1885 -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ 2444 -e 's/@''GNULIB_NANOSLEEP''@/$(GL_GNULIB_NANOSLEEP)/g' \
1886 -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ 2445 -e 's/@''GNULIB_STRFTIME''@/$(GL_GNULIB_STRFTIME)/g' \
2446 -e 's/@''GNULIB_STRPTIME''@/$(GL_GNULIB_STRPTIME)/g' \
2447 -e 's/@''GNULIB_TIMEGM''@/$(GL_GNULIB_TIMEGM)/g' \
2448 -e 's/@''GNULIB_TIMESPEC_GET''@/$(GL_GNULIB_TIMESPEC_GET)/g' \
2449 -e 's/@''GNULIB_TIMESPEC_GETRES''@/$(GL_GNULIB_TIMESPEC_GETRES)/g' \
2450 -e 's/@''GNULIB_TIME_R''@/$(GL_GNULIB_TIME_R)/g' \
2451 -e 's/@''GNULIB_TIME_RZ''@/$(GL_GNULIB_TIME_RZ)/g' \
2452 -e 's/@''GNULIB_TZSET''@/$(GL_GNULIB_TZSET)/g' \
2453 -e 's/@''GNULIB_MDA_TZSET''@/$(GL_GNULIB_MDA_TZSET)/g' \
1887 -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ 2454 -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
1888 -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ 2455 -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
1889 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ 2456 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
1890 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ 2457 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
2458 -e 's|@''HAVE_TIMESPEC_GET''@|$(HAVE_TIMESPEC_GET)|g' \
2459 -e 's|@''HAVE_TIMESPEC_GETRES''@|$(HAVE_TIMESPEC_GETRES)|g' \
2460 -e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \
2461 -e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \
2462 -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
2463 -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
1891 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ 2464 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
1892 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ 2465 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
1893 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ 2466 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
2467 -e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \
1894 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ 2468 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
2469 -e 's|@''REPLACE_TZSET''@|$(REPLACE_TZSET)|g' \
1895 -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ 2470 -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \
1896 -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ 2471 -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
1897 -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ 2472 -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
2473 -e 's|@''UNISTD_H_DEFINES_STRUCT_TIMESPEC''@|$(UNISTD_H_DEFINES_STRUCT_TIMESPEC)|g' \
2474 -e 's|@''TIME_H_DEFINES_TIME_UTC''@|$(TIME_H_DEFINES_TIME_UTC)|g' \
1898 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2475 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1899 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2476 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1900 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 2477 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
1901 < $(srcdir)/time.in.h; \ 2478 $(srcdir)/time.in.h > $@-t
1902 } > $@-t && \ 2479 $(AM_V_at)mv $@-t $@
1903 mv $@-t $@
1904MOSTLYCLEANFILES += time.h time.h-t 2480MOSTLYCLEANFILES += time.h time.h-t
1905 2481
1906EXTRA_DIST += time.in.h 2482EXTRA_DIST += time.in.h
@@ -1909,19 +2485,19 @@ EXTRA_DIST += time.in.h
1909 2485
1910## begin gnulib module time_r 2486## begin gnulib module time_r
1911 2487
1912 2488if GL_COND_OBJ_TIME_R
1913EXTRA_DIST += time_r.c 2489libgnu_a_SOURCES += time_r.c
1914 2490endif
1915EXTRA_libgnu_a_SOURCES += time_r.c
1916 2491
1917## end gnulib module time_r 2492## end gnulib module time_r
1918 2493
1919## begin gnulib module timegm 2494## begin gnulib module timegm
1920 2495
2496if GL_COND_OBJ_TIMEGM
2497libgnu_a_SOURCES += timegm.c
2498endif
1921 2499
1922EXTRA_DIST += mktime-internal.h timegm.c 2500EXTRA_DIST += mktime-internal.h
1923
1924EXTRA_libgnu_a_SOURCES += timegm.c
1925 2501
1926## end gnulib module timegm 2502## end gnulib module timegm
1927 2503
@@ -1933,69 +2509,104 @@ libgnu_a_SOURCES += unistd.c
1933# We need the following in order to create an empty placeholder for 2509# We need the following in order to create an empty placeholder for
1934# <unistd.h> when the system doesn't have one. 2510# <unistd.h> when the system doesn't have one.
1935unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 2511unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
1936 $(AM_V_GEN)rm -f $@-t $@ && \ 2512 $(gl_V_at)$(SED_HEADER_STDOUT) \
1937 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 2513 -e 's|@''GUARD_PREFIX''@|GL|g' \
1938 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
1939 -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ 2514 -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
1940 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2515 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
1941 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2516 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1942 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2517 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1943 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ 2518 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
1944 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \ 2519 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
1945 -e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \ 2520 -e 's/@''GNULIB_ACCESS''@/$(GL_GNULIB_ACCESS)/g' \
1946 -e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \ 2521 -e 's/@''GNULIB_CHDIR''@/$(GL_GNULIB_CHDIR)/g' \
1947 -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \ 2522 -e 's/@''GNULIB_CHOWN''@/$(GL_GNULIB_CHOWN)/g' \
1948 -e 's/@''GNULIB_DUP''@/$(GNULIB_DUP)/g' \ 2523 -e 's/@''GNULIB_CLOSE''@/$(GL_GNULIB_CLOSE)/g' \
1949 -e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \ 2524 -e 's/@''GNULIB_COPY_FILE_RANGE''@/$(GL_GNULIB_COPY_FILE_RANGE)/g' \
1950 -e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \ 2525 -e 's/@''GNULIB_DUP''@/$(GL_GNULIB_DUP)/g' \
1951 -e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \ 2526 -e 's/@''GNULIB_DUP2''@/$(GL_GNULIB_DUP2)/g' \
1952 -e 's/@''GNULIB_EUIDACCESS''@/$(GNULIB_EUIDACCESS)/g' \ 2527 -e 's/@''GNULIB_DUP3''@/$(GL_GNULIB_DUP3)/g' \
1953 -e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \ 2528 -e 's/@''GNULIB_ENVIRON''@/$(GL_GNULIB_ENVIRON)/g' \
1954 -e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \ 2529 -e 's/@''GNULIB_EUIDACCESS''@/$(GL_GNULIB_EUIDACCESS)/g' \
1955 -e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \ 2530 -e 's/@''GNULIB_EXECL''@/$(GL_GNULIB_EXECL)/g' \
1956 -e 's/@''GNULIB_FDATASYNC''@/$(GNULIB_FDATASYNC)/g' \ 2531 -e 's/@''GNULIB_EXECLE''@/$(GL_GNULIB_EXECLE)/g' \
1957 -e 's/@''GNULIB_FSYNC''@/$(GNULIB_FSYNC)/g' \ 2532 -e 's/@''GNULIB_EXECLP''@/$(GL_GNULIB_EXECLP)/g' \
1958 -e 's/@''GNULIB_FTRUNCATE''@/$(GNULIB_FTRUNCATE)/g' \ 2533 -e 's/@''GNULIB_EXECV''@/$(GL_GNULIB_EXECV)/g' \
1959 -e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \ 2534 -e 's/@''GNULIB_EXECVE''@/$(GL_GNULIB_EXECVE)/g' \
1960 -e 's/@''GNULIB_GETDOMAINNAME''@/$(GNULIB_GETDOMAINNAME)/g' \ 2535 -e 's/@''GNULIB_EXECVP''@/$(GL_GNULIB_EXECVP)/g' \
1961 -e 's/@''GNULIB_GETDTABLESIZE''@/$(GNULIB_GETDTABLESIZE)/g' \ 2536 -e 's/@''GNULIB_EXECVPE''@/$(GL_GNULIB_EXECVPE)/g' \
1962 -e 's/@''GNULIB_GETGROUPS''@/$(GNULIB_GETGROUPS)/g' \ 2537 -e 's/@''GNULIB_FACCESSAT''@/$(GL_GNULIB_FACCESSAT)/g' \
1963 -e 's/@''GNULIB_GETHOSTNAME''@/$(GNULIB_GETHOSTNAME)/g' \ 2538 -e 's/@''GNULIB_FCHDIR''@/$(GL_GNULIB_FCHDIR)/g' \
1964 -e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \ 2539 -e 's/@''GNULIB_FCHOWNAT''@/$(GL_GNULIB_FCHOWNAT)/g' \
1965 -e 's/@''GNULIB_GETLOGIN_R''@/$(GNULIB_GETLOGIN_R)/g' \ 2540 -e 's/@''GNULIB_FDATASYNC''@/$(GL_GNULIB_FDATASYNC)/g' \
1966 -e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \ 2541 -e 's/@''GNULIB_FSYNC''@/$(GL_GNULIB_FSYNC)/g' \
1967 -e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \ 2542 -e 's/@''GNULIB_FTRUNCATE''@/$(GL_GNULIB_FTRUNCATE)/g' \
1968 -e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \ 2543 -e 's/@''GNULIB_GETCWD''@/$(GL_GNULIB_GETCWD)/g' \
1969 -e 's/@''GNULIB_ISATTY''@/$(GNULIB_ISATTY)/g' \ 2544 -e 's/@''GNULIB_GETDOMAINNAME''@/$(GL_GNULIB_GETDOMAINNAME)/g' \
1970 -e 's/@''GNULIB_LCHOWN''@/$(GNULIB_LCHOWN)/g' \ 2545 -e 's/@''GNULIB_GETDTABLESIZE''@/$(GL_GNULIB_GETDTABLESIZE)/g' \
1971 -e 's/@''GNULIB_LINK''@/$(GNULIB_LINK)/g' \ 2546 -e 's/@''GNULIB_GETENTROPY''@/$(GL_GNULIB_GETENTROPY)/g' \
1972 -e 's/@''GNULIB_LINKAT''@/$(GNULIB_LINKAT)/g' \ 2547 -e 's/@''GNULIB_GETGROUPS''@/$(GL_GNULIB_GETGROUPS)/g' \
1973 -e 's/@''GNULIB_LSEEK''@/$(GNULIB_LSEEK)/g' \ 2548 -e 's/@''GNULIB_GETHOSTNAME''@/$(GL_GNULIB_GETHOSTNAME)/g' \
1974 -e 's/@''GNULIB_PIPE''@/$(GNULIB_PIPE)/g' \ 2549 -e 's/@''GNULIB_GETLOGIN''@/$(GL_GNULIB_GETLOGIN)/g' \
1975 -e 's/@''GNULIB_PIPE2''@/$(GNULIB_PIPE2)/g' \ 2550 -e 's/@''GNULIB_GETLOGIN_R''@/$(GL_GNULIB_GETLOGIN_R)/g' \
1976 -e 's/@''GNULIB_PREAD''@/$(GNULIB_PREAD)/g' \ 2551 -e 's/@''GNULIB_GETOPT_POSIX''@/$(GL_GNULIB_GETOPT_POSIX)/g' \
1977 -e 's/@''GNULIB_PWRITE''@/$(GNULIB_PWRITE)/g' \ 2552 -e 's/@''GNULIB_GETPAGESIZE''@/$(GL_GNULIB_GETPAGESIZE)/g' \
1978 -e 's/@''GNULIB_READ''@/$(GNULIB_READ)/g' \ 2553 -e 's/@''GNULIB_GETPASS''@/$(GL_GNULIB_GETPASS)/g' \
1979 -e 's/@''GNULIB_READLINK''@/$(GNULIB_READLINK)/g' \ 2554 -e 's/@''GNULIB_GETPASS_GNU''@/$(GL_GNULIB_GETPASS_GNU)/g' \
1980 -e 's/@''GNULIB_READLINKAT''@/$(GNULIB_READLINKAT)/g' \ 2555 -e 's/@''GNULIB_GETUSERSHELL''@/$(GL_GNULIB_GETUSERSHELL)/g' \
1981 -e 's/@''GNULIB_RMDIR''@/$(GNULIB_RMDIR)/g' \ 2556 -e 's/@''GNULIB_GROUP_MEMBER''@/$(GL_GNULIB_GROUP_MEMBER)/g' \
1982 -e 's/@''GNULIB_SETHOSTNAME''@/$(GNULIB_SETHOSTNAME)/g' \ 2557 -e 's/@''GNULIB_ISATTY''@/$(GL_GNULIB_ISATTY)/g' \
1983 -e 's/@''GNULIB_SLEEP''@/$(GNULIB_SLEEP)/g' \ 2558 -e 's/@''GNULIB_LCHOWN''@/$(GL_GNULIB_LCHOWN)/g' \
1984 -e 's/@''GNULIB_SYMLINK''@/$(GNULIB_SYMLINK)/g' \ 2559 -e 's/@''GNULIB_LINK''@/$(GL_GNULIB_LINK)/g' \
1985 -e 's/@''GNULIB_SYMLINKAT''@/$(GNULIB_SYMLINKAT)/g' \ 2560 -e 's/@''GNULIB_LINKAT''@/$(GL_GNULIB_LINKAT)/g' \
1986 -e 's/@''GNULIB_TTYNAME_R''@/$(GNULIB_TTYNAME_R)/g' \ 2561 -e 's/@''GNULIB_LSEEK''@/$(GL_GNULIB_LSEEK)/g' \
1987 -e 's/@''GNULIB_UNISTD_H_GETOPT''@/0$(GNULIB_GL_UNISTD_H_GETOPT)/g' \ 2562 -e 's/@''GNULIB_PIPE''@/$(GL_GNULIB_PIPE)/g' \
1988 -e 's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GNULIB_UNISTD_H_NONBLOCKING)/g' \ 2563 -e 's/@''GNULIB_PIPE2''@/$(GL_GNULIB_PIPE2)/g' \
1989 -e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GNULIB_UNISTD_H_SIGPIPE)/g' \ 2564 -e 's/@''GNULIB_PREAD''@/$(GL_GNULIB_PREAD)/g' \
1990 -e 's/@''GNULIB_UNLINK''@/$(GNULIB_UNLINK)/g' \ 2565 -e 's/@''GNULIB_PWRITE''@/$(GL_GNULIB_PWRITE)/g' \
1991 -e 's/@''GNULIB_UNLINKAT''@/$(GNULIB_UNLINKAT)/g' \ 2566 -e 's/@''GNULIB_READ''@/$(GL_GNULIB_READ)/g' \
1992 -e 's/@''GNULIB_USLEEP''@/$(GNULIB_USLEEP)/g' \ 2567 -e 's/@''GNULIB_READLINK''@/$(GL_GNULIB_READLINK)/g' \
1993 -e 's/@''GNULIB_WRITE''@/$(GNULIB_WRITE)/g' \ 2568 -e 's/@''GNULIB_READLINKAT''@/$(GL_GNULIB_READLINKAT)/g' \
2569 -e 's/@''GNULIB_RMDIR''@/$(GL_GNULIB_RMDIR)/g' \
2570 -e 's/@''GNULIB_SETHOSTNAME''@/$(GL_GNULIB_SETHOSTNAME)/g' \
2571 -e 's/@''GNULIB_SLEEP''@/$(GL_GNULIB_SLEEP)/g' \
2572 -e 's/@''GNULIB_SYMLINK''@/$(GL_GNULIB_SYMLINK)/g' \
2573 -e 's/@''GNULIB_SYMLINKAT''@/$(GL_GNULIB_SYMLINKAT)/g' \
2574 -e 's/@''GNULIB_TRUNCATE''@/$(GL_GNULIB_TRUNCATE)/g' \
2575 -e 's/@''GNULIB_TTYNAME_R''@/$(GL_GNULIB_TTYNAME_R)/g' \
2576 -e 's/@''GNULIB_UNISTD_H_GETOPT''@/0$(GL_GNULIB_UNISTD_H_GETOPT)/g' \
2577 -e 's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GL_GNULIB_UNISTD_H_NONBLOCKING)/g' \
2578 -e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GL_GNULIB_UNISTD_H_SIGPIPE)/g' \
2579 -e 's/@''GNULIB_UNLINK''@/$(GL_GNULIB_UNLINK)/g' \
2580 -e 's/@''GNULIB_UNLINKAT''@/$(GL_GNULIB_UNLINKAT)/g' \
2581 -e 's/@''GNULIB_USLEEP''@/$(GL_GNULIB_USLEEP)/g' \
2582 -e 's/@''GNULIB_WRITE''@/$(GL_GNULIB_WRITE)/g' \
2583 -e 's/@''GNULIB_MDA_ACCESS''@/$(GL_GNULIB_MDA_ACCESS)/g' \
2584 -e 's/@''GNULIB_MDA_CHDIR''@/$(GL_GNULIB_MDA_CHDIR)/g' \
2585 -e 's/@''GNULIB_MDA_CLOSE''@/$(GL_GNULIB_MDA_CLOSE)/g' \
2586 -e 's/@''GNULIB_MDA_DUP''@/$(GL_GNULIB_MDA_DUP)/g' \
2587 -e 's/@''GNULIB_MDA_DUP2''@/$(GL_GNULIB_MDA_DUP2)/g' \
2588 -e 's/@''GNULIB_MDA_EXECL''@/$(GL_GNULIB_MDA_EXECL)/g' \
2589 -e 's/@''GNULIB_MDA_EXECLE''@/$(GL_GNULIB_MDA_EXECLE)/g' \
2590 -e 's/@''GNULIB_MDA_EXECLP''@/$(GL_GNULIB_MDA_EXECLP)/g' \
2591 -e 's/@''GNULIB_MDA_EXECV''@/$(GL_GNULIB_MDA_EXECV)/g' \
2592 -e 's/@''GNULIB_MDA_EXECVE''@/$(GL_GNULIB_MDA_EXECVE)/g' \
2593 -e 's/@''GNULIB_MDA_EXECVP''@/$(GL_GNULIB_MDA_EXECVP)/g' \
2594 -e 's/@''GNULIB_MDA_EXECVPE''@/$(GL_GNULIB_MDA_EXECVPE)/g' \
2595 -e 's/@''GNULIB_MDA_GETCWD''@/$(GL_GNULIB_MDA_GETCWD)/g' \
2596 -e 's/@''GNULIB_MDA_GETPID''@/$(GL_GNULIB_MDA_GETPID)/g' \
2597 -e 's/@''GNULIB_MDA_ISATTY''@/$(GL_GNULIB_MDA_ISATTY)/g' \
2598 -e 's/@''GNULIB_MDA_LSEEK''@/$(GL_GNULIB_MDA_LSEEK)/g' \
2599 -e 's/@''GNULIB_MDA_READ''@/$(GL_GNULIB_MDA_READ)/g' \
2600 -e 's/@''GNULIB_MDA_RMDIR''@/$(GL_GNULIB_MDA_RMDIR)/g' \
2601 -e 's/@''GNULIB_MDA_SWAB''@/$(GL_GNULIB_MDA_SWAB)/g' \
2602 -e 's/@''GNULIB_MDA_UNLINK''@/$(GL_GNULIB_MDA_UNLINK)/g' \
2603 -e 's/@''GNULIB_MDA_WRITE''@/$(GL_GNULIB_MDA_WRITE)/g' \
1994 < $(srcdir)/unistd.in.h | \ 2604 < $(srcdir)/unistd.in.h | \
1995 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \ 2605 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
1996 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ 2606 -e 's|@''HAVE_COPY_FILE_RANGE''@|$(HAVE_COPY_FILE_RANGE)|g' \
1997 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \ 2607 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
1998 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ 2608 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
2609 -e 's|@''HAVE_EXECVPE''@|$(HAVE_EXECVPE)|g' \
1999 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \ 2610 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
2000 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \ 2611 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
2001 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \ 2612 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
@@ -2003,10 +2614,11 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2003 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ 2614 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
2004 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ 2615 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
2005 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ 2616 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
2617 -e 's|@''HAVE_GETENTROPY''@|$(HAVE_GETENTROPY)|g' \
2006 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ 2618 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
2007 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ 2619 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
2008 -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
2009 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ 2620 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
2621 -e 's|@''HAVE_GETPASS''@|$(HAVE_GETPASS)|g' \
2010 -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \ 2622 -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \
2011 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ 2623 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
2012 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ 2624 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
@@ -2024,28 +2636,44 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2024 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ 2636 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
2025 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ 2637 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
2026 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ 2638 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
2639 -e 's|@''HAVE_DECL_EXECVPE''@|$(HAVE_DECL_EXECVPE)|g' \
2027 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \ 2640 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
2028 -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \ 2641 -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \
2029 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \ 2642 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \
2643 -e 's|@''HAVE_DECL_GETLOGIN''@|$(HAVE_DECL_GETLOGIN)|g' \
2030 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ 2644 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
2031 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \ 2645 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
2032 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \ 2646 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
2033 -e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \ 2647 -e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \
2648 -e 's|@''HAVE_DECL_TRUNCATE''@|$(HAVE_DECL_TRUNCATE)|g' \
2034 -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \ 2649 -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \
2035 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ 2650 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
2036 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ 2651 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
2037 | \ 2652 | \
2038 sed -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ 2653 sed -e 's|@''REPLACE_ACCESS''@|$(REPLACE_ACCESS)|g' \
2654 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
2039 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ 2655 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
2656 -e 's|@''REPLACE_COPY_FILE_RANGE''@|$(REPLACE_COPY_FILE_RANGE)|g' \
2040 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ 2657 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
2041 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ 2658 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
2659 -e 's|@''REPLACE_EXECL''@|$(REPLACE_EXECL)|g' \
2660 -e 's|@''REPLACE_EXECLE''@|$(REPLACE_EXECLE)|g' \
2661 -e 's|@''REPLACE_EXECLP''@|$(REPLACE_EXECLP)|g' \
2662 -e 's|@''REPLACE_EXECV''@|$(REPLACE_EXECV)|g' \
2663 -e 's|@''REPLACE_EXECVE''@|$(REPLACE_EXECVE)|g' \
2664 -e 's|@''REPLACE_EXECVP''@|$(REPLACE_EXECVP)|g' \
2665 -e 's|@''REPLACE_EXECVPE''@|$(REPLACE_EXECVPE)|g' \
2666 -e 's|@''REPLACE_FACCESSAT''@|$(REPLACE_FACCESSAT)|g' \
2042 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ 2667 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
2043 -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ 2668 -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \
2044 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ 2669 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
2045 -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ 2670 -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \
2671 -e 's|@''REPLACE_GETDTABLESIZE''@|$(REPLACE_GETDTABLESIZE)|g' \
2046 -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ 2672 -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
2047 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ 2673 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
2048 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ 2674 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
2675 -e 's|@''REPLACE_GETPASS''@|$(REPLACE_GETPASS)|g' \
2676 -e 's|@''REPLACE_GETPASS_FOR_GETPASS_GNU''@|$(REPLACE_GETPASS_FOR_GETPASS_GNU)|g' \
2049 -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \ 2677 -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \
2050 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ 2678 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
2051 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \ 2679 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
@@ -2055,33 +2683,43 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2055 -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \ 2683 -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
2056 -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \ 2684 -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \
2057 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ 2685 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
2686 -e 's|@''REPLACE_READLINKAT''@|$(REPLACE_READLINKAT)|g' \
2058 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ 2687 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
2059 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ 2688 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
2060 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ 2689 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
2690 -e 's|@''REPLACE_SYMLINKAT''@|$(REPLACE_SYMLINKAT)|g' \
2691 -e 's|@''REPLACE_TRUNCATE''@|$(REPLACE_TRUNCATE)|g' \
2061 -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \ 2692 -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \
2062 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ 2693 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
2063 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ 2694 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
2064 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ 2695 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
2065 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ 2696 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
2697 -e 's|@''UNISTD_H_HAVE_SYS_RANDOM_H''@|$(UNISTD_H_HAVE_SYS_RANDOM_H)|g' \
2066 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ 2698 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
2067 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ 2699 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
2068 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2700 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2069 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2701 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
2070 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 2702 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2071 } > $@-t && \ 2703 > $@-t
2072 mv $@-t $@ 2704 $(AM_V_at)mv $@-t $@
2073MOSTLYCLEANFILES += unistd.h unistd.h-t 2705MOSTLYCLEANFILES += unistd.h unistd.h-t
2074 2706
2075EXTRA_DIST += unistd.in.h 2707EXTRA_DIST += unistd.in.h
2076 2708
2077## end gnulib module unistd 2709## end gnulib module unistd
2078 2710
2079## begin gnulib module unsetenv 2711## begin gnulib module unlocked-io-internal
2080 2712
2081 2713
2082EXTRA_DIST += unsetenv.c 2714EXTRA_DIST += unlocked-io.h
2715
2716## end gnulib module unlocked-io-internal
2717
2718## begin gnulib module unsetenv
2083 2719
2084EXTRA_libgnu_a_SOURCES += unsetenv.c 2720if GL_COND_OBJ_UNSETENV
2721libgnu_a_SOURCES += unsetenv.c
2722endif
2085 2723
2086## end gnulib module unsetenv 2724## end gnulib module unsetenv
2087 2725
@@ -2126,54 +2764,59 @@ BUILT_SOURCES += wchar.h
2126# We need the following in order to create <wchar.h> when the system 2764# We need the following in order to create <wchar.h> when the system
2127# version does not work standalone. 2765# version does not work standalone.
2128wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) 2766wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
2129 $(AM_V_GEN)rm -f $@-t $@ && \ 2767 $(gl_V_at)$(SED_HEADER_STDOUT) \
2130 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 2768 -e 's|@''GUARD_PREFIX''@|GL|g' \
2131 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
2132 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2769 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
2133 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2770 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2134 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2771 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2135 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \ 2772 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
2136 -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \ 2773 -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
2137 -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \ 2774 -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
2138 -e 's/@''GNULIB_BTOWC''@/$(GNULIB_BTOWC)/g' \ 2775 -e 's/@''HAVE_CRTDEFS_H''@/$(HAVE_CRTDEFS_H)/g' \
2139 -e 's/@''GNULIB_WCTOB''@/$(GNULIB_WCTOB)/g' \ 2776 -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
2140 -e 's/@''GNULIB_MBSINIT''@/$(GNULIB_MBSINIT)/g' \ 2777 -e 's/@''GNULIB_BTOWC''@/$(GL_GNULIB_BTOWC)/g' \
2141 -e 's/@''GNULIB_MBRTOWC''@/$(GNULIB_MBRTOWC)/g' \ 2778 -e 's/@''GNULIB_WCTOB''@/$(GL_GNULIB_WCTOB)/g' \
2142 -e 's/@''GNULIB_MBRLEN''@/$(GNULIB_MBRLEN)/g' \ 2779 -e 's/@''GNULIB_MBSINIT''@/$(GL_GNULIB_MBSINIT)/g' \
2143 -e 's/@''GNULIB_MBSRTOWCS''@/$(GNULIB_MBSRTOWCS)/g' \ 2780 -e 's/@''GNULIB_MBRTOWC''@/$(GL_GNULIB_MBRTOWC)/g' \
2144 -e 's/@''GNULIB_MBSNRTOWCS''@/$(GNULIB_MBSNRTOWCS)/g' \ 2781 -e 's/@''GNULIB_MBRLEN''@/$(GL_GNULIB_MBRLEN)/g' \
2145 -e 's/@''GNULIB_WCRTOMB''@/$(GNULIB_WCRTOMB)/g' \ 2782 -e 's/@''GNULIB_MBSRTOWCS''@/$(GL_GNULIB_MBSRTOWCS)/g' \
2146 -e 's/@''GNULIB_WCSRTOMBS''@/$(GNULIB_WCSRTOMBS)/g' \ 2783 -e 's/@''GNULIB_MBSNRTOWCS''@/$(GL_GNULIB_MBSNRTOWCS)/g' \
2147 -e 's/@''GNULIB_WCSNRTOMBS''@/$(GNULIB_WCSNRTOMBS)/g' \ 2784 -e 's/@''GNULIB_WCRTOMB''@/$(GL_GNULIB_WCRTOMB)/g' \
2148 -e 's/@''GNULIB_WCWIDTH''@/$(GNULIB_WCWIDTH)/g' \ 2785 -e 's/@''GNULIB_WCSRTOMBS''@/$(GL_GNULIB_WCSRTOMBS)/g' \
2149 -e 's/@''GNULIB_WMEMCHR''@/$(GNULIB_WMEMCHR)/g' \ 2786 -e 's/@''GNULIB_WCSNRTOMBS''@/$(GL_GNULIB_WCSNRTOMBS)/g' \
2150 -e 's/@''GNULIB_WMEMCMP''@/$(GNULIB_WMEMCMP)/g' \ 2787 -e 's/@''GNULIB_WCWIDTH''@/$(GL_GNULIB_WCWIDTH)/g' \
2151 -e 's/@''GNULIB_WMEMCPY''@/$(GNULIB_WMEMCPY)/g' \ 2788 -e 's/@''GNULIB_WMEMCHR''@/$(GL_GNULIB_WMEMCHR)/g' \
2152 -e 's/@''GNULIB_WMEMMOVE''@/$(GNULIB_WMEMMOVE)/g' \ 2789 -e 's/@''GNULIB_WMEMCMP''@/$(GL_GNULIB_WMEMCMP)/g' \
2153 -e 's/@''GNULIB_WMEMSET''@/$(GNULIB_WMEMSET)/g' \ 2790 -e 's/@''GNULIB_WMEMCPY''@/$(GL_GNULIB_WMEMCPY)/g' \
2154 -e 's/@''GNULIB_WCSLEN''@/$(GNULIB_WCSLEN)/g' \ 2791 -e 's/@''GNULIB_WMEMMOVE''@/$(GL_GNULIB_WMEMMOVE)/g' \
2155 -e 's/@''GNULIB_WCSNLEN''@/$(GNULIB_WCSNLEN)/g' \ 2792 -e 's/@''GNULIB_WMEMPCPY''@/$(GL_GNULIB_WMEMPCPY)/g' \
2156 -e 's/@''GNULIB_WCSCPY''@/$(GNULIB_WCSCPY)/g' \ 2793 -e 's/@''GNULIB_WMEMSET''@/$(GL_GNULIB_WMEMSET)/g' \
2157 -e 's/@''GNULIB_WCPCPY''@/$(GNULIB_WCPCPY)/g' \ 2794 -e 's/@''GNULIB_WCSLEN''@/$(GL_GNULIB_WCSLEN)/g' \
2158 -e 's/@''GNULIB_WCSNCPY''@/$(GNULIB_WCSNCPY)/g' \ 2795 -e 's/@''GNULIB_WCSNLEN''@/$(GL_GNULIB_WCSNLEN)/g' \
2159 -e 's/@''GNULIB_WCPNCPY''@/$(GNULIB_WCPNCPY)/g' \ 2796 -e 's/@''GNULIB_WCSCPY''@/$(GL_GNULIB_WCSCPY)/g' \
2160 -e 's/@''GNULIB_WCSCAT''@/$(GNULIB_WCSCAT)/g' \ 2797 -e 's/@''GNULIB_WCPCPY''@/$(GL_GNULIB_WCPCPY)/g' \
2161 -e 's/@''GNULIB_WCSNCAT''@/$(GNULIB_WCSNCAT)/g' \ 2798 -e 's/@''GNULIB_WCSNCPY''@/$(GL_GNULIB_WCSNCPY)/g' \
2162 -e 's/@''GNULIB_WCSCMP''@/$(GNULIB_WCSCMP)/g' \ 2799 -e 's/@''GNULIB_WCPNCPY''@/$(GL_GNULIB_WCPNCPY)/g' \
2163 -e 's/@''GNULIB_WCSNCMP''@/$(GNULIB_WCSNCMP)/g' \ 2800 -e 's/@''GNULIB_WCSCAT''@/$(GL_GNULIB_WCSCAT)/g' \
2164 -e 's/@''GNULIB_WCSCASECMP''@/$(GNULIB_WCSCASECMP)/g' \ 2801 -e 's/@''GNULIB_WCSNCAT''@/$(GL_GNULIB_WCSNCAT)/g' \
2165 -e 's/@''GNULIB_WCSNCASECMP''@/$(GNULIB_WCSNCASECMP)/g' \ 2802 -e 's/@''GNULIB_WCSCMP''@/$(GL_GNULIB_WCSCMP)/g' \
2166 -e 's/@''GNULIB_WCSCOLL''@/$(GNULIB_WCSCOLL)/g' \ 2803 -e 's/@''GNULIB_WCSNCMP''@/$(GL_GNULIB_WCSNCMP)/g' \
2167 -e 's/@''GNULIB_WCSXFRM''@/$(GNULIB_WCSXFRM)/g' \ 2804 -e 's/@''GNULIB_WCSCASECMP''@/$(GL_GNULIB_WCSCASECMP)/g' \
2168 -e 's/@''GNULIB_WCSDUP''@/$(GNULIB_WCSDUP)/g' \ 2805 -e 's/@''GNULIB_WCSNCASECMP''@/$(GL_GNULIB_WCSNCASECMP)/g' \
2169 -e 's/@''GNULIB_WCSCHR''@/$(GNULIB_WCSCHR)/g' \ 2806 -e 's/@''GNULIB_WCSCOLL''@/$(GL_GNULIB_WCSCOLL)/g' \
2170 -e 's/@''GNULIB_WCSRCHR''@/$(GNULIB_WCSRCHR)/g' \ 2807 -e 's/@''GNULIB_WCSXFRM''@/$(GL_GNULIB_WCSXFRM)/g' \
2171 -e 's/@''GNULIB_WCSCSPN''@/$(GNULIB_WCSCSPN)/g' \ 2808 -e 's/@''GNULIB_WCSDUP''@/$(GL_GNULIB_WCSDUP)/g' \
2172 -e 's/@''GNULIB_WCSSPN''@/$(GNULIB_WCSSPN)/g' \ 2809 -e 's/@''GNULIB_WCSCHR''@/$(GL_GNULIB_WCSCHR)/g' \
2173 -e 's/@''GNULIB_WCSPBRK''@/$(GNULIB_WCSPBRK)/g' \ 2810 -e 's/@''GNULIB_WCSRCHR''@/$(GL_GNULIB_WCSRCHR)/g' \
2174 -e 's/@''GNULIB_WCSSTR''@/$(GNULIB_WCSSTR)/g' \ 2811 -e 's/@''GNULIB_WCSCSPN''@/$(GL_GNULIB_WCSCSPN)/g' \
2175 -e 's/@''GNULIB_WCSTOK''@/$(GNULIB_WCSTOK)/g' \ 2812 -e 's/@''GNULIB_WCSSPN''@/$(GL_GNULIB_WCSSPN)/g' \
2176 -e 's/@''GNULIB_WCSWIDTH''@/$(GNULIB_WCSWIDTH)/g' \ 2813 -e 's/@''GNULIB_WCSPBRK''@/$(GL_GNULIB_WCSPBRK)/g' \
2814 -e 's/@''GNULIB_WCSSTR''@/$(GL_GNULIB_WCSSTR)/g' \
2815 -e 's/@''GNULIB_WCSTOK''@/$(GL_GNULIB_WCSTOK)/g' \
2816 -e 's/@''GNULIB_WCSWIDTH''@/$(GL_GNULIB_WCSWIDTH)/g' \
2817 -e 's/@''GNULIB_WCSFTIME''@/$(GL_GNULIB_WCSFTIME)/g' \
2818 -e 's/@''GNULIB_MDA_WCSDUP''@/$(GL_GNULIB_MDA_WCSDUP)/g' \
2819 -e 's/@''GNULIB_FREE_POSIX''@/$(GL_GNULIB_FREE_POSIX)/g' \
2177 < $(srcdir)/wchar.in.h | \ 2820 < $(srcdir)/wchar.in.h | \
2178 sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ 2821 sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
2179 -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ 2822 -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
@@ -2189,6 +2832,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2189 -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \ 2832 -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \
2190 -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \ 2833 -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \
2191 -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \ 2834 -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \
2835 -e 's|@''HAVE_WMEMPCPY''@|$(HAVE_WMEMPCPY)|g' \
2192 -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \ 2836 -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \
2193 -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \ 2837 -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \
2194 -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \ 2838 -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \
@@ -2213,12 +2857,15 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2213 -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \ 2857 -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \
2214 -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \ 2858 -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \
2215 -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \ 2859 -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \
2860 -e 's|@''HAVE_WCSFTIME''@|$(HAVE_WCSFTIME)|g' \
2216 -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \ 2861 -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
2862 -e 's|@''HAVE_DECL_WCSDUP''@|$(HAVE_DECL_WCSDUP)|g' \
2217 -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ 2863 -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
2218 | \ 2864 | \
2219 sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \ 2865 sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \
2220 -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \ 2866 -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \
2221 -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \ 2867 -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \
2868 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
2222 -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \ 2869 -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \
2223 -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \ 2870 -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \
2224 -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \ 2871 -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \
@@ -2229,11 +2876,13 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2229 -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ 2876 -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \
2230 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ 2877 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
2231 -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \ 2878 -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
2879 -e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \
2880 -e 's|@''REPLACE_WCSTOK''@|$(REPLACE_WCSTOK)|g' \
2232 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2881 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2233 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2882 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
2234 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 2883 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2235 } > $@-t && \ 2884 > $@-t
2236 mv $@-t $@ 2885 $(AM_V_at)mv $@-t $@
2237MOSTLYCLEANFILES += wchar.h wchar.h-t 2886MOSTLYCLEANFILES += wchar.h wchar.h-t
2238 2887
2239EXTRA_DIST += wchar.in.h 2888EXTRA_DIST += wchar.in.h
@@ -2242,10 +2891,9 @@ EXTRA_DIST += wchar.in.h
2242 2891
2243## begin gnulib module wcrtomb 2892## begin gnulib module wcrtomb
2244 2893
2245 2894if GL_COND_OBJ_WCRTOMB
2246EXTRA_DIST += wcrtomb.c 2895libgnu_a_SOURCES += wcrtomb.c
2247 2896endif
2248EXTRA_libgnu_a_SOURCES += wcrtomb.c
2249 2897
2250## end gnulib module wcrtomb 2898## end gnulib module wcrtomb
2251 2899
@@ -2257,38 +2905,82 @@ libgnu_a_SOURCES += wctype-h.c
2257# We need the following in order to create <wctype.h> when the system 2905# We need the following in order to create <wctype.h> when the system
2258# doesn't have one that works with the given compiler. 2906# doesn't have one that works with the given compiler.
2259wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) 2907wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
2260 $(AM_V_GEN)rm -f $@-t $@ && \ 2908 $(gl_V_at)$(SED_HEADER_STDOUT) \
2261 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 2909 -e 's|@''GUARD_PREFIX''@|GL|g' \
2262 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
2263 -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ 2910 -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \
2264 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ 2911 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
2265 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2912 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2266 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2913 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2267 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ 2914 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
2268 -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \ 2915 -e 's/@''HAVE_CRTDEFS_H''@/$(HAVE_CRTDEFS_H)/g' \
2269 -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \ 2916 -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
2270 -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \ 2917 -e 's/@''GNULIB_ISWBLANK''@/$(GL_GNULIB_ISWBLANK)/g' \
2271 -e 's/@''GNULIB_WCTRANS''@/$(GNULIB_WCTRANS)/g' \ 2918 -e 's/@''GNULIB_ISWDIGIT''@/$(GL_GNULIB_ISWDIGIT)/g' \
2272 -e 's/@''GNULIB_TOWCTRANS''@/$(GNULIB_TOWCTRANS)/g' \ 2919 -e 's/@''GNULIB_ISWXDIGIT''@/$(GL_GNULIB_ISWXDIGIT)/g' \
2920 -e 's/@''GNULIB_WCTYPE''@/$(GL_GNULIB_WCTYPE)/g' \
2921 -e 's/@''GNULIB_ISWCTYPE''@/$(GL_GNULIB_ISWCTYPE)/g' \
2922 -e 's/@''GNULIB_WCTRANS''@/$(GL_GNULIB_WCTRANS)/g' \
2923 -e 's/@''GNULIB_TOWCTRANS''@/$(GL_GNULIB_TOWCTRANS)/g' \
2273 -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \ 2924 -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \
2274 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ 2925 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \
2275 -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \ 2926 -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \
2276 -e 's/@''HAVE_WCTRANS_T''@/$(HAVE_WCTRANS_T)/g' \ 2927 -e 's/@''HAVE_WCTRANS_T''@/$(HAVE_WCTRANS_T)/g' \
2277 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ 2928 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
2278 -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \ 2929 -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \
2930 -e 's/@''REPLACE_ISWDIGIT''@/$(REPLACE_ISWDIGIT)/g' \
2931 -e 's/@''REPLACE_ISWXDIGIT''@/$(REPLACE_ISWXDIGIT)/g' \
2279 -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ 2932 -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \
2280 -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \ 2933 -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \
2281 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2934 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2282 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 2935 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2283 < $(srcdir)/wctype.in.h; \ 2936 $(srcdir)/wctype.in.h > $@-t
2284 } > $@-t && \ 2937 $(AM_V_at)mv $@-t $@
2285 mv $@-t $@
2286MOSTLYCLEANFILES += wctype.h wctype.h-t 2938MOSTLYCLEANFILES += wctype.h wctype.h-t
2287 2939
2288EXTRA_DIST += wctype.in.h 2940EXTRA_DIST += wctype.in.h
2289 2941
2290## end gnulib module wctype-h 2942## end gnulib module wctype-h
2291 2943
2944## begin gnulib module windows-mutex
2945
2946if GL_COND_OBJ_WINDOWS_MUTEX
2947libgnu_a_SOURCES += windows-mutex.c
2948endif
2949
2950EXTRA_DIST += windows-initguard.h windows-mutex.h
2951
2952## end gnulib module windows-mutex
2953
2954## begin gnulib module windows-once
2955
2956if GL_COND_OBJ_WINDOWS_ONCE
2957libgnu_a_SOURCES += windows-once.c
2958endif
2959
2960EXTRA_DIST += windows-once.h
2961
2962## end gnulib module windows-once
2963
2964## begin gnulib module windows-recmutex
2965
2966if GL_COND_OBJ_WINDOWS_RECMUTEX
2967libgnu_a_SOURCES += windows-recmutex.c
2968endif
2969
2970EXTRA_DIST += windows-initguard.h windows-recmutex.h
2971
2972## end gnulib module windows-recmutex
2973
2974## begin gnulib module windows-rwlock
2975
2976if GL_COND_OBJ_WINDOWS_RWLOCK
2977libgnu_a_SOURCES += windows-rwlock.c
2978endif
2979
2980EXTRA_DIST += windows-initguard.h windows-rwlock.h
2981
2982## end gnulib module windows-rwlock
2983
2292## begin gnulib module xalloc 2984## begin gnulib module xalloc
2293 2985
2294libgnu_a_SOURCES += xmalloc.c 2986libgnu_a_SOURCES += xmalloc.c
@@ -2301,6 +2993,8 @@ EXTRA_DIST += xalloc.h
2301 2993
2302libgnu_a_SOURCES += xalloc-die.c 2994libgnu_a_SOURCES += xalloc-die.c
2303 2995
2996EXTRA_DIST += xalloc.h
2997
2304## end gnulib module xalloc-die 2998## end gnulib module xalloc-die
2305 2999
2306## begin gnulib module xalloc-oversized 3000## begin gnulib module xalloc-oversized
@@ -2316,12 +3010,6 @@ libgnu_a_SOURCES += xsize.h xsize.c
2316 3010
2317## end gnulib module xsize 3011## end gnulib module xsize
2318 3012
2319## begin gnulib module xstrndup
2320
2321libgnu_a_SOURCES += xstrndup.h xstrndup.c
2322
2323## end gnulib module xstrndup
2324
2325 3013
2326mostlyclean-local: mostlyclean-generic 3014mostlyclean-local: mostlyclean-generic
2327 @for dir in '' $(MOSTLYCLEANDIRS); do \ 3015 @for dir in '' $(MOSTLYCLEANDIRS); do \
@@ -2330,3 +3018,7 @@ mostlyclean-local: mostlyclean-generic
2330 fi; \ 3018 fi; \
2331 done; \ 3019 done; \
2332 : 3020 :
3021distclean-local: distclean-gnulib-libobjs
3022distclean-gnulib-libobjs:
3023 -rm -f @gl_LIBOBJDEPS@
3024maintainer-clean-local: distclean-gnulib-libobjs
diff --git a/gl/_Noreturn.h b/gl/_Noreturn.h
new file mode 100644
index 0000000..6ecea98
--- /dev/null
+++ b/gl/_Noreturn.h
@@ -0,0 +1,50 @@
1/* A C macro for declaring that a function does not return.
2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#ifndef _Noreturn
18# if (defined __cplusplus \
19 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
20 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
21 && 0)
22 /* [[noreturn]] is not practically usable, because with it the syntax
23 extern _Noreturn void func (...);
24 would not be valid; such a declaration would only be valid with 'extern'
25 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
26 AIX system header files and several gnulib header files use precisely
27 this syntax with 'extern'. */
28# define _Noreturn [[noreturn]]
29# elif (defined __clang__ && __clang_major__ < 16 \
30 && defined _GL_WORK_AROUND_LLVM_BUG_59792)
31 /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
32 that rare LLVM bug, though you may get many false-alarm warnings. */
33# define _Noreturn
34# elif ((!defined __cplusplus || defined __clang__) \
35 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
36 || (!defined __STRICT_ANSI__ \
37 && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
38 || (defined __apple_build_version__ \
39 ? 6000000 <= __apple_build_version__ \
40 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
41 /* _Noreturn works as-is. */
42# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
43 || 0x5110 <= __SUNPRO_C)
44# define _Noreturn __attribute__ ((__noreturn__))
45# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
46# define _Noreturn __declspec (noreturn)
47# else
48# define _Noreturn
49# endif
50#endif
diff --git a/gl/af_alg.c b/gl/af_alg.c
new file mode 100644
index 0000000..9f022ce
--- /dev/null
+++ b/gl/af_alg.c
@@ -0,0 +1,213 @@
1/* af_alg.c - Compute message digests from file streams and buffers.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Matteo Croce <mcroce@redhat.com>, 2018. */
18
19#include <config.h>
20
21#include "af_alg.h"
22
23#if USE_LINUX_CRYPTO_API
24
25#include <unistd.h>
26#include <string.h>
27#include <stdio.h>
28#include <errno.h>
29#include <linux/if_alg.h>
30#include <sys/stat.h>
31#include <sys/sendfile.h>
32#include <sys/socket.h>
33
34#include "sys-limits.h"
35
36#define BLOCKSIZE 32768
37
38/* Return a newly created socket for ALG.
39 On error, return a negative error number. */
40static int
41alg_socket (char const *alg)
42{
43 struct sockaddr_alg salg = {
44 .salg_family = AF_ALG,
45 .salg_type = "hash",
46 };
47 /* Copy alg into salg.salg_name, without calling strcpy nor strlen. */
48 for (size_t i = 0; (salg.salg_name[i] = alg[i]) != '\0'; i++)
49 if (i == sizeof salg.salg_name - 1)
50 /* alg is too long. */
51 return -EINVAL;
52
53 int cfd = socket (AF_ALG, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
54 if (cfd < 0)
55 return -EAFNOSUPPORT;
56 int ofd = (bind (cfd, (struct sockaddr *) &salg, sizeof salg) == 0
57 ? accept4 (cfd, NULL, 0, SOCK_CLOEXEC)
58 : -1);
59 close (cfd);
60 return ofd < 0 ? -EAFNOSUPPORT : ofd;
61}
62
63int
64afalg_buffer (const char *buffer, size_t len, const char *alg,
65 void *resblock, ssize_t hashlen)
66{
67 /* On Linux < 4.9, the value for an empty stream is wrong (all zeroes).
68 See <https://patchwork.kernel.org/patch/9308641/>.
69 This was not fixed properly until November 2016,
70 see <https://patchwork.kernel.org/patch/9434741/>. */
71 if (len == 0)
72 return -EAFNOSUPPORT;
73
74 int ofd = alg_socket (alg);
75 if (ofd < 0)
76 return ofd;
77
78 int result;
79
80 for (;;)
81 {
82 ssize_t size = (len > BLOCKSIZE ? BLOCKSIZE : len);
83 if (send (ofd, buffer, size, MSG_MORE) != size)
84 {
85 result = -EAFNOSUPPORT;
86 break;
87 }
88 buffer += size;
89 len -= size;
90 if (len == 0)
91 {
92 result = read (ofd, resblock, hashlen) == hashlen ? 0 : -EAFNOSUPPORT;
93 break;
94 }
95 }
96
97 close (ofd);
98 return result;
99}
100
101int
102afalg_stream (FILE *stream, const char *alg,
103 void *resblock, ssize_t hashlen)
104{
105 int ofd = alg_socket (alg);
106 if (ofd < 0)
107 return ofd;
108
109 /* If STREAM's size is known and nonzero and not too large, attempt
110 sendfile to pipe the data. The nonzero restriction avoids issues
111 with /proc files that pretend to be empty, and lets the classic
112 read-write loop work around an empty-input bug noted below. */
113 int fd = fileno (stream);
114 int result;
115 struct stat st;
116 off_t off = ftello (stream);
117 if (0 <= off && fstat (fd, &st) == 0
118 && (S_ISREG (st.st_mode) || S_TYPEISSHM (&st) || S_TYPEISTMO (&st))
119 && off < st.st_size && st.st_size - off < SYS_BUFSIZE_MAX)
120 {
121 /* Make sure the offset of fileno (stream) reflects how many bytes
122 have been read from stream before this function got invoked.
123 Note: fflush on an input stream after ungetc does not work as expected
124 on some platforms. Therefore this situation is not supported here. */
125 if (fflush (stream))
126 result = -EIO;
127 else
128 {
129 off_t nbytes = st.st_size - off;
130 if (sendfile (ofd, fd, &off, nbytes) == nbytes)
131 {
132 if (read (ofd, resblock, hashlen) == hashlen)
133 {
134 /* The input buffers of stream are no longer valid. */
135 if (lseek (fd, off, SEEK_SET) != (off_t)-1)
136 result = 0;
137 else
138 /* The file position of fd has not changed. */
139 result = -EAFNOSUPPORT;
140 }
141 else
142 /* The file position of fd has not changed. */
143 result = -EAFNOSUPPORT;
144 }
145 else
146 /* The file position of fd has not changed. */
147 result = -EAFNOSUPPORT;
148 }
149 }
150 else
151 {
152 /* sendfile not possible, do a classic read-write loop. */
153
154 /* Number of bytes to seek (backwards) in case of error. */
155 off_t nseek = 0;
156
157 for (;;)
158 {
159 char buf[BLOCKSIZE];
160 /* When the stream is not seekable, start with a single-byte block,
161 so that we can use ungetc() in the case that send() fails. */
162 size_t blocksize = (nseek == 0 && off < 0 ? 1 : BLOCKSIZE);
163 ssize_t size = fread (buf, 1, blocksize, stream);
164 if (size == 0)
165 {
166 /* On Linux < 4.9, the value for an empty stream is wrong (all 0).
167 See <https://patchwork.kernel.org/patch/9308641/>.
168 This was not fixed properly until November 2016,
169 see <https://patchwork.kernel.org/patch/9434741/>. */
170 result = ferror (stream) ? -EIO : nseek == 0 ? -EAFNOSUPPORT : 0;
171 break;
172 }
173 nseek -= size;
174 if (send (ofd, buf, size, MSG_MORE) != size)
175 {
176 if (nseek == -1)
177 {
178 /* 1 byte of pushback buffer is guaranteed on stream, even
179 if stream is not seekable. */
180 ungetc ((unsigned char) buf[0], stream);
181 result = -EAFNOSUPPORT;
182 }
183 else if (fseeko (stream, nseek, SEEK_CUR) == 0)
184 /* The position of stream has been restored. */
185 result = -EAFNOSUPPORT;
186 else
187 result = -EIO;
188 break;
189 }
190
191 /* Don't assume that EOF is sticky. See:
192 <https://sourceware.org/bugzilla/show_bug.cgi?id=19476>. */
193 if (feof (stream))
194 {
195 result = 0;
196 break;
197 }
198 }
199
200 if (result == 0 && read (ofd, resblock, hashlen) != hashlen)
201 {
202 if (nseek == 0 || fseeko (stream, nseek, SEEK_CUR) == 0)
203 /* The position of stream has been restored. */
204 result = -EAFNOSUPPORT;
205 else
206 result = -EIO;
207 }
208 }
209 close (ofd);
210 return result;
211}
212
213#endif
diff --git a/gl/af_alg.h b/gl/af_alg.h
new file mode 100644
index 0000000..e8ffb3f
--- /dev/null
+++ b/gl/af_alg.h
@@ -0,0 +1,115 @@
1/* af_alg.h - Compute message digests from file streams and buffers.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Matteo Croce <mcroce@redhat.com>, 2018.
18 Documentation by Bruno Haible <bruno@clisp.org>, 2018. */
19
20/* Declare specific functions for computing message digests
21 using the Linux kernel crypto API, if available. This kernel API gives
22 access to specialized crypto instructions (that would also be available
23 in user space) or to crypto devices (not directly available in user space).
24
25 For a more complete set of facilities that use the Linux kernel crypto API,
26 look at libkcapi. */
27
28#ifndef AF_ALG_H
29# define AF_ALG_H 1
30
31# include <stdio.h>
32# include <errno.h>
33
34# ifdef __cplusplus
35extern "C" {
36# endif
37
38# if USE_LINUX_CRYPTO_API
39
40/* Compute a message digest of a memory region.
41
42 The memory region starts at BUFFER and is LEN bytes long.
43
44 ALG is the message digest algorithm; see the file /proc/crypto.
45
46 RESBLOCK points to a block of HASHLEN bytes, for the result.
47 HASHLEN must be the length of the message digest, in bytes, in particular:
48
49 alg | hashlen
50 -------+--------
51 md5 | 16
52 sha1 | 20
53 sha224 | 28
54 sha256 | 32
55 sha384 | 48
56 sha512 | 64
57
58 If successful, fill RESBLOCK and return 0.
59 Upon failure, return a negated error number. */
60int
61afalg_buffer (const char *buffer, size_t len, const char *alg,
62 void *resblock, ssize_t hashlen);
63
64/* Compute a message digest of data read from STREAM.
65
66 STREAM is an open file stream. The last operation on STREAM should
67 not be 'ungetc', and if STREAM is also open for writing it should
68 have been fflushed since its last write. Read from the current
69 position to the end of STREAM. Handle regular files efficiently.
70
71 ALG is the message digest algorithm; see the file /proc/crypto.
72
73 RESBLOCK points to a block of HASHLEN bytes, for the result.
74 HASHLEN must be the length of the message digest, in bytes, in particular:
75
76 alg | hashlen
77 -------+--------
78 md5 | 16
79 sha1 | 20
80 sha224 | 28
81 sha256 | 32
82 sha384 | 48
83 sha512 | 64
84
85 If successful, fill RESBLOCK and return 0.
86 Upon failure, return a negated error number.
87 Unless returning 0 or -EIO, restore STREAM's file position so that
88 the caller can fall back on some other method. */
89int
90afalg_stream (FILE *stream, const char *alg,
91 void *resblock, ssize_t hashlen);
92
93# else
94
95static inline int
96afalg_buffer (const char *buffer, size_t len, const char *alg,
97 void *resblock, ssize_t hashlen)
98{
99 return -EAFNOSUPPORT;
100}
101
102static inline int
103afalg_stream (FILE *stream, const char *alg,
104 void *resblock, ssize_t hashlen)
105{
106 return -EAFNOSUPPORT;
107}
108
109# endif
110
111# ifdef __cplusplus
112}
113# endif
114
115#endif /* AF_ALG_H */
diff --git a/gl/alloca.in.h b/gl/alloca.in.h
index 72d28ee..a1bb3d7 100644
--- a/gl/alloca.in.h
+++ b/gl/alloca.in.h
@@ -1,22 +1,20 @@
1/* Memory allocation on the stack. 1/* Memory allocation on the stack.
2 2
3 Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation, 3 Copyright (C) 1995, 1999, 2001-2004, 2006-2023 Free Software Foundation,
4 Inc. 4 Inc.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This file is free software: you can redistribute it and/or modify
7 under the terms of the GNU General Public License as published 7 it under the terms of the GNU Lesser General Public License as
8 by the Free Software Foundation; either version 3, or (at your option) 8 published by the Free Software Foundation; either version 2.1 of the
9 any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 General Public License for more details. 14 GNU Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public License
17 License along with this program; if not, see 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 <http://www.gnu.org/licenses/>.
19 */
20 18
21/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H 19/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
22 means there is a real alloca function. */ 20 means there is a real alloca function. */
@@ -35,7 +33,16 @@
35 */ 33 */
36 34
37#ifndef alloca 35#ifndef alloca
38# ifdef __GNUC__ 36 /* Some version of mingw have an <alloca.h> that causes trouble when
37 included after 'alloca' gets defined as a macro. As a workaround,
38 include this <alloca.h> first and define 'alloca' as a macro afterwards
39 if needed. */
40# if defined __GNUC__ && (defined _WIN32 && ! defined __CYGWIN__) && @HAVE_ALLOCA_H@
41# include_next <alloca.h>
42# endif
43#endif
44#ifndef alloca
45# if defined __GNUC__ || (__clang_major__ >= 4)
39# define alloca __builtin_alloca 46# define alloca __builtin_alloca
40# elif defined _AIX 47# elif defined _AIX
41# define alloca __alloca 48# define alloca __alloca
@@ -51,6 +58,8 @@ extern "C"
51void *_alloca (unsigned short); 58void *_alloca (unsigned short);
52# pragma intrinsic (_alloca) 59# pragma intrinsic (_alloca)
53# define alloca _alloca 60# define alloca _alloca
61# elif defined __MVS__
62# include <stdlib.h>
54# else 63# else
55# include <stddef.h> 64# include <stddef.h>
56# ifdef __cplusplus 65# ifdef __cplusplus
diff --git a/gl/arg-nonnull.h b/gl/arg-nonnull.h
new file mode 100644
index 0000000..9498ae1
--- /dev/null
+++ b/gl/arg-nonnull.h
@@ -0,0 +1,26 @@
1/* A C macro for declaring that specific arguments must not be NULL.
2 Copyright (C) 2009-2023 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
18 that the values passed as arguments n, ..., m must be non-NULL pointers.
19 n = 1 stands for the first argument, n = 2 for the second argument etc. */
20#ifndef _GL_ARG_NONNULL
21# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
22# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
23# else
24# define _GL_ARG_NONNULL(params)
25# endif
26#endif
diff --git a/gl/arpa_inet.in.h b/gl/arpa_inet.in.h
index ba89e97..80e6713 100644
--- a/gl/arpa_inet.in.h
+++ b/gl/arpa_inet.in.h
@@ -1,19 +1,19 @@
1/* A GNU-like <arpa/inet.h>. 1/* A GNU-like <arpa/inet.h>.
2 2
3 Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _@GUARD_PREFIX@_ARPA_INET_H 18#ifndef _@GUARD_PREFIX@_ARPA_INET_H
19 19
@@ -49,6 +49,12 @@
49#ifndef _@GUARD_PREFIX@_ARPA_INET_H 49#ifndef _@GUARD_PREFIX@_ARPA_INET_H
50#define _@GUARD_PREFIX@_ARPA_INET_H 50#define _@GUARD_PREFIX@_ARPA_INET_H
51 51
52/* Get all possible declarations of inet_ntop() and inet_pton(). */
53#if (@GNULIB_INET_NTOP@ || @GNULIB_INET_PTON@ || defined GNULIB_POSIXCHECK) \
54 && @HAVE_WS2TCPIP_H@
55# include <ws2tcpip.h>
56#endif
57
52/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 58/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
53 59
54/* The definition of _GL_ARG_NONNULL is copied here. */ 60/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -70,8 +76,8 @@
70 the return value is NULL and errno is set to ENOSPC. A good value 76 the return value is NULL and errno is set to ENOSPC. A good value
71 for CNT is 46. 77 for CNT is 46.
72 78
73 For more details, see the POSIX:2001 specification 79 For more details, see the POSIX:2008 specification
74 <http://www.opengroup.org/susv3xsh/inet_ntop.html>. */ 80 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html>. */
75# if @REPLACE_INET_NTOP@ 81# if @REPLACE_INET_NTOP@
76# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 82# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
77# undef inet_ntop 83# undef inet_ntop
@@ -97,7 +103,9 @@ _GL_CXXALIAS_SYS_CAST (inet_ntop, const char *,
97 (int af, const void *restrict src, 103 (int af, const void *restrict src,
98 char *restrict dst, socklen_t cnt)); 104 char *restrict dst, socklen_t cnt));
99# endif 105# endif
106# if __GLIBC__ >= 2
100_GL_CXXALIASWARN (inet_ntop); 107_GL_CXXALIASWARN (inet_ntop);
108# endif
101#elif defined GNULIB_POSIXCHECK 109#elif defined GNULIB_POSIXCHECK
102# undef inet_ntop 110# undef inet_ntop
103# if HAVE_RAW_DECL_INET_NTOP 111# if HAVE_RAW_DECL_INET_NTOP
@@ -126,7 +134,9 @@ _GL_FUNCDECL_SYS (inet_pton, int,
126_GL_CXXALIAS_SYS (inet_pton, int, 134_GL_CXXALIAS_SYS (inet_pton, int,
127 (int af, const char *restrict src, void *restrict dst)); 135 (int af, const char *restrict src, void *restrict dst));
128# endif 136# endif
137# if __GLIBC__ >= 2
129_GL_CXXALIASWARN (inet_pton); 138_GL_CXXALIASWARN (inet_pton);
139# endif
130#elif defined GNULIB_POSIXCHECK 140#elif defined GNULIB_POSIXCHECK
131# undef inet_pton 141# undef inet_pton
132# if HAVE_RAW_DECL_INET_PTON 142# if HAVE_RAW_DECL_INET_PTON
diff --git a/gl/asnprintf.c b/gl/asnprintf.c
index 76e228d..f4861bf 100644
--- a/gl/asnprintf.c
+++ b/gl/asnprintf.c
@@ -1,18 +1,18 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002, 2006, 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
diff --git a/gl/asprintf.c b/gl/asprintf.c
index 713dae1..ba58e06 100644
--- a/gl/asprintf.c
+++ b/gl/asprintf.c
@@ -1,19 +1,19 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006-2007, 2009-2013 Free Software Foundation, 2 Copyright (C) 1999, 2002, 2006-2007, 2009-2023 Free Software Foundation,
3 Inc. 3 Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/assert.in.h b/gl/assert.in.h
new file mode 100644
index 0000000..b0ab99c
--- /dev/null
+++ b/gl/assert.in.h
@@ -0,0 +1,27 @@
1/* Substitute for and wrapper around <assert.h>
2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Do not guard the include, since <assert.h> is supposed to define
18 the assert macro each time it is included. */
19
20#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@
22#endif
23@PRAGMA_COLUMNS@
24
25#@INCLUDE_NEXT@ @NEXT_ASSERT_H@
26
27/* The definition of static_assert is copied here. */
diff --git a/gl/attribute.h b/gl/attribute.h
new file mode 100644
index 0000000..130644d
--- /dev/null
+++ b/gl/attribute.h
@@ -0,0 +1,226 @@
1/* ATTRIBUTE_* macros for using attributes in GCC and similar compilers
2
3 Copyright 2020-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20/* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_*
21 macros used within Gnulib. */
22
23/* These attributes can be placed in two ways:
24 - At the start of a declaration (i.e. even before storage-class
25 specifiers!); then they apply to all entities that are declared
26 by the declaration.
27 - Immediately after the name of an entity being declared by the
28 declaration; then they apply to that entity only. */
29
30#ifndef _GL_ATTRIBUTE_H
31#define _GL_ATTRIBUTE_H
32
33
34/* This file defines two types of attributes:
35 * C23 standard attributes. These have macro names that do not begin with
36 'ATTRIBUTE_'.
37 * Selected GCC attributes; see:
38 https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
39 https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
40 https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
41 These names begin with 'ATTRIBUTE_' to avoid name clashes. */
42
43
44/* =============== Attributes for specific kinds of functions =============== */
45
46/* Attributes for functions that should not be used. */
47
48/* Warn if the entity is used. */
49/* Applies to:
50 - function, variable,
51 - struct, union, struct/union member,
52 - enumeration, enumeration item,
53 - typedef,
54 in C++ also: namespace, class, template specialization. */
55#define DEPRECATED _GL_ATTRIBUTE_DEPRECATED
56
57/* If a function call is not optimized way, warn with MSG. */
58/* Applies to: functions. */
59#define ATTRIBUTE_WARNING(msg) _GL_ATTRIBUTE_WARNING (msg)
60
61/* If a function call is not optimized way, report an error with MSG. */
62/* Applies to: functions. */
63#define ATTRIBUTE_ERROR(msg) _GL_ATTRIBUTE_ERROR (msg)
64
65
66/* Attributes for memory-allocating functions. */
67
68/* The function returns a pointer to freshly allocated memory. */
69/* Applies to: functions. */
70#define ATTRIBUTE_MALLOC _GL_ATTRIBUTE_MALLOC
71
72/* ATTRIBUTE_ALLOC_SIZE ((N)) - The Nth argument of the function
73 is the size of the returned memory block.
74 ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments
75 to determine the size of the returned memory block. */
76/* Applies to: function, pointer to function, function types. */
77#define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args)
78
79/* ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
80 that can be freed by passing them as the Ith argument to the
81 function F.
82 ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
83 can be freed via 'free'; it can be used only after declaring 'free'. */
84/* Applies to: functions. Cannot be used on inline functions. */
85#define ATTRIBUTE_DEALLOC(f, i) _GL_ATTRIBUTE_DEALLOC(f, i)
86#define ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC_FREE
87
88/* Attributes for variadic functions. */
89
90/* The variadic function expects a trailing NULL argument.
91 ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
92 ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
93/* Applies to: functions. */
94#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos)
95
96
97/* ================== Attributes for compiler diagnostics ================== */
98
99/* Attributes that help the compiler diagnose programmer mistakes.
100 Some of them may also help for some compiler optimizations. */
101
102/* ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)) -
103 The STRING-INDEXth function argument is a format string of style
104 ARCHETYPE, which is one of:
105 printf, gnu_printf
106 scanf, gnu_scanf,
107 strftime, gnu_strftime,
108 strfmon,
109 or the same thing prefixed and suffixed with '__'.
110 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
111 are suitable for the format string. */
112/* Applies to: functions. */
113#define ATTRIBUTE_FORMAT(spec) _GL_ATTRIBUTE_FORMAT (spec)
114
115/* ATTRIBUTE_NONNULL ((N1, N2,...)) - Arguments N1, N2,... must not be NULL.
116 ATTRIBUTE_NONNULL () - All pointer arguments must not be null. */
117/* Applies to: functions. */
118#define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args)
119
120/* The function's return value is a non-NULL pointer. */
121/* Applies to: functions. */
122#define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL
123
124/* Warn if the caller does not use the return value,
125 unless the caller uses something like ignore_value. */
126/* Applies to: function, enumeration, class. */
127#define NODISCARD _GL_ATTRIBUTE_NODISCARD
128
129
130/* Attributes that disable false alarms when the compiler diagnoses
131 programmer "mistakes". */
132
133/* Do not warn if the entity is not used. */
134/* Applies to:
135 - function, variable,
136 - struct, union, struct/union member,
137 - enumeration, enumeration item,
138 - typedef,
139 in C++ also: class. */
140#define MAYBE_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
141
142/* The contents of a character array is not meant to be NUL-terminated. */
143/* Applies to: struct/union members and variables that are arrays of element
144 type '[[un]signed] char'. */
145#define ATTRIBUTE_NONSTRING _GL_ATTRIBUTE_NONSTRING
146
147/* Do not warn if control flow falls through to the immediately
148 following 'case' or 'default' label. */
149/* Applies to: Empty statement (;), inside a 'switch' statement. */
150#define FALLTHROUGH _GL_ATTRIBUTE_FALLTHROUGH
151
152
153/* ================== Attributes for debugging information ================== */
154
155/* Attributes regarding debugging information emitted by the compiler. */
156
157/* Omit the function from stack traces when debugging. */
158/* Applies to: function. */
159#define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL
160
161/* Make the entity visible to debuggers etc., even with '-fwhole-program'. */
162/* Applies to: functions, variables. */
163#define ATTRIBUTE_EXTERNALLY_VISIBLE _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
164
165
166/* ========== Attributes that mainly direct compiler optimizations ========== */
167
168/* The function does not throw exceptions. */
169/* Applies to: functions. */
170#define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW
171
172/* Do not inline the function. */
173/* Applies to: functions. */
174#define ATTRIBUTE_NOINLINE _GL_ATTRIBUTE_NOINLINE
175
176/* Always inline the function, and report an error if the compiler
177 cannot inline. */
178/* Applies to: function. */
179#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
180
181/* It is OK for a compiler to omit duplicate calls with the same arguments.
182 This attribute is safe for a function that neither depends on
183 nor affects observable state, and always returns exactly once -
184 e.g., does not loop forever, and does not call longjmp.
185 (This attribute is stricter than ATTRIBUTE_PURE.) */
186/* Applies to: functions. */
187#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
188
189/* It is OK for a compiler to omit duplicate calls with the same
190 arguments if observable state is not changed between calls.
191 This attribute is safe for a function that does not affect
192 observable state, and always returns exactly once.
193 (This attribute is looser than ATTRIBUTE_CONST.) */
194/* Applies to: functions. */
195#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
196
197/* The function is rarely executed. */
198/* Applies to: functions. */
199#define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD
200
201/* If called from some other compilation unit, the function executes
202 code from that unit only by return or by exception handling,
203 letting the compiler optimize that unit more aggressively. */
204/* Applies to: functions. */
205#define ATTRIBUTE_LEAF _GL_ATTRIBUTE_LEAF
206
207/* For struct members: The member has the smallest possible alignment.
208 For struct, union, class: All members have the smallest possible alignment,
209 minimizing the memory required. */
210/* Applies to: struct members, struct, union,
211 in C++ also: class. */
212#define ATTRIBUTE_PACKED _GL_ATTRIBUTE_PACKED
213
214
215/* ================ Attributes that make invalid code valid ================ */
216
217/* Attributes that prevent fatal compiler optimizations for code that is not
218 fully ISO C compliant. */
219
220/* Pointers to the type may point to the same storage as pointers to
221 other types, thus disabling strict aliasing optimization. */
222/* Applies to: types. */
223#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
224
225
226#endif /* _GL_ATTRIBUTE_H */
diff --git a/gl/base64.c b/gl/base64.c
index 8da969c..95b669a 100644
--- a/gl/base64.c
+++ b/gl/base64.c
@@ -1,24 +1,24 @@
1/* base64.c -- Encode binary data using printable characters. 1/* base64.c -- Encode binary data using printable characters.
2 Copyright (C) 1999-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 1999-2001, 2004-2006, 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Simon Josefsson. Partially adapted from GNU MailUtils 17/* Written by Simon Josefsson. Partially adapted from GNU MailUtils
18 * (mailbox/filter_trans.c, as of 2004-11-28). Improved by review 18 * (mailbox/filter_trans.c, as of 2004-11-28). Improved by review
19 * from Paul Eggert, Bruno Haible, and Stepan Kasal. 19 * from Paul Eggert, Bruno Haible, and Stepan Kasal.
20 * 20 *
21 * See also RFC 4648 <http://www.ietf.org/rfc/rfc4648.txt>. 21 * See also RFC 4648 <https://www.ietf.org/rfc/rfc4648.txt>.
22 * 22 *
23 * Be careful with error checking. Here is how you would typically 23 * Be careful with error checking. Here is how you would typically
24 * use these functions: 24 * use these functions:
@@ -30,7 +30,7 @@
30 * FAIL: memory allocation error 30 * FAIL: memory allocation error
31 * OK: data in OUT/OUTLEN 31 * OK: data in OUT/OUTLEN
32 * 32 *
33 * size_t outlen = base64_encode_alloc (in, inlen, &out); 33 * idx_t outlen = base64_encode_alloc (in, inlen, &out);
34 * if (out == NULL && outlen == 0 && inlen != 0) 34 * if (out == NULL && outlen == 0 && inlen != 0)
35 * FAIL: input too long 35 * FAIL: input too long
36 * if (out == NULL) 36 * if (out == NULL)
@@ -44,51 +44,84 @@
44/* Get prototype. */ 44/* Get prototype. */
45#include "base64.h" 45#include "base64.h"
46 46
47/* Get malloc. */ 47/* Get imalloc. */
48#include <stdlib.h> 48#include <ialloc.h>
49
50#include <intprops.h>
49 51
50/* Get UCHAR_MAX. */ 52/* Get UCHAR_MAX. */
51#include <limits.h> 53#include <limits.h>
52 54
53#include <string.h> 55#include <string.h>
54 56
55/* C89 compliant way to cast 'char' to 'unsigned char'. */ 57/* Convert 'char' to 'unsigned char' without casting. */
56static unsigned char 58static unsigned char
57to_uchar (char ch) 59to_uchar (char ch)
58{ 60{
59 return ch; 61 return ch;
60} 62}
61 63
64static const char b64c[64] =
65 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
66
67/* Base64 encode IN array of size INLEN into OUT array. OUT needs
68 to be of length >= BASE64_LENGTH(INLEN), and INLEN needs to be
69 a multiple of 3. */
70static void
71base64_encode_fast (const char *restrict in, idx_t inlen, char *restrict out)
72{
73 while (inlen)
74 {
75 *out++ = b64c[(to_uchar (in[0]) >> 2) & 0x3f];
76 *out++ = b64c[((to_uchar (in[0]) << 4) + (to_uchar (in[1]) >> 4)) & 0x3f];
77 *out++ = b64c[((to_uchar (in[1]) << 2) + (to_uchar (in[2]) >> 6)) & 0x3f];
78 *out++ = b64c[to_uchar (in[2]) & 0x3f];
79
80 inlen -= 3;
81 in += 3;
82 }
83}
84
62/* Base64 encode IN array of size INLEN into OUT array of size OUTLEN. 85/* Base64 encode IN array of size INLEN into OUT array of size OUTLEN.
63 If OUTLEN is less than BASE64_LENGTH(INLEN), write as many bytes as 86 If OUTLEN is less than BASE64_LENGTH(INLEN), write as many bytes as
64 possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero 87 possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero
65 terminate the output buffer. */ 88 terminate the output buffer. */
66void 89void
67base64_encode (const char *restrict in, size_t inlen, 90base64_encode (const char *restrict in, idx_t inlen,
68 char *restrict out, size_t outlen) 91 char *restrict out, idx_t outlen)
69{ 92{
70 static const char b64str[64] = 93 /* Note this outlen constraint can be enforced at compile time.
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 94 I.E. that the output buffer is exactly large enough to hold
95 the encoded inlen bytes. The inlen constraints (of corresponding
96 to outlen, and being a multiple of 3) can change at runtime
97 at the end of input. However the common case when reading
98 large inputs is to have both constraints satisfied, so we depend
99 on both in base_encode_fast(). */
100 if (outlen % 4 == 0 && inlen == (outlen >> 2) * 3)
101 {
102 base64_encode_fast (in, inlen, out);
103 return;
104 }
72 105
73 while (inlen && outlen) 106 while (inlen && outlen)
74 { 107 {
75 *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f]; 108 *out++ = b64c[(to_uchar (in[0]) >> 2) & 0x3f];
76 if (!--outlen) 109 if (!--outlen)
77 break; 110 break;
78 *out++ = b64str[((to_uchar (in[0]) << 4) 111 *out++ = b64c[((to_uchar (in[0]) << 4)
79 + (--inlen ? to_uchar (in[1]) >> 4 : 0)) 112 + (--inlen ? to_uchar (in[1]) >> 4 : 0))
80 & 0x3f]; 113 & 0x3f];
81 if (!--outlen) 114 if (!--outlen)
82 break; 115 break;
83 *out++ = 116 *out++ =
84 (inlen 117 (inlen
85 ? b64str[((to_uchar (in[1]) << 2) 118 ? b64c[((to_uchar (in[1]) << 2)
86 + (--inlen ? to_uchar (in[2]) >> 6 : 0)) 119 + (--inlen ? to_uchar (in[2]) >> 6 : 0))
87 & 0x3f] 120 & 0x3f]
88 : '='); 121 : '=');
89 if (!--outlen) 122 if (!--outlen)
90 break; 123 break;
91 *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '='; 124 *out++ = inlen ? b64c[to_uchar (in[2]) & 0x3f] : '=';
92 if (!--outlen) 125 if (!--outlen)
93 break; 126 break;
94 if (inlen) 127 if (inlen)
@@ -110,30 +143,21 @@ base64_encode (const char *restrict in, size_t inlen,
110 memory allocation failed, OUT is set to NULL, and the return value 143 memory allocation failed, OUT is set to NULL, and the return value
111 indicates length of the requested memory block, i.e., 144 indicates length of the requested memory block, i.e.,
112 BASE64_LENGTH(inlen) + 1. */ 145 BASE64_LENGTH(inlen) + 1. */
113size_t 146idx_t
114base64_encode_alloc (const char *in, size_t inlen, char **out) 147base64_encode_alloc (const char *in, idx_t inlen, char **out)
115{ 148{
116 size_t outlen = 1 + BASE64_LENGTH (inlen);
117
118 /* Check for overflow in outlen computation. 149 /* Check for overflow in outlen computation.
119 * 150 Treat negative INLEN as overflow, for better compatibility with
120 * If there is no overflow, outlen >= inlen. 151 pre-2021-08-27 API, which used size_t. */
121 * 152 idx_t in_over_3 = inlen / 3 + (inlen % 3 != 0), outlen;
122 * If the operation (inlen + 2) overflows then it yields at most +1, so 153 if (! INT_MULTIPLY_OK (in_over_3, 4, &outlen) || inlen < 0)
123 * outlen is 0.
124 *
125 * If the multiplication overflows, we lose at least half of the
126 * correct value, so the result is < ((inlen + 2) / 3) * 2, which is
127 * less than (inlen + 2) * 0.66667, which is less than inlen as soon as
128 * (inlen > 4).
129 */
130 if (inlen > outlen)
131 { 154 {
132 *out = NULL; 155 *out = NULL;
133 return 0; 156 return 0;
134 } 157 }
158 outlen++;
135 159
136 *out = malloc (outlen); 160 *out = imalloc (outlen);
137 if (!*out) 161 if (!*out)
138 return outlen; 162 return outlen;
139 163
@@ -317,7 +341,7 @@ base64_decode_ctx_init (struct base64_decode_context *ctx)
317static char * 341static char *
318get_4 (struct base64_decode_context *ctx, 342get_4 (struct base64_decode_context *ctx,
319 char const *restrict *in, char const *restrict in_end, 343 char const *restrict *in, char const *restrict in_end,
320 size_t *n_non_newline) 344 idx_t *n_non_newline)
321{ 345{
322 if (ctx->i == 4) 346 if (ctx->i == 4)
323 ctx->i = 0; 347 ctx->i = 0;
@@ -369,8 +393,8 @@ get_4 (struct base64_decode_context *ctx,
369 *OUT to point to the byte after the last one written, and decrement 393 *OUT to point to the byte after the last one written, and decrement
370 *OUTLEN to reflect the number of bytes remaining in *OUT. */ 394 *OUTLEN to reflect the number of bytes remaining in *OUT. */
371static bool 395static bool
372decode_4 (char const *restrict in, size_t inlen, 396decode_4 (char const *restrict in, idx_t inlen,
373 char *restrict *outp, size_t *outleft) 397 char *restrict *outp, idx_t *outleft)
374{ 398{
375 char *out = *outp; 399 char *out = *outp;
376 if (inlen < 2) 400 if (inlen < 2)
@@ -455,10 +479,10 @@ decode_4 (char const *restrict in, size_t inlen,
455 479
456bool 480bool
457base64_decode_ctx (struct base64_decode_context *ctx, 481base64_decode_ctx (struct base64_decode_context *ctx,
458 const char *restrict in, size_t inlen, 482 const char *restrict in, idx_t inlen,
459 char *restrict out, size_t *outlen) 483 char *restrict out, idx_t *outlen)
460{ 484{
461 size_t outleft = *outlen; 485 idx_t outleft = *outlen;
462 bool ignore_newlines = ctx != NULL; 486 bool ignore_newlines = ctx != NULL;
463 bool flush_ctx = false; 487 bool flush_ctx = false;
464 unsigned int ctx_i = 0; 488 unsigned int ctx_i = 0;
@@ -472,7 +496,7 @@ base64_decode_ctx (struct base64_decode_context *ctx,
472 496
473 while (true) 497 while (true)
474 { 498 {
475 size_t outleft_save = outleft; 499 idx_t outleft_save = outleft;
476 if (ctx_i == 0 && !flush_ctx) 500 if (ctx_i == 0 && !flush_ctx)
477 { 501 {
478 while (true) 502 while (true)
@@ -546,17 +570,17 @@ base64_decode_ctx (struct base64_decode_context *ctx,
546 undefined. */ 570 undefined. */
547bool 571bool
548base64_decode_alloc_ctx (struct base64_decode_context *ctx, 572base64_decode_alloc_ctx (struct base64_decode_context *ctx,
549 const char *in, size_t inlen, char **out, 573 const char *in, idx_t inlen, char **out,
550 size_t *outlen) 574 idx_t *outlen)
551{ 575{
552 /* This may allocate a few bytes too many, depending on input, 576 /* This may allocate a few bytes too many, depending on input,
553 but it's not worth the extra CPU time to compute the exact size. 577 but it's not worth the extra CPU time to compute the exact size.
554 The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the 578 The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the
555 input ends with "=" and minus another 1 if the input ends with "==". 579 input ends with "=" and minus another 1 if the input ends with "==".
556 Dividing before multiplying avoids the possibility of overflow. */ 580 Shifting before multiplying avoids the possibility of overflow. */
557 size_t needlen = 3 * (inlen / 4) + 3; 581 idx_t needlen = 3 * ((inlen >> 2) + 1);
558 582
559 *out = malloc (needlen); 583 *out = imalloc (needlen);
560 if (!*out) 584 if (!*out)
561 return true; 585 return true;
562 586
diff --git a/gl/base64.h b/gl/base64.h
index 343150c..9913765 100644
--- a/gl/base64.h
+++ b/gl/base64.h
@@ -1,28 +1,25 @@
1/* base64.h -- Encode binary data using printable characters. 1/* base64.h -- Encode binary data using printable characters.
2 Copyright (C) 2004-2006, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2004-2006, 2009-2023 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef BASE64_H 18#ifndef BASE64_H
19# define BASE64_H 19# define BASE64_H
20 20
21/* Get size_t. */ 21/* Get idx_t. */
22# include <stddef.h> 22# include <idx.h>
23
24/* Get bool. */
25# include <stdbool.h>
26 23
27# ifdef __cplusplus 24# ifdef __cplusplus
28extern "C" { 25extern "C" {
@@ -34,26 +31,26 @@ extern "C" {
34 31
35struct base64_decode_context 32struct base64_decode_context
36{ 33{
37 unsigned int i; 34 int i;
38 char buf[4]; 35 char buf[4];
39}; 36};
40 37
41extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST; 38extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST;
42 39
43extern void base64_encode (const char *restrict in, size_t inlen, 40extern void base64_encode (const char *restrict in, idx_t inlen,
44 char *restrict out, size_t outlen); 41 char *restrict out, idx_t outlen);
45 42
46extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out); 43extern idx_t base64_encode_alloc (const char *in, idx_t inlen, char **out);
47 44
48extern void base64_decode_ctx_init (struct base64_decode_context *ctx); 45extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
49 46
50extern bool base64_decode_ctx (struct base64_decode_context *ctx, 47extern bool base64_decode_ctx (struct base64_decode_context *ctx,
51 const char *restrict in, size_t inlen, 48 const char *restrict in, idx_t inlen,
52 char *restrict out, size_t *outlen); 49 char *restrict out, idx_t *outlen);
53 50
54extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx, 51extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
55 const char *in, size_t inlen, 52 const char *in, idx_t inlen,
56 char **out, size_t *outlen); 53 char **out, idx_t *outlen);
57 54
58#define base64_decode(in, inlen, out, outlen) \ 55#define base64_decode(in, inlen, out, outlen) \
59 base64_decode_ctx (NULL, in, inlen, out, outlen) 56 base64_decode_ctx (NULL, in, inlen, out, outlen)
diff --git a/gl/basename-lgpl.c b/gl/basename-lgpl.c
index 9307e83..6de60aa 100644
--- a/gl/basename-lgpl.c
+++ b/gl/basename-lgpl.c
@@ -1,37 +1,36 @@
1/* basename.c -- return the last element in a file name 1/* basename.c -- return the last element in a file name
2 2
3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2023 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 file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 2.1 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
21#include "dirname.h" 21/* Specification. */
22#include "basename-lgpl.h"
22 23
23#include <string.h> 24#include <string.h>
24 25
25/* Return the address of the last file name component of NAME. If 26#include "filename.h"
26 NAME has no relative file name components because it is a file
27 system root, return the empty string. */
28 27
29char * 28char *
30last_component (char const *name) 29last_component (char const *name)
31{ 30{
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); 31 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
33 char const *p; 32 char const *p;
34 bool saw_slash = false; 33 bool last_was_slash = false;
35 34
36 while (ISSLASH (*base)) 35 while (ISSLASH (*base))
37 base++; 36 base++;
@@ -39,21 +38,17 @@ last_component (char const *name)
39 for (p = base; *p; p++) 38 for (p = base; *p; p++)
40 { 39 {
41 if (ISSLASH (*p)) 40 if (ISSLASH (*p))
42 saw_slash = true; 41 last_was_slash = true;
43 else if (saw_slash) 42 else if (last_was_slash)
44 { 43 {
45 base = p; 44 base = p;
46 saw_slash = false; 45 last_was_slash = false;
47 } 46 }
48 } 47 }
49 48
50 return (char *) base; 49 return (char *) base;
51} 50}
52 51
53/* Return the length of the basename NAME. Typically NAME is the
54 value returned by base_name or last_component. Act like strlen
55 (NAME), except omit all trailing slashes. */
56
57size_t 52size_t
58base_len (char const *name) 53base_len (char const *name)
59{ 54{
diff --git a/gl/basename-lgpl.h b/gl/basename-lgpl.h
new file mode 100644
index 0000000..5d996c1
--- /dev/null
+++ b/gl/basename-lgpl.h
@@ -0,0 +1,78 @@
1/* Extract the last component (base name) of a file name.
2
3 Copyright (C) 1998, 2001, 2003-2006, 2009-2023 Free Software Foundation,
4 Inc.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file 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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19#ifndef _BASENAME_LGPL_H
20#define _BASENAME_LGPL_H
21
22#include <stddef.h>
23
24#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
25# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
26#endif
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32
33/* Return the address of the last file name component of FILENAME.
34 If FILENAME has some trailing slash(es), they are considered to be
35 part of the last component.
36 If FILENAME has no relative file name components because it is a file
37 system root, return the empty string.
38 Examples:
39 FILENAME RESULT
40 "foo.c" "foo.c"
41 "foo/bar.c" "bar.c"
42 "/foo/bar.c" "bar.c"
43 "foo/bar/" "bar/"
44 "foo/bar//" "bar//"
45 "/" ""
46 "//" ""
47 "" ""
48 The return value is a tail of the given FILENAME; do NOT free() it! */
49
50/* This function was traditionally called 'basename', but we avoid this
51 function name because
52 * Various platforms have different functions in their libc.
53 In particular, the glibc basename(), defined in <string.h>, does
54 not consider trailing slashes to be part of the component:
55 FILENAME RESULT
56 "foo/bar/" ""
57 "foo/bar//" ""
58 * The 'basename' command eliminates trailing slashes and for a root
59 produces a non-empty result:
60 FILENAME RESULT
61 "foo/bar/" "bar"
62 "foo/bar//" "bar"
63 "/" "/"
64 "//" "/"
65 */
66extern char *last_component (char const *filename) _GL_ATTRIBUTE_PURE;
67
68/* Return the length of the basename FILENAME.
69 Typically FILENAME is the value returned by base_name or last_component.
70 Act like strlen (FILENAME), except omit all trailing slashes. */
71extern size_t base_len (char const *filename) _GL_ATTRIBUTE_PURE;
72
73
74#ifdef __cplusplus
75} /* extern "C" */
76#endif
77
78#endif /* _BASENAME_LGPL_H */
diff --git a/gl/basename.c b/gl/basename.c
index d73fd41..21fab1e 100644
--- a/gl/basename.c
+++ b/gl/basename.c
@@ -1,11 +1,11 @@
1/* basename.c -- return the last element in a file name 1/* basename.c -- return the last element in a file name
2 2
3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2023 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 3 of the License, or 8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) 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,
@@ -14,7 +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, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
@@ -22,37 +22,43 @@
22 22
23#include <string.h> 23#include <string.h>
24#include "xalloc.h" 24#include "xalloc.h"
25#include "xstrndup.h"
26 25
27char * 26char *
28base_name (char const *name) 27base_name (char const *name)
29{ 28{
30 char const *base = last_component (name); 29 char const *base = last_component (name);
31 size_t length; 30 idx_t length;
32 31 int dotslash_len;
33 /* If there is no last component, then name is a file system root or the 32 if (*base)
34 empty string. */ 33 {
35 if (! *base) 34 length = base_len (base);
36 return xstrndup (name, base_len (name)); 35
37 36 /* Collapse a sequence of trailing slashes into one. */
38 /* Collapse a sequence of trailing slashes into one. */ 37 length += ISSLASH (base[length]);
39 length = base_len (base); 38
40 if (ISSLASH (base[length])) 39 /* On systems with drive letters, "a/b:c" must return "./b:c" rather
41 length++; 40 than "b:c" to avoid confusion with a drive letter. On systems
42 41 with pure POSIX semantics, this is not an issue. */
43 /* On systems with drive letters, "a/b:c" must return "./b:c" rather 42 dotslash_len = FILE_SYSTEM_PREFIX_LEN (base) != 0 ? 2 : 0;
44 than "b:c" to avoid confusion with a drive letter. On systems 43 }
45 with pure POSIX semantics, this is not an issue. */ 44 else
46 if (FILE_SYSTEM_PREFIX_LEN (base)) 45 {
46 /* There is no last component, so NAME is a file system root or
47 the empty string. */
48 base = name;
49 length = base_len (base);
50 dotslash_len = 0;
51 }
52
53 char *p = ximalloc (dotslash_len + length + 1);
54 if (dotslash_len)
47 { 55 {
48 char *p = xmalloc (length + 3);
49 p[0] = '.'; 56 p[0] = '.';
50 p[1] = '/'; 57 p[1] = '/';
51 memcpy (p + 2, base, length);
52 p[length + 2] = '\0';
53 return p;
54 } 58 }
55 59
56 /* Finally, copy the basename. */ 60 /* Finally, copy the basename. */
57 return xstrndup (base, length); 61 memcpy (p + dotslash_len, base, length);
62 p[dotslash_len + length] = '\0';
63 return p;
58} 64}
diff --git a/gl/btowc.c b/gl/btowc.c
index 6c7cbec..caadbd7 100644
--- a/gl/btowc.c
+++ b/gl/btowc.c
@@ -1,19 +1,19 @@
1/* Convert unibyte character to wide character. 1/* Convert unibyte character to wide character.
2 Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008, 2010-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/byteswap.in.h b/gl/byteswap.in.h
new file mode 100644
index 0000000..e61be27
--- /dev/null
+++ b/gl/byteswap.in.h
@@ -0,0 +1,44 @@
1/* byteswap.h - Byte swapping
2 Copyright (C) 2005, 2007, 2009-2023 Free Software Foundation, Inc.
3 Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _GL_BYTESWAP_H
19#define _GL_BYTESWAP_H
20
21/* Given an unsigned 16-bit argument X, return the value corresponding to
22 X with reversed byte order. */
23#define bswap_16(x) ((((x) & 0x00FF) << 8) | \
24 (((x) & 0xFF00) >> 8))
25
26/* Given an unsigned 32-bit argument X, return the value corresponding to
27 X with reversed byte order. */
28#define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
29 (((x) & 0x0000FF00) << 8) | \
30 (((x) & 0x00FF0000) >> 8) | \
31 (((x) & 0xFF000000) >> 24))
32
33/* Given an unsigned 64-bit argument X, return the value corresponding to
34 X with reversed byte order. */
35#define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
36 (((x) & 0x000000000000FF00ULL) << 40) | \
37 (((x) & 0x0000000000FF0000ULL) << 24) | \
38 (((x) & 0x00000000FF000000ULL) << 8) | \
39 (((x) & 0x000000FF00000000ULL) >> 8) | \
40 (((x) & 0x0000FF0000000000ULL) >> 24) | \
41 (((x) & 0x00FF000000000000ULL) >> 40) | \
42 (((x) & 0xFF00000000000000ULL) >> 56))
43
44#endif /* _GL_BYTESWAP_H */
diff --git a/gl/c++defs.h b/gl/c++defs.h
new file mode 100644
index 0000000..8ad4695
--- /dev/null
+++ b/gl/c++defs.h
@@ -0,0 +1,331 @@
1/* C++ compatible function declaration macros.
2 Copyright (C) 2010-2023 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#ifndef _GL_CXXDEFS_H
18#define _GL_CXXDEFS_H
19
20/* Begin/end the GNULIB_NAMESPACE namespace. */
21#if defined __cplusplus && defined GNULIB_NAMESPACE
22# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
23# define _GL_END_NAMESPACE }
24#else
25# define _GL_BEGIN_NAMESPACE
26# define _GL_END_NAMESPACE
27#endif
28
29/* The three most frequent use cases of these macros are:
30
31 * For providing a substitute for a function that is missing on some
32 platforms, but is declared and works fine on the platforms on which
33 it exists:
34
35 #if @GNULIB_FOO@
36 # if !@HAVE_FOO@
37 _GL_FUNCDECL_SYS (foo, ...);
38 # endif
39 _GL_CXXALIAS_SYS (foo, ...);
40 _GL_CXXALIASWARN (foo);
41 #elif defined GNULIB_POSIXCHECK
42 ...
43 #endif
44
45 * For providing a replacement for a function that exists on all platforms,
46 but is broken/insufficient and needs to be replaced on some platforms:
47
48 #if @GNULIB_FOO@
49 # if @REPLACE_FOO@
50 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
51 # undef foo
52 # define foo rpl_foo
53 # endif
54 _GL_FUNCDECL_RPL (foo, ...);
55 _GL_CXXALIAS_RPL (foo, ...);
56 # else
57 _GL_CXXALIAS_SYS (foo, ...);
58 # endif
59 _GL_CXXALIASWARN (foo);
60 #elif defined GNULIB_POSIXCHECK
61 ...
62 #endif
63
64 * For providing a replacement for a function that exists on some platforms
65 but is broken/insufficient and needs to be replaced on some of them and
66 is additionally either missing or undeclared on some other platforms:
67
68 #if @GNULIB_FOO@
69 # if @REPLACE_FOO@
70 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
71 # undef foo
72 # define foo rpl_foo
73 # endif
74 _GL_FUNCDECL_RPL (foo, ...);
75 _GL_CXXALIAS_RPL (foo, ...);
76 # else
77 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
78 _GL_FUNCDECL_SYS (foo, ...);
79 # endif
80 _GL_CXXALIAS_SYS (foo, ...);
81 # endif
82 _GL_CXXALIASWARN (foo);
83 #elif defined GNULIB_POSIXCHECK
84 ...
85 #endif
86*/
87
88/* _GL_EXTERN_C declaration;
89 performs the declaration with C linkage. */
90#if defined __cplusplus
91# define _GL_EXTERN_C extern "C"
92#else
93# define _GL_EXTERN_C extern
94#endif
95
96/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
97 declares a replacement function, named rpl_func, with the given prototype,
98 consisting of return type, parameters, and attributes.
99 Example:
100 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
101 _GL_ARG_NONNULL ((1)));
102 */
103#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
104 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
105#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
106 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
107
108/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
109 declares the system function, named func, with the given prototype,
110 consisting of return type, parameters, and attributes.
111 Example:
112 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
113 _GL_ARG_NONNULL ((1)));
114 */
115#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
116 _GL_EXTERN_C rettype func parameters_and_attributes
117
118/* _GL_CXXALIAS_RPL (func, rettype, parameters);
119 declares a C++ alias called GNULIB_NAMESPACE::func
120 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
121 Example:
122 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
123
124 Wrapping rpl_func in an object with an inline conversion operator
125 avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
126 actually used in the program. */
127#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
128 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
129#if defined __cplusplus && defined GNULIB_NAMESPACE
130# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
131 namespace GNULIB_NAMESPACE \
132 { \
133 static const struct _gl_ ## func ## _wrapper \
134 { \
135 typedef rettype (*type) parameters; \
136 \
137 inline operator type () const \
138 { \
139 return ::rpl_func; \
140 } \
141 } func = {}; \
142 } \
143 _GL_EXTERN_C int _gl_cxxalias_dummy
144#else
145# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
146 _GL_EXTERN_C int _gl_cxxalias_dummy
147#endif
148
149/* _GL_CXXALIAS_MDA (func, rettype, parameters);
150 is to be used when func is a Microsoft deprecated alias, on native Windows.
151 It declares a C++ alias called GNULIB_NAMESPACE::func
152 that redirects to _func, if GNULIB_NAMESPACE is defined.
153 Example:
154 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
155 */
156#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
157 _GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
158
159/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
160 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
161 except that the C function rpl_func may have a slightly different
162 declaration. A cast is used to silence the "invalid conversion" error
163 that would otherwise occur. */
164#if defined __cplusplus && defined GNULIB_NAMESPACE
165# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
166 namespace GNULIB_NAMESPACE \
167 { \
168 static const struct _gl_ ## func ## _wrapper \
169 { \
170 typedef rettype (*type) parameters; \
171 \
172 inline operator type () const \
173 { \
174 return reinterpret_cast<type>(::rpl_func); \
175 } \
176 } func = {}; \
177 } \
178 _GL_EXTERN_C int _gl_cxxalias_dummy
179#else
180# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
181 _GL_EXTERN_C int _gl_cxxalias_dummy
182#endif
183
184/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
185 is like _GL_CXXALIAS_MDA (func, rettype, parameters);
186 except that the C function func may have a slightly different declaration.
187 A cast is used to silence the "invalid conversion" error that would
188 otherwise occur. */
189#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
190 _GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
191
192/* _GL_CXXALIAS_SYS (func, rettype, parameters);
193 declares a C++ alias called GNULIB_NAMESPACE::func
194 that redirects to the system provided function func, if GNULIB_NAMESPACE
195 is defined.
196 Example:
197 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
198
199 Wrapping func in an object with an inline conversion operator
200 avoids a reference to func unless GNULIB_NAMESPACE::func is
201 actually used in the program. */
202#if defined __cplusplus && defined GNULIB_NAMESPACE
203# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
204 namespace GNULIB_NAMESPACE \
205 { \
206 static const struct _gl_ ## func ## _wrapper \
207 { \
208 typedef rettype (*type) parameters; \
209 \
210 inline operator type () const \
211 { \
212 return ::func; \
213 } \
214 } func = {}; \
215 } \
216 _GL_EXTERN_C int _gl_cxxalias_dummy
217#else
218# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
219 _GL_EXTERN_C int _gl_cxxalias_dummy
220#endif
221
222/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
223 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
224 except that the C function func may have a slightly different declaration.
225 A cast is used to silence the "invalid conversion" error that would
226 otherwise occur. */
227#if defined __cplusplus && defined GNULIB_NAMESPACE
228# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
229 namespace GNULIB_NAMESPACE \
230 { \
231 static const struct _gl_ ## func ## _wrapper \
232 { \
233 typedef rettype (*type) parameters; \
234 \
235 inline operator type () const \
236 { \
237 return reinterpret_cast<type>(::func); \
238 } \
239 } func = {}; \
240 } \
241 _GL_EXTERN_C int _gl_cxxalias_dummy
242#else
243# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
244 _GL_EXTERN_C int _gl_cxxalias_dummy
245#endif
246
247/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
248 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
249 except that the C function is picked among a set of overloaded functions,
250 namely the one with rettype2 and parameters2. Two consecutive casts
251 are used to silence the "cannot find a match" and "invalid conversion"
252 errors that would otherwise occur. */
253#if defined __cplusplus && defined GNULIB_NAMESPACE
254 /* The outer cast must be a reinterpret_cast.
255 The inner cast: When the function is defined as a set of overloaded
256 functions, it works as a static_cast<>, choosing the designated variant.
257 When the function is defined as a single variant, it works as a
258 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
259# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
260 namespace GNULIB_NAMESPACE \
261 { \
262 static const struct _gl_ ## func ## _wrapper \
263 { \
264 typedef rettype (*type) parameters; \
265 \
266 inline operator type () const \
267 { \
268 return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); \
269 } \
270 } func = {}; \
271 } \
272 _GL_EXTERN_C int _gl_cxxalias_dummy
273#else
274# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
275 _GL_EXTERN_C int _gl_cxxalias_dummy
276#endif
277
278/* _GL_CXXALIASWARN (func);
279 causes a warning to be emitted when ::func is used but not when
280 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
281 variants. */
282#if defined __cplusplus && defined GNULIB_NAMESPACE
283# define _GL_CXXALIASWARN(func) \
284 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
285# define _GL_CXXALIASWARN_1(func,namespace) \
286 _GL_CXXALIASWARN_2 (func, namespace)
287/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
288 we enable the warning only when not optimizing. */
289# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
290# define _GL_CXXALIASWARN_2(func,namespace) \
291 _GL_WARN_ON_USE (func, \
292 "The symbol ::" #func " refers to the system function. " \
293 "Use " #namespace "::" #func " instead.")
294# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
295# define _GL_CXXALIASWARN_2(func,namespace) \
296 extern __typeof__ (func) func
297# else
298# define _GL_CXXALIASWARN_2(func,namespace) \
299 _GL_EXTERN_C int _gl_cxxalias_dummy
300# endif
301#else
302# define _GL_CXXALIASWARN(func) \
303 _GL_EXTERN_C int _gl_cxxalias_dummy
304#endif
305
306/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
307 causes a warning to be emitted when the given overloaded variant of ::func
308 is used but not when GNULIB_NAMESPACE::func is used. */
309#if defined __cplusplus && defined GNULIB_NAMESPACE
310# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
311 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
312 GNULIB_NAMESPACE)
313# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
314 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
315/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
316 we enable the warning only when not optimizing. */
317# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
318# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
319 _GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
320 "The symbol ::" #func " refers to the system function. " \
321 "Use " #namespace "::" #func " instead.")
322# else
323# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
324 _GL_EXTERN_C int _gl_cxxalias_dummy
325# endif
326#else
327# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
328 _GL_EXTERN_C int _gl_cxxalias_dummy
329#endif
330
331#endif /* _GL_CXXDEFS_H */
diff --git a/gl/calloc.c b/gl/calloc.c
new file mode 100644
index 0000000..08843ac
--- /dev/null
+++ b/gl/calloc.c
@@ -0,0 +1,55 @@
1/* calloc() function that is glibc compatible.
2 This wrapper function is required at least on Tru64 UNIX 5.1 and mingw.
3 Copyright (C) 2004-2007, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* written by Jim Meyering and Bruno Haible */
19
20#include <config.h>
21
22/* Specification. */
23#include <stdlib.h>
24
25#include <errno.h>
26
27#include "xalloc-oversized.h"
28
29/* Call the system's calloc below. */
30#undef calloc
31
32/* Allocate and zero-fill an NxS-byte block of memory from the heap,
33 even if N or S is zero. */
34
35void *
36rpl_calloc (size_t n, size_t s)
37{
38 if (n == 0 || s == 0)
39 n = s = 1;
40
41 if (xalloc_oversized (n, s))
42 {
43 errno = ENOMEM;
44 return NULL;
45 }
46
47 void *result = calloc (n, s);
48
49#if !HAVE_MALLOC_POSIX
50 if (result == NULL)
51 errno = ENOMEM;
52#endif
53
54 return result;
55}
diff --git a/gl/cdefs.h b/gl/cdefs.h
new file mode 100644
index 0000000..09a3d19
--- /dev/null
+++ b/gl/cdefs.h
@@ -0,0 +1,707 @@
1/* Copyright (C) 1992-2023 Free Software Foundation, Inc.
2 Copyright The GNU Toolchain Authors.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_CDEFS_H
20#define _SYS_CDEFS_H 1
21
22/* We are almost always included from features.h. */
23#ifndef _FEATURES_H
24# include <features.h>
25#endif
26
27/* The GNU libc does not support any K&R compilers or the traditional mode
28 of ISO C compilers anymore. Check for some of the combinations not
29 supported anymore. */
30#if defined __GNUC__ && !defined __STDC__
31# error "You need a ISO C conforming compiler to use the glibc headers"
32#endif
33
34/* Some user header file might have defined this before. */
35#undef __P
36#undef __PMT
37
38/* Compilers that lack __has_attribute may object to
39 #if defined __has_attribute && __has_attribute (...)
40 even though they do not need to evaluate the right-hand side of the &&.
41 Similarly for __has_builtin, etc. */
42#if (defined __has_attribute \
43 && (!defined __clang_minor__ \
44 || (defined __apple_build_version__ \
45 ? 6000000 <= __apple_build_version__ \
46 : 3 < __clang_major__ + (5 <= __clang_minor__))))
47# define __glibc_has_attribute(attr) __has_attribute (attr)
48#else
49# define __glibc_has_attribute(attr) 0
50#endif
51#ifdef __has_builtin
52# define __glibc_has_builtin(name) __has_builtin (name)
53#else
54# define __glibc_has_builtin(name) 0
55#endif
56#ifdef __has_extension
57# define __glibc_has_extension(ext) __has_extension (ext)
58#else
59# define __glibc_has_extension(ext) 0
60#endif
61
62#if defined __GNUC__ || defined __clang__
63
64/* All functions, except those with callbacks or those that
65 synchronize memory, are leaf functions. */
66# if __GNUC_PREREQ (4, 6) && !defined _LIBC
67# define __LEAF , __leaf__
68# define __LEAF_ATTR __attribute__ ((__leaf__))
69# else
70# define __LEAF
71# define __LEAF_ATTR
72# endif
73
74/* GCC can always grok prototypes. For C++ programs we add throw()
75 to help it optimize the function calls. But this only works with
76 gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
77 as non-throwing using a function attribute since programs can use
78 the -fexceptions options for C code as well. */
79# if !defined __cplusplus \
80 && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
81# define __THROW __attribute__ ((__nothrow__ __LEAF))
82# define __THROWNL __attribute__ ((__nothrow__))
83# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
84# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
85# else
86# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
87# if __cplusplus >= 201103L
88# define __THROW noexcept (true)
89# else
90# define __THROW throw ()
91# endif
92# define __THROWNL __THROW
93# define __NTH(fct) __LEAF_ATTR fct __THROW
94# define __NTHNL(fct) fct __THROW
95# else
96# define __THROW
97# define __THROWNL
98# define __NTH(fct) fct
99# define __NTHNL(fct) fct
100# endif
101# endif
102
103#else /* Not GCC or clang. */
104
105# if (defined __cplusplus \
106 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
107# define __inline inline
108# else
109# define __inline /* No inline functions. */
110# endif
111
112# define __THROW
113# define __THROWNL
114# define __NTH(fct) fct
115
116#endif /* GCC || clang. */
117
118/* These two macros are not used in glibc anymore. They are kept here
119 only because some other projects expect the macros to be defined. */
120#define __P(args) args
121#define __PMT(args) args
122
123/* For these things, GCC behaves the ANSI way normally,
124 and the non-ANSI way under -traditional. */
125
126#define __CONCAT(x,y) x ## y
127#define __STRING(x) #x
128
129/* This is not a typedef so `const __ptr_t' does the right thing. */
130#define __ptr_t void *
131
132
133/* C++ needs to know that types and declarations are C, not C++. */
134#ifdef __cplusplus
135# define __BEGIN_DECLS extern "C" {
136# define __END_DECLS }
137#else
138# define __BEGIN_DECLS
139# define __END_DECLS
140#endif
141
142
143/* Fortify support. */
144#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
145#define __bos0(ptr) __builtin_object_size (ptr, 0)
146
147/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
148#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \
149 || __GNUC_PREREQ (12, 0))
150# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
151# define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
152#else
153# define __glibc_objsize0(__o) __bos0 (__o)
154# define __glibc_objsize(__o) __bos (__o)
155#endif
156
157/* Compile time conditions to choose between the regular, _chk and _chk_warn
158 variants. These conditions should get evaluated to constant and optimized
159 away. */
160
161#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
162#define __glibc_unsigned_or_positive(__l) \
163 ((__typeof (__l)) 0 < (__typeof (__l)) -1 \
164 || (__builtin_constant_p (__l) && (__l) > 0))
165
166/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
167 condition can be folded to a constant and if it is true, or unknown (-1) */
168#define __glibc_safe_or_unknown_len(__l, __s, __osz) \
169 ((__osz) == (__SIZE_TYPE__) -1 \
170 || (__glibc_unsigned_or_positive (__l) \
171 && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
172 (__s), (__osz))) \
173 && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), (__s), (__osz))))
174
175/* Conversely, we know at compile time that the length is unsafe if the
176 __L * __S <= __OBJSZ condition can be folded to a constant and if it is
177 false. */
178#define __glibc_unsafe_len(__l, __s, __osz) \
179 (__glibc_unsigned_or_positive (__l) \
180 && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
181 __s, __osz)) \
182 && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
183
184/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
185 declared. */
186
187#define __glibc_fortify(f, __l, __s, __osz, ...) \
188 (__glibc_safe_or_unknown_len (__l, __s, __osz) \
189 ? __ ## f ## _alias (__VA_ARGS__) \
190 : (__glibc_unsafe_len (__l, __s, __osz) \
191 ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \
192 : __ ## f ## _chk (__VA_ARGS__, __osz))) \
193
194/* Fortify function f, where object size argument passed to f is the number of
195 elements and not total size. */
196
197#define __glibc_fortify_n(f, __l, __s, __osz, ...) \
198 (__glibc_safe_or_unknown_len (__l, __s, __osz) \
199 ? __ ## f ## _alias (__VA_ARGS__) \
200 : (__glibc_unsafe_len (__l, __s, __osz) \
201 ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \
202 : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \
203
204#if __GNUC_PREREQ (4,3)
205# define __warnattr(msg) __attribute__((__warning__ (msg)))
206# define __errordecl(name, msg) \
207 extern void name (void) __attribute__((__error__ (msg)))
208#else
209# define __warnattr(msg)
210# define __errordecl(name, msg) extern void name (void)
211#endif
212
213/* Support for flexible arrays.
214 Headers that should use flexible arrays only if they're "real"
215 (e.g. only if they won't affect sizeof()) should test
216 #if __glibc_c99_flexarr_available. */
217#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
218# define __flexarr []
219# define __glibc_c99_flexarr_available 1
220#elif __GNUC_PREREQ (2,97) || defined __clang__
221/* GCC 2.97 and clang support C99 flexible array members as an extension,
222 even when in C89 mode or compiling C++ (any version). */
223# define __flexarr []
224# define __glibc_c99_flexarr_available 1
225#elif defined __GNUC__
226/* Pre-2.97 GCC did not support C99 flexible arrays but did have
227 an equivalent extension with slightly different notation. */
228# define __flexarr [0]
229# define __glibc_c99_flexarr_available 1
230#else
231/* Some other non-C99 compiler. Approximate with [1]. */
232# define __flexarr [1]
233# define __glibc_c99_flexarr_available 0
234#endif
235
236
237/* __asm__ ("xyz") is used throughout the headers to rename functions
238 at the assembly language level. This is wrapped by the __REDIRECT
239 macro, in order to support compilers that can do this some other
240 way. When compilers don't support asm-names at all, we have to do
241 preprocessor tricks instead (which don't have exactly the right
242 semantics, but it's the best we can do).
243
244 Example:
245 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
246
247#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
248
249# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
250# ifdef __cplusplus
251# define __REDIRECT_NTH(name, proto, alias) \
252 name proto __THROW __asm__ (__ASMNAME (#alias))
253# define __REDIRECT_NTHNL(name, proto, alias) \
254 name proto __THROWNL __asm__ (__ASMNAME (#alias))
255# else
256# define __REDIRECT_NTH(name, proto, alias) \
257 name proto __asm__ (__ASMNAME (#alias)) __THROW
258# define __REDIRECT_NTHNL(name, proto, alias) \
259 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
260# endif
261# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
262# define __ASMNAME2(prefix, cname) __STRING (prefix) cname
263
264/*
265#elif __SOME_OTHER_COMPILER__
266
267# define __REDIRECT(name, proto, alias) name proto; \
268 _Pragma("let " #name " = " #alias)
269*/
270#endif
271
272/* GCC and clang have various useful declarations that can be made with
273 the '__attribute__' syntax. All of the ways we use this do fine if
274 they are omitted for compilers that don't understand it. */
275#if !(defined __GNUC__ || defined __clang__)
276# define __attribute__(xyz) /* Ignore */
277#endif
278
279/* At some point during the gcc 2.96 development the `malloc' attribute
280 for functions was introduced. We don't want to use it unconditionally
281 (although this would be possible) since it generates warnings. */
282#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
283# define __attribute_malloc__ __attribute__ ((__malloc__))
284#else
285# define __attribute_malloc__ /* Ignore */
286#endif
287
288/* Tell the compiler which arguments to an allocation function
289 indicate the size of the allocation. */
290#if __GNUC_PREREQ (4, 3)
291# define __attribute_alloc_size__(params) \
292 __attribute__ ((__alloc_size__ params))
293#else
294# define __attribute_alloc_size__(params) /* Ignore. */
295#endif
296
297/* Tell the compiler which argument to an allocation function
298 indicates the alignment of the allocation. */
299#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
300# define __attribute_alloc_align__(param) \
301 __attribute__ ((__alloc_align__ param))
302#else
303# define __attribute_alloc_align__(param) /* Ignore. */
304#endif
305
306/* At some point during the gcc 2.96 development the `pure' attribute
307 for functions was introduced. We don't want to use it unconditionally
308 (although this would be possible) since it generates warnings. */
309#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
310# define __attribute_pure__ __attribute__ ((__pure__))
311#else
312# define __attribute_pure__ /* Ignore */
313#endif
314
315/* This declaration tells the compiler that the value is constant. */
316#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
317# define __attribute_const__ __attribute__ ((__const__))
318#else
319# define __attribute_const__ /* Ignore */
320#endif
321
322#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
323# define __attribute_maybe_unused__ __attribute__ ((__unused__))
324#else
325# define __attribute_maybe_unused__ /* Ignore */
326#endif
327
328/* At some point during the gcc 3.1 development the `used' attribute
329 for functions was introduced. We don't want to use it unconditionally
330 (although this would be possible) since it generates warnings. */
331#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
332# define __attribute_used__ __attribute__ ((__used__))
333# define __attribute_noinline__ __attribute__ ((__noinline__))
334#else
335# define __attribute_used__ __attribute__ ((__unused__))
336# define __attribute_noinline__ /* Ignore */
337#endif
338
339/* Since version 3.2, gcc allows marking deprecated functions. */
340#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
341# define __attribute_deprecated__ __attribute__ ((__deprecated__))
342#else
343# define __attribute_deprecated__ /* Ignore */
344#endif
345
346/* Since version 4.5, gcc also allows one to specify the message printed
347 when a deprecated function is used. clang claims to be gcc 4.2, but
348 may also support this feature. */
349#if __GNUC_PREREQ (4,5) \
350 || __glibc_has_extension (__attribute_deprecated_with_message__)
351# define __attribute_deprecated_msg__(msg) \
352 __attribute__ ((__deprecated__ (msg)))
353#else
354# define __attribute_deprecated_msg__(msg) __attribute_deprecated__
355#endif
356
357/* At some point during the gcc 2.8 development the `format_arg' attribute
358 for functions was introduced. We don't want to use it unconditionally
359 (although this would be possible) since it generates warnings.
360 If several `format_arg' attributes are given for the same function, in
361 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
362 all designated arguments are considered. */
363#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
364# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
365#else
366# define __attribute_format_arg__(x) /* Ignore */
367#endif
368
369/* At some point during the gcc 2.97 development the `strfmon' format
370 attribute for functions was introduced. We don't want to use it
371 unconditionally (although this would be possible) since it
372 generates warnings. */
373#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
374# define __attribute_format_strfmon__(a,b) \
375 __attribute__ ((__format__ (__strfmon__, a, b)))
376#else
377# define __attribute_format_strfmon__(a,b) /* Ignore */
378#endif
379
380/* The nonnull function attribute marks pointer parameters that
381 must not be NULL. This has the name __nonnull in glibc,
382 and __attribute_nonnull__ in files shared with Gnulib to avoid
383 collision with a different __nonnull in DragonFlyBSD 5.9. */
384#ifndef __attribute_nonnull__
385# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
386# define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
387# else
388# define __attribute_nonnull__(params)
389# endif
390#endif
391#ifndef __nonnull
392# define __nonnull(params) __attribute_nonnull__ (params)
393#endif
394
395/* The returns_nonnull function attribute marks the return type of the function
396 as always being non-null. */
397#ifndef __returns_nonnull
398# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
399# define __returns_nonnull __attribute__ ((__returns_nonnull__))
400# else
401# define __returns_nonnull
402# endif
403#endif
404
405/* If fortification mode, we warn about unused results of certain
406 function calls which can lead to problems. */
407#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
408# define __attribute_warn_unused_result__ \
409 __attribute__ ((__warn_unused_result__))
410# if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
411# define __wur __attribute_warn_unused_result__
412# endif
413#else
414# define __attribute_warn_unused_result__ /* empty */
415#endif
416#ifndef __wur
417# define __wur /* Ignore */
418#endif
419
420/* Forces a function to be always inlined. */
421#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
422/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
423 it conflicts with this definition. Therefore undefine it first to
424 allow either header to be included first. */
425# undef __always_inline
426# define __always_inline __inline __attribute__ ((__always_inline__))
427#else
428# undef __always_inline
429# define __always_inline __inline
430#endif
431
432/* Associate error messages with the source location of the call site rather
433 than with the source location inside the function. */
434#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
435# define __attribute_artificial__ __attribute__ ((__artificial__))
436#else
437# define __attribute_artificial__ /* Ignore */
438#endif
439
440/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
441 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
442 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
443 older than 4.3 may define these macros and still not guarantee GNU inlining
444 semantics.
445
446 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
447 semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
448 __GNUC_GNU_INLINE__ macro definitions. */
449#if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
450 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
451 || defined __GNUC_GNU_INLINE__)))
452# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
453# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
454# define __extern_always_inline \
455 extern __always_inline __attribute__ ((__gnu_inline__))
456# else
457# define __extern_inline extern __inline
458# define __extern_always_inline extern __always_inline
459# endif
460#endif
461
462#ifdef __extern_always_inline
463# define __fortify_function __extern_always_inline __attribute_artificial__
464#endif
465
466/* GCC 4.3 and above allow passing all anonymous arguments of an
467 __extern_always_inline function to some other vararg function. */
468#if __GNUC_PREREQ (4,3)
469# define __va_arg_pack() __builtin_va_arg_pack ()
470# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
471#endif
472
473/* It is possible to compile containing GCC extensions even if GCC is
474 run in pedantic mode if the uses are carefully marked using the
475 `__extension__' keyword. But this is not generally available before
476 version 2.8. */
477#if !(__GNUC_PREREQ (2,8) || defined __clang__)
478# define __extension__ /* Ignore */
479#endif
480
481/* __restrict is known in EGCS 1.2 and above, and in clang.
482 It works also in C++ mode (outside of arrays), but only when spelled
483 as '__restrict', not 'restrict'. */
484#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
485# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
486# define __restrict restrict
487# else
488# define __restrict /* Ignore */
489# endif
490#endif
491
492/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
493 array_name[restrict]
494 GCC 3.1 and clang support this.
495 This syntax is not usable in C++ mode. */
496#if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
497# define __restrict_arr __restrict
498#else
499# ifdef __GNUC__
500# define __restrict_arr /* Not supported in old GCC. */
501# else
502# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
503# define __restrict_arr restrict
504# else
505/* Some other non-C99 compiler. */
506# define __restrict_arr /* Not supported. */
507# endif
508# endif
509#endif
510
511#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
512# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
513# define __glibc_likely(cond) __builtin_expect ((cond), 1)
514#else
515# define __glibc_unlikely(cond) (cond)
516# define __glibc_likely(cond) (cond)
517#endif
518
519#if (!defined _Noreturn \
520 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
521 && !(__GNUC_PREREQ (4,7) \
522 || (3 < __clang_major__ + (5 <= __clang_minor__))))
523# if __GNUC_PREREQ (2,8)
524# define _Noreturn __attribute__ ((__noreturn__))
525# else
526# define _Noreturn
527# endif
528#endif
529
530#if __GNUC_PREREQ (8, 0)
531/* Describes a char array whose address can safely be passed as the first
532 argument to strncpy and strncat, as the char array is not necessarily
533 a NUL-terminated string. */
534# define __attribute_nonstring__ __attribute__ ((__nonstring__))
535#else
536# define __attribute_nonstring__
537#endif
538
539/* Undefine (also defined in libc-symbols.h). */
540#undef __attribute_copy__
541#if __GNUC_PREREQ (9, 0)
542/* Copies attributes from the declaration or type referenced by
543 the argument. */
544# define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
545#else
546# define __attribute_copy__(arg)
547#endif
548
549#if (!defined _Static_assert && !defined __cplusplus \
550 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
551 && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
552 || defined __STRICT_ANSI__))
553# define _Static_assert(expr, diagnostic) \
554 extern int (*__Static_assert_function (void)) \
555 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
556#endif
557
558/* Gnulib avoids including these, as they don't work on non-glibc or
559 older glibc platforms. */
560#ifndef __GNULIB_CDEFS
561# include <bits/wordsize.h>
562# include <bits/long-double.h>
563#endif
564
565#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
566# ifdef __REDIRECT
567
568/* Alias name defined automatically. */
569# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
570# define __LDBL_REDIR_DECL(name) \
571 extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
572
573/* Alias name defined automatically, with leading underscores. */
574# define __LDBL_REDIR2_DECL(name) \
575 extern __typeof (__##name) __##name \
576 __asm (__ASMNAME ("__" #name "ieee128"));
577
578/* Alias name defined manually. */
579# define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
580# define __LDBL_REDIR1_DECL(name, alias) \
581 extern __typeof (name) name __asm (__ASMNAME (#alias));
582
583# define __LDBL_REDIR1_NTH(name, proto, alias) \
584 __REDIRECT_NTH (name, proto, alias)
585# define __REDIRECT_NTH_LDBL(name, proto, alias) \
586 __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
587
588/* Unused. */
589# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
590# define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
591
592# else
593_Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
594# endif
595#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
596# define __LDBL_COMPAT 1
597# ifdef __REDIRECT
598# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
599# define __LDBL_REDIR(name, proto) \
600 __LDBL_REDIR1 (name, proto, __nldbl_##name)
601# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
602# define __LDBL_REDIR_NTH(name, proto) \
603 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
604# define __LDBL_REDIR2_DECL(name) \
605 extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
606# define __LDBL_REDIR1_DECL(name, alias) \
607 extern __typeof (name) name __asm (__ASMNAME (#alias));
608# define __LDBL_REDIR_DECL(name) \
609 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
610# define __REDIRECT_LDBL(name, proto, alias) \
611 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
612# define __REDIRECT_NTH_LDBL(name, proto, alias) \
613 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
614# endif
615#endif
616#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
617 || !defined __REDIRECT
618# define __LDBL_REDIR1(name, proto, alias) name proto
619# define __LDBL_REDIR(name, proto) name proto
620# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
621# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
622# define __LDBL_REDIR2_DECL(name)
623# define __LDBL_REDIR_DECL(name)
624# ifdef __REDIRECT
625# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
626# define __REDIRECT_NTH_LDBL(name, proto, alias) \
627 __REDIRECT_NTH (name, proto, alias)
628# endif
629#endif
630
631/* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
632 intended for use in preprocessor macros.
633
634 Note: MESSAGE must be a _single_ string; concatenation of string
635 literals is not supported. */
636#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
637# define __glibc_macro_warning1(message) _Pragma (#message)
638# define __glibc_macro_warning(message) \
639 __glibc_macro_warning1 (GCC warning message)
640#else
641# define __glibc_macro_warning(msg)
642#endif
643
644/* Generic selection (ISO C11) is a C-only feature, available in GCC
645 since version 4.9. Previous versions do not provide generic
646 selection, even though they might set __STDC_VERSION__ to 201112L,
647 when in -std=c11 mode. Thus, we must check for !defined __GNUC__
648 when testing __STDC_VERSION__ for generic selection support.
649 On the other hand, Clang also defines __GNUC__, so a clang-specific
650 check is required to enable the use of generic selection. */
651#if !defined __cplusplus \
652 && (__GNUC_PREREQ (4, 9) \
653 || __glibc_has_extension (c_generic_selections) \
654 || (!defined __GNUC__ && defined __STDC_VERSION__ \
655 && __STDC_VERSION__ >= 201112L))
656# define __HAVE_GENERIC_SELECTION 1
657#else
658# define __HAVE_GENERIC_SELECTION 0
659#endif
660
661#if __GNUC_PREREQ (10, 0)
662/* Designates a 1-based positional argument ref-index of pointer type
663 that can be used to access size-index elements of the pointed-to
664 array according to access mode, or at least one element when
665 size-index is not provided:
666 access (access-mode, <ref-index> [, <size-index>]) */
667# define __attr_access(x) __attribute__ ((__access__ x))
668/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
669 use the access attribute to get object sizes from function definition
670 arguments, so we can't use them on functions we fortify. Drop the object
671 size hints for such functions. */
672# if __USE_FORTIFY_LEVEL == 3
673# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
674# else
675# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
676# endif
677# if __GNUC_PREREQ (11, 0)
678# define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
679# else
680# define __attr_access_none(argno)
681# endif
682#else
683# define __fortified_attr_access(a, o, s)
684# define __attr_access(x)
685# define __attr_access_none(argno)
686#endif
687
688#if __GNUC_PREREQ (11, 0)
689/* Designates dealloc as a function to call to deallocate objects
690 allocated by the declared function. */
691# define __attr_dealloc(dealloc, argno) \
692 __attribute__ ((__malloc__ (dealloc, argno)))
693# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
694#else
695# define __attr_dealloc(dealloc, argno)
696# define __attr_dealloc_free
697#endif
698
699/* Specify that a function such as setjmp or vfork may return
700 twice. */
701#if __GNUC_PREREQ (4, 1)
702# define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
703#else
704# define __attribute_returns_twice__ /* Ignore. */
705#endif
706
707#endif /* sys/cdefs.h */
diff --git a/gl/cloexec.c b/gl/cloexec.c
new file mode 100644
index 0000000..e4cecbd
--- /dev/null
+++ b/gl/cloexec.c
@@ -0,0 +1,83 @@
1/* cloexec.c - set or clear the close-on-exec descriptor flag
2
3 Copyright (C) 1991, 2004-2006, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* The code is taken from glibc/manual/llio.texi */
19
20#include <config.h>
21
22#include "cloexec.h"
23
24#include <errno.h>
25#include <fcntl.h>
26#include <unistd.h>
27
28/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
29 or clear the flag if VALUE is false.
30 Return 0 on success, or -1 on error with 'errno' set.
31
32 Note that on MingW, this function does NOT protect DESC from being
33 inherited into spawned children. Instead, either use dup_cloexec
34 followed by closing the original DESC, or use interfaces such as
35 open or pipe2 that accept flags like O_CLOEXEC to create DESC
36 non-inheritable in the first place. */
37
38int
39set_cloexec_flag (int desc, bool value)
40{
41#ifdef F_SETFD
42
43 int flags = fcntl (desc, F_GETFD, 0);
44
45 if (0 <= flags)
46 {
47 int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
48
49 if (flags == newflags
50 || fcntl (desc, F_SETFD, newflags) != -1)
51 return 0;
52 }
53
54 return -1;
55
56#else /* !F_SETFD */
57
58 /* Use dup2 to reject invalid file descriptors; the cloexec flag
59 will be unaffected. */
60 if (desc < 0)
61 {
62 errno = EBADF;
63 return -1;
64 }
65 if (dup2 (desc, desc) < 0)
66 /* errno is EBADF here. */
67 return -1;
68
69 /* There is nothing we can do on this kind of platform. Punt. */
70 return 0;
71#endif /* !F_SETFD */
72}
73
74
75/* Duplicates a file handle FD, while marking the copy to be closed
76 prior to exec or spawn. Returns -1 and sets errno if FD could not
77 be duplicated. */
78
79int
80dup_cloexec (int fd)
81{
82 return fcntl (fd, F_DUPFD_CLOEXEC, 0);
83}
diff --git a/gl/cloexec.h b/gl/cloexec.h
new file mode 100644
index 0000000..057fd66
--- /dev/null
+++ b/gl/cloexec.h
@@ -0,0 +1,34 @@
1/* cloexec.c - set or clear the close-on-exec descriptor flag
2
3 Copyright (C) 2004, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
19 or clear the flag if VALUE is false.
20 Return 0 on success, or -1 on error with 'errno' set.
21
22 Note that on MingW, this function does NOT protect DESC from being
23 inherited into spawned children. Instead, either use dup_cloexec
24 followed by closing the original DESC, or use interfaces such as
25 open or pipe2 that accept flags like O_CLOEXEC to create DESC
26 non-inheritable in the first place. */
27
28int set_cloexec_flag (int desc, bool value);
29
30/* Duplicates a file handle FD, while marking the copy to be closed
31 prior to exec or spawn. Returns -1 and sets errno if FD could not
32 be duplicated. */
33
34int dup_cloexec (int fd);
diff --git a/gl/close.c b/gl/close.c
new file mode 100644
index 0000000..3c1b09e
--- /dev/null
+++ b/gl/close.c
@@ -0,0 +1,75 @@
1/* close replacement.
2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <unistd.h>
21
22#include <errno.h>
23
24#include "fd-hook.h"
25#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
26# include "msvc-inval.h"
27#endif
28
29#undef close
30
31#if defined _WIN32 && !defined __CYGWIN__
32# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
33static int
34close_nothrow (int fd)
35{
36 int result;
37
38 TRY_MSVC_INVAL
39 {
40 result = _close (fd);
41 }
42 CATCH_MSVC_INVAL
43 {
44 result = -1;
45 errno = EBADF;
46 }
47 DONE_MSVC_INVAL;
48
49 return result;
50}
51# else
52# define close_nothrow _close
53# endif
54#else
55# define close_nothrow close
56#endif
57
58/* Override close() to call into other gnulib modules. */
59
60int
61rpl_close (int fd)
62{
63#if WINDOWS_SOCKETS
64 int retval = execute_all_close_hooks (close_nothrow, fd);
65#else
66 int retval = close_nothrow (fd);
67#endif
68
69#if REPLACE_FCHDIR
70 if (retval >= 0)
71 _gl_unregister_fd (fd);
72#endif
73
74 return retval;
75}
diff --git a/gl/config.charset b/gl/config.charset
deleted file mode 100644
index a991419..0000000
--- a/gl/config.charset
+++ /dev/null
@@ -1,684 +0,0 @@
1#! /bin/sh
2# Output a system dependent table of character encoding aliases.
3#
4# Copyright (C) 2000-2004, 2006-2013 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, see <http://www.gnu.org/licenses/>.
18#
19# The table consists of lines of the form
20# ALIAS CANONICAL
21#
22# ALIAS is the (system dependent) result of "nl_langinfo (CODESET)".
23# ALIAS is compared in a case sensitive way.
24#
25# CANONICAL is the GNU canonical name for this character encoding.
26# It must be an encoding supported by libiconv. Support by GNU libc is
27# also desirable. CANONICAL is case insensitive. Usually an upper case
28# MIME charset name is preferred.
29# The current list of GNU canonical charset names is as follows.
30#
31# name MIME? used by which systems
32# (darwin = Mac OS X, woe32 = native Windows)
33#
34# ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin cygwin
35# ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin
36# ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin
37# ISO-8859-3 Y glibc solaris cygwin
38# ISO-8859-4 Y osf solaris freebsd netbsd openbsd darwin
39# ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin
40# ISO-8859-6 Y glibc aix hpux solaris cygwin
41# ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd openbsd darwin cygwin
42# ISO-8859-8 Y glibc aix hpux osf solaris cygwin
43# ISO-8859-9 Y glibc aix hpux irix osf solaris darwin cygwin
44# ISO-8859-13 glibc netbsd openbsd darwin cygwin
45# ISO-8859-14 glibc cygwin
46# ISO-8859-15 glibc aix osf solaris freebsd netbsd openbsd darwin cygwin
47# KOI8-R Y glibc solaris freebsd netbsd openbsd darwin
48# KOI8-U Y glibc freebsd netbsd openbsd darwin cygwin
49# KOI8-T glibc
50# CP437 dos
51# CP775 dos
52# CP850 aix osf dos
53# CP852 dos
54# CP855 dos
55# CP856 aix
56# CP857 dos
57# CP861 dos
58# CP862 dos
59# CP864 dos
60# CP865 dos
61# CP866 freebsd netbsd openbsd darwin dos
62# CP869 dos
63# CP874 woe32 dos
64# CP922 aix
65# CP932 aix cygwin woe32 dos
66# CP943 aix
67# CP949 osf darwin woe32 dos
68# CP950 woe32 dos
69# CP1046 aix
70# CP1124 aix
71# CP1125 dos
72# CP1129 aix
73# CP1131 darwin
74# CP1250 woe32
75# CP1251 glibc solaris netbsd openbsd darwin cygwin woe32
76# CP1252 aix woe32
77# CP1253 woe32
78# CP1254 woe32
79# CP1255 glibc woe32
80# CP1256 woe32
81# CP1257 woe32
82# GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin
83# EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin
84# EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin
85# EUC-TW glibc aix hpux irix osf solaris netbsd
86# BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin
87# BIG5-HKSCS glibc solaris darwin
88# GBK glibc aix osf solaris darwin cygwin woe32 dos
89# GB18030 glibc solaris netbsd darwin
90# SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin
91# JOHAB glibc solaris woe32
92# TIS-620 glibc aix hpux osf solaris cygwin
93# VISCII Y glibc
94# TCVN5712-1 glibc
95# ARMSCII-8 glibc darwin
96# GEORGIAN-PS glibc cygwin
97# PT154 glibc
98# HP-ROMAN8 hpux
99# HP-ARABIC8 hpux
100# HP-GREEK8 hpux
101# HP-HEBREW8 hpux
102# HP-TURKISH8 hpux
103# HP-KANA8 hpux
104# DEC-KANJI osf
105# DEC-HANYU osf
106# UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin
107#
108# Note: Names which are not marked as being a MIME name should not be used in
109# Internet protocols for information interchange (mail, news, etc.).
110#
111# Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
112# must understand both names and treat them as equivalent.
113#
114# The first argument passed to this file is the canonical host specification,
115# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
116# or
117# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
118
119host="$1"
120os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'`
121echo "# This file contains a table of character encoding aliases,"
122echo "# suitable for operating system '${os}'."
123echo "# It was automatically generated from config.charset."
124# List of references, updated during installation:
125echo "# Packages using this file: "
126case "$os" in
127 linux-gnulibc1*)
128 # Linux libc5 doesn't have nl_langinfo(CODESET); therefore
129 # localcharset.c falls back to using the full locale name
130 # from the environment variables.
131 echo "C ASCII"
132 echo "POSIX ASCII"
133 for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \
134 en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \
135 en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \
136 es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \
137 et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \
138 fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \
139 it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \
140 sv_FI sv_SE; do
141 echo "$l ISO-8859-1"
142 echo "$l.iso-8859-1 ISO-8859-1"
143 echo "$l.iso-8859-15 ISO-8859-15"
144 echo "$l.iso-8859-15@euro ISO-8859-15"
145 echo "$l@euro ISO-8859-15"
146 echo "$l.cp-437 CP437"
147 echo "$l.cp-850 CP850"
148 echo "$l.cp-1252 CP1252"
149 echo "$l.cp-1252@euro CP1252"
150 #echo "$l.atari-st ATARI-ST" # not a commonly used encoding
151 echo "$l.utf-8 UTF-8"
152 echo "$l.utf-8@euro UTF-8"
153 done
154 for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \
155 sl_SI sr sr_CS sr_YU; do
156 echo "$l ISO-8859-2"
157 echo "$l.iso-8859-2 ISO-8859-2"
158 echo "$l.cp-852 CP852"
159 echo "$l.cp-1250 CP1250"
160 echo "$l.utf-8 UTF-8"
161 done
162 for l in mk mk_MK ru ru_RU; do
163 echo "$l ISO-8859-5"
164 echo "$l.iso-8859-5 ISO-8859-5"
165 echo "$l.koi8-r KOI8-R"
166 echo "$l.cp-866 CP866"
167 echo "$l.cp-1251 CP1251"
168 echo "$l.utf-8 UTF-8"
169 done
170 for l in ar ar_SA; do
171 echo "$l ISO-8859-6"
172 echo "$l.iso-8859-6 ISO-8859-6"
173 echo "$l.cp-864 CP864"
174 #echo "$l.cp-868 CP868" # not a commonly used encoding
175 echo "$l.cp-1256 CP1256"
176 echo "$l.utf-8 UTF-8"
177 done
178 for l in el el_GR gr gr_GR; do
179 echo "$l ISO-8859-7"
180 echo "$l.iso-8859-7 ISO-8859-7"
181 echo "$l.cp-869 CP869"
182 echo "$l.cp-1253 CP1253"
183 echo "$l.cp-1253@euro CP1253"
184 echo "$l.utf-8 UTF-8"
185 echo "$l.utf-8@euro UTF-8"
186 done
187 for l in he he_IL iw iw_IL; do
188 echo "$l ISO-8859-8"
189 echo "$l.iso-8859-8 ISO-8859-8"
190 echo "$l.cp-862 CP862"
191 echo "$l.cp-1255 CP1255"
192 echo "$l.utf-8 UTF-8"
193 done
194 for l in tr tr_TR; do
195 echo "$l ISO-8859-9"
196 echo "$l.iso-8859-9 ISO-8859-9"
197 echo "$l.cp-857 CP857"
198 echo "$l.cp-1254 CP1254"
199 echo "$l.utf-8 UTF-8"
200 done
201 for l in lt lt_LT lv lv_LV; do
202 #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name
203 echo "$l ISO-8859-13"
204 done
205 for l in ru_UA uk uk_UA; do
206 echo "$l KOI8-U"
207 done
208 for l in zh zh_CN; do
209 #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name
210 echo "$l GB2312"
211 done
212 for l in ja ja_JP ja_JP.EUC; do
213 echo "$l EUC-JP"
214 done
215 for l in ko ko_KR; do
216 echo "$l EUC-KR"
217 done
218 for l in th th_TH; do
219 echo "$l TIS-620"
220 done
221 for l in fa fa_IR; do
222 #echo "$l ISIRI-3342" # a broken encoding
223 echo "$l.utf-8 UTF-8"
224 done
225 ;;
226 linux* | *-gnu*)
227 # With glibc-2.1 or newer, we don't need any canonicalization,
228 # because glibc has iconv and both glibc and libiconv support all
229 # GNU canonical names directly. Therefore, the Makefile does not
230 # need to install the alias file at all.
231 # The following applies only to glibc-2.0.x and older libcs.
232 echo "ISO_646.IRV:1983 ASCII"
233 ;;
234 aix*)
235 echo "ISO8859-1 ISO-8859-1"
236 echo "ISO8859-2 ISO-8859-2"
237 echo "ISO8859-5 ISO-8859-5"
238 echo "ISO8859-6 ISO-8859-6"
239 echo "ISO8859-7 ISO-8859-7"
240 echo "ISO8859-8 ISO-8859-8"
241 echo "ISO8859-9 ISO-8859-9"
242 echo "ISO8859-15 ISO-8859-15"
243 echo "IBM-850 CP850"
244 echo "IBM-856 CP856"
245 echo "IBM-921 ISO-8859-13"
246 echo "IBM-922 CP922"
247 echo "IBM-932 CP932"
248 echo "IBM-943 CP943"
249 echo "IBM-1046 CP1046"
250 echo "IBM-1124 CP1124"
251 echo "IBM-1129 CP1129"
252 echo "IBM-1252 CP1252"
253 echo "IBM-eucCN GB2312"
254 echo "IBM-eucJP EUC-JP"
255 echo "IBM-eucKR EUC-KR"
256 echo "IBM-eucTW EUC-TW"
257 echo "big5 BIG5"
258 echo "GBK GBK"
259 echo "TIS-620 TIS-620"
260 echo "UTF-8 UTF-8"
261 ;;
262 hpux*)
263 echo "iso88591 ISO-8859-1"
264 echo "iso88592 ISO-8859-2"
265 echo "iso88595 ISO-8859-5"
266 echo "iso88596 ISO-8859-6"
267 echo "iso88597 ISO-8859-7"
268 echo "iso88598 ISO-8859-8"
269 echo "iso88599 ISO-8859-9"
270 echo "iso885915 ISO-8859-15"
271 echo "roman8 HP-ROMAN8"
272 echo "arabic8 HP-ARABIC8"
273 echo "greek8 HP-GREEK8"
274 echo "hebrew8 HP-HEBREW8"
275 echo "turkish8 HP-TURKISH8"
276 echo "kana8 HP-KANA8"
277 echo "tis620 TIS-620"
278 echo "big5 BIG5"
279 echo "eucJP EUC-JP"
280 echo "eucKR EUC-KR"
281 echo "eucTW EUC-TW"
282 echo "hp15CN GB2312"
283 #echo "ccdc ?" # what is this?
284 echo "SJIS SHIFT_JIS"
285 echo "utf8 UTF-8"
286 ;;
287 irix*)
288 echo "ISO8859-1 ISO-8859-1"
289 echo "ISO8859-2 ISO-8859-2"
290 echo "ISO8859-5 ISO-8859-5"
291 echo "ISO8859-7 ISO-8859-7"
292 echo "ISO8859-9 ISO-8859-9"
293 echo "eucCN GB2312"
294 echo "eucJP EUC-JP"
295 echo "eucKR EUC-KR"
296 echo "eucTW EUC-TW"
297 ;;
298 osf*)
299 echo "ISO8859-1 ISO-8859-1"
300 echo "ISO8859-2 ISO-8859-2"
301 echo "ISO8859-4 ISO-8859-4"
302 echo "ISO8859-5 ISO-8859-5"
303 echo "ISO8859-7 ISO-8859-7"
304 echo "ISO8859-8 ISO-8859-8"
305 echo "ISO8859-9 ISO-8859-9"
306 echo "ISO8859-15 ISO-8859-15"
307 echo "cp850 CP850"
308 echo "big5 BIG5"
309 echo "dechanyu DEC-HANYU"
310 echo "dechanzi GB2312"
311 echo "deckanji DEC-KANJI"
312 echo "deckorean EUC-KR"
313 echo "eucJP EUC-JP"
314 echo "eucKR EUC-KR"
315 echo "eucTW EUC-TW"
316 echo "GBK GBK"
317 echo "KSC5601 CP949"
318 echo "sdeckanji EUC-JP"
319 echo "SJIS SHIFT_JIS"
320 echo "TACTIS TIS-620"
321 echo "UTF-8 UTF-8"
322 ;;
323 solaris*)
324 echo "646 ASCII"
325 echo "ISO8859-1 ISO-8859-1"
326 echo "ISO8859-2 ISO-8859-2"
327 echo "ISO8859-3 ISO-8859-3"
328 echo "ISO8859-4 ISO-8859-4"
329 echo "ISO8859-5 ISO-8859-5"
330 echo "ISO8859-6 ISO-8859-6"
331 echo "ISO8859-7 ISO-8859-7"
332 echo "ISO8859-8 ISO-8859-8"
333 echo "ISO8859-9 ISO-8859-9"
334 echo "ISO8859-15 ISO-8859-15"
335 echo "koi8-r KOI8-R"
336 echo "ansi-1251 CP1251"
337 echo "BIG5 BIG5"
338 echo "Big5-HKSCS BIG5-HKSCS"
339 echo "gb2312 GB2312"
340 echo "GBK GBK"
341 echo "GB18030 GB18030"
342 echo "cns11643 EUC-TW"
343 echo "5601 EUC-KR"
344 echo "ko_KR.johap92 JOHAB"
345 echo "eucJP EUC-JP"
346 echo "PCK SHIFT_JIS"
347 echo "TIS620.2533 TIS-620"
348 #echo "sun_eu_greek ?" # what is this?
349 echo "UTF-8 UTF-8"
350 ;;
351 freebsd* | os2*)
352 # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
353 # localcharset.c falls back to using the full locale name
354 # from the environment variables.
355 # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
356 # reuse FreeBSD's locale data for OS/2.
357 echo "C ASCII"
358 echo "US-ASCII ASCII"
359 for l in la_LN lt_LN; do
360 echo "$l.ASCII ASCII"
361 done
362 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
363 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \
364 lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do
365 echo "$l.ISO_8859-1 ISO-8859-1"
366 echo "$l.DIS_8859-15 ISO-8859-15"
367 done
368 for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do
369 echo "$l.ISO_8859-2 ISO-8859-2"
370 done
371 for l in la_LN lt_LT; do
372 echo "$l.ISO_8859-4 ISO-8859-4"
373 done
374 for l in ru_RU ru_SU; do
375 echo "$l.KOI8-R KOI8-R"
376 echo "$l.ISO_8859-5 ISO-8859-5"
377 echo "$l.CP866 CP866"
378 done
379 echo "uk_UA.KOI8-U KOI8-U"
380 echo "zh_TW.BIG5 BIG5"
381 echo "zh_TW.Big5 BIG5"
382 echo "zh_CN.EUC GB2312"
383 echo "ja_JP.EUC EUC-JP"
384 echo "ja_JP.SJIS SHIFT_JIS"
385 echo "ja_JP.Shift_JIS SHIFT_JIS"
386 echo "ko_KR.EUC EUC-KR"
387 ;;
388 netbsd*)
389 echo "646 ASCII"
390 echo "ISO8859-1 ISO-8859-1"
391 echo "ISO8859-2 ISO-8859-2"
392 echo "ISO8859-4 ISO-8859-4"
393 echo "ISO8859-5 ISO-8859-5"
394 echo "ISO8859-7 ISO-8859-7"
395 echo "ISO8859-13 ISO-8859-13"
396 echo "ISO8859-15 ISO-8859-15"
397 echo "eucCN GB2312"
398 echo "eucJP EUC-JP"
399 echo "eucKR EUC-KR"
400 echo "eucTW EUC-TW"
401 echo "BIG5 BIG5"
402 echo "SJIS SHIFT_JIS"
403 ;;
404 openbsd*)
405 echo "646 ASCII"
406 echo "ISO8859-1 ISO-8859-1"
407 echo "ISO8859-2 ISO-8859-2"
408 echo "ISO8859-4 ISO-8859-4"
409 echo "ISO8859-5 ISO-8859-5"
410 echo "ISO8859-7 ISO-8859-7"
411 echo "ISO8859-13 ISO-8859-13"
412 echo "ISO8859-15 ISO-8859-15"
413 ;;
414 darwin[56]*)
415 # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore
416 # localcharset.c falls back to using the full locale name
417 # from the environment variables.
418 echo "C ASCII"
419 for l in en_AU en_CA en_GB en_US la_LN; do
420 echo "$l.US-ASCII ASCII"
421 done
422 for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
423 fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \
424 nl_NL no_NO pt_PT sv_SE; do
425 echo "$l ISO-8859-1"
426 echo "$l.ISO8859-1 ISO-8859-1"
427 echo "$l.ISO8859-15 ISO-8859-15"
428 done
429 for l in la_LN; do
430 echo "$l.ISO8859-1 ISO-8859-1"
431 echo "$l.ISO8859-15 ISO-8859-15"
432 done
433 for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do
434 echo "$l.ISO8859-2 ISO-8859-2"
435 done
436 for l in la_LN lt_LT; do
437 echo "$l.ISO8859-4 ISO-8859-4"
438 done
439 for l in ru_RU; do
440 echo "$l.KOI8-R KOI8-R"
441 echo "$l.ISO8859-5 ISO-8859-5"
442 echo "$l.CP866 CP866"
443 done
444 for l in bg_BG; do
445 echo "$l.CP1251 CP1251"
446 done
447 echo "uk_UA.KOI8-U KOI8-U"
448 echo "zh_TW.BIG5 BIG5"
449 echo "zh_TW.Big5 BIG5"
450 echo "zh_CN.EUC GB2312"
451 echo "ja_JP.EUC EUC-JP"
452 echo "ja_JP.SJIS SHIFT_JIS"
453 echo "ko_KR.EUC EUC-KR"
454 ;;
455 darwin*)
456 # Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is
457 # useless:
458 # - It returns the empty string when LANG is set to a locale of the
459 # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
460 # LC_CTYPE file.
461 # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
462 # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
463 # - The documentation says:
464 # "... all code that calls BSD system routines should ensure
465 # that the const *char parameters of these routines are in UTF-8
466 # encoding. All BSD system functions expect their string
467 # parameters to be in UTF-8 encoding and nothing else."
468 # It also says
469 # "An additional caveat is that string parameters for files,
470 # paths, and other file-system entities must be in canonical
471 # UTF-8. In a canonical UTF-8 Unicode string, all decomposable
472 # characters are decomposed ..."
473 # but this is not true: You can pass non-decomposed UTF-8 strings
474 # to file system functions, and it is the OS which will convert
475 # them to decomposed UTF-8 before accessing the file system.
476 # - The Apple Terminal application displays UTF-8 by default.
477 # - However, other applications are free to use different encodings:
478 # - xterm uses ISO-8859-1 by default.
479 # - TextEdit uses MacRoman by default.
480 # We prefer UTF-8 over decomposed UTF-8-MAC because one should
481 # minimize the use of decomposed Unicode. Unfortunately, through the
482 # Darwin file system, decomposed UTF-8 strings are leaked into user
483 # space nevertheless.
484 # Then there are also the locales with encodings other than US-ASCII
485 # and UTF-8. These locales can be occasionally useful to users (e.g.
486 # when grepping through ISO-8859-1 encoded text files), when all their
487 # file names are in US-ASCII.
488 echo "ISO8859-1 ISO-8859-1"
489 echo "ISO8859-2 ISO-8859-2"
490 echo "ISO8859-4 ISO-8859-4"
491 echo "ISO8859-5 ISO-8859-5"
492 echo "ISO8859-7 ISO-8859-7"
493 echo "ISO8859-9 ISO-8859-9"
494 echo "ISO8859-13 ISO-8859-13"
495 echo "ISO8859-15 ISO-8859-15"
496 echo "KOI8-R KOI8-R"
497 echo "KOI8-U KOI8-U"
498 echo "CP866 CP866"
499 echo "CP949 CP949"
500 echo "CP1131 CP1131"
501 echo "CP1251 CP1251"
502 echo "eucCN GB2312"
503 echo "GB2312 GB2312"
504 echo "eucJP EUC-JP"
505 echo "eucKR EUC-KR"
506 echo "Big5 BIG5"
507 echo "Big5HKSCS BIG5-HKSCS"
508 echo "GBK GBK"
509 echo "GB18030 GB18030"
510 echo "SJIS SHIFT_JIS"
511 echo "ARMSCII-8 ARMSCII-8"
512 echo "PT154 PT154"
513 #echo "ISCII-DEV ?"
514 echo "* UTF-8"
515 ;;
516 beos* | haiku*)
517 # BeOS and Haiku have a single locale, and it has UTF-8 encoding.
518 echo "* UTF-8"
519 ;;
520 msdosdjgpp*)
521 # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore
522 # localcharset.c falls back to using the full locale name
523 # from the environment variables.
524 echo "#"
525 echo "# The encodings given here may not all be correct."
526 echo "# If you find that the encoding given for your language and"
527 echo "# country is not the one your DOS machine actually uses, just"
528 echo "# correct it in this file, and send a mail to"
529 echo "# Juan Manuel Guerrero <juan.guerrero@gmx.de>"
530 echo "# and Bruno Haible <bruno@clisp.org>."
531 echo "#"
532 echo "C ASCII"
533 # ISO-8859-1 languages
534 echo "ca CP850"
535 echo "ca_ES CP850"
536 echo "da CP865" # not CP850 ??
537 echo "da_DK CP865" # not CP850 ??
538 echo "de CP850"
539 echo "de_AT CP850"
540 echo "de_CH CP850"
541 echo "de_DE CP850"
542 echo "en CP850"
543 echo "en_AU CP850" # not CP437 ??
544 echo "en_CA CP850"
545 echo "en_GB CP850"
546 echo "en_NZ CP437"
547 echo "en_US CP437"
548 echo "en_ZA CP850" # not CP437 ??
549 echo "es CP850"
550 echo "es_AR CP850"
551 echo "es_BO CP850"
552 echo "es_CL CP850"
553 echo "es_CO CP850"
554 echo "es_CR CP850"
555 echo "es_CU CP850"
556 echo "es_DO CP850"
557 echo "es_EC CP850"
558 echo "es_ES CP850"
559 echo "es_GT CP850"
560 echo "es_HN CP850"
561 echo "es_MX CP850"
562 echo "es_NI CP850"
563 echo "es_PA CP850"
564 echo "es_PY CP850"
565 echo "es_PE CP850"
566 echo "es_SV CP850"
567 echo "es_UY CP850"
568 echo "es_VE CP850"
569 echo "et CP850"
570 echo "et_EE CP850"
571 echo "eu CP850"
572 echo "eu_ES CP850"
573 echo "fi CP850"
574 echo "fi_FI CP850"
575 echo "fr CP850"
576 echo "fr_BE CP850"
577 echo "fr_CA CP850"
578 echo "fr_CH CP850"
579 echo "fr_FR CP850"
580 echo "ga CP850"
581 echo "ga_IE CP850"
582 echo "gd CP850"
583 echo "gd_GB CP850"
584 echo "gl CP850"
585 echo "gl_ES CP850"
586 echo "id CP850" # not CP437 ??
587 echo "id_ID CP850" # not CP437 ??
588 echo "is CP861" # not CP850 ??
589 echo "is_IS CP861" # not CP850 ??
590 echo "it CP850"
591 echo "it_CH CP850"
592 echo "it_IT CP850"
593 echo "lt CP775"
594 echo "lt_LT CP775"
595 echo "lv CP775"
596 echo "lv_LV CP775"
597 echo "nb CP865" # not CP850 ??
598 echo "nb_NO CP865" # not CP850 ??
599 echo "nl CP850"
600 echo "nl_BE CP850"
601 echo "nl_NL CP850"
602 echo "nn CP865" # not CP850 ??
603 echo "nn_NO CP865" # not CP850 ??
604 echo "no CP865" # not CP850 ??
605 echo "no_NO CP865" # not CP850 ??
606 echo "pt CP850"
607 echo "pt_BR CP850"
608 echo "pt_PT CP850"
609 echo "sv CP850"
610 echo "sv_SE CP850"
611 # ISO-8859-2 languages
612 echo "cs CP852"
613 echo "cs_CZ CP852"
614 echo "hr CP852"
615 echo "hr_HR CP852"
616 echo "hu CP852"
617 echo "hu_HU CP852"
618 echo "pl CP852"
619 echo "pl_PL CP852"
620 echo "ro CP852"
621 echo "ro_RO CP852"
622 echo "sk CP852"
623 echo "sk_SK CP852"
624 echo "sl CP852"
625 echo "sl_SI CP852"
626 echo "sq CP852"
627 echo "sq_AL CP852"
628 echo "sr CP852" # CP852 or CP866 or CP855 ??
629 echo "sr_CS CP852" # CP852 or CP866 or CP855 ??
630 echo "sr_YU CP852" # CP852 or CP866 or CP855 ??
631 # ISO-8859-3 languages
632 echo "mt CP850"
633 echo "mt_MT CP850"
634 # ISO-8859-5 languages
635 echo "be CP866"
636 echo "be_BE CP866"
637 echo "bg CP866" # not CP855 ??
638 echo "bg_BG CP866" # not CP855 ??
639 echo "mk CP866" # not CP855 ??
640 echo "mk_MK CP866" # not CP855 ??
641 echo "ru CP866"
642 echo "ru_RU CP866"
643 echo "uk CP1125"
644 echo "uk_UA CP1125"
645 # ISO-8859-6 languages
646 echo "ar CP864"
647 echo "ar_AE CP864"
648 echo "ar_DZ CP864"
649 echo "ar_EG CP864"
650 echo "ar_IQ CP864"
651 echo "ar_IR CP864"
652 echo "ar_JO CP864"
653 echo "ar_KW CP864"
654 echo "ar_MA CP864"
655 echo "ar_OM CP864"
656 echo "ar_QA CP864"
657 echo "ar_SA CP864"
658 echo "ar_SY CP864"
659 # ISO-8859-7 languages
660 echo "el CP869"
661 echo "el_GR CP869"
662 # ISO-8859-8 languages
663 echo "he CP862"
664 echo "he_IL CP862"
665 # ISO-8859-9 languages
666 echo "tr CP857"
667 echo "tr_TR CP857"
668 # Japanese
669 echo "ja CP932"
670 echo "ja_JP CP932"
671 # Chinese
672 echo "zh_CN GBK"
673 echo "zh_TW CP950" # not CP938 ??
674 # Korean
675 echo "kr CP949" # not CP934 ??
676 echo "kr_KR CP949" # not CP934 ??
677 # Thai
678 echo "th CP874"
679 echo "th_TH CP874"
680 # Other
681 echo "eo CP850"
682 echo "eo_EO CP850"
683 ;;
684esac
diff --git a/gl/dirname-lgpl.c b/gl/dirname-lgpl.c
index 82f6630..e9454af 100644
--- a/gl/dirname-lgpl.c
+++ b/gl/dirname-lgpl.c
@@ -1,20 +1,20 @@
1/* dirname.c -- return all but the last element in a file name 1/* dirname.c -- return all but the last element in a file name
2 2
3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2023 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 file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 2.1 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
diff --git a/gl/dirname.c b/gl/dirname.c
index 1fb6588..e72f713 100644
--- a/gl/dirname.c
+++ b/gl/dirname.c
@@ -1,11 +1,11 @@
1/* dirname.c -- return all but the last element in a file name 1/* dirname.c -- return all but the last element in a file name
2 2
3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2023 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 3 of the License, or 8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) 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,
@@ -14,7 +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, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
diff --git a/gl/dirname.h b/gl/dirname.h
index 4ad0312..f98e83b 100644
--- a/gl/dirname.h
+++ b/gl/dirname.h
@@ -1,46 +1,53 @@
1/* Take file names apart into directory and base names. 1/* Take file names apart into directory and base names.
2 2
3 Copyright (C) 1998, 2001, 2003-2006, 2009-2013 Free Software Foundation, 3 Copyright (C) 1998, 2001, 2003-2006, 2009-2023 Free Software Foundation,
4 Inc. 4 Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 2.1 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#ifndef DIRNAME_H_ 19#ifndef DIRNAME_H_
20# define DIRNAME_H_ 1 20# define DIRNAME_H_ 1
21 21
22# include <stdbool.h> 22# include <stdlib.h>
23# include <stddef.h> 23# include "filename.h"
24# include "dosname.h" 24# include "basename-lgpl.h"
25 25
26# ifndef DIRECTORY_SEPARATOR 26# ifndef DIRECTORY_SEPARATOR
27# define DIRECTORY_SEPARATOR '/' 27# define DIRECTORY_SEPARATOR '/'
28# endif 28# endif
29 29
30# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT 30#ifdef __cplusplus
31# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 31extern "C" {
32# endif 32#endif
33 33
34# if GNULIB_DIRNAME 34# if GNULIB_DIRNAME
35char *base_name (char const *file); 35char *base_name (char const *file)
36char *dir_name (char const *file); 36 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
37 _GL_ATTRIBUTE_RETURNS_NONNULL;
38char *dir_name (char const *file)
39 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
40 _GL_ATTRIBUTE_RETURNS_NONNULL;
37# endif 41# endif
38 42
39char *mdir_name (char const *file); 43char *mdir_name (char const *file)
40size_t base_len (char const *file) _GL_ATTRIBUTE_PURE; 44 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
41size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE; 45size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE;
42char *last_component (char const *file) _GL_ATTRIBUTE_PURE;
43 46
44bool strip_trailing_slashes (char *file); 47bool strip_trailing_slashes (char *file);
45 48
49#ifdef __cplusplus
50} /* extern "C" */
51#endif
52
46#endif /* not DIRNAME_H_ */ 53#endif /* not DIRNAME_H_ */
diff --git a/gl/dosname.h b/gl/dosname.h
deleted file mode 100644
index ba63ce4..0000000
--- a/gl/dosname.h
+++ /dev/null
@@ -1,53 +0,0 @@
1/* File names on MS-DOS/Windows systems.
2
3 Copyright (C) 2000-2001, 2004-2006, 2009-2013 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 From Paul Eggert and Jim Meyering. */
19
20#ifndef _DOSNAME_H
21#define _DOSNAME_H
22
23#if (defined _WIN32 || defined __WIN32__ || \
24 defined __MSDOS__ || defined __CYGWIN__ || \
25 defined __EMX__ || defined __DJGPP__)
26 /* This internal macro assumes ASCII, but all hosts that support drive
27 letters use ASCII. */
28# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \
29 <= 'z' - 'a')
30# define FILE_SYSTEM_PREFIX_LEN(Filename) \
31 (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
32# ifndef __CYGWIN__
33# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
34# endif
35# define ISSLASH(C) ((C) == '/' || (C) == '\\')
36#else
37# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
38# define ISSLASH(C) ((C) == '/')
39#endif
40
41#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
42# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
43#endif
44
45#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
46# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
47# else
48# define IS_ABSOLUTE_FILE_NAME(F) \
49 (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0)
50#endif
51#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
52
53#endif /* DOSNAME_H_ */
diff --git a/gl/dup2.c b/gl/dup2.c
new file mode 100644
index 0000000..7d197ca
--- /dev/null
+++ b/gl/dup2.c
@@ -0,0 +1,189 @@
1/* Duplicate an open file descriptor to a specified file descriptor.
2
3 Copyright (C) 1999, 2004-2007, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* written by Paul Eggert */
19
20#include <config.h>
21
22/* Specification. */
23#include <unistd.h>
24
25#include <errno.h>
26#include <fcntl.h>
27
28#undef dup2
29
30#if defined _WIN32 && ! defined __CYGWIN__
31
32/* Get declarations of the native Windows API functions. */
33# define WIN32_LEAN_AND_MEAN
34# include <windows.h>
35
36# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
37# include "msvc-inval.h"
38# endif
39
40/* Get _get_osfhandle. */
41# if GNULIB_MSVC_NOTHROW
42# include "msvc-nothrow.h"
43# else
44# include <io.h>
45# endif
46
47# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
48static int
49dup2_nothrow (int fd, int desired_fd)
50{
51 int result;
52
53 TRY_MSVC_INVAL
54 {
55 result = _dup2 (fd, desired_fd);
56 }
57 CATCH_MSVC_INVAL
58 {
59 errno = EBADF;
60 result = -1;
61 }
62 DONE_MSVC_INVAL;
63
64 return result;
65}
66# else
67# define dup2_nothrow _dup2
68# endif
69
70static int
71ms_windows_dup2 (int fd, int desired_fd)
72{
73 int result;
74
75 /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open,
76 dup2 (fd, fd) returns 0, but all further attempts to use fd in
77 future dup2 calls will hang. */
78 if (fd == desired_fd)
79 {
80 if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
81 {
82 errno = EBADF;
83 return -1;
84 }
85 return fd;
86 }
87
88 /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
89 https://bugs.winehq.org/show_bug.cgi?id=21289 */
90 if (desired_fd < 0)
91 {
92 errno = EBADF;
93 return -1;
94 }
95
96 result = dup2_nothrow (fd, desired_fd);
97
98 if (result == 0)
99 result = desired_fd;
100
101 return result;
102}
103
104# define dup2 ms_windows_dup2
105
106#elif defined __KLIBC__
107
108# include <InnoTekLIBC/backend.h>
109
110static int
111klibc_dup2dirfd (int fd, int desired_fd)
112{
113 int tempfd;
114 int dupfd;
115
116 tempfd = open ("NUL", O_RDONLY);
117 if (tempfd == -1)
118 return -1;
119
120 if (tempfd == desired_fd)
121 {
122 close (tempfd);
123
124 char path[_MAX_PATH];
125 if (__libc_Back_ioFHToPath (fd, path, sizeof (path)))
126 return -1;
127
128 return open(path, O_RDONLY);
129 }
130
131 dupfd = klibc_dup2dirfd (fd, desired_fd);
132
133 close (tempfd);
134
135 return dupfd;
136}
137
138static int
139klibc_dup2 (int fd, int desired_fd)
140{
141 int dupfd;
142 struct stat sbuf;
143
144 dupfd = dup2 (fd, desired_fd);
145 if (dupfd == -1 && errno == ENOTSUP \
146 && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
147 {
148 close (desired_fd);
149
150 return klibc_dup2dirfd (fd, desired_fd);
151 }
152
153 return dupfd;
154}
155
156# define dup2 klibc_dup2
157#endif
158
159int
160rpl_dup2 (int fd, int desired_fd)
161{
162 int result;
163
164#ifdef F_GETFL
165 /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
166 On Cygwin 1.5.x, dup2 (1, 1) returns 0.
167 On Cygwin 1.7.17, dup2 (1, -1) dumps core.
168 On Cygwin 1.7.25, dup2 (1, 256) can dump core.
169 On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
170# if HAVE_SETDTABLESIZE
171 setdtablesize (desired_fd + 1);
172# endif
173 if (desired_fd < 0)
174 fd = desired_fd;
175 if (fd == desired_fd)
176 return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
177#endif
178
179 result = dup2 (fd, desired_fd);
180
181 /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */
182 if (result == -1 && errno == EMFILE)
183 errno = EBADF;
184#if REPLACE_FCHDIR
185 if (fd != desired_fd && result != -1)
186 result = _gl_register_dup (fd, result);
187#endif
188 return result;
189}
diff --git a/gl/dynarray.h b/gl/dynarray.h
new file mode 100644
index 0000000..9155910
--- /dev/null
+++ b/gl/dynarray.h
@@ -0,0 +1,284 @@
1/* Type-safe arrays which grow dynamically.
2 Copyright 2021-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Paul Eggert and Bruno Haible, 2021. */
18
19#ifndef _GL_DYNARRAY_H
20#define _GL_DYNARRAY_H
21
22/* Before including this file, you need to define:
23
24 DYNARRAY_STRUCT
25 The struct tag of dynamic array to be defined.
26
27 DYNARRAY_ELEMENT
28 The type name of the element type. Elements are copied
29 as if by memcpy, and can change address as the dynamic
30 array grows.
31
32 DYNARRAY_PREFIX
33 The prefix of the functions which are defined.
34
35 The following parameters are optional:
36
37 DYNARRAY_ELEMENT_FREE
38 DYNARRAY_ELEMENT_FREE (E) is evaluated to deallocate the
39 contents of elements. E is of type DYNARRAY_ELEMENT *.
40
41 DYNARRAY_ELEMENT_INIT
42 DYNARRAY_ELEMENT_INIT (E) is evaluated to initialize a new
43 element. E is of type DYNARRAY_ELEMENT *.
44 If DYNARRAY_ELEMENT_FREE but not DYNARRAY_ELEMENT_INIT is
45 defined, new elements are automatically zero-initialized.
46 Otherwise, new elements have undefined contents.
47
48 DYNARRAY_INITIAL_SIZE
49 The size of the statically allocated array (default:
50 at least 2, more elements if they fit into 128 bytes).
51 Must be a preprocessor constant. If DYNARRAY_INITIAL_SIZE is 0,
52 there is no statically allocated array at, and all non-empty
53 arrays are heap-allocated.
54
55 DYNARRAY_FINAL_TYPE
56 The name of the type which holds the final array. If not
57 defined, is PREFIX##finalize not provided. DYNARRAY_FINAL_TYPE
58 must be a struct type, with members of type DYNARRAY_ELEMENT and
59 size_t at the start (in this order).
60
61 These macros are undefined after this header file has been
62 included.
63
64 The following types are provided (their members are private to the
65 dynarray implementation):
66
67 struct DYNARRAY_STRUCT
68
69 The following functions are provided:
70 */
71
72/* Initialize a dynamic array object. This must be called before any
73 use of the object. */
74#if 0
75static void
76 DYNARRAY_PREFIX##init (struct DYNARRAY_STRUCT *list);
77#endif
78
79/* Deallocate the dynamic array and its elements. */
80#if 0
81static void
82 DYNARRAY_PREFIX##free (struct DYNARRAY_STRUCT *list);
83#endif
84
85/* Return true if the dynamic array is in an error state. */
86#if 0
87static bool
88 DYNARRAY_PREFIX##has_failed (const struct DYNARRAY_STRUCT *list);
89#endif
90
91/* Mark the dynamic array as failed. All elements are deallocated as
92 a side effect. */
93#if 0
94static void
95 DYNARRAY_PREFIX##mark_failed (struct DYNARRAY_STRUCT *list);
96#endif
97
98/* Return the number of elements which have been added to the dynamic
99 array. */
100#if 0
101static size_t
102 DYNARRAY_PREFIX##size (const struct DYNARRAY_STRUCT *list);
103#endif
104
105/* Return a pointer to the first array element, if any. For a
106 zero-length array, the pointer can be NULL even though the dynamic
107 array has not entered the failure state. */
108#if 0
109static DYNARRAY_ELEMENT *
110 DYNARRAY_PREFIX##begin (const struct DYNARRAY_STRUCT *list);
111#endif
112
113/* Return a pointer one element past the last array element. For a
114 zero-length array, the pointer can be NULL even though the dynamic
115 array has not entered the failure state. */
116#if 0
117static DYNARRAY_ELEMENT *
118 DYNARRAY_PREFIX##end (const struct DYNARRAY_STRUCT *list);
119#endif
120
121/* Return a pointer to the array element at INDEX. Terminate the
122 process if INDEX is out of bounds. */
123#if 0
124static DYNARRAY_ELEMENT *
125 DYNARRAY_PREFIX##at (struct DYNARRAY_STRUCT *list, size_t index);
126#endif
127
128/* Add ITEM at the end of the array, enlarging it by one element.
129 Mark *LIST as failed if the dynamic array allocation size cannot be
130 increased. */
131#if 0
132static void
133 DYNARRAY_PREFIX##add (struct DYNARRAY_STRUCT *list,
134 DYNARRAY_ELEMENT item);
135#endif
136
137/* Allocate a place for a new element in *LIST and return a pointer to
138 it. The pointer can be NULL if the dynamic array cannot be
139 enlarged due to a memory allocation failure. */
140#if 0
141static DYNARRAY_ELEMENT *
142 DYNARRAY_PREFIX##emplace (struct DYNARRAY_STRUCT *list);
143#endif
144
145/* Change the size of *LIST to SIZE. If SIZE is larger than the
146 existing size, new elements are added (which can be initialized).
147 Otherwise, the list is truncated, and elements are freed. Return
148 false on memory allocation failure (and mark *LIST as failed). */
149#if 0
150static bool
151 DYNARRAY_PREFIX##resize (struct DYNARRAY_STRUCT *list, size_t size);
152#endif
153
154/* Remove the last element of LIST if it is present. */
155#if 0
156static void
157 DYNARRAY_PREFIX##remove_last (struct DYNARRAY_STRUCT *list);
158#endif
159
160/* Remove all elements from the list. The elements are freed, but the
161 list itself is not. */
162#if 0
163static void
164 DYNARRAY_PREFIX##clear (struct DYNARRAY_STRUCT *list);
165#endif
166
167#if defined DYNARRAY_FINAL_TYPE
168/* Transfer the dynamic array to a permanent location at *RESULT.
169 Returns true on success on false on allocation failure. In either
170 case, *LIST is re-initialized and can be reused. A NULL pointer is
171 stored in *RESULT if LIST refers to an empty list. On success, the
172 pointer in *RESULT is heap-allocated and must be deallocated using
173 free. */
174#if 0
175static bool
176 DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *list,
177 DYNARRAY_FINAL_TYPE *result);
178#endif
179#else /* !defined DYNARRAY_FINAL_TYPE */
180/* Transfer the dynamic array to a heap-allocated array and return a
181 pointer to it. The pointer is NULL if memory allocation fails, or
182 if the array is empty, so this function should be used only for
183 arrays which are known not be empty (usually because they always
184 have a sentinel at the end). If LENGTHP is not NULL, the array
185 length is written to *LENGTHP. *LIST is re-initialized and can be
186 reused. */
187#if 0
188static DYNARRAY_ELEMENT *
189 DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *list,
190 size_t *lengthp);
191#endif
192#endif
193
194/* A minimal example which provides a growing list of integers can be
195 defined like this:
196
197 struct int_array
198 {
199 // Pointer to result array followed by its length,
200 // as required by DYNARRAY_FINAL_TYPE.
201 int *array;
202 size_t length;
203 };
204
205 #define DYNARRAY_STRUCT dynarray_int
206 #define DYNARRAY_ELEMENT int
207 #define DYNARRAY_PREFIX dynarray_int_
208 #define DYNARRAY_FINAL_TYPE struct int_array
209 #include <malloc/dynarray-skeleton.c>
210
211 To create a three-element array with elements 1, 2, 3, use this
212 code:
213
214 struct dynarray_int dyn;
215 dynarray_int_init (&dyn);
216 for (int i = 1; i <= 3; ++i)
217 {
218 int *place = dynarray_int_emplace (&dyn);
219 assert (place != NULL);
220 *place = i;
221 }
222 struct int_array result;
223 bool ok = dynarray_int_finalize (&dyn, &result);
224 assert (ok);
225 assert (result.length == 3);
226 assert (result.array[0] == 1);
227 assert (result.array[1] == 2);
228 assert (result.array[2] == 3);
229 free (result.array);
230
231 If the elements contain resources which must be freed, define
232 DYNARRAY_ELEMENT_FREE appropriately, like this:
233
234 struct str_array
235 {
236 char **array;
237 size_t length;
238 };
239
240 #define DYNARRAY_STRUCT dynarray_str
241 #define DYNARRAY_ELEMENT char *
242 #define DYNARRAY_ELEMENT_FREE(ptr) free (*ptr)
243 #define DYNARRAY_PREFIX dynarray_str_
244 #define DYNARRAY_FINAL_TYPE struct str_array
245 #include <malloc/dynarray-skeleton.c>
246 */
247
248
249/* The implementation is imported from glibc. */
250
251/* Avoid possible conflicts with symbols exported by the GNU libc. */
252#define __libc_dynarray_at_failure gl_dynarray_at_failure
253#define __libc_dynarray_emplace_enlarge gl_dynarray_emplace_enlarge
254#define __libc_dynarray_finalize gl_dynarray_finalize
255#define __libc_dynarray_resize_clear gl_dynarray_resize_clear
256#define __libc_dynarray_resize gl_dynarray_resize
257
258#if defined DYNARRAY_STRUCT || defined DYNARRAY_ELEMENT || defined DYNARRAY_PREFIX
259
260# ifndef _GL_LIKELY
261/* Rely on __builtin_expect, as provided by the module 'builtin-expect'. */
262# define _GL_LIKELY(cond) __builtin_expect ((cond), 1)
263# define _GL_UNLIKELY(cond) __builtin_expect ((cond), 0)
264# endif
265
266/* Define auxiliary structs and declare auxiliary functions, common to all
267 instantiations of dynarray. */
268# include <malloc/dynarray.gl.h>
269
270/* Define the instantiation, specified through
271 DYNARRAY_STRUCT
272 DYNARRAY_ELEMENT
273 DYNARRAY_PREFIX
274 etc. */
275# include <malloc/dynarray-skeleton.gl.h>
276
277#else
278
279/* This file is being included from one of the malloc/dynarray_*.c files. */
280# include <malloc/dynarray.h>
281
282#endif
283
284#endif /* _GL_DYNARRAY_H */
diff --git a/gl/errno.in.h b/gl/errno.in.h
index 49b3546..3dda9c2 100644
--- a/gl/errno.in.h
+++ b/gl/errno.in.h
@@ -1,19 +1,19 @@
1/* A POSIX-like <errno.h>. 1/* A POSIX-like <errno.h>.
2 2
3 Copyright (C) 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _@GUARD_PREFIX@_ERRNO_H 18#ifndef _@GUARD_PREFIX@_ERRNO_H
19 19
@@ -30,7 +30,7 @@
30 30
31 31
32/* On native Windows platforms, many macros are not defined. */ 32/* On native Windows platforms, many macros are not defined. */
33# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 33# if defined _WIN32 && ! defined __CYGWIN__
34 34
35/* These are the same values as defined by MSVC 10, for interoperability. */ 35/* These are the same values as defined by MSVC 10, for interoperability. */
36 36
@@ -248,7 +248,7 @@
248 interoperability. */ 248 interoperability. */
249# define EOWNERDEAD 58 249# define EOWNERDEAD 58
250# define ENOTRECOVERABLE 59 250# define ENOTRECOVERABLE 59
251# elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 251# elif defined _WIN32 && ! defined __CYGWIN__
252 /* We have a conflict here: pthreads-win32 defines these values 252 /* We have a conflict here: pthreads-win32 defines these values
253 differently than MSVC 10. It's hairy to decide which one to use. */ 253 differently than MSVC 10. It's hairy to decide which one to use. */
254# if defined __MINGW32__ && !defined USE_WINDOWS_THREADS 254# if defined __MINGW32__ && !defined USE_WINDOWS_THREADS
diff --git a/gl/error.c b/gl/error.c
index 865b293..6875f13 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -1,19 +1,19 @@
1/* Error handler for noninteractive utilities 1/* Error handler for noninteractive utilities
2 Copyright (C) 1990-1998, 2000-2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 1990-1998, 2000-2007, 2009-2023 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ 18/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
19 19
@@ -39,6 +39,11 @@
39# include <stdint.h> 39# include <stdint.h>
40# include <wchar.h> 40# include <wchar.h>
41# define mbsrtowcs __mbsrtowcs 41# define mbsrtowcs __mbsrtowcs
42# define USE_UNLOCKED_IO 0
43# define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(a, b)
44# define _GL_ARG_NONNULL(a)
45#else
46# include "getprogname.h"
42#endif 47#endif
43 48
44#if USE_UNLOCKED_IO 49#if USE_UNLOCKED_IO
@@ -72,14 +77,14 @@ extern void __error (int status, int errnum, const char *message, ...)
72extern void __error_at_line (int status, int errnum, const char *file_name, 77extern void __error_at_line (int status, int errnum, const char *file_name,
73 unsigned int line_number, const char *message, 78 unsigned int line_number, const char *message,
74 ...) 79 ...)
75 __attribute__ ((__format__ (__printf__, 5, 6)));; 80 __attribute__ ((__format__ (__printf__, 5, 6)));
76# define error __error 81# define error __error
77# define error_at_line __error_at_line 82# define error_at_line __error_at_line
78 83
79# include <libio/iolibio.h> 84# include <libio/iolibio.h>
80# define fflush(s) INTUSE(_IO_fflush) (s) 85# define fflush(s) _IO_fflush (s)
81# undef putc 86# undef putc
82# define putc(c, fp) INTUSE(_IO_putc) (c, fp) 87# define putc(c, fp) _IO_putc (c, fp)
83 88
84# include <bits/libc-lock.h> 89# include <bits/libc-lock.h>
85 90
@@ -88,35 +93,37 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
88# include <fcntl.h> 93# include <fcntl.h>
89# include <unistd.h> 94# include <unistd.h>
90 95
91# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 96# if defined _WIN32 && ! defined __CYGWIN__
92/* Get declarations of the native Windows API functions. */ 97/* Get declarations of the native Windows API functions. */
93# define WIN32_LEAN_AND_MEAN 98# define WIN32_LEAN_AND_MEAN
94# include <windows.h> 99# include <windows.h>
95/* Get _get_osfhandle. */ 100/* Get _get_osfhandle. */
96# include "msvc-nothrow.h" 101# if GNULIB_MSVC_NOTHROW
102# include "msvc-nothrow.h"
103# else
104# include <io.h>
105# endif
97# endif 106# endif
98 107
99/* The gnulib override of fcntl is not needed in this file. */ 108/* The gnulib override of fcntl is not needed in this file. */
100# undef fcntl 109# undef fcntl
101 110
102# if !HAVE_DECL_STRERROR_R 111# if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R)
103# ifndef HAVE_DECL_STRERROR_R 112# ifndef HAVE_DECL_STRERROR_R
104"this configure-time declaration test was not run" 113"this configure-time declaration test was not run"
105# endif 114# endif
106# if STRERROR_R_CHAR_P 115# if STRERROR_R_CHAR_P
107char *strerror_r (); 116char *strerror_r (int errnum, char *buf, size_t buflen);
108# else 117# else
109int strerror_r (); 118int strerror_r (int errnum, char *buf, size_t buflen);
110# endif 119# endif
111# endif 120# endif
112 121
113/* The calling program should define program_name and set it to the 122# define program_name getprogname ()
114 name of the executing program. */
115extern char *program_name;
116 123
117# if HAVE_STRERROR_R || defined strerror_r 124# if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r
118# define __strerror_r strerror_r 125# define __strerror_r strerror_r
119# endif /* HAVE_STRERROR_R || defined strerror_r */ 126# endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */
120#endif /* not _LIBC */ 127#endif /* not _LIBC */
121 128
122#if !_LIBC 129#if !_LIBC
@@ -124,7 +131,7 @@ extern char *program_name;
124static int 131static int
125is_open (int fd) 132is_open (int fd)
126{ 133{
127# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 134# if defined _WIN32 && ! defined __CYGWIN__
128 /* On native Windows: The initial state of unassigned standard file 135 /* On native Windows: The initial state of unassigned standard file
129 descriptors is that they are open but point to an INVALID_HANDLE_VALUE. 136 descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
130 There is no fcntl, and the gnulib replacement fcntl does not support 137 There is no fcntl, and the gnulib replacement fcntl does not support
@@ -169,9 +176,9 @@ print_errno_message (int errnum)
169{ 176{
170 char const *s; 177 char const *s;
171 178
172#if defined HAVE_STRERROR_R || _LIBC 179#if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R
173 char errbuf[1024]; 180 char errbuf[1024];
174# if STRERROR_R_CHAR_P || _LIBC 181# if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P)
175 s = __strerror_r (errnum, errbuf, sizeof errbuf); 182 s = __strerror_r (errnum, errbuf, sizeof errbuf);
176# else 183# else
177 if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) 184 if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
@@ -195,13 +202,12 @@ print_errno_message (int errnum)
195#endif 202#endif
196} 203}
197 204
198static void 205static void _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))
199error_tail (int status, int errnum, const char *message, va_list args) 206error_tail (int status, int errnum, const char *message, va_list args)
200{ 207{
201#if _LIBC 208#if _LIBC
202 if (_IO_fwide (stderr, 0) > 0) 209 if (_IO_fwide (stderr, 0) > 0)
203 { 210 {
204# define ALLOCA_LIMIT 2000
205 size_t len = strlen (message) + 1; 211 size_t len = strlen (message) + 1;
206 wchar_t *wmessage = NULL; 212 wchar_t *wmessage = NULL;
207 mbstate_t st; 213 mbstate_t st;
@@ -237,7 +243,7 @@ error_tail (int status, int errnum, const char *message, va_list args)
237 if (res != len) 243 if (res != len)
238 break; 244 break;
239 245
240 if (__builtin_expect (len >= SIZE_MAX / 2, 0)) 246 if (__builtin_expect (len >= SIZE_MAX / sizeof (wchar_t) / 2, 0))
241 { 247 {
242 /* This really should not happen if everything is fine. */ 248 /* This really should not happen if everything is fine. */
243 res = (size_t) -1; 249 res = (size_t) -1;
@@ -266,7 +272,6 @@ error_tail (int status, int errnum, const char *message, va_list args)
266 else 272 else
267#endif 273#endif
268 vfprintf (stderr, message, args); 274 vfprintf (stderr, message, args);
269 va_end (args);
270 275
271 ++error_message_count; 276 ++error_message_count;
272 if (errnum) 277 if (errnum)
@@ -316,6 +321,7 @@ error (int status, int errnum, const char *message, ...)
316 321
317 va_start (args, message); 322 va_start (args, message);
318 error_tail (status, errnum, message, args); 323 error_tail (status, errnum, message, args);
324 va_end (args);
319 325
320#ifdef _LIBC 326#ifdef _LIBC
321 _IO_funlockfile (stderr); 327 _IO_funlockfile (stderr);
@@ -342,7 +348,10 @@ error_at_line (int status, int errnum, const char *file_name,
342 348
343 if (old_line_number == line_number 349 if (old_line_number == line_number
344 && (file_name == old_file_name 350 && (file_name == old_file_name
345 || strcmp (old_file_name, file_name) == 0)) 351 || (old_file_name != NULL
352 && file_name != NULL
353 && strcmp (old_file_name, file_name) == 0)))
354
346 /* Simply return and print nothing. */ 355 /* Simply return and print nothing. */
347 return; 356 return;
348 357
@@ -374,15 +383,16 @@ error_at_line (int status, int errnum, const char *file_name,
374 } 383 }
375 384
376#if _LIBC 385#if _LIBC
377 __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", 386 __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ",
378 file_name, line_number); 387 file_name, line_number);
379#else 388#else
380 fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", 389 fprintf (stderr, file_name != NULL ? "%s:%u: " : " ",
381 file_name, line_number); 390 file_name, line_number);
382#endif 391#endif
383 392
384 va_start (args, message); 393 va_start (args, message);
385 error_tail (status, errnum, message, args); 394 error_tail (status, errnum, message, args);
395 va_end (args);
386 396
387#ifdef _LIBC 397#ifdef _LIBC
388 _IO_funlockfile (stderr); 398 _IO_funlockfile (stderr);
diff --git a/gl/error.h b/gl/error.h
index afcb0e1..a240526 100644
--- a/gl/error.h
+++ b/gl/error.h
@@ -1,35 +1,26 @@
1/* Declaration for error-reporting function 1/* Declaration for error-reporting function
2 Copyright (C) 1995-1997, 2003, 2006, 2008-2013 Free Software Foundation, 2 Copyright (C) 1995-1997, 2003, 2006, 2008-2023 Free Software Foundation,
3 Inc. 3 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 file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 2.1 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#ifndef _ERROR_H 19#ifndef _ERROR_H
20#define _ERROR_H 1 20#define _ERROR_H 1
21 21
22/* The __attribute__ feature is available in gcc versions 2.5 and later. 22/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. */
23 The __-protected variants of the attributes 'format' and 'printf' are 23#include <stdio.h>
24 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
25 We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
26 gnulib and libintl do '#define printf __printf__' when they override
27 the 'printf' function. */
28#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
29# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
30#else
31# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
32#endif
33 24
34#ifdef __cplusplus 25#ifdef __cplusplus
35extern "C" { 26extern "C" {
@@ -40,11 +31,21 @@ extern "C" {
40 If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */ 31 If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */
41 32
42extern void error (int __status, int __errnum, const char *__format, ...) 33extern void error (int __status, int __errnum, const char *__format, ...)
43 _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); 34#if GNULIB_VFPRINTF_POSIX
35 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4))
36#else
37 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 3, 4))
38#endif
39 ;
44 40
45extern void error_at_line (int __status, int __errnum, const char *__fname, 41extern void error_at_line (int __status, int __errnum, const char *__fname,
46 unsigned int __lineno, const char *__format, ...) 42 unsigned int __lineno, const char *__format, ...)
47 _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6)); 43#if GNULIB_VFPRINTF_POSIX
44 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 5, 6))
45#else
46 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 5, 6))
47#endif
48 ;
48 49
49/* If NULL, error will flush stdout, then print on stderr the program 50/* If NULL, error will flush stdout, then print on stderr the program
50 name, a colon and a space. Otherwise, error will call this 51 name, a colon and a space. Otherwise, error will call this
diff --git a/gl/exitfail.c b/gl/exitfail.c
index b0b4ebe..d67a130 100644
--- a/gl/exitfail.c
+++ b/gl/exitfail.c
@@ -1,19 +1,19 @@
1/* Failure exit status 1/* Failure exit status
2 2
3 Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc. 3 Copyright (C) 2002-2003, 2005-2007, 2009-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/exitfail.h b/gl/exitfail.h
index e54333b..85a6af6 100644
--- a/gl/exitfail.h
+++ b/gl/exitfail.h
@@ -1,18 +1,18 @@
1/* Failure exit status 1/* Failure exit status
2 2
3 Copyright (C) 2002, 2009-2013 Free Software Foundation, Inc. 3 Copyright (C) 2002, 2009-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18extern int volatile exit_failure; 18extern int volatile exit_failure;
diff --git a/gl/fcntl.c b/gl/fcntl.c
new file mode 100644
index 0000000..e220800
--- /dev/null
+++ b/gl/fcntl.c
@@ -0,0 +1,629 @@
1/* Provide file descriptor control.
2
3 Copyright (C) 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Written by Eric Blake <ebb9@byu.net>. */
19
20#include <config.h>
21
22/* Specification. */
23#include <fcntl.h>
24
25#include <errno.h>
26#include <limits.h>
27#include <stdarg.h>
28#include <stdlib.h>
29#include <unistd.h>
30
31#ifdef __KLIBC__
32# define INCL_DOS
33# include <os2.h>
34#endif
35
36#if defined _WIN32 && ! defined __CYGWIN__
37/* Get declarations of the native Windows API functions. */
38# define WIN32_LEAN_AND_MEAN
39# include <windows.h>
40
41/* Get _get_osfhandle. */
42# if GNULIB_MSVC_NOTHROW
43# include "msvc-nothrow.h"
44# else
45# include <io.h>
46# endif
47
48/* Upper bound on getdtablesize(). See lib/getdtablesize.c. */
49# define OPEN_MAX_MAX 0x10000
50
51/* Duplicate OLDFD into the first available slot of at least NEWFD,
52 which must be positive, with FLAGS determining whether the duplicate
53 will be inheritable. */
54static int
55dupfd (int oldfd, int newfd, int flags)
56{
57 /* Mingw has no way to create an arbitrary fd. Iterate until all
58 file descriptors less than newfd are filled up. */
59 HANDLE curr_process = GetCurrentProcess ();
60 HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
61 unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
62 unsigned int fds_to_close_bound = 0;
63 int result;
64 BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
65 int mode;
66
67 if (newfd < 0 || getdtablesize () <= newfd)
68 {
69 errno = EINVAL;
70 return -1;
71 }
72 if (old_handle == INVALID_HANDLE_VALUE
73 || (mode = _setmode (oldfd, O_BINARY)) == -1)
74 {
75 /* oldfd is not open, or is an unassigned standard file
76 descriptor. */
77 errno = EBADF;
78 return -1;
79 }
80 _setmode (oldfd, mode);
81 flags |= mode;
82
83 for (;;)
84 {
85 HANDLE new_handle;
86 int duplicated_fd;
87 unsigned int index;
88
89 if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
90 old_handle, /* SourceHandle */
91 curr_process, /* TargetProcessHandle */
92 (PHANDLE) &new_handle, /* TargetHandle */
93 (DWORD) 0, /* DesiredAccess */
94 inherit, /* InheritHandle */
95 DUPLICATE_SAME_ACCESS)) /* Options */
96 {
97 switch (GetLastError ())
98 {
99 case ERROR_TOO_MANY_OPEN_FILES:
100 errno = EMFILE;
101 break;
102 case ERROR_INVALID_HANDLE:
103 case ERROR_INVALID_TARGET_HANDLE:
104 case ERROR_DIRECT_ACCESS_HANDLE:
105 errno = EBADF;
106 break;
107 case ERROR_INVALID_PARAMETER:
108 case ERROR_INVALID_FUNCTION:
109 case ERROR_INVALID_ACCESS:
110 errno = EINVAL;
111 break;
112 default:
113 errno = EACCES;
114 break;
115 }
116 result = -1;
117 break;
118 }
119 duplicated_fd = _open_osfhandle ((intptr_t) new_handle, flags);
120 if (duplicated_fd < 0)
121 {
122 CloseHandle (new_handle);
123 result = -1;
124 break;
125 }
126 if (newfd <= duplicated_fd)
127 {
128 result = duplicated_fd;
129 break;
130 }
131
132 /* Set the bit duplicated_fd in fds_to_close[]. */
133 index = (unsigned int) duplicated_fd / CHAR_BIT;
134 if (fds_to_close_bound <= index)
135 {
136 if (sizeof fds_to_close <= index)
137 /* Need to increase OPEN_MAX_MAX. */
138 abort ();
139 memset (fds_to_close + fds_to_close_bound, '\0',
140 index + 1 - fds_to_close_bound);
141 fds_to_close_bound = index + 1;
142 }
143 fds_to_close[index] |= 1 << ((unsigned int) duplicated_fd % CHAR_BIT);
144 }
145
146 /* Close the previous fds that turned out to be too small. */
147 {
148 int saved_errno = errno;
149 unsigned int duplicated_fd;
150
151 for (duplicated_fd = 0;
152 duplicated_fd < fds_to_close_bound * CHAR_BIT;
153 duplicated_fd++)
154 if ((fds_to_close[duplicated_fd / CHAR_BIT]
155 >> (duplicated_fd % CHAR_BIT))
156 & 1)
157 close (duplicated_fd);
158
159 errno = saved_errno;
160 }
161
162# if REPLACE_FCHDIR
163 if (0 <= result)
164 result = _gl_register_dup (oldfd, result);
165# endif
166 return result;
167}
168#endif /* W32 */
169
170/* Forward declarations, because we '#undef fcntl' in the middle of this
171 compilation unit. */
172/* Our implementation of fcntl (fd, F_DUPFD, target). */
173static int rpl_fcntl_DUPFD (int fd, int target);
174/* Our implementation of fcntl (fd, F_DUPFD_CLOEXEC, target). */
175static int rpl_fcntl_DUPFD_CLOEXEC (int fd, int target);
176#ifdef __KLIBC__
177/* Adds support for fcntl on directories. */
178static int klibc_fcntl (int fd, int action, /* arg */...);
179#endif
180
181
182/* Perform the specified ACTION on the file descriptor FD, possibly
183 using the argument ARG further described below. This replacement
184 handles the following actions, and forwards all others on to the
185 native fcntl. An unrecognized ACTION returns -1 with errno set to
186 EINVAL.
187
188 F_DUPFD - duplicate FD, with int ARG being the minimum target fd.
189 If successful, return the duplicate, which will be inheritable;
190 otherwise return -1 and set errno.
191
192 F_DUPFD_CLOEXEC - duplicate FD, with int ARG being the minimum
193 target fd. If successful, return the duplicate, which will not be
194 inheritable; otherwise return -1 and set errno.
195
196 F_GETFD - ARG need not be present. If successful, return a
197 non-negative value containing the descriptor flags of FD (only
198 FD_CLOEXEC is portable, but other flags may be present); otherwise
199 return -1 and set errno. */
200
201int
202fcntl (int fd, int action, /* arg */...)
203#undef fcntl
204#ifdef __KLIBC__
205# define fcntl klibc_fcntl
206#endif
207{
208 va_list arg;
209 int result = -1;
210 va_start (arg, action);
211 switch (action)
212 {
213 case F_DUPFD:
214 {
215 int target = va_arg (arg, int);
216 result = rpl_fcntl_DUPFD (fd, target);
217 break;
218 }
219
220 case F_DUPFD_CLOEXEC:
221 {
222 int target = va_arg (arg, int);
223 result = rpl_fcntl_DUPFD_CLOEXEC (fd, target);
224 break;
225 }
226
227#if !HAVE_FCNTL
228 case F_GETFD:
229 {
230# if defined _WIN32 && ! defined __CYGWIN__
231 HANDLE handle = (HANDLE) _get_osfhandle (fd);
232 DWORD flags;
233 if (handle == INVALID_HANDLE_VALUE
234 || GetHandleInformation (handle, &flags) == 0)
235 errno = EBADF;
236 else
237 result = (flags & HANDLE_FLAG_INHERIT) ? 0 : FD_CLOEXEC;
238# else /* !W32 */
239 /* Use dup2 to reject invalid file descriptors. No way to
240 access this information, so punt. */
241 if (0 <= dup2 (fd, fd))
242 result = 0;
243# endif /* !W32 */
244 break;
245 } /* F_GETFD */
246#endif /* !HAVE_FCNTL */
247
248 /* Implementing F_SETFD on mingw is not trivial - there is no
249 API for changing the O_NOINHERIT bit on an fd, and merely
250 changing the HANDLE_FLAG_INHERIT bit on the underlying handle
251 can lead to odd state. It may be possible by duplicating the
252 handle, using _open_osfhandle with the right flags, then
253 using dup2 to move the duplicate onto the original, but that
254 is not supported for now. */
255
256 default:
257 {
258#if HAVE_FCNTL
259 switch (action)
260 {
261 #ifdef F_BARRIERFSYNC /* macOS */
262 case F_BARRIERFSYNC:
263 #endif
264 #ifdef F_CHKCLEAN /* macOS */
265 case F_CHKCLEAN:
266 #endif
267 #ifdef F_CLOSEM /* NetBSD, HP-UX */
268 case F_CLOSEM:
269 #endif
270 #ifdef F_FLUSH_DATA /* macOS */
271 case F_FLUSH_DATA:
272 #endif
273 #ifdef F_FREEZE_FS /* macOS */
274 case F_FREEZE_FS:
275 #endif
276 #ifdef F_FULLFSYNC /* macOS */
277 case F_FULLFSYNC:
278 #endif
279 #ifdef F_GETCONFINED /* macOS */
280 case F_GETCONFINED:
281 #endif
282 #ifdef F_GETDEFAULTPROTLEVEL /* macOS */
283 case F_GETDEFAULTPROTLEVEL:
284 #endif
285 #ifdef F_GETFD /* POSIX */
286 case F_GETFD:
287 #endif
288 #ifdef F_GETFL /* POSIX */
289 case F_GETFL:
290 #endif
291 #ifdef F_GETLEASE /* Linux */
292 case F_GETLEASE:
293 #endif
294 #ifdef F_GETNOSIGPIPE /* macOS */
295 case F_GETNOSIGPIPE:
296 #endif
297 #ifdef F_GETOWN /* POSIX */
298 case F_GETOWN:
299 #endif
300 #ifdef F_GETPIPE_SZ /* Linux */
301 case F_GETPIPE_SZ:
302 #endif
303 #ifdef F_GETPROTECTIONCLASS /* macOS */
304 case F_GETPROTECTIONCLASS:
305 #endif
306 #ifdef F_GETPROTECTIONLEVEL /* macOS */
307 case F_GETPROTECTIONLEVEL:
308 #endif
309 #ifdef F_GET_SEALS /* Linux */
310 case F_GET_SEALS:
311 #endif
312 #ifdef F_GETSIG /* Linux */
313 case F_GETSIG:
314 #endif
315 #ifdef F_MAXFD /* NetBSD */
316 case F_MAXFD:
317 #endif
318 #ifdef F_RECYCLE /* macOS */
319 case F_RECYCLE:
320 #endif
321 #ifdef F_SETFIFOENH /* HP-UX */
322 case F_SETFIFOENH:
323 #endif
324 #ifdef F_THAW_FS /* macOS */
325 case F_THAW_FS:
326 #endif
327 /* These actions take no argument. */
328 result = fcntl (fd, action);
329 break;
330
331 #ifdef F_ADD_SEALS /* Linux */
332 case F_ADD_SEALS:
333 #endif
334 #ifdef F_BADFD /* Solaris */
335 case F_BADFD:
336 #endif
337 #ifdef F_CHECK_OPENEVT /* macOS */
338 case F_CHECK_OPENEVT:
339 #endif
340 #ifdef F_DUP2FD /* FreeBSD, AIX, Solaris */
341 case F_DUP2FD:
342 #endif
343 #ifdef F_DUP2FD_CLOEXEC /* FreeBSD, Solaris */
344 case F_DUP2FD_CLOEXEC:
345 #endif
346 #ifdef F_DUP2FD_CLOFORK /* Solaris */
347 case F_DUP2FD_CLOFORK:
348 #endif
349 #ifdef F_DUPFD /* POSIX */
350 case F_DUPFD:
351 #endif
352 #ifdef F_DUPFD_CLOEXEC /* POSIX */
353 case F_DUPFD_CLOEXEC:
354 #endif
355 #ifdef F_DUPFD_CLOFORK /* Solaris */
356 case F_DUPFD_CLOFORK:
357 #endif
358 #ifdef F_GETXFL /* Solaris */
359 case F_GETXFL:
360 #endif
361 #ifdef F_GLOBAL_NOCACHE /* macOS */
362 case F_GLOBAL_NOCACHE:
363 #endif
364 #ifdef F_MAKECOMPRESSED /* macOS */
365 case F_MAKECOMPRESSED:
366 #endif
367 #ifdef F_MOVEDATAEXTENTS /* macOS */
368 case F_MOVEDATAEXTENTS:
369 #endif
370 #ifdef F_NOCACHE /* macOS */
371 case F_NOCACHE:
372 #endif
373 #ifdef F_NODIRECT /* macOS */
374 case F_NODIRECT:
375 #endif
376 #ifdef F_NOTIFY /* Linux */
377 case F_NOTIFY:
378 #endif
379 #ifdef F_OPLKACK /* IRIX */
380 case F_OPLKACK:
381 #endif
382 #ifdef F_OPLKREG /* IRIX */
383 case F_OPLKREG:
384 #endif
385 #ifdef F_RDAHEAD /* macOS */
386 case F_RDAHEAD:
387 #endif
388 #ifdef F_SETBACKINGSTORE /* macOS */
389 case F_SETBACKINGSTORE:
390 #endif
391 #ifdef F_SETCONFINED /* macOS */
392 case F_SETCONFINED:
393 #endif
394 #ifdef F_SETFD /* POSIX */
395 case F_SETFD:
396 #endif
397 #ifdef F_SETFL /* POSIX */
398 case F_SETFL:
399 #endif
400 #ifdef F_SETLEASE /* Linux */
401 case F_SETLEASE:
402 #endif
403 #ifdef F_SETNOSIGPIPE /* macOS */
404 case F_SETNOSIGPIPE:
405 #endif
406 #ifdef F_SETOWN /* POSIX */
407 case F_SETOWN:
408 #endif
409 #ifdef F_SETPIPE_SZ /* Linux */
410 case F_SETPIPE_SZ:
411 #endif
412 #ifdef F_SETPROTECTIONCLASS /* macOS */
413 case F_SETPROTECTIONCLASS:
414 #endif
415 #ifdef F_SETSIG /* Linux */
416 case F_SETSIG:
417 #endif
418 #ifdef F_SINGLE_WRITER /* macOS */
419 case F_SINGLE_WRITER:
420 #endif
421 /* These actions take an 'int' argument. */
422 {
423 int x = va_arg (arg, int);
424 result = fcntl (fd, action, x);
425 }
426 break;
427
428 default:
429 /* Other actions take a pointer argument. */
430 {
431 void *p = va_arg (arg, void *);
432 result = fcntl (fd, action, p);
433 }
434 break;
435 }
436#else
437 errno = EINVAL;
438#endif
439 break;
440 }
441 }
442 va_end (arg);
443 return result;
444}
445
446static int
447rpl_fcntl_DUPFD (int fd, int target)
448{
449 int result;
450#if !HAVE_FCNTL
451 result = dupfd (fd, target, 0);
452#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
453 /* Detect invalid target; needed for cygwin 1.5.x. */
454 if (target < 0 || getdtablesize () <= target)
455 {
456 result = -1;
457 errno = EINVAL;
458 }
459 else
460 {
461 /* Haiku alpha 2 loses fd flags on original. */
462 int flags = fcntl (fd, F_GETFD);
463 if (flags < 0)
464 result = -1;
465 else
466 {
467 result = fcntl (fd, F_DUPFD, target);
468 if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
469 {
470 int saved_errno = errno;
471 close (result);
472 result = -1;
473 errno = saved_errno;
474 }
475# if REPLACE_FCHDIR
476 if (0 <= result)
477 result = _gl_register_dup (fd, result);
478# endif
479 }
480 }
481#else
482 result = fcntl (fd, F_DUPFD, target);
483#endif
484 return result;
485}
486
487static int
488rpl_fcntl_DUPFD_CLOEXEC (int fd, int target)
489{
490 int result;
491#if !HAVE_FCNTL
492 result = dupfd (fd, target, O_CLOEXEC);
493#else /* HAVE_FCNTL */
494# if defined __NetBSD__ || defined __HAIKU__
495 /* On NetBSD 9.0, the system fcntl (fd, F_DUPFD_CLOEXEC, target)
496 has only the same effect as fcntl (fd, F_DUPFD, target). */
497 /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets
498 the FD_CLOEXEC flag on fd, not on target. Therefore avoid the
499 system fcntl in this case. */
500# define have_dupfd_cloexec -1
501# else
502 /* Try the system call first, if the headers claim it exists
503 (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
504 may be running with a glibc that has the macro but with an
505 older kernel that does not support it. Cache the
506 information on whether the system call really works, but
507 avoid caching failure if the corresponding F_DUPFD fails
508 for any reason. 0 = unknown, 1 = yes, -1 = no. */
509 static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
510 if (0 <= have_dupfd_cloexec)
511 {
512 result = fcntl (fd, F_DUPFD_CLOEXEC, target);
513 if (0 <= result || errno != EINVAL)
514 {
515 have_dupfd_cloexec = 1;
516# if REPLACE_FCHDIR
517 if (0 <= result)
518 result = _gl_register_dup (fd, result);
519# endif
520 }
521 else
522 {
523 result = rpl_fcntl_DUPFD (fd, target);
524 if (result >= 0)
525 have_dupfd_cloexec = -1;
526 }
527 }
528 else
529# endif
530 result = rpl_fcntl_DUPFD (fd, target);
531 if (0 <= result && have_dupfd_cloexec == -1)
532 {
533 int flags = fcntl (result, F_GETFD);
534 if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
535 {
536 int saved_errno = errno;
537 close (result);
538 errno = saved_errno;
539 result = -1;
540 }
541 }
542#endif /* HAVE_FCNTL */
543 return result;
544}
545
546#undef fcntl
547
548#ifdef __KLIBC__
549
550static int
551klibc_fcntl (int fd, int action, /* arg */...)
552{
553 va_list arg_ptr;
554 int arg;
555 struct stat sbuf;
556 int result;
557
558 va_start (arg_ptr, action);
559 arg = va_arg (arg_ptr, int);
560 result = fcntl (fd, action, arg);
561 /* EPERM for F_DUPFD, ENOTSUP for others */
562 if (result == -1 && (errno == EPERM || errno == ENOTSUP)
563 && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
564 {
565 ULONG ulMode;
566
567 switch (action)
568 {
569 case F_DUPFD:
570 /* Find available fd */
571 while (fcntl (arg, F_GETFL) != -1 || errno != EBADF)
572 arg++;
573
574 result = dup2 (fd, arg);
575 break;
576
577 /* Using underlying APIs is right ? */
578 case F_GETFD:
579 if (DosQueryFHState (fd, &ulMode))
580 break;
581
582 result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0;
583 break;
584
585 case F_SETFD:
586 if (arg & ~FD_CLOEXEC)
587 break;
588
589 if (DosQueryFHState (fd, &ulMode))
590 break;
591
592 if (arg & FD_CLOEXEC)
593 ulMode |= OPEN_FLAGS_NOINHERIT;
594 else
595 ulMode &= ~OPEN_FLAGS_NOINHERIT;
596
597 /* Filter supported flags. */
598 ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR
599 | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT);
600
601 if (DosSetFHState (fd, ulMode))
602 break;
603
604 result = 0;
605 break;
606
607 case F_GETFL:
608 result = 0;
609 break;
610
611 case F_SETFL:
612 if (arg != 0)
613 break;
614
615 result = 0;
616 break;
617
618 default:
619 errno = EINVAL;
620 break;
621 }
622 }
623
624 va_end (arg_ptr);
625
626 return result;
627}
628
629#endif
diff --git a/gl/fcntl.in.h b/gl/fcntl.in.h
new file mode 100644
index 0000000..e034eaf
--- /dev/null
+++ b/gl/fcntl.in.h
@@ -0,0 +1,445 @@
1/* Like <fcntl.h>, but with non-working flags defined to 0.
2
3 Copyright (C) 2006-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* written by Paul Eggert */
19
20#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@
22#endif
23@PRAGMA_COLUMNS@
24
25#if defined __need_system_fcntl_h
26/* Special invocation convention. */
27
28/* Needed before <sys/stat.h>.
29 May also define off_t to a 64-bit type on native Windows. */
30#include <sys/types.h>
31/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
32 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
33 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
34 extern "C" { ... } block, which leads to errors in C++ mode with the
35 overridden <sys/stat.h> from gnulib. These errors are known to be gone
36 with g++ version >= 4.3. */
37#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
38# include <sys/stat.h>
39#endif
40#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
41
42/* Native Windows platforms declare open(), creat() in <io.h>. */
43#if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
44 && (defined _WIN32 && ! defined __CYGWIN__)
45# include <io.h>
46#endif
47
48#else
49/* Normal invocation convention. */
50
51#ifndef _@GUARD_PREFIX@_FCNTL_H
52
53/* Needed before <sys/stat.h>.
54 May also define off_t to a 64-bit type on native Windows. */
55#include <sys/types.h>
56/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
57 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
58 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
59 extern "C" { ... } block, which leads to errors in C++ mode with the
60 overridden <sys/stat.h> from gnulib. These errors are known to be gone
61 with g++ version >= 4.3. */
62#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
63# include <sys/stat.h>
64#endif
65/* The include_next requires a split double-inclusion guard. */
66#@INCLUDE_NEXT@ @NEXT_FCNTL_H@
67
68/* Native Windows platforms declare open(), creat() in <io.h>. */
69#if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
70 && (defined _WIN32 && ! defined __CYGWIN__)
71# include <io.h>
72#endif
73
74#ifndef _@GUARD_PREFIX@_FCNTL_H
75#define _@GUARD_PREFIX@_FCNTL_H
76
77#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
78# include <unistd.h>
79#endif
80
81
82/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
83
84/* The definition of _GL_ARG_NONNULL is copied here. */
85
86/* The definition of _GL_WARN_ON_USE is copied here. */
87
88
89/* Declare overridden functions. */
90
91#if @GNULIB_CREAT@
92# if @REPLACE_CREAT@
93# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
94# undef creat
95# define creat rpl_creat
96# endif
97_GL_FUNCDECL_RPL (creat, int, (const char *filename, mode_t mode)
98 _GL_ARG_NONNULL ((1)));
99_GL_CXXALIAS_RPL (creat, int, (const char *filename, mode_t mode));
100# elif defined _WIN32 && !defined __CYGWIN__
101# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
102# undef creat
103# define creat _creat
104# endif
105_GL_CXXALIAS_MDA (creat, int, (const char *filename, mode_t mode));
106# else
107_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
108# endif
109_GL_CXXALIASWARN (creat);
110#elif defined GNULIB_POSIXCHECK
111# undef creat
112/* Assume creat is always declared. */
113_GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
114 "use gnulib module creat for portability");
115#elif @GNULIB_MDA_CREAT@
116/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
117 required. In C++ with GNULIB_NAMESPACE, avoid differences between
118 platforms by defining GNULIB_NAMESPACE::creat always. */
119# if defined _WIN32 && !defined __CYGWIN__
120# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121# undef creat
122# define creat _creat
123# endif
124/* Need to cast, because in mingw the last argument is 'int mode'. */
125_GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
126# else
127_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
128# endif
129_GL_CXXALIASWARN (creat);
130#endif
131
132#if @GNULIB_FCNTL@
133# if @REPLACE_FCNTL@
134# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
135# undef fcntl
136# define fcntl rpl_fcntl
137# endif
138_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
139_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
140# if !GNULIB_defined_rpl_fcntl
141# define GNULIB_defined_rpl_fcntl 1
142# endif
143# else
144# if !@HAVE_FCNTL@
145_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
146# if !GNULIB_defined_fcntl
147# define GNULIB_defined_fcntl 1
148# endif
149# endif
150_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
151# endif
152_GL_CXXALIASWARN (fcntl);
153#elif defined GNULIB_POSIXCHECK
154# undef fcntl
155# if HAVE_RAW_DECL_FCNTL
156_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
157 "use gnulib module fcntl for portability");
158# endif
159#endif
160
161#if @GNULIB_OPEN@
162# if @REPLACE_OPEN@
163# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
164# undef open
165# define open rpl_open
166# endif
167_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
168 _GL_ARG_NONNULL ((1)));
169_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
170# elif defined _WIN32 && !defined __CYGWIN__
171# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
172# undef open
173# define open _open
174# endif
175_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
176# else
177_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
178# endif
179/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
180 default argument. _GL_CXXALIASWARN does not work in this case. */
181# if !defined __hpux
182_GL_CXXALIASWARN (open);
183# endif
184#elif defined GNULIB_POSIXCHECK
185# undef open
186/* Assume open is always declared. */
187_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
188 "use gnulib module open for portability");
189#elif @GNULIB_MDA_OPEN@
190/* On native Windows, map 'open' to '_open', so that -loldnames is not
191 required. In C++ with GNULIB_NAMESPACE, avoid differences between
192 platforms by defining GNULIB_NAMESPACE::open always. */
193# if defined _WIN32 && !defined __CYGWIN__
194# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
195# undef open
196# define open _open
197# endif
198_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
199# else
200_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
201# endif
202# if !defined __hpux
203_GL_CXXALIASWARN (open);
204# endif
205#endif
206
207#if @GNULIB_OPENAT@
208# if @REPLACE_OPENAT@
209# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
210# undef openat
211# define openat rpl_openat
212# endif
213_GL_FUNCDECL_RPL (openat, int,
214 (int fd, char const *file, int flags, /* mode_t mode */ ...)
215 _GL_ARG_NONNULL ((2)));
216_GL_CXXALIAS_RPL (openat, int,
217 (int fd, char const *file, int flags, /* mode_t mode */ ...));
218# else
219# if !@HAVE_OPENAT@
220_GL_FUNCDECL_SYS (openat, int,
221 (int fd, char const *file, int flags, /* mode_t mode */ ...)
222 _GL_ARG_NONNULL ((2)));
223# endif
224_GL_CXXALIAS_SYS (openat, int,
225 (int fd, char const *file, int flags, /* mode_t mode */ ...));
226# endif
227_GL_CXXALIASWARN (openat);
228#elif defined GNULIB_POSIXCHECK
229# undef openat
230# if HAVE_RAW_DECL_OPENAT
231_GL_WARN_ON_USE (openat, "openat is not portable - "
232 "use gnulib module openat for portability");
233# endif
234#endif
235
236
237/* Fix up the FD_* macros, only known to be missing on mingw. */
238
239#ifndef FD_CLOEXEC
240# define FD_CLOEXEC 1
241#endif
242
243/* Fix up the supported F_* macros. Intentionally leave other F_*
244 macros undefined. Only known to be missing on mingw. */
245
246#ifndef F_DUPFD_CLOEXEC
247# define F_DUPFD_CLOEXEC 0x40000000
248/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
249# define GNULIB_defined_F_DUPFD_CLOEXEC 1
250#else
251# define GNULIB_defined_F_DUPFD_CLOEXEC 0
252#endif
253
254#ifndef F_DUPFD
255# define F_DUPFD 1
256#endif
257
258#ifndef F_GETFD
259# define F_GETFD 2
260#endif
261
262/* Fix up the O_* macros. */
263
264/* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
265 to values outside 'int' range, so omit these misdefinitions.
266 But avoid namespace pollution on non-AIX systems. */
267#ifdef _AIX
268# include <limits.h>
269# if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
270# undef O_CLOEXEC
271# endif
272# if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
273# undef O_NOFOLLOW
274# endif
275# if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
276# undef O_TTY_INIT
277# endif
278#endif
279
280#if !defined O_DIRECT && defined O_DIRECTIO
281/* Tru64 spells it 'O_DIRECTIO'. */
282# define O_DIRECT O_DIRECTIO
283#endif
284
285#if !defined O_CLOEXEC && defined O_NOINHERIT
286/* Mingw spells it 'O_NOINHERIT'. */
287# define O_CLOEXEC O_NOINHERIT
288#endif
289
290#ifndef O_CLOEXEC
291# define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
292# define GNULIB_defined_O_CLOEXEC 1
293#else
294# define GNULIB_defined_O_CLOEXEC 0
295#endif
296
297#ifndef O_DIRECT
298# define O_DIRECT 0
299#endif
300
301#ifndef O_DIRECTORY
302# define O_DIRECTORY 0
303#endif
304
305#ifndef O_DSYNC
306# define O_DSYNC 0
307#endif
308
309#ifndef O_EXEC
310# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
311#endif
312
313#ifndef O_IGNORE_CTTY
314# define O_IGNORE_CTTY 0
315#endif
316
317#ifndef O_NDELAY
318# define O_NDELAY 0
319#endif
320
321#ifndef O_NOATIME
322# define O_NOATIME 0
323#endif
324
325#ifndef O_NONBLOCK
326# define O_NONBLOCK O_NDELAY
327#endif
328
329/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
330 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
331 or to 0 as fallback. */
332#if @GNULIB_NONBLOCKING@
333# if O_NONBLOCK
334# define GNULIB_defined_O_NONBLOCK 0
335# else
336# define GNULIB_defined_O_NONBLOCK 1
337# undef O_NONBLOCK
338# define O_NONBLOCK 0x40000000
339# endif
340#endif
341
342#ifndef O_NOCTTY
343# define O_NOCTTY 0
344#endif
345
346#ifndef O_NOFOLLOW
347# define O_NOFOLLOW 0
348#endif
349
350#ifndef O_NOLINK
351# define O_NOLINK 0
352#endif
353
354#ifndef O_NOLINKS
355# define O_NOLINKS 0
356#endif
357
358#ifndef O_NOTRANS
359# define O_NOTRANS 0
360#endif
361
362#ifndef O_RSYNC
363# define O_RSYNC 0
364#endif
365
366#ifndef O_SEARCH
367# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
368#endif
369
370#ifndef O_SYNC
371# define O_SYNC 0
372#endif
373
374#ifndef O_TTY_INIT
375# define O_TTY_INIT 0
376#endif
377
378#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
379# undef O_ACCMODE
380# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
381#endif
382
383/* For systems that distinguish between text and binary I/O.
384 O_BINARY is usually declared in fcntl.h */
385#if !defined O_BINARY && defined _O_BINARY
386 /* For MSC-compatible compilers. */
387# define O_BINARY _O_BINARY
388# define O_TEXT _O_TEXT
389#endif
390
391#if defined __BEOS__ || defined __HAIKU__
392 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
393# undef O_BINARY
394# undef O_TEXT
395#endif
396
397#ifndef O_BINARY
398# define O_BINARY 0
399# define O_TEXT 0
400#endif
401
402/* Fix up the AT_* macros. */
403
404/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
405 value exceeds INT_MAX, so its use as an int doesn't conform to the
406 C standard, and GCC and Sun C complain in some cases. If the bug
407 is present, undef AT_FDCWD here, so it can be redefined below. */
408#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
409# undef AT_FDCWD
410#endif
411
412/* Use the same bit pattern as Solaris 9, but with the proper
413 signedness. The bit pattern is important, in case this actually is
414 Solaris with the above workaround. */
415#ifndef AT_FDCWD
416# define AT_FDCWD (-3041965)
417#endif
418
419/* Use the same values as Solaris 9. This shouldn't matter, but
420 there's no real reason to differ. */
421#ifndef AT_SYMLINK_NOFOLLOW
422# define AT_SYMLINK_NOFOLLOW 4096
423#endif
424
425#ifndef AT_REMOVEDIR
426# define AT_REMOVEDIR 1
427#endif
428
429/* Solaris 9 lacks these two, so just pick unique values. */
430#ifndef AT_SYMLINK_FOLLOW
431# define AT_SYMLINK_FOLLOW 2
432#endif
433
434#ifndef AT_EACCESS
435# define AT_EACCESS 4
436#endif
437
438/* Ignore this flag if not supported. */
439#ifndef AT_NO_AUTOMOUNT
440# define AT_NO_AUTOMOUNT 0
441#endif
442
443#endif /* _@GUARD_PREFIX@_FCNTL_H */
444#endif /* _@GUARD_PREFIX@_FCNTL_H */
445#endif
diff --git a/gl/fd-hook.c b/gl/fd-hook.c
index e158a52..3626115 100644
--- a/gl/fd-hook.c
+++ b/gl/fd-hook.c
@@ -1,19 +1,19 @@
1/* Hook for making making file descriptor functions close(), ioctl() extensible. 1/* Hook for making file descriptor functions close(), ioctl() extensible.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2009-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009. 3 Written by Bruno Haible <bruno@clisp.org>, 2009.
4 4
5 This program is free software: you can redistribute it and/or modify it 5 This file is free software: you can redistribute it and/or modify
6 under the terms of the GNU General Public License as published 6 it under the terms of the GNU Lesser General Public License as
7 by the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 General Public License for more details. 13 GNU Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/fd-hook.h b/gl/fd-hook.h
index d15b577..6bf3c24 100644
--- a/gl/fd-hook.h
+++ b/gl/fd-hook.h
@@ -1,18 +1,18 @@
1/* Hook for making making file descriptor functions close(), ioctl() extensible. 1/* Hook for making file descriptor functions close(), ioctl() extensible.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify it 4 This file is free software: you can redistribute it and/or modify
5 under the terms of the GNU General Public License as published 5 it under the terms of the GNU Lesser General Public License as
6 by the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation; either version 2.1 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17 17
18#ifndef FD_HOOK_H 18#ifndef FD_HOOK_H
diff --git a/gl/fflush.c b/gl/fflush.c
new file mode 100644
index 0000000..f3689b3
--- /dev/null
+++ b/gl/fflush.c
@@ -0,0 +1,233 @@
1/* fflush.c -- allow flushing input streams
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Eric Blake. */
18
19#include <config.h>
20
21/* Specification. */
22#include <stdio.h>
23
24#include <errno.h>
25#include <unistd.h>
26
27#include "freading.h"
28
29#include "stdio-impl.h"
30
31#undef fflush
32
33
34#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
35/* GNU libc, BeOS, Haiku, Linux libc5 */
36
37/* Clear the stream's ungetc buffer, preserving the value of ftello (fp). */
38static void
39clear_ungetc_buffer_preserving_position (FILE *fp)
40{
41 if (fp->_flags & _IO_IN_BACKUP)
42 /* _IO_free_backup_area is a bit complicated. Simply call fseek. */
43 fseeko (fp, 0, SEEK_CUR);
44}
45
46#else
47
48/* Clear the stream's ungetc buffer. May modify the value of ftello (fp). */
49static void
50clear_ungetc_buffer (FILE *fp)
51{
52# if defined __sferror || defined __DragonFly__ || defined __ANDROID__
53 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
54 if (HASUB (fp))
55 {
56 fp_->_p += fp_->_r;
57 fp_->_r = 0;
58 }
59# elif defined __EMX__ /* emx+gcc */
60 if (fp->_ungetc_count > 0)
61 {
62 fp->_ungetc_count = 0;
63 fp->_rcount = - fp->_rcount;
64 }
65# elif defined _IOERR /* Minix, AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
66 /* Nothing to do. */
67# else /* other implementations */
68 fseeko (fp, 0, SEEK_CUR);
69# endif
70}
71
72#endif
73
74#if ! (defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1)
75/* GNU libc, BeOS, Haiku, Linux libc5 */
76
77# if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
78/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
79
80static int
81disable_seek_optimization (FILE *fp)
82{
83 int saved_flags = fp_->_flags & (__SOPT | __SNPT);
84 fp_->_flags = (fp_->_flags & ~__SOPT) | __SNPT;
85 return saved_flags;
86}
87
88static void
89restore_seek_optimization (FILE *fp, int saved_flags)
90{
91 fp_->_flags = (fp_->_flags & ~(__SOPT | __SNPT)) | saved_flags;
92}
93
94# else
95
96static void
97update_fpos_cache (_GL_ATTRIBUTE_MAYBE_UNUSED FILE *fp,
98 _GL_ATTRIBUTE_MAYBE_UNUSED off_t pos)
99{
100# if defined __sferror || defined __DragonFly__ || defined __ANDROID__
101 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
102# if defined __CYGWIN__ || defined __ANDROID__
103 /* fp_->_offset is typed as an integer. */
104 fp_->_offset = pos;
105# else
106 /* fp_->_offset is an fpos_t. */
107 /* Use a union, since on NetBSD, the compilation flags determine
108 whether fpos_t is typedef'd to off_t or a struct containing a
109 single off_t member. */
110 union
111 {
112 fpos_t f;
113 off_t o;
114 } u;
115 u.o = pos;
116 fp_->_offset = u.f;
117# endif
118 fp_->_flags |= __SOFF;
119# endif
120}
121# endif
122#endif
123
124/* Flush all pending data on STREAM according to POSIX rules. Both
125 output and seekable input streams are supported. */
126int
127rpl_fflush (FILE *stream)
128{
129 /* When stream is NULL, POSIX and C99 only require flushing of "output
130 streams and update streams in which the most recent operation was not
131 input", and all implementations do this.
132
133 When stream is "an output stream or an update stream in which the most
134 recent operation was not input", POSIX and C99 requires that fflush
135 writes out any buffered data, and all implementations do this.
136
137 When stream is, however, an input stream or an update stream in
138 which the most recent operation was input, C99 specifies nothing,
139 and POSIX only specifies behavior if the stream is seekable.
140 mingw, in particular, drops the input buffer, leaving the file
141 descriptor positioned at the end of the input buffer. I.e. ftell
142 (stream) is lost. We don't want to call the implementation's
143 fflush in this case.
144
145 We test ! freading (stream) here, rather than fwriting (stream), because
146 what we need to know is whether the stream holds a "read buffer", and on
147 mingw this is indicated by _IOREAD, regardless of _IOWRT. */
148 if (stream == NULL || ! freading (stream))
149 return fflush (stream);
150
151#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
152 /* GNU libc, BeOS, Haiku, Linux libc5 */
153
154 clear_ungetc_buffer_preserving_position (stream);
155
156 return fflush (stream);
157
158#else
159 {
160 /* What POSIX says:
161 1) About the file-position indicator (-> fseeko, ftello):
162 The file position indicator is incremented by fgetc() and decremented
163 by ungetc():
164 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetc.html>
165 "... the fgetc() function shall ... advance the associated file
166 position indicator for the stream ..."
167 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ungetc.html>
168 "The file-position indicator is decremented by each successful
169 call to ungetc()..."
170 2) fflush discards bytes pushed back by ungetc:
171 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html>
172 "...any characters pushed back onto the stream by ungetc()
173 or ungetwc() that have not subsequently been read from the
174 stream shall be discarded..."
175 This implies implicitly: fflush does not change the file position
176 indicator.
177 3) Effects on the file descriptor, if the file descriptor is capable of
178 seeking:
179 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html>
180 "...the file offset of the underlying open file description shall
181 be set to the file position of the stream..." */
182
183 /* POSIX does not specify fflush behavior for non-seekable input
184 streams. Some implementations purge unread data, some return
185 EBADF, some do nothing. */
186 off_t pos = ftello (stream);
187 if (pos == -1)
188 {
189 errno = EBADF;
190 return EOF;
191 }
192
193 /* Clear the ungetc buffer. */
194 clear_ungetc_buffer (stream);
195
196 /* To get here, we must be flushing a seekable input stream, so the
197 semantics of fpurge are now appropriate to clear the buffer. To
198 avoid losing data, the lseek is also necessary. */
199 {
200 int result = fpurge (stream);
201 if (result != 0)
202 return result;
203 }
204
205# if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
206 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
207
208 {
209 /* Disable seek optimization for the next fseeko call. This tells the
210 following fseeko call to seek to the desired position directly, rather
211 than to seek to a block-aligned boundary. */
212 int saved_flags = disable_seek_optimization (stream);
213 int result = fseeko (stream, pos, SEEK_SET);
214
215 restore_seek_optimization (stream, saved_flags);
216 return result;
217 }
218
219# else
220
221 pos = lseek (fileno (stream), pos, SEEK_SET);
222 if (pos == -1)
223 return EOF;
224 /* After a successful lseek, update the file descriptor's position cache
225 in the stream. */
226 update_fpos_cache (stream, pos);
227
228 return 0;
229
230# endif
231 }
232#endif
233}
diff --git a/gl/filename.h b/gl/filename.h
new file mode 100644
index 0000000..a2400a9
--- /dev/null
+++ b/gl/filename.h
@@ -0,0 +1,112 @@
1/* Basic filename support macros.
2 Copyright (C) 2001-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19/* From Paul Eggert and Jim Meyering. */
20
21#ifndef _FILENAME_H
22#define _FILENAME_H
23
24#include <string.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30
31/* Filename support.
32 ISSLASH(C) tests whether C is a directory separator
33 character.
34 HAS_DEVICE(Filename) tests whether Filename contains a device
35 specification.
36 FILE_SYSTEM_PREFIX_LEN(Filename) length of the device specification
37 at the beginning of Filename,
38 index of the part consisting of
39 alternating components and slashes.
40 FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
41 1 when a non-empty device specification
42 can be followed by an empty or relative
43 part,
44 0 when a non-empty device specification
45 must be followed by a slash,
46 0 when device specification don't exist.
47 IS_ABSOLUTE_FILE_NAME(Filename)
48 tests whether Filename is independent of
49 any notion of "current directory".
50 IS_RELATIVE_FILE_NAME(Filename)
51 tests whether Filename may be concatenated
52 to a directory filename.
53 Note: On native Windows, OS/2, DOS, "c:" is neither an absolute nor a
54 relative file name!
55 IS_FILE_NAME_WITH_DIR(Filename) tests whether Filename contains a device
56 or directory specification.
57 */
58#if defined _WIN32 || defined __CYGWIN__ \
59 || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__
60 /* Native Windows, Cygwin, OS/2, DOS */
61# define ISSLASH(C) ((C) == '/' || (C) == '\\')
62 /* Internal macro: Tests whether a character is a drive letter. */
63# define _IS_DRIVE_LETTER(C) \
64 (((C) >= 'A' && (C) <= 'Z') || ((C) >= 'a' && (C) <= 'z'))
65 /* Help the compiler optimizing it. This assumes ASCII. */
66# undef _IS_DRIVE_LETTER
67# define _IS_DRIVE_LETTER(C) \
68 (((unsigned int) (C) | ('a' - 'A')) - 'a' <= 'z' - 'a')
69# define HAS_DEVICE(Filename) \
70 (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':')
71# define FILE_SYSTEM_PREFIX_LEN(Filename) (HAS_DEVICE (Filename) ? 2 : 0)
72# ifdef __CYGWIN__
73# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
74# else
75 /* On native Windows, OS/2, DOS, the system has the notion of a
76 "current directory" on each drive. */
77# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
78# endif
79# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
80# define IS_ABSOLUTE_FILE_NAME(Filename) \
81 ISSLASH ((Filename)[FILE_SYSTEM_PREFIX_LEN (Filename)])
82# else
83# define IS_ABSOLUTE_FILE_NAME(Filename) \
84 (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename))
85# endif
86# define IS_RELATIVE_FILE_NAME(Filename) \
87 (! (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename)))
88# define IS_FILE_NAME_WITH_DIR(Filename) \
89 (strchr ((Filename), '/') != NULL || strchr ((Filename), '\\') != NULL \
90 || HAS_DEVICE (Filename))
91#else
92 /* Unix */
93# define ISSLASH(C) ((C) == '/')
94# define HAS_DEVICE(Filename) ((void) (Filename), 0)
95# define FILE_SYSTEM_PREFIX_LEN(Filename) ((void) (Filename), 0)
96# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
97# define IS_ABSOLUTE_FILE_NAME(Filename) ISSLASH ((Filename)[0])
98# define IS_RELATIVE_FILE_NAME(Filename) (! ISSLASH ((Filename)[0]))
99# define IS_FILE_NAME_WITH_DIR(Filename) (strchr ((Filename), '/') != NULL)
100#endif
101
102/* Deprecated macros. For backward compatibility with old users of the
103 'filename' module. */
104#define IS_ABSOLUTE_PATH IS_ABSOLUTE_FILE_NAME
105#define IS_PATH_WITH_DIR IS_FILE_NAME_WITH_DIR
106
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif /* _FILENAME_H */
diff --git a/gl/float+.h b/gl/float+.h
index 32fb790..e7531e4 100644
--- a/gl/float+.h
+++ b/gl/float+.h
@@ -1,19 +1,19 @@
1/* Supplemental information about the floating-point formats. 1/* Supplemental information about the floating-point formats.
2 Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2007. 3 Written by Bruno Haible <bruno@clisp.org>, 2007.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _FLOATPLUS_H 18#ifndef _FLOATPLUS_H
19#define _FLOATPLUS_H 19#define _FLOATPLUS_H
diff --git a/gl/float.c b/gl/float.c
index 366945f..f81ff33 100644
--- a/gl/float.c
+++ b/gl/float.c
@@ -1,19 +1,19 @@
1/* Auxiliary definitions for <float.h>. 1/* Auxiliary definitions for <float.h>.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011. 3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/float.in.h b/gl/float.in.h
index 84e1950..bf2c502 100644
--- a/gl/float.in.h
+++ b/gl/float.in.h
@@ -1,19 +1,19 @@
1/* A correct <float.h>. 1/* A correct <float.h>.
2 2
3 Copyright (C) 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _@GUARD_PREFIX@_FLOAT_H 18#ifndef _@GUARD_PREFIX@_FLOAT_H
19 19
@@ -62,8 +62,8 @@
62 62
63/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of 63/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
64 precision in the compiler but 64 bits of precision at runtime. See 64 precision in the compiler but 64 bits of precision at runtime. See
65 <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>. */ 65 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>. */
66#if defined __i386__ && defined __FreeBSD__ 66#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
67/* Number of mantissa units, in base FLT_RADIX. */ 67/* Number of mantissa units, in base FLT_RADIX. */
68# undef LDBL_MANT_DIG 68# undef LDBL_MANT_DIG
69# define LDBL_MANT_DIG 64 69# define LDBL_MANT_DIG 64
@@ -81,7 +81,7 @@
81# define LDBL_MAX_EXP 16384 81# define LDBL_MAX_EXP 16384
82/* Minimum positive normalized number. */ 82/* Minimum positive normalized number. */
83# undef LDBL_MIN 83# undef LDBL_MIN
84# define LDBL_MIN 3.3621031431120935E-4932L /* = 0x1p-16382L */ 84# define LDBL_MIN 3.362103143112093506262677817321752E-4932L /* = 0x1p-16382L */
85/* Maximum representable finite number. */ 85/* Maximum representable finite number. */
86# undef LDBL_MAX 86# undef LDBL_MAX
87/* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }. 87/* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }.
@@ -93,11 +93,14 @@
93 extern const long double LDBL_MAX; 93 extern const long double LDBL_MAX;
94 94
95 Unfortunately, this is not a constant expression. */ 95 Unfortunately, this is not a constant expression. */
96# if !GNULIB_defined_long_double_union
96union gl_long_double_union 97union gl_long_double_union
97 { 98 {
98 struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd; 99 struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd;
99 long double ld; 100 long double ld;
100 }; 101 };
102# define GNULIB_defined_long_double_union 1
103# endif
101extern const union gl_long_double_union gl_LDBL_MAX; 104extern const union gl_long_double_union gl_LDBL_MAX;
102# define LDBL_MAX (gl_LDBL_MAX.ld) 105# define LDBL_MAX (gl_LDBL_MAX.ld)
103/* Minimum e such that 10^e is in the range of normalized numbers. */ 106/* Minimum e such that 10^e is in the range of normalized numbers. */
@@ -146,11 +149,14 @@ extern const union gl_long_double_union gl_LDBL_MAX;
146 149
147 Unfortunately, this is not a constant expression, and the latter expression 150 Unfortunately, this is not a constant expression, and the latter expression
148 does not work well when GCC is optimizing.. */ 151 does not work well when GCC is optimizing.. */
152# if !GNULIB_defined_long_double_union
149union gl_long_double_union 153union gl_long_double_union
150 { 154 {
151 struct { double hi; double lo; } dd; 155 struct { double hi; double lo; } dd;
152 long double ld; 156 long double ld;
153 }; 157 };
158# define GNULIB_defined_long_double_union 1
159# endif
154extern const union gl_long_double_union gl_LDBL_MAX; 160extern const union gl_long_double_union gl_LDBL_MAX;
155# define LDBL_MAX (gl_LDBL_MAX.ld) 161# define LDBL_MAX (gl_LDBL_MAX.ld)
156#endif 162#endif
diff --git a/gl/floor.c b/gl/floor.c
index cf29b19..238f487 100644
--- a/gl/floor.c
+++ b/gl/floor.c
@@ -1,18 +1,18 @@
1/* Round towards negative infinity. 1/* Round towards negative infinity.
2 Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2010-2023 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation, either version 3 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ 17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
18 18
@@ -44,7 +44,7 @@
44 44
45/* MSVC with option -fp:strict refuses to compile constant initializers that 45/* MSVC with option -fp:strict refuses to compile constant initializers that
46 contain floating-point operations. Pacify this compiler. */ 46 contain floating-point operations. Pacify this compiler. */
47#ifdef _MSC_VER 47#if defined _MSC_VER && !defined __clang__
48# pragma fenv_access (off) 48# pragma fenv_access (off)
49#endif 49#endif
50 50
diff --git a/gl/floorf.c b/gl/floorf.c
index bbd3382..e465c18 100644
--- a/gl/floorf.c
+++ b/gl/floorf.c
@@ -1,18 +1,18 @@
1/* Round towards negative infinity. 1/* Round towards negative infinity.
2 Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation, either version 3 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ 17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
18 18
diff --git a/gl/fopen.c b/gl/fopen.c
new file mode 100644
index 0000000..f8469a0
--- /dev/null
+++ b/gl/fopen.c
@@ -0,0 +1,229 @@
1/* Open a stream to a file.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
18
19/* If the user's config.h happens to include <stdio.h>, let it include only
20 the system's <stdio.h> here, so that orig_fopen doesn't recurse to
21 rpl_fopen. */
22#define _GL_ALREADY_INCLUDING_STDIO_H
23#include <config.h>
24
25/* Get the original definition of fopen. It might be defined as a macro. */
26#include <stdio.h>
27#undef _GL_ALREADY_INCLUDING_STDIO_H
28
29static FILE *
30orig_fopen (const char *filename, const char *mode)
31{
32 return fopen (filename, mode);
33}
34
35/* Specification. */
36/* Write "stdio.h" here, not <stdio.h>, otherwise OSF/1 5.1 DTK cc eliminates
37 this include because of the preliminary #include <stdio.h> above. */
38#include "stdio.h"
39
40#include <errno.h>
41#include <fcntl.h>
42#include <string.h>
43#include <unistd.h>
44#include <sys/types.h>
45#include <sys/stat.h>
46
47FILE *
48rpl_fopen (const char *filename, const char *mode)
49{
50 int open_direction;
51 int open_flags;
52#if GNULIB_FOPEN_GNU
53 bool open_flags_gnu;
54# define BUF_SIZE 80
55 char fdopen_mode_buf[BUF_SIZE + 1];
56#endif
57
58#if defined _WIN32 && ! defined __CYGWIN__
59 if (strcmp (filename, "/dev/null") == 0)
60 filename = "NUL";
61#endif
62
63 /* Parse the mode. */
64 open_direction = 0;
65 open_flags = 0;
66#if GNULIB_FOPEN_GNU
67 open_flags_gnu = false;
68#endif
69 {
70 const char *p = mode;
71#if GNULIB_FOPEN_GNU
72 char *q = fdopen_mode_buf;
73#endif
74
75 for (; *p != '\0'; p++)
76 {
77 switch (*p)
78 {
79 case 'r':
80 open_direction = O_RDONLY;
81#if GNULIB_FOPEN_GNU
82 if (q < fdopen_mode_buf + BUF_SIZE)
83 *q++ = *p;
84#endif
85 continue;
86 case 'w':
87 open_direction = O_WRONLY;
88 open_flags |= O_CREAT | O_TRUNC;
89#if GNULIB_FOPEN_GNU
90 if (q < fdopen_mode_buf + BUF_SIZE)
91 *q++ = *p;
92#endif
93 continue;
94 case 'a':
95 open_direction = O_WRONLY;
96 open_flags |= O_CREAT | O_APPEND;
97#if GNULIB_FOPEN_GNU
98 if (q < fdopen_mode_buf + BUF_SIZE)
99 *q++ = *p;
100#endif
101 continue;
102 case 'b':
103 /* While it is non-standard, O_BINARY is guaranteed by
104 gnulib <fcntl.h>. We can also assume that orig_fopen
105 supports the 'b' flag. */
106 open_flags |= O_BINARY;
107#if GNULIB_FOPEN_GNU
108 if (q < fdopen_mode_buf + BUF_SIZE)
109 *q++ = *p;
110#endif
111 continue;
112 case '+':
113 open_direction = O_RDWR;
114#if GNULIB_FOPEN_GNU
115 if (q < fdopen_mode_buf + BUF_SIZE)
116 *q++ = *p;
117#endif
118 continue;
119#if GNULIB_FOPEN_GNU
120 case 'x':
121 open_flags |= O_EXCL;
122 open_flags_gnu = true;
123 continue;
124 case 'e':
125 open_flags |= O_CLOEXEC;
126 open_flags_gnu = true;
127 continue;
128#endif
129 default:
130 break;
131 }
132#if GNULIB_FOPEN_GNU
133 /* The rest of the mode string can be a platform-dependent extension.
134 Copy it unmodified. */
135 {
136 size_t len = strlen (p);
137 if (len > fdopen_mode_buf + BUF_SIZE - q)
138 len = fdopen_mode_buf + BUF_SIZE - q;
139 memcpy (q, p, len);
140 q += len;
141 }
142#endif
143 break;
144 }
145#if GNULIB_FOPEN_GNU
146 *q = '\0';
147#endif
148 }
149
150#if FOPEN_TRAILING_SLASH_BUG
151 /* Fail if the mode requires write access and the filename ends in a slash,
152 as POSIX says such a filename must name a directory
153 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
154 "A pathname that contains at least one non-<slash> character and that
155 ends with one or more trailing <slash> characters shall not be resolved
156 successfully unless the last pathname component before the trailing
157 <slash> characters names an existing directory"
158 If the named file already exists as a directory, then if a mode that
159 requires write access is specified, fopen() must fail because POSIX
160 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html>
161 says that it fails with errno = EISDIR in this case.
162 If the named file does not exist or does not name a directory, then
163 fopen() must fail since the file does not contain a '.' directory. */
164 {
165 size_t len = strlen (filename);
166 if (len > 0 && filename[len - 1] == '/')
167 {
168 int fd;
169 struct stat statbuf;
170 FILE *fp;
171
172 if (open_direction != O_RDONLY)
173 {
174 errno = EISDIR;
175 return NULL;
176 }
177
178 fd = open (filename, open_direction | open_flags,
179 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
180 if (fd < 0)
181 return NULL;
182
183 if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
184 {
185 close (fd);
186 errno = ENOTDIR;
187 return NULL;
188 }
189
190# if GNULIB_FOPEN_GNU
191 fp = fdopen (fd, fdopen_mode_buf);
192# else
193 fp = fdopen (fd, mode);
194# endif
195 if (fp == NULL)
196 {
197 int saved_errno = errno;
198 close (fd);
199 errno = saved_errno;
200 }
201 return fp;
202 }
203 }
204#endif
205
206#if GNULIB_FOPEN_GNU
207 if (open_flags_gnu)
208 {
209 int fd;
210 FILE *fp;
211
212 fd = open (filename, open_direction | open_flags,
213 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
214 if (fd < 0)
215 return NULL;
216
217 fp = fdopen (fd, fdopen_mode_buf);
218 if (fp == NULL)
219 {
220 int saved_errno = errno;
221 close (fd);
222 errno = saved_errno;
223 }
224 return fp;
225 }
226#endif
227
228 return orig_fopen (filename, mode);
229}
diff --git a/gl/fpurge.c b/gl/fpurge.c
new file mode 100644
index 0000000..0dcb2b7
--- /dev/null
+++ b/gl/fpurge.c
@@ -0,0 +1,150 @@
1/* Flushing buffers of a FILE stream.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <stdio.h>
21
22#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.10, Android API >= 23, musl libc */
23# if HAVE_STDIO_EXT_H
24# include <stdio_ext.h>
25# endif
26#endif
27#include <stdlib.h>
28
29#include "stdio-impl.h"
30
31int
32fpurge (FILE *fp)
33{
34#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.10, Android API >= 23, musl libc */
35
36 __fpurge (fp);
37 /* The __fpurge function does not have a return value. */
38 return 0;
39
40#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin >= 1.7 */
41
42 /* Call the system's fpurge function. */
43# undef fpurge
44# if !HAVE_DECL_FPURGE
45 extern int fpurge (FILE *);
46# endif
47 int result = fpurge (fp);
48# if defined __sferror || defined __DragonFly__ || defined __ANDROID__
49 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
50 if (result == 0)
51 /* Correct the invariants that fpurge broke.
52 <stdio.h> on BSD systems says:
53 "The following always hold: if _flags & __SRD, _w is 0."
54 If this invariant is not fulfilled and the stream is read-write but
55 currently reading, subsequent putc or fputc calls will write directly
56 into the buffer, although they shouldn't be allowed to. */
57 if ((fp_->_flags & __SRD) != 0)
58 fp_->_w = 0;
59# endif
60 return result;
61
62#else
63
64 /* Most systems provide FILE as a struct and the necessary bitmask in
65 <stdio.h>, because they need it for implementing getc() and putc() as
66 fast macros. */
67# if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
68 /* GNU libc, BeOS, Haiku, Linux libc5 */
69 fp->_IO_read_end = fp->_IO_read_ptr;
70 fp->_IO_write_ptr = fp->_IO_write_base;
71 /* Avoid memory leak when there is an active ungetc buffer. */
72 if (fp->_IO_save_base != NULL)
73 {
74 free (fp->_IO_save_base);
75 fp->_IO_save_base = NULL;
76 }
77 return 0;
78# elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
79 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
80 fp_->_p = fp_->_bf._base;
81 fp_->_r = 0;
82 fp_->_w = ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
83 ? fp_->_bf._size
84 : 0);
85 /* Avoid memory leak when there is an active ungetc buffer. */
86 if (fp_ub._base != NULL)
87 {
88 if (fp_ub._base != fp_->_ubuf)
89 free (fp_ub._base);
90 fp_ub._base = NULL;
91 }
92 return 0;
93# elif defined __EMX__ /* emx+gcc */
94 fp->_ptr = fp->_buffer;
95 fp->_rcount = 0;
96 fp->_wcount = 0;
97 fp->_ungetc_count = 0;
98 return 0;
99# elif defined __minix /* Minix */
100 fp->_ptr = fp->_buf;
101 if (fp->_ptr != NULL)
102 fp->_count = 0;
103 return 0;
104# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
105 fp_->_ptr = fp_->_base;
106 if (fp_->_ptr != NULL)
107 fp_->_cnt = 0;
108 return 0;
109# elif defined __UCLIBC__ /* uClibc */
110# ifdef __STDIO_BUFFERS
111 if (fp->__modeflags & __FLAG_WRITING)
112 fp->__bufpos = fp->__bufstart;
113 else if (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING))
114 fp->__bufpos = fp->__bufread;
115# endif
116 return 0;
117# elif defined __QNX__ /* QNX */
118 fp->_Rback = fp->_Back + sizeof (fp->_Back);
119 fp->_Rsave = NULL;
120 if (fp->_Mode & 0x2000 /* _MWRITE */)
121 /* fp->_Buf <= fp->_Next <= fp->_Wend */
122 fp->_Next = fp->_Buf;
123 else
124 /* fp->_Buf <= fp->_Next <= fp->_Rend */
125 fp->_Rend = fp->_Next;
126 return 0;
127# elif defined __MINT__ /* Atari FreeMiNT */
128 if (fp->__pushed_back)
129 {
130 fp->__bufp = fp->__pushback_bufp;
131 fp->__pushed_back = 0;
132 }
133 /* Preserve the current file position. */
134 if (fp->__target != -1)
135 fp->__target += fp->__bufp - fp->__buffer;
136 fp->__bufp = fp->__buffer;
137 /* Nothing in the buffer, next getc is nontrivial. */
138 fp->__get_limit = fp->__bufp;
139 /* Nothing in the buffer, next putc is nontrivial. */
140 fp->__put_limit = fp->__buffer;
141 return 0;
142# elif defined EPLAN9 /* Plan9 */
143 fp->rp = fp->wp = fp->lp = fp->buf;
144 return 0;
145# else
146# error "Please port gnulib fpurge.c to your platform! Look at the definitions of fflush, setvbuf and ungetc on your system, then report this to bug-gnulib."
147# endif
148
149#endif
150}
diff --git a/gl/freading.c b/gl/freading.c
new file mode 100644
index 0000000..b9377cb
--- /dev/null
+++ b/gl/freading.c
@@ -0,0 +1,76 @@
1/* Retrieve information about a FILE stream.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include "freading.h"
21
22#include "stdio-impl.h"
23
24/* Don't use glibc's __freading function in glibc < 2.7, see
25 <https://sourceware.org/bugzilla/show_bug.cgi?id=4359> */
26#if !(HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)))
27
28bool
29freading (FILE *fp)
30{
31 /* Most systems provide FILE as a struct and the necessary bitmask in
32 <stdio.h>, because they need it for implementing getc() and putc() as
33 fast macros. */
34# if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
35 /* GNU libc, BeOS, Haiku, Linux libc5 */
36 return ((fp->_flags & _IO_NO_WRITES) != 0
37 || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
38 && fp->_IO_read_base != NULL));
39# elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
40 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin < 1.7.34, Minix 3, Android */
41 return (fp_->_flags & __SRD) != 0;
42# elif defined __EMX__ /* emx+gcc */
43 return (fp->_flags & _IOREAD) != 0;
44# elif defined __minix /* Minix */
45 return (fp->_flags & _IOREADING) != 0;
46# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
47# if defined __sun /* Solaris */
48 return (fp_->_flag & _IOREAD) != 0 && (fp_->_flag & _IOWRT) == 0;
49# else
50 return (fp_->_flag & _IOREAD) != 0;
51# endif
52# elif defined __UCLIBC__ /* uClibc */
53 return (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) != 0;
54# elif defined __QNX__ /* QNX */
55 return ((fp->_Mode & 0x2 /* _MOPENW */) == 0
56 || (fp->_Mode & 0x1000 /* _MREAD */) != 0);
57# elif defined __MINT__ /* Atari FreeMiNT */
58 if (!fp->__mode.__write)
59 return 1;
60 if (!fp->__mode.__read)
61 return 0;
62# ifdef _IO_CURRENTLY_GETTING /* Flag added on 2009-02-28 */
63 return (fp->__flags & _IO_CURRENTLY_GETTING) != 0;
64# else
65 return (fp->__buffer < fp->__get_limit /*|| fp->__bufp == fp->__put_limit ??*/);
66# endif
67# elif defined EPLAN9 /* Plan9 */
68 if (fp->state == 0 /* CLOSED */ || fp->state == 4 /* WR */)
69 return 0;
70 return (fp->state == 3 /* RD */ && (fp->bufl == 0 || fp->rp < fp->wp));
71# else
72# error "Please port gnulib freading.c to your platform!"
73# endif
74}
75
76#endif
diff --git a/gl/freading.h b/gl/freading.h
new file mode 100644
index 0000000..27b3abb
--- /dev/null
+++ b/gl/freading.h
@@ -0,0 +1,54 @@
1/* Retrieve information about a FILE stream.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <stdio.h>
18
19/* Return true if the stream STREAM is opened read-only, or if the
20 last operation on the stream was a read operation. Return false if
21 the stream is opened write-only or append-only, or if it supports
22 writing and there is no current read operation (such as fgetc).
23
24 freading and fwriting will never both be true. If STREAM supports
25 both reads and writes, then:
26 - both freading and fwriting might be false when the stream is first
27 opened, after read encounters EOF, or after fflush,
28 - freading might be false or true and fwriting might be false
29 after repositioning (such as fseek, fsetpos, or rewind),
30 depending on the underlying implementation.
31
32 STREAM must not be wide-character oriented. */
33
34#if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
35/* Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.34, Android API >= 29, not glibc >= 2.2, but glibc >= 2.7, or musl libc */
36
37# if HAVE_STDIO_EXT_H
38# include <stdio_ext.h>
39# endif
40# define freading(stream) (__freading (stream) != 0)
41
42#else
43
44# ifdef __cplusplus
45extern "C" {
46# endif
47
48extern bool freading (FILE *stream) _GL_ATTRIBUTE_PURE;
49
50# ifdef __cplusplus
51}
52# endif
53
54#endif
diff --git a/gl/free.c b/gl/free.c
new file mode 100644
index 0000000..372a6b0
--- /dev/null
+++ b/gl/free.c
@@ -0,0 +1,53 @@
1/* Make free() preserve errno.
2
3 Copyright (C) 2003, 2006, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* written by Paul Eggert */
19
20#include <config.h>
21
22/* Specification. */
23#include <stdlib.h>
24
25/* A function definition is only needed if HAVE_FREE_POSIX is not defined. */
26#if !HAVE_FREE_POSIX
27
28# include <errno.h>
29
30void
31rpl_free (void *p)
32# undef free
33{
34# if defined __GNUC__ && !defined __clang__
35 /* An invalid GCC optimization
36 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98396>
37 would optimize away the assignments in the code below, when link-time
38 optimization (LTO) is enabled. Make the code more complicated, so that
39 GCC does not grok how to optimize it. */
40 int err[2];
41 err[0] = errno;
42 err[1] = errno;
43 errno = 0;
44 free (p);
45 errno = err[errno == 0];
46# else
47 int err = errno;
48 free (p);
49 errno = err;
50# endif
51}
52
53#endif
diff --git a/gl/fseek.c b/gl/fseek.c
new file mode 100644
index 0000000..9764375
--- /dev/null
+++ b/gl/fseek.c
@@ -0,0 +1,30 @@
1/* An fseek() function that, together with fflush(), is POSIX compliant.
2 Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <stdio.h>
21
22/* Get off_t. */
23#include <unistd.h>
24
25int
26fseek (FILE *fp, long offset, int whence)
27{
28 /* Use the replacement fseeko function with all its workarounds. */
29 return fseeko (fp, (off_t)offset, whence);
30}
diff --git a/gl/fseeko.c b/gl/fseeko.c
new file mode 100644
index 0000000..89a7087
--- /dev/null
+++ b/gl/fseeko.c
@@ -0,0 +1,164 @@
1/* An fseeko() function that, together with fflush(), is POSIX compliant.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <stdio.h>
21
22/* Get off_t, lseek, _POSIX_VERSION. */
23#include <unistd.h>
24
25#include "stdio-impl.h"
26
27int
28fseeko (FILE *fp, off_t offset, int whence)
29#undef fseeko
30#if !HAVE_FSEEKO
31# undef fseek
32# define fseeko fseek
33#endif
34#if _GL_WINDOWS_64_BIT_OFF_T
35# undef fseeko
36# if HAVE__FSEEKI64 && HAVE_DECL__FSEEKI64 /* msvc, mingw since msvcrt8.0, mingw64 */
37# define fseeko _fseeki64
38# else /* mingw before msvcrt8.0 */
39# define fseeko fseeko64
40# endif
41#endif
42{
43#if LSEEK_PIPE_BROKEN
44 /* mingw gives bogus answers rather than failure on non-seekable files. */
45 if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
46 return EOF;
47#endif
48
49 /* These tests are based on fpurge.c. */
50#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
51 /* GNU libc, BeOS, Haiku, Linux libc5 */
52 if (fp->_IO_read_end == fp->_IO_read_ptr
53 && fp->_IO_write_ptr == fp->_IO_write_base
54 && fp->_IO_save_base == NULL)
55#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
56 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
57# if defined __SL64 && defined __SCLE /* Cygwin */
58 if ((fp->_flags & __SL64) == 0)
59 {
60 /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
61 mode; but has an fseeko that requires 64-bit mode. */
62 FILE *tmp = fopen ("/dev/null", "r");
63 if (!tmp)
64 return -1;
65 fp->_flags |= __SL64;
66 fp->_seek64 = tmp->_seek64;
67 fclose (tmp);
68 }
69# endif
70 if (fp_->_p == fp_->_bf._base
71 && fp_->_r == 0
72 && fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
73 ? fp_->_bf._size
74 : 0)
75 && fp_ub._base == NULL)
76#elif defined __EMX__ /* emx+gcc */
77 if (fp->_ptr == fp->_buffer
78 && fp->_rcount == 0
79 && fp->_wcount == 0
80 && fp->_ungetc_count == 0)
81#elif defined __minix /* Minix */
82 if (fp_->_ptr == fp_->_buf
83 && (fp_->_ptr == NULL || fp_->_count == 0))
84#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
85 if (fp_->_ptr == fp_->_base
86 && (fp_->_ptr == NULL || fp_->_cnt == 0))
87#elif defined __UCLIBC__ /* uClibc */
88 if (((fp->__modeflags & __FLAG_WRITING) == 0
89 || fp->__bufpos == fp->__bufstart)
90 && ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
91 || fp->__bufpos == fp->__bufread))
92#elif defined __QNX__ /* QNX */
93 if ((fp->_Mode & 0x2000 /* _MWRITE */ ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
94 && fp->_Rback == fp->_Back + sizeof (fp->_Back)
95 && fp->_Rsave == NULL)
96#elif defined __MINT__ /* Atari FreeMiNT */
97 if (fp->__bufp == fp->__buffer
98 && fp->__get_limit == fp->__bufp
99 && fp->__put_limit == fp->__bufp
100 && !fp->__pushed_back)
101#elif defined EPLAN9 /* Plan9 */
102 if (fp->rp == fp->buf
103 && fp->wp == fp->buf)
104#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION
105 /* Cross-compiling to some other system advertising conformance to
106 POSIX.1-2008 or later. Assume fseeko and fflush work as advertised.
107 If this assumption is incorrect, please report the bug to
108 bug-gnulib. */
109 if (0)
110#else
111 #error "Please port gnulib fseeko.c to your platform! Look at the code in fseeko.c, then report this to bug-gnulib."
112#endif
113 {
114 /* We get here when an fflush() call immediately preceded this one (or
115 if ftell() has created buffers but no I/O has occurred on a
116 newly-opened stream). We know there are no buffers. */
117 off_t pos = lseek (fileno (fp), offset, whence);
118 if (pos == -1)
119 {
120#if defined __sferror || defined __DragonFly__ || defined __ANDROID__
121 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
122 fp_->_flags &= ~__SOFF;
123#endif
124 return -1;
125 }
126
127#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
128 /* GNU libc, BeOS, Haiku, Linux libc5 */
129 fp->_flags &= ~_IO_EOF_SEEN;
130 fp->_offset = pos;
131#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
132 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
133# if defined __CYGWIN__ || (defined __NetBSD__ && __NetBSD_Version__ >= 600000000) || defined __minix
134 /* fp_->_offset is typed as an integer. */
135 fp_->_offset = pos;
136# else
137 /* fp_->_offset is an fpos_t. */
138 {
139 /* Use a union, since on NetBSD, the compilation flags
140 determine whether fpos_t is typedef'd to off_t or a struct
141 containing a single off_t member. */
142 union
143 {
144 fpos_t f;
145 off_t o;
146 } u;
147 u.o = pos;
148 fp_->_offset = u.f;
149 }
150# endif
151 fp_->_flags |= __SOFF;
152 fp_->_flags &= ~__SEOF;
153#elif defined __EMX__ /* emx+gcc */
154 fp->_flags &= ~_IOEOF;
155#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */
156 fp_->_flag &= ~_IOEOF;
157#elif defined __MINT__ /* Atari FreeMiNT */
158 fp->__offset = pos;
159 fp->__eof = 0;
160#endif
161 return 0;
162 }
163 return fseeko (fp, offset, whence);
164}
diff --git a/gl/fstat.c b/gl/fstat.c
new file mode 100644
index 0000000..6a23500
--- /dev/null
+++ b/gl/fstat.c
@@ -0,0 +1,94 @@
1/* fstat() replacement.
2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* If the user's config.h happens to include <sys/stat.h>, let it include only
18 the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
19 rpl_fstat. */
20#define __need_system_sys_stat_h
21#include <config.h>
22
23/* Get the original definition of fstat. It might be defined as a macro. */
24#include <sys/types.h>
25#include <sys/stat.h>
26#undef __need_system_sys_stat_h
27
28#if defined _WIN32 && ! defined __CYGWIN__
29# define WINDOWS_NATIVE
30#endif
31
32#if !defined WINDOWS_NATIVE
33
34static int
35orig_fstat (int fd, struct stat *buf)
36{
37 return fstat (fd, buf);
38}
39
40#endif
41
42/* Specification. */
43#ifdef __osf__
44/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
45 eliminates this include because of the preliminary #include <sys/stat.h>
46 above. */
47# include "sys/stat.h"
48#else
49# include <sys/stat.h>
50#endif
51
52#include "stat-time.h"
53
54#include <errno.h>
55#include <unistd.h>
56#ifdef WINDOWS_NATIVE
57# define WIN32_LEAN_AND_MEAN
58# include <windows.h>
59# if GNULIB_MSVC_NOTHROW
60# include "msvc-nothrow.h"
61# else
62# include <io.h>
63# endif
64# include "stat-w32.h"
65#endif
66
67int
68rpl_fstat (int fd, struct stat *buf)
69{
70#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
71 /* Handle the case when rpl_open() used a dummy file descriptor to work
72 around an open() that can't normally visit directories. */
73 const char *name = _gl_directory_name (fd);
74 if (name != NULL)
75 return stat (name, buf);
76#endif
77
78#ifdef WINDOWS_NATIVE
79 /* Fill the fields ourselves, because the original fstat function returns
80 values for st_atime, st_mtime, st_ctime that depend on the current time
81 zone. See
82 <https://lists.gnu.org/r/bug-gnulib/2017-04/msg00134.html> */
83 HANDLE h = (HANDLE) _get_osfhandle (fd);
84
85 if (h == INVALID_HANDLE_VALUE)
86 {
87 errno = EBADF;
88 return -1;
89 }
90 return _gl_fstat_by_handle (h, NULL, buf);
91#else
92 return stat_time_normalize (orig_fstat (fd, buf), buf);
93#endif
94}
diff --git a/gl/fsusage.c b/gl/fsusage.c
index 6103ecf..f6f4b1c 100644
--- a/gl/fsusage.c
+++ b/gl/fsusage.c
@@ -1,20 +1,20 @@
1/* fsusage.c -- return space usage of mounted file systems 1/* fsusage.c -- return space usage of mounted file systems
2 2
3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2013 Free Software 3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2023 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 file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation, either version 3 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
@@ -43,23 +43,11 @@
43# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ 43# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */
44# include <sys/fs/s5param.h> 44# include <sys/fs/s5param.h>
45# endif 45# endif
46# if defined HAVE_SYS_FILSYS_H && !defined _CRAY
47# include <sys/filsys.h> /* SVR2 */
48# endif
49# if HAVE_SYS_STATFS_H 46# if HAVE_SYS_STATFS_H
50# include <sys/statfs.h> 47# include <sys/statfs.h>
51# endif 48# endif
52# if HAVE_DUSTAT_H /* AIX PS/2 */
53# include <sys/dustat.h>
54# endif
55# include "full-read.h"
56#endif 49#endif
57 50
58/* The results of open() in this file are not used with fchdir,
59 therefore save some unnecessary work in fchdir.c. */
60#undef open
61#undef close
62
63/* Many space usage primitives use all 1 bits to denote a value that is 51/* Many space usage primitives use all 1 bits to denote a value that is
64 not applicable or unknown. Propagate this information by returning 52 not applicable or unknown. Propagate this information by returning
65 a uintmax_t value that is all 1 bits if X is all 1 bits, even if X 53 a uintmax_t value that is all 1 bits if X is all 1 bits, even if X
@@ -143,7 +131,6 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
143 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; 131 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0;
144 fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); 132 fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files);
145 fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); 133 fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree);
146 fsp->fsu_favail = PROPAGATE_ALL_ONES (vfsd.f_favail);
147 return 0; 134 return 0;
148 } 135 }
149 136
@@ -161,58 +148,6 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
161 ? PROPAGATE_ALL_ONES (fsd.f_frsize) 148 ? PROPAGATE_ALL_ONES (fsd.f_frsize)
162 : PROPAGATE_ALL_ONES (fsd.f_bsize)); 149 : PROPAGATE_ALL_ONES (fsd.f_bsize));
163 150
164#elif defined STAT_STATFS2_FS_DATA /* Ultrix */
165
166 struct fs_data fsd;
167
168 if (statfs (file, &fsd) != 1)
169 return -1;
170
171 fsp->fsu_blocksize = 1024;
172 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.fd_req.btot);
173 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.fd_req.bfree);
174 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.fd_req.bfreen);
175 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0;
176 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot);
177 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
178 fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
179
180#elif defined STAT_READ_FILSYS /* SVR2 */
181# ifndef SUPERBOFF
182# define SUPERBOFF (SUPERB * 512)
183# endif
184
185 struct filsys fsd;
186 int fd;
187
188 if (! disk)
189 {
190 errno = 0;
191 return -1;
192 }
193
194 fd = open (disk, O_RDONLY);
195 if (fd < 0)
196 return -1;
197 lseek (fd, (off_t) SUPERBOFF, 0);
198 if (full_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
199 {
200 close (fd);
201 return -1;
202 }
203 close (fd);
204
205 fsp->fsu_blocksize = (fsd.s_type == Fs2b ? 1024 : 512);
206 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.s_fsize);
207 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.s_tfree);
208 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree);
209 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0;
210 fsp->fsu_files = (fsd.s_isize == -1
211 ? UINTMAX_MAX
212 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
213 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
214 fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.s_tinode);
215
216#elif defined STAT_STATFS3_OSF1 /* OSF/1 */ 151#elif defined STAT_STATFS3_OSF1 /* OSF/1 */
217 152
218 struct statfs fsd; 153 struct statfs fsd;
@@ -266,12 +201,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
266 201
267 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 202 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
268 203
269#elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \ 204#elif defined STAT_STATFS4 /* SVR3, old Irix */
270 Dolphin */
271
272# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN
273# define f_bavail f_bfree
274# endif
275 205
276 struct statfs fsd; 206 struct statfs fsd;
277 207
@@ -281,11 +211,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
281 /* Empirically, the block counts on most SVR3 and SVR3-derived 211 /* Empirically, the block counts on most SVR3 and SVR3-derived
282 systems seem to always be in terms of 512-byte blocks, 212 systems seem to always be in terms of 512-byte blocks,
283 no matter what value f_bsize has. */ 213 no matter what value f_bsize has. */
284# if _AIX || defined _CRAY
285 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize);
286# else
287 fsp->fsu_blocksize = 512; 214 fsp->fsu_blocksize = 512;
288# endif
289 215
290#endif 216#endif
291 217
@@ -299,38 +225,9 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
299 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; 225 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0;
300 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); 226 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files);
301 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); 227 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree);
302 fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.f_ffree);
303 228
304#endif 229#endif
305 230
306 (void) disk; /* avoid argument-unused warning */ 231 (void) disk; /* avoid argument-unused warning */
307 return 0; 232 return 0;
308} 233}
309
310#if defined _AIX && defined _I386
311/* AIX PS/2 does not supply statfs. */
312
313int
314statfs (char *file, struct statfs *fsb)
315{
316 struct stat stats;
317 struct dustat fsd;
318
319 if (stat (file, &stats) != 0)
320 return -1;
321 if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
322 return -1;
323 fsb->f_type = 0;
324 fsb->f_bsize = fsd.du_bsize;
325 fsb->f_blocks = fsd.du_fsize - fsd.du_isize;
326 fsb->f_bfree = fsd.du_tfree;
327 fsb->f_bavail = fsd.du_tfree;
328 fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb;
329 fsb->f_ffree = fsd.du_tinode;
330 fsb->f_favail = fsd.du_tinode;
331 fsb->f_fsid.val[0] = fsd.du_site;
332 fsb->f_fsid.val[1] = fsd.du_pckno;
333 return 0;
334}
335
336#endif /* _AIX && _I386 */
diff --git a/gl/fsusage.h b/gl/fsusage.h
index e2654fd..9630b04 100644
--- a/gl/fsusage.h
+++ b/gl/fsusage.h
@@ -1,20 +1,20 @@
1/* fsusage.h -- declarations for file system space usage info 1/* fsusage.h -- declarations for file system space usage info
2 2
3 Copyright (C) 1991-1992, 1997, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1991-1992, 1997, 2003-2006, 2009-2023 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 file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation, either version 3 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19/* Space usage statistics for a file system. Blocks are 512-byte. */ 19/* Space usage statistics for a file system. Blocks are 512-byte. */
20 20
@@ -22,7 +22,6 @@
22# define FSUSAGE_H_ 22# define FSUSAGE_H_
23 23
24# include <stdint.h> 24# include <stdint.h>
25# include <stdbool.h>
26 25
27struct fs_usage 26struct fs_usage
28{ 27{
@@ -32,8 +31,7 @@ struct fs_usage
32 uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ 31 uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */
33 bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ 32 bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */
34 uintmax_t fsu_files; /* Total file nodes. */ 33 uintmax_t fsu_files; /* Total file nodes. */
35 uintmax_t fsu_ffree; /* Free file nodes to superuser. */ 34 uintmax_t fsu_ffree; /* Free file nodes. */
36 uintmax_t fsu_favail; /* Free file nodes to non-superuser. */
37}; 35};
38 36
39int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); 37int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp);
diff --git a/gl/ftell.c b/gl/ftell.c
new file mode 100644
index 0000000..ce2bd54
--- /dev/null
+++ b/gl/ftell.c
@@ -0,0 +1,37 @@
1/* An ftell() function that works around platform bugs.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <stdio.h>
21
22#include <errno.h>
23#include <limits.h>
24
25long
26ftell (FILE *fp)
27{
28 /* Use the replacement ftello function with all its workarounds. */
29 off_t offset = ftello (fp);
30 if (LONG_MIN <= offset && offset <= LONG_MAX)
31 return /* (long) */ offset;
32 else
33 {
34 errno = EOVERFLOW;
35 return -1;
36 }
37}
diff --git a/gl/ftello.c b/gl/ftello.c
new file mode 100644
index 0000000..14184e5
--- /dev/null
+++ b/gl/ftello.c
@@ -0,0 +1,157 @@
1/* An ftello() function that works around platform bugs.
2 Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <stdio.h>
21
22#include <errno.h>
23#include "intprops.h"
24
25/* Get lseek. */
26#include <unistd.h>
27
28#include "stdio-impl.h"
29
30off_t
31ftello (FILE *fp)
32#undef ftello
33#if !HAVE_FTELLO
34# undef ftell
35# define ftello ftell
36#endif
37#if _GL_WINDOWS_64_BIT_OFF_T
38# undef ftello
39# if HAVE__FTELLI64 /* msvc, mingw64 */
40# define ftello _ftelli64
41# else /* mingw */
42# define ftello ftello64
43# endif
44#endif
45{
46#if FTELLO_BROKEN_AFTER_UNGETC /* macOS >= 10.15 */
47 /* The system's ftello() is completely broken, because it calls __sflush,
48 which makes side effects on the stream. */
49
50 /* Handle non-seekable files first. */
51 if (fp->_file < 0 || fp->_seek == NULL)
52 {
53 errno = ESPIPE;
54 return -1;
55 }
56
57 /* Determine the current offset, ignoring buffered and pushed-back bytes. */
58 off_t pos;
59
60 if (fp->_flags & __SOFF)
61 pos = fp->_offset;
62 else
63 {
64 pos = fp->_seek (fp->_cookie, 0, SEEK_CUR);
65 if (pos < 0)
66 return -1;
67 if (fp->_flags & __SOPT)
68 {
69 fp->_offset = pos;
70 fp->_flags |= __SOFF;
71 }
72 }
73
74 if (fp->_flags & __SRD)
75 {
76 /* Now consider buffered and pushed-back bytes from ungetc. */
77 if (fp->_ub._base != NULL)
78 /* Considering the buffered bytes, we are at position
79 pos - fp->_ur.
80 Considering also the pushed-back bytes, we are at position
81 pos - fp->_ur - fp->_r. */
82 pos = pos - fp->_ur - fp->_r;
83 else
84 /* Considering the buffered bytes, we are at position
85 pos - fp->_r. */
86 pos = pos - fp->_r;
87 if (pos < 0)
88 {
89 errno = EIO;
90 return -1;
91 }
92 }
93 else if ((fp->_flags & __SWR) && fp->_p != NULL)
94 {
95 /* Consider the buffered bytes. */
96 off_t buffered = fp->_p - fp->_bf._base;
97
98 /* Compute pos + buffered, with overflow check. */
99 off_t sum;
100 if (! INT_ADD_OK (pos, buffered, &sum))
101 {
102 errno = EOVERFLOW;
103 return -1;
104 }
105 pos = sum;
106 }
107
108 return pos;
109
110#else
111
112# if LSEEK_PIPE_BROKEN
113 /* mingw gives bogus answers rather than failure on non-seekable files. */
114 if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
115 return -1;
116# endif
117
118# if FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE /* Solaris */
119 /* The Solaris stdio leaves the _IOREAD flag set after reading from a file
120 reaches EOF and the program then starts writing to the file. ftello
121 gets confused by this. */
122 if (fp_->_flag & _IOWRT)
123 {
124 off_t pos;
125
126 /* Call ftello nevertheless, for the side effects that it does on fp. */
127 ftello (fp);
128
129 /* Compute the file position ourselves. */
130 pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR);
131 if (pos >= 0)
132 {
133 if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL)
134 pos += fp_->_ptr - fp_->_base;
135 }
136 return pos;
137 }
138# endif
139
140# if defined __SL64 && defined __SCLE /* Cygwin */
141 if ((fp->_flags & __SL64) == 0)
142 {
143 /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
144 mode; but has an ftello that requires 64-bit mode. */
145 FILE *tmp = fopen ("/dev/null", "r");
146 if (!tmp)
147 return -1;
148 fp->_flags |= __SL64;
149 fp->_seek64 = tmp->_seek64;
150 fclose (tmp);
151 }
152# endif
153
154 return ftello (fp);
155
156#endif
157}
diff --git a/gl/full-read.c b/gl/full-read.c
deleted file mode 100644
index a0dc82c..0000000
--- a/gl/full-read.c
+++ /dev/null
@@ -1,18 +0,0 @@
1/* An interface to read that retries after partial reads and interrupts.
2 Copyright (C) 2002-2003, 2009-2013 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#define FULL_READ
18#include "full-write.c"
diff --git a/gl/full-read.h b/gl/full-read.h
deleted file mode 100644
index 66c8c5c..0000000
--- a/gl/full-read.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* An interface to read() that reads all it is asked to read.
2
3 Copyright (C) 2002, 2009-2013 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, read to the Free Software Foundation,
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <stddef.h>
20
21/* Read COUNT bytes at BUF to descriptor FD, retrying if interrupted
22 or if partial reads occur. Return the number of bytes successfully
23 read, setting errno if that is less than COUNT. errno = 0 means EOF. */
24extern size_t full_read (int fd, void *buf, size_t count);
diff --git a/gl/full-write.c b/gl/full-write.c
deleted file mode 100644
index beb5bf9..0000000
--- a/gl/full-write.c
+++ /dev/null
@@ -1,79 +0,0 @@
1/* An interface to read and write that retries (if necessary) until complete.
2
3 Copyright (C) 1993-1994, 1997-2006, 2009-2013 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#ifdef FULL_READ
22# include "full-read.h"
23#else
24# include "full-write.h"
25#endif
26
27#include <errno.h>
28
29#ifdef FULL_READ
30# include "safe-read.h"
31# define safe_rw safe_read
32# define full_rw full_read
33# undef const
34# define const /* empty */
35#else
36# include "safe-write.h"
37# define safe_rw safe_write
38# define full_rw full_write
39#endif
40
41#ifdef FULL_READ
42/* Set errno to zero upon EOF. */
43# define ZERO_BYTE_TRANSFER_ERRNO 0
44#else
45/* Some buggy drivers return 0 when one tries to write beyond
46 a device's end. (Example: Linux 1.2.13 on /dev/fd0.)
47 Set errno to ENOSPC so they get a sensible diagnostic. */
48# define ZERO_BYTE_TRANSFER_ERRNO ENOSPC
49#endif
50
51/* Write(read) COUNT bytes at BUF to(from) descriptor FD, retrying if
52 interrupted or if a partial write(read) occurs. Return the number
53 of bytes transferred.
54 When writing, set errno if fewer than COUNT bytes are written.
55 When reading, if fewer than COUNT bytes are read, you must examine
56 errno to distinguish failure from EOF (errno == 0). */
57size_t
58full_rw (int fd, const void *buf, size_t count)
59{
60 size_t total = 0;
61 const char *ptr = (const char *) buf;
62
63 while (count > 0)
64 {
65 size_t n_rw = safe_rw (fd, ptr, count);
66 if (n_rw == (size_t) -1)
67 break;
68 if (n_rw == 0)
69 {
70 errno = ZERO_BYTE_TRANSFER_ERRNO;
71 break;
72 }
73 total += n_rw;
74 ptr += n_rw;
75 count -= n_rw;
76 }
77
78 return total;
79}
diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c
index 1e371d2..3436c07 100644
--- a/gl/gai_strerror.c
+++ b/gl/gai_strerror.c
@@ -1,20 +1,20 @@
1/* Copyright (C) 1997, 2001-2002, 2004-2006, 2008-2013 Free Software 1/* Copyright (C) 1997, 2001-2002, 2004-2006, 2008-2023 Free Software
2 Foundation, Inc. 2 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 Philip Blundell <pjb27@cam.ac.uk>, 1997. 4 Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3, or (at your option) 8 published by the Free Software Foundation; either version 2.1 of the
9 any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#ifndef _LIBC 19#ifndef _LIBC
20# include <config.h> 20# include <config.h>
diff --git a/gl/getaddrinfo.c b/gl/getaddrinfo.c
index 58d2811..6586ee5 100644
--- a/gl/getaddrinfo.c
+++ b/gl/getaddrinfo.c
@@ -1,19 +1,19 @@
1/* Get address information (partial implementation). 1/* Get address information (partial implementation).
2 Copyright (C) 1997, 2001-2002, 2004-2013 Free Software Foundation, Inc. 2 Copyright (C) 1997, 2001-2002, 2004-2023 Free Software Foundation, Inc.
3 Contributed by Simon Josefsson <simon@josefsson.org>. 3 Contributed by Simon Josefsson <simon@josefsson.org>.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc 18/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
19 optimizes away the sa == NULL test below. */ 19 optimizes away the sa == NULL test below. */
@@ -39,8 +39,6 @@
39/* Get snprintf. */ 39/* Get snprintf. */
40#include <stdio.h> 40#include <stdio.h>
41 41
42#include <stdbool.h>
43
44#include "gettext.h" 42#include "gettext.h"
45#define _(String) gettext (String) 43#define _(String) gettext (String)
46#define N_(String) String 44#define N_(String) String
@@ -54,14 +52,48 @@
54# define PF_UNSPEC 0 52# define PF_UNSPEC 0
55#endif 53#endif
56 54
57#if defined _WIN32 || defined __WIN32__ 55#if HAVE_GETADDRINFO
58# define WINDOWS_NATIVE 56
59#endif 57/* Override with cdecl calling convention. */
58
59int
60getaddrinfo (const char *restrict nodename,
61 const char *restrict servname,
62 const struct addrinfo *restrict hints,
63 struct addrinfo **restrict res)
64# undef getaddrinfo
65{
66 return getaddrinfo (nodename, servname, hints, res);
67}
68
69void
70freeaddrinfo (struct addrinfo *ai)
71# undef freeaddrinfo
72{
73 freeaddrinfo (ai);
74}
75
76#else
77
78# if defined _WIN32 && !defined __CYGWIN__
79# define WINDOWS_NATIVE
80# endif
60 81
61/* gl_sockets_startup */ 82/* gl_sockets_startup */
62#include "sockets.h" 83# include "sockets.h"
84
85# ifdef WINDOWS_NATIVE
86
87/* Don't assume that UNICODE is not defined. */
88# undef GetModuleHandle
89# define GetModuleHandle GetModuleHandleA
90
91# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
92
93/* Avoid warnings from gcc -Wcast-function-type. */
94# define GetProcAddress \
95 (void *) GetProcAddress
63 96
64#ifdef WINDOWS_NATIVE
65typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, 97typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
66 const struct addrinfo*, 98 const struct addrinfo*,
67 struct addrinfo**); 99 struct addrinfo**);
@@ -107,20 +139,43 @@ use_win32_p (void)
107 139
108 return 1; 140 return 1;
109} 141}
110#endif 142
143# else
144
145static int
146use_win32_p (void)
147{
148 static int done = 0;
149
150 if (!done)
151 {
152 done = 1;
153
154 gl_sockets_startup (SOCKETS_1_1);
155 }
156
157 return 1;
158}
159
160# define getaddrinfo_ptr getaddrinfo
161# define freeaddrinfo_ptr freeaddrinfo
162# define getnameinfo_ptr getnameinfo
163
164# endif
165# endif
111 166
112static bool 167static bool
113validate_family (int family) 168validate_family (int family)
114{ 169{
115 /* FIXME: Support more families. */ 170 /* FIXME: Support more families. */
116#if HAVE_IPV4 171# if HAVE_IPV4
117 if (family == PF_INET) 172 if (family == PF_INET)
118 return true; 173 return true;
119#endif 174# endif
120#if HAVE_IPV6 175# if HAVE_IPV6
121 if (family == PF_INET6) 176 if (family == PF_INET6)
122 return true; 177 return true;
123#endif 178# endif
124 if (family == PF_UNSPEC) 179 if (family == PF_UNSPEC)
125 return true; 180 return true;
126 return false; 181 return false;
@@ -133,29 +188,30 @@ getaddrinfo (const char *restrict nodename,
133 const char *restrict servname, 188 const char *restrict servname,
134 const struct addrinfo *restrict hints, 189 const struct addrinfo *restrict hints,
135 struct addrinfo **restrict res) 190 struct addrinfo **restrict res)
191#undef getaddrinfo
136{ 192{
137 struct addrinfo *tmp; 193 struct addrinfo *tmp;
138 int port = 0; 194 int port = 0;
139 struct hostent *he; 195 struct hostent *he;
140 void *storage; 196 void *storage;
141 size_t size; 197 size_t size;
142#if HAVE_IPV6 198# if HAVE_IPV6
143 struct v6_pair { 199 struct v6_pair {
144 struct addrinfo addrinfo; 200 struct addrinfo addrinfo;
145 struct sockaddr_in6 sockaddr_in6; 201 struct sockaddr_in6 sockaddr_in6;
146 }; 202 };
147#endif 203# endif
148#if HAVE_IPV4 204# if HAVE_IPV4
149 struct v4_pair { 205 struct v4_pair {
150 struct addrinfo addrinfo; 206 struct addrinfo addrinfo;
151 struct sockaddr_in sockaddr_in; 207 struct sockaddr_in sockaddr_in;
152 }; 208 };
153#endif 209# endif
154 210
155#ifdef WINDOWS_NATIVE 211# ifdef WINDOWS_NATIVE
156 if (use_win32_p ()) 212 if (use_win32_p ())
157 return getaddrinfo_ptr (nodename, servname, hints, res); 213 return getaddrinfo_ptr (nodename, servname, hints, res);
158#endif 214# endif
159 215
160 if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE))) 216 if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
161 /* FIXME: Support more flags. */ 217 /* FIXME: Support more flags. */
@@ -174,11 +230,11 @@ getaddrinfo (const char *restrict nodename,
174 if (!(hints->ai_flags & AI_PASSIVE)) 230 if (!(hints->ai_flags & AI_PASSIVE))
175 return EAI_NONAME; 231 return EAI_NONAME;
176 232
177#ifdef HAVE_IPV6 233# ifdef HAVE_IPV6
178 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; 234 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0";
179#else 235# else
180 nodename = "0.0.0.0"; 236 nodename = "0.0.0.0";
181#endif 237# endif
182 } 238 }
183 239
184 if (servname) 240 if (servname)
@@ -212,17 +268,17 @@ getaddrinfo (const char *restrict nodename,
212 268
213 switch (he->h_addrtype) 269 switch (he->h_addrtype)
214 { 270 {
215#if HAVE_IPV6 271# if HAVE_IPV6
216 case PF_INET6: 272 case PF_INET6:
217 size = sizeof (struct v6_pair); 273 size = sizeof (struct v6_pair);
218 break; 274 break;
219#endif 275# endif
220 276
221#if HAVE_IPV4 277# if HAVE_IPV4
222 case PF_INET: 278 case PF_INET:
223 size = sizeof (struct v4_pair); 279 size = sizeof (struct v4_pair);
224 break; 280 break;
225#endif 281# endif
226 282
227 default: 283 default:
228 return EAI_NODATA; 284 return EAI_NODATA;
@@ -234,7 +290,7 @@ getaddrinfo (const char *restrict nodename,
234 290
235 switch (he->h_addrtype) 291 switch (he->h_addrtype)
236 { 292 {
237#if HAVE_IPV6 293# if HAVE_IPV6
238 case PF_INET6: 294 case PF_INET6:
239 { 295 {
240 struct v6_pair *p = storage; 296 struct v6_pair *p = storage;
@@ -256,9 +312,9 @@ getaddrinfo (const char *restrict nodename,
256 tmp->ai_addrlen = sizeof *sinp; 312 tmp->ai_addrlen = sizeof *sinp;
257 } 313 }
258 break; 314 break;
259#endif 315# endif
260 316
261#if HAVE_IPV4 317# if HAVE_IPV4
262 case PF_INET: 318 case PF_INET:
263 { 319 {
264 struct v4_pair *p = storage; 320 struct v4_pair *p = storage;
@@ -280,7 +336,7 @@ getaddrinfo (const char *restrict nodename,
280 tmp->ai_addrlen = sizeof *sinp; 336 tmp->ai_addrlen = sizeof *sinp;
281 } 337 }
282 break; 338 break;
283#endif 339# endif
284 340
285 default: 341 default:
286 free (storage); 342 free (storage);
@@ -308,21 +364,21 @@ getaddrinfo (const char *restrict nodename,
308 tmp->ai_addr->sa_family = he->h_addrtype; 364 tmp->ai_addr->sa_family = he->h_addrtype;
309 tmp->ai_family = he->h_addrtype; 365 tmp->ai_family = he->h_addrtype;
310 366
311#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 367# ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
312 switch (he->h_addrtype) 368 switch (he->h_addrtype)
313 { 369 {
314#if HAVE_IPV4 370# if HAVE_IPV4
315 case AF_INET: 371 case AF_INET:
316 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in); 372 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in);
317 break; 373 break;
318#endif 374# endif
319#if HAVE_IPV6 375# if HAVE_IPV6
320 case AF_INET6: 376 case AF_INET6:
321 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6); 377 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6);
322 break; 378 break;
323#endif 379# endif
324 } 380 }
325#endif 381# endif
326 382
327 /* FIXME: If more than one address, create linked list of addrinfo's. */ 383 /* FIXME: If more than one address, create linked list of addrinfo's. */
328 384
@@ -334,14 +390,15 @@ getaddrinfo (const char *restrict nodename,
334/* Free 'addrinfo' structure AI including associated storage. */ 390/* Free 'addrinfo' structure AI including associated storage. */
335void 391void
336freeaddrinfo (struct addrinfo *ai) 392freeaddrinfo (struct addrinfo *ai)
393#undef freeaddrinfo
337{ 394{
338#ifdef WINDOWS_NATIVE 395# ifdef WINDOWS_NATIVE
339 if (use_win32_p ()) 396 if (use_win32_p ())
340 { 397 {
341 freeaddrinfo_ptr (ai); 398 freeaddrinfo_ptr (ai);
342 return; 399 return;
343 } 400 }
344#endif 401# endif
345 402
346 while (ai) 403 while (ai)
347 { 404 {
@@ -360,12 +417,13 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
360 char *restrict node, socklen_t nodelen, 417 char *restrict node, socklen_t nodelen,
361 char *restrict service, socklen_t servicelen, 418 char *restrict service, socklen_t servicelen,
362 int flags) 419 int flags)
420#undef getnameinfo
363{ 421{
364#ifdef WINDOWS_NATIVE 422# ifdef WINDOWS_NATIVE
365 if (use_win32_p ()) 423 if (use_win32_p ())
366 return getnameinfo_ptr (sa, salen, node, nodelen, 424 return getnameinfo_ptr (sa, salen, node, nodelen,
367 service, servicelen, flags); 425 service, servicelen, flags);
368#endif 426# endif
369 427
370 /* FIXME: Support other flags. */ 428 /* FIXME: Support other flags. */
371 if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) || 429 if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) ||
@@ -378,18 +436,18 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
378 436
379 switch (sa->sa_family) 437 switch (sa->sa_family)
380 { 438 {
381#if HAVE_IPV4 439# if HAVE_IPV4
382 case AF_INET: 440 case AF_INET:
383 if (salen < sizeof (struct sockaddr_in)) 441 if (salen < sizeof (struct sockaddr_in))
384 return EAI_FAMILY; 442 return EAI_FAMILY;
385 break; 443 break;
386#endif 444# endif
387#if HAVE_IPV6 445# if HAVE_IPV6
388 case AF_INET6: 446 case AF_INET6:
389 if (salen < sizeof (struct sockaddr_in6)) 447 if (salen < sizeof (struct sockaddr_in6))
390 return EAI_FAMILY; 448 return EAI_FAMILY;
391 break; 449 break;
392#endif 450# endif
393 default: 451 default:
394 return EAI_FAMILY; 452 return EAI_FAMILY;
395 } 453 }
@@ -398,23 +456,23 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
398 { 456 {
399 switch (sa->sa_family) 457 switch (sa->sa_family)
400 { 458 {
401#if HAVE_IPV4 459# if HAVE_IPV4
402 case AF_INET: 460 case AF_INET:
403 if (!inet_ntop (AF_INET, 461 if (!inet_ntop (AF_INET,
404 &(((const struct sockaddr_in *) sa)->sin_addr), 462 &(((const struct sockaddr_in *) sa)->sin_addr),
405 node, nodelen)) 463 node, nodelen))
406 return EAI_SYSTEM; 464 return EAI_SYSTEM;
407 break; 465 break;
408#endif 466# endif
409 467
410#if HAVE_IPV6 468# if HAVE_IPV6
411 case AF_INET6: 469 case AF_INET6:
412 if (!inet_ntop (AF_INET6, 470 if (!inet_ntop (AF_INET6,
413 &(((const struct sockaddr_in6 *) sa)->sin6_addr), 471 &(((const struct sockaddr_in6 *) sa)->sin6_addr),
414 node, nodelen)) 472 node, nodelen))
415 return EAI_SYSTEM; 473 return EAI_SYSTEM;
416 break; 474 break;
417#endif 475# endif
418 476
419 default: 477 default:
420 return EAI_FAMILY; 478 return EAI_FAMILY;
@@ -424,12 +482,12 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
424 if (service && servicelen > 0 && flags & NI_NUMERICSERV) 482 if (service && servicelen > 0 && flags & NI_NUMERICSERV)
425 switch (sa->sa_family) 483 switch (sa->sa_family)
426 { 484 {
427#if HAVE_IPV4 485# if HAVE_IPV4
428 case AF_INET: 486 case AF_INET:
429#endif 487# endif
430#if HAVE_IPV6 488# if HAVE_IPV6
431 case AF_INET6: 489 case AF_INET6:
432#endif 490# endif
433 { 491 {
434 unsigned short int port 492 unsigned short int port
435 = ntohs (((const struct sockaddr_in *) sa)->sin_port); 493 = ntohs (((const struct sockaddr_in *) sa)->sin_port);
@@ -441,3 +499,5 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
441 499
442 return 0; 500 return 0;
443} 501}
502
503#endif
diff --git a/gl/getdelim.c b/gl/getdelim.c
new file mode 100644
index 0000000..79ec3dd
--- /dev/null
+++ b/gl/getdelim.c
@@ -0,0 +1,147 @@
1/* getdelim.c --- Implementation of replacement getdelim function.
2 Copyright (C) 1994, 1996-1998, 2001, 2003, 2005-2023 Free Software
3 Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Ported from glibc by Simon Josefsson. */
19
20/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
21 optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below. */
22#define _GL_ARG_NONNULL(params)
23
24#include <config.h>
25
26#include <stdio.h>
27
28#include <limits.h>
29#include <stdint.h>
30#include <stdlib.h>
31#include <errno.h>
32
33#ifndef SSIZE_MAX
34# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
35#endif
36
37#if USE_UNLOCKED_IO
38# include "unlocked-io.h"
39# define getc_maybe_unlocked(fp) getc(fp)
40#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
41# undef flockfile
42# undef funlockfile
43# define flockfile(x) ((void) 0)
44# define funlockfile(x) ((void) 0)
45# define getc_maybe_unlocked(fp) getc(fp)
46#else
47# define getc_maybe_unlocked(fp) getc_unlocked(fp)
48#endif
49
50static void
51alloc_failed (void)
52{
53#if defined _WIN32 && ! defined __CYGWIN__
54 /* Avoid errno problem without using the realloc module; see:
55 https://lists.gnu.org/r/bug-gnulib/2016-08/msg00025.html */
56 errno = ENOMEM;
57#endif
58}
59
60/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
61 NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
62 NULL), pointing to *N characters of space. It is realloc'ed as
63 necessary. Returns the number of characters read (not including
64 the null terminator), or -1 on error or EOF. */
65
66ssize_t
67getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
68{
69 ssize_t result;
70 size_t cur_len = 0;
71
72 if (lineptr == NULL || n == NULL || fp == NULL)
73 {
74 errno = EINVAL;
75 return -1;
76 }
77
78 flockfile (fp);
79
80 if (*lineptr == NULL || *n == 0)
81 {
82 char *new_lineptr;
83 *n = 120;
84 new_lineptr = (char *) realloc (*lineptr, *n);
85 if (new_lineptr == NULL)
86 {
87 alloc_failed ();
88 result = -1;
89 goto unlock_return;
90 }
91 *lineptr = new_lineptr;
92 }
93
94 for (;;)
95 {
96 int i;
97
98 i = getc_maybe_unlocked (fp);
99 if (i == EOF)
100 {
101 result = -1;
102 break;
103 }
104
105 /* Make enough space for len+1 (for final NUL) bytes. */
106 if (cur_len + 1 >= *n)
107 {
108 size_t needed_max =
109 SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
110 size_t needed = 2 * *n + 1; /* Be generous. */
111 char *new_lineptr;
112
113 if (needed_max < needed)
114 needed = needed_max;
115 if (cur_len + 1 >= needed)
116 {
117 result = -1;
118 errno = EOVERFLOW;
119 goto unlock_return;
120 }
121
122 new_lineptr = (char *) realloc (*lineptr, needed);
123 if (new_lineptr == NULL)
124 {
125 alloc_failed ();
126 result = -1;
127 goto unlock_return;
128 }
129
130 *lineptr = new_lineptr;
131 *n = needed;
132 }
133
134 (*lineptr)[cur_len] = i;
135 cur_len++;
136
137 if (i == delimiter)
138 break;
139 }
140 (*lineptr)[cur_len] = '\0';
141 result = cur_len ? cur_len : result;
142
143 unlock_return:
144 funlockfile (fp); /* doesn't set errno */
145
146 return result;
147}
diff --git a/gl/getdtablesize.c b/gl/getdtablesize.c
new file mode 100644
index 0000000..ac2d175
--- /dev/null
+++ b/gl/getdtablesize.c
@@ -0,0 +1,124 @@
1/* getdtablesize() function: Return maximum possible file descriptor value + 1.
2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#include <unistd.h>
22
23#if defined _WIN32 && ! defined __CYGWIN__
24
25# include <stdio.h>
26
27# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
28# include "msvc-inval.h"
29# endif
30
31# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
32static int
33_setmaxstdio_nothrow (int newmax)
34{
35 int result;
36
37 TRY_MSVC_INVAL
38 {
39 result = _setmaxstdio (newmax);
40 }
41 CATCH_MSVC_INVAL
42 {
43 result = -1;
44 }
45 DONE_MSVC_INVAL;
46
47 return result;
48}
49# else
50# define _setmaxstdio_nothrow _setmaxstdio
51# endif
52
53/* Cache for the previous getdtablesize () result. Safe to cache because
54 Windows also lacks setrlimit. */
55static int dtablesize;
56
57int
58getdtablesize (void)
59{
60 if (dtablesize == 0)
61 {
62 /* We are looking for the number N such that the valid file descriptors
63 are 0..N-1. It can be obtained through a loop as follows:
64 {
65 int fd;
66 for (fd = 3; fd < 65536; fd++)
67 if (dup2 (0, fd) == -1)
68 break;
69 return fd;
70 }
71 On Windows XP, the result is 2048.
72 The drawback of this loop is that it allocates memory for a libc
73 internal array that is never freed.
74
75 The number N can also be obtained as the upper bound for
76 _getmaxstdio (). _getmaxstdio () returns the maximum number of open
77 FILE objects. The sanity check in _setmaxstdio reveals the maximum
78 number of file descriptors. This too allocates memory, but it is
79 freed when we call _setmaxstdio with the original value. */
80 int orig_max_stdio = _getmaxstdio ();
81 unsigned int bound;
82 for (bound = 0x10000; _setmaxstdio_nothrow (bound) < 0; bound = bound / 2)
83 ;
84 _setmaxstdio_nothrow (orig_max_stdio);
85 dtablesize = bound;
86 }
87 return dtablesize;
88}
89
90#else
91
92# include <limits.h>
93# include <sys/resource.h>
94
95# ifndef RLIM_SAVED_CUR
96# define RLIM_SAVED_CUR RLIM_INFINITY
97# endif
98# ifndef RLIM_SAVED_MAX
99# define RLIM_SAVED_MAX RLIM_INFINITY
100# endif
101
102# ifdef __CYGWIN__
103 /* Cygwin 1.7.25 auto-increases the RLIMIT_NOFILE soft limit until it
104 hits the compile-time constant hard limit of 3200. We might as
105 well just report the hard limit. */
106# define rlim_cur rlim_max
107# endif
108
109int
110getdtablesize (void)
111{
112 struct rlimit lim;
113
114 if (getrlimit (RLIMIT_NOFILE, &lim) == 0
115 && 0 <= lim.rlim_cur && lim.rlim_cur <= INT_MAX
116 && lim.rlim_cur != RLIM_INFINITY
117 && lim.rlim_cur != RLIM_SAVED_CUR
118 && lim.rlim_cur != RLIM_SAVED_MAX)
119 return lim.rlim_cur;
120
121 return INT_MAX;
122}
123
124#endif
diff --git a/gl/gethostname.c b/gl/gethostname.c
index 2201573..0c616c3 100644
--- a/gl/gethostname.c
+++ b/gl/gethostname.c
@@ -1,26 +1,26 @@
1/* gethostname emulation for SysV and POSIX.1. 1/* gethostname emulation for SysV and POSIX.1.
2 2
3 Copyright (C) 1992, 2003, 2006, 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 1992, 2003, 2006, 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* David MacKenzie <djm@gnu.ai.mit.edu> 18/* David MacKenzie <djm@gnu.ai.mit.edu>
19 Windows port by Simon Josefsson <simon@josefsson.org> */ 19 Windows port by Simon Josefsson <simon@josefsson.org> */
20 20
21#include <config.h> 21#include <config.h>
22 22
23#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) 23#if !(defined _WIN32 && !defined __CYGWIN__)
24/* Unix API. */ 24/* Unix API. */
25 25
26/* Specification. */ 26/* Specification. */
diff --git a/gl/getline.c b/gl/getline.c
new file mode 100644
index 0000000..85f16ab
--- /dev/null
+++ b/gl/getline.c
@@ -0,0 +1,27 @@
1/* getline.c --- Implementation of replacement getline function.
2 Copyright (C) 2005-2007, 2009-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Simon Josefsson. */
18
19#include <config.h>
20
21#include <stdio.h>
22
23ssize_t
24getline (char **lineptr, size_t *n, FILE *stream)
25{
26 return getdelim (lineptr, n, '\n', stream);
27}
diff --git a/gl/getloadavg.c b/gl/getloadavg.c
index 6e22819..59b53e7 100644
--- a/gl/getloadavg.c
+++ b/gl/getloadavg.c
@@ -1,6 +1,6 @@
1/* Get the system load averages. 1/* Get the system load averages.
2 2
3 Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2013 Free Software 3 Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2023 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6 NOTE: The canonical source of this file is maintained with gnulib. 6 NOTE: The canonical source of this file is maintained with gnulib.
@@ -8,7 +8,7 @@
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 3 of the License, or 11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) 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,
@@ -17,7 +17,7 @@
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 19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 21
22/* Compile-time symbols that this file uses: 22/* Compile-time symbols that this file uses:
23 23
@@ -47,29 +47,25 @@
47 N_NAME_POINTER The nlist n_name element is a pointer, 47 N_NAME_POINTER The nlist n_name element is a pointer,
48 not an array. 48 not an array.
49 HAVE_STRUCT_NLIST_N_UN_N_NAME 'n_un.n_name' is member of 'struct nlist'. 49 HAVE_STRUCT_NLIST_N_UN_N_NAME 'n_un.n_name' is member of 'struct nlist'.
50 LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing 50 LINUX_LDAV_FILE [__linux__, __ANDROID__, __CYGWIN__]: File
51 load averages. 51 containing load averages.
52 52
53 Specific system predefines this file uses, aside from setting 53 Specific system predefines this file uses, aside from setting
54 default values if not emacs: 54 default values if not emacs:
55 55
56 apollo 56 apollo
57 BSD Real BSD, not just BSD-like. 57 BSD Real BSD, not just BSD-like.
58 convex
59 DGUX 58 DGUX
60 eunice UNIX emulator under VMS. 59 eunice UNIX emulator under VMS.
61 hpux 60 hpux
62 __MSDOS__ No-op for MSDOS. 61 __MSDOS__ No-op for MSDOS.
63 NeXT 62 NeXT
64 sgi 63 sgi
65 sequent Sequent Dynix 3.x.x (BSD)
66 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV)
67 sony_news NEWS-OS (works at least for 4.1C)
68 UMAX 64 UMAX
69 UMAX4_3 65 UMAX4_3
70 VMS 66 VMS
71 WINDOWS32 No-op for Windows95/NT. 67 _WIN32 Native Windows (possibly also defined on Cygwin)
72 __linux__ Linux: assumes /proc file system mounted. 68 __linux__, __ANDROID__ Linux: assumes /proc file system mounted.
73 Support from Michael K. Johnson. 69 Support from Michael K. Johnson.
74 __CYGWIN__ Cygwin emulates linux /proc/loadavg. 70 __CYGWIN__ Cygwin emulates linux /proc/loadavg.
75 __NetBSD__ NetBSD: assumes /kern file system mounted. 71 __NetBSD__ NetBSD: assumes /kern file system mounted.
@@ -86,7 +82,6 @@
86#include <stdlib.h> 82#include <stdlib.h>
87 83
88#include <errno.h> 84#include <errno.h>
89#include <stdbool.h>
90#include <stdio.h> 85#include <stdio.h>
91 86
92# include <sys/types.h> 87# include <sys/types.h>
@@ -97,9 +92,8 @@
97 92
98# include "intprops.h" 93# include "intprops.h"
99 94
100# if !defined (BSD) && defined (ultrix) 95# if defined _WIN32 && ! defined __CYGWIN__ && ! defined WINDOWS32
101/* Ultrix behaves like BSD on Vaxen. */ 96# define WINDOWS32
102# define BSD
103# endif 97# endif
104 98
105# ifdef NeXT 99# ifdef NeXT
@@ -141,10 +135,6 @@
141# define MORE_BSD 135# define MORE_BSD
142# endif 136# endif
143 137
144# if defined (ultrix) && defined (mips)
145# define decstation
146# endif
147
148# if defined (__SVR4) && !defined (SVR4) 138# if defined (__SVR4) && !defined (SVR4)
149# define SVR4 139# define SVR4
150# endif 140# endif
@@ -168,13 +158,6 @@
168# include <sys/table.h> 158# include <sys/table.h>
169# endif 159# endif
170 160
171/* UTek's /bin/cc on the 4300 has no architecture specific cpp define by
172 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine
173 that with a couple of other things and we'll have a unique match. */
174# if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES)
175# define tek4300 /* Define by emacs, but not by other users. */
176# endif
177
178 161
179/* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ 162/* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */
180# ifndef LOAD_AVE_TYPE 163# ifndef LOAD_AVE_TYPE
@@ -187,14 +170,6 @@
187# define LOAD_AVE_TYPE long 170# define LOAD_AVE_TYPE long
188# endif 171# endif
189 172
190# ifdef decstation
191# define LOAD_AVE_TYPE long
192# endif
193
194# ifdef _SEQUENT_
195# define LOAD_AVE_TYPE long
196# endif
197
198# ifdef sgi 173# ifdef sgi
199# define LOAD_AVE_TYPE long 174# define LOAD_AVE_TYPE long
200# endif 175# endif
@@ -203,41 +178,14 @@
203# define LOAD_AVE_TYPE long 178# define LOAD_AVE_TYPE long
204# endif 179# endif
205 180
206# ifdef sony_news
207# define LOAD_AVE_TYPE long
208# endif
209
210# ifdef sequent
211# define LOAD_AVE_TYPE long
212# endif
213
214# ifdef OSF_ALPHA 181# ifdef OSF_ALPHA
215# define LOAD_AVE_TYPE long 182# define LOAD_AVE_TYPE long
216# endif 183# endif
217 184
218# if defined (ardent) && defined (titan)
219# define LOAD_AVE_TYPE long
220# endif
221
222# ifdef tek4300
223# define LOAD_AVE_TYPE long
224# endif
225
226# if defined (alliant) && defined (i860) /* Alliant FX/2800 */
227# define LOAD_AVE_TYPE long
228# endif
229
230# if defined _AIX && ! defined HAVE_LIBPERFSTAT 185# if defined _AIX && ! defined HAVE_LIBPERFSTAT
231# define LOAD_AVE_TYPE long 186# define LOAD_AVE_TYPE long
232# endif 187# endif
233 188
234# ifdef convex
235# define LOAD_AVE_TYPE double
236# ifndef LDAV_CVT
237# define LDAV_CVT(n) (n)
238# endif
239# endif
240
241# endif /* No LOAD_AVE_TYPE. */ 189# endif /* No LOAD_AVE_TYPE. */
242 190
243# ifdef OSF_ALPHA 191# ifdef OSF_ALPHA
@@ -247,13 +195,6 @@
247# define FSCALE 1024.0 195# define FSCALE 1024.0
248# endif 196# endif
249 197
250# if defined (alliant) && defined (i860) /* Alliant FX/2800 */
251/* <sys/param.h> defines an incorrect value for FSCALE on an
252 Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */
253# undef FSCALE
254# define FSCALE 100.0
255# endif
256
257 198
258# ifndef FSCALE 199# ifndef FSCALE
259 200
@@ -263,25 +204,17 @@
263# define FSCALE 2048.0 204# define FSCALE 2048.0
264# endif 205# endif
265 206
266# if defined (MIPS) || defined (SVR4) || defined (decstation) 207# if defined (MIPS) || defined (SVR4)
267# define FSCALE 256 208# define FSCALE 256
268# endif 209# endif
269 210
270# if defined (sgi) || defined (sequent) 211# if defined (sgi)
271/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined 212/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined
272 above under #ifdef MIPS. But we want the sgi value. */ 213 above under #ifdef MIPS. But we want the sgi value. */
273# undef FSCALE 214# undef FSCALE
274# define FSCALE 1000.0 215# define FSCALE 1000.0
275# endif 216# endif
276 217
277# if defined (ardent) && defined (titan)
278# define FSCALE 65536.0
279# endif
280
281# ifdef tek4300
282# define FSCALE 100.0
283# endif
284
285# if defined _AIX && !defined HAVE_LIBPERFSTAT 218# if defined _AIX && !defined HAVE_LIBPERFSTAT
286# define FSCALE 65536.0 219# define FSCALE 65536.0
287# endif 220# endif
@@ -303,28 +236,22 @@
303# endif 236# endif
304 237
305 238
306# if !defined (KERNEL_FILE) && defined (sequent)
307# define KERNEL_FILE "/dynix"
308# endif
309
310# if !defined (KERNEL_FILE) && defined (hpux) 239# if !defined (KERNEL_FILE) && defined (hpux)
311# define KERNEL_FILE "/hp-ux" 240# define KERNEL_FILE "/hp-ux"
312# endif 241# endif
313 242
314# if !defined (KERNEL_FILE) && (defined (_SEQUENT_) || defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan))) 243# if !defined (KERNEL_FILE) && (defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi))
315# define KERNEL_FILE "/unix" 244# define KERNEL_FILE "/unix"
316# endif 245# endif
317 246
318 247
319# if !defined (LDAV_SYMBOL) && defined (alliant) 248# if !defined (LDAV_SYMBOL) && (defined (hpux) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (_AIX) && !defined(HAVE_LIBPERFSTAT)))
320# define LDAV_SYMBOL "_Loadavg"
321# endif
322
323# 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)))
324# define LDAV_SYMBOL "avenrun" 249# define LDAV_SYMBOL "avenrun"
325# endif 250# endif
326 251
327# include <unistd.h> 252# ifdef HAVE_UNISTD_H
253# include <unistd.h>
254# endif
328 255
329/* LOAD_AVE_TYPE should only get defined if we're going to use the 256/* LOAD_AVE_TYPE should only get defined if we're going to use the
330 nlist method. */ 257 nlist method. */
@@ -335,7 +262,7 @@
335# ifdef LOAD_AVE_TYPE 262# ifdef LOAD_AVE_TYPE
336 263
337# ifndef __VMS 264# ifndef __VMS
338# ifndef __linux__ 265# if !(defined __linux__ || defined __ANDROID__)
339# ifndef NLIST_STRUCT 266# ifndef NLIST_STRUCT
340# include <a.out.h> 267# include <a.out.h>
341# else /* NLIST_STRUCT */ 268# else /* NLIST_STRUCT */
@@ -358,7 +285,7 @@
358# ifndef LDAV_SYMBOL 285# ifndef LDAV_SYMBOL
359# define LDAV_SYMBOL "_avenrun" 286# define LDAV_SYMBOL "_avenrun"
360# endif /* LDAV_SYMBOL */ 287# endif /* LDAV_SYMBOL */
361# endif /* __linux__ */ 288# endif /* __linux__ || __ANDROID__ */
362 289
363# else /* __VMS */ 290# else /* __VMS */
364 291
@@ -431,7 +358,8 @@
431# include <sys/dg_sys_info.h> 358# include <sys/dg_sys_info.h>
432# endif 359# endif
433 360
434# if (defined __linux__ || defined __CYGWIN__ || defined SUNOS_5 \ 361# if (defined __linux__ || defined __ANDROID__ \
362 || defined __CYGWIN__ || defined SUNOS_5 \
435 || (defined LOAD_AVE_TYPE && ! defined __VMS)) 363 || (defined LOAD_AVE_TYPE && ! defined __VMS))
436# include <fcntl.h> 364# include <fcntl.h>
437# endif 365# endif
@@ -460,7 +388,7 @@ static bool getloadavg_initialized;
460/* Offset in kmem to seek to read load average, or 0 means invalid. */ 388/* Offset in kmem to seek to read load average, or 0 means invalid. */
461static long offset; 389static long offset;
462 390
463# if ! defined __VMS && ! defined sgi && ! defined __linux__ 391# if ! defined __VMS && ! defined sgi && ! (defined __linux__ || defined __ANDROID__)
464static struct nlist name_list[2]; 392static struct nlist name_list[2];
465# endif 393# endif
466 394
@@ -495,17 +423,17 @@ getloadavg (double loadavg[], int nelem)
495 int saved_errno; 423 int saved_errno;
496 424
497 kc = kstat_open (); 425 kc = kstat_open ();
498 if (kc == 0) 426 if (kc == NULL)
499 return -1; 427 return -1;
500 ksp = kstat_lookup (kc, "unix", 0, "system_misc"); 428 ksp = kstat_lookup (kc, "unix", 0, "system_misc");
501 if (ksp == 0) 429 if (ksp == NULL)
502 return -1; 430 return -1;
503 if (kstat_read (kc, ksp, 0) == -1) 431 if (kstat_read (kc, ksp, 0) == -1)
504 return -1; 432 return -1;
505 433
506 434
507 kn = kstat_data_lookup (ksp, "avenrun_1min"); 435 kn = kstat_data_lookup (ksp, "avenrun_1min");
508 if (kn == 0) 436 if (kn == NULL)
509 { 437 {
510 /* Return -1 if no load average information is available. */ 438 /* Return -1 if no load average information is available. */
511 nelem = 0; 439 nelem = 0;
@@ -518,14 +446,14 @@ getloadavg (double loadavg[], int nelem)
518 if (nelem >= 2) 446 if (nelem >= 2)
519 { 447 {
520 kn = kstat_data_lookup (ksp, "avenrun_5min"); 448 kn = kstat_data_lookup (ksp, "avenrun_5min");
521 if (kn != 0) 449 if (kn != NULL)
522 { 450 {
523 loadavg[elem++] = (double) kn->value.ul / FSCALE; 451 loadavg[elem++] = (double) kn->value.ul / FSCALE;
524 452
525 if (nelem >= 3) 453 if (nelem >= 3)
526 { 454 {
527 kn = kstat_data_lookup (ksp, "avenrun_15min"); 455 kn = kstat_data_lookup (ksp, "avenrun_15min");
528 if (kn != 0) 456 if (kn != NULL)
529 loadavg[elem++] = (double) kn->value.ul / FSCALE; 457 loadavg[elem++] = (double) kn->value.ul / FSCALE;
530 } 458 }
531 } 459 }
@@ -570,8 +498,8 @@ getloadavg (double loadavg[], int nelem)
570 } 498 }
571# endif 499# endif
572 500
573# if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) 501# if !defined (LDAV_DONE) && (defined __linux__ || defined __ANDROID__ || defined __CYGWIN__)
574 /* Linux without glibc, Cygwin */ 502 /* Linux without glibc, Android, Cygwin */
575# define LDAV_DONE 503# define LDAV_DONE
576# undef LOAD_AVE_TYPE 504# undef LOAD_AVE_TYPE
577 505
@@ -583,7 +511,7 @@ getloadavg (double loadavg[], int nelem)
583 char const *ptr = ldavgbuf; 511 char const *ptr = ldavgbuf;
584 int fd, count, saved_errno; 512 int fd, count, saved_errno;
585 513
586 fd = open (LINUX_LDAV_FILE, O_RDONLY); 514 fd = open (LINUX_LDAV_FILE, O_RDONLY | O_CLOEXEC);
587 if (fd == -1) 515 if (fd == -1)
588 return -1; 516 return -1;
589 count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); 517 count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
@@ -621,12 +549,12 @@ getloadavg (double loadavg[], int nelem)
621 for (ptr++; '0' <= *ptr && *ptr <= '9'; ptr++) 549 for (ptr++; '0' <= *ptr && *ptr <= '9'; ptr++)
622 numerator = 10 * numerator + (*ptr - '0'), denominator *= 10; 550 numerator = 10 * numerator + (*ptr - '0'), denominator *= 10;
623 551
624 loadavg[elem++] = numerator / denominator; 552 loadavg[elem] = numerator / denominator;
625 } 553 }
626 554
627 return elem; 555 return elem;
628 556
629# endif /* __linux__ || __CYGWIN__ */ 557# endif /* __linux__ || __ANDROID__ || __CYGWIN__ */
630 558
631# if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */ 559# if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */
632# define LDAV_DONE 560# define LDAV_DONE
@@ -638,15 +566,22 @@ getloadavg (double loadavg[], int nelem)
638 566
639 unsigned long int load_ave[3], scale; 567 unsigned long int load_ave[3], scale;
640 int count; 568 int count;
641 FILE *fp; 569 char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1];
642 570 int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC);
643 fp = fopen (NETBSD_LDAV_FILE, "r"); 571 if (fd < 0)
644 if (fp == NULL) 572 return fd;
645 return -1; 573 int nread = read (fd, readbuf, sizeof readbuf - 1);
646 count = fscanf (fp, "%lu %lu %lu %lu\n", 574 int err = errno;
575 close (fd);
576 if (nread < 0)
577 {
578 errno = err;
579 return -1;
580 }
581 readbuf[nread] = '\0';
582 count = sscanf (readbuf, "%lu %lu %lu %lu\n",
647 &load_ave[0], &load_ave[1], &load_ave[2], 583 &load_ave[0], &load_ave[1], &load_ave[2],
648 &scale); 584 &scale);
649 (void) fclose (fp);
650 if (count != 4) 585 if (count != 4)
651 { 586 {
652 errno = ENOTSUP; 587 errno = ENOTSUP;
@@ -915,7 +850,7 @@ getloadavg (double loadavg[], int nelem)
915 850
916# ifndef SUNOS_5 851# ifndef SUNOS_5
917 if ( 852 if (
918# if !(defined (_AIX) && !defined (ps2)) 853# if !defined (_AIX)
919 nlist (KERNEL_FILE, name_list) 854 nlist (KERNEL_FILE, name_list)
920# else /* _AIX */ 855# else /* _AIX */
921 knlist (name_list, 1, sizeof (name_list[0])) 856 knlist (name_list, 1, sizeof (name_list[0]))
@@ -940,33 +875,17 @@ getloadavg (double loadavg[], int nelem)
940 if (!getloadavg_initialized) 875 if (!getloadavg_initialized)
941 { 876 {
942# ifndef SUNOS_5 877# ifndef SUNOS_5
943 /* Set the channel to close on exec, so it does not
944 litter any child's descriptor table. */
945# ifndef O_CLOEXEC
946# define O_CLOEXEC 0
947# endif
948 int fd = open ("/dev/kmem", O_RDONLY | O_CLOEXEC); 878 int fd = open ("/dev/kmem", O_RDONLY | O_CLOEXEC);
949 if (0 <= fd) 879 if (0 <= fd)
950 { 880 {
951# if F_DUPFD_CLOEXEC 881 channel = fd;
952 if (fd <= STDERR_FILENO) 882 getloadavg_initialized = true;
953 {
954 int fd1 = fcntl (fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
955 close (fd);
956 fd = fd1;
957 }
958# endif
959 if (0 <= fd)
960 {
961 channel = fd;
962 getloadavg_initialized = true;
963 }
964 } 883 }
965# else /* SUNOS_5 */ 884# else /* SUNOS_5 */
966 /* We pass 0 for the kernel, corefile, and swapfile names 885 /* We pass 0 for the kernel, corefile, and swapfile names
967 to use the currently running kernel. */ 886 to use the currently running kernel. */
968 kd = kvm_open (0, 0, 0, O_RDONLY, 0); 887 kd = kvm_open (0, 0, 0, O_RDONLY, 0);
969 if (kd != 0) 888 if (kd != NULL)
970 { 889 {
971 /* nlist the currently running kernel. */ 890 /* nlist the currently running kernel. */
972 kvm_nlist (kd, name_list); 891 kvm_nlist (kd, name_list);
diff --git a/gl/getopt-cdefs.in.h b/gl/getopt-cdefs.in.h
new file mode 100644
index 0000000..e76c78c
--- /dev/null
+++ b/gl/getopt-cdefs.in.h
@@ -0,0 +1,66 @@
1/* getopt-on-non-glibc compatibility macros.
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 This file is part of gnulib.
4 Unlike most of the getopt implementation, it is NOT shared
5 with the GNU C Library.
6
7 This file is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
11
12 This file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19
20#ifndef _GETOPT_CDEFS_H
21#define _GETOPT_CDEFS_H 1
22
23/* This header should not be used directly; include getopt.h or
24 unistd.h instead. It does not have a protective #error, because
25 the guard macro for getopt.h in gnulib is not fixed. */
26
27/* getopt-core.h and getopt-ext.h are shared with GNU libc, and expect
28 a number of the internal macros supplied to GNU libc's headers by
29 sys/cdefs.h. Provide fallback definitions for all of them. */
30#if @HAVE_SYS_CDEFS_H@
31# include <sys/cdefs.h>
32#endif
33
34#ifndef __BEGIN_DECLS
35# ifdef __cplusplus
36# define __BEGIN_DECLS extern "C" {
37# else
38# define __BEGIN_DECLS /* nothing */
39# endif
40#endif
41#ifndef __END_DECLS
42# ifdef __cplusplus
43# define __END_DECLS }
44# else
45# define __END_DECLS /* nothing */
46# endif
47#endif
48
49#ifndef __GNUC_PREREQ
50# if defined __GNUC__ && defined __GNUC_VERSION__
51# define __GNUC_PREREQ(maj, min) \
52 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
53# else
54# define __GNUC_PREREQ(maj, min) 0
55# endif
56#endif
57
58#ifndef __THROW
59# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
60# define __THROW throw ()
61# else
62# define __THROW
63# endif
64#endif
65
66#endif /* _GETOPT_CDEFS_H */
diff --git a/gl/getopt-core.h b/gl/getopt-core.h
new file mode 100644
index 0000000..c5dd493
--- /dev/null
+++ b/gl/getopt-core.h
@@ -0,0 +1,96 @@
1/* Declarations for getopt (basic, portable features only).
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library and is also part of gnulib.
4 Patches to this file should be submitted to both projects.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library 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 GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#ifndef _GETOPT_CORE_H
21#define _GETOPT_CORE_H 1
22
23/* This header should not be used directly; include getopt.h or
24 unistd.h instead. Unlike most bits headers, it does not have
25 a protective #error, because the guard macro for getopt.h in
26 gnulib is not fixed. */
27
28__BEGIN_DECLS
29
30/* For communication from 'getopt' to the caller.
31 When 'getopt' finds an option that takes an argument,
32 the argument value is returned here.
33 Also, when 'ordering' is RETURN_IN_ORDER,
34 each non-option ARGV-element is returned here. */
35
36extern char *optarg;
37
38/* Index in ARGV of the next element to be scanned.
39 This is used for communication to and from the caller
40 and for communication between successive calls to 'getopt'.
41
42 On entry to 'getopt', zero means this is the first call; initialize.
43
44 When 'getopt' returns -1, this is the index of the first of the
45 non-option elements that the caller should itself scan.
46
47 Otherwise, 'optind' communicates from one call to the next
48 how much of ARGV has been scanned so far. */
49
50extern int optind;
51
52/* Callers store zero here to inhibit the error message 'getopt' prints
53 for unrecognized options. */
54
55extern int opterr;
56
57/* Set to an option character which was unrecognized. */
58
59extern int optopt;
60
61/* Get definitions and prototypes for functions to process the
62 arguments in ARGV (ARGC of them, minus the program name) for
63 options given in OPTS.
64
65 Return the option character from OPTS just read. Return -1 when
66 there are no more options. For unrecognized options, or options
67 missing arguments, 'optopt' is set to the option letter, and '?' is
68 returned.
69
70 The OPTS string is a list of characters which are recognized option
71 letters, optionally followed by colons, specifying that that letter
72 takes an argument, to be placed in 'optarg'.
73
74 If a letter in OPTS is followed by two colons, its argument is
75 optional. This behavior is specific to the GNU 'getopt'.
76
77 The argument '--' causes premature termination of argument
78 scanning, explicitly telling 'getopt' that there are no more
79 options.
80
81 If OPTS begins with '-', then non-option arguments are treated as
82 arguments to the option '\1'. This behavior is specific to the GNU
83 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
84 the environment, then do not permute arguments.
85
86 For standards compliance, the 'argv' argument has the type
87 char *const *, but this is inaccurate; if argument permutation is
88 enabled, the argv array (not the strings it points to) must be
89 writable. */
90
91extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
92 __THROW _GL_ARG_NONNULL ((2, 3));
93
94__END_DECLS
95
96#endif /* _GETOPT_CORE_H */
diff --git a/gl/getopt-ext.h b/gl/getopt-ext.h
new file mode 100644
index 0000000..d37c293
--- /dev/null
+++ b/gl/getopt-ext.h
@@ -0,0 +1,77 @@
1/* Declarations for getopt (GNU extensions).
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library and is also part of gnulib.
4 Patches to this file should be submitted to both projects.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library 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 GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#ifndef _GETOPT_EXT_H
21#define _GETOPT_EXT_H 1
22
23/* This header should not be used directly; include getopt.h instead.
24 Unlike most bits headers, it does not have a protective #error,
25 because the guard macro for getopt.h in gnulib is not fixed. */
26
27__BEGIN_DECLS
28
29/* Describe the long-named options requested by the application.
30 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
31 of 'struct option' terminated by an element containing a name which is
32 zero.
33
34 The field 'has_arg' is:
35 no_argument (or 0) if the option does not take an argument,
36 required_argument (or 1) if the option requires an argument,
37 optional_argument (or 2) if the option takes an optional argument.
38
39 If the field 'flag' is not NULL, it points to a variable that is set
40 to the value given in the field 'val' when the option is found, but
41 left unchanged if the option is not found.
42
43 To have a long-named option do something other than set an 'int' to
44 a compiled-in constant, such as set a value from 'optarg', set the
45 option's 'flag' field to zero and its 'val' field to a nonzero
46 value (the equivalent single-letter option character, if there is
47 one). For long options that have a zero 'flag' field, 'getopt'
48 returns the contents of the 'val' field. */
49
50struct option
51{
52 const char *name;
53 /* has_arg can't be an enum because some compilers complain about
54 type mismatches in all the code that assumes it is an int. */
55 int has_arg;
56 int *flag;
57 int val;
58};
59
60/* Names for the values of the 'has_arg' field of 'struct option'. */
61
62#define no_argument 0
63#define required_argument 1
64#define optional_argument 2
65
66extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
67 const char *__shortopts,
68 const struct option *__longopts, int *__longind)
69 __THROW _GL_ARG_NONNULL ((2, 3));
70extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
71 const char *__shortopts,
72 const struct option *__longopts, int *__longind)
73 __THROW _GL_ARG_NONNULL ((2, 3));
74
75__END_DECLS
76
77#endif /* _GETOPT_EXT_H */
diff --git a/gl/getopt-pfx-core.h b/gl/getopt-pfx-core.h
new file mode 100644
index 0000000..3a2fde5
--- /dev/null
+++ b/gl/getopt-pfx-core.h
@@ -0,0 +1,66 @@
1/* getopt (basic, portable features) gnulib wrapper header.
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 This file is part of gnulib.
4 Unlike most of the getopt implementation, it is NOT shared
5 with the GNU C Library.
6
7 This file is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
11
12 This file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19
20#ifndef _GETOPT_PFX_CORE_H
21#define _GETOPT_PFX_CORE_H 1
22
23/* This header should not be used directly; include getopt.h or
24 unistd.h instead. It does not have a protective #error, because
25 the guard macro for getopt.h in gnulib is not fixed. */
26
27/* Standalone applications should #define __GETOPT_PREFIX to an
28 identifier that prefixes the external functions and variables
29 defined in getopt-core.h and getopt-ext.h. Systematically
30 rename identifiers so that they do not collide with the system
31 functions and variables. Renaming avoids problems with some
32 compilers and linkers. */
33#ifdef __GETOPT_PREFIX
34# ifndef __GETOPT_ID
35# define __GETOPT_CONCAT(x, y) x ## y
36# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
37# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
38# endif
39# undef getopt
40# undef optarg
41# undef opterr
42# undef optind
43# undef optopt
44# define getopt __GETOPT_ID (getopt)
45# define optarg __GETOPT_ID (optarg)
46# define opterr __GETOPT_ID (opterr)
47# define optind __GETOPT_ID (optind)
48# define optopt __GETOPT_ID (optopt)
49
50/* Work around a a problem on macOS, which declares getopt with a
51 trailing __DARWIN_ALIAS(getopt) that would expand to something like
52 __asm("_" "rpl_getopt" "$UNIX2003") were it not for the following
53 hack to suppress the macOS declaration <https://bugs.gnu.org/40205>. */
54# ifdef __APPLE__
55# define _GETOPT
56# endif
57
58/* The system's getopt.h may have already included getopt-core.h to
59 declare the unprefixed identifiers. Undef _GETOPT_CORE_H so that
60 getopt-core.h declares them with prefixes. */
61# undef _GETOPT_CORE_H
62#endif
63
64#include <getopt-core.h>
65
66#endif /* _GETOPT_PFX_CORE_H */
diff --git a/gl/getopt-pfx-ext.h b/gl/getopt-pfx-ext.h
new file mode 100644
index 0000000..8578d72
--- /dev/null
+++ b/gl/getopt-pfx-ext.h
@@ -0,0 +1,70 @@
1/* getopt (GNU extensions) gnulib wrapper header.
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 This file is part of gnulib.
4 Unlike most of the getopt implementation, it is NOT shared
5 with the GNU C Library.
6
7 This file is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
11
12 This file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19
20#ifndef _GETOPT_PFX_EXT_H
21#define _GETOPT_PFX_EXT_H 1
22
23/* This header should not be used directly; include getopt.h instead.
24 It does not have a protective #error, because the guard macro for
25 getopt.h in gnulib is not fixed. */
26
27/* Standalone applications should #define __GETOPT_PREFIX to an
28 identifier that prefixes the external functions and variables
29 defined in getopt-core.h and getopt-ext.h. Systematically
30 rename identifiers so that they do not collide with the system
31 functions and variables. Renaming avoids problems with some
32 compilers and linkers. */
33#ifdef __GETOPT_PREFIX
34# ifndef __GETOPT_ID
35# define __GETOPT_CONCAT(x, y) x ## y
36# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
37# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
38# endif
39# undef getopt_long
40# undef getopt_long_only
41# undef option
42# undef _getopt_internal
43# define getopt_long __GETOPT_ID (getopt_long)
44# define getopt_long_only __GETOPT_ID (getopt_long_only)
45# define option __GETOPT_ID (option)
46# define _getopt_internal __GETOPT_ID (getopt_internal)
47
48/* The system's getopt.h may have already included getopt-ext.h to
49 declare the unprefixed identifiers. Undef _GETOPT_EXT_H so that
50 getopt-ext.h declares them with prefixes. */
51# undef _GETOPT_EXT_H
52#endif
53
54/* Standalone applications get correct prototypes for getopt_long and
55 getopt_long_only; they declare "char **argv". For backward
56 compatibility with old applications, if __GETOPT_PREFIX is not
57 defined, we supply GNU-libc-compatible, but incorrect, prototypes
58 using "char *const *argv". (GNU libc is stuck with the incorrect
59 prototypes, as they are baked into older versions of LSB.) */
60#ifndef __getopt_argv_const
61# if defined __GETOPT_PREFIX
62# define __getopt_argv_const /* empty */
63# else
64# define __getopt_argv_const const
65# endif
66#endif
67
68#include <getopt-ext.h>
69
70#endif /* _GETOPT_PFX_EXT_H */
diff --git a/gl/getopt.c b/gl/getopt.c
index ef0f4ce..1e2441c 100644
--- a/gl/getopt.c
+++ b/gl/getopt.c
@@ -1,23 +1,21 @@
1/* Getopt for GNU. 1/* Getopt for GNU.
2 NOTE: getopt is part of the C library, so if you don't know what 2 Copyright (C) 1987-2023 Free Software Foundation, Inc.
3 "Keep this file name-space clean" means, talk to drepper@gnu.org 3 This file is part of the GNU C Library and is also part of gnulib.
4 before changing it! 4 Patches to this file should be submitted to both projects.
5 Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2013 Free Software 5
6 Foundation, Inc. 6 The GNU C Library is free software; you can redistribute it and/or
7 This file is part of the GNU C Library. 7 modify it under the terms of the GNU Lesser General Public
8 8 License as published by the Free Software Foundation; either
9 This program is free software: you can redistribute it and/or modify 9 version 2.1 of the License, or (at your option) any later version.
10 it under the terms of the GNU General Public License as published by 10
11 the Free Software Foundation; either version 3 of the License, or 11 The GNU C Library is distributed in the hope that it will be useful,
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 GNU General Public License for more details. 14 Lesser General Public License for more details.
18 15
19 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU Lesser General Public
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
21 19
22#ifndef _LIBC 20#ifndef _LIBC
23# include <config.h> 21# include <config.h>
@@ -31,30 +29,54 @@
31#include <unistd.h> 29#include <unistd.h>
32 30
33#ifdef _LIBC 31#ifdef _LIBC
32/* When used as part of glibc, error printing must be done differently
33 for standards compliance. getopt is not a cancellation point, so
34 it must not call functions that are, and it is specified by an
35 older standard than stdio locking, so it must not refer to
36 functions in the "user namespace" related to stdio locking.
37 Finally, it must use glibc's internal message translation so that
38 the messages are looked up in the proper text domain. */
34# include <libintl.h> 39# include <libintl.h>
40# define fprintf __fxprintf_nocancel
41# define flockfile(fp) _IO_flockfile (fp)
42# define funlockfile(fp) _IO_funlockfile (fp)
35#else 43#else
36# include "gettext.h" 44# include "gettext.h"
37# define _(msgid) gettext (msgid) 45# define _(msgid) gettext (msgid)
46/* When used standalone, flockfile and funlockfile might not be
47 available. */
48# if (!defined _POSIX_THREAD_SAFE_FUNCTIONS \
49 || (defined _WIN32 && ! defined __CYGWIN__))
50# define flockfile(fp) /* nop */
51# define funlockfile(fp) /* nop */
52# endif
53/* When used standalone, do not attempt to use alloca. */
54# define __libc_use_alloca(size) 0
55# undef alloca
56# define alloca(size) (abort (), (void *)0)
38#endif 57#endif
39 58
40#if defined _LIBC && defined USE_IN_LIBIO 59/* This implementation of 'getopt' has three modes for handling
41# include <wchar.h> 60 options interspersed with non-option arguments. It can stop
42#endif 61 scanning for options at the first non-option argument encountered,
43 62 as POSIX specifies. It can continue scanning for options after the
44/* This version of 'getopt' appears to the caller like standard Unix 'getopt' 63 first non-option argument, but permute 'argv' as it goes so that,
45 but it behaves differently for the user, since it allows the user 64 after 'getopt' is done, all the options precede all the non-option
46 to intersperse the options with the other arguments. 65 arguments and 'optind' points to the first non-option argument.
47 66 Or, it can report non-option arguments as if they were arguments to
48 As 'getopt_long' works, it permutes the elements of ARGV so that, 67 the option character '\x01'.
49 when it is done, all the options precede everything else. Thus 68
50 all application programs are extended to handle flexible argument order. 69 The default behavior of 'getopt_long' is to permute the argument list.
51 70 When this implementation is used standalone, the default behavior of
52 Using 'getopt' or setting the environment variable POSIXLY_CORRECT 71 'getopt' is to stop at the first non-option argument, but when it is
72 used as part of GNU libc it also permutes the argument list. In both
73 cases, setting the environment variable POSIXLY_CORRECT to any value
53 disables permutation. 74 disables permutation.
54 Then the behavior is completely standard.
55 75
56 GNU application programs can use a third alternative mode in which 76 If the first character of the OPTSTRING argument to 'getopt' or
57 they can distinguish the relative order of options and other arguments. */ 77 'getopt_long' is '+', both functions will stop at the first
78 non-option argument. If it is '-', both functions will report
79 non-option arguments as arguments to the option character '\x01'. */
58 80
59#include "getopt_int.h" 81#include "getopt_int.h"
60 82
@@ -95,42 +117,7 @@ int optopt = '?';
95/* Keep a global copy of all internal members of getopt_data. */ 117/* Keep a global copy of all internal members of getopt_data. */
96 118
97static struct _getopt_data getopt_data; 119static struct _getopt_data getopt_data;
98
99
100#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
101extern char *getenv ();
102#endif
103 120
104#ifdef _LIBC
105/* Stored original parameters.
106 XXX This is no good solution. We should rather copy the args so
107 that we can compare them later. But we must not use malloc(3). */
108extern int __libc_argc;
109extern char **__libc_argv;
110
111/* Bash 2.0 gives us an environment variable containing flags
112 indicating ARGV elements that should not be considered arguments. */
113
114# ifdef USE_NONOPTION_FLAGS
115/* Defined in getopt_init.c */
116extern char *__getopt_nonoption_flags;
117# endif
118
119# ifdef USE_NONOPTION_FLAGS
120# define SWAP_FLAGS(ch1, ch2) \
121 if (d->__nonoption_flags_len > 0) \
122 { \
123 char __tmp = __getopt_nonoption_flags[ch1]; \
124 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
125 __getopt_nonoption_flags[ch2] = __tmp; \
126 }
127# else
128# define SWAP_FLAGS(ch1, ch2)
129# endif
130#else /* !_LIBC */
131# define SWAP_FLAGS(ch1, ch2)
132#endif /* _LIBC */
133
134/* Exchange two adjacent subsequences of ARGV. 121/* Exchange two adjacent subsequences of ARGV.
135 One subsequence is elements [first_nonopt,last_nonopt) 122 One subsequence is elements [first_nonopt,last_nonopt)
136 which contains all the non-options that have been skipped so far. 123 which contains all the non-options that have been skipped so far.
@@ -153,64 +140,40 @@ exchange (char **argv, struct _getopt_data *d)
153 It leaves the longer segment in the right place overall, 140 It leaves the longer segment in the right place overall,
154 but it consists of two parts that need to be swapped next. */ 141 but it consists of two parts that need to be swapped next. */
155 142
156#if defined _LIBC && defined USE_NONOPTION_FLAGS
157 /* First make sure the handling of the '__getopt_nonoption_flags'
158 string can work normally. Our top argument must be in the range
159 of the string. */
160 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
161 {
162 /* We must extend the array. The user plays games with us and
163 presents new arguments. */
164 char *new_str = malloc (top + 1);
165 if (new_str == NULL)
166 d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
167 else
168 {
169 memset (__mempcpy (new_str, __getopt_nonoption_flags,
170 d->__nonoption_flags_max_len),
171 '\0', top + 1 - d->__nonoption_flags_max_len);
172 d->__nonoption_flags_max_len = top + 1;
173 __getopt_nonoption_flags = new_str;
174 }
175 }
176#endif
177
178 while (top > middle && middle > bottom) 143 while (top > middle && middle > bottom)
179 { 144 {
180 if (top - middle > middle - bottom) 145 if (top - middle > middle - bottom)
181 { 146 {
182 /* Bottom segment is the short one. */ 147 /* Bottom segment is the short one. */
183 int len = middle - bottom; 148 int len = middle - bottom;
184 register int i; 149 int i;
185 150
186 /* Swap it with the top part of the top segment. */ 151 /* Swap it with the top part of the top segment. */
187 for (i = 0; i < len; i++) 152 for (i = 0; i < len; i++)
188 { 153 {
189 tem = argv[bottom + i]; 154 tem = argv[bottom + i];
190 argv[bottom + i] = argv[top - (middle - bottom) + i]; 155 argv[bottom + i] = argv[top - (middle - bottom) + i];
191 argv[top - (middle - bottom) + i] = tem; 156 argv[top - (middle - bottom) + i] = tem;
192 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); 157 }
193 } 158 /* Exclude the moved bottom segment from further swapping. */
194 /* Exclude the moved bottom segment from further swapping. */ 159 top -= len;
195 top -= len; 160 }
196 }
197 else 161 else
198 { 162 {
199 /* Top segment is the short one. */ 163 /* Top segment is the short one. */
200 int len = top - middle; 164 int len = top - middle;
201 register int i; 165 int i;
202 166
203 /* Swap it with the bottom part of the bottom segment. */ 167 /* Swap it with the bottom part of the bottom segment. */
204 for (i = 0; i < len; i++) 168 for (i = 0; i < len; i++)
205 { 169 {
206 tem = argv[bottom + i]; 170 tem = argv[bottom + i];
207 argv[bottom + i] = argv[middle + i]; 171 argv[bottom + i] = argv[middle + i];
208 argv[middle + i] = tem; 172 argv[middle + i] = tem;
209 SWAP_FLAGS (bottom + i, middle + i); 173 }
210 } 174 /* Exclude the moved top segment from further swapping. */
211 /* Exclude the moved top segment from further swapping. */ 175 bottom += len;
212 bottom += len; 176 }
213 }
214 } 177 }
215 178
216 /* Update records for the slots the non-options now occupy. */ 179 /* Update records for the slots the non-options now occupy. */
@@ -219,25 +182,216 @@ exchange (char **argv, struct _getopt_data *d)
219 d->__last_nonopt = d->optind; 182 d->__last_nonopt = d->optind;
220} 183}
221 184
222/* Initialize the internal data when the first call is made. */ 185/* Process the argument starting with d->__nextchar as a long option.
186 d->optind should *not* have been advanced over this argument.
187
188 If the value returned is -1, it was not actually a long option, the
189 state is unchanged, and the argument should be processed as a set
190 of short options (this can only happen when long_only is true).
191 Otherwise, the option (and its argument, if any) have been consumed
192 and the return value is the value to return from _getopt_internal_r. */
193static int
194process_long_option (int argc, char **argv, const char *optstring,
195 const struct option *longopts, int *longind,
196 int long_only, struct _getopt_data *d,
197 int print_errors, const char *prefix)
198{
199 char *nameend;
200 size_t namelen;
201 const struct option *p;
202 const struct option *pfound = NULL;
203 int n_options;
204 int option_index;
205
206 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
207 /* Do nothing. */ ;
208 namelen = nameend - d->__nextchar;
209
210 /* First look for an exact match, counting the options as a side
211 effect. */
212 for (p = longopts, n_options = 0; p->name; p++, n_options++)
213 if (!strncmp (p->name, d->__nextchar, namelen)
214 && namelen == strlen (p->name))
215 {
216 /* Exact match found. */
217 pfound = p;
218 option_index = n_options;
219 break;
220 }
221
222 if (pfound == NULL)
223 {
224 /* Didn't find an exact match, so look for abbreviations. */
225 unsigned char *ambig_set = NULL;
226 int ambig_malloced = 0;
227 int ambig_fallback = 0;
228 int indfound = -1;
229
230 for (p = longopts, option_index = 0; p->name; p++, option_index++)
231 if (!strncmp (p->name, d->__nextchar, namelen))
232 {
233 if (pfound == NULL)
234 {
235 /* First nonexact match found. */
236 pfound = p;
237 indfound = option_index;
238 }
239 else if (long_only
240 || pfound->has_arg != p->has_arg
241 || pfound->flag != p->flag
242 || pfound->val != p->val)
243 {
244 /* Second or later nonexact match found. */
245 if (!ambig_fallback)
246 {
247 if (!print_errors)
248 /* Don't waste effort tracking the ambig set if
249 we're not going to print it anyway. */
250 ambig_fallback = 1;
251 else if (!ambig_set)
252 {
253 if (__libc_use_alloca (n_options))
254 ambig_set = alloca (n_options);
255 else if ((ambig_set = malloc (n_options)) == NULL)
256 /* Fall back to simpler error message. */
257 ambig_fallback = 1;
258 else
259 ambig_malloced = 1;
260
261 if (ambig_set)
262 {
263 memset (ambig_set, 0, n_options);
264 ambig_set[indfound] = 1;
265 }
266 }
267 if (ambig_set)
268 ambig_set[option_index] = 1;
269 }
270 }
271 }
272
273 if (ambig_set || ambig_fallback)
274 {
275 if (print_errors)
276 {
277 if (ambig_fallback)
278 fprintf (stderr, _("%s: option '%s%s' is ambiguous\n"),
279 argv[0], prefix, d->__nextchar);
280 else
281 {
282 flockfile (stderr);
283 fprintf (stderr,
284 _("%s: option '%s%s' is ambiguous; possibilities:"),
285 argv[0], prefix, d->__nextchar);
286
287 for (option_index = 0; option_index < n_options; option_index++)
288 if (ambig_set[option_index])
289 fprintf (stderr, " '%s%s'",
290 prefix, longopts[option_index].name);
291
292 /* This must use 'fprintf' even though it's only
293 printing a single character, so that it goes through
294 __fxprintf_nocancel when compiled as part of glibc. */
295 fprintf (stderr, "\n");
296 funlockfile (stderr);
297 }
298 }
299 if (ambig_malloced)
300 free (ambig_set);
301 d->__nextchar += strlen (d->__nextchar);
302 d->optind++;
303 d->optopt = 0;
304 return '?';
305 }
306
307 option_index = indfound;
308 }
309
310 if (pfound == NULL)
311 {
312 /* Can't find it as a long option. If this is not getopt_long_only,
313 or the option starts with '--' or is not a valid short option,
314 then it's an error. */
315 if (!long_only || argv[d->optind][1] == '-'
316 || strchr (optstring, *d->__nextchar) == NULL)
317 {
318 if (print_errors)
319 fprintf (stderr, _("%s: unrecognized option '%s%s'\n"),
320 argv[0], prefix, d->__nextchar);
321
322 d->__nextchar = NULL;
323 d->optind++;
324 d->optopt = 0;
325 return '?';
326 }
327
328 /* Otherwise interpret it as a short option. */
329 return -1;
330 }
331
332 /* We have found a matching long option. Consume it. */
333 d->optind++;
334 d->__nextchar = NULL;
335 if (*nameend)
336 {
337 /* Don't test has_arg with >, because some C compilers don't
338 allow it to be used on enums. */
339 if (pfound->has_arg)
340 d->optarg = nameend + 1;
341 else
342 {
343 if (print_errors)
344 fprintf (stderr,
345 _("%s: option '%s%s' doesn't allow an argument\n"),
346 argv[0], prefix, pfound->name);
347
348 d->optopt = pfound->val;
349 return '?';
350 }
351 }
352 else if (pfound->has_arg == 1)
353 {
354 if (d->optind < argc)
355 d->optarg = argv[d->optind++];
356 else
357 {
358 if (print_errors)
359 fprintf (stderr,
360 _("%s: option '%s%s' requires an argument\n"),
361 argv[0], prefix, pfound->name);
362
363 d->optopt = pfound->val;
364 return optstring[0] == ':' ? ':' : '?';
365 }
366 }
367
368 if (longind != NULL)
369 *longind = option_index;
370 if (pfound->flag)
371 {
372 *(pfound->flag) = pfound->val;
373 return 0;
374 }
375 return pfound->val;
376}
377
378/* Initialize internal data upon the first call to getopt. */
223 379
224static const char * 380static const char *
225_getopt_initialize (int argc _GL_UNUSED, 381_getopt_initialize (_GL_UNUSED int argc,
226 char **argv _GL_UNUSED, const char *optstring, 382 _GL_UNUSED char **argv, const char *optstring,
227 struct _getopt_data *d, int posixly_correct) 383 struct _getopt_data *d, int posixly_correct)
228{ 384{
229 /* Start processing options with ARGV-element 1 (since ARGV-element 0 385 /* Start processing options with ARGV-element 1 (since ARGV-element 0
230 is the program name); the sequence of previously skipped 386 is the program name); the sequence of previously skipped
231 non-option ARGV-elements is empty. */ 387 non-option ARGV-elements is empty. */
388 if (d->optind == 0)
389 d->optind = 1;
232 390
233 d->__first_nonopt = d->__last_nonopt = d->optind; 391 d->__first_nonopt = d->__last_nonopt = d->optind;
234
235 d->__nextchar = NULL; 392 d->__nextchar = NULL;
236 393
237 d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
238
239 /* Determine how to handle the ordering of options and nonoptions. */ 394 /* Determine how to handle the ordering of options and nonoptions. */
240
241 if (optstring[0] == '-') 395 if (optstring[0] == '-')
242 { 396 {
243 d->__ordering = RETURN_IN_ORDER; 397 d->__ordering = RETURN_IN_ORDER;
@@ -248,41 +402,12 @@ _getopt_initialize (int argc _GL_UNUSED,
248 d->__ordering = REQUIRE_ORDER; 402 d->__ordering = REQUIRE_ORDER;
249 ++optstring; 403 ++optstring;
250 } 404 }
251 else if (d->__posixly_correct) 405 else if (posixly_correct || !!getenv ("POSIXLY_CORRECT"))
252 d->__ordering = REQUIRE_ORDER; 406 d->__ordering = REQUIRE_ORDER;
253 else 407 else
254 d->__ordering = PERMUTE; 408 d->__ordering = PERMUTE;
255 409
256#if defined _LIBC && defined USE_NONOPTION_FLAGS 410 d->__initialized = 1;
257 if (!d->__posixly_correct
258 && argc == __libc_argc && argv == __libc_argv)
259 {
260 if (d->__nonoption_flags_max_len == 0)
261 {
262 if (__getopt_nonoption_flags == NULL
263 || __getopt_nonoption_flags[0] == '\0')
264 d->__nonoption_flags_max_len = -1;
265 else
266 {
267 const char *orig_str = __getopt_nonoption_flags;
268 int len = d->__nonoption_flags_max_len = strlen (orig_str);
269 if (d->__nonoption_flags_max_len < argc)
270 d->__nonoption_flags_max_len = argc;
271 __getopt_nonoption_flags =
272 (char *) malloc (d->__nonoption_flags_max_len);
273 if (__getopt_nonoption_flags == NULL)
274 d->__nonoption_flags_max_len = -1;
275 else
276 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
277 '\0', d->__nonoption_flags_max_len - len);
278 }
279 }
280 d->__nonoption_flags_len = d->__nonoption_flags_max_len;
281 }
282 else
283 d->__nonoption_flags_len = 0;
284#endif
285
286 return optstring; 411 return optstring;
287} 412}
288 413
@@ -344,8 +469,8 @@ _getopt_initialize (int argc _GL_UNUSED,
344 469
345int 470int
346_getopt_internal_r (int argc, char **argv, const char *optstring, 471_getopt_internal_r (int argc, char **argv, const char *optstring,
347 const struct option *longopts, int *longind, 472 const struct option *longopts, int *longind,
348 int long_only, struct _getopt_data *d, int posixly_correct) 473 int long_only, struct _getopt_data *d, int posixly_correct)
349{ 474{
350 int print_errors = d->opterr; 475 int print_errors = d->opterr;
351 476
@@ -355,431 +480,129 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
355 d->optarg = NULL; 480 d->optarg = NULL;
356 481
357 if (d->optind == 0 || !d->__initialized) 482 if (d->optind == 0 || !d->__initialized)
358 { 483 optstring = _getopt_initialize (argc, argv, optstring, d, posixly_correct);
359 if (d->optind == 0)
360 d->optind = 1; /* Don't scan ARGV[0], the program name. */
361 optstring = _getopt_initialize (argc, argv, optstring, d,
362 posixly_correct);
363 d->__initialized = 1;
364 }
365 else if (optstring[0] == '-' || optstring[0] == '+') 484 else if (optstring[0] == '-' || optstring[0] == '+')
366 optstring++; 485 optstring++;
486
367 if (optstring[0] == ':') 487 if (optstring[0] == ':')
368 print_errors = 0; 488 print_errors = 0;
369 489
370 /* Test whether ARGV[optind] points to a non-option argument. 490 /* Test whether ARGV[optind] points to a non-option argument. */
371 Either it does not have option syntax, or there is an environment flag 491#define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
372 from the shell indicating it is not an option. The later information
373 is only used when the used in the GNU libc. */
374#if defined _LIBC && defined USE_NONOPTION_FLAGS
375# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
376 || (d->optind < d->__nonoption_flags_len \
377 && __getopt_nonoption_flags[d->optind] == '1'))
378#else
379# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
380#endif
381 492
382 if (d->__nextchar == NULL || *d->__nextchar == '\0') 493 if (d->__nextchar == NULL || *d->__nextchar == '\0')
383 { 494 {
384 /* Advance to the next ARGV-element. */ 495 /* Advance to the next ARGV-element. */
385 496
386 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been 497 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
387 moved back by the user (who may also have changed the arguments). */ 498 moved back by the user (who may also have changed the arguments). */
388 if (d->__last_nonopt > d->optind) 499 if (d->__last_nonopt > d->optind)
389 d->__last_nonopt = d->optind; 500 d->__last_nonopt = d->optind;
390 if (d->__first_nonopt > d->optind) 501 if (d->__first_nonopt > d->optind)
391 d->__first_nonopt = d->optind; 502 d->__first_nonopt = d->optind;
392 503
393 if (d->__ordering == PERMUTE) 504 if (d->__ordering == PERMUTE)
394 { 505 {
395 /* If we have just processed some options following some non-options, 506 /* If we have just processed some options following some non-options,
396 exchange them so that the options come first. */ 507 exchange them so that the options come first. */
397 508
398 if (d->__first_nonopt != d->__last_nonopt 509 if (d->__first_nonopt != d->__last_nonopt
399 && d->__last_nonopt != d->optind) 510 && d->__last_nonopt != d->optind)
400 exchange ((char **) argv, d); 511 exchange (argv, d);
401 else if (d->__last_nonopt != d->optind) 512 else if (d->__last_nonopt != d->optind)
402 d->__first_nonopt = d->optind; 513 d->__first_nonopt = d->optind;
403 514
404 /* Skip any additional non-options 515 /* Skip any additional non-options
405 and extend the range of non-options previously skipped. */ 516 and extend the range of non-options previously skipped. */
406 517
407 while (d->optind < argc && NONOPTION_P) 518 while (d->optind < argc && NONOPTION_P)
408 d->optind++; 519 d->optind++;
409 d->__last_nonopt = d->optind; 520 d->__last_nonopt = d->optind;
410 } 521 }
411 522
412 /* The special ARGV-element '--' means premature end of options. 523 /* The special ARGV-element '--' means premature end of options.
413 Skip it like a null option, 524 Skip it like a null option,
414 then exchange with previous non-options as if it were an option, 525 then exchange with previous non-options as if it were an option,
415 then skip everything else like a non-option. */ 526 then skip everything else like a non-option. */
416 527
417 if (d->optind != argc && !strcmp (argv[d->optind], "--")) 528 if (d->optind != argc && !strcmp (argv[d->optind], "--"))
418 { 529 {
419 d->optind++; 530 d->optind++;
420 531
421 if (d->__first_nonopt != d->__last_nonopt 532 if (d->__first_nonopt != d->__last_nonopt
422 && d->__last_nonopt != d->optind) 533 && d->__last_nonopt != d->optind)
423 exchange ((char **) argv, d); 534 exchange (argv, d);
424 else if (d->__first_nonopt == d->__last_nonopt) 535 else if (d->__first_nonopt == d->__last_nonopt)
425 d->__first_nonopt = d->optind; 536 d->__first_nonopt = d->optind;
426 d->__last_nonopt = argc; 537 d->__last_nonopt = argc;
427 538
428 d->optind = argc; 539 d->optind = argc;
429 } 540 }
430 541
431 /* If we have done all the ARGV-elements, stop the scan 542 /* If we have done all the ARGV-elements, stop the scan
432 and back over any non-options that we skipped and permuted. */ 543 and back over any non-options that we skipped and permuted. */
433 544
434 if (d->optind == argc) 545 if (d->optind == argc)
435 { 546 {
436 /* Set the next-arg-index to point at the non-options 547 /* Set the next-arg-index to point at the non-options
437 that we previously skipped, so the caller will digest them. */ 548 that we previously skipped, so the caller will digest them. */
438 if (d->__first_nonopt != d->__last_nonopt) 549 if (d->__first_nonopt != d->__last_nonopt)
439 d->optind = d->__first_nonopt; 550 d->optind = d->__first_nonopt;
440 return -1; 551 return -1;
441 } 552 }
442 553
443 /* If we have come to a non-option and did not permute it, 554 /* If we have come to a non-option and did not permute it,
444 either stop the scan or describe it to the caller and pass it by. */ 555 either stop the scan or describe it to the caller and pass it by. */
445 556
446 if (NONOPTION_P) 557 if (NONOPTION_P)
447 { 558 {
448 if (d->__ordering == REQUIRE_ORDER) 559 if (d->__ordering == REQUIRE_ORDER)
449 return -1; 560 return -1;
450 d->optarg = argv[d->optind++]; 561 d->optarg = argv[d->optind++];
451 return 1; 562 return 1;
452 } 563 }
453 564
454 /* We have found another option-ARGV-element. 565 /* We have found another option-ARGV-element.
455 Skip the initial punctuation. */ 566 Check whether it might be a long option. */
456 567 if (longopts)
457 d->__nextchar = (argv[d->optind] + 1 568 {
458 + (longopts != NULL && argv[d->optind][1] == '-')); 569 if (argv[d->optind][1] == '-')
459 } 570 {
460 571 /* "--foo" is always a long option. The special option
461 /* Decode the current option-ARGV-element. */ 572 "--" was handled above. */
462 573 d->__nextchar = argv[d->optind] + 2;
463 /* Check whether the ARGV-element is a long option. 574 return process_long_option (argc, argv, optstring, longopts,
464 575 longind, long_only, d,
465 If long_only and the ARGV-element has the form "-f", where f is 576 print_errors, "--");
466 a valid short option, don't consider it an abbreviated form of 577 }
467 a long option that starts with f. Otherwise there would be no 578
468 way to give the -f short option. 579 /* If long_only and the ARGV-element has the form "-f",
469 580 where f is a valid short option, don't consider it an
470 On the other hand, if there's a long option "fubar" and 581 abbreviated form of a long option that starts with f.
471 the ARGV-element is "-fu", do consider that an abbreviation of 582 Otherwise there would be no way to give the -f short
472 the long option, just like "--fu", and not "-f" with arg "u". 583 option.
473 584
474 This distinction seems to be the most useful approach. */ 585 On the other hand, if there's a long option "fubar" and
475 586 the ARGV-element is "-fu", do consider that an
476 if (longopts != NULL 587 abbreviation of the long option, just like "--fu", and
477 && (argv[d->optind][1] == '-' 588 not "-f" with arg "u".
478 || (long_only && (argv[d->optind][2] 589
479 || !strchr (optstring, argv[d->optind][1]))))) 590 This distinction seems to be the most useful approach. */
480 { 591 if (long_only && (argv[d->optind][2]
481 char *nameend; 592 || !strchr (optstring, argv[d->optind][1])))
482 unsigned int namelen; 593 {
483 const struct option *p; 594 int code;
484 const struct option *pfound = NULL; 595 d->__nextchar = argv[d->optind] + 1;
485 struct option_list 596 code = process_long_option (argc, argv, optstring, longopts,
486 { 597 longind, long_only, d,
487 const struct option *p; 598 print_errors, "-");
488 struct option_list *next; 599 if (code != -1)
489 } *ambig_list = NULL; 600 return code;
490 int exact = 0; 601 }
491 int indfound = -1; 602 }
492 int option_index; 603
493 604 /* It is not a long option. Skip the initial punctuation. */
494 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) 605 d->__nextchar = argv[d->optind] + 1;
495 /* Do nothing. */ ;
496 namelen = nameend - d->__nextchar;
497
498 /* Test all long options for either exact match
499 or abbreviated matches. */
500 for (p = longopts, option_index = 0; p->name; p++, option_index++)
501 if (!strncmp (p->name, d->__nextchar, namelen))
502 {
503 if (namelen == (unsigned int) strlen (p->name))
504 {
505 /* Exact match found. */
506 pfound = p;
507 indfound = option_index;
508 exact = 1;
509 break;
510 }
511 else if (pfound == NULL)
512 {
513 /* First nonexact match found. */
514 pfound = p;
515 indfound = option_index;
516 }
517 else if (long_only
518 || pfound->has_arg != p->has_arg
519 || pfound->flag != p->flag
520 || pfound->val != p->val)
521 {
522 /* Second or later nonexact match found. */
523 struct option_list *newp = malloc (sizeof (*newp));
524 newp->p = p;
525 newp->next = ambig_list;
526 ambig_list = newp;
527 }
528 }
529
530 if (ambig_list != NULL && !exact)
531 {
532 if (print_errors)
533 {
534 struct option_list first;
535 first.p = pfound;
536 first.next = ambig_list;
537 ambig_list = &first;
538
539#if defined _LIBC && defined USE_IN_LIBIO
540 char *buf = NULL;
541 size_t buflen = 0;
542
543 FILE *fp = open_memstream (&buf, &buflen);
544 if (fp != NULL)
545 {
546 fprintf (fp,
547 _("%s: option '%s' is ambiguous; possibilities:"),
548 argv[0], argv[d->optind]);
549
550 do
551 {
552 fprintf (fp, " '--%s'", ambig_list->p->name);
553 ambig_list = ambig_list->next;
554 }
555 while (ambig_list != NULL);
556
557 fputc_unlocked ('\n', fp);
558
559 if (__builtin_expect (fclose (fp) != EOF, 1))
560 {
561 _IO_flockfile (stderr);
562
563 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
564 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
565
566 __fxprintf (NULL, "%s", buf);
567
568 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
569 _IO_funlockfile (stderr);
570
571 free (buf);
572 }
573 }
574#else
575 fprintf (stderr,
576 _("%s: option '%s' is ambiguous; possibilities:"),
577 argv[0], argv[d->optind]);
578 do
579 {
580 fprintf (stderr, " '--%s'", ambig_list->p->name);
581 ambig_list = ambig_list->next;
582 }
583 while (ambig_list != NULL);
584
585 fputc ('\n', stderr);
586#endif
587 }
588 d->__nextchar += strlen (d->__nextchar);
589 d->optind++;
590 d->optopt = 0;
591 return '?';
592 }
593
594 while (ambig_list != NULL)
595 {
596 struct option_list *pn = ambig_list->next;
597 free (ambig_list);
598 ambig_list = pn;
599 }
600
601 if (pfound != NULL)
602 {
603 option_index = indfound;
604 d->optind++;
605 if (*nameend)
606 {
607 /* Don't test has_arg with >, because some C compilers don't
608 allow it to be used on enums. */
609 if (pfound->has_arg)
610 d->optarg = nameend + 1;
611 else
612 {
613 if (print_errors)
614 {
615#if defined _LIBC && defined USE_IN_LIBIO
616 char *buf;
617 int n;
618#endif
619
620 if (argv[d->optind - 1][1] == '-')
621 {
622 /* --option */
623#if defined _LIBC && defined USE_IN_LIBIO
624 n = __asprintf (&buf, _("\
625%s: option '--%s' doesn't allow an argument\n"),
626 argv[0], pfound->name);
627#else
628 fprintf (stderr, _("\
629%s: option '--%s' doesn't allow an argument\n"),
630 argv[0], pfound->name);
631#endif
632 }
633 else
634 {
635 /* +option or -option */
636#if defined _LIBC && defined USE_IN_LIBIO
637 n = __asprintf (&buf, _("\
638%s: option '%c%s' doesn't allow an argument\n"),
639 argv[0], argv[d->optind - 1][0],
640 pfound->name);
641#else
642 fprintf (stderr, _("\
643%s: option '%c%s' doesn't allow an argument\n"),
644 argv[0], argv[d->optind - 1][0],
645 pfound->name);
646#endif
647 }
648
649#if defined _LIBC && defined USE_IN_LIBIO
650 if (n >= 0)
651 {
652 _IO_flockfile (stderr);
653
654 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
655 ((_IO_FILE *) stderr)->_flags2
656 |= _IO_FLAGS2_NOTCANCEL;
657
658 __fxprintf (NULL, "%s", buf);
659
660 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
661 _IO_funlockfile (stderr);
662
663 free (buf);
664 }
665#endif
666 }
667
668 d->__nextchar += strlen (d->__nextchar);
669
670 d->optopt = pfound->val;
671 return '?';
672 }
673 }
674 else if (pfound->has_arg == 1)
675 {
676 if (d->optind < argc)
677 d->optarg = argv[d->optind++];
678 else
679 {
680 if (print_errors)
681 {
682#if defined _LIBC && defined USE_IN_LIBIO
683 char *buf;
684
685 if (__asprintf (&buf, _("\
686%s: option '--%s' requires an argument\n"),
687 argv[0], pfound->name) >= 0)
688 {
689 _IO_flockfile (stderr);
690
691 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
692 ((_IO_FILE *) stderr)->_flags2
693 |= _IO_FLAGS2_NOTCANCEL;
694
695 __fxprintf (NULL, "%s", buf);
696
697 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
698 _IO_funlockfile (stderr);
699
700 free (buf);
701 }
702#else
703 fprintf (stderr,
704 _("%s: option '--%s' requires an argument\n"),
705 argv[0], pfound->name);
706#endif
707 }
708 d->__nextchar += strlen (d->__nextchar);
709 d->optopt = pfound->val;
710 return optstring[0] == ':' ? ':' : '?';
711 }
712 }
713 d->__nextchar += strlen (d->__nextchar);
714 if (longind != NULL)
715 *longind = option_index;
716 if (pfound->flag)
717 {
718 *(pfound->flag) = pfound->val;
719 return 0;
720 }
721 return pfound->val;
722 }
723
724 /* Can't find it as a long option. If this is not getopt_long_only,
725 or the option starts with '--' or is not a valid short
726 option, then it's an error.
727 Otherwise interpret it as a short option. */
728 if (!long_only || argv[d->optind][1] == '-'
729 || strchr (optstring, *d->__nextchar) == NULL)
730 {
731 if (print_errors)
732 {
733#if defined _LIBC && defined USE_IN_LIBIO
734 char *buf;
735 int n;
736#endif
737
738 if (argv[d->optind][1] == '-')
739 {
740 /* --option */
741#if defined _LIBC && defined USE_IN_LIBIO
742 n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
743 argv[0], d->__nextchar);
744#else
745 fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
746 argv[0], d->__nextchar);
747#endif
748 }
749 else
750 {
751 /* +option or -option */
752#if defined _LIBC && defined USE_IN_LIBIO
753 n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
754 argv[0], argv[d->optind][0], d->__nextchar);
755#else
756 fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
757 argv[0], argv[d->optind][0], d->__nextchar);
758#endif
759 }
760
761#if defined _LIBC && defined USE_IN_LIBIO
762 if (n >= 0)
763 {
764 _IO_flockfile (stderr);
765
766 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
767 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
768
769 __fxprintf (NULL, "%s", buf);
770
771 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
772 _IO_funlockfile (stderr);
773
774 free (buf);
775 }
776#endif
777 }
778 d->__nextchar = (char *) "";
779 d->optind++;
780 d->optopt = 0;
781 return '?';
782 }
783 } 606 }
784 607
785 /* Look at and handle the next short option-character. */ 608 /* Look at and handle the next short option-character. */
@@ -794,331 +617,83 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
794 617
795 if (temp == NULL || c == ':' || c == ';') 618 if (temp == NULL || c == ':' || c == ';')
796 { 619 {
797 if (print_errors) 620 if (print_errors)
798 { 621 fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
799#if defined _LIBC && defined USE_IN_LIBIO 622 d->optopt = c;
800 char *buf; 623 return '?';
801 int n;
802#endif
803
804#if defined _LIBC && defined USE_IN_LIBIO
805 n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
806 argv[0], c);
807#else
808 fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
809#endif
810
811#if defined _LIBC && defined USE_IN_LIBIO
812 if (n >= 0)
813 {
814 _IO_flockfile (stderr);
815
816 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
817 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
818
819 __fxprintf (NULL, "%s", buf);
820
821 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
822 _IO_funlockfile (stderr);
823
824 free (buf);
825 }
826#endif
827 }
828 d->optopt = c;
829 return '?';
830 } 624 }
625
831 /* Convenience. Treat POSIX -W foo same as long option --foo */ 626 /* Convenience. Treat POSIX -W foo same as long option --foo */
832 if (temp[0] == 'W' && temp[1] == ';') 627 if (temp[0] == 'W' && temp[1] == ';' && longopts != NULL)
833 { 628 {
834 char *nameend; 629 /* This is an option that requires an argument. */
835 const struct option *p; 630 if (*d->__nextchar != '\0')
836 const struct option *pfound = NULL; 631 d->optarg = d->__nextchar;
837 int exact = 0; 632 else if (d->optind == argc)
838 int ambig = 0; 633 {
839 int indfound = 0; 634 if (print_errors)
840 int option_index; 635 fprintf (stderr,
841 636 _("%s: option requires an argument -- '%c'\n"),
842 if (longopts == NULL) 637 argv[0], c);
843 goto no_longs; 638
844 639 d->optopt = c;
845 /* This is an option that requires an argument. */ 640 if (optstring[0] == ':')
846 if (*d->__nextchar != '\0') 641 c = ':';
847 { 642 else
848 d->optarg = d->__nextchar; 643 c = '?';
849 /* If we end this ARGV-element by taking the rest as an arg, 644 return c;
850 we must advance to the next element now. */ 645 }
851 d->optind++; 646 else
852 } 647 d->optarg = argv[d->optind];
853 else if (d->optind == argc) 648
854 { 649 d->__nextchar = d->optarg;
855 if (print_errors) 650 d->optarg = NULL;
856 { 651 return process_long_option (argc, argv, optstring, longopts, longind,
857#if defined _LIBC && defined USE_IN_LIBIO 652 0 /* long_only */, d, print_errors, "-W ");
858 char *buf;
859
860 if (__asprintf (&buf,
861 _("%s: option requires an argument -- '%c'\n"),
862 argv[0], c) >= 0)
863 {
864 _IO_flockfile (stderr);
865
866 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
867 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
868
869 __fxprintf (NULL, "%s", buf);
870
871 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
872 _IO_funlockfile (stderr);
873
874 free (buf);
875 }
876#else
877 fprintf (stderr,
878 _("%s: option requires an argument -- '%c'\n"),
879 argv[0], c);
880#endif
881 }
882 d->optopt = c;
883 if (optstring[0] == ':')
884 c = ':';
885 else
886 c = '?';
887 return c;
888 }
889 else
890 /* We already incremented 'd->optind' once;
891 increment it again when taking next ARGV-elt as argument. */
892 d->optarg = argv[d->optind++];
893
894 /* optarg is now the argument, see if it's in the
895 table of longopts. */
896
897 for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
898 nameend++)
899 /* Do nothing. */ ;
900
901 /* Test all long options for either exact match
902 or abbreviated matches. */
903 for (p = longopts, option_index = 0; p->name; p++, option_index++)
904 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
905 {
906 if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
907 {
908 /* Exact match found. */
909 pfound = p;
910 indfound = option_index;
911 exact = 1;
912 break;
913 }
914 else if (pfound == NULL)
915 {
916 /* First nonexact match found. */
917 pfound = p;
918 indfound = option_index;
919 }
920 else if (long_only
921 || pfound->has_arg != p->has_arg
922 || pfound->flag != p->flag
923 || pfound->val != p->val)
924 /* Second or later nonexact match found. */
925 ambig = 1;
926 }
927 if (ambig && !exact)
928 {
929 if (print_errors)
930 {
931#if defined _LIBC && defined USE_IN_LIBIO
932 char *buf;
933
934 if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
935 argv[0], d->optarg) >= 0)
936 {
937 _IO_flockfile (stderr);
938
939 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
940 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
941
942 __fxprintf (NULL, "%s", buf);
943
944 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
945 _IO_funlockfile (stderr);
946
947 free (buf);
948 }
949#else
950 fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
951 argv[0], d->optarg);
952#endif
953 }
954 d->__nextchar += strlen (d->__nextchar);
955 d->optind++;
956 return '?';
957 }
958 if (pfound != NULL)
959 {
960 option_index = indfound;
961 if (*nameend)
962 {
963 /* Don't test has_arg with >, because some C compilers don't
964 allow it to be used on enums. */
965 if (pfound->has_arg)
966 d->optarg = nameend + 1;
967 else
968 {
969 if (print_errors)
970 {
971#if defined _LIBC && defined USE_IN_LIBIO
972 char *buf;
973
974 if (__asprintf (&buf, _("\
975%s: option '-W %s' doesn't allow an argument\n"),
976 argv[0], pfound->name) >= 0)
977 {
978 _IO_flockfile (stderr);
979
980 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
981 ((_IO_FILE *) stderr)->_flags2
982 |= _IO_FLAGS2_NOTCANCEL;
983
984 __fxprintf (NULL, "%s", buf);
985
986 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
987 _IO_funlockfile (stderr);
988
989 free (buf);
990 }
991#else
992 fprintf (stderr, _("\
993%s: option '-W %s' doesn't allow an argument\n"),
994 argv[0], pfound->name);
995#endif
996 }
997
998 d->__nextchar += strlen (d->__nextchar);
999 return '?';
1000 }
1001 }
1002 else if (pfound->has_arg == 1)
1003 {
1004 if (d->optind < argc)
1005 d->optarg = argv[d->optind++];
1006 else
1007 {
1008 if (print_errors)
1009 {
1010#if defined _LIBC && defined USE_IN_LIBIO
1011 char *buf;
1012
1013 if (__asprintf (&buf, _("\
1014%s: option '-W %s' requires an argument\n"),
1015 argv[0], pfound->name) >= 0)
1016 {
1017 _IO_flockfile (stderr);
1018
1019 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1020 ((_IO_FILE *) stderr)->_flags2
1021 |= _IO_FLAGS2_NOTCANCEL;
1022
1023 __fxprintf (NULL, "%s", buf);
1024
1025 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
1026 _IO_funlockfile (stderr);
1027
1028 free (buf);
1029 }
1030#else
1031 fprintf (stderr, _("\
1032%s: option '-W %s' requires an argument\n"),
1033 argv[0], pfound->name);
1034#endif
1035 }
1036 d->__nextchar += strlen (d->__nextchar);
1037 return optstring[0] == ':' ? ':' : '?';
1038 }
1039 }
1040 else
1041 d->optarg = NULL;
1042 d->__nextchar += strlen (d->__nextchar);
1043 if (longind != NULL)
1044 *longind = option_index;
1045 if (pfound->flag)
1046 {
1047 *(pfound->flag) = pfound->val;
1048 return 0;
1049 }
1050 return pfound->val;
1051 }
1052
1053 no_longs:
1054 d->__nextchar = NULL;
1055 return 'W'; /* Let the application handle it. */
1056 } 653 }
1057 if (temp[1] == ':') 654 if (temp[1] == ':')
1058 { 655 {
1059 if (temp[2] == ':') 656 if (temp[2] == ':')
1060 { 657 {
1061 /* This is an option that accepts an argument optionally. */ 658 /* This is an option that accepts an argument optionally. */
1062 if (*d->__nextchar != '\0') 659 if (*d->__nextchar != '\0')
1063 { 660 {
1064 d->optarg = d->__nextchar; 661 d->optarg = d->__nextchar;
1065 d->optind++; 662 d->optind++;
1066 } 663 }
1067 else 664 else
1068 d->optarg = NULL; 665 d->optarg = NULL;
1069 d->__nextchar = NULL; 666 d->__nextchar = NULL;
1070 } 667 }
1071 else 668 else
1072 { 669 {
1073 /* This is an option that requires an argument. */ 670 /* This is an option that requires an argument. */
1074 if (*d->__nextchar != '\0') 671 if (*d->__nextchar != '\0')
1075 { 672 {
1076 d->optarg = d->__nextchar; 673 d->optarg = d->__nextchar;
1077 /* If we end this ARGV-element by taking the rest as an arg, 674 /* If we end this ARGV-element by taking the rest as an arg,
1078 we must advance to the next element now. */ 675 we must advance to the next element now. */
1079 d->optind++; 676 d->optind++;
1080 } 677 }
1081 else if (d->optind == argc) 678 else if (d->optind == argc)
1082 { 679 {
1083 if (print_errors) 680 if (print_errors)
1084 { 681 fprintf (stderr,
1085#if defined _LIBC && defined USE_IN_LIBIO 682 _("%s: option requires an argument -- '%c'\n"),
1086 char *buf; 683 argv[0], c);
1087 684
1088 if (__asprintf (&buf, _("\ 685 d->optopt = c;
1089%s: option requires an argument -- '%c'\n"), 686 if (optstring[0] == ':')
1090 argv[0], c) >= 0) 687 c = ':';
1091 { 688 else
1092 _IO_flockfile (stderr); 689 c = '?';
1093 690 }
1094 int old_flags2 = ((_IO_FILE *) stderr)->_flags2; 691 else
1095 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; 692 /* We already incremented 'optind' once;
1096 693 increment it again when taking next ARGV-elt as argument. */
1097 __fxprintf (NULL, "%s", buf); 694 d->optarg = argv[d->optind++];
1098 695 d->__nextchar = NULL;
1099 ((_IO_FILE *) stderr)->_flags2 = old_flags2; 696 }
1100 _IO_funlockfile (stderr);
1101
1102 free (buf);
1103 }
1104#else
1105 fprintf (stderr,
1106 _("%s: option requires an argument -- '%c'\n"),
1107 argv[0], c);
1108#endif
1109 }
1110 d->optopt = c;
1111 if (optstring[0] == ':')
1112 c = ':';
1113 else
1114 c = '?';
1115 }
1116 else
1117 /* We already incremented 'optind' once;
1118 increment it again when taking next ARGV-elt as argument. */
1119 d->optarg = argv[d->optind++];
1120 d->__nextchar = NULL;
1121 }
1122 } 697 }
1123 return c; 698 return c;
1124 } 699 }
@@ -1126,8 +701,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
1126 701
1127int 702int
1128_getopt_internal (int argc, char **argv, const char *optstring, 703_getopt_internal (int argc, char **argv, const char *optstring,
1129 const struct option *longopts, int *longind, int long_only, 704 const struct option *longopts, int *longind, int long_only,
1130 int posixly_correct) 705 int posixly_correct)
1131{ 706{
1132 int result; 707 int result;
1133 708
@@ -1135,8 +710,8 @@ _getopt_internal (int argc, char **argv, const char *optstring,
1135 getopt_data.opterr = opterr; 710 getopt_data.opterr = opterr;
1136 711
1137 result = _getopt_internal_r (argc, argv, optstring, longopts, 712 result = _getopt_internal_r (argc, argv, optstring, longopts,
1138 longind, long_only, &getopt_data, 713 longind, long_only, &getopt_data,
1139 posixly_correct); 714 posixly_correct);
1140 715
1141 optind = getopt_data.optind; 716 optind = getopt_data.optind;
1142 optarg = getopt_data.optarg; 717 optarg = getopt_data.optarg;
@@ -1145,32 +720,23 @@ _getopt_internal (int argc, char **argv, const char *optstring,
1145 return result; 720 return result;
1146} 721}
1147 722
1148/* glibc gets a LSB-compliant getopt. 723/* glibc gets a LSB-compliant getopt and a POSIX-complaint __posix_getopt.
1149 Standalone applications get a POSIX-compliant getopt. */ 724 Standalone applications just get a POSIX-compliant getopt.
1150#if _LIBC 725 POSIX and LSB both require these functions to take 'char *const *argv'
1151enum { POSIXLY_CORRECT = 0 }; 726 even though this is incorrect (because of the permutation). */
1152#else 727#define GETOPT_ENTRY(NAME, POSIXLY_CORRECT) \
1153enum { POSIXLY_CORRECT = 1 }; 728 int \
1154#endif 729 NAME (int argc, char *const *argv, const char *optstring) \
1155 730 { \
1156int 731 return _getopt_internal (argc, (char **)argv, optstring, \
1157getopt (int argc, char *const *argv, const char *optstring) 732 0, 0, 0, POSIXLY_CORRECT); \
1158{ 733 }
1159 return _getopt_internal (argc, (char **) argv, optstring,
1160 (const struct option *) 0,
1161 (int *) 0,
1162 0, POSIXLY_CORRECT);
1163}
1164 734
1165#ifdef _LIBC 735#ifdef _LIBC
1166int 736GETOPT_ENTRY(getopt, 0)
1167__posix_getopt (int argc, char *const *argv, const char *optstring) 737GETOPT_ENTRY(__posix_getopt, 1)
1168{ 738#else
1169 return _getopt_internal (argc, argv, optstring, 739GETOPT_ENTRY(getopt, 1)
1170 (const struct option *) 0,
1171 (int *) 0,
1172 0, 1);
1173}
1174#endif 740#endif
1175 741
1176 742
@@ -1191,51 +757,51 @@ main (int argc, char **argv)
1191 757
1192 c = getopt (argc, argv, "abc:d:0123456789"); 758 c = getopt (argc, argv, "abc:d:0123456789");
1193 if (c == -1) 759 if (c == -1)
1194 break; 760 break;
1195 761
1196 switch (c) 762 switch (c)
1197 { 763 {
1198 case '0': 764 case '0':
1199 case '1': 765 case '1':
1200 case '2': 766 case '2':
1201 case '3': 767 case '3':
1202 case '4': 768 case '4':
1203 case '5': 769 case '5':
1204 case '6': 770 case '6':
1205 case '7': 771 case '7':
1206 case '8': 772 case '8':
1207 case '9': 773 case '9':
1208 if (digit_optind != 0 && digit_optind != this_option_optind) 774 if (digit_optind != 0 && digit_optind != this_option_optind)
1209 printf ("digits occur in two different argv-elements.\n"); 775 printf ("digits occur in two different argv-elements.\n");
1210 digit_optind = this_option_optind; 776 digit_optind = this_option_optind;
1211 printf ("option %c\n", c); 777 printf ("option %c\n", c);
1212 break; 778 break;
1213 779
1214 case 'a': 780 case 'a':
1215 printf ("option a\n"); 781 printf ("option a\n");
1216 break; 782 break;
1217 783
1218 case 'b': 784 case 'b':
1219 printf ("option b\n"); 785 printf ("option b\n");
1220 break; 786 break;
1221 787
1222 case 'c': 788 case 'c':
1223 printf ("option c with value '%s'\n", optarg); 789 printf ("option c with value '%s'\n", optarg);
1224 break; 790 break;
1225 791
1226 case '?': 792 case '?':
1227 break; 793 break;
1228 794
1229 default: 795 default:
1230 printf ("?? getopt returned character code 0%o ??\n", c); 796 printf ("?? getopt returned character code 0%o ??\n", c);
1231 } 797 }
1232 } 798 }
1233 799
1234 if (optind < argc) 800 if (optind < argc)
1235 { 801 {
1236 printf ("non-option ARGV-elements: "); 802 printf ("non-option ARGV-elements: ");
1237 while (optind < argc) 803 while (optind < argc)
1238 printf ("%s ", argv[optind++]); 804 printf ("%s ", argv[optind++]);
1239 printf ("\n"); 805 printf ("\n");
1240 } 806 }
1241 807
diff --git a/gl/getopt.in.h b/gl/getopt.in.h
index d9c7d81..0867d36 100644
--- a/gl/getopt.in.h
+++ b/gl/getopt.in.h
@@ -1,20 +1,22 @@
1/* Declarations for getopt. 1/* Declarations for getopt.
2 Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software 2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 Foundation, Inc. 3 This file is part of gnulib.
4 This file is part of the GNU C Library. 4 Unlike most of the getopt implementation, it is NOT shared
5 5 with the GNU C Library, which supplies a different version of
6 This program is free software: you can redistribute it and/or modify 6 this file.
7 it under the terms of the GNU General Public License as published by 7
8 the Free Software Foundation; either version 3 of the License, or 8 This file is free software: you can redistribute it and/or modify
9 (at your option) any later version. 9 it under the terms of the GNU Lesser General Public License as
10 10 published by the Free Software Foundation; either version 2.1 of the
11 This program is distributed in the hope that it will be useful, 11 License, or (at your option) any later version.
12
13 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 16 GNU Lesser General Public License for more details.
15 17
16 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 20
19#ifndef _@GUARD_PREFIX@_GETOPT_H 21#ifndef _@GUARD_PREFIX@_GETOPT_H
20 22
@@ -32,22 +34,15 @@
32# undef _GL_SYSTEM_GETOPT 34# undef _GL_SYSTEM_GETOPT
33#endif 35#endif
34 36
35#ifndef _@GUARD_PREFIX@_GETOPT_H 37#define _@GUARD_PREFIX@_GETOPT_H 1
36
37#ifndef __need_getopt
38# define _@GUARD_PREFIX@_GETOPT_H 1
39#endif
40 38
41/* Standalone applications should #define __GETOPT_PREFIX to an 39/* Standalone applications should #define __GETOPT_PREFIX to an
42 identifier that prefixes the external functions and variables 40 identifier that prefixes the external functions and variables
43 defined in this header. When this happens, include the 41 defined in getopt-core.h and getopt-ext.h. When this happens,
44 headers that might declare getopt so that they will not cause 42 include the headers that might declare getopt so that they will not
45 confusion if included after this file (if the system had <getopt.h>, 43 cause confusion if included after this file (if the system had
46 we have already included it). Then systematically rename 44 <getopt.h>, we have already included it). */
47 identifiers so that they do not collide with the system functions 45#if defined __GETOPT_PREFIX
48 and variables. Renaming avoids problems with some compilers and
49 linkers. */
50#if defined __GETOPT_PREFIX && !defined __need_getopt
51# if !@HAVE_GETOPT_H@ 46# if !@HAVE_GETOPT_H@
52# define __need_system_stdlib_h 47# define __need_system_stdlib_h
53# include <stdlib.h> 48# include <stdlib.h>
@@ -55,201 +50,12 @@
55# include <stdio.h> 50# include <stdio.h>
56# include <unistd.h> 51# include <unistd.h>
57# endif 52# endif
58# undef __need_getopt
59# undef getopt
60# undef getopt_long
61# undef getopt_long_only
62# undef optarg
63# undef opterr
64# undef optind
65# undef optopt
66# undef option
67# define __GETOPT_CONCAT(x, y) x ## y
68# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
69# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
70# define getopt __GETOPT_ID (getopt)
71# define getopt_long __GETOPT_ID (getopt_long)
72# define getopt_long_only __GETOPT_ID (getopt_long_only)
73# define optarg __GETOPT_ID (optarg)
74# define opterr __GETOPT_ID (opterr)
75# define optind __GETOPT_ID (optind)
76# define optopt __GETOPT_ID (optopt)
77# define option __GETOPT_ID (option)
78# define _getopt_internal __GETOPT_ID (getopt_internal)
79#endif
80
81/* Standalone applications get correct prototypes for getopt_long and
82 getopt_long_only; they declare "char **argv". libc uses prototypes
83 with "char *const *argv" that are incorrect because getopt_long and
84 getopt_long_only can permute argv; this is required for backward
85 compatibility (e.g., for LSB 2.0.1).
86
87 This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt',
88 but it caused redefinition warnings if both unistd.h and getopt.h were
89 included, since unistd.h includes getopt.h having previously defined
90 __need_getopt.
91
92 The only place where __getopt_argv_const is used is in definitions
93 of getopt_long and getopt_long_only below, but these are visible
94 only if __need_getopt is not defined, so it is quite safe to rewrite
95 the conditional as follows:
96*/
97#if !defined __need_getopt
98# if defined __GETOPT_PREFIX
99# define __getopt_argv_const /* empty */
100# else
101# define __getopt_argv_const const
102# endif
103#endif
104
105/* If __GNU_LIBRARY__ is not already defined, either we are being used
106 standalone, or this is the first header included in the source file.
107 If we are being used with glibc, we need to include <features.h>, but
108 that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
109 not defined, include <ctype.h>, which will pull in <features.h> for us
110 if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
111 doesn't flood the namespace with stuff the way some other headers do.) */
112#if !defined __GNU_LIBRARY__
113# include <ctype.h>
114#endif
115
116#ifndef __THROW
117# ifndef __GNUC_PREREQ
118# define __GNUC_PREREQ(maj, min) (0)
119# endif
120# if defined __cplusplus && __GNUC_PREREQ (2,8)
121# define __THROW throw ()
122# else
123# define __THROW
124# endif
125#endif 53#endif
126 54
127/* The definition of _GL_ARG_NONNULL is copied here. */ 55/* The definition of _GL_ARG_NONNULL is copied here. */
128 56
129#ifdef __cplusplus 57#include <getopt-cdefs.h>
130extern "C" { 58#include <getopt-pfx-core.h>
131#endif 59#include <getopt-pfx-ext.h>
132
133/* For communication from 'getopt' to the caller.
134 When 'getopt' finds an option that takes an argument,
135 the argument value is returned here.
136 Also, when 'ordering' is RETURN_IN_ORDER,
137 each non-option ARGV-element is returned here. */
138
139extern char *optarg;
140
141/* Index in ARGV of the next element to be scanned.
142 This is used for communication to and from the caller
143 and for communication between successive calls to 'getopt'.
144
145 On entry to 'getopt', zero means this is the first call; initialize.
146
147 When 'getopt' returns -1, this is the index of the first of the
148 non-option elements that the caller should itself scan.
149
150 Otherwise, 'optind' communicates from one call to the next
151 how much of ARGV has been scanned so far. */
152
153extern int optind;
154
155/* Callers store zero here to inhibit the error message 'getopt' prints
156 for unrecognized options. */
157
158extern int opterr;
159 60
160/* Set to an option character which was unrecognized. */
161
162extern int optopt;
163
164#ifndef __need_getopt
165/* Describe the long-named options requested by the application.
166 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
167 of 'struct option' terminated by an element containing a name which is
168 zero.
169
170 The field 'has_arg' is:
171 no_argument (or 0) if the option does not take an argument,
172 required_argument (or 1) if the option requires an argument,
173 optional_argument (or 2) if the option takes an optional argument.
174
175 If the field 'flag' is not NULL, it points to a variable that is set
176 to the value given in the field 'val' when the option is found, but
177 left unchanged if the option is not found.
178
179 To have a long-named option do something other than set an 'int' to
180 a compiled-in constant, such as set a value from 'optarg', set the
181 option's 'flag' field to zero and its 'val' field to a nonzero
182 value (the equivalent single-letter option character, if there is
183 one). For long options that have a zero 'flag' field, 'getopt'
184 returns the contents of the 'val' field. */
185
186# if !GNULIB_defined_struct_option
187struct option
188{
189 const char *name;
190 /* has_arg can't be an enum because some compilers complain about
191 type mismatches in all the code that assumes it is an int. */
192 int has_arg;
193 int *flag;
194 int val;
195};
196# define GNULIB_defined_struct_option 1
197# endif
198
199/* Names for the values of the 'has_arg' field of 'struct option'. */
200
201# define no_argument 0
202# define required_argument 1
203# define optional_argument 2
204#endif /* need getopt */
205
206
207/* Get definitions and prototypes for functions to process the
208 arguments in ARGV (ARGC of them, minus the program name) for
209 options given in OPTS.
210
211 Return the option character from OPTS just read. Return -1 when
212 there are no more options. For unrecognized options, or options
213 missing arguments, 'optopt' is set to the option letter, and '?' is
214 returned.
215
216 The OPTS string is a list of characters which are recognized option
217 letters, optionally followed by colons, specifying that that letter
218 takes an argument, to be placed in 'optarg'.
219
220 If a letter in OPTS is followed by two colons, its argument is
221 optional. This behavior is specific to the GNU 'getopt'.
222
223 The argument '--' causes premature termination of argument
224 scanning, explicitly telling 'getopt' that there are no more
225 options.
226
227 If OPTS begins with '-', then non-option arguments are treated as
228 arguments to the option '\1'. This behavior is specific to the GNU
229 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
230 the environment, then do not permute arguments. */
231
232extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
233 __THROW _GL_ARG_NONNULL ((2, 3));
234
235#ifndef __need_getopt
236extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
237 const char *__shortopts,
238 const struct option *__longopts, int *__longind)
239 __THROW _GL_ARG_NONNULL ((2, 3));
240extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
241 const char *__shortopts,
242 const struct option *__longopts, int *__longind)
243 __THROW _GL_ARG_NONNULL ((2, 3));
244
245#endif
246
247#ifdef __cplusplus
248}
249#endif
250
251/* Make sure we later can get all the definitions and declarations. */
252#undef __need_getopt
253
254#endif /* _@GUARD_PREFIX@_GETOPT_H */
255#endif /* _@GUARD_PREFIX@_GETOPT_H */ 61#endif /* _@GUARD_PREFIX@_GETOPT_H */
diff --git a/gl/getopt1.c b/gl/getopt1.c
index 55a6b4e..49323aa 100644
--- a/gl/getopt1.c
+++ b/gl/getopt1.c
@@ -1,56 +1,44 @@
1/* getopt_long and getopt_long_only entry points for GNU getopt. 1/* getopt_long and getopt_long_only entry points for GNU getopt.
2 Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2013 Free Software 2 Copyright (C) 1987-2023 Free Software Foundation, Inc.
3 Foundation, Inc. 3 This file is part of the GNU C Library and is also part of gnulib.
4 This file is part of the GNU C Library. 4 Patches to this file should be submitted to both projects.
5 5
6 This program is free software: you can redistribute it and/or modify 6 The GNU C Library is free software; you can redistribute it and/or
7 it under the terms of the GNU General Public License as published by 7 modify it under the terms of the GNU Lesser General Public
8 the Free Software Foundation; either version 3 of the License, or 8 License as published by the Free Software Foundation; either
9 (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU
14 GNU General Public License for more details. 14 Lesser 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 Lesser General Public
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
18 19
19#ifdef _LIBC 20#ifndef _LIBC
20# include <getopt.h>
21#else
22# include <config.h> 21# include <config.h>
23# include "getopt.h"
24#endif 22#endif
25#include "getopt_int.h"
26
27#include <stdio.h>
28 23
29/* This needs to come after some library #include 24#include "getopt.h"
30 to get __GNU_LIBRARY__ defined. */ 25#include "getopt_int.h"
31#ifdef __GNU_LIBRARY__
32#include <stdlib.h>
33#endif
34
35#ifndef NULL
36#define NULL 0
37#endif
38 26
39int 27int
40getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, 28getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
41 const struct option *long_options, int *opt_index) 29 const struct option *long_options, int *opt_index)
42{ 30{
43 return _getopt_internal (argc, (char **) argv, options, long_options, 31 return _getopt_internal (argc, (char **) argv, options, long_options,
44 opt_index, 0, 0); 32 opt_index, 0, 0);
45} 33}
46 34
47int 35int
48_getopt_long_r (int argc, char **argv, const char *options, 36_getopt_long_r (int argc, char **argv, const char *options,
49 const struct option *long_options, int *opt_index, 37 const struct option *long_options, int *opt_index,
50 struct _getopt_data *d) 38 struct _getopt_data *d)
51{ 39{
52 return _getopt_internal_r (argc, argv, options, long_options, opt_index, 40 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
53 0, d, 0); 41 0, d, 0);
54} 42}
55 43
56/* Like getopt_long, but '-' as well as '--' can indicate a long option. 44/* Like getopt_long, but '-' as well as '--' can indicate a long option.
@@ -60,26 +48,27 @@ _getopt_long_r (int argc, char **argv, const char *options,
60 48
61int 49int
62getopt_long_only (int argc, char *__getopt_argv_const *argv, 50getopt_long_only (int argc, char *__getopt_argv_const *argv,
63 const char *options, 51 const char *options,
64 const struct option *long_options, int *opt_index) 52 const struct option *long_options, int *opt_index)
65{ 53{
66 return _getopt_internal (argc, (char **) argv, options, long_options, 54 return _getopt_internal (argc, (char **) argv, options, long_options,
67 opt_index, 1, 0); 55 opt_index, 1, 0);
68} 56}
69 57
70int 58int
71_getopt_long_only_r (int argc, char **argv, const char *options, 59_getopt_long_only_r (int argc, char **argv, const char *options,
72 const struct option *long_options, int *opt_index, 60 const struct option *long_options, int *opt_index,
73 struct _getopt_data *d) 61 struct _getopt_data *d)
74{ 62{
75 return _getopt_internal_r (argc, argv, options, long_options, opt_index, 63 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
76 1, d, 0); 64 1, d, 0);
77} 65}
78 66
79 67
80#ifdef TEST 68#ifdef TEST
81 69
82#include <stdio.h> 70#include <stdio.h>
71#include <stdlib.h>
83 72
84int 73int
85main (int argc, char **argv) 74main (int argc, char **argv)
@@ -93,74 +82,74 @@ main (int argc, char **argv)
93 int option_index = 0; 82 int option_index = 0;
94 static const struct option long_options[] = 83 static const struct option long_options[] =
95 { 84 {
96 {"add", 1, 0, 0}, 85 {"add", 1, 0, 0},
97 {"append", 0, 0, 0}, 86 {"append", 0, 0, 0},
98 {"delete", 1, 0, 0}, 87 {"delete", 1, 0, 0},
99 {"verbose", 0, 0, 0}, 88 {"verbose", 0, 0, 0},
100 {"create", 0, 0, 0}, 89 {"create", 0, 0, 0},
101 {"file", 1, 0, 0}, 90 {"file", 1, 0, 0},
102 {0, 0, 0, 0} 91 {0, 0, 0, 0}
103 }; 92 };
104 93
105 c = getopt_long (argc, argv, "abc:d:0123456789", 94 c = getopt_long (argc, argv, "abc:d:0123456789",
106 long_options, &option_index); 95 long_options, &option_index);
107 if (c == -1) 96 if (c == -1)
108 break; 97 break;
109 98
110 switch (c) 99 switch (c)
111 { 100 {
112 case 0: 101 case 0:
113 printf ("option %s", long_options[option_index].name); 102 printf ("option %s", long_options[option_index].name);
114 if (optarg) 103 if (optarg)
115 printf (" with arg %s", optarg); 104 printf (" with arg %s", optarg);
116 printf ("\n"); 105 printf ("\n");
117 break; 106 break;
118 107
119 case '0': 108 case '0':
120 case '1': 109 case '1':
121 case '2': 110 case '2':
122 case '3': 111 case '3':
123 case '4': 112 case '4':
124 case '5': 113 case '5':
125 case '6': 114 case '6':
126 case '7': 115 case '7':
127 case '8': 116 case '8':
128 case '9': 117 case '9':
129 if (digit_optind != 0 && digit_optind != this_option_optind) 118 if (digit_optind != 0 && digit_optind != this_option_optind)
130 printf ("digits occur in two different argv-elements.\n"); 119 printf ("digits occur in two different argv-elements.\n");
131 digit_optind = this_option_optind; 120 digit_optind = this_option_optind;
132 printf ("option %c\n", c); 121 printf ("option %c\n", c);
133 break; 122 break;
134 123
135 case 'a': 124 case 'a':
136 printf ("option a\n"); 125 printf ("option a\n");
137 break; 126 break;
138 127
139 case 'b': 128 case 'b':
140 printf ("option b\n"); 129 printf ("option b\n");
141 break; 130 break;
142 131
143 case 'c': 132 case 'c':
144 printf ("option c with value '%s'\n", optarg); 133 printf ("option c with value '%s'\n", optarg);
145 break; 134 break;
146 135
147 case 'd': 136 case 'd':
148 printf ("option d with value '%s'\n", optarg); 137 printf ("option d with value '%s'\n", optarg);
149 break; 138 break;
150 139
151 case '?': 140 case '?':
152 break; 141 break;
153 142
154 default: 143 default:
155 printf ("?? getopt returned character code 0%o ??\n", c); 144 printf ("?? getopt returned character code 0%o ??\n", c);
156 } 145 }
157 } 146 }
158 147
159 if (optind < argc) 148 if (optind < argc)
160 { 149 {
161 printf ("non-option ARGV-elements: "); 150 printf ("non-option ARGV-elements: ");
162 while (optind < argc) 151 while (optind < argc)
163 printf ("%s ", argv[optind++]); 152 printf ("%s ", argv[optind++]);
164 printf ("\n"); 153 printf ("\n");
165 } 154 }
166 155
diff --git a/gl/getopt_int.h b/gl/getopt_int.h
index a6e4b9e..4d9e24b 100644
--- a/gl/getopt_int.h
+++ b/gl/getopt_int.h
@@ -1,30 +1,31 @@
1/* Internal declarations for getopt. 1/* Internal declarations for getopt.
2 Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2013 Free Software 2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
3 Foundation, Inc. 3 This file is part of the GNU C Library and is also part of gnulib.
4 This file is part of the GNU C Library. 4 Patches to this file should be submitted to both projects.
5 5
6 This program is free software: you can redistribute it and/or modify 6 The GNU C Library is free software; you can redistribute it and/or
7 it under the terms of the GNU General Public License as published by 7 modify it under the terms of the GNU Lesser General Public
8 the Free Software Foundation; either version 3 of the License, or 8 License as published by the Free Software Foundation; either
9 (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU
14 GNU General Public License for more details. 14 Lesser 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 Lesser General Public
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
18 19
19#ifndef _GETOPT_INT_H 20#ifndef _GETOPT_INT_H
20#define _GETOPT_INT_H 1 21#define _GETOPT_INT_H 1
21 22
22#include <getopt.h> 23#include <getopt.h>
23 24
24extern int _getopt_internal (int ___argc, char **___argv, 25extern int _getopt_internal (int ___argc, char **___argv,
25 const char *__shortopts, 26 const char *__shortopts,
26 const struct option *__longopts, int *__longind, 27 const struct option *__longopts, int *__longind,
27 int __long_only, int __posixly_correct); 28 int __long_only, int __posixly_correct);
28 29
29 30
30/* Reentrant versions which can handle parsing multiple argument 31/* Reentrant versions which can handle parsing multiple argument
@@ -32,28 +33,20 @@ extern int _getopt_internal (int ___argc, char **___argv,
32 33
33/* Describe how to deal with options that follow non-option ARGV-elements. 34/* Describe how to deal with options that follow non-option ARGV-elements.
34 35
35 If the caller did not specify anything, 36 REQUIRE_ORDER means don't recognize them as options; stop option
36 the default is REQUIRE_ORDER if the environment variable 37 processing when the first non-option is seen. This is what POSIX
37 POSIXLY_CORRECT is defined, PERMUTE otherwise. 38 specifies should happen.
38 39
39 REQUIRE_ORDER means don't recognize them as options; 40 PERMUTE means permute the contents of ARGV as we scan, so that
40 stop option processing when the first non-option is seen. 41 eventually all the non-options are at the end. This allows options
41 This is what Unix does. 42 to be given in any order, even with programs that were not written
42 This mode of operation is selected by either setting the environment 43 to expect this.
43 variable POSIXLY_CORRECT, or using '+' as the first character
44 of the list of option characters, or by calling getopt.
45
46 PERMUTE is the default. We permute the contents of ARGV as we
47 scan, so that eventually all the non-options are at the end.
48 This allows options to be given in any order, even with programs
49 that were not written to expect this.
50 44
51 RETURN_IN_ORDER is an option available to programs that were 45 RETURN_IN_ORDER is an option available to programs that were
52 written to expect options and other ARGV-elements in any order 46 written to expect options and other ARGV-elements in any order
53 and that care about the ordering of the two. We describe each 47 and that care about the ordering of the two. We describe each
54 non-option ARGV-element as if it were the argument of an option 48 non-option ARGV-element as if it were the argument of an option
55 with character code 1. Using '-' as the first character of the 49 with character code 1.
56 list of option characters selects this mode of operation.
57 50
58 The special argument '--' forces an end of option-scanning regardless 51 The special argument '--' forces an end of option-scanning regardless
59 of the value of 'ordering'. In the case of RETURN_IN_ORDER, only 52 of the value of 'ordering'. In the case of RETURN_IN_ORDER, only
@@ -91,11 +84,6 @@ struct _getopt_data
91 /* See __ord above. */ 84 /* See __ord above. */
92 enum __ord __ordering; 85 enum __ord __ordering;
93 86
94 /* If the POSIXLY_CORRECT environment variable is set
95 or getopt was called. */
96 int __posixly_correct;
97
98
99 /* Handle permutation of arguments. */ 87 /* Handle permutation of arguments. */
100 88
101 /* Describe the part of ARGV that contains non-options that have 89 /* Describe the part of ARGV that contains non-options that have
@@ -104,32 +92,27 @@ struct _getopt_data
104 92
105 int __first_nonopt; 93 int __first_nonopt;
106 int __last_nonopt; 94 int __last_nonopt;
107
108#if defined _LIBC && defined USE_NONOPTION_FLAGS
109 int __nonoption_flags_max_len;
110 int __nonoption_flags_len;
111#endif
112}; 95};
113 96
114/* The initializer is necessary to set OPTIND and OPTERR to their 97/* The initializer is necessary to set OPTIND and OPTERR to their
115 default values and to clear the initialization flag. */ 98 default values and to clear the initialization flag. */
116#define _GETOPT_DATA_INITIALIZER { 1, 1 } 99#define _GETOPT_DATA_INITIALIZER { 1, 1 }
117 100
118extern int _getopt_internal_r (int ___argc, char **___argv, 101extern int _getopt_internal_r (int ___argc, char **___argv,
119 const char *__shortopts, 102 const char *__shortopts,
120 const struct option *__longopts, int *__longind, 103 const struct option *__longopts, int *__longind,
121 int __long_only, struct _getopt_data *__data, 104 int __long_only, struct _getopt_data *__data,
122 int __posixly_correct); 105 int __posixly_correct);
123 106
124extern int _getopt_long_r (int ___argc, char **___argv, 107extern int _getopt_long_r (int ___argc, char **___argv,
125 const char *__shortopts, 108 const char *__shortopts,
126 const struct option *__longopts, int *__longind, 109 const struct option *__longopts, int *__longind,
127 struct _getopt_data *__data); 110 struct _getopt_data *__data);
128 111
129extern int _getopt_long_only_r (int ___argc, char **___argv, 112extern int _getopt_long_only_r (int ___argc, char **___argv,
130 const char *__shortopts, 113 const char *__shortopts,
131 const struct option *__longopts, 114 const struct option *__longopts,
132 int *__longind, 115 int *__longind,
133 struct _getopt_data *__data); 116 struct _getopt_data *__data);
134 117
135#endif /* getopt_int.h */ 118#endif /* getopt_int.h */
diff --git a/gl/getprogname.c b/gl/getprogname.c
new file mode 100644
index 0000000..32c9604
--- /dev/null
+++ b/gl/getprogname.c
@@ -0,0 +1,302 @@
1/* Program name management.
2 Copyright (C) 2016-2023 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 Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include "getprogname.h"
21
22#include <errno.h> /* get program_invocation_name declaration */
23#include <stdlib.h> /* get __argv declaration */
24
25#ifdef _AIX
26# include <unistd.h>
27# include <procinfo.h>
28# include <string.h>
29#endif
30
31#ifdef __MVS__
32# ifndef _OPEN_SYS
33# define _OPEN_SYS
34# endif
35# include <string.h>
36# include <sys/ps.h>
37#endif
38
39#ifdef __hpux
40# include <unistd.h>
41# include <sys/param.h>
42# include <sys/pstat.h>
43# include <string.h>
44#endif
45
46#if defined __sgi || defined __osf__
47# include <string.h>
48# include <unistd.h>
49# include <stdio.h>
50# include <fcntl.h>
51# include <sys/procfs.h>
52#endif
53
54#if defined __SCO_VERSION__ || defined __sysv5__
55# include <fcntl.h>
56# include <stdlib.h>
57# include <string.h>
58#endif
59
60#include "basename-lgpl.h"
61
62#ifndef HAVE_GETPROGNAME /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
63char const *
64getprogname (void)
65{
66# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME /* glibc, BeOS */
67 /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
68 return program_invocation_short_name;
69# elif HAVE_DECL_PROGRAM_INVOCATION_NAME /* glibc, BeOS */
70 /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
71 return last_component (program_invocation_name);
72# elif HAVE_GETEXECNAME /* Solaris */
73 /* https://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrb1/index.html */
74 const char *p = getexecname ();
75 if (!p)
76 p = "?";
77 return last_component (p);
78# elif HAVE_DECL___ARGV /* mingw, MSVC */
79 /* https://docs.microsoft.com/en-us/cpp/c-runtime-library/argc-argv-wargv */
80 const char *p = __argv && __argv[0] ? __argv[0] : "?";
81 return last_component (p);
82# elif HAVE_VAR___PROGNAME /* OpenBSD, Android, QNX */
83 /* https://man.openbsd.org/style.9 */
84 /* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2F__progname.html */
85 /* Be careful to declare this only when we absolutely need it
86 (OpenBSD 5.1), rather than when it's available. Otherwise,
87 its mere declaration makes program_invocation_short_name
88 malfunction (have zero length) with Fedora 25's glibc. */
89 extern char *__progname;
90 const char *p = __progname;
91# if defined __ANDROID__
92 return last_component (p);
93# else
94 return p && p[0] ? p : "?";
95# endif
96# elif _AIX /* AIX */
97 /* Idea by Bastien ROUCARIÈS,
98 https://lists.gnu.org/r/bug-gnulib/2010-12/msg00095.html
99 Reference: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_61/com.ibm.aix.basetrf1/getprocs.htm
100 */
101 static char *p;
102 static int first = 1;
103 if (first)
104 {
105 first = 0;
106 pid_t pid = getpid ();
107 struct procentry64 procs;
108 p = (0 < getprocs64 (&procs, sizeof procs, NULL, 0, &pid, 1)
109 ? strdup (procs.pi_comm)
110 : NULL);
111 if (!p)
112 p = "?";
113 }
114 return p;
115# elif defined __hpux
116 static char *p;
117 static int first = 1;
118 if (first)
119 {
120 first = 0;
121 pid_t pid = getpid ();
122 struct pst_status status;
123 if (pstat_getproc (&status, sizeof status, 0, pid) > 0)
124 {
125 char *ucomm = status.pst_ucomm;
126 char *cmd = status.pst_cmd;
127 if (strlen (ucomm) < PST_UCOMMLEN - 1)
128 p = ucomm;
129 else
130 {
131 /* ucomm is truncated to length PST_UCOMMLEN - 1.
132 Look at cmd instead. */
133 char *space = strchr (cmd, ' ');
134 if (space != NULL)
135 *space = '\0';
136 p = strrchr (cmd, '/');
137 if (p != NULL)
138 p++;
139 else
140 p = cmd;
141 if (strlen (p) > PST_UCOMMLEN - 1
142 && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
143 /* p is less truncated than ucomm. */
144 ;
145 else
146 p = ucomm;
147 }
148 p = strdup (p);
149 }
150 else
151 {
152# if !defined __LP64__
153 /* Support for 32-bit programs running in 64-bit HP-UX.
154 The documented way to do this is to use the same source code
155 as above, but in a compilation unit where '#define _PSTAT64 1'
156 is in effect. I prefer a single compilation unit; the struct
157 size and the offsets are not going to change. */
158 char status64[1216];
159 if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0)
160 {
161 char *ucomm = status64 + 288;
162 char *cmd = status64 + 168;
163 if (strlen (ucomm) < PST_UCOMMLEN - 1)
164 p = ucomm;
165 else
166 {
167 /* ucomm is truncated to length PST_UCOMMLEN - 1.
168 Look at cmd instead. */
169 char *space = strchr (cmd, ' ');
170 if (space != NULL)
171 *space = '\0';
172 p = strrchr (cmd, '/');
173 if (p != NULL)
174 p++;
175 else
176 p = cmd;
177 if (strlen (p) > PST_UCOMMLEN - 1
178 && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
179 /* p is less truncated than ucomm. */
180 ;
181 else
182 p = ucomm;
183 }
184 p = strdup (p);
185 }
186 else
187# endif
188 p = NULL;
189 }
190 if (!p)
191 p = "?";
192 }
193 return p;
194# elif __MVS__ /* z/OS */
195 /* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/rtwgetp.htm */
196 static char *p = "?";
197 static int first = 1;
198 if (first)
199 {
200 pid_t pid = getpid ();
201 int token;
202 W_PSPROC buf;
203 first = 0;
204 memset (&buf, 0, sizeof(buf));
205 buf.ps_cmdptr = (char *) malloc (buf.ps_cmdlen = PS_CMDBLEN_LONG);
206 buf.ps_conttyptr = (char *) malloc (buf.ps_conttylen = PS_CONTTYBLEN);
207 buf.ps_pathptr = (char *) malloc (buf.ps_pathlen = PS_PATHBLEN);
208 if (buf.ps_cmdptr && buf.ps_conttyptr && buf.ps_pathptr)
209 {
210 for (token = 0; token >= 0;
211 token = w_getpsent (token, &buf, sizeof(buf)))
212 {
213 if (token > 0 && buf.ps_pid == pid)
214 {
215 char *s = strdup (last_component (buf.ps_pathptr));
216 if (s)
217 p = s;
218 break;
219 }
220 }
221 }
222 free (buf.ps_cmdptr);
223 free (buf.ps_conttyptr);
224 free (buf.ps_pathptr);
225 }
226 return p;
227# elif defined __sgi || defined __osf__ /* IRIX or Tru64 */
228 char filename[50];
229 int fd;
230
231 # if defined __sgi
232 sprintf (filename, "/proc/pinfo/%d", (int) getpid ());
233 # else
234 sprintf (filename, "/proc/%d", (int) getpid ());
235 # endif
236 fd = open (filename, O_RDONLY | O_CLOEXEC);
237 if (0 <= fd)
238 {
239 prpsinfo_t buf;
240 int ioctl_ok = 0 <= ioctl (fd, PIOCPSINFO, &buf);
241 close (fd);
242 if (ioctl_ok)
243 {
244 char *name = buf.pr_fname;
245 size_t namesize = sizeof buf.pr_fname;
246 /* It may not be NUL-terminated. */
247 char *namenul = memchr (name, '\0', namesize);
248 size_t namelen = namenul ? namenul - name : namesize;
249 char *namecopy = malloc (namelen + 1);
250 if (namecopy)
251 {
252 namecopy[namelen] = '\0';
253 return memcpy (namecopy, name, namelen);
254 }
255 }
256 }
257 return NULL;
258# elif defined __SCO_VERSION__ || defined __sysv5__ /* SCO OpenServer6/UnixWare */
259 char buf[80];
260 int fd;
261 sprintf (buf, "/proc/%d/cmdline", getpid());
262 fd = open (buf, O_RDONLY);
263 if (0 <= fd)
264 {
265 size_t n = read (fd, buf, 79);
266 if (n > 0)
267 {
268 buf[n] = '\0'; /* Guarantee null-termination */
269 char *progname;
270 progname = strrchr (buf, '/');
271 if (progname)
272 {
273 progname = progname + 1; /* Skip the '/' */
274 }
275 else
276 {
277 progname = buf;
278 }
279 char *ret;
280 ret = malloc (strlen (progname) + 1);
281 if (ret)
282 {
283 strcpy (ret, progname);
284 return ret;
285 }
286 }
287 close (fd);
288 }
289 return "?";
290# else
291# error "getprogname module not ported to this OS"
292# endif
293}
294
295#endif
296
297/*
298 * Hey Emacs!
299 * Local Variables:
300 * coding: utf-8
301 * End:
302 */
diff --git a/gl/getprogname.h b/gl/getprogname.h
new file mode 100644
index 0000000..4b9126f
--- /dev/null
+++ b/gl/getprogname.h
@@ -0,0 +1,40 @@
1/* Program name management.
2 Copyright (C) 2016-2023 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 Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#ifndef _GL_GETPROGNAME_H
18#define _GL_GETPROGNAME_H
19
20#include <stdlib.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* Return the base name of the executing program.
27 On native Windows this will usually end in ".exe" or ".EXE". */
28#ifndef HAVE_GETPROGNAME
29extern char const *getprogname (void)
30# ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME
31 _GL_ATTRIBUTE_PURE
32# endif
33 ;
34#endif
35
36#ifdef __cplusplus
37}
38#endif
39
40#endif
diff --git a/gl/gettext.h b/gl/gettext.h
index d021571..d0462c4 100644
--- a/gl/gettext.h
+++ b/gl/gettext.h
@@ -1,25 +1,26 @@
1/* Convenience header for conditional use of GNU <libintl.h>. 1/* Convenience header for conditional use of GNU <libintl.h>.
2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software 2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2023 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _LIBGETTEXT_H 18#ifndef _LIBGETTEXT_H
19#define _LIBGETTEXT_H 1 19#define _LIBGETTEXT_H 1
20 20
21/* NLS can be disabled through the configure --disable-nls option. */ 21/* NLS can be disabled through the configure --disable-nls option
22#if ENABLE_NLS 22 or through "#define ENABLE NLS 0" before including this file. */
23#if defined ENABLE_NLS && ENABLE_NLS
23 24
24/* Get declarations of GNU message catalog functions. */ 25/* Get declarations of GNU message catalog functions. */
25# include <libintl.h> 26# include <libintl.h>
@@ -137,7 +138,7 @@
137#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ 138#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
138 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) 139 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
139 140
140#ifdef __GNUC__ 141#if defined __GNUC__ || defined __clang__
141__inline 142__inline
142#else 143#else
143#ifdef __cplusplus 144#ifdef __cplusplus
@@ -156,7 +157,7 @@ pgettext_aux (const char *domain,
156 return translation; 157 return translation;
157} 158}
158 159
159#ifdef __GNUC__ 160#if defined __GNUC__ || defined __clang__
160__inline 161__inline
161#else 162#else
162#ifdef __cplusplus 163#ifdef __cplusplus
@@ -183,8 +184,15 @@ npgettext_aux (const char *domain,
183 184
184#include <string.h> 185#include <string.h>
185 186
186#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \ 187/* GNULIB_NO_VLA can be defined to disable use of VLAs even if supported.
187 /* || __STDC_VERSION__ >= 199901L */ ) 188 This relates to the -Wvla and -Wvla-larger-than warnings, enabled in
189 the default GCC many warnings set. This allows programs to disable use
190 of VLAs, which may be unintended, or may be awkward to support portably,
191 or may have security implications due to non-deterministic stack usage. */
192
193#if (!defined GNULIB_NO_VLA \
194 && defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
195 && !defined __STDC_NO_VLA__)
188# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 196# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
189#else 197#else
190# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0 198# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
@@ -199,7 +207,7 @@ npgettext_aux (const char *domain,
199#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ 207#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
200 dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) 208 dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
201 209
202#ifdef __GNUC__ 210#if defined __GNUC__ || defined __clang__
203__inline 211__inline
204#else 212#else
205#ifdef __cplusplus 213#ifdef __cplusplus
@@ -225,15 +233,17 @@ dcpgettext_expr (const char *domain,
225 if (msg_ctxt_id != NULL) 233 if (msg_ctxt_id != NULL)
226#endif 234#endif
227 { 235 {
236 int found_translation;
228 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 237 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
229 msg_ctxt_id[msgctxt_len - 1] = '\004'; 238 msg_ctxt_id[msgctxt_len - 1] = '\004';
230 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 239 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
231 translation = dcgettext (domain, msg_ctxt_id, category); 240 translation = dcgettext (domain, msg_ctxt_id, category);
241 found_translation = (translation != msg_ctxt_id);
232#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 242#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
233 if (msg_ctxt_id != buf) 243 if (msg_ctxt_id != buf)
234 free (msg_ctxt_id); 244 free (msg_ctxt_id);
235#endif 245#endif
236 if (translation != msg_ctxt_id) 246 if (found_translation)
237 return translation; 247 return translation;
238 } 248 }
239 return msgid; 249 return msgid;
@@ -244,7 +254,7 @@ dcpgettext_expr (const char *domain,
244#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ 254#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
245 dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) 255 dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
246 256
247#ifdef __GNUC__ 257#if defined __GNUC__ || defined __clang__
248__inline 258__inline
249#else 259#else
250#ifdef __cplusplus 260#ifdef __cplusplus
@@ -271,15 +281,17 @@ dcnpgettext_expr (const char *domain,
271 if (msg_ctxt_id != NULL) 281 if (msg_ctxt_id != NULL)
272#endif 282#endif
273 { 283 {
284 int found_translation;
274 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 285 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
275 msg_ctxt_id[msgctxt_len - 1] = '\004'; 286 msg_ctxt_id[msgctxt_len - 1] = '\004';
276 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 287 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
277 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 288 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
289 found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
278#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 290#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
279 if (msg_ctxt_id != buf) 291 if (msg_ctxt_id != buf)
280 free (msg_ctxt_id); 292 free (msg_ctxt_id);
281#endif 293#endif
282 if (!(translation == msg_ctxt_id || translation == msgid_plural)) 294 if (found_translation)
283 return translation; 295 return translation;
284 } 296 }
285 return (n == 1 ? msgid : msgid_plural); 297 return (n == 1 ? msgid : msgid_plural);
diff --git a/gl/gl_openssl.h b/gl/gl_openssl.h
new file mode 100644
index 0000000..f63c386
--- /dev/null
+++ b/gl/gl_openssl.h
@@ -0,0 +1,116 @@
1/* Wrap openssl crypto hash routines in gnulib interface. -*- coding: utf-8 -*-
2
3 Copyright (C) 2013-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Written by Pádraig Brady */
19
20#ifndef GL_OPENSSL_NAME
21# error "Please define GL_OPENSSL_NAME to 1,5,256 etc."
22#endif
23
24#ifndef _GL_INLINE_HEADER_BEGIN
25# error "Please include config.h first."
26#endif
27_GL_INLINE_HEADER_BEGIN
28#ifndef GL_OPENSSL_INLINE
29# define GL_OPENSSL_INLINE _GL_INLINE
30#endif
31
32/* Concatenate two preprocessor tokens. */
33#define _GLCRYPTO_CONCAT_(prefix, suffix) prefix##suffix
34#define _GLCRYPTO_CONCAT(prefix, suffix) _GLCRYPTO_CONCAT_ (prefix, suffix)
35
36#if GL_OPENSSL_NAME == 5
37# define OPENSSL_ALG md5
38#else
39# define OPENSSL_ALG _GLCRYPTO_CONCAT (sha, GL_OPENSSL_NAME)
40#endif
41
42/* Context type mappings. */
43#if BASE_OPENSSL_TYPE != GL_OPENSSL_NAME
44# undef BASE_OPENSSL_TYPE
45# if GL_OPENSSL_NAME == 224
46# define BASE_OPENSSL_TYPE 256
47# elif GL_OPENSSL_NAME == 384
48# define BASE_OPENSSL_TYPE 512
49# endif
50# define md5_CTX MD5_CTX
51# define sha1_CTX SHA_CTX
52# define sha224_CTX SHA256_CTX
53# define sha224_ctx sha256_ctx
54# define sha256_CTX SHA256_CTX
55# define sha384_CTX SHA512_CTX
56# define sha384_ctx sha512_ctx
57# define sha512_CTX SHA512_CTX
58# undef _gl_CTX
59# undef _gl_ctx
60# define _gl_CTX _GLCRYPTO_CONCAT (OPENSSL_ALG, _CTX) /* openssl type. */
61# define _gl_ctx _GLCRYPTO_CONCAT (OPENSSL_ALG, _ctx) /* gnulib type. */
62
63struct _gl_ctx { _gl_CTX CTX; };
64#endif
65
66/* Function name mappings. */
67#define md5_prefix MD5
68#define sha1_prefix SHA1
69#define sha224_prefix SHA224
70#define sha256_prefix SHA256
71#define sha384_prefix SHA384
72#define sha512_prefix SHA512
73#define _GLCRYPTO_PREFIX _GLCRYPTO_CONCAT (OPENSSL_ALG, _prefix)
74#define OPENSSL_FN(suffix) _GLCRYPTO_CONCAT (_GLCRYPTO_PREFIX, suffix)
75#define GL_CRYPTO_FN(suffix) _GLCRYPTO_CONCAT (OPENSSL_ALG, suffix)
76
77GL_OPENSSL_INLINE void
78GL_CRYPTO_FN (_init_ctx) (struct _gl_ctx *ctx)
79{ (void) OPENSSL_FN (_Init) ((_gl_CTX *) ctx); }
80
81/* These were never exposed by gnulib. */
82#if ! (GL_OPENSSL_NAME == 224 || GL_OPENSSL_NAME == 384)
83GL_OPENSSL_INLINE void
84GL_CRYPTO_FN (_process_bytes) (const void *buf, size_t len, struct _gl_ctx *ctx)
85{ OPENSSL_FN (_Update) ((_gl_CTX *) ctx, buf, len); }
86
87GL_OPENSSL_INLINE void
88GL_CRYPTO_FN (_process_block) (const void *buf, size_t len, struct _gl_ctx *ctx)
89{ GL_CRYPTO_FN (_process_bytes) (buf, len, ctx); }
90#endif
91
92GL_OPENSSL_INLINE void *
93GL_CRYPTO_FN (_finish_ctx) (struct _gl_ctx *ctx, void *restrict res)
94{ OPENSSL_FN (_Final) ((unsigned char *) res, (_gl_CTX *) ctx); return res; }
95
96GL_OPENSSL_INLINE void *
97GL_CRYPTO_FN (_buffer) (const char *buf, size_t len, void *restrict res)
98{ return OPENSSL_FN () ((const unsigned char *) buf, len, (unsigned char *) res); }
99
100GL_OPENSSL_INLINE void *
101GL_CRYPTO_FN (_read_ctx) (const struct _gl_ctx *ctx, void *restrict res)
102{
103 /* Assume any unprocessed bytes in ctx are not to be ignored. */
104 _gl_CTX tmp_ctx = *(_gl_CTX *) ctx;
105 OPENSSL_FN (_Final) ((unsigned char *) res, &tmp_ctx);
106 return res;
107}
108
109/* Undef so we can include multiple times. */
110#undef GL_CRYPTO_FN
111#undef OPENSSL_FN
112#undef _GLCRYPTO_PREFIX
113#undef OPENSSL_ALG
114#undef GL_OPENSSL_NAME
115
116_GL_INLINE_HEADER_END
diff --git a/gl/glthread/lock.c b/gl/glthread/lock.c
index f62aa30..82fb755 100644
--- a/gl/glthread/lock.c
+++ b/gl/glthread/lock.c
@@ -1,22 +1,21 @@
1/* Locking in multithreaded situations. 1/* Locking in multithreaded situations.
2 Copyright (C) 2005-2013 Free Software Foundation, Inc. 2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005. 17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, 18 Based on GCC's gthr-posix.h, gthr-posix95.h. */
19 gthr-win32.h. */
20 19
21#include <config.h> 20#include <config.h>
22 21
@@ -24,15 +23,267 @@
24 23
25/* ========================================================================= */ 24/* ========================================================================= */
26 25
26#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS
27
28/* -------------------------- gl_lock_t datatype -------------------------- */
29
30int
31glthread_lock_init (gl_lock_t *lock)
32{
33 if (mtx_init (&lock->mutex, mtx_plain) != thrd_success)
34 return ENOMEM;
35 lock->init_needed = 0;
36 return 0;
37}
38
39int
40glthread_lock_lock (gl_lock_t *lock)
41{
42 if (lock->init_needed)
43 call_once (&lock->init_once, lock->init_func);
44 if (mtx_lock (&lock->mutex) != thrd_success)
45 return EAGAIN;
46 return 0;
47}
48
49int
50glthread_lock_unlock (gl_lock_t *lock)
51{
52 if (lock->init_needed)
53 call_once (&lock->init_once, lock->init_func);
54 if (mtx_unlock (&lock->mutex) != thrd_success)
55 return EINVAL;
56 return 0;
57}
58
59int
60glthread_lock_destroy (gl_lock_t *lock)
61{
62 if (lock->init_needed)
63 call_once (&lock->init_once, lock->init_func);
64 mtx_destroy (&lock->mutex);
65 return 0;
66}
67
68/* ------------------------- gl_rwlock_t datatype ------------------------- */
69
70int
71glthread_rwlock_init (gl_rwlock_t *lock)
72{
73 if (mtx_init (&lock->lock, mtx_plain) != thrd_success
74 || cnd_init (&lock->waiting_readers) != thrd_success
75 || cnd_init (&lock->waiting_writers) != thrd_success)
76 return ENOMEM;
77 lock->waiting_writers_count = 0;
78 lock->runcount = 0;
79 lock->init_needed = 0;
80 return 0;
81}
82
83int
84glthread_rwlock_rdlock (gl_rwlock_t *lock)
85{
86 if (lock->init_needed)
87 call_once (&lock->init_once, lock->init_func);
88 if (mtx_lock (&lock->lock) != thrd_success)
89 return EAGAIN;
90 /* Test whether only readers are currently running, and whether the runcount
91 field will not overflow, and whether no writer is waiting. The latter
92 condition is because POSIX recommends that "write locks shall take
93 precedence over read locks", to avoid "writer starvation". */
94 while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0))
95 {
96 /* This thread has to wait for a while. Enqueue it among the
97 waiting_readers. */
98 if (cnd_wait (&lock->waiting_readers, &lock->lock) != thrd_success)
99 {
100 mtx_unlock (&lock->lock);
101 return EINVAL;
102 }
103 }
104 lock->runcount++;
105 if (mtx_unlock (&lock->lock) != thrd_success)
106 return EINVAL;
107 return 0;
108}
109
110int
111glthread_rwlock_wrlock (gl_rwlock_t *lock)
112{
113 if (lock->init_needed)
114 call_once (&lock->init_once, lock->init_func);
115 if (mtx_lock (&lock->lock) != thrd_success)
116 return EAGAIN;
117 /* Test whether no readers or writers are currently running. */
118 while (!(lock->runcount == 0))
119 {
120 /* This thread has to wait for a while. Enqueue it among the
121 waiting_writers. */
122 lock->waiting_writers_count++;
123 if (cnd_wait (&lock->waiting_writers, &lock->lock) != thrd_success)
124 {
125 lock->waiting_writers_count--;
126 mtx_unlock (&lock->lock);
127 return EINVAL;
128 }
129 lock->waiting_writers_count--;
130 }
131 lock->runcount--; /* runcount becomes -1 */
132 if (mtx_unlock (&lock->lock) != thrd_success)
133 return EINVAL;
134 return 0;
135}
136
137int
138glthread_rwlock_unlock (gl_rwlock_t *lock)
139{
140 if (lock->init_needed)
141 call_once (&lock->init_once, lock->init_func);
142 if (mtx_lock (&lock->lock) != thrd_success)
143 return EAGAIN;
144 if (lock->runcount < 0)
145 {
146 /* Drop a writer lock. */
147 if (!(lock->runcount == -1))
148 {
149 mtx_unlock (&lock->lock);
150 return EINVAL;
151 }
152 lock->runcount = 0;
153 }
154 else
155 {
156 /* Drop a reader lock. */
157 if (!(lock->runcount > 0))
158 {
159 mtx_unlock (&lock->lock);
160 return EINVAL;
161 }
162 lock->runcount--;
163 }
164 if (lock->runcount == 0)
165 {
166 /* POSIX recommends that "write locks shall take precedence over read
167 locks", to avoid "writer starvation". */
168 if (lock->waiting_writers_count > 0)
169 {
170 /* Wake up one of the waiting writers. */
171 if (cnd_signal (&lock->waiting_writers) != thrd_success)
172 {
173 mtx_unlock (&lock->lock);
174 return EINVAL;
175 }
176 }
177 else
178 {
179 /* Wake up all waiting readers. */
180 if (cnd_broadcast (&lock->waiting_readers) != thrd_success)
181 {
182 mtx_unlock (&lock->lock);
183 return EINVAL;
184 }
185 }
186 }
187 if (mtx_unlock (&lock->lock) != thrd_success)
188 return EINVAL;
189 return 0;
190}
191
192int
193glthread_rwlock_destroy (gl_rwlock_t *lock)
194{
195 if (lock->init_needed)
196 call_once (&lock->init_once, lock->init_func);
197 mtx_destroy (&lock->lock);
198 cnd_destroy (&lock->waiting_readers);
199 cnd_destroy (&lock->waiting_writers);
200 return 0;
201}
202
203/* --------------------- gl_recursive_lock_t datatype --------------------- */
204
205int
206glthread_recursive_lock_init (gl_recursive_lock_t *lock)
207{
208 if (mtx_init (&lock->mutex, mtx_plain | mtx_recursive) != thrd_success)
209 return ENOMEM;
210 lock->init_needed = 0;
211 return 0;
212}
213
214int
215glthread_recursive_lock_lock (gl_recursive_lock_t *lock)
216{
217 if (lock->init_needed)
218 call_once (&lock->init_once, lock->init_func);
219 if (mtx_lock (&lock->mutex) != thrd_success)
220 return EAGAIN;
221 return 0;
222}
223
224int
225glthread_recursive_lock_unlock (gl_recursive_lock_t *lock)
226{
227 if (lock->init_needed)
228 call_once (&lock->init_once, lock->init_func);
229 if (mtx_unlock (&lock->mutex) != thrd_success)
230 return EINVAL;
231 return 0;
232}
233
234int
235glthread_recursive_lock_destroy (gl_recursive_lock_t *lock)
236{
237 if (lock->init_needed)
238 call_once (&lock->init_once, lock->init_func);
239 mtx_destroy (&lock->mutex);
240 return 0;
241}
242
243/* -------------------------- gl_once_t datatype -------------------------- */
244
245#endif
246
247/* ========================================================================= */
248
27#if USE_POSIX_THREADS 249#if USE_POSIX_THREADS
28 250
29/* -------------------------- gl_lock_t datatype -------------------------- */ 251/* -------------------------- gl_lock_t datatype -------------------------- */
30 252
31/* ------------------------- gl_rwlock_t datatype ------------------------- */ 253/* ------------------------- gl_rwlock_t datatype ------------------------- */
32 254
33# if HAVE_PTHREAD_RWLOCK 255# if HAVE_PTHREAD_RWLOCK && (HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER || (defined PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP && (__GNU_LIBRARY__ > 1)))
256
257# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP
258
259# if !HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER
260 /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */
261
262int
263glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock)
264{
265 pthread_rwlockattr_t attributes;
266 int err;
34 267
35# if !defined PTHREAD_RWLOCK_INITIALIZER 268 err = pthread_rwlockattr_init (&attributes);
269 if (err != 0)
270 return err;
271 /* Note: PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is the only value that
272 causes the writer to be preferred. PTHREAD_RWLOCK_PREFER_WRITER_NP does not
273 do this; see
274 http://man7.org/linux/man-pages/man3/pthread_rwlockattr_setkind_np.3.html */
275 err = pthread_rwlockattr_setkind_np (&attributes,
276 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
277 if (err == 0)
278 err = pthread_rwlock_init(lock, &attributes);
279 /* pthread_rwlockattr_destroy always returns 0. It cannot influence the
280 return value. */
281 pthread_rwlockattr_destroy (&attributes);
282 return err;
283}
284
285# endif
286# else
36 287
37int 288int
38glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) 289glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
@@ -152,11 +403,9 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
152 if (err != 0) 403 if (err != 0)
153 return err; 404 return err;
154 /* Test whether only readers are currently running, and whether the runcount 405 /* Test whether only readers are currently running, and whether the runcount
155 field will not overflow. */ 406 field will not overflow, and whether no writer is waiting. The latter
156 /* POSIX says: "It is implementation-defined whether the calling thread 407 condition is because POSIX recommends that "write locks shall take
157 acquires the lock when a writer does not hold the lock and there are 408 precedence over read locks", to avoid "writer starvation". */
158 writers blocked on the lock." Let's say, no: give the writers a higher
159 priority. */
160 while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) 409 while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0))
161 { 410 {
162 /* This thread has to wait for a while. Enqueue it among the 411 /* This thread has to wait for a while. Enqueue it among the
@@ -469,161 +718,25 @@ glthread_once_singlethreaded (pthread_once_t *once_control)
469 return 0; 718 return 0;
470} 719}
471 720
472#endif 721# if !(PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK)
473
474/* ========================================================================= */
475
476#if USE_PTH_THREADS
477
478/* Use the GNU Pth threads library. */
479
480/* -------------------------- gl_lock_t datatype -------------------------- */
481
482/* ------------------------- gl_rwlock_t datatype ------------------------- */
483
484/* --------------------- gl_recursive_lock_t datatype --------------------- */
485
486/* -------------------------- gl_once_t datatype -------------------------- */
487
488static void
489glthread_once_call (void *arg)
490{
491 void (**gl_once_temp_addr) (void) = (void (**) (void)) arg;
492 void (*initfunction) (void) = *gl_once_temp_addr;
493 initfunction ();
494}
495
496int
497glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void))
498{
499 void (*temp) (void) = initfunction;
500 return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0);
501}
502
503int
504glthread_once_singlethreaded (pth_once_t *once_control)
505{
506 /* We know that pth_once_t is an integer type. */
507 if (*once_control == PTH_ONCE_INIT)
508 {
509 /* First time use of once_control. Invert the marker. */
510 *once_control = ~ PTH_ONCE_INIT;
511 return 1;
512 }
513 else
514 return 0;
515}
516
517#endif
518
519/* ========================================================================= */
520
521#if USE_SOLARIS_THREADS
522
523/* Use the old Solaris threads library. */
524
525/* -------------------------- gl_lock_t datatype -------------------------- */
526
527/* ------------------------- gl_rwlock_t datatype ------------------------- */
528
529/* --------------------- gl_recursive_lock_t datatype --------------------- */
530 722
531int 723int
532glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) 724glthread_once_multithreaded (pthread_once_t *once_control,
725 void (*init_function) (void))
533{ 726{
534 int err; 727 int err = pthread_once (once_control, init_function);
535 728 if (err == ENOSYS)
536 err = mutex_init (&lock->mutex, USYNC_THREAD, NULL);
537 if (err != 0)
538 return err;
539 lock->owner = (thread_t) 0;
540 lock->depth = 0;
541 return 0;
542}
543
544int
545glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
546{
547 thread_t self = thr_self ();
548 if (lock->owner != self)
549 { 729 {
550 int err; 730 /* This happens on FreeBSD 11: The pthread_once function in libc returns
551 731 ENOSYS. */
552 err = mutex_lock (&lock->mutex); 732 if (glthread_once_singlethreaded (once_control))
553 if (err != 0) 733 init_function ();
554 return err; 734 return 0;
555 lock->owner = self;
556 } 735 }
557 if (++(lock->depth) == 0) /* wraparound? */ 736 return err;
558 {
559 lock->depth--;
560 return EAGAIN;
561 }
562 return 0;
563} 737}
564 738
565int 739# endif
566glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
567{
568 if (lock->owner != thr_self ())
569 return EPERM;
570 if (lock->depth == 0)
571 return EINVAL;
572 if (--(lock->depth) == 0)
573 {
574 lock->owner = (thread_t) 0;
575 return mutex_unlock (&lock->mutex);
576 }
577 else
578 return 0;
579}
580
581int
582glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
583{
584 if (lock->owner != (thread_t) 0)
585 return EBUSY;
586 return mutex_destroy (&lock->mutex);
587}
588
589/* -------------------------- gl_once_t datatype -------------------------- */
590
591int
592glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void))
593{
594 if (!once_control->inited)
595 {
596 int err;
597
598 /* Use the mutex to guarantee that if another thread is already calling
599 the initfunction, this thread waits until it's finished. */
600 err = mutex_lock (&once_control->mutex);
601 if (err != 0)
602 return err;
603 if (!once_control->inited)
604 {
605 once_control->inited = 1;
606 initfunction ();
607 }
608 return mutex_unlock (&once_control->mutex);
609 }
610 else
611 return 0;
612}
613
614int
615glthread_once_singlethreaded (gl_once_t *once_control)
616{
617 /* We know that gl_once_t contains an integer type. */
618 if (!once_control->inited)
619 {
620 /* First time use of once_control. Invert the marker. */
621 once_control->inited = ~ 0;
622 return 1;
623 }
624 else
625 return 0;
626}
627 740
628#endif 741#endif
629 742
@@ -631,427 +744,6 @@ glthread_once_singlethreaded (gl_once_t *once_control)
631 744
632#if USE_WINDOWS_THREADS 745#if USE_WINDOWS_THREADS
633 746
634/* -------------------------- gl_lock_t datatype -------------------------- */
635
636void
637glthread_lock_init_func (gl_lock_t *lock)
638{
639 InitializeCriticalSection (&lock->lock);
640 lock->guard.done = 1;
641}
642
643int
644glthread_lock_lock_func (gl_lock_t *lock)
645{
646 if (!lock->guard.done)
647 {
648 if (InterlockedIncrement (&lock->guard.started) == 0)
649 /* This thread is the first one to need this lock. Initialize it. */
650 glthread_lock_init (lock);
651 else
652 /* Yield the CPU while waiting for another thread to finish
653 initializing this lock. */
654 while (!lock->guard.done)
655 Sleep (0);
656 }
657 EnterCriticalSection (&lock->lock);
658 return 0;
659}
660
661int
662glthread_lock_unlock_func (gl_lock_t *lock)
663{
664 if (!lock->guard.done)
665 return EINVAL;
666 LeaveCriticalSection (&lock->lock);
667 return 0;
668}
669
670int
671glthread_lock_destroy_func (gl_lock_t *lock)
672{
673 if (!lock->guard.done)
674 return EINVAL;
675 DeleteCriticalSection (&lock->lock);
676 lock->guard.done = 0;
677 return 0;
678}
679
680/* ------------------------- gl_rwlock_t datatype ------------------------- */
681
682/* In this file, the waitqueues are implemented as circular arrays. */
683#define gl_waitqueue_t gl_carray_waitqueue_t
684
685static void
686gl_waitqueue_init (gl_waitqueue_t *wq)
687{
688 wq->array = NULL;
689 wq->count = 0;
690 wq->alloc = 0;
691 wq->offset = 0;
692}
693
694/* Enqueues the current thread, represented by an event, in a wait queue.
695 Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */
696static HANDLE
697gl_waitqueue_add (gl_waitqueue_t *wq)
698{
699 HANDLE event;
700 unsigned int index;
701
702 if (wq->count == wq->alloc)
703 {
704 unsigned int new_alloc = 2 * wq->alloc + 1;
705 HANDLE *new_array =
706 (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE));
707 if (new_array == NULL)
708 /* No more memory. */
709 return INVALID_HANDLE_VALUE;
710 /* Now is a good opportunity to rotate the array so that its contents
711 starts at offset 0. */
712 if (wq->offset > 0)
713 {
714 unsigned int old_count = wq->count;
715 unsigned int old_alloc = wq->alloc;
716 unsigned int old_offset = wq->offset;
717 unsigned int i;
718 if (old_offset + old_count > old_alloc)
719 {
720 unsigned int limit = old_offset + old_count - old_alloc;
721 for (i = 0; i < limit; i++)
722 new_array[old_alloc + i] = new_array[i];
723 }
724 for (i = 0; i < old_count; i++)
725 new_array[i] = new_array[old_offset + i];
726 wq->offset = 0;
727 }
728 wq->array = new_array;
729 wq->alloc = new_alloc;
730 }
731 /* Whether the created event is a manual-reset one or an auto-reset one,
732 does not matter, since we will wait on it only once. */
733 event = CreateEvent (NULL, TRUE, FALSE, NULL);
734 if (event == INVALID_HANDLE_VALUE)
735 /* No way to allocate an event. */
736 return INVALID_HANDLE_VALUE;
737 index = wq->offset + wq->count;
738 if (index >= wq->alloc)
739 index -= wq->alloc;
740 wq->array[index] = event;
741 wq->count++;
742 return event;
743}
744
745/* Notifies the first thread from a wait queue and dequeues it. */
746static void
747gl_waitqueue_notify_first (gl_waitqueue_t *wq)
748{
749 SetEvent (wq->array[wq->offset + 0]);
750 wq->offset++;
751 wq->count--;
752 if (wq->count == 0 || wq->offset == wq->alloc)
753 wq->offset = 0;
754}
755
756/* Notifies all threads from a wait queue and dequeues them all. */
757static void
758gl_waitqueue_notify_all (gl_waitqueue_t *wq)
759{
760 unsigned int i;
761
762 for (i = 0; i < wq->count; i++)
763 {
764 unsigned int index = wq->offset + i;
765 if (index >= wq->alloc)
766 index -= wq->alloc;
767 SetEvent (wq->array[index]);
768 }
769 wq->count = 0;
770 wq->offset = 0;
771}
772
773void
774glthread_rwlock_init_func (gl_rwlock_t *lock)
775{
776 InitializeCriticalSection (&lock->lock);
777 gl_waitqueue_init (&lock->waiting_readers);
778 gl_waitqueue_init (&lock->waiting_writers);
779 lock->runcount = 0;
780 lock->guard.done = 1;
781}
782
783int
784glthread_rwlock_rdlock_func (gl_rwlock_t *lock)
785{
786 if (!lock->guard.done)
787 {
788 if (InterlockedIncrement (&lock->guard.started) == 0)
789 /* This thread is the first one to need this lock. Initialize it. */
790 glthread_rwlock_init (lock);
791 else
792 /* Yield the CPU while waiting for another thread to finish
793 initializing this lock. */
794 while (!lock->guard.done)
795 Sleep (0);
796 }
797 EnterCriticalSection (&lock->lock);
798 /* Test whether only readers are currently running, and whether the runcount
799 field will not overflow. */
800 if (!(lock->runcount + 1 > 0))
801 {
802 /* This thread has to wait for a while. Enqueue it among the
803 waiting_readers. */
804 HANDLE event = gl_waitqueue_add (&lock->waiting_readers);
805 if (event != INVALID_HANDLE_VALUE)
806 {
807 DWORD result;
808 LeaveCriticalSection (&lock->lock);
809 /* Wait until another thread signals this event. */
810 result = WaitForSingleObject (event, INFINITE);
811 if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
812 abort ();
813 CloseHandle (event);
814 /* The thread which signalled the event already did the bookkeeping:
815 removed us from the waiting_readers, incremented lock->runcount. */
816 if (!(lock->runcount > 0))
817 abort ();
818 return 0;
819 }
820 else
821 {
822 /* Allocation failure. Weird. */
823 do
824 {
825 LeaveCriticalSection (&lock->lock);
826 Sleep (1);
827 EnterCriticalSection (&lock->lock);
828 }
829 while (!(lock->runcount + 1 > 0));
830 }
831 }
832 lock->runcount++;
833 LeaveCriticalSection (&lock->lock);
834 return 0;
835}
836
837int
838glthread_rwlock_wrlock_func (gl_rwlock_t *lock)
839{
840 if (!lock->guard.done)
841 {
842 if (InterlockedIncrement (&lock->guard.started) == 0)
843 /* This thread is the first one to need this lock. Initialize it. */
844 glthread_rwlock_init (lock);
845 else
846 /* Yield the CPU while waiting for another thread to finish
847 initializing this lock. */
848 while (!lock->guard.done)
849 Sleep (0);
850 }
851 EnterCriticalSection (&lock->lock);
852 /* Test whether no readers or writers are currently running. */
853 if (!(lock->runcount == 0))
854 {
855 /* This thread has to wait for a while. Enqueue it among the
856 waiting_writers. */
857 HANDLE event = gl_waitqueue_add (&lock->waiting_writers);
858 if (event != INVALID_HANDLE_VALUE)
859 {
860 DWORD result;
861 LeaveCriticalSection (&lock->lock);
862 /* Wait until another thread signals this event. */
863 result = WaitForSingleObject (event, INFINITE);
864 if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
865 abort ();
866 CloseHandle (event);
867 /* The thread which signalled the event already did the bookkeeping:
868 removed us from the waiting_writers, set lock->runcount = -1. */
869 if (!(lock->runcount == -1))
870 abort ();
871 return 0;
872 }
873 else
874 {
875 /* Allocation failure. Weird. */
876 do
877 {
878 LeaveCriticalSection (&lock->lock);
879 Sleep (1);
880 EnterCriticalSection (&lock->lock);
881 }
882 while (!(lock->runcount == 0));
883 }
884 }
885 lock->runcount--; /* runcount becomes -1 */
886 LeaveCriticalSection (&lock->lock);
887 return 0;
888}
889
890int
891glthread_rwlock_unlock_func (gl_rwlock_t *lock)
892{
893 if (!lock->guard.done)
894 return EINVAL;
895 EnterCriticalSection (&lock->lock);
896 if (lock->runcount < 0)
897 {
898 /* Drop a writer lock. */
899 if (!(lock->runcount == -1))
900 abort ();
901 lock->runcount = 0;
902 }
903 else
904 {
905 /* Drop a reader lock. */
906 if (!(lock->runcount > 0))
907 {
908 LeaveCriticalSection (&lock->lock);
909 return EPERM;
910 }
911 lock->runcount--;
912 }
913 if (lock->runcount == 0)
914 {
915 /* POSIX recommends that "write locks shall take precedence over read
916 locks", to avoid "writer starvation". */
917 if (lock->waiting_writers.count > 0)
918 {
919 /* Wake up one of the waiting writers. */
920 lock->runcount--;
921 gl_waitqueue_notify_first (&lock->waiting_writers);
922 }
923 else
924 {
925 /* Wake up all waiting readers. */
926 lock->runcount += lock->waiting_readers.count;
927 gl_waitqueue_notify_all (&lock->waiting_readers);
928 }
929 }
930 LeaveCriticalSection (&lock->lock);
931 return 0;
932}
933
934int
935glthread_rwlock_destroy_func (gl_rwlock_t *lock)
936{
937 if (!lock->guard.done)
938 return EINVAL;
939 if (lock->runcount != 0)
940 return EBUSY;
941 DeleteCriticalSection (&lock->lock);
942 if (lock->waiting_readers.array != NULL)
943 free (lock->waiting_readers.array);
944 if (lock->waiting_writers.array != NULL)
945 free (lock->waiting_writers.array);
946 lock->guard.done = 0;
947 return 0;
948}
949
950/* --------------------- gl_recursive_lock_t datatype --------------------- */
951
952void
953glthread_recursive_lock_init_func (gl_recursive_lock_t *lock)
954{
955 lock->owner = 0;
956 lock->depth = 0;
957 InitializeCriticalSection (&lock->lock);
958 lock->guard.done = 1;
959}
960
961int
962glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock)
963{
964 if (!lock->guard.done)
965 {
966 if (InterlockedIncrement (&lock->guard.started) == 0)
967 /* This thread is the first one to need this lock. Initialize it. */
968 glthread_recursive_lock_init (lock);
969 else
970 /* Yield the CPU while waiting for another thread to finish
971 initializing this lock. */
972 while (!lock->guard.done)
973 Sleep (0);
974 }
975 {
976 DWORD self = GetCurrentThreadId ();
977 if (lock->owner != self)
978 {
979 EnterCriticalSection (&lock->lock);
980 lock->owner = self;
981 }
982 if (++(lock->depth) == 0) /* wraparound? */
983 {
984 lock->depth--;
985 return EAGAIN;
986 }
987 }
988 return 0;
989}
990
991int
992glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock)
993{
994 if (lock->owner != GetCurrentThreadId ())
995 return EPERM;
996 if (lock->depth == 0)
997 return EINVAL;
998 if (--(lock->depth) == 0)
999 {
1000 lock->owner = 0;
1001 LeaveCriticalSection (&lock->lock);
1002 }
1003 return 0;
1004}
1005
1006int
1007glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock)
1008{
1009 if (lock->owner != 0)
1010 return EBUSY;
1011 DeleteCriticalSection (&lock->lock);
1012 lock->guard.done = 0;
1013 return 0;
1014}
1015
1016/* -------------------------- gl_once_t datatype -------------------------- */
1017
1018void
1019glthread_once_func (gl_once_t *once_control, void (*initfunction) (void))
1020{
1021 if (once_control->inited <= 0)
1022 {
1023 if (InterlockedIncrement (&once_control->started) == 0)
1024 {
1025 /* This thread is the first one to come to this once_control. */
1026 InitializeCriticalSection (&once_control->lock);
1027 EnterCriticalSection (&once_control->lock);
1028 once_control->inited = 0;
1029 initfunction ();
1030 once_control->inited = 1;
1031 LeaveCriticalSection (&once_control->lock);
1032 }
1033 else
1034 {
1035 /* Undo last operation. */
1036 InterlockedDecrement (&once_control->started);
1037 /* Some other thread has already started the initialization.
1038 Yield the CPU while waiting for the other thread to finish
1039 initializing and taking the lock. */
1040 while (once_control->inited < 0)
1041 Sleep (0);
1042 if (once_control->inited <= 0)
1043 {
1044 /* Take the lock. This blocks until the other thread has
1045 finished calling the initfunction. */
1046 EnterCriticalSection (&once_control->lock);
1047 LeaveCriticalSection (&once_control->lock);
1048 if (!(once_control->inited > 0))
1049 abort ();
1050 }
1051 }
1052 }
1053}
1054
1055#endif 747#endif
1056 748
1057/* ========================================================================= */ 749/* ========================================================================= */
diff --git a/gl/glthread/lock.h b/gl/glthread/lock.h
index d20bbde..ae3ee2d 100644
--- a/gl/glthread/lock.h
+++ b/gl/glthread/lock.h
@@ -1,22 +1,21 @@
1/* Locking in multithreaded situations. 1/* Locking in multithreaded situations.
2 Copyright (C) 2005-2013 Free Software Foundation, Inc. 2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005. 17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, 18 Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-win32.h. */
19 gthr-win32.h. */
20 19
21/* This file contains locking primitives for use with a given thread library. 20/* This file contains locking primitives for use with a given thread library.
22 It does not contain primitives for creating threads or for other 21 It does not contain primitives for creating threads or for other
@@ -81,6 +80,127 @@
81#include <errno.h> 80#include <errno.h>
82#include <stdlib.h> 81#include <stdlib.h>
83 82
83#if !defined c11_threads_in_use
84# if HAVE_THREADS_H && USE_POSIX_THREADS_FROM_LIBC
85# define c11_threads_in_use() 1
86# elif HAVE_THREADS_H && USE_POSIX_THREADS_WEAK
87# include <threads.h>
88# pragma weak thrd_exit
89# define c11_threads_in_use() (thrd_exit != NULL)
90# else
91# define c11_threads_in_use() 0
92# endif
93#endif
94
95/* ========================================================================= */
96
97#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS
98
99/* Use the ISO C threads library. */
100
101# include <threads.h>
102
103# ifdef __cplusplus
104extern "C" {
105# endif
106
107/* -------------------------- gl_lock_t datatype -------------------------- */
108
109typedef struct
110 {
111 int volatile init_needed;
112 once_flag init_once;
113 void (*init_func) (void);
114 mtx_t mutex;
115 }
116 gl_lock_t;
117# define gl_lock_define(STORAGECLASS, NAME) \
118 STORAGECLASS gl_lock_t NAME;
119# define gl_lock_define_initialized(STORAGECLASS, NAME) \
120 static void _atomic_init_##NAME (void); \
121 STORAGECLASS gl_lock_t NAME = \
122 { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \
123 static void _atomic_init_##NAME (void) \
124 { \
125 if (glthread_lock_init (&(NAME))) \
126 abort (); \
127 }
128extern int glthread_lock_init (gl_lock_t *lock);
129extern int glthread_lock_lock (gl_lock_t *lock);
130extern int glthread_lock_unlock (gl_lock_t *lock);
131extern int glthread_lock_destroy (gl_lock_t *lock);
132
133/* ------------------------- gl_rwlock_t datatype ------------------------- */
134
135typedef struct
136 {
137 int volatile init_needed;
138 once_flag init_once;
139 void (*init_func) (void);
140 mtx_t lock; /* protects the remaining fields */
141 cnd_t waiting_readers; /* waiting readers */
142 cnd_t waiting_writers; /* waiting writers */
143 unsigned int waiting_writers_count; /* number of waiting writers */
144 int runcount; /* number of readers running, or -1 when a writer runs */
145 }
146 gl_rwlock_t;
147# define gl_rwlock_define(STORAGECLASS, NAME) \
148 STORAGECLASS gl_rwlock_t NAME;
149# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
150 static void _atomic_init_##NAME (void); \
151 STORAGECLASS gl_rwlock_t NAME = \
152 { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \
153 static void _atomic_init_##NAME (void) \
154 { \
155 if (glthread_rwlock_init (&(NAME))) \
156 abort (); \
157 }
158extern int glthread_rwlock_init (gl_rwlock_t *lock);
159extern int glthread_rwlock_rdlock (gl_rwlock_t *lock);
160extern int glthread_rwlock_wrlock (gl_rwlock_t *lock);
161extern int glthread_rwlock_unlock (gl_rwlock_t *lock);
162extern int glthread_rwlock_destroy (gl_rwlock_t *lock);
163
164/* --------------------- gl_recursive_lock_t datatype --------------------- */
165
166typedef struct
167 {
168 int volatile init_needed;
169 once_flag init_once;
170 void (*init_func) (void);
171 mtx_t mutex;
172 }
173 gl_recursive_lock_t;
174# define gl_recursive_lock_define(STORAGECLASS, NAME) \
175 STORAGECLASS gl_recursive_lock_t NAME;
176# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
177 static void _atomic_init_##NAME (void); \
178 STORAGECLASS gl_recursive_lock_t NAME = \
179 { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \
180 static void _atomic_init_##NAME (void) \
181 { \
182 if (glthread_recursive_lock_init (&(NAME))) \
183 abort (); \
184 }
185extern int glthread_recursive_lock_init (gl_recursive_lock_t *lock);
186extern int glthread_recursive_lock_lock (gl_recursive_lock_t *lock);
187extern int glthread_recursive_lock_unlock (gl_recursive_lock_t *lock);
188extern int glthread_recursive_lock_destroy (gl_recursive_lock_t *lock);
189
190/* -------------------------- gl_once_t datatype -------------------------- */
191
192typedef once_flag gl_once_t;
193# define gl_once_define(STORAGECLASS, NAME) \
194 STORAGECLASS once_flag NAME = ONCE_FLAG_INIT;
195# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
196 (call_once (ONCE_CONTROL, INITFUNCTION), 0)
197
198# ifdef __cplusplus
199}
200# endif
201
202#endif
203
84/* ========================================================================= */ 204/* ========================================================================= */
85 205
86#if USE_POSIX_THREADS 206#if USE_POSIX_THREADS
@@ -139,13 +259,25 @@ extern int glthread_in_use (void);
139# pragma weak pthread_mutexattr_init 259# pragma weak pthread_mutexattr_init
140# pragma weak pthread_mutexattr_settype 260# pragma weak pthread_mutexattr_settype
141# pragma weak pthread_mutexattr_destroy 261# pragma weak pthread_mutexattr_destroy
262# pragma weak pthread_rwlockattr_init
263# if __GNU_LIBRARY__ > 1
264# pragma weak pthread_rwlockattr_setkind_np
265# endif
266# pragma weak pthread_rwlockattr_destroy
142# ifndef pthread_self 267# ifndef pthread_self
143# pragma weak pthread_self 268# pragma weak pthread_self
144# endif 269# endif
145 270
146# if !PTHREAD_IN_USE_DETECTION_HARD 271# if !PTHREAD_IN_USE_DETECTION_HARD
147# pragma weak pthread_cancel 272 /* Considering all platforms with USE_POSIX_THREADS_WEAK, only few symbols
148# define pthread_in_use() (pthread_cancel != NULL) 273 can be used to determine whether libpthread is in use. These are:
274 pthread_mutexattr_gettype
275 pthread_rwlockattr_destroy
276 pthread_rwlockattr_init
277 */
278# pragma weak pthread_mutexattr_gettype
279# define pthread_in_use() \
280 (pthread_mutexattr_gettype != NULL || c11_threads_in_use ())
149# endif 281# endif
150 282
151# else 283# else
@@ -176,19 +308,32 @@ typedef pthread_mutex_t gl_lock_t;
176 308
177/* ------------------------- gl_rwlock_t datatype ------------------------- */ 309/* ------------------------- gl_rwlock_t datatype ------------------------- */
178 310
179# if HAVE_PTHREAD_RWLOCK 311# if HAVE_PTHREAD_RWLOCK && (HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER || (defined PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP && (__GNU_LIBRARY__ > 1)))
180 312
181# ifdef PTHREAD_RWLOCK_INITIALIZER 313# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP
182 314
183typedef pthread_rwlock_t gl_rwlock_t; 315typedef pthread_rwlock_t gl_rwlock_t;
184# define gl_rwlock_define(STORAGECLASS, NAME) \ 316# define gl_rwlock_define(STORAGECLASS, NAME) \
185 STORAGECLASS pthread_rwlock_t NAME; 317 STORAGECLASS pthread_rwlock_t NAME;
186# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ 318# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
187 STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer; 319 STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer;
188# define gl_rwlock_initializer \ 320# if HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER
189 PTHREAD_RWLOCK_INITIALIZER 321# if defined PTHREAD_RWLOCK_INITIALIZER
190# define glthread_rwlock_init(LOCK) \ 322# define gl_rwlock_initializer \
191 (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0) 323 PTHREAD_RWLOCK_INITIALIZER
324# else
325# define gl_rwlock_initializer \
326 PTHREAD_RWLOCK_INITIALIZER_NP
327# endif
328# define glthread_rwlock_init(LOCK) \
329 (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0)
330# else /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */
331# define gl_rwlock_initializer \
332 PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP
333# define glthread_rwlock_init(LOCK) \
334 (pthread_in_use () ? glthread_rwlock_init_for_glibc (LOCK) : 0)
335extern int glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock);
336# endif
192# define glthread_rwlock_rdlock(LOCK) \ 337# define glthread_rwlock_rdlock(LOCK) \
193 (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0) 338 (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0)
194# define glthread_rwlock_wrlock(LOCK) \ 339# define glthread_rwlock_wrlock(LOCK) \
@@ -362,248 +507,20 @@ extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *l
362typedef pthread_once_t gl_once_t; 507typedef pthread_once_t gl_once_t;
363# define gl_once_define(STORAGECLASS, NAME) \ 508# define gl_once_define(STORAGECLASS, NAME) \
364 STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT; 509 STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
365# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ 510# if PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK
366 (pthread_in_use () \ 511# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
367 ? pthread_once (ONCE_CONTROL, INITFUNCTION) \ 512 (pthread_in_use () \
368 : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) 513 ? pthread_once (ONCE_CONTROL, INITFUNCTION) \
369extern int glthread_once_singlethreaded (pthread_once_t *once_control); 514 : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
370
371# ifdef __cplusplus
372}
373# endif
374
375#endif
376
377/* ========================================================================= */
378
379#if USE_PTH_THREADS
380
381/* Use the GNU Pth threads library. */
382
383# include <pth.h>
384
385# ifdef __cplusplus
386extern "C" {
387# endif
388
389# if USE_PTH_THREADS_WEAK
390
391/* Use weak references to the GNU Pth threads library. */
392
393# pragma weak pth_mutex_init
394# pragma weak pth_mutex_acquire
395# pragma weak pth_mutex_release
396# pragma weak pth_rwlock_init
397# pragma weak pth_rwlock_acquire
398# pragma weak pth_rwlock_release
399# pragma weak pth_once
400
401# pragma weak pth_cancel
402# define pth_in_use() (pth_cancel != NULL)
403
404# else 515# else
405 516# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
406# define pth_in_use() 1 517 (pthread_in_use () \
407 518 ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
519 : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
520extern int glthread_once_multithreaded (pthread_once_t *once_control,
521 void (*init_function) (void));
408# endif 522# endif
409 523extern int glthread_once_singlethreaded (pthread_once_t *once_control);
410/* -------------------------- gl_lock_t datatype -------------------------- */
411
412typedef pth_mutex_t gl_lock_t;
413# define gl_lock_define(STORAGECLASS, NAME) \
414 STORAGECLASS pth_mutex_t NAME;
415# define gl_lock_define_initialized(STORAGECLASS, NAME) \
416 STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;
417# define gl_lock_initializer \
418 PTH_MUTEX_INIT
419# define glthread_lock_init(LOCK) \
420 (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
421# define glthread_lock_lock(LOCK) \
422 (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
423# define glthread_lock_unlock(LOCK) \
424 (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
425# define glthread_lock_destroy(LOCK) \
426 ((void)(LOCK), 0)
427
428/* ------------------------- gl_rwlock_t datatype ------------------------- */
429
430typedef pth_rwlock_t gl_rwlock_t;
431# define gl_rwlock_define(STORAGECLASS, NAME) \
432 STORAGECLASS pth_rwlock_t NAME;
433# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
434 STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;
435# define gl_rwlock_initializer \
436 PTH_RWLOCK_INIT
437# define glthread_rwlock_init(LOCK) \
438 (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0)
439# define glthread_rwlock_rdlock(LOCK) \
440 (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? errno : 0)
441# define glthread_rwlock_wrlock(LOCK) \
442 (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? errno : 0)
443# define glthread_rwlock_unlock(LOCK) \
444 (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0)
445# define glthread_rwlock_destroy(LOCK) \
446 ((void)(LOCK), 0)
447
448/* --------------------- gl_recursive_lock_t datatype --------------------- */
449
450/* In Pth, mutexes are recursive by default. */
451typedef pth_mutex_t gl_recursive_lock_t;
452# define gl_recursive_lock_define(STORAGECLASS, NAME) \
453 STORAGECLASS pth_mutex_t NAME;
454# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
455 STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;
456# define gl_recursive_lock_initializer \
457 PTH_MUTEX_INIT
458# define glthread_recursive_lock_init(LOCK) \
459 (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
460# define glthread_recursive_lock_lock(LOCK) \
461 (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
462# define glthread_recursive_lock_unlock(LOCK) \
463 (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
464# define glthread_recursive_lock_destroy(LOCK) \
465 ((void)(LOCK), 0)
466
467/* -------------------------- gl_once_t datatype -------------------------- */
468
469typedef pth_once_t gl_once_t;
470# define gl_once_define(STORAGECLASS, NAME) \
471 STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;
472# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
473 (pth_in_use () \
474 ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
475 : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
476extern int glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void));
477extern int glthread_once_singlethreaded (pth_once_t *once_control);
478
479# ifdef __cplusplus
480}
481# endif
482
483#endif
484
485/* ========================================================================= */
486
487#if USE_SOLARIS_THREADS
488
489/* Use the old Solaris threads library. */
490
491# include <thread.h>
492# include <synch.h>
493
494# ifdef __cplusplus
495extern "C" {
496# endif
497
498# if USE_SOLARIS_THREADS_WEAK
499
500/* Use weak references to the old Solaris threads library. */
501
502# pragma weak mutex_init
503# pragma weak mutex_lock
504# pragma weak mutex_unlock
505# pragma weak mutex_destroy
506# pragma weak rwlock_init
507# pragma weak rw_rdlock
508# pragma weak rw_wrlock
509# pragma weak rw_unlock
510# pragma weak rwlock_destroy
511# pragma weak thr_self
512
513# pragma weak thr_suspend
514# define thread_in_use() (thr_suspend != NULL)
515
516# else
517
518# define thread_in_use() 1
519
520# endif
521
522/* -------------------------- gl_lock_t datatype -------------------------- */
523
524typedef mutex_t gl_lock_t;
525# define gl_lock_define(STORAGECLASS, NAME) \
526 STORAGECLASS mutex_t NAME;
527# define gl_lock_define_initialized(STORAGECLASS, NAME) \
528 STORAGECLASS mutex_t NAME = gl_lock_initializer;
529# define gl_lock_initializer \
530 DEFAULTMUTEX
531# define glthread_lock_init(LOCK) \
532 (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0)
533# define glthread_lock_lock(LOCK) \
534 (thread_in_use () ? mutex_lock (LOCK) : 0)
535# define glthread_lock_unlock(LOCK) \
536 (thread_in_use () ? mutex_unlock (LOCK) : 0)
537# define glthread_lock_destroy(LOCK) \
538 (thread_in_use () ? mutex_destroy (LOCK) : 0)
539
540/* ------------------------- gl_rwlock_t datatype ------------------------- */
541
542typedef rwlock_t gl_rwlock_t;
543# define gl_rwlock_define(STORAGECLASS, NAME) \
544 STORAGECLASS rwlock_t NAME;
545# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
546 STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;
547# define gl_rwlock_initializer \
548 DEFAULTRWLOCK
549# define glthread_rwlock_init(LOCK) \
550 (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0)
551# define glthread_rwlock_rdlock(LOCK) \
552 (thread_in_use () ? rw_rdlock (LOCK) : 0)
553# define glthread_rwlock_wrlock(LOCK) \
554 (thread_in_use () ? rw_wrlock (LOCK) : 0)
555# define glthread_rwlock_unlock(LOCK) \
556 (thread_in_use () ? rw_unlock (LOCK) : 0)
557# define glthread_rwlock_destroy(LOCK) \
558 (thread_in_use () ? rwlock_destroy (LOCK) : 0)
559
560/* --------------------- gl_recursive_lock_t datatype --------------------- */
561
562/* Old Solaris threads did not have recursive locks.
563 We have to implement them ourselves. */
564
565typedef struct
566 {
567 mutex_t mutex;
568 thread_t owner;
569 unsigned long depth;
570 }
571 gl_recursive_lock_t;
572# define gl_recursive_lock_define(STORAGECLASS, NAME) \
573 STORAGECLASS gl_recursive_lock_t NAME;
574# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
575 STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
576# define gl_recursive_lock_initializer \
577 { DEFAULTMUTEX, (thread_t) 0, 0 }
578# define glthread_recursive_lock_init(LOCK) \
579 (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
580# define glthread_recursive_lock_lock(LOCK) \
581 (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
582# define glthread_recursive_lock_unlock(LOCK) \
583 (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
584# define glthread_recursive_lock_destroy(LOCK) \
585 (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
586extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
587extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
588extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
589extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
590
591/* -------------------------- gl_once_t datatype -------------------------- */
592
593typedef struct
594 {
595 volatile int inited;
596 mutex_t mutex;
597 }
598 gl_once_t;
599# define gl_once_define(STORAGECLASS, NAME) \
600 STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX };
601# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
602 (thread_in_use () \
603 ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
604 : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
605extern int glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void));
606extern int glthread_once_singlethreaded (gl_once_t *once_control);
607 524
608# ifdef __cplusplus 525# ifdef __cplusplus
609} 526}
@@ -618,6 +535,11 @@ extern int glthread_once_singlethreaded (gl_once_t *once_control);
618# define WIN32_LEAN_AND_MEAN /* avoid including junk */ 535# define WIN32_LEAN_AND_MEAN /* avoid including junk */
619# include <windows.h> 536# include <windows.h>
620 537
538# include "windows-mutex.h"
539# include "windows-rwlock.h"
540# include "windows-recmutex.h"
541# include "windows-once.h"
542
621# ifdef __cplusplus 543# ifdef __cplusplus
622extern "C" { 544extern "C" {
623# endif 545# endif
@@ -633,127 +555,69 @@ extern "C" {
633/* There is no way to statically initialize a CRITICAL_SECTION. It needs 555/* There is no way to statically initialize a CRITICAL_SECTION. It needs
634 to be done lazily, once only. For this we need spinlocks. */ 556 to be done lazily, once only. For this we need spinlocks. */
635 557
636typedef struct { volatile int done; volatile long started; } gl_spinlock_t;
637
638/* -------------------------- gl_lock_t datatype -------------------------- */ 558/* -------------------------- gl_lock_t datatype -------------------------- */
639 559
640typedef struct 560typedef glwthread_mutex_t gl_lock_t;
641 {
642 gl_spinlock_t guard; /* protects the initialization */
643 CRITICAL_SECTION lock;
644 }
645 gl_lock_t;
646# define gl_lock_define(STORAGECLASS, NAME) \ 561# define gl_lock_define(STORAGECLASS, NAME) \
647 STORAGECLASS gl_lock_t NAME; 562 STORAGECLASS gl_lock_t NAME;
648# define gl_lock_define_initialized(STORAGECLASS, NAME) \ 563# define gl_lock_define_initialized(STORAGECLASS, NAME) \
649 STORAGECLASS gl_lock_t NAME = gl_lock_initializer; 564 STORAGECLASS gl_lock_t NAME = gl_lock_initializer;
650# define gl_lock_initializer \ 565# define gl_lock_initializer \
651 { { 0, -1 } } 566 GLWTHREAD_MUTEX_INIT
652# define glthread_lock_init(LOCK) \ 567# define glthread_lock_init(LOCK) \
653 (glthread_lock_init_func (LOCK), 0) 568 (glwthread_mutex_init (LOCK), 0)
654# define glthread_lock_lock(LOCK) \ 569# define glthread_lock_lock(LOCK) \
655 glthread_lock_lock_func (LOCK) 570 glwthread_mutex_lock (LOCK)
656# define glthread_lock_unlock(LOCK) \ 571# define glthread_lock_unlock(LOCK) \
657 glthread_lock_unlock_func (LOCK) 572 glwthread_mutex_unlock (LOCK)
658# define glthread_lock_destroy(LOCK) \ 573# define glthread_lock_destroy(LOCK) \
659 glthread_lock_destroy_func (LOCK) 574 glwthread_mutex_destroy (LOCK)
660extern void glthread_lock_init_func (gl_lock_t *lock);
661extern int glthread_lock_lock_func (gl_lock_t *lock);
662extern int glthread_lock_unlock_func (gl_lock_t *lock);
663extern int glthread_lock_destroy_func (gl_lock_t *lock);
664 575
665/* ------------------------- gl_rwlock_t datatype ------------------------- */ 576/* ------------------------- gl_rwlock_t datatype ------------------------- */
666 577
667/* It is impossible to implement read-write locks using plain locks, without 578typedef glwthread_rwlock_t gl_rwlock_t;
668 introducing an extra thread dedicated to managing read-write locks.
669 Therefore here we need to use the low-level Event type. */
670
671typedef struct
672 {
673 HANDLE *array; /* array of waiting threads, each represented by an event */
674 unsigned int count; /* number of waiting threads */
675 unsigned int alloc; /* length of allocated array */
676 unsigned int offset; /* index of first waiting thread in array */
677 }
678 gl_carray_waitqueue_t;
679typedef struct
680 {
681 gl_spinlock_t guard; /* protects the initialization */
682 CRITICAL_SECTION lock; /* protects the remaining fields */
683 gl_carray_waitqueue_t waiting_readers; /* waiting readers */
684 gl_carray_waitqueue_t waiting_writers; /* waiting writers */
685 int runcount; /* number of readers running, or -1 when a writer runs */
686 }
687 gl_rwlock_t;
688# define gl_rwlock_define(STORAGECLASS, NAME) \ 579# define gl_rwlock_define(STORAGECLASS, NAME) \
689 STORAGECLASS gl_rwlock_t NAME; 580 STORAGECLASS gl_rwlock_t NAME;
690# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ 581# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
691 STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; 582 STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
692# define gl_rwlock_initializer \ 583# define gl_rwlock_initializer \
693 { { 0, -1 } } 584 GLWTHREAD_RWLOCK_INIT
694# define glthread_rwlock_init(LOCK) \ 585# define glthread_rwlock_init(LOCK) \
695 (glthread_rwlock_init_func (LOCK), 0) 586 (glwthread_rwlock_init (LOCK), 0)
696# define glthread_rwlock_rdlock(LOCK) \ 587# define glthread_rwlock_rdlock(LOCK) \
697 glthread_rwlock_rdlock_func (LOCK) 588 glwthread_rwlock_rdlock (LOCK)
698# define glthread_rwlock_wrlock(LOCK) \ 589# define glthread_rwlock_wrlock(LOCK) \
699 glthread_rwlock_wrlock_func (LOCK) 590 glwthread_rwlock_wrlock (LOCK)
700# define glthread_rwlock_unlock(LOCK) \ 591# define glthread_rwlock_unlock(LOCK) \
701 glthread_rwlock_unlock_func (LOCK) 592 glwthread_rwlock_unlock (LOCK)
702# define glthread_rwlock_destroy(LOCK) \ 593# define glthread_rwlock_destroy(LOCK) \
703 glthread_rwlock_destroy_func (LOCK) 594 glwthread_rwlock_destroy (LOCK)
704extern void glthread_rwlock_init_func (gl_rwlock_t *lock);
705extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock);
706extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock);
707extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock);
708extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock);
709 595
710/* --------------------- gl_recursive_lock_t datatype --------------------- */ 596/* --------------------- gl_recursive_lock_t datatype --------------------- */
711 597
712/* The native Windows documentation says that CRITICAL_SECTION already 598typedef glwthread_recmutex_t gl_recursive_lock_t;
713 implements a recursive lock. But we need not rely on it: It's easy to
714 implement a recursive lock without this assumption. */
715
716typedef struct
717 {
718 gl_spinlock_t guard; /* protects the initialization */
719 DWORD owner;
720 unsigned long depth;
721 CRITICAL_SECTION lock;
722 }
723 gl_recursive_lock_t;
724# define gl_recursive_lock_define(STORAGECLASS, NAME) \ 599# define gl_recursive_lock_define(STORAGECLASS, NAME) \
725 STORAGECLASS gl_recursive_lock_t NAME; 600 STORAGECLASS gl_recursive_lock_t NAME;
726# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ 601# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
727 STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; 602 STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
728# define gl_recursive_lock_initializer \ 603# define gl_recursive_lock_initializer \
729 { { 0, -1 }, 0, 0 } 604 GLWTHREAD_RECMUTEX_INIT
730# define glthread_recursive_lock_init(LOCK) \ 605# define glthread_recursive_lock_init(LOCK) \
731 (glthread_recursive_lock_init_func (LOCK), 0) 606 (glwthread_recmutex_init (LOCK), 0)
732# define glthread_recursive_lock_lock(LOCK) \ 607# define glthread_recursive_lock_lock(LOCK) \
733 glthread_recursive_lock_lock_func (LOCK) 608 glwthread_recmutex_lock (LOCK)
734# define glthread_recursive_lock_unlock(LOCK) \ 609# define glthread_recursive_lock_unlock(LOCK) \
735 glthread_recursive_lock_unlock_func (LOCK) 610 glwthread_recmutex_unlock (LOCK)
736# define glthread_recursive_lock_destroy(LOCK) \ 611# define glthread_recursive_lock_destroy(LOCK) \
737 glthread_recursive_lock_destroy_func (LOCK) 612 glwthread_recmutex_destroy (LOCK)
738extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock);
739extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock);
740extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock);
741extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock);
742 613
743/* -------------------------- gl_once_t datatype -------------------------- */ 614/* -------------------------- gl_once_t datatype -------------------------- */
744 615
745typedef struct 616typedef glwthread_once_t gl_once_t;
746 {
747 volatile int inited;
748 volatile long started;
749 CRITICAL_SECTION lock;
750 }
751 gl_once_t;
752# define gl_once_define(STORAGECLASS, NAME) \ 617# define gl_once_define(STORAGECLASS, NAME) \
753 STORAGECLASS gl_once_t NAME = { -1, -1 }; 618 STORAGECLASS gl_once_t NAME = GLWTHREAD_ONCE_INIT;
754# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ 619# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
755 (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0) 620 (glwthread_once (ONCE_CONTROL, INITFUNCTION), 0)
756extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (void));
757 621
758# ifdef __cplusplus 622# ifdef __cplusplus
759} 623}
@@ -763,7 +627,7 @@ extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (v
763 627
764/* ========================================================================= */ 628/* ========================================================================= */
765 629
766#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS) 630#if !(USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS)
767 631
768/* Provide dummy implementation if threads are not supported. */ 632/* Provide dummy implementation if threads are not supported. */
769 633
diff --git a/gl/glthread/threadlib.c b/gl/glthread/threadlib.c
index b447657..5ecf827 100644
--- a/gl/glthread/threadlib.c
+++ b/gl/glthread/threadlib.c
@@ -1,18 +1,18 @@
1/* Multithreading primitives. 1/* Multithreading primitives.
2 Copyright (C) 2005-2013 Free Software Foundation, Inc. 2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ 17/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
18 18
@@ -20,15 +20,48 @@
20 20
21/* ========================================================================= */ 21/* ========================================================================= */
22 22
23#if USE_POSIX_THREADS 23#if USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS
24 24
25/* Use the POSIX threads library. */ 25/* Use the POSIX threads library. */
26 26
27# include <errno.h>
27# include <pthread.h> 28# include <pthread.h>
28# include <stdlib.h> 29# include <stdlib.h>
29 30
30# if PTHREAD_IN_USE_DETECTION_HARD 31# if PTHREAD_IN_USE_DETECTION_HARD
31 32
33# if defined __FreeBSD__ || defined __DragonFly__ /* FreeBSD */
34
35/* Test using pthread_key_create. */
36
37int
38glthread_in_use (void)
39{
40 static int tested;
41 static int result; /* 1: linked with -lpthread, 0: only with libc */
42
43 if (!tested)
44 {
45 pthread_key_t key;
46 int err = pthread_key_create (&key, NULL);
47
48 if (err == ENOSYS)
49 result = 0;
50 else
51 {
52 result = 1;
53 if (err == 0)
54 pthread_key_delete (key);
55 }
56 tested = 1;
57 }
58 return result;
59}
60
61# else /* Solaris, HP-UX */
62
63/* Test using pthread_create. */
64
32/* The function to be executed by a dummy thread. */ 65/* The function to be executed by a dummy thread. */
33static void * 66static void *
34dummy_thread_func (void *arg) 67dummy_thread_func (void *arg)
@@ -62,6 +95,8 @@ glthread_in_use (void)
62 return result; 95 return result;
63} 96}
64 97
98# endif
99
65# endif 100# endif
66 101
67#endif 102#endif
diff --git a/gl/hard-locale.c b/gl/hard-locale.c
new file mode 100644
index 0000000..0a28552
--- /dev/null
+++ b/gl/hard-locale.c
@@ -0,0 +1,35 @@
1/* hard-locale.c -- Determine whether a locale is hard.
2
3 Copyright (C) 1997-1999, 2002-2004, 2006-2007, 2009-2023 Free Software
4 Foundation, Inc.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file 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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21#include "hard-locale.h"
22
23#include <locale.h>
24#include <string.h>
25
26bool
27hard_locale (int category)
28{
29 char locale[SETLOCALE_NULL_MAX];
30
31 if (setlocale_null_r (category, locale, sizeof (locale)))
32 return false;
33
34 return !(strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0);
35}
diff --git a/gl/hard-locale.h b/gl/hard-locale.h
new file mode 100644
index 0000000..880c9e8
--- /dev/null
+++ b/gl/hard-locale.h
@@ -0,0 +1,26 @@
1/* Determine whether a locale is hard.
2
3 Copyright (C) 1999, 2003-2004, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef HARD_LOCALE_H_
19# define HARD_LOCALE_H_ 1
20
21/* Return true if the specified CATEGORY of the current locale is hard, i.e.
22 different from the C or POSIX locale that has a fixed behavior.
23 CATEGORY must be one of the LC_* values, but not LC_ALL. */
24extern bool hard_locale (int category);
25
26#endif /* HARD_LOCALE_H_ */
diff --git a/gl/ialloc.c b/gl/ialloc.c
new file mode 100644
index 0000000..cd44d8c
--- /dev/null
+++ b/gl/ialloc.c
@@ -0,0 +1,21 @@
1/* malloc with idx_t rather than size_t
2
3 Copyright 2021-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20#define IALLOC_INLINE _GL_EXTERN_INLINE
21#include "ialloc.h"
diff --git a/gl/ialloc.h b/gl/ialloc.h
new file mode 100644
index 0000000..1d43faf
--- /dev/null
+++ b/gl/ialloc.h
@@ -0,0 +1,100 @@
1/* ialloc.h -- malloc with idx_t rather than size_t
2
3 Copyright 2021-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef IALLOC_H_
19#define IALLOC_H_
20
21#include "idx.h"
22
23#include <errno.h>
24#include <stdint.h>
25#include <stdlib.h>
26
27#ifndef _GL_INLINE_HEADER_BEGIN
28 #error "Please include config.h first."
29#endif
30_GL_INLINE_HEADER_BEGIN
31#ifndef IALLOC_INLINE
32# define IALLOC_INLINE _GL_INLINE
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39IALLOC_INLINE void * _GL_ATTRIBUTE_COLD
40_gl_alloc_nomem (void)
41{
42 errno = ENOMEM;
43 return NULL;
44}
45
46IALLOC_INLINE
47_GL_ATTRIBUTE_MALLOC /*_GL_ATTRIBUTE_DEALLOC_FREE*/
48void *
49imalloc (idx_t s)
50{
51 return s <= SIZE_MAX ? malloc (s) : _gl_alloc_nomem ();
52}
53
54IALLOC_INLINE
55/*_GL_ATTRIBUTE_DEALLOC_FREE*/
56void *
57irealloc (void *p, idx_t s)
58{
59 /* Work around GNU realloc glitch by treating a zero size as if it
60 were 1, so that returning NULL is equivalent to failing. */
61 return s <= SIZE_MAX ? realloc (p, s | !s) : _gl_alloc_nomem ();
62}
63
64IALLOC_INLINE
65_GL_ATTRIBUTE_MALLOC /*_GL_ATTRIBUTE_DEALLOC_FREE*/
66void *
67icalloc (idx_t n, idx_t s)
68{
69 if (SIZE_MAX < n)
70 {
71 if (s != 0)
72 return _gl_alloc_nomem ();
73 n = 0;
74 }
75 if (SIZE_MAX < s)
76 {
77 if (n != 0)
78 return _gl_alloc_nomem ();
79 s = 0;
80 }
81 return calloc (n, s);
82}
83
84IALLOC_INLINE void *
85ireallocarray (void *p, idx_t n, idx_t s)
86{
87 /* Work around GNU reallocarray glitch by treating a zero size as if
88 it were 1, so that returning NULL is equivalent to failing. */
89 if (n == 0 || s == 0)
90 n = s = 1;
91 return (n <= SIZE_MAX && s <= SIZE_MAX
92 ? reallocarray (p, n, s)
93 : _gl_alloc_nomem ());
94}
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif
diff --git a/gl/idpriv-droptemp.c b/gl/idpriv-droptemp.c
index 13d1064..2a85431 100644
--- a/gl/idpriv-droptemp.c
+++ b/gl/idpriv-droptemp.c
@@ -1,9 +1,9 @@
1/* Dropping uid/gid privileges of the current process temporarily. 1/* Dropping uid/gid privileges of the current process temporarily.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2009-2023 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 3 of the License, or 6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) 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,
@@ -12,7 +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, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
@@ -58,7 +58,9 @@ idpriv_temp_drop (void)
58 58
59 /* This is for executables that have the setuid bit set. */ 59 /* This is for executables that have the setuid bit set. */
60# if HAVE_SETRESUID /* glibc, FreeBSD, OpenBSD, HP-UX */ 60# if HAVE_SETRESUID /* glibc, FreeBSD, OpenBSD, HP-UX */
61 /* See <http://www.usenix.org/events/sec02/full_papers/chen/chen.pdf> 61 /* See
62 Hao Chen, David Wagner, Drew Dean: Setuid Demystified
63 <https://www.usenix.org/legacy/publications/library/proceedings/sec02/full_papers/chen/chen.pdf>
62 figure 14. */ 64 figure 14. */
63 if (setresuid (-1, uid, saved_uid) < 0) 65 if (setresuid (-1, uid, saved_uid) < 0)
64 return -1; 66 return -1;
@@ -134,7 +136,9 @@ idpriv_temp_restore (void)
134 136
135 /* This is for executables that have the setuid bit set. */ 137 /* This is for executables that have the setuid bit set. */
136# if HAVE_SETRESUID /* glibc, FreeBSD, OpenBSD, HP-UX */ 138# if HAVE_SETRESUID /* glibc, FreeBSD, OpenBSD, HP-UX */
137 /* See <http://www.usenix.org/events/sec02/full_papers/chen/chen.pdf> 139 /* See
140 Hao Chen, David Wagner, Drew Dean: Setuid Demystified
141 <https://www.usenix.org/legacy/publications/library/proceedings/sec02/full_papers/chen/chen.pdf>
138 figure 14. */ 142 figure 14. */
139 if (setresuid (-1, saved_uid, -1) < 0) 143 if (setresuid (-1, saved_uid, -1) < 0)
140 return -1; 144 return -1;
diff --git a/gl/idpriv.h b/gl/idpriv.h
index f454a2c..99f87c0 100644
--- a/gl/idpriv.h
+++ b/gl/idpriv.h
@@ -1,9 +1,9 @@
1/* Dropping uid/gid privileges of the current process. 1/* Dropping uid/gid privileges of the current process.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2009-2023 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 3 of the License, or 6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) 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,
@@ -12,7 +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, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#ifndef _IDPRIV_H 17#ifndef _IDPRIV_H
18#define _IDPRIV_H 18#define _IDPRIV_H
@@ -74,11 +74,11 @@ extern "C" {
74 74
75/* For more in-depth discussion of these topics, see the papers/articles 75/* For more in-depth discussion of these topics, see the papers/articles
76 * Hao Chen, David Wagner, Drew Dean: Setuid Demystified 76 * Hao Chen, David Wagner, Drew Dean: Setuid Demystified
77 <http://www.usenix.org/events/sec02/full_papers/chen/chen.pdf> 77 <https://www.usenix.org/legacy/publications/library/proceedings/sec02/full_papers/chen/chen.pdf>
78 * Dan Tsafrir, Dilma da Silva, David Wagner: The Murky Issue of Changing 78 * Dan Tsafrir, Dilma da Silva, David Wagner: The Murky Issue of Changing
79 Process Identity: Revising "Setuid Demystified" 79 Process Identity: Revising "Setuid Demystified"
80 <http://www.eecs.berkeley.edu/~daw/papers/setuid-login08b.pdf> 80 <https://people.eecs.berkeley.edu/~daw/papers/setuid-login08b.pdf>
81 <http://code.google.com/p/change-process-identity/> 81 <https://code.google.com/archive/p/change-process-identity/>
82 * Dhruv Mohindra: Observe correct revocation order while relinquishing 82 * Dhruv Mohindra: Observe correct revocation order while relinquishing
83 privileges 83 privileges
84 <https://www.securecoding.cert.org/confluence/display/seccode/POS36-C.+Observe+correct+revocation+order+while+relinquishing+privileges> 84 <https://www.securecoding.cert.org/confluence/display/seccode/POS36-C.+Observe+correct+revocation+order+while+relinquishing+privileges>
diff --git a/gl/idx.h b/gl/idx.h
new file mode 100644
index 0000000..23020b7
--- /dev/null
+++ b/gl/idx.h
@@ -0,0 +1,134 @@
1/* A type for indices and sizes.
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _IDX_H
20#define _IDX_H
21
22/* Get ptrdiff_t. */
23#include <stddef.h>
24
25/* Get PTRDIFF_MAX. */
26#include <stdint.h>
27
28/* The type 'idx_t' holds an (array) index or an (object) size.
29 Its implementation promotes to a signed integer type,
30 which can hold the values
31 0..2^63-1 (on 64-bit platforms) or
32 0..2^31-1 (on 32-bit platforms).
33
34 Why a signed integer type?
35
36 * Security: Signed types can be checked for overflow via
37 '-fsanitize=undefined', but unsigned types cannot.
38
39 * Comparisons without surprises: ISO C99 § 6.3.1.8 specifies a few
40 surprising results for comparisons, such as
41
42 (int) -3 < (unsigned long) 7 => false
43 (int) -3 < (unsigned int) 7 => false
44 and on 32-bit machines:
45 (long) -3 < (unsigned int) 7 => false
46
47 This is surprising because the natural comparison order is by
48 value in the realm of infinite-precision signed integers (ℤ).
49
50 The best way to get rid of such surprises is to use signed types
51 for numerical integer values, and use unsigned types only for
52 bit masks and enums.
53
54 Why not use 'size_t' directly?
55
56 * Because 'size_t' is an unsigned type, and a signed type is better.
57 See above.
58
59 Why not use 'ssize_t'?
60
61 * 'ptrdiff_t' is more portable; it is standardized by ISO C
62 whereas 'ssize_t' is standardized only by POSIX.
63
64 * 'ssize_t' is not required to be as wide as 'size_t', and some
65 now-obsolete POSIX platforms had 'size_t' wider than 'ssize_t'.
66
67 * Conversely, some now-obsolete platforms had 'ptrdiff_t' wider
68 than 'size_t', which can be a win and conforms to POSIX.
69
70 Won't this cause a problem with objects larger than PTRDIFF_MAX?
71
72 * Typical modern or large platforms do not allocate such objects,
73 so this is not much of a problem in practice; for example, you
74 can safely write 'idx_t len = strlen (s);'. To port to older
75 small platforms where allocations larger than PTRDIFF_MAX could
76 in theory be a problem, you can use Gnulib's ialloc module, or
77 functions like ximalloc in Gnulib's xalloc module.
78
79 Why not use 'ptrdiff_t' directly?
80
81 * Maintainability: When reading and modifying code, it helps to know that
82 a certain variable cannot have negative values. For example, when you
83 have a loop
84
85 int n = ...;
86 for (int i = 0; i < n; i++) ...
87
88 or
89
90 ptrdiff_t n = ...;
91 for (ptrdiff_t i = 0; i < n; i++) ...
92
93 you have to ask yourself "what if n < 0?". Whereas in
94
95 idx_t n = ...;
96 for (idx_t i = 0; i < n; i++) ...
97
98 you know that this case cannot happen.
99
100 Similarly, when a programmer writes
101
102 idx_t = ptr2 - ptr1;
103
104 there is an implied assertion that ptr1 and ptr2 point into the same
105 object and that ptr1 <= ptr2.
106
107 * Being future-proof: In the future, range types (integers which are
108 constrained to a certain range of values) may be added to C compilers
109 or to the C standard. Several programming languages (Ada, Haskell,
110 Common Lisp, Pascal) already have range types. Such range types may
111 help producing good code and good warnings. The type 'idx_t' could
112 then be typedef'ed to a range type that is signed after promotion. */
113
114/* In the future, idx_t could be typedef'ed to a signed range type.
115 The clang "extended integer types", supported in Clang 11 or newer
116 <https://clang.llvm.org/docs/LanguageExtensions.html#extended-integer-types>,
117 are a special case of range types. However, these types don't support binary
118 operators with plain integer types (e.g. expressions such as x > 1).
119 Therefore, they don't behave like signed types (and not like unsigned types
120 either). So, we cannot use them here. */
121
122/* Use the signed type 'ptrdiff_t'. */
123/* Note: ISO C does not mandate that 'size_t' and 'ptrdiff_t' have the same
124 size, but it is so on all platforms we have seen since 1990. */
125typedef ptrdiff_t idx_t;
126
127/* IDX_MAX is the maximum value of an idx_t. */
128#define IDX_MAX PTRDIFF_MAX
129
130/* So far no need has been found for an IDX_WIDTH macro.
131 Perhaps there should be another macro IDX_VALUE_BITS that does not
132 count the sign bit and is therefore one less than PTRDIFF_WIDTH. */
133
134#endif /* _IDX_H */
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c
index fdfd21d..9e2d412 100644
--- a/gl/inet_ntop.c
+++ b/gl/inet_ntop.c
@@ -1,19 +1,19 @@
1/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form 1/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form
2 2
3 Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* 18/*
19 * Copyright (c) 1996-1999 by Internet Software Consortium. 19 * Copyright (c) 1996-1999 by Internet Software Consortium.
@@ -40,7 +40,7 @@
40/* Use this to suppress gcc's "...may be used before initialized" warnings. 40/* Use this to suppress gcc's "...may be used before initialized" warnings.
41 Beware: The Code argument must not contain commas. */ 41 Beware: The Code argument must not contain commas. */
42#ifndef IF_LINT 42#ifndef IF_LINT
43# ifdef lint 43# if defined GCC_LINT || defined lint
44# define IF_LINT(Code) Code 44# define IF_LINT(Code) Code
45# else 45# else
46# define IF_LINT(Code) /* empty */ 46# define IF_LINT(Code) /* empty */
diff --git a/gl/intprops-internal.h b/gl/intprops-internal.h
new file mode 100644
index 0000000..0467a9c
--- /dev/null
+++ b/gl/intprops-internal.h
@@ -0,0 +1,392 @@
1/* intprops-internal.h -- properties of integer types not visible to users
2
3 Copyright (C) 2001-2023 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _GL_INTPROPS_INTERNAL_H
19#define _GL_INTPROPS_INTERNAL_H
20
21#include <limits.h>
22
23/* Return a value with the common real type of E and V and the value of V.
24 Do not evaluate E. */
25#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
26
27/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
28 <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */
29#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
30
31/* The extra casts in the following macros work around compiler bugs,
32 e.g., in Cray C 5.0.3.0. */
33
34/* True if the real type T is signed. */
35#define _GL_TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
36
37/* Return 1 if the real expression E, after promotion, has a
38 signed or floating type. Do not evaluate E. */
39#define _GL_EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
40
41
42/* Minimum and maximum values for integer types and expressions. */
43
44/* The width in bits of the integer type or expression T.
45 Do not evaluate T. T must not be a bit-field expression.
46 Padding bits are not supported; this is checked at compile-time below. */
47#define _GL_TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
48
49/* The maximum and minimum values for the type of the expression E,
50 after integer promotion. E is not evaluated. */
51#define _GL_INT_MINIMUM(e) \
52 (_GL_EXPR_SIGNED (e) \
53 ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
54 : _GL_INT_CONVERT (e, 0))
55#define _GL_INT_MAXIMUM(e) \
56 (_GL_EXPR_SIGNED (e) \
57 ? _GL_SIGNED_INT_MAXIMUM (e) \
58 : _GL_INT_NEGATE_CONVERT (e, 1))
59#define _GL_SIGNED_INT_MAXIMUM(e) \
60 (((_GL_INT_CONVERT (e, 1) << (_GL_TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
61
62/* Work around OpenVMS incompatibility with C99. */
63#if !defined LLONG_MAX && defined __INT64_MAX
64# define LLONG_MAX __INT64_MAX
65# define LLONG_MIN __INT64_MIN
66#endif
67
68/* This include file assumes that signed types are two's complement without
69 padding bits; the above macros have undefined behavior otherwise.
70 If this is a problem for you, please let us know how to fix it for your host.
71 This assumption is tested by the intprops-tests module. */
72
73/* Does the __typeof__ keyword work? This could be done by
74 'configure', but for now it's easier to do it by hand. */
75#if (2 <= __GNUC__ \
76 || (4 <= __clang_major__) \
77 || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
78 || (0x5110 <= __SUNPRO_C && !__STDC__))
79# define _GL_HAVE___TYPEOF__ 1
80#else
81# define _GL_HAVE___TYPEOF__ 0
82#endif
83
84/* Return 1 if the integer type or expression T might be signed. Return 0
85 if it is definitely unsigned. T must not be a bit-field expression.
86 This macro does not evaluate its argument, and expands to an
87 integer constant expression. */
88#if _GL_HAVE___TYPEOF__
89# define _GL_SIGNED_TYPE_OR_EXPR(t) _GL_TYPE_SIGNED (__typeof__ (t))
90#else
91# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
92#endif
93
94/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
95 A should not have side effects, and A's type should be an
96 integer with minimum value MIN and maximum MAX. */
97#define _GL_INT_NEGATE_RANGE_OVERFLOW(a, min, max) \
98 ((min) < 0 ? (a) < - (max) : 0 < (a))
99
100/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
101 (A, B, P) work when P is non-null. */
102#ifdef __EDG__
103/* EDG-based compilers like nvc 22.1 cannot add 64-bit signed to unsigned
104 <https://bugs.gnu.org/53256>. */
105# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
106#elif defined __has_builtin
107# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
108/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
109 see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>. */
110#elif 7 <= __GNUC__
111# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
112#else
113# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
114#endif
115
116/* True if __builtin_mul_overflow (A, B, P) works when P is non-null. */
117#if defined __clang_major__ && __clang_major__ < 14
118/* Work around Clang bug <https://bugs.llvm.org/show_bug.cgi?id=16404>. */
119# define _GL_HAS_BUILTIN_MUL_OVERFLOW 0
120#else
121# define _GL_HAS_BUILTIN_MUL_OVERFLOW _GL_HAS_BUILTIN_ADD_OVERFLOW
122#endif
123
124/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for
125 __builtin_sub_overflow_p and __builtin_mul_overflow_p. */
126#ifdef __EDG__
127/* In EDG-based compilers like ICC 2021.3 and earlier,
128 __builtin_add_overflow_p etc. are not treated as integral constant
129 expressions even when all arguments are. */
130# define _GL_HAS_BUILTIN_OVERFLOW_P 0
131#elif defined __has_builtin
132# define _GL_HAS_BUILTIN_OVERFLOW_P __has_builtin (__builtin_mul_overflow_p)
133#else
134# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
135#endif
136
137#if (!defined _GL_STDCKDINT_H && 202311 <= __STDC_VERSION__ \
138 && ! (_GL_HAS_BUILTIN_ADD_OVERFLOW && _GL_HAS_BUILTIN_MUL_OVERFLOW))
139# include <stdckdint.h>
140#endif
141
142/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R.
143 Return 1 if the result overflows. Arguments should not have side
144 effects and A, B and *R can be of any integer type other than char,
145 bool, a bit-precise integer type, or an enumeration type. */
146#if _GL_HAS_BUILTIN_ADD_OVERFLOW
147# define _GL_INT_ADD_WRAPV(a, b, r) __builtin_add_overflow (a, b, r)
148# define _GL_INT_SUBTRACT_WRAPV(a, b, r) __builtin_sub_overflow (a, b, r)
149#elif defined ckd_add && defined ckd_sub && !defined _GL_STDCKDINT_H
150# define _GL_INT_ADD_WRAPV(a, b, r) ckd_add (r, + (a), + (b))
151# define _GL_INT_SUBTRACT_WRAPV(a, b, r) ckd_sub (r, + (a), + (b))
152#else
153# define _GL_INT_ADD_WRAPV(a, b, r) \
154 _GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW)
155# define _GL_INT_SUBTRACT_WRAPV(a, b, r) \
156 _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
157#endif
158#if _GL_HAS_BUILTIN_MUL_OVERFLOW
159# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
160 || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \
161 && !defined __EDG__)
162# define _GL_INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r)
163# else
164 /* Work around GCC bug 91450. */
165# define _GL_INT_MULTIPLY_WRAPV(a, b, r) \
166 ((!_GL_SIGNED_TYPE_OR_EXPR (*(r)) && _GL_EXPR_SIGNED (a) && _GL_EXPR_SIGNED (b) \
167 && _GL_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \
168 ? ((void) __builtin_mul_overflow (a, b, r), 1) \
169 : __builtin_mul_overflow (a, b, r))
170# endif
171#elif defined ckd_mul && !defined _GL_STDCKDINT_H
172# define _GL_INT_MULTIPLY_WRAPV(a, b, r) ckd_mul (r, + (a), + (b))
173#else
174# define _GL_INT_MULTIPLY_WRAPV(a, b, r) \
175 _GL_INT_OP_WRAPV (a, b, r, *, _GL_INT_MULTIPLY_RANGE_OVERFLOW)
176#endif
177
178/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See:
179 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193
180 https://llvm.org/bugs/show_bug.cgi?id=25390
181 For now, assume all versions of GCC-like compilers generate bogus
182 warnings for _Generic. This matters only for compilers that
183 lack relevant builtins. */
184#if __GNUC__ || defined __clang__
185# define _GL__GENERIC_BOGUS 1
186#else
187# define _GL__GENERIC_BOGUS 0
188#endif
189
190/* Store the low-order bits of A <op> B into *R, where OP specifies
191 the operation and OVERFLOW the overflow predicate. Return 1 if the
192 result overflows. Arguments should not have side effects,
193 and A, B and *R can be of any integer type other than char, bool, a
194 bit-precise integer type, or an enumeration type. */
195#if 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
196# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \
197 (_Generic \
198 (*(r), \
199 signed char: \
200 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
201 signed char, SCHAR_MIN, SCHAR_MAX), \
202 unsigned char: \
203 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
204 unsigned char, 0, UCHAR_MAX), \
205 short int: \
206 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
207 short int, SHRT_MIN, SHRT_MAX), \
208 unsigned short int: \
209 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
210 unsigned short int, 0, USHRT_MAX), \
211 int: \
212 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
213 int, INT_MIN, INT_MAX), \
214 unsigned int: \
215 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
216 unsigned int, 0, UINT_MAX), \
217 long int: \
218 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
219 long int, LONG_MIN, LONG_MAX), \
220 unsigned long int: \
221 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
222 unsigned long int, 0, ULONG_MAX), \
223 long long int: \
224 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
225 long long int, LLONG_MIN, LLONG_MAX), \
226 unsigned long long int: \
227 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
228 unsigned long long int, 0, ULLONG_MAX)))
229#else
230/* Store the low-order bits of A <op> B into *R, where OP specifies
231 the operation and OVERFLOW the overflow predicate. If *R is
232 signed, its type is ST with bounds SMIN..SMAX; otherwise its type
233 is UT with bounds U..UMAX. ST and UT are narrower than int.
234 Return 1 if the result overflows. Arguments should not have side
235 effects, and A, B and *R can be of any integer type other than
236 char, bool, a bit-precise integer type, or an enumeration type. */
237# if _GL_HAVE___TYPEOF__
238# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \
239 (_GL_TYPE_SIGNED (__typeof__ (*(r))) \
240 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, st, smin, smax) \
241 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, ut, 0, umax))
242# else
243# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \
244 (overflow (a, b, smin, smax) \
245 ? (overflow (a, b, 0, umax) \
246 ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 1) \
247 : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) < 0) \
248 : (overflow (a, b, 0, umax) \
249 ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) >= 0 \
250 : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 0)))
251# endif
252
253# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \
254 (sizeof *(r) == sizeof (signed char) \
255 ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \
256 signed char, SCHAR_MIN, SCHAR_MAX, \
257 unsigned char, UCHAR_MAX) \
258 : sizeof *(r) == sizeof (short int) \
259 ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \
260 short int, SHRT_MIN, SHRT_MAX, \
261 unsigned short int, USHRT_MAX) \
262 : sizeof *(r) == sizeof (int) \
263 ? (_GL_EXPR_SIGNED (*(r)) \
264 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
265 int, INT_MIN, INT_MAX) \
266 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
267 unsigned int, 0, UINT_MAX)) \
268 : _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow))
269# ifdef LLONG_MAX
270# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
271 (sizeof *(r) == sizeof (long int) \
272 ? (_GL_EXPR_SIGNED (*(r)) \
273 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
274 long int, LONG_MIN, LONG_MAX) \
275 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
276 unsigned long int, 0, ULONG_MAX)) \
277 : (_GL_EXPR_SIGNED (*(r)) \
278 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
279 long long int, LLONG_MIN, LLONG_MAX) \
280 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
281 unsigned long long int, 0, ULLONG_MAX)))
282# else
283# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
284 (_GL_EXPR_SIGNED (*(r)) \
285 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
286 long int, LONG_MIN, LONG_MAX) \
287 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
288 unsigned long int, 0, ULONG_MAX))
289# endif
290#endif
291
292/* Store the low-order bits of A <op> B into *R, where the operation
293 is given by OP. Use the unsigned type UT for calculation to avoid
294 overflow problems. *R's type is T, with extrema TMIN and TMAX.
295 T can be any signed integer type other than char, bool, a
296 bit-precise integer type, or an enumeration type.
297 Return 1 if the result overflows. */
298#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \
299 (overflow (a, b, tmin, tmax) \
300 ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \
301 : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0))
302
303/* Return 1 if the integer expressions A - B and -A would overflow,
304 respectively. Arguments should not have side effects,
305 and can be any signed integer type other than char, bool, a
306 bit-precise integer type, or an enumeration type.
307 These macros are tuned for their last input argument being a constant. */
308
309#if _GL_HAS_BUILTIN_OVERFLOW_P
310# define _GL_INT_NEGATE_OVERFLOW(a) \
311 __builtin_sub_overflow_p (0, a, (__typeof__ (- (a))) 0)
312#else
313# define _GL_INT_NEGATE_OVERFLOW(a) \
314 _GL_INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
315#endif
316
317/* Return the low-order bits of A <op> B, where the operation is given
318 by OP. Use the unsigned type UT for calculation to avoid undefined
319 behavior on signed integer overflow, and convert the result to type T.
320 UT is at least as wide as T and is no narrower than unsigned int,
321 T is two's complement, and there is no padding or trap representations.
322 Assume that converting UT to T yields the low-order bits, as is
323 done in all known two's-complement C compilers. E.g., see:
324 https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
325
326 According to the C standard, converting UT to T yields an
327 implementation-defined result or signal for values outside T's
328 range. However, code that works around this theoretical problem
329 runs afoul of a compiler bug in Oracle Studio 12.3 x86. See:
330 https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html
331 As the compiler bug is real, don't try to work around the
332 theoretical problem. */
333
334#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \
335 ((t) ((ut) (a) op (ut) (b)))
336
337/* Return true if the numeric values A + B, A - B, A * B fall outside
338 the range TMIN..TMAX. Arguments should not have side effects
339 and can be any integer type other than char, bool,
340 a bit-precise integer type, or an enumeration type.
341 TMIN should be signed and nonpositive.
342 TMAX should be positive, and should be signed unless TMIN is zero. */
343#define _GL_INT_ADD_RANGE_OVERFLOW(a, b, tmin, tmax) \
344 ((b) < 0 \
345 ? (((tmin) \
346 ? ((_GL_EXPR_SIGNED (_GL_INT_CONVERT (a, (tmin) - (b))) || (b) < (tmin)) \
347 && (a) < (tmin) - (b)) \
348 : (a) <= -1 - (b)) \
349 || ((_GL_EXPR_SIGNED (a) ? 0 <= (a) : (tmax) < (a)) && (tmax) < (a) + (b))) \
350 : (a) < 0 \
351 ? (((tmin) \
352 ? ((_GL_EXPR_SIGNED (_GL_INT_CONVERT (b, (tmin) - (a))) || (a) < (tmin)) \
353 && (b) < (tmin) - (a)) \
354 : (b) <= -1 - (a)) \
355 || ((_GL_EXPR_SIGNED (_GL_INT_CONVERT (a, b)) || (tmax) < (b)) \
356 && (tmax) < (a) + (b))) \
357 : (tmax) < (b) || (tmax) - (b) < (a))
358#define _GL_INT_SUBTRACT_RANGE_OVERFLOW(a, b, tmin, tmax) \
359 (((a) < 0) == ((b) < 0) \
360 ? ((a) < (b) \
361 ? !(tmin) || -1 - (tmin) < (b) - (a) - 1 \
362 : (tmax) < (a) - (b)) \
363 : (a) < 0 \
364 ? ((!_GL_EXPR_SIGNED (_GL_INT_CONVERT ((a) - (tmin), b)) && (a) - (tmin) < 0) \
365 || (a) - (tmin) < (b)) \
366 : ((! (_GL_EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
367 && _GL_EXPR_SIGNED (_GL_INT_CONVERT ((tmax) + (b), a))) \
368 && (tmax) <= -1 - (b)) \
369 || (tmax) + (b) < (a)))
370#define _GL_INT_MULTIPLY_RANGE_OVERFLOW(a, b, tmin, tmax) \
371 ((b) < 0 \
372 ? ((a) < 0 \
373 ? (_GL_EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
374 ? (a) < (tmax) / (b) \
375 : ((_GL_INT_NEGATE_OVERFLOW (b) \
376 ? _GL_INT_CONVERT (b, tmax) >> (_GL_TYPE_WIDTH (+ (b)) - 1) \
377 : (tmax) / -(b)) \
378 <= -1 - (a))) \
379 : _GL_INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \
380 ? (_GL_EXPR_SIGNED (a) \
381 ? 0 < (a) + (tmin) \
382 : 0 < (a) && -1 - (tmin) < (a) - 1) \
383 : (tmin) / (b) < (a)) \
384 : (b) == 0 \
385 ? 0 \
386 : ((a) < 0 \
387 ? (_GL_INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (a, tmin)) && (a) == -1 \
388 ? (_GL_EXPR_SIGNED (b) ? 0 < (b) + (tmin) : -1 - (tmin) < (b) - 1) \
389 : (tmin) / (a) < (b)) \
390 : (tmax) / (b) < (a)))
391
392#endif /* _GL_INTPROPS_INTERNAL_H */
diff --git a/gl/intprops.h b/gl/intprops.h
index f57f9b4..44b5e60 100644
--- a/gl/intprops.h
+++ b/gl/intprops.h
@@ -1,34 +1,24 @@
1/* intprops.h -- properties of integer types 1/* intprops.h -- properties of integer types
2 2
3 Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc. 3 Copyright (C) 2001-2023 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 it
6 it under the terms of the GNU General Public License as published by 6 under the terms of the GNU Lesser General Public License as published
7 the Free Software Foundation; either version 3 of the License, or 7 by the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19 17
20#ifndef _GL_INTPROPS_H 18#ifndef _GL_INTPROPS_H
21#define _GL_INTPROPS_H 19#define _GL_INTPROPS_H
22 20
23#include <limits.h> 21#include "intprops-internal.h"
24
25/* Return an integer value, converted to the same type as the integer
26 expression E after integer type promotion. V is the unconverted value. */
27#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
28
29/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
30 <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */
31#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))
32 22
33/* The extra casts in the following macros work around compiler bugs, 23/* The extra casts in the following macros work around compiler bugs,
34 e.g., in Cray C 5.0.3.0. */ 24 e.g., in Cray C 5.0.3.0. */
@@ -37,72 +27,27 @@
37 an integer. */ 27 an integer. */
38#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) 28#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
39 29
40/* True if negative values of the signed integer type T use two's 30/* True if the real type T is signed. */
41 complement, ones' complement, or signed magnitude representation, 31#define TYPE_SIGNED(t) _GL_TYPE_SIGNED (t)
42 respectively. Much GNU code assumes two's complement, but some
43 people like to be portable to all possible C hosts. */
44#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
45#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
46#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
47 32
48/* True if the signed integer expression E uses two's complement. */ 33/* Return 1 if the real expression E, after promotion, has a
49#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1) 34 signed or floating type. Do not evaluate E. */
35#define EXPR_SIGNED(e) _GL_EXPR_SIGNED (e)
50 36
51/* True if the arithmetic type T is signed. */
52#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
53 37
54/* Return 1 if the integer expression E, after integer promotion, has 38/* Minimum and maximum values for integer types and expressions. */
55 a signed type. */
56#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
57 39
58 40/* The width in bits of the integer type or expression T.
59/* Minimum and maximum values for integer types and expressions. These 41 Do not evaluate T. T must not be a bit-field expression.
60 macros have undefined behavior if T is signed and has padding bits. 42 Padding bits are not supported; this is checked at compile-time below. */
61 If this is a problem for you, please let us know how to fix it for 43#define TYPE_WIDTH(t) _GL_TYPE_WIDTH (t)
62 your host. */
63 44
64/* The maximum and minimum values for the integer type T. */ 45/* The maximum and minimum values for the integer type T. */
65#define TYPE_MINIMUM(t) \ 46#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
66 ((t) (! TYPE_SIGNED (t) \
67 ? (t) 0 \
68 : TYPE_SIGNED_MAGNITUDE (t) \
69 ? ~ (t) 0 \
70 : ~ TYPE_MAXIMUM (t)))
71#define TYPE_MAXIMUM(t) \ 47#define TYPE_MAXIMUM(t) \
72 ((t) (! TYPE_SIGNED (t) \ 48 ((t) (! TYPE_SIGNED (t) \
73 ? (t) -1 \ 49 ? (t) -1 \
74 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) 50 : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
75
76/* The maximum and minimum values for the type of the expression E,
77 after integer promotion. E should not have side effects. */
78#define _GL_INT_MINIMUM(e) \
79 (_GL_INT_SIGNED (e) \
80 ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \
81 : _GL_INT_CONVERT (e, 0))
82#define _GL_INT_MAXIMUM(e) \
83 (_GL_INT_SIGNED (e) \
84 ? _GL_SIGNED_INT_MAXIMUM (e) \
85 : _GL_INT_NEGATE_CONVERT (e, 1))
86#define _GL_SIGNED_INT_MAXIMUM(e) \
87 (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
88
89
90/* Return 1 if the __typeof__ keyword works. This could be done by
91 'configure', but for now it's easier to do it by hand. */
92#if 2 <= __GNUC__ || defined __IBM__TYPEOF__ || 0x5110 <= __SUNPRO_C
93# define _GL_HAVE___TYPEOF__ 1
94#else
95# define _GL_HAVE___TYPEOF__ 0
96#endif
97
98/* Return 1 if the integer type or expression T might be signed. Return 0
99 if it is definitely unsigned. This macro does not evaluate its argument,
100 and expands to an integer constant expression. */
101#if _GL_HAVE___TYPEOF__
102# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
103#else
104# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
105#endif
106 51
107/* Bound on length of the string representing an unsigned integer 52/* Bound on length of the string representing an unsigned integer
108 value representable in B bits. log10 (2.0) < 146/485. The 53 value representable in B bits. log10 (2.0) < 146/485. The
@@ -110,30 +55,31 @@
110#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) 55#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
111 56
112/* Bound on length of the string representing an integer type or expression T. 57/* Bound on length of the string representing an integer type or expression T.
58 T must not be a bit-field expression.
59
113 Subtract 1 for the sign bit if T is signed, and then add 1 more for 60 Subtract 1 for the sign bit if T is signed, and then add 1 more for
114 a minus sign if needed. 61 a minus sign if needed.
115 62
116 Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is 63 Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 1 when its argument is
117 signed, this macro may overestimate the true bound by one byte when 64 unsigned, this macro may overestimate the true bound by one byte when
118 applied to unsigned types of size 2, 4, 16, ... bytes. */ 65 applied to unsigned types of size 2, 4, 16, ... bytes. */
119#define INT_STRLEN_BOUND(t) \ 66#define INT_STRLEN_BOUND(t) \
120 (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ 67 (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \
121 - _GL_SIGNED_TYPE_OR_EXPR (t)) \
122 + _GL_SIGNED_TYPE_OR_EXPR (t)) 68 + _GL_SIGNED_TYPE_OR_EXPR (t))
123 69
124/* Bound on buffer size needed to represent an integer type or expression T, 70/* Bound on buffer size needed to represent an integer type or expression T,
125 including the terminating null. */ 71 including the terminating null. T must not be a bit-field expression. */
126#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) 72#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
127 73
128 74
129/* Range overflow checks. 75/* Range overflow checks.
130 76
131 The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C 77 The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
132 operators might not yield numerically correct answers due to 78 operators overflow arithmetically when given the same arguments.
133 arithmetic overflow. They do not rely on undefined or 79 These macros do not rely on undefined or implementation-defined behavior.
134 implementation-defined behavior. Their implementations are simple 80 Although their implementations are simple and straightforward,
135 and straightforward, but they are a bit harder to use than the 81 they are harder to use and may be less efficient than the
136 INT_<op>_OVERFLOW macros described below. 82 INT_<op>_WRAPV, INT_<op>_OK, and INT_<op>_OVERFLOW macros described below.
137 83
138 Example usage: 84 Example usage:
139 85
@@ -157,6 +103,9 @@
157 must have minimum value MIN and maximum MAX. Unsigned types should 103 must have minimum value MIN and maximum MAX. Unsigned types should
158 use a zero MIN of the proper type. 104 use a zero MIN of the proper type.
159 105
106 Because all arguments are subject to integer promotions, these
107 macros typically do not work on types narrower than 'int'.
108
160 These macros are tuned for constant MIN and MAX. For commutative 109 These macros are tuned for constant MIN and MAX. For commutative
161 operations such as A + B, they are also tuned for constant B. */ 110 operations such as A + B, they are also tuned for constant B. */
162 111
@@ -177,14 +126,12 @@
177/* Return 1 if - A would overflow in [MIN,MAX] arithmetic. 126/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
178 See above for restrictions. */ 127 See above for restrictions. */
179#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ 128#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \
180 ((min) < 0 \ 129 _GL_INT_NEGATE_RANGE_OVERFLOW (a, min, max)
181 ? (a) < - (max) \
182 : 0 < (a))
183 130
184/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. 131/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
185 See above for restrictions. Avoid && and || as they tickle 132 See above for restrictions. Avoid && and || as they tickle
186 bugs in Sun C 5.11 2010/08/13 and other compilers; see 133 bugs in Sun C 5.11 2010/08/13 and other compilers; see
187 <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>. */ 134 <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00401.html>. */
188#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ 135#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
189 ((b) < 0 \ 136 ((b) < 0 \
190 ? ((a) < 0 \ 137 ? ((a) < 0 \
@@ -223,24 +170,32 @@
223 ? (a) < (min) >> (b) \ 170 ? (a) < (min) >> (b) \
224 : (max) >> (b) < (a)) 171 : (max) >> (b) < (a))
225 172
226
227/* The _GL*_OVERFLOW macros have the same restrictions as the 173/* The _GL*_OVERFLOW macros have the same restrictions as the
228 *_RANGE_OVERFLOW macros, except that they do not assume that operands 174 *_RANGE_OVERFLOW macros, except that they do not assume that operands
229 (e.g., A and B) have the same type as MIN and MAX. Instead, they assume 175 (e.g., A and B) have the same type as MIN and MAX. Instead, they assume
230 that the result (e.g., A + B) has that type. */ 176 that the result (e.g., A + B) has that type. */
231#define _GL_ADD_OVERFLOW(a, b, min, max) \ 177#if _GL_HAS_BUILTIN_OVERFLOW_P
232 ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ 178# define _GL_ADD_OVERFLOW(a, b, min, max) \
233 : (a) < 0 ? (b) <= (a) + (b) \ 179 __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
234 : (b) < 0 ? (a) <= (a) + (b) \ 180# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
235 : (a) + (b) < (b)) 181 __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
236#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ 182# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
237 ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ 183 __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0)
238 : (a) < 0 ? 1 \ 184#else
239 : (b) < 0 ? (a) - (b) <= (a) \ 185# define _GL_ADD_OVERFLOW(a, b, min, max) \
240 : (a) < (b)) 186 ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
241#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ 187 : (a) < 0 ? (b) <= (a) + (b) \
242 (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ 188 : (b) < 0 ? (a) <= (a) + (b) \
243 || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) 189 : (a) + (b) < (b))
190# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
191 ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
192 : (a) < 0 ? 1 \
193 : (b) < 0 ? (a) - (b) <= (a) \
194 : (a) < (b))
195# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
196 (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
197 || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
198#endif
244#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ 199#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \
245 ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ 200 ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
246 : (a) < 0 ? (b) <= (a) + (b) - 1 \ 201 : (a) < 0 ? (b) <= (a) + (b) - 1 \
@@ -262,22 +217,31 @@
262 : (a) % - (b)) \ 217 : (a) % - (b)) \
263 == 0) 218 == 0)
264 219
265 220/* Check for integer overflow, and report low order bits of answer.
266/* Integer overflow checks.
267 221
268 The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators 222 The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
269 might not yield numerically correct answers due to arithmetic overflow. 223 might not yield numerically correct answers due to arithmetic overflow.
270 They work correctly on all known practical hosts, and do not rely 224 The INT_<op>_WRAPV macros compute the low-order bits of the sum,
225 difference, and product of two C integers, and return 1 if these
226 low-order bits are not numerically correct.
227 These macros work correctly on all known practical hosts, and do not rely
271 on undefined behavior due to signed arithmetic overflow. 228 on undefined behavior due to signed arithmetic overflow.
272 229
273 Example usage: 230 Example usage, assuming A and B are long int:
274 231
275 long int i = ...; 232 if (INT_MULTIPLY_OVERFLOW (a, b))
276 long int j = ...; 233 printf ("result would overflow\n");
277 if (INT_MULTIPLY_OVERFLOW (i, j))
278 printf ("multiply would overflow");
279 else 234 else
280 printf ("product is %ld", i * j); 235 printf ("result is %ld (no overflow)\n", a * b);
236
237 Example usage with WRAPV flavor:
238
239 long int result;
240 bool overflow = INT_MULTIPLY_WRAPV (a, b, &result);
241 printf ("result is %ld (%s)\n", result,
242 overflow ? "after overflow" : "no overflow");
243
244 Restrictions on these macros:
281 245
282 These macros do not check for all possible numerical problems or 246 These macros do not check for all possible numerical problems or
283 undefined or unspecified behavior: they do not check for division 247 undefined or unspecified behavior: they do not check for division
@@ -286,7 +250,23 @@
286 These macros may evaluate their arguments zero or multiple times, so the 250 These macros may evaluate their arguments zero or multiple times, so the
287 arguments should not have side effects. 251 arguments should not have side effects.
288 252
289 These macros are tuned for their last argument being a constant. 253 The WRAPV macros are not constant expressions. They support only
254 +, binary -, and *.
255
256 Because the WRAPV macros convert the result, they report overflow
257 in different circumstances than the OVERFLOW macros do. For
258 example, in the typical case with 16-bit 'short' and 32-bit 'int',
259 if A, B and *R are all of type 'short' then INT_ADD_OVERFLOW (A, B)
260 returns false because the addition cannot overflow after A and B
261 are converted to 'int', whereas INT_ADD_WRAPV (A, B, R) returns
262 true or false depending on whether the sum fits into 'short'.
263
264 These macros are tuned for their last input argument being a constant.
265
266 A, B, and *R should be integers; they need not be the same type,
267 and they need not be all signed or all unsigned.
268 However, none of the integer types should be bit-precise,
269 and *R's type should not be char, bool, or an enumeration type.
290 270
291 Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, 271 Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
292 A % B, and A << B would overflow, respectively. */ 272 A % B, and A << B would overflow, respectively. */
@@ -295,8 +275,7 @@
295 _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) 275 _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
296#define INT_SUBTRACT_OVERFLOW(a, b) \ 276#define INT_SUBTRACT_OVERFLOW(a, b) \
297 _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) 277 _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
298#define INT_NEGATE_OVERFLOW(a) \ 278#define INT_NEGATE_OVERFLOW(a) _GL_INT_NEGATE_OVERFLOW (a)
299 INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
300#define INT_MULTIPLY_OVERFLOW(a, b) \ 279#define INT_MULTIPLY_OVERFLOW(a, b) \
301 _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW) 280 _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
302#define INT_DIVIDE_OVERFLOW(a, b) \ 281#define INT_DIVIDE_OVERFLOW(a, b) \
@@ -313,7 +292,44 @@
313 Arguments should be free of side effects. */ 292 Arguments should be free of side effects. */
314#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ 293#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
315 op_result_overflow (a, b, \ 294 op_result_overflow (a, b, \
316 _GL_INT_MINIMUM (0 * (b) + (a)), \ 295 _GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
317 _GL_INT_MAXIMUM (0 * (b) + (a))) 296 _GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))
297
298/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R.
299 Return 1 if the result overflows. See above for restrictions. */
300#define INT_ADD_WRAPV(a, b, r) _GL_INT_ADD_WRAPV (a, b, r)
301#define INT_SUBTRACT_WRAPV(a, b, r) _GL_INT_SUBTRACT_WRAPV (a, b, r)
302#define INT_MULTIPLY_WRAPV(a, b, r) _GL_INT_MULTIPLY_WRAPV (a, b, r)
303
304/* The following macros compute A + B, A - B, and A * B, respectively.
305 If no overflow occurs, they set *R to the result and return 1;
306 otherwise, they return 0 and may modify *R.
307
308 Example usage:
309
310 long int result;
311 if (INT_ADD_OK (a, b, &result))
312 printf ("result is %ld\n", result);
313 else
314 printf ("overflow\n");
315
316 A, B, and *R should be integers; they need not be the same type,
317 and they need not be all signed or all unsigned.
318 However, none of the integer types should be bit-precise,
319 and *R's type should not be char, bool, or an enumeration type.
320
321 These macros work correctly on all known practical hosts, and do not rely
322 on undefined behavior due to signed arithmetic overflow.
323
324 These macros are not constant expressions.
325
326 These macros may evaluate their arguments zero or multiple times, so the
327 arguments should not have side effects.
328
329 These macros are tuned for B being a constant. */
330
331#define INT_ADD_OK(a, b, r) (! INT_ADD_WRAPV (a, b, r))
332#define INT_SUBTRACT_OK(a, b, r) (! INT_SUBTRACT_WRAPV (a, b, r))
333#define INT_MULTIPLY_OK(a, b, r) (! INT_MULTIPLY_WRAPV (a, b, r))
318 334
319#endif /* _GL_INTPROPS_H */ 335#endif /* _GL_INTPROPS_H */
diff --git a/gl/inttypes.in.h b/gl/inttypes.in.h
new file mode 100644
index 0000000..50a2bbf
--- /dev/null
+++ b/gl/inttypes.in.h
@@ -0,0 +1,1002 @@
1/* Copyright (C) 2006-2023 Free Software Foundation, Inc.
2 Written by Paul Eggert, Bruno Haible, Derek Price.
3 This file is part of gnulib.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/*
19 * ISO C 99 <inttypes.h> for platforms that lack it.
20 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html>
21 */
22
23#if __GNUC__ >= 3
24@PRAGMA_SYSTEM_HEADER@
25#endif
26@PRAGMA_COLUMNS@
27
28/* Include the original <inttypes.h> if it exists, and if this file
29 has not been included yet or if this file includes gnulib stdint.h
30 which in turn includes this file.
31 The include_next requires a split double-inclusion guard. */
32#if ! defined INTTYPES_H || defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
33# if @HAVE_INTTYPES_H@
34
35 /* Some pre-C++11 <stdint.h> implementations need this. */
36# if defined __cplusplus && ! defined __STDC_FORMAT_MACROS
37# define __STDC_FORMAT_MACROS 1
38# endif
39
40# @INCLUDE_NEXT@ @NEXT_INTTYPES_H@
41
42# define _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H
43# endif
44#endif
45
46#if ! defined INTTYPES_H && ! defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
47#define INTTYPES_H
48
49/* Include <stdint.h> or the gnulib replacement.
50 But avoid namespace pollution on glibc systems. */
51#ifndef __GLIBC__
52# include <stdint.h>
53#endif
54/* Get CHAR_BIT, INT_MAX, LONG_MAX, etc. */
55#include <limits.h>
56/* On mingw, __USE_MINGW_ANSI_STDIO only works if <stdio.h> is also included */
57#if defined _WIN32 && ! defined __CYGWIN__
58# include <stdio.h>
59#endif
60
61#if !(INT_MAX == 0x7fffffff && INT_MIN + INT_MAX == -1)
62# error "This file assumes that 'int' is 32-bit two's complement. Please report your platform and compiler to <bug-gnulib@gnu.org>."
63#endif
64
65/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
66
67/* The definition of _GL_ARG_NONNULL is copied here. */
68
69/* The definition of _GL_WARN_ON_USE is copied here. */
70
71/* 7.8.1 Macros for format specifiers */
72
73#if defined _TNS_R_TARGET
74 /* Tandem NonStop R series and compatible platforms released before
75 July 2005 support %Ld but not %lld. */
76# define _LONG_LONG_FORMAT_PREFIX "L"
77#else
78# define _LONG_LONG_FORMAT_PREFIX "ll"
79#endif
80
81#if !defined PRId8
82# ifdef INT8_MAX
83# define PRId8 "d"
84# endif
85#endif
86#if !defined PRIi8
87# ifdef INT8_MAX
88# define PRIi8 "i"
89# endif
90#endif
91#if !defined PRIo8
92# ifdef UINT8_MAX
93# define PRIo8 "o"
94# endif
95#endif
96#if !defined PRIu8
97# ifdef UINT8_MAX
98# define PRIu8 "u"
99# endif
100#endif
101#if !defined PRIx8
102# ifdef UINT8_MAX
103# define PRIx8 "x"
104# endif
105#endif
106#if !defined PRIX8
107# ifdef UINT8_MAX
108# define PRIX8 "X"
109# endif
110#endif
111#if !defined PRId16
112# ifdef INT16_MAX
113# define PRId16 "d"
114# endif
115#endif
116#if !defined PRIi16
117# ifdef INT16_MAX
118# define PRIi16 "i"
119# endif
120#endif
121#if !defined PRIo16
122# ifdef UINT16_MAX
123# define PRIo16 "o"
124# endif
125#endif
126#if !defined PRIu16
127# ifdef UINT16_MAX
128# define PRIu16 "u"
129# endif
130#endif
131#if !defined PRIx16
132# ifdef UINT16_MAX
133# define PRIx16 "x"
134# endif
135#endif
136#if !defined PRIX16
137# ifdef UINT16_MAX
138# define PRIX16 "X"
139# endif
140#endif
141#if !defined PRId32
142# ifdef INT32_MAX
143# define PRId32 "d"
144# endif
145#endif
146#if !defined PRIi32
147# ifdef INT32_MAX
148# define PRIi32 "i"
149# endif
150#endif
151#if !defined PRIo32
152# ifdef UINT32_MAX
153# define PRIo32 "o"
154# endif
155#endif
156#if !defined PRIu32
157# ifdef UINT32_MAX
158# define PRIu32 "u"
159# endif
160#endif
161#if !defined PRIx32
162# ifdef UINT32_MAX
163# define PRIx32 "x"
164# endif
165#endif
166#if !defined PRIX32
167# ifdef UINT32_MAX
168# define PRIX32 "X"
169# endif
170#endif
171#ifdef INT64_MAX
172# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @INT64_MAX_EQ_LONG_MAX@)
173# define _PRI64_PREFIX "l"
174# elif defined _MSC_VER || defined __MINGW32__
175# define _PRI64_PREFIX "I64"
176# elif LONG_MAX >> 30 == 1
177# define _PRI64_PREFIX _LONG_LONG_FORMAT_PREFIX
178# endif
179# if !defined PRId64
180# define PRId64 _PRI64_PREFIX "d"
181# endif
182# if !defined PRIi64
183# define PRIi64 _PRI64_PREFIX "i"
184# endif
185#endif
186#ifdef UINT64_MAX
187# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @UINT64_MAX_EQ_ULONG_MAX@)
188# define _PRIu64_PREFIX "l"
189# elif defined _MSC_VER || defined __MINGW32__
190# define _PRIu64_PREFIX "I64"
191# elif ULONG_MAX >> 31 == 1
192# define _PRIu64_PREFIX _LONG_LONG_FORMAT_PREFIX
193# endif
194# if !defined PRIo64
195# define PRIo64 _PRIu64_PREFIX "o"
196# endif
197# if !defined PRIu64
198# define PRIu64 _PRIu64_PREFIX "u"
199# endif
200# if !defined PRIx64
201# define PRIx64 _PRIu64_PREFIX "x"
202# endif
203# if !defined PRIX64
204# define PRIX64 _PRIu64_PREFIX "X"
205# endif
206#endif
207
208#if !defined PRIdLEAST8
209# define PRIdLEAST8 "d"
210#endif
211#if !defined PRIiLEAST8
212# define PRIiLEAST8 "i"
213#endif
214#if !defined PRIoLEAST8
215# define PRIoLEAST8 "o"
216#endif
217#if !defined PRIuLEAST8
218# define PRIuLEAST8 "u"
219#endif
220#if !defined PRIxLEAST8
221# define PRIxLEAST8 "x"
222#endif
223#if !defined PRIXLEAST8
224# define PRIXLEAST8 "X"
225#endif
226#if !defined PRIdLEAST16
227# define PRIdLEAST16 "d"
228#endif
229#if !defined PRIiLEAST16
230# define PRIiLEAST16 "i"
231#endif
232#if !defined PRIoLEAST16
233# define PRIoLEAST16 "o"
234#endif
235#if !defined PRIuLEAST16
236# define PRIuLEAST16 "u"
237#endif
238#if !defined PRIxLEAST16
239# define PRIxLEAST16 "x"
240#endif
241#if !defined PRIXLEAST16
242# define PRIXLEAST16 "X"
243#endif
244#if !defined PRIdLEAST32
245# define PRIdLEAST32 "d"
246#endif
247#if !defined PRIiLEAST32
248# define PRIiLEAST32 "i"
249#endif
250#if !defined PRIoLEAST32
251# define PRIoLEAST32 "o"
252#endif
253#if !defined PRIuLEAST32
254# define PRIuLEAST32 "u"
255#endif
256#if !defined PRIxLEAST32
257# define PRIxLEAST32 "x"
258#endif
259#if !defined PRIXLEAST32
260# define PRIXLEAST32 "X"
261#endif
262#ifdef INT64_MAX
263# if !defined PRIdLEAST64
264# define PRIdLEAST64 PRId64
265# endif
266# if !defined PRIiLEAST64
267# define PRIiLEAST64 PRIi64
268# endif
269#endif
270#ifdef UINT64_MAX
271# if !defined PRIoLEAST64
272# define PRIoLEAST64 PRIo64
273# endif
274# if !defined PRIuLEAST64
275# define PRIuLEAST64 PRIu64
276# endif
277# if !defined PRIxLEAST64
278# define PRIxLEAST64 PRIx64
279# endif
280# if !defined PRIXLEAST64
281# define PRIXLEAST64 PRIX64
282# endif
283#endif
284
285#if !defined PRIdFAST8
286# if INT_FAST8_MAX > INT32_MAX
287# define PRIdFAST8 PRId64
288# else
289# define PRIdFAST8 "d"
290# endif
291#endif
292#if !defined PRIiFAST8
293# if INT_FAST8_MAX > INT32_MAX
294# define PRIiFAST8 PRIi64
295# else
296# define PRIiFAST8 "i"
297# endif
298#endif
299#if !defined PRIoFAST8
300# if UINT_FAST8_MAX > UINT32_MAX
301# define PRIoFAST8 PRIo64
302# else
303# define PRIoFAST8 "o"
304# endif
305#endif
306#if !defined PRIuFAST8
307# if UINT_FAST8_MAX > UINT32_MAX
308# define PRIuFAST8 PRIu64
309# else
310# define PRIuFAST8 "u"
311# endif
312#endif
313#if !defined PRIxFAST8
314# if UINT_FAST8_MAX > UINT32_MAX
315# define PRIxFAST8 PRIx64
316# else
317# define PRIxFAST8 "x"
318# endif
319#endif
320#if !defined PRIXFAST8
321# if UINT_FAST8_MAX > UINT32_MAX
322# define PRIXFAST8 PRIX64
323# else
324# define PRIXFAST8 "X"
325# endif
326#endif
327#if !defined PRIdFAST16
328# if INT_FAST16_MAX > INT32_MAX
329# define PRIdFAST16 PRId64
330# else
331# define PRIdFAST16 "d"
332# endif
333#endif
334#if !defined PRIiFAST16
335# if INT_FAST16_MAX > INT32_MAX
336# define PRIiFAST16 PRIi64
337# else
338# define PRIiFAST16 "i"
339# endif
340#endif
341#if !defined PRIoFAST16
342# if UINT_FAST16_MAX > UINT32_MAX
343# define PRIoFAST16 PRIo64
344# else
345# define PRIoFAST16 "o"
346# endif
347#endif
348#if !defined PRIuFAST16
349# if UINT_FAST16_MAX > UINT32_MAX
350# define PRIuFAST16 PRIu64
351# else
352# define PRIuFAST16 "u"
353# endif
354#endif
355#if !defined PRIxFAST16
356# if UINT_FAST16_MAX > UINT32_MAX
357# define PRIxFAST16 PRIx64
358# else
359# define PRIxFAST16 "x"
360# endif
361#endif
362#if !defined PRIXFAST16
363# if UINT_FAST16_MAX > UINT32_MAX
364# define PRIXFAST16 PRIX64
365# else
366# define PRIXFAST16 "X"
367# endif
368#endif
369#if !defined PRIdFAST32
370# if INT_FAST32_MAX > INT32_MAX
371# define PRIdFAST32 PRId64
372# else
373# define PRIdFAST32 "d"
374# endif
375#endif
376#if !defined PRIiFAST32
377# if INT_FAST32_MAX > INT32_MAX
378# define PRIiFAST32 PRIi64
379# else
380# define PRIiFAST32 "i"
381# endif
382#endif
383#if !defined PRIoFAST32
384# if UINT_FAST32_MAX > UINT32_MAX
385# define PRIoFAST32 PRIo64
386# else
387# define PRIoFAST32 "o"
388# endif
389#endif
390#if !defined PRIuFAST32
391# if UINT_FAST32_MAX > UINT32_MAX
392# define PRIuFAST32 PRIu64
393# else
394# define PRIuFAST32 "u"
395# endif
396#endif
397#if !defined PRIxFAST32
398# if UINT_FAST32_MAX > UINT32_MAX
399# define PRIxFAST32 PRIx64
400# else
401# define PRIxFAST32 "x"
402# endif
403#endif
404#if !defined PRIXFAST32
405# if UINT_FAST32_MAX > UINT32_MAX
406# define PRIXFAST32 PRIX64
407# else
408# define PRIXFAST32 "X"
409# endif
410#endif
411#ifdef INT64_MAX
412# if !defined PRIdFAST64
413# define PRIdFAST64 PRId64
414# endif
415# if !defined PRIiFAST64
416# define PRIiFAST64 PRIi64
417# endif
418#endif
419#ifdef UINT64_MAX
420# if !defined PRIoFAST64
421# define PRIoFAST64 PRIo64
422# endif
423# if !defined PRIuFAST64
424# define PRIuFAST64 PRIu64
425# endif
426# if !defined PRIxFAST64
427# define PRIxFAST64 PRIx64
428# endif
429# if !defined PRIXFAST64
430# define PRIXFAST64 PRIX64
431# endif
432#endif
433
434#if !defined PRIdMAX
435# if @INT32_MAX_LT_INTMAX_MAX@
436# define PRIdMAX PRId64
437# else
438# define PRIdMAX "ld"
439# endif
440#endif
441#if !defined PRIiMAX
442# if @INT32_MAX_LT_INTMAX_MAX@
443# define PRIiMAX PRIi64
444# else
445# define PRIiMAX "li"
446# endif
447#endif
448#if !defined PRIoMAX
449# if @UINT32_MAX_LT_UINTMAX_MAX@
450# define PRIoMAX PRIo64
451# else
452# define PRIoMAX "lo"
453# endif
454#endif
455#if !defined PRIuMAX
456# if @UINT32_MAX_LT_UINTMAX_MAX@
457# define PRIuMAX PRIu64
458# else
459# define PRIuMAX "lu"
460# endif
461#endif
462#if !defined PRIxMAX
463# if @UINT32_MAX_LT_UINTMAX_MAX@
464# define PRIxMAX PRIx64
465# else
466# define PRIxMAX "lx"
467# endif
468#endif
469#if !defined PRIXMAX
470# if @UINT32_MAX_LT_UINTMAX_MAX@
471# define PRIXMAX PRIX64
472# else
473# define PRIXMAX "lX"
474# endif
475#endif
476
477#if !defined PRIdPTR
478# ifdef INTPTR_MAX
479# define PRIdPTR @PRIPTR_PREFIX@ "d"
480# endif
481#endif
482#if !defined PRIiPTR
483# ifdef INTPTR_MAX
484# define PRIiPTR @PRIPTR_PREFIX@ "i"
485# endif
486#endif
487#if !defined PRIoPTR
488# ifdef UINTPTR_MAX
489# define PRIoPTR @PRIPTR_PREFIX@ "o"
490# endif
491#endif
492#if !defined PRIuPTR
493# ifdef UINTPTR_MAX
494# define PRIuPTR @PRIPTR_PREFIX@ "u"
495# endif
496#endif
497#if !defined PRIxPTR
498# ifdef UINTPTR_MAX
499# define PRIxPTR @PRIPTR_PREFIX@ "x"
500# endif
501#endif
502#if !defined PRIXPTR
503# ifdef UINTPTR_MAX
504# define PRIXPTR @PRIPTR_PREFIX@ "X"
505# endif
506#endif
507
508#if !defined SCNd8
509# ifdef INT8_MAX
510# define SCNd8 "hhd"
511# endif
512#endif
513#if !defined SCNi8
514# ifdef INT8_MAX
515# define SCNi8 "hhi"
516# endif
517#endif
518#if !defined SCNo8
519# ifdef UINT8_MAX
520# define SCNo8 "hho"
521# endif
522#endif
523#if !defined SCNu8
524# ifdef UINT8_MAX
525# define SCNu8 "hhu"
526# endif
527#endif
528#if !defined SCNx8
529# ifdef UINT8_MAX
530# define SCNx8 "hhx"
531# endif
532#endif
533#if !defined SCNd16
534# ifdef INT16_MAX
535# define SCNd16 "hd"
536# endif
537#endif
538#if !defined SCNi16
539# ifdef INT16_MAX
540# define SCNi16 "hi"
541# endif
542#endif
543#if !defined SCNo16
544# ifdef UINT16_MAX
545# define SCNo16 "ho"
546# endif
547#endif
548#if !defined SCNu16
549# ifdef UINT16_MAX
550# define SCNu16 "hu"
551# endif
552#endif
553#if !defined SCNx16
554# ifdef UINT16_MAX
555# define SCNx16 "hx"
556# endif
557#endif
558#if !defined SCNd32
559# ifdef INT32_MAX
560# define SCNd32 "d"
561# endif
562#endif
563#if !defined SCNi32
564# ifdef INT32_MAX
565# define SCNi32 "i"
566# endif
567#endif
568#if !defined SCNo32
569# ifdef UINT32_MAX
570# define SCNo32 "o"
571# endif
572#endif
573#if !defined SCNu32
574# ifdef UINT32_MAX
575# define SCNu32 "u"
576# endif
577#endif
578#if !defined SCNx32
579# ifdef UINT32_MAX
580# define SCNx32 "x"
581# endif
582#endif
583#ifdef INT64_MAX
584# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @INT64_MAX_EQ_LONG_MAX@)
585# define _SCN64_PREFIX "l"
586# elif defined _MSC_VER || defined __MINGW32__
587# define _SCN64_PREFIX "I64"
588# elif LONG_MAX >> 30 == 1
589# define _SCN64_PREFIX _LONG_LONG_FORMAT_PREFIX
590# endif
591# if !defined SCNd64
592# define SCNd64 _SCN64_PREFIX "d"
593# endif
594# if !defined SCNi64
595# define SCNi64 _SCN64_PREFIX "i"
596# endif
597#endif
598#ifdef UINT64_MAX
599# if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @UINT64_MAX_EQ_ULONG_MAX@)
600# define _SCNu64_PREFIX "l"
601# elif defined _MSC_VER || defined __MINGW32__
602# define _SCNu64_PREFIX "I64"
603# elif ULONG_MAX >> 31 == 1
604# define _SCNu64_PREFIX _LONG_LONG_FORMAT_PREFIX
605# endif
606# if !defined SCNo64
607# define SCNo64 _SCNu64_PREFIX "o"
608# endif
609# if !defined SCNu64
610# define SCNu64 _SCNu64_PREFIX "u"
611# endif
612# if !defined SCNx64
613# define SCNx64 _SCNu64_PREFIX "x"
614# endif
615#endif
616
617#if !defined SCNdLEAST8
618# define SCNdLEAST8 "hhd"
619#endif
620#if !defined SCNiLEAST8
621# define SCNiLEAST8 "hhi"
622#endif
623#if !defined SCNoLEAST8
624# define SCNoLEAST8 "hho"
625#endif
626#if !defined SCNuLEAST8
627# define SCNuLEAST8 "hhu"
628#endif
629#if !defined SCNxLEAST8
630# define SCNxLEAST8 "hhx"
631#endif
632#if !defined SCNdLEAST16
633# define SCNdLEAST16 "hd"
634#endif
635#if !defined SCNiLEAST16
636# define SCNiLEAST16 "hi"
637#endif
638#if !defined SCNoLEAST16
639# define SCNoLEAST16 "ho"
640#endif
641#if !defined SCNuLEAST16
642# define SCNuLEAST16 "hu"
643#endif
644#if !defined SCNxLEAST16
645# define SCNxLEAST16 "hx"
646#endif
647#if !defined SCNdLEAST32
648# define SCNdLEAST32 "d"
649#endif
650#if !defined SCNiLEAST32
651# define SCNiLEAST32 "i"
652#endif
653#if !defined SCNoLEAST32
654# define SCNoLEAST32 "o"
655#endif
656#if !defined SCNuLEAST32
657# define SCNuLEAST32 "u"
658#endif
659#if !defined SCNxLEAST32
660# define SCNxLEAST32 "x"
661#endif
662#ifdef INT64_MAX
663# if !defined SCNdLEAST64
664# define SCNdLEAST64 SCNd64
665# endif
666# if !defined SCNiLEAST64
667# define SCNiLEAST64 SCNi64
668# endif
669#endif
670#ifdef UINT64_MAX
671# if !defined SCNoLEAST64
672# define SCNoLEAST64 SCNo64
673# endif
674# if !defined SCNuLEAST64
675# define SCNuLEAST64 SCNu64
676# endif
677# if !defined SCNxLEAST64
678# define SCNxLEAST64 SCNx64
679# endif
680#endif
681
682#if !defined SCNdFAST8
683# if INT_FAST8_MAX > INT32_MAX
684# define SCNdFAST8 SCNd64
685# elif INT_FAST8_MAX == 0x7fff
686# define SCNdFAST8 "hd"
687# elif INT_FAST8_MAX == 0x7f
688# define SCNdFAST8 "hhd"
689# else
690# define SCNdFAST8 "d"
691# endif
692#endif
693#if !defined SCNiFAST8
694# if INT_FAST8_MAX > INT32_MAX
695# define SCNiFAST8 SCNi64
696# elif INT_FAST8_MAX == 0x7fff
697# define SCNiFAST8 "hi"
698# elif INT_FAST8_MAX == 0x7f
699# define SCNiFAST8 "hhi"
700# else
701# define SCNiFAST8 "i"
702# endif
703#endif
704#if !defined SCNoFAST8
705# if UINT_FAST8_MAX > UINT32_MAX
706# define SCNoFAST8 SCNo64
707# elif UINT_FAST8_MAX == 0xffff
708# define SCNoFAST8 "ho"
709# elif UINT_FAST8_MAX == 0xff
710# define SCNoFAST8 "hho"
711# else
712# define SCNoFAST8 "o"
713# endif
714#endif
715#if !defined SCNuFAST8
716# if UINT_FAST8_MAX > UINT32_MAX
717# define SCNuFAST8 SCNu64
718# elif UINT_FAST8_MAX == 0xffff
719# define SCNuFAST8 "hu"
720# elif UINT_FAST8_MAX == 0xff
721# define SCNuFAST8 "hhu"
722# else
723# define SCNuFAST8 "u"
724# endif
725#endif
726#if !defined SCNxFAST8
727# if UINT_FAST8_MAX > UINT32_MAX
728# define SCNxFAST8 SCNx64
729# elif UINT_FAST8_MAX == 0xffff
730# define SCNxFAST8 "hx"
731# elif UINT_FAST8_MAX == 0xff
732# define SCNxFAST8 "hhx"
733# else
734# define SCNxFAST8 "x"
735# endif
736#endif
737#if !defined SCNdFAST16
738# if INT_FAST16_MAX > INT32_MAX
739# define SCNdFAST16 SCNd64
740# elif INT_FAST16_MAX == 0x7fff
741# define SCNdFAST16 "hd"
742# else
743# define SCNdFAST16 "d"
744# endif
745#endif
746#if !defined SCNiFAST16
747# if INT_FAST16_MAX > INT32_MAX
748# define SCNiFAST16 SCNi64
749# elif INT_FAST16_MAX == 0x7fff
750# define SCNiFAST16 "hi"
751# else
752# define SCNiFAST16 "i"
753# endif
754#endif
755#if !defined SCNoFAST16
756# if UINT_FAST16_MAX > UINT32_MAX
757# define SCNoFAST16 SCNo64
758# elif UINT_FAST16_MAX == 0xffff
759# define SCNoFAST16 "ho"
760# else
761# define SCNoFAST16 "o"
762# endif
763#endif
764#if !defined SCNuFAST16
765# if UINT_FAST16_MAX > UINT32_MAX
766# define SCNuFAST16 SCNu64
767# elif UINT_FAST16_MAX == 0xffff
768# define SCNuFAST16 "hu"
769# else
770# define SCNuFAST16 "u"
771# endif
772#endif
773#if !defined SCNxFAST16
774# if UINT_FAST16_MAX > UINT32_MAX
775# define SCNxFAST16 SCNx64
776# elif UINT_FAST16_MAX == 0xffff
777# define SCNxFAST16 "hx"
778# else
779# define SCNxFAST16 "x"
780# endif
781#endif
782#if !defined SCNdFAST32
783# if INT_FAST32_MAX > INT32_MAX
784# define SCNdFAST32 SCNd64
785# else
786# define SCNdFAST32 "d"
787# endif
788#endif
789#if !defined SCNiFAST32
790# if INT_FAST32_MAX > INT32_MAX
791# define SCNiFAST32 SCNi64
792# else
793# define SCNiFAST32 "i"
794# endif
795#endif
796#if !defined SCNoFAST32
797# if UINT_FAST32_MAX > UINT32_MAX
798# define SCNoFAST32 SCNo64
799# else
800# define SCNoFAST32 "o"
801# endif
802#endif
803#if !defined SCNuFAST32
804# if UINT_FAST32_MAX > UINT32_MAX
805# define SCNuFAST32 SCNu64
806# else
807# define SCNuFAST32 "u"
808# endif
809#endif
810#if !defined SCNxFAST32
811# if UINT_FAST32_MAX > UINT32_MAX
812# define SCNxFAST32 SCNx64
813# else
814# define SCNxFAST32 "x"
815# endif
816#endif
817#ifdef INT64_MAX
818# if !defined SCNdFAST64
819# define SCNdFAST64 SCNd64
820# endif
821# if !defined SCNiFAST64
822# define SCNiFAST64 SCNi64
823# endif
824#endif
825#ifdef UINT64_MAX
826# if !defined SCNoFAST64
827# define SCNoFAST64 SCNo64
828# endif
829# if !defined SCNuFAST64
830# define SCNuFAST64 SCNu64
831# endif
832# if !defined SCNxFAST64
833# define SCNxFAST64 SCNx64
834# endif
835#endif
836
837#if !defined SCNdMAX
838# if @INT32_MAX_LT_INTMAX_MAX@
839# define SCNdMAX SCNd64
840# else
841# define SCNdMAX "ld"
842# endif
843#endif
844#if !defined SCNiMAX
845# if @INT32_MAX_LT_INTMAX_MAX@
846# define SCNiMAX SCNi64
847# else
848# define SCNiMAX "li"
849# endif
850#endif
851#if !defined SCNoMAX
852# if @UINT32_MAX_LT_UINTMAX_MAX@
853# define SCNoMAX SCNo64
854# else
855# define SCNoMAX "lo"
856# endif
857#endif
858#if !defined SCNuMAX
859# if @UINT32_MAX_LT_UINTMAX_MAX@
860# define SCNuMAX SCNu64
861# else
862# define SCNuMAX "lu"
863# endif
864#endif
865#if !defined SCNxMAX
866# if @UINT32_MAX_LT_UINTMAX_MAX@
867# define SCNxMAX SCNx64
868# else
869# define SCNxMAX "lx"
870# endif
871#endif
872
873#if !defined SCNdPTR
874# ifdef INTPTR_MAX
875# define SCNdPTR @PRIPTR_PREFIX@ "d"
876# endif
877#endif
878#if !defined SCNiPTR
879# ifdef INTPTR_MAX
880# define SCNiPTR @PRIPTR_PREFIX@ "i"
881# endif
882#endif
883#if !defined SCNoPTR
884# ifdef UINTPTR_MAX
885# define SCNoPTR @PRIPTR_PREFIX@ "o"
886# endif
887#endif
888#if !defined SCNuPTR
889# ifdef UINTPTR_MAX
890# define SCNuPTR @PRIPTR_PREFIX@ "u"
891# endif
892#endif
893#if !defined SCNxPTR
894# ifdef UINTPTR_MAX
895# define SCNxPTR @PRIPTR_PREFIX@ "x"
896# endif
897#endif
898
899/* 7.8.2 Functions for greatest-width integer types */
900
901#ifdef __cplusplus
902extern "C" {
903#endif
904
905#if @GNULIB_IMAXABS@
906# if !@HAVE_DECL_IMAXABS@
907extern intmax_t imaxabs (intmax_t);
908# endif
909#elif defined GNULIB_POSIXCHECK
910# undef imaxabs
911# if HAVE_RAW_DECL_IMAXABS
912_GL_WARN_ON_USE (imaxabs, "imaxabs is unportable - "
913 "use gnulib module imaxabs for portability");
914# endif
915#endif
916
917#if @GNULIB_IMAXDIV@
918# if !@HAVE_IMAXDIV_T@
919# if !GNULIB_defined_imaxdiv_t
920typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
921# define GNULIB_defined_imaxdiv_t 1
922# endif
923# endif
924# if !@HAVE_DECL_IMAXDIV@
925extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
926# endif
927#elif defined GNULIB_POSIXCHECK
928# undef imaxdiv
929# if HAVE_RAW_DECL_IMAXDIV
930_GL_WARN_ON_USE (imaxdiv, "imaxdiv is unportable - "
931 "use gnulib module imaxdiv for portability");
932# endif
933#endif
934
935#if @GNULIB_STRTOIMAX@
936# if @REPLACE_STRTOIMAX@
937# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
938# undef strtoimax
939# define strtoimax rpl_strtoimax
940# endif
941_GL_FUNCDECL_RPL (strtoimax, intmax_t,
942 (const char *restrict, char **restrict, int)
943 _GL_ARG_NONNULL ((1)));
944_GL_CXXALIAS_RPL (strtoimax, intmax_t,
945 (const char *restrict, char **restrict, int));
946# else
947# if !@HAVE_DECL_STRTOIMAX@
948# undef strtoimax
949_GL_FUNCDECL_SYS (strtoimax, intmax_t,
950 (const char *restrict, char **restrict, int)
951 _GL_ARG_NONNULL ((1)));
952# endif
953_GL_CXXALIAS_SYS (strtoimax, intmax_t,
954 (const char *restrict, char **restrict, int));
955# endif
956_GL_CXXALIASWARN (strtoimax);
957#elif defined GNULIB_POSIXCHECK
958# undef strtoimax
959# if HAVE_RAW_DECL_STRTOIMAX
960_GL_WARN_ON_USE (strtoimax, "strtoimax is unportable - "
961 "use gnulib module strtoimax for portability");
962# endif
963#endif
964
965#if @GNULIB_STRTOUMAX@
966# if @REPLACE_STRTOUMAX@
967# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
968# undef strtoumax
969# define strtoumax rpl_strtoumax
970# endif
971_GL_FUNCDECL_RPL (strtoumax, uintmax_t,
972 (const char *restrict, char **restrict, int)
973 _GL_ARG_NONNULL ((1)));
974_GL_CXXALIAS_RPL (strtoumax, uintmax_t,
975 (const char *restrict, char **restrict, int));
976# else
977# if !@HAVE_DECL_STRTOUMAX@
978# undef strtoumax
979_GL_FUNCDECL_SYS (strtoumax, uintmax_t,
980 (const char *restrict, char **restrict, int)
981 _GL_ARG_NONNULL ((1)));
982# endif
983_GL_CXXALIAS_SYS (strtoumax, uintmax_t,
984 (const char *restrict, char **restrict, int));
985# endif
986_GL_CXXALIASWARN (strtoumax);
987#elif defined GNULIB_POSIXCHECK
988# undef strtoumax
989# if HAVE_RAW_DECL_STRTOUMAX
990_GL_WARN_ON_USE (strtoumax, "strtoumax is unportable - "
991 "use gnulib module strtoumax for portability");
992# endif
993#endif
994
995/* Don't bother defining or declaring wcstoimax and wcstoumax, since
996 wide-character functions like this are hardly ever useful. */
997
998#ifdef __cplusplus
999}
1000#endif
1001
1002#endif /* !defined INTTYPES_H && !defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H */
diff --git a/gl/itold.c b/gl/itold.c
index 9aabc7e..0ef4464 100644
--- a/gl/itold.c
+++ b/gl/itold.c
@@ -1,19 +1,19 @@
1/* Replacement for 'int' to 'long double' conversion routine. 1/* Replacement for 'int' to 'long double' conversion routine.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011. 3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/langinfo.in.h b/gl/langinfo.in.h
index 5388ce6..c7555a6 100644
--- a/gl/langinfo.in.h
+++ b/gl/langinfo.in.h
@@ -1,22 +1,22 @@
1/* Substitute for and wrapper around <langinfo.h>. 1/* Substitute for and wrapper around <langinfo.h>.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* 17/*
18 * POSIX <langinfo.h> for platforms that lack it or have an incomplete one. 18 * POSIX <langinfo.h> for platforms that lack it or have an incomplete one.
19 * <http://www.opengroup.org/onlinepubs/9699919799/basedefs/langinfo.h.html> 19 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/langinfo.h.html>
20 */ 20 */
21 21
22#ifndef _@GUARD_PREFIX@_LANGINFO_H 22#ifndef _@GUARD_PREFIX@_LANGINFO_H
@@ -49,7 +49,10 @@ typedef int nl_item;
49# define CODESET 10000 49# define CODESET 10000
50/* nl_langinfo items of the LC_NUMERIC category */ 50/* nl_langinfo items of the LC_NUMERIC category */
51# define RADIXCHAR 10001 51# define RADIXCHAR 10001
52# define DECIMAL_POINT RADIXCHAR
52# define THOUSEP 10002 53# define THOUSEP 10002
54# define THOUSANDS_SEP THOUSEP
55# define GROUPING 10114
53/* nl_langinfo items of the LC_TIME category */ 56/* nl_langinfo items of the LC_TIME category */
54# define D_T_FMT 10003 57# define D_T_FMT 10003
55# define D_FMT 10004 58# define D_FMT 10004
@@ -83,6 +86,18 @@ typedef int nl_item;
83# define MON_10 (MON_1 + 9) 86# define MON_10 (MON_1 + 9)
84# define MON_11 (MON_1 + 10) 87# define MON_11 (MON_1 + 10)
85# define MON_12 (MON_1 + 11) 88# define MON_12 (MON_1 + 11)
89# define ALTMON_1 10200
90# define ALTMON_2 (ALTMON_1 + 1)
91# define ALTMON_3 (ALTMON_1 + 2)
92# define ALTMON_4 (ALTMON_1 + 3)
93# define ALTMON_5 (ALTMON_1 + 4)
94# define ALTMON_6 (ALTMON_1 + 5)
95# define ALTMON_7 (ALTMON_1 + 6)
96# define ALTMON_8 (ALTMON_1 + 7)
97# define ALTMON_9 (ALTMON_1 + 8)
98# define ALTMON_10 (ALTMON_1 + 9)
99# define ALTMON_11 (ALTMON_1 + 10)
100# define ALTMON_12 (ALTMON_1 + 11)
86# define ABMON_1 10035 101# define ABMON_1 10035
87# define ABMON_2 (ABMON_1 + 1) 102# define ABMON_2 (ABMON_1 + 1)
88# define ABMON_3 (ABMON_1 + 2) 103# define ABMON_3 (ABMON_1 + 2)
@@ -102,6 +117,21 @@ typedef int nl_item;
102# define ALT_DIGITS 10051 117# define ALT_DIGITS 10051
103/* nl_langinfo items of the LC_MONETARY category */ 118/* nl_langinfo items of the LC_MONETARY category */
104# define CRNCYSTR 10052 119# define CRNCYSTR 10052
120# define CURRENCY_SYMBOL CRNCYSTR
121# define INT_CURR_SYMBOL 10100
122# define MON_DECIMAL_POINT 10101
123# define MON_THOUSANDS_SEP 10102
124# define MON_GROUPING 10103
125# define POSITIVE_SIGN 10104
126# define NEGATIVE_SIGN 10105
127# define FRAC_DIGITS 10106
128# define INT_FRAC_DIGITS 10107
129# define P_CS_PRECEDES 10108
130# define N_CS_PRECEDES 10109
131# define P_SEP_BY_SPACE 10110
132# define N_SEP_BY_SPACE 10111
133# define P_SIGN_POSN 10112
134# define N_SIGN_POSN 10113
105/* nl_langinfo items of the LC_MESSAGES category */ 135/* nl_langinfo items of the LC_MESSAGES category */
106# define YESEXPR 10053 136# define YESEXPR 10053
107# define NOEXPR 10054 137# define NOEXPR 10054
@@ -120,6 +150,22 @@ typedef int nl_item;
120# define GNULIB_defined_T_FMT_AMPM 1 150# define GNULIB_defined_T_FMT_AMPM 1
121# endif 151# endif
122 152
153# if !@HAVE_LANGINFO_ALTMON@
154# define ALTMON_1 10200
155# define ALTMON_2 (ALTMON_1 + 1)
156# define ALTMON_3 (ALTMON_1 + 2)
157# define ALTMON_4 (ALTMON_1 + 3)
158# define ALTMON_5 (ALTMON_1 + 4)
159# define ALTMON_6 (ALTMON_1 + 5)
160# define ALTMON_7 (ALTMON_1 + 6)
161# define ALTMON_8 (ALTMON_1 + 7)
162# define ALTMON_9 (ALTMON_1 + 8)
163# define ALTMON_10 (ALTMON_1 + 9)
164# define ALTMON_11 (ALTMON_1 + 10)
165# define ALTMON_12 (ALTMON_1 + 11)
166# define GNULIB_defined_ALTMON 1
167# endif
168
123# if !@HAVE_LANGINFO_ERA@ 169# if !@HAVE_LANGINFO_ERA@
124# define ERA 10047 170# define ERA 10047
125# define ERA_D_FMT 10048 171# define ERA_D_FMT 10048
diff --git a/gl/lc-charset-dispatch.c b/gl/lc-charset-dispatch.c
new file mode 100644
index 0000000..cd74466
--- /dev/null
+++ b/gl/lc-charset-dispatch.c
@@ -0,0 +1,82 @@
1/* Dispatching based on the current locale's character encoding.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2018. */
18
19#include <config.h>
20
21/* Specification. */
22#include "lc-charset-dispatch.h"
23
24#if GNULIB_defined_mbstate_t
25
26# include "localcharset.h"
27# include "streq.h"
28
29# if GNULIB_WCHAR_SINGLE_LOCALE
30/* When we know that the locale does not change, provide a speedup by
31 caching the value of locale_encoding_classification. */
32# define locale_encoding_classification_cached locale_encoding_classification
33# else
34/* By default, don't make assumptions, hence no caching. */
35# define locale_encoding_classification_uncached locale_encoding_classification
36# endif
37
38# if GNULIB_WCHAR_SINGLE_LOCALE
39static inline
40# endif
41enc_t
42locale_encoding_classification_uncached (void)
43{
44 const char *encoding = locale_charset ();
45 if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
46 return enc_utf8;
47 if (STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
48 return enc_eucjp;
49 if (STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
50 || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
51 || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
52 return enc_94;
53 if (STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
54 return enc_euctw;
55 if (STREQ_OPT (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
56 return enc_gb18030;
57 if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
58 return enc_sjis;
59 return enc_other;
60}
61
62# if GNULIB_WCHAR_SINGLE_LOCALE
63
64static int cached_locale_enc = -1;
65
66enc_t
67locale_encoding_classification_cached (void)
68{
69 if (cached_locale_enc < 0)
70 cached_locale_enc = locale_encoding_classification_uncached ();
71 return cached_locale_enc;
72}
73
74# endif
75
76#else
77
78/* This declaration is solely to ensure that after preprocessing
79 this file is never empty. */
80typedef int dummy;
81
82#endif
diff --git a/gl/lc-charset-dispatch.h b/gl/lc-charset-dispatch.h
new file mode 100644
index 0000000..c82b6a6
--- /dev/null
+++ b/gl/lc-charset-dispatch.h
@@ -0,0 +1,40 @@
1/* Dispatching based on the current locale's character encoding.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2018. */
18
19#include <wchar.h>
20
21#if GNULIB_defined_mbstate_t
22
23/* A classification of special values of the encoding of the current locale. */
24typedef enum
25 {
26 enc_other, /* other */
27 enc_utf8, /* UTF-8 */
28 enc_eucjp, /* EUC-JP */
29 enc_94, /* EUC-KR, GB2312, BIG5 */
30 enc_euctw, /* EUC-TW */
31 enc_gb18030, /* GB18030 */
32 enc_sjis /* SJIS */
33 }
34 enc_t;
35
36/* Returns a classification of special values of the encoding of the current
37 locale. */
38extern enc_t locale_encoding_classification (void);
39
40#endif
diff --git a/gl/libc-config.h b/gl/libc-config.h
new file mode 100644
index 0000000..1d28e58
--- /dev/null
+++ b/gl/libc-config.h
@@ -0,0 +1,202 @@
1/* System definitions for code taken from the GNU C Library
2
3 Copyright 2017-2023 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this program; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19/* Written by Paul Eggert. */
20
21/* This is intended to be a good-enough substitute for glibc system
22 macros like those defined in <sys/cdefs.h>, so that Gnulib code
23 shared with glibc can do this as the first #include:
24
25 #ifndef _LIBC
26 # include <libc-config.h>
27 #endif
28
29 When compiled as part of glibc this is a no-op; when compiled as
30 part of Gnulib this includes Gnulib's <config.h> and defines macros
31 that glibc library code would normally assume.
32
33 Note: This header file MUST NOT be included by public header files
34 of Gnulib. */
35
36#include <config.h>
37
38/* On glibc this includes <features.h> and <sys/cdefs.h> and #defines
39 _FEATURES_H, __WORDSIZE, and __set_errno. On FreeBSD 11 and
40 DragonFlyBSD 5.9 it includes <sys/cdefs.h> which defines __nonnull.
41 Elsewhere it is harmless. */
42#include <errno.h>
43
44/* From glibc <errno.h>. */
45#ifndef __set_errno
46# define __set_errno(val) (errno = (val))
47#endif
48
49/* From glibc <features.h>. */
50
51#ifndef __GNUC_PREREQ
52# if defined __GNUC__ && defined __GNUC_MINOR__
53# define __GNUC_PREREQ(maj, min) ((maj) < __GNUC__ + ((min) <= __GNUC_MINOR__))
54# else
55# define __GNUC_PREREQ(maj, min) 0
56# endif
57#endif
58
59#ifndef __glibc_clang_prereq
60# if defined __clang_major__ && defined __clang_minor__
61# ifdef __apple_build_version__
62/* Apple for some reason renumbers __clang_major__ and __clang_minor__.
63 Gnulib code uses only __glibc_clang_prereq (3, 5); map it to
64 6000000 <= __apple_build_version__. Support for other calls to
65 __glibc_clang_prereq can be added here as needed. */
66# define __glibc_clang_prereq(maj, min) \
67 ((maj) == 3 && (min) == 5 ? 6000000 <= __apple_build_version__ : 0)
68# else
69# define __glibc_clang_prereq(maj, min) \
70 ((maj) < __clang_major__ + ((min) <= __clang_minor__))
71# endif
72# else
73# define __glibc_clang_prereq(maj, min) 0
74# endif
75#endif
76
77#ifndef __attribute_nonnull__
78/* <sys/cdefs.h> either does not exist, or is too old for Gnulib.
79 Prepare to include <cdefs.h>, which is Gnulib's version of a
80 more-recent glibc <sys/cdefs.h>. */
81
82/* Define _FEATURES_H so that <cdefs.h> does not include <features.h>. */
83# ifndef _FEATURES_H
84# define _FEATURES_H 1
85# endif
86/* Define __GNULIB_CDEFS so that <cdefs.h> does not attempt to include
87 nonexistent files. */
88# define __GNULIB_CDEFS
89/* Undef the macros unconditionally defined by our copy of glibc
90 <sys/cdefs.h>, so that they do not clash with any system-defined
91 versions. */
92# undef _SYS_CDEFS_H
93# undef __ASMNAME
94# undef __ASMNAME2
95# undef __BEGIN_DECLS
96# undef __CONCAT
97# undef __END_DECLS
98# undef __HAVE_GENERIC_SELECTION
99# undef __LDBL_COMPAT
100# undef __LDBL_REDIR
101# undef __LDBL_REDIR1
102# undef __LDBL_REDIR1_DECL
103# undef __LDBL_REDIR1_NTH
104# undef __LDBL_REDIR2_DECL
105# undef __LDBL_REDIR_DECL
106# undef __LDBL_REDIR_NTH
107# undef __LEAF
108# undef __LEAF_ATTR
109# undef __NTH
110# undef __NTHNL
111# undef __REDIRECT
112# undef __REDIRECT_LDBL
113# undef __REDIRECT_NTH
114# undef __REDIRECT_NTHNL
115# undef __REDIRECT_NTH_LDBL
116# undef __STRING
117# undef __THROW
118# undef __THROWNL
119# undef __attr_access
120# undef __attr_access_none
121# undef __attr_dealloc
122# undef __attr_dealloc_free
123# undef __attribute__
124# undef __attribute_alloc_align__
125# undef __attribute_alloc_size__
126# undef __attribute_artificial__
127# undef __attribute_const__
128# undef __attribute_deprecated__
129# undef __attribute_deprecated_msg__
130# undef __attribute_format_arg__
131# undef __attribute_format_strfmon__
132# undef __attribute_malloc__
133# undef __attribute_maybe_unused__
134# undef __attribute_noinline__
135# undef __attribute_nonstring__
136# undef __attribute_pure__
137# undef __attribute_returns_twice__
138# undef __attribute_used__
139# undef __attribute_warn_unused_result__
140# undef __bos
141# undef __bos0
142# undef __errordecl
143# undef __extension__
144# undef __extern_always_inline
145# undef __extern_inline
146# undef __flexarr
147# undef __fortified_attr_access
148# undef __fortify_function
149# undef __glibc_c99_flexarr_available
150# undef __glibc_fortify
151# undef __glibc_fortify_n
152# undef __glibc_has_attribute
153# undef __glibc_has_builtin
154# undef __glibc_has_extension
155# undef __glibc_likely
156# undef __glibc_macro_warning
157# undef __glibc_macro_warning1
158# undef __glibc_objsize
159# undef __glibc_objsize0
160# undef __glibc_safe_len_cond
161# undef __glibc_safe_or_unknown_len
162# undef __glibc_unlikely
163# undef __glibc_unsafe_len
164# undef __glibc_unsigned_or_positive
165# undef __inline
166# undef __ptr_t
167# undef __restrict
168# undef __restrict_arr
169# undef __va_arg_pack
170# undef __va_arg_pack_len
171# undef __warnattr
172# undef __wur
173
174/* Include our copy of glibc <sys/cdefs.h>. */
175# include <cdefs.h>
176
177/* <cdefs.h> __inline is too pessimistic for non-GCC. */
178# undef __inline
179# ifndef HAVE___INLINE
180# if 199901 <= __STDC_VERSION__ || defined inline
181# define __inline inline
182# else
183# define __inline
184# endif
185# endif
186
187#endif /* defined __glibc_likely */
188
189
190/* A substitute for glibc <libc-symbols.h>, good enough for Gnulib. */
191#define attribute_hidden
192#define libc_hidden_proto(name)
193#define libc_hidden_def(name)
194#define libc_hidden_weak(name)
195#define libc_hidden_ver(local, name)
196#define strong_alias(name, aliasname)
197#define weak_alias(name, aliasname)
198
199/* A substitute for glibc <shlib-compat.h>, good enough for Gnulib. */
200#define SHLIB_COMPAT(lib, introduced, obsoleted) 0
201#define compat_symbol(lib, local, symbol, version) extern int dummy
202#define versioned_symbol(lib, local, symbol, version) extern int dummy
diff --git a/gl/limits.in.h b/gl/limits.in.h
new file mode 100644
index 0000000..eaeac47
--- /dev/null
+++ b/gl/limits.in.h
@@ -0,0 +1,131 @@
1/* A GNU-like <limits.h>.
2
3 Copyright 2016-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@
20#endif
21@PRAGMA_COLUMNS@
22
23#if defined _GL_ALREADY_INCLUDING_LIMITS_H
24/* Special invocation convention:
25 On Haiku/x86_64, we have a sequence of nested includes
26 <limits.h> -> <syslimits.h> -> <limits.h>.
27 In this situation, LONG_MAX and INT_MAX are not yet defined,
28 therefore we should not attempt to define LONG_BIT. */
29
30#@INCLUDE_NEXT@ @NEXT_LIMITS_H@
31
32#else
33/* Normal invocation convention. */
34
35#ifndef _@GUARD_PREFIX@_LIMITS_H
36
37# define _GL_ALREADY_INCLUDING_LIMITS_H
38
39/* The include_next requires a split double-inclusion guard. */
40# @INCLUDE_NEXT@ @NEXT_LIMITS_H@
41
42# undef _GL_ALREADY_INCLUDING_LIMITS_H
43
44#ifndef _@GUARD_PREFIX@_LIMITS_H
45#define _@GUARD_PREFIX@_LIMITS_H
46
47#ifndef LLONG_MIN
48# if defined LONG_LONG_MIN /* HP-UX 11.31 */
49# define LLONG_MIN LONG_LONG_MIN
50# elif defined LONGLONG_MIN /* IRIX 6.5 */
51# define LLONG_MIN LONGLONG_MIN
52# elif defined __GNUC__
53# define LLONG_MIN (- __LONG_LONG_MAX__ - 1LL)
54# endif
55#endif
56#ifndef LLONG_MAX
57# if defined LONG_LONG_MAX /* HP-UX 11.31 */
58# define LLONG_MAX LONG_LONG_MAX
59# elif defined LONGLONG_MAX /* IRIX 6.5 */
60# define LLONG_MAX LONGLONG_MAX
61# elif defined __GNUC__
62# define LLONG_MAX __LONG_LONG_MAX__
63# endif
64#endif
65#ifndef ULLONG_MAX
66# if defined ULONG_LONG_MAX /* HP-UX 11.31 */
67# define ULLONG_MAX ULONG_LONG_MAX
68# elif defined ULONGLONG_MAX /* IRIX 6.5 */
69# define ULLONG_MAX ULONGLONG_MAX
70# elif defined __GNUC__
71# define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1ULL)
72# endif
73#endif
74
75/* The number of usable bits in an unsigned or signed integer type
76 with minimum value MIN and maximum value MAX, as an int expression
77 suitable in #if. Cover all known practical hosts. This
78 implementation exploits the fact that MAX is 1 less than a power of
79 2, and merely counts the number of 1 bits in MAX; "COBn" means
80 "count the number of 1 bits in the low-order n bits"). */
81#define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max))
82#define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n))
83#define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n))
84#define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n))
85#define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n))
86#define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n))
87#define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1))
88
89#ifndef WORD_BIT
90/* Assume 'int' is 32 bits wide. */
91# define WORD_BIT 32
92#endif
93#ifndef LONG_BIT
94/* Assume 'long' is 32 or 64 bits wide. */
95# if LONG_MAX == INT_MAX
96# define LONG_BIT 32
97# else
98# define LONG_BIT 64
99# endif
100#endif
101
102/* Macros specified by C23 and by ISO/IEC TS 18661-1:2014. */
103
104#if (! defined ULLONG_WIDTH \
105 && (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__ \
106 || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
107# define CHAR_WIDTH _GL_INTEGER_WIDTH (CHAR_MIN, CHAR_MAX)
108# define SCHAR_WIDTH _GL_INTEGER_WIDTH (SCHAR_MIN, SCHAR_MAX)
109# define UCHAR_WIDTH _GL_INTEGER_WIDTH (0, UCHAR_MAX)
110# define SHRT_WIDTH _GL_INTEGER_WIDTH (SHRT_MIN, SHRT_MAX)
111# define USHRT_WIDTH _GL_INTEGER_WIDTH (0, USHRT_MAX)
112# define INT_WIDTH _GL_INTEGER_WIDTH (INT_MIN, INT_MAX)
113# define UINT_WIDTH _GL_INTEGER_WIDTH (0, UINT_MAX)
114# define LONG_WIDTH _GL_INTEGER_WIDTH (LONG_MIN, LONG_MAX)
115# define ULONG_WIDTH _GL_INTEGER_WIDTH (0, ULONG_MAX)
116# define LLONG_WIDTH _GL_INTEGER_WIDTH (LLONG_MIN, LLONG_MAX)
117# define ULLONG_WIDTH _GL_INTEGER_WIDTH (0, ULLONG_MAX)
118#endif
119
120/* Macros specified by C23. */
121
122#if (! defined BOOL_WIDTH \
123 && (defined _GNU_SOURCE \
124 || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
125# define BOOL_MAX 1
126# define BOOL_WIDTH 1
127#endif
128
129#endif /* _@GUARD_PREFIX@_LIMITS_H */
130#endif /* _@GUARD_PREFIX@_LIMITS_H */
131#endif
diff --git a/gl/localcharset.c b/gl/localcharset.c
index a225a2e..7ed9c95 100644
--- a/gl/localcharset.c
+++ b/gl/localcharset.c
@@ -1,19 +1,19 @@
1/* Determine a canonical name for the current locale's character encoding. 1/* Determine a canonical name for the current locale's character encoding.
2 2
3 Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2000-2006, 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Bruno Haible <bruno@clisp.org>. */ 18/* Written by Bruno Haible <bruno@clisp.org>. */
19 19
@@ -22,7 +22,6 @@
22/* Specification. */ 22/* Specification. */
23#include "localcharset.h" 23#include "localcharset.h"
24 24
25#include <fcntl.h>
26#include <stddef.h> 25#include <stddef.h>
27#include <stdio.h> 26#include <stdio.h>
28#include <string.h> 27#include <string.h>
@@ -32,8 +31,9 @@
32# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */ 31# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
33#endif 32#endif
34 33
35#if defined _WIN32 || defined __WIN32__ 34#if defined _WIN32 && !defined __CYGWIN__
36# define WINDOWS_NATIVE 35# define WINDOWS_NATIVE
36# include <locale.h>
37#endif 37#endif
38 38
39#if defined __EMX__ 39#if defined __EMX__
@@ -44,11 +44,10 @@
44#endif 44#endif
45 45
46#if !defined WINDOWS_NATIVE 46#if !defined WINDOWS_NATIVE
47# include <unistd.h>
48# if HAVE_LANGINFO_CODESET 47# if HAVE_LANGINFO_CODESET
49# include <langinfo.h> 48# include <langinfo.h>
50# else 49# else
51# if 0 /* see comment below */ 50# if 0 /* see comment regarding use of setlocale(), below */
52# include <locale.h> 51# include <locale.h>
53# endif 52# endif
54# endif 53# endif
@@ -59,6 +58,9 @@
59#elif defined WINDOWS_NATIVE 58#elif defined WINDOWS_NATIVE
60# define WIN32_LEAN_AND_MEAN 59# define WIN32_LEAN_AND_MEAN
61# include <windows.h> 60# include <windows.h>
61 /* For the use of setlocale() below, the Gnulib override in setlocale.c is
62 not needed; see the platform lists in setlocale_null.m4. */
63# undef setlocale
62#endif 64#endif
63#if defined OS2 65#if defined OS2
64# define INCL_DOS 66# define INCL_DOS
@@ -70,288 +72,755 @@
70# include <xlocale.h> 72# include <xlocale.h>
71#endif 73#endif
72 74
73#if ENABLE_RELOCATABLE
74# include "relocatable.h"
75#else
76# define relocate(pathname) (pathname)
77#endif
78 75
79/* Get LIBDIR. */ 76#if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2
80#ifndef LIBDIR
81# include "configmake.h"
82#endif
83
84/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */
85#ifndef O_NOFOLLOW
86# define O_NOFOLLOW 0
87#endif
88
89#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
90 /* Native Windows, Cygwin, OS/2, DOS */
91# define ISSLASH(C) ((C) == '/' || (C) == '\\')
92#endif
93
94#ifndef DIRECTORY_SEPARATOR
95# define DIRECTORY_SEPARATOR '/'
96#endif
97 77
98#ifndef ISSLASH 78/* On these platforms, we use a mapping from non-canonical encoding name
99# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) 79 to GNU canonical encoding name. */
100#endif
101 80
102#if HAVE_DECL_GETC_UNLOCKED 81/* With glibc-2.1 or newer, we don't need any canonicalization,
103# undef getc 82 because glibc has iconv and both glibc and libiconv support all
104# define getc getc_unlocked 83 GNU canonical names directly. */
105#endif 84# if !((defined __GNU_LIBRARY__ && __GLIBC__ >= 2) || defined __UCLIBC__)
106 85
107/* The following static variable is declared 'volatile' to avoid a 86struct table_entry
108 possible multithread problem in the function get_charset_aliases. If we
109 are running in a threaded environment, and if two threads initialize
110 'charset_aliases' simultaneously, both will produce the same value,
111 and everything will be ok if the two assignments to 'charset_aliases'
112 are atomic. But I don't know what will happen if the two assignments mix. */
113#if __STDC__ != 1
114# define volatile /* empty */
115#endif
116/* Pointer to the contents of the charset.alias file, if it has already been
117 read, else NULL. Its format is:
118 ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */
119static const char * volatile charset_aliases;
120
121/* Return a pointer to the contents of the charset.alias file. */
122static const char *
123get_charset_aliases (void)
124{ 87{
125 const char *cp; 88 const char alias[11+1];
126 89 const char canonical[11+1];
127 cp = charset_aliases; 90};
128 if (cp == NULL) 91
129 { 92/* Table of platform-dependent mappings, sorted in ascending order. */
130#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__) 93static const struct table_entry alias_table[] =
131 const char *dir; 94 {
132 const char *base = "charset.alias"; 95# if defined __FreeBSD__ /* FreeBSD */
133 char *file_name; 96 /*{ "ARMSCII-8", "ARMSCII-8" },*/
134 97 { "Big5", "BIG5" },
135 /* Make it possible to override the charset.alias location. This is 98 { "C", "ASCII" },
136 necessary for running the testsuite before "make install". */ 99 /*{ "CP1131", "CP1131" },*/
137 dir = getenv ("CHARSETALIASDIR"); 100 /*{ "CP1251", "CP1251" },*/
138 if (dir == NULL || dir[0] == '\0') 101 /*{ "CP866", "CP866" },*/
139 dir = relocate (LIBDIR); 102 /*{ "GB18030", "GB18030" },*/
140 103 /*{ "GB2312", "GB2312" },*/
141 /* Concatenate dir and base into freshly allocated file_name. */ 104 /*{ "GBK", "GBK" },*/
142 { 105 /*{ "ISCII-DEV", "?" },*/
143 size_t dir_len = strlen (dir); 106 { "ISO8859-1", "ISO-8859-1" },
144 size_t base_len = strlen (base); 107 { "ISO8859-13", "ISO-8859-13" },
145 int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); 108 { "ISO8859-15", "ISO-8859-15" },
146 file_name = (char *) malloc (dir_len + add_slash + base_len + 1); 109 { "ISO8859-2", "ISO-8859-2" },
147 if (file_name != NULL) 110 { "ISO8859-5", "ISO-8859-5" },
148 { 111 { "ISO8859-7", "ISO-8859-7" },
149 memcpy (file_name, dir, dir_len); 112 { "ISO8859-9", "ISO-8859-9" },
150 if (add_slash) 113 /*{ "KOI8-R", "KOI8-R" },*/
151 file_name[dir_len] = DIRECTORY_SEPARATOR; 114 /*{ "KOI8-U", "KOI8-U" },*/
152 memcpy (file_name + dir_len + add_slash, base, base_len + 1); 115 { "SJIS", "SHIFT_JIS" },
153 } 116 { "US-ASCII", "ASCII" },
154 } 117 { "eucCN", "GB2312" },
155 118 { "eucJP", "EUC-JP" },
156 if (file_name == NULL) 119 { "eucKR", "EUC-KR" }
157 /* Out of memory. Treat the file as empty. */ 120# define alias_table_defined
158 cp = ""; 121# endif
159 else 122# if defined __NetBSD__ /* NetBSD */
160 { 123 { "646", "ASCII" },
161 int fd; 124 /*{ "ARMSCII-8", "ARMSCII-8" },*/
162 125 /*{ "BIG5", "BIG5" },*/
163 /* Open the file. Reject symbolic links on platforms that support 126 { "Big5-HKSCS", "BIG5-HKSCS" },
164 O_NOFOLLOW. This is a security feature. Without it, an attacker 127 /*{ "CP1251", "CP1251" },*/
165 could retrieve parts of the contents (namely, the tail of the 128 /*{ "CP866", "CP866" },*/
166 first line that starts with "* ") of an arbitrary file by placing 129 /*{ "GB18030", "GB18030" },*/
167 a symbolic link to that file under the name "charset.alias" in 130 /*{ "GB2312", "GB2312" },*/
168 some writable directory and defining the environment variable 131 { "ISO8859-1", "ISO-8859-1" },
169 CHARSETALIASDIR to point to that directory. */ 132 { "ISO8859-13", "ISO-8859-13" },
170 fd = open (file_name, 133 { "ISO8859-15", "ISO-8859-15" },
171 O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0)); 134 { "ISO8859-2", "ISO-8859-2" },
172 if (fd < 0) 135 { "ISO8859-4", "ISO-8859-4" },
173 /* File not found. Treat it as empty. */ 136 { "ISO8859-5", "ISO-8859-5" },
174 cp = ""; 137 { "ISO8859-7", "ISO-8859-7" },
175 else 138 /*{ "KOI8-R", "KOI8-R" },*/
176 { 139 /*{ "KOI8-U", "KOI8-U" },*/
177 FILE *fp; 140 /*{ "PT154", "PT154" },*/
178 141 { "SJIS", "SHIFT_JIS" },
179 fp = fdopen (fd, "r"); 142 { "eucCN", "GB2312" },
180 if (fp == NULL) 143 { "eucJP", "EUC-JP" },
181 { 144 { "eucKR", "EUC-KR" },
182 /* Out of memory. Treat the file as empty. */ 145 { "eucTW", "EUC-TW" }
183 close (fd); 146# define alias_table_defined
184 cp = ""; 147# endif
185 } 148# if defined __OpenBSD__ /* OpenBSD */
186 else 149 { "646", "ASCII" },
187 { 150 { "ISO8859-1", "ISO-8859-1" },
188 /* Parse the file's contents. */ 151 { "ISO8859-13", "ISO-8859-13" },
189 char *res_ptr = NULL; 152 { "ISO8859-15", "ISO-8859-15" },
190 size_t res_size = 0; 153 { "ISO8859-2", "ISO-8859-2" },
191 154 { "ISO8859-4", "ISO-8859-4" },
192 for (;;) 155 { "ISO8859-5", "ISO-8859-5" },
193 { 156 { "ISO8859-7", "ISO-8859-7" },
194 int c; 157 { "US-ASCII", "ASCII" }
195 char buf1[50+1]; 158# define alias_table_defined
196 char buf2[50+1]; 159# endif
197 size_t l1, l2; 160# if defined __APPLE__ && defined __MACH__ /* Mac OS X */
198 char *old_res_ptr; 161 /* Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is
199 162 useless:
200 c = getc (fp); 163 - It returns the empty string when LANG is set to a locale of the
201 if (c == EOF) 164 form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
202 break; 165 LC_CTYPE file.
203 if (c == '\n' || c == ' ' || c == '\t') 166 - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
204 continue; 167 the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
205 if (c == '#') 168 - The documentation says:
206 { 169 "... all code that calls BSD system routines should ensure
207 /* Skip comment, to end of line. */ 170 that the const *char parameters of these routines are in UTF-8
208 do 171 encoding. All BSD system functions expect their string
209 c = getc (fp); 172 parameters to be in UTF-8 encoding and nothing else."
210 while (!(c == EOF || c == '\n')); 173 It also says
211 if (c == EOF) 174 "An additional caveat is that string parameters for files,
212 break; 175 paths, and other file-system entities must be in canonical
213 continue; 176 UTF-8. In a canonical UTF-8 Unicode string, all decomposable
214 } 177 characters are decomposed ..."
215 ungetc (c, fp); 178 but this is not true: You can pass non-decomposed UTF-8 strings
216 if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) 179 to file system functions, and it is the OS which will convert
217 break; 180 them to decomposed UTF-8 before accessing the file system.
218 l1 = strlen (buf1); 181 - The Apple Terminal application displays UTF-8 by default.
219 l2 = strlen (buf2); 182 - However, other applications are free to use different encodings:
220 old_res_ptr = res_ptr; 183 - xterm uses ISO-8859-1 by default.
221 if (res_size == 0) 184 - TextEdit uses MacRoman by default.
222 { 185 We prefer UTF-8 over decomposed UTF-8-MAC because one should
223 res_size = l1 + 1 + l2 + 1; 186 minimize the use of decomposed Unicode. Unfortunately, through the
224 res_ptr = (char *) malloc (res_size + 1); 187 Darwin file system, decomposed UTF-8 strings are leaked into user
225 } 188 space nevertheless.
226 else 189 Then there are also the locales with encodings other than US-ASCII
227 { 190 and UTF-8. These locales can be occasionally useful to users (e.g.
228 res_size += l1 + 1 + l2 + 1; 191 when grepping through ISO-8859-1 encoded text files), when all their
229 res_ptr = (char *) realloc (res_ptr, res_size + 1); 192 file names are in US-ASCII.
230 } 193 */
231 if (res_ptr == NULL) 194 { "ARMSCII-8", "ARMSCII-8" },
232 { 195 { "Big5", "BIG5" },
233 /* Out of memory. */ 196 { "Big5HKSCS", "BIG5-HKSCS" },
234 res_size = 0; 197 { "CP1131", "CP1131" },
235 free (old_res_ptr); 198 { "CP1251", "CP1251" },
236 break; 199 { "CP866", "CP866" },
237 } 200 { "CP949", "CP949" },
238 strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); 201 { "GB18030", "GB18030" },
239 strcpy (res_ptr + res_size - (l2 + 1), buf2); 202 { "GB2312", "GB2312" },
240 } 203 { "GBK", "GBK" },
241 fclose (fp); 204 /*{ "ISCII-DEV", "?" },*/
242 if (res_size == 0) 205 { "ISO8859-1", "ISO-8859-1" },
243 cp = ""; 206 { "ISO8859-13", "ISO-8859-13" },
244 else 207 { "ISO8859-15", "ISO-8859-15" },
245 { 208 { "ISO8859-2", "ISO-8859-2" },
246 *(res_ptr + res_size) = '\0'; 209 { "ISO8859-4", "ISO-8859-4" },
247 cp = res_ptr; 210 { "ISO8859-5", "ISO-8859-5" },
248 } 211 { "ISO8859-7", "ISO-8859-7" },
249 } 212 { "ISO8859-9", "ISO-8859-9" },
250 } 213 { "KOI8-R", "KOI8-R" },
214 { "KOI8-U", "KOI8-U" },
215 { "PT154", "PT154" },
216 { "SJIS", "SHIFT_JIS" },
217 { "eucCN", "GB2312" },
218 { "eucJP", "EUC-JP" },
219 { "eucKR", "EUC-KR" }
220# define alias_table_defined
221# endif
222# if defined _AIX /* AIX */
223 /*{ "GBK", "GBK" },*/
224 { "IBM-1046", "CP1046" },
225 { "IBM-1124", "CP1124" },
226 { "IBM-1129", "CP1129" },
227 { "IBM-1252", "CP1252" },
228 { "IBM-850", "CP850" },
229 { "IBM-856", "CP856" },
230 { "IBM-921", "ISO-8859-13" },
231 { "IBM-922", "CP922" },
232 { "IBM-932", "CP932" },
233 { "IBM-943", "CP943" },
234 { "IBM-eucCN", "GB2312" },
235 { "IBM-eucJP", "EUC-JP" },
236 { "IBM-eucKR", "EUC-KR" },
237 { "IBM-eucTW", "EUC-TW" },
238 { "ISO8859-1", "ISO-8859-1" },
239 { "ISO8859-15", "ISO-8859-15" },
240 { "ISO8859-2", "ISO-8859-2" },
241 { "ISO8859-5", "ISO-8859-5" },
242 { "ISO8859-6", "ISO-8859-6" },
243 { "ISO8859-7", "ISO-8859-7" },
244 { "ISO8859-8", "ISO-8859-8" },
245 { "ISO8859-9", "ISO-8859-9" },
246 { "TIS-620", "TIS-620" },
247 /*{ "UTF-8", "UTF-8" },*/
248 { "big5", "BIG5" }
249# define alias_table_defined
250# endif
251# if defined __hpux /* HP-UX */
252 { "SJIS", "SHIFT_JIS" },
253 { "arabic8", "HP-ARABIC8" },
254 { "big5", "BIG5" },
255 { "cp1251", "CP1251" },
256 { "eucJP", "EUC-JP" },
257 { "eucKR", "EUC-KR" },
258 { "eucTW", "EUC-TW" },
259 { "gb18030", "GB18030" },
260 { "greek8", "HP-GREEK8" },
261 { "hebrew8", "HP-HEBREW8" },
262 { "hkbig5", "BIG5-HKSCS" },
263 { "hp15CN", "GB2312" },
264 { "iso88591", "ISO-8859-1" },
265 { "iso885913", "ISO-8859-13" },
266 { "iso885915", "ISO-8859-15" },
267 { "iso88592", "ISO-8859-2" },
268 { "iso88594", "ISO-8859-4" },
269 { "iso88595", "ISO-8859-5" },
270 { "iso88596", "ISO-8859-6" },
271 { "iso88597", "ISO-8859-7" },
272 { "iso88598", "ISO-8859-8" },
273 { "iso88599", "ISO-8859-9" },
274 { "kana8", "HP-KANA8" },
275 { "koi8r", "KOI8-R" },
276 { "roman8", "HP-ROMAN8" },
277 { "tis620", "TIS-620" },
278 { "turkish8", "HP-TURKISH8" },
279 { "utf8", "UTF-8" }
280# define alias_table_defined
281# endif
282# if defined __sgi /* IRIX */
283 { "ISO8859-1", "ISO-8859-1" },
284 { "ISO8859-15", "ISO-8859-15" },
285 { "ISO8859-2", "ISO-8859-2" },
286 { "ISO8859-5", "ISO-8859-5" },
287 { "ISO8859-7", "ISO-8859-7" },
288 { "ISO8859-9", "ISO-8859-9" },
289 { "eucCN", "GB2312" },
290 { "eucJP", "EUC-JP" },
291 { "eucKR", "EUC-KR" },
292 { "eucTW", "EUC-TW" }
293# define alias_table_defined
294# endif
295# if defined __osf__ /* OSF/1 */
296 /*{ "GBK", "GBK" },*/
297 { "ISO8859-1", "ISO-8859-1" },
298 { "ISO8859-15", "ISO-8859-15" },
299 { "ISO8859-2", "ISO-8859-2" },
300 { "ISO8859-4", "ISO-8859-4" },
301 { "ISO8859-5", "ISO-8859-5" },
302 { "ISO8859-7", "ISO-8859-7" },
303 { "ISO8859-8", "ISO-8859-8" },
304 { "ISO8859-9", "ISO-8859-9" },
305 { "KSC5601", "CP949" },
306 { "SJIS", "SHIFT_JIS" },
307 { "TACTIS", "TIS-620" },
308 /*{ "UTF-8", "UTF-8" },*/
309 { "big5", "BIG5" },
310 { "cp850", "CP850" },
311 { "dechanyu", "DEC-HANYU" },
312 { "dechanzi", "GB2312" },
313 { "deckanji", "DEC-KANJI" },
314 { "deckorean", "EUC-KR" },
315 { "eucJP", "EUC-JP" },
316 { "eucKR", "EUC-KR" },
317 { "eucTW", "EUC-TW" },
318 { "sdeckanji", "EUC-JP" }
319# define alias_table_defined
320# endif
321# if defined __sun /* Solaris */
322 { "5601", "EUC-KR" },
323 { "646", "ASCII" },
324 /*{ "BIG5", "BIG5" },*/
325 { "Big5-HKSCS", "BIG5-HKSCS" },
326 { "GB18030", "GB18030" },
327 /*{ "GBK", "GBK" },*/
328 { "ISO8859-1", "ISO-8859-1" },
329 { "ISO8859-11", "TIS-620" },
330 { "ISO8859-13", "ISO-8859-13" },
331 { "ISO8859-15", "ISO-8859-15" },
332 { "ISO8859-2", "ISO-8859-2" },
333 { "ISO8859-3", "ISO-8859-3" },
334 { "ISO8859-4", "ISO-8859-4" },
335 { "ISO8859-5", "ISO-8859-5" },
336 { "ISO8859-6", "ISO-8859-6" },
337 { "ISO8859-7", "ISO-8859-7" },
338 { "ISO8859-8", "ISO-8859-8" },
339 { "ISO8859-9", "ISO-8859-9" },
340 { "PCK", "SHIFT_JIS" },
341 { "TIS620.2533", "TIS-620" },
342 /*{ "UTF-8", "UTF-8" },*/
343 { "ansi-1251", "CP1251" },
344 { "cns11643", "EUC-TW" },
345 { "eucJP", "EUC-JP" },
346 { "gb2312", "GB2312" },
347 { "koi8-r", "KOI8-R" }
348# define alias_table_defined
349# endif
350# if defined __minix /* Minix */
351 { "646", "ASCII" }
352# define alias_table_defined
353# endif
354# if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Windows */
355 { "CP1361", "JOHAB" },
356 { "CP20127", "ASCII" },
357 { "CP20866", "KOI8-R" },
358 { "CP20936", "GB2312" },
359 { "CP21866", "KOI8-RU" },
360 { "CP28591", "ISO-8859-1" },
361 { "CP28592", "ISO-8859-2" },
362 { "CP28593", "ISO-8859-3" },
363 { "CP28594", "ISO-8859-4" },
364 { "CP28595", "ISO-8859-5" },
365 { "CP28596", "ISO-8859-6" },
366 { "CP28597", "ISO-8859-7" },
367 { "CP28598", "ISO-8859-8" },
368 { "CP28599", "ISO-8859-9" },
369 { "CP28605", "ISO-8859-15" },
370 { "CP38598", "ISO-8859-8" },
371 { "CP51932", "EUC-JP" },
372 { "CP51936", "GB2312" },
373 { "CP51949", "EUC-KR" },
374 { "CP51950", "EUC-TW" },
375 { "CP54936", "GB18030" },
376 { "CP65001", "UTF-8" },
377 { "CP936", "GBK" }
378# define alias_table_defined
379# endif
380# if defined OS2 /* OS/2 */
381 /* The list of encodings is taken from "List of OS/2 Codepages"
382 by Alex Taylor:
383 <http://altsan.org/os2/toolkits/uls/index.html#codepages>.
384 See also "__convcp() of kLIBC":
385 <https://github.com/bitwiseworks/libc/blob/master/src/emx/src/lib/locale/__convcp.c>. */
386 { "CP1004", "CP1252" },
387 /*{ "CP1041", "CP943" },*/
388 /*{ "CP1088", "CP949" },*/
389 { "CP1089", "ISO-8859-6" },
390 /*{ "CP1114", "CP950" },*/
391 /*{ "CP1115", "GB2312" },*/
392 { "CP1208", "UTF-8" },
393 /*{ "CP1380", "GB2312" },*/
394 { "CP1381", "GB2312" },
395 { "CP1383", "GB2312" },
396 { "CP1386", "GBK" },
397 /*{ "CP301", "CP943" },*/
398 { "CP3372", "EUC-JP" },
399 { "CP4946", "CP850" },
400 /*{ "CP5048", "JIS_X0208-1990" },*/
401 /*{ "CP5049", "JIS_X0212-1990" },*/
402 /*{ "CP5067", "KS_C_5601-1987" },*/
403 { "CP813", "ISO-8859-7" },
404 { "CP819", "ISO-8859-1" },
405 { "CP878", "KOI8-R" },
406 /*{ "CP897", "CP943" },*/
407 { "CP912", "ISO-8859-2" },
408 { "CP913", "ISO-8859-3" },
409 { "CP914", "ISO-8859-4" },
410 { "CP915", "ISO-8859-5" },
411 { "CP916", "ISO-8859-8" },
412 { "CP920", "ISO-8859-9" },
413 { "CP921", "ISO-8859-13" },
414 { "CP923", "ISO-8859-15" },
415 /*{ "CP941", "CP943" },*/
416 /*{ "CP947", "CP950" },*/
417 /*{ "CP951", "CP949" },*/
418 /*{ "CP952", "JIS_X0208-1990" },*/
419 /*{ "CP953", "JIS_X0212-1990" },*/
420 { "CP954", "EUC-JP" },
421 { "CP964", "EUC-TW" },
422 { "CP970", "EUC-KR" },
423 /*{ "CP971", "KS_C_5601-1987" },*/
424 { "IBM-1004", "CP1252" },
425 /*{ "IBM-1006", "?" },*/
426 /*{ "IBM-1008", "?" },*/
427 /*{ "IBM-1041", "CP943" },*/
428 /*{ "IBM-1051", "?" },*/
429 /*{ "IBM-1088", "CP949" },*/
430 { "IBM-1089", "ISO-8859-6" },
431 /*{ "IBM-1098", "?" },*/
432 /*{ "IBM-1114", "CP950" },*/
433 /*{ "IBM-1115", "GB2312" },*/
434 /*{ "IBM-1116", "?" },*/
435 /*{ "IBM-1117", "?" },*/
436 /*{ "IBM-1118", "?" },*/
437 /*{ "IBM-1119", "?" },*/
438 { "IBM-1124", "CP1124" },
439 { "IBM-1125", "CP1125" },
440 { "IBM-1131", "CP1131" },
441 { "IBM-1208", "UTF-8" },
442 { "IBM-1250", "CP1250" },
443 { "IBM-1251", "CP1251" },
444 { "IBM-1252", "CP1252" },
445 { "IBM-1253", "CP1253" },
446 { "IBM-1254", "CP1254" },
447 { "IBM-1255", "CP1255" },
448 { "IBM-1256", "CP1256" },
449 { "IBM-1257", "CP1257" },
450 /*{ "IBM-1275", "?" },*/
451 /*{ "IBM-1276", "?" },*/
452 /*{ "IBM-1277", "?" },*/
453 /*{ "IBM-1280", "?" },*/
454 /*{ "IBM-1281", "?" },*/
455 /*{ "IBM-1282", "?" },*/
456 /*{ "IBM-1283", "?" },*/
457 /*{ "IBM-1380", "GB2312" },*/
458 { "IBM-1381", "GB2312" },
459 { "IBM-1383", "GB2312" },
460 { "IBM-1386", "GBK" },
461 /*{ "IBM-301", "CP943" },*/
462 { "IBM-3372", "EUC-JP" },
463 { "IBM-367", "ASCII" },
464 { "IBM-437", "CP437" },
465 { "IBM-4946", "CP850" },
466 /*{ "IBM-5048", "JIS_X0208-1990" },*/
467 /*{ "IBM-5049", "JIS_X0212-1990" },*/
468 /*{ "IBM-5067", "KS_C_5601-1987" },*/
469 { "IBM-813", "ISO-8859-7" },
470 { "IBM-819", "ISO-8859-1" },
471 { "IBM-850", "CP850" },
472 /*{ "IBM-851", "?" },*/
473 { "IBM-852", "CP852" },
474 { "IBM-855", "CP855" },
475 { "IBM-856", "CP856" },
476 { "IBM-857", "CP857" },
477 /*{ "IBM-859", "?" },*/
478 { "IBM-860", "CP860" },
479 { "IBM-861", "CP861" },
480 { "IBM-862", "CP862" },
481 { "IBM-863", "CP863" },
482 { "IBM-864", "CP864" },
483 { "IBM-865", "CP865" },
484 { "IBM-866", "CP866" },
485 /*{ "IBM-868", "?" },*/
486 { "IBM-869", "CP869" },
487 { "IBM-874", "CP874" },
488 { "IBM-878", "KOI8-R" },
489 /*{ "IBM-895", "?" },*/
490 /*{ "IBM-897", "CP943" },*/
491 /*{ "IBM-907", "?" },*/
492 /*{ "IBM-909", "?" },*/
493 { "IBM-912", "ISO-8859-2" },
494 { "IBM-913", "ISO-8859-3" },
495 { "IBM-914", "ISO-8859-4" },
496 { "IBM-915", "ISO-8859-5" },
497 { "IBM-916", "ISO-8859-8" },
498 { "IBM-920", "ISO-8859-9" },
499 { "IBM-921", "ISO-8859-13" },
500 { "IBM-922", "CP922" },
501 { "IBM-923", "ISO-8859-15" },
502 { "IBM-932", "CP932" },
503 /*{ "IBM-941", "CP943" },*/
504 /*{ "IBM-942", "?" },*/
505 { "IBM-943", "CP943" },
506 /*{ "IBM-947", "CP950" },*/
507 { "IBM-949", "CP949" },
508 { "IBM-950", "CP950" },
509 /*{ "IBM-951", "CP949" },*/
510 /*{ "IBM-952", "JIS_X0208-1990" },*/
511 /*{ "IBM-953", "JIS_X0212-1990" },*/
512 { "IBM-954", "EUC-JP" },
513 /*{ "IBM-955", "?" },*/
514 { "IBM-964", "EUC-TW" },
515 { "IBM-970", "EUC-KR" },
516 /*{ "IBM-971", "KS_C_5601-1987" },*/
517 { "IBM-eucCN", "GB2312" },
518 { "IBM-eucJP", "EUC-JP" },
519 { "IBM-eucKR", "EUC-KR" },
520 { "IBM-eucTW", "EUC-TW" },
521 { "IBM33722", "EUC-JP" },
522 { "ISO8859-1", "ISO-8859-1" },
523 { "ISO8859-2", "ISO-8859-2" },
524 { "ISO8859-3", "ISO-8859-3" },
525 { "ISO8859-4", "ISO-8859-4" },
526 { "ISO8859-5", "ISO-8859-5" },
527 { "ISO8859-6", "ISO-8859-6" },
528 { "ISO8859-7", "ISO-8859-7" },
529 { "ISO8859-8", "ISO-8859-8" },
530 { "ISO8859-9", "ISO-8859-9" },
531 /*{ "JISX0201-1976", "JISX0201-1976" },*/
532 /*{ "JISX0208-1978", "?" },*/
533 /*{ "JISX0208-1983", "JIS_X0208-1983" },*/
534 /*{ "JISX0208-1990", "JIS_X0208-1990" },*/
535 /*{ "JISX0212-1990", "JIS_X0212-1990" },*/
536 /*{ "KSC5601-1987", "KS_C_5601-1987" },*/
537 { "SJIS-1", "CP943" },
538 { "SJIS-2", "CP943" },
539 { "eucJP", "EUC-JP" },
540 { "eucKR", "EUC-KR" },
541 { "eucTW-1993", "EUC-TW" }
542# define alias_table_defined
543# endif
544# if defined VMS /* OpenVMS */
545 /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
546 "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
547 section 10.7 "Handling Different Character Sets". */
548 { "DECHANYU", "DEC-HANYU" },
549 { "DECHANZI", "GB2312" },
550 { "DECKANJI", "DEC-KANJI" },
551 { "DECKOREAN", "EUC-KR" },
552 { "ISO8859-1", "ISO-8859-1" },
553 { "ISO8859-2", "ISO-8859-2" },
554 { "ISO8859-5", "ISO-8859-5" },
555 { "ISO8859-7", "ISO-8859-7" },
556 { "ISO8859-8", "ISO-8859-8" },
557 { "ISO8859-9", "ISO-8859-9" },
558 { "SDECKANJI", "EUC-JP" },
559 { "SJIS", "SHIFT_JIS" },
560 { "eucJP", "EUC-JP" },
561 { "eucTW", "EUC-TW" }
562# define alias_table_defined
563# endif
564# ifndef alias_table_defined
565 /* Just a dummy entry, to avoid a C syntax error. */
566 { "", "" }
567# endif
568 };
251 569
252 free (file_name); 570# endif
253 }
254 571
255#else 572#else
256 573
257# if defined DARWIN7 574/* On these platforms, we use a mapping from locale name to GNU canonical
258 /* To avoid the trouble of installing a file that is shared by many 575 encoding name. */
259 GNU packages -- many packaging systems have problems with this --,
260 simply inline the aliases here. */
261 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
262 "ISO8859-2" "\0" "ISO-8859-2" "\0"
263 "ISO8859-4" "\0" "ISO-8859-4" "\0"
264 "ISO8859-5" "\0" "ISO-8859-5" "\0"
265 "ISO8859-7" "\0" "ISO-8859-7" "\0"
266 "ISO8859-9" "\0" "ISO-8859-9" "\0"
267 "ISO8859-13" "\0" "ISO-8859-13" "\0"
268 "ISO8859-15" "\0" "ISO-8859-15" "\0"
269 "KOI8-R" "\0" "KOI8-R" "\0"
270 "KOI8-U" "\0" "KOI8-U" "\0"
271 "CP866" "\0" "CP866" "\0"
272 "CP949" "\0" "CP949" "\0"
273 "CP1131" "\0" "CP1131" "\0"
274 "CP1251" "\0" "CP1251" "\0"
275 "eucCN" "\0" "GB2312" "\0"
276 "GB2312" "\0" "GB2312" "\0"
277 "eucJP" "\0" "EUC-JP" "\0"
278 "eucKR" "\0" "EUC-KR" "\0"
279 "Big5" "\0" "BIG5" "\0"
280 "Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
281 "GBK" "\0" "GBK" "\0"
282 "GB18030" "\0" "GB18030" "\0"
283 "SJIS" "\0" "SHIFT_JIS" "\0"
284 "ARMSCII-8" "\0" "ARMSCII-8" "\0"
285 "PT154" "\0" "PT154" "\0"
286 /*"ISCII-DEV" "\0" "?" "\0"*/
287 "*" "\0" "UTF-8" "\0";
288# endif
289 576
290# if defined VMS 577struct table_entry
291 /* To avoid the troubles of an extra file charset.alias_vms in the 578{
292 sources of many GNU packages, simply inline the aliases here. */ 579 const char locale[17+1];
293 /* The list of encodings is taken from the OpenVMS 7.3-1 documentation 580 const char canonical[11+1];
294 "Compaq C Run-Time Library Reference Manual for OpenVMS systems" 581};
295 section 10.7 "Handling Different Character Sets". */ 582
296 cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" 583/* Table of platform-dependent mappings, sorted in ascending order. */
297 "ISO8859-2" "\0" "ISO-8859-2" "\0" 584static const struct table_entry locale_table[] =
298 "ISO8859-5" "\0" "ISO-8859-5" "\0" 585 {
299 "ISO8859-7" "\0" "ISO-8859-7" "\0" 586# if defined __FreeBSD__ /* FreeBSD 4.2 */
300 "ISO8859-8" "\0" "ISO-8859-8" "\0" 587 { "cs_CZ.ISO_8859-2", "ISO-8859-2" },
301 "ISO8859-9" "\0" "ISO-8859-9" "\0" 588 { "da_DK.DIS_8859-15", "ISO-8859-15" },
302 /* Japanese */ 589 { "da_DK.ISO_8859-1", "ISO-8859-1" },
303 "eucJP" "\0" "EUC-JP" "\0" 590 { "de_AT.DIS_8859-15", "ISO-8859-15" },
304 "SJIS" "\0" "SHIFT_JIS" "\0" 591 { "de_AT.ISO_8859-1", "ISO-8859-1" },
305 "DECKANJI" "\0" "DEC-KANJI" "\0" 592 { "de_CH.DIS_8859-15", "ISO-8859-15" },
306 "SDECKANJI" "\0" "EUC-JP" "\0" 593 { "de_CH.ISO_8859-1", "ISO-8859-1" },
307 /* Chinese */ 594 { "de_DE.DIS_8859-15", "ISO-8859-15" },
308 "eucTW" "\0" "EUC-TW" "\0" 595 { "de_DE.ISO_8859-1", "ISO-8859-1" },
309 "DECHANYU" "\0" "DEC-HANYU" "\0" 596 { "en_AU.DIS_8859-15", "ISO-8859-15" },
310 "DECHANZI" "\0" "GB2312" "\0" 597 { "en_AU.ISO_8859-1", "ISO-8859-1" },
311 /* Korean */ 598 { "en_CA.DIS_8859-15", "ISO-8859-15" },
312 "DECKOREAN" "\0" "EUC-KR" "\0"; 599 { "en_CA.ISO_8859-1", "ISO-8859-1" },
600 { "en_GB.DIS_8859-15", "ISO-8859-15" },
601 { "en_GB.ISO_8859-1", "ISO-8859-1" },
602 { "en_US.DIS_8859-15", "ISO-8859-15" },
603 { "en_US.ISO_8859-1", "ISO-8859-1" },
604 { "es_ES.DIS_8859-15", "ISO-8859-15" },
605 { "es_ES.ISO_8859-1", "ISO-8859-1" },
606 { "fi_FI.DIS_8859-15", "ISO-8859-15" },
607 { "fi_FI.ISO_8859-1", "ISO-8859-1" },
608 { "fr_BE.DIS_8859-15", "ISO-8859-15" },
609 { "fr_BE.ISO_8859-1", "ISO-8859-1" },
610 { "fr_CA.DIS_8859-15", "ISO-8859-15" },
611 { "fr_CA.ISO_8859-1", "ISO-8859-1" },
612 { "fr_CH.DIS_8859-15", "ISO-8859-15" },
613 { "fr_CH.ISO_8859-1", "ISO-8859-1" },
614 { "fr_FR.DIS_8859-15", "ISO-8859-15" },
615 { "fr_FR.ISO_8859-1", "ISO-8859-1" },
616 { "hr_HR.ISO_8859-2", "ISO-8859-2" },
617 { "hu_HU.ISO_8859-2", "ISO-8859-2" },
618 { "is_IS.DIS_8859-15", "ISO-8859-15" },
619 { "is_IS.ISO_8859-1", "ISO-8859-1" },
620 { "it_CH.DIS_8859-15", "ISO-8859-15" },
621 { "it_CH.ISO_8859-1", "ISO-8859-1" },
622 { "it_IT.DIS_8859-15", "ISO-8859-15" },
623 { "it_IT.ISO_8859-1", "ISO-8859-1" },
624 { "ja_JP.EUC", "EUC-JP" },
625 { "ja_JP.SJIS", "SHIFT_JIS" },
626 { "ja_JP.Shift_JIS", "SHIFT_JIS" },
627 { "ko_KR.EUC", "EUC-KR" },
628 { "la_LN.ASCII", "ASCII" },
629 { "la_LN.DIS_8859-15", "ISO-8859-15" },
630 { "la_LN.ISO_8859-1", "ISO-8859-1" },
631 { "la_LN.ISO_8859-2", "ISO-8859-2" },
632 { "la_LN.ISO_8859-4", "ISO-8859-4" },
633 { "lt_LN.ASCII", "ASCII" },
634 { "lt_LN.DIS_8859-15", "ISO-8859-15" },
635 { "lt_LN.ISO_8859-1", "ISO-8859-1" },
636 { "lt_LN.ISO_8859-2", "ISO-8859-2" },
637 { "lt_LT.ISO_8859-4", "ISO-8859-4" },
638 { "nl_BE.DIS_8859-15", "ISO-8859-15" },
639 { "nl_BE.ISO_8859-1", "ISO-8859-1" },
640 { "nl_NL.DIS_8859-15", "ISO-8859-15" },
641 { "nl_NL.ISO_8859-1", "ISO-8859-1" },
642 { "no_NO.DIS_8859-15", "ISO-8859-15" },
643 { "no_NO.ISO_8859-1", "ISO-8859-1" },
644 { "pl_PL.ISO_8859-2", "ISO-8859-2" },
645 { "pt_PT.DIS_8859-15", "ISO-8859-15" },
646 { "pt_PT.ISO_8859-1", "ISO-8859-1" },
647 { "ru_RU.CP866", "CP866" },
648 { "ru_RU.ISO_8859-5", "ISO-8859-5" },
649 { "ru_RU.KOI8-R", "KOI8-R" },
650 { "ru_SU.CP866", "CP866" },
651 { "ru_SU.ISO_8859-5", "ISO-8859-5" },
652 { "ru_SU.KOI8-R", "KOI8-R" },
653 { "sl_SI.ISO_8859-2", "ISO-8859-2" },
654 { "sv_SE.DIS_8859-15", "ISO-8859-15" },
655 { "sv_SE.ISO_8859-1", "ISO-8859-1" },
656 { "uk_UA.KOI8-U", "KOI8-U" },
657 { "zh_CN.EUC", "GB2312" },
658 { "zh_TW.BIG5", "BIG5" },
659 { "zh_TW.Big5", "BIG5" }
660# define locale_table_defined
313# endif 661# endif
314 662# if defined __DJGPP__ /* DOS / DJGPP 2.03 */
315# if defined WINDOWS_NATIVE || defined __CYGWIN__ 663 /* The encodings given here may not all be correct.
316 /* To avoid the troubles of installing a separate file in the same 664 If you find that the encoding given for your language and
317 directory as the DLL and of retrieving the DLL's directory at 665 country is not the one your DOS machine actually uses, just
318 runtime, simply inline the aliases here. */ 666 correct it in this file, and send a mail to
319 667 Juan Manuel Guerrero <juan.guerrero@gmx.de>
320 cp = "CP936" "\0" "GBK" "\0" 668 and <bug-gnulib@gnu.org>. */
321 "CP1361" "\0" "JOHAB" "\0" 669 { "C", "ASCII" },
322 "CP20127" "\0" "ASCII" "\0" 670 { "ar", "CP864" },
323 "CP20866" "\0" "KOI8-R" "\0" 671 { "ar_AE", "CP864" },
324 "CP20936" "\0" "GB2312" "\0" 672 { "ar_DZ", "CP864" },
325 "CP21866" "\0" "KOI8-RU" "\0" 673 { "ar_EG", "CP864" },
326 "CP28591" "\0" "ISO-8859-1" "\0" 674 { "ar_IQ", "CP864" },
327 "CP28592" "\0" "ISO-8859-2" "\0" 675 { "ar_IR", "CP864" },
328 "CP28593" "\0" "ISO-8859-3" "\0" 676 { "ar_JO", "CP864" },
329 "CP28594" "\0" "ISO-8859-4" "\0" 677 { "ar_KW", "CP864" },
330 "CP28595" "\0" "ISO-8859-5" "\0" 678 { "ar_MA", "CP864" },
331 "CP28596" "\0" "ISO-8859-6" "\0" 679 { "ar_OM", "CP864" },
332 "CP28597" "\0" "ISO-8859-7" "\0" 680 { "ar_QA", "CP864" },
333 "CP28598" "\0" "ISO-8859-8" "\0" 681 { "ar_SA", "CP864" },
334 "CP28599" "\0" "ISO-8859-9" "\0" 682 { "ar_SY", "CP864" },
335 "CP28605" "\0" "ISO-8859-15" "\0" 683 { "be", "CP866" },
336 "CP38598" "\0" "ISO-8859-8" "\0" 684 { "be_BE", "CP866" },
337 "CP51932" "\0" "EUC-JP" "\0" 685 { "bg", "CP866" }, /* not CP855 ?? */
338 "CP51936" "\0" "GB2312" "\0" 686 { "bg_BG", "CP866" }, /* not CP855 ?? */
339 "CP51949" "\0" "EUC-KR" "\0" 687 { "ca", "CP850" },
340 "CP51950" "\0" "EUC-TW" "\0" 688 { "ca_ES", "CP850" },
341 "CP54936" "\0" "GB18030" "\0" 689 { "cs", "CP852" },
342 "CP65001" "\0" "UTF-8" "\0"; 690 { "cs_CZ", "CP852" },
691 { "da", "CP865" }, /* not CP850 ?? */
692 { "da_DK", "CP865" }, /* not CP850 ?? */
693 { "de", "CP850" },
694 { "de_AT", "CP850" },
695 { "de_CH", "CP850" },
696 { "de_DE", "CP850" },
697 { "el", "CP869" },
698 { "el_GR", "CP869" },
699 { "en", "CP850" },
700 { "en_AU", "CP850" }, /* not CP437 ?? */
701 { "en_CA", "CP850" },
702 { "en_GB", "CP850" },
703 { "en_NZ", "CP437" },
704 { "en_US", "CP437" },
705 { "en_ZA", "CP850" }, /* not CP437 ?? */
706 { "eo", "CP850" },
707 { "eo_EO", "CP850" },
708 { "es", "CP850" },
709 { "es_AR", "CP850" },
710 { "es_BO", "CP850" },
711 { "es_CL", "CP850" },
712 { "es_CO", "CP850" },
713 { "es_CR", "CP850" },
714 { "es_CU", "CP850" },
715 { "es_DO", "CP850" },
716 { "es_EC", "CP850" },
717 { "es_ES", "CP850" },
718 { "es_GT", "CP850" },
719 { "es_HN", "CP850" },
720 { "es_MX", "CP850" },
721 { "es_NI", "CP850" },
722 { "es_PA", "CP850" },
723 { "es_PE", "CP850" },
724 { "es_PY", "CP850" },
725 { "es_SV", "CP850" },
726 { "es_UY", "CP850" },
727 { "es_VE", "CP850" },
728 { "et", "CP850" },
729 { "et_EE", "CP850" },
730 { "eu", "CP850" },
731 { "eu_ES", "CP850" },
732 { "fi", "CP850" },
733 { "fi_FI", "CP850" },
734 { "fr", "CP850" },
735 { "fr_BE", "CP850" },
736 { "fr_CA", "CP850" },
737 { "fr_CH", "CP850" },
738 { "fr_FR", "CP850" },
739 { "ga", "CP850" },
740 { "ga_IE", "CP850" },
741 { "gd", "CP850" },
742 { "gd_GB", "CP850" },
743 { "gl", "CP850" },
744 { "gl_ES", "CP850" },
745 { "he", "CP862" },
746 { "he_IL", "CP862" },
747 { "hr", "CP852" },
748 { "hr_HR", "CP852" },
749 { "hu", "CP852" },
750 { "hu_HU", "CP852" },
751 { "id", "CP850" }, /* not CP437 ?? */
752 { "id_ID", "CP850" }, /* not CP437 ?? */
753 { "is", "CP861" }, /* not CP850 ?? */
754 { "is_IS", "CP861" }, /* not CP850 ?? */
755 { "it", "CP850" },
756 { "it_CH", "CP850" },
757 { "it_IT", "CP850" },
758 { "ja", "CP932" },
759 { "ja_JP", "CP932" },
760 { "kr", "CP949" }, /* not CP934 ?? */
761 { "kr_KR", "CP949" }, /* not CP934 ?? */
762 { "lt", "CP775" },
763 { "lt_LT", "CP775" },
764 { "lv", "CP775" },
765 { "lv_LV", "CP775" },
766 { "mk", "CP866" }, /* not CP855 ?? */
767 { "mk_MK", "CP866" }, /* not CP855 ?? */
768 { "mt", "CP850" },
769 { "mt_MT", "CP850" },
770 { "nb", "CP865" }, /* not CP850 ?? */
771 { "nb_NO", "CP865" }, /* not CP850 ?? */
772 { "nl", "CP850" },
773 { "nl_BE", "CP850" },
774 { "nl_NL", "CP850" },
775 { "nn", "CP865" }, /* not CP850 ?? */
776 { "nn_NO", "CP865" }, /* not CP850 ?? */
777 { "no", "CP865" }, /* not CP850 ?? */
778 { "no_NO", "CP865" }, /* not CP850 ?? */
779 { "pl", "CP852" },
780 { "pl_PL", "CP852" },
781 { "pt", "CP850" },
782 { "pt_BR", "CP850" },
783 { "pt_PT", "CP850" },
784 { "ro", "CP852" },
785 { "ro_RO", "CP852" },
786 { "ru", "CP866" },
787 { "ru_RU", "CP866" },
788 { "sk", "CP852" },
789 { "sk_SK", "CP852" },
790 { "sl", "CP852" },
791 { "sl_SI", "CP852" },
792 { "sq", "CP852" },
793 { "sq_AL", "CP852" },
794 { "sr", "CP852" }, /* CP852 or CP866 or CP855 ?? */
795 { "sr_CS", "CP852" }, /* CP852 or CP866 or CP855 ?? */
796 { "sr_YU", "CP852" }, /* CP852 or CP866 or CP855 ?? */
797 { "sv", "CP850" },
798 { "sv_SE", "CP850" },
799 { "th", "CP874" },
800 { "th_TH", "CP874" },
801 { "tr", "CP857" },
802 { "tr_TR", "CP857" },
803 { "uk", "CP1125" },
804 { "uk_UA", "CP1125" },
805 { "zh_CN", "GBK" },
806 { "zh_TW", "CP950" } /* not CP938 ?? */
807# define locale_table_defined
343# endif 808# endif
344#endif 809# ifndef locale_table_defined
810 /* Just a dummy entry, to avoid a C syntax error. */
811 { "", "" }
812# endif
813 };
345 814
346 charset_aliases = cp; 815#endif
347 }
348 816
349 return cp;
350}
351 817
352/* Determine the current locale's character encoding, and canonicalize it 818/* Determine the current locale's character encoding, and canonicalize it
353 into one of the canonical names listed in config.charset. 819 into one of the canonical names listed below.
354 The result must not be freed; it is statically allocated. 820 The result must not be freed; it is statically allocated. The result
821 becomes invalid when setlocale() is used to change the global locale, or
822 when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG
823 is changed; threads in multithreaded programs should not do this.
355 If the canonical name cannot be determined, the result is a non-canonical 824 If the canonical name cannot be determined, the result is a non-canonical
356 name. */ 825 name. */
357 826
@@ -362,9 +831,15 @@ const char *
362locale_charset (void) 831locale_charset (void)
363{ 832{
364 const char *codeset; 833 const char *codeset;
365 const char *aliases;
366 834
367#if !(defined WINDOWS_NATIVE || defined OS2) 835 /* This function must be multithread-safe. To achieve this without using
836 thread-local storage, we use a simple strcpy or memcpy to fill this static
837 buffer. Filling it through, for example, strcpy + strcat would not be
838 guaranteed to leave the buffer's contents intact if another thread is
839 currently accessing it. If necessary, the contents is first assembled in
840 a stack-allocated buffer. */
841
842#if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2
368 843
369# if HAVE_LANGINFO_CODESET 844# if HAVE_LANGINFO_CODESET
370 845
@@ -378,7 +853,7 @@ locale_charset (void)
378 if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) 853 if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
379 { 854 {
380 const char *locale; 855 const char *locale;
381 static char buf[2 + 10 + 1]; 856 static char resultbuf[2 + 10 + 1];
382 857
383 locale = getenv ("LC_ALL"); 858 locale = getenv ("LC_ALL");
384 if (locale == NULL || locale[0] == '\0') 859 if (locale == NULL || locale[0] == '\0')
@@ -402,11 +877,12 @@ locale_charset (void)
402 modifier = strchr (dot, '@'); 877 modifier = strchr (dot, '@');
403 if (modifier == NULL) 878 if (modifier == NULL)
404 return dot; 879 return dot;
405 if (modifier - dot < sizeof (buf)) 880 if (modifier - dot < sizeof (resultbuf))
406 { 881 {
407 memcpy (buf, dot, modifier - dot); 882 /* This way of filling resultbuf is multithread-safe. */
408 buf [modifier - dot] = '\0'; 883 memcpy (resultbuf, dot, modifier - dot);
409 return buf; 884 resultbuf [modifier - dot] = '\0';
885 return resultbuf;
410 } 886 }
411 } 887 }
412 } 888 }
@@ -422,62 +898,65 @@ locale_charset (void)
422 converting to GetConsoleOutputCP(). This leads to correct results, 898 converting to GetConsoleOutputCP(). This leads to correct results,
423 except when SetConsoleOutputCP has been called and a raster font is 899 except when SetConsoleOutputCP has been called and a raster font is
424 in use. */ 900 in use. */
425 sprintf (buf, "CP%u", GetACP ()); 901 {
426 codeset = buf; 902 char buf[2 + 10 + 1];
427 }
428# endif
429
430# else
431
432 /* On old systems which lack it, use setlocale or getenv. */
433 const char *locale = NULL;
434 903
435 /* But most old systems don't have a complete set of locales. Some 904 sprintf (buf, "CP%u", GetACP ());
436 (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't 905 strcpy (resultbuf, buf);
437 use setlocale here; it would return "C" when it doesn't support the 906 codeset = resultbuf;
438 locale name the user has set. */ 907 }
439# if 0
440 locale = setlocale (LC_CTYPE, NULL);
441# endif
442 if (locale == NULL || locale[0] == '\0')
443 {
444 locale = getenv ("LC_ALL");
445 if (locale == NULL || locale[0] == '\0')
446 {
447 locale = getenv ("LC_CTYPE");
448 if (locale == NULL || locale[0] == '\0')
449 locale = getenv ("LANG");
450 }
451 } 908 }
909# endif
452 910
453 /* On some old systems, one used to set locale = "iso8859_1". On others, 911 if (codeset == NULL)
454 you set it to "language_COUNTRY.charset". In any case, we resolve it 912 /* The canonical name cannot be determined. */
455 through the charset.alias file. */ 913 codeset = "";
456 codeset = locale;
457 914
458# endif 915# elif defined WINDOWS_NATIVE
459 916
460#elif defined WINDOWS_NATIVE 917 char buf[2 + 10 + 1];
918 static char resultbuf[2 + 10 + 1];
461 919
462 static char buf[2 + 10 + 1]; 920 /* The Windows API has a function returning the locale's codepage as
921 a number, but the value doesn't change according to what the
922 'setlocale' call specified. So we use it as a last resort, in
923 case the string returned by 'setlocale' doesn't specify the
924 codepage. */
925 char *current_locale = setlocale (LC_CTYPE, NULL);
926 char *pdot = strrchr (current_locale, '.');
463 927
464 /* The Windows API has a function returning the locale's codepage as a 928 if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf))
465 number: GetACP(). 929 sprintf (buf, "CP%s", pdot + 1);
466 When the output goes to a console window, it needs to be provided in 930 else
467 GetOEMCP() encoding if the console is using a raster font, or in 931 {
468 GetConsoleOutputCP() encoding if it is using a TrueType font. 932 /* The Windows API has a function returning the locale's codepage as a
469 But in GUI programs and for output sent to files and pipes, GetACP() 933 number: GetACP().
470 encoding is the best bet. */ 934 When the output goes to a console window, it needs to be provided in
471 sprintf (buf, "CP%u", GetACP ()); 935 GetOEMCP() encoding if the console is using a raster font, or in
472 codeset = buf; 936 GetConsoleOutputCP() encoding if it is using a TrueType font.
937 But in GUI programs and for output sent to files and pipes, GetACP()
938 encoding is the best bet. */
939 sprintf (buf, "CP%u", GetACP ());
940 }
941 /* For a locale name such as "French_France.65001", in Windows 10,
942 setlocale now returns "French_France.utf8" instead. */
943 if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0)
944 codeset = "UTF-8";
945 else
946 {
947 strcpy (resultbuf, buf);
948 codeset = resultbuf;
949 }
473 950
474#elif defined OS2 951# elif defined OS2
475 952
476 const char *locale; 953 const char *locale;
477 static char buf[2 + 10 + 1]; 954 static char resultbuf[2 + 10 + 1];
478 ULONG cp[3]; 955 ULONG cp[3];
479 ULONG cplen; 956 ULONG cplen;
480 957
958 codeset = NULL;
959
481 /* Allow user to override the codeset, as set in the operating system, 960 /* Allow user to override the codeset, as set in the operating system,
482 with standard language environment variables. */ 961 with standard language environment variables. */
483 locale = getenv ("LC_ALL"); 962 locale = getenv ("LC_ALL");
@@ -501,51 +980,173 @@ locale_charset (void)
501 modifier = strchr (dot, '@'); 980 modifier = strchr (dot, '@');
502 if (modifier == NULL) 981 if (modifier == NULL)
503 return dot; 982 return dot;
504 if (modifier - dot < sizeof (buf)) 983 if (modifier - dot < sizeof (resultbuf))
505 { 984 {
506 memcpy (buf, dot, modifier - dot); 985 /* This way of filling resultbuf is multithread-safe. */
507 buf [modifier - dot] = '\0'; 986 memcpy (resultbuf, dot, modifier - dot);
508 return buf; 987 resultbuf [modifier - dot] = '\0';
988 return resultbuf;
509 } 989 }
510 } 990 }
511 991
512 /* Resolve through the charset.alias file. */ 992 /* For the POSIX locale, don't use the system's codepage. */
513 codeset = locale; 993 if (strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0)
994 codeset = "";
514 } 995 }
515 else 996
997 if (codeset == NULL)
516 { 998 {
517 /* OS/2 has a function returning the locale's codepage as a number. */ 999 /* OS/2 has a function returning the locale's codepage as a number. */
518 if (DosQueryCp (sizeof (cp), cp, &cplen)) 1000 if (DosQueryCp (sizeof (cp), cp, &cplen))
519 codeset = ""; 1001 codeset = "";
520 else 1002 else
521 { 1003 {
1004 char buf[2 + 10 + 1];
1005
522 sprintf (buf, "CP%u", cp[0]); 1006 sprintf (buf, "CP%u", cp[0]);
523 codeset = buf; 1007 strcpy (resultbuf, buf);
1008 codeset = resultbuf;
524 } 1009 }
525 } 1010 }
526 1011
527#endif 1012# else
528 1013
529 if (codeset == NULL) 1014# error "Add code for other platforms here."
530 /* The canonical name cannot be determined. */ 1015
531 codeset = ""; 1016# endif
1017
1018 /* Resolve alias. */
1019 {
1020# ifdef alias_table_defined
1021 /* On some platforms, UTF-8 locales are the most frequently used ones.
1022 Speed up the common case and slow down the less common cases by
1023 testing for this case first. */
1024# if defined __OpenBSD__ || (defined __APPLE__ && defined __MACH__) || defined __sun || defined __CYGWIN__
1025 if (strcmp (codeset, "UTF-8") == 0)
1026 goto done_table_lookup;
1027 else
1028# endif
1029 {
1030 const struct table_entry * const table = alias_table;
1031 size_t const table_size =
1032 sizeof (alias_table) / sizeof (struct table_entry);
1033 /* The table is sorted. Perform a binary search. */
1034 size_t hi = table_size;
1035 size_t lo = 0;
1036 while (lo < hi)
1037 {
1038 /* Invariant:
1039 for i < lo, strcmp (table[i].alias, codeset) < 0,
1040 for i >= hi, strcmp (table[i].alias, codeset) > 0. */
1041 size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
1042 int cmp = strcmp (table[mid].alias, codeset);
1043 if (cmp < 0)
1044 lo = mid + 1;
1045 else if (cmp > 0)
1046 hi = mid;
1047 else
1048 {
1049 /* Found an i with
1050 strcmp (table[i].alias, codeset) == 0. */
1051 codeset = table[mid].canonical;
1052 goto done_table_lookup;
1053 }
1054 }
1055 }
1056 if (0)
1057 done_table_lookup: ;
1058 else
1059# endif
1060 {
1061 /* Did not find it in the table. */
1062 /* On Mac OS X, all modern locales use the UTF-8 encoding.
1063 BeOS and Haiku have a single locale, and it has UTF-8 encoding. */
1064# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__
1065 codeset = "UTF-8";
1066# else
1067 /* Don't return an empty string. GNU libc and GNU libiconv interpret
1068 the empty string as denoting "the locale's character encoding",
1069 thus GNU libiconv would call this function a second time. */
1070 if (codeset[0] == '\0')
1071 codeset = "ASCII";
1072# endif
1073 }
1074 }
1075
1076#else
532 1077
533 /* Resolve alias. */ 1078 /* On old systems which lack it, use setlocale or getenv. */
534 for (aliases = get_charset_aliases (); 1079 const char *locale = NULL;
535 *aliases != '\0'; 1080
536 aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) 1081 /* But most old systems don't have a complete set of locales. Some
537 if (strcmp (codeset, aliases) == 0 1082 (like DJGPP) have only the C locale. Therefore we don't use setlocale
538 || (aliases[0] == '*' && aliases[1] == '\0')) 1083 here; it would return "C" when it doesn't support the locale name the
1084 user has set. */
1085# if 0
1086 locale = setlocale (LC_CTYPE, NULL);
1087# endif
1088 if (locale == NULL || locale[0] == '\0')
1089 {
1090 locale = getenv ("LC_ALL");
1091 if (locale == NULL || locale[0] == '\0')
1092 {
1093 locale = getenv ("LC_CTYPE");
1094 if (locale == NULL || locale[0] == '\0')
1095 locale = getenv ("LANG");
1096 if (locale == NULL)
1097 locale = "";
1098 }
1099 }
1100
1101 /* Map locale name to canonical encoding name. */
1102 {
1103# ifdef locale_table_defined
1104 const struct table_entry * const table = locale_table;
1105 size_t const table_size =
1106 sizeof (locale_table) / sizeof (struct table_entry);
1107 /* The table is sorted. Perform a binary search. */
1108 size_t hi = table_size;
1109 size_t lo = 0;
1110 while (lo < hi)
539 { 1111 {
540 codeset = aliases + strlen (aliases) + 1; 1112 /* Invariant:
541 break; 1113 for i < lo, strcmp (table[i].locale, locale) < 0,
1114 for i >= hi, strcmp (table[i].locale, locale) > 0. */
1115 size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
1116 int cmp = strcmp (table[mid].locale, locale);
1117 if (cmp < 0)
1118 lo = mid + 1;
1119 else if (cmp > 0)
1120 hi = mid;
1121 else
1122 {
1123 /* Found an i with
1124 strcmp (table[i].locale, locale) == 0. */
1125 codeset = table[mid].canonical;
1126 goto done_table_lookup;
1127 }
1128 }
1129 if (0)
1130 done_table_lookup: ;
1131 else
1132# endif
1133 {
1134 /* Did not find it in the table. */
1135 /* On Mac OS X, all modern locales use the UTF-8 encoding.
1136 BeOS and Haiku have a single locale, and it has UTF-8 encoding. */
1137# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__
1138 codeset = "UTF-8";
1139# else
1140 /* The canonical name cannot be determined. */
1141 /* Don't return an empty string. GNU libc and GNU libiconv interpret
1142 the empty string as denoting "the locale's character encoding",
1143 thus GNU libiconv would call this function a second time. */
1144 codeset = "ASCII";
1145# endif
542 } 1146 }
1147 }
543 1148
544 /* Don't return an empty string. GNU libc and GNU libiconv interpret 1149#endif
545 the empty string as denoting "the locale's character encoding",
546 thus GNU libiconv would call this function a second time. */
547 if (codeset[0] == '\0')
548 codeset = "ASCII";
549 1150
550#ifdef DARWIN7 1151#ifdef DARWIN7
551 /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8" 1152 /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8"
diff --git a/gl/localcharset.h b/gl/localcharset.h
index c209829..29ee8dc 100644
--- a/gl/localcharset.h
+++ b/gl/localcharset.h
@@ -1,19 +1,19 @@
1/* Determine a canonical name for the current locale's character encoding. 1/* Determine a canonical name for the current locale's character encoding.
2 Copyright (C) 2000-2003, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2000-2003, 2009-2023 Free Software Foundation, Inc.
3 This file is part of the GNU CHARSET Library. 3 This file is part of the GNU CHARSET Library.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _LOCALCHARSET_H 18#ifndef _LOCALCHARSET_H
19#define _LOCALCHARSET_H 19#define _LOCALCHARSET_H
@@ -25,12 +25,109 @@ extern "C" {
25 25
26 26
27/* Determine the current locale's character encoding, and canonicalize it 27/* Determine the current locale's character encoding, and canonicalize it
28 into one of the canonical names listed in config.charset. 28 into one of the canonical names listed below.
29 The result must not be freed; it is statically allocated. 29 The result must not be freed; it is statically allocated. The result
30 becomes invalid when setlocale() is used to change the global locale, or
31 when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG
32 is changed; threads in multithreaded programs should not do this.
30 If the canonical name cannot be determined, the result is a non-canonical 33 If the canonical name cannot be determined, the result is a non-canonical
31 name. */ 34 name. */
32extern const char * locale_charset (void); 35extern const char * locale_charset (void);
33 36
37/* About GNU canonical names for character encodings:
38
39 Every canonical name must be supported by GNU libiconv. Support by GNU libc
40 is also desirable.
41
42 The name is case insensitive. Usually an upper case MIME charset name is
43 preferred.
44
45 The current list of these GNU canonical names is:
46
47 name MIME? used by which systems
48 (darwin = Mac OS X, windows = native Windows)
49
50 ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin minix cygwin
51 ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
52 ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
53 ISO-8859-3 Y glibc solaris cygwin
54 ISO-8859-4 Y hpux osf solaris freebsd netbsd openbsd darwin
55 ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
56 ISO-8859-6 Y glibc aix hpux solaris cygwin
57 ISO-8859-7 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos
58 ISO-8859-8 Y glibc aix hpux osf solaris cygwin zos
59 ISO-8859-9 Y glibc aix hpux irix osf solaris freebsd darwin cygwin zos
60 ISO-8859-13 glibc hpux solaris freebsd netbsd openbsd darwin cygwin
61 ISO-8859-14 glibc cygwin
62 ISO-8859-15 glibc aix irix osf solaris freebsd netbsd openbsd darwin cygwin
63 KOI8-R Y glibc hpux solaris freebsd netbsd openbsd darwin
64 KOI8-U Y glibc freebsd netbsd openbsd darwin cygwin
65 KOI8-T glibc
66 CP437 dos
67 CP775 dos
68 CP850 aix osf dos
69 CP852 dos
70 CP855 dos
71 CP856 aix
72 CP857 dos
73 CP861 dos
74 CP862 dos
75 CP864 dos
76 CP865 dos
77 CP866 freebsd netbsd openbsd darwin dos
78 CP869 dos
79 CP874 windows dos
80 CP922 aix
81 CP932 aix cygwin windows dos
82 CP943 aix zos
83 CP949 osf darwin windows dos
84 CP950 windows dos
85 CP1046 aix
86 CP1124 aix
87 CP1125 dos
88 CP1129 aix
89 CP1131 freebsd darwin
90 CP1250 windows
91 CP1251 glibc hpux solaris freebsd netbsd openbsd darwin cygwin windows
92 CP1252 aix windows
93 CP1253 windows
94 CP1254 windows
95 CP1255 glibc windows
96 CP1256 windows
97 CP1257 windows
98 GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin cygwin zos
99 EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin
100 EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin zos
101 EUC-TW glibc aix hpux irix osf solaris netbsd
102 BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin zos
103 BIG5-HKSCS glibc hpux solaris netbsd darwin
104 GBK glibc aix osf solaris freebsd darwin cygwin windows dos
105 GB18030 glibc hpux solaris freebsd netbsd darwin
106 SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin
107 JOHAB glibc solaris windows
108 TIS-620 glibc aix hpux osf solaris cygwin zos
109 VISCII Y glibc
110 TCVN5712-1 glibc
111 ARMSCII-8 glibc freebsd netbsd darwin
112 GEORGIAN-PS glibc cygwin
113 PT154 glibc netbsd cygwin
114 HP-ROMAN8 hpux
115 HP-ARABIC8 hpux
116 HP-GREEK8 hpux
117 HP-HEBREW8 hpux
118 HP-TURKISH8 hpux
119 HP-KANA8 hpux
120 DEC-KANJI osf
121 DEC-HANYU osf
122 UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin zos
123
124 Note: Names which are not marked as being a MIME name should not be used in
125 Internet protocols for information interchange (mail, news, etc.).
126
127 Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
128 must understand both names and treat them as equivalent.
129 */
130
34 131
35#ifdef __cplusplus 132#ifdef __cplusplus
36} 133}
diff --git a/gl/locale.in.h b/gl/locale.in.h
index 264161a..538b834 100644
--- a/gl/locale.in.h
+++ b/gl/locale.in.h
@@ -1,28 +1,31 @@
1/* A POSIX <locale.h>. 1/* A POSIX <locale.h>.
2 Copyright (C) 2007-2013 Free Software Foundation, Inc. 2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation; either version 2.1 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#if __GNUC__ >= 3 17#if __GNUC__ >= 3
18@PRAGMA_SYSTEM_HEADER@ 18@PRAGMA_SYSTEM_HEADER@
19#endif 19#endif
20@PRAGMA_COLUMNS@ 20@PRAGMA_COLUMNS@
21 21
22#ifdef _GL_ALREADY_INCLUDING_LOCALE_H 22#if (defined _WIN32 && !defined __CYGWIN__ && defined __need_locale_t) \
23 || defined _GL_ALREADY_INCLUDING_LOCALE_H
23 24
24/* Special invocation conventions to handle Solaris header files 25/* Special invocation convention:
25 (through Solaris 10) when combined with gettext's libintl.h. */ 26 - Inside mingw header files,
27 - To handle Solaris header files (through Solaris 10) when combined
28 with gettext's libintl.h. */
26 29
27#@INCLUDE_NEXT@ @NEXT_LOCALE_H@ 30#@INCLUDE_NEXT@ @NEXT_LOCALE_H@
28 31
@@ -61,6 +64,18 @@
61# define LC_MESSAGES 1729 64# define LC_MESSAGES 1729
62#endif 65#endif
63 66
67/* On native Windows with MSVC, 'struct lconv' lacks the members int_p_* and
68 int_n_*. Instead of overriding 'struct lconv', merely define these member
69 names as macros. This avoids trouble in C++ mode. */
70#if defined _MSC_VER
71# define int_p_cs_precedes p_cs_precedes
72# define int_p_sign_posn p_sign_posn
73# define int_p_sep_by_space p_sep_by_space
74# define int_n_cs_precedes n_cs_precedes
75# define int_n_sign_posn n_sign_posn
76# define int_n_sep_by_space n_sep_by_space
77#endif
78
64/* Bionic libc's 'struct lconv' is just a dummy. */ 79/* Bionic libc's 'struct lconv' is just a dummy. */
65#if @REPLACE_STRUCT_LCONV@ 80#if @REPLACE_STRUCT_LCONV@
66# define lconv rpl_lconv 81# define lconv rpl_lconv
@@ -69,7 +84,7 @@ struct lconv
69 /* All 'char *' are actually 'const char *'. */ 84 /* All 'char *' are actually 'const char *'. */
70 85
71 /* Members that depend on the LC_NUMERIC category of the locale. See 86 /* Members that depend on the LC_NUMERIC category of the locale. See
72 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_04> */ 87 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_04> */
73 88
74 /* Symbol used as decimal point. */ 89 /* Symbol used as decimal point. */
75 char *decimal_point; 90 char *decimal_point;
@@ -81,7 +96,7 @@ struct lconv
81 char *grouping; 96 char *grouping;
82 97
83 /* Members that depend on the LC_MONETARY category of the locale. See 98 /* Members that depend on the LC_MONETARY category of the locale. See
84 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_03> */ 99 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_03> */
85 100
86 /* Symbol used as decimal point. */ 101 /* Symbol used as decimal point. */
87 char *mon_decimal_point; 102 char *mon_decimal_point;
@@ -153,7 +168,9 @@ _GL_CXXALIAS_RPL (localeconv, struct lconv *, (void));
153# else 168# else
154_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void)); 169_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void));
155# endif 170# endif
171# if __GLIBC__ >= 2
156_GL_CXXALIASWARN (localeconv); 172_GL_CXXALIASWARN (localeconv);
173# endif
157#elif @REPLACE_STRUCT_LCONV@ 174#elif @REPLACE_STRUCT_LCONV@
158# undef localeconv 175# undef localeconv
159# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv 176# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv
@@ -178,7 +195,9 @@ _GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale));
178# else 195# else
179_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale)); 196_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale));
180# endif 197# endif
198# if __GLIBC__ >= 2
181_GL_CXXALIASWARN (setlocale); 199_GL_CXXALIASWARN (setlocale);
200# endif
182#elif defined GNULIB_POSIXCHECK 201#elif defined GNULIB_POSIXCHECK
183# undef setlocale 202# undef setlocale
184# if HAVE_RAW_DECL_SETLOCALE 203# if HAVE_RAW_DECL_SETLOCALE
@@ -187,11 +206,50 @@ _GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - "
187# endif 206# endif
188#endif 207#endif
189 208
190#if @GNULIB_DUPLOCALE@ 209#if @GNULIB_SETLOCALE_NULL@
210/* Included here for convenience. */
211# include "setlocale_null.h"
212#endif
213
214#if /*@GNULIB_NEWLOCALE@ ||*/ (@GNULIB_LOCALENAME@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_NEWLOCALE@)
215# if @REPLACE_NEWLOCALE@
216# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
217# undef newlocale
218# define newlocale rpl_newlocale
219# define GNULIB_defined_newlocale 1
220# endif
221_GL_FUNCDECL_RPL (newlocale, locale_t,
222 (int category_mask, const char *name, locale_t base)
223 _GL_ARG_NONNULL ((2)));
224_GL_CXXALIAS_RPL (newlocale, locale_t,
225 (int category_mask, const char *name, locale_t base));
226# else
227# if @HAVE_NEWLOCALE@
228_GL_CXXALIAS_SYS (newlocale, locale_t,
229 (int category_mask, const char *name, locale_t base));
230# endif
231# endif
232# if @HAVE_NEWLOCALE@
233_GL_CXXALIASWARN (newlocale);
234# endif
235# if @HAVE_NEWLOCALE@ || @REPLACE_NEWLOCALE@
236# ifndef HAVE_WORKING_NEWLOCALE
237# define HAVE_WORKING_NEWLOCALE 1
238# endif
239# endif
240#elif defined GNULIB_POSIXCHECK
241# undef newlocale
242# if HAVE_RAW_DECL_NEWLOCALE
243_GL_WARN_ON_USE (newlocale, "newlocale is not portable");
244# endif
245#endif
246
247#if @GNULIB_DUPLOCALE@ || (@GNULIB_LOCALENAME@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_DUPLOCALE@)
191# if @REPLACE_DUPLOCALE@ 248# if @REPLACE_DUPLOCALE@
192# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 249# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
193# undef duplocale 250# undef duplocale
194# define duplocale rpl_duplocale 251# define duplocale rpl_duplocale
252# define GNULIB_defined_duplocale 1
195# endif 253# endif
196_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1))); 254_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
197_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale)); 255_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
@@ -203,6 +261,11 @@ _GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
203# if @HAVE_DUPLOCALE@ 261# if @HAVE_DUPLOCALE@
204_GL_CXXALIASWARN (duplocale); 262_GL_CXXALIASWARN (duplocale);
205# endif 263# endif
264# if @HAVE_DUPLOCALE@ || @REPLACE_DUPLOCALE@
265# ifndef HAVE_WORKING_DUPLOCALE
266# define HAVE_WORKING_DUPLOCALE 1
267# endif
268# endif
206#elif defined GNULIB_POSIXCHECK 269#elif defined GNULIB_POSIXCHECK
207# undef duplocale 270# undef duplocale
208# if HAVE_RAW_DECL_DUPLOCALE 271# if HAVE_RAW_DECL_DUPLOCALE
@@ -211,6 +274,32 @@ _GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
211# endif 274# endif
212#endif 275#endif
213 276
277#if /*@GNULIB_FREELOCALE@ ||*/ (@GNULIB_LOCALENAME@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_FREELOCALE@)
278# if @REPLACE_FREELOCALE@
279# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
280# undef freelocale
281# define freelocale rpl_freelocale
282# define GNULIB_defined_freelocale 1
283# endif
284_GL_FUNCDECL_RPL (freelocale, void, (locale_t locale) _GL_ARG_NONNULL ((1)));
285_GL_CXXALIAS_RPL (freelocale, void, (locale_t locale));
286# else
287# if @HAVE_FREELOCALE@
288/* Need to cast, because on FreeBSD and Mac OS X 10.13, the return type is
289 int. */
290_GL_CXXALIAS_SYS_CAST (freelocale, void, (locale_t locale));
291# endif
292# endif
293# if @HAVE_FREELOCALE@
294_GL_CXXALIASWARN (freelocale);
295# endif
296#elif defined GNULIB_POSIXCHECK
297# undef freelocale
298# if HAVE_RAW_DECL_FREELOCALE
299_GL_WARN_ON_USE (freelocale, "freelocale is not portable");
300# endif
301#endif
302
214#endif /* _@GUARD_PREFIX@_LOCALE_H */ 303#endif /* _@GUARD_PREFIX@_LOCALE_H */
215#endif /* ! _GL_ALREADY_INCLUDING_LOCALE_H */
216#endif /* _@GUARD_PREFIX@_LOCALE_H */ 304#endif /* _@GUARD_PREFIX@_LOCALE_H */
305#endif /* !(__need_locale_t || _GL_ALREADY_INCLUDING_LOCALE_H) */
diff --git a/gl/localeconv.c b/gl/localeconv.c
index 7c7c77c..60c050f 100644
--- a/gl/localeconv.c
+++ b/gl/localeconv.c
@@ -1,18 +1,18 @@
1/* Query locale dependent information for formatting numbers. 1/* Query locale dependent information for formatting numbers.
2 Copyright (C) 2012-2013 Free Software Foundation, Inc. 2 Copyright (C) 2012-2023 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation; either version 2.1 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
diff --git a/gl/lseek.c b/gl/lseek.c
new file mode 100644
index 0000000..7919b03
--- /dev/null
+++ b/gl/lseek.c
@@ -0,0 +1,89 @@
1/* An lseek() function that detects pipes.
2 Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <unistd.h>
21
22#if defined _WIN32 && ! defined __CYGWIN__
23/* Windows platforms. */
24/* Get GetFileType. */
25# include <windows.h>
26/* Get _get_osfhandle. */
27# if GNULIB_MSVC_NOTHROW
28# include "msvc-nothrow.h"
29# else
30# include <io.h>
31# endif
32#else
33# include <sys/stat.h>
34#endif
35#include <errno.h>
36
37#undef lseek
38
39off_t
40rpl_lseek (int fd, off_t offset, int whence)
41{
42#if defined _WIN32 && ! defined __CYGWIN__
43 /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */
44 HANDLE h = (HANDLE) _get_osfhandle (fd);
45 if (h == INVALID_HANDLE_VALUE)
46 {
47 errno = EBADF;
48 return -1;
49 }
50 if (GetFileType (h) != FILE_TYPE_DISK)
51 {
52 errno = ESPIPE;
53 return -1;
54 }
55#elif defined __APPLE__ && defined __MACH__ && defined SEEK_DATA
56 if (whence == SEEK_DATA)
57 {
58 /* If OFFSET points to data, macOS lseek+SEEK_DATA returns the
59 start S of the first data region that begins *after* OFFSET,
60 where the region from OFFSET to S consists of possibly-empty
61 data followed by a possibly-empty hole. To work around this
62 portability glitch, check whether OFFSET is within data by
63 using lseek+SEEK_HOLE, and if so return to OFFSET by using
64 lseek+SEEK_SET. Also, contrary to the macOS documentation,
65 lseek+SEEK_HOLE can fail with ENXIO if there are no holes on
66 or after OFFSET. What a mess! */
67 off_t next_hole = lseek (fd, offset, SEEK_HOLE);
68 if (next_hole < 0)
69 return errno == ENXIO ? offset : next_hole;
70 if (next_hole != offset)
71 whence = SEEK_SET;
72 }
73#else
74 /* BeOS lseek mistakenly succeeds on pipes... */
75 struct stat statbuf;
76 if (fstat (fd, &statbuf) < 0)
77 return -1;
78 if (!S_ISREG (statbuf.st_mode))
79 {
80 errno = ESPIPE;
81 return -1;
82 }
83#endif
84#if _GL_WINDOWS_64_BIT_OFF_T || (defined __MINGW32__ && defined _FILE_OFFSET_BITS && (_FILE_OFFSET_BITS == 64))
85 return _lseeki64 (fd, offset, whence);
86#else
87 return lseek (fd, offset, whence);
88#endif
89}
diff --git a/gl/m4/00gnulib.m4 b/gl/m4/00gnulib.m4
index d4ad759..7fe03e0 100644
--- a/gl/m4/00gnulib.m4
+++ b/gl/m4/00gnulib.m4
@@ -1,27 +1,82 @@
1# 00gnulib.m4 serial 2 1# 00gnulib.m4 serial 8
2dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2023 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 This file must be named something that sorts before all other 7dnl This file must be named something that sorts before all other
8dnl gnulib-provided .m4 files. It is needed until such time as we can 8dnl gnulib-provided .m4 files. It is needed until the clang fix has
9dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics. 9dnl been included in Autoconf.
10 10
11# AC_DEFUN_ONCE([NAME], VALUE) 11# The following definitions arrange to use a compiler option
12# ---------------------------- 12# -Werror=implicit-function-declaration in AC_CHECK_DECL, when the
13# Define NAME to expand to VALUE on the first use (whether by direct 13# compiler is clang. Without it, clang implicitly declares "known"
14# expansion, or by AC_REQUIRE), and to nothing on all subsequent uses. 14# library functions in C mode, but not in C++ mode, which would cause
15# Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This 15# Gnulib to omit a declaration and thus later produce an error in C++
16# definition is slower than the version in Autoconf 2.64, because it 16# mode. As of clang 9.0, these "known" functions are identified through
17# can only use interfaces that existed since 2.59; but it achieves the 17# LIBBUILTIN invocations in the LLVM source file
18# same effect. Quoting is necessary to avoid confusing Automake. 18# llvm/tools/clang/include/clang/Basic/Builtins.def.
19m4_version_prereq([2.63.263], [], 19# It's not possible to AC_REQUIRE the extra tests from AC_CHECK_DECL,
20[m4_define([AC][_DEFUN_ONCE], 20# because AC_CHECK_DECL, like other Autoconf built-ins, is not supposed
21 [AC][_DEFUN([$1], 21# to AC_REQUIRE anything: some configure.ac files have their first
22 [AC_REQUIRE([_gl_DEFUN_ONCE([$1])], 22# AC_CHECK_DECL executed conditionally. Therefore append the extra tests
23 [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl 23# to AC_PROG_CC.
24[AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])]) 24AC_DEFUN([gl_COMPILER_CLANG],
25[
26dnl AC_REQUIRE([AC_PROG_CC])
27 AC_CACHE_CHECK([whether the compiler is clang],
28 [gl_cv_compiler_clang],
29 [dnl Use _AC_COMPILE_IFELSE instead of AC_EGREP_CPP, to avoid error
30 dnl "circular dependency of AC_LANG_COMPILER(C)" if AC_PROG_CC has
31 dnl not yet been invoked.
32 _AC_COMPILE_IFELSE(
33 [AC_LANG_PROGRAM([[
34 #ifdef __clang__
35 barfbarf
36 #endif
37 ]],[[]])
38 ],
39 [gl_cv_compiler_clang=no],
40 [gl_cv_compiler_clang=yes])
41 ])
42])
43AC_DEFUN([gl_COMPILER_PREPARE_CHECK_DECL],
44[
45dnl AC_REQUIRE([AC_PROG_CC])
46dnl AC_REQUIRE([gl_COMPILER_CLANG])
47 AC_CACHE_CHECK([for compiler option needed when checking for declarations],
48 [gl_cv_compiler_check_decl_option],
49 [if test $gl_cv_compiler_clang = yes; then
50 dnl Test whether the compiler supports the option
51 dnl '-Werror=implicit-function-declaration'.
52 save_ac_compile="$ac_compile"
53 ac_compile="$ac_compile -Werror=implicit-function-declaration"
54 dnl Use _AC_COMPILE_IFELSE instead of AC_COMPILE_IFELSE, to avoid a
55 dnl warning "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
56 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
57 [gl_cv_compiler_check_decl_option='-Werror=implicit-function-declaration'],
58 [gl_cv_compiler_check_decl_option=none])
59 ac_compile="$save_ac_compile"
60 else
61 gl_cv_compiler_check_decl_option=none
62 fi
63 ])
64 if test "x$gl_cv_compiler_check_decl_option" != xnone; then
65 ac_compile_for_check_decl="$ac_compile $gl_cv_compiler_check_decl_option"
66 else
67 ac_compile_for_check_decl="$ac_compile"
68 fi
69])
70dnl Redefine _AC_CHECK_DECL_BODY so that it references ac_compile_for_check_decl
71dnl instead of ac_compile. If, for whatever reason, the override of AC_PROG_CC
72dnl in zzgnulib.m4 is inactive, use the original ac_compile.
73m4_define([_AC_CHECK_DECL_BODY],
74[ ac_save_ac_compile="$ac_compile"
75 if test -n "$ac_compile_for_check_decl"; then
76 ac_compile="$ac_compile_for_check_decl"
77 fi]
78m4_defn([_AC_CHECK_DECL_BODY])[ ac_compile="$ac_save_ac_compile"
79])
25 80
26# gl_00GNULIB 81# gl_00GNULIB
27# ----------- 82# -----------
diff --git a/gl/m4/__inline.m4 b/gl/m4/__inline.m4
new file mode 100644
index 0000000..acf8668
--- /dev/null
+++ b/gl/m4/__inline.m4
@@ -0,0 +1,22 @@
1# Test for __inline keyword
2dnl Copyright 2017-2023 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___INLINE],
8[
9 AC_CACHE_CHECK([whether the compiler supports the __inline keyword],
10 [gl_cv_c___inline],
11 [AC_COMPILE_IFELSE(
12 [AC_LANG_PROGRAM(
13 [[typedef int foo_t;
14 static __inline foo_t foo (void) { return 0; }]],
15 [[return foo ();]])],
16 [gl_cv_c___inline=yes],
17 [gl_cv_c___inline=no])])
18 if test $gl_cv_c___inline = yes; then
19 AC_DEFINE([HAVE___INLINE], [1],
20 [Define to 1 if the compiler supports the keyword '__inline'.])
21 fi
22])
diff --git a/gl/m4/absolute-header.m4 b/gl/m4/absolute-header.m4
new file mode 100644
index 0000000..e794764
--- /dev/null
+++ b/gl/m4/absolute-header.m4
@@ -0,0 +1,100 @@
1# absolute-header.m4 serial 17
2dnl Copyright (C) 2006-2023 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 Derek Price.
8
9# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
10# ---------------------------------------
11# Find the absolute name of a header file, testing first if the header exists.
12# If the header were sys/inttypes.h, this macro would define
13# ABSOLUTE_SYS_INTTYPES_H to the '""' quoted absolute name of sys/inttypes.h
14# in config.h
15# (e.g. '#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
16# The three "///" are to pacify Sun C 5.8, which otherwise would say
17# "warning: #include of /usr/include/... may be non-portable".
18# Use '""', not '<>', so that the /// cannot be confused with a C99 comment.
19# Note: This macro assumes that the header file is not empty after
20# preprocessing, i.e. it does not only define preprocessor macros but also
21# provides some type/enum definitions or function/variable declarations.
22AC_DEFUN([gl_ABSOLUTE_HEADER],
23[AC_REQUIRE([AC_CANONICAL_HOST])
24AC_LANG_PREPROC_REQUIRE()dnl
25m4_foreach_w([gl_HEADER_NAME], [$1],
26 [AS_VAR_PUSHDEF([gl_absolute_header],
27 [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
28 AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
29 [gl_absolute_header],
30 [AS_VAR_PUSHDEF([ac_header_exists],
31 [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
32 AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
33 if test AS_VAR_GET([ac_header_exists]) = yes; then
34 gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
35 fi
36 AS_VAR_POPDEF([ac_header_exists])dnl
37 ])dnl
38 AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
39 ["AS_VAR_GET([gl_absolute_header])"],
40 [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
41 AS_VAR_POPDEF([gl_absolute_header])dnl
42])dnl
43])# gl_ABSOLUTE_HEADER
44
45# gl_ABSOLUTE_HEADER_ONE(HEADER)
46# ------------------------------
47# Like gl_ABSOLUTE_HEADER, except that:
48# - it assumes that the header exists,
49# - it uses the current CPPFLAGS,
50# - it does not cache the result,
51# - it is silent.
52AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
53[
54 AC_REQUIRE([AC_CANONICAL_HOST])
55 AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])])
56 dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
57 dnl that contain only a #include of other header files and no
58 dnl non-comment tokens of their own. This leads to a failure to
59 dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
60 dnl and others. The workaround is to force preservation of comments
61 dnl through option -C. This ensures all necessary #line directives
62 dnl are present. GCC supports option -C as well.
63 case "$host_os" in
64 aix*) gl_absname_cpp="$ac_cpp -C" ;;
65 *) gl_absname_cpp="$ac_cpp" ;;
66 esac
67changequote(,)
68 case "$host_os" in
69 mingw*)
70 dnl For the sake of native Windows compilers (excluding gcc),
71 dnl treat backslash as a directory separator, like /.
72 dnl Actually, these compilers use a double-backslash as
73 dnl directory separator, inside the
74 dnl # line "filename"
75 dnl directives.
76 gl_dirsep_regex='[/\\]'
77 ;;
78 *)
79 gl_dirsep_regex='\/'
80 ;;
81 esac
82 dnl A sed expression that turns a string into a basic regular
83 dnl expression, for use within "/.../".
84 gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
85 gl_header_literal_regex=`echo '$1' \
86 | sed -e "$gl_make_literal_regex_sed"`
87 gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
88 s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
89 s|^/[^/]|//&|
90 p
91 q
92 }'
93changequote([,])
94 dnl eval is necessary to expand gl_absname_cpp.
95 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
96 dnl so use subshell.
97 AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
98[`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
99 sed -n "$gl_absolute_header_sed"`])
100])
diff --git a/gl/m4/af_alg.m4 b/gl/m4/af_alg.m4
new file mode 100644
index 0000000..f4c0d62
--- /dev/null
+++ b/gl/m4/af_alg.m4
@@ -0,0 +1,57 @@
1# af_alg.m4 serial 6
2dnl Copyright 2018-2023 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 Matteo Croce.
8
9AC_DEFUN_ONCE([gl_AF_ALG],
10[
11 AC_REQUIRE([gl_SYS_SOCKET_H])
12 AC_REQUIRE([AC_C_INLINE])
13
14 dnl Check whether linux/if_alg.h has needed features.
15 AC_CACHE_CHECK([whether linux/if_alg.h has struct sockaddr_alg.],
16 [gl_cv_header_linux_if_alg_salg],
17 [AC_COMPILE_IFELSE(
18 [AC_LANG_PROGRAM([[#include <sys/socket.h>
19 #include <linux/if_alg.h>
20 struct sockaddr_alg salg = {
21 .salg_family = AF_ALG,
22 .salg_type = "hash",
23 .salg_name = "sha1",
24 };]])],
25 [gl_cv_header_linux_if_alg_salg=yes],
26 [gl_cv_header_linux_if_alg_salg=no])])
27 if test "$gl_cv_header_linux_if_alg_salg" = yes; then
28 AC_DEFINE([HAVE_LINUX_IF_ALG_H], [1],
29 [Define to 1 if you have 'struct sockaddr_alg' defined.])
30 fi
31
32 dnl The default is to not use AF_ALG if available,
33 dnl as it's system dependent as to whether the kernel
34 dnl routines are faster than libcrypto for example.
35 use_af_alg=no
36 AC_ARG_WITH([linux-crypto],
37 [AS_HELP_STRING([[--with-linux-crypto]],
38 [use Linux kernel cryptographic API (if available) for the hash functions
39 MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512 on files])],
40 [use_af_alg=$withval],
41 [use_af_alg=no])
42 dnl We cannot use it if it is not available.
43 if test "$gl_cv_header_linux_if_alg_salg" != yes; then
44 if test "$use_af_alg" != no; then
45 AC_MSG_WARN([Linux kernel cryptographic API not found])
46 fi
47 use_af_alg=no
48 fi
49
50 if test "$use_af_alg" != no; then
51 USE_AF_ALG=1
52 else
53 USE_AF_ALG=0
54 fi
55 AC_DEFINE_UNQUOTED([USE_LINUX_CRYPTO_API], [$USE_AF_ALG],
56 [Define to 1 if you want to use the Linux kernel cryptographic API.])
57])
diff --git a/gl/m4/alloca.m4 b/gl/m4/alloca.m4
index 270abd0..c685fac 100644
--- a/gl/m4/alloca.m4
+++ b/gl/m4/alloca.m4
@@ -1,5 +1,5 @@
1# alloca.m4 serial 14 1# alloca.m4 serial 21
2dnl Copyright (C) 2002-2004, 2006-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2002-2004, 2006-2007, 2009-2023 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
@@ -26,30 +26,35 @@ AC_DEFUN([gl_FUNC_ALLOCA],
26 AC_DEFINE([HAVE_ALLOCA], [1], 26 AC_DEFINE([HAVE_ALLOCA], [1],
27 [Define to 1 if you have 'alloca' after including <alloca.h>, 27 [Define to 1 if you have 'alloca' after including <alloca.h>,
28 a header that may be supplied by this distribution.]) 28 a header that may be supplied by this distribution.])
29 ALLOCA_H=alloca.h 29 GL_GENERATE_ALLOCA_H=true
30 else 30 else
31 dnl alloca exists as a library function, i.e. it is slow and probably 31 dnl alloca exists as a library function, i.e. it is slow and probably
32 dnl a memory leak. Don't define HAVE_ALLOCA in this case. 32 dnl a memory leak. Don't define HAVE_ALLOCA in this case.
33 ALLOCA_H= 33 GL_GENERATE_ALLOCA_H=false
34 fi 34 fi
35 else 35 else
36 ALLOCA_H=alloca.h 36 GL_GENERATE_ALLOCA_H=true
37 fi 37 fi
38 AC_SUBST([ALLOCA_H]) 38
39 AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"]) 39 if test $ac_cv_working_alloca_h = yes; then
40 HAVE_ALLOCA_H=1
41 else
42 HAVE_ALLOCA_H=0
43 fi
44 AC_SUBST([HAVE_ALLOCA_H])
40]) 45])
41 46
42# Prerequisites of lib/alloca.c. 47# Prerequisites of lib/alloca.c.
43# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. 48# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
44AC_DEFUN([gl_PREREQ_ALLOCA], [:]) 49AC_DEFUN([gl_PREREQ_ALLOCA], [:])
45 50
46# This works around a bug in autoconf <= 2.68. 51m4_version_prereq([2.70], [], [
47# See <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00277.html>.
48 52
49m4_version_prereq([2.69], [] ,[ 53# This works around a bug in autoconf <= 2.68 and has simplifications
50 54# from 2.70. See:
51# This is taken from the following Autoconf patch: 55# https://lists.gnu.org/r/bug-gnulib/2011-06/msg00277.html
52# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497 56# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497
57# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=15edf7fd8094fd14a89d9891dd72a9624762597a
53 58
54# _AC_LIBOBJ_ALLOCA 59# _AC_LIBOBJ_ALLOCA
55# ----------------- 60# -----------------
@@ -65,26 +70,6 @@ AC_LIBSOURCES(alloca.c)
65AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl 70AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
66AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.]) 71AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.])
67 72
68AC_CACHE_CHECK(whether 'alloca.c' needs Cray hooks, ac_cv_os_cray,
69[AC_EGREP_CPP(webecray,
70[#if defined CRAY && ! defined CRAY2
71webecray
72#else
73wenotbecray
74#endif
75], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
76if test $ac_cv_os_cray = yes; then
77 for ac_func in _getb67 GETB67 getb67; do
78 AC_CHECK_FUNC($ac_func,
79 [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
80 [Define to one of '_getb67', 'GETB67',
81 'getb67' for Cray-2 and Cray-YMP
82 systems. This function is required for
83 'alloca.c' support on those systems.])
84 break])
85 done
86fi
87
88AC_CACHE_CHECK([stack direction for C alloca], 73AC_CACHE_CHECK([stack direction for C alloca],
89 [ac_cv_c_stack_direction], 74 [ac_cv_c_stack_direction],
90[AC_RUN_IFELSE([AC_LANG_SOURCE( 75[AC_RUN_IFELSE([AC_LANG_SOURCE(
@@ -115,7 +100,7 @@ AH_VERBATIM([STACK_DIRECTION],
115 STACK_DIRECTION > 0 => grows toward higher addresses 100 STACK_DIRECTION > 0 => grows toward higher addresses
116 STACK_DIRECTION < 0 => grows toward lower addresses 101 STACK_DIRECTION < 0 => grows toward lower addresses
117 STACK_DIRECTION = 0 => direction of growth unknown */ 102 STACK_DIRECTION = 0 => direction of growth unknown */
118@%:@undef STACK_DIRECTION])dnl 103#undef STACK_DIRECTION])dnl
119AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) 104AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
120])# _AC_LIBOBJ_ALLOCA 105])# _AC_LIBOBJ_ALLOCA
121]) 106])
diff --git a/gl/m4/arpa_inet_h.m4 b/gl/m4/arpa_inet_h.m4
index ea69af5..fa5fe83 100644
--- a/gl/m4/arpa_inet_h.m4
+++ b/gl/m4/arpa_inet_h.m4
@@ -1,15 +1,15 @@
1# arpa_inet_h.m4 serial 13 1# arpa_inet_h.m4 serial 17
2dnl Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2008-2023 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 and Bruno Haible 7dnl Written by Simon Josefsson and Bruno Haible
8 8
9AC_DEFUN([gl_HEADER_ARPA_INET], 9AC_DEFUN_ONCE([gl_ARPA_INET_H],
10[ 10[
11 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 11 dnl Ensure to expand the default settings once only, before all statements
12 dnl once only, before all statements that occur in other macros. 12 dnl that occur in other macros.
13 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS]) 13 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
14 14
15 AC_CHECK_HEADERS_ONCE([arpa/inet.h]) 15 AC_CHECK_HEADERS_ONCE([arpa/inet.h])
@@ -24,6 +24,8 @@ AC_DEFUN([gl_HEADER_ARPA_INET],
24 24
25 AC_REQUIRE([gl_FEATURES_H]) 25 AC_REQUIRE([gl_FEATURES_H])
26 26
27 gl_PREREQ_SYS_H_WS2TCPIP
28
27 dnl Check for declarations of anything we want to poison if the 29 dnl Check for declarations of anything we want to poison if the
28 dnl corresponding gnulib module is not in use. 30 dnl corresponding gnulib module is not in use.
29 gl_WARN_ON_USE_PREPARE([[ 31 gl_WARN_ON_USE_PREPARE([[
@@ -38,17 +40,32 @@ AC_DEFUN([gl_HEADER_ARPA_INET],
38 ]], [inet_ntop inet_pton]) 40 ]], [inet_ntop inet_pton])
39]) 41])
40 42
43# gl_ARPA_INET_MODULE_INDICATOR([modulename])
44# sets the shell variable that indicates the presence of the given module
45# to a C preprocessor expression that will evaluate to 1.
46# This macro invocation must not occur in macros that are AC_REQUIREd.
41AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR], 47AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR],
42[ 48[
43 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 49 dnl Ensure to expand the default settings once only.
44 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS]) 50 gl_ARPA_INET_H_REQUIRE_DEFAULTS
45 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 51 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
46]) 52])
47 53
54# Initializes the default values for AC_SUBSTed shell variables.
55# This macro must not be AC_REQUIREd. It must only be invoked, and only
56# outside of macros or in macros that are not AC_REQUIREd.
57AC_DEFUN([gl_ARPA_INET_H_REQUIRE_DEFAULTS],
58[
59 m4_defun(GL_MODULE_INDICATOR_PREFIX[_ARPA_INET_H_MODULE_INDICATOR_DEFAULTS], [
60 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_INET_NTOP])
61 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_INET_PTON])
62 ])
63 m4_require(GL_MODULE_INDICATOR_PREFIX[_ARPA_INET_H_MODULE_INDICATOR_DEFAULTS])
64 AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
65])
66
48AC_DEFUN([gl_ARPA_INET_H_DEFAULTS], 67AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
49[ 68[
50 GNULIB_INET_NTOP=0; AC_SUBST([GNULIB_INET_NTOP])
51 GNULIB_INET_PTON=0; AC_SUBST([GNULIB_INET_PTON])
52 dnl Assume proper GNU behavior unless another module says otherwise. 69 dnl Assume proper GNU behavior unless another module says otherwise.
53 HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP]) 70 HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP])
54 HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON]) 71 HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON])
diff --git a/gl/m4/assert_h.m4 b/gl/m4/assert_h.m4
new file mode 100644
index 0000000..abba4fa
--- /dev/null
+++ b/gl/m4/assert_h.m4
@@ -0,0 +1,67 @@
1# assert-h.m4
2dnl Copyright (C) 2011-2023 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
9AC_DEFUN([gl_ASSERT_H],
10[
11 AC_CACHE_CHECK([for static_assert], [gl_cv_static_assert],
12 [gl_save_CFLAGS=$CFLAGS
13 for gl_working in "yes, a keyword" "yes, an <assert.h> macro"; do
14 AS_CASE([$gl_working],
15 [*assert.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_ASSERT_H"])
16
17 AC_COMPILE_IFELSE(
18 [AC_LANG_PROGRAM(
19 [[#if defined __clang__ && __STDC_VERSION__ < 202311
20 #pragma clang diagnostic error "-Wc2x-extensions"
21 #pragma clang diagnostic error "-Wc++17-extensions"
22 #endif
23 #ifdef INCLUDE_ASSERT_H
24 #include <assert.h>
25 #endif
26 static_assert (2 + 2 == 4, "arithmetic does not work");
27 static_assert (2 + 2 == 4);
28 ]],
29 [[
30 static_assert (sizeof (char) == 1, "sizeof does not work");
31 static_assert (sizeof (char) == 1);
32 ]])],
33 [gl_cv_static_assert=$gl_working],
34 [gl_cv_static_assert=no])
35 CFLAGS=$gl_save_CFLAGS
36 test "$gl_cv_static_assert" != no && break
37 done])
38
39 GL_GENERATE_ASSERT_H=false
40 AS_CASE([$gl_cv_static_assert],
41 [yes*keyword*],
42 [AC_DEFINE([HAVE_C_STATIC_ASSERT], [1],
43 [Define to 1 if the static_assert keyword works.])],
44 [no],
45 [GL_GENERATE_ASSERT_H=true
46 gl_NEXT_HEADERS([assert.h])])
47
48 dnl The "zz" puts this toward config.h's end, to avoid potential
49 dnl collisions with other definitions. #undef assert so that
50 dnl programs are not tempted to use it without specifically
51 dnl including assert.h. Break the #undef apart with a comment
52 dnl so that 'configure' does not comment it out.
53 AH_VERBATIM([zzstatic_assert],
54[#if (!defined HAVE_C_STATIC_ASSERT && !defined assert \
55 && (!defined __cplusplus \
56 || (__cpp_static_assert < 201411 \
57 && __GNUG__ < 6 && __clang_major__ < 6)))
58 #include <assert.h>
59 #undef/**/assert
60 /* Solaris 11.4 <assert.h> defines static_assert as a macro with 2 arguments.
61 We need it also to be invocable with a single argument. */
62 #if defined __sun && (__STDC_VERSION__ - 0 >= 201112L) && !defined __cplusplus
63 #undef/**/static_assert
64 #define static_assert _Static_assert
65 #endif
66#endif])
67])
diff --git a/gl/m4/base64.m4 b/gl/m4/base64.m4
index fc19893..987930a 100644
--- a/gl/m4/base64.m4
+++ b/gl/m4/base64.m4
@@ -1,5 +1,5 @@
1# base64.m4 serial 4 1# base64.m4 serial 4
2dnl Copyright (C) 2004, 2006, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/btowc.m4 b/gl/m4/btowc.m4
index 978a06e..77218a7 100644
--- a/gl/m4/btowc.m4
+++ b/gl/m4/btowc.m4
@@ -1,5 +1,5 @@
1# btowc.m4 serial 10 1# btowc.m4 serial 12
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -10,7 +10,7 @@ AC_DEFUN([gl_FUNC_BTOWC],
10 10
11 dnl Check whether <wchar.h> is usable at all, first. Otherwise the test 11 dnl Check whether <wchar.h> is usable at all, first. Otherwise the test
12 dnl program below may lead to an endless loop. See 12 dnl program below may lead to an endless loop. See
13 dnl <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. 13 dnl <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>.
14 AC_REQUIRE([gl_WCHAR_H_INLINE_OK]) 14 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
15 15
16 AC_CHECK_FUNCS_ONCE([btowc]) 16 AC_CHECK_FUNCS_ONCE([btowc])
@@ -28,14 +28,6 @@ AC_DEFUN([gl_FUNC_BTOWC],
28 [ 28 [
29 AC_RUN_IFELSE( 29 AC_RUN_IFELSE(
30 [AC_LANG_SOURCE([[ 30 [AC_LANG_SOURCE([[
31#include <string.h>
32/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
33 <wchar.h>.
34 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
35 included before <wchar.h>. */
36#include <stddef.h>
37#include <stdio.h>
38#include <time.h>
39#include <wchar.h> 31#include <wchar.h>
40int main () 32int main ()
41{ 33{
@@ -50,6 +42,8 @@ changequote(,)dnl
50 case "$host_os" in 42 case "$host_os" in
51 # Guess no on Cygwin. 43 # Guess no on Cygwin.
52 cygwin*) gl_cv_func_btowc_nul="guessing no" ;; 44 cygwin*) gl_cv_func_btowc_nul="guessing no" ;;
45 # Guess yes on native Windows.
46 mingw*) gl_cv_func_btowc_nul="guessing yes" ;;
53 # Guess yes otherwise. 47 # Guess yes otherwise.
54 *) gl_cv_func_btowc_nul="guessing yes" ;; 48 *) gl_cv_func_btowc_nul="guessing yes" ;;
55 esac 49 esac
@@ -65,24 +59,19 @@ changequote([,])dnl
65 dnl is present. 59 dnl is present.
66changequote(,)dnl 60changequote(,)dnl
67 case "$host_os" in 61 case "$host_os" in
68 # Guess no on IRIX. 62 # Guess no on IRIX.
69 irix*) gl_cv_func_btowc_eof="guessing no" ;; 63 irix*) gl_cv_func_btowc_eof="guessing no" ;;
70 # Guess yes otherwise. 64 # Guess yes on native Windows.
71 *) gl_cv_func_btowc_eof="guessing yes" ;; 65 mingw*) gl_cv_func_btowc_eof="guessing yes" ;;
66 # Guess yes otherwise.
67 *) gl_cv_func_btowc_eof="guessing yes" ;;
72 esac 68 esac
73changequote([,])dnl 69changequote([,])dnl
74 if test $LOCALE_FR != none; then 70 if test $LOCALE_FR != none; then
75 AC_RUN_IFELSE( 71 AC_RUN_IFELSE(
76 [AC_LANG_SOURCE([[ 72 [AC_LANG_SOURCE([[
77#include <locale.h> 73#include <locale.h>
78#include <string.h>
79/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
80 <wchar.h>.
81 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
82 included before <wchar.h>. */
83#include <stddef.h>
84#include <stdio.h> 74#include <stdio.h>
85#include <time.h>
86#include <wchar.h> 75#include <wchar.h>
87int main () 76int main ()
88{ 77{
diff --git a/gl/m4/builtin-expect.m4 b/gl/m4/builtin-expect.m4
new file mode 100644
index 0000000..531ed48
--- /dev/null
+++ b/gl/m4/builtin-expect.m4
@@ -0,0 +1,49 @@
1dnl Check for __builtin_expect.
2
3dnl Copyright 2016-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8dnl Written by Paul Eggert.
9
10AC_DEFUN([gl___BUILTIN_EXPECT],
11[
12 AC_CACHE_CHECK([for __builtin_expect],
13 [gl_cv___builtin_expect],
14 [AC_LINK_IFELSE(
15 [AC_LANG_SOURCE([[
16 int
17 main (int argc, char **argv)
18 {
19 argc = __builtin_expect (argc, 100);
20 return argv[argc != 100][0];
21 }]])],
22 [gl_cv___builtin_expect=yes],
23 [AC_LINK_IFELSE(
24 [AC_LANG_SOURCE([[
25 #include <builtins.h>
26 int
27 main (int argc, char **argv)
28 {
29 argc = __builtin_expect (argc, 100);
30 return argv[argc != 100][0];
31 }]])],
32 [gl_cv___builtin_expect="in <builtins.h>"],
33 [gl_cv___builtin_expect=no])])])
34 if test "$gl_cv___builtin_expect" = yes; then
35 AC_DEFINE([HAVE___BUILTIN_EXPECT], [1])
36 elif test "$gl_cv___builtin_expect" = "in <builtins.h>"; then
37 AC_DEFINE([HAVE___BUILTIN_EXPECT], [2])
38 fi
39 AH_VERBATIM([HAVE___BUILTIN_EXPECT],
40 [/* Define to 1 if the compiler supports __builtin_expect,
41 and to 2 if <builtins.h> does. */
42#undef HAVE___BUILTIN_EXPECT
43#ifndef HAVE___BUILTIN_EXPECT
44# define __builtin_expect(e, c) (e)
45#elif HAVE___BUILTIN_EXPECT == 2
46# include <builtins.h>
47#endif
48 ])
49])
diff --git a/gl/m4/byteswap.m4 b/gl/m4/byteswap.m4
new file mode 100644
index 0000000..8058d17
--- /dev/null
+++ b/gl/m4/byteswap.m4
@@ -0,0 +1,17 @@
1# byteswap.m4 serial 5
2dnl Copyright (C) 2005, 2007, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl Written by Oskar Liljeblad.
8
9AC_DEFUN([gl_BYTESWAP],
10[
11 dnl Prerequisites of lib/byteswap.in.h.
12 AC_CHECK_HEADERS([byteswap.h], [
13 GL_GENERATE_BYTESWAP_H=false
14 ], [
15 GL_GENERATE_BYTESWAP_H=true
16 ])
17])
diff --git a/gl/m4/c-bool.m4 b/gl/m4/c-bool.m4
new file mode 100644
index 0000000..f614371
--- /dev/null
+++ b/gl/m4/c-bool.m4
@@ -0,0 +1,51 @@
1# Check for bool that conforms to C2023.
2
3dnl Copyright 2022-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_C_BOOL],
9[
10 AC_CACHE_CHECK([for bool, true, false], [gl_cv_c_bool],
11 [AC_COMPILE_IFELSE(
12 [AC_LANG_SOURCE([[
13 #if true == false
14 #error "true == false"
15 #endif
16 extern bool b;
17 bool b = true == false;]])],
18 [gl_cv_c_bool=yes],
19 [gl_cv_c_bool=no])])
20 if test "$gl_cv_c_bool" = yes; then
21 AC_DEFINE([HAVE_C_BOOL], [1],
22 [Define to 1 if bool, true and false work as per C2023.])
23 fi
24
25 AC_CHECK_HEADERS_ONCE([stdbool.h])
26
27 dnl The "zz" puts this toward config.h's end, to avoid potential
28 dnl collisions with other definitions.
29 dnl If 'bool', 'true' and 'false' do not work, arrange for them to work.
30 dnl In C, this means including <stdbool.h> if it is not already included.
31 dnl However, if the preprocessor mistakenly treats 'true' as 0,
32 dnl define it to a bool expression equal to 1; this is needed in
33 dnl Sun C++ 5.11 (Oracle Solaris Studio 12.2, 2010) and older.
34 AH_VERBATIM([zzbool],
35[#ifndef HAVE_C_BOOL
36# if !defined __cplusplus && !defined __bool_true_false_are_defined
37# if HAVE_STDBOOL_H
38# include <stdbool.h>
39# else
40# if defined __SUNPRO_C
41# error "<stdbool.h> is not usable with this configuration. To make it usable, add -D_STDC_C99= to $CC."
42# else
43# error "<stdbool.h> does not exist on this platform. Use gnulib module 'stdbool-c99' instead of gnulib module 'stdbool'."
44# endif
45# endif
46# endif
47# if !true
48# define true (!false)
49# endif
50#endif])
51])
diff --git a/gl/m4/calloc.m4 b/gl/m4/calloc.m4
new file mode 100644
index 0000000..23c0dd9
--- /dev/null
+++ b/gl/m4/calloc.m4
@@ -0,0 +1,83 @@
1# calloc.m4 serial 29
2
3# Copyright (C) 2004-2023 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# Written by Jim Meyering.
9
10# Determine whether calloc (N, S) returns non-NULL when N*S is zero,
11# and returns NULL when N*S overflows.
12# If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc
13# and arrange to use a calloc wrapper function that does work in that case.
14
15# _AC_FUNC_CALLOC_IF([IF-WORKS], [IF-NOT])
16# -------------------------------------
17# If calloc is compatible with GNU calloc, run IF-WORKS, otherwise, IF-NOT.
18AC_DEFUN([_AC_FUNC_CALLOC_IF],
19[
20 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
21 AC_CACHE_CHECK([whether calloc (0, n) and calloc (n, 0) return nonnull],
22 [ac_cv_func_calloc_0_nonnull],
23 [if test $cross_compiling != yes; then
24 ac_cv_func_calloc_0_nonnull=yes
25 AC_RUN_IFELSE(
26 [AC_LANG_PROGRAM(
27 [AC_INCLUDES_DEFAULT],
28 [[int result = 0;
29 char * volatile p = calloc (0, 0);
30 if (!p)
31 result |= 1;
32 free (p);
33 return result;
34 ]])],
35 [],
36 [ac_cv_func_calloc_0_nonnull=no])
37 else
38 case "$host_os" in
39 # Guess yes on glibc systems.
40 *-gnu* | gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
41 # Guess yes on musl systems.
42 *-musl*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
43 # Guess yes on native Windows.
44 mingw*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
45 # If we don't know, obey --enable-cross-guesses.
46 *) ac_cv_func_calloc_0_nonnull="$gl_cross_guess_normal" ;;
47 esac
48 fi
49 ])
50 AS_CASE([$ac_cv_func_calloc_0_nonnull], [*yes], [$1], [$2])
51])
52
53
54# gl_FUNC_CALLOC_GNU
55# ------------------
56# Replace calloc if it is not compatible with GNU libc.
57AC_DEFUN([gl_FUNC_CALLOC_GNU],
58[
59 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
60 AC_REQUIRE([gl_FUNC_CALLOC_POSIX])
61 REPLACE_CALLOC_FOR_CALLOC_GNU="$REPLACE_CALLOC_FOR_CALLOC_POSIX"
62 if test $REPLACE_CALLOC_FOR_CALLOC_GNU = 0; then
63 _AC_FUNC_CALLOC_IF([], [REPLACE_CALLOC_FOR_CALLOC_GNU=1])
64 fi
65])# gl_FUNC_CALLOC_GNU
66
67# gl_FUNC_CALLOC_POSIX
68# --------------------
69# Test whether 'calloc' is POSIX compliant (sets errno to ENOMEM when it
70# fails, and doesn't mess up with ptrdiff_t or size_t overflow),
71# and replace calloc if it is not.
72AC_DEFUN([gl_FUNC_CALLOC_POSIX],
73[
74 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
75 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
76 if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then
77 REPLACE_CALLOC_FOR_CALLOC_POSIX=1
78 fi
79 dnl Although in theory we should also test for size_t overflow,
80 dnl in practice testing for ptrdiff_t overflow suffices
81 dnl since PTRDIFF_MAX <= SIZE_MAX on all known Gnulib porting targets.
82 dnl A separate size_t test would slow down 'configure'.
83])
diff --git a/gl/m4/close.m4 b/gl/m4/close.m4
new file mode 100644
index 0000000..9f95c67
--- /dev/null
+++ b/gl/m4/close.m4
@@ -0,0 +1,35 @@
1# close.m4 serial 9
2dnl Copyright (C) 2008-2023 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_CLOSE],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 m4_ifdef([gl_MSVC_INVAL], [
11 AC_REQUIRE([gl_MSVC_INVAL])
12 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
13 REPLACE_CLOSE=1
14 fi
15 ])
16 m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
17 gl_PREREQ_SYS_H_WINSOCK2
18 if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
19 dnl Even if the 'socket' module is not used here, another part of the
20 dnl application may use it and pass file descriptors that refer to
21 dnl sockets to the close() function. So enable the support for sockets.
22 REPLACE_CLOSE=1
23 fi
24 ])
25 dnl Replace close() for supporting the gnulib-defined fchdir() function,
26 dnl to keep fchdir's bookkeeping up-to-date.
27 m4_ifdef([gl_FUNC_FCHDIR], [
28 if test $REPLACE_CLOSE = 0; then
29 gl_TEST_FCHDIR
30 if test $HAVE_FCHDIR = 0; then
31 REPLACE_CLOSE=1
32 fi
33 fi
34 ])
35])
diff --git a/gl/m4/codeset.m4 b/gl/m4/codeset.m4
index c2761be..5804f47 100644
--- a/gl/m4/codeset.m4
+++ b/gl/m4/codeset.m4
@@ -1,5 +1,6 @@
1# codeset.m4 serial 5 (gettext-0.18.2) 1# codeset.m4 serial 5 (gettext-0.18.2)
2dnl Copyright (C) 2000-2002, 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2006, 2008-2014, 2016, 2019-2023 Free Software
3dnl Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/configmake.m4 b/gl/m4/configmake.m4
deleted file mode 100644
index 823ffc0..0000000
--- a/gl/m4/configmake.m4
+++ /dev/null
@@ -1,50 +0,0 @@
1# configmake.m4 serial 1
2dnl Copyright (C) 2010-2013 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_CONFIGMAKE_PREP
8# ------------------
9# Guarantee all of the standard directory variables, even when used with
10# autoconf 2.59 (datarootdir wasn't supported until 2.59c) or automake
11# 1.9.6 (pkglibexecdir wasn't supported until 1.10b.).
12AC_DEFUN([gl_CONFIGMAKE_PREP],
13[
14 dnl Technically, datadir should default to datarootdir. But if
15 dnl autoconf is too old to provide datarootdir, then reversing the
16 dnl definition is a reasonable compromise. Only AC_SUBST a variable
17 dnl if it was not already defined earlier by autoconf.
18 if test "x$datarootdir" = x; then
19 AC_SUBST([datarootdir], ['${datadir}'])
20 fi
21 dnl Copy the approach used in autoconf 2.60.
22 if test "x$docdir" = x; then
23 AC_SUBST([docdir], [m4_ifset([AC_PACKAGE_TARNAME],
24 ['${datarootdir}/doc/${PACKAGE_TARNAME}'],
25 ['${datarootdir}/doc/${PACKAGE}'])])
26 fi
27 dnl The remaining variables missing from autoconf 2.59 are easier.
28 if test "x$htmldir" = x; then
29 AC_SUBST([htmldir], ['${docdir}'])
30 fi
31 if test "x$dvidir" = x; then
32 AC_SUBST([dvidir], ['${docdir}'])
33 fi
34 if test "x$pdfdir" = x; then
35 AC_SUBST([pdfdir], ['${docdir}'])
36 fi
37 if test "x$psdir" = x; then
38 AC_SUBST([psdir], ['${docdir}'])
39 fi
40 if test "x$lispdir" = x; then
41 AC_SUBST([lispdir], ['${datarootdir}/emacs/site-lisp'])
42 fi
43 if test "x$localedir" = x; then
44 AC_SUBST([localedir], ['${datarootdir}/locale'])
45 fi
46
47 dnl Automake 1.9.6 only lacks pkglibexecdir; and since 1.11 merely
48 dnl provides it without AC_SUBST, this blind use of AC_SUBST is safe.
49 AC_SUBST([pkglibexecdir], ['${libexecdir}/${PACKAGE}'])
50])
diff --git a/gl/m4/dirname.m4 b/gl/m4/dirname.m4
deleted file mode 100644
index 5897a2a..0000000
--- a/gl/m4/dirname.m4
+++ /dev/null
@@ -1,19 +0,0 @@
1#serial 10 -*- autoconf -*-
2dnl Copyright (C) 2002-2006, 2009-2013 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_DIRNAME],
8[
9 AC_REQUIRE([gl_DIRNAME_LGPL])
10])
11
12AC_DEFUN([gl_DIRNAME_LGPL],
13[
14 dnl Prerequisites of lib/dirname.h.
15 AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
16
17 dnl No prerequisites of lib/basename-lgpl.c, lib/dirname-lgpl.c,
18 dnl lib/stripslash.c.
19])
diff --git a/gl/m4/double-slash-root.m4 b/gl/m4/double-slash-root.m4
index bd6f867..1776e5e 100644
--- a/gl/m4/double-slash-root.m4
+++ b/gl/m4/double-slash-root.m4
@@ -1,5 +1,5 @@
1# double-slash-root.m4 serial 4 -*- Autoconf -*- 1# double-slash-root.m4 serial 4 -*- Autoconf -*-
2dnl Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/dup2.m4 b/gl/m4/dup2.m4
new file mode 100644
index 0000000..e1cc73e
--- /dev/null
+++ b/gl/m4/dup2.m4
@@ -0,0 +1,105 @@
1#serial 27
2dnl Copyright (C) 2002, 2005, 2007, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_DUP2],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
12 [AC_RUN_IFELSE([
13 AC_LANG_PROGRAM(
14 [[#include <errno.h>
15 #include <fcntl.h>
16 #include <limits.h>
17 #include <sys/resource.h>
18 #include <unistd.h>
19 ]GL_MDA_DEFINES[
20 #ifndef RLIM_SAVED_CUR
21 # define RLIM_SAVED_CUR RLIM_INFINITY
22 #endif
23 #ifndef RLIM_SAVED_MAX
24 # define RLIM_SAVED_MAX RLIM_INFINITY
25 #endif
26 ]],
27 [[int result = 0;
28 int bad_fd = INT_MAX;
29 struct rlimit rlim;
30 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
31 && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
32 && rlim.rlim_cur != RLIM_INFINITY
33 && rlim.rlim_cur != RLIM_SAVED_MAX
34 && rlim.rlim_cur != RLIM_SAVED_CUR)
35 bad_fd = rlim.rlim_cur;
36 #ifdef FD_CLOEXEC
37 if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
38 result |= 1;
39 #endif
40 if (dup2 (1, 1) != 1)
41 result |= 2;
42 #ifdef FD_CLOEXEC
43 if (fcntl (1, F_GETFD) != FD_CLOEXEC)
44 result |= 4;
45 #endif
46 close (0);
47 if (dup2 (0, 0) != -1)
48 result |= 8;
49 /* Many gnulib modules require POSIX conformance of EBADF. */
50 if (dup2 (2, bad_fd) == -1 && errno != EBADF)
51 result |= 16;
52 /* Flush out some cygwin core dumps. */
53 if (dup2 (2, -1) != -1 || errno != EBADF)
54 result |= 32;
55 dup2 (2, 255);
56 dup2 (2, 256);
57 /* On OS/2 kLIBC, dup2() does not work on a directory fd. */
58 {
59 int fd = open (".", O_RDONLY);
60 if (fd == -1)
61 result |= 64;
62 else if (dup2 (fd, fd + 1) == -1)
63 result |= 128;
64 close (fd);
65 }
66 return result;]])
67 ],
68 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
69 [case "$host_os" in
70 mingw*) # on this platform, dup2 always returns 0 for success
71 gl_cv_func_dup2_works="guessing no" ;;
72 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
73 gl_cv_func_dup2_works="guessing no" ;;
74 aix* | freebsd*)
75 # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
76 # not EBADF.
77 gl_cv_func_dup2_works="guessing no" ;;
78 haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
79 gl_cv_func_dup2_works="guessing no" ;;
80 *-android*) # implemented using dup3(), which fails if oldfd == newfd
81 gl_cv_func_dup2_works="guessing no" ;;
82 os2*) # on OS/2 kLIBC, dup2() does not work on a directory fd.
83 gl_cv_func_dup2_works="guessing no" ;;
84 *) gl_cv_func_dup2_works="guessing yes" ;;
85 esac])
86 ])
87 case "$gl_cv_func_dup2_works" in
88 *yes) ;;
89 *)
90 REPLACE_DUP2=1
91 AC_CHECK_FUNCS([setdtablesize])
92 ;;
93 esac
94 dnl Replace dup2() for supporting the gnulib-defined fchdir() function,
95 dnl to keep fchdir's bookkeeping up-to-date.
96 m4_ifdef([gl_FUNC_FCHDIR], [
97 gl_TEST_FCHDIR
98 if test $HAVE_FCHDIR = 0; then
99 REPLACE_DUP2=1
100 fi
101 ])
102])
103
104# Prerequisites of lib/dup2.c.
105AC_DEFUN([gl_PREREQ_DUP2], [])
diff --git a/gl/m4/eealloc.m4 b/gl/m4/eealloc.m4
index c640ec1..cb3e08f 100644
--- a/gl/m4/eealloc.m4
+++ b/gl/m4/eealloc.m4
@@ -1,5 +1,5 @@
1# eealloc.m4 serial 3 1# eealloc.m4 serial 3
2dnl Copyright (C) 2003, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/environ.m4 b/gl/m4/environ.m4
index 593a33e..741dfc5 100644
--- a/gl/m4/environ.m4
+++ b/gl/m4/environ.m4
@@ -1,5 +1,5 @@
1# environ.m4 serial 6 1# environ.m4 serial 8
2dnl Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2004, 2006-2023 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.
@@ -29,16 +29,15 @@ AC_DEFUN_ONCE([gl_ENVIRON],
29AC_DEFUN([gt_CHECK_VAR_DECL], 29AC_DEFUN([gt_CHECK_VAR_DECL],
30[ 30[
31 define([gt_cv_var], [gt_cv_var_]$2[_declaration]) 31 define([gt_cv_var], [gt_cv_var_]$2[_declaration])
32 AC_MSG_CHECKING([if $2 is properly declared]) 32 AC_CACHE_CHECK([if $2 is properly declared], [gt_cv_var],
33 AC_CACHE_VAL([gt_cv_var], [ 33 [AC_COMPILE_IFELSE(
34 AC_COMPILE_IFELSE( 34 [AC_LANG_PROGRAM(
35 [AC_LANG_PROGRAM( 35 [[$1
36 [[$1 36 typedef struct { int foo; } foo_t;
37 extern struct { int foo; } $2;]], 37 extern foo_t $2;]],
38 [[$2.foo = 1;]])], 38 [[$2.foo = 1;]])],
39 [gt_cv_var=no], 39 [gt_cv_var=no],
40 [gt_cv_var=yes])]) 40 [gt_cv_var=yes])])
41 AC_MSG_RESULT([$gt_cv_var])
42 if test $gt_cv_var = yes; then 41 if test $gt_cv_var = yes; then
43 AC_DEFINE([HAVE_]m4_translit($2, [a-z], [A-Z])[_DECL], 1, 42 AC_DEFINE([HAVE_]m4_translit($2, [a-z], [A-Z])[_DECL], 1,
44 [Define if you have the declaration of $2.]) 43 [Define if you have the declaration of $2.])
diff --git a/gl/m4/errno_h.m4 b/gl/m4/errno_h.m4
index c813ea5..4c70d22 100644
--- a/gl/m4/errno_h.m4
+++ b/gl/m4/errno_h.m4
@@ -1,9 +1,11 @@
1# errno_h.m4 serial 12 1# errno_h.m4 serial 14
2dnl Copyright (C) 2004, 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2008-2023 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_PREREQ([2.61])
8
7AC_DEFUN_ONCE([gl_HEADER_ERRNO_H], 9AC_DEFUN_ONCE([gl_HEADER_ERRNO_H],
8[ 10[
9 AC_REQUIRE([AC_PROG_CC]) 11 AC_REQUIRE([AC_PROG_CC])
@@ -66,13 +68,11 @@ booboo
66 [gl_cv_header_errno_h_complete=yes]) 68 [gl_cv_header_errno_h_complete=yes])
67 ]) 69 ])
68 if test $gl_cv_header_errno_h_complete = yes; then 70 if test $gl_cv_header_errno_h_complete = yes; then
69 ERRNO_H='' 71 GL_GENERATE_ERRNO_H=false
70 else 72 else
71 gl_NEXT_HEADERS([errno.h]) 73 gl_NEXT_HEADERS([errno.h])
72 ERRNO_H='errno.h' 74 GL_GENERATE_ERRNO_H=true
73 fi 75 fi
74 AC_SUBST([ERRNO_H])
75 AM_CONDITIONAL([GL_GENERATE_ERRNO_H], [test -n "$ERRNO_H"])
76 gl_REPLACE_ERRNO_VALUE([EMULTIHOP]) 76 gl_REPLACE_ERRNO_VALUE([EMULTIHOP])
77 gl_REPLACE_ERRNO_VALUE([ENOLINK]) 77 gl_REPLACE_ERRNO_VALUE([ENOLINK])
78 gl_REPLACE_ERRNO_VALUE([EOVERFLOW]) 78 gl_REPLACE_ERRNO_VALUE([EOVERFLOW])
@@ -86,7 +86,7 @@ booboo
86# Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE. 86# Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE.
87AC_DEFUN([gl_REPLACE_ERRNO_VALUE], 87AC_DEFUN([gl_REPLACE_ERRNO_VALUE],
88[ 88[
89 if test -n "$ERRNO_H"; then 89 if $GL_GENERATE_ERRNO_H; then
90 AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [ 90 AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [
91 AC_EGREP_CPP([yes],[ 91 AC_EGREP_CPP([yes],[
92#include <errno.h> 92#include <errno.h>
@@ -129,9 +129,3 @@ yes
129 AC_SUBST($1[_VALUE]) 129 AC_SUBST($1[_VALUE])
130 fi 130 fi
131]) 131])
132
133dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
134dnl Remove this when we can assume autoconf >= 2.61.
135m4_ifdef([AC_COMPUTE_INT], [], [
136 AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
137])
diff --git a/gl/m4/error.m4 b/gl/m4/error.m4
index 29e6fdc..8cc75df 100644
--- a/gl/m4/error.m4
+++ b/gl/m4/error.m4
@@ -1,6 +1,6 @@
1#serial 14 1#serial 15
2 2
3# Copyright (C) 1996-1998, 2001-2004, 2009-2013 Free Software Foundation, Inc. 3# Copyright (C) 1996-1998, 2001-2004, 2009-2023 Free Software Foundation, Inc.
4# 4#
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,
@@ -22,6 +22,10 @@ AC_DEFUN([gl_ERROR],
22# Prerequisites of lib/error.c. 22# Prerequisites of lib/error.c.
23AC_DEFUN([gl_PREREQ_ERROR], 23AC_DEFUN([gl_PREREQ_ERROR],
24[ 24[
25 dnl Use system extensions on Android, so that AC_FUNC_STRERROR_R
26 dnl discovers the GNU API for strerror_r on Android API level 23 and later.
27 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
28
25 AC_REQUIRE([AC_FUNC_STRERROR_R]) 29 AC_REQUIRE([AC_FUNC_STRERROR_R])
26 : 30 :
27]) 31])
diff --git a/gl/m4/exponentd.m4 b/gl/m4/exponentd.m4
index 09df468..2ef4643 100644
--- a/gl/m4/exponentd.m4
+++ b/gl/m4/exponentd.m4
@@ -1,5 +1,5 @@
1# exponentd.m4 serial 3 1# exponentd.m4 serial 3
2dnl Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2008, 2010-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4
index e30f122..5336b8d 100644
--- a/gl/m4/extensions.m4
+++ b/gl/m4/extensions.m4
@@ -1,14 +1,19 @@
1# serial 13 -*- Autoconf -*- 1# serial 23 -*- 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-2013 Free Software Foundation, Inc. 4# Copyright (C) 2003, 2006-2023 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
9dnl Define to empty for the benefit of Autoconf 2.69 and earlier, so that
10dnl AC_USE_SYSTEM_EXTENSIONS (below) can be used unchanged from Autoconf 2.70+.
11m4_ifndef([AC_CHECK_INCLUDES_DEFAULT],
12 [AC_DEFUN([AC_CHECK_INCLUDES_DEFAULT], [])])
13
9# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from git 14# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from git
10# Autoconf. Perhaps we can remove this once we can assume Autoconf 15# Autoconf. Perhaps we can remove this once we can assume Autoconf
11# 2.70 or later everywhere, but since Autoconf mutates rapidly 16# is recent-enough everywhere, but since Autoconf mutates rapidly
12# enough in this area it's likely we'll need to redefine 17# enough in this area it's likely we'll need to redefine
13# AC_USE_SYSTEM_EXTENSIONS for quite some time. 18# AC_USE_SYSTEM_EXTENSIONS for quite some time.
14 19
@@ -26,67 +31,125 @@
26# its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS 31# its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS
27# invocation occurs in gl_EARLY, not in gl_INIT. 32# invocation occurs in gl_EARLY, not in gl_INIT.
28 33
34m4_version_prereq([2.72], [], [
35
29# AC_USE_SYSTEM_EXTENSIONS 36# AC_USE_SYSTEM_EXTENSIONS
30# ------------------------ 37# ------------------------
31# Enable extensions on systems that normally disable them, 38# Enable extensions on systems that normally disable them,
32# typically due to standards-conformance issues. 39# typically due to standards-conformance issues.
33# 40# We unconditionally define as many of the known feature-enabling
34# Remember that #undef in AH_VERBATIM gets replaced with #define by 41# as possible, reserving conditional behavior for macros that are
35# AC_DEFINE. The goal here is to define all known feature-enabling 42# known to cause problems on some platforms (such as __EXTENSIONS__).
36# macros, then, if reports of conflicts are made, disable macros that
37# cause problems on some platforms (such as __EXTENSIONS__).
38AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS], 43AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS],
39[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl 44[AC_BEFORE([$0], [AC_PREPROC_IFELSE])dnl
45AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
46AC_BEFORE([$0], [AC_LINK_IFELSE])dnl
40AC_BEFORE([$0], [AC_RUN_IFELSE])dnl 47AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
41 48AC_BEFORE([$0], [AC_CHECK_INCLUDES_DEFAULT])dnl
42 AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) 49dnl #undef in AH_VERBATIM gets replaced with #define by AC_DEFINE.
43 if test "$MINIX" = yes; then
44 AC_DEFINE([_POSIX_SOURCE], [1],
45 [Define to 1 if you need to in order for 'stat' and other
46 things to work.])
47 AC_DEFINE([_POSIX_1_SOURCE], [2],
48 [Define to 2 if the system does not provide POSIX.1 features
49 except with this defined.])
50 AC_DEFINE([_MINIX], [1],
51 [Define to 1 if on MINIX.])
52 AC_DEFINE([_NETBSD_SOURCE], [1],
53 [Define to 1 to make NetBSD features available. MINIX 3 needs this.])
54 fi
55
56dnl Use a different key than __EXTENSIONS__, as that name broke existing 50dnl Use a different key than __EXTENSIONS__, as that name broke existing
57dnl configure.ac when using autoheader 2.62. 51dnl configure.ac when using autoheader 2.62.
58 AH_VERBATIM([USE_SYSTEM_EXTENSIONS], 52dnl The macros below are in alphabetical order ignoring leading _ or __
53dnl prefixes.
54AH_VERBATIM([USE_SYSTEM_EXTENSIONS],
59[/* Enable extensions on AIX 3, Interix. */ 55[/* Enable extensions on AIX 3, Interix. */
60#ifndef _ALL_SOURCE 56#ifndef _ALL_SOURCE
61# undef _ALL_SOURCE 57# undef _ALL_SOURCE
62#endif 58#endif
63/* Enable general extensions on OS X. */ 59/* Enable general extensions on macOS. */
64#ifndef _DARWIN_C_SOURCE 60#ifndef _DARWIN_C_SOURCE
65# undef _DARWIN_C_SOURCE 61# undef _DARWIN_C_SOURCE
66#endif 62#endif
63/* Enable general extensions on Solaris. */
64#ifndef __EXTENSIONS__
65# undef __EXTENSIONS__
66#endif
67/* Enable GNU extensions on systems that have them. */ 67/* Enable GNU extensions on systems that have them. */
68#ifndef _GNU_SOURCE 68#ifndef _GNU_SOURCE
69# undef _GNU_SOURCE 69# undef _GNU_SOURCE
70#endif 70#endif
71/* Enable threading extensions on Solaris. */ 71/* Enable X/Open compliant socket functions that do not require linking
72 with -lxnet on HP-UX 11.11. */
73#ifndef _HPUX_ALT_XOPEN_SOCKET_API
74# undef _HPUX_ALT_XOPEN_SOCKET_API
75#endif
76/* Identify the host operating system as Minix.
77 This macro does not affect the system headers' behavior.
78 A future release of Autoconf may stop defining this macro. */
79#ifndef _MINIX
80# undef _MINIX
81#endif
82/* Enable general extensions on NetBSD.
83 Enable NetBSD compatibility extensions on Minix. */
84#ifndef _NETBSD_SOURCE
85# undef _NETBSD_SOURCE
86#endif
87/* Enable OpenBSD compatibility extensions on NetBSD.
88 Oddly enough, this does nothing on OpenBSD. */
89#ifndef _OPENBSD_SOURCE
90# undef _OPENBSD_SOURCE
91#endif
92/* Define to 1 if needed for POSIX-compatible behavior. */
93#ifndef _POSIX_SOURCE
94# undef _POSIX_SOURCE
95#endif
96/* Define to 2 if needed for POSIX-compatible behavior. */
97#ifndef _POSIX_1_SOURCE
98# undef _POSIX_1_SOURCE
99#endif
100/* Enable POSIX-compatible threading on Solaris. */
72#ifndef _POSIX_PTHREAD_SEMANTICS 101#ifndef _POSIX_PTHREAD_SEMANTICS
73# undef _POSIX_PTHREAD_SEMANTICS 102# undef _POSIX_PTHREAD_SEMANTICS
74#endif 103#endif
104/* Enable extensions specified by ISO/IEC TS 18661-5:2014. */
105#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
106# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
107#endif
108/* Enable extensions specified by ISO/IEC TS 18661-1:2014. */
109#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
110# undef __STDC_WANT_IEC_60559_BFP_EXT__
111#endif
112/* Enable extensions specified by ISO/IEC TS 18661-2:2015. */
113#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
114# undef __STDC_WANT_IEC_60559_DFP_EXT__
115#endif
116/* Enable extensions specified by C23 Annex F. */
117#ifndef __STDC_WANT_IEC_60559_EXT__
118# undef __STDC_WANT_IEC_60559_EXT__
119#endif
120/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */
121#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
122# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
123#endif
124/* Enable extensions specified by C23 Annex H and ISO/IEC TS 18661-3:2015. */
125#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
126# undef __STDC_WANT_IEC_60559_TYPES_EXT__
127#endif
128/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */
129#ifndef __STDC_WANT_LIB_EXT2__
130# undef __STDC_WANT_LIB_EXT2__
131#endif
132/* Enable extensions specified by ISO/IEC 24747:2009. */
133#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
134# undef __STDC_WANT_MATH_SPEC_FUNCS__
135#endif
75/* Enable extensions on HP NonStop. */ 136/* Enable extensions on HP NonStop. */
76#ifndef _TANDEM_SOURCE 137#ifndef _TANDEM_SOURCE
77# undef _TANDEM_SOURCE 138# undef _TANDEM_SOURCE
78#endif 139#endif
79/* Enable X/Open extensions if necessary. HP-UX 11.11 defines 140/* Enable X/Open extensions. Define to 500 only if necessary
80 mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of 141 to make mbstate_t available. */
81 whether compiling with -Ae or -D_HPUX_SOURCE=1. */
82#ifndef _XOPEN_SOURCE 142#ifndef _XOPEN_SOURCE
83# undef _XOPEN_SOURCE 143# undef _XOPEN_SOURCE
84#endif 144#endif
85/* Enable general extensions on Solaris. */ 145])dnl
86#ifndef __EXTENSIONS__ 146
87# undef __EXTENSIONS__ 147 AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])dnl
88#endif 148 _AC_CHECK_HEADER_ONCE([wchar.h])
89]) 149 _AC_CHECK_HEADER_ONCE([minix/config.h])
150
151dnl Defining __EXTENSIONS__ may break the system headers on some systems.
152dnl (FIXME: Which ones?)
90 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], 153 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
91 [ac_cv_safe_to_define___extensions__], 154 [ac_cv_safe_to_define___extensions__],
92 [AC_COMPILE_IFELSE( 155 [AC_COMPILE_IFELSE(
@@ -95,30 +158,57 @@ dnl configure.ac when using autoheader 2.62.
95 ]AC_INCLUDES_DEFAULT])], 158 ]AC_INCLUDES_DEFAULT])],
96 [ac_cv_safe_to_define___extensions__=yes], 159 [ac_cv_safe_to_define___extensions__=yes],
97 [ac_cv_safe_to_define___extensions__=no])]) 160 [ac_cv_safe_to_define___extensions__=no])])
98 test $ac_cv_safe_to_define___extensions__ = yes && 161
99 AC_DEFINE([__EXTENSIONS__]) 162dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to
100 AC_DEFINE([_ALL_SOURCE]) 163dnl 500, regardless of whether compiling with -Ae or -D_HPUX_SOURCE=1.
101 AC_DEFINE([_DARWIN_C_SOURCE]) 164dnl But defining _XOPEN_SOURCE may turn *off* extensions on platforms
102 AC_DEFINE([_GNU_SOURCE]) 165dnl not covered by turn-on-extensions macros (notably Dragonfly, Free,
103 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) 166dnl and OpenBSD, which don't have any equivalent of _NETBSD_SOURCE) so
104 AC_DEFINE([_TANDEM_SOURCE]) 167dnl it should only be defined when necessary.
105 AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined], 168 AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined],
106 [ac_cv_should_define__xopen_source], 169 [ac_cv_should_define__xopen_source],
107 [ac_cv_should_define__xopen_source=no 170 [ac_cv_should_define__xopen_source=no
108 AC_COMPILE_IFELSE( 171 AS_IF([test $ac_cv_header_wchar_h = yes],
109 [AC_LANG_PROGRAM([[ 172 [AC_COMPILE_IFELSE(
173 [AC_LANG_PROGRAM([[
110 #include <wchar.h> 174 #include <wchar.h>
111 mbstate_t x;]])], 175 mbstate_t x;]])],
112 [], 176 [],
113 [AC_COMPILE_IFELSE( 177 [AC_COMPILE_IFELSE(
114 [AC_LANG_PROGRAM([[ 178 [AC_LANG_PROGRAM([[
115 #define _XOPEN_SOURCE 500 179 #define _XOPEN_SOURCE 500
116 #include <wchar.h> 180 #include <wchar.h>
117 mbstate_t x;]])], 181 mbstate_t x;]])],
118 [ac_cv_should_define__xopen_source=yes])])]) 182 [ac_cv_should_define__xopen_source=yes])])])])
119 test $ac_cv_should_define__xopen_source = yes && 183
120 AC_DEFINE([_XOPEN_SOURCE], [500]) 184 AC_DEFINE([_ALL_SOURCE])
185 AC_DEFINE([_DARWIN_C_SOURCE])
186 AC_DEFINE([_GNU_SOURCE])
187 AC_DEFINE([_HPUX_ALT_XOPEN_SOCKET_API])
188 AC_DEFINE([_NETBSD_SOURCE])
189 AC_DEFINE([_OPENBSD_SOURCE])
190 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
191 AC_DEFINE([__STDC_WANT_IEC_60559_ATTRIBS_EXT__])
192 AC_DEFINE([__STDC_WANT_IEC_60559_BFP_EXT__])
193 AC_DEFINE([__STDC_WANT_IEC_60559_DFP_EXT__])
194 AC_DEFINE([__STDC_WANT_IEC_60559_EXT__])
195 AC_DEFINE([__STDC_WANT_IEC_60559_FUNCS_EXT__])
196 AC_DEFINE([__STDC_WANT_IEC_60559_TYPES_EXT__])
197 AC_DEFINE([__STDC_WANT_LIB_EXT2__])
198 AC_DEFINE([__STDC_WANT_MATH_SPEC_FUNCS__])
199 AC_DEFINE([_TANDEM_SOURCE])
200 AS_IF([test $ac_cv_header_minix_config_h = yes],
201 [MINIX=yes
202 AC_DEFINE([_MINIX])
203 AC_DEFINE([_POSIX_SOURCE])
204 AC_DEFINE([_POSIX_1_SOURCE], [2])],
205 [MINIX=])
206 AS_IF([test $ac_cv_safe_to_define___extensions__ = yes],
207 [AC_DEFINE([__EXTENSIONS__])])
208 AS_IF([test $ac_cv_should_define__xopen_source = yes],
209 [AC_DEFINE([_XOPEN_SOURCE], [500])])
121])# AC_USE_SYSTEM_EXTENSIONS 210])# AC_USE_SYSTEM_EXTENSIONS
211])
122 212
123# gl_USE_SYSTEM_EXTENSIONS 213# gl_USE_SYSTEM_EXTENSIONS
124# ------------------------ 214# ------------------------
@@ -126,13 +216,17 @@ dnl configure.ac when using autoheader 2.62.
126# typically due to standards-conformance issues. 216# typically due to standards-conformance issues.
127AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS], 217AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
128[ 218[
129 dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS.
130 dnl gnulib does not need it. But if it gets required by third-party macros
131 dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a
132 dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
133 dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE,
134 dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck.
135 AC_REQUIRE([AC_GNU_SOURCE])
136
137 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 219 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
220
221 dnl On OpenBSD 6.8 with GCC, the include files contain a couple of
222 dnl definitions that are only activated with an explicit -D_ISOC11_SOURCE.
223 dnl That's because this version of GCC (4.2.1) supports the option
224 dnl '-std=gnu99' but not the option '-std=gnu11'.
225 AC_REQUIRE([AC_CANONICAL_HOST])
226 case "$host_os" in
227 openbsd*)
228 AC_DEFINE([_ISOC11_SOURCE], [1],
229 [Define to enable the declarations of ISO C 11 types and functions.])
230 ;;
231 esac
138]) 232])
diff --git a/gl/m4/extern-inline.m4 b/gl/m4/extern-inline.m4
index c4c5e7f..c001b1c 100644
--- a/gl/m4/extern-inline.m4
+++ b/gl/m4/extern-inline.m4
@@ -1,61 +1,121 @@
1dnl 'extern inline' a la ISO C99. 1dnl 'extern inline' a la ISO C99.
2 2
3dnl Copyright 2012-2013 Free Software Foundation, Inc. 3dnl Copyright 2012-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7 7
8AC_DEFUN([gl_EXTERN_INLINE], 8AC_DEFUN([gl_EXTERN_INLINE],
9[ 9[
10 AH_VERBATIM([extern_inline], 10 AC_CACHE_CHECK([whether ctype.h defines __header_inline],
11 [gl_cv_have___header_inline],
12 [AC_PREPROC_IFELSE(
13 [AC_LANG_SOURCE([[#include <ctype.h>
14 #ifndef __header_inline
15 #error "<ctype.h> does not define __header_inline"
16 #endif
17 ]])],
18 [gl_cv_have___header_inline=yes],
19 [gl_cv_have___header_inline=no])])
20 if test "$gl_cv_have___header_inline" = yes; then
21 AC_DEFINE([HAVE___HEADER_INLINE], [1],
22 [Define to 1 if ctype.h defines __header_inline.])
23 fi
24
25 AH_VERBATIM([HAVE___HEADER_INLINE_1],
11[/* Please see the Gnulib manual for how to use these macros. 26[/* Please see the Gnulib manual for how to use these macros.
12 27
13 Suppress extern inline with HP-UX cc, as it appears to be broken; see 28 Suppress extern inline with HP-UX cc, as it appears to be broken; see
14 <http://lists.gnu.org/archive/html/bug-texinfo/2013-02/msg00030.html>. 29 <https://lists.gnu.org/r/bug-texinfo/2013-02/msg00030.html>.
15 30
16 Suppress extern inline with Sun C in standards-conformance mode, as it 31 Suppress extern inline with Sun C in standards-conformance mode, as it
17 mishandles inline functions that call each other. E.g., for 'inline void f 32 mishandles inline functions that call each other. E.g., for 'inline void f
18 (void) { } inline void g (void) { f (); }', c99 incorrectly complains 33 (void) { } inline void g (void) { f (); }', c99 incorrectly complains
19 'reference to static identifier "f" in extern inline function'. 34 'reference to static identifier "f" in extern inline function'.
20 This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16. 35 This bug was observed with Oracle Developer Studio 12.6
36 (Sun C 5.15 SunOS_sparc 2017/05/30).
37
38 Suppress extern inline (with or without __attribute__ ((__gnu_inline__)))
39 on configurations that mistakenly use 'static inline' to implement
40 functions or macros in standard C headers like <ctype.h>. For example,
41 if isdigit is mistakenly implemented via a static inline function,
42 a program containing an extern inline function that calls isdigit
43 may not work since the C standard prohibits extern inline functions
44 from calling static functions (ISO C 99 section 6.7.4.(3).
45 This bug is known to occur on:
46
47 OS X 10.8 and earlier; see:
48 https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html
49
50 DragonFly; see
51 http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log
21 52
22 Suppress the use of extern inline on Apple's platforms, as Libc at least 53 FreeBSD; see:
23 through Libc-825.26 (2013-04-09) is incompatible with it; see, e.g., 54 https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html
24 <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>. 55
25 Perhaps Apple will fix this some day. */ 56 OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and
57 for clang but remains for g++; see <https://trac.macports.org/ticket/41033>.
58 Assume DragonFly and FreeBSD will be similar.
59
60 GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
61 inline semantics, unless -fgnu89-inline is used. It defines a macro
62 __GNUC_STDC_INLINE__ to indicate this situation or a macro
63 __GNUC_GNU_INLINE__ to indicate the opposite situation.
64 GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline
65 semantics but warns, unless -fgnu89-inline is used:
66 warning: C99 inline functions are not supported; using GNU89
67 warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute
68 It defines a macro __GNUC_GNU_INLINE__ to indicate this situation.
69 */
70#if (((defined __APPLE__ && defined __MACH__) \
71 || defined __DragonFly__ || defined __FreeBSD__) \
72 && (defined HAVE___HEADER_INLINE \
73 ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \
74 && ! defined __clang__) \
75 : ((! defined _DONT_USE_CTYPE_INLINE_ \
76 && (defined __GNUC__ || defined __cplusplus)) \
77 || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
78 && defined __GNUC__ && ! defined __cplusplus))))
79# define _GL_EXTERN_INLINE_STDHEADER_BUG
80#endif
26#if ((__GNUC__ \ 81#if ((__GNUC__ \
27 ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \ 82 ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
28 : (199901L <= __STDC_VERSION__ \ 83 : (199901L <= __STDC_VERSION__ \
29 && !defined __HP_cc \ 84 && !defined __HP_cc \
85 && !defined __PGI \
30 && !(defined __SUNPRO_C && __STDC__))) \ 86 && !(defined __SUNPRO_C && __STDC__))) \
31 && !defined __APPLE__) 87 && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
32# define _GL_INLINE inline 88# define _GL_INLINE inline
33# define _GL_EXTERN_INLINE extern inline 89# define _GL_EXTERN_INLINE extern inline
90# define _GL_EXTERN_INLINE_IN_USE
34#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \ 91#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
35 && !defined __APPLE__) 92 && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
36# if __GNUC_GNU_INLINE__ 93# if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__
37 /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */ 94 /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
38# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__)) 95# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
39# else 96# else
40# define _GL_INLINE extern inline 97# define _GL_INLINE extern inline
41# endif 98# endif
42# define _GL_EXTERN_INLINE extern 99# define _GL_EXTERN_INLINE extern
100# define _GL_EXTERN_INLINE_IN_USE
43#else 101#else
44# define _GL_INLINE static _GL_UNUSED 102# define _GL_INLINE _GL_UNUSED static
45# define _GL_EXTERN_INLINE static _GL_UNUSED 103# define _GL_EXTERN_INLINE _GL_UNUSED static
46#endif 104#endif
47 105
48#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) 106/* In GCC 4.6 (inclusive) to 5.1 (exclusive),
107 suppress bogus "no previous prototype for 'FOO'"
108 and "no previous declaration for 'FOO'" diagnostics,
109 when FOO is an inline function in the header; see
110 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113> and
111 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63877>. */
112#if __GNUC__ == 4 && 6 <= __GNUC_MINOR__
49# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ 113# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
50# define _GL_INLINE_HEADER_CONST_PRAGMA 114# define _GL_INLINE_HEADER_CONST_PRAGMA
51# else 115# else
52# define _GL_INLINE_HEADER_CONST_PRAGMA \ 116# define _GL_INLINE_HEADER_CONST_PRAGMA \
53 _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") 117 _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
54# endif 118# endif
55 /* Suppress GCC's bogus "no previous prototype for 'FOO'"
56 and "no previous declaration for 'FOO'" diagnostics,
57 when FOO is an inline function in the header; see
58 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>. */
59# define _GL_INLINE_HEADER_BEGIN \ 119# define _GL_INLINE_HEADER_BEGIN \
60 _Pragma ("GCC diagnostic push") \ 120 _Pragma ("GCC diagnostic push") \
61 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ 121 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4
index 87cc4bd..59d558b 100644
--- a/gl/m4/fcntl-o.m4
+++ b/gl/m4/fcntl-o.m4
@@ -1,23 +1,22 @@
1# fcntl-o.m4 serial 4 1# fcntl-o.m4 serial 7
2dnl Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006, 2009-2023 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 Paul Eggert. 7dnl Written by Paul Eggert.
8 8
9AC_PREREQ([2.60])
10
9# Test whether the flags O_NOATIME and O_NOFOLLOW actually work. 11# Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
10# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. 12# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
11# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. 13# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
12AC_DEFUN([gl_FCNTL_O_FLAGS], 14AC_DEFUN([gl_FCNTL_O_FLAGS],
13[ 15[
14 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW. 16 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
15 dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes 17 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16 dnl AC_GNU_SOURCE.
17 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
18 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
19 [AC_REQUIRE([AC_GNU_SOURCE])])
20 18
19 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
21 AC_CHECK_HEADERS_ONCE([unistd.h]) 20 AC_CHECK_HEADERS_ONCE([unistd.h])
22 AC_CHECK_FUNCS_ONCE([symlink]) 21 AC_CHECK_FUNCS_ONCE([symlink])
23 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], 22 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
@@ -33,6 +32,7 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
33 # defined sleep(n) _sleep ((n) * 1000) 32 # defined sleep(n) _sleep ((n) * 1000)
34 #endif 33 #endif
35 #include <fcntl.h> 34 #include <fcntl.h>
35 ]GL_MDA_DEFINES[
36 #ifndef O_NOATIME 36 #ifndef O_NOATIME
37 #define O_NOATIME 0 37 #define O_NOATIME 0
38 #endif 38 #endif
@@ -116,7 +116,13 @@ AC_DEFUN([gl_FCNTL_O_FLAGS],
116 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( 116 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
117 *) gl_cv_header_working_fcntl_h='no';; 117 *) gl_cv_header_working_fcntl_h='no';;
118 esac], 118 esac],
119 [gl_cv_header_working_fcntl_h=cross-compiling])]) 119 [case "$host_os" in
120 # Guess 'no' on native Windows.
121 mingw*) gl_cv_header_working_fcntl_h='no' ;;
122 *) gl_cv_header_working_fcntl_h=cross-compiling ;;
123 esac
124 ])
125 ])
120 126
121 case $gl_cv_header_working_fcntl_h in #( 127 case $gl_cv_header_working_fcntl_h in #(
122 *O_NOATIME* | no | cross-compiling) ac_val=0;; #( 128 *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
diff --git a/gl/m4/fcntl.m4 b/gl/m4/fcntl.m4
new file mode 100644
index 0000000..524a99a
--- /dev/null
+++ b/gl/m4/fcntl.m4
@@ -0,0 +1,151 @@
1# fcntl.m4 serial 11
2dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# For now, this module ensures that fcntl()
8# - supports F_DUPFD correctly
9# - supports or emulates F_DUPFD_CLOEXEC
10# - supports F_GETFD
11# Still to be ported to mingw:
12# - F_SETFD
13# - F_GETFL, F_SETFL
14# - F_GETOWN, F_SETOWN
15# - F_GETLK, F_SETLK, F_SETLKW
16AC_DEFUN([gl_FUNC_FCNTL],
17[
18 dnl Persuade glibc to expose F_DUPFD_CLOEXEC.
19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
20 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
21 AC_REQUIRE([AC_CANONICAL_HOST])
22 AC_CHECK_FUNCS_ONCE([fcntl])
23 if test $ac_cv_func_fcntl = no; then
24 gl_REPLACE_FCNTL
25 else
26 dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
27 dnl haiku alpha 2 F_DUPFD has wrong errno
28 AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
29 [gl_cv_func_fcntl_f_dupfd_works],
30 [AC_RUN_IFELSE(
31 [AC_LANG_PROGRAM(
32 [[#include <errno.h>
33 #include <fcntl.h>
34 #include <limits.h>
35 #include <sys/resource.h>
36 #include <unistd.h>
37 ]GL_MDA_DEFINES[
38 #ifndef RLIM_SAVED_CUR
39 # define RLIM_SAVED_CUR RLIM_INFINITY
40 #endif
41 #ifndef RLIM_SAVED_MAX
42 # define RLIM_SAVED_MAX RLIM_INFINITY
43 #endif
44 ]],
45 [[int result = 0;
46 int bad_fd = INT_MAX;
47 struct rlimit rlim;
48 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
49 && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
50 && rlim.rlim_cur != RLIM_INFINITY
51 && rlim.rlim_cur != RLIM_SAVED_MAX
52 && rlim.rlim_cur != RLIM_SAVED_CUR)
53 bad_fd = rlim.rlim_cur;
54 if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
55 if (errno != EINVAL) result |= 2;
56 if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4;
57 if (errno != EINVAL) result |= 8;
58 /* On OS/2 kLIBC, F_DUPFD does not work on a directory fd */
59 {
60 int fd;
61 fd = open (".", O_RDONLY);
62 if (fd == -1)
63 result |= 16;
64 else if (fcntl (fd, F_DUPFD, STDERR_FILENO + 1) == -1)
65 result |= 32;
66
67 close (fd);
68 }
69 return result;]])],
70 [gl_cv_func_fcntl_f_dupfd_works=yes],
71 [gl_cv_func_fcntl_f_dupfd_works=no],
72 [case $host_os in
73 aix* | cygwin* | haiku*)
74 gl_cv_func_fcntl_f_dupfd_works="guessing no" ;;
75 *) gl_cv_func_fcntl_f_dupfd_works="guessing yes" ;;
76 esac])])
77 case $gl_cv_func_fcntl_f_dupfd_works in
78 *yes) ;;
79 *) gl_REPLACE_FCNTL
80 AC_DEFINE([FCNTL_DUPFD_BUGGY], [1], [Define this to 1 if F_DUPFD
81 behavior does not match POSIX]) ;;
82 esac
83
84 dnl Many systems lack F_DUPFD_CLOEXEC.
85 dnl NetBSD 9.0 declares F_DUPFD_CLOEXEC but it works only like F_DUPFD.
86 AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC],
87 [gl_cv_func_fcntl_f_dupfd_cloexec],
88 [AC_RUN_IFELSE(
89 [AC_LANG_SOURCE(
90 [[#include <fcntl.h>
91 #include <unistd.h>
92 int main (int argc, char *argv[])
93 {
94 if (argc == 1)
95 /* parent process */
96 {
97 if (fcntl (1, F_DUPFD_CLOEXEC, 10) < 0)
98 return 1;
99 return execl ("./conftest", "./conftest", "child", NULL);
100 }
101 else
102 /* child process */
103 return (fcntl (10, F_GETFL) < 0 ? 0 : 42);
104 }
105 ]])
106 ],
107 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
108#ifdef __linux__
109/* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace
110 it to support the semantics on older kernels that failed with EINVAL. */
111choke me
112#endif
113 ]])],
114 [gl_cv_func_fcntl_f_dupfd_cloexec=yes],
115 [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])
116 ],
117 [gl_cv_func_fcntl_f_dupfd_cloexec=no],
118 [case "$host_os" in
119 # Guess no on NetBSD.
120 netbsd*) gl_cv_func_fcntl_f_dupfd_cloexec="guessing no" ;;
121 *) gl_cv_func_fcntl_f_dupfd_cloexec="$gl_cross_guess_normal" ;;
122 esac
123 ])
124 ])
125 case "$gl_cv_func_fcntl_f_dupfd_cloexec" in
126 *yes) ;;
127 *) gl_REPLACE_FCNTL
128 dnl No witness macro needed for this bug.
129 ;;
130 esac
131 fi
132 dnl Replace fcntl() for supporting the gnulib-defined fchdir() function,
133 dnl to keep fchdir's bookkeeping up-to-date.
134 m4_ifdef([gl_FUNC_FCHDIR], [
135 gl_TEST_FCHDIR
136 if test $HAVE_FCHDIR = 0; then
137 gl_REPLACE_FCNTL
138 fi
139 ])
140])
141
142AC_DEFUN([gl_REPLACE_FCNTL],
143[
144 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
145 AC_CHECK_FUNCS_ONCE([fcntl])
146 if test $ac_cv_func_fcntl = no; then
147 HAVE_FCNTL=0
148 else
149 REPLACE_FCNTL=1
150 fi
151])
diff --git a/gl/m4/fcntl_h.m4 b/gl/m4/fcntl_h.m4
new file mode 100644
index 0000000..68f4e64
--- /dev/null
+++ b/gl/m4/fcntl_h.m4
@@ -0,0 +1,70 @@
1# serial 20
2# Configure fcntl.h.
3dnl Copyright (C) 2006-2007, 2009-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8dnl Written by Paul Eggert.
9
10AC_DEFUN_ONCE([gl_FCNTL_H],
11[
12 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
13 AC_REQUIRE([gl_FCNTL_O_FLAGS])
14 gl_NEXT_HEADERS([fcntl.h])
15
16 dnl Ensure the type pid_t gets defined.
17 AC_REQUIRE([AC_TYPE_PID_T])
18
19 dnl Ensure the type mode_t gets defined.
20 AC_REQUIRE([AC_TYPE_MODE_T])
21
22 dnl Check for declarations of anything we want to poison if the
23 dnl corresponding gnulib module is not in use, if it is not common
24 dnl enough to be declared everywhere.
25 gl_WARN_ON_USE_PREPARE([[#include <fcntl.h>
26 ]], [fcntl openat])
27])
28
29# gl_FCNTL_MODULE_INDICATOR([modulename])
30# sets the shell variable that indicates the presence of the given module
31# to a C preprocessor expression that will evaluate to 1.
32# This macro invocation must not occur in macros that are AC_REQUIREd.
33AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
34[
35 dnl Ensure to expand the default settings once only.
36 gl_FCNTL_H_REQUIRE_DEFAULTS
37 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
38 dnl Define it also as a C macro, for the benefit of the unit tests.
39 gl_MODULE_INDICATOR_FOR_TESTS([$1])
40])
41
42# Initializes the default values for AC_SUBSTed shell variables.
43# This macro must not be AC_REQUIREd. It must only be invoked, and only
44# outside of macros or in macros that are not AC_REQUIREd.
45AC_DEFUN([gl_FCNTL_H_REQUIRE_DEFAULTS],
46[
47 m4_defun(GL_MODULE_INDICATOR_PREFIX[_FCNTL_H_MODULE_INDICATOR_DEFAULTS], [
48 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CREAT])
49 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCNTL])
50 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NONBLOCKING])
51 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OPEN])
52 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OPENAT])
53 dnl Support Microsoft deprecated alias function names by default.
54 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CREAT], [1])
55 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_OPEN], [1])
56 ])
57 m4_require(GL_MODULE_INDICATOR_PREFIX[_FCNTL_H_MODULE_INDICATOR_DEFAULTS])
58 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
59])
60
61AC_DEFUN([gl_FCNTL_H_DEFAULTS],
62[
63 dnl Assume proper GNU behavior unless another module says otherwise.
64 HAVE_FCNTL=1; AC_SUBST([HAVE_FCNTL])
65 HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT])
66 REPLACE_CREAT=0; AC_SUBST([REPLACE_CREAT])
67 REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL])
68 REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN])
69 REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT])
70])
diff --git a/gl/m4/fflush.m4 b/gl/m4/fflush.m4
new file mode 100644
index 0000000..3e3c890
--- /dev/null
+++ b/gl/m4/fflush.m4
@@ -0,0 +1,100 @@
1# fflush.m4 serial 18
2
3# Copyright (C) 2007-2023 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
8dnl From Eric Blake
9
10dnl Find out how to obey POSIX semantics of fflush(stdin) discarding
11dnl unread input on seekable streams, rather than C99 undefined semantics.
12
13AC_DEFUN([gl_FUNC_FFLUSH],
14[
15 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
16 gl_FUNC_FFLUSH_STDIN
17 case "$gl_cv_func_fflush_stdin" in
18 *yes) ;;
19 *) REPLACE_FFLUSH=1 ;;
20 esac
21])
22
23dnl Determine whether fflush works on input streams.
24dnl Sets gl_cv_func_fflush_stdin.
25
26AC_DEFUN([gl_FUNC_FFLUSH_STDIN],
27[
28 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
29 AC_CHECK_HEADERS_ONCE([unistd.h])
30 AC_CACHE_CHECK([whether fflush works on input streams],
31 [gl_cv_func_fflush_stdin],
32 [echo hello world > conftest.txt
33 AC_RUN_IFELSE([AC_LANG_PROGRAM(
34 [[
35#include <stdio.h>
36#if HAVE_UNISTD_H
37# include <unistd.h>
38#else /* on Windows with MSVC */
39# include <io.h>
40#endif
41 ]GL_MDA_DEFINES],
42 [[FILE *f = fopen ("conftest.txt", "r");
43 char buffer[10];
44 int fd;
45 int c;
46 if (f == NULL)
47 return 1;
48 fd = fileno (f);
49 if (fd < 0 || fread (buffer, 1, 5, f) != 5)
50 { fclose (f); return 2; }
51 /* For deterministic results, ensure f read a bigger buffer. */
52 if (lseek (fd, 0, SEEK_CUR) == 5)
53 { fclose (f); return 3; }
54 /* POSIX requires fflush-fseek to set file offset of fd. This fails
55 on BSD systems and on mingw. */
56 if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
57 { fclose (f); return 4; }
58 if (lseek (fd, 0, SEEK_CUR) != 5)
59 { fclose (f); return 5; }
60 /* Verify behaviour of fflush after ungetc. See
61 <https://www.opengroup.org/austin/aardvark/latest/xshbug3.txt> */
62 /* Verify behaviour of fflush after a backup ungetc. This fails on
63 mingw. */
64 c = fgetc (f);
65 ungetc (c, f);
66 fflush (f);
67 if (fgetc (f) != c)
68 { fclose (f); return 6; }
69 /* Verify behaviour of fflush after a non-backup ungetc. This fails
70 on glibc 2.8 and on BSD systems. */
71 c = fgetc (f);
72 ungetc ('@', f);
73 fflush (f);
74 if (fgetc (f) != c)
75 { fclose (f); return 7; }
76 fclose (f);
77 return 0;
78 ]])],
79 [gl_cv_func_fflush_stdin=yes],
80 [gl_cv_func_fflush_stdin=no],
81 [case "$host_os" in
82 # Guess no on native Windows.
83 mingw*) gl_cv_func_fflush_stdin="guessing no" ;;
84 *) gl_cv_func_fflush_stdin=cross ;;
85 esac
86 ])
87 rm conftest.txt
88 ])
89 case "$gl_cv_func_fflush_stdin" in
90 *yes) gl_func_fflush_stdin=1 ;;
91 *no) gl_func_fflush_stdin=0 ;;
92 *) gl_func_fflush_stdin='(-1)' ;;
93 esac
94 AC_DEFINE_UNQUOTED([FUNC_FFLUSH_STDIN], [$gl_func_fflush_stdin],
95 [Define to 1 if fflush is known to work on stdin as per POSIX.1-2008,
96 0 if fflush is known to not work, -1 if unknown.])
97])
98
99# Prerequisites of lib/fflush.c.
100AC_DEFUN([gl_PREREQ_FFLUSH], [:])
diff --git a/gl/m4/float_h.m4 b/gl/m4/float_h.m4
index 397f2d1..2f0c9c4 100644
--- a/gl/m4/float_h.m4
+++ b/gl/m4/float_h.m4
@@ -1,5 +1,5 @@
1# float_h.m4 serial 9 1# float_h.m4 serial 13
2dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2023 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,42 +8,46 @@ AC_DEFUN([gl_FLOAT_H],
8[ 8[
9 AC_REQUIRE([AC_PROG_CC]) 9 AC_REQUIRE([AC_PROG_CC])
10 AC_REQUIRE([AC_CANONICAL_HOST]) 10 AC_REQUIRE([AC_CANONICAL_HOST])
11 FLOAT_H= 11 GL_GENERATE_FLOAT_H=false
12 REPLACE_FLOAT_LDBL=0 12 REPLACE_FLOAT_LDBL=0
13 case "$host_os" in 13 case "$host_os" in
14 aix* | beos* | openbsd* | mirbsd* | irix*) 14 aix* | beos* | openbsd* | mirbsd* | irix*)
15 FLOAT_H=float.h 15 GL_GENERATE_FLOAT_H=true
16 ;; 16 ;;
17 freebsd*) 17 freebsd* | dragonfly*)
18 case "$host_cpu" in 18 case "$host_cpu" in
19changequote(,)dnl 19changequote(,)dnl
20 i[34567]86 ) 20 i[34567]86 )
21changequote([,])dnl 21changequote([,])dnl
22 FLOAT_H=float.h 22 GL_GENERATE_FLOAT_H=true
23 ;; 23 ;;
24 x86_64 ) 24 x86_64 )
25 # On x86_64 systems, the C compiler may still be generating 25 # On x86_64 systems, the C compiler may still be generating
26 # 32-bit code. 26 # 32-bit code.
27 AC_EGREP_CPP([yes], 27 AC_COMPILE_IFELSE(
28 [#if defined __LP64__ || defined __x86_64__ || defined __amd64__ 28 [AC_LANG_SOURCE(
29 yes 29 [[#if defined __LP64__ || defined __x86_64__ || defined __amd64__
30 #endif], 30 int ok;
31 #else
32 error fail
33 #endif
34 ]])],
31 [], 35 [],
32 [FLOAT_H=float.h]) 36 [GL_GENERATE_FLOAT_H=true])
33 ;; 37 ;;
34 esac 38 esac
35 ;; 39 ;;
36 linux*) 40 linux*)
37 case "$host_cpu" in 41 case "$host_cpu" in
38 powerpc*) 42 powerpc*)
39 FLOAT_H=float.h 43 GL_GENERATE_FLOAT_H=true
40 ;; 44 ;;
41 esac 45 esac
42 ;; 46 ;;
43 esac 47 esac
44 case "$host_os" in 48 case "$host_os" in
45 aix* | freebsd* | linux*) 49 aix* | freebsd* | dragonfly* | linux*)
46 if test -n "$FLOAT_H"; then 50 if $GL_GENERATE_FLOAT_H; then
47 REPLACE_FLOAT_LDBL=1 51 REPLACE_FLOAT_LDBL=1
48 fi 52 fi
49 ;; 53 ;;
@@ -69,14 +73,20 @@ int main ()
69 [gl_cv_func_itold_works=no], 73 [gl_cv_func_itold_works=no],
70 [case "$host" in 74 [case "$host" in
71 sparc*-*-linux*) 75 sparc*-*-linux*)
72 AC_EGREP_CPP([yes], 76 AC_COMPILE_IFELSE(
73 [#if defined __LP64__ || defined __arch64__ 77 [AC_LANG_SOURCE(
74 yes 78 [[#if defined __LP64__ || defined __arch64__
75 #endif], 79 int ok;
80 #else
81 error fail
82 #endif
83 ]])],
76 [gl_cv_func_itold_works="guessing no"], 84 [gl_cv_func_itold_works="guessing no"],
77 [gl_cv_func_itold_works="guessing yes"]) 85 [gl_cv_func_itold_works="guessing yes"])
78 ;; 86 ;;
79 *) gl_cv_func_itold_works="guessing yes" ;; 87 # Guess yes on native Windows.
88 mingw*) gl_cv_func_itold_works="guessing yes" ;;
89 *) gl_cv_func_itold_works="guessing yes" ;;
80 esac 90 esac
81 ]) 91 ])
82 ]) 92 ])
@@ -85,14 +95,12 @@ int main ()
85 REPLACE_ITOLD=1 95 REPLACE_ITOLD=1
86 dnl We add the workaround to <float.h> but also to <math.h>, 96 dnl We add the workaround to <float.h> but also to <math.h>,
87 dnl to increase the chances that the fix function gets pulled in. 97 dnl to increase the chances that the fix function gets pulled in.
88 FLOAT_H=float.h 98 GL_GENERATE_FLOAT_H=true
89 ;; 99 ;;
90 esac 100 esac
91 101
92 if test -n "$FLOAT_H"; then 102 if $GL_GENERATE_FLOAT_H; then
93 gl_NEXT_HEADERS([float.h]) 103 gl_NEXT_HEADERS([float.h])
94 fi 104 fi
95 AC_SUBST([FLOAT_H])
96 AM_CONDITIONAL([GL_GENERATE_FLOAT_H], [test -n "$FLOAT_H"])
97 AC_SUBST([REPLACE_ITOLD]) 105 AC_SUBST([REPLACE_ITOLD])
98]) 106])
diff --git a/gl/m4/floorf.m4 b/gl/m4/floorf.m4
index c892ff9..c49ffa6 100644
--- a/gl/m4/floorf.m4
+++ b/gl/m4/floorf.m4
@@ -1,5 +1,5 @@
1# floorf.m4 serial 13 1# floorf.m4 serial 18
2dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2023 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,7 +39,7 @@ AC_DEFUN([gl_FUNC_FLOORF],
39static float dummy (float f) { return 0; } 39static float dummy (float f) { return 0; }
40int main (int argc, char *argv[]) 40int main (int argc, char *argv[])
41{ 41{
42 float (*my_floorf) (float) = argc ? floorf : dummy; 42 float (* volatile my_floorf) (float) = argc ? floorf : dummy;
43 /* Test whether floorf (-0.0f) is -0.0f. */ 43 /* Test whether floorf (-0.0f) is -0.0f. */
44 if (signbitf (minus_zerof) && !signbitf (my_floorf (minus_zerof))) 44 if (signbitf (minus_zerof) && !signbitf (my_floorf (minus_zerof)))
45 return 1; 45 return 1;
@@ -49,10 +49,14 @@ int main (int argc, char *argv[])
49 [gl_cv_func_floorf_ieee=yes], 49 [gl_cv_func_floorf_ieee=yes],
50 [gl_cv_func_floorf_ieee=no], 50 [gl_cv_func_floorf_ieee=no],
51 [case "$host_os" in 51 [case "$host_os" in
52 # Guess yes on glibc systems. 52 # Guess yes on glibc systems.
53 *-gnu*) gl_cv_func_floorf_ieee="guessing yes" ;; 53 *-gnu* | gnu*) gl_cv_func_floorf_ieee="guessing yes" ;;
54 # If we don't know, assume the worst. 54 # Guess yes on musl systems.
55 *) gl_cv_func_floorf_ieee="guessing no" ;; 55 *-musl*) gl_cv_func_floorf_ieee="guessing yes" ;;
56 # Guess yes on native Windows.
57 mingw*) gl_cv_func_floorf_ieee="guessing yes" ;;
58 # If we don't know, obey --enable-cross-guesses.
59 *) gl_cv_func_floorf_ieee="$gl_cross_guess_normal" ;;
56 esac 60 esac
57 ]) 61 ])
58 LIBS="$save_LIBS" 62 LIBS="$save_LIBS"
diff --git a/gl/m4/fopen.m4 b/gl/m4/fopen.m4
new file mode 100644
index 0000000..9c39ff7
--- /dev/null
+++ b/gl/m4/fopen.m4
@@ -0,0 +1,149 @@
1# fopen.m4 serial 13
2dnl Copyright (C) 2007-2023 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_FOPEN],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 case "$host_os" in
12 mingw* | pw*)
13 dnl Replace fopen, for handling of "/dev/null".
14 REPLACE_FOPEN=1
15 dnl fopen on mingw also has the trailing slash bug.
16 gl_cv_func_fopen_slash="guessing no"
17 ;;
18 *)
19 dnl fopen("foo/", "w") should not create a file when the file name has a
20 dnl trailing slash.
21 AC_CACHE_CHECK([whether fopen recognizes a trailing slash],
22 [gl_cv_func_fopen_slash],
23 [
24 AC_RUN_IFELSE(
25 [AC_LANG_SOURCE([[
26#include <stddef.h>
27#include <stdio.h>
28int main ()
29{
30 FILE *fp = fopen ("conftest.sl/", "w");
31 int result = (fp != NULL);
32 if (fp != NULL)
33 fclose (fp);
34 return result;
35}]])],
36 [gl_cv_func_fopen_slash=yes],
37 [gl_cv_func_fopen_slash=no],
38 [
39changequote(,)dnl
40 case "$host_os" in
41 aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
42 gl_cv_func_fopen_slash="guessing no" ;;
43 *)
44 gl_cv_func_fopen_slash="guessing yes" ;;
45 esac
46changequote([,])dnl
47 ])
48 rm -f conftest.sl
49 ])
50 ;;
51 esac
52 case "$gl_cv_func_fopen_slash" in
53 *no)
54 AC_DEFINE([FOPEN_TRAILING_SLASH_BUG], [1],
55 [Define to 1 if fopen() fails to recognize a trailing slash.])
56 REPLACE_FOPEN=1
57 ;;
58 esac
59])
60
61AC_DEFUN([gl_FUNC_FOPEN_GNU],
62[
63 AC_REQUIRE([gl_FUNC_FOPEN])
64 AC_CACHE_CHECK([whether fopen supports the mode character 'x'],
65 [gl_cv_func_fopen_mode_x],
66 [rm -f conftest.x
67 AC_RUN_IFELSE(
68 [AC_LANG_SOURCE([[
69#include <stdio.h>
70#include <errno.h>
71int main ()
72{
73 FILE *fp;
74 fp = fopen ("conftest.x", "w");
75 fclose (fp);
76 fp = fopen ("conftest.x", "wx");
77 if (fp != NULL)
78 /* 'x' ignored */
79 return 1;
80 else if (errno == EEXIST)
81 return 0;
82 else
83 /* 'x' rejected */
84 return 2;
85}]])],
86 [gl_cv_func_fopen_mode_x=yes],
87 [gl_cv_func_fopen_mode_x=no],
88 [case "$host_os" in
89 # Guess yes on glibc and musl systems.
90 linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl*)
91 gl_cv_func_fopen_mode_x="guessing yes" ;;
92 # If we don't know, obey --enable-cross-guesses.
93 *)
94 gl_cv_func_fopen_mode_x="$gl_cross_guess_normal" ;;
95 esac
96 ])
97 rm -f conftest.x
98 ])
99 AC_CACHE_CHECK([whether fopen supports the mode character 'e'],
100 [gl_cv_func_fopen_mode_e],
101 [echo foo > conftest.x
102 AC_RUN_IFELSE(
103 [AC_LANG_SOURCE([[
104#include <stdio.h>
105#include <errno.h>
106#include <fcntl.h>
107]GL_MDA_DEFINES[
108int main ()
109{
110 FILE *fp = fopen ("conftest.x", "re");
111 if (fp != NULL)
112 {
113 if (fcntl (fileno (fp), F_GETFD) & FD_CLOEXEC)
114 return 0;
115 else
116 /* 'e' ignored */
117 return 1;
118 }
119 else
120 /* 'e' rejected */
121 return 2;
122}]])],
123 [gl_cv_func_fopen_mode_e=yes],
124 [gl_cv_func_fopen_mode_e=no],
125 [case "$host_os" in
126 # Guess yes on glibc and musl systems.
127 linux*-gnu* | gnu* | kfreebsd*-gnu | *-musl*)
128 gl_cv_func_fopen_mode_e="guessing yes" ;;
129 # Guess no on native Windows.
130 mingw*)
131 gl_cv_func_fopen_mode_e="guessing no" ;;
132 # If we don't know, obey --enable-cross-guesses.
133 *)
134 gl_cv_func_fopen_mode_e="$gl_cross_guess_normal" ;;
135 esac
136 ])
137 rm -f conftest.x
138 ])
139 REPLACE_FOPEN_FOR_FOPEN_GNU="$REPLACE_FOPEN"
140 case "$gl_cv_func_fopen_mode_x" in
141 *no) REPLACE_FOPEN_FOR_FOPEN_GNU=1 ;;
142 esac
143 case "$gl_cv_func_fopen_mode_e" in
144 *no) REPLACE_FOPEN_FOR_FOPEN_GNU=1 ;;
145 esac
146])
147
148# Prerequisites of lib/fopen.c.
149AC_DEFUN([gl_PREREQ_FOPEN], [:])
diff --git a/gl/m4/fpurge.m4 b/gl/m4/fpurge.m4
new file mode 100644
index 0000000..b365409
--- /dev/null
+++ b/gl/m4/fpurge.m4
@@ -0,0 +1,73 @@
1# fpurge.m4 serial 12
2dnl Copyright (C) 2007, 2009-2023 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_FPURGE],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11 AC_CHECK_HEADERS_ONCE([stdio_ext.h])
12 AC_CHECK_FUNCS_ONCE([fpurge])
13 AC_CHECK_FUNCS_ONCE([__fpurge])
14 AC_CHECK_DECLS([fpurge], , , [[#include <stdio.h>]])
15 if test "x$ac_cv_func_fpurge" = xyes; then
16 HAVE_FPURGE=1
17 # Detect BSD bug. Only cygwin 1.7 and musl are known to be immune.
18 AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works],
19 [AC_RUN_IFELSE(
20 [AC_LANG_PROGRAM(
21 [[#include <stdio.h>
22]],
23 [[FILE *f = fopen ("conftest.txt", "w+");
24 if (!f)
25 return 1;
26 if (fputc ('a', f) != 'a')
27 { fclose (f); return 2; }
28 rewind (f);
29 if (fgetc (f) != 'a')
30 { fclose (f); return 3; }
31 if (fgetc (f) != EOF)
32 { fclose (f); return 4; }
33 if (fpurge (f) != 0)
34 { fclose (f); return 5; }
35 if (putc ('b', f) != 'b')
36 { fclose (f); return 6; }
37 if (fclose (f) != 0)
38 return 7;
39 if ((f = fopen ("conftest.txt", "r")) == NULL)
40 return 8;
41 if (fgetc (f) != 'a')
42 { fclose (f); return 9; }
43 if (fgetc (f) != 'b')
44 { fclose (f); return 10; }
45 if (fgetc (f) != EOF)
46 { fclose (f); return 11; }
47 if (fclose (f) != 0)
48 return 12;
49 if (remove ("conftest.txt") != 0)
50 return 13;
51 return 0;
52 ]])],
53 [gl_cv_func_fpurge_works=yes],
54 [gl_cv_func_fpurge_works=no],
55 [case "$host_os" in
56 # Guess yes on musl systems.
57 *-musl*) gl_cv_func_fpurge_works="guessing yes" ;;
58 # Otherwise obey --enable-cross-guesses.
59 *) gl_cv_func_fpurge_works="$gl_cross_guess_normal" ;;
60 esac
61 ])
62 ])
63 case "$gl_cv_func_fpurge_works" in
64 *yes) ;;
65 *) REPLACE_FPURGE=1 ;;
66 esac
67 else
68 HAVE_FPURGE=0
69 fi
70 if test "x$ac_cv_have_decl_fpurge" = xno; then
71 HAVE_DECL_FPURGE=0
72 fi
73])
diff --git a/gl/m4/sha1.m4 b/gl/m4/freading.m4
index 21c775e..3533336 100644
--- a/gl/m4/sha1.m4
+++ b/gl/m4/freading.m4
@@ -1,12 +1,11 @@
1# sha1.m4 serial 11 1# freading.m4 serial 2
2dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2023 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_SHA1], 7AC_DEFUN([gl_FUNC_FREADING],
8[ 8[
9 dnl Prerequisites of lib/sha1.c. 9 AC_CHECK_HEADERS_ONCE([stdio_ext.h])
10 AC_REQUIRE([gl_BIGENDIAN]) 10 AC_CHECK_FUNCS_ONCE([__freading])
11 :
12]) 11])
diff --git a/gl/m4/free.m4 b/gl/m4/free.m4
new file mode 100644
index 0000000..0389dea
--- /dev/null
+++ b/gl/m4/free.m4
@@ -0,0 +1,52 @@
1# free.m4 serial 6
2# Copyright (C) 2003-2005, 2009-2023 Free Software Foundation, Inc.
3# This file is free software; the Free Software Foundation
4# gives unlimited permission to copy and/or distribute it,
5# with or without modifications, as long as this notice is preserved.
6
7# Written by Paul Eggert and Bruno Haible.
8
9AC_DEFUN([gl_FUNC_FREE],
10[
11 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
12
13 dnl In the next release of POSIX, free must preserve errno.
14 dnl https://www.austingroupbugs.net/view.php?id=385
15 dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924
16 dnl So far, we know of three platforms that do this:
17 dnl * glibc >= 2.33, thanks to the fix for this bug:
18 dnl <https://sourceware.org/bugzilla/show_bug.cgi?id=17924>
19 dnl * OpenBSD >= 4.5, thanks to this commit:
20 dnl <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/malloc.c.diff?r1=1.100&r2=1.101&f=h>
21 dnl * Solaris, because its malloc() implementation is based on brk(),
22 dnl not mmap(); hence its free() implementation makes no system calls.
23 dnl For other platforms, you can only be sure if they state it in their
24 dnl documentation, or by code inspection of the free() implementation in libc.
25 AC_CACHE_CHECK([whether free is known to preserve errno],
26 [gl_cv_func_free_preserves_errno],
27 [AC_COMPILE_IFELSE(
28 [AC_LANG_PROGRAM(
29 [[#include <stdlib.h>
30 ]],
31 [[#if 2 < __GLIBC__ + (33 <= __GLIBC_MINOR__)
32 #elif defined __OpenBSD__
33 #elif defined __sun
34 #else
35 #error "'free' is not known to preserve errno"
36 #endif
37 ]])],
38 [gl_cv_func_free_preserves_errno=yes],
39 [gl_cv_func_free_preserves_errno=no])
40 ])
41
42 case $gl_cv_func_free_preserves_errno in
43 *yes)
44 AC_DEFINE([HAVE_FREE_POSIX], [1],
45 [Define if the 'free' function is guaranteed to preserve errno.])
46 ;;
47 *) REPLACE_FREE=1 ;;
48 esac
49])
50
51# Prerequisites of lib/free.c.
52AC_DEFUN([gl_PREREQ_FREE], [:])
diff --git a/gl/m4/fseek.m4 b/gl/m4/fseek.m4
new file mode 100644
index 0000000..c5fe688
--- /dev/null
+++ b/gl/m4/fseek.m4
@@ -0,0 +1,15 @@
1# fseek.m4 serial 4
2dnl Copyright (C) 2007, 2009-2023 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_FSEEK],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_FSEEKO])
11 dnl When fseeko needs fixes, fseek needs them too.
12 if test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1; then
13 REPLACE_FSEEK=1
14 fi
15])
diff --git a/gl/m4/fseeko.m4 b/gl/m4/fseeko.m4
new file mode 100644
index 0000000..05ee06b
--- /dev/null
+++ b/gl/m4/fseeko.m4
@@ -0,0 +1,77 @@
1# fseeko.m4 serial 20
2dnl Copyright (C) 2007-2023 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_FSEEKO],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([gl_STDIN_LARGE_OFFSET])
11 AC_REQUIRE([gl_SYS_TYPES_H])
12 AC_REQUIRE([AC_PROG_CC])
13
14 dnl Persuade glibc <stdio.h> to declare fseeko().
15 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16
17 AC_CACHE_CHECK([for fseeko], [gl_cv_func_fseeko],
18 [
19 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
20]], [[fseeko (stdin, 0, 0);]])],
21 [gl_cv_func_fseeko=yes], [gl_cv_func_fseeko=no])
22 ])
23
24 AC_CHECK_DECLS_ONCE([fseeko])
25 if test $ac_cv_have_decl_fseeko = no; then
26 HAVE_DECL_FSEEKO=0
27 fi
28
29 if test $gl_cv_func_fseeko = no; then
30 HAVE_FSEEKO=0
31 else
32 if test $WINDOWS_64_BIT_OFF_T = 1; then
33 REPLACE_FSEEKO=1
34 fi
35 if test $gl_cv_var_stdin_large_offset = no; then
36 REPLACE_FSEEKO=1
37 fi
38 m4_ifdef([gl_FUNC_FFLUSH_STDIN], [
39 gl_FUNC_FFLUSH_STDIN
40 case "$gl_cv_func_fflush_stdin" in
41 *yes) ;;
42 *) REPLACE_FSEEKO=1 ;;
43 esac
44 ])
45 fi
46])
47
48dnl Code shared by fseeko and ftello. Determine if large files are supported,
49dnl but stdin does not start as a large file by default.
50AC_DEFUN([gl_STDIN_LARGE_OFFSET],
51 [
52 AC_CACHE_CHECK([whether stdin defaults to large file offsets],
53 [gl_cv_var_stdin_large_offset],
54 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
55[[#if defined __SL64 && defined __SCLE /* cygwin */
56 /* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making
57 fseeko/ftello needlessly fail. This bug was fixed in 1.5.25, and
58 it is easier to do a version check than building a runtime test. */
59# include <cygwin/version.h>
60# if CYGWIN_VERSION_DLL_COMBINED < CYGWIN_VERSION_DLL_MAKE_COMBINED (1005, 25)
61 choke me
62# endif
63#endif]])],
64 [gl_cv_var_stdin_large_offset=yes],
65 [gl_cv_var_stdin_large_offset=no])])
66])
67
68# Prerequisites of lib/fseeko.c.
69AC_DEFUN([gl_PREREQ_FSEEKO],
70[
71 dnl Native Windows has the function _fseeki64. mingw hides it in some
72 dnl circumstances, but mingw64 makes it usable again.
73 AC_CHECK_FUNCS([_fseeki64])
74 if test $ac_cv_func__fseeki64 = yes; then
75 AC_CHECK_DECLS([_fseeki64])
76 fi
77])
diff --git a/gl/m4/fstat.m4 b/gl/m4/fstat.m4
new file mode 100644
index 0000000..7cb2edb
--- /dev/null
+++ b/gl/m4/fstat.m4
@@ -0,0 +1,40 @@
1# fstat.m4 serial 8
2dnl Copyright (C) 2011-2023 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_FSTAT],
8[
9 AC_REQUIRE([AC_CANONICAL_HOST])
10 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
11
12 case "$host_os" in
13 mingw* | solaris*)
14 dnl On MinGW, the original stat() returns st_atime, st_mtime,
15 dnl st_ctime values that are affected by the time zone.
16 dnl Solaris stat can return a negative tv_nsec.
17 REPLACE_FSTAT=1
18 ;;
19 esac
20
21 dnl Replace fstat() for supporting the gnulib-defined open() on directories.
22 m4_ifdef([gl_FUNC_FCHDIR], [
23 gl_TEST_FCHDIR
24 if test $HAVE_FCHDIR = 0; then
25 case "$gl_cv_func_open_directory_works" in
26 *yes) ;;
27 *)
28 REPLACE_FSTAT=1
29 ;;
30 esac
31 fi
32 ])
33])
34
35# Prerequisites of lib/fstat.c and lib/stat-w32.c.
36AC_DEFUN([gl_PREREQ_FSTAT], [
37 AC_REQUIRE([gl_SYS_STAT_H])
38 AC_REQUIRE([gl_PREREQ_STAT_W32])
39 :
40])
diff --git a/gl/m4/fstypename.m4 b/gl/m4/fstypename.m4
index c72ecb8..f65c459 100644
--- a/gl/m4/fstypename.m4
+++ b/gl/m4/fstypename.m4
@@ -6,7 +6,7 @@ dnl See if struct statfs has the f_fstypename member.
6dnl If so, define HAVE_STRUCT_STATFS_F_FSTYPENAME. 6dnl If so, define HAVE_STRUCT_STATFS_F_FSTYPENAME.
7dnl 7dnl
8 8
9# Copyright (C) 1998-1999, 2001, 2004, 2006, 2009-2013 Free Software 9# Copyright (C) 1998-1999, 2001, 2004, 2006, 2009-2023 Free Software
10# Foundation, Inc. 10# Foundation, Inc.
11# This file is free software; the Free Software Foundation 11# This file is free software; the Free Software Foundation
12# gives unlimited permission to copy and/or distribute it, 12# gives unlimited permission to copy and/or distribute it,
diff --git a/gl/m4/fsusage.m4 b/gl/m4/fsusage.m4
index 6277bfa..88f3ca8 100644
--- a/gl/m4/fsusage.m4
+++ b/gl/m4/fsusage.m4
@@ -1,7 +1,7 @@
1# serial 30 1# serial 35
2# Obtaining file system usage information. 2# Obtaining file system usage information.
3 3
4# Copyright (C) 1997-1998, 2000-2001, 2003-2013 Free Software Foundation, Inc. 4# Copyright (C) 1997-1998, 2000-2001, 2003-2023 Free Software Foundation, Inc.
5# 5#
6# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
@@ -29,27 +29,29 @@ AC_DEFUN([gl_FSUSAGE],
29 29
30AC_DEFUN([gl_FILE_SYSTEM_USAGE], 30AC_DEFUN([gl_FILE_SYSTEM_USAGE],
31[ 31[
32dnl Enable large-file support. This has the effect of changing the size 32 dnl Enable large-file support. This has the effect of changing the size
33dnl of field f_blocks in 'struct statvfs' from 32 bit to 64 bit on 33 dnl of field f_blocks in 'struct statvfs' from 32 bit to 64 bit on
34dnl glibc/Hurd, HP-UX 11, Solaris (32-bit mode). It also changes the size 34 dnl glibc/Hurd, HP-UX 11, Solaris (32-bit mode). It also changes the size
35dnl of field f_blocks in 'struct statfs' from 32 bit to 64 bit on 35 dnl of field f_blocks in 'struct statfs' from 32 bit to 64 bit on
36dnl Mac OS X >= 10.5 (32-bit mode). 36 dnl Mac OS X >= 10.5 (32-bit mode).
37AC_REQUIRE([AC_SYS_LARGEFILE]) 37 AC_REQUIRE([AC_SYS_LARGEFILE])
38 38
39AC_MSG_NOTICE([checking how to get file system space usage]) 39 ac_fsusage_space=no
40ac_fsusage_space=no
41 40
42# Perform only the link test since it seems there are no variants of the 41 # Perform only the link test since it seems there are no variants of the
43# statvfs function. This check is more than just AC_CHECK_FUNCS([statvfs]) 42 # statvfs function. This check is more than just AC_CHECK_FUNCS([statvfs])
44# because that got a false positive on SCO OSR5. Adding the declaration 43 # because that got a false positive on SCO OSR5. Adding the declaration
45# of a 'struct statvfs' causes this test to fail (as it should) on such 44 # of a 'struct statvfs' causes this test to fail (as it should) on such
46# systems. That system is reported to work fine with STAT_STATFS4 which 45 # systems. That system is reported to work fine with STAT_STATFS4 which
47# is what it gets when this test fails. 46 # is what it gets when this test fails.
48if test $ac_fsusage_space = no; then 47 if test $ac_fsusage_space = no; then
49 # glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0, 48 # glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
50 # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS. 49 # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
51 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs], 50 AC_CACHE_CHECK([for statvfs function (SVR4)],
52 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> 51 [fu_cv_sys_stat_statvfs],
52 [AC_LINK_IFELSE(
53 [AC_LANG_PROGRAM([[
54#include <sys/types.h>
53#ifdef __osf__ 55#ifdef __osf__
54"Do not use Tru64's statvfs implementation" 56"Do not use Tru64's statvfs implementation"
55#endif 57#endif
@@ -68,45 +70,47 @@ struct statvfs fsd;
68int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1]; 70int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1];
69#endif 71#endif
70]], 72]],
71 [[statvfs (0, &fsd);]])], 73 [[statvfs (0, &fsd);]])],
72 [fu_cv_sys_stat_statvfs=yes], 74 [fu_cv_sys_stat_statvfs=yes],
73 [fu_cv_sys_stat_statvfs=no])]) 75 [fu_cv_sys_stat_statvfs=no])
74 if test $fu_cv_sys_stat_statvfs = yes; then
75 ac_fsusage_space=yes
76 # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
77 # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
78 # statvfs with large-file support is already equivalent to statvfs64.
79 AC_CACHE_CHECK([whether to use statvfs64],
80 [fu_cv_sys_stat_statvfs64],
81 [AC_LINK_IFELSE(
82 [AC_LANG_PROGRAM(
83 [[#include <sys/types.h>
84 #include <sys/statvfs.h>
85 struct statvfs64 fsd;
86 int check_f_blocks_larger_in_statvfs64
87 [sizeof (((struct statvfs64 *) 0)->f_blocks)
88 > sizeof (((struct statvfs *) 0)->f_blocks)
89 ? 1 : -1];
90 ]],
91 [[statvfs64 (0, &fsd);]])],
92 [fu_cv_sys_stat_statvfs64=yes],
93 [fu_cv_sys_stat_statvfs64=no])
94 ]) 76 ])
95 if test $fu_cv_sys_stat_statvfs64 = yes; then 77 if test $fu_cv_sys_stat_statvfs = yes; then
96 AC_DEFINE([STAT_STATVFS64], [1], 78 ac_fsusage_space=yes
97 [ Define if statvfs64 should be preferred over statvfs.]) 79 # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
98 else 80 # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
99 AC_DEFINE([STAT_STATVFS], [1], 81 # statvfs with large-file support is already equivalent to statvfs64.
100 [ Define if there is a function named statvfs. (SVR4)]) 82 AC_CACHE_CHECK([whether to use statvfs64],
83 [fu_cv_sys_stat_statvfs64],
84 [AC_LINK_IFELSE(
85 [AC_LANG_PROGRAM(
86 [[#include <sys/types.h>
87 #include <sys/statvfs.h>
88 struct statvfs64 fsd;
89 int check_f_blocks_larger_in_statvfs64
90 [sizeof (((struct statvfs64 *) 0)->f_blocks)
91 > sizeof (((struct statvfs *) 0)->f_blocks)
92 ? 1 : -1];
93 ]],
94 [[statvfs64 (0, &fsd);]])],
95 [fu_cv_sys_stat_statvfs64=yes],
96 [fu_cv_sys_stat_statvfs64=no])
97 ])
98 if test $fu_cv_sys_stat_statvfs64 = yes; then
99 AC_DEFINE([STAT_STATVFS64], [1],
100 [Define if statvfs64 should be preferred over statvfs.])
101 else
102 AC_DEFINE([STAT_STATVFS], [1],
103 [Define if there is a function named statvfs. (SVR4)])
104 fi
101 fi 105 fi
102 fi 106 fi
103fi
104 107
105# Check for this unconditionally so we have a 108 # Check for this unconditionally so we have a
106# good fallback on glibc/Linux > 2.6 < 2.6.36 109 # good fallback on glibc/Linux > 2.6 < 2.6.36
107AC_MSG_CHECKING([for two-argument statfs with statfs.f_frsize member]) 110 AC_CACHE_CHECK([for two-argument statfs with statfs.f_frsize member],
108AC_CACHE_VAL([fu_cv_sys_stat_statfs2_frsize], 111 [fu_cv_sys_stat_statfs2_frsize],
109[AC_RUN_IFELSE([AC_LANG_SOURCE([[ 112 [AC_RUN_IFELSE(
113 [AC_LANG_SOURCE([[
110#ifdef HAVE_SYS_PARAM_H 114#ifdef HAVE_SYS_PARAM_H
111#include <sys/param.h> 115#include <sys/param.h>
112#endif 116#endif
@@ -119,26 +123,26 @@ AC_CACHE_VAL([fu_cv_sys_stat_statfs2_frsize],
119 int 123 int
120 main () 124 main ()
121 { 125 {
122 struct statfs fsd; 126 struct statfs fsd;
123 fsd.f_frsize = 0; 127 fsd.f_frsize = 0;
124 return statfs (".", &fsd) != 0; 128 return statfs (".", &fsd) != 0;
125 }]])], 129 }]])],
126 [fu_cv_sys_stat_statfs2_frsize=yes], 130 [fu_cv_sys_stat_statfs2_frsize=yes],
127 [fu_cv_sys_stat_statfs2_frsize=no], 131 [fu_cv_sys_stat_statfs2_frsize=no],
128 [fu_cv_sys_stat_statfs2_frsize=no])]) 132 [fu_cv_sys_stat_statfs2_frsize=no])
129AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_frsize]) 133 ])
130if test $fu_cv_sys_stat_statfs2_frsize = yes; then 134 if test $fu_cv_sys_stat_statfs2_frsize = yes; then
131 ac_fsusage_space=yes 135 ac_fsusage_space=yes
132 AC_DEFINE([STAT_STATFS2_FRSIZE], [1], 136 AC_DEFINE([STAT_STATFS2_FRSIZE], [1],
133[ Define if statfs takes 2 args and struct statfs has a field named f_frsize. 137 [Define if statfs takes 2 args and struct statfs has a field named f_frsize.
134 (glibc/Linux > 2.6)]) 138 (glibc/Linux > 2.6)])
135fi 139 fi
136 140
137if test $ac_fsusage_space = no; then 141 if test $ac_fsusage_space = no; then
138 # DEC Alpha running OSF/1 142 # DEC Alpha running OSF/1
139 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)]) 143 AC_CACHE_CHECK([for 3-argument statfs function (DEC OSF/1)],
140 AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1], 144 [fu_cv_sys_stat_statfs3_osf1],
141 [AC_RUN_IFELSE([AC_LANG_SOURCE([[ 145 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
142#include <sys/param.h> 146#include <sys/param.h>
143#include <sys/types.h> 147#include <sys/types.h>
144#include <sys/mount.h> 148#include <sys/mount.h>
@@ -149,28 +153,27 @@ if test $ac_fsusage_space = no; then
149 fsd.f_fsize = 0; 153 fsd.f_fsize = 0;
150 return statfs (".", &fsd, sizeof (struct statfs)) != 0; 154 return statfs (".", &fsd, sizeof (struct statfs)) != 0;
151 }]])], 155 }]])],
152 [fu_cv_sys_stat_statfs3_osf1=yes], 156 [fu_cv_sys_stat_statfs3_osf1=yes],
153 [fu_cv_sys_stat_statfs3_osf1=no], 157 [fu_cv_sys_stat_statfs3_osf1=no],
154 [fu_cv_sys_stat_statfs3_osf1=no])]) 158 [fu_cv_sys_stat_statfs3_osf1=no])
155 AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1]) 159 ])
156 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then 160 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
157 ac_fsusage_space=yes 161 ac_fsusage_space=yes
158 AC_DEFINE([STAT_STATFS3_OSF1], [1], 162 AC_DEFINE([STAT_STATFS3_OSF1], [1],
159 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)]) 163 [Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
164 fi
160 fi 165 fi
161fi
162 166
163if test $ac_fsusage_space = no; then 167 if test $ac_fsusage_space = no; then
164 # glibc/Linux, Mac OS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4. 168 # glibc/Linux, Mac OS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
165 # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0, 169 # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
166 # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.) 170 # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
167 # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and 171 # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
168 # <sys/vfs.h>.) 172 # <sys/vfs.h>.)
169 # (On Solaris, statfs has 4 arguments.) 173 # (On Solaris, statfs has 4 arguments.)
170 AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl 174 AC_CACHE_CHECK([for two-argument statfs with statfs.f_bsize member (AIX, 4.3BSD)],
171member (AIX, 4.3BSD)]) 175 [fu_cv_sys_stat_statfs2_bsize],
172 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize], 176 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
173 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
174#ifdef HAVE_SYS_PARAM_H 177#ifdef HAVE_SYS_PARAM_H
175#include <sys/param.h> 178#include <sys/param.h>
176#endif 179#endif
@@ -183,88 +186,56 @@ member (AIX, 4.3BSD)])
183 int 186 int
184 main () 187 main ()
185 { 188 {
186 struct statfs fsd; 189 struct statfs fsd;
187 fsd.f_bsize = 0; 190 fsd.f_bsize = 0;
188 return statfs (".", &fsd) != 0; 191 return statfs (".", &fsd) != 0;
189 }]])], 192 }]])],
190 [fu_cv_sys_stat_statfs2_bsize=yes], 193 [fu_cv_sys_stat_statfs2_bsize=yes],
191 [fu_cv_sys_stat_statfs2_bsize=no], 194 [fu_cv_sys_stat_statfs2_bsize=no],
192 [fu_cv_sys_stat_statfs2_bsize=no])]) 195 [fu_cv_sys_stat_statfs2_bsize=no])
193 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize]) 196 ])
194 if test $fu_cv_sys_stat_statfs2_bsize = yes; then 197 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
195 ac_fsusage_space=yes 198 ac_fsusage_space=yes
196 AC_DEFINE([STAT_STATFS2_BSIZE], [1], 199 AC_DEFINE([STAT_STATFS2_BSIZE], [1],
197[ Define if statfs takes 2 args and struct statfs has a field named f_bsize. 200 [Define if statfs takes 2 args and struct statfs has a field named f_bsize.
198 (4.3BSD, SunOS 4, HP-UX, AIX PS/2)]) 201 (4.3BSD, SunOS 4, HP-UX)])
202 fi
199 fi 203 fi
200fi
201 204
202if test $ac_fsusage_space = no; then 205 if test $ac_fsusage_space = no; then
203 # SVR3 206 # SVR3
204 # (Solaris already handled above.) 207 # (Solaris already handled above.)
205 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)]) 208 AC_CACHE_CHECK([for four-argument statfs (SVR3)],
206 AC_CACHE_VAL([fu_cv_sys_stat_statfs4], 209 [fu_cv_sys_stat_statfs4],
207 [AC_RUN_IFELSE([AC_LANG_SOURCE([[ 210 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
208#include <sys/types.h> 211#include <sys/types.h>
209#include <sys/statfs.h> 212#include <sys/statfs.h>
210 int 213 int
211 main () 214 main ()
212 { 215 {
213 struct statfs fsd; 216 struct statfs fsd;
214 return statfs (".", &fsd, sizeof fsd, 0) != 0; 217 return statfs (".", &fsd, sizeof fsd, 0) != 0;
215 }]])],
216 [fu_cv_sys_stat_statfs4=yes],
217 [fu_cv_sys_stat_statfs4=no],
218 [fu_cv_sys_stat_statfs4=no])])
219 AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
220 if test $fu_cv_sys_stat_statfs4 = yes; then
221 ac_fsusage_space=yes
222 AC_DEFINE([STAT_STATFS4], [1],
223 [ Define if statfs takes 4 args. (SVR3, Dynix, old Irix, old AIX, Dolphin)])
224 fi
225fi
226
227if test $ac_fsusage_space = no; then
228 # 4.4BSD and older NetBSD
229 # (OSF/1 already handled above.)
230 # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
231 # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
232 # <sys/mount.h>.)
233 AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
234member (4.4BSD and NetBSD)])
235 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
236 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
237#include <sys/types.h>
238#ifdef HAVE_SYS_PARAM_H
239#include <sys/param.h>
240#endif
241#ifdef HAVE_SYS_MOUNT_H
242#include <sys/mount.h>
243#endif
244 int
245 main ()
246 {
247 struct statfs fsd;
248 fsd.f_fsize = 0;
249 return statfs (".", &fsd) != 0;
250 }]])], 218 }]])],
251 [fu_cv_sys_stat_statfs2_fsize=yes], 219 [fu_cv_sys_stat_statfs4=yes],
252 [fu_cv_sys_stat_statfs2_fsize=no], 220 [fu_cv_sys_stat_statfs4=no],
253 [fu_cv_sys_stat_statfs2_fsize=no])]) 221 [fu_cv_sys_stat_statfs4=no])
254 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize]) 222 ])
255 if test $fu_cv_sys_stat_statfs2_fsize = yes; then 223 if test $fu_cv_sys_stat_statfs4 = yes; then
256 ac_fsusage_space=yes 224 ac_fsusage_space=yes
257 AC_DEFINE([STAT_STATFS2_FSIZE], [1], 225 AC_DEFINE([STAT_STATFS4], [1],
258[ Define if statfs takes 2 args and struct statfs has a field named f_fsize. 226 [Define if statfs takes 4 args. (SVR3, old Irix)])
259 (4.4BSD, NetBSD)]) 227 fi
260 fi 228 fi
261fi
262 229
263if test $ac_fsusage_space = no; then 230 if test $ac_fsusage_space = no; then
264 # Ultrix 231 # 4.4BSD and older NetBSD
265 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)]) 232 # (OSF/1 already handled above.)
266 AC_CACHE_VAL([fu_cv_sys_stat_fs_data], 233 # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
267 [AC_RUN_IFELSE([AC_LANG_SOURCE([[ 234 # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
235 # <sys/mount.h>.)
236 AC_CACHE_CHECK([for two-argument statfs with statfs.f_fsize member (4.4BSD and NetBSD)],
237 [fu_cv_sys_stat_statfs2_fsize],
238 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
268#include <sys/types.h> 239#include <sys/types.h>
269#ifdef HAVE_SYS_PARAM_H 240#ifdef HAVE_SYS_PARAM_H
270#include <sys/param.h> 241#include <sys/param.h>
@@ -272,41 +243,26 @@ if test $ac_fsusage_space = no; then
272#ifdef HAVE_SYS_MOUNT_H 243#ifdef HAVE_SYS_MOUNT_H
273#include <sys/mount.h> 244#include <sys/mount.h>
274#endif 245#endif
275#ifdef HAVE_SYS_FS_TYPES_H
276#include <sys/fs_types.h>
277#endif
278 int 246 int
279 main () 247 main ()
280 { 248 {
281 struct fs_data fsd; 249 struct statfs fsd;
282 /* Ultrix's statfs returns 1 for success, 250 fsd.f_fsize = 0;
283 0 for not mounted, -1 for failure. */ 251 return statfs (".", &fsd) != 0;
284 return statfs (".", &fsd) != 1;
285 }]])], 252 }]])],
286 [fu_cv_sys_stat_fs_data=yes], 253 [fu_cv_sys_stat_statfs2_fsize=yes],
287 [fu_cv_sys_stat_fs_data=no], 254 [fu_cv_sys_stat_statfs2_fsize=no],
288 [fu_cv_sys_stat_fs_data=no])]) 255 [fu_cv_sys_stat_statfs2_fsize=no])
289 AC_MSG_RESULT([$fu_cv_sys_stat_fs_data]) 256 ])
290 if test $fu_cv_sys_stat_fs_data = yes; then 257 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
291 ac_fsusage_space=yes 258 ac_fsusage_space=yes
292 AC_DEFINE([STAT_STATFS2_FS_DATA], [1], 259 AC_DEFINE([STAT_STATFS2_FSIZE], [1],
293[ Define if statfs takes 2 args and the second argument has 260 [Define if statfs takes 2 args and struct statfs has a field named f_fsize.
294 type struct fs_data. (Ultrix)]) 261 (4.4BSD, NetBSD)])
262 fi
295 fi 263 fi
296fi
297 264
298if test $ac_fsusage_space = no; then 265 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
299 # SVR2
300 # (AIX, HP-UX, OSF/1 already handled above.)
301 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
302 ]])],
303 [AC_DEFINE([STAT_READ_FILSYS], [1],
304 [Define if there is no specific function for reading file systems usage
305 information and you have the <sys/filsys.h> header file. (SVR2)])
306 ac_fsusage_space=yes])
307fi
308
309AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
310 266
311]) 267])
312 268
@@ -316,18 +272,22 @@ AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
316# enable the work-around code in fsusage.c. 272# enable the work-around code in fsusage.c.
317AC_DEFUN([gl_STATFS_TRUNCATES], 273AC_DEFUN([gl_STATFS_TRUNCATES],
318[ 274[
319 AC_MSG_CHECKING([for statfs that truncates block counts]) 275 AC_CACHE_CHECK([for statfs that truncates block counts],
320 AC_CACHE_VAL([fu_cv_sys_truncating_statfs], 276 [fu_cv_sys_truncating_statfs],
321 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 277 [AC_COMPILE_IFELSE(
278 [AC_LANG_PROGRAM([[
322#if !defined(sun) && !defined(__sun) 279#if !defined(sun) && !defined(__sun)
323choke -- this is a workaround for a Sun-specific problem 280choke -- this is a workaround for a Sun-specific problem
324#endif 281#endif
325#include <sys/types.h> 282#include <sys/types.h>
326#include <sys/vfs.h>]], 283#include <sys/vfs.h>
327 [[struct statfs t; long c = *(t.f_spare); 284 ]],
328 if (c) return 0;]])], 285 [[struct statfs t; long c = *(t.f_spare);
329 [fu_cv_sys_truncating_statfs=yes], 286 if (c) return 0;
330 [fu_cv_sys_truncating_statfs=no])]) 287 ]])],
288 [fu_cv_sys_truncating_statfs=yes],
289 [fu_cv_sys_truncating_statfs=no])
290 ])
331 if test $fu_cv_sys_truncating_statfs = yes; then 291 if test $fu_cv_sys_truncating_statfs = yes; then
332 AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1], 292 AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
333 [Define if the block counts reported by statfs may be truncated to 2GB 293 [Define if the block counts reported by statfs may be truncated to 2GB
@@ -335,13 +295,12 @@ choke -- this is a workaround for a Sun-specific problem
335 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem. 295 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
336 SunOS 4.1.1 seems not to be affected.)]) 296 SunOS 4.1.1 seems not to be affected.)])
337 fi 297 fi
338 AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
339]) 298])
340 299
341 300
342# Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE. 301# Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
343AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA], 302AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
344[ 303[
345 AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h]) 304 AC_CHECK_HEADERS([sys/fs/s5param.h sys/statfs.h])
346 gl_STATFS_TRUNCATES 305 gl_STATFS_TRUNCATES
347]) 306])
diff --git a/gl/m4/ftell.m4 b/gl/m4/ftell.m4
new file mode 100644
index 0000000..79f1aaf
--- /dev/null
+++ b/gl/m4/ftell.m4
@@ -0,0 +1,15 @@
1# ftell.m4 serial 3
2dnl Copyright (C) 2007, 2009-2023 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_FTELL],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_FTELLO])
11 dnl When ftello needs fixes, ftell needs them too.
12 if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
13 REPLACE_FTELL=1
14 fi
15])
diff --git a/gl/m4/ftello.m4 b/gl/m4/ftello.m4
new file mode 100644
index 0000000..4901b16
--- /dev/null
+++ b/gl/m4/ftello.m4
@@ -0,0 +1,151 @@
1# ftello.m4 serial 14
2dnl Copyright (C) 2007-2023 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_FTELLO],
8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AC_REQUIRE([AC_PROG_CC])
11 AC_REQUIRE([gl_STDIN_LARGE_OFFSET])
12 AC_REQUIRE([gl_SYS_TYPES_H])
13
14 dnl Persuade glibc <stdio.h> to declare ftello().
15 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16
17 AC_CHECK_DECLS_ONCE([ftello])
18 if test $ac_cv_have_decl_ftello = no; then
19 HAVE_DECL_FTELLO=0
20 fi
21
22 AC_CACHE_CHECK([for ftello], [gl_cv_func_ftello],
23 [
24 AC_LINK_IFELSE(
25 [AC_LANG_PROGRAM(
26 [[#include <stdio.h>]],
27 [[ftello (stdin);]])],
28 [gl_cv_func_ftello=yes],
29 [gl_cv_func_ftello=no])
30 ])
31 if test $gl_cv_func_ftello = no; then
32 HAVE_FTELLO=0
33 else
34 if test $WINDOWS_64_BIT_OFF_T = 1; then
35 REPLACE_FTELLO=1
36 fi
37 if test $gl_cv_var_stdin_large_offset = no; then
38 REPLACE_FTELLO=1
39 fi
40 if test $REPLACE_FTELLO = 0; then
41 dnl Detect bug on Solaris.
42 dnl ftell and ftello produce incorrect results after putc that followed a
43 dnl getc call that reached EOF on Solaris. This is because the _IOREAD
44 dnl flag does not get cleared in this case, even though _IOWRT gets set,
45 dnl and ftell and ftello look whether the _IOREAD flag is set.
46 AC_REQUIRE([AC_CANONICAL_HOST])
47 AC_CACHE_CHECK([whether ftello works],
48 [gl_cv_func_ftello_works],
49 [
50 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
51 dnl be opened.
52changequote(,)dnl
53 case "$host_os" in
54 # Guess no on Solaris.
55 solaris*) gl_cv_func_ftello_works="guessing no" ;;
56 # Guess yes on native Windows.
57 mingw*) gl_cv_func_ftello_works="guessing yes" ;;
58 # Guess yes otherwise.
59 *) gl_cv_func_ftello_works="guessing yes" ;;
60 esac
61changequote([,])dnl
62 AC_RUN_IFELSE(
63 [AC_LANG_SOURCE([[
64#include <stdio.h>
65#include <stdlib.h>
66#include <string.h>
67#define TESTFILE "conftest.tmp"
68int
69main (void)
70{
71 FILE *fp;
72
73 /* Create a file with some contents. */
74 fp = fopen (TESTFILE, "w");
75 if (fp == NULL)
76 return 70;
77 if (fwrite ("foogarsh", 1, 8, fp) < 8)
78 { fclose (fp); return 71; }
79 if (fclose (fp))
80 return 72;
81
82 /* The file's contents is now "foogarsh". */
83
84 /* Try writing after reading to EOF. */
85 fp = fopen (TESTFILE, "r+");
86 if (fp == NULL)
87 return 73;
88 if (fseek (fp, -1, SEEK_END))
89 { fclose (fp); return 74; }
90 if (!(getc (fp) == 'h'))
91 { fclose (fp); return 1; }
92 if (!(getc (fp) == EOF))
93 { fclose (fp); return 2; }
94 if (!(ftell (fp) == 8))
95 { fclose (fp); return 3; }
96 if (!(ftell (fp) == 8))
97 { fclose (fp); return 4; }
98 if (!(putc ('!', fp) == '!'))
99 { fclose (fp); return 5; }
100 if (!(ftell (fp) == 9))
101 { fclose (fp); return 6; }
102 if (!(fclose (fp) == 0))
103 return 7;
104 fp = fopen (TESTFILE, "r");
105 if (fp == NULL)
106 return 75;
107 {
108 char buf[10];
109 if (!(fread (buf, 1, 10, fp) == 9))
110 { fclose (fp); return 10; }
111 if (!(memcmp (buf, "foogarsh!", 9) == 0))
112 { fclose (fp); return 11; }
113 }
114 if (!(fclose (fp) == 0))
115 return 12;
116
117 /* The file's contents is now "foogarsh!". */
118
119 return 0;
120}]])],
121 [gl_cv_func_ftello_works=yes],
122 [gl_cv_func_ftello_works=no], [:])
123 ])
124 case "$gl_cv_func_ftello_works" in
125 *yes) ;;
126 *)
127 REPLACE_FTELLO=1
128 AC_DEFINE([FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE], [1],
129 [Define to 1 if the system's ftello function has the Solaris bug.])
130 ;;
131 esac
132 fi
133 if test $REPLACE_FTELLO = 0; then
134 dnl Detect bug on macOS >= 10.15.
135 gl_FUNC_UNGETC_WORKS
136 if test $gl_ftello_broken_after_ungetc = yes; then
137 REPLACE_FTELLO=1
138 AC_DEFINE([FTELLO_BROKEN_AFTER_UNGETC], [1],
139 [Define to 1 if the system's ftello function has the macOS bug.])
140 fi
141 fi
142 fi
143])
144
145# Prerequisites of lib/ftello.c.
146AC_DEFUN([gl_PREREQ_FTELLO],
147[
148 dnl Native Windows has the function _ftelli64. mingw hides it, but mingw64
149 dnl makes it usable again.
150 AC_CHECK_FUNCS([_ftelli64])
151])
diff --git a/gl/m4/getaddrinfo.m4 b/gl/m4/getaddrinfo.m4
index 1d631f8..15f09ff 100644
--- a/gl/m4/getaddrinfo.m4
+++ b/gl/m4/getaddrinfo.m4
@@ -1,14 +1,13 @@
1# getaddrinfo.m4 serial 30 1# getaddrinfo.m4 serial 34
2dnl Copyright (C) 2004-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2023 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_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
10 AC_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H 10 AC_REQUIRE([gl_NETDB_H])dnl for HAVE_NETDB_H
11 AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
12 GETADDRINFO_LIB= 11 GETADDRINFO_LIB=
13 gai_saved_LIBS="$LIBS" 12 gai_saved_LIBS="$LIBS"
14 13
@@ -55,10 +54,40 @@ AC_DEFUN([gl_GETADDRINFO],
55 if test "$gl_cv_w32_getaddrinfo" = "yes"; then 54 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
56 GETADDRINFO_LIB="-lws2_32" 55 GETADDRINFO_LIB="-lws2_32"
57 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB" 56 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
57 dnl Check for correct signature, in particular for a cdecl-compatible
58 dnl calling convention.
59 AC_CACHE_CHECK([for getaddrinfo with POSIX signature],
60 [gl_cv_func_getaddrinfo_posix_signature],
61 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
62#include <sys/types.h>
63#ifdef HAVE_SYS_SOCKET_H
64#include <sys/socket.h>
65#endif
66#ifdef HAVE_NETDB_H
67#include <netdb.h>
68#endif
69#ifdef HAVE_WS2TCPIP_H
70#include <ws2tcpip.h>
71#endif
72#include <stddef.h>
73extern
74#ifdef __cplusplus
75"C"
76#endif
77int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
78]])],
79 [gl_cv_func_getaddrinfo_posix_signature=yes],
80 [gl_cv_func_getaddrinfo_posix_signature=no])
81 ])
82 if test $gl_cv_func_getaddrinfo_posix_signature = no; then
83 REPLACE_GETADDRINFO=1
84 fi
58 else 85 else
59 HAVE_GETADDRINFO=0 86 HAVE_GETADDRINFO=0
60 fi 87 fi
61 fi 88 fi
89 AC_DEFINE_UNQUOTED([HAVE_GETADDRINFO], [$HAVE_GETADDRINFO],
90 [Define to 1 if getaddrinfo exists, or to 0 otherwise.])
62 91
63 # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an 92 # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
64 # inline function declared in ws2tcpip.h, so we need to get that 93 # inline function declared in ws2tcpip.h, so we need to get that
@@ -127,13 +156,13 @@ const char *gai_strerror(int);]])],
127# Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c. 156# Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
128AC_DEFUN([gl_PREREQ_GETADDRINFO], [ 157AC_DEFUN([gl_PREREQ_GETADDRINFO], [
129 AC_REQUIRE([gl_NETDB_H_DEFAULTS]) 158 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
130 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H 159 AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
131 AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB 160 AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
132 AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB 161 AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
133 AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB 162 AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB
134 AC_REQUIRE([AC_C_RESTRICT]) 163 AC_REQUIRE([AC_C_RESTRICT])
135 AC_REQUIRE([gl_SOCKET_FAMILIES]) 164 AC_REQUIRE([gl_SOCKET_FAMILIES])
136 AC_REQUIRE([gl_HEADER_SYS_SOCKET]) 165 AC_REQUIRE([gl_SYS_SOCKET_H])
137 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 166 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
138 167
139 dnl Including sys/socket.h is wrong for Windows, but Windows does not 168 dnl Including sys/socket.h is wrong for Windows, but Windows does not
diff --git a/gl/m4/getdelim.m4 b/gl/m4/getdelim.m4
new file mode 100644
index 0000000..9aaed20
--- /dev/null
+++ b/gl/m4/getdelim.m4
@@ -0,0 +1,111 @@
1# getdelim.m4 serial 16
2
3dnl Copyright (C) 2005-2007, 2009-2023 Free Software Foundation, Inc.
4dnl
5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved.
8
9AC_PREREQ([2.59])
10
11AC_DEFUN([gl_FUNC_GETDELIM],
12[
13 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST])
15
16 dnl Persuade glibc <stdio.h> to declare getdelim().
17 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
18
19 AC_CHECK_DECLS_ONCE([getdelim])
20
21 AC_CHECK_FUNCS_ONCE([getdelim])
22 if test $ac_cv_func_getdelim = yes; then
23 HAVE_GETDELIM=1
24 dnl Found it in some library. Verify that it works.
25 AC_CACHE_CHECK([for working getdelim function],
26 [gl_cv_func_working_getdelim],
27 [case "$host_os" in
28 darwin*)
29 dnl On macOS 10.13, valgrind detected an out-of-bounds read during
30 dnl the GNU sed test suite:
31 dnl Invalid read of size 16
32 dnl at 0x100EE6A05: _platform_memchr$VARIANT$Base (in /usr/lib/system/libsystem_platform.dylib)
33 dnl by 0x100B7B0BD: getdelim (in /usr/lib/system/libsystem_c.dylib)
34 dnl by 0x10000B0BE: ck_getdelim (utils.c:254)
35 gl_cv_func_working_getdelim=no ;;
36 *)
37 echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
38 AC_RUN_IFELSE([AC_LANG_SOURCE([[
39# include <stdio.h>
40# include <stdlib.h>
41# include <string.h>
42 int main ()
43 {
44 FILE *in = fopen ("./conftest.data", "r");
45 if (!in)
46 return 1;
47 {
48 /* Test result for a NULL buffer and a zero size.
49 Based on a test program from Karl Heuer. */
50 char *line = NULL;
51 size_t siz = 0;
52 int len = getdelim (&line, &siz, '\n', in);
53 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
54 { free (line); fclose (in); return 2; }
55 free (line);
56 }
57 {
58 /* Test result for a NULL buffer and a non-zero size.
59 This crashes on FreeBSD 8.0. */
60 char *line = NULL;
61 size_t siz = (size_t)(~0) / 4;
62 if (getdelim (&line, &siz, '\n', in) == -1)
63 { fclose (in); return 3; }
64 free (line);
65 }
66 fclose (in);
67 return 0;
68 }
69 ]])],
70 [gl_cv_func_working_getdelim=yes],
71 [gl_cv_func_working_getdelim=no],
72 [dnl We're cross compiling.
73 dnl Guess it works on glibc2 systems and musl systems.
74 AC_EGREP_CPP([Lucky GNU user],
75 [
76#include <features.h>
77#ifdef __GNU_LIBRARY__
78 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
79 Lucky GNU user
80 #endif
81#endif
82 ],
83 [gl_cv_func_working_getdelim="guessing yes"],
84 [case "$host_os" in
85 *-musl*) gl_cv_func_working_getdelim="guessing yes" ;;
86 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
87 esac
88 ])
89 ])
90 ;;
91 esac
92 ])
93 case "$gl_cv_func_working_getdelim" in
94 *yes) ;;
95 *) REPLACE_GETDELIM=1 ;;
96 esac
97 else
98 HAVE_GETDELIM=0
99 fi
100
101 if test $ac_cv_have_decl_getdelim = no; then
102 HAVE_DECL_GETDELIM=0
103 fi
104])
105
106# Prerequisites of lib/getdelim.c.
107AC_DEFUN([gl_PREREQ_GETDELIM],
108[
109 AC_CHECK_FUNCS([flockfile funlockfile])
110 AC_CHECK_DECLS([getc_unlocked])
111])
diff --git a/gl/m4/getdtablesize.m4 b/gl/m4/getdtablesize.m4
new file mode 100644
index 0000000..8bcda90
--- /dev/null
+++ b/gl/m4/getdtablesize.m4
@@ -0,0 +1,63 @@
1# getdtablesize.m4 serial 8
2dnl Copyright (C) 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_GETDTABLESIZE],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_CHECK_FUNCS_ONCE([getdtablesize])
12 AC_CHECK_DECLS_ONCE([getdtablesize])
13 if test $ac_cv_func_getdtablesize = yes &&
14 test $ac_cv_have_decl_getdtablesize = yes; then
15 AC_CACHE_CHECK([whether getdtablesize works],
16 [gl_cv_func_getdtablesize_works],
17 [dnl There are two concepts: the "maximum possible file descriptor value + 1"
18 dnl and the "maximum number of open file descriptors in a process".
19 dnl Per SUSv2 and POSIX, getdtablesize() should return the first one.
20 dnl On most platforms, the first and the second concept are the same.
21 dnl On OpenVMS, however, they are different and getdtablesize() returns
22 dnl the second one; thus the test below fails. But we don't care
23 dnl because there's no good way to write a replacement getdtablesize().
24 case "$host_os" in
25 vms*) gl_cv_func_getdtablesize_works="no (limitation)" ;;
26 *)
27 dnl Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft
28 dnl limit up to an unchangeable hard limit; all other platforms
29 dnl correctly require setrlimit before getdtablesize() can report
30 dnl a larger value.
31 AC_RUN_IFELSE([
32 AC_LANG_PROGRAM(
33 [[#include <unistd.h>]
34 GL_MDA_DEFINES
35 ],
36 [[int size = getdtablesize();
37 if (dup2 (0, getdtablesize()) != -1)
38 return 1;
39 if (size != getdtablesize())
40 return 2;
41 ]])],
42 [gl_cv_func_getdtablesize_works=yes],
43 [gl_cv_func_getdtablesize_works=no],
44 [case "$host_os" in
45 cygwin*) # on cygwin 1.5.25, getdtablesize() automatically grows
46 gl_cv_func_getdtablesize_works="guessing no" ;;
47 *) gl_cv_func_getdtablesize_works="guessing yes" ;;
48 esac
49 ])
50 ;;
51 esac
52 ])
53 case "$gl_cv_func_getdtablesize_works" in
54 *yes | "no (limitation)") ;;
55 *) REPLACE_GETDTABLESIZE=1 ;;
56 esac
57 else
58 HAVE_GETDTABLESIZE=0
59 fi
60])
61
62# Prerequisites of lib/getdtablesize.c.
63AC_DEFUN([gl_PREREQ_GETDTABLESIZE], [:])
diff --git a/gl/m4/gethostname.m4 b/gl/m4/gethostname.m4
index 7413f9e..63f5f63 100644
--- a/gl/m4/gethostname.m4
+++ b/gl/m4/gethostname.m4
@@ -1,5 +1,5 @@
1# gethostname.m4 serial 13 1# gethostname.m4 serial 15
2dnl Copyright (C) 2002, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2008-2023 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.
@@ -48,7 +48,7 @@ AC_DEFUN([gl_PREREQ_HOST_NAME_MAX], [
48 dnl - On most Unix systems, use MAXHOSTNAMELEN from <sys/param.h> instead. 48 dnl - On most Unix systems, use MAXHOSTNAMELEN from <sys/param.h> instead.
49 dnl - On Solaris, Cygwin, BeOS, use MAXHOSTNAMELEN from <netdb.h> instead. 49 dnl - On Solaris, Cygwin, BeOS, use MAXHOSTNAMELEN from <netdb.h> instead.
50 dnl - On mingw, use 256, because 50 dnl - On mingw, use 256, because
51 dnl <http://msdn.microsoft.com/en-us/library/ms738527.aspx> says: 51 dnl <https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-gethostname> says:
52 dnl "if a buffer of 256 bytes is passed in the name parameter and 52 dnl "if a buffer of 256 bytes is passed in the name parameter and
53 dnl the namelen parameter is set to 256, the buffer size will always 53 dnl the namelen parameter is set to 256, the buffer size will always
54 dnl be adequate." 54 dnl be adequate."
@@ -74,7 +74,7 @@ lucky
74 dnl mingw. 74 dnl mingw.
75 gl_cv_decl_HOST_NAME_MAX=256 75 gl_cv_decl_HOST_NAME_MAX=256
76 else 76 else
77 _AC_COMPUTE_INT([MAXHOSTNAMELEN], [gl_cv_decl_HOST_NAME_MAX], [ 77 AC_COMPUTE_INT([gl_cv_decl_HOST_NAME_MAX], [MAXHOSTNAMELEN], [
78#include <sys/types.h> 78#include <sys/types.h>
79#if HAVE_SYS_PARAM_H 79#if HAVE_SYS_PARAM_H
80# include <sys/param.h> 80# include <sys/param.h>
diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4
new file mode 100644
index 0000000..03569f0
--- /dev/null
+++ b/gl/m4/getline.m4
@@ -0,0 +1,109 @@
1# getline.m4 serial 30
2
3dnl Copyright (C) 1998-2003, 2005-2007, 2009-2023 Free Software Foundation,
4dnl Inc.
5dnl
6dnl This file is free software; the Free Software Foundation
7dnl gives unlimited permission to copy and/or distribute it,
8dnl with or without modifications, as long as this notice is preserved.
9
10AC_PREREQ([2.59])
11
12dnl See if there's a working, system-supplied version of the getline function.
13dnl We can't just do AC_REPLACE_FUNCS([getline]) because some systems
14dnl have a function by that name in -linet that doesn't have anything
15dnl to do with the function we need.
16AC_DEFUN([gl_FUNC_GETLINE],
17[
18 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
19 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
20
21 dnl Persuade glibc <stdio.h> to declare getline().
22 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
23
24 AC_CHECK_DECLS_ONCE([getline])
25
26 gl_getline_needs_run_time_check=no
27 AC_CHECK_FUNC([getline],
28 [dnl Found it in some library. Verify that it works.
29 gl_getline_needs_run_time_check=yes],
30 [am_cv_func_working_getline=no])
31 if test $gl_getline_needs_run_time_check = yes; then
32 AC_CACHE_CHECK([for working getline function],
33 [am_cv_func_working_getline],
34 [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
35 AC_RUN_IFELSE([AC_LANG_SOURCE([[
36# include <stdio.h>
37# include <stdlib.h>
38# include <string.h>
39 int main ()
40 {
41 FILE *in = fopen ("./conftest.data", "r");
42 if (!in)
43 return 1;
44 {
45 /* Test result for a NULL buffer and a zero size.
46 Based on a test program from Karl Heuer. */
47 char *line = NULL;
48 size_t siz = 0;
49 int len = getline (&line, &siz, in);
50 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
51 { free (line); fclose (in); return 2; }
52 free (line);
53 }
54 {
55 /* Test result for a NULL buffer and a non-zero size.
56 This crashes on FreeBSD 8.0. */
57 char *line = NULL;
58 size_t siz = (size_t)(~0) / 4;
59 if (getline (&line, &siz, in) == -1)
60 { fclose (in); return 3; }
61 free (line);
62 }
63 fclose (in);
64 return 0;
65 }
66 ]])],
67 [am_cv_func_working_getline=yes],
68 [am_cv_func_working_getline=no],
69 [dnl We're cross compiling.
70 dnl Guess it works on glibc2 systems and musl systems.
71 AC_EGREP_CPP([Lucky GNU user],
72 [
73#include <features.h>
74#ifdef __GNU_LIBRARY__
75 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
76 Lucky GNU user
77 #endif
78#endif
79 ],
80 [am_cv_func_working_getline="guessing yes"],
81 [case "$host_os" in
82 *-musl*) am_cv_func_working_getline="guessing yes" ;;
83 *) am_cv_func_working_getline="$gl_cross_guess_normal" ;;
84 esac
85 ])
86 ])
87 ])
88 fi
89
90 if test $ac_cv_have_decl_getline = no; then
91 HAVE_DECL_GETLINE=0
92 fi
93
94 case "$am_cv_func_working_getline" in
95 *yes) ;;
96 *)
97 dnl Set REPLACE_GETLINE always: Even if we have not found the broken
98 dnl getline function among $LIBS, it may exist in libinet and the
99 dnl executable may be linked with -linet.
100 REPLACE_GETLINE=1
101 ;;
102 esac
103])
104
105# Prerequisites of lib/getline.c.
106AC_DEFUN([gl_PREREQ_GETLINE],
107[
108 :
109])
diff --git a/gl/m4/getloadavg.m4 b/gl/m4/getloadavg.m4
index 611372a..79e420b 100644
--- a/gl/m4/getloadavg.m4
+++ b/gl/m4/getloadavg.m4
@@ -1,13 +1,13 @@
1# Check for getloadavg. 1# Check for getloadavg.
2 2
3# Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2013 Free Software 3# Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2023 Free Software
4# Foundation, Inc. 4# Foundation, Inc.
5 5
6# This file is free software; the Free Software Foundation 6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved. 8# with or without modifications, as long as this notice is preserved.
9 9
10#serial 6 10#serial 10
11 11
12# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. 12# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
13# New applications should use gl_GETLOADAVG instead. 13# New applications should use gl_GETLOADAVG instead.
@@ -22,7 +22,7 @@ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
22 22
23gl_save_LIBS=$LIBS 23gl_save_LIBS=$LIBS
24 24
25# getloadvg is present in libc on glibc >= 2.2, Mac OS X, FreeBSD >= 2.0, 25# getloadavg is present in libc on glibc >= 2.2, Mac OS X, FreeBSD >= 2.0,
26# NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7. 26# NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7.
27HAVE_GETLOADAVG=1 27HAVE_GETLOADAVG=1
28AC_CHECK_FUNC([getloadavg], [], 28AC_CHECK_FUNC([getloadavg], [],
@@ -45,7 +45,9 @@ AC_CHECK_FUNC([getloadavg], [],
45 # There is a commonly available library for RS/6000 AIX. 45 # There is a commonly available library for RS/6000 AIX.
46 # Since it is not a standard part of AIX, it might be installed locally. 46 # Since it is not a standard part of AIX, it might be installed locally.
47 gl_getloadavg_LIBS=$LIBS 47 gl_getloadavg_LIBS=$LIBS
48 LIBS="-L/usr/local/lib $LIBS" 48 if test $cross_compiling != yes; then
49 LIBS="-L/usr/local/lib $LIBS"
50 fi
49 AC_CHECK_LIB([getloadavg], [getloadavg], 51 AC_CHECK_LIB([getloadavg], [getloadavg],
50 [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes], 52 [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes],
51 [LIBS=$gl_getloadavg_LIBS]) 53 [LIBS=$gl_getloadavg_LIBS])
@@ -92,6 +94,9 @@ else
92fi 94fi
93AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0], 95AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
94 [[#if HAVE_SYS_LOADAVG_H 96 [[#if HAVE_SYS_LOADAVG_H
97 /* OpenIndiana has a bug: <sys/time.h> must be included before
98 <sys/loadavg.h>. */
99 # include <sys/time.h>
95 # include <sys/loadavg.h> 100 # include <sys/loadavg.h>
96 #endif 101 #endif
97 #include <stdlib.h>]]) 102 #include <stdlib.h>]])
@@ -105,7 +110,7 @@ AC_DEFUN([gl_PREREQ_GETLOADAVG],
105[ 110[
106# Figure out what our getloadavg.c needs. 111# Figure out what our getloadavg.c needs.
107 112
108AC_CHECK_HEADERS_ONCE([sys/param.h]) 113AC_CHECK_HEADERS_ONCE([sys/param.h unistd.h])
109 114
110# On HPUX9, an unprivileged user can get load averages this way. 115# On HPUX9, an unprivileged user can get load averages this way.
111if test $gl_func_getloadavg_done = no; then 116if test $gl_func_getloadavg_done = no; then
@@ -142,7 +147,7 @@ fi
142AC_CHECK_HEADERS([nlist.h], 147AC_CHECK_HEADERS([nlist.h],
143[AC_CHECK_MEMBERS([struct nlist.n_un.n_name], 148[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
144 [], [], 149 [], [],
145 [@%:@include <nlist.h>]) 150 [#include <nlist.h>])
146 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]], 151 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
147 [[struct nlist x; 152 [[struct nlist x;
148 #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME 153 #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
diff --git a/gl/m4/getopt.m4 b/gl/m4/getopt.m4
index 50f4509..7981a09 100644
--- a/gl/m4/getopt.m4
+++ b/gl/m4/getopt.m4
@@ -1,5 +1,5 @@
1# getopt.m4 serial 44 1# getopt.m4 serial 48
2dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2008-2023 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,8 @@ AC_DEFUN([gl_FUNC_GETOPT_POSIX],
21 REPLACE_GETOPT=1 21 REPLACE_GETOPT=1
22 fi 22 fi
23 ]) 23 ])
24 GL_GENERATE_GETOPT_H=false
25 GL_GENERATE_GETOPT_CDEFS_H=false
24 if test $REPLACE_GETOPT = 1; then 26 if test $REPLACE_GETOPT = 1; then
25 dnl Arrange for getopt.h to be created. 27 dnl Arrange for getopt.h to be created.
26 gl_GETOPT_SUBSTITUTE_HEADER 28 gl_GETOPT_SUBSTITUTE_HEADER
@@ -32,9 +34,16 @@ AC_DEFUN([gl_FUNC_GETOPT_POSIX],
32# getopt_long_only. 34# getopt_long_only.
33AC_DEFUN([gl_FUNC_GETOPT_GNU], 35AC_DEFUN([gl_FUNC_GETOPT_GNU],
34[ 36[
37 dnl Set the variable gl_getopt_required, so that all invocations of
38 dnl gl_GETOPT_CHECK_HEADERS in the scope of the current configure file
39 dnl will check for getopt with GNU extensions.
40 dnl This means that if one gnulib-tool invocation requests getopt-posix
41 dnl and another gnulib-tool invocation requests getopt-gnu, it is as if
42 dnl both had requested getopt-gnu.
35 m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU]) 43 m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU])
36 44
37 AC_REQUIRE([gl_FUNC_GETOPT_POSIX]) 45 dnl No need to invoke gl_FUNC_GETOPT_POSIX here; this is automatically
46 dnl done through the module dependency getopt-gnu -> getopt-posix.
38]) 47])
39 48
40# Determine whether to replace the entire getopt facility. 49# Determine whether to replace the entire getopt facility.
@@ -295,8 +304,10 @@ dnl is ambiguous with environment values that contain newlines.
295 ]])], 304 ]])],
296 [gl_cv_func_getopt_gnu=yes], 305 [gl_cv_func_getopt_gnu=yes],
297 [gl_cv_func_getopt_gnu=no], 306 [gl_cv_func_getopt_gnu=no],
298 [dnl Cross compiling. Assume the worst, even on glibc platforms. 307 [dnl Cross compiling.
299 gl_cv_func_getopt_gnu="guessing no" 308 dnl Assume the worst, even on glibc platforms.
309 dnl But obey --enable-cross-guesses.
310 gl_cv_func_getopt_gnu="$gl_cross_guess_normal"
300 ]) 311 ])
301 case $gl_had_POSIXLY_CORRECT in 312 case $gl_had_POSIXLY_CORRECT in
302 exported) ;; 313 exported) ;;
@@ -354,15 +365,17 @@ dnl is ambiguous with environment values that contain newlines.
354 365
355AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], 366AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
356[ 367[
357 GETOPT_H=getopt.h 368 AC_CHECK_HEADERS_ONCE([sys/cdefs.h])
369 if test $ac_cv_header_sys_cdefs_h = yes; then
370 HAVE_SYS_CDEFS_H=1
371 else
372 HAVE_SYS_CDEFS_H=0
373 fi
374 AC_SUBST([HAVE_SYS_CDEFS_H])
375
358 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]], 376 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
359 [Define to rpl_ if the getopt replacement functions and variables 377 [Define to rpl_ if the getopt replacement functions and variables
360 should be used.]) 378 should be used.])
361 AC_SUBST([GETOPT_H]) 379 GL_GENERATE_GETOPT_H=true
362]) 380 GL_GENERATE_GETOPT_CDEFS_H=true
363
364# Prerequisites of lib/getopt*.
365AC_DEFUN([gl_PREREQ_GETOPT],
366[
367 AC_CHECK_DECLS_ONCE([getenv])
368]) 381])
diff --git a/gl/m4/getprogname.m4 b/gl/m4/getprogname.m4
new file mode 100644
index 0000000..b67c527
--- /dev/null
+++ b/gl/m4/getprogname.m4
@@ -0,0 +1,43 @@
1# getprogname.m4 - check for getprogname or replacements for it
2
3# Copyright (C) 2016-2023 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
10AC_DEFUN([gl_FUNC_GETPROGNAME],
11[
12 AC_CHECK_FUNCS_ONCE([getprogname getexecname])
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 ac_found=0
15 AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
16 [#include <errno.h>])
17 AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
18 [#include <errno.h>])
19 AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
20
21 # Incur the cost of this test only if none of the above worked.
22 if test $ac_found = 0; then
23 # On OpenBSD 5.1, using the global __progname variable appears to be
24 # the only way to implement getprogname.
25 AC_CACHE_CHECK([whether __progname is defined in default libraries],
26 [gl_cv_var___progname],
27 [
28 gl_cv_var___progname=
29 AC_LINK_IFELSE(
30 [AC_LANG_PROGRAM(
31 [[extern char *__progname;]],
32 [[return *__progname;]]
33 )],
34 [gl_cv_var___progname=yes]
35 )
36 ]
37 )
38 if test "$gl_cv_var___progname" = yes; then
39 AC_DEFINE([HAVE_VAR___PROGNAME], 1,
40 [Define if you have a global __progname variable])
41 fi
42 fi
43])
diff --git a/gl/m4/gettext.m4 b/gl/m4/gettext.m4
deleted file mode 100644
index 8d1f066..0000000
--- a/gl/m4/gettext.m4
+++ /dev/null
@@ -1,401 +0,0 @@
1# gettext.m4 serial 66 (gettext-0.18.2)
2dnl Copyright (C) 1995-2013 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 Authors:
17dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
18dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006, 2008-2010.
19
20dnl Macro to add for using GNU gettext.
21
22dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
23dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
24dnl default (if it is not specified or empty) is 'no-libtool'.
25dnl INTLSYMBOL should be 'external' for packages with no intl directory,
26dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
27dnl If INTLSYMBOL is 'use-libtool', then a libtool library
28dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
29dnl depending on --{enable,disable}-{shared,static} and on the presence of
30dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
31dnl $(top_builddir)/intl/libintl.a will be created.
32dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
33dnl implementations (in libc or libintl) without the ngettext() function
34dnl will be ignored. If NEEDSYMBOL is specified and is
35dnl 'need-formatstring-macros', then GNU gettext implementations that don't
36dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
37dnl INTLDIR is used to find the intl libraries. If empty,
38dnl the value '$(top_builddir)/intl/' is used.
39dnl
40dnl The result of the configuration is one of three cases:
41dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
42dnl and used.
43dnl Catalog format: GNU --> install in $(datadir)
44dnl Catalog extension: .mo after installation, .gmo in source tree
45dnl 2) GNU gettext has been found in the system's C library.
46dnl Catalog format: GNU --> install in $(datadir)
47dnl Catalog extension: .mo after installation, .gmo in source tree
48dnl 3) No internationalization, always use English msgid.
49dnl Catalog format: none
50dnl Catalog extension: none
51dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
52dnl The use of .gmo is historical (it was needed to avoid overwriting the
53dnl GNU format catalogs when building on a platform with an X/Open gettext),
54dnl but we keep it in order not to force irrelevant filename changes on the
55dnl maintainers.
56dnl
57AC_DEFUN([AM_GNU_GETTEXT],
58[
59 dnl Argument checking.
60 ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
61 [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
62])])])])])
63 ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old],
64 [AC_DIAGNOSE([obsolete], [Use of AM_GNU_GETTEXT without [external] argument is deprecated.])])
65 ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
66 [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
67])])])])
68 define([gt_included_intl],
69 ifelse([$1], [external],
70 ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]),
71 [yes]))
72 define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], []))
73 gt_NEEDS_INIT
74 AM_GNU_GETTEXT_NEED([$2])
75
76 AC_REQUIRE([AM_PO_SUBDIRS])dnl
77 ifelse(gt_included_intl, yes, [
78 AC_REQUIRE([AM_INTL_SUBDIR])dnl
79 ])
80
81 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
82 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
83 AC_REQUIRE([AC_LIB_RPATH])
84
85 dnl Sometimes libintl requires libiconv, so first search for libiconv.
86 dnl Ideally we would do this search only after the
87 dnl if test "$USE_NLS" = "yes"; then
88 dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
89 dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
90 dnl the configure script would need to contain the same shell code
91 dnl again, outside any 'if'. There are two solutions:
92 dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
93 dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
94 dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
95 dnl documented, we avoid it.
96 ifelse(gt_included_intl, yes, , [
97 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
98 ])
99
100 dnl Sometimes, on Mac OS X, libintl requires linking with CoreFoundation.
101 gt_INTL_MACOSX
102
103 dnl Set USE_NLS.
104 AC_REQUIRE([AM_NLS])
105
106 ifelse(gt_included_intl, yes, [
107 BUILD_INCLUDED_LIBINTL=no
108 USE_INCLUDED_LIBINTL=no
109 ])
110 LIBINTL=
111 LTLIBINTL=
112 POSUB=
113
114 dnl Add a version number to the cache macros.
115 case " $gt_needs " in
116 *" need-formatstring-macros "*) gt_api_version=3 ;;
117 *" need-ngettext "*) gt_api_version=2 ;;
118 *) gt_api_version=1 ;;
119 esac
120 gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
121 gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
122
123 dnl If we use NLS figure out what method
124 if test "$USE_NLS" = "yes"; then
125 gt_use_preinstalled_gnugettext=no
126 ifelse(gt_included_intl, yes, [
127 AC_MSG_CHECKING([whether included gettext is requested])
128 AC_ARG_WITH([included-gettext],
129 [ --with-included-gettext use the GNU gettext library included here],
130 nls_cv_force_use_gnu_gettext=$withval,
131 nls_cv_force_use_gnu_gettext=no)
132 AC_MSG_RESULT([$nls_cv_force_use_gnu_gettext])
133
134 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
135 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
136 ])
137 dnl User does not insist on using GNU NLS library. Figure out what
138 dnl to use. If GNU gettext is available we use this. Else we have
139 dnl to fall back to GNU NLS library.
140
141 if test $gt_api_version -ge 3; then
142 gt_revision_test_code='
143#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
144#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
145#endif
146changequote(,)dnl
147typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
148changequote([,])dnl
149'
150 else
151 gt_revision_test_code=
152 fi
153 if test $gt_api_version -ge 2; then
154 gt_expression_test_code=' + * ngettext ("", "", 0)'
155 else
156 gt_expression_test_code=
157 fi
158
159 AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
160 [AC_LINK_IFELSE(
161 [AC_LANG_PROGRAM(
162 [[
163#include <libintl.h>
164$gt_revision_test_code
165extern int _nl_msg_cat_cntr;
166extern int *_nl_domain_bindings;
167 ]],
168 [[
169bindtextdomain ("", "");
170return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings
171 ]])],
172 [eval "$gt_func_gnugettext_libc=yes"],
173 [eval "$gt_func_gnugettext_libc=no"])])
174
175 if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
176 dnl Sometimes libintl requires libiconv, so first search for libiconv.
177 ifelse(gt_included_intl, yes, , [
178 AM_ICONV_LINK
179 ])
180 dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
181 dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
182 dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
183 dnl even if libiconv doesn't exist.
184 AC_LIB_LINKFLAGS_BODY([intl])
185 AC_CACHE_CHECK([for GNU gettext in libintl],
186 [$gt_func_gnugettext_libintl],
187 [gt_save_CPPFLAGS="$CPPFLAGS"
188 CPPFLAGS="$CPPFLAGS $INCINTL"
189 gt_save_LIBS="$LIBS"
190 LIBS="$LIBS $LIBINTL"
191 dnl Now see whether libintl exists and does not depend on libiconv.
192 AC_LINK_IFELSE(
193 [AC_LANG_PROGRAM(
194 [[
195#include <libintl.h>
196$gt_revision_test_code
197extern int _nl_msg_cat_cntr;
198extern
199#ifdef __cplusplus
200"C"
201#endif
202const char *_nl_expand_alias (const char *);
203 ]],
204 [[
205bindtextdomain ("", "");
206return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")
207 ]])],
208 [eval "$gt_func_gnugettext_libintl=yes"],
209 [eval "$gt_func_gnugettext_libintl=no"])
210 dnl Now see whether libintl exists and depends on libiconv.
211 if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
212 LIBS="$LIBS $LIBICONV"
213 AC_LINK_IFELSE(
214 [AC_LANG_PROGRAM(
215 [[
216#include <libintl.h>
217$gt_revision_test_code
218extern int _nl_msg_cat_cntr;
219extern
220#ifdef __cplusplus
221"C"
222#endif
223const char *_nl_expand_alias (const char *);
224 ]],
225 [[
226bindtextdomain ("", "");
227return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")
228 ]])],
229 [LIBINTL="$LIBINTL $LIBICONV"
230 LTLIBINTL="$LTLIBINTL $LTLIBICONV"
231 eval "$gt_func_gnugettext_libintl=yes"
232 ])
233 fi
234 CPPFLAGS="$gt_save_CPPFLAGS"
235 LIBS="$gt_save_LIBS"])
236 fi
237
238 dnl If an already present or preinstalled GNU gettext() is found,
239 dnl use it. But if this macro is used in GNU gettext, and GNU
240 dnl gettext is already preinstalled in libintl, we update this
241 dnl libintl. (Cf. the install rule in intl/Makefile.in.)
242 if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
243 || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
244 && test "$PACKAGE" != gettext-runtime \
245 && test "$PACKAGE" != gettext-tools; }; then
246 gt_use_preinstalled_gnugettext=yes
247 else
248 dnl Reset the values set by searching for libintl.
249 LIBINTL=
250 LTLIBINTL=
251 INCINTL=
252 fi
253
254 ifelse(gt_included_intl, yes, [
255 if test "$gt_use_preinstalled_gnugettext" != "yes"; then
256 dnl GNU gettext is not found in the C library.
257 dnl Fall back on included GNU gettext library.
258 nls_cv_use_gnu_gettext=yes
259 fi
260 fi
261
262 if test "$nls_cv_use_gnu_gettext" = "yes"; then
263 dnl Mark actions used to generate GNU NLS library.
264 BUILD_INCLUDED_LIBINTL=yes
265 USE_INCLUDED_LIBINTL=yes
266 LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD"
267 LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD"
268 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
269 fi
270
271 CATOBJEXT=
272 if test "$gt_use_preinstalled_gnugettext" = "yes" \
273 || test "$nls_cv_use_gnu_gettext" = "yes"; then
274 dnl Mark actions to use GNU gettext tools.
275 CATOBJEXT=.gmo
276 fi
277 ])
278
279 if test -n "$INTL_MACOSX_LIBS"; then
280 if test "$gt_use_preinstalled_gnugettext" = "yes" \
281 || test "$nls_cv_use_gnu_gettext" = "yes"; then
282 dnl Some extra flags are needed during linking.
283 LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
284 LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
285 fi
286 fi
287
288 if test "$gt_use_preinstalled_gnugettext" = "yes" \
289 || test "$nls_cv_use_gnu_gettext" = "yes"; then
290 AC_DEFINE([ENABLE_NLS], [1],
291 [Define to 1 if translation of program messages to the user's native language
292 is requested.])
293 else
294 USE_NLS=no
295 fi
296 fi
297
298 AC_MSG_CHECKING([whether to use NLS])
299 AC_MSG_RESULT([$USE_NLS])
300 if test "$USE_NLS" = "yes"; then
301 AC_MSG_CHECKING([where the gettext function comes from])
302 if test "$gt_use_preinstalled_gnugettext" = "yes"; then
303 if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
304 gt_source="external libintl"
305 else
306 gt_source="libc"
307 fi
308 else
309 gt_source="included intl directory"
310 fi
311 AC_MSG_RESULT([$gt_source])
312 fi
313
314 if test "$USE_NLS" = "yes"; then
315
316 if test "$gt_use_preinstalled_gnugettext" = "yes"; then
317 if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
318 AC_MSG_CHECKING([how to link with libintl])
319 AC_MSG_RESULT([$LIBINTL])
320 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
321 fi
322
323 dnl For backward compatibility. Some packages may be using this.
324 AC_DEFINE([HAVE_GETTEXT], [1],
325 [Define if the GNU gettext() function is already present or preinstalled.])
326 AC_DEFINE([HAVE_DCGETTEXT], [1],
327 [Define if the GNU dcgettext() function is already present or preinstalled.])
328 fi
329
330 dnl We need to process the po/ directory.
331 POSUB=po
332 fi
333
334 ifelse(gt_included_intl, yes, [
335 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
336 dnl to 'yes' because some of the testsuite requires it.
337 if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
338 BUILD_INCLUDED_LIBINTL=yes
339 fi
340
341 dnl Make all variables we use known to autoconf.
342 AC_SUBST([BUILD_INCLUDED_LIBINTL])
343 AC_SUBST([USE_INCLUDED_LIBINTL])
344 AC_SUBST([CATOBJEXT])
345
346 dnl For backward compatibility. Some configure.ins may be using this.
347 nls_cv_header_intl=
348 nls_cv_header_libgt=
349
350 dnl For backward compatibility. Some Makefiles may be using this.
351 DATADIRNAME=share
352 AC_SUBST([DATADIRNAME])
353
354 dnl For backward compatibility. Some Makefiles may be using this.
355 INSTOBJEXT=.mo
356 AC_SUBST([INSTOBJEXT])
357
358 dnl For backward compatibility. Some Makefiles may be using this.
359 GENCAT=gencat
360 AC_SUBST([GENCAT])
361
362 dnl For backward compatibility. Some Makefiles may be using this.
363 INTLOBJS=
364 if test "$USE_INCLUDED_LIBINTL" = yes; then
365 INTLOBJS="\$(GETTOBJS)"
366 fi
367 AC_SUBST([INTLOBJS])
368
369 dnl Enable libtool support if the surrounding package wishes it.
370 INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
371 AC_SUBST([INTL_LIBTOOL_SUFFIX_PREFIX])
372 ])
373
374 dnl For backward compatibility. Some Makefiles may be using this.
375 INTLLIBS="$LIBINTL"
376 AC_SUBST([INTLLIBS])
377
378 dnl Make all documented variables known to autoconf.
379 AC_SUBST([LIBINTL])
380 AC_SUBST([LTLIBINTL])
381 AC_SUBST([POSUB])
382])
383
384
385dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
386m4_define([gt_NEEDS_INIT],
387[
388 m4_divert_text([DEFAULTS], [gt_needs=])
389 m4_define([gt_NEEDS_INIT], [])
390])
391
392
393dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
394AC_DEFUN([AM_GNU_GETTEXT_NEED],
395[
396 m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
397])
398
399
400dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
401AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
diff --git a/gl/m4/gl-openssl.m4 b/gl/m4/gl-openssl.m4
new file mode 100644
index 0000000..7eab4e1
--- /dev/null
+++ b/gl/m4/gl-openssl.m4
@@ -0,0 +1,76 @@
1# gl-openssl.m4 serial 6
2dnl Copyright (C) 2013-2023 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_SET_CRYPTO_CHECK_DEFAULT],
8[
9 m4_define([gl_CRYPTO_CHECK_DEFAULT], [$1])
10])
11gl_SET_CRYPTO_CHECK_DEFAULT([no])
12
13AC_DEFUN([gl_CRYPTO_CHECK],
14[
15 dnl gnulib users set this before gl_INIT with gl_SET_CRYPTO_CHECK_DEFAULT()
16 m4_divert_once([DEFAULTS], [with_openssl_default='gl_CRYPTO_CHECK_DEFAULT'])
17
18 dnl Only clear once, so crypto routines can be checked for individually
19 m4_divert_once([DEFAULTS], [LIB_CRYPTO=])
20
21 AC_ARG_WITH([openssl],
22 [[ --with-openssl[=ARG] use libcrypto hash routines for the hash functions
23 MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512.
24 Valid ARGs are:
25 'yes',
26 'no',
27 'auto' => use if any version available,
28 'auto-gpl-compat' => use if GPL compatible version
29 available,
30 'optional' => use if available
31 and warn if not available;
32 Default is ']gl_CRYPTO_CHECK_DEFAULT['.]m4_ifdef([gl_AF_ALG], [
33 Note also --with-linux-crypto, which will enable the
34 use of Linux kernel crypto routines (if available),
35 which has precedence for files.])],
36 [],
37 [with_openssl=$with_openssl_default])
38
39 AC_SUBST([LIB_CRYPTO])
40 if test "x$with_openssl" != xno; then
41 if test "x$with_openssl" = xauto-gpl-compat; then
42 AC_CACHE_CHECK([whether openssl is GPL compatible],
43 [gl_cv_openssl_gpl_compat],
44 [AC_COMPILE_IFELSE(
45 [AC_LANG_PROGRAM([[
46 #include <openssl/opensslv.h>
47 #if OPENSSL_VERSION_MAJOR < 3
48 #error "openssl >= version 3 not found"
49 #endif
50 ]])],
51 [gl_cv_openssl_gpl_compat=yes],
52 [gl_cv_openssl_gpl_compat=no])])
53 fi
54 if test "x$with_openssl" != xauto-gpl-compat ||
55 test "x$gl_cv_openssl_gpl_compat" = xyes; then
56 AC_CHECK_LIB([crypto], [$1],
57 [AC_CHECK_HEADERS(
58 m4_if([$1], [MD5], [openssl/md5.h], [openssl/sha.h]),
59 [LIB_CRYPTO=-lcrypto
60 AC_DEFINE([HAVE_OPENSSL_$1], [1],
61 [Define to 1 if libcrypto is used for $1.])])])
62 fi
63 if test "x$LIB_CRYPTO" = x; then
64 message='openssl development library not found for $1.
65 If you want to install it, first find the pre-built package name:
66 - On Debian and Debian-based systems: libssl-dev,
67 - On Red Hat distributions: openssl-devel.
68 - Other: https://repology.org/project/openssl/versions'
69 if test "x$with_openssl" = xyes; then
70 AC_MSG_ERROR([$message])
71 elif test "x$with_openssl" = xoptional; then
72 AC_MSG_WARN([$message])
73 fi
74 fi
75 fi
76])
diff --git a/gl/m4/glibc2.m4 b/gl/m4/glibc2.m4
deleted file mode 100644
index 0e50682..0000000
--- a/gl/m4/glibc2.m4
+++ /dev/null
@@ -1,31 +0,0 @@
1# glibc2.m4 serial 3
2dnl Copyright (C) 2000-2002, 2004, 2008, 2010-2013 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8# Test for the GNU C Library, version 2.0 or newer.
9# From Bruno Haible.
10
11AC_DEFUN([gt_GLIBC2],
12 [
13 AC_CACHE_CHECK([whether we are using the GNU C Library 2 or newer],
14 [ac_cv_gnu_library_2],
15 [AC_EGREP_CPP([Lucky GNU user],
16 [
17#include <features.h>
18#ifdef __GNU_LIBRARY__
19 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
20 Lucky GNU user
21 #endif
22#endif
23 ],
24 [ac_cv_gnu_library_2=yes],
25 [ac_cv_gnu_library_2=no])
26 ]
27 )
28 AC_SUBST([GLIBC2])
29 GLIBC2="$ac_cv_gnu_library_2"
30 ]
31)
diff --git a/gl/m4/glibc21.m4 b/gl/m4/glibc21.m4
deleted file mode 100644
index 613fb2a..0000000
--- a/gl/m4/glibc21.m4
+++ /dev/null
@@ -1,34 +0,0 @@
1# glibc21.m4 serial 5
2dnl Copyright (C) 2000-2002, 2004, 2008, 2010-2013 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8# Test for the GNU C Library, version 2.1 or newer, or uClibc.
9# From Bruno Haible.
10
11AC_DEFUN([gl_GLIBC21],
12 [
13 AC_CACHE_CHECK([whether we are using the GNU C Library >= 2.1 or uClibc],
14 [ac_cv_gnu_library_2_1],
15 [AC_EGREP_CPP([Lucky],
16 [
17#include <features.h>
18#ifdef __GNU_LIBRARY__
19 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
20 Lucky GNU user
21 #endif
22#endif
23#ifdef __UCLIBC__
24 Lucky user
25#endif
26 ],
27 [ac_cv_gnu_library_2_1=yes],
28 [ac_cv_gnu_library_2_1=no])
29 ]
30 )
31 AC_SUBST([GLIBC21])
32 GLIBC21="$ac_cv_gnu_library_2_1"
33 ]
34)
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 90ad4aa..267f069 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -1,8 +1,8 @@
1# Copyright (C) 2002-2013 Free Software Foundation, Inc. 1# Copyright (C) 2002-2023 Free Software Foundation, Inc.
2# 2#
3# This file is free software; you can redistribute it and/or modify 3# This file is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by 4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or 5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version. 6# (at your option) any later version.
7# 7#
8# This file is distributed in the hope that it will be useful, 8# This file is distributed in the hope that it will be useful,
@@ -11,7 +11,7 @@
11# GNU General Public License for more details. 11# GNU General Public License for more details.
12# 12#
13# You should have received a copy of the GNU General Public License 13# You should have received a copy of the GNU General Public License
14# along with this file. If not, see <http://www.gnu.org/licenses/>. 14# along with this file. If not, see <https://www.gnu.org/licenses/>.
15# 15#
16# As a special exception to the GNU General Public License, 16# As a special exception to the GNU General Public License,
17# this file may be distributed as part of a program that 17# this file may be distributed as part of a program that
@@ -27,13 +27,45 @@
27 27
28 28
29# Specification in the form of a command-line invocation: 29# Specification in the form of a command-line invocation:
30# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname environ floorf fsusage getaddrinfo gethostname getloadavg getopt-gnu gettext idpriv-droptemp mountlist regex setenv strcase strcasestr strsep timegm unsetenv vasprintf vsnprintf 30# gnulib-tool --import \
31# --lib=libgnu \
32# --source-base=gl \
33# --m4-base=gl/m4 \
34# --doc-base=doc \
35# --tests-base=tests \
36# --aux-dir=build-aux \
37# --no-conditional-dependencies \
38# --no-libtool \
39# --macro-prefix=gl \
40# --no-vc-files \
41# base64 \
42# crypto/sha256 \
43# dirname \
44# environ \
45# floorf \
46# fsusage \
47# getaddrinfo \
48# gethostname \
49# getloadavg \
50# getopt-gnu \
51# gettext-h \
52# idpriv-droptemp \
53# mountlist \
54# regex \
55# setenv \
56# strcase \
57# strcasestr \
58# strsep \
59# timegm \
60# unsetenv \
61# vasprintf \
62# vsnprintf
31 63
32# Specification in the form of a few gnulib-tool.m4 macro invocations: 64# Specification in the form of a few gnulib-tool.m4 macro invocations:
33gl_LOCAL_DIR([]) 65gl_LOCAL_DIR([])
34gl_MODULES([ 66gl_MODULES([
35 base64 67 base64
36 crypto/sha1 68 crypto/sha256
37 dirname 69 dirname
38 environ 70 environ
39 floorf 71 floorf
@@ -42,7 +74,7 @@ gl_MODULES([
42 gethostname 74 gethostname
43 getloadavg 75 getloadavg
44 getopt-gnu 76 getopt-gnu
45 gettext 77 gettext-h
46 idpriv-droptemp 78 idpriv-droptemp
47 mountlist 79 mountlist
48 regex 80 regex
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index 0ae5a9e..facc340 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,25 +1,59 @@
1# gnulib-common.m4 serial 33 1# gnulib-common.m4 serial 75a
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2023 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_PREREQ([2.62])
8
7# gl_COMMON 9# gl_COMMON
8# is expanded unconditionally through gnulib-tool magic. 10# is expanded unconditionally through gnulib-tool magic.
9AC_DEFUN([gl_COMMON], [ 11AC_DEFUN([gl_COMMON], [
10 dnl Use AC_REQUIRE here, so that the code is expanded once only. 12 dnl Use AC_REQUIRE here, so that the code is expanded once only.
11 AC_REQUIRE([gl_00GNULIB]) 13 AC_REQUIRE([gl_00GNULIB])
12 AC_REQUIRE([gl_COMMON_BODY]) 14 AC_REQUIRE([gl_COMMON_BODY])
15 AC_REQUIRE([gl_ZZGNULIB])
13]) 16])
14AC_DEFUN([gl_COMMON_BODY], [ 17AC_DEFUN([gl_COMMON_BODY], [
18 AH_VERBATIM([_GL_GNUC_PREREQ],
19[/* True if the compiler says it groks GNU C version MAJOR.MINOR. */
20#if defined __GNUC__ && defined __GNUC_MINOR__
21# define _GL_GNUC_PREREQ(major, minor) \
22 ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
23#else
24# define _GL_GNUC_PREREQ(major, minor) 0
25#endif
26])
15 AH_VERBATIM([_Noreturn], 27 AH_VERBATIM([_Noreturn],
16[/* The _Noreturn keyword of C11. */ 28[/* The _Noreturn keyword of C11. */
17#if ! (defined _Noreturn \ 29#ifndef _Noreturn
18 || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) 30# if (defined __cplusplus \
19# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ 31 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
20 || 0x5110 <= __SUNPRO_C) 32 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
33 && 0)
34 /* [[noreturn]] is not practically usable, because with it the syntax
35 extern _Noreturn void func (...);
36 would not be valid; such a declaration would only be valid with 'extern'
37 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
38 AIX system header files and several gnulib header files use precisely
39 this syntax with 'extern'. */
40# define _Noreturn [[noreturn]]
41# elif (defined __clang__ && __clang_major__ < 16 \
42 && defined _GL_WORK_AROUND_LLVM_BUG_59792)
43 /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
44 that rare LLVM bug, though you may get many false-alarm warnings. */
45# define _Noreturn
46# elif ((!defined __cplusplus || defined __clang__) \
47 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
48 || (!defined __STRICT_ANSI__ \
49 && (_GL_GNUC_PREREQ (4, 7) \
50 || (defined __apple_build_version__ \
51 ? 6000000 <= __apple_build_version__ \
52 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
53 /* _Noreturn works as-is. */
54# elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
21# define _Noreturn __attribute__ ((__noreturn__)) 55# define _Noreturn __attribute__ ((__noreturn__))
22# elif defined _MSC_VER && 1200 <= _MSC_VER 56# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
23# define _Noreturn __declspec (noreturn) 57# define _Noreturn __declspec (noreturn)
24# else 58# else
25# define _Noreturn 59# define _Noreturn
@@ -36,33 +70,519 @@ AC_DEFUN([gl_COMMON_BODY], [
36#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__ 70#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
37# define __GNUC_STDC_INLINE__ 1 71# define __GNUC_STDC_INLINE__ 1
38#endif]) 72#endif])
39 AH_VERBATIM([unused_parameter], 73 AH_VERBATIM([attribute],
40[/* Define as a marker that can be attached to declarations that might not 74[/* Attributes. */
41 be used. This helps to reduce warnings, such as from 75#if (defined __has_attribute \
42 GCC -Wunused-parameter. */ 76 && (!defined __clang_minor__ \
43#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 77 || (defined __apple_build_version__ \
44# define _GL_UNUSED __attribute__ ((__unused__)) 78 ? 6000000 <= __apple_build_version__ \
79 : 3 < __clang_major__ + (5 <= __clang_minor__))))
80# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
45#else 81#else
46# define _GL_UNUSED 82# define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
83# define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
84# define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
85# define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
86# define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
87# define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
88# define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
89# define _GL_ATTR_diagnose_if 0
90# define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
91# define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
92# define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
93# define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
94# define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
95# define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
96# ifdef _ICC
97# define _GL_ATTR_may_alias 0
98# else
99# define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
100# endif
101# define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
102# define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
103# define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
104# define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
105# define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
106# define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
107# define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
108# define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
109# define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
110# define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
47#endif 111#endif
48/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
49 is a misnomer outside of parameter lists. */
50#define _UNUSED_PARAMETER_ _GL_UNUSED
51 112
52/* The __pure__ attribute was added in gcc 2.96. */ 113/* Disable GCC -Wpedantic if using __has_c_attribute and this is not C23+. */
53#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 114#if (defined __has_c_attribute && _GL_GNUC_PREREQ (4, 6) \
54# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 115 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710)
55#else 116# pragma GCC diagnostic ignored "-Wpedantic"
56# define _GL_ATTRIBUTE_PURE /* empty */
57#endif 117#endif
58 118
59/* The __const__ attribute was added in gcc 2.95. */ 119]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
60#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 120[
61# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) 121/* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
62#else 122 is the size of the returned memory block.
63# define _GL_ATTRIBUTE_CONST /* empty */ 123 _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
124 by the Nth argument of the function is the size of the returned memory block.
125 */
126/* Applies to: function, pointer to function, function types. */
127#ifndef _GL_ATTRIBUTE_ALLOC_SIZE
128# if _GL_HAS_ATTRIBUTE (alloc_size)
129# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
130# else
131# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
132# endif
133#endif
134
135/* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
136 function and report an error if it cannot do so. */
137/* Applies to: function. */
138#ifndef _GL_ATTRIBUTE_ALWAYS_INLINE
139# if _GL_HAS_ATTRIBUTE (always_inline)
140# define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
141# else
142# define _GL_ATTRIBUTE_ALWAYS_INLINE
143# endif
144#endif
145
146/* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
147 in stack traces when debugging. The compiler should omit the function from
148 stack traces. */
149/* Applies to: function. */
150#ifndef _GL_ATTRIBUTE_ARTIFICIAL
151# if _GL_HAS_ATTRIBUTE (artificial)
152# define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
153# else
154# define _GL_ATTRIBUTE_ARTIFICIAL
155# endif
156#endif
157
158/* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
159/* Applies to: functions. */
160/* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
161 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
162 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
163#ifndef _GL_ATTRIBUTE_COLD
164# if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
165# ifndef __SUNPRO_C
166# define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
167# else
168# define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
169# endif
170# else
171# define _GL_ATTRIBUTE_COLD
172# endif
173#endif
174
175/* _GL_ATTRIBUTE_CONST declares that it is OK for a compiler to omit duplicate
176 calls to the function with the same arguments.
177 This attribute is safe for a function that neither depends on nor affects
178 observable state, and always returns exactly once - e.g., does not loop
179 forever, and does not call longjmp.
180 (This attribute is stricter than _GL_ATTRIBUTE_PURE.) */
181/* Applies to: functions. */
182#ifndef _GL_ATTRIBUTE_CONST
183# if _GL_HAS_ATTRIBUTE (const)
184# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
185# else
186# define _GL_ATTRIBUTE_CONST
187# endif
188#endif
189
190/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
191 that can be freed by passing them as the Ith argument to the
192 function F.
193 _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
194 can be freed via 'free'; it can be used only after declaring 'free'. */
195/* Applies to: functions. Cannot be used on inline functions. */
196#ifndef _GL_ATTRIBUTE_DEALLOC
197# if _GL_GNUC_PREREQ (11, 0)
198# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
199# else
200# define _GL_ATTRIBUTE_DEALLOC(f, i)
201# endif
202#endif
203/* If gnulib's <string.h> or <wchar.h> has already defined this macro, continue
204 to use this earlier definition, since <stdlib.h> may not have been included
205 yet. */
206#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
207# if defined __cplusplus && defined __GNUC__ && !defined __clang__
208/* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
209# define _GL_ATTRIBUTE_DEALLOC_FREE \
210 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
211# else
212# define _GL_ATTRIBUTE_DEALLOC_FREE \
213 _GL_ATTRIBUTE_DEALLOC (free, 1)
214# endif
215#endif
216
217/* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
218 The compiler may warn if the entity is used. */
219/* Applies to:
220 - function, variable,
221 - struct, union, struct/union member,
222 - enumeration, enumeration item,
223 - typedef,
224 in C++ also: namespace, class, template specialization. */
225#ifndef _GL_ATTRIBUTE_DEPRECATED
226# ifdef __has_c_attribute
227# if __has_c_attribute (__deprecated__)
228# define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
229# endif
230# endif
231# if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated)
232# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
233# endif
234# ifndef _GL_ATTRIBUTE_DEPRECATED
235# define _GL_ATTRIBUTE_DEPRECATED
236# endif
237#endif
238
239/* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
240 the function call is not optimized away.
241 _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
242 the function call is not optimized away. */
243/* Applies to: functions. */
244#if !(defined _GL_ATTRIBUTE_ERROR && defined _GL_ATTRIBUTE_WARNING)
245# if _GL_HAS_ATTRIBUTE (error)
246# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
247# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
248# elif _GL_HAS_ATTRIBUTE (diagnose_if)
249# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
250# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
251# else
252# define _GL_ATTRIBUTE_ERROR(msg)
253# define _GL_ATTRIBUTE_WARNING(msg)
254# endif
255#endif
256
257/* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
258 visible to debuggers etc., even with '-fwhole-program'. */
259/* Applies to: functions, variables. */
260#ifndef _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
261# if _GL_HAS_ATTRIBUTE (externally_visible)
262# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
263# else
264# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
265# endif
266#endif
267
268/* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
269 the control flow falls through to the immediately following 'case' or
270 'default' label. The compiler should not warn in this case. */
271/* Applies to: Empty statement (;), inside a 'switch' statement. */
272/* Always expands to something. */
273#ifndef _GL_ATTRIBUTE_FALLTHROUGH
274# ifdef __has_c_attribute
275# if __has_c_attribute (__fallthrough__)
276# define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
277# endif
278# endif
279# if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
280# define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
281# endif
282# ifndef _GL_ATTRIBUTE_FALLTHROUGH
283# define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
284# endif
285#endif
286
287/* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
288 declares that the STRING-INDEXth function argument is a format string of
289 style ARCHETYPE, which is one of:
290 printf, gnu_printf
291 scanf, gnu_scanf,
292 strftime, gnu_strftime,
293 strfmon,
294 or the same thing prefixed and suffixed with '__'.
295 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
296 are suitable for the format string. */
297/* Applies to: functions. */
298#ifndef _GL_ATTRIBUTE_FORMAT
299# if _GL_HAS_ATTRIBUTE (format)
300# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
301# else
302# define _GL_ATTRIBUTE_FORMAT(spec)
303# endif
304#endif
305
306/* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
307 compilation unit, it executes code from that unit only by return or by
308 exception handling. This declaration lets the compiler optimize that unit
309 more aggressively. */
310/* Applies to: functions. */
311#ifndef _GL_ATTRIBUTE_LEAF
312# if _GL_HAS_ATTRIBUTE (leaf)
313# define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
314# else
315# define _GL_ATTRIBUTE_LEAF
316# endif
317#endif
318
319/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
320 allocated memory. */
321/* Applies to: functions. */
322#ifndef _GL_ATTRIBUTE_MALLOC
323# if _GL_HAS_ATTRIBUTE (malloc)
324# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
325# else
326# define _GL_ATTRIBUTE_MALLOC
327# endif
328#endif
329
330/* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
331 same storage as pointers to other types. Thus this declaration disables
332 strict aliasing optimization. */
333/* Applies to: types. */
334/* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
335#ifndef _GL_ATTRIBUTE_MAY_ALIAS
336# if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
337# define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
338# else
339# define _GL_ATTRIBUTE_MAY_ALIAS
340# endif
341#endif
342
343/* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
344 the entity is not used. The compiler should not warn if the entity is not
345 used. */
346/* Applies to:
347 - function, variable,
348 - struct, union, struct/union member,
349 - enumeration, enumeration item,
350 - typedef,
351 in C++ also: class. */
352/* In C++ and C23, this is spelled [[__maybe_unused__]].
353 GCC's syntax is __attribute__ ((__unused__)).
354 clang supports both syntaxes. */
355#ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
356# ifdef __has_c_attribute
357# if __has_c_attribute (__maybe_unused__)
358# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
359# endif
360# endif
361# ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
362# define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
363# endif
364#endif
365/* Alternative spelling of this macro, for convenience and for
366 compatibility with glibc/include/libc-symbols.h. */
367#define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
368/* Earlier spellings of this macro. */
369#define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
370
371/* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
372 discard the return value. The compiler may warn if the caller does not use
373 the return value, unless the caller uses something like ignore_value. */
374/* Applies to: function, enumeration, class. */
375#ifndef _GL_ATTRIBUTE_NODISCARD
376# ifdef __has_c_attribute
377# if __has_c_attribute (__nodiscard__)
378# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
379# endif
380# endif
381# if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
382# define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
383# endif
384# ifndef _GL_ATTRIBUTE_NODISCARD
385# define _GL_ATTRIBUTE_NODISCARD
386# endif
387#endif
388
389/* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
390 function. */
391/* Applies to: functions. */
392#ifndef _GL_ATTRIBUTE_NOINLINE
393# if _GL_HAS_ATTRIBUTE (noinline)
394# define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
395# else
396# define _GL_ATTRIBUTE_NOINLINE
397# endif
398#endif
399
400/* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
401 must not be NULL.
402 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
403 null. */
404/* Applies to: functions. */
405#ifndef _GL_ATTRIBUTE_NONNULL
406# if _GL_HAS_ATTRIBUTE (nonnull)
407# define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
408# else
409# define _GL_ATTRIBUTE_NONNULL(args)
410# endif
411#endif
412
413/* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
414 not meant to be NUL-terminated. */
415/* Applies to: struct/union members and variables that are arrays of element
416 type '[[un]signed] char'. */
417#ifndef _GL_ATTRIBUTE_NONSTRING
418# if _GL_HAS_ATTRIBUTE (nonstring)
419# define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
420# else
421# define _GL_ATTRIBUTE_NONSTRING
422# endif
423#endif
424
425/* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
426
427/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
428 */
429/* Applies to: functions. */
430#ifndef _GL_ATTRIBUTE_NOTHROW
431# if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
432# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
433# else
434# define _GL_ATTRIBUTE_NOTHROW
435# endif
436#endif
437
438/* _GL_ATTRIBUTE_PACKED declares:
439 For struct members: The member has the smallest possible alignment.
440 For struct, union, class: All members have the smallest possible alignment,
441 minimizing the memory required. */
442/* Applies to: struct members, struct, union,
443 in C++ also: class. */
444#ifndef _GL_ATTRIBUTE_PACKED
445# if _GL_HAS_ATTRIBUTE (packed)
446# define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
447# else
448# define _GL_ATTRIBUTE_PACKED
449# endif
450#endif
451
452/* _GL_ATTRIBUTE_PURE declares that It is OK for a compiler to omit duplicate
453 calls to the function with the same arguments if observable state is not
454 changed between calls.
455 This attribute is safe for a function that does not affect
456 observable state, and always returns exactly once.
457 (This attribute is looser than _GL_ATTRIBUTE_CONST.) */
458/* Applies to: functions. */
459#ifndef _GL_ATTRIBUTE_PURE
460# if _GL_HAS_ATTRIBUTE (pure)
461# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
462# else
463# define _GL_ATTRIBUTE_PURE
464# endif
465#endif
466
467/* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
468 a non-NULL pointer. */
469/* Applies to: functions. */
470#ifndef _GL_ATTRIBUTE_RETURNS_NONNULL
471# if _GL_HAS_ATTRIBUTE (returns_nonnull)
472# define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
473# else
474# define _GL_ATTRIBUTE_RETURNS_NONNULL
475# endif
476#endif
477
478/* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
479 trailing NULL argument.
480 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
481 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
482/* Applies to: functions. */
483#ifndef _GL_ATTRIBUTE_SENTINEL
484# if _GL_HAS_ATTRIBUTE (sentinel)
485# define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
486# else
487# define _GL_ATTRIBUTE_SENTINEL(pos)
488# endif
489#endif
490
491/* A helper macro. Don't use it directly. */
492#ifndef _GL_ATTRIBUTE_UNUSED
493# if _GL_HAS_ATTRIBUTE (unused)
494# define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
495# else
496# define _GL_ATTRIBUTE_UNUSED
497# endif
498#endif
499
500]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
501[
502/* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
503 immediately preceding label is not used. The compiler should not warn
504 if the label is not used. */
505/* Applies to: label (both in C and C++). */
506/* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
507 syntax. But clang does. */
508#ifndef _GL_UNUSED_LABEL
509# if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
510# define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
511# else
512# define _GL_UNUSED_LABEL
513# endif
64#endif 514#endif
65]) 515])
516 AH_VERBATIM([async_safe],
517[/* The _GL_ASYNC_SAFE marker should be attached to functions that are
518 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
519 invoked from such signal handlers. Such functions have some restrictions:
520 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
521 or should be listed as async-signal-safe in POSIX
522 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
523 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
524 particular, are NOT async-signal-safe.
525 * All memory locations (variables and struct fields) that these functions
526 access must be marked 'volatile'. This holds for both read and write
527 accesses. Otherwise the compiler might optimize away stores to and
528 reads from such locations that occur in the program, depending on its
529 data flow analysis. For example, when the program contains a loop
530 that is intended to inspect a variable set from within a signal handler
531 while (!signal_occurred)
532 ;
533 the compiler is allowed to transform this into an endless loop if the
534 variable 'signal_occurred' is not declared 'volatile'.
535 Additionally, recall that:
536 * A signal handler should not modify errno (except if it is a handler
537 for a fatal signal and ends by raising the same signal again, thus
538 provoking the termination of the process). If it invokes a function
539 that may clobber errno, it needs to save and restore the value of
540 errno. */
541#define _GL_ASYNC_SAFE
542])
543 AH_VERBATIM([micro_optimizations],
544[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
545 n1 and n2 are expressions without side effects, that evaluate to real
546 numbers (excluding NaN).
547 It returns
548 1 if n1 > n2
549 0 if n1 == n2
550 -1 if n1 < n2
551 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
552 jump with nearly all GCC versions up to GCC 10.
553 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
554 GCC versions up to GCC 9.
555 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
556 avoids conditional jumps in all GCC versions >= 3.4. */
557#define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
558])
559 dnl Hint which direction to take regarding cross-compilation guesses:
560 dnl When a user installs a program on a platform they are not intimately
561 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
562 dnl choice. It implements the "If we don't know, assume the worst" principle.
563 dnl However, when an operating system developer (on a platform which is not
564 dnl yet known to gnulib) builds packages for their platform, they want to
565 dnl expose, not hide, possible platform bugs; in this case,
566 dnl --enable-cross-guesses=risky is the appropriate choice.
567 dnl Sets the variables
568 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
569 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
570 AC_ARG_ENABLE([cross-guesses],
571 [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
572 [specify policy for cross-compilation guesses])],
573 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
574 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
575 enableval=conservative
576 fi
577 gl_cross_guesses="$enableval"],
578 [gl_cross_guesses=conservative])
579 if test $gl_cross_guesses = risky; then
580 gl_cross_guess_normal="guessing yes"
581 gl_cross_guess_inverted="guessing no"
582 else
583 gl_cross_guess_normal="guessing no"
584 gl_cross_guess_inverted="guessing yes"
585 fi
66 dnl Preparation for running test programs: 586 dnl Preparation for running test programs:
67 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not 587 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
68 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics 588 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
@@ -71,6 +591,16 @@ AC_DEFUN([gl_COMMON_BODY], [
71 export LIBC_FATAL_STDERR_ 591 export LIBC_FATAL_STDERR_
72]) 592])
73 593
594# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
595# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
596# initializes the shell variable that indicates the presence of the given module
597# as a C preprocessor expression.
598AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
599[
600 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
601 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
602])
603
74# gl_MODULE_INDICATOR_CONDITION 604# gl_MODULE_INDICATOR_CONDITION
75# expands to a C preprocessor expression that evaluates to 1 or 0, depending 605# expands to a C preprocessor expression that evaluates to 1 or 0, depending
76# whether a gnulib module that has been requested shall be considered present 606# whether a gnulib module that has been requested shall be considered present
@@ -83,9 +613,9 @@ m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
83AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE], 613AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
84[ 614[
85 gl_MODULE_INDICATOR_SET_VARIABLE_AUX( 615 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
86 [GNULIB_[]m4_translit([[$1]], 616 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
87 [abcdefghijklmnopqrstuvwxyz./-], 617 [abcdefghijklmnopqrstuvwxyz./-],
88 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])], 618 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
89 [gl_MODULE_INDICATOR_CONDITION]) 619 [gl_MODULE_INDICATOR_CONDITION])
90]) 620])
91 621
@@ -197,42 +727,20 @@ AC_DEFUN([gl_FEATURES_H],
197 AC_SUBST([HAVE_FEATURES_H]) 727 AC_SUBST([HAVE_FEATURES_H])
198]) 728])
199 729
200# m4_foreach_w
201# is a backport of autoconf-2.59c's m4_foreach_w.
202# Remove this macro when we can assume autoconf >= 2.60.
203m4_ifndef([m4_foreach_w],
204 [m4_define([m4_foreach_w],
205 [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
206
207# AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
208# ----------------------------------------------------
209# Backport of autoconf-2.63b's macro.
210# Remove this macro when we can assume autoconf >= 2.64.
211m4_ifndef([AS_VAR_IF],
212[m4_define([AS_VAR_IF],
213[AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
214
215# gl_PROG_CC_C99 730# gl_PROG_CC_C99
216# Modifies the value of the shell variable CC in an attempt to make $CC 731# Modifies the value of the shell variable CC in an attempt to make $CC
217# understand ISO C99 source code. 732# understand ISO C99 source code.
218# This is like AC_PROG_CC_C99, except that
219# - AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60,
220# - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
221# <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00367.html>,
222# but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
223# <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00441.html>.
224# Remaining problems:
225# - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
226# to CC twice
227# <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00431.html>.
228# - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard.
229AC_DEFUN([gl_PROG_CC_C99], 733AC_DEFUN([gl_PROG_CC_C99],
230[ 734[
231 dnl Change that version number to the minimum Autoconf version that supports 735 dnl Just use AC_PROG_CC_C99.
232 dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls. 736 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
233 m4_version_prereq([9.0], 737 dnl value of CC will contain the C99 enabling options twice. But this is only
234 [AC_REQUIRE([AC_PROG_CC_C99])], 738 dnl a cosmetic problem.
235 [AC_REQUIRE([AC_PROG_CC_STDC])]) 739 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
740 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
741 m4_version_prereq([2.70],
742 [AC_REQUIRE([AC_PROG_CC])],
743 [AC_REQUIRE([AC_PROG_CC_C99])])
236]) 744])
237 745
238# gl_PROG_AR_RANLIB 746# gl_PROG_AR_RANLIB
@@ -243,9 +751,11 @@ AC_DEFUN([gl_PROG_AR_RANLIB],
243[ 751[
244 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler 752 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
245 dnl as "cc", and GCC as "gcc". They have different object file formats and 753 dnl as "cc", and GCC as "gcc". They have different object file formats and
246 dnl library formats. In particular, the GNU binutils programs ar, ranlib 754 dnl library formats. In particular, the GNU binutils programs ar and ranlib
247 dnl produce libraries that work only with gcc, not with cc. 755 dnl produce libraries that work only with gcc, not with cc.
248 AC_REQUIRE([AC_PROG_CC]) 756 AC_REQUIRE([AC_PROG_CC])
757 dnl The '][' hides this use from 'aclocal'.
758 AC_BEFORE([$0], [A][M_PROG_AR])
249 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler], 759 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
250 [ 760 [
251 AC_EGREP_CPP([Amsterdam], 761 AC_EGREP_CPP([Amsterdam],
@@ -257,25 +767,39 @@ Amsterdam
257 [gl_cv_c_amsterdam_compiler=yes], 767 [gl_cv_c_amsterdam_compiler=yes],
258 [gl_cv_c_amsterdam_compiler=no]) 768 [gl_cv_c_amsterdam_compiler=no])
259 ]) 769 ])
260 if test -z "$AR"; then 770
261 if test $gl_cv_c_amsterdam_compiler = yes; then 771 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
772 dnl building with __ACK__.
773 if test $gl_cv_c_amsterdam_compiler = yes; then
774 if test -z "$AR"; then
262 AR='cc -c.a' 775 AR='cc -c.a'
263 if test -z "$ARFLAGS"; then
264 ARFLAGS='-o'
265 fi
266 else
267 dnl Use the Automake-documented default values for AR and ARFLAGS,
268 dnl but prefer ${host}-ar over ar (useful for cross-compiling).
269 AC_CHECK_TOOL([AR], [ar], [ar])
270 if test -z "$ARFLAGS"; then
271 ARFLAGS='cru'
272 fi
273 fi 776 fi
274 else
275 if test -z "$ARFLAGS"; then 777 if test -z "$ARFLAGS"; then
276 ARFLAGS='cru' 778 ARFLAGS='-o'
277 fi 779 fi
780 else
781 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
782 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
783 dnl script on-demand, if not specified by ./configure of course).
784 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
785 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
786 dnl because AM_PROG_AR is written so it could re-set AR variable even for
787 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
788 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
789 dnl default value and automake should usually know them).
790 dnl
791 dnl The '][' hides this use from 'aclocal'.
792 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
278 fi 793 fi
794
795 dnl In case the code above has not helped with setting AR/ARFLAGS, use
796 dnl Automake-documented default values for AR and ARFLAGS, but prefer
797 dnl ${host}-ar over ar (useful for cross-compiling).
798 AC_CHECK_TOOL([AR], [ar], [ar])
799 if test -z "$ARFLAGS"; then
800 ARFLAGS='cr'
801 fi
802
279 AC_SUBST([AR]) 803 AC_SUBST([AR])
280 AC_SUBST([ARFLAGS]) 804 AC_SUBST([ARFLAGS])
281 if test -z "$RANLIB"; then 805 if test -z "$RANLIB"; then
@@ -289,46 +813,29 @@ Amsterdam
289 AC_SUBST([RANLIB]) 813 AC_SUBST([RANLIB])
290]) 814])
291 815
292# AC_PROG_MKDIR_P
293# is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix
294# for interoperability with automake-1.9.6 from autoconf-2.62.
295# Remove this macro when we can assume autoconf >= 2.62 or
296# autoconf >= 2.60 && automake >= 1.10.
297# AC_AUTOCONF_VERSION was introduced in 2.62, so use that as the witness.
298m4_ifndef([AC_AUTOCONF_VERSION],[
299m4_ifdef([AC_PROG_MKDIR_P], [
300 dnl For automake-1.9.6 && autoconf < 2.62: Ensure MKDIR_P is AC_SUBSTed.
301 m4_define([AC_PROG_MKDIR_P],
302 m4_defn([AC_PROG_MKDIR_P])[
303 AC_SUBST([MKDIR_P])])], [
304 dnl For autoconf < 2.60: Backport of AC_PROG_MKDIR_P.
305 AC_DEFUN_ONCE([AC_PROG_MKDIR_P],
306 [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
307 MKDIR_P='$(mkdir_p)'
308 AC_SUBST([MKDIR_P])])])
309])
310
311# AC_C_RESTRICT 816# AC_C_RESTRICT
312# This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61, 817# This definition is copied from post-2.70 Autoconf and overrides the
313# so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++ 818# AC_C_RESTRICT macro from autoconf 2.60..2.70.
314# works. 819m4_version_prereq([2.70.1], [], [
315# This definition can be removed once autoconf >= 2.62 can be assumed.
316# AC_AUTOCONF_VERSION was introduced in 2.62, so use that as the witness.
317m4_ifndef([AC_AUTOCONF_VERSION],[
318AC_DEFUN([AC_C_RESTRICT], 820AC_DEFUN([AC_C_RESTRICT],
319[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], 821[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
320 [ac_cv_c_restrict=no 822 [ac_cv_c_restrict=no
321 # The order here caters to the fact that C++ does not require restrict. 823 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
322 for ac_kw in __restrict __restrict__ _Restrict restrict; do 824 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
323 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 825 # Put 'restrict' last, because C++ lacks it.
324 [[typedef int * int_ptr; 826 for ac_kw in __restrict__ __restrict _Restrict restrict; do
325 int foo (int_ptr $ac_kw ip) { 827 AC_COMPILE_IFELSE(
326 return ip[0]; 828 [AC_LANG_PROGRAM(
327 }]], 829 [[typedef int *int_ptr;
328 [[int s[1]; 830 int foo (int_ptr $ac_kw ip) { return ip[0]; }
329 int * $ac_kw t = s; 831 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
330 t[0] = 0; 832 int bar (int ip[$ac_kw]) { return ip[0]; }
331 return foo(t)]])], 833 ]],
834 [[int s[1];
835 int *$ac_kw t = s;
836 t[0] = 0;
837 return foo (t) + bar (t);
838 ]])],
332 [ac_cv_c_restrict=$ac_kw]) 839 [ac_cv_c_restrict=$ac_kw])
333 test "$ac_cv_c_restrict" != no && break 840 test "$ac_cv_c_restrict" != no && break
334 done 841 done
@@ -336,22 +843,24 @@ AC_DEFUN([AC_C_RESTRICT],
336 AH_VERBATIM([restrict], 843 AH_VERBATIM([restrict],
337[/* Define to the equivalent of the C99 'restrict' keyword, or to 844[/* Define to the equivalent of the C99 'restrict' keyword, or to
338 nothing if this is not supported. Do not define if restrict is 845 nothing if this is not supported. Do not define if restrict is
339 supported directly. */ 846 supported only directly. */
340#undef restrict 847#undef restrict
341/* Work around a bug in Sun C++: it does not support _Restrict, even 848/* Work around a bug in older versions of Sun C++, which did not
342 though the corresponding Sun C compiler does, which causes 849 #define __restrict__ or support _Restrict or __restrict__
343 "#define restrict _Restrict" in the previous line. Perhaps some future 850 even though the corresponding Sun C compiler ended up with
344 version of Sun C++ will work with _Restrict; if so, it'll probably 851 "#define restrict _Restrict" or "#define restrict __restrict__"
345 define __RESTRICT, just as Sun C does. */ 852 in the previous line. This workaround can be removed once
346#if defined __SUNPRO_CC && !defined __RESTRICT 853 we assume Oracle Developer Studio 12.5 (2016) or later. */
854#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
347# define _Restrict 855# define _Restrict
856# define __restrict__
348#endif]) 857#endif])
349 case $ac_cv_c_restrict in 858 case $ac_cv_c_restrict in
350 restrict) ;; 859 restrict) ;;
351 no) AC_DEFINE([restrict], []) ;; 860 no) AC_DEFINE([restrict], []) ;;
352 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; 861 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
353 esac 862 esac
354]) 863])# AC_C_RESTRICT
355]) 864])
356 865
357# gl_BIGENDIAN 866# gl_BIGENDIAN
@@ -363,6 +872,22 @@ AC_DEFUN([gl_BIGENDIAN],
363 AC_C_BIGENDIAN 872 AC_C_BIGENDIAN
364]) 873])
365 874
875# A temporary file descriptor.
876# Must be less than 10, because dash 0.5.8 does not support redirections
877# with multi-digit file descriptors.
878m4_define([GL_TMP_FD], 9)
879
880# gl_SILENT(command)
881# executes command, but without the normal configure output.
882# This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
883# inside another AC_CACHE_CHECK.
884AC_DEFUN([gl_SILENT],
885[
886 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
887 $1
888 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
889])
890
366# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it) 891# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
367# is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not 892# is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
368# output a spurious "(cached)" mark in the midst of other configure output. 893# output a spurious "(cached)" mark in the midst of other configure output.
@@ -370,8 +895,257 @@ AC_DEFUN([gl_BIGENDIAN],
370# by an AC_MSG_CHECKING/AC_MSG_RESULT pair. 895# by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
371AC_DEFUN([gl_CACHE_VAL_SILENT], 896AC_DEFUN([gl_CACHE_VAL_SILENT],
372[ 897[
373 saved_as_echo_n="$as_echo_n" 898 gl_SILENT([
374 as_echo_n=':' 899 AC_CACHE_VAL([$1], [$2])
375 AC_CACHE_VAL([$1], [$2]) 900 ])
376 as_echo_n="$saved_as_echo_n" 901])
902
903# gl_CONDITIONAL(conditional, condition)
904# is like AM_CONDITIONAL(conditional, condition), except that it does not
905# produce an error
906# configure: error: conditional "..." was never defined.
907# Usually this means the macro was only invoked conditionally.
908# when only invoked conditionally. Instead, in that case, both the _TRUE
909# and the _FALSE case are disabled.
910AC_DEFUN([gl_CONDITIONAL],
911[
912 pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
913 AM_CONDITIONAL([$1], [$2])
914 popdef([AC_CONFIG_COMMANDS_PRE])dnl
915 if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
916 [$1]_TRUE='#'
917 [$1]_FALSE='#'
918 fi
919])
920
921# gl_CC_ALLOW_WARNINGS
922# sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
923# that reverts a preceding '-Werror' option, if available.
924# This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
925# and empty otherwise.
926AC_DEFUN([gl_CC_ALLOW_WARNINGS],
927[
928 AC_REQUIRE([AC_PROG_CC])
929 AC_CACHE_CHECK([for C compiler option to allow warnings],
930 [gl_cv_cc_wallow],
931 [rm -f conftest*
932 echo 'int dummy;' > conftest.c
933 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
934 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
935 dnl Test the number of error output lines, because AIX xlc accepts the
936 dnl option '-Wno-error', just to produce a warning
937 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
938 dnl afterwards.
939 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
940 gl_cv_cc_wallow='-Wno-error'
941 else
942 gl_cv_cc_wallow=none
943 fi
944 rm -f conftest*
945 ])
946 case "$gl_cv_cc_wallow" in
947 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
948 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
949 esac
950 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
951])
952
953# gl_CXX_ALLOW_WARNINGS
954# sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
955# that reverts a preceding '-Werror' option, if available.
956AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
957[
958 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
959 if test -n "$CXX" && test "$CXX" != no; then
960 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
961 [gl_cv_cxx_wallow],
962 [rm -f conftest*
963 echo 'int dummy;' > conftest.cc
964 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
965 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
966 dnl Test the number of error output lines, because AIX xlC accepts the
967 dnl option '-Wno-error', just to produce a warning
968 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
969 dnl afterwards.
970 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
971 gl_cv_cxx_wallow='-Wno-error'
972 else
973 gl_cv_cxx_wallow=none
974 fi
975 rm -f conftest*
976 ])
977 case "$gl_cv_cxx_wallow" in
978 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
979 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
980 esac
981 else
982 GL_CXXFLAG_ALLOW_WARNINGS=''
983 fi
984 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
985])
986
987# gl_CC_GNULIB_WARNINGS
988# sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
989# set that enables or disables warnings as suitable for the Gnulib coding style.
990AC_DEFUN([gl_CC_GNULIB_WARNINGS],
991[
992 AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
993 dnl Assume that the compiler supports -Wno-* options only if it also supports
994 dnl -Wno-error.
995 GL_CFLAG_GNULIB_WARNINGS=''
996 if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
997 dnl Enable these warning options:
998 dnl
999 dnl GCC clang
1000 dnl -Wno-cast-qual >= 3 >= 3.9
1001 dnl -Wno-conversion >= 3 >= 3.9
1002 dnl -Wno-float-conversion >= 4.9 >= 3.9
1003 dnl -Wno-float-equal >= 3 >= 3.9
1004 dnl -Wimplicit-fallthrough >= 7 >= 3.9
1005 dnl -Wno-pedantic >= 4.8 >= 3.9
1006 dnl -Wno-sign-compare >= 3 >= 3.9
1007 dnl -Wno-sign-conversion >= 4.3 >= 3.9
1008 dnl -Wno-type-limits >= 4.3 >= 3.9
1009 dnl -Wno-undef >= 3 >= 3.9
1010 dnl -Wno-unsuffixed-float-constants >= 4.5
1011 dnl -Wno-unused-function >= 3 >= 3.9
1012 dnl -Wno-unused-parameter >= 3 >= 3.9
1013 dnl
1014 cat > conftest.c <<\EOF
1015 #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1016 -Wno-cast-qual
1017 -Wno-conversion
1018 -Wno-float-equal
1019 -Wno-sign-compare
1020 -Wno-undef
1021 -Wno-unused-function
1022 -Wno-unused-parameter
1023 #endif
1024 #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1025 -Wno-float-conversion
1026 #endif
1027 #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1028 -Wimplicit-fallthrough
1029 #endif
1030 #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1031 -Wno-pedantic
1032 #endif
1033 #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
1034 -Wno-sign-conversion
1035 -Wno-type-limits
1036 #endif
1037 #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
1038 -Wno-unsuffixed-float-constants
1039 #endif
1040EOF
1041 gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
1042 if AC_TRY_EVAL([gl_command]); then
1043 gl_options=`grep -v '#' conftest.out`
1044 for word in $gl_options; do
1045 GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
1046 done
1047 fi
1048 rm -f conftest.c conftest.out
1049 fi
1050 AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
1051])
1052
1053dnl gl_CONDITIONAL_HEADER([foo.h])
1054dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
1055dnl and produces
1056dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
1057dnl on whether GL_GENERATE_FOO_H is true or false,
1058dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
1059dnl the shell variable GL_GENERATE_FOO_H.
1060AC_DEFUN([gl_CONDITIONAL_HEADER],
1061[
1062 m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
1063 m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1064 m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
1065 case "$gl_generate_var" in
1066 false) gl_header_name='' ;;
1067 true)
1068 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
1069 dnl versa.
1070 if test -z "$gl_header_name"; then
1071 gl_header_name="${gl_source_base_prefix}$1"
1072 fi
1073 ;;
1074 *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
1075 esac
1076 AC_SUBST(gl_header_name)
1077 gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
1078 m4_popdef([gl_generate_cond])
1079 m4_popdef([gl_generate_var])
1080 m4_popdef([gl_header_name])
1081])
1082
1083dnl Expands to some code for use in .c programs that, on native Windows, defines
1084dnl the Microsoft deprecated alias function names to the underscore-prefixed
1085dnl actual function names. With this macro, these function names are available
1086dnl without linking with '-loldnames' and without generating warnings.
1087dnl Usage: Use it after all system header files are included.
1088dnl #include <...>
1089dnl #include <...>
1090dnl ]GL_MDA_DEFINES[
1091dnl ...
1092AC_DEFUN([GL_MDA_DEFINES],[
1093AC_REQUIRE([_GL_MDA_DEFINES])
1094[$gl_mda_defines]
1095])
1096AC_DEFUN([_GL_MDA_DEFINES],
1097[gl_mda_defines='
1098#if defined _WIN32 && !defined __CYGWIN__
1099#define access _access
1100#define chdir _chdir
1101#define chmod _chmod
1102#define close _close
1103#define creat _creat
1104#define dup _dup
1105#define dup2 _dup2
1106#define ecvt _ecvt
1107#define execl _execl
1108#define execle _execle
1109#define execlp _execlp
1110#define execv _execv
1111#define execve _execve
1112#define execvp _execvp
1113#define execvpe _execvpe
1114#define fcloseall _fcloseall
1115#define fcvt _fcvt
1116#define fdopen _fdopen
1117#define fileno _fileno
1118#define gcvt _gcvt
1119#define getcwd _getcwd
1120#define getpid _getpid
1121#define getw _getw
1122#define isatty _isatty
1123#define j0 _j0
1124#define j1 _j1
1125#define jn _jn
1126#define lfind _lfind
1127#define lsearch _lsearch
1128#define lseek _lseek
1129#define memccpy _memccpy
1130#define mkdir _mkdir
1131#define mktemp _mktemp
1132#define open _open
1133#define putenv _putenv
1134#define putw _putw
1135#define read _read
1136#define rmdir _rmdir
1137#define strdup _strdup
1138#define swab _swab
1139#define tempnam _tempnam
1140#define tzset _tzset
1141#define umask _umask
1142#define unlink _unlink
1143#define utime _utime
1144#define wcsdup _wcsdup
1145#define write _write
1146#define y0 _y0
1147#define y1 _y1
1148#define yn _yn
1149#endif
1150'
377]) 1151])
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 9a4f502..4764622 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -1,9 +1,9 @@
1# DO NOT EDIT! GENERATED AUTOMATICALLY! 1# DO NOT EDIT! GENERATED AUTOMATICALLY!
2# Copyright (C) 2002-2013 Free Software Foundation, Inc. 2# Copyright (C) 2002-2023 Free Software Foundation, Inc.
3# 3#
4# This file is free software; you can redistribute it and/or modify 4# This file 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 3 of the License, or 6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version. 7# (at your option) any later version.
8# 8#
9# This file is distributed in the hope that it will be useful, 9# This file is distributed in the hope that it will be useful,
@@ -12,7 +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 file. If not, see <http://www.gnu.org/licenses/>. 15# along with this file. If not, see <https://www.gnu.org/licenses/>.
16# 16#
17# As a special exception to the GNU General Public License, 17# As a special exception to the GNU General Public License,
18# this file may be distributed as part of a program that 18# this file may be distributed as part of a program that
@@ -37,50 +37,91 @@ AC_DEFUN([gl_EARLY],
37 m4_pattern_allow([^gl_ES$])dnl a valid locale name 37 m4_pattern_allow([^gl_ES$])dnl a valid locale name
38 m4_pattern_allow([^gl_LIBOBJS$])dnl a variable 38 m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
39 m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable 39 m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
40
41 # Pre-early section.
42 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
40 AC_REQUIRE([gl_PROG_AR_RANLIB]) 43 AC_REQUIRE([gl_PROG_AR_RANLIB])
41 AC_REQUIRE([AM_PROG_CC_C_O]) 44
45 # Code from module absolute-header:
42 # Code from module alloca-opt: 46 # Code from module alloca-opt:
43 # Code from module arpa_inet: 47 # Code from module arpa_inet:
48 # Code from module assert-h:
49 # Code from module attribute:
44 # Code from module base64: 50 # Code from module base64:
51 # Code from module basename-lgpl:
45 # Code from module btowc: 52 # Code from module btowc:
46 # Code from module configmake: 53 # Code from module builtin-expect:
47 # Code from module crypto/sha1: 54 # Code from module byteswap:
55 # Code from module c99:
56 # Code from module calloc-gnu:
57 # Code from module calloc-posix:
58 # Code from module cloexec:
59 # Code from module close:
60 # Code from module crypto/af_alg:
61 # Code from module crypto/sha256:
62 # Code from module crypto/sha256-buffer:
48 # Code from module dirname: 63 # Code from module dirname:
49 # Code from module dirname-lgpl: 64 # Code from module dirname-lgpl:
50 # Code from module dosname:
51 # Code from module double-slash-root: 65 # Code from module double-slash-root:
66 # Code from module dup2:
52 # Code from module environ: 67 # Code from module environ:
53 # Code from module errno: 68 # Code from module errno:
54 # Code from module error: 69 # Code from module error:
55 # Code from module exitfail: 70 # Code from module exitfail:
56 # Code from module extensions: 71 # Code from module extensions:
57 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
58 # Code from module extern-inline: 72 # Code from module extern-inline:
73 # Code from module fcntl:
74 # Code from module fcntl-h:
59 # Code from module fd-hook: 75 # Code from module fd-hook:
76 # Code from module fflush:
77 AC_REQUIRE([gl_SET_LARGEFILE_SOURCE])
78 # Code from module filename:
60 # Code from module float: 79 # Code from module float:
61 # Code from module floorf: 80 # Code from module floorf:
81 # Code from module fopen:
82 # Code from module fopen-gnu:
83 # Code from module fpurge:
84 # Code from module freading:
85 # Code from module free-posix:
86 # Code from module fseek:
87 # Code from module fseeko:
88 AC_REQUIRE([gl_SET_LARGEFILE_SOURCE])
89 # Code from module fstat:
62 # Code from module fsusage: 90 # Code from module fsusage:
63 # Code from module full-read: 91 # Code from module ftell:
92 # Code from module ftello:
93 AC_REQUIRE([gl_SET_LARGEFILE_SOURCE])
94 # Code from module gen-header:
64 # Code from module getaddrinfo: 95 # Code from module getaddrinfo:
96 # Code from module getdelim:
97 # Code from module getdtablesize:
65 # Code from module gethostname: 98 # Code from module gethostname:
99 # Code from module getline:
66 # Code from module getloadavg: 100 # Code from module getloadavg:
67 # Code from module getopt-gnu: 101 # Code from module getopt-gnu:
68 # Code from module getopt-posix: 102 # Code from module getopt-posix:
69 # Code from module gettext: 103 # Code from module getprogname:
70 # Code from module gettext-h: 104 # Code from module gettext-h:
71 # Code from module havelib: 105 # Code from module glibc-internal/dynarray:
106 # Code from module hard-locale:
72 # Code from module hostent: 107 # Code from module hostent:
108 # Code from module ialloc:
73 # Code from module idpriv-droptemp: 109 # Code from module idpriv-droptemp:
110 # Code from module idx:
74 # Code from module include_next: 111 # Code from module include_next:
75 # Code from module inet_ntop: 112 # Code from module inet_ntop:
76 # Code from module intprops: 113 # Code from module intprops:
114 # Code from module inttypes-incomplete:
77 # Code from module langinfo: 115 # Code from module langinfo:
78 # Code from module largefile: 116 # Code from module largefile:
79 AC_REQUIRE([AC_SYS_LARGEFILE]) 117 AC_REQUIRE([AC_SYS_LARGEFILE])
118 # Code from module libc-config:
119 # Code from module limits-h:
80 # Code from module localcharset: 120 # Code from module localcharset:
81 # Code from module locale: 121 # Code from module locale:
82 # Code from module localeconv: 122 # Code from module localeconv:
83 # Code from module lock: 123 # Code from module lock:
124 # Code from module lseek:
84 # Code from module malloc-gnu: 125 # Code from module malloc-gnu:
85 # Code from module malloc-posix: 126 # Code from module malloc-posix:
86 # Code from module malloca: 127 # Code from module malloca:
@@ -89,6 +130,7 @@ AC_DEFUN([gl_EARLY],
89 # Code from module mbsinit: 130 # Code from module mbsinit:
90 # Code from module mbtowc: 131 # Code from module mbtowc:
91 # Code from module memchr: 132 # Code from module memchr:
133 # Code from module minmax:
92 # Code from module mktime: 134 # Code from module mktime:
93 # Code from module mktime-internal: 135 # Code from module mktime-internal:
94 # Code from module mountlist: 136 # Code from module mountlist:
@@ -99,11 +141,15 @@ AC_DEFUN([gl_EARLY],
99 # Code from module netinet_in: 141 # Code from module netinet_in:
100 # Code from module nl_langinfo: 142 # Code from module nl_langinfo:
101 # Code from module nocrash: 143 # Code from module nocrash:
102 # Code from module read: 144 # Code from module open:
145 # Code from module pathmax:
146 # Code from module realloc-gnu:
147 # Code from module realloc-posix:
148 # Code from module reallocarray:
103 # Code from module regex: 149 # Code from module regex:
104 # Code from module safe-read:
105 # Code from module servent: 150 # Code from module servent:
106 # Code from module setenv: 151 # Code from module setenv:
152 # Code from module setlocale-null:
107 # Code from module size_max: 153 # Code from module size_max:
108 # Code from module snippet/_Noreturn: 154 # Code from module snippet/_Noreturn:
109 # Code from module snippet/arg-nonnull: 155 # Code from module snippet/arg-nonnull:
@@ -114,8 +160,12 @@ AC_DEFUN([gl_EARLY],
114 # Code from module sockets: 160 # Code from module sockets:
115 # Code from module socklen: 161 # Code from module socklen:
116 # Code from module ssize_t: 162 # Code from module ssize_t:
163 # Code from module stat:
164 # Code from module stat-time:
165 # Code from module std-gnu11:
117 # Code from module stdalign: 166 # Code from module stdalign:
118 # Code from module stdbool: 167 # Code from module stdbool:
168 # Code from module stdckdint:
119 # Code from module stddef: 169 # Code from module stddef:
120 # Code from module stdint: 170 # Code from module stdint:
121 # Code from module stdio: 171 # Code from module stdio:
@@ -128,11 +178,10 @@ AC_DEFUN([gl_EARLY],
128 # Code from module strerror-override: 178 # Code from module strerror-override:
129 # Code from module string: 179 # Code from module string:
130 # Code from module strings: 180 # Code from module strings:
131 # Code from module strndup:
132 # Code from module strnlen:
133 # Code from module strsep: 181 # Code from module strsep:
134 # Code from module strstr-simple: 182 # Code from module strstr-simple:
135 # Code from module sys_socket: 183 # Code from module sys_socket:
184 # Code from module sys_stat:
136 # Code from module sys_types: 185 # Code from module sys_types:
137 # Code from module sys_uio: 186 # Code from module sys_uio:
138 # Code from module threadlib: 187 # Code from module threadlib:
@@ -141,7 +190,9 @@ AC_DEFUN([gl_EARLY],
141 # Code from module time_r: 190 # Code from module time_r:
142 # Code from module timegm: 191 # Code from module timegm:
143 # Code from module unistd: 192 # Code from module unistd:
193 # Code from module unlocked-io-internal:
144 # Code from module unsetenv: 194 # Code from module unsetenv:
195 # Code from module vararrays:
145 # Code from module vasnprintf: 196 # Code from module vasnprintf:
146 # Code from module vasprintf: 197 # Code from module vasprintf:
147 # Code from module verify: 198 # Code from module verify:
@@ -149,11 +200,14 @@ AC_DEFUN([gl_EARLY],
149 # Code from module wchar: 200 # Code from module wchar:
150 # Code from module wcrtomb: 201 # Code from module wcrtomb:
151 # Code from module wctype-h: 202 # Code from module wctype-h:
203 # Code from module windows-mutex:
204 # Code from module windows-once:
205 # Code from module windows-recmutex:
206 # Code from module windows-rwlock:
152 # Code from module xalloc: 207 # Code from module xalloc:
153 # Code from module xalloc-die: 208 # Code from module xalloc-die:
154 # Code from module xalloc-oversized: 209 # Code from module xalloc-oversized:
155 # Code from module xsize: 210 # Code from module xsize:
156 # Code from module xstrndup:
157]) 211])
158 212
159# This macro should be invoked from ./configure.ac, in the section 213# This macro should be invoked from ./configure.ac, in the section
@@ -170,154 +224,300 @@ AC_DEFUN([gl_INIT],
170 m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) 224 m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES]))
171 m4_pushdef([gl_LIBSOURCES_LIST], []) 225 m4_pushdef([gl_LIBSOURCES_LIST], [])
172 m4_pushdef([gl_LIBSOURCES_DIR], []) 226 m4_pushdef([gl_LIBSOURCES_DIR], [])
227 m4_pushdef([GL_MACRO_PREFIX], [gl])
228 m4_pushdef([GL_MODULE_INDICATOR_PREFIX], [GL])
173 gl_COMMON 229 gl_COMMON
174 gl_source_base='gl' 230 gl_source_base='gl'
231 gl_source_base_prefix=
175 gl_FUNC_ALLOCA 232 gl_FUNC_ALLOCA
176 gl_HEADER_ARPA_INET 233 gl_CONDITIONAL_HEADER([alloca.h])
234 AC_PROG_MKDIR_P
235 gl_ARPA_INET_H
236 gl_ARPA_INET_H_REQUIRE_DEFAULTS
237 AC_PROG_MKDIR_P
238 gl_ASSERT_H
239 gl_CONDITIONAL_HEADER([assert.h])
177 AC_PROG_MKDIR_P 240 AC_PROG_MKDIR_P
178 gl_FUNC_BASE64 241 gl_FUNC_BASE64
179 gl_FUNC_BTOWC 242 gl_FUNC_BTOWC
180 if test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1; then 243 gl_CONDITIONAL([GL_COND_OBJ_BTOWC],
181 AC_LIBOBJ([btowc]) 244 [test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1])
245 AM_COND_IF([GL_COND_OBJ_BTOWC], [
182 gl_PREREQ_BTOWC 246 gl_PREREQ_BTOWC
183 fi 247 ])
184 gl_WCHAR_MODULE_INDICATOR([btowc]) 248 gl_WCHAR_MODULE_INDICATOR([btowc])
185 gl_CONFIGMAKE_PREP 249 gl___BUILTIN_EXPECT
186 gl_SHA1 250 gl_BYTESWAP
187 gl_DIRNAME 251 gl_CONDITIONAL_HEADER([byteswap.h])
252 AC_PROG_MKDIR_P
253 gl_FUNC_CALLOC_GNU
254 if test $REPLACE_CALLOC_FOR_CALLOC_GNU = 1; then
255 AC_LIBOBJ([calloc])
256 fi
257 gl_STDLIB_MODULE_INDICATOR([calloc-gnu])
258 gl_FUNC_CALLOC_POSIX
259 if test $REPLACE_CALLOC_FOR_CALLOC_POSIX = 1; then
260 AC_LIBOBJ([calloc])
261 fi
262 gl_STDLIB_MODULE_INDICATOR([calloc-posix])
263 gl_MODULE_INDICATOR_FOR_TESTS([cloexec])
264 gl_FUNC_CLOSE
265 gl_CONDITIONAL([GL_COND_OBJ_CLOSE], [test $REPLACE_CLOSE = 1])
266 gl_UNISTD_MODULE_INDICATOR([close])
267 gl_AF_ALG
268 AC_REQUIRE([AC_C_RESTRICT])
269 gl_SHA256
188 gl_MODULE_INDICATOR([dirname]) 270 gl_MODULE_INDICATOR([dirname])
189 gl_DIRNAME_LGPL
190 gl_DOUBLE_SLASH_ROOT 271 gl_DOUBLE_SLASH_ROOT
272 gl_FUNC_DUP2
273 gl_CONDITIONAL([GL_COND_OBJ_DUP2], [test $REPLACE_DUP2 = 1])
274 AM_COND_IF([GL_COND_OBJ_DUP2], [
275 gl_PREREQ_DUP2
276 ])
277 gl_UNISTD_MODULE_INDICATOR([dup2])
191 gl_ENVIRON 278 gl_ENVIRON
192 gl_UNISTD_MODULE_INDICATOR([environ]) 279 gl_UNISTD_MODULE_INDICATOR([environ])
193 gl_HEADER_ERRNO_H 280 gl_HEADER_ERRNO_H
281 gl_CONDITIONAL_HEADER([errno.h])
282 AC_PROG_MKDIR_P
194 gl_ERROR 283 gl_ERROR
195 if test $ac_cv_lib_error_at_line = no; then 284 gl_CONDITIONAL([GL_COND_OBJ_ERROR], [test "$ac_cv_lib_error_at_line" = no])
196 AC_LIBOBJ([error]) 285 AM_COND_IF([GL_COND_OBJ_ERROR], [
197 gl_PREREQ_ERROR 286 gl_PREREQ_ERROR
198 fi 287 ])
199 m4_ifdef([AM_XGETTEXT_OPTION], 288 m4_ifdef([AM_XGETTEXT_OPTION],
200 [AM_][XGETTEXT_OPTION([--flag=error:3:c-format]) 289 [AM_][XGETTEXT_OPTION([--flag=error:3:c-format])
201 AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])]) 290 AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
202 AC_REQUIRE([gl_EXTERN_INLINE]) 291 AC_REQUIRE([gl_EXTERN_INLINE])
292 gl_FUNC_FCNTL
293 gl_CONDITIONAL([GL_COND_OBJ_FCNTL],
294 [test $HAVE_FCNTL = 0 || test $REPLACE_FCNTL = 1])
295 gl_FCNTL_MODULE_INDICATOR([fcntl])
296 gl_FCNTL_H
297 gl_FCNTL_H_REQUIRE_DEFAULTS
298 AC_PROG_MKDIR_P
299 gl_FUNC_FFLUSH
300 gl_CONDITIONAL([GL_COND_OBJ_FFLUSH], [test $REPLACE_FFLUSH = 1])
301 AM_COND_IF([GL_COND_OBJ_FFLUSH], [
302 gl_PREREQ_FFLUSH
303 ])
304 gl_MODULE_INDICATOR([fflush])
305 gl_STDIO_MODULE_INDICATOR([fflush])
203 gl_FLOAT_H 306 gl_FLOAT_H
204 if test $REPLACE_FLOAT_LDBL = 1; then 307 gl_CONDITIONAL_HEADER([float.h])
205 AC_LIBOBJ([float]) 308 AC_PROG_MKDIR_P
206 fi 309 gl_CONDITIONAL([GL_COND_OBJ_FLOAT], [test $REPLACE_FLOAT_LDBL = 1])
207 if test $REPLACE_ITOLD = 1; then 310 gl_CONDITIONAL([GL_COND_OBJ_ITOLD], [test $REPLACE_ITOLD = 1])
208 AC_LIBOBJ([itold])
209 fi
210 gl_FUNC_FLOORF 311 gl_FUNC_FLOORF
211 if test $HAVE_DECL_FLOORF = 0 || test $REPLACE_FLOORF = 1; then 312 gl_CONDITIONAL([GL_COND_OBJ_FLOORF],
212 AC_LIBOBJ([floorf]) 313 [test $HAVE_DECL_FLOORF = 0 || test $REPLACE_FLOORF = 1])
213 fi
214 gl_MATH_MODULE_INDICATOR([floorf]) 314 gl_MATH_MODULE_INDICATOR([floorf])
315 gl_FUNC_FOPEN
316 if test $REPLACE_FOPEN = 1; then
317 AC_LIBOBJ([fopen])
318 gl_PREREQ_FOPEN
319 fi
320 gl_STDIO_MODULE_INDICATOR([fopen])
321 gl_FUNC_FOPEN_GNU
322 if test $REPLACE_FOPEN_FOR_FOPEN_GNU = 1; then
323 AC_LIBOBJ([fopen])
324 gl_PREREQ_FOPEN
325 fi
326 gl_MODULE_INDICATOR([fopen-gnu])
327 gl_STDIO_MODULE_INDICATOR([fopen-gnu])
328 gl_FUNC_FPURGE
329 gl_CONDITIONAL([GL_COND_OBJ_FPURGE],
330 [test $HAVE_FPURGE = 0 || test $REPLACE_FPURGE = 1])
331 gl_STDIO_MODULE_INDICATOR([fpurge])
332 gl_FUNC_FREADING
333 gl_FUNC_FREE
334 gl_CONDITIONAL([GL_COND_OBJ_FREE], [test $REPLACE_FREE = 1])
335 AM_COND_IF([GL_COND_OBJ_FREE], [
336 gl_PREREQ_FREE
337 ])
338 gl_STDLIB_MODULE_INDICATOR([free-posix])
339 gl_FUNC_FSEEK
340 gl_CONDITIONAL([GL_COND_OBJ_FSEEK], [test $REPLACE_FSEEK = 1])
341 gl_STDIO_MODULE_INDICATOR([fseek])
342 gl_FUNC_FSEEKO
343 gl_CONDITIONAL([GL_COND_OBJ_FSEEKO],
344 [test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1])
345 AM_COND_IF([GL_COND_OBJ_FSEEKO], [
346 gl_PREREQ_FSEEKO
347 ])
348 gl_STDIO_MODULE_INDICATOR([fseeko])
349 gl_FUNC_FSTAT
350 gl_CONDITIONAL([GL_COND_OBJ_FSTAT], [test $REPLACE_FSTAT = 1])
351 AM_COND_IF([GL_COND_OBJ_FSTAT], [
352 case "$host_os" in
353 mingw*)
354 AC_LIBOBJ([stat-w32])
355 ;;
356 esac
357 gl_PREREQ_FSTAT
358 ])
359 gl_SYS_STAT_MODULE_INDICATOR([fstat])
215 gl_FSUSAGE 360 gl_FSUSAGE
216 if test $gl_cv_fs_space = yes; then 361 gl_CONDITIONAL([GL_COND_OBJ_FSUSAGE], [test $gl_cv_fs_space = yes])
217 AC_LIBOBJ([fsusage]) 362 AM_COND_IF([GL_COND_OBJ_FSUSAGE], [
218 gl_PREREQ_FSUSAGE_EXTRA 363 gl_PREREQ_FSUSAGE_EXTRA
219 fi 364 ])
365 gl_FUNC_FTELL
366 gl_CONDITIONAL([GL_COND_OBJ_FTELL], [test $REPLACE_FTELL = 1])
367 gl_STDIO_MODULE_INDICATOR([ftell])
368 gl_FUNC_FTELLO
369 gl_CONDITIONAL([GL_COND_OBJ_FTELLO],
370 [test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1])
371 AM_COND_IF([GL_COND_OBJ_FTELLO], [
372 gl_PREREQ_FTELLO
373 ])
374 gl_STDIO_MODULE_INDICATOR([ftello])
220 gl_GETADDRINFO 375 gl_GETADDRINFO
221 if test $HAVE_GETADDRINFO = 0; then 376 gl_CONDITIONAL([GL_COND_OBJ_GETADDRINFO],
222 AC_LIBOBJ([getaddrinfo]) 377 [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1])
223 fi 378 gl_CONDITIONAL([GL_COND_OBJ_GAI_STRERROR],
224 if test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1; then 379 [test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1])
225 AC_LIBOBJ([gai_strerror])
226 fi
227 gl_NETDB_MODULE_INDICATOR([getaddrinfo]) 380 gl_NETDB_MODULE_INDICATOR([getaddrinfo])
381 gl_FUNC_GETDELIM
382 gl_CONDITIONAL([GL_COND_OBJ_GETDELIM],
383 [test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1])
384 AM_COND_IF([GL_COND_OBJ_GETDELIM], [
385 gl_PREREQ_GETDELIM
386 ])
387 gl_STDIO_MODULE_INDICATOR([getdelim])
388 gl_FUNC_GETDTABLESIZE
389 gl_CONDITIONAL([GL_COND_OBJ_GETDTABLESIZE],
390 [test $HAVE_GETDTABLESIZE = 0 || test $REPLACE_GETDTABLESIZE = 1])
391 AM_COND_IF([GL_COND_OBJ_GETDTABLESIZE], [
392 gl_PREREQ_GETDTABLESIZE
393 ])
394 gl_UNISTD_MODULE_INDICATOR([getdtablesize])
228 gl_FUNC_GETHOSTNAME 395 gl_FUNC_GETHOSTNAME
229 if test $HAVE_GETHOSTNAME = 0; then 396 gl_CONDITIONAL([GL_COND_OBJ_GETHOSTNAME], [test $HAVE_GETHOSTNAME = 0])
230 AC_LIBOBJ([gethostname]) 397 AM_COND_IF([GL_COND_OBJ_GETHOSTNAME], [
231 gl_PREREQ_GETHOSTNAME 398 gl_PREREQ_GETHOSTNAME
232 fi 399 ])
233 gl_UNISTD_MODULE_INDICATOR([gethostname]) 400 gl_UNISTD_MODULE_INDICATOR([gethostname])
401 gl_FUNC_GETLINE
402 gl_CONDITIONAL([GL_COND_OBJ_GETLINE], [test $REPLACE_GETLINE = 1])
403 AM_COND_IF([GL_COND_OBJ_GETLINE], [
404 gl_PREREQ_GETLINE
405 ])
406 gl_STDIO_MODULE_INDICATOR([getline])
407 AC_REQUIRE([AC_CANONICAL_HOST])
234 gl_GETLOADAVG 408 gl_GETLOADAVG
235 if test $HAVE_GETLOADAVG = 0; then 409 gl_CONDITIONAL([GL_COND_OBJ_GETLOADAVG], [test $HAVE_GETLOADAVG = 0])
236 AC_LIBOBJ([getloadavg]) 410 AM_COND_IF([GL_COND_OBJ_GETLOADAVG], [
237 gl_PREREQ_GETLOADAVG 411 gl_PREREQ_GETLOADAVG
238 fi 412 ])
239 gl_STDLIB_MODULE_INDICATOR([getloadavg]) 413 gl_STDLIB_MODULE_INDICATOR([getloadavg])
240 gl_FUNC_GETOPT_GNU 414 gl_FUNC_GETOPT_GNU
241 if test $REPLACE_GETOPT = 1; then 415 dnl Because of the way gl_FUNC_GETOPT_GNU is implemented (the gl_getopt_required
242 AC_LIBOBJ([getopt]) 416 dnl mechanism), there is no need to do any AC_LIBOBJ or AC_SUBST here; they are
243 AC_LIBOBJ([getopt1]) 417 dnl done in the getopt-posix module.
244 gl_PREREQ_GETOPT
245 dnl Arrange for unistd.h to include getopt.h.
246 GNULIB_GL_UNISTD_H_GETOPT=1
247 fi
248 AC_SUBST([GNULIB_GL_UNISTD_H_GETOPT])
249 gl_MODULE_INDICATOR_FOR_TESTS([getopt-gnu])
250 gl_FUNC_GETOPT_POSIX 418 gl_FUNC_GETOPT_POSIX
251 if test $REPLACE_GETOPT = 1; then 419 gl_CONDITIONAL_HEADER([getopt.h])
252 AC_LIBOBJ([getopt]) 420 gl_CONDITIONAL_HEADER([getopt-cdefs.h])
253 AC_LIBOBJ([getopt1]) 421 AC_PROG_MKDIR_P
254 gl_PREREQ_GETOPT 422 gl_CONDITIONAL([GL_COND_OBJ_GETOPT], [test $REPLACE_GETOPT = 1])
255 dnl Arrange for unistd.h to include getopt.h. 423 AM_COND_IF([GL_COND_OBJ_GETOPT], [
256 GNULIB_GL_UNISTD_H_GETOPT=1 424 dnl Define the substituted variable GNULIB_UNISTD_H_GETOPT to 1.
257 fi 425 gl_UNISTD_H_REQUIRE_DEFAULTS
258 AC_SUBST([GNULIB_GL_UNISTD_H_GETOPT]) 426 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_GETOPT], [1])
259 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. 427 ])
260 AM_GNU_GETTEXT_VERSION([0.18.1]) 428 gl_UNISTD_MODULE_INDICATOR([getopt-posix])
429 gl_FUNC_GETPROGNAME
261 AC_SUBST([LIBINTL]) 430 AC_SUBST([LIBINTL])
262 AC_SUBST([LTLIBINTL]) 431 AC_SUBST([LTLIBINTL])
432 AC_PROG_MKDIR_P
433 AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
434 LIB_HARD_LOCALE="$LIB_SETLOCALE_NULL"
435 AC_SUBST([LIB_HARD_LOCALE])
263 gl_HOSTENT 436 gl_HOSTENT
264 gl_IDPRIV 437 gl_IDPRIV
265 gl_FUNC_INET_NTOP 438 gl_FUNC_INET_NTOP
266 if test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1; then 439 gl_CONDITIONAL([GL_COND_OBJ_INET_NTOP],
267 AC_LIBOBJ([inet_ntop]) 440 [test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1])
441 AM_COND_IF([GL_COND_OBJ_INET_NTOP], [
268 gl_PREREQ_INET_NTOP 442 gl_PREREQ_INET_NTOP
269 fi 443 ])
270 gl_ARPA_INET_MODULE_INDICATOR([inet_ntop]) 444 gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
445 gl_INTTYPES_INCOMPLETE
446 gl_INTTYPES_H_REQUIRE_DEFAULTS
447 AC_PROG_MKDIR_P
271 gl_LANGINFO_H 448 gl_LANGINFO_H
449 gl_LANGINFO_H_REQUIRE_DEFAULTS
450 AC_PROG_MKDIR_P
272 AC_REQUIRE([gl_LARGEFILE]) 451 AC_REQUIRE([gl_LARGEFILE])
452 gl___INLINE
453 gl_LIMITS_H
454 gl_CONDITIONAL_HEADER([limits.h])
455 AC_PROG_MKDIR_P
273 gl_LOCALCHARSET 456 gl_LOCALCHARSET
274 LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(abs_top_builddir)/$gl_source_base\"" 457 dnl For backward compatibility. Some packages still use this.
458 LOCALCHARSET_TESTS_ENVIRONMENT=
275 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT]) 459 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
276 gl_LOCALE_H 460 gl_LOCALE_H
461 gl_LOCALE_H_REQUIRE_DEFAULTS
462 AC_PROG_MKDIR_P
277 gl_FUNC_LOCALECONV 463 gl_FUNC_LOCALECONV
278 if test $REPLACE_LOCALECONV = 1; then 464 gl_CONDITIONAL([GL_COND_OBJ_LOCALECONV], [test $REPLACE_LOCALECONV = 1])
279 AC_LIBOBJ([localeconv]) 465 AM_COND_IF([GL_COND_OBJ_LOCALECONV], [
280 gl_PREREQ_LOCALECONV 466 gl_PREREQ_LOCALECONV
281 fi 467 ])
282 gl_LOCALE_MODULE_INDICATOR([localeconv]) 468 gl_LOCALE_MODULE_INDICATOR([localeconv])
283 gl_LOCK 469 gl_LOCK
284 gl_MODULE_INDICATOR([lock]) 470 gl_MODULE_INDICATOR([lock])
471 gl_FUNC_LSEEK
472 gl_CONDITIONAL([GL_COND_OBJ_LSEEK], [test $REPLACE_LSEEK = 1])
473 gl_UNISTD_MODULE_INDICATOR([lseek])
285 gl_FUNC_MALLOC_GNU 474 gl_FUNC_MALLOC_GNU
286 if test $REPLACE_MALLOC = 1; then 475 if test $REPLACE_MALLOC_FOR_MALLOC_GNU = 1; then
287 AC_LIBOBJ([malloc]) 476 AC_LIBOBJ([malloc])
288 fi 477 fi
289 gl_MODULE_INDICATOR([malloc-gnu]) 478 gl_STDLIB_MODULE_INDICATOR([malloc-gnu])
290 gl_FUNC_MALLOC_POSIX 479 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
291 if test $REPLACE_MALLOC = 1; then 480 if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then
292 AC_LIBOBJ([malloc]) 481 AC_LIBOBJ([malloc])
293 fi 482 fi
294 gl_STDLIB_MODULE_INDICATOR([malloc-posix]) 483 gl_STDLIB_MODULE_INDICATOR([malloc-posix])
295 gl_MALLOCA 484 gl_MALLOCA
296 gl_MATH_H 485 gl_MATH_H
486 gl_MATH_H_REQUIRE_DEFAULTS
487 AC_PROG_MKDIR_P
297 gl_FUNC_MBRTOWC 488 gl_FUNC_MBRTOWC
298 if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then 489 gl_CONDITIONAL([GL_COND_OBJ_MBRTOWC],
299 AC_LIBOBJ([mbrtowc]) 490 [test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1])
491 AM_COND_IF([GL_COND_OBJ_MBRTOWC], [
492 if test $REPLACE_MBSTATE_T = 1; then
493 AC_LIBOBJ([lc-charset-dispatch])
494 AC_LIBOBJ([mbtowc-lock])
495 gl_PREREQ_MBTOWC_LOCK
496 fi
300 gl_PREREQ_MBRTOWC 497 gl_PREREQ_MBRTOWC
301 fi 498 ])
302 gl_WCHAR_MODULE_INDICATOR([mbrtowc]) 499 gl_WCHAR_MODULE_INDICATOR([mbrtowc])
303 gl_FUNC_MBSINIT 500 gl_FUNC_MBSINIT
304 if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then 501 gl_CONDITIONAL([GL_COND_OBJ_MBSINIT],
305 AC_LIBOBJ([mbsinit]) 502 [test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1])
503 AM_COND_IF([GL_COND_OBJ_MBSINIT], [
306 gl_PREREQ_MBSINIT 504 gl_PREREQ_MBSINIT
307 fi 505 ])
308 gl_WCHAR_MODULE_INDICATOR([mbsinit]) 506 gl_WCHAR_MODULE_INDICATOR([mbsinit])
309 gl_FUNC_MBTOWC 507 gl_FUNC_MBTOWC
310 if test $REPLACE_MBTOWC = 1; then 508 gl_CONDITIONAL([GL_COND_OBJ_MBTOWC],
311 AC_LIBOBJ([mbtowc]) 509 [test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1])
510 AM_COND_IF([GL_COND_OBJ_MBTOWC], [
312 gl_PREREQ_MBTOWC 511 gl_PREREQ_MBTOWC
313 fi 512 ])
314 gl_STDLIB_MODULE_INDICATOR([mbtowc]) 513 gl_STDLIB_MODULE_INDICATOR([mbtowc])
315 gl_FUNC_MEMCHR 514 gl_FUNC_MEMCHR
316 if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then 515 gl_CONDITIONAL([GL_COND_OBJ_MEMCHR], [test $REPLACE_MEMCHR = 1])
317 AC_LIBOBJ([memchr]) 516 AM_COND_IF([GL_COND_OBJ_MEMCHR], [
318 gl_PREREQ_MEMCHR 517 gl_PREREQ_MEMCHR
319 fi 518 ])
320 gl_STRING_MODULE_INDICATOR([memchr]) 519 gl_STRING_MODULE_INDICATOR([memchr])
520 gl_MINMAX
321 gl_FUNC_MKTIME 521 gl_FUNC_MKTIME
322 if test $REPLACE_MKTIME = 1; then 522 if test $REPLACE_MKTIME = 1; then
323 AC_LIBOBJ([mktime]) 523 AC_LIBOBJ([mktime])
@@ -325,73 +525,162 @@ AC_DEFUN([gl_INIT],
325 fi 525 fi
326 gl_TIME_MODULE_INDICATOR([mktime]) 526 gl_TIME_MODULE_INDICATOR([mktime])
327 gl_FUNC_MKTIME_INTERNAL 527 gl_FUNC_MKTIME_INTERNAL
328 if test $REPLACE_MKTIME = 1; then 528 if test $WANT_MKTIME_INTERNAL = 1; then
329 AC_LIBOBJ([mktime]) 529 AC_LIBOBJ([mktime])
330 gl_PREREQ_MKTIME 530 gl_PREREQ_MKTIME
331 fi 531 fi
332 gl_MOUNTLIST 532 gl_MOUNTLIST
333 if test $gl_cv_list_mounted_fs = yes; then 533 gl_CONDITIONAL([GL_COND_OBJ_MOUNTLIST], [test $gl_cv_list_mounted_fs = yes])
334 AC_LIBOBJ([mountlist]) 534 AM_COND_IF([GL_COND_OBJ_MOUNTLIST], [
335 gl_PREREQ_MOUNTLIST_EXTRA 535 gl_PREREQ_MOUNTLIST_EXTRA
336 fi 536 ])
337 gl_MSVC_INVAL 537 AC_REQUIRE([gl_MSVC_INVAL])
338 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then 538 gl_CONDITIONAL([GL_COND_OBJ_MSVC_INVAL],
339 AC_LIBOBJ([msvc-inval]) 539 [test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1])
340 fi 540 AC_REQUIRE([gl_MSVC_NOTHROW])
341 gl_MSVC_NOTHROW 541 gl_CONDITIONAL([GL_COND_OBJ_MSVC_NOTHROW],
342 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then 542 [test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1])
343 AC_LIBOBJ([msvc-nothrow]) 543 gl_MODULE_INDICATOR([msvc-nothrow])
344 fi
345 gl_MULTIARCH 544 gl_MULTIARCH
346 gl_HEADER_NETDB 545 gl_NETDB_H
546 gl_NETDB_H_REQUIRE_DEFAULTS
547 AC_PROG_MKDIR_P
347 gl_HEADER_NETINET_IN 548 gl_HEADER_NETINET_IN
549 gl_CONDITIONAL_HEADER([netinet/in.h])
348 AC_PROG_MKDIR_P 550 AC_PROG_MKDIR_P
349 gl_FUNC_NL_LANGINFO 551 gl_FUNC_NL_LANGINFO
350 if test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1; then 552 gl_CONDITIONAL([GL_COND_OBJ_NL_LANGINFO],
351 AC_LIBOBJ([nl_langinfo]) 553 [test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1])
554 gl_CONDITIONAL([GL_COND_OBJ_NL_LANGINFO_LOCK],
555 [test $REPLACE_NL_LANGINFO = 1 && test $NL_LANGINFO_MTSAFE = 0])
556 if test $REPLACE_NL_LANGINFO = 1 && test $NL_LANGINFO_MTSAFE = 0; then
557 gl_PREREQ_NL_LANGINFO_LOCK
352 fi 558 fi
353 gl_LANGINFO_MODULE_INDICATOR([nl_langinfo]) 559 gl_LANGINFO_MODULE_INDICATOR([nl_langinfo])
354 gl_FUNC_READ 560 gl_FUNC_OPEN
355 if test $REPLACE_READ = 1; then 561 gl_CONDITIONAL([GL_COND_OBJ_OPEN], [test $REPLACE_OPEN = 1])
356 AC_LIBOBJ([read]) 562 AM_COND_IF([GL_COND_OBJ_OPEN], [
357 gl_PREREQ_READ 563 gl_PREREQ_OPEN
564 ])
565 gl_FCNTL_MODULE_INDICATOR([open])
566 gl_PATHMAX
567 gl_FUNC_REALLOC_GNU
568 if test $REPLACE_REALLOC_FOR_REALLOC_GNU = 1; then
569 AC_LIBOBJ([realloc])
570 fi
571 gl_STDLIB_MODULE_INDICATOR([realloc-gnu])
572 gl_FUNC_REALLOC_POSIX
573 if test $REPLACE_REALLOC_FOR_REALLOC_POSIX = 1; then
574 AC_LIBOBJ([realloc])
358 fi 575 fi
359 gl_UNISTD_MODULE_INDICATOR([read]) 576 gl_STDLIB_MODULE_INDICATOR([realloc-posix])
577 gl_FUNC_REALLOCARRAY
578 gl_CONDITIONAL([GL_COND_OBJ_REALLOCARRAY],
579 [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1])
580 AM_COND_IF([GL_COND_OBJ_REALLOCARRAY], [
581 gl_PREREQ_REALLOCARRAY
582 ])
583 gl_MODULE_INDICATOR([reallocarray])
584 gl_STDLIB_MODULE_INDICATOR([reallocarray])
360 gl_REGEX 585 gl_REGEX
361 if test $ac_use_included_regex = yes; then 586 gl_CONDITIONAL([GL_COND_OBJ_REGEX], [test $ac_use_included_regex = yes])
362 AC_LIBOBJ([regex]) 587 AM_COND_IF([GL_COND_OBJ_REGEX], [
363 gl_PREREQ_REGEX 588 gl_PREREQ_REGEX
364 fi 589 ])
365 gl_PREREQ_SAFE_READ
366 gl_SERVENT 590 gl_SERVENT
367 gl_FUNC_SETENV 591 gl_FUNC_SETENV
368 if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then 592 gl_CONDITIONAL([GL_COND_OBJ_SETENV],
369 AC_LIBOBJ([setenv]) 593 [test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1])
370 fi
371 gl_STDLIB_MODULE_INDICATOR([setenv]) 594 gl_STDLIB_MODULE_INDICATOR([setenv])
595 gl_FUNC_SETLOCALE_NULL
596 gl_CONDITIONAL([GL_COND_OBJ_SETLOCALE_LOCK],
597 [test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0])
598 AM_COND_IF([GL_COND_OBJ_SETLOCALE_LOCK], [
599 gl_PREREQ_SETLOCALE_LOCK
600 ])
601 gl_LOCALE_MODULE_INDICATOR([setlocale_null])
372 gl_SIZE_MAX 602 gl_SIZE_MAX
373 gl_FUNC_SNPRINTF 603 gl_FUNC_SNPRINTF
374 gl_STDIO_MODULE_INDICATOR([snprintf]) 604 gl_STDIO_MODULE_INDICATOR([snprintf])
375 gl_MODULE_INDICATOR([snprintf]) 605 gl_MODULE_INDICATOR([snprintf])
376 gl_SOCKETLIB 606 AC_REQUIRE([gl_SOCKETLIB])
377 gl_SOCKETS 607 AC_REQUIRE([gl_SOCKETS])
378 gl_TYPE_SOCKLEN_T 608 gl_TYPE_SOCKLEN_T
379 gt_TYPE_SSIZE_T 609 gt_TYPE_SSIZE_T
610 gl_FUNC_STAT
611 gl_CONDITIONAL([GL_COND_OBJ_STAT], [test $REPLACE_STAT = 1])
612 AM_COND_IF([GL_COND_OBJ_STAT], [
613 case "$host_os" in
614 mingw*)
615 AC_LIBOBJ([stat-w32])
616 ;;
617 esac
618 gl_PREREQ_STAT
619 ])
620 gl_SYS_STAT_MODULE_INDICATOR([stat])
621 gl_STAT_TIME
622 gl_STAT_BIRTHTIME
380 gl_STDALIGN_H 623 gl_STDALIGN_H
381 AM_STDBOOL_H 624 gl_CONDITIONAL_HEADER([stdalign.h])
625 AC_PROG_MKDIR_P
626 gl_C_BOOL
627 AC_CHECK_HEADERS_ONCE([stdckdint.h])
628 if test $ac_cv_header_stdckdint_h = yes; then
629 GL_GENERATE_STDCKDINT_H=false
630 else
631 GL_GENERATE_STDCKDINT_H=true
632 fi
633 gl_CONDITIONAL_HEADER([stdckdint.h])
634 AC_PROG_MKDIR_P
382 gl_STDDEF_H 635 gl_STDDEF_H
636 gl_STDDEF_H_REQUIRE_DEFAULTS
637 gl_CONDITIONAL_HEADER([stddef.h])
638 AC_PROG_MKDIR_P
383 gl_STDINT_H 639 gl_STDINT_H
640 gl_CONDITIONAL_HEADER([stdint.h])
641 dnl Because of gl_REPLACE_LIMITS_H:
642 gl_CONDITIONAL_HEADER([limits.h])
643 AC_PROG_MKDIR_P
384 gl_STDIO_H 644 gl_STDIO_H
645 gl_STDIO_H_REQUIRE_DEFAULTS
646 AC_PROG_MKDIR_P
647 gl_CONDITIONAL([GL_COND_OBJ_STDIO_READ], [test $REPLACE_STDIO_READ_FUNCS = 1])
648 gl_CONDITIONAL([GL_COND_OBJ_STDIO_WRITE], [test $REPLACE_STDIO_WRITE_FUNCS = 1])
649 dnl No need to create extra modules for these functions. Everyone who uses
650 dnl <stdio.h> likely needs them.
651 gl_STDIO_MODULE_INDICATOR([fscanf])
652 gl_MODULE_INDICATOR([fscanf])
653 gl_STDIO_MODULE_INDICATOR([scanf])
654 gl_MODULE_INDICATOR([scanf])
655 gl_STDIO_MODULE_INDICATOR([fgetc])
656 gl_STDIO_MODULE_INDICATOR([getc])
657 gl_STDIO_MODULE_INDICATOR([getchar])
658 gl_STDIO_MODULE_INDICATOR([fgets])
659 gl_STDIO_MODULE_INDICATOR([fread])
660 dnl No need to create extra modules for these functions. Everyone who uses
661 dnl <stdio.h> likely needs them.
662 gl_STDIO_MODULE_INDICATOR([fprintf])
663 gl_STDIO_MODULE_INDICATOR([printf])
664 gl_STDIO_MODULE_INDICATOR([vfprintf])
665 gl_STDIO_MODULE_INDICATOR([vprintf])
666 gl_STDIO_MODULE_INDICATOR([fputc])
667 gl_STDIO_MODULE_INDICATOR([putc])
668 gl_STDIO_MODULE_INDICATOR([putchar])
669 gl_STDIO_MODULE_INDICATOR([fputs])
670 gl_STDIO_MODULE_INDICATOR([puts])
671 gl_STDIO_MODULE_INDICATOR([fwrite])
385 gl_STDLIB_H 672 gl_STDLIB_H
673 gl_STDLIB_H_REQUIRE_DEFAULTS
674 AC_PROG_MKDIR_P
386 gl_STRCASE 675 gl_STRCASE
387 if test $HAVE_STRCASECMP = 0; then 676 gl_CONDITIONAL([GL_COND_OBJ_STRCASECMP], [test $HAVE_STRCASECMP = 0])
388 AC_LIBOBJ([strcasecmp]) 677 AM_COND_IF([GL_COND_OBJ_STRCASECMP], [
389 gl_PREREQ_STRCASECMP 678 gl_PREREQ_STRCASECMP
390 fi 679 ])
391 if test $HAVE_STRNCASECMP = 0; then 680 gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP], [test $HAVE_STRNCASECMP = 0])
392 AC_LIBOBJ([strncasecmp]) 681 AM_COND_IF([GL_COND_OBJ_STRNCASECMP], [
393 gl_PREREQ_STRNCASECMP 682 gl_PREREQ_STRNCASECMP
394 fi 683 ])
395 gl_FUNC_STRCASESTR 684 gl_FUNC_STRCASESTR
396 if test $HAVE_STRCASESTR = 0 || test $REPLACE_STRCASESTR = 1; then 685 if test $HAVE_STRCASESTR = 0 || test $REPLACE_STRCASESTR = 1; then
397 AC_LIBOBJ([strcasestr]) 686 AC_LIBOBJ([strcasestr])
@@ -404,68 +693,76 @@ AC_DEFUN([gl_INIT],
404 fi 693 fi
405 gl_STRING_MODULE_INDICATOR([strcasestr]) 694 gl_STRING_MODULE_INDICATOR([strcasestr])
406 gl_FUNC_STRERROR 695 gl_FUNC_STRERROR
407 if test $REPLACE_STRERROR = 1; then 696 gl_CONDITIONAL([GL_COND_OBJ_STRERROR], [test $REPLACE_STRERROR = 1])
408 AC_LIBOBJ([strerror])
409 fi
410 gl_MODULE_INDICATOR([strerror]) 697 gl_MODULE_INDICATOR([strerror])
411 gl_STRING_MODULE_INDICATOR([strerror]) 698 gl_STRING_MODULE_INDICATOR([strerror])
412 AC_REQUIRE([gl_HEADER_ERRNO_H]) 699 AC_REQUIRE([gl_HEADER_ERRNO_H])
413 AC_REQUIRE([gl_FUNC_STRERROR_0]) 700 AC_REQUIRE([gl_FUNC_STRERROR_0])
414 if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then 701 gl_CONDITIONAL([GL_COND_OBJ_STRERROR_OVERRIDE],
415 AC_LIBOBJ([strerror-override]) 702 [test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1])
703 AM_COND_IF([GL_COND_OBJ_STRERROR_OVERRIDE], [
416 gl_PREREQ_SYS_H_WINSOCK2 704 gl_PREREQ_SYS_H_WINSOCK2
417 fi 705 ])
418 gl_HEADER_STRING_H 706 gl_STRING_H
419 gl_HEADER_STRINGS_H 707 gl_STRING_H_REQUIRE_DEFAULTS
420 gl_FUNC_STRNDUP 708 AC_PROG_MKDIR_P
421 if test $HAVE_STRNDUP = 0 || test $REPLACE_STRNDUP = 1; then 709 gl_STRINGS_H
422 AC_LIBOBJ([strndup]) 710 gl_STRINGS_H_REQUIRE_DEFAULTS
423 fi 711 AC_PROG_MKDIR_P
424 gl_STRING_MODULE_INDICATOR([strndup])
425 gl_FUNC_STRNLEN
426 if test $HAVE_DECL_STRNLEN = 0 || test $REPLACE_STRNLEN = 1; then
427 AC_LIBOBJ([strnlen])
428 gl_PREREQ_STRNLEN
429 fi
430 gl_STRING_MODULE_INDICATOR([strnlen])
431 gl_FUNC_STRSEP 712 gl_FUNC_STRSEP
432 if test $HAVE_STRSEP = 0; then 713 gl_CONDITIONAL([GL_COND_OBJ_STRSEP], [test $HAVE_STRSEP = 0])
433 AC_LIBOBJ([strsep]) 714 AM_COND_IF([GL_COND_OBJ_STRSEP], [
434 gl_PREREQ_STRSEP 715 gl_PREREQ_STRSEP
435 fi 716 ])
436 gl_STRING_MODULE_INDICATOR([strsep]) 717 gl_STRING_MODULE_INDICATOR([strsep])
437 gl_FUNC_STRSTR_SIMPLE 718 gl_FUNC_STRSTR_SIMPLE
438 if test $REPLACE_STRSTR = 1; then 719 if test $REPLACE_STRSTR = 1; then
439 AC_LIBOBJ([strstr]) 720 AC_LIBOBJ([strstr])
440 fi 721 fi
441 gl_STRING_MODULE_INDICATOR([strstr]) 722 gl_STRING_MODULE_INDICATOR([strstr])
442 gl_HEADER_SYS_SOCKET 723 gl_SYS_SOCKET_H
724 gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
725 AC_PROG_MKDIR_P
726 gl_SYS_STAT_H
727 gl_SYS_STAT_H_REQUIRE_DEFAULTS
443 AC_PROG_MKDIR_P 728 AC_PROG_MKDIR_P
444 gl_SYS_TYPES_H 729 gl_SYS_TYPES_H
730 gl_SYS_TYPES_H_REQUIRE_DEFAULTS
731 AC_PROG_MKDIR_P
732 gl_SYS_UIO_H
733 gl_SYS_UIO_H_REQUIRE_DEFAULTS
445 AC_PROG_MKDIR_P 734 AC_PROG_MKDIR_P
446 gl_HEADER_SYS_UIO 735 AC_REQUIRE([gl_THREADLIB])
736 gl_TIME_H
737 gl_TIME_H_REQUIRE_DEFAULTS
447 AC_PROG_MKDIR_P 738 AC_PROG_MKDIR_P
448 gl_THREADLIB
449 gl_HEADER_TIME_H
450 gl_TIME_R 739 gl_TIME_R
451 if test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1; then 740 gl_CONDITIONAL([GL_COND_OBJ_TIME_R],
452 AC_LIBOBJ([time_r]) 741 [test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1])
742 AM_COND_IF([GL_COND_OBJ_TIME_R], [
453 gl_PREREQ_TIME_R 743 gl_PREREQ_TIME_R
454 fi 744 ])
455 gl_TIME_MODULE_INDICATOR([time_r]) 745 gl_TIME_MODULE_INDICATOR([time_r])
456 gl_FUNC_TIMEGM 746 gl_FUNC_TIMEGM
457 if test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1; then 747 gl_CONDITIONAL([GL_COND_OBJ_TIMEGM],
458 AC_LIBOBJ([timegm]) 748 [test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1])
749 AM_COND_IF([GL_COND_OBJ_TIMEGM], [
459 gl_PREREQ_TIMEGM 750 gl_PREREQ_TIMEGM
460 fi 751 ])
461 gl_TIME_MODULE_INDICATOR([timegm]) 752 gl_TIME_MODULE_INDICATOR([timegm])
462 gl_UNISTD_H 753 gl_UNISTD_H
754 gl_UNISTD_H_REQUIRE_DEFAULTS
755 AC_PROG_MKDIR_P
756 gl_FUNC_GLIBC_UNLOCKED_IO
463 gl_FUNC_UNSETENV 757 gl_FUNC_UNSETENV
464 if test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1; then 758 gl_CONDITIONAL([GL_COND_OBJ_UNSETENV],
465 AC_LIBOBJ([unsetenv]) 759 [test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1])
760 AM_COND_IF([GL_COND_OBJ_UNSETENV], [
466 gl_PREREQ_UNSETENV 761 gl_PREREQ_UNSETENV
467 fi 762 ])
468 gl_STDLIB_MODULE_INDICATOR([unsetenv]) 763 gl_STDLIB_MODULE_INDICATOR([unsetenv])
764 AC_C_VARARRAYS
765 AC_REQUIRE([AC_C_RESTRICT])
469 gl_FUNC_VASNPRINTF 766 gl_FUNC_VASNPRINTF
470 gl_FUNC_VASPRINTF 767 gl_FUNC_VASPRINTF
471 gl_STDIO_MODULE_INDICATOR([vasprintf]) 768 gl_STDIO_MODULE_INDICATOR([vasprintf])
@@ -475,16 +772,34 @@ AC_DEFUN([gl_INIT],
475 gl_FUNC_VSNPRINTF 772 gl_FUNC_VSNPRINTF
476 gl_STDIO_MODULE_INDICATOR([vsnprintf]) 773 gl_STDIO_MODULE_INDICATOR([vsnprintf])
477 gl_WCHAR_H 774 gl_WCHAR_H
775 gl_WCHAR_H_REQUIRE_DEFAULTS
776 AC_PROG_MKDIR_P
478 gl_FUNC_WCRTOMB 777 gl_FUNC_WCRTOMB
479 if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then 778 gl_CONDITIONAL([GL_COND_OBJ_WCRTOMB],
480 AC_LIBOBJ([wcrtomb]) 779 [test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1])
780 AM_COND_IF([GL_COND_OBJ_WCRTOMB], [
481 gl_PREREQ_WCRTOMB 781 gl_PREREQ_WCRTOMB
482 fi 782 ])
483 gl_WCHAR_MODULE_INDICATOR([wcrtomb]) 783 gl_WCHAR_MODULE_INDICATOR([wcrtomb])
484 gl_WCTYPE_H 784 gl_WCTYPE_H
785 gl_WCTYPE_H_REQUIRE_DEFAULTS
786 AC_PROG_MKDIR_P
787 AC_REQUIRE([AC_CANONICAL_HOST])
788 gl_CONDITIONAL([GL_COND_OBJ_WINDOWS_MUTEX],
789 [case "$host_os" in mingw*) true;; *) false;; esac])
790 AC_REQUIRE([AC_CANONICAL_HOST])
791 gl_CONDITIONAL([GL_COND_OBJ_WINDOWS_ONCE],
792 [case "$host_os" in mingw*) true;; *) false;; esac])
793 AC_REQUIRE([AC_CANONICAL_HOST])
794 gl_CONDITIONAL([GL_COND_OBJ_WINDOWS_RECMUTEX],
795 [case "$host_os" in mingw*) true;; *) false;; esac])
796 AC_REQUIRE([AC_CANONICAL_HOST])
797 gl_CONDITIONAL([GL_COND_OBJ_WINDOWS_RWLOCK],
798 [case "$host_os" in mingw*) true;; *) false;; esac])
485 gl_XALLOC 799 gl_XALLOC
800 gl_MODULE_INDICATOR([xalloc])
801 gl_MODULE_INDICATOR([xalloc-die])
486 gl_XSIZE 802 gl_XSIZE
487 gl_XSTRNDUP
488 # End of code from modules 803 # End of code from modules
489 m4_ifval(gl_LIBSOURCES_LIST, [ 804 m4_ifval(gl_LIBSOURCES_LIST, [
490 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || 805 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
@@ -497,6 +812,8 @@ AC_DEFUN([gl_INIT],
497 m4_if(m4_sysval, [0], [], 812 m4_if(m4_sysval, [0], [],
498 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) 813 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])
499 ]) 814 ])
815 m4_popdef([GL_MODULE_INDICATOR_PREFIX])
816 m4_popdef([GL_MACRO_PREFIX])
500 m4_popdef([gl_LIBSOURCES_DIR]) 817 m4_popdef([gl_LIBSOURCES_DIR])
501 m4_popdef([gl_LIBSOURCES_LIST]) 818 m4_popdef([gl_LIBSOURCES_LIST])
502 m4_popdef([AC_LIBSOURCES]) 819 m4_popdef([AC_LIBSOURCES])
@@ -505,16 +822,28 @@ AC_DEFUN([gl_INIT],
505 AC_CONFIG_COMMANDS_PRE([ 822 AC_CONFIG_COMMANDS_PRE([
506 gl_libobjs= 823 gl_libobjs=
507 gl_ltlibobjs= 824 gl_ltlibobjs=
825 gl_libobjdeps=
508 if test -n "$gl_LIBOBJS"; then 826 if test -n "$gl_LIBOBJS"; then
509 # Remove the extension. 827 # Remove the extension.
828changequote(,)dnl
510 sed_drop_objext='s/\.o$//;s/\.obj$//' 829 sed_drop_objext='s/\.o$//;s/\.obj$//'
830 sed_dirname1='s,//*,/,g'
831 sed_dirname2='s,\(.\)/$,\1,'
832 sed_dirname3='s,^[^/]*$,.,'
833 sed_dirname4='s,\(.\)/[^/]*$,\1,'
834 sed_basename1='s,.*/,,'
835changequote([, ])dnl
511 for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do 836 for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do
512 gl_libobjs="$gl_libobjs $i.$ac_objext" 837 gl_libobjs="$gl_libobjs $i.$ac_objext"
513 gl_ltlibobjs="$gl_ltlibobjs $i.lo" 838 gl_ltlibobjs="$gl_ltlibobjs $i.lo"
839 i_dir=`echo "$i" | sed -e "$sed_dirname1" -e "$sed_dirname2" -e "$sed_dirname3" -e "$sed_dirname4"`
840 i_base=`echo "$i" | sed -e "$sed_basename1"`
841 gl_libobjdeps="$gl_libobjdeps $i_dir/\$(DEPDIR)/$i_base.Po"
514 done 842 done
515 fi 843 fi
516 AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) 844 AC_SUBST([gl_LIBOBJS], [$gl_libobjs])
517 AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) 845 AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs])
846 AC_SUBST([gl_LIBOBJDEPS], [$gl_libobjdeps])
518 ]) 847 ])
519 gltests_libdeps= 848 gltests_libdeps=
520 gltests_ltlibdeps= 849 gltests_ltlibdeps=
@@ -523,8 +852,11 @@ AC_DEFUN([gl_INIT],
523 m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES])) 852 m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES]))
524 m4_pushdef([gltests_LIBSOURCES_LIST], []) 853 m4_pushdef([gltests_LIBSOURCES_LIST], [])
525 m4_pushdef([gltests_LIBSOURCES_DIR], []) 854 m4_pushdef([gltests_LIBSOURCES_DIR], [])
855 m4_pushdef([GL_MACRO_PREFIX], [gltests])
856 m4_pushdef([GL_MODULE_INDICATOR_PREFIX], [GL])
526 gl_COMMON 857 gl_COMMON
527 gl_source_base='tests' 858 gl_source_base='tests'
859 gl_source_base_prefix=
528changequote(,)dnl 860changequote(,)dnl
529 gltests_WITNESS=IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e 's/[^A-Z0-9_]/_/g'`_GNULIB_TESTS 861 gltests_WITNESS=IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e 's/[^A-Z0-9_]/_/g'`_GNULIB_TESTS
530changequote([, ])dnl 862changequote([, ])dnl
@@ -543,6 +875,8 @@ changequote([, ])dnl
543 m4_if(m4_sysval, [0], [], 875 m4_if(m4_sysval, [0], [],
544 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) 876 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])
545 ]) 877 ])
878 m4_popdef([GL_MODULE_INDICATOR_PREFIX])
879 m4_popdef([GL_MACRO_PREFIX])
546 m4_popdef([gltests_LIBSOURCES_DIR]) 880 m4_popdef([gltests_LIBSOURCES_DIR])
547 m4_popdef([gltests_LIBSOURCES_LIST]) 881 m4_popdef([gltests_LIBSOURCES_LIST])
548 m4_popdef([AC_LIBSOURCES]) 882 m4_popdef([AC_LIBSOURCES])
@@ -551,17 +885,30 @@ changequote([, ])dnl
551 AC_CONFIG_COMMANDS_PRE([ 885 AC_CONFIG_COMMANDS_PRE([
552 gltests_libobjs= 886 gltests_libobjs=
553 gltests_ltlibobjs= 887 gltests_ltlibobjs=
888 gltests_libobjdeps=
554 if test -n "$gltests_LIBOBJS"; then 889 if test -n "$gltests_LIBOBJS"; then
555 # Remove the extension. 890 # Remove the extension.
891changequote(,)dnl
556 sed_drop_objext='s/\.o$//;s/\.obj$//' 892 sed_drop_objext='s/\.o$//;s/\.obj$//'
893 sed_dirname1='s,//*,/,g'
894 sed_dirname2='s,\(.\)/$,\1,'
895 sed_dirname3='s,^[^/]*$,.,'
896 sed_dirname4='s,\(.\)/[^/]*$,\1,'
897 sed_basename1='s,.*/,,'
898changequote([, ])dnl
557 for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do 899 for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do
558 gltests_libobjs="$gltests_libobjs $i.$ac_objext" 900 gltests_libobjs="$gltests_libobjs $i.$ac_objext"
559 gltests_ltlibobjs="$gltests_ltlibobjs $i.lo" 901 gltests_ltlibobjs="$gltests_ltlibobjs $i.lo"
902 i_dir=`echo "$i" | sed -e "$sed_dirname1" -e "$sed_dirname2" -e "$sed_dirname3" -e "$sed_dirname4"`
903 i_base=`echo "$i" | sed -e "$sed_basename1"`
904 gltests_libobjdeps="$gltests_libobjdeps $i_dir/\$(DEPDIR)/$i_base.Po"
560 done 905 done
561 fi 906 fi
562 AC_SUBST([gltests_LIBOBJS], [$gltests_libobjs]) 907 AC_SUBST([gltests_LIBOBJS], [$gltests_libobjs])
563 AC_SUBST([gltests_LTLIBOBJS], [$gltests_ltlibobjs]) 908 AC_SUBST([gltests_LTLIBOBJS], [$gltests_ltlibobjs])
909 AC_SUBST([gltests_LIBOBJDEPS], [$gltests_libobjdeps])
564 ]) 910 ])
911 AC_REQUIRE([gl_CC_GNULIB_WARNINGS])
565 LIBGNU_LIBDEPS="$gl_libdeps" 912 LIBGNU_LIBDEPS="$gl_libdeps"
566 AC_SUBST([LIBGNU_LIBDEPS]) 913 AC_SUBST([LIBGNU_LIBDEPS])
567 LIBGNU_LTLIBDEPS="$gl_ltlibdeps" 914 LIBGNU_LTLIBDEPS="$gl_ltlibdeps"
@@ -625,76 +972,130 @@ AC_DEFUN([gltests_LIBSOURCES], [
625# This macro records the list of files which have been installed by 972# This macro records the list of files which have been installed by
626# gnulib-tool and may be removed by future gnulib-tool invocations. 973# gnulib-tool and may be removed by future gnulib-tool invocations.
627AC_DEFUN([gl_FILE_LIST], [ 974AC_DEFUN([gl_FILE_LIST], [
628 build-aux/config.rpath 975 lib/_Noreturn.h
629 build-aux/snippet/_Noreturn.h 976 lib/af_alg.c
630 build-aux/snippet/arg-nonnull.h 977 lib/af_alg.h
631 build-aux/snippet/c++defs.h
632 build-aux/snippet/warn-on-use.h
633 lib/alloca.in.h 978 lib/alloca.in.h
979 lib/arg-nonnull.h
634 lib/arpa_inet.in.h 980 lib/arpa_inet.in.h
635 lib/asnprintf.c 981 lib/asnprintf.c
636 lib/asprintf.c 982 lib/asprintf.c
983 lib/assert.in.h
984 lib/attribute.h
637 lib/base64.c 985 lib/base64.c
638 lib/base64.h 986 lib/base64.h
639 lib/basename-lgpl.c 987 lib/basename-lgpl.c
988 lib/basename-lgpl.h
640 lib/basename.c 989 lib/basename.c
641 lib/btowc.c 990 lib/btowc.c
642 lib/config.charset 991 lib/byteswap.in.h
992 lib/c++defs.h
993 lib/calloc.c
994 lib/cdefs.h
995 lib/cloexec.c
996 lib/cloexec.h
997 lib/close.c
643 lib/dirname-lgpl.c 998 lib/dirname-lgpl.c
644 lib/dirname.c 999 lib/dirname.c
645 lib/dirname.h 1000 lib/dirname.h
646 lib/dosname.h 1001 lib/dup2.c
1002 lib/dynarray.h
647 lib/errno.in.h 1003 lib/errno.in.h
648 lib/error.c 1004 lib/error.c
649 lib/error.h 1005 lib/error.h
650 lib/exitfail.c 1006 lib/exitfail.c
651 lib/exitfail.h 1007 lib/exitfail.h
1008 lib/fcntl.c
1009 lib/fcntl.in.h
652 lib/fd-hook.c 1010 lib/fd-hook.c
653 lib/fd-hook.h 1011 lib/fd-hook.h
1012 lib/fflush.c
1013 lib/filename.h
654 lib/float+.h 1014 lib/float+.h
655 lib/float.c 1015 lib/float.c
656 lib/float.in.h 1016 lib/float.in.h
657 lib/floor.c 1017 lib/floor.c
658 lib/floorf.c 1018 lib/floorf.c
1019 lib/fopen.c
1020 lib/fpurge.c
1021 lib/freading.c
1022 lib/freading.h
1023 lib/free.c
1024 lib/fseek.c
1025 lib/fseeko.c
1026 lib/fstat.c
659 lib/fsusage.c 1027 lib/fsusage.c
660 lib/fsusage.h 1028 lib/fsusage.h
661 lib/full-read.c 1029 lib/ftell.c
662 lib/full-read.h 1030 lib/ftello.c
663 lib/full-write.c
664 lib/gai_strerror.c 1031 lib/gai_strerror.c
665 lib/getaddrinfo.c 1032 lib/getaddrinfo.c
1033 lib/getdelim.c
1034 lib/getdtablesize.c
666 lib/gethostname.c 1035 lib/gethostname.c
1036 lib/getline.c
667 lib/getloadavg.c 1037 lib/getloadavg.c
1038 lib/getopt-cdefs.in.h
1039 lib/getopt-core.h
1040 lib/getopt-ext.h
1041 lib/getopt-pfx-core.h
1042 lib/getopt-pfx-ext.h
668 lib/getopt.c 1043 lib/getopt.c
669 lib/getopt.in.h 1044 lib/getopt.in.h
670 lib/getopt1.c 1045 lib/getopt1.c
671 lib/getopt_int.h 1046 lib/getopt_int.h
1047 lib/getprogname.c
1048 lib/getprogname.h
672 lib/gettext.h 1049 lib/gettext.h
1050 lib/gl_openssl.h
673 lib/glthread/lock.c 1051 lib/glthread/lock.c
674 lib/glthread/lock.h 1052 lib/glthread/lock.h
675 lib/glthread/threadlib.c 1053 lib/glthread/threadlib.c
1054 lib/hard-locale.c
1055 lib/hard-locale.h
1056 lib/ialloc.c
1057 lib/ialloc.h
676 lib/idpriv-droptemp.c 1058 lib/idpriv-droptemp.c
677 lib/idpriv.h 1059 lib/idpriv.h
1060 lib/idx.h
678 lib/inet_ntop.c 1061 lib/inet_ntop.c
1062 lib/intprops-internal.h
679 lib/intprops.h 1063 lib/intprops.h
1064 lib/inttypes.in.h
680 lib/itold.c 1065 lib/itold.c
681 lib/langinfo.in.h 1066 lib/langinfo.in.h
1067 lib/lc-charset-dispatch.c
1068 lib/lc-charset-dispatch.h
1069 lib/libc-config.h
1070 lib/limits.in.h
682 lib/localcharset.c 1071 lib/localcharset.c
683 lib/localcharset.h 1072 lib/localcharset.h
684 lib/locale.in.h 1073 lib/locale.in.h
685 lib/localeconv.c 1074 lib/localeconv.c
1075 lib/lseek.c
686 lib/malloc.c 1076 lib/malloc.c
1077 lib/malloc/dynarray-skeleton.c
1078 lib/malloc/dynarray.h
1079 lib/malloc/dynarray_at_failure.c
1080 lib/malloc/dynarray_emplace_enlarge.c
1081 lib/malloc/dynarray_finalize.c
1082 lib/malloc/dynarray_resize.c
1083 lib/malloc/dynarray_resize_clear.c
687 lib/malloca.c 1084 lib/malloca.c
688 lib/malloca.h 1085 lib/malloca.h
689 lib/malloca.valgrind
690 lib/math.c 1086 lib/math.c
691 lib/math.in.h 1087 lib/math.in.h
1088 lib/mbrtowc-impl-utf8.h
1089 lib/mbrtowc-impl.h
692 lib/mbrtowc.c 1090 lib/mbrtowc.c
693 lib/mbsinit.c 1091 lib/mbsinit.c
694 lib/mbtowc-impl.h 1092 lib/mbtowc-impl.h
1093 lib/mbtowc-lock.c
1094 lib/mbtowc-lock.h
695 lib/mbtowc.c 1095 lib/mbtowc.c
696 lib/memchr.c 1096 lib/memchr.c
697 lib/memchr.valgrind 1097 lib/memchr.valgrind
1098 lib/minmax.h
698 lib/mktime-internal.h 1099 lib/mktime-internal.h
699 lib/mktime.c 1100 lib/mktime.c
700 lib/mountlist.c 1101 lib/mountlist.c
@@ -705,33 +1106,45 @@ AC_DEFUN([gl_FILE_LIST], [
705 lib/msvc-nothrow.h 1106 lib/msvc-nothrow.h
706 lib/netdb.in.h 1107 lib/netdb.in.h
707 lib/netinet_in.in.h 1108 lib/netinet_in.in.h
1109 lib/nl_langinfo-lock.c
708 lib/nl_langinfo.c 1110 lib/nl_langinfo.c
1111 lib/open.c
1112 lib/pathmax.h
709 lib/printf-args.c 1113 lib/printf-args.c
710 lib/printf-args.h 1114 lib/printf-args.h
711 lib/printf-parse.c 1115 lib/printf-parse.c
712 lib/printf-parse.h 1116 lib/printf-parse.h
713 lib/read.c 1117 lib/realloc.c
714 lib/ref-add.sin 1118 lib/reallocarray.c
715 lib/ref-del.sin
716 lib/regcomp.c 1119 lib/regcomp.c
717 lib/regex.c 1120 lib/regex.c
718 lib/regex.h 1121 lib/regex.h
719 lib/regex_internal.c 1122 lib/regex_internal.c
720 lib/regex_internal.h 1123 lib/regex_internal.h
721 lib/regexec.c 1124 lib/regexec.c
722 lib/safe-read.c
723 lib/safe-read.h
724 lib/setenv.c 1125 lib/setenv.c
725 lib/sha1.c 1126 lib/setlocale-lock.c
726 lib/sha1.h 1127 lib/setlocale_null.c
1128 lib/setlocale_null.h
1129 lib/sha256-stream.c
1130 lib/sha256.c
1131 lib/sha256.h
727 lib/size_max.h 1132 lib/size_max.h
728 lib/snprintf.c 1133 lib/snprintf.c
729 lib/sockets.c 1134 lib/sockets.c
730 lib/sockets.h 1135 lib/sockets.h
1136 lib/stat-time.c
1137 lib/stat-time.h
1138 lib/stat-w32.c
1139 lib/stat-w32.h
1140 lib/stat.c
731 lib/stdalign.in.h 1141 lib/stdalign.in.h
732 lib/stdbool.in.h 1142 lib/stdckdint.in.h
733 lib/stddef.in.h 1143 lib/stddef.in.h
734 lib/stdint.in.h 1144 lib/stdint.in.h
1145 lib/stdio-impl.h
1146 lib/stdio-read.c
1147 lib/stdio-write.c
735 lib/stdio.in.h 1148 lib/stdio.in.h
736 lib/stdlib.in.h 1149 lib/stdlib.in.h
737 lib/str-two-way.h 1150 lib/str-two-way.h
@@ -745,12 +1158,12 @@ AC_DEFUN([gl_FILE_LIST], [
745 lib/strings.in.h 1158 lib/strings.in.h
746 lib/stripslash.c 1159 lib/stripslash.c
747 lib/strncasecmp.c 1160 lib/strncasecmp.c
748 lib/strndup.c
749 lib/strnlen.c
750 lib/strsep.c 1161 lib/strsep.c
751 lib/strstr.c 1162 lib/strstr.c
1163 lib/sys-limits.h
752 lib/sys_socket.c 1164 lib/sys_socket.c
753 lib/sys_socket.in.h 1165 lib/sys_socket.in.h
1166 lib/sys_stat.in.h
754 lib/sys_types.in.h 1167 lib/sys_types.in.h
755 lib/sys_uio.in.h 1168 lib/sys_uio.in.h
756 lib/time.in.h 1169 lib/time.in.h
@@ -758,6 +1171,7 @@ AC_DEFUN([gl_FILE_LIST], [
758 lib/timegm.c 1171 lib/timegm.c
759 lib/unistd.c 1172 lib/unistd.c
760 lib/unistd.in.h 1173 lib/unistd.in.h
1174 lib/unlocked-io.h
761 lib/unsetenv.c 1175 lib/unsetenv.c
762 lib/vasnprintf.c 1176 lib/vasnprintf.c
763 lib/vasnprintf.h 1177 lib/vasnprintf.h
@@ -765,27 +1179,43 @@ AC_DEFUN([gl_FILE_LIST], [
765 lib/verify.h 1179 lib/verify.h
766 lib/vsnprintf.c 1180 lib/vsnprintf.c
767 lib/w32sock.h 1181 lib/w32sock.h
1182 lib/warn-on-use.h
768 lib/wchar.in.h 1183 lib/wchar.in.h
769 lib/wcrtomb.c 1184 lib/wcrtomb.c
770 lib/wctype-h.c 1185 lib/wctype-h.c
771 lib/wctype.in.h 1186 lib/wctype.in.h
1187 lib/windows-initguard.h
1188 lib/windows-mutex.c
1189 lib/windows-mutex.h
1190 lib/windows-once.c
1191 lib/windows-once.h
1192 lib/windows-recmutex.c
1193 lib/windows-recmutex.h
1194 lib/windows-rwlock.c
1195 lib/windows-rwlock.h
772 lib/xalloc-die.c 1196 lib/xalloc-die.c
773 lib/xalloc-oversized.h 1197 lib/xalloc-oversized.h
774 lib/xalloc.h 1198 lib/xalloc.h
775 lib/xmalloc.c 1199 lib/xmalloc.c
776 lib/xsize.c 1200 lib/xsize.c
777 lib/xsize.h 1201 lib/xsize.h
778 lib/xstrndup.c
779 lib/xstrndup.h
780 m4/00gnulib.m4 1202 m4/00gnulib.m4
1203 m4/__inline.m4
1204 m4/absolute-header.m4
1205 m4/af_alg.m4
781 m4/alloca.m4 1206 m4/alloca.m4
782 m4/arpa_inet_h.m4 1207 m4/arpa_inet_h.m4
1208 m4/assert_h.m4
783 m4/base64.m4 1209 m4/base64.m4
784 m4/btowc.m4 1210 m4/btowc.m4
1211 m4/builtin-expect.m4
1212 m4/byteswap.m4
1213 m4/c-bool.m4
1214 m4/calloc.m4
1215 m4/close.m4
785 m4/codeset.m4 1216 m4/codeset.m4
786 m4/configmake.m4
787 m4/dirname.m4
788 m4/double-slash-root.m4 1217 m4/double-slash-root.m4
1218 m4/dup2.m4
789 m4/eealloc.m4 1219 m4/eealloc.m4
790 m4/environ.m4 1220 m4/environ.m4
791 m4/errno_h.m4 1221 m4/errno_h.m4
@@ -794,37 +1224,42 @@ AC_DEFUN([gl_FILE_LIST], [
794 m4/extensions.m4 1224 m4/extensions.m4
795 m4/extern-inline.m4 1225 m4/extern-inline.m4
796 m4/fcntl-o.m4 1226 m4/fcntl-o.m4
1227 m4/fcntl.m4
1228 m4/fcntl_h.m4
1229 m4/fflush.m4
797 m4/float_h.m4 1230 m4/float_h.m4
798 m4/floorf.m4 1231 m4/floorf.m4
1232 m4/fopen.m4
1233 m4/fpurge.m4
1234 m4/freading.m4
1235 m4/free.m4
1236 m4/fseek.m4
1237 m4/fseeko.m4
1238 m4/fstat.m4
799 m4/fstypename.m4 1239 m4/fstypename.m4
800 m4/fsusage.m4 1240 m4/fsusage.m4
1241 m4/ftell.m4
1242 m4/ftello.m4
801 m4/getaddrinfo.m4 1243 m4/getaddrinfo.m4
1244 m4/getdelim.m4
1245 m4/getdtablesize.m4
802 m4/gethostname.m4 1246 m4/gethostname.m4
1247 m4/getline.m4
803 m4/getloadavg.m4 1248 m4/getloadavg.m4
804 m4/getopt.m4 1249 m4/getopt.m4
805 m4/gettext.m4 1250 m4/getprogname.m4
806 m4/glibc2.m4 1251 m4/gl-openssl.m4
807 m4/glibc21.m4
808 m4/gnulib-common.m4 1252 m4/gnulib-common.m4
809 m4/hostent.m4 1253 m4/hostent.m4
810 m4/iconv.m4
811 m4/idpriv.m4 1254 m4/idpriv.m4
812 m4/include_next.m4 1255 m4/include_next.m4
813 m4/inet_ntop.m4 1256 m4/inet_ntop.m4
814 m4/intdiv0.m4
815 m4/intl.m4
816 m4/intldir.m4
817 m4/intlmacosx.m4
818 m4/intmax.m4
819 m4/intmax_t.m4 1257 m4/intmax_t.m4
820 m4/inttypes-pri.m4 1258 m4/inttypes.m4
821 m4/inttypes_h.m4 1259 m4/inttypes_h.m4
822 m4/langinfo_h.m4 1260 m4/langinfo_h.m4
823 m4/largefile.m4 1261 m4/largefile.m4
824 m4/lcmessage.m4 1262 m4/limits-h.m4
825 m4/lib-ld.m4
826 m4/lib-link.m4
827 m4/lib-prefix.m4
828 m4/localcharset.m4 1263 m4/localcharset.m4
829 m4/locale-fr.m4 1264 m4/locale-fr.m4
830 m4/locale-ja.m4 1265 m4/locale-ja.m4
@@ -832,8 +1267,7 @@ AC_DEFUN([gl_FILE_LIST], [
832 m4/locale_h.m4 1267 m4/locale_h.m4
833 m4/localeconv.m4 1268 m4/localeconv.m4
834 m4/lock.m4 1269 m4/lock.m4
835 m4/longlong.m4 1270 m4/lseek.m4
836 m4/ls-mntd-fs.m4
837 m4/malloc.m4 1271 m4/malloc.m4
838 m4/malloca.m4 1272 m4/malloca.m4
839 m4/math_h.m4 1273 m4/math_h.m4
@@ -842,8 +1276,10 @@ AC_DEFUN([gl_FILE_LIST], [
842 m4/mbstate_t.m4 1276 m4/mbstate_t.m4
843 m4/mbtowc.m4 1277 m4/mbtowc.m4
844 m4/memchr.m4 1278 m4/memchr.m4
1279 m4/minmax.m4
845 m4/mktime.m4 1280 m4/mktime.m4
846 m4/mmap-anon.m4 1281 m4/mmap-anon.m4
1282 m4/mode_t.m4
847 m4/mountlist.m4 1283 m4/mountlist.m4
848 m4/msvc-inval.m4 1284 m4/msvc-inval.m4
849 m4/msvc-nothrow.m4 1285 m4/msvc-nothrow.m4
@@ -851,20 +1287,22 @@ AC_DEFUN([gl_FILE_LIST], [
851 m4/netdb_h.m4 1287 m4/netdb_h.m4
852 m4/netinet_in_h.m4 1288 m4/netinet_in_h.m4
853 m4/nl_langinfo.m4 1289 m4/nl_langinfo.m4
854 m4/nls.m4
855 m4/nocrash.m4 1290 m4/nocrash.m4
856 m4/off_t.m4 1291 m4/off_t.m4
857 m4/onceonly.m4 1292 m4/open-cloexec.m4
858 m4/po.m4 1293 m4/open-slash.m4
859 m4/printf-posix.m4 1294 m4/open.m4
1295 m4/pathmax.m4
1296 m4/pid_t.m4
860 m4/printf.m4 1297 m4/printf.m4
861 m4/progtest.m4 1298 m4/pthread_rwlock_rdlock.m4
862 m4/read.m4 1299 m4/realloc.m4
1300 m4/reallocarray.m4
863 m4/regex.m4 1301 m4/regex.m4
864 m4/safe-read.m4
865 m4/servent.m4 1302 m4/servent.m4
866 m4/setenv.m4 1303 m4/setenv.m4
867 m4/sha1.m4 1304 m4/setlocale_null.m4
1305 m4/sha256.m4
868 m4/size_max.m4 1306 m4/size_max.m4
869 m4/snprintf.m4 1307 m4/snprintf.m4
870 m4/socketlib.m4 1308 m4/socketlib.m4
@@ -872,8 +1310,10 @@ AC_DEFUN([gl_FILE_LIST], [
872 m4/socklen.m4 1310 m4/socklen.m4
873 m4/sockpfaf.m4 1311 m4/sockpfaf.m4
874 m4/ssize_t.m4 1312 m4/ssize_t.m4
1313 m4/stat-time.m4
1314 m4/stat.m4
1315 m4/std-gnu11.m4
875 m4/stdalign.m4 1316 m4/stdalign.m4
876 m4/stdbool.m4
877 m4/stddef_h.m4 1317 m4/stddef_h.m4
878 m4/stdint.m4 1318 m4/stdint.m4
879 m4/stdint_h.m4 1319 m4/stdint_h.m4
@@ -884,19 +1324,20 @@ AC_DEFUN([gl_FILE_LIST], [
884 m4/strerror.m4 1324 m4/strerror.m4
885 m4/string_h.m4 1325 m4/string_h.m4
886 m4/strings_h.m4 1326 m4/strings_h.m4
887 m4/strndup.m4
888 m4/strnlen.m4
889 m4/strsep.m4 1327 m4/strsep.m4
890 m4/strstr.m4 1328 m4/strstr.m4
891 m4/sys_socket_h.m4 1329 m4/sys_socket_h.m4
1330 m4/sys_stat_h.m4
892 m4/sys_types_h.m4 1331 m4/sys_types_h.m4
893 m4/sys_uio_h.m4 1332 m4/sys_uio_h.m4
894 m4/threadlib.m4 1333 m4/threadlib.m4
895 m4/time_h.m4 1334 m4/time_h.m4
896 m4/time_r.m4 1335 m4/time_r.m4
897 m4/timegm.m4 1336 m4/timegm.m4
898 m4/uintmax_t.m4 1337 m4/ungetc.m4
899 m4/unistd_h.m4 1338 m4/unistd_h.m4
1339 m4/unlocked-io.m4
1340 m4/vararrays.m4
900 m4/vasnprintf.m4 1341 m4/vasnprintf.m4
901 m4/vasprintf.m4 1342 m4/vasprintf.m4
902 m4/visibility.m4 1343 m4/visibility.m4
@@ -909,5 +1350,5 @@ AC_DEFUN([gl_FILE_LIST], [
909 m4/wint_t.m4 1350 m4/wint_t.m4
910 m4/xalloc.m4 1351 m4/xalloc.m4
911 m4/xsize.m4 1352 m4/xsize.m4
912 m4/xstrndup.m4 1353 m4/zzgnulib.m4
913]) 1354])
diff --git a/gl/m4/gnulib-tool.m4 b/gl/m4/gnulib-tool.m4
index f3dea1a..a9dd569 100644
--- a/gl/m4/gnulib-tool.m4
+++ b/gl/m4/gnulib-tool.m4
@@ -1,5 +1,5 @@
1# gnulib-tool.m4 serial 2 1# gnulib-tool.m4 serial 4
2dnl Copyright (C) 2004-2005, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2005, 2009-2023 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.
@@ -44,6 +44,12 @@ AC_DEFUN([gl_LGPL], [])
44dnl Usage: gl_MAKEFILE_NAME([FILENAME]) 44dnl Usage: gl_MAKEFILE_NAME([FILENAME])
45AC_DEFUN([gl_MAKEFILE_NAME], []) 45AC_DEFUN([gl_MAKEFILE_NAME], [])
46 46
47dnl Usage: gl_TESTS_MAKEFILE_NAME([FILENAME])
48AC_DEFUN([gl_TESTS_MAKEFILE_NAME], [])
49
50dnl Usage: gl_AUTOMAKE_SUBDIR
51AC_DEFUN([gl_AUTOMAKE_SUBDIR], [])
52
47dnl Usage: gl_LIBTOOL 53dnl Usage: gl_LIBTOOL
48AC_DEFUN([gl_LIBTOOL], []) 54AC_DEFUN([gl_LIBTOOL], [])
49 55
diff --git a/gl/m4/hostent.m4 b/gl/m4/hostent.m4
index 72be876..3b2cc2b 100644
--- a/gl/m4/hostent.m4
+++ b/gl/m4/hostent.m4
@@ -1,5 +1,5 @@
1# hostent.m4 serial 2 1# hostent.m4 serial 4
2dnl Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2010-2023 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,12 +8,12 @@ AC_DEFUN([gl_HOSTENT],
8[ 8[
9 dnl Where are gethostent(), sethostent(), endhostent(), gethostbyname(), 9 dnl Where are gethostent(), sethostent(), endhostent(), gethostbyname(),
10 dnl gethostbyaddr() defined? 10 dnl gethostbyaddr() defined?
11 dnl - On Solaris, they are in libnsl. Ignore libxnet. 11 dnl - On Solaris < 11.4, they are in libnsl. Ignore libxnet.
12 dnl - On Haiku, they are in libnetwork. 12 dnl - On Haiku, they are in libnetwork.
13 dnl - On BeOS, they are in libnet. 13 dnl - On BeOS, they are in libnet.
14 dnl - On native Windows, they are in ws2_32.dll. 14 dnl - On native Windows, they are in ws2_32.dll.
15 dnl - Otherwise they are in libc. 15 dnl - Otherwise they are in libc.
16 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H 16 AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
17 HOSTENT_LIB= 17 HOSTENT_LIB=
18 gl_saved_libs="$LIBS" 18 gl_saved_libs="$LIBS"
19 AC_SEARCH_LIBS([gethostbyname], [nsl network net], 19 AC_SEARCH_LIBS([gethostbyname], [nsl network net],
diff --git a/gl/m4/iconv.m4 b/gl/m4/iconv.m4
deleted file mode 100644
index a503646..0000000
--- a/gl/m4/iconv.m4
+++ /dev/null
@@ -1,268 +0,0 @@
1# iconv.m4 serial 18 (gettext-0.18.2)
2dnl Copyright (C) 2000-2002, 2007-2013 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.
8
9AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
10[
11 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
12 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
13 AC_REQUIRE([AC_LIB_RPATH])
14
15 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
16 dnl accordingly.
17 AC_LIB_LINKFLAGS_BODY([iconv])
18])
19
20AC_DEFUN([AM_ICONV_LINK],
21[
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).
24 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
25
26 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
27 dnl accordingly.
28 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
29
30 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
31 dnl because if the user has installed libiconv and not disabled its use
32 dnl via --without-libiconv-prefix, he wants to use it. The first
33 dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
34 am_save_CPPFLAGS="$CPPFLAGS"
35 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
36
37 AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
38 am_cv_func_iconv="no, consider installing GNU libiconv"
39 am_cv_lib_iconv=no
40 AC_LINK_IFELSE(
41 [AC_LANG_PROGRAM(
42 [[
43#include <stdlib.h>
44#include <iconv.h>
45 ]],
46 [[iconv_t cd = iconv_open("","");
47 iconv(cd,NULL,NULL,NULL,NULL);
48 iconv_close(cd);]])],
49 [am_cv_func_iconv=yes])
50 if test "$am_cv_func_iconv" != yes; then
51 am_save_LIBS="$LIBS"
52 LIBS="$LIBS $LIBICONV"
53 AC_LINK_IFELSE(
54 [AC_LANG_PROGRAM(
55 [[
56#include <stdlib.h>
57#include <iconv.h>
58 ]],
59 [[iconv_t cd = iconv_open("","");
60 iconv(cd,NULL,NULL,NULL,NULL);
61 iconv_close(cd);]])],
62 [am_cv_lib_iconv=yes]
63 [am_cv_func_iconv=yes])
64 LIBS="$am_save_LIBS"
65 fi
66 ])
67 if test "$am_cv_func_iconv" = yes; then
68 AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
69 dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
70 dnl Solaris 10.
71 am_save_LIBS="$LIBS"
72 if test $am_cv_lib_iconv = yes; then
73 LIBS="$LIBS $LIBICONV"
74 fi
75 AC_RUN_IFELSE(
76 [AC_LANG_SOURCE([[
77#include <iconv.h>
78#include <string.h>
79int main ()
80{
81 int result = 0;
82 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
83 returns. */
84 {
85 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
86 if (cd_utf8_to_88591 != (iconv_t)(-1))
87 {
88 static const char input[] = "\342\202\254"; /* EURO SIGN */
89 char buf[10];
90 const char *inptr = input;
91 size_t inbytesleft = strlen (input);
92 char *outptr = buf;
93 size_t outbytesleft = sizeof (buf);
94 size_t res = iconv (cd_utf8_to_88591,
95 (char **) &inptr, &inbytesleft,
96 &outptr, &outbytesleft);
97 if (res == 0)
98 result |= 1;
99 iconv_close (cd_utf8_to_88591);
100 }
101 }
102 /* Test against Solaris 10 bug: Failures are not distinguishable from
103 successful returns. */
104 {
105 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
106 if (cd_ascii_to_88591 != (iconv_t)(-1))
107 {
108 static const char input[] = "\263";
109 char buf[10];
110 const char *inptr = input;
111 size_t inbytesleft = strlen (input);
112 char *outptr = buf;
113 size_t outbytesleft = sizeof (buf);
114 size_t res = iconv (cd_ascii_to_88591,
115 (char **) &inptr, &inbytesleft,
116 &outptr, &outbytesleft);
117 if (res == 0)
118 result |= 2;
119 iconv_close (cd_ascii_to_88591);
120 }
121 }
122 /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
123 {
124 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
125 if (cd_88591_to_utf8 != (iconv_t)(-1))
126 {
127 static const char input[] = "\304";
128 static char buf[2] = { (char)0xDE, (char)0xAD };
129 const char *inptr = input;
130 size_t inbytesleft = 1;
131 char *outptr = buf;
132 size_t outbytesleft = 1;
133 size_t res = iconv (cd_88591_to_utf8,
134 (char **) &inptr, &inbytesleft,
135 &outptr, &outbytesleft);
136 if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
137 result |= 4;
138 iconv_close (cd_88591_to_utf8);
139 }
140 }
141#if 0 /* This bug could be worked around by the caller. */
142 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
143 {
144 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
145 if (cd_88591_to_utf8 != (iconv_t)(-1))
146 {
147 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
148 char buf[50];
149 const char *inptr = input;
150 size_t inbytesleft = strlen (input);
151 char *outptr = buf;
152 size_t outbytesleft = sizeof (buf);
153 size_t res = iconv (cd_88591_to_utf8,
154 (char **) &inptr, &inbytesleft,
155 &outptr, &outbytesleft);
156 if ((int)res > 0)
157 result |= 8;
158 iconv_close (cd_88591_to_utf8);
159 }
160 }
161#endif
162 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
163 provided. */
164 if (/* Try standardized names. */
165 iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
166 /* Try IRIX, OSF/1 names. */
167 && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
168 /* Try AIX names. */
169 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
170 /* Try HP-UX names. */
171 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
172 result |= 16;
173 return result;
174}]])],
175 [am_cv_func_iconv_works=yes],
176 [am_cv_func_iconv_works=no],
177 [
178changequote(,)dnl
179 case "$host_os" in
180 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
181 *) am_cv_func_iconv_works="guessing yes" ;;
182 esac
183changequote([,])dnl
184 ])
185 LIBS="$am_save_LIBS"
186 ])
187 case "$am_cv_func_iconv_works" in
188 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
189 *) am_func_iconv=yes ;;
190 esac
191 else
192 am_func_iconv=no am_cv_lib_iconv=no
193 fi
194 if test "$am_func_iconv" = yes; then
195 AC_DEFINE([HAVE_ICONV], [1],
196 [Define if you have the iconv() function and it works.])
197 fi
198 if test "$am_cv_lib_iconv" = yes; then
199 AC_MSG_CHECKING([how to link with libiconv])
200 AC_MSG_RESULT([$LIBICONV])
201 else
202 dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
203 dnl either.
204 CPPFLAGS="$am_save_CPPFLAGS"
205 LIBICONV=
206 LTLIBICONV=
207 fi
208 AC_SUBST([LIBICONV])
209 AC_SUBST([LTLIBICONV])
210])
211
212dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
213dnl avoid warnings like
214dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
215dnl This is tricky because of the way 'aclocal' is implemented:
216dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
217dnl Otherwise aclocal's initial scan pass would miss the macro definition.
218dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
219dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
220dnl warnings.
221m4_define([gl_iconv_AC_DEFUN],
222 m4_version_prereq([2.64],
223 [[AC_DEFUN_ONCE(
224 [$1], [$2])]],
225 [m4_ifdef([gl_00GNULIB],
226 [[AC_DEFUN_ONCE(
227 [$1], [$2])]],
228 [[AC_DEFUN(
229 [$1], [$2])]])]))
230gl_iconv_AC_DEFUN([AM_ICONV],
231[
232 AM_ICONV_LINK
233 if test "$am_cv_func_iconv" = yes; then
234 AC_MSG_CHECKING([for iconv declaration])
235 AC_CACHE_VAL([am_cv_proto_iconv], [
236 AC_COMPILE_IFELSE(
237 [AC_LANG_PROGRAM(
238 [[
239#include <stdlib.h>
240#include <iconv.h>
241extern
242#ifdef __cplusplus
243"C"
244#endif
245#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
246size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
247#else
248size_t iconv();
249#endif
250 ]],
251 [[]])],
252 [am_cv_proto_iconv_arg1=""],
253 [am_cv_proto_iconv_arg1="const"])
254 am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
255 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
256 AC_MSG_RESULT([
257 $am_cv_proto_iconv])
258 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
259 [Define as const if the declaration of iconv() needs const.])
260 dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
261 m4_ifdef([gl_ICONV_H_DEFAULTS],
262 [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
263 if test -n "$am_cv_proto_iconv_arg1"; then
264 ICONV_CONST="const"
265 fi
266 ])
267 fi
268])
diff --git a/gl/m4/idpriv.m4 b/gl/m4/idpriv.m4
index 167f523..fc3dd17 100644
--- a/gl/m4/idpriv.m4
+++ b/gl/m4/idpriv.m4
@@ -1,5 +1,5 @@
1# idpriv.m4 serial 1 1# idpriv.m4 serial 1
2dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4
index 108d945..9f19215 100644
--- a/gl/m4/include_next.m4
+++ b/gl/m4/include_next.m4
@@ -1,12 +1,13 @@
1# include_next.m4 serial 23 1# include_next.m4 serial 26
2dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2023 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 From Paul Eggert and Derek Price. 7dnl From Paul Eggert and Derek Price.
8 8
9dnl Sets INCLUDE_NEXT and PRAGMA_SYSTEM_HEADER. 9dnl Sets INCLUDE_NEXT, INCLUDE_NEXT_AS_FIRST_DIRECTIVE, PRAGMA_SYSTEM_HEADER,
10dnl and PRAGMA_COLUMNS.
10dnl 11dnl
11dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to 12dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
12dnl 'include' otherwise. 13dnl 'include' otherwise.
@@ -105,19 +106,21 @@ dnl We intentionally avoid using AC_LANG_SOURCE here.
105 AC_SUBST([INCLUDE_NEXT]) 106 AC_SUBST([INCLUDE_NEXT])
106 AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE]) 107 AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
107 AC_SUBST([PRAGMA_SYSTEM_HEADER]) 108 AC_SUBST([PRAGMA_SYSTEM_HEADER])
108 AC_CACHE_CHECK([whether system header files limit the line length], 109
109 [gl_cv_pragma_columns], 110 dnl HP NonStop systems, which define __TANDEM, limit the line length
110 [dnl HP NonStop systems, which define __TANDEM, have this misfeature. 111 dnl after including some system header files.
111 AC_EGREP_CPP([choke me], 112 AC_CACHE_CHECK([whether source code line length is unlimited],
113 [gl_cv_source_line_length_unlimited],
114 [AC_EGREP_CPP([choke me],
112 [ 115 [
113#ifdef __TANDEM 116#ifdef __TANDEM
114choke me 117choke me
115#endif 118#endif
116 ], 119 ],
117 [gl_cv_pragma_columns=yes], 120 [gl_cv_source_line_length_unlimited=no],
118 [gl_cv_pragma_columns=no]) 121 [gl_cv_source_line_length_unlimited=yes])
119 ]) 122 ])
120 if test $gl_cv_pragma_columns = yes; then 123 if test $gl_cv_source_line_length_unlimited = no; then
121 PRAGMA_COLUMNS="#pragma COLUMNS 10000" 124 PRAGMA_COLUMNS="#pragma COLUMNS 10000"
122 else 125 else
123 PRAGMA_COLUMNS= 126 PRAGMA_COLUMNS=
@@ -175,89 +178,40 @@ AC_DEFUN([gl_NEXT_HEADERS_INTERNAL],
175 [AC_CHECK_HEADERS_ONCE([$1]) 178 [AC_CHECK_HEADERS_ONCE([$1])
176 ]) 179 ])
177 180
178dnl FIXME: gl_next_header and gl_header_exists must be used unquoted
179dnl until we can assume autoconf 2.64 or newer.
180 m4_foreach_w([gl_HEADER_NAME], [$1], 181 m4_foreach_w([gl_HEADER_NAME], [$1],
181 [AS_VAR_PUSHDEF([gl_next_header], 182 [AS_VAR_PUSHDEF([gl_next_header],
182 [gl_cv_next_]m4_defn([gl_HEADER_NAME])) 183 [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
183 if test $gl_cv_have_include_next = yes; then 184 if test $gl_cv_have_include_next = yes; then
184 AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>']) 185 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
185 else 186 else
186 AC_CACHE_CHECK( 187 AC_CACHE_CHECK(
187 [absolute name of <]m4_defn([gl_HEADER_NAME])[>], 188 [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
188 m4_defn([gl_next_header]), 189 [gl_next_header],
189 [m4_if([$2], [check], 190 [m4_if([$2], [check],
190 [AS_VAR_PUSHDEF([gl_header_exists], 191 [AS_VAR_PUSHDEF([gl_header_exists],
191 [ac_cv_header_]m4_defn([gl_HEADER_NAME])) 192 [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
192 if test AS_VAR_GET(gl_header_exists) = yes; then 193 if test AS_VAR_GET([gl_header_exists]) = yes; then
193 AS_VAR_POPDEF([gl_header_exists]) 194 AS_VAR_POPDEF([gl_header_exists])
194 ]) 195 ])
195 AC_LANG_CONFTEST( 196 gl_ABSOLUTE_HEADER_ONE(gl_HEADER_NAME)
196 [AC_LANG_SOURCE( 197 AS_VAR_COPY([gl_header], [gl_cv_absolute_]AS_TR_SH(gl_HEADER_NAME))
197 [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] 198 AS_VAR_SET([gl_next_header], ['"'$gl_header'"'])
198 )])
199 dnl AIX "xlc -E" and "cc -E" omit #line directives for header
200 dnl files that contain only a #include of other header files and
201 dnl no non-comment tokens of their own. This leads to a failure
202 dnl to detect the absolute name of <dirent.h>, <signal.h>,
203 dnl <poll.h> and others. The workaround is to force preservation
204 dnl of comments through option -C. This ensures all necessary
205 dnl #line directives are present. GCC supports option -C as well.
206 case "$host_os" in
207 aix*) gl_absname_cpp="$ac_cpp -C" ;;
208 *) gl_absname_cpp="$ac_cpp" ;;
209 esac
210changequote(,)
211 case "$host_os" in
212 mingw*)
213 dnl For the sake of native Windows compilers (excluding gcc),
214 dnl treat backslash as a directory separator, like /.
215 dnl Actually, these compilers use a double-backslash as
216 dnl directory separator, inside the
217 dnl # line "filename"
218 dnl directives.
219 gl_dirsep_regex='[/\\]'
220 ;;
221 *)
222 gl_dirsep_regex='\/'
223 ;;
224 esac
225 dnl A sed expression that turns a string into a basic regular
226 dnl expression, for use within "/.../".
227 gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
228changequote([,])
229 gl_header_literal_regex=`echo ']m4_defn([gl_HEADER_NAME])[' \
230 | sed -e "$gl_make_literal_regex_sed"`
231 gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
232 s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
233changequote(,)dnl
234 s|^/[^/]|//&|
235changequote([,])dnl
236 p
237 q
238 }'
239 dnl eval is necessary to expand gl_absname_cpp.
240 dnl Ultrix and Pyramid sh refuse to redirect output of eval,
241 dnl so use subshell.
242 AS_VAR_SET(gl_next_header,
243 ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
244 sed -n "$gl_absolute_header_sed"`'"'])
245 m4_if([$2], [check], 199 m4_if([$2], [check],
246 [else 200 [else
247 AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>']) 201 AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
248 fi 202 fi
249 ]) 203 ])
250 ]) 204 ])
251 fi 205 fi
252 AC_SUBST( 206 AC_SUBST(
253 AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])), 207 AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
254 [AS_VAR_GET(gl_next_header)]) 208 [AS_VAR_GET([gl_next_header])])
255 if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then 209 if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
256 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next' 210 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
257 gl_next_as_first_directive='<'gl_HEADER_NAME'>' 211 gl_next_as_first_directive='<'gl_HEADER_NAME'>'
258 else 212 else
259 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include' 213 # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
260 gl_next_as_first_directive=AS_VAR_GET(gl_next_header) 214 gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
261 fi 215 fi
262 AC_SUBST( 216 AC_SUBST(
263 AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])), 217 AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4
index 476f063..48822d6 100644
--- a/gl/m4/inet_ntop.m4
+++ b/gl/m4/inet_ntop.m4
@@ -1,5 +1,5 @@
1# inet_ntop.m4 serial 19 1# inet_ntop.m4 serial 21
2dnl Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2006, 2008-2023 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,6 +16,7 @@ AC_DEFUN([gl_FUNC_INET_NTOP],
16 dnl Most platforms that provide inet_ntop define it in libc. 16 dnl Most platforms that provide inet_ntop define it in libc.
17 dnl Solaris 8..10 provide inet_ntop in libnsl instead. 17 dnl Solaris 8..10 provide inet_ntop in libnsl instead.
18 dnl Solaris 2.6..7 provide inet_ntop in libresolv instead. 18 dnl Solaris 2.6..7 provide inet_ntop in libresolv instead.
19 dnl Haiku provides it in -lnetwork.
19 dnl Native Windows provides it in -lws2_32 instead, with a declaration in 20 dnl Native Windows provides it in -lws2_32 instead, with a declaration in
20 dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl 21 dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
21 dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it). 22 dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
@@ -23,19 +24,20 @@ AC_DEFUN([gl_FUNC_INET_NTOP],
23 INET_NTOP_LIB= 24 INET_NTOP_LIB=
24 gl_PREREQ_SYS_H_WINSOCK2 25 gl_PREREQ_SYS_H_WINSOCK2
25 if test $HAVE_WINSOCK2_H = 1; then 26 if test $HAVE_WINSOCK2_H = 1; then
27 dnl It needs to be overridden, because the stdcall calling convention
28 dnl is not compliant with POSIX. Set REPLACE_INET_NTOP in order to avoid
29 dnl a name conflict at the linker level, even though the header file
30 dnl <ws2tcpip.h> declares inet_ntop only if _WIN32_WINNT >= 0x0600.
31 REPLACE_INET_NTOP=1
26 AC_CHECK_DECLS([inet_ntop],,, [[#include <ws2tcpip.h>]]) 32 AC_CHECK_DECLS([inet_ntop],,, [[#include <ws2tcpip.h>]])
27 if test $ac_cv_have_decl_inet_ntop = yes; then 33 if test $ac_cv_have_decl_inet_ntop = yes; then
28 dnl It needs to be overridden, because the stdcall calling convention
29 dnl is not compliant with POSIX.
30 REPLACE_INET_NTOP=1
31 INET_NTOP_LIB="-lws2_32" 34 INET_NTOP_LIB="-lws2_32"
32 else 35 else
33 HAVE_DECL_INET_NTOP=0 36 HAVE_DECL_INET_NTOP=0
34 HAVE_INET_NTOP=0
35 fi 37 fi
36 else 38 else
37 gl_save_LIBS=$LIBS 39 gl_save_LIBS=$LIBS
38 AC_SEARCH_LIBS([inet_ntop], [nsl resolv], [], 40 AC_SEARCH_LIBS([inet_ntop], [nsl resolv network], [],
39 [AC_CHECK_FUNCS([inet_ntop]) 41 [AC_CHECK_FUNCS([inet_ntop])
40 if test $ac_cv_func_inet_ntop = no; then 42 if test $ac_cv_func_inet_ntop = no; then
41 HAVE_INET_NTOP=0 43 HAVE_INET_NTOP=0
diff --git a/gl/m4/intdiv0.m4 b/gl/m4/intdiv0.m4
deleted file mode 100644
index 74d0e80..0000000
--- a/gl/m4/intdiv0.m4
+++ /dev/null
@@ -1,87 +0,0 @@
1# intdiv0.m4 serial 6 (gettext-0.18.2)
2dnl Copyright (C) 2002, 2007-2008, 2010-2013 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.
8
9AC_DEFUN([gt_INTDIV0],
10[
11 AC_REQUIRE([AC_PROG_CC])dnl
12 AC_REQUIRE([AC_CANONICAL_HOST])dnl
13
14 AC_CACHE_CHECK([whether integer division by zero raises SIGFPE],
15 gt_cv_int_divbyzero_sigfpe,
16 [
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 Mac OS 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_RUN_IFELSE(
33 [AC_LANG_SOURCE([[
34#include <stdlib.h>
35#include <signal.h>
36
37static void
38sigfpe_handler (int sig)
39{
40 /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */
41 exit (sig != SIGFPE);
42}
43
44int x = 1;
45int y = 0;
46int z;
47int nan;
48
49int main ()
50{
51 signal (SIGFPE, sigfpe_handler);
52/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */
53#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP)
54 signal (SIGTRAP, sigfpe_handler);
55#endif
56/* Linux/SPARC yields signal SIGILL. */
57#if defined (__sparc__) && defined (__linux__)
58 signal (SIGILL, sigfpe_handler);
59#endif
60
61 z = x / y;
62 nan = y / y;
63 exit (2);
64}
65]])],
66 [gt_cv_int_divbyzero_sigfpe=yes],
67 [gt_cv_int_divbyzero_sigfpe=no],
68 [
69 # Guess based on the CPU.
70changequote(,)dnl
71 case "$host_cpu" in
72 alpha* | i[34567]86 | x86_64 | m68k | s390*)
73 gt_cv_int_divbyzero_sigfpe="guessing yes";;
74 *)
75 gt_cv_int_divbyzero_sigfpe="guessing no";;
76 esac
77changequote([,])dnl
78 ])
79 fi
80 ])
81 case "$gt_cv_int_divbyzero_sigfpe" in
82 *yes) value=1;;
83 *) value=0;;
84 esac
85 AC_DEFINE_UNQUOTED([INTDIV0_RAISES_SIGFPE], [$value],
86 [Define if integer division by zero raises signal SIGFPE.])
87])
diff --git a/gl/m4/intl.m4 b/gl/m4/intl.m4
deleted file mode 100644
index 959bd04..0000000
--- a/gl/m4/intl.m4
+++ /dev/null
@@ -1,271 +0,0 @@
1# intl.m4 serial 23 (gettext-0.18.3)
2dnl Copyright (C) 1995-2013 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 Authors:
17dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
18dnl Bruno Haible <haible@clisp.cons.org>, 2000-2009.
19
20AC_PREREQ([2.60])
21
22dnl Checks for all prerequisites of the intl subdirectory,
23dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS,
24dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL.
25AC_DEFUN([AM_INTL_SUBDIR],
26[
27 AC_REQUIRE([AC_PROG_INSTALL])dnl
28 AC_REQUIRE([AC_PROG_MKDIR_P])dnl
29 AC_REQUIRE([AC_PROG_CC])dnl
30 AC_REQUIRE([AC_CANONICAL_HOST])dnl
31 AC_REQUIRE([gt_GLIBC2])dnl
32 AC_REQUIRE([AC_PROG_RANLIB])dnl
33 AC_REQUIRE([gl_VISIBILITY])dnl
34 AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl
35 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl
36 AC_REQUIRE([gt_TYPE_WCHAR_T])dnl
37 AC_REQUIRE([gt_TYPE_WINT_T])dnl
38 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
39 AC_REQUIRE([gt_TYPE_INTMAX_T])
40 AC_REQUIRE([gt_PRINTF_POSIX])
41 AC_REQUIRE([gl_GLIBC21])dnl
42 AC_REQUIRE([gl_XSIZE])dnl
43 AC_REQUIRE([gl_FCNTL_O_FLAGS])dnl
44 AC_REQUIRE([gt_INTL_MACOSX])dnl
45
46 dnl Support for automake's --enable-silent-rules.
47 case "$enable_silent_rules" in
48 yes) INTL_DEFAULT_VERBOSITY=0;;
49 no) INTL_DEFAULT_VERBOSITY=1;;
50 *) INTL_DEFAULT_VERBOSITY=1;;
51 esac
52 AC_SUBST([INTL_DEFAULT_VERBOSITY])
53
54 AC_CHECK_TYPE([ptrdiff_t], ,
55 [AC_DEFINE([ptrdiff_t], [long],
56 [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
57 ])
58 AC_CHECK_HEADERS([features.h stddef.h stdlib.h string.h])
59 AC_CHECK_FUNCS([asprintf fwprintf newlocale putenv setenv setlocale \
60 snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
61
62 dnl Use the _snprintf function only if it is declared (because on NetBSD it
63 dnl is defined as a weak alias of snprintf; we prefer to use the latter).
64 AC_CHECK_DECLS([_snprintf _snwprintf], , , [#include <stdio.h>])
65
66 dnl Use the *_unlocked functions only if they are declared.
67 dnl (because some of them were defined without being declared in Solaris
68 dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
69 dnl on Solaris 2.5.1 to run on Solaris 2.6).
70 AC_CHECK_DECLS([getc_unlocked], , , [#include <stdio.h>])
71
72 case $gt_cv_func_printf_posix in
73 *yes) HAVE_POSIX_PRINTF=1 ;;
74 *) HAVE_POSIX_PRINTF=0 ;;
75 esac
76 AC_SUBST([HAVE_POSIX_PRINTF])
77 if test "$ac_cv_func_asprintf" = yes; then
78 HAVE_ASPRINTF=1
79 else
80 HAVE_ASPRINTF=0
81 fi
82 AC_SUBST([HAVE_ASPRINTF])
83 if test "$ac_cv_func_snprintf" = yes; then
84 HAVE_SNPRINTF=1
85 else
86 HAVE_SNPRINTF=0
87 fi
88 AC_SUBST([HAVE_SNPRINTF])
89 if test "$ac_cv_func_newlocale" = yes; then
90 HAVE_NEWLOCALE=1
91 else
92 HAVE_NEWLOCALE=0
93 fi
94 AC_SUBST([HAVE_NEWLOCALE])
95 if test "$ac_cv_func_wprintf" = yes; then
96 HAVE_WPRINTF=1
97 else
98 HAVE_WPRINTF=0
99 fi
100 AC_SUBST([HAVE_WPRINTF])
101
102 AM_LANGINFO_CODESET
103 gt_LC_MESSAGES
104
105 dnl Compilation on mingw and Cygwin needs special Makefile rules, because
106 dnl 1. when we install a shared library, we must arrange to export
107 dnl auxiliary pointer variables for every exported variable,
108 dnl 2. when we install a shared library and a static library simultaneously,
109 dnl the include file specifies __declspec(dllimport) and therefore we
110 dnl must arrange to define the auxiliary pointer variables for the
111 dnl exported variables _also_ in the static library.
112 if test "$enable_shared" = yes; then
113 case "$host_os" in
114 mingw* | cygwin*) is_woe32dll=yes ;;
115 *) is_woe32dll=no ;;
116 esac
117 else
118 is_woe32dll=no
119 fi
120 WOE32DLL=$is_woe32dll
121 AC_SUBST([WOE32DLL])
122
123 dnl On mingw and Cygwin, we can activate special Makefile rules which add
124 dnl version information to the shared libraries and executables.
125 case "$host_os" in
126 mingw* | cygwin*) is_woe32=yes ;;
127 *) is_woe32=no ;;
128 esac
129 WOE32=$is_woe32
130 AC_SUBST([WOE32])
131 if test $WOE32 = yes; then
132 dnl Check for a program that compiles Windows resource files.
133 AC_CHECK_TOOL([WINDRES], [windres])
134 fi
135
136 dnl Determine whether when creating a library, "-lc" should be passed to
137 dnl libtool or not. On many platforms, it is required for the libtool option
138 dnl -no-undefined to work. On HP-UX, however, the -lc - stored by libtool
139 dnl in the *.la files - makes it impossible to create multithreaded programs,
140 dnl because libtool also reorders the -lc to come before the -pthread, and
141 dnl this disables pthread_create() <http://docs.hp.com/en/1896/pthreads.html>.
142 case "$host_os" in
143 hpux*) LTLIBC="" ;;
144 *) LTLIBC="-lc" ;;
145 esac
146 AC_SUBST([LTLIBC])
147
148 dnl Rename some macros and functions used for locking.
149 AH_BOTTOM([
150#define __libc_lock_t gl_lock_t
151#define __libc_lock_define gl_lock_define
152#define __libc_lock_define_initialized gl_lock_define_initialized
153#define __libc_lock_init gl_lock_init
154#define __libc_lock_lock gl_lock_lock
155#define __libc_lock_unlock gl_lock_unlock
156#define __libc_lock_recursive_t gl_recursive_lock_t
157#define __libc_lock_define_recursive gl_recursive_lock_define
158#define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized
159#define __libc_lock_init_recursive gl_recursive_lock_init
160#define __libc_lock_lock_recursive gl_recursive_lock_lock
161#define __libc_lock_unlock_recursive gl_recursive_lock_unlock
162#define glthread_in_use libintl_thread_in_use
163#define glthread_lock_init_func libintl_lock_init_func
164#define glthread_lock_lock_func libintl_lock_lock_func
165#define glthread_lock_unlock_func libintl_lock_unlock_func
166#define glthread_lock_destroy_func libintl_lock_destroy_func
167#define glthread_rwlock_init_multithreaded libintl_rwlock_init_multithreaded
168#define glthread_rwlock_init_func libintl_rwlock_init_func
169#define glthread_rwlock_rdlock_multithreaded libintl_rwlock_rdlock_multithreaded
170#define glthread_rwlock_rdlock_func libintl_rwlock_rdlock_func
171#define glthread_rwlock_wrlock_multithreaded libintl_rwlock_wrlock_multithreaded
172#define glthread_rwlock_wrlock_func libintl_rwlock_wrlock_func
173#define glthread_rwlock_unlock_multithreaded libintl_rwlock_unlock_multithreaded
174#define glthread_rwlock_unlock_func libintl_rwlock_unlock_func
175#define glthread_rwlock_destroy_multithreaded libintl_rwlock_destroy_multithreaded
176#define glthread_rwlock_destroy_func libintl_rwlock_destroy_func
177#define glthread_recursive_lock_init_multithreaded libintl_recursive_lock_init_multithreaded
178#define glthread_recursive_lock_init_func libintl_recursive_lock_init_func
179#define glthread_recursive_lock_lock_multithreaded libintl_recursive_lock_lock_multithreaded
180#define glthread_recursive_lock_lock_func libintl_recursive_lock_lock_func
181#define glthread_recursive_lock_unlock_multithreaded libintl_recursive_lock_unlock_multithreaded
182#define glthread_recursive_lock_unlock_func libintl_recursive_lock_unlock_func
183#define glthread_recursive_lock_destroy_multithreaded libintl_recursive_lock_destroy_multithreaded
184#define glthread_recursive_lock_destroy_func libintl_recursive_lock_destroy_func
185#define glthread_once_func libintl_once_func
186#define glthread_once_singlethreaded libintl_once_singlethreaded
187#define glthread_once_multithreaded libintl_once_multithreaded
188])
189])
190
191
192dnl Checks for the core files of the intl subdirectory:
193dnl dcigettext.c
194dnl eval-plural.h
195dnl explodename.c
196dnl finddomain.c
197dnl gettextP.h
198dnl gmo.h
199dnl hash-string.h hash-string.c
200dnl l10nflist.c
201dnl libgnuintl.h.in (except the *printf stuff)
202dnl loadinfo.h
203dnl loadmsgcat.c
204dnl localealias.c
205dnl log.c
206dnl plural-exp.h plural-exp.c
207dnl plural.y
208dnl Used by libglocale.
209AC_DEFUN([gt_INTL_SUBDIR_CORE],
210[
211 AC_REQUIRE([AC_C_INLINE])dnl
212 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
213 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
214 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
215 AC_REQUIRE([AC_FUNC_MMAP])dnl
216 AC_REQUIRE([gt_INTDIV0])dnl
217 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl
218 AC_REQUIRE([gt_INTTYPES_PRI])dnl
219 AC_REQUIRE([gl_LOCK])dnl
220
221 AC_LINK_IFELSE(
222 [AC_LANG_PROGRAM(
223 [[int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }]],
224 [[]])],
225 [AC_DEFINE([HAVE_BUILTIN_EXPECT], [1],
226 [Define to 1 if the compiler understands __builtin_expect.])])
227
228 AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h])
229 AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \
230 stpcpy strcasecmp strdup strtoul tsearch uselocale argz_count \
231 argz_stringify argz_next __fsetlocking])
232
233 dnl Use the *_unlocked functions only if they are declared.
234 dnl (because some of them were defined without being declared in Solaris
235 dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
236 dnl on Solaris 2.5.1 to run on Solaris 2.6).
237 AC_CHECK_DECLS([feof_unlocked fgets_unlocked], , , [#include <stdio.h>])
238
239 AM_ICONV
240
241 dnl intl/plural.c is generated from intl/plural.y. It requires bison,
242 dnl because plural.y uses bison specific features. It requires at least
243 dnl bison-1.26 because earlier versions generate a plural.c that doesn't
244 dnl compile.
245 dnl bison is only needed for the maintainer (who touches plural.y). But in
246 dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
247 dnl the rule in general Makefile. Now, some people carelessly touch the
248 dnl files or have a broken "make" program, hence the plural.c rule will
249 dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
250 dnl present or too old.
251 AC_CHECK_PROGS([INTLBISON], [bison])
252 if test -z "$INTLBISON"; then
253 ac_verc_fail=yes
254 else
255 dnl Found it, now check the version.
256 AC_MSG_CHECKING([version of bison])
257changequote(<<,>>)dnl
258 ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
259 case $ac_prog_version in
260 '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
261 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
262changequote([,])dnl
263 ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
264 *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
265 esac
266 AC_MSG_RESULT([$ac_prog_version])
267 fi
268 if test $ac_verc_fail = yes; then
269 INTLBISON=:
270 fi
271])
diff --git a/gl/m4/intldir.m4 b/gl/m4/intldir.m4
deleted file mode 100644
index 388ecd6..0000000
--- a/gl/m4/intldir.m4
+++ /dev/null
@@ -1,19 +0,0 @@
1# intldir.m4 serial 2 (gettext-0.18)
2dnl Copyright (C) 2006, 2009-2013 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
16AC_PREREQ([2.52])
17
18dnl Tells the AM_GNU_GETTEXT macro to consider an intl/ directory.
19AC_DEFUN([AM_GNU_GETTEXT_INTL_SUBDIR], [])
diff --git a/gl/m4/intlmacosx.m4 b/gl/m4/intlmacosx.m4
deleted file mode 100644
index ab97d39..0000000
--- a/gl/m4/intlmacosx.m4
+++ /dev/null
@@ -1,56 +0,0 @@
1# intlmacosx.m4 serial 5 (gettext-0.18.2)
2dnl Copyright (C) 2004-2013 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 Mac OS X.
17dnl Defines INTL_MACOSX_LIBS.
18AC_DEFUN([gt_INTL_MACOSX],
19[
20 dnl Check for API introduced in Mac OS 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_LINK_IFELSE(
26 [AC_LANG_PROGRAM(
27 [[#include <CoreFoundation/CFPreferences.h>]],
28 [[CFPreferencesCopyAppValue(NULL, NULL)]])],
29 [gt_cv_func_CFPreferencesCopyAppValue=yes],
30 [gt_cv_func_CFPreferencesCopyAppValue=no])
31 LIBS="$gt_save_LIBS"])
32 if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then
33 AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], [1],
34 [Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
35 fi
36 dnl Check for API introduced in Mac OS X 10.3.
37 AC_CACHE_CHECK([for CFLocaleCopyCurrent], [gt_cv_func_CFLocaleCopyCurrent],
38 [gt_save_LIBS="$LIBS"
39 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
40 AC_LINK_IFELSE(
41 [AC_LANG_PROGRAM(
42 [[#include <CoreFoundation/CFLocale.h>]],
43 [[CFLocaleCopyCurrent();]])],
44 [gt_cv_func_CFLocaleCopyCurrent=yes],
45 [gt_cv_func_CFLocaleCopyCurrent=no])
46 LIBS="$gt_save_LIBS"])
47 if test $gt_cv_func_CFLocaleCopyCurrent = yes; then
48 AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], [1],
49 [Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the CoreFoundation framework.])
50 fi
51 INTL_MACOSX_LIBS=
52 if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then
53 INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
54 fi
55 AC_SUBST([INTL_MACOSX_LIBS])
56])
diff --git a/gl/m4/intmax.m4 b/gl/m4/intmax.m4
deleted file mode 100644
index 18733a5..0000000
--- a/gl/m4/intmax.m4
+++ /dev/null
@@ -1,36 +0,0 @@
1# intmax.m4 serial 6 (gettext-0.18.2)
2dnl Copyright (C) 2002-2005, 2008-2013 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 system has the 'intmax_t' type, but don't attempt to
9dnl find a replacement if it is lacking.
10
11AC_DEFUN([gt_TYPE_INTMAX_T],
12[
13 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
14 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
15 AC_CACHE_CHECK([for intmax_t], [gt_cv_c_intmax_t],
16 [AC_COMPILE_IFELSE(
17 [AC_LANG_PROGRAM(
18 [[
19#include <stddef.h>
20#include <stdlib.h>
21#if HAVE_STDINT_H_WITH_UINTMAX
22#include <stdint.h>
23#endif
24#if HAVE_INTTYPES_H_WITH_UINTMAX
25#include <inttypes.h>
26#endif
27 ]],
28 [[intmax_t x = -1;
29 return !x;]])],
30 [gt_cv_c_intmax_t=yes],
31 [gt_cv_c_intmax_t=no])])
32 if test $gt_cv_c_intmax_t = yes; then
33 AC_DEFINE([HAVE_INTMAX_T], [1],
34 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
35 fi
36])
diff --git a/gl/m4/intmax_t.m4 b/gl/m4/intmax_t.m4
index 6ea7053..ef32e1b 100644
--- a/gl/m4/intmax_t.m4
+++ b/gl/m4/intmax_t.m4
@@ -1,5 +1,5 @@
1# intmax_t.m4 serial 8 1# intmax_t.m4 serial 9
2dnl Copyright (C) 1997-2004, 2006-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 1997-2004, 2006-2007, 2009-2023 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
@@ -19,11 +19,7 @@ AC_DEFUN([gl_AC_TYPE_INTMAX_T],
19 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) 19 AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
20 AC_REQUIRE([gl_AC_HEADER_STDINT_H]) 20 AC_REQUIRE([gl_AC_HEADER_STDINT_H])
21 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then 21 if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then
22 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 22 AC_DEFINE_UNQUOTED([intmax_t], [long long],
23 test $ac_cv_type_long_long_int = yes \
24 && ac_type='long long' \
25 || ac_type='long'
26 AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
27 [Define to long or long long if <inttypes.h> and <stdint.h> don't define.]) 23 [Define to long or long long if <inttypes.h> and <stdint.h> don't define.])
28 else 24 else
29 AC_DEFINE([HAVE_INTMAX_T], [1], 25 AC_DEFINE([HAVE_INTMAX_T], [1],
@@ -57,11 +53,7 @@ AC_DEFUN([gt_AC_TYPE_INTMAX_T],
57 AC_DEFINE([HAVE_INTMAX_T], [1], 53 AC_DEFINE([HAVE_INTMAX_T], [1],
58 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) 54 [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
59 else 55 else
60 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 56 AC_DEFINE_UNQUOTED([intmax_t], [long long],
61 test $ac_cv_type_long_long_int = yes \
62 && ac_type='long long' \
63 || ac_type='long'
64 AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
65 [Define to long or long long if <stdint.h> and <inttypes.h> don't define.]) 57 [Define to long or long long if <stdint.h> and <inttypes.h> don't define.])
66 fi 58 fi
67]) 59])
diff --git a/gl/m4/inttypes-pri.m4 b/gl/m4/inttypes-pri.m4
deleted file mode 100644
index e5a1e05..0000000
--- a/gl/m4/inttypes-pri.m4
+++ /dev/null
@@ -1,42 +0,0 @@
1# inttypes-pri.m4 serial 7 (gettext-0.18.2)
2dnl Copyright (C) 1997-2002, 2006, 2008-2013 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.
8
9AC_PREREQ([2.53])
10
11# Define PRI_MACROS_BROKEN if <inttypes.h> exists and defines the PRI*
12# macros to non-string values. This is the case on AIX 4.3.3.
13
14AC_DEFUN([gt_INTTYPES_PRI],
15[
16 AC_CHECK_HEADERS([inttypes.h])
17 if test $ac_cv_header_inttypes_h = yes; then
18 AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken],
19 [gt_cv_inttypes_pri_broken],
20 [
21 AC_COMPILE_IFELSE(
22 [AC_LANG_PROGRAM(
23 [[
24#include <inttypes.h>
25#ifdef PRId32
26char *p = PRId32;
27#endif
28 ]],
29 [[]])],
30 [gt_cv_inttypes_pri_broken=no],
31 [gt_cv_inttypes_pri_broken=yes])
32 ])
33 fi
34 if test "$gt_cv_inttypes_pri_broken" = yes; then
35 AC_DEFINE_UNQUOTED([PRI_MACROS_BROKEN], [1],
36 [Define if <inttypes.h> exists and defines unusable PRI* macros.])
37 PRI_MACROS_BROKEN=1
38 else
39 PRI_MACROS_BROKEN=0
40 fi
41 AC_SUBST([PRI_MACROS_BROKEN])
42])
diff --git a/gl/m4/inttypes.m4 b/gl/m4/inttypes.m4
new file mode 100644
index 0000000..bf2eab2
--- /dev/null
+++ b/gl/m4/inttypes.m4
@@ -0,0 +1,180 @@
1# inttypes.m4 serial 36
2dnl Copyright (C) 2006-2023 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 Derek Price, Bruno Haible.
8dnl Test whether <inttypes.h> is supported or must be substituted.
9
10AC_DEFUN_ONCE([gl_INTTYPES_H],
11[
12 AC_REQUIRE([gl_INTTYPES_INCOMPLETE])
13 gl_INTTYPES_PRI_SCN
14])
15
16AC_DEFUN_ONCE([gl_INTTYPES_INCOMPLETE],
17[
18 AC_REQUIRE([gl_STDINT_H])
19 AC_CHECK_HEADERS_ONCE([inttypes.h])
20
21 dnl Override <inttypes.h> always, so that the portability warnings work.
22 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
23 gl_CHECK_NEXT_HEADERS([inttypes.h])
24
25 AC_REQUIRE([gl_MULTIARCH])
26
27 dnl Check for declarations of anything we want to poison if the
28 dnl corresponding gnulib module is not in use.
29 gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
30 ]], [imaxabs imaxdiv strtoimax strtoumax])
31
32 AC_REQUIRE([AC_C_RESTRICT])
33])
34
35# Ensure that the PRI* and SCN* macros are defined appropriately.
36AC_DEFUN([gl_INTTYPES_PRI_SCN],
37[
38 PRIPTR_PREFIX=
39 if $GL_GENERATE_STDINT_H; then
40 dnl Using the gnulib <stdint.h>. It defines intptr_t to 'long' or
41 dnl 'long long', depending on _WIN64.
42 AC_COMPILE_IFELSE(
43 [AC_LANG_PROGRAM([[
44 #ifdef _WIN64
45 LLP64
46 #endif
47 ]])
48 ],
49 [PRIPTR_PREFIX='"l"'],
50 [PRIPTR_PREFIX='"ll"'])
51 else
52 dnl Using the system's <stdint.h>.
53 for glpfx in '' l ll I64; do
54 case $glpfx in
55 '') gltype1='int';;
56 l) gltype1='long int';;
57 ll) gltype1='long long int';;
58 I64) gltype1='__int64';;
59 esac
60 AC_COMPILE_IFELSE(
61 [AC_LANG_PROGRAM([[#include <stdint.h>
62 extern intptr_t foo;
63 extern $gltype1 foo;]])],
64 [PRIPTR_PREFIX='"'$glpfx'"'])
65 test -n "$PRIPTR_PREFIX" && break
66 done
67 fi
68 AC_SUBST([PRIPTR_PREFIX])
69
70 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
71 [INT32_MAX_LT_INTMAX_MAX],
72 [defined INT32_MAX && defined INTMAX_MAX],
73 [INT32_MAX < INTMAX_MAX],
74 [sizeof (int) < sizeof (long long int)])
75 if test $APPLE_UNIVERSAL_BUILD = 0; then
76 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
77 [INT64_MAX_EQ_LONG_MAX],
78 [defined INT64_MAX],
79 [INT64_MAX == LONG_MAX],
80 [sizeof (long long int) == sizeof (long int)])
81 else
82 INT64_MAX_EQ_LONG_MAX=-1
83 fi
84 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
85 [UINT32_MAX_LT_UINTMAX_MAX],
86 [defined UINT32_MAX && defined UINTMAX_MAX],
87 [UINT32_MAX < UINTMAX_MAX],
88 [sizeof (unsigned int) < sizeof (unsigned long long int)])
89 if test $APPLE_UNIVERSAL_BUILD = 0; then
90 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
91 [UINT64_MAX_EQ_ULONG_MAX],
92 [defined UINT64_MAX],
93 [UINT64_MAX == ULONG_MAX],
94 [sizeof (unsigned long long int) == sizeof (unsigned long int)])
95 else
96 UINT64_MAX_EQ_ULONG_MAX=-1
97 fi
98])
99
100# Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
101# If $2 is true, the condition is $3; otherwise if long long int is supported
102# approximate the condition with $4; otherwise, assume the condition is false.
103# The condition should work on all C99 platforms; the approximations should be
104# good enough to work on all practical pre-C99 platforms.
105# $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
106AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
107[
108 AC_CACHE_CHECK([whether $3],
109 [gl_cv_test_$1],
110 [AC_COMPILE_IFELSE(
111 [AC_LANG_PROGRAM(
112 [[/* Work also in C++ mode. */
113 #define __STDC_LIMIT_MACROS 1
114
115 /* Work if build is not clean. */
116 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
117
118 #include <limits.h>
119 #if HAVE_STDINT_H
120 #include <stdint.h>
121 #endif
122
123 #if $2
124 #define CONDITION ($3)
125 #else
126 #define CONDITION ($4)
127 #endif
128 int test[CONDITION ? 1 : -1];]])],
129 [gl_cv_test_$1=yes],
130 [gl_cv_test_$1=no])])
131 if test $gl_cv_test_$1 = yes; then
132 $1=1;
133 else
134 $1=0;
135 fi
136 AC_SUBST([$1])
137])
138
139# gl_INTTYPES_MODULE_INDICATOR([modulename])
140# sets the shell variable that indicates the presence of the given module
141# to a C preprocessor expression that will evaluate to 1.
142# This macro invocation must not occur in macros that are AC_REQUIREd.
143AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
144[
145 dnl Ensure to expand the default settings once only.
146 gl_INTTYPES_H_REQUIRE_DEFAULTS
147 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
148])
149
150# Initializes the default values for AC_SUBSTed shell variables.
151# This macro must not be AC_REQUIREd. It must only be invoked, and only
152# outside of macros or in macros that are not AC_REQUIREd.
153AC_DEFUN([gl_INTTYPES_H_REQUIRE_DEFAULTS],
154[
155 m4_defun(GL_MODULE_INDICATOR_PREFIX[_INTTYPES_H_MODULE_INDICATOR_DEFAULTS], [
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_IMAXABS])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_IMAXDIV])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOIMAX])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOUMAX])
160 ])
161 m4_require(GL_MODULE_INDICATOR_PREFIX[_INTTYPES_H_MODULE_INDICATOR_DEFAULTS])
162 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
163])
164
165AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
166[
167 dnl Assume proper GNU behavior unless another module says otherwise.
168 HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
169 HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
170 HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
171 HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
172 HAVE_IMAXDIV_T=1; AC_SUBST([HAVE_IMAXDIV_T])
173 REPLACE_STRTOIMAX=0; AC_SUBST([REPLACE_STRTOIMAX])
174 REPLACE_STRTOUMAX=0; AC_SUBST([REPLACE_STRTOUMAX])
175 INT32_MAX_LT_INTMAX_MAX=1; AC_SUBST([INT32_MAX_LT_INTMAX_MAX])
176 INT64_MAX_EQ_LONG_MAX='defined _LP64'; AC_SUBST([INT64_MAX_EQ_LONG_MAX])
177 PRIPTR_PREFIX=__PRIPTR_PREFIX; AC_SUBST([PRIPTR_PREFIX])
178 UINT32_MAX_LT_UINTMAX_MAX=1; AC_SUBST([UINT32_MAX_LT_UINTMAX_MAX])
179 UINT64_MAX_EQ_ULONG_MAX='defined _LP64'; AC_SUBST([UINT64_MAX_EQ_ULONG_MAX])
180])
diff --git a/gl/m4/inttypes_h.m4 b/gl/m4/inttypes_h.m4
index 5f05ac5..68c60e9 100644
--- a/gl/m4/inttypes_h.m4
+++ b/gl/m4/inttypes_h.m4
@@ -1,5 +1,5 @@
1# inttypes_h.m4 serial 10 1# inttypes_h.m4 serial 10
2dnl Copyright (C) 1997-2004, 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2006, 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/langinfo_h.m4 b/gl/m4/langinfo_h.m4
index 73bef8b..b17a526 100644
--- a/gl/m4/langinfo_h.m4
+++ b/gl/m4/langinfo_h.m4
@@ -1,10 +1,10 @@
1# langinfo_h.m4 serial 7 1# langinfo_h.m4 serial 12
2dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2023 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_LANGINFO_H], 7AC_DEFUN_ONCE([gl_LANGINFO_H],
8[ 8[
9 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS]) 9 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
10 10
@@ -17,13 +17,17 @@ AC_DEFUN([gl_LANGINFO_H],
17 dnl Determine whether <langinfo.h> exists. It is missing on mingw and BeOS. 17 dnl Determine whether <langinfo.h> exists. It is missing on mingw and BeOS.
18 HAVE_LANGINFO_CODESET=0 18 HAVE_LANGINFO_CODESET=0
19 HAVE_LANGINFO_T_FMT_AMPM=0 19 HAVE_LANGINFO_T_FMT_AMPM=0
20 HAVE_LANGINFO_ALTMON=0
20 HAVE_LANGINFO_ERA=0 21 HAVE_LANGINFO_ERA=0
21 HAVE_LANGINFO_YESEXPR=0 22 HAVE_LANGINFO_YESEXPR=0
22 AC_CHECK_HEADERS_ONCE([langinfo.h]) 23 AC_CHECK_HEADERS_ONCE([langinfo.h])
23 if test $ac_cv_header_langinfo_h = yes; then 24 if test $ac_cv_header_langinfo_h = yes; then
24 HAVE_LANGINFO_H=1 25 HAVE_LANGINFO_H=1
25 dnl Determine what <langinfo.h> defines. CODESET and ERA etc. are missing 26 dnl Determine what <langinfo.h> defines.
26 dnl on OpenBSD 3.8. T_FMT_AMPM and YESEXPR, NOEXPR are missing on IRIX 5.3. 27 dnl CODESET is missing on OpenBSD 3.8.
28 dnl ERA etc. are missing on OpenBSD 6.7.
29 dnl T_FMT_AMPM and YESEXPR, NOEXPR are missing on IRIX 5.3.
30 dnl ALTMON_* are missing on glibc 2.26 and many other systems.
27 AC_CACHE_CHECK([whether langinfo.h defines CODESET], 31 AC_CACHE_CHECK([whether langinfo.h defines CODESET],
28 [gl_cv_header_langinfo_codeset], 32 [gl_cv_header_langinfo_codeset],
29 [AC_COMPILE_IFELSE( 33 [AC_COMPILE_IFELSE(
@@ -48,6 +52,18 @@ int a = T_FMT_AMPM;
48 if test $gl_cv_header_langinfo_t_fmt_ampm = yes; then 52 if test $gl_cv_header_langinfo_t_fmt_ampm = yes; then
49 HAVE_LANGINFO_T_FMT_AMPM=1 53 HAVE_LANGINFO_T_FMT_AMPM=1
50 fi 54 fi
55 AC_CACHE_CHECK([whether langinfo.h defines ALTMON_1],
56 [gl_cv_header_langinfo_altmon],
57 [AC_COMPILE_IFELSE(
58 [AC_LANG_PROGRAM([[#include <langinfo.h>
59int a = ALTMON_1;
60]])],
61 [gl_cv_header_langinfo_altmon=yes],
62 [gl_cv_header_langinfo_altmon=no])
63 ])
64 if test $gl_cv_header_langinfo_altmon = yes; then
65 HAVE_LANGINFO_ALTMON=1
66 fi
51 AC_CACHE_CHECK([whether langinfo.h defines ERA], 67 AC_CACHE_CHECK([whether langinfo.h defines ERA],
52 [gl_cv_header_langinfo_era], 68 [gl_cv_header_langinfo_era],
53 [AC_COMPILE_IFELSE( 69 [AC_COMPILE_IFELSE(
@@ -78,6 +94,7 @@ int a = YESEXPR;
78 AC_SUBST([HAVE_LANGINFO_H]) 94 AC_SUBST([HAVE_LANGINFO_H])
79 AC_SUBST([HAVE_LANGINFO_CODESET]) 95 AC_SUBST([HAVE_LANGINFO_CODESET])
80 AC_SUBST([HAVE_LANGINFO_T_FMT_AMPM]) 96 AC_SUBST([HAVE_LANGINFO_T_FMT_AMPM])
97 AC_SUBST([HAVE_LANGINFO_ALTMON])
81 AC_SUBST([HAVE_LANGINFO_ERA]) 98 AC_SUBST([HAVE_LANGINFO_ERA])
82 AC_SUBST([HAVE_LANGINFO_YESEXPR]) 99 AC_SUBST([HAVE_LANGINFO_YESEXPR])
83 100
@@ -87,18 +104,33 @@ int a = YESEXPR;
87 ]], [nl_langinfo]) 104 ]], [nl_langinfo])
88]) 105])
89 106
107# gl_LANGINFO_MODULE_INDICATOR([modulename])
108# sets the shell variable that indicates the presence of the given module
109# to a C preprocessor expression that will evaluate to 1.
110# This macro invocation must not occur in macros that are AC_REQUIREd.
90AC_DEFUN([gl_LANGINFO_MODULE_INDICATOR], 111AC_DEFUN([gl_LANGINFO_MODULE_INDICATOR],
91[ 112[
92 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 113 dnl Ensure to expand the default settings once only.
93 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS]) 114 gl_LANGINFO_H_REQUIRE_DEFAULTS
94 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 115 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
95 dnl Define it also as a C macro, for the benefit of the unit tests. 116 dnl Define it also as a C macro, for the benefit of the unit tests.
96 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 117 gl_MODULE_INDICATOR_FOR_TESTS([$1])
97]) 118])
98 119
120# Initializes the default values for AC_SUBSTed shell variables.
121# This macro must not be AC_REQUIREd. It must only be invoked, and only
122# outside of macros or in macros that are not AC_REQUIREd.
123AC_DEFUN([gl_LANGINFO_H_REQUIRE_DEFAULTS],
124[
125 m4_defun(GL_MODULE_INDICATOR_PREFIX[_LANGINFO_H_MODULE_INDICATOR_DEFAULTS], [
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NL_LANGINFO])
127 ])
128 m4_require(GL_MODULE_INDICATOR_PREFIX[_LANGINFO_H_MODULE_INDICATOR_DEFAULTS])
129 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
130])
131
99AC_DEFUN([gl_LANGINFO_H_DEFAULTS], 132AC_DEFUN([gl_LANGINFO_H_DEFAULTS],
100[ 133[
101 GNULIB_NL_LANGINFO=0; AC_SUBST([GNULIB_NL_LANGINFO])
102 dnl Assume proper GNU behavior unless another module says otherwise. 134 dnl Assume proper GNU behavior unless another module says otherwise.
103 HAVE_NL_LANGINFO=1; AC_SUBST([HAVE_NL_LANGINFO]) 135 HAVE_NL_LANGINFO=1; AC_SUBST([HAVE_NL_LANGINFO])
104 REPLACE_NL_LANGINFO=0; AC_SUBST([REPLACE_NL_LANGINFO]) 136 REPLACE_NL_LANGINFO=0; AC_SUBST([REPLACE_NL_LANGINFO])
diff --git a/gl/m4/largefile.m4 b/gl/m4/largefile.m4
index 1e605e3..7fb81b8 100644
--- a/gl/m4/largefile.m4
+++ b/gl/m4/largefile.m4
@@ -1,104 +1,319 @@
1# Enable large files on systems where this is not the default. 1# Enable large files on systems where this is not the default.
2# Enable support for files on Linux file systems with 64-bit inode numbers.
2 3
3# Copyright 1992-1996, 1998-2013 Free Software Foundation, Inc. 4# Copyright 1992-1996, 1998-2023 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation 5# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it, 6# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved. 7# with or without modifications, as long as this notice is preserved.
7 8
8# The following implementation works around a problem in autoconf <= 2.69; 9# The following macro works around a problem in Autoconf's AC_FUNC_FSEEKO:
10# It does not set _LARGEFILE_SOURCE=1 on HP-UX/ia64 32-bit, although this
11# setting of _LARGEFILE_SOURCE is needed so that <stdio.h> declares fseeko
12# and ftello in C++ mode as well.
13# Fixed in Autoconf 2.72, which has AC_SYS_YEAR2038.
14AC_DEFUN([gl_SET_LARGEFILE_SOURCE],
15 m4_ifndef([AC_SYS_YEAR2038], [[
16 AC_REQUIRE([AC_CANONICAL_HOST])
17 AC_FUNC_FSEEKO
18 case "$host_os" in
19 hpux*)
20 AC_DEFINE([_LARGEFILE_SOURCE], [1],
21 [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).])
22 ;;
23 esac
24 ]])
25)
26
27# Work around a problem in autoconf <= 2.69:
9# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5, 28# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5,
10# or configures them incorrectly in some cases. 29# or configures them incorrectly in some cases.
11m4_version_prereq([2.70], [] ,[ 30m4_version_prereq([2.70], [], [
12 31
13# _AC_SYS_LARGEFILE_TEST_INCLUDES 32# _AC_SYS_LARGEFILE_TEST_INCLUDES
14# ------------------------------- 33# -------------------------------
15m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], 34m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
16[@%:@include <sys/types.h> 35[#include <sys/types.h>
17 /* Check that off_t can represent 2**63 - 1 correctly. 36 /* Check that off_t can represent 2**63 - 1 correctly.
18 We can't simply define LARGE_OFF_T to be 9223372036854775807, 37 We can't simply define LARGE_OFF_T to be 9223372036854775807,
19 since some C++ compilers masquerading as C compilers 38 since some C++ compilers masquerading as C compilers
20 incorrectly reject 9223372036854775807. */ 39 incorrectly reject 9223372036854775807. */
21@%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) 40#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
22 int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721 41 int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
23 && LARGE_OFF_T % 2147483647 == 1) 42 && LARGE_OFF_T % 2147483647 == 1)
24 ? 1 : -1]];[]dnl 43 ? 1 : -1]];[]dnl
25]) 44])
45])# m4_version_prereq 2.70
46
47# Support AC_SYS_YEAR2038, even if Autoconf 2.71 or earlier.
48# This code is taken from Autoconf master.
49m4_ifndef([AC_SYS_YEAR2038], [
50
51# _AC_SYS_YEAR2038_TEST_CODE
52# --------------------------
53# C code used to probe for time_t that can represent time points more
54# than 2**31 - 1 seconds after the epoch. With the usual Unix epoch,
55# these correspond to dates after 2038-01-18 22:14:07 +0000 (Gregorian),
56# hence the name.
57AC_DEFUN([_AC_SYS_YEAR2038_TEST_CODE],
58[[
59 #include <time.h>
60 /* Check that time_t can represent 2**32 - 1 correctly. */
61 #define LARGE_TIME_T \\
62 ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30)))
63 int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535
64 && LARGE_TIME_T % 65537 == 0)
65 ? 1 : -1];
66]])
67
68# _AC_SYS_YEAR2038_OPTIONS
69# ------------------------
70# List of known ways to enable support for large time_t. If you change
71# this list you probably also need to change the AS_CASE at the end of
72# _AC_SYS_YEAR2038_PROBE.
73m4_define([_AC_SYS_YEAR2038_OPTIONS], m4_normalize(
74 ["none needed"] dnl 64-bit and newer 32-bit Unix
75 ["-D_TIME_BITS=64"] dnl glibc 2.34 with some 32-bit ABIs
76 ["-D__MINGW_USE_VC2005_COMPAT"] dnl 32-bit MinGW
77 ["-U_USE_32_BIT_TIME_T -D__MINGW_USE_VC2005_COMPAT"]
78 dnl 32-bit MinGW (misconfiguration)
79))
80
81# _AC_SYS_YEAR2038_PROBE([IF-NOT-DETECTED])
82# -----------------------------------------
83# Subroutine of AC_SYS_YEAR2038. Probe for time_t that can represent
84# time points more than 2**31 - 1 seconds after the epoch (dates after
85# 2038-01-18, see above) and set the cache variable ac_cv_sys_year2038_opts
86# to one of the values in the _AC_SYS_YEAR2038_OPTIONS list, or to
87# "support not detected" if none of them worked. Then, set compilation
88# options and #defines as necessary to enable large time_t support.
89#
90# Note that we do not test whether mktime, localtime, etc. handle
91# large values of time_t correctly, as that would require use of
92# AC_TRY_RUN. Note also that some systems only support large time_t
93# together with large off_t.
94#
95# If support is not detected, the behavior depends on which of the
96# top-level AC_SYS_YEAR2038 macros was used (see below).
97#
98# If you change this macro you may also need to change
99# _AC_SYS_YEAR2038_OPTIONS.
100AC_DEFUN([_AC_SYS_YEAR2038_PROBE],
101[AC_CACHE_CHECK([for $CC option to enable timestamps after Jan 2038],
102 [ac_cv_sys_year2038_opts],
103 [ac_save_CPPFLAGS="$CPPFLAGS"
104 ac_opt_found=no
105 for ac_opt in _AC_SYS_YEAR2038_OPTIONS; do
106 AS_IF([test x"$ac_opt" != x"none needed"],
107 [CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"])
108 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_YEAR2038_TEST_CODE])],
109 [ac_cv_sys_year2038_opts="$ac_opt"
110 ac_opt_found=yes])
111 test $ac_opt_found = no || break
112 done
113 CPPFLAGS="$ac_save_CPPFLAGS"
114 test $ac_opt_found = yes || ac_cv_sys_year2038_opts="support not detected"])
115
116ac_have_year2038=yes
117AS_CASE([$ac_cv_sys_year2038_opts],
118 ["none needed"], [],
119 ["support not detected"],
120 [ac_have_year2038=no
121 AS_CASE([$enable_year2038],
122 [yes],
123 [# If we're not cross compiling and 'touch' works with a large
124 # timestamp, then we can presume the system supports wider time_t
125 # *somehow* and we just weren't able to detect it. One common
126 # case that we deliberately *don't* probe for is a system that
127 # supports both 32- and 64-bit ABIs but only the 64-bit ABI offers
128 # wide time_t. (It would be inappropriate for us to override an
129 # intentional use of -m32.) Error out, demanding use of
130 # --disable-year2038 if this is intentional.
131 AS_IF([test $cross_compiling = no],
132 [AS_IF([TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null],
133 [AS_CASE([`TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null`],
134 [*'Feb 7 2106'* | *'Feb 7 17:10'*],
135 [AC_MSG_FAILURE(m4_text_wrap(
136 [this system appears to support timestamps after January 2038,
137 but no mechanism for enabling wide 'time_t' was detected.
138 Did you mean to build a 64-bit binary? (e.g. 'CC="${CC} -m64"'.)
139 To proceed with 32-bit time_t, configure with '--disable-year2038'.],
140 [], [], [55]))])])])])],
141
142 ["-D_TIME_BITS=64"],
143 [AC_DEFINE([_TIME_BITS], [64],
144 [Number of bits in time_t, on hosts where this is settable.])],
145
146 ["-D__MINGW_USE_VC2005_COMPAT=1"],
147 [AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
148 [Define to 1 on platforms where this makes time_t a 64-bit type.])],
149
150 ["-U_USE_32_BIT_TIME_T"*],
151 [AC_MSG_FAILURE(m4_text_wrap(
152 [the 'time_t' type is currently forced to be 32-bit.
153 It will stop working after January 2038.
154 Remove _USE_32BIT_TIME_T from the compiler flags.],
155 [], [], [55]))],
156
157 [AC_MSG_ERROR(
158 [internal error: bad value for \$ac_cv_sys_year2038_opts])])
159])
160
161# _AC_SYS_YEAR2038_ENABLE
162# -----------------------
163# Subroutine of AC_SYS_YEAR2038 and _AC_SYS_YEAR2038_OPT_IN.
164# Depending on which of the YEAR2038 macros was used, add either an
165# --enable-year2038, or a --disable-year2038, or no option at all to
166# the configure script. Note that this is expanded very late and
167# therefore there cannot be any code in the AC_ARG_ENABLE. The
168# default value for enable_year2038 is emitted unconditionally
169# because the generated code always looks at this variable.
170m4_define([_AC_SYS_YEAR2038_ENABLE],
171[m4_divert_text([DEFAULTS],
172 m4_provide_if([AC_SYS_YEAR2038],
173 [enable_year2038=yes],
174 [enable_year2038=no]))]dnl
175[AC_ARG_ENABLE([year2038],
176 m4_provide_if([AC_SYS_YEAR2038],
177 [AS_HELP_STRING([--disable-year2038],
178 [do not support timestamps after 2038])],
179 [AS_HELP_STRING([--enable-year2038],
180 [support timestamps after 2038])]))])
181
182# _AC_SYS_YEAR2038_OPT_IN
183# -----------------------
184# If the --enable-year2038 option is given to configure, attempt to
185# detect and activate support for large time_t on 32-bit systems.
186# This macro is automatically invoked by AC_SYS_LARGEFILE when large
187# *file* support is detected. It does not AC_REQUIRE AC_SYS_LARGEFILE
188# to avoid a dependency loop, and is therefore unsafe to expose as a
189# documented macro.
190AC_DEFUN([_AC_SYS_YEAR2038_OPT_IN],
191[m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
192 AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE])
193 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
194])])
195
196# AC_SYS_YEAR2038
197# ---------------
198# Attempt to detect and activate support for large time_t.
199# On systems where time_t is not always 64 bits, this probe can be
200# skipped by passing the --disable-year2038 option to configure.
201AC_DEFUN([AC_SYS_YEAR2038],
202[AC_REQUIRE([AC_SYS_LARGEFILE])]dnl
203[m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
204 AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE])
205 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
206])])
207
208# _AC_SYS_LARGEFILE_TEST_CODE
209# ---------------------------
210# C code used to probe for large file support.
211m4_define([_AC_SYS_LARGEFILE_TEST_CODE],
212[@%:@include <sys/types.h>
213 /* Check that off_t can represent 2**63 - 1 correctly.
214 We can't simply define LARGE_OFF_T to be 9223372036854775807,
215 since some C++ compilers masquerading as C compilers
216 incorrectly reject 9223372036854775807. */
217@%:@define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
218 int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
219 && LARGE_OFF_T % 2147483647 == 1)
220 ? 1 : -1]];[]dnl
221])
222
223# _AC_SYS_LARGEFILE_OPTIONS
224# -------------------------
225# List of known ways to enable support for large files. If you change
226# this list you probably also need to change the AS_CASE at the end of
227# _AC_SYS_LARGEFILE_PROBE.
228m4_define([_AC_SYS_LARGEFILE_OPTIONS], m4_normalize(
229 ["none needed"] dnl Most current systems
230 ["-D_FILE_OFFSET_BITS=64"] dnl X/Open LFS spec
231 ["-D_LARGE_FILES=1"] dnl AIX (which versions?)
232 ["-n32"] dnl Irix 6.2 w/ SGI compiler
233))
234
235# _AC_SYS_LARGEFILE_PROBE
236# -----------------------
237# Subroutine of AC_SYS_LARGEFILE. Probe for large file support and set
238# the cache variable ac_cv_sys_largefile_opts to one of the values in
239# the _AC_SYS_LARGEFILE_OPTIONS list, or to "support not detected" if
240# none of the options in that list worked. Then, set compilation
241# options and #defines as necessary to enable large file support.
242#
243# If large file support is not detected, the behavior depends on which of
244# the top-level AC_SYS_LARGEFILE macros was used (see below).
245#
246# If you change this macro you may also need to change
247# _AC_SYS_LARGEFILE_OPTIONS.
248AC_DEFUN([_AC_SYS_LARGEFILE_PROBE],
249[AC_CACHE_CHECK([for $CC option to enable large file support],
250 [ac_cv_sys_largefile_opts],
251 [ac_save_CC="$CC"
252 ac_opt_found=no
253 for ac_opt in _AC_SYS_LARGEFILE_OPTIONS; do
254 AS_IF([test x"$ac_opt" != x"none needed"],
255 [CC="$ac_save_CC $ac_opt"])
256 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_CODE])],
257 [ac_cv_sys_largefile_opts="$ac_opt"
258 ac_opt_found=yes])
259 test $ac_opt_found = no || break
260 done
261 CC="$ac_save_CC"
262 test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected"])
263
264ac_have_largefile=yes
265AS_CASE([$ac_cv_sys_largefile_opts],
266 ["none needed"], [],
267 ["support not detected"],
268 [ac_have_largefile=no],
269
270 ["-D_FILE_OFFSET_BITS=64"],
271 [AC_DEFINE([_FILE_OFFSET_BITS], [64],
272 [Number of bits in a file offset, on hosts where this is settable.])],
273
274 ["-D_LARGE_FILES=1"],
275 [AC_DEFINE([_LARGE_FILES], [1],
276 [Define to 1 on platforms where this makes off_t a 64-bit type.])],
26 277
278 ["-n32"],
279 [CC="$CC -n32"],
27 280
28# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, 281 [AC_MSG_ERROR(
29# CACHE-VAR, 282 [internal error: bad value for \$ac_cv_sys_largefile_opts])])
30# DESCRIPTION,
31# PROLOGUE, [FUNCTION-BODY])
32# --------------------------------------------------------
33m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
34[AC_CACHE_CHECK([for $1 value needed for large files], [$3],
35[while :; do
36 m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
37 [AC_LANG_PROGRAM([$5], [$6])],
38 [$3=no; break])
39 m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
40 [AC_LANG_PROGRAM([@%:@define $1 $2
41$5], [$6])],
42 [$3=$2; break])
43 $3=unknown
44 break
45done])
46case $$3 in #(
47 no | unknown) ;;
48 *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);;
49esac
50rm -rf conftest*[]dnl
51])# _AC_SYS_LARGEFILE_MACRO_VALUE
52 283
284_AC_SYS_YEAR2038_OPT_IN
285])
286
287# _AC_SYS_LARGEFILE_ENABLE
288# ------------------------
289# Subroutine of AC_SYS_LARGEFILE. Note that this
290# is expanded very late and therefore there cannot be any code in the
291# AC_ARG_ENABLE. The default value for enable_largefile is emitted
292# unconditionally because the generated shell code always looks at
293# this variable.
294m4_define([_AC_SYS_LARGEFILE_ENABLE],
295[m4_divert_text([DEFAULTS],
296 enable_largefile=yes)]dnl
297[AC_ARG_ENABLE([largefile],
298 [AS_HELP_STRING([--disable-largefile], [omit support for large files])])])
53 299
54# AC_SYS_LARGEFILE 300# AC_SYS_LARGEFILE
55# ---------------- 301# ----------------
56# By default, many hosts won't let programs access large files; 302# By default, many hosts won't let programs access large files;
57# one must use special compiler options to get large-file access to work. 303# one must use special compiler options to get large-file access to work.
58# For more details about this brain damage please see: 304# For more details about this brain damage please see:
59# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html 305# http://www.unix.org/version2/whatsnew/lfs20mar.html
306# Additionally, on Linux file systems with 64-bit inodes a file that happens
307# to have a 64-bit inode number cannot be accessed by 32-bit applications on
308# Linux x86/x86_64. This can occur with file systems such as XFS and NFS.
309# This macro allows configuration to continue if the system doesn't support
310# large files.
60AC_DEFUN([AC_SYS_LARGEFILE], 311AC_DEFUN([AC_SYS_LARGEFILE],
61[AC_ARG_ENABLE(largefile, 312[m4_provide_if([_AC_SYS_LARGEFILE_PROBE], [], [dnl
62 [ --disable-largefile omit support for large files]) 313 AS_IF([test "$enable_largefile" != no], [_AC_SYS_LARGEFILE_PROBE])
63if test "$enable_largefile" != no; then 314 AC_CONFIG_COMMANDS_PRE([_AC_SYS_LARGEFILE_ENABLE])
64 315])])
65 AC_CACHE_CHECK([for special C compiler options needed for large files], 316])# m4_ifndef AC_SYS_YEAR2038
66 ac_cv_sys_largefile_CC,
67 [ac_cv_sys_largefile_CC=no
68 if test "$GCC" != yes; then
69 ac_save_CC=$CC
70 while :; do
71 # IRIX 6.2 and later do not support large files by default,
72 # so use the C compiler's -n32 option if that helps.
73 AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
74 AC_COMPILE_IFELSE([], [break])
75 CC="$CC -n32"
76 AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
77 break
78 done
79 CC=$ac_save_CC
80 rm -f conftest.$ac_ext
81 fi])
82 if test "$ac_cv_sys_largefile_CC" != no; then
83 CC=$CC$ac_cv_sys_largefile_CC
84 fi
85
86 _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
87 ac_cv_sys_file_offset_bits,
88 [Number of bits in a file offset, on hosts where this is settable.],
89 [_AC_SYS_LARGEFILE_TEST_INCLUDES])
90 if test $ac_cv_sys_file_offset_bits = unknown; then
91 _AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
92 ac_cv_sys_large_files,
93 [Define for large files, on AIX-style hosts.],
94 [_AC_SYS_LARGEFILE_TEST_INCLUDES])
95 fi
96
97 AC_DEFINE([_DARWIN_USE_64_BIT_INODE], [1],
98 [Enable large inode numbers on Mac OS X 10.5.])
99fi
100])# AC_SYS_LARGEFILE
101])# m4_version_prereq 2.70
102 317
103# Enable large files on systems where this is implemented by Gnulib, not by the 318# Enable large files on systems where this is implemented by Gnulib, not by the
104# system headers. 319# system headers.
@@ -126,9 +341,24 @@ AC_DEFUN([gl_LARGEFILE],
126 else 341 else
127 WINDOWS_64_BIT_OFF_T=0 342 WINDOWS_64_BIT_OFF_T=0
128 fi 343 fi
129 dnl But all native Windows platforms (including mingw64) have a 32-bit 344 dnl Some mingw versions define, if _FILE_OFFSET_BITS=64, 'struct stat'
130 dnl st_size member in 'struct stat'. 345 dnl to 'struct _stat32i64' or 'struct _stat64' (depending on
131 WINDOWS_64_BIT_ST_SIZE=1 346 dnl _USE_32BIT_TIME_T), which has a 32-bit st_size member.
347 AC_CACHE_CHECK([for 64-bit st_size], [gl_cv_member_st_size_64],
348 [AC_COMPILE_IFELSE(
349 [AC_LANG_PROGRAM(
350 [[#include <sys/types.h>
351 struct stat buf;
352 int verify_st_size_size[sizeof (buf.st_size) >= 8 ? 1 : -1];
353 ]],
354 [[]])],
355 [gl_cv_member_st_size_64=yes], [gl_cv_member_st_size_64=no])
356 ])
357 if test $gl_cv_member_st_size_64 = no; then
358 WINDOWS_64_BIT_ST_SIZE=1
359 else
360 WINDOWS_64_BIT_ST_SIZE=0
361 fi
132 ;; 362 ;;
133 *) 363 *)
134 dnl Nothing to do on gnulib's side. 364 dnl Nothing to do on gnulib's side.
diff --git a/gl/m4/lcmessage.m4 b/gl/m4/lcmessage.m4
deleted file mode 100644
index d62a175..0000000
--- a/gl/m4/lcmessage.m4
+++ /dev/null
@@ -1,35 +0,0 @@
1# lcmessage.m4 serial 7 (gettext-0.18.2)
2dnl Copyright (C) 1995-2002, 2004-2005, 2008-2013 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7dnl
8dnl This file can can be used in projects which are not available under
9dnl the GNU General Public License or the GNU Library General Public
10dnl License but which still want to provide support for the GNU gettext
11dnl functionality.
12dnl Please note that the actual code of the GNU gettext library is covered
13dnl by the GNU Library General Public License, and the rest of the GNU
14dnl gettext package package is covered by the GNU General Public License.
15dnl They are *not* in the public domain.
16
17dnl Authors:
18dnl Ulrich Drepper <drepper@cygnus.com>, 1995.
19
20# Check whether LC_MESSAGES is available in <locale.h>.
21
22AC_DEFUN([gt_LC_MESSAGES],
23[
24 AC_CACHE_CHECK([for LC_MESSAGES], [gt_cv_val_LC_MESSAGES],
25 [AC_LINK_IFELSE(
26 [AC_LANG_PROGRAM(
27 [[#include <locale.h>]],
28 [[return LC_MESSAGES]])],
29 [gt_cv_val_LC_MESSAGES=yes],
30 [gt_cv_val_LC_MESSAGES=no])])
31 if test $gt_cv_val_LC_MESSAGES = yes; then
32 AC_DEFINE([HAVE_LC_MESSAGES], [1],
33 [Define if your <locale.h> file defines LC_MESSAGES.])
34 fi
35])
diff --git a/gl/m4/lib-ld.m4 b/gl/m4/lib-ld.m4
deleted file mode 100644
index c145e47..0000000
--- a/gl/m4/lib-ld.m4
+++ /dev/null
@@ -1,119 +0,0 @@
1# lib-ld.m4 serial 6
2dnl Copyright (C) 1996-2003, 2009-2013 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 Subroutines of libtool.m4,
8dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid
9dnl collision with libtool.m4.
10
11dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no.
12AC_DEFUN([AC_LIB_PROG_LD_GNU],
13[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld],
14[# I'd rather use --version here, but apparently some GNU lds only accept -v.
15case `$LD -v 2>&1 </dev/null` in
16*GNU* | *'with BFD'*)
17 acl_cv_prog_gnu_ld=yes
18 ;;
19*)
20 acl_cv_prog_gnu_ld=no
21 ;;
22esac])
23with_gnu_ld=$acl_cv_prog_gnu_ld
24])
25
26dnl From libtool-2.4. Sets the variable LD.
27AC_DEFUN([AC_LIB_PROG_LD],
28[AC_REQUIRE([AC_PROG_CC])dnl
29AC_REQUIRE([AC_CANONICAL_HOST])dnl
30
31AC_ARG_WITH([gnu-ld],
32 [AS_HELP_STRING([--with-gnu-ld],
33 [assume the C compiler uses GNU ld [default=no]])],
34 [test "$withval" = no || with_gnu_ld=yes],
35 [with_gnu_ld=no])dnl
36
37# Prepare PATH_SEPARATOR.
38# The user is always right.
39if test "${PATH_SEPARATOR+set}" != set; then
40 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
41 # contains only /bin. Note that ksh looks also at the FPATH variable,
42 # so we have to set that as well for the test.
43 PATH_SEPARATOR=:
44 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
45 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
46 || PATH_SEPARATOR=';'
47 }
48fi
49
50ac_prog=ld
51if test "$GCC" = yes; then
52 # Check if gcc -print-prog-name=ld gives a path.
53 AC_MSG_CHECKING([for ld used by $CC])
54 case $host in
55 *-*-mingw*)
56 # gcc leaves a trailing carriage return which upsets mingw
57 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
58 *)
59 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
60 esac
61 case $ac_prog in
62 # Accept absolute paths.
63 [[\\/]]* | ?:[[\\/]]*)
64 re_direlt='/[[^/]][[^/]]*/\.\./'
65 # Canonicalize the pathname of ld
66 ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'`
67 while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do
68 ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
69 done
70 test -z "$LD" && LD="$ac_prog"
71 ;;
72 "")
73 # If it fails, then pretend we aren't using GCC.
74 ac_prog=ld
75 ;;
76 *)
77 # If it is relative, then search for the first ld in PATH.
78 with_gnu_ld=unknown
79 ;;
80 esac
81elif test "$with_gnu_ld" = yes; then
82 AC_MSG_CHECKING([for GNU ld])
83else
84 AC_MSG_CHECKING([for non-GNU ld])
85fi
86AC_CACHE_VAL([acl_cv_path_LD],
87[if test -z "$LD"; then
88 acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
89 for ac_dir in $PATH; do
90 IFS="$acl_save_ifs"
91 test -z "$ac_dir" && ac_dir=.
92 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
93 acl_cv_path_LD="$ac_dir/$ac_prog"
94 # Check to see if the program is GNU ld. I'd rather use --version,
95 # but apparently some variants of GNU ld only accept -v.
96 # Break only if it was the GNU/non-GNU ld that we prefer.
97 case `"$acl_cv_path_LD" -v 2>&1 </dev/null` in
98 *GNU* | *'with BFD'*)
99 test "$with_gnu_ld" != no && break
100 ;;
101 *)
102 test "$with_gnu_ld" != yes && break
103 ;;
104 esac
105 fi
106 done
107 IFS="$acl_save_ifs"
108else
109 acl_cv_path_LD="$LD" # Let the user override the test with a path.
110fi])
111LD="$acl_cv_path_LD"
112if test -n "$LD"; then
113 AC_MSG_RESULT([$LD])
114else
115 AC_MSG_RESULT([no])
116fi
117test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
118AC_LIB_PROG_LD_GNU
119])
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4
deleted file mode 100644
index 073f040..0000000
--- a/gl/m4/lib-link.m4
+++ /dev/null
@@ -1,777 +0,0 @@
1# lib-link.m4 serial 26 (gettext-0.18.2)
2dnl Copyright (C) 2001-2013 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.
8
9AC_PREREQ([2.54])
10
11dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
12dnl the libraries corresponding to explicit and implicit dependencies.
13dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
14dnl augments the CPPFLAGS variable.
15dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
16dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
17AC_DEFUN([AC_LIB_LINKFLAGS],
18[
19 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
20 AC_REQUIRE([AC_LIB_RPATH])
21 pushdef([Name],[m4_translit([$1],[./+-], [____])])
22 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
23 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
24 AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
25 AC_LIB_LINKFLAGS_BODY([$1], [$2])
26 ac_cv_lib[]Name[]_libs="$LIB[]NAME"
27 ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
28 ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
29 ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
30 ])
31 LIB[]NAME="$ac_cv_lib[]Name[]_libs"
32 LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
33 INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
34 LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
35 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
36 AC_SUBST([LIB]NAME)
37 AC_SUBST([LTLIB]NAME)
38 AC_SUBST([LIB]NAME[_PREFIX])
39 dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
40 dnl results of this search when this library appears as a dependency.
41 HAVE_LIB[]NAME=yes
42 popdef([NAME])
43 popdef([Name])
44])
45
46dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message])
47dnl searches for libname and the libraries corresponding to explicit and
48dnl implicit dependencies, together with the specified include files and
49dnl the ability to compile and link the specified testcode. The missing-message
50dnl defaults to 'no' and may contain additional hints for the user.
51dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME}
52dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and
53dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
54dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
55dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
56dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
57AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
58[
59 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
60 AC_REQUIRE([AC_LIB_RPATH])
61 pushdef([Name],[m4_translit([$1],[./+-], [____])])
62 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
63 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
64
65 dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
66 dnl accordingly.
67 AC_LIB_LINKFLAGS_BODY([$1], [$2])
68
69 dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
70 dnl because if the user has installed lib[]Name and not disabled its use
71 dnl via --without-lib[]Name-prefix, he wants to use it.
72 ac_save_CPPFLAGS="$CPPFLAGS"
73 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
74
75 AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
76 ac_save_LIBS="$LIBS"
77 dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS,
78 dnl because these -l options might require -L options that are present in
79 dnl LIBS. -l options benefit only from the -L options listed before it.
80 dnl Otherwise, add it to the front of LIBS, because it may be a static
81 dnl library that depends on another static library that is present in LIBS.
82 dnl Static libraries benefit only from the static libraries listed after
83 dnl it.
84 case " $LIB[]NAME" in
85 *" -l"*) LIBS="$LIBS $LIB[]NAME" ;;
86 *) LIBS="$LIB[]NAME $LIBS" ;;
87 esac
88 AC_LINK_IFELSE(
89 [AC_LANG_PROGRAM([[$3]], [[$4]])],
90 [ac_cv_lib[]Name=yes],
91 [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
92 LIBS="$ac_save_LIBS"
93 ])
94 if test "$ac_cv_lib[]Name" = yes; then
95 HAVE_LIB[]NAME=yes
96 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
97 AC_MSG_CHECKING([how to link with lib[]$1])
98 AC_MSG_RESULT([$LIB[]NAME])
99 else
100 HAVE_LIB[]NAME=no
101 dnl If $LIB[]NAME didn't lead to a usable library, we don't need
102 dnl $INC[]NAME either.
103 CPPFLAGS="$ac_save_CPPFLAGS"
104 LIB[]NAME=
105 LTLIB[]NAME=
106 LIB[]NAME[]_PREFIX=
107 fi
108 AC_SUBST([HAVE_LIB]NAME)
109 AC_SUBST([LIB]NAME)
110 AC_SUBST([LTLIB]NAME)
111 AC_SUBST([LIB]NAME[_PREFIX])
112 popdef([NAME])
113 popdef([Name])
114])
115
116dnl Determine the platform dependent parameters needed to use rpath:
117dnl acl_libext,
118dnl acl_shlibext,
119dnl acl_libname_spec,
120dnl acl_library_names_spec,
121dnl acl_hardcode_libdir_flag_spec,
122dnl acl_hardcode_libdir_separator,
123dnl acl_hardcode_direct,
124dnl acl_hardcode_minus_L.
125AC_DEFUN([AC_LIB_RPATH],
126[
127 dnl Tell automake >= 1.10 to complain if config.rpath is missing.
128 m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
129 AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
130 AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
131 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
132 AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
133 AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [
134 CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
135 ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
136 . ./conftest.sh
137 rm -f ./conftest.sh
138 acl_cv_rpath=done
139 ])
140 wl="$acl_cv_wl"
141 acl_libext="$acl_cv_libext"
142 acl_shlibext="$acl_cv_shlibext"
143 acl_libname_spec="$acl_cv_libname_spec"
144 acl_library_names_spec="$acl_cv_library_names_spec"
145 acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
146 acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
147 acl_hardcode_direct="$acl_cv_hardcode_direct"
148 acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
149 dnl Determine whether the user wants rpath handling at all.
150 AC_ARG_ENABLE([rpath],
151 [ --disable-rpath do not hardcode runtime library paths],
152 :, enable_rpath=yes)
153])
154
155dnl AC_LIB_FROMPACKAGE(name, package)
156dnl declares that libname comes from the given package. The configure file
157dnl will then not have a --with-libname-prefix option but a
158dnl --with-package-prefix option. Several libraries can come from the same
159dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar
160dnl macro call that searches for libname.
161AC_DEFUN([AC_LIB_FROMPACKAGE],
162[
163 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
164 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
165 define([acl_frompackage_]NAME, [$2])
166 popdef([NAME])
167 pushdef([PACK],[$2])
168 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
169 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
170 define([acl_libsinpackage_]PACKUP,
171 m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1])
172 popdef([PACKUP])
173 popdef([PACK])
174])
175
176dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
177dnl the libraries corresponding to explicit and implicit dependencies.
178dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
179dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
180dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
181AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
182[
183 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
184 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
185 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
186 pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])])
187 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
188 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
189 pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])])
190 dnl Autoconf >= 2.61 supports dots in --with options.
191 pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[m4_translit(PACK,[.],[_])],PACK)])
192 dnl By default, look in $includedir and $libdir.
193 use_additional=yes
194 AC_LIB_WITH_FINAL_PREFIX([
195 eval additional_includedir=\"$includedir\"
196 eval additional_libdir=\"$libdir\"
197 ])
198 AC_ARG_WITH(P_A_C_K[-prefix],
199[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib
200 --without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]],
201[
202 if test "X$withval" = "Xno"; then
203 use_additional=no
204 else
205 if test "X$withval" = "X"; then
206 AC_LIB_WITH_FINAL_PREFIX([
207 eval additional_includedir=\"$includedir\"
208 eval additional_libdir=\"$libdir\"
209 ])
210 else
211 additional_includedir="$withval/include"
212 additional_libdir="$withval/$acl_libdirstem"
213 if test "$acl_libdirstem2" != "$acl_libdirstem" \
214 && ! test -d "$withval/$acl_libdirstem"; then
215 additional_libdir="$withval/$acl_libdirstem2"
216 fi
217 fi
218 fi
219])
220 dnl Search the library and its dependencies in $additional_libdir and
221 dnl $LDFLAGS. Using breadth-first-seach.
222 LIB[]NAME=
223 LTLIB[]NAME=
224 INC[]NAME=
225 LIB[]NAME[]_PREFIX=
226 dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
227 dnl computed. So it has to be reset here.
228 HAVE_LIB[]NAME=
229 rpathdirs=
230 ltrpathdirs=
231 names_already_handled=
232 names_next_round='$1 $2'
233 while test -n "$names_next_round"; do
234 names_this_round="$names_next_round"
235 names_next_round=
236 for name in $names_this_round; do
237 already_handled=
238 for n in $names_already_handled; do
239 if test "$n" = "$name"; then
240 already_handled=yes
241 break
242 fi
243 done
244 if test -z "$already_handled"; then
245 names_already_handled="$names_already_handled $name"
246 dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
247 dnl or AC_LIB_HAVE_LINKFLAGS call.
248 uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'`
249 eval value=\"\$HAVE_LIB$uppername\"
250 if test -n "$value"; then
251 if test "$value" = yes; then
252 eval value=\"\$LIB$uppername\"
253 test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
254 eval value=\"\$LTLIB$uppername\"
255 test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
256 else
257 dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
258 dnl that this library doesn't exist. So just drop it.
259 :
260 fi
261 else
262 dnl Search the library lib$name in $additional_libdir and $LDFLAGS
263 dnl and the already constructed $LIBNAME/$LTLIBNAME.
264 found_dir=
265 found_la=
266 found_so=
267 found_a=
268 eval libname=\"$acl_libname_spec\" # typically: libname=lib$name
269 if test -n "$acl_shlibext"; then
270 shrext=".$acl_shlibext" # typically: shrext=.so
271 else
272 shrext=
273 fi
274 if test $use_additional = yes; then
275 dir="$additional_libdir"
276 dnl The same code as in the loop below:
277 dnl First look for a shared library.
278 if test -n "$acl_shlibext"; then
279 if test -f "$dir/$libname$shrext"; then
280 found_dir="$dir"
281 found_so="$dir/$libname$shrext"
282 else
283 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
284 ver=`(cd "$dir" && \
285 for f in "$libname$shrext".*; do echo "$f"; done \
286 | sed -e "s,^$libname$shrext\\\\.,," \
287 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
288 | sed 1q ) 2>/dev/null`
289 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
290 found_dir="$dir"
291 found_so="$dir/$libname$shrext.$ver"
292 fi
293 else
294 eval library_names=\"$acl_library_names_spec\"
295 for f in $library_names; do
296 if test -f "$dir/$f"; then
297 found_dir="$dir"
298 found_so="$dir/$f"
299 break
300 fi
301 done
302 fi
303 fi
304 fi
305 dnl Then look for a static library.
306 if test "X$found_dir" = "X"; then
307 if test -f "$dir/$libname.$acl_libext"; then
308 found_dir="$dir"
309 found_a="$dir/$libname.$acl_libext"
310 fi
311 fi
312 if test "X$found_dir" != "X"; then
313 if test -f "$dir/$libname.la"; then
314 found_la="$dir/$libname.la"
315 fi
316 fi
317 fi
318 if test "X$found_dir" = "X"; then
319 for x in $LDFLAGS $LTLIB[]NAME; do
320 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
321 case "$x" in
322 -L*)
323 dir=`echo "X$x" | sed -e 's/^X-L//'`
324 dnl First look for a shared library.
325 if test -n "$acl_shlibext"; then
326 if test -f "$dir/$libname$shrext"; then
327 found_dir="$dir"
328 found_so="$dir/$libname$shrext"
329 else
330 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
331 ver=`(cd "$dir" && \
332 for f in "$libname$shrext".*; do echo "$f"; done \
333 | sed -e "s,^$libname$shrext\\\\.,," \
334 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
335 | sed 1q ) 2>/dev/null`
336 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
337 found_dir="$dir"
338 found_so="$dir/$libname$shrext.$ver"
339 fi
340 else
341 eval library_names=\"$acl_library_names_spec\"
342 for f in $library_names; do
343 if test -f "$dir/$f"; then
344 found_dir="$dir"
345 found_so="$dir/$f"
346 break
347 fi
348 done
349 fi
350 fi
351 fi
352 dnl Then look for a static library.
353 if test "X$found_dir" = "X"; then
354 if test -f "$dir/$libname.$acl_libext"; then
355 found_dir="$dir"
356 found_a="$dir/$libname.$acl_libext"
357 fi
358 fi
359 if test "X$found_dir" != "X"; then
360 if test -f "$dir/$libname.la"; then
361 found_la="$dir/$libname.la"
362 fi
363 fi
364 ;;
365 esac
366 if test "X$found_dir" != "X"; then
367 break
368 fi
369 done
370 fi
371 if test "X$found_dir" != "X"; then
372 dnl Found the library.
373 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
374 if test "X$found_so" != "X"; then
375 dnl Linking with a shared library. We attempt to hardcode its
376 dnl directory into the executable's runpath, unless it's the
377 dnl standard /usr/lib.
378 if test "$enable_rpath" = no \
379 || test "X$found_dir" = "X/usr/$acl_libdirstem" \
380 || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then
381 dnl No hardcoding is needed.
382 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
383 else
384 dnl Use an explicit option to hardcode DIR into the resulting
385 dnl binary.
386 dnl Potentially add DIR to ltrpathdirs.
387 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
388 haveit=
389 for x in $ltrpathdirs; do
390 if test "X$x" = "X$found_dir"; then
391 haveit=yes
392 break
393 fi
394 done
395 if test -z "$haveit"; then
396 ltrpathdirs="$ltrpathdirs $found_dir"
397 fi
398 dnl The hardcoding into $LIBNAME is system dependent.
399 if test "$acl_hardcode_direct" = yes; then
400 dnl Using DIR/libNAME.so during linking hardcodes DIR into the
401 dnl resulting binary.
402 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
403 else
404 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
405 dnl Use an explicit option to hardcode DIR into the resulting
406 dnl binary.
407 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
408 dnl Potentially add DIR to rpathdirs.
409 dnl The rpathdirs will be appended to $LIBNAME at the end.
410 haveit=
411 for x in $rpathdirs; do
412 if test "X$x" = "X$found_dir"; then
413 haveit=yes
414 break
415 fi
416 done
417 if test -z "$haveit"; then
418 rpathdirs="$rpathdirs $found_dir"
419 fi
420 else
421 dnl Rely on "-L$found_dir".
422 dnl But don't add it if it's already contained in the LDFLAGS
423 dnl or the already constructed $LIBNAME
424 haveit=
425 for x in $LDFLAGS $LIB[]NAME; do
426 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
427 if test "X$x" = "X-L$found_dir"; then
428 haveit=yes
429 break
430 fi
431 done
432 if test -z "$haveit"; then
433 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
434 fi
435 if test "$acl_hardcode_minus_L" != no; then
436 dnl FIXME: Not sure whether we should use
437 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
438 dnl here.
439 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
440 else
441 dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
442 dnl here, because this doesn't fit in flags passed to the
443 dnl compiler. So give up. No hardcoding. This affects only
444 dnl very old systems.
445 dnl FIXME: Not sure whether we should use
446 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
447 dnl here.
448 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
449 fi
450 fi
451 fi
452 fi
453 else
454 if test "X$found_a" != "X"; then
455 dnl Linking with a static library.
456 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
457 else
458 dnl We shouldn't come here, but anyway it's good to have a
459 dnl fallback.
460 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
461 fi
462 fi
463 dnl Assume the include files are nearby.
464 additional_includedir=
465 case "$found_dir" in
466 */$acl_libdirstem | */$acl_libdirstem/)
467 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
468 if test "$name" = '$1'; then
469 LIB[]NAME[]_PREFIX="$basedir"
470 fi
471 additional_includedir="$basedir/include"
472 ;;
473 */$acl_libdirstem2 | */$acl_libdirstem2/)
474 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'`
475 if test "$name" = '$1'; then
476 LIB[]NAME[]_PREFIX="$basedir"
477 fi
478 additional_includedir="$basedir/include"
479 ;;
480 esac
481 if test "X$additional_includedir" != "X"; then
482 dnl Potentially add $additional_includedir to $INCNAME.
483 dnl But don't add it
484 dnl 1. if it's the standard /usr/include,
485 dnl 2. if it's /usr/local/include and we are using GCC on Linux,
486 dnl 3. if it's already present in $CPPFLAGS or the already
487 dnl constructed $INCNAME,
488 dnl 4. if it doesn't exist as a directory.
489 if test "X$additional_includedir" != "X/usr/include"; then
490 haveit=
491 if test "X$additional_includedir" = "X/usr/local/include"; then
492 if test -n "$GCC"; then
493 case $host_os in
494 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
495 esac
496 fi
497 fi
498 if test -z "$haveit"; then
499 for x in $CPPFLAGS $INC[]NAME; do
500 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
501 if test "X$x" = "X-I$additional_includedir"; then
502 haveit=yes
503 break
504 fi
505 done
506 if test -z "$haveit"; then
507 if test -d "$additional_includedir"; then
508 dnl Really add $additional_includedir to $INCNAME.
509 INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
510 fi
511 fi
512 fi
513 fi
514 fi
515 dnl Look for dependencies.
516 if test -n "$found_la"; then
517 dnl Read the .la file. It defines the variables
518 dnl dlname, library_names, old_library, dependency_libs, current,
519 dnl age, revision, installed, dlopen, dlpreopen, libdir.
520 save_libdir="$libdir"
521 case "$found_la" in
522 */* | *\\*) . "$found_la" ;;
523 *) . "./$found_la" ;;
524 esac
525 libdir="$save_libdir"
526 dnl We use only dependency_libs.
527 for dep in $dependency_libs; do
528 case "$dep" in
529 -L*)
530 additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
531 dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
532 dnl But don't add it
533 dnl 1. if it's the standard /usr/lib,
534 dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
535 dnl 3. if it's already present in $LDFLAGS or the already
536 dnl constructed $LIBNAME,
537 dnl 4. if it doesn't exist as a directory.
538 if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \
539 && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then
540 haveit=
541 if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \
542 || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then
543 if test -n "$GCC"; then
544 case $host_os in
545 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
546 esac
547 fi
548 fi
549 if test -z "$haveit"; then
550 haveit=
551 for x in $LDFLAGS $LIB[]NAME; do
552 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
553 if test "X$x" = "X-L$additional_libdir"; then
554 haveit=yes
555 break
556 fi
557 done
558 if test -z "$haveit"; then
559 if test -d "$additional_libdir"; then
560 dnl Really add $additional_libdir to $LIBNAME.
561 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
562 fi
563 fi
564 haveit=
565 for x in $LDFLAGS $LTLIB[]NAME; do
566 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
567 if test "X$x" = "X-L$additional_libdir"; then
568 haveit=yes
569 break
570 fi
571 done
572 if test -z "$haveit"; then
573 if test -d "$additional_libdir"; then
574 dnl Really add $additional_libdir to $LTLIBNAME.
575 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
576 fi
577 fi
578 fi
579 fi
580 ;;
581 -R*)
582 dir=`echo "X$dep" | sed -e 's/^X-R//'`
583 if test "$enable_rpath" != no; then
584 dnl Potentially add DIR to rpathdirs.
585 dnl The rpathdirs will be appended to $LIBNAME at the end.
586 haveit=
587 for x in $rpathdirs; do
588 if test "X$x" = "X$dir"; then
589 haveit=yes
590 break
591 fi
592 done
593 if test -z "$haveit"; then
594 rpathdirs="$rpathdirs $dir"
595 fi
596 dnl Potentially add DIR to ltrpathdirs.
597 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
598 haveit=
599 for x in $ltrpathdirs; do
600 if test "X$x" = "X$dir"; then
601 haveit=yes
602 break
603 fi
604 done
605 if test -z "$haveit"; then
606 ltrpathdirs="$ltrpathdirs $dir"
607 fi
608 fi
609 ;;
610 -l*)
611 dnl Handle this in the next round.
612 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
613 ;;
614 *.la)
615 dnl Handle this in the next round. Throw away the .la's
616 dnl directory; it is already contained in a preceding -L
617 dnl option.
618 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
619 ;;
620 *)
621 dnl Most likely an immediate library name.
622 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
623 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
624 ;;
625 esac
626 done
627 fi
628 else
629 dnl Didn't find the library; assume it is in the system directories
630 dnl known to the linker and runtime loader. (All the system
631 dnl directories known to the linker should also be known to the
632 dnl runtime loader, otherwise the system is severely misconfigured.)
633 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
634 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
635 fi
636 fi
637 fi
638 done
639 done
640 if test "X$rpathdirs" != "X"; then
641 if test -n "$acl_hardcode_libdir_separator"; then
642 dnl Weird platform: only the last -rpath option counts, the user must
643 dnl pass all path elements in one option. We can arrange that for a
644 dnl single library, but not when more than one $LIBNAMEs are used.
645 alldirs=
646 for found_dir in $rpathdirs; do
647 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
648 done
649 dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
650 acl_save_libdir="$libdir"
651 libdir="$alldirs"
652 eval flag=\"$acl_hardcode_libdir_flag_spec\"
653 libdir="$acl_save_libdir"
654 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
655 else
656 dnl The -rpath options are cumulative.
657 for found_dir in $rpathdirs; do
658 acl_save_libdir="$libdir"
659 libdir="$found_dir"
660 eval flag=\"$acl_hardcode_libdir_flag_spec\"
661 libdir="$acl_save_libdir"
662 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
663 done
664 fi
665 fi
666 if test "X$ltrpathdirs" != "X"; then
667 dnl When using libtool, the option that works for both libraries and
668 dnl executables is -R. The -R options are cumulative.
669 for found_dir in $ltrpathdirs; do
670 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
671 done
672 fi
673 popdef([P_A_C_K])
674 popdef([PACKLIBS])
675 popdef([PACKUP])
676 popdef([PACK])
677 popdef([NAME])
678])
679
680dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
681dnl unless already present in VAR.
682dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
683dnl contains two or three consecutive elements that belong together.
684AC_DEFUN([AC_LIB_APPENDTOVAR],
685[
686 for element in [$2]; do
687 haveit=
688 for x in $[$1]; do
689 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
690 if test "X$x" = "X$element"; then
691 haveit=yes
692 break
693 fi
694 done
695 if test -z "$haveit"; then
696 [$1]="${[$1]}${[$1]:+ }$element"
697 fi
698 done
699])
700
701dnl For those cases where a variable contains several -L and -l options
702dnl referring to unknown libraries and directories, this macro determines the
703dnl necessary additional linker options for the runtime path.
704dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
705dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
706dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
707dnl otherwise linking without libtool is assumed.
708AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
709[
710 AC_REQUIRE([AC_LIB_RPATH])
711 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
712 $1=
713 if test "$enable_rpath" != no; then
714 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
715 dnl Use an explicit option to hardcode directories into the resulting
716 dnl binary.
717 rpathdirs=
718 next=
719 for opt in $2; do
720 if test -n "$next"; then
721 dir="$next"
722 dnl No need to hardcode the standard /usr/lib.
723 if test "X$dir" != "X/usr/$acl_libdirstem" \
724 && test "X$dir" != "X/usr/$acl_libdirstem2"; then
725 rpathdirs="$rpathdirs $dir"
726 fi
727 next=
728 else
729 case $opt in
730 -L) next=yes ;;
731 -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
732 dnl No need to hardcode the standard /usr/lib.
733 if test "X$dir" != "X/usr/$acl_libdirstem" \
734 && test "X$dir" != "X/usr/$acl_libdirstem2"; then
735 rpathdirs="$rpathdirs $dir"
736 fi
737 next= ;;
738 *) next= ;;
739 esac
740 fi
741 done
742 if test "X$rpathdirs" != "X"; then
743 if test -n ""$3""; then
744 dnl libtool is used for linking. Use -R options.
745 for dir in $rpathdirs; do
746 $1="${$1}${$1:+ }-R$dir"
747 done
748 else
749 dnl The linker is used for linking directly.
750 if test -n "$acl_hardcode_libdir_separator"; then
751 dnl Weird platform: only the last -rpath option counts, the user
752 dnl must pass all path elements in one option.
753 alldirs=
754 for dir in $rpathdirs; do
755 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
756 done
757 acl_save_libdir="$libdir"
758 libdir="$alldirs"
759 eval flag=\"$acl_hardcode_libdir_flag_spec\"
760 libdir="$acl_save_libdir"
761 $1="$flag"
762 else
763 dnl The -rpath options are cumulative.
764 for dir in $rpathdirs; do
765 acl_save_libdir="$libdir"
766 libdir="$dir"
767 eval flag=\"$acl_hardcode_libdir_flag_spec\"
768 libdir="$acl_save_libdir"
769 $1="${$1}${$1:+ }$flag"
770 done
771 fi
772 fi
773 fi
774 fi
775 fi
776 AC_SUBST([$1])
777])
diff --git a/gl/m4/lib-prefix.m4 b/gl/m4/lib-prefix.m4
deleted file mode 100644
index 60908e8..0000000
--- a/gl/m4/lib-prefix.m4
+++ /dev/null
@@ -1,224 +0,0 @@
1# lib-prefix.m4 serial 7 (gettext-0.18)
2dnl Copyright (C) 2001-2005, 2008-2013 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.
8
9dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
10dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
11dnl require excessive bracketing.
12ifdef([AC_HELP_STRING],
13[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
14[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
15
16dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
17dnl to access previously installed libraries. The basic assumption is that
18dnl a user will want packages to use other packages he previously installed
19dnl with the same --prefix option.
20dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
21dnl libraries, but is otherwise very convenient.
22AC_DEFUN([AC_LIB_PREFIX],
23[
24 AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
25 AC_REQUIRE([AC_PROG_CC])
26 AC_REQUIRE([AC_CANONICAL_HOST])
27 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
28 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
29 dnl By default, look in $includedir and $libdir.
30 use_additional=yes
31 AC_LIB_WITH_FINAL_PREFIX([
32 eval additional_includedir=\"$includedir\"
33 eval additional_libdir=\"$libdir\"
34 ])
35 AC_LIB_ARG_WITH([lib-prefix],
36[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
37 --without-lib-prefix don't search for libraries in includedir and libdir],
38[
39 if test "X$withval" = "Xno"; then
40 use_additional=no
41 else
42 if test "X$withval" = "X"; then
43 AC_LIB_WITH_FINAL_PREFIX([
44 eval additional_includedir=\"$includedir\"
45 eval additional_libdir=\"$libdir\"
46 ])
47 else
48 additional_includedir="$withval/include"
49 additional_libdir="$withval/$acl_libdirstem"
50 fi
51 fi
52])
53 if test $use_additional = yes; then
54 dnl Potentially add $additional_includedir to $CPPFLAGS.
55 dnl But don't add it
56 dnl 1. if it's the standard /usr/include,
57 dnl 2. if it's already present in $CPPFLAGS,
58 dnl 3. if it's /usr/local/include and we are using GCC on Linux,
59 dnl 4. if it doesn't exist as a directory.
60 if test "X$additional_includedir" != "X/usr/include"; then
61 haveit=
62 for x in $CPPFLAGS; do
63 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
64 if test "X$x" = "X-I$additional_includedir"; then
65 haveit=yes
66 break
67 fi
68 done
69 if test -z "$haveit"; then
70 if test "X$additional_includedir" = "X/usr/local/include"; then
71 if test -n "$GCC"; then
72 case $host_os in
73 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
74 esac
75 fi
76 fi
77 if test -z "$haveit"; then
78 if test -d "$additional_includedir"; then
79 dnl Really add $additional_includedir to $CPPFLAGS.
80 CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
81 fi
82 fi
83 fi
84 fi
85 dnl Potentially add $additional_libdir to $LDFLAGS.
86 dnl But don't add it
87 dnl 1. if it's the standard /usr/lib,
88 dnl 2. if it's already present in $LDFLAGS,
89 dnl 3. if it's /usr/local/lib and we are using GCC on Linux,
90 dnl 4. if it doesn't exist as a directory.
91 if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
92 haveit=
93 for x in $LDFLAGS; do
94 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
95 if test "X$x" = "X-L$additional_libdir"; then
96 haveit=yes
97 break
98 fi
99 done
100 if test -z "$haveit"; then
101 if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
102 if test -n "$GCC"; then
103 case $host_os in
104 linux*) haveit=yes;;
105 esac
106 fi
107 fi
108 if test -z "$haveit"; then
109 if test -d "$additional_libdir"; then
110 dnl Really add $additional_libdir to $LDFLAGS.
111 LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
112 fi
113 fi
114 fi
115 fi
116 fi
117])
118
119dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
120dnl acl_final_exec_prefix, containing the values to which $prefix and
121dnl $exec_prefix will expand at the end of the configure script.
122AC_DEFUN([AC_LIB_PREPARE_PREFIX],
123[
124 dnl Unfortunately, prefix and exec_prefix get only finally determined
125 dnl at the end of configure.
126 if test "X$prefix" = "XNONE"; then
127 acl_final_prefix="$ac_default_prefix"
128 else
129 acl_final_prefix="$prefix"
130 fi
131 if test "X$exec_prefix" = "XNONE"; then
132 acl_final_exec_prefix='${prefix}'
133 else
134 acl_final_exec_prefix="$exec_prefix"
135 fi
136 acl_save_prefix="$prefix"
137 prefix="$acl_final_prefix"
138 eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
139 prefix="$acl_save_prefix"
140])
141
142dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
143dnl variables prefix and exec_prefix bound to the values they will have
144dnl at the end of the configure script.
145AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
146[
147 acl_save_prefix="$prefix"
148 prefix="$acl_final_prefix"
149 acl_save_exec_prefix="$exec_prefix"
150 exec_prefix="$acl_final_exec_prefix"
151 $1
152 exec_prefix="$acl_save_exec_prefix"
153 prefix="$acl_save_prefix"
154])
155
156dnl AC_LIB_PREPARE_MULTILIB creates
157dnl - a variable acl_libdirstem, containing the basename of the libdir, either
158dnl "lib" or "lib64" or "lib/64",
159dnl - a variable acl_libdirstem2, as a secondary possible value for
160dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or
161dnl "lib/amd64".
162AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
163[
164 dnl There is no formal standard regarding lib and lib64.
165 dnl On glibc systems, the current practice is that on a system supporting
166 dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
167 dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine
168 dnl the compiler's default mode by looking at the compiler's library search
169 dnl path. If at least one of its elements ends in /lib64 or points to a
170 dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI.
171 dnl Otherwise we use the default, namely "lib".
172 dnl On Solaris systems, the current practice is that on a system supporting
173 dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
174 dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
175 dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
176 AC_REQUIRE([AC_CANONICAL_HOST])
177 acl_libdirstem=lib
178 acl_libdirstem2=
179 case "$host_os" in
180 solaris*)
181 dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
182 dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
183 dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
184 dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
185 dnl symlink is missing, so we set acl_libdirstem2 too.
186 AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
187 [AC_EGREP_CPP([sixtyfour bits], [
188#ifdef _LP64
189sixtyfour bits
190#endif
191 ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
192 ])
193 if test $gl_cv_solaris_64bit = yes; then
194 acl_libdirstem=lib/64
195 case "$host_cpu" in
196 sparc*) acl_libdirstem2=lib/sparcv9 ;;
197 i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
198 esac
199 fi
200 ;;
201 *)
202 searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
203 if test -n "$searchpath"; then
204 acl_save_IFS="${IFS= }"; IFS=":"
205 for searchdir in $searchpath; do
206 if test -d "$searchdir"; then
207 case "$searchdir" in
208 */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
209 */../ | */.. )
210 # Better ignore directories of this form. They are misleading.
211 ;;
212 *) searchdir=`cd "$searchdir" && pwd`
213 case "$searchdir" in
214 */lib64 ) acl_libdirstem=lib64 ;;
215 esac ;;
216 esac
217 fi
218 done
219 IFS="$acl_save_IFS"
220 fi
221 ;;
222 esac
223 test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
224])
diff --git a/gl/m4/limits-h.m4 b/gl/m4/limits-h.m4
new file mode 100644
index 0000000..5088fa1
--- /dev/null
+++ b/gl/m4/limits-h.m4
@@ -0,0 +1,41 @@
1dnl Check whether limits.h has needed features.
2
3dnl Copyright 2016-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8dnl From Paul Eggert.
9
10AC_DEFUN_ONCE([gl_LIMITS_H],
11[
12 gl_CHECK_NEXT_HEADERS([limits.h])
13
14 AC_CACHE_CHECK([whether limits.h has WORD_BIT, BOOL_WIDTH etc.],
15 [gl_cv_header_limits_width],
16 [AC_COMPILE_IFELSE(
17 [AC_LANG_PROGRAM(
18 [[#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
19 #define __STDC_WANT_IEC_60559_BFP_EXT__ 1
20 #endif
21 #include <limits.h>
22 long long llm = LLONG_MAX;
23 int wb = WORD_BIT;
24 int ullw = ULLONG_WIDTH;
25 int bw = BOOL_WIDTH;
26 ]])],
27 [gl_cv_header_limits_width=yes],
28 [gl_cv_header_limits_width=no])])
29 if test "$gl_cv_header_limits_width" = yes; then
30 GL_GENERATE_LIMITS_H=false
31 else
32 GL_GENERATE_LIMITS_H=true
33 fi
34])
35
36dnl Unconditionally enables the replacement of <limits.h>.
37AC_DEFUN([gl_REPLACE_LIMITS_H],
38[
39 AC_REQUIRE([gl_LIMITS_H])
40 GL_GENERATE_LIMITS_H=true
41])
diff --git a/gl/m4/localcharset.m4 b/gl/m4/localcharset.m4
index 2e93e58..15b6b2a 100644
--- a/gl/m4/localcharset.m4
+++ b/gl/m4/localcharset.m4
@@ -1,5 +1,5 @@
1# localcharset.m4 serial 7 1# localcharset.m4 serial 8
2dnl Copyright (C) 2002, 2004, 2006, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2004, 2006, 2009-2023 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,10 +8,4 @@ AC_DEFUN([gl_LOCALCHARSET],
8[ 8[
9 dnl Prerequisites of lib/localcharset.c. 9 dnl Prerequisites of lib/localcharset.c.
10 AC_REQUIRE([AM_LANGINFO_CODESET]) 10 AC_REQUIRE([AM_LANGINFO_CODESET])
11 AC_REQUIRE([gl_FCNTL_O_FLAGS])
12 AC_CHECK_DECLS_ONCE([getc_unlocked])
13
14 dnl Prerequisites of the lib/Makefile.am snippet.
15 AC_REQUIRE([AC_CANONICAL_HOST])
16 AC_REQUIRE([gl_GLIBC21])
17]) 11])
diff --git a/gl/m4/locale-fr.m4 b/gl/m4/locale-fr.m4
index ef199e3..8c41fad 100644
--- a/gl/m4/locale-fr.m4
+++ b/gl/m4/locale-fr.m4
@@ -1,5 +1,5 @@
1# locale-fr.m4 serial 17 1# locale-fr.m4 serial 20
2dnl Copyright (C) 2003, 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2023 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,8 +12,7 @@ AC_DEFUN([gt_LOCALE_FR],
12 AC_REQUIRE([AC_CANONICAL_HOST]) 12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_REQUIRE([AM_LANGINFO_CODESET]) 13 AC_REQUIRE([AM_LANGINFO_CODESET])
14 AC_CACHE_CHECK([for a traditional french locale], [gt_cv_locale_fr], [ 14 AC_CACHE_CHECK([for a traditional french locale], [gt_cv_locale_fr], [
15 AC_LANG_CONFTEST([AC_LANG_SOURCE([ 15 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
16changequote(,)dnl
17#include <locale.h> 16#include <locale.h>
18#include <time.h> 17#include <time.h>
19#if HAVE_LANGINFO_CODESET 18#if HAVE_LANGINFO_CODESET
@@ -24,8 +23,14 @@ changequote(,)dnl
24struct tm t; 23struct tm t;
25char buf[16]; 24char buf[16];
26int main () { 25int main () {
26 /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
27 imitates locale dependent behaviour by looking at the environment
28 variables, and all locales use the UTF-8 encoding. */
29#if defined __BEOS__ || defined __HAIKU__
30 return 1;
31#else
27 /* Check whether the given locale name is recognized by the system. */ 32 /* Check whether the given locale name is recognized by the system. */
28#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 33# if defined _WIN32 && !defined __CYGWIN__
29 /* On native Windows, setlocale(category, "") looks at the system settings, 34 /* On native Windows, setlocale(category, "") looks at the system settings,
30 not at the environment variables. Also, when an encoding suffix such 35 not at the environment variables. Also, when an encoding suffix such
31 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE 36 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -33,9 +38,9 @@ int main () {
33 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL 38 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
34 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) 39 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
35 return 1; 40 return 1;
36#else 41# else
37 if (setlocale (LC_ALL, "") == NULL) return 1; 42 if (setlocale (LC_ALL, "") == NULL) return 1;
38#endif 43# endif
39 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". 44 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
40 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) 45 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
41 is empty, and the behaviour of Tcl 8.4 in this locale is not useful. 46 is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
@@ -44,35 +49,35 @@ int main () {
44 some unit tests fail. 49 some unit tests fail.
45 On MirBSD 10, when an unsupported locale is specified, setlocale() 50 On MirBSD 10, when an unsupported locale is specified, setlocale()
46 succeeds but then nl_langinfo(CODESET) is "UTF-8". */ 51 succeeds but then nl_langinfo(CODESET) is "UTF-8". */
47#if HAVE_LANGINFO_CODESET 52# if HAVE_LANGINFO_CODESET
48 { 53 {
49 const char *cs = nl_langinfo (CODESET); 54 const char *cs = nl_langinfo (CODESET);
50 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0 55 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
51 || strcmp (cs, "UTF-8") == 0) 56 || strcmp (cs, "UTF-8") == 0)
52 return 1; 57 return 1;
53 } 58 }
54#endif 59# endif
55#ifdef __CYGWIN__ 60# ifdef __CYGWIN__
56 /* On Cygwin, avoid locale names without encoding suffix, because the 61 /* On Cygwin, avoid locale names without encoding suffix, because the
57 locale_charset() function relies on the encoding suffix. Note that 62 locale_charset() function relies on the encoding suffix. Note that
58 LC_ALL is set on the command line. */ 63 LC_ALL is set on the command line. */
59 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; 64 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
60#endif 65# endif
61 /* Check whether in the abbreviation of the second month, the second 66 /* Check whether in the abbreviation of the second month, the second
62 character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only 67 character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only
63 one byte long. This excludes the UTF-8 encoding. */ 68 one byte long. This excludes the UTF-8 encoding. */
64 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; 69 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
65 if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1; 70 if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1;
66#if !defined __BIONIC__ /* Bionic libc's 'struct lconv' is just a dummy. */ 71# if !defined __BIONIC__ /* Bionic libc's 'struct lconv' is just a dummy. */
67 /* Check whether the decimal separator is a comma. 72 /* Check whether the decimal separator is a comma.
68 On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point 73 On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
69 are nl_langinfo(RADIXCHAR) are both ".". */ 74 are nl_langinfo(RADIXCHAR) are both ".". */
70 if (localeconv () ->decimal_point[0] != ',') return 1; 75 if (localeconv () ->decimal_point[0] != ',') return 1;
71#endif 76# endif
72 return 0; 77 return 0;
78#endif
73} 79}
74changequote([,])dnl 80 ]])])
75 ])])
76 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then 81 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
77 case "$host_os" in 82 case "$host_os" in
78 # Handle native Windows specially, because there setlocale() interprets 83 # Handle native Windows specially, because there setlocale() interprets
@@ -136,8 +141,7 @@ AC_DEFUN([gt_LOCALE_FR_UTF8],
136[ 141[
137 AC_REQUIRE([AM_LANGINFO_CODESET]) 142 AC_REQUIRE([AM_LANGINFO_CODESET])
138 AC_CACHE_CHECK([for a french Unicode locale], [gt_cv_locale_fr_utf8], [ 143 AC_CACHE_CHECK([for a french Unicode locale], [gt_cv_locale_fr_utf8], [
139 AC_LANG_CONFTEST([AC_LANG_SOURCE([ 144 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
140changequote(,)dnl
141#include <locale.h> 145#include <locale.h>
142#include <time.h> 146#include <time.h>
143#if HAVE_LANGINFO_CODESET 147#if HAVE_LANGINFO_CODESET
@@ -153,7 +157,7 @@ int main () {
153 variables, and all locales use the UTF-8 encoding. */ 157 variables, and all locales use the UTF-8 encoding. */
154#if !(defined __BEOS__ || defined __HAIKU__) 158#if !(defined __BEOS__ || defined __HAIKU__)
155 /* Check whether the given locale name is recognized by the system. */ 159 /* Check whether the given locale name is recognized by the system. */
156# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 160# if defined _WIN32 && !defined __CYGWIN__
157 /* On native Windows, setlocale(category, "") looks at the system settings, 161 /* On native Windows, setlocale(category, "") looks at the system settings,
158 not at the environment variables. Also, when an encoding suffix such 162 not at the environment variables. Also, when an encoding suffix such
159 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE 163 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -199,8 +203,7 @@ int main () {
199#endif 203#endif
200 return 0; 204 return 0;
201} 205}
202changequote([,])dnl 206 ]])])
203 ])])
204 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then 207 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
205 case "$host_os" in 208 case "$host_os" in
206 # Handle native Windows specially, because there setlocale() interprets 209 # Handle native Windows specially, because there setlocale() interprets
diff --git a/gl/m4/locale-ja.m4 b/gl/m4/locale-ja.m4
index 132a3e7..2590173 100644
--- a/gl/m4/locale-ja.m4
+++ b/gl/m4/locale-ja.m4
@@ -1,5 +1,5 @@
1# locale-ja.m4 serial 12 1# locale-ja.m4 serial 15
2dnl Copyright (C) 2003, 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2023 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,8 +12,7 @@ AC_DEFUN([gt_LOCALE_JA],
12 AC_REQUIRE([AC_CANONICAL_HOST]) 12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_REQUIRE([AM_LANGINFO_CODESET]) 13 AC_REQUIRE([AM_LANGINFO_CODESET])
14 AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [ 14 AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [
15 AC_LANG_CONFTEST([AC_LANG_SOURCE([ 15 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
16changequote(,)dnl
17#include <locale.h> 16#include <locale.h>
18#include <time.h> 17#include <time.h>
19#if HAVE_LANGINFO_CODESET 18#if HAVE_LANGINFO_CODESET
@@ -25,9 +24,14 @@ struct tm t;
25char buf[16]; 24char buf[16];
26int main () 25int main ()
27{ 26{
28 const char *p; 27 /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
28 imitates locale dependent behaviour by looking at the environment
29 variables, and all locales use the UTF-8 encoding. */
30#if defined __BEOS__ || defined __HAIKU__
31 return 1;
32#else
29 /* Check whether the given locale name is recognized by the system. */ 33 /* Check whether the given locale name is recognized by the system. */
30#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 34# if defined _WIN32 && !defined __CYGWIN__
31 /* On native Windows, setlocale(category, "") looks at the system settings, 35 /* On native Windows, setlocale(category, "") looks at the system settings,
32 not at the environment variables. Also, when an encoding suffix such 36 not at the environment variables. Also, when an encoding suffix such
33 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE 37 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -35,9 +39,9 @@ int main ()
35 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL 39 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
36 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) 40 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
37 return 1; 41 return 1;
38#else 42# else
39 if (setlocale (LC_ALL, "") == NULL) return 1; 43 if (setlocale (LC_ALL, "") == NULL) return 1;
40#endif 44# endif
41 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". 45 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
42 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) 46 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
43 is empty, and the behaviour of Tcl 8.4 in this locale is not useful. 47 is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
@@ -46,35 +50,38 @@ int main ()
46 some unit tests fail. 50 some unit tests fail.
47 On MirBSD 10, when an unsupported locale is specified, setlocale() 51 On MirBSD 10, when an unsupported locale is specified, setlocale()
48 succeeds but then nl_langinfo(CODESET) is "UTF-8". */ 52 succeeds but then nl_langinfo(CODESET) is "UTF-8". */
49#if HAVE_LANGINFO_CODESET 53# if HAVE_LANGINFO_CODESET
50 { 54 {
51 const char *cs = nl_langinfo (CODESET); 55 const char *cs = nl_langinfo (CODESET);
52 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0 56 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
53 || strcmp (cs, "UTF-8") == 0) 57 || strcmp (cs, "UTF-8") == 0)
54 return 1; 58 return 1;
55 } 59 }
56#endif 60# endif
57#ifdef __CYGWIN__ 61# ifdef __CYGWIN__
58 /* On Cygwin, avoid locale names without encoding suffix, because the 62 /* On Cygwin, avoid locale names without encoding suffix, because the
59 locale_charset() function relies on the encoding suffix. Note that 63 locale_charset() function relies on the encoding suffix. Note that
60 LC_ALL is set on the command line. */ 64 LC_ALL is set on the command line. */
61 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; 65 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
62#endif 66# endif
63 /* Check whether MB_CUR_MAX is > 1. This excludes the dysfunctional locales 67 /* Check whether MB_CUR_MAX is > 1. This excludes the dysfunctional locales
64 on Cygwin 1.5.x. */ 68 on Cygwin 1.5.x. */
65 if (MB_CUR_MAX == 1) 69 if (MB_CUR_MAX == 1)
66 return 1; 70 return 1;
67 /* Check whether in a month name, no byte in the range 0x80..0x9F occurs. 71 /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
68 This excludes the UTF-8 encoding (except on MirBSD). */ 72 This excludes the UTF-8 encoding (except on MirBSD). */
69 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; 73 {
70 if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1; 74 const char *p;
71 for (p = buf; *p != '\0'; p++) 75 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
72 if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0) 76 if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
73 return 1; 77 for (p = buf; *p != '\0'; p++)
78 if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
79 return 1;
80 }
74 return 0; 81 return 0;
82#endif
75} 83}
76changequote([,])dnl 84 ]])])
77 ])])
78 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then 85 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
79 case "$host_os" in 86 case "$host_os" in
80 # Handle native Windows specially, because there setlocale() interprets 87 # Handle native Windows specially, because there setlocale() interprets
diff --git a/gl/m4/locale-zh.m4 b/gl/m4/locale-zh.m4
index 4eed73f..b9f9eef 100644
--- a/gl/m4/locale-zh.m4
+++ b/gl/m4/locale-zh.m4
@@ -1,5 +1,5 @@
1# locale-zh.m4 serial 12 1# locale-zh.m4 serial 15
2dnl Copyright (C) 2003, 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2023 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,8 +12,7 @@ AC_DEFUN([gt_LOCALE_ZH_CN],
12 AC_REQUIRE([AC_CANONICAL_HOST]) 12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_REQUIRE([AM_LANGINFO_CODESET]) 13 AC_REQUIRE([AM_LANGINFO_CODESET])
14 AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [ 14 AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [
15 AC_LANG_CONFTEST([AC_LANG_SOURCE([ 15 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
16changequote(,)dnl
17#include <locale.h> 16#include <locale.h>
18#include <stdlib.h> 17#include <stdlib.h>
19#include <time.h> 18#include <time.h>
@@ -26,9 +25,14 @@ struct tm t;
26char buf[16]; 25char buf[16];
27int main () 26int main ()
28{ 27{
29 const char *p; 28 /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
29 imitates locale dependent behaviour by looking at the environment
30 variables, and all locales use the UTF-8 encoding. */
31#if defined __BEOS__ || defined __HAIKU__
32 return 1;
33#else
30 /* Check whether the given locale name is recognized by the system. */ 34 /* Check whether the given locale name is recognized by the system. */
31#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 35# if defined _WIN32 && !defined __CYGWIN__
32 /* On native Windows, setlocale(category, "") looks at the system settings, 36 /* On native Windows, setlocale(category, "") looks at the system settings,
33 not at the environment variables. Also, when an encoding suffix such 37 not at the environment variables. Also, when an encoding suffix such
34 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE 38 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
@@ -36,9 +40,9 @@ int main ()
36 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL 40 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
37 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) 41 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
38 return 1; 42 return 1;
39#else 43# else
40 if (setlocale (LC_ALL, "") == NULL) return 1; 44 if (setlocale (LC_ALL, "") == NULL) return 1;
41#endif 45# endif
42 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". 46 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
43 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) 47 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
44 is empty, and the behaviour of Tcl 8.4 in this locale is not useful. 48 is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
@@ -47,35 +51,38 @@ int main ()
47 some unit tests fail. 51 some unit tests fail.
48 On MirBSD 10, when an unsupported locale is specified, setlocale() 52 On MirBSD 10, when an unsupported locale is specified, setlocale()
49 succeeds but then nl_langinfo(CODESET) is "UTF-8". */ 53 succeeds but then nl_langinfo(CODESET) is "UTF-8". */
50#if HAVE_LANGINFO_CODESET 54# if HAVE_LANGINFO_CODESET
51 { 55 {
52 const char *cs = nl_langinfo (CODESET); 56 const char *cs = nl_langinfo (CODESET);
53 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0 57 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
54 || strcmp (cs, "UTF-8") == 0) 58 || strcmp (cs, "UTF-8") == 0)
55 return 1; 59 return 1;
56 } 60 }
57#endif 61# endif
58#ifdef __CYGWIN__ 62# ifdef __CYGWIN__
59 /* On Cygwin, avoid locale names without encoding suffix, because the 63 /* On Cygwin, avoid locale names without encoding suffix, because the
60 locale_charset() function relies on the encoding suffix. Note that 64 locale_charset() function relies on the encoding suffix. Note that
61 LC_ALL is set on the command line. */ 65 LC_ALL is set on the command line. */
62 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; 66 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
63#endif 67# endif
64 /* Check whether in a month name, no byte in the range 0x80..0x9F occurs. 68 /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
65 This excludes the UTF-8 encoding (except on MirBSD). */ 69 This excludes the UTF-8 encoding (except on MirBSD). */
66 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; 70 {
67 if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1; 71 const char *p;
68 for (p = buf; *p != '\0'; p++) 72 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
69 if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0) 73 if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
70 return 1; 74 for (p = buf; *p != '\0'; p++)
75 if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
76 return 1;
77 }
71 /* Check whether a typical GB18030 multibyte sequence is recognized as a 78 /* Check whether a typical GB18030 multibyte sequence is recognized as a
72 single wide character. This excludes the GB2312 and GBK encodings. */ 79 single wide character. This excludes the GB2312 and GBK encodings. */
73 if (mblen ("\203\062\332\066", 5) != 4) 80 if (mblen ("\203\062\332\066", 5) != 4)
74 return 1; 81 return 1;
75 return 0; 82 return 0;
83#endif
76} 84}
77changequote([,])dnl 85 ]])])
78 ])])
79 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then 86 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
80 case "$host_os" in 87 case "$host_os" in
81 # Handle native Windows specially, because there setlocale() interprets 88 # Handle native Windows specially, because there setlocale() interprets
diff --git a/gl/m4/locale_h.m4 b/gl/m4/locale_h.m4
index 8bd12e8..a33a0a4 100644
--- a/gl/m4/locale_h.m4
+++ b/gl/m4/locale_h.m4
@@ -1,13 +1,13 @@
1# locale_h.m4 serial 19 1# locale_h.m4 serial 28
2dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2023 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_LOCALE_H], 7AC_DEFUN_ONCE([gl_LOCALE_H],
8[ 8[
9 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 9 dnl Ensure to expand the default settings once only, before all statements
10 dnl once only, before all statements that occur in other macros. 10 dnl that occur in other macros.
11 AC_REQUIRE([gl_LOCALE_H_DEFAULTS]) 11 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
12 12
13 dnl Persuade glibc <locale.h> to define locale_t and the int_p_*, int_n_* 13 dnl Persuade glibc <locale.h> to define locale_t and the int_p_*, int_n_*
@@ -17,7 +17,9 @@ AC_DEFUN([gl_LOCALE_H],
17 dnl If <stddef.h> is replaced, then <locale.h> must also be replaced. 17 dnl If <stddef.h> is replaced, then <locale.h> must also be replaced.
18 AC_REQUIRE([gl_STDDEF_H]) 18 AC_REQUIRE([gl_STDDEF_H])
19 19
20 dnl Solaris 11 2011-11 defines the int_p_*, int_n_* members of 'struct lconv' 20 AC_REQUIRE([gl_LOCALE_T])
21
22 dnl Solaris 11.0 defines the int_p_*, int_n_* members of 'struct lconv'
21 dnl only if _LCONV_C99 is defined. 23 dnl only if _LCONV_C99 is defined.
22 AC_REQUIRE([AC_CANONICAL_HOST]) 24 AC_REQUIRE([AC_CANONICAL_HOST])
23 case "$host_os" in 25 case "$host_os" in
@@ -37,34 +39,6 @@ AC_DEFUN([gl_LOCALE_H],
37 [gl_cv_header_locale_h_posix2001=yes], 39 [gl_cv_header_locale_h_posix2001=yes],
38 [gl_cv_header_locale_h_posix2001=no])]) 40 [gl_cv_header_locale_h_posix2001=no])])
39 41
40 dnl Check for <xlocale.h>.
41 AC_CHECK_HEADERS_ONCE([xlocale.h])
42 if test $ac_cv_header_xlocale_h = yes; then
43 HAVE_XLOCALE_H=1
44 dnl Check whether use of locale_t requires inclusion of <xlocale.h>,
45 dnl e.g. on Mac OS X 10.5. If <locale.h> does not define locale_t by
46 dnl itself, we assume that <xlocale.h> will do so.
47 AC_CACHE_CHECK([whether locale.h defines locale_t],
48 [gl_cv_header_locale_has_locale_t],
49 [AC_COMPILE_IFELSE(
50 [AC_LANG_PROGRAM(
51 [[#include <locale.h>
52 locale_t x;]],
53 [[]])],
54 [gl_cv_header_locale_has_locale_t=yes],
55 [gl_cv_header_locale_has_locale_t=no])
56 ])
57 if test $gl_cv_header_locale_has_locale_t = yes; then
58 gl_cv_header_locale_h_needs_xlocale_h=no
59 else
60 gl_cv_header_locale_h_needs_xlocale_h=yes
61 fi
62 else
63 HAVE_XLOCALE_H=0
64 gl_cv_header_locale_h_needs_xlocale_h=no
65 fi
66 AC_SUBST([HAVE_XLOCALE_H])
67
68 dnl Check whether 'struct lconv' is complete. 42 dnl Check whether 'struct lconv' is complete.
69 dnl Bionic libc's 'struct lconv' is just a dummy. 43 dnl Bionic libc's 'struct lconv' is just a dummy.
70 dnl On OpenBSD 4.9, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 1.5.x, 44 dnl On OpenBSD 4.9, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 1.5.x,
@@ -82,7 +56,20 @@ AC_DEFUN([gl_LOCALE_H],
82 [gl_cv_sys_struct_lconv_ok=no]) 56 [gl_cv_sys_struct_lconv_ok=no])
83 ]) 57 ])
84 if test $gl_cv_sys_struct_lconv_ok = no; then 58 if test $gl_cv_sys_struct_lconv_ok = no; then
85 REPLACE_STRUCT_LCONV=1 59 dnl On native Windows with MSVC, merely define these member names as macros.
60 dnl This avoids trouble in C++ mode.
61 case "$host_os" in
62 mingw*)
63 AC_EGREP_CPP([Special], [
64#ifdef _MSC_VER
65 Special
66#endif
67 ],
68 [],
69 [REPLACE_STRUCT_LCONV=1])
70 ;;
71 *) REPLACE_STRUCT_LCONV=1 ;;
72 esac
86 fi 73 fi
87 74
88 dnl <locale.h> is always overridden, because of GNULIB_POSIXCHECK. 75 dnl <locale.h> is always overridden, because of GNULIB_POSIXCHECK.
@@ -96,27 +83,92 @@ AC_DEFUN([gl_LOCALE_H],
96# include <xlocale.h> 83# include <xlocale.h>
97#endif 84#endif
98 ]], 85 ]],
99 [setlocale duplocale]) 86 [setlocale newlocale duplocale freelocale])
87])
88
89dnl Checks to determine whether the system has the locale_t type,
90dnl and how to obtain it.
91AC_DEFUN([gl_LOCALE_T],
92[
93 dnl Persuade glibc and Solaris <locale.h> to define locale_t.
94 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
95
96 dnl Check whether use of locale_t requires inclusion of <xlocale.h>,
97 dnl e.g. on Mac OS X 10.5. If <locale.h> does not define locale_t by
98 dnl itself, we assume that <xlocale.h> will do so.
99 AC_CACHE_CHECK([whether locale.h defines locale_t],
100 [gl_cv_header_locale_has_locale_t],
101 [AC_COMPILE_IFELSE(
102 [AC_LANG_PROGRAM(
103 [[#include <locale.h>
104 locale_t x;]],
105 [[]])],
106 [gl_cv_header_locale_has_locale_t=yes],
107 [gl_cv_header_locale_has_locale_t=no])
108 ])
109
110 dnl Check for <xlocale.h>.
111 AC_CHECK_HEADERS_ONCE([xlocale.h])
112 if test $ac_cv_header_xlocale_h = yes; then
113 HAVE_XLOCALE_H=1
114 if test $gl_cv_header_locale_has_locale_t = yes; then
115 gl_cv_header_locale_h_needs_xlocale_h=no
116 else
117 gl_cv_header_locale_h_needs_xlocale_h=yes
118 fi
119 HAVE_LOCALE_T=1
120 else
121 HAVE_XLOCALE_H=0
122 gl_cv_header_locale_h_needs_xlocale_h=no
123 if test $gl_cv_header_locale_has_locale_t = yes; then
124 HAVE_LOCALE_T=1
125 else
126 HAVE_LOCALE_T=0
127 fi
128 fi
129 AC_SUBST([HAVE_XLOCALE_H])
100]) 130])
101 131
132# gl_LOCALE_MODULE_INDICATOR([modulename])
133# sets the shell variable that indicates the presence of the given module
134# to a C preprocessor expression that will evaluate to 1.
135# This macro invocation must not occur in macros that are AC_REQUIREd.
102AC_DEFUN([gl_LOCALE_MODULE_INDICATOR], 136AC_DEFUN([gl_LOCALE_MODULE_INDICATOR],
103[ 137[
104 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 138 dnl Ensure to expand the default settings once only.
105 AC_REQUIRE([gl_LOCALE_H_DEFAULTS]) 139 gl_LOCALE_H_REQUIRE_DEFAULTS
106 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 140 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
107 dnl Define it also as a C macro, for the benefit of the unit tests. 141 dnl Define it also as a C macro, for the benefit of the unit tests.
108 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 142 gl_MODULE_INDICATOR_FOR_TESTS([$1])
109]) 143])
110 144
145# Initializes the default values for AC_SUBSTed shell variables.
146# This macro must not be AC_REQUIREd. It must only be invoked, and only
147# outside of macros or in macros that are not AC_REQUIREd.
148AC_DEFUN([gl_LOCALE_H_REQUIRE_DEFAULTS],
149[
150 m4_defun(GL_MODULE_INDICATOR_PREFIX[_LOCALE_H_MODULE_INDICATOR_DEFAULTS], [
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALECONV])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETLOCALE])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETLOCALE_NULL])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DUPLOCALE])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALENAME])
156 ])
157 m4_require(GL_MODULE_INDICATOR_PREFIX[_LOCALE_H_MODULE_INDICATOR_DEFAULTS])
158 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
159])
160
111AC_DEFUN([gl_LOCALE_H_DEFAULTS], 161AC_DEFUN([gl_LOCALE_H_DEFAULTS],
112[ 162[
113 GNULIB_LOCALECONV=0; AC_SUBST([GNULIB_LOCALECONV])
114 GNULIB_SETLOCALE=0; AC_SUBST([GNULIB_SETLOCALE])
115 GNULIB_DUPLOCALE=0; AC_SUBST([GNULIB_DUPLOCALE])
116 dnl Assume proper GNU behavior unless another module says otherwise. 163 dnl Assume proper GNU behavior unless another module says otherwise.
164 HAVE_NEWLOCALE=1; AC_SUBST([HAVE_NEWLOCALE])
117 HAVE_DUPLOCALE=1; AC_SUBST([HAVE_DUPLOCALE]) 165 HAVE_DUPLOCALE=1; AC_SUBST([HAVE_DUPLOCALE])
166 HAVE_FREELOCALE=1; AC_SUBST([HAVE_FREELOCALE])
118 REPLACE_LOCALECONV=0; AC_SUBST([REPLACE_LOCALECONV]) 167 REPLACE_LOCALECONV=0; AC_SUBST([REPLACE_LOCALECONV])
119 REPLACE_SETLOCALE=0; AC_SUBST([REPLACE_SETLOCALE]) 168 REPLACE_SETLOCALE=0; AC_SUBST([REPLACE_SETLOCALE])
169 REPLACE_NEWLOCALE=0; AC_SUBST([REPLACE_NEWLOCALE])
120 REPLACE_DUPLOCALE=0; AC_SUBST([REPLACE_DUPLOCALE]) 170 REPLACE_DUPLOCALE=0; AC_SUBST([REPLACE_DUPLOCALE])
171 REPLACE_FREELOCALE=0; AC_SUBST([REPLACE_FREELOCALE])
121 REPLACE_STRUCT_LCONV=0; AC_SUBST([REPLACE_STRUCT_LCONV]) 172 REPLACE_STRUCT_LCONV=0; AC_SUBST([REPLACE_STRUCT_LCONV])
173 LOCALENAME_ENHANCE_LOCALE_FUNCS=0; AC_SUBST([LOCALENAME_ENHANCE_LOCALE_FUNCS])
122]) 174])
diff --git a/gl/m4/localeconv.m4 b/gl/m4/localeconv.m4
index b8bb596..ae225fe 100644
--- a/gl/m4/localeconv.m4
+++ b/gl/m4/localeconv.m4
@@ -1,5 +1,5 @@
1# localeconv.m4 serial 1 1# localeconv.m4 serial 1
2dnl Copyright (C) 2012-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2012-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/lock.m4 b/gl/m4/lock.m4
index aae1701..88cf557 100644
--- a/gl/m4/lock.m4
+++ b/gl/m4/lock.m4
@@ -1,5 +1,5 @@
1# lock.m4 serial 13 (gettext-0.18.2) 1# lock.m4 serial 14
2dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2023 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,11 +12,16 @@ AC_DEFUN([gl_LOCK],
12 if test "$gl_threads_api" = posix; then 12 if test "$gl_threads_api" = posix; then
13 # OSF/1 4.0 and Mac OS X 10.1 lack the pthread_rwlock_t type and the 13 # OSF/1 4.0 and Mac OS X 10.1 lack the pthread_rwlock_t type and the
14 # pthread_rwlock_* functions. 14 # pthread_rwlock_* functions.
15 has_rwlock=false
15 AC_CHECK_TYPE([pthread_rwlock_t], 16 AC_CHECK_TYPE([pthread_rwlock_t],
16 [AC_DEFINE([HAVE_PTHREAD_RWLOCK], [1], 17 [has_rwlock=true
18 AC_DEFINE([HAVE_PTHREAD_RWLOCK], [1],
17 [Define if the POSIX multithreading library has read/write locks.])], 19 [Define if the POSIX multithreading library has read/write locks.])],
18 [], 20 [],
19 [#include <pthread.h>]) 21 [#include <pthread.h>])
22 if $has_rwlock; then
23 gl_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER
24 fi
20 # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. 25 # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro.
21 AC_COMPILE_IFELSE([ 26 AC_COMPILE_IFELSE([
22 AC_LANG_PROGRAM( 27 AC_LANG_PROGRAM(
diff --git a/gl/m4/longlong.m4 b/gl/m4/longlong.m4
deleted file mode 100644
index 3af6ab5..0000000
--- a/gl/m4/longlong.m4
+++ /dev/null
@@ -1,113 +0,0 @@
1# longlong.m4 serial 17
2dnl Copyright (C) 1999-2007, 2009-2013 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_LONG_LONG_INT if 'long long int' works.
10# This fixes a bug in Autoconf 2.61, and can be faster
11# than what's in Autoconf 2.62 through 2.68.
12
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
15# defined. In this case you can treat 'long long int' like 'long int'.
16
17AC_DEFUN([AC_TYPE_LONG_LONG_INT],
18[
19 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
20 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
21 [ac_cv_type_long_long_int=yes
22 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
23 ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
24 if test $ac_cv_type_long_long_int = yes; then
25 dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
26 dnl If cross compiling, assume the bug is not important, since
27 dnl nobody cross compiles for this platform as far as we know.
28 AC_RUN_IFELSE(
29 [AC_LANG_PROGRAM(
30 [[@%:@include <limits.h>
31 @%:@ifndef LLONG_MAX
32 @%:@ define HALF \
33 (1LL << (sizeof (long long int) * CHAR_BIT - 2))
34 @%:@ define LLONG_MAX (HALF - 1 + HALF)
35 @%:@endif]],
36 [[long long int n = 1;
37 int i;
38 for (i = 0; ; i++)
39 {
40 long long int m = n << i;
41 if (m >> i != n)
42 return 1;
43 if (LLONG_MAX / 2 < m)
44 break;
45 }
46 return 0;]])],
47 [],
48 [ac_cv_type_long_long_int=no],
49 [:])
50 fi
51 fi])
52 if test $ac_cv_type_long_long_int = yes; then
53 AC_DEFINE([HAVE_LONG_LONG_INT], [1],
54 [Define to 1 if the system has the type 'long long int'.])
55 fi
56])
57
58# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
59# This fixes a bug in Autoconf 2.61, and can be faster
60# than what's in Autoconf 2.62 through 2.68.
61
62# Note: If the type 'unsigned long long int' exists but is only 32 bits
63# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
64# will not be defined. In this case you can treat 'unsigned long long int'
65# like 'unsigned long int'.
66
67AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
68[
69 AC_CACHE_CHECK([for unsigned long long int],
70 [ac_cv_type_unsigned_long_long_int],
71 [ac_cv_type_unsigned_long_long_int=yes
72 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
73 AC_LINK_IFELSE(
74 [_AC_TYPE_LONG_LONG_SNIPPET],
75 [],
76 [ac_cv_type_unsigned_long_long_int=no])
77 fi])
78 if test $ac_cv_type_unsigned_long_long_int = yes; then
79 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
80 [Define to 1 if the system has the type 'unsigned long long int'.])
81 fi
82])
83
84# Expands to a C program that can be used to test for simultaneous support
85# of 'long long' and 'unsigned long long'. We don't want to say that
86# 'long long' is available if 'unsigned long long' is not, or vice versa,
87# because too many programs rely on the symmetry between signed and unsigned
88# integer types (excluding 'bool').
89AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
90[
91 AC_LANG_PROGRAM(
92 [[/* For now, do not test the preprocessor; as of 2007 there are too many
93 implementations with broken preprocessors. Perhaps this can
94 be revisited in 2012. In the meantime, code should not expect
95 #if to work with literals wider than 32 bits. */
96 /* Test literals. */
97 long long int ll = 9223372036854775807ll;
98 long long int nll = -9223372036854775807LL;
99 unsigned long long int ull = 18446744073709551615ULL;
100 /* Test constant expressions. */
101 typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
102 ? 1 : -1)];
103 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
104 ? 1 : -1)];
105 int i = 63;]],
106 [[/* Test availability of runtime routines for shift and division. */
107 long long int llmax = 9223372036854775807ll;
108 unsigned long long int ullmax = 18446744073709551615ull;
109 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
110 | (llmax / ll) | (llmax % ll)
111 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
112 | (ullmax / ull) | (ullmax % ull));]])
113])
diff --git a/gl/m4/ls-mntd-fs.m4 b/gl/m4/ls-mntd-fs.m4
deleted file mode 100644
index fb116c8..0000000
--- a/gl/m4/ls-mntd-fs.m4
+++ /dev/null
@@ -1,357 +0,0 @@
1# serial 30
2# How to list mounted file systems.
3
4# Copyright (C) 1998-2004, 2006, 2009-2013 Free Software Foundation, Inc.
5#
6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved.
9
10dnl From Jim Meyering.
11dnl
12dnl This is not pretty. I've just taken the autoconf code and wrapped
13dnl it in an AC_DEFUN and made some other fixes.
14dnl
15
16# Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
17# through Autoconf 2.59. We can remove this once we assume Autoconf 2.60
18# or later.
19AC_DEFUN([AC_FUNC_GETMNTENT],
20[# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
21# -lseq on Dynix/PTX, -lgen on Unixware.
22AC_SEARCH_LIBS([getmntent], [sun seq gen])
23AC_CHECK_FUNCS([getmntent])
24])
25
26# gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
27AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
28 [
29AC_CHECK_FUNCS([listmntent getmntinfo])
30AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
31
32# We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
33# NGROUPS (as the array dimension for a struct member) without a definition.
34AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
35
36AC_CHECK_HEADERS([sys/mount.h], [], [],
37 [AC_INCLUDES_DEFAULT
38 [#if HAVE_SYS_PARAM_H
39 #include <sys/param.h>
40 #endif]])
41
42AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
43 getfsstat_includes="\
44$ac_includes_default
45#if HAVE_SYS_PARAM_H
46# include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
47#endif
48#if HAVE_SYS_UCRED_H
49# include <grp.h> /* needed for definition of NGROUPS */
50# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
51#endif
52#if HAVE_SYS_MOUNT_H
53# include <sys/mount.h>
54#endif
55#if HAVE_SYS_FS_TYPES_H
56# include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
57#endif
58"
59AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
60
61# Determine how to get the list of mounted file systems.
62ac_list_mounted_fs=
63
64# If the getmntent function is available but not in the standard library,
65# make sure LIBS contains the appropriate -l option.
66AC_FUNC_GETMNTENT
67
68# This test must precede the ones for getmntent because Unicos-9 is
69# reported to have the getmntent function, but its support is incompatible
70# with other getmntent implementations.
71
72# NOTE: Normally, I wouldn't use a check for system type as I've done for
73# 'CRAY' below since that goes against the whole autoconf philosophy. But
74# I think there is too great a chance that some non-Cray system has a
75# function named listmntent to risk the false positive.
76
77if test -z "$ac_list_mounted_fs"; then
78 # Cray UNICOS 9
79 AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
80 AC_CACHE_VAL([fu_cv_sys_mounted_cray_listmntent],
81 [fu_cv_sys_mounted_cray_listmntent=no
82 AC_EGREP_CPP([yes],
83 [#ifdef _CRAY
84yes
85#endif
86 ], [test $ac_cv_func_listmntent = yes \
87 && fu_cv_sys_mounted_cray_listmntent=yes]
88 )
89 ]
90 )
91 AC_MSG_RESULT([$fu_cv_sys_mounted_cray_listmntent])
92 if test $fu_cv_sys_mounted_cray_listmntent = yes; then
93 ac_list_mounted_fs=found
94 AC_DEFINE([MOUNTED_LISTMNTENT], [1],
95 [Define if there is a function named listmntent that can be used to
96 list all mounted file systems. (UNICOS)])
97 fi
98fi
99
100if test -z "$ac_list_mounted_fs"; then
101 # AIX.
102 AC_MSG_CHECKING([for mntctl function and struct vmount])
103 AC_CACHE_VAL([fu_cv_sys_mounted_vmount],
104 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
105 [fu_cv_sys_mounted_vmount=yes],
106 [fu_cv_sys_mounted_vmount=no])])
107 AC_MSG_RESULT([$fu_cv_sys_mounted_vmount])
108 if test $fu_cv_sys_mounted_vmount = yes; then
109 ac_list_mounted_fs=found
110 AC_DEFINE([MOUNTED_VMOUNT], [1],
111 [Define if there is a function named mntctl that can be used to read
112 the list of mounted file systems, and there is a system header file
113 that declares 'struct vmount'. (AIX)])
114 fi
115fi
116
117if test $ac_cv_func_getmntent = yes; then
118
119 # This system has the getmntent function.
120 # Determine whether it's the one-argument variant or the two-argument one.
121
122 if test -z "$ac_list_mounted_fs"; then
123 # 4.3BSD, SunOS, HP-UX, Dynix, Irix
124 AC_MSG_CHECKING([for one-argument getmntent function])
125 AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1],
126 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
127/* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
128#include <stdio.h>
129
130#include <mntent.h>
131#if !defined MOUNTED
132# if defined _PATH_MOUNTED /* GNU libc */
133# define MOUNTED _PATH_MOUNTED
134# endif
135# if defined MNT_MNTTAB /* HP-UX. */
136# define MOUNTED MNT_MNTTAB
137# endif
138# if defined MNTTABNAME /* Dynix. */
139# define MOUNTED MNTTABNAME
140# endif
141#endif
142]],
143 [[ struct mntent *mnt = 0; char *table = MOUNTED;
144 if (sizeof mnt && sizeof table) return 0;]])],
145 [fu_cv_sys_mounted_getmntent1=yes],
146 [fu_cv_sys_mounted_getmntent1=no])])
147 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent1])
148 if test $fu_cv_sys_mounted_getmntent1 = yes; then
149 ac_list_mounted_fs=found
150 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
151 [Define if there is a function named getmntent for reading the list
152 of mounted file systems, and that function takes a single argument.
153 (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
154 fi
155 fi
156
157 if test -z "$ac_list_mounted_fs"; then
158 # SVR4
159 AC_MSG_CHECKING([for two-argument getmntent function])
160 AC_CACHE_VAL([fu_cv_sys_mounted_getmntent2],
161 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
162 fu_cv_sys_mounted_getmntent2=yes,
163 fu_cv_sys_mounted_getmntent2=no)])
164 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent2])
165 if test $fu_cv_sys_mounted_getmntent2 = yes; then
166 ac_list_mounted_fs=found
167 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
168 [Define if there is a function named getmntent for reading the list of
169 mounted file systems, and that function takes two arguments. (SVR4)])
170 AC_CHECK_FUNCS([hasmntopt])
171 fi
172 fi
173
174fi
175
176if test -z "$ac_list_mounted_fs"; then
177 # DEC Alpha running OSF/1, and Apple Darwin 1.3.
178 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
179
180 AC_MSG_CHECKING([for getfsstat function])
181 AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat],
182 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
183#include <sys/types.h>
184#if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
185# define FS_TYPE(Ent) ((Ent).f_fstypename)
186#else
187# define FS_TYPE(Ent) mnt_names[(Ent).f_type]
188#endif
189$getfsstat_includes]]
190,
191 [[struct statfs *stats;
192 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
193 char *t = FS_TYPE (*stats); ]])],
194 [fu_cv_sys_mounted_getfsstat=yes],
195 [fu_cv_sys_mounted_getfsstat=no])])
196 AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat])
197 if test $fu_cv_sys_mounted_getfsstat = yes; then
198 ac_list_mounted_fs=found
199 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
200 [Define if there is a function named getfsstat for reading the
201 list of mounted file systems. (DEC Alpha running OSF/1)])
202 fi
203fi
204
205if test -z "$ac_list_mounted_fs"; then
206 # SVR3
207 AC_MSG_CHECKING([for FIXME existence of three headers])
208 AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp],
209 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
210#include <sys/statfs.h>
211#include <sys/fstyp.h>
212#include <mnttab.h>]])],
213 [fu_cv_sys_mounted_fread_fstyp=yes],
214 [fu_cv_sys_mounted_fread_fstyp=no])])
215 AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp])
216 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
217 ac_list_mounted_fs=found
218 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
219 [Define if (like SVR2) there is no specific function for reading the
220 list of mounted file systems, and your system has these header files:
221 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
222 fi
223fi
224
225if test -z "$ac_list_mounted_fs"; then
226 # 4.4BSD and DEC OSF/1.
227 AC_MSG_CHECKING([for getmntinfo function])
228 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo],
229 [
230 test "$ac_cv_func_getmntinfo" = yes \
231 && fu_cv_sys_mounted_getmntinfo=yes \
232 || fu_cv_sys_mounted_getmntinfo=no
233 ])
234 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo])
235 if test $fu_cv_sys_mounted_getmntinfo = yes; then
236 AC_MSG_CHECKING([whether getmntinfo returns statvfs structures])
237 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2],
238 [
239 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
240#if HAVE_SYS_PARAM_H
241# include <sys/param.h>
242#endif
243#include <sys/types.h>
244#if HAVE_SYS_MOUNT_H
245# include <sys/mount.h>
246#endif
247#if HAVE_SYS_STATVFS_H
248# include <sys/statvfs.h>
249#endif
250extern
251#ifdef __cplusplus
252"C"
253#endif
254int getmntinfo (struct statfs **, int);
255 ]], [])],
256 [fu_cv_sys_mounted_getmntinfo2=no],
257 [fu_cv_sys_mounted_getmntinfo2=yes])
258 ])
259 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2])
260 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
261 ac_list_mounted_fs=found
262 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
263 [Define if there is a function named getmntinfo for reading the
264 list of mounted file systems and it returns an array of
265 'struct statfs'. (4.4BSD, Darwin)])
266 else
267 ac_list_mounted_fs=found
268 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
269 [Define if there is a function named getmntinfo for reading the
270 list of mounted file systems and it returns an array of
271 'struct statvfs'. (NetBSD 3.0)])
272 fi
273 fi
274fi
275
276if test -z "$ac_list_mounted_fs"; then
277 # Ultrix
278 AC_MSG_CHECKING([for getmnt function])
279 AC_CACHE_VAL([fu_cv_sys_mounted_getmnt],
280 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
281#include <sys/fs_types.h>
282#include <sys/mount.h>]])],
283 [fu_cv_sys_mounted_getmnt=yes],
284 [fu_cv_sys_mounted_getmnt=no])])
285 AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt])
286 if test $fu_cv_sys_mounted_getmnt = yes; then
287 ac_list_mounted_fs=found
288 AC_DEFINE([MOUNTED_GETMNT], [1],
289 [Define if there is a function named getmnt for reading the list of
290 mounted file systems. (Ultrix)])
291 fi
292fi
293
294if test -z "$ac_list_mounted_fs"; then
295 # BeOS
296 AC_CHECK_FUNCS([next_dev fs_stat_dev])
297 AC_CHECK_HEADERS([fs_info.h])
298 AC_MSG_CHECKING([for BEOS mounted file system support functions])
299 if test $ac_cv_header_fs_info_h = yes \
300 && test $ac_cv_func_next_dev = yes \
301 && test $ac_cv_func_fs_stat_dev = yes; then
302 fu_result=yes
303 else
304 fu_result=no
305 fi
306 AC_MSG_RESULT([$fu_result])
307 if test $fu_result = yes; then
308 ac_list_mounted_fs=found
309 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
310 [Define if there are functions named next_dev and fs_stat_dev for
311 reading the list of mounted file systems. (BeOS)])
312 fi
313fi
314
315if test -z "$ac_list_mounted_fs"; then
316 # SVR2
317 AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
318 AC_CACHE_VAL([fu_cv_sys_mounted_fread],
319 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
320 [fu_cv_sys_mounted_fread=yes],
321 [fu_cv_sys_mounted_fread=no])])
322 AC_MSG_RESULT([$fu_cv_sys_mounted_fread])
323 if test $fu_cv_sys_mounted_fread = yes; then
324 ac_list_mounted_fs=found
325 AC_DEFINE([MOUNTED_FREAD], [1],
326 [Define if there is no specific function for reading the list of
327 mounted file systems. fread will be used to read /etc/mnttab.
328 (SVR2) ])
329 fi
330fi
331
332if test -z "$ac_list_mounted_fs"; then
333 # Interix / BSD alike statvfs
334 # the code is really interix specific, so make sure, we're on it.
335 case "$host" in
336 *-interix*)
337 AC_CHECK_FUNCS([statvfs])
338 if test $ac_cv_func_statvfs = yes; then
339 ac_list_mounted_fs=found
340 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
341 [Define if we are on interix, and ought to use statvfs plus
342 some special knowledge on where mounted file systems can be
343 found. (Interix)])
344 fi
345 ;;
346 esac
347fi
348
349if test -z "$ac_list_mounted_fs"; then
350 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
351 # FIXME -- no need to abort building the whole package
352 # Can't build mountlist.c or anything that needs its functions
353fi
354
355AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
356
357 ])
diff --git a/gl/m4/lseek.m4 b/gl/m4/lseek.m4
new file mode 100644
index 0000000..fd4f1f2
--- /dev/null
+++ b/gl/m4/lseek.m4
@@ -0,0 +1,78 @@
1# lseek.m4 serial 12
2dnl Copyright (C) 2007, 2009-2023 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_LSEEK],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10
11 AC_REQUIRE([AC_CANONICAL_HOST])
12 AC_REQUIRE([AC_PROG_CC])
13 AC_CHECK_HEADERS_ONCE([unistd.h])
14 AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
15 [case "$host_os" in
16 mingw*)
17 dnl Native Windows.
18 dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or
19 dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT)
20 dnl for a pipe depends on the environment: In a Cygwin 1.5
21 dnl environment it succeeds (wrong); in a Cygwin 1.7 environment
22 dnl it fails with a wrong errno value.
23 gl_cv_func_lseek_pipe=no
24 ;;
25 *)
26 if test $cross_compiling = no; then
27 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
28#include <sys/types.h> /* for off_t */
29#include <stdio.h> /* for SEEK_CUR */
30#if HAVE_UNISTD_H
31# include <unistd.h>
32#else /* on Windows with MSVC */
33# include <io.h>
34#endif
35]GL_MDA_DEFINES],
36[[
37 /* Exit with success only if stdin is seekable. */
38 return lseek (0, (off_t)0, SEEK_CUR) < 0;
39]])],
40 [if test -s conftest$ac_exeext \
41 && ./conftest$ac_exeext < conftest.$ac_ext \
42 && test 1 = "`echo hi \
43 | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
44 gl_cv_func_lseek_pipe=yes
45 else
46 gl_cv_func_lseek_pipe=no
47 fi
48 ],
49 [gl_cv_func_lseek_pipe=no])
50 else
51 AC_COMPILE_IFELSE(
52 [AC_LANG_SOURCE([[
53#if defined __BEOS__
54/* BeOS mistakenly return 0 when trying to seek on pipes. */
55 Choke me.
56#endif]])],
57 [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
58 fi
59 ;;
60 esac
61 ])
62 if test "$gl_cv_func_lseek_pipe" = no; then
63 REPLACE_LSEEK=1
64 AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
65 [Define to 1 if lseek does not detect pipes.])
66 fi
67
68 AC_REQUIRE([gl_SYS_TYPES_H])
69 if test $WINDOWS_64_BIT_OFF_T = 1; then
70 REPLACE_LSEEK=1
71 fi
72
73 dnl macOS SEEK_DATA is incompatible with other platforms.
74 case $host_os in
75 darwin*)
76 REPLACE_LSEEK=1;;
77 esac
78])
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4
index 4b24a0b..5540292 100644
--- a/gl/m4/malloc.m4
+++ b/gl/m4/malloc.m4
@@ -1,98 +1,175 @@
1# malloc.m4 serial 14 1# malloc.m4 serial 28
2dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2023 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
7m4_version_prereq([2.70], [] ,[ 7# This is adapted with modifications from upstream Autoconf here:
8 8# https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n949
9# This is taken from the following Autoconf patch:
10# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
11AC_DEFUN([_AC_FUNC_MALLOC_IF], 9AC_DEFUN([_AC_FUNC_MALLOC_IF],
12[ 10[
13 AC_REQUIRE([AC_HEADER_STDC])dnl
14 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles 11 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
15 AC_CHECK_HEADERS([stdlib.h]) 12 AC_CACHE_CHECK([whether malloc (0) returns nonnull],
16 AC_CACHE_CHECK([for GNU libc compatible malloc],
17 [ac_cv_func_malloc_0_nonnull], 13 [ac_cv_func_malloc_0_nonnull],
18 [AC_RUN_IFELSE( 14 [AC_RUN_IFELSE(
19 [AC_LANG_PROGRAM( 15 [AC_LANG_PROGRAM(
20 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H 16 [[#include <stdlib.h>
21 # include <stdlib.h>
22 #else
23 char *malloc ();
24 #endif
25 ]], 17 ]],
26 [[return ! malloc (0);]]) 18 [[void *p = malloc (0);
19 int result = !p;
20 free (p);
21 return result;]])
27 ], 22 ],
28 [ac_cv_func_malloc_0_nonnull=yes], 23 [ac_cv_func_malloc_0_nonnull=yes],
29 [ac_cv_func_malloc_0_nonnull=no], 24 [ac_cv_func_malloc_0_nonnull=no],
30 [case "$host_os" in 25 [case "$host_os" in
31 # Guess yes on platforms where we know the result. 26 # Guess yes on platforms where we know the result.
32 *-gnu* | freebsd* | netbsd* | openbsd* \ 27 *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
33 | hpux* | solaris* | cygwin* | mingw*) 28 | gnu* | *-musl* | midnightbsd* \
34 ac_cv_func_malloc_0_nonnull=yes ;; 29 | hpux* | solaris* | cygwin* | mingw* | msys* )
35 # If we don't know, assume the worst. 30 ac_cv_func_malloc_0_nonnull="guessing yes" ;;
36 *) ac_cv_func_malloc_0_nonnull=no ;; 31 # If we don't know, obey --enable-cross-guesses.
32 *) ac_cv_func_malloc_0_nonnull="$gl_cross_guess_normal" ;;
37 esac 33 esac
38 ]) 34 ])
39 ]) 35 ])
40 AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2]) 36 AS_CASE([$ac_cv_func_malloc_0_nonnull], [*yes], [$1], [$2])
41])# _AC_FUNC_MALLOC_IF 37])# _AC_FUNC_MALLOC_IF
42 38
43])
44
45# gl_FUNC_MALLOC_GNU 39# gl_FUNC_MALLOC_GNU
46# ------------------ 40# ------------------
47# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if 41# Replace malloc if it is not compatible with GNU libc.
48# it is not.
49AC_DEFUN([gl_FUNC_MALLOC_GNU], 42AC_DEFUN([gl_FUNC_MALLOC_GNU],
50[ 43[
51 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 44 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
52 dnl _AC_FUNC_MALLOC_IF is defined in Autoconf. 45 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
53 _AC_FUNC_MALLOC_IF( 46 REPLACE_MALLOC_FOR_MALLOC_GNU="$REPLACE_MALLOC_FOR_MALLOC_POSIX"
54 [AC_DEFINE([HAVE_MALLOC_GNU], [1], 47 if test $REPLACE_MALLOC_FOR_MALLOC_GNU = 0; then
55 [Define to 1 if your system has a GNU libc compatible 'malloc' 48 _AC_FUNC_MALLOC_IF([], [REPLACE_MALLOC_FOR_MALLOC_GNU=1])
56 function, and to 0 otherwise.])], 49 fi
57 [AC_DEFINE([HAVE_MALLOC_GNU], [0]) 50])
58 REPLACE_MALLOC=1 51
52# gl_FUNC_MALLOC_PTRDIFF
53# ----------------------
54# Test whether malloc (N) reliably fails when N exceeds PTRDIFF_MAX,
55# and replace malloc otherwise.
56AC_DEFUN([gl_FUNC_MALLOC_PTRDIFF],
57[
58 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
59 AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF])
60 test "$gl_cv_malloc_ptrdiff" = yes || REPLACE_MALLOC_FOR_MALLOC_POSIX=1
61])
62
63# Test whether malloc, realloc, calloc refuse to create objects
64# larger than what can be expressed in ptrdiff_t.
65# Set gl_cv_func_malloc_gnu to yes or no accordingly.
66AC_DEFUN([gl_CHECK_MALLOC_PTRDIFF],
67[
68 AC_CACHE_CHECK([whether malloc is ptrdiff_t safe],
69 [gl_cv_malloc_ptrdiff],
70 [AC_COMPILE_IFELSE(
71 [AC_LANG_PROGRAM(
72 [[#include <stdint.h>
73 ]],
74 [[/* 64-bit ptrdiff_t is so wide that no practical platform
75 can exceed it. */
76 #define WIDE_PTRDIFF (PTRDIFF_MAX >> 31 >> 31 != 0)
77
78 /* On rare machines where size_t fits in ptrdiff_t there
79 is no problem. */
80 #define NARROW_SIZE (SIZE_MAX <= PTRDIFF_MAX)
81
82 /* glibc 2.30 and later malloc refuses to exceed ptrdiff_t
83 bounds even on 32-bit platforms. We don't know which
84 non-glibc systems are safe. */
85 #define KNOWN_SAFE (2 < __GLIBC__ + (30 <= __GLIBC_MINOR__))
86
87 #if WIDE_PTRDIFF || NARROW_SIZE || KNOWN_SAFE
88 return 0;
89 #else
90 #error "malloc might not be ptrdiff_t safe"
91 syntax error
92 #endif
93 ]])],
94 [gl_cv_malloc_ptrdiff=yes],
95 [gl_cv_malloc_ptrdiff=no])
59 ]) 96 ])
60]) 97])
61 98
62# gl_FUNC_MALLOC_POSIX 99# gl_FUNC_MALLOC_POSIX
63# -------------------- 100# --------------------
64# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it 101# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
65# fails), and replace malloc if it is not. 102# fails, and doesn't mess up with ptrdiff_t overflow), and replace
103# malloc if it is not.
66AC_DEFUN([gl_FUNC_MALLOC_POSIX], 104AC_DEFUN([gl_FUNC_MALLOC_POSIX],
67[ 105[
68 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 106 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
107 AC_REQUIRE([gl_FUNC_MALLOC_PTRDIFF])
69 AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) 108 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
70 if test $gl_cv_func_malloc_posix = yes; then 109 if test "$gl_cv_func_malloc_posix" = yes; then
71 AC_DEFINE([HAVE_MALLOC_POSIX], [1], 110 AC_DEFINE([HAVE_MALLOC_POSIX], [1],
72 [Define if the 'malloc' function is POSIX compliant.]) 111 [Define if malloc, realloc, and calloc set errno on allocation failure.])
73 else 112 else
74 REPLACE_MALLOC=1 113 REPLACE_MALLOC_FOR_MALLOC_POSIX=1
75 fi 114 fi
76]) 115])
77 116
78# Test whether malloc, realloc, calloc are POSIX compliant, 117# Test whether malloc, realloc, calloc set errno to ENOMEM on failure.
79# Set gl_cv_func_malloc_posix to yes or no accordingly. 118# Set gl_cv_func_malloc_posix to yes or no accordingly.
80AC_DEFUN([gl_CHECK_MALLOC_POSIX], 119AC_DEFUN([gl_CHECK_MALLOC_POSIX],
81[ 120[
82 AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant], 121 AC_REQUIRE([AC_CANONICAL_HOST])
122 AC_CACHE_CHECK([whether malloc, realloc, calloc set errno on failure],
83 [gl_cv_func_malloc_posix], 123 [gl_cv_func_malloc_posix],
84 [ 124 [
85 dnl It is too dangerous to try to allocate a large amount of memory: 125 dnl It is too dangerous to try to allocate a large amount of memory:
86 dnl some systems go to their knees when you do that. So assume that 126 dnl some systems go to their knees when you do that. So assume that
87 dnl all Unix implementations of the function are POSIX compliant. 127 dnl all Unix implementations of the function set errno on failure,
88 AC_COMPILE_IFELSE( 128 dnl except on those platforms where we have seen 'test-malloc-gnu',
89 [AC_LANG_PROGRAM( 129 dnl 'test-realloc-gnu', 'test-calloc-gnu' fail.
90 [[]], 130 case "$host_os" in
91 [[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 131 mingw*)
92 choke me 132 gl_cv_func_malloc_posix=no ;;
93 #endif 133 irix* | solaris*)
94 ]])], 134 dnl On IRIX 6.5, the three functions return NULL with errno unset
95 [gl_cv_func_malloc_posix=yes], 135 dnl when the argument is larger than PTRDIFF_MAX.
96 [gl_cv_func_malloc_posix=no]) 136 dnl On Solaris 11.3, the three functions return NULL with errno set
137 dnl to EAGAIN, not ENOMEM, when the argument is larger than
138 dnl PTRDIFF_MAX.
139 dnl Here is a test program:
140m4_divert_push([KILL])
141#include <errno.h>
142#include <stdio.h>
143#include <stdlib.h>
144#define ptrdiff_t long
145#ifndef PTRDIFF_MAX
146# define PTRDIFF_MAX ((ptrdiff_t) ((1UL << (8 * sizeof (ptrdiff_t) - 1)) - 1))
147#endif
148
149int main ()
150{
151 void *p;
152
153 fprintf (stderr, "PTRDIFF_MAX = %lu\n", (unsigned long) PTRDIFF_MAX);
154
155 errno = 0;
156 p = malloc ((unsigned long) PTRDIFF_MAX + 1);
157 fprintf (stderr, "p=%p errno=%d\n", p, errno);
158
159 errno = 0;
160 p = calloc (PTRDIFF_MAX / 2 + 1, 2);
161 fprintf (stderr, "p=%p errno=%d\n", p, errno);
162
163 errno = 0;
164 p = realloc (NULL, (unsigned long) PTRDIFF_MAX + 1);
165 fprintf (stderr, "p=%p errno=%d\n", p, errno);
166
167 return 0;
168}
169m4_divert_pop([KILL])
170 gl_cv_func_malloc_posix=no ;;
171 *)
172 gl_cv_func_malloc_posix=yes ;;
173 esac
97 ]) 174 ])
98]) 175])
diff --git a/gl/m4/malloca.m4 b/gl/m4/malloca.m4
index 791ce10..1d777eb 100644
--- a/gl/m4/malloca.m4
+++ b/gl/m4/malloca.m4
@@ -1,5 +1,5 @@
1# malloca.m4 serial 1 1# malloca.m4 serial 2
2dnl Copyright (C) 2003-2004, 2006-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2003-2004, 2006-2007, 2009-2023 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
@@ -11,5 +11,4 @@ AC_DEFUN([gl_MALLOCA],
11 dnl @ALLOCA@ and @LTALLOCA@. 11 dnl @ALLOCA@ and @LTALLOCA@.
12 dnl gl_FUNC_ALLOCA dnl Already brought in by the module dependencies. 12 dnl gl_FUNC_ALLOCA dnl Already brought in by the module dependencies.
13 AC_REQUIRE([gl_EEMALLOC]) 13 AC_REQUIRE([gl_EEMALLOC])
14 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
15]) 14])
diff --git a/gl/m4/math_h.m4 b/gl/m4/math_h.m4
index bf0845f..d2e90ff 100644
--- a/gl/m4/math_h.m4
+++ b/gl/m4/math_h.m4
@@ -1,16 +1,16 @@
1# math_h.m4 serial 114 1# math_h.m4 serial 125
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2023 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_MATH_H], 7AC_DEFUN_ONCE([gl_MATH_H],
8[ 8[
9 AC_REQUIRE([gl_MATH_H_DEFAULTS]) 9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 gl_CHECK_NEXT_HEADERS([math.h]) 10 gl_CHECK_NEXT_HEADERS([math.h])
11 11
12 AC_CACHE_CHECK([whether NAN macro works], [gl_cv_header_math_nan_works], 12 AC_CACHE_CHECK([whether NAN macro works], [gl_cv_header_math_nan_works],
13 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>]], 13 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]],
14 [[/* Solaris 10 has a broken definition of NAN. Other platforms 14 [[/* Solaris 10 has a broken definition of NAN. Other platforms
15 fail to provide NAN, or provide it only in C99 mode; this 15 fail to provide NAN, or provide it only in C99 mode; this
16 test only needs to fail when NAN is provided but wrong. */ 16 test only needs to fail when NAN is provided but wrong. */
@@ -25,7 +25,7 @@ AC_DEFUN([gl_MATH_H],
25 REPLACE_NAN=1 25 REPLACE_NAN=1
26 fi 26 fi
27 AC_CACHE_CHECK([whether HUGE_VAL works], [gl_cv_header_math_huge_val_works], 27 AC_CACHE_CHECK([whether HUGE_VAL works], [gl_cv_header_math_huge_val_works],
28 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <math.h>]], 28 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]],
29 [[/* Solaris 10 has a broken definition of HUGE_VAL. */ 29 [[/* Solaris 10 has a broken definition of HUGE_VAL. */
30 double d = HUGE_VAL; 30 double d = HUGE_VAL;
31 return d == 0;]])], 31 return d == 0;]])],
@@ -53,272 +53,310 @@ AC_DEFUN([gl_MATH_H],
53 tanf tanl tanhf trunc truncf truncl]) 53 tanf tanl tanhf trunc truncf truncl])
54]) 54])
55 55
56# gl_MATH_MODULE_INDICATOR([modulename])
57# sets the shell variable that indicates the presence of the given module
58# to a C preprocessor expression that will evaluate to 1.
59# This macro invocation must not occur in macros that are AC_REQUIREd.
56AC_DEFUN([gl_MATH_MODULE_INDICATOR], 60AC_DEFUN([gl_MATH_MODULE_INDICATOR],
57[ 61[
58 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 62 dnl Ensure to expand the default settings once only.
59 AC_REQUIRE([gl_MATH_H_DEFAULTS]) 63 gl_MATH_H_REQUIRE_DEFAULTS
60 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 64 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
61 dnl Define it also as a C macro, for the benefit of the unit tests. 65 dnl Define it also as a C macro, for the benefit of the unit tests.
62 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 66 gl_MODULE_INDICATOR_FOR_TESTS([$1])
63]) 67])
64 68
69# Initializes the default values for AC_SUBSTed shell variables.
70# This macro must not be AC_REQUIREd. It must only be invoked, and only
71# outside of macros or in macros that are not AC_REQUIREd.
72AC_DEFUN([gl_MATH_H_REQUIRE_DEFAULTS],
73[
74 m4_defun(GL_MODULE_INDICATOR_PREFIX[_MATH_H_MODULE_INDICATOR_DEFAULTS], [
75 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACOSF])
76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACOSL])
77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ASINF])
78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ASINL])
79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ATANF])
80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ATANL])
81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ATAN2F])
82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CBRT])
83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CBRTF])
84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CBRTL])
85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CEIL])
86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CEILF])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CEILL])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COPYSIGN])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COPYSIGNF])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COPYSIGNL])
91 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COSF])
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COSL])
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COSHF])
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPF])
95 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPL])
96 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXP2])
97 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXP2F])
98 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXP2L])
99 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPM1])
100 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPM1F])
101 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPM1L])
102 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FABSF])
103 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FABSL])
104 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FLOOR])
105 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FLOORF])
106 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FLOORL])
107 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FMA])
108 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FMAF])
109 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FMAL])
110 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FMOD])
111 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FMODF])
112 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FMODL])
113 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREXPF])
114 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREXP])
115 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREXPL])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_HYPOT])
117 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_HYPOTF])
118 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_HYPOTL])
119 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ILOGB])
120 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ILOGBF])
121 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ILOGBL])
122 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISFINITE])
123 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISINF])
124 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISNAN])
125 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISNANF])
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISNAND])
127 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISNANL])
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LDEXPF])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LDEXPL])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOGF])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOGL])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG10])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG10F])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG10L])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG1P])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG1PF])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG1PL])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG2])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG2F])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOG2L])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOGB])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOGBF])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOGBL])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MODF])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MODFF])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MODFL])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POWF])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMAINDER])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMAINDERF])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMAINDERL])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RINT])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RINTF])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RINTL])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ROUND])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ROUNDF])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ROUNDL])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGNBIT])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINF])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINL])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SINHF])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SQRTF])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SQRTL])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TANF])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TANL])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TANHF])
167 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNC])
168 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCF])
169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCL])
170 dnl Support Microsoft deprecated alias function names by default.
171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_J0], [1])
172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_J1], [1])
173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_JN], [1])
174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_Y0], [1])
175 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_Y1], [1])
176 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_YN], [1])
177 ])
178 m4_require(GL_MODULE_INDICATOR_PREFIX[_MATH_H_MODULE_INDICATOR_DEFAULTS])
179 AC_REQUIRE([gl_MATH_H_DEFAULTS])
180])
181
65AC_DEFUN([gl_MATH_H_DEFAULTS], 182AC_DEFUN([gl_MATH_H_DEFAULTS],
66[ 183[
67 GNULIB_ACOSF=0; AC_SUBST([GNULIB_ACOSF])
68 GNULIB_ACOSL=0; AC_SUBST([GNULIB_ACOSL])
69 GNULIB_ASINF=0; AC_SUBST([GNULIB_ASINF])
70 GNULIB_ASINL=0; AC_SUBST([GNULIB_ASINL])
71 GNULIB_ATANF=0; AC_SUBST([GNULIB_ATANF])
72 GNULIB_ATANL=0; AC_SUBST([GNULIB_ATANL])
73 GNULIB_ATAN2F=0; AC_SUBST([GNULIB_ATAN2F])
74 GNULIB_CBRT=0; AC_SUBST([GNULIB_CBRT])
75 GNULIB_CBRTF=0; AC_SUBST([GNULIB_CBRTF])
76 GNULIB_CBRTL=0; AC_SUBST([GNULIB_CBRTL])
77 GNULIB_CEIL=0; AC_SUBST([GNULIB_CEIL])
78 GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF])
79 GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL])
80 GNULIB_COPYSIGN=0; AC_SUBST([GNULIB_COPYSIGN])
81 GNULIB_COPYSIGNF=0; AC_SUBST([GNULIB_COPYSIGNF])
82 GNULIB_COPYSIGNL=0; AC_SUBST([GNULIB_COPYSIGNL])
83 GNULIB_COSF=0; AC_SUBST([GNULIB_COSF])
84 GNULIB_COSL=0; AC_SUBST([GNULIB_COSL])
85 GNULIB_COSHF=0; AC_SUBST([GNULIB_COSHF])
86 GNULIB_EXPF=0; AC_SUBST([GNULIB_EXPF])
87 GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL])
88 GNULIB_EXP2=0; AC_SUBST([GNULIB_EXP2])
89 GNULIB_EXP2F=0; AC_SUBST([GNULIB_EXP2F])
90 GNULIB_EXP2L=0; AC_SUBST([GNULIB_EXP2L])
91 GNULIB_EXPM1=0; AC_SUBST([GNULIB_EXPM1])
92 GNULIB_EXPM1F=0; AC_SUBST([GNULIB_EXPM1F])
93 GNULIB_EXPM1L=0; AC_SUBST([GNULIB_EXPM1L])
94 GNULIB_FABSF=0; AC_SUBST([GNULIB_FABSF])
95 GNULIB_FABSL=0; AC_SUBST([GNULIB_FABSL])
96 GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR])
97 GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF])
98 GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL])
99 GNULIB_FMA=0; AC_SUBST([GNULIB_FMA])
100 GNULIB_FMAF=0; AC_SUBST([GNULIB_FMAF])
101 GNULIB_FMAL=0; AC_SUBST([GNULIB_FMAL])
102 GNULIB_FMOD=0; AC_SUBST([GNULIB_FMOD])
103 GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF])
104 GNULIB_FMODL=0; AC_SUBST([GNULIB_FMODL])
105 GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF])
106 GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP])
107 GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL])
108 GNULIB_HYPOT=0; AC_SUBST([GNULIB_HYPOT])
109 GNULIB_HYPOTF=0; AC_SUBST([GNULIB_HYPOTF])
110 GNULIB_HYPOTL=0; AC_SUBST([GNULIB_HYPOTL])
111 GNULIB_ILOGB=0; AC_SUBST([GNULIB_ILOGB])
112 GNULIB_ILOGBF=0; AC_SUBST([GNULIB_ILOGBF])
113 GNULIB_ILOGBL=0; AC_SUBST([GNULIB_ILOGBL])
114 GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE])
115 GNULIB_ISINF=0; AC_SUBST([GNULIB_ISINF])
116 GNULIB_ISNAN=0; AC_SUBST([GNULIB_ISNAN])
117 GNULIB_ISNANF=0; AC_SUBST([GNULIB_ISNANF])
118 GNULIB_ISNAND=0; AC_SUBST([GNULIB_ISNAND])
119 GNULIB_ISNANL=0; AC_SUBST([GNULIB_ISNANL])
120 GNULIB_LDEXPF=0; AC_SUBST([GNULIB_LDEXPF])
121 GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL])
122 GNULIB_LOG=0; AC_SUBST([GNULIB_LOG])
123 GNULIB_LOGF=0; AC_SUBST([GNULIB_LOGF])
124 GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL])
125 GNULIB_LOG10=0; AC_SUBST([GNULIB_LOG10])
126 GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F])
127 GNULIB_LOG10L=0; AC_SUBST([GNULIB_LOG10L])
128 GNULIB_LOG1P=0; AC_SUBST([GNULIB_LOG1P])
129 GNULIB_LOG1PF=0; AC_SUBST([GNULIB_LOG1PF])
130 GNULIB_LOG1PL=0; AC_SUBST([GNULIB_LOG1PL])
131 GNULIB_LOG2=0; AC_SUBST([GNULIB_LOG2])
132 GNULIB_LOG2F=0; AC_SUBST([GNULIB_LOG2F])
133 GNULIB_LOG2L=0; AC_SUBST([GNULIB_LOG2L])
134 GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB])
135 GNULIB_LOGBF=0; AC_SUBST([GNULIB_LOGBF])
136 GNULIB_LOGBL=0; AC_SUBST([GNULIB_LOGBL])
137 GNULIB_MODF=0; AC_SUBST([GNULIB_MODF])
138 GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF])
139 GNULIB_MODFL=0; AC_SUBST([GNULIB_MODFL])
140 GNULIB_POWF=0; AC_SUBST([GNULIB_POWF])
141 GNULIB_REMAINDER=0; AC_SUBST([GNULIB_REMAINDER])
142 GNULIB_REMAINDERF=0; AC_SUBST([GNULIB_REMAINDERF])
143 GNULIB_REMAINDERL=0; AC_SUBST([GNULIB_REMAINDERL])
144 GNULIB_RINT=0; AC_SUBST([GNULIB_RINT])
145 GNULIB_RINTF=0; AC_SUBST([GNULIB_RINTF])
146 GNULIB_RINTL=0; AC_SUBST([GNULIB_RINTL])
147 GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND])
148 GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF])
149 GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL])
150 GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT])
151 GNULIB_SINF=0; AC_SUBST([GNULIB_SINF])
152 GNULIB_SINL=0; AC_SUBST([GNULIB_SINL])
153 GNULIB_SINHF=0; AC_SUBST([GNULIB_SINHF])
154 GNULIB_SQRTF=0; AC_SUBST([GNULIB_SQRTF])
155 GNULIB_SQRTL=0; AC_SUBST([GNULIB_SQRTL])
156 GNULIB_TANF=0; AC_SUBST([GNULIB_TANF])
157 GNULIB_TANL=0; AC_SUBST([GNULIB_TANL])
158 GNULIB_TANHF=0; AC_SUBST([GNULIB_TANHF])
159 GNULIB_TRUNC=0; AC_SUBST([GNULIB_TRUNC])
160 GNULIB_TRUNCF=0; AC_SUBST([GNULIB_TRUNCF])
161 GNULIB_TRUNCL=0; AC_SUBST([GNULIB_TRUNCL])
162 dnl Assume proper GNU behavior unless another module says otherwise. 184 dnl Assume proper GNU behavior unless another module says otherwise.
163 HAVE_ACOSF=1; AC_SUBST([HAVE_ACOSF]) 185 HAVE_ACOSF=1; AC_SUBST([HAVE_ACOSF])
164 HAVE_ACOSL=1; AC_SUBST([HAVE_ACOSL]) 186 HAVE_ACOSL=1; AC_SUBST([HAVE_ACOSL])
165 HAVE_ASINF=1; AC_SUBST([HAVE_ASINF]) 187 HAVE_ASINF=1; AC_SUBST([HAVE_ASINF])
166 HAVE_ASINL=1; AC_SUBST([HAVE_ASINL]) 188 HAVE_ASINL=1; AC_SUBST([HAVE_ASINL])
167 HAVE_ATANF=1; AC_SUBST([HAVE_ATANF]) 189 HAVE_ATANF=1; AC_SUBST([HAVE_ATANF])
168 HAVE_ATANL=1; AC_SUBST([HAVE_ATANL]) 190 HAVE_ATANL=1; AC_SUBST([HAVE_ATANL])
169 HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F]) 191 HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F])
170 HAVE_CBRT=1; AC_SUBST([HAVE_CBRT]) 192 HAVE_CBRT=1; AC_SUBST([HAVE_CBRT])
171 HAVE_CBRTF=1; AC_SUBST([HAVE_CBRTF]) 193 HAVE_CBRTF=1; AC_SUBST([HAVE_CBRTF])
172 HAVE_CBRTL=1; AC_SUBST([HAVE_CBRTL]) 194 HAVE_CBRTL=1; AC_SUBST([HAVE_CBRTL])
173 HAVE_COPYSIGN=1; AC_SUBST([HAVE_COPYSIGN]) 195 HAVE_COPYSIGN=1; AC_SUBST([HAVE_COPYSIGN])
174 HAVE_COPYSIGNL=1; AC_SUBST([HAVE_COPYSIGNL]) 196 HAVE_COPYSIGNL=1; AC_SUBST([HAVE_COPYSIGNL])
175 HAVE_COSF=1; AC_SUBST([HAVE_COSF]) 197 HAVE_COSF=1; AC_SUBST([HAVE_COSF])
176 HAVE_COSL=1; AC_SUBST([HAVE_COSL]) 198 HAVE_COSL=1; AC_SUBST([HAVE_COSL])
177 HAVE_COSHF=1; AC_SUBST([HAVE_COSHF]) 199 HAVE_COSHF=1; AC_SUBST([HAVE_COSHF])
178 HAVE_EXPF=1; AC_SUBST([HAVE_EXPF]) 200 HAVE_EXPF=1; AC_SUBST([HAVE_EXPF])
179 HAVE_EXPL=1; AC_SUBST([HAVE_EXPL]) 201 HAVE_EXPL=1; AC_SUBST([HAVE_EXPL])
180 HAVE_EXPM1=1; AC_SUBST([HAVE_EXPM1]) 202 HAVE_EXPM1=1; AC_SUBST([HAVE_EXPM1])
181 HAVE_EXPM1F=1; AC_SUBST([HAVE_EXPM1F]) 203 HAVE_EXPM1F=1; AC_SUBST([HAVE_EXPM1F])
182 HAVE_FABSF=1; AC_SUBST([HAVE_FABSF]) 204 HAVE_FABSF=1; AC_SUBST([HAVE_FABSF])
183 HAVE_FABSL=1; AC_SUBST([HAVE_FABSL]) 205 HAVE_FABSL=1; AC_SUBST([HAVE_FABSL])
184 HAVE_FMA=1; AC_SUBST([HAVE_FMA]) 206 HAVE_FMA=1; AC_SUBST([HAVE_FMA])
185 HAVE_FMAF=1; AC_SUBST([HAVE_FMAF]) 207 HAVE_FMAF=1; AC_SUBST([HAVE_FMAF])
186 HAVE_FMAL=1; AC_SUBST([HAVE_FMAL]) 208 HAVE_FMAL=1; AC_SUBST([HAVE_FMAL])
187 HAVE_FMODF=1; AC_SUBST([HAVE_FMODF]) 209 HAVE_FMODF=1; AC_SUBST([HAVE_FMODF])
188 HAVE_FMODL=1; AC_SUBST([HAVE_FMODL]) 210 HAVE_FMODL=1; AC_SUBST([HAVE_FMODL])
189 HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF]) 211 HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF])
190 HAVE_HYPOTF=1; AC_SUBST([HAVE_HYPOTF]) 212 HAVE_HYPOTF=1; AC_SUBST([HAVE_HYPOTF])
191 HAVE_HYPOTL=1; AC_SUBST([HAVE_HYPOTL]) 213 HAVE_HYPOTL=1; AC_SUBST([HAVE_HYPOTL])
192 HAVE_ILOGB=1; AC_SUBST([HAVE_ILOGB]) 214 HAVE_ILOGB=1; AC_SUBST([HAVE_ILOGB])
193 HAVE_ILOGBF=1; AC_SUBST([HAVE_ILOGBF]) 215 HAVE_ILOGBF=1; AC_SUBST([HAVE_ILOGBF])
194 HAVE_ILOGBL=1; AC_SUBST([HAVE_ILOGBL]) 216 HAVE_ILOGBL=1; AC_SUBST([HAVE_ILOGBL])
195 HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF]) 217 HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF])
196 HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND]) 218 HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND])
197 HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL]) 219 HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL])
198 HAVE_LDEXPF=1; AC_SUBST([HAVE_LDEXPF]) 220 HAVE_LDEXPF=1; AC_SUBST([HAVE_LDEXPF])
199 HAVE_LOGF=1; AC_SUBST([HAVE_LOGF]) 221 HAVE_LOGF=1; AC_SUBST([HAVE_LOGF])
200 HAVE_LOGL=1; AC_SUBST([HAVE_LOGL]) 222 HAVE_LOGL=1; AC_SUBST([HAVE_LOGL])
201 HAVE_LOG10F=1; AC_SUBST([HAVE_LOG10F]) 223 HAVE_LOG10F=1; AC_SUBST([HAVE_LOG10F])
202 HAVE_LOG10L=1; AC_SUBST([HAVE_LOG10L]) 224 HAVE_LOG10L=1; AC_SUBST([HAVE_LOG10L])
203 HAVE_LOG1P=1; AC_SUBST([HAVE_LOG1P]) 225 HAVE_LOG1P=1; AC_SUBST([HAVE_LOG1P])
204 HAVE_LOG1PF=1; AC_SUBST([HAVE_LOG1PF]) 226 HAVE_LOG1PF=1; AC_SUBST([HAVE_LOG1PF])
205 HAVE_LOG1PL=1; AC_SUBST([HAVE_LOG1PL]) 227 HAVE_LOG1PL=1; AC_SUBST([HAVE_LOG1PL])
206 HAVE_LOGBF=1; AC_SUBST([HAVE_LOGBF]) 228 HAVE_LOGBF=1; AC_SUBST([HAVE_LOGBF])
207 HAVE_LOGBL=1; AC_SUBST([HAVE_LOGBL]) 229 HAVE_LOGBL=1; AC_SUBST([HAVE_LOGBL])
208 HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) 230 HAVE_MODFF=1; AC_SUBST([HAVE_MODFF])
209 HAVE_MODFL=1; AC_SUBST([HAVE_MODFL]) 231 HAVE_MODFL=1; AC_SUBST([HAVE_MODFL])
210 HAVE_POWF=1; AC_SUBST([HAVE_POWF]) 232 HAVE_POWF=1; AC_SUBST([HAVE_POWF])
211 HAVE_REMAINDER=1; AC_SUBST([HAVE_REMAINDER]) 233 HAVE_REMAINDER=1; AC_SUBST([HAVE_REMAINDER])
212 HAVE_REMAINDERF=1; AC_SUBST([HAVE_REMAINDERF]) 234 HAVE_REMAINDERF=1; AC_SUBST([HAVE_REMAINDERF])
213 HAVE_RINT=1; AC_SUBST([HAVE_RINT]) 235 HAVE_RINT=1; AC_SUBST([HAVE_RINT])
214 HAVE_RINTL=1; AC_SUBST([HAVE_RINTL]) 236 HAVE_RINTL=1; AC_SUBST([HAVE_RINTL])
215 HAVE_SINF=1; AC_SUBST([HAVE_SINF]) 237 HAVE_SINF=1; AC_SUBST([HAVE_SINF])
216 HAVE_SINL=1; AC_SUBST([HAVE_SINL]) 238 HAVE_SINL=1; AC_SUBST([HAVE_SINL])
217 HAVE_SINHF=1; AC_SUBST([HAVE_SINHF]) 239 HAVE_SINHF=1; AC_SUBST([HAVE_SINHF])
218 HAVE_SQRTF=1; AC_SUBST([HAVE_SQRTF]) 240 HAVE_SQRTF=1; AC_SUBST([HAVE_SQRTF])
219 HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL]) 241 HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL])
220 HAVE_TANF=1; AC_SUBST([HAVE_TANF]) 242 HAVE_TANF=1; AC_SUBST([HAVE_TANF])
221 HAVE_TANL=1; AC_SUBST([HAVE_TANL]) 243 HAVE_TANL=1; AC_SUBST([HAVE_TANL])
222 HAVE_TANHF=1; AC_SUBST([HAVE_TANHF]) 244 HAVE_TANHF=1; AC_SUBST([HAVE_TANHF])
223 HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) 245 HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL])
224 HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) 246 HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL])
225 HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) 247 HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL])
226 HAVE_DECL_CBRTF=1; AC_SUBST([HAVE_DECL_CBRTF]) 248 HAVE_DECL_CBRTF=1; AC_SUBST([HAVE_DECL_CBRTF])
227 HAVE_DECL_CBRTL=1; AC_SUBST([HAVE_DECL_CBRTL]) 249 HAVE_DECL_CBRTL=1; AC_SUBST([HAVE_DECL_CBRTL])
228 HAVE_DECL_CEILF=1; AC_SUBST([HAVE_DECL_CEILF]) 250 HAVE_DECL_CEILF=1; AC_SUBST([HAVE_DECL_CEILF])
229 HAVE_DECL_CEILL=1; AC_SUBST([HAVE_DECL_CEILL]) 251 HAVE_DECL_CEILL=1; AC_SUBST([HAVE_DECL_CEILL])
230 HAVE_DECL_COPYSIGNF=1; AC_SUBST([HAVE_DECL_COPYSIGNF]) 252 HAVE_DECL_COPYSIGNF=1; AC_SUBST([HAVE_DECL_COPYSIGNF])
231 HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL]) 253 HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL])
232 HAVE_DECL_EXPL=1; AC_SUBST([HAVE_DECL_EXPL]) 254 HAVE_DECL_EXPL=1; AC_SUBST([HAVE_DECL_EXPL])
233 HAVE_DECL_EXP2=1; AC_SUBST([HAVE_DECL_EXP2]) 255 HAVE_DECL_EXP2=1; AC_SUBST([HAVE_DECL_EXP2])
234 HAVE_DECL_EXP2F=1; AC_SUBST([HAVE_DECL_EXP2F]) 256 HAVE_DECL_EXP2F=1; AC_SUBST([HAVE_DECL_EXP2F])
235 HAVE_DECL_EXP2L=1; AC_SUBST([HAVE_DECL_EXP2L]) 257 HAVE_DECL_EXP2L=1; AC_SUBST([HAVE_DECL_EXP2L])
236 HAVE_DECL_EXPM1L=1; AC_SUBST([HAVE_DECL_EXPM1L]) 258 HAVE_DECL_EXPM1L=1; AC_SUBST([HAVE_DECL_EXPM1L])
237 HAVE_DECL_FLOORF=1; AC_SUBST([HAVE_DECL_FLOORF]) 259 HAVE_DECL_FLOORF=1; AC_SUBST([HAVE_DECL_FLOORF])
238 HAVE_DECL_FLOORL=1; AC_SUBST([HAVE_DECL_FLOORL]) 260 HAVE_DECL_FLOORL=1; AC_SUBST([HAVE_DECL_FLOORL])
239 HAVE_DECL_FREXPL=1; AC_SUBST([HAVE_DECL_FREXPL]) 261 HAVE_DECL_FREXPL=1; AC_SUBST([HAVE_DECL_FREXPL])
240 HAVE_DECL_LDEXPL=1; AC_SUBST([HAVE_DECL_LDEXPL]) 262 HAVE_DECL_LDEXPL=1; AC_SUBST([HAVE_DECL_LDEXPL])
241 HAVE_DECL_LOGL=1; AC_SUBST([HAVE_DECL_LOGL]) 263 HAVE_DECL_LOGL=1; AC_SUBST([HAVE_DECL_LOGL])
242 HAVE_DECL_LOG10L=1; AC_SUBST([HAVE_DECL_LOG10L]) 264 HAVE_DECL_LOG10L=1; AC_SUBST([HAVE_DECL_LOG10L])
243 HAVE_DECL_LOG2=1; AC_SUBST([HAVE_DECL_LOG2]) 265 HAVE_DECL_LOG2=1; AC_SUBST([HAVE_DECL_LOG2])
244 HAVE_DECL_LOG2F=1; AC_SUBST([HAVE_DECL_LOG2F]) 266 HAVE_DECL_LOG2F=1; AC_SUBST([HAVE_DECL_LOG2F])
245 HAVE_DECL_LOG2L=1; AC_SUBST([HAVE_DECL_LOG2L]) 267 HAVE_DECL_LOG2L=1; AC_SUBST([HAVE_DECL_LOG2L])
246 HAVE_DECL_LOGB=1; AC_SUBST([HAVE_DECL_LOGB]) 268 HAVE_DECL_LOGB=1; AC_SUBST([HAVE_DECL_LOGB])
247 HAVE_DECL_REMAINDER=1; AC_SUBST([HAVE_DECL_REMAINDER]) 269 HAVE_DECL_REMAINDER=1; AC_SUBST([HAVE_DECL_REMAINDER])
248 HAVE_DECL_REMAINDERL=1; AC_SUBST([HAVE_DECL_REMAINDERL]) 270 HAVE_DECL_REMAINDERL=1; AC_SUBST([HAVE_DECL_REMAINDERL])
249 HAVE_DECL_RINTF=1; AC_SUBST([HAVE_DECL_RINTF]) 271 HAVE_DECL_RINTF=1; AC_SUBST([HAVE_DECL_RINTF])
250 HAVE_DECL_ROUND=1; AC_SUBST([HAVE_DECL_ROUND]) 272 HAVE_DECL_ROUND=1; AC_SUBST([HAVE_DECL_ROUND])
251 HAVE_DECL_ROUNDF=1; AC_SUBST([HAVE_DECL_ROUNDF]) 273 HAVE_DECL_ROUNDF=1; AC_SUBST([HAVE_DECL_ROUNDF])
252 HAVE_DECL_ROUNDL=1; AC_SUBST([HAVE_DECL_ROUNDL]) 274 HAVE_DECL_ROUNDL=1; AC_SUBST([HAVE_DECL_ROUNDL])
253 HAVE_DECL_SINL=1; AC_SUBST([HAVE_DECL_SINL]) 275 HAVE_DECL_SINL=1; AC_SUBST([HAVE_DECL_SINL])
254 HAVE_DECL_SQRTL=1; AC_SUBST([HAVE_DECL_SQRTL]) 276 HAVE_DECL_SQRTL=1; AC_SUBST([HAVE_DECL_SQRTL])
255 HAVE_DECL_TANL=1; AC_SUBST([HAVE_DECL_TANL]) 277 HAVE_DECL_TANL=1; AC_SUBST([HAVE_DECL_TANL])
256 HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC]) 278 HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC])
257 HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF]) 279 HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF])
258 HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL]) 280 HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL])
259 REPLACE_CBRTF=0; AC_SUBST([REPLACE_CBRTF]) 281 REPLACE_ACOSF=0; AC_SUBST([REPLACE_ACOSF])
260 REPLACE_CBRTL=0; AC_SUBST([REPLACE_CBRTL]) 282 REPLACE_ASINF=0; AC_SUBST([REPLACE_ASINF])
261 REPLACE_CEIL=0; AC_SUBST([REPLACE_CEIL]) 283 REPLACE_ATANF=0; AC_SUBST([REPLACE_ATANF])
262 REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF]) 284 REPLACE_ATAN2F=0; AC_SUBST([REPLACE_ATAN2F])
263 REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL]) 285 REPLACE_CBRTF=0; AC_SUBST([REPLACE_CBRTF])
264 REPLACE_EXPM1=0; AC_SUBST([REPLACE_EXPM1]) 286 REPLACE_CBRTL=0; AC_SUBST([REPLACE_CBRTL])
265 REPLACE_EXPM1F=0; AC_SUBST([REPLACE_EXPM1F]) 287 REPLACE_CEIL=0; AC_SUBST([REPLACE_CEIL])
266 REPLACE_EXP2=0; AC_SUBST([REPLACE_EXP2]) 288 REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF])
267 REPLACE_EXP2L=0; AC_SUBST([REPLACE_EXP2L]) 289 REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL])
268 REPLACE_FABSL=0; AC_SUBST([REPLACE_FABSL]) 290 REPLACE_COSF=0; AC_SUBST([REPLACE_COSF])
269 REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR]) 291 REPLACE_COSHF=0; AC_SUBST([REPLACE_COSHF])
270 REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF]) 292 REPLACE_EXPF=0; AC_SUBST([REPLACE_EXPF])
271 REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL]) 293 REPLACE_EXPL=0; AC_SUBST([REPLACE_EXPL])
272 REPLACE_FMA=0; AC_SUBST([REPLACE_FMA]) 294 REPLACE_EXPM1=0; AC_SUBST([REPLACE_EXPM1])
273 REPLACE_FMAF=0; AC_SUBST([REPLACE_FMAF]) 295 REPLACE_EXPM1F=0; AC_SUBST([REPLACE_EXPM1F])
274 REPLACE_FMAL=0; AC_SUBST([REPLACE_FMAL]) 296 REPLACE_EXPM1L=0; AC_SUBST([REPLACE_EXPM1L])
275 REPLACE_FMOD=0; AC_SUBST([REPLACE_FMOD]) 297 REPLACE_EXP2=0; AC_SUBST([REPLACE_EXP2])
276 REPLACE_FMODF=0; AC_SUBST([REPLACE_FMODF]) 298 REPLACE_EXP2L=0; AC_SUBST([REPLACE_EXP2L])
277 REPLACE_FMODL=0; AC_SUBST([REPLACE_FMODL]) 299 REPLACE_FABSL=0; AC_SUBST([REPLACE_FABSL])
278 REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF]) 300 REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR])
279 REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP]) 301 REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF])
280 REPLACE_FREXPL=0; AC_SUBST([REPLACE_FREXPL]) 302 REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL])
281 REPLACE_HUGE_VAL=0; AC_SUBST([REPLACE_HUGE_VAL]) 303 REPLACE_FMA=0; AC_SUBST([REPLACE_FMA])
282 REPLACE_HYPOT=0; AC_SUBST([REPLACE_HYPOT]) 304 REPLACE_FMAF=0; AC_SUBST([REPLACE_FMAF])
283 REPLACE_HYPOTF=0; AC_SUBST([REPLACE_HYPOTF]) 305 REPLACE_FMAL=0; AC_SUBST([REPLACE_FMAL])
284 REPLACE_HYPOTL=0; AC_SUBST([REPLACE_HYPOTL]) 306 REPLACE_FMOD=0; AC_SUBST([REPLACE_FMOD])
285 REPLACE_ILOGB=0; AC_SUBST([REPLACE_ILOGB]) 307 REPLACE_FMODF=0; AC_SUBST([REPLACE_FMODF])
286 REPLACE_ILOGBF=0; AC_SUBST([REPLACE_ILOGBF]) 308 REPLACE_FMODL=0; AC_SUBST([REPLACE_FMODL])
287 REPLACE_ISFINITE=0; AC_SUBST([REPLACE_ISFINITE]) 309 REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF])
288 REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF]) 310 REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP])
289 REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) 311 REPLACE_FREXPL=0; AC_SUBST([REPLACE_FREXPL])
290 REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL]) 312 REPLACE_HUGE_VAL=0; AC_SUBST([REPLACE_HUGE_VAL])
291 REPLACE_LOG=0; AC_SUBST([REPLACE_LOG]) 313 REPLACE_HYPOT=0; AC_SUBST([REPLACE_HYPOT])
292 REPLACE_LOGF=0; AC_SUBST([REPLACE_LOGF]) 314 REPLACE_HYPOTF=0; AC_SUBST([REPLACE_HYPOTF])
293 REPLACE_LOGL=0; AC_SUBST([REPLACE_LOGL]) 315 REPLACE_HYPOTL=0; AC_SUBST([REPLACE_HYPOTL])
294 REPLACE_LOG10=0; AC_SUBST([REPLACE_LOG10]) 316 REPLACE_ILOGB=0; AC_SUBST([REPLACE_ILOGB])
295 REPLACE_LOG10F=0; AC_SUBST([REPLACE_LOG10F]) 317 REPLACE_ILOGBF=0; AC_SUBST([REPLACE_ILOGBF])
296 REPLACE_LOG10L=0; AC_SUBST([REPLACE_LOG10L]) 318 REPLACE_ILOGBL=0; AC_SUBST([REPLACE_ILOGBL])
297 REPLACE_LOG1P=0; AC_SUBST([REPLACE_LOG1P]) 319 REPLACE_ISFINITE=0; AC_SUBST([REPLACE_ISFINITE])
298 REPLACE_LOG1PF=0; AC_SUBST([REPLACE_LOG1PF]) 320 REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF])
299 REPLACE_LOG1PL=0; AC_SUBST([REPLACE_LOG1PL]) 321 REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN])
300 REPLACE_LOG2=0; AC_SUBST([REPLACE_LOG2]) 322 REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL])
301 REPLACE_LOG2F=0; AC_SUBST([REPLACE_LOG2F]) 323 REPLACE_LOG=0; AC_SUBST([REPLACE_LOG])
302 REPLACE_LOG2L=0; AC_SUBST([REPLACE_LOG2L]) 324 REPLACE_LOGF=0; AC_SUBST([REPLACE_LOGF])
303 REPLACE_LOGB=0; AC_SUBST([REPLACE_LOGB]) 325 REPLACE_LOGL=0; AC_SUBST([REPLACE_LOGL])
304 REPLACE_LOGBF=0; AC_SUBST([REPLACE_LOGBF]) 326 REPLACE_LOG10=0; AC_SUBST([REPLACE_LOG10])
305 REPLACE_LOGBL=0; AC_SUBST([REPLACE_LOGBL]) 327 REPLACE_LOG10F=0; AC_SUBST([REPLACE_LOG10F])
306 REPLACE_MODF=0; AC_SUBST([REPLACE_MODF]) 328 REPLACE_LOG10L=0; AC_SUBST([REPLACE_LOG10L])
307 REPLACE_MODFF=0; AC_SUBST([REPLACE_MODFF]) 329 REPLACE_LOG1P=0; AC_SUBST([REPLACE_LOG1P])
308 REPLACE_MODFL=0; AC_SUBST([REPLACE_MODFL]) 330 REPLACE_LOG1PF=0; AC_SUBST([REPLACE_LOG1PF])
309 REPLACE_NAN=0; AC_SUBST([REPLACE_NAN]) 331 REPLACE_LOG1PL=0; AC_SUBST([REPLACE_LOG1PL])
310 REPLACE_REMAINDER=0; AC_SUBST([REPLACE_REMAINDER]) 332 REPLACE_LOG2=0; AC_SUBST([REPLACE_LOG2])
311 REPLACE_REMAINDERF=0; AC_SUBST([REPLACE_REMAINDERF]) 333 REPLACE_LOG2F=0; AC_SUBST([REPLACE_LOG2F])
312 REPLACE_REMAINDERL=0; AC_SUBST([REPLACE_REMAINDERL]) 334 REPLACE_LOG2L=0; AC_SUBST([REPLACE_LOG2L])
313 REPLACE_ROUND=0; AC_SUBST([REPLACE_ROUND]) 335 REPLACE_LOGB=0; AC_SUBST([REPLACE_LOGB])
314 REPLACE_ROUNDF=0; AC_SUBST([REPLACE_ROUNDF]) 336 REPLACE_LOGBF=0; AC_SUBST([REPLACE_LOGBF])
315 REPLACE_ROUNDL=0; AC_SUBST([REPLACE_ROUNDL]) 337 REPLACE_LOGBL=0; AC_SUBST([REPLACE_LOGBL])
316 REPLACE_SIGNBIT=0; AC_SUBST([REPLACE_SIGNBIT]) 338 REPLACE_MODF=0; AC_SUBST([REPLACE_MODF])
317 REPLACE_SIGNBIT_USING_GCC=0; AC_SUBST([REPLACE_SIGNBIT_USING_GCC]) 339 REPLACE_MODFF=0; AC_SUBST([REPLACE_MODFF])
318 REPLACE_SQRTL=0; AC_SUBST([REPLACE_SQRTL]) 340 REPLACE_MODFL=0; AC_SUBST([REPLACE_MODFL])
319 REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC]) 341 REPLACE_NAN=0; AC_SUBST([REPLACE_NAN])
320 REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF]) 342 REPLACE_REMAINDER=0; AC_SUBST([REPLACE_REMAINDER])
321 REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL]) 343 REPLACE_REMAINDERF=0; AC_SUBST([REPLACE_REMAINDERF])
344 REPLACE_REMAINDERL=0; AC_SUBST([REPLACE_REMAINDERL])
345 REPLACE_RINTL=0; AC_SUBST([REPLACE_RINTL])
346 REPLACE_ROUND=0; AC_SUBST([REPLACE_ROUND])
347 REPLACE_ROUNDF=0; AC_SUBST([REPLACE_ROUNDF])
348 REPLACE_ROUNDL=0; AC_SUBST([REPLACE_ROUNDL])
349 REPLACE_SIGNBIT=0; AC_SUBST([REPLACE_SIGNBIT])
350 REPLACE_SIGNBIT_USING_BUILTINS=0; AC_SUBST([REPLACE_SIGNBIT_USING_BUILTINS])
351 REPLACE_SINF=0; AC_SUBST([REPLACE_SINF])
352 REPLACE_SINHF=0; AC_SUBST([REPLACE_SINHF])
353 REPLACE_SQRTF=0; AC_SUBST([REPLACE_SQRTF])
354 REPLACE_SQRTL=0; AC_SUBST([REPLACE_SQRTL])
355 REPLACE_TANF=0; AC_SUBST([REPLACE_TANF])
356 REPLACE_TANHF=0; AC_SUBST([REPLACE_TANHF])
357 REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC])
358 REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF])
359 REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL])
322]) 360])
323 361
324# gl_LONG_DOUBLE_VS_DOUBLE 362# gl_LONG_DOUBLE_VS_DOUBLE
diff --git a/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4
index 4c9f388..bb39304 100644
--- a/gl/m4/mbrtowc.m4
+++ b/gl/m4/mbrtowc.m4
@@ -1,5 +1,5 @@
1# mbrtowc.m4 serial 25 1# mbrtowc.m4 serial 38 -*- coding: utf-8 -*-
2dnl Copyright (C) 2001-2002, 2004-2005, 2008-2013 Free Software Foundation, 2dnl Copyright (C) 2001-2002, 2004-2005, 2008-2023 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,8 @@ dnl with or without modifications, as long as this notice is preserved.
8AC_DEFUN([gl_FUNC_MBRTOWC], 8AC_DEFUN([gl_FUNC_MBRTOWC],
9[ 9[
10 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 10 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([gl_PTHREADLIB])
12 AC_CHECK_HEADERS_ONCE([threads.h])
11 13
12 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 14 AC_REQUIRE([AC_TYPE_MBSTATE_T])
13 gl_MBSTATE_T_BROKEN 15 gl_MBSTATE_T_BROKEN
@@ -16,15 +18,8 @@ AC_DEFUN([gl_FUNC_MBRTOWC],
16 if test $ac_cv_func_mbrtowc = no; then 18 if test $ac_cv_func_mbrtowc = no; then
17 HAVE_MBRTOWC=0 19 HAVE_MBRTOWC=0
18 AC_CHECK_DECLS([mbrtowc],,, [[ 20 AC_CHECK_DECLS([mbrtowc],,, [[
19/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 21 #include <wchar.h>
20 <wchar.h>. 22 ]])
21 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
22 included before <wchar.h>. */
23#include <stddef.h>
24#include <stdio.h>
25#include <time.h>
26#include <wchar.h>
27]])
28 if test $ac_cv_have_decl_mbrtowc = yes; then 23 if test $ac_cv_have_decl_mbrtowc = yes; then
29 dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although 24 dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although
30 dnl it does not have the function. Avoid a collision with gnulib's 25 dnl it does not have the function. Avoid a collision with gnulib's
@@ -39,6 +34,9 @@ AC_DEFUN([gl_FUNC_MBRTOWC],
39 gl_MBRTOWC_NULL_ARG2 34 gl_MBRTOWC_NULL_ARG2
40 gl_MBRTOWC_RETVAL 35 gl_MBRTOWC_RETVAL
41 gl_MBRTOWC_NUL_RETVAL 36 gl_MBRTOWC_NUL_RETVAL
37 gl_MBRTOWC_STORES_INCOMPLETE
38 gl_MBRTOWC_EMPTY_INPUT
39 gl_MBRTOWC_C_LOCALE
42 case "$gl_cv_func_mbrtowc_null_arg1" in 40 case "$gl_cv_func_mbrtowc_null_arg1" in
43 *yes) ;; 41 *yes) ;;
44 *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1], 42 *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1],
@@ -67,8 +65,47 @@ AC_DEFUN([gl_FUNC_MBRTOWC],
67 REPLACE_MBRTOWC=1 65 REPLACE_MBRTOWC=1
68 ;; 66 ;;
69 esac 67 esac
68 case "$gl_cv_func_mbrtowc_stores_incomplete" in
69 *no) ;;
70 *) AC_DEFINE([MBRTOWC_STORES_INCOMPLETE_BUG], [1],
71 [Define if the mbrtowc function stores a wide character when reporting incomplete input.])
72 REPLACE_MBRTOWC=1
73 ;;
74 esac
75 case "$gl_cv_func_mbrtowc_empty_input" in
76 *yes) ;;
77 *) AC_DEFINE([MBRTOWC_EMPTY_INPUT_BUG], [1],
78 [Define if the mbrtowc function does not return (size_t) -2
79 for empty input.])
80 REPLACE_MBRTOWC=1
81 ;;
82 esac
83 case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
84 *yes) ;;
85 *) AC_DEFINE([MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ], [1],
86 [Define if the mbrtowc function may signal encoding errors in the C locale.])
87 REPLACE_MBRTOWC=1
88 ;;
89 esac
70 fi 90 fi
71 fi 91 fi
92 if test $REPLACE_MBSTATE_T = 1; then
93 case "$host_os" in
94 mingw*) LIB_MBRTOWC= ;;
95 *)
96 gl_WEAK_SYMBOLS
97 case "$gl_cv_have_weak" in
98 *yes) LIB_MBRTOWC= ;;
99 *) LIB_MBRTOWC="$LIBPTHREAD" ;;
100 esac
101 ;;
102 esac
103 else
104 LIB_MBRTOWC=
105 fi
106 dnl LIB_MBRTOWC is expected to be '-pthread' or '-lpthread' on AIX
107 dnl with gcc or xlc, and empty otherwise.
108 AC_SUBST([LIB_MBRTOWC])
72]) 109])
73 110
74dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that 111dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
@@ -80,11 +117,19 @@ dnl avoid inconsistencies.
80AC_DEFUN([gl_MBSTATE_T_BROKEN], 117AC_DEFUN([gl_MBSTATE_T_BROKEN],
81[ 118[
82 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 119 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
120 AC_REQUIRE([AC_CANONICAL_HOST])
83 121
84 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 122 AC_REQUIRE([AC_TYPE_MBSTATE_T])
85 AC_CHECK_FUNCS_ONCE([mbsinit]) 123 AC_CHECK_FUNCS_ONCE([mbsinit])
86 AC_CHECK_FUNCS_ONCE([mbrtowc]) 124 AC_CHECK_FUNCS_ONCE([mbrtowc])
87 if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then 125 dnl On native Windows, we know exactly how mbsinit() behaves and don't need
126 dnl to override it, even if - like on MSVC - mbsinit() is only defined as
127 dnl an inline function, not as a global function.
128 if case "$host_os" in
129 mingw*) true ;;
130 *) test $ac_cv_func_mbsinit = yes ;;
131 esac \
132 && test $ac_cv_func_mbrtowc = yes; then
88 gl_MBRTOWC_INCOMPLETE_STATE 133 gl_MBRTOWC_INCOMPLETE_STATE
89 gl_MBRTOWC_SANITYCHECK 134 gl_MBRTOWC_SANITYCHECK
90 REPLACE_MBSTATE_T=0 135 REPLACE_MBSTATE_T=0
@@ -109,6 +154,7 @@ AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
109[ 154[
110 AC_REQUIRE([AC_PROG_CC]) 155 AC_REQUIRE([AC_PROG_CC])
111 AC_REQUIRE([gt_LOCALE_JA]) 156 AC_REQUIRE([gt_LOCALE_JA])
157 AC_REQUIRE([gt_LOCALE_FR_UTF8])
112 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 158 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
113 AC_CACHE_CHECK([whether mbrtowc handles incomplete characters], 159 AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
114 [gl_cv_func_mbrtowc_incomplete_state], 160 [gl_cv_func_mbrtowc_incomplete_state],
@@ -128,13 +174,6 @@ changequote([,])dnl
128 [AC_LANG_SOURCE([[ 174 [AC_LANG_SOURCE([[
129#include <locale.h> 175#include <locale.h>
130#include <string.h> 176#include <string.h>
131/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
132 <wchar.h>.
133 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
134 included before <wchar.h>. */
135#include <stddef.h>
136#include <stdio.h>
137#include <time.h>
138#include <wchar.h> 177#include <wchar.h>
139int main () 178int main ()
140{ 179{
@@ -147,13 +186,39 @@ int main ()
147 memset (&state, '\0', sizeof (mbstate_t)); 186 memset (&state, '\0', sizeof (mbstate_t));
148 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) 187 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
149 if (mbsinit (&state)) 188 if (mbsinit (&state))
150 return 1; 189 return 2;
190 }
191 return 0;
192}]])],
193 [gl_cv_func_mbrtowc_incomplete_state=yes],
194 [gl_cv_func_mbrtowc_incomplete_state=no],
195 [:])
196 else
197 if test $LOCALE_FR_UTF8 != none; then
198 AC_RUN_IFELSE(
199 [AC_LANG_SOURCE([[
200#include <locale.h>
201#include <string.h>
202#include <wchar.h>
203int main ()
204{
205 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
206 {
207 const char input[] = "B\303\274\303\237er"; /* "Büßer" */
208 mbstate_t state;
209 wchar_t wc;
210
211 memset (&state, '\0', sizeof (mbstate_t));
212 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
213 if (mbsinit (&state))
214 return 2;
151 } 215 }
152 return 0; 216 return 0;
153}]])], 217}]])],
154 [gl_cv_func_mbrtowc_incomplete_state=yes], 218 [gl_cv_func_mbrtowc_incomplete_state=yes],
155 [gl_cv_func_mbrtowc_incomplete_state=no], 219 [gl_cv_func_mbrtowc_incomplete_state=no],
156 [:]) 220 [:])
221 fi
157 fi 222 fi
158 ]) 223 ])
159]) 224])
@@ -185,13 +250,6 @@ changequote([,])dnl
185#include <locale.h> 250#include <locale.h>
186#include <stdlib.h> 251#include <stdlib.h>
187#include <string.h> 252#include <string.h>
188/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
189 <wchar.h>.
190 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
191 included before <wchar.h>. */
192#include <stddef.h>
193#include <stdio.h>
194#include <time.h>
195#include <wchar.h> 253#include <wchar.h>
196int main () 254int main ()
197{ 255{
@@ -207,7 +265,7 @@ int main ()
207 memset (&state, '\0', sizeof (mbstate_t)); 265 memset (&state, '\0', sizeof (mbstate_t));
208 if (mbrtowc (&wc, input + 3, 6, &state) != 4 266 if (mbrtowc (&wc, input + 3, 6, &state) != 4
209 && mbtowc (&wc, input + 3, 6) == 4) 267 && mbtowc (&wc, input + 3, 6) == 4)
210 return 1; 268 return 2;
211 } 269 }
212 return 0; 270 return 0;
213}]])], 271}]])],
@@ -245,13 +303,6 @@ changequote([,])dnl
245#include <locale.h> 303#include <locale.h>
246#include <stdlib.h> 304#include <stdlib.h>
247#include <string.h> 305#include <string.h>
248/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
249 <wchar.h>.
250 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
251 included before <wchar.h>. */
252#include <stddef.h>
253#include <stdio.h>
254#include <time.h>
255#include <wchar.h> 306#include <wchar.h>
256int main () 307int main ()
257{ 308{
@@ -314,13 +365,6 @@ changequote([,])dnl
314 [AC_LANG_SOURCE([[ 365 [AC_LANG_SOURCE([[
315#include <locale.h> 366#include <locale.h>
316#include <string.h> 367#include <string.h>
317/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
318 <wchar.h>.
319 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
320 included before <wchar.h>. */
321#include <stddef.h>
322#include <stdio.h>
323#include <time.h>
324#include <wchar.h> 368#include <wchar.h>
325int main () 369int main ()
326{ 370{
@@ -335,7 +379,7 @@ int main ()
335 mbrtowc (&wc, NULL, 5, &state); 379 mbrtowc (&wc, NULL, 5, &state);
336 /* Check that wc was not modified. */ 380 /* Check that wc was not modified. */
337 if (wc != (wchar_t) 0xBADFACE) 381 if (wc != (wchar_t) 0xBADFACE)
338 return 1; 382 return 2;
339 } 383 }
340 return 0; 384 return 0;
341}]])], 385}]])],
@@ -376,13 +420,6 @@ changequote([,])dnl
376 [AC_LANG_SOURCE([[ 420 [AC_LANG_SOURCE([[
377#include <locale.h> 421#include <locale.h>
378#include <string.h> 422#include <string.h>
379/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
380 <wchar.h>.
381 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
382 included before <wchar.h>. */
383#include <stddef.h>
384#include <stdio.h>
385#include <time.h>
386#include <wchar.h> 423#include <wchar.h>
387int main () 424int main ()
388{ 425{
@@ -504,13 +541,6 @@ changequote([,])dnl
504 [AC_LANG_SOURCE([[ 541 [AC_LANG_SOURCE([[
505#include <locale.h> 542#include <locale.h>
506#include <string.h> 543#include <string.h>
507/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
508 <wchar.h>.
509 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
510 included before <wchar.h>. */
511#include <stddef.h>
512#include <stdio.h>
513#include <time.h>
514#include <wchar.h> 544#include <wchar.h>
515int main () 545int main ()
516{ 546{
@@ -522,7 +552,7 @@ int main ()
522 552
523 memset (&state, '\0', sizeof (mbstate_t)); 553 memset (&state, '\0', sizeof (mbstate_t));
524 if (mbrtowc (&wc, "", 1, &state) != 0) 554 if (mbrtowc (&wc, "", 1, &state) != 0)
525 return 1; 555 return 2;
526 } 556 }
527 return 0; 557 return 0;
528}]])], 558}]])],
@@ -533,11 +563,206 @@ int main ()
533 ]) 563 ])
534]) 564])
535 565
536# Prerequisites of lib/mbrtowc.c. 566dnl Test whether mbrtowc stores a wide character when reporting incomplete
567dnl input.
568
569AC_DEFUN([gl_MBRTOWC_STORES_INCOMPLETE],
570[
571 AC_REQUIRE([AC_PROG_CC])
572 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
573 AC_CACHE_CHECK([whether mbrtowc stores incomplete characters],
574 [gl_cv_func_mbrtowc_stores_incomplete],
575 [
576 dnl Initial guess, used when cross-compiling or when no suitable locale
577 dnl is present.
578changequote(,)dnl
579 case "$host_os" in
580 # Guess yes on native Windows.
581 mingw*) gl_cv_func_mbrtowc_stores_incomplete="guessing yes" ;;
582 *) gl_cv_func_mbrtowc_stores_incomplete="guessing no" ;;
583 esac
584changequote([,])dnl
585 case "$host_os" in
586 mingw*)
587 AC_RUN_IFELSE(
588 [AC_LANG_SOURCE([[
589#include <locale.h>
590#include <string.h>
591#include <wchar.h>
592int main ()
593{
594 int result = 0;
595 if (setlocale (LC_ALL, "French_France.65001") != NULL)
596 {
597 wchar_t wc = (wchar_t) 0xBADFACE;
598 mbstate_t state;
599
600 memset (&state, '\0', sizeof (mbstate_t));
601 if (mbrtowc (&wc, "\303", 1, &state) == (size_t)(-2)
602 && wc != (wchar_t) 0xBADFACE)
603 result |= 1;
604 }
605 if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL)
606 {
607 wchar_t wc = (wchar_t) 0xBADFACE;
608 mbstate_t state;
609
610 memset (&state, '\0', sizeof (mbstate_t));
611 if (mbrtowc (&wc, "\226", 1, &state) == (size_t)(-2)
612 && wc != (wchar_t) 0xBADFACE)
613 result |= 2;
614 }
615 if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL)
616 {
617 wchar_t wc = (wchar_t) 0xBADFACE;
618 mbstate_t state;
619
620 memset (&state, '\0', sizeof (mbstate_t));
621 if (mbrtowc (&wc, "\245", 1, &state) == (size_t)(-2)
622 && wc != (wchar_t) 0xBADFACE)
623 result |= 4;
624 }
625 if (setlocale (LC_ALL, "Chinese_China.936") != NULL)
626 {
627 wchar_t wc = (wchar_t) 0xBADFACE;
628 mbstate_t state;
629
630 memset (&state, '\0', sizeof (mbstate_t));
631 if (mbrtowc (&wc, "\261", 1, &state) == (size_t)(-2)
632 && wc != (wchar_t) 0xBADFACE)
633 result |= 8;
634 }
635 return result;
636}]])],
637 [gl_cv_func_mbrtowc_stores_incomplete=no],
638 [gl_cv_func_mbrtowc_stores_incomplete=yes],
639 [:])
640 ;;
641 *)
642 AC_REQUIRE([gt_LOCALE_FR_UTF8])
643 if test $LOCALE_FR_UTF8 != none; then
644 AC_RUN_IFELSE(
645 [AC_LANG_SOURCE([[
646#include <locale.h>
647#include <string.h>
648#include <wchar.h>
649int main ()
650{
651 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
652 {
653 wchar_t wc = (wchar_t) 0xBADFACE;
654 mbstate_t state;
655
656 memset (&state, '\0', sizeof (mbstate_t));
657 if (mbrtowc (&wc, "\303", 1, &state) == (size_t)(-2)
658 && wc != (wchar_t) 0xBADFACE)
659 return 1;
660 }
661 return 0;
662}]])],
663 [gl_cv_func_mbrtowc_stores_incomplete=no],
664 [gl_cv_func_mbrtowc_stores_incomplete=yes],
665 [:])
666 fi
667 ;;
668 esac
669 ])
670])
671
672dnl Test whether mbrtowc returns the correct value on empty input.
673
674AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT],
675[
676 AC_REQUIRE([AC_PROG_CC])
677 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
678 AC_CACHE_CHECK([whether mbrtowc works on empty input],
679 [gl_cv_func_mbrtowc_empty_input],
680 [
681 dnl Initial guess, used when cross-compiling or when no suitable locale
682 dnl is present.
683changequote(,)dnl
684 case "$host_os" in
685 # Guess no on AIX and glibc systems.
686 aix* | *-gnu* | gnu*) gl_cv_func_mbrtowc_empty_input="guessing no" ;;
687 # Guess yes on native Windows.
688 mingw*) gl_cv_func_mbrtowc_empty_input="guessing yes" ;;
689 *) gl_cv_func_mbrtowc_empty_input="guessing yes" ;;
690 esac
691changequote([,])dnl
692 AC_RUN_IFELSE(
693 [AC_LANG_SOURCE([[
694 #include <wchar.h>
695 static wchar_t wc;
696 static mbstate_t mbs;
697 int
698 main (void)
699 {
700 return mbrtowc (&wc, "", 0, &mbs) != (size_t) -2;
701 }]])],
702 [gl_cv_func_mbrtowc_empty_input=yes],
703 [gl_cv_func_mbrtowc_empty_input=no],
704 [:])
705 ])
706])
707
708dnl Test whether mbrtowc reports encoding errors in the C locale.
709dnl Although POSIX was never intended to allow this, the GNU C Library
710dnl and other implementations do it. See:
711dnl https://sourceware.org/bugzilla/show_bug.cgi?id=19932
712
713AC_DEFUN([gl_MBRTOWC_C_LOCALE],
714[
715 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
716 AC_CACHE_CHECK([whether the C locale is free of encoding errors],
717 [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ],
718 [
719 dnl Initial guess, used when cross-compiling or when no suitable locale
720 dnl is present.
721 gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="$gl_cross_guess_normal"
722
723 AC_RUN_IFELSE(
724 [AC_LANG_PROGRAM(
725 [[#include <limits.h>
726 #include <locale.h>
727 #include <wchar.h>
728 ]], [[
729 int i;
730 char *locale = setlocale (LC_ALL, "C");
731 if (! locale)
732 return 2;
733 for (i = CHAR_MIN; i <= CHAR_MAX; i++)
734 {
735 char c = i;
736 wchar_t wc;
737 mbstate_t mbs = { 0, };
738 size_t ss = mbrtowc (&wc, &c, 1, &mbs);
739 if (1 < ss)
740 return 3;
741 }
742 return 0;
743 ]])],
744 [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=yes],
745 [gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=no],
746 [case "$host_os" in
747 # Guess yes on native Windows.
748 mingw*) gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="guessing yes" ;;
749 esac
750 ])
751 ])
752])
753
754# Prerequisites of lib/mbrtowc.c and lib/lc-charset-dispatch.c.
537AC_DEFUN([gl_PREREQ_MBRTOWC], [ 755AC_DEFUN([gl_PREREQ_MBRTOWC], [
756 AC_REQUIRE([AC_C_INLINE])
538 : 757 :
539]) 758])
540 759
760# Prerequisites of lib/mbtowc-lock.c.
761AC_DEFUN([gl_PREREQ_MBTOWC_LOCK],
762[
763 gl_VISIBILITY
764])
765
541 766
542dnl From Paul Eggert 767dnl From Paul Eggert
543 768
@@ -547,24 +772,17 @@ AC_DEFUN([AC_FUNC_MBRTOWC],
547[ 772[
548 dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. 773 dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
549 AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], 774 AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
550 gl_cv_func_mbrtowc, 775 [gl_cv_func_mbrtowc],
551 [AC_LINK_IFELSE( 776 [AC_LINK_IFELSE(
552 [AC_LANG_PROGRAM( 777 [AC_LANG_PROGRAM(
553 [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be 778 [[#include <wchar.h>]],
554 included before <wchar.h>.
555 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
556 must be included before <wchar.h>. */
557 #include <stddef.h>
558 #include <stdio.h>
559 #include <time.h>
560 #include <wchar.h>]],
561 [[wchar_t wc; 779 [[wchar_t wc;
562 char const s[] = ""; 780 char const s[] = "";
563 size_t n = 1; 781 size_t n = 1;
564 mbstate_t state; 782 mbstate_t state;
565 return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], 783 return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
566 gl_cv_func_mbrtowc=yes, 784 [gl_cv_func_mbrtowc=yes],
567 gl_cv_func_mbrtowc=no)]) 785 [gl_cv_func_mbrtowc=no])])
568 if test $gl_cv_func_mbrtowc = yes; then 786 if test $gl_cv_func_mbrtowc = yes; then
569 AC_DEFINE([HAVE_MBRTOWC], [1], 787 AC_DEFINE([HAVE_MBRTOWC], [1],
570 [Define to 1 if mbrtowc and mbstate_t are properly declared.]) 788 [Define to 1 if mbrtowc and mbstate_t are properly declared.])
diff --git a/gl/m4/mbsinit.m4 b/gl/m4/mbsinit.m4
index 2e6d092..c388a8b 100644
--- a/gl/m4/mbsinit.m4
+++ b/gl/m4/mbsinit.m4
@@ -1,5 +1,5 @@
1# mbsinit.m4 serial 8 1# mbsinit.m4 serial 9
2dnl Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2010-2023 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,15 +16,8 @@ AC_DEFUN([gl_FUNC_MBSINIT],
16 if test $ac_cv_func_mbsinit = no; then 16 if test $ac_cv_func_mbsinit = no; then
17 HAVE_MBSINIT=0 17 HAVE_MBSINIT=0
18 AC_CHECK_DECLS([mbsinit],,, [[ 18 AC_CHECK_DECLS([mbsinit],,, [[
19/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 19 #include <wchar.h>
20 <wchar.h>. 20 ]])
21 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
22 included before <wchar.h>. */
23#include <stddef.h>
24#include <stdio.h>
25#include <time.h>
26#include <wchar.h>
27]])
28 if test $ac_cv_have_decl_mbsinit = yes; then 21 if test $ac_cv_have_decl_mbsinit = yes; then
29 dnl On Minix 3.1.8, the system's <wchar.h> declares mbsinit() although 22 dnl On Minix 3.1.8, the system's <wchar.h> declares mbsinit() although
30 dnl it does not have the function. Avoid a collision with gnulib's 23 dnl it does not have the function. Avoid a collision with gnulib's
diff --git a/gl/m4/mbstate_t.m4 b/gl/m4/mbstate_t.m4
index ed00117..dcd66b9 100644
--- a/gl/m4/mbstate_t.m4
+++ b/gl/m4/mbstate_t.m4
@@ -1,5 +1,5 @@
1# mbstate_t.m4 serial 13 1# mbstate_t.m4 serial 14
2dnl Copyright (C) 2000-2002, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -20,14 +20,7 @@ AC_DEFUN([AC_TYPE_MBSTATE_T],
20 [AC_COMPILE_IFELSE( 20 [AC_COMPILE_IFELSE(
21 [AC_LANG_PROGRAM( 21 [AC_LANG_PROGRAM(
22 [AC_INCLUDES_DEFAULT[ 22 [AC_INCLUDES_DEFAULT[
23/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 23 #include <wchar.h>]],
24 <wchar.h>.
25 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
26 included before <wchar.h>. */
27#include <stddef.h>
28#include <stdio.h>
29#include <time.h>
30#include <wchar.h>]],
31 [[mbstate_t x; return sizeof x;]])], 24 [[mbstate_t x; return sizeof x;]])],
32 [ac_cv_type_mbstate_t=yes], 25 [ac_cv_type_mbstate_t=yes],
33 [ac_cv_type_mbstate_t=no])]) 26 [ac_cv_type_mbstate_t=no])])
diff --git a/gl/m4/mbtowc.m4 b/gl/m4/mbtowc.m4
index e479461..7823be0 100644
--- a/gl/m4/mbtowc.m4
+++ b/gl/m4/mbtowc.m4
@@ -1,5 +1,5 @@
1# mbtowc.m4 serial 2 1# mbtowc.m4 serial 3
2dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2011-2023 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,8 +8,13 @@ AC_DEFUN([gl_FUNC_MBTOWC],
8[ 8[
9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10 10
11 if false; then 11 AC_CHECK_FUNCS([mbtowc])
12 REPLACE_MBTOWC=1 12 if test $ac_cv_func_mbtowc = no; then
13 HAVE_MBTOWC=0
14 else
15 if false; then
16 REPLACE_MBTOWC=1
17 fi
13 fi 18 fi
14]) 19])
15 20
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4
index 2d8abe7..4f1aed0 100644
--- a/gl/m4/memchr.m4
+++ b/gl/m4/memchr.m4
@@ -1,35 +1,30 @@
1# memchr.m4 serial 12 1# memchr.m4 serial 18
2dnl Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2009-2023 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_ONCE([gl_FUNC_MEMCHR], 7AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
8[ 8[
9 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
10
9 dnl Check for prerequisites for memory fence checks. 11 dnl Check for prerequisites for memory fence checks.
10 gl_FUNC_MMAP_ANON 12 gl_FUNC_MMAP_ANON
11 AC_CHECK_HEADERS_ONCE([sys/mman.h]) 13 AC_CHECK_HEADERS_ONCE([sys/mman.h])
12 AC_CHECK_FUNCS_ONCE([mprotect]) 14 AC_CHECK_FUNCS_ONCE([mprotect])
13 15
14 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 16 AC_REQUIRE([gl_STRING_H_DEFAULTS])
15 m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [ 17 # Detect platform-specific bugs in some versions of glibc:
16 dnl These days, we assume memchr is present. But if support for old 18 # memchr should not dereference anything with length 0
17 dnl platforms is desired: 19 # https://bugzilla.redhat.com/show_bug.cgi?id=499689
18 AC_CHECK_FUNCS_ONCE([memchr]) 20 # memchr should not dereference overestimated length after a match
19 if test $ac_cv_func_memchr = no; then 21 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
20 HAVE_MEMCHR=0 22 # https://sourceware.org/bugzilla/show_bug.cgi?id=10162
21 fi 23 # memchr should cast the second argument to 'unsigned char'.
22 ]) 24 # This bug exists in Android 4.3.
23 if test $HAVE_MEMCHR = 1; then 25 # Assume that memchr works on platforms that lack mprotect.
24 # Detect platform-specific bugs in some versions of glibc: 26 AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
25 # memchr should not dereference anything with length 0 27 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
26 # http://bugzilla.redhat.com/499689
27 # memchr should not dereference overestimated length after a match
28 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
29 # http://sourceware.org/bugzilla/show_bug.cgi?id=10162
30 # Assume that memchr works on platforms that lack mprotect.
31 AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
32 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
33#include <string.h> 28#include <string.h>
34#if HAVE_SYS_MMAN_H 29#if HAVE_SYS_MMAN_H
35# include <fcntl.h> 30# include <fcntl.h>
@@ -64,6 +59,7 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
64#endif 59#endif
65 if (fence) 60 if (fence)
66 { 61 {
62 /* Test against bugs on glibc systems. */
67 if (memchr (fence, 0, 0)) 63 if (memchr (fence, 0, 0))
68 result |= 1; 64 result |= 1;
69 strcpy (fence - 9, "12345678"); 65 strcpy (fence - 9, "12345678");
@@ -71,15 +67,37 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
71 result |= 2; 67 result |= 2;
72 if (memchr (fence - 1, 0, 3) != fence - 1) 68 if (memchr (fence - 1, 0, 3) != fence - 1)
73 result |= 4; 69 result |= 4;
70 /* Test against bug on AIX 7.2. */
71 if (memchr (fence - 4, '6', 16) != fence - 4)
72 result |= 8;
74 } 73 }
74 /* Test against bug on Android 4.3. */
75 {
76 char input[3];
77 input[0] = 'a';
78 input[1] = 'b';
79 input[2] = 'c';
80 if (memchr (input, 0x789abc00 | 'b', 3) != input + 1)
81 result |= 16;
82 }
75 return result; 83 return result;
76]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], 84]])],
77 [dnl Be pessimistic for now. 85 [gl_cv_func_memchr_works=yes],
78 gl_cv_func_memchr_works="guessing no"])]) 86 [gl_cv_func_memchr_works=no],
79 if test "$gl_cv_func_memchr_works" != yes; then 87 [case "$host_os" in
80 REPLACE_MEMCHR=1 88 # Guess no on Android.
81 fi 89 linux*-android*) gl_cv_func_memchr_works="guessing no" ;;
82 fi 90 # Guess yes on native Windows.
91 mingw*) gl_cv_func_memchr_works="guessing yes" ;;
92 # If we don't know, obey --enable-cross-guesses.
93 *) gl_cv_func_memchr_works="$gl_cross_guess_normal" ;;
94 esac
95 ])
96 ])
97 case "$gl_cv_func_memchr_works" in
98 *yes) ;;
99 *) REPLACE_MEMCHR=1 ;;
100 esac
83]) 101])
84 102
85# Prerequisites of lib/memchr.c. 103# Prerequisites of lib/memchr.c.
diff --git a/gl/m4/minmax.m4 b/gl/m4/minmax.m4
new file mode 100644
index 0000000..fd09846
--- /dev/null
+++ b/gl/m4/minmax.m4
@@ -0,0 +1,44 @@
1# minmax.m4 serial 4
2dnl Copyright (C) 2005, 2009-2023 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.53])
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_COMPILE_IFELSE(
32 [AC_LANG_PROGRAM(
33 [[#include <$1>
34 int x = MIN (42, 17);]],
35 [[]])],
36 [gl_cv_minmax_in_]header[=yes],
37 [gl_cv_minmax_in_]header[=no])])
38 if test $gl_cv_minmax_in_[]header = yes; then
39 AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
40 [Define to 1 if <$1> defines the MIN and MAX macros.])
41 fi
42 m4_popdef([HEADER])
43 m4_popdef([header])
44])
diff --git a/gl/m4/mktime.m4 b/gl/m4/mktime.m4
index faefb77..e9d31f3 100644
--- a/gl/m4/mktime.m4
+++ b/gl/m4/mktime.m4
@@ -1,5 +1,5 @@
1# serial 25 1# serial 37
2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2023 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
@@ -7,24 +7,40 @@ dnl with or without modifications, as long as this notice is preserved.
7 7
8dnl From Jim Meyering. 8dnl From Jim Meyering.
9 9
10AC_DEFUN([gl_FUNC_MKTIME], 10AC_DEFUN([gl_TIME_T_IS_SIGNED],
11[
12 AC_CACHE_CHECK([whether time_t is signed],
13 [gl_cv_time_t_is_signed],
14 [AC_COMPILE_IFELSE(
15 [AC_LANG_PROGRAM([[#include <time.h>
16 char time_t_signed[(time_t) -1 < 0 ? 1 : -1];]])],
17 [gl_cv_time_t_is_signed=yes],
18 [gl_cv_time_t_is_signed=no])])
19 if test $gl_cv_time_t_is_signed = yes; then
20 AC_DEFINE([TIME_T_IS_SIGNED], [1], [Define to 1 if time_t is signed.])
21 fi
22])
23
24dnl Test whether mktime works. Set gl_cv_func_working_mktime.
25AC_DEFUN([gl_FUNC_MKTIME_WORKS],
11[ 26[
12 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 27 AC_REQUIRE([gl_TIME_T_IS_SIGNED])
28 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 29
14 dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained 30 dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained
15 dnl in Autoconf and because it invokes AC_LIBOBJ. 31 dnl in Autoconf and because it invokes AC_LIBOBJ.
16 AC_CHECK_HEADERS_ONCE([unistd.h]) 32 AC_CHECK_HEADERS_ONCE([unistd.h])
17 AC_CHECK_DECLS_ONCE([alarm]) 33 AC_CHECK_DECLS_ONCE([alarm])
18 AC_REQUIRE([gl_MULTIARCH]) 34 AC_REQUIRE([gl_MULTIARCH])
19 if test $APPLE_UNIVERSAL_BUILD = 1; then
20 # A universal build on Apple Mac OS X platforms.
21 # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode.
22 # But we need a configuration result that is valid in both modes.
23 gl_cv_func_working_mktime=no
24 fi
25 AC_CACHE_CHECK([for working mktime], [gl_cv_func_working_mktime], 35 AC_CACHE_CHECK([for working mktime], [gl_cv_func_working_mktime],
26 [AC_RUN_IFELSE( 36 [if test $APPLE_UNIVERSAL_BUILD = 1; then
27 [AC_LANG_SOURCE( 37 # A universal build on Apple Mac OS X platforms.
38 # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode.
39 # But we need a configuration result that is valid in both modes.
40 gl_cv_func_working_mktime="guessing no"
41 else
42 AC_RUN_IFELSE(
43 [AC_LANG_SOURCE(
28[[/* Test program from Paul Eggert and Tony Leneis. */ 44[[/* Test program from Paul Eggert and Tony Leneis. */
29#include <limits.h> 45#include <limits.h>
30#include <stdlib.h> 46#include <stdlib.h>
@@ -38,8 +54,11 @@ AC_DEFUN([gl_FUNC_MKTIME],
38# include <signal.h> 54# include <signal.h>
39#endif 55#endif
40 56
41/* Work around redefinition to rpl_putenv by other config tests. */ 57]GL_MDA_DEFINES[
42#undef putenv 58
59#ifndef TIME_T_IS_SIGNED
60# define TIME_T_IS_SIGNED 0
61#endif
43 62
44static time_t time_t_max; 63static time_t time_t_max;
45static time_t time_t_min; 64static time_t time_t_min;
@@ -63,7 +82,8 @@ spring_forward_gap ()
63 instead of "TZ=America/Vancouver" in order to detect the bug even 82 instead of "TZ=America/Vancouver" in order to detect the bug even
64 on systems that don't support the Olson extension, or don't have the 83 on systems that don't support the Olson extension, or don't have the
65 full zoneinfo tables installed. */ 84 full zoneinfo tables installed. */
66 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0"); 85 if (putenv ("TZ=PST8PDT,M4.1.0,M10.5.0") != 0)
86 return -1;
67 87
68 tm.tm_year = 98; 88 tm.tm_year = 98;
69 tm.tm_mon = 3; 89 tm.tm_mon = 3;
@@ -151,7 +171,8 @@ year_2050_test ()
151 instead of "TZ=America/Vancouver" in order to detect the bug even 171 instead of "TZ=America/Vancouver" in order to detect the bug even
152 on systems that don't support the Olson extension, or don't have the 172 on systems that don't support the Olson extension, or don't have the
153 full zoneinfo tables installed. */ 173 full zoneinfo tables installed. */
154 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0"); 174 if (putenv ("TZ=PST8PDT,M4.1.0,M10.5.0") != 0)
175 return -1;
155 176
156 t = mktime (&tm); 177 t = mktime (&tm);
157 178
@@ -162,6 +183,25 @@ year_2050_test ()
162 || (0 < t && answer - 120 <= t && t <= answer + 120)); 183 || (0 < t && answer - 120 <= t && t <= answer + 120));
163} 184}
164 185
186static int
187indiana_test ()
188{
189 if (putenv ("TZ=America/Indiana/Indianapolis") != 0)
190 return -1;
191 struct tm tm;
192 tm.tm_year = 1986 - 1900; tm.tm_mon = 4 - 1; tm.tm_mday = 28;
193 tm.tm_hour = 16; tm.tm_min = 24; tm.tm_sec = 50; tm.tm_isdst = 0;
194 time_t std = mktime (&tm);
195 if (! (std == 515107490 || std == 515107503))
196 return 1;
197
198 /* This platform supports TZDB, either without or with leap seconds.
199 Return true if GNU Bug#48085 is absent. */
200 tm.tm_isdst = 1;
201 time_t dst = mktime (&tm);
202 return std - dst == 60 * 60;
203}
204
165int 205int
166main () 206main ()
167{ 207{
@@ -169,7 +209,6 @@ main ()
169 time_t t, delta; 209 time_t t, delta;
170 int i, j; 210 int i, j;
171 int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1; 211 int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1;
172 int time_t_signed = ! ((time_t) 0 < (time_t) -1);
173 212
174#if HAVE_DECL_ALARM 213#if HAVE_DECL_ALARM
175 /* This test makes some buggy mktime implementations loop. 214 /* This test makes some buggy mktime implementations loop.
@@ -179,11 +218,11 @@ main ()
179 alarm (60); 218 alarm (60);
180#endif 219#endif
181 220
182 time_t_max = (! time_t_signed 221 time_t_max = (! TIME_T_IS_SIGNED
183 ? (time_t) -1 222 ? (time_t) -1
184 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1) 223 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1)
185 * 2 + 1)); 224 * 2 + 1));
186 time_t_min = (! time_t_signed 225 time_t_min = (! TIME_T_IS_SIGNED
187 ? (time_t) 0 226 ? (time_t) 0
188 : time_t_signed_magnitude 227 : time_t_signed_magnitude
189 ? ~ (time_t) 0 228 ? ~ (time_t) 0
@@ -218,35 +257,62 @@ main ()
218 result |= 16; 257 result |= 16;
219 if (! spring_forward_gap ()) 258 if (! spring_forward_gap ())
220 result |= 32; 259 result |= 32;
221 if (! year_2050_test ()) 260 if (! year_2050_test () || ! indiana_test ())
222 result |= 64; 261 result |= 64;
223 return result; 262 return result;
224}]])], 263}]])],
225 [gl_cv_func_working_mktime=yes], 264 [gl_cv_func_working_mktime=yes],
226 [gl_cv_func_working_mktime=no], 265 [gl_cv_func_working_mktime=no],
227 [gl_cv_func_working_mktime=no]) 266 [case "$host_os" in
267 # Guess no on native Windows.
268 mingw*) gl_cv_func_working_mktime="guessing no" ;;
269 *) gl_cv_func_working_mktime="$gl_cross_guess_normal" ;;
270 esac
271 ])
272 fi
228 ]) 273 ])
274])
275
276dnl Main macro of module 'mktime'.
277AC_DEFUN([gl_FUNC_MKTIME],
278[
279 AC_REQUIRE([gl_TIME_H_DEFAULTS])
280 AC_REQUIRE([AC_CANONICAL_HOST])
281 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
229 282
230 if test $gl_cv_func_working_mktime = no; then 283 REPLACE_MKTIME=0
284 if test "$gl_cv_func_working_mktime" != yes; then
231 REPLACE_MKTIME=1 285 REPLACE_MKTIME=1
232 else 286 AC_DEFINE([NEED_MKTIME_WORKING], [1],
233 REPLACE_MKTIME=0 287 [Define if the compilation of mktime.c should define 'mktime'
288 with the algorithmic workarounds.])
234 fi 289 fi
290 case "$host_os" in
291 mingw*)
292 REPLACE_MKTIME=1
293 AC_DEFINE([NEED_MKTIME_WINDOWS], [1],
294 [Define if the compilation of mktime.c should define 'mktime'
295 with the native Windows TZ workaround.])
296 ;;
297 esac
235]) 298])
236 299
300dnl Main macro of module 'mktime-internal'.
237AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ 301AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [
238 AC_REQUIRE([gl_FUNC_MKTIME]) 302 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
239 if test $REPLACE_MKTIME = 0; then 303
240 dnl BeOS has __mktime_internal in libc, but other platforms don't. 304 WANT_MKTIME_INTERNAL=0
241 AC_CHECK_FUNC([__mktime_internal], 305 dnl BeOS has __mktime_internal in libc, but other platforms don't.
242 [AC_DEFINE([mktime_internal], [__mktime_internal], 306 AC_CHECK_FUNC([__mktime_internal],
243 [Define to the real name of the mktime_internal function.]) 307 [AC_DEFINE([mktime_internal], [__mktime_internal],
244 ], 308 [Define to the real name of the mktime_internal function.])
245 [dnl mktime works but it doesn't export __mktime_internal, 309 ],
246 dnl so we need to substitute our own mktime implementation. 310 [dnl mktime works but it doesn't export __mktime_internal,
247 REPLACE_MKTIME=1 311 dnl so we need to substitute our own mktime implementation.
248 ]) 312 WANT_MKTIME_INTERNAL=1
249 fi 313 AC_DEFINE([NEED_MKTIME_INTERNAL], [1],
314 [Define if the compilation of mktime.c should define 'mktime_internal'.])
315 ])
250]) 316])
251 317
252# Prerequisites of lib/mktime.c. 318# Prerequisites of lib/mktime.c.
diff --git a/gl/m4/mmap-anon.m4 b/gl/m4/mmap-anon.m4
index 9b60ddf..d07d26e 100644
--- a/gl/m4/mmap-anon.m4
+++ b/gl/m4/mmap-anon.m4
@@ -1,5 +1,5 @@
1# mmap-anon.m4 serial 10 1# mmap-anon.m4 serial 12
2dnl Copyright (C) 2005, 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2007, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -9,11 +9,11 @@ dnl with or without modifications, as long as this notice is preserved.
9# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS 9# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
10# and MAP_ANON exist and have the same value. 10# and MAP_ANON exist and have the same value.
11# - On HP-UX, only MAP_ANONYMOUS exists. 11# - On HP-UX, only MAP_ANONYMOUS exists.
12# - On Mac OS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists. 12# - On Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, only MAP_ANON exists.
13# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be 13# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
14# used. 14# used.
15 15
16AC_DEFUN([gl_FUNC_MMAP_ANON], 16AC_DEFUN_ONCE([gl_FUNC_MMAP_ANON],
17[ 17[
18 dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS. 18 dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
diff --git a/gl/m4/mode_t.m4 b/gl/m4/mode_t.m4
new file mode 100644
index 0000000..82197c0
--- /dev/null
+++ b/gl/m4/mode_t.m4
@@ -0,0 +1,26 @@
1# mode_t.m4 serial 2
2dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# For using mode_t, it's sufficient to use AC_TYPE_MODE_T and
8# include <sys/types.h>.
9
10# Define PROMOTED_MODE_T to the type that is the result of "default argument
11# promotion" (ISO C 6.5.2.2.(6)) of the type mode_t.
12AC_DEFUN([gl_PROMOTED_TYPE_MODE_T],
13[
14 AC_REQUIRE([AC_TYPE_MODE_T])
15 AC_CACHE_CHECK([for promoted mode_t type], [gl_cv_promoted_mode_t], [
16 dnl Assume mode_t promotes to 'int' if and only if it is smaller than 'int',
17 dnl and to itself otherwise. This assumption is not guaranteed by the ISO C
18 dnl standard, but we don't know of any real-world counterexamples.
19 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]],
20 [[typedef int array[2 * (sizeof (mode_t) < sizeof (int)) - 1];]])],
21 [gl_cv_promoted_mode_t='int'],
22 [gl_cv_promoted_mode_t='mode_t'])
23 ])
24 AC_DEFINE_UNQUOTED([PROMOTED_MODE_T], [$gl_cv_promoted_mode_t],
25 [Define to the type that is the result of default argument promotions of type mode_t.])
26])
diff --git a/gl/m4/mountlist.m4 b/gl/m4/mountlist.m4
index cd137c9..a9b4edb 100644
--- a/gl/m4/mountlist.m4
+++ b/gl/m4/mountlist.m4
@@ -1,19 +1,338 @@
1# serial 11 1# serial 15
2dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2009-2023 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 From Jim Meyering.
8
9AC_PREREQ([2.60])
10
7AC_DEFUN([gl_MOUNTLIST], 11AC_DEFUN([gl_MOUNTLIST],
8[ 12[
9 gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], 13 AC_REQUIRE([AC_CANONICAL_HOST])
10 [gl_cv_list_mounted_fs=no]) 14 AC_CHECK_FUNCS([listmntent])
15 AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
16
17 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
18 # NGROUPS (as the array dimension for a struct member) without a definition.
19 AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
20
21 AC_CHECK_HEADERS([sys/mount.h], [], [],
22 [AC_INCLUDES_DEFAULT
23 [#if HAVE_SYS_PARAM_H
24 #include <sys/param.h>
25 #endif
26 ]])
27
28 AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
29 getfsstat_includes="\
30$ac_includes_default
31#if HAVE_SYS_PARAM_H
32# include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
33#endif
34#if HAVE_SYS_UCRED_H
35# include <grp.h> /* needed for definition of NGROUPS */
36# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
37#endif
38#if HAVE_SYS_MOUNT_H
39# include <sys/mount.h>
40#endif
41#if HAVE_SYS_FS_TYPES_H
42# include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
43#endif
44"
45 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
46
47 # Determine how to get the list of mounted file systems.
48 ac_list_mounted_fs=
49
50 # If the getmntent function is available but not in the standard library,
51 # make sure LIBS contains the appropriate -l option.
52 AC_FUNC_GETMNTENT
53
54 if test -z "$ac_list_mounted_fs"; then
55 # AIX.
56 AC_CACHE_CHECK([for mntctl function and struct vmount],
57 [fu_cv_sys_mounted_vmount],
58 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
59 [fu_cv_sys_mounted_vmount=yes],
60 [fu_cv_sys_mounted_vmount=no])])
61 if test $fu_cv_sys_mounted_vmount = yes; then
62 ac_list_mounted_fs=found
63 AC_DEFINE([MOUNTED_VMOUNT], [1],
64 [Define if there is a function named mntctl that can be used to read
65 the list of mounted file systems, and there is a system header file
66 that declares 'struct vmount'. (AIX)])
67 fi
68 fi
69
70 if test $ac_cv_func_getmntent = yes; then
71
72 # This system has the getmntent function.
73 # Determine whether it's the one-argument variant or the two-argument one.
74
75 if test -z "$ac_list_mounted_fs"; then
76 # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
77 AC_CACHE_CHECK([for one-argument getmntent function],
78 [fu_cv_sys_mounted_getmntent1],
79 [AC_COMPILE_IFELSE(
80 [AC_LANG_PROGRAM([[
81/* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
82#include <stdio.h>
83
84#include <mntent.h>
85#if defined __ANDROID__ /* Android */
86# undef MOUNTED
87# define MOUNTED "/proc/mounts"
88#elif !defined MOUNTED
89# if defined _PATH_MOUNTED /* GNU libc */
90# define MOUNTED _PATH_MOUNTED
91# endif
92# if defined MNT_MNTTAB /* HP-UX. */
93# define MOUNTED MNT_MNTTAB
94# endif
95#endif
96]],
97 [[struct mntent *mnt = 0; char *table = MOUNTED;
98 if (sizeof mnt && sizeof table) return 0;
99 ]])],
100 [fu_cv_sys_mounted_getmntent1=yes],
101 [fu_cv_sys_mounted_getmntent1=no])
102 ])
103 if test $fu_cv_sys_mounted_getmntent1 = yes; then
104 ac_list_mounted_fs=found
105 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
106 [Define if there is a function named getmntent for reading the list
107 of mounted file systems, and that function takes a single argument.
108 (4.3BSD, SunOS, HP-UX, Irix)])
109 AC_CHECK_FUNCS([setmntent endmntent hasmntopt])
110 fi
111 fi
112
113 if test -z "$ac_list_mounted_fs"; then
114 # Solaris >= 8.
115 AC_CACHE_CHECK([for getextmntent function],
116 [fu_cv_sys_mounted_getextmntent],
117 [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
118 [fu_cv_sys_mounted_getextmntent=yes],
119 [fu_cv_sys_mounted_getextmntent=no])])
120 if test $fu_cv_sys_mounted_getextmntent = yes; then
121 ac_list_mounted_fs=found
122 AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
123 [Define if there is a function named getextmntent for reading the list
124 of mounted file systems. (Solaris)])
125 fi
126 fi
127
128 if test -z "$ac_list_mounted_fs"; then
129 # Solaris < 8, also (obsolete) SVR4.
130 # Solaris >= 8 has the two-argument getmntent but is already handled above.
131 AC_CACHE_CHECK([for two-argument getmntent function],
132 [fu_cv_sys_mounted_getmntent2],
133 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
134 [fu_cv_sys_mounted_getmntent2=yes],
135 [fu_cv_sys_mounted_getmntent2=no])
136 ])
137 if test $fu_cv_sys_mounted_getmntent2 = yes; then
138 ac_list_mounted_fs=found
139 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
140 [Define if there is a function named getmntent for reading the list of
141 mounted file systems, and that function takes two arguments. (SVR4)])
142 AC_CHECK_FUNCS([hasmntopt])
143 fi
144 fi
145
146 fi
147
148 if test -z "$ac_list_mounted_fs"; then
149 # OSF/1, also (obsolete) Apple Darwin 1.3.
150 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
151
152 AC_CACHE_CHECK([for getfsstat function],
153 [fu_cv_sys_mounted_getfsstat],
154 [AC_LINK_IFELSE(
155 [AC_LANG_PROGRAM([[
156#include <sys/types.h>
157#if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
158# define FS_TYPE(Ent) ((Ent).f_fstypename)
159#else
160# define FS_TYPE(Ent) mnt_names[(Ent).f_type]
161#endif
162$getfsstat_includes
163 ]],
164 [[struct statfs *stats;
165 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
166 char *t = FS_TYPE (*stats);
167 ]])],
168 [fu_cv_sys_mounted_getfsstat=yes],
169 [fu_cv_sys_mounted_getfsstat=no])
170 ])
171 if test $fu_cv_sys_mounted_getfsstat = yes; then
172 ac_list_mounted_fs=found
173 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
174 [Define if there is a function named getfsstat for reading the
175 list of mounted file systems. (DEC Alpha running OSF/1)])
176 fi
177 fi
178
179 if test -z "$ac_list_mounted_fs"; then
180 # (obsolete) SVR3
181 AC_CACHE_CHECK([for FIXME existence of three headers],
182 [fu_cv_sys_mounted_fread_fstyp],
183 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
184#include <sys/statfs.h>
185#include <sys/fstyp.h>
186#include <mnttab.h>
187]])],
188 [fu_cv_sys_mounted_fread_fstyp=yes],
189 [fu_cv_sys_mounted_fread_fstyp=no])
190 ])
191 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
192 ac_list_mounted_fs=found
193 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
194 [Define if (like SVR2) there is no specific function for reading the
195 list of mounted file systems, and your system has these header files:
196 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
197 fi
198 fi
199
200 if test -z "$ac_list_mounted_fs"; then
201 # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
202 # OSF/1 also has getmntinfo but is already handled above.
203 # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
204 # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
205 # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
206 AC_CACHE_CHECK([for getmntinfo function],
207 [fu_cv_sys_mounted_getmntinfo],
208 [AC_LINK_IFELSE(
209 [AC_LANG_PROGRAM([[
210#if HAVE_SYS_PARAM_H
211# include <sys/param.h>
212#endif
213#include <sys/types.h>
214#if HAVE_SYS_MOUNT_H
215# include <sys/mount.h>
216#endif
217#if HAVE_SYS_STATVFS_H
218# include <sys/statvfs.h>
219#endif
220#include <stdlib.h>
221 ]],
222 [[int count = getmntinfo (NULL, MNT_WAIT);
223 ]])],
224 [fu_cv_sys_mounted_getmntinfo=yes],
225 [fu_cv_sys_mounted_getmntinfo=no])
226 ])
227 if test $fu_cv_sys_mounted_getmntinfo = yes; then
228 AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
229 [fu_cv_sys_mounted_getmntinfo2],
230 [AC_COMPILE_IFELSE(
231 [AC_LANG_PROGRAM([[
232#if HAVE_SYS_PARAM_H
233# include <sys/param.h>
234#endif
235#include <sys/types.h>
236#if HAVE_SYS_MOUNT_H
237# include <sys/mount.h>
238#endif
239#if HAVE_SYS_STATVFS_H
240# include <sys/statvfs.h>
241#endif
242extern
243#ifdef __cplusplus
244"C"
245#endif
246int getmntinfo (struct statfs **, int);
247 ]], [[]])],
248 [fu_cv_sys_mounted_getmntinfo2=no],
249 [fu_cv_sys_mounted_getmntinfo2=yes])
250 ])
251 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
252 # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
253 ac_list_mounted_fs=found
254 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
255 [Define if there is a function named getmntinfo for reading the
256 list of mounted file systems and it returns an array of
257 'struct statfs'. (4.4BSD, Darwin)])
258 else
259 # NetBSD, Minix.
260 ac_list_mounted_fs=found
261 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
262 [Define if there is a function named getmntinfo for reading the
263 list of mounted file systems and it returns an array of
264 'struct statvfs'. (NetBSD 3.0)])
265 fi
266 fi
267 fi
268
269 if test -z "$ac_list_mounted_fs"; then
270 # Haiku, also (obsolete) BeOS.
271 AC_CHECK_FUNCS([next_dev fs_stat_dev])
272 AC_CHECK_HEADERS([fs_info.h])
273 AC_CACHE_CHECK([for BEOS mounted file system support functions],
274 [fu_cv_sys_mounted_fs_stat_dev],
275 [if test $ac_cv_header_fs_info_h = yes \
276 && test $ac_cv_func_next_dev = yes \
277 && test $ac_cv_func_fs_stat_dev = yes; then
278 fu_cv_sys_mounted_fs_stat_dev=yes
279 else
280 fu_cv_sys_mounted_fs_stat_dev=no
281 fi
282 ])
283 if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
284 ac_list_mounted_fs=found
285 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
286 [Define if there are functions named next_dev and fs_stat_dev for
287 reading the list of mounted file systems. (BeOS)])
288 fi
289 fi
290
291 if test -z "$ac_list_mounted_fs"; then
292 # Interix / BSD alike statvfs
293 # the code is really interix specific, so make sure, we're on it.
294 case "$host" in
295 *-interix*)
296 AC_CHECK_FUNCS([statvfs])
297 if test $ac_cv_func_statvfs = yes; then
298 ac_list_mounted_fs=found
299 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
300 [Define if we are on interix, and ought to use statvfs plus
301 some special knowledge on where mounted file systems can be
302 found. (Interix)])
303 fi
304 ;;
305 esac
306 fi
307
308 if test -z "$ac_list_mounted_fs"; then
309 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
310 # FIXME -- no need to abort building the whole package
311 # Can't build mountlist.c or anything that needs its functions
312 fi
313
314 if test $ac_list_mounted_fs = found; then
315 gl_cv_list_mounted_fs=yes
316 else
317 gl_cv_list_mounted_fs=no
318 fi
11]) 319])
12 320
13# Prerequisites of lib/mountlist.c not done by gl_LIST_MOUNTED_FILE_SYSTEMS. 321# Prerequisites of lib/mountlist.c not done by gl_MOUNTLIST.
14AC_DEFUN([gl_PREREQ_MOUNTLIST_EXTRA], 322AC_DEFUN([gl_PREREQ_MOUNTLIST_EXTRA],
15[ 323[
16 dnl Note gl_LIST_MOUNTED_FILE_SYSTEMS checks for mntent.h, not sys/mntent.h. 324 dnl Note gl_MOUNTLIST checks for mntent.h, not sys/mntent.h.
17 AC_CHECK_HEADERS([sys/mntent.h]) 325 AC_CHECK_HEADERS([sys/mntent.h])
326 AC_HEADER_MAJOR()dnl for use of makedev ()
18 gl_FSTYPENAME 327 gl_FSTYPENAME
19]) 328])
329
330# Replace Autoconf's AC_FUNC_GETMNTENT to omit checks that are unnecessary
331# nowadays.
332AC_DEFUN([AC_FUNC_GETMNTENT],
333[
334 # getmntent is in the standard C library on most systems, but in -lgen on
335 # Unixware.
336 AC_SEARCH_LIBS([getmntent], [gen])
337 AC_CHECK_FUNCS([getmntent])
338])
diff --git a/gl/m4/msvc-inval.m4 b/gl/m4/msvc-inval.m4
index 9a6a47a..8d9d21b 100644
--- a/gl/m4/msvc-inval.m4
+++ b/gl/m4/msvc-inval.m4
@@ -1,5 +1,5 @@
1# msvc-inval.m4 serial 1 1# msvc-inval.m4 serial 1
2dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2011-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/msvc-nothrow.m4 b/gl/m4/msvc-nothrow.m4
index a39618a..0263e49 100644
--- a/gl/m4/msvc-nothrow.m4
+++ b/gl/m4/msvc-nothrow.m4
@@ -1,5 +1,5 @@
1# msvc-nothrow.m4 serial 1 1# msvc-nothrow.m4 serial 1
2dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2011-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/multiarch.m4 b/gl/m4/multiarch.m4
index 552ec7e..3ba5b0f 100644
--- a/gl/m4/multiarch.m4
+++ b/gl/m4/multiarch.m4
@@ -1,5 +1,5 @@
1# multiarch.m4 serial 7 1# multiarch.m4 serial 9
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 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,37 +21,40 @@ dnl with or without modifications, as long as this notice is preserved.
21AC_DEFUN_ONCE([gl_MULTIARCH], 21AC_DEFUN_ONCE([gl_MULTIARCH],
22[ 22[
23 dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN. 23 dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN.
24 gl_cv_c_multiarch=no 24 AC_CACHE_CHECK([whether the compiler produces multi-arch binaries],
25 AC_COMPILE_IFELSE( 25 [gl_cv_c_multiarch],
26 [AC_LANG_SOURCE( 26 [gl_cv_c_multiarch=no
27 [[#ifndef __APPLE_CC__ 27 AC_COMPILE_IFELSE(
28 not a universal capable compiler 28 [AC_LANG_SOURCE(
29 #endif 29 [[#ifndef __APPLE_CC__
30 typedef int dummy; 30 not a universal capable compiler
31 ]])], 31 #endif
32 [ 32 typedef int dummy;
33 dnl Check for potential -arch flags. It is not universal unless 33 ]])],
34 dnl there are at least two -arch flags with different values. 34 [
35 arch= 35 dnl Check for potential -arch flags. It is not universal unless
36 prev= 36 dnl there are at least two -arch flags with different values.
37 for word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do 37 arch=
38 if test -n "$prev"; then 38 prev=
39 case $word in 39 for word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
40 i?86 | x86_64 | ppc | ppc64) 40 if test -n "$prev"; then
41 if test -z "$arch" || test "$arch" = "$word"; then 41 case $word in
42 arch="$word" 42 i?86 | x86_64 | ppc | ppc64 | arm | arm64)
43 else 43 if test -z "$arch" || test "$arch" = "$word"; then
44 gl_cv_c_multiarch=yes 44 arch="$word"
45 fi 45 else
46 ;; 46 gl_cv_c_multiarch=yes
47 esac 47 fi
48 prev= 48 ;;
49 else 49 esac
50 if test "x$word" = "x-arch"; then 50 prev=
51 prev=arch 51 else
52 fi 52 if test "x$word" = "x-arch"; then
53 fi 53 prev=arch
54 done 54 fi
55 fi
56 done
57 ])
55 ]) 58 ])
56 if test $gl_cv_c_multiarch = yes; then 59 if test $gl_cv_c_multiarch = yes; then
57 APPLE_UNIVERSAL_BUILD=1 60 APPLE_UNIVERSAL_BUILD=1
diff --git a/gl/m4/netdb_h.m4 b/gl/m4/netdb_h.m4
index 2c69f99..e6aa892 100644
--- a/gl/m4/netdb_h.m4
+++ b/gl/m4/netdb_h.m4
@@ -1,10 +1,10 @@
1# netdb_h.m4 serial 11 1# netdb_h.m4 serial 15
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 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_HEADER_NETDB], 7AC_DEFUN_ONCE([gl_NETDB_H],
8[ 8[
9 AC_REQUIRE([gl_NETDB_H_DEFAULTS]) 9 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
10 gl_CHECK_NEXT_HEADERS([netdb.h]) 10 gl_CHECK_NEXT_HEADERS([netdb.h])
@@ -21,18 +21,33 @@ AC_DEFUN([gl_HEADER_NETDB],
21 [getaddrinfo freeaddrinfo gai_strerror getnameinfo]) 21 [getaddrinfo freeaddrinfo gai_strerror getnameinfo])
22]) 22])
23 23
24# gl_NETDB_MODULE_INDICATOR([modulename])
25# sets the shell variable that indicates the presence of the given module
26# to a C preprocessor expression that will evaluate to 1.
27# This macro invocation must not occur in macros that are AC_REQUIREd.
24AC_DEFUN([gl_NETDB_MODULE_INDICATOR], 28AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
25[ 29[
26 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 30 dnl Ensure to expand the default settings once only.
27 AC_REQUIRE([gl_NETDB_H_DEFAULTS]) 31 gl_NETDB_H_REQUIRE_DEFAULTS
28 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 32 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
29 dnl Define it also as a C macro, for the benefit of the unit tests. 33 dnl Define it also as a C macro, for the benefit of the unit tests.
30 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 34 gl_MODULE_INDICATOR_FOR_TESTS([$1])
31]) 35])
32 36
37# Initializes the default values for AC_SUBSTed shell variables.
38# This macro must not be AC_REQUIREd. It must only be invoked, and only
39# outside of macros or in macros that are not AC_REQUIREd.
40AC_DEFUN([gl_NETDB_H_REQUIRE_DEFAULTS],
41[
42 m4_defun(GL_MODULE_INDICATOR_PREFIX[_NETDB_H_MODULE_INDICATOR_DEFAULTS], [
43 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETADDRINFO])
44 ])
45 m4_require(GL_MODULE_INDICATOR_PREFIX[_NETDB_H_MODULE_INDICATOR_DEFAULTS])
46 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
47])
48
33AC_DEFUN([gl_NETDB_H_DEFAULTS], 49AC_DEFUN([gl_NETDB_H_DEFAULTS],
34[ 50[
35 GNULIB_GETADDRINFO=0; AC_SUBST([GNULIB_GETADDRINFO])
36 dnl Assume proper GNU behavior unless another module says otherwise. 51 dnl Assume proper GNU behavior unless another module says otherwise.
37 HAVE_STRUCT_ADDRINFO=1; AC_SUBST([HAVE_STRUCT_ADDRINFO]) 52 HAVE_STRUCT_ADDRINFO=1; AC_SUBST([HAVE_STRUCT_ADDRINFO])
38 HAVE_DECL_FREEADDRINFO=1; AC_SUBST([HAVE_DECL_FREEADDRINFO]) 53 HAVE_DECL_FREEADDRINFO=1; AC_SUBST([HAVE_DECL_FREEADDRINFO])
@@ -40,4 +55,5 @@ AC_DEFUN([gl_NETDB_H_DEFAULTS],
40 HAVE_DECL_GETADDRINFO=1; AC_SUBST([HAVE_DECL_GETADDRINFO]) 55 HAVE_DECL_GETADDRINFO=1; AC_SUBST([HAVE_DECL_GETADDRINFO])
41 HAVE_DECL_GETNAMEINFO=1; AC_SUBST([HAVE_DECL_GETNAMEINFO]) 56 HAVE_DECL_GETNAMEINFO=1; AC_SUBST([HAVE_DECL_GETNAMEINFO])
42 REPLACE_GAI_STRERROR=0; AC_SUBST([REPLACE_GAI_STRERROR]) 57 REPLACE_GAI_STRERROR=0; AC_SUBST([REPLACE_GAI_STRERROR])
58 REPLACE_GETADDRINFO=0; AC_SUBST([REPLACE_GETADDRINFO])
43]) 59])
diff --git a/gl/m4/netinet_in_h.m4 b/gl/m4/netinet_in_h.m4
index 21971b2..7115419 100644
--- a/gl/m4/netinet_in_h.m4
+++ b/gl/m4/netinet_in_h.m4
@@ -1,5 +1,5 @@
1# netinet_in_h.m4 serial 5 1# netinet_in_h.m4 serial 6
2dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2023 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,9 +14,9 @@ AC_DEFUN([gl_HEADER_NETINET_IN],
14 [gl_cv_header_netinet_in_h_selfcontained=no]) 14 [gl_cv_header_netinet_in_h_selfcontained=no])
15 ]) 15 ])
16 if test $gl_cv_header_netinet_in_h_selfcontained = yes; then 16 if test $gl_cv_header_netinet_in_h_selfcontained = yes; then
17 NETINET_IN_H='' 17 GL_GENERATE_NETINET_IN_H=false
18 else 18 else
19 NETINET_IN_H='netinet/in.h' 19 GL_GENERATE_NETINET_IN_H=true
20 AC_CHECK_HEADERS([netinet/in.h]) 20 AC_CHECK_HEADERS([netinet/in.h])
21 gl_CHECK_NEXT_HEADERS([netinet/in.h]) 21 gl_CHECK_NEXT_HEADERS([netinet/in.h])
22 if test $ac_cv_header_netinet_in_h = yes; then 22 if test $ac_cv_header_netinet_in_h = yes; then
@@ -26,6 +26,4 @@ AC_DEFUN([gl_HEADER_NETINET_IN],
26 fi 26 fi
27 AC_SUBST([HAVE_NETINET_IN_H]) 27 AC_SUBST([HAVE_NETINET_IN_H])
28 fi 28 fi
29 AC_SUBST([NETINET_IN_H])
30 AM_CONDITIONAL([GL_GENERATE_NETINET_IN_H], [test -n "$NETINET_IN_H"])
31]) 29])
diff --git a/gl/m4/nl_langinfo.m4 b/gl/m4/nl_langinfo.m4
index 25e2101..51e783c 100644
--- a/gl/m4/nl_langinfo.m4
+++ b/gl/m4/nl_langinfo.m4
@@ -1,5 +1,5 @@
1# nl_langinfo.m4 serial 5 1# nl_langinfo.m4 serial 8
2dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -9,7 +9,10 @@ AC_DEFUN([gl_FUNC_NL_LANGINFO],
9 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS]) 9 AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
10 AC_REQUIRE([gl_LANGINFO_H]) 10 AC_REQUIRE([gl_LANGINFO_H])
11 AC_CHECK_FUNCS_ONCE([nl_langinfo]) 11 AC_CHECK_FUNCS_ONCE([nl_langinfo])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
14 AC_REQUIRE([gl_PTHREADLIB])
15 AC_CHECK_HEADERS_ONCE([threads.h])
13 if test $ac_cv_func_nl_langinfo = yes; then 16 if test $ac_cv_func_nl_langinfo = yes; then
14 # On Irix 6.5, YESEXPR is defined, but nl_langinfo(YESEXPR) is broken. 17 # On Irix 6.5, YESEXPR is defined, but nl_langinfo(YESEXPR) is broken.
15 AC_CACHE_CHECK([whether YESEXPR works], 18 AC_CACHE_CHECK([whether YESEXPR works],
@@ -36,8 +39,19 @@ AC_DEFUN([gl_FUNC_NL_LANGINFO],
36 AC_DEFINE_UNQUOTED([FUNC_NL_LANGINFO_YESEXPR_WORKS], 39 AC_DEFINE_UNQUOTED([FUNC_NL_LANGINFO_YESEXPR_WORKS],
37 [$FUNC_NL_LANGINFO_YESEXPR_WORKS], 40 [$FUNC_NL_LANGINFO_YESEXPR_WORKS],
38 [Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string.]) 41 [Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string.])
39 if test $HAVE_LANGINFO_CODESET = 1 && test $HAVE_LANGINFO_ERA = 1 \ 42 # On Solaris 10 and Solaris 11.3, nl_langinfo is not multithread-safe.
40 && test $FUNC_NL_LANGINFO_YESEXPR_WORKS = 1; then 43 case "$host_os" in
44 solaris*) NL_LANGINFO_MTSAFE=0 ;;
45 *) NL_LANGINFO_MTSAFE=1 ;;
46 esac
47 AC_DEFINE_UNQUOTED([NL_LANGINFO_MTSAFE], [$NL_LANGINFO_MTSAFE],
48 [Define to 1 if nl_langinfo is multithread-safe.])
49 if test $HAVE_LANGINFO_CODESET = 1 \
50 && test $HAVE_LANGINFO_T_FMT_AMPM = 1 \
51 && test $HAVE_LANGINFO_ALTMON = 1 \
52 && test $HAVE_LANGINFO_ERA = 1 \
53 && test $FUNC_NL_LANGINFO_YESEXPR_WORKS = 1 \
54 && test $NL_LANGINFO_MTSAFE = 1; then
41 : 55 :
42 else 56 else
43 REPLACE_NL_LANGINFO=1 57 REPLACE_NL_LANGINFO=1
@@ -47,4 +61,17 @@ AC_DEFUN([gl_FUNC_NL_LANGINFO],
47 else 61 else
48 HAVE_NL_LANGINFO=0 62 HAVE_NL_LANGINFO=0
49 fi 63 fi
64 if test $HAVE_NL_LANGINFO = 0 || test $HAVE_LANGINFO_CODESET = 0; then
65 LIB_NL_LANGINFO="$LIB_SETLOCALE_NULL"
66 else
67 LIB_NL_LANGINFO=
68 fi
69 dnl LIB_NL_LANGINFO is expected to be empty everywhere.
70 AC_SUBST([LIB_NL_LANGINFO])
71])
72
73# Prerequisites of lib/nl_langinfo-lock.c.
74AC_DEFUN([gl_PREREQ_NL_LANGINFO_LOCK],
75[
76 gl_VISIBILITY
50]) 77])
diff --git a/gl/m4/nls.m4 b/gl/m4/nls.m4
deleted file mode 100644
index 8f8a147..0000000
--- a/gl/m4/nls.m4
+++ /dev/null
@@ -1,32 +0,0 @@
1# nls.m4 serial 5 (gettext-0.18)
2dnl Copyright (C) 1995-2003, 2005-2006, 2008-2013 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7dnl
8dnl This file can can be used in projects which are not available under
9dnl the GNU General Public License or the GNU Library General Public
10dnl License but which still want to provide support for the GNU gettext
11dnl functionality.
12dnl Please note that the actual code of the GNU gettext library is covered
13dnl by the GNU Library General Public License, and the rest of the GNU
14dnl gettext package package is covered by the GNU General Public License.
15dnl They are *not* in the public domain.
16
17dnl Authors:
18dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
19dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
20
21AC_PREREQ([2.50])
22
23AC_DEFUN([AM_NLS],
24[
25 AC_MSG_CHECKING([whether NLS is requested])
26 dnl Default is enabled NLS
27 AC_ARG_ENABLE([nls],
28 [ --disable-nls do not use Native Language Support],
29 USE_NLS=$enableval, USE_NLS=yes)
30 AC_MSG_RESULT([$USE_NLS])
31 AC_SUBST([USE_NLS])
32])
diff --git a/gl/m4/nocrash.m4 b/gl/m4/nocrash.m4
index 105b884..6a76638 100644
--- a/gl/m4/nocrash.m4
+++ b/gl/m4/nocrash.m4
@@ -1,5 +1,5 @@
1# nocrash.m4 serial 4 1# nocrash.m4 serial 5
2dnl Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2009-2023 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.
@@ -53,7 +53,7 @@ nocrash_init (void)
53 /* Allocate a port on which the thread shall listen for exceptions. */ 53 /* Allocate a port on which the thread shall listen for exceptions. */
54 if (mach_port_allocate (self, MACH_PORT_RIGHT_RECEIVE, &our_exception_port) 54 if (mach_port_allocate (self, MACH_PORT_RIGHT_RECEIVE, &our_exception_port)
55 == KERN_SUCCESS) { 55 == KERN_SUCCESS) {
56 /* See http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/mach_port_insert_right.html. */ 56 /* See https://web.mit.edu/darwin/src/modules/xnu/osfmk/man/mach_port_insert_right.html. */
57 if (mach_port_insert_right (self, our_exception_port, our_exception_port, 57 if (mach_port_insert_right (self, our_exception_port, our_exception_port,
58 MACH_MSG_TYPE_MAKE_SEND) 58 MACH_MSG_TYPE_MAKE_SEND)
59 == KERN_SUCCESS) { 59 == KERN_SUCCESS) {
@@ -72,14 +72,14 @@ nocrash_init (void)
72 for a particular thread. This has the effect that when our exception 72 for a particular thread. This has the effect that when our exception
73 port gets the message, the thread specific exception port has already 73 port gets the message, the thread specific exception port has already
74 been asked, and we don't need to bother about it. 74 been asked, and we don't need to bother about it.
75 See http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_set_exception_ports.html. */ 75 See https://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_set_exception_ports.html. */
76 task_set_exception_ports (self, mask, our_exception_port, 76 task_set_exception_ports (self, mask, our_exception_port,
77 EXCEPTION_DEFAULT, MACHINE_THREAD_STATE); 77 EXCEPTION_DEFAULT, MACHINE_THREAD_STATE);
78 } 78 }
79 } 79 }
80 } 80 }
81} 81}
82#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 82#elif defined _WIN32 && ! defined __CYGWIN__
83/* Avoid a crash on native Windows. */ 83/* Avoid a crash on native Windows. */
84#define WIN32_LEAN_AND_MEAN 84#define WIN32_LEAN_AND_MEAN
85#include <windows.h> 85#include <windows.h>
@@ -110,11 +110,12 @@ nocrash_init (void)
110#else 110#else
111/* Avoid a crash on POSIX systems. */ 111/* Avoid a crash on POSIX systems. */
112#include <signal.h> 112#include <signal.h>
113#include <unistd.h>
113/* A POSIX signal handler. */ 114/* A POSIX signal handler. */
114static void 115static void
115exception_handler (int sig) 116exception_handler (int sig)
116{ 117{
117 exit (1); 118 _exit (1);
118} 119}
119static void 120static void
120nocrash_init (void) 121nocrash_init (void)
diff --git a/gl/m4/off_t.m4 b/gl/m4/off_t.m4
index d355d01..880f347 100644
--- a/gl/m4/off_t.m4
+++ b/gl/m4/off_t.m4
@@ -1,5 +1,5 @@
1# off_t.m4 serial 1 1# off_t.m4 serial 1
2dnl Copyright (C) 2012-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2012-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/onceonly.m4 b/gl/m4/onceonly.m4
deleted file mode 100644
index 0a875a3..0000000
--- a/gl/m4/onceonly.m4
+++ /dev/null
@@ -1,104 +0,0 @@
1# onceonly.m4 serial 9
2dnl Copyright (C) 2002-2003, 2005-2006, 2008-2013 Free Software Foundation,
3dnl Inc.
4dnl
5dnl This file is free software; you can redistribute it and/or modify
6dnl it under the terms of the GNU General Public License as published by
7dnl the Free Software Foundation; either version 3 of the License, or
8dnl (at your option) any later version.
9dnl
10dnl This file is distributed in the hope that it will be useful,
11dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13dnl GNU General Public License for more details.
14dnl
15dnl You should have received a copy of the GNU General Public License
16dnl along with this file. If not, see <http://www.gnu.org/licenses/>.
17dnl
18dnl As a special exception to the GNU General Public License,
19dnl this file may be distributed as part of a program
20dnl that contains a configuration script generated by Autoconf, under
21dnl the same distribution terms as the rest of that program.
22
23dnl This file defines some "once only" variants of standard autoconf macros.
24dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
25dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
26dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
27dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL
28dnl The advantage is that the check for each of the headers/functions/decls
29dnl will be put only once into the 'configure' file. It keeps the size of
30dnl the 'configure' file down, and avoids redundant output when 'configure'
31dnl is run.
32dnl The drawback is that the checks cannot be conditionalized. If you write
33dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi
34dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to
35dnl empty, and the check will be inserted before the body of the AC_DEFUNed
36dnl function.
37
38dnl The original code implemented AC_CHECK_HEADERS_ONCE and AC_CHECK_FUNCS_ONCE
39dnl in terms of AC_DEFUN and AC_REQUIRE. This implementation uses diversions to
40dnl named sections DEFAULTS and INIT_PREPARE in order to check all requested
41dnl headers at once, thus reducing the size of 'configure'. It is known to work
42dnl with autoconf 2.57..2.62 at least . The size reduction is ca. 9%.
43
44dnl Autoconf version 2.59 plus gnulib is required; this file is not needed
45dnl with Autoconf 2.60 or greater. But note that autoconf's implementation of
46dnl AC_CHECK_DECLS_ONCE expects a comma-separated list of symbols as first
47dnl argument!
48AC_PREREQ([2.59])
49
50# AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of
51# AC_CHECK_HEADERS(HEADER1 HEADER2 ...).
52AC_DEFUN([AC_CHECK_HEADERS_ONCE], [
53 :
54 m4_foreach_w([gl_HEADER_NAME], [$1], [
55 AC_DEFUN([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME,
56 [./-], [___])), [
57 m4_divert_text([INIT_PREPARE],
58 [gl_header_list="$gl_header_list gl_HEADER_NAME"])
59 gl_HEADERS_EXPANSION
60 AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])),
61 [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.])
62 ])
63 AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME,
64 [./-], [___])))
65 ])
66])
67m4_define([gl_HEADERS_EXPANSION], [
68 m4_divert_text([DEFAULTS], [gl_header_list=])
69 AC_CHECK_HEADERS([$gl_header_list])
70 m4_define([gl_HEADERS_EXPANSION], [])
71])
72
73# AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of
74# AC_CHECK_FUNCS(FUNC1 FUNC2 ...).
75AC_DEFUN([AC_CHECK_FUNCS_ONCE], [
76 :
77 m4_foreach_w([gl_FUNC_NAME], [$1], [
78 AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [
79 m4_divert_text([INIT_PREPARE],
80 [gl_func_list="$gl_func_list gl_FUNC_NAME"])
81 gl_FUNCS_EXPANSION
82 AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])),
83 [Define to 1 if you have the ']m4_defn([gl_FUNC_NAME])[' function.])
84 ])
85 AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]))
86 ])
87])
88m4_define([gl_FUNCS_EXPANSION], [
89 m4_divert_text([DEFAULTS], [gl_func_list=])
90 AC_CHECK_FUNCS([$gl_func_list])
91 m4_define([gl_FUNCS_EXPANSION], [])
92])
93
94# AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of
95# AC_CHECK_DECLS(DECL1, DECL2, ...).
96AC_DEFUN([AC_CHECK_DECLS_ONCE], [
97 :
98 m4_foreach_w([gl_DECL_NAME], [$1], [
99 AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [
100 AC_CHECK_DECLS(m4_defn([gl_DECL_NAME]))
101 ])
102 AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]))
103 ])
104])
diff --git a/gl/m4/open-cloexec.m4 b/gl/m4/open-cloexec.m4
new file mode 100644
index 0000000..fd572fc
--- /dev/null
+++ b/gl/m4/open-cloexec.m4
@@ -0,0 +1,21 @@
1# Test whether O_CLOEXEC is defined.
2
3dnl Copyright 2017-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_PREPROC_O_CLOEXEC],
9[
10 AC_CACHE_CHECK([for O_CLOEXEC],
11 [gl_cv_macro_O_CLOEXEC],
12 [AC_COMPILE_IFELSE(
13 [AC_LANG_PROGRAM([[#include <fcntl.h>
14 #ifndef O_CLOEXEC
15 choke me;
16 #endif
17 ]],
18 [[return O_CLOEXEC;]])],
19 [gl_cv_macro_O_CLOEXEC=yes],
20 [gl_cv_macro_O_CLOEXEC=no])])
21])
diff --git a/gl/m4/open-slash.m4 b/gl/m4/open-slash.m4
new file mode 100644
index 0000000..1f731f8
--- /dev/null
+++ b/gl/m4/open-slash.m4
@@ -0,0 +1,60 @@
1# open-slash.m4 serial 2
2dnl Copyright (C) 2007-2023 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 Tests whether open() and creat() recognize a trailing slash.
8dnl Sets gl_cv_func_open_slash.
9AC_DEFUN([gl_OPEN_TRAILING_SLASH_BUG],
10[
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 dnl open("foo/") should not create a file when the file name has a
13 dnl trailing slash. FreeBSD only has the problem on symlinks.
14 AC_CHECK_FUNCS_ONCE([lstat])
15 AC_CACHE_CHECK([whether open recognizes a trailing slash],
16 [gl_cv_func_open_slash],
17 [# Assume that if we have lstat, we can also check symlinks.
18 if test $ac_cv_func_lstat = yes; then
19 touch conftest.tmp
20 ln -s conftest.tmp conftest.lnk
21 fi
22 AC_RUN_IFELSE(
23 [AC_LANG_SOURCE([[
24#include <fcntl.h>
25#if HAVE_UNISTD_H
26# include <unistd.h>
27#endif
28]GL_MDA_DEFINES[
29int main ()
30{
31 int result = 0;
32#if HAVE_LSTAT
33 if (open ("conftest.lnk/", O_RDONLY) != -1)
34 result |= 1;
35#endif
36 if (open ("conftest.sl/", O_CREAT, 0600) >= 0)
37 result |= 2;
38 return result;
39}]])],
40 [gl_cv_func_open_slash=yes],
41 [gl_cv_func_open_slash=no],
42 [
43changequote(,)dnl
44 case "$host_os" in
45 freebsd* | aix* | hpux* | solaris2.[0-9] | solaris2.[0-9].*)
46 gl_cv_func_open_slash="guessing no" ;;
47 *)
48 gl_cv_func_open_slash="guessing yes" ;;
49 esac
50changequote([,])dnl
51 ])
52 rm -f conftest.sl conftest.tmp conftest.lnk
53 ])
54 case "$gl_cv_func_open_slash" in
55 *no)
56 AC_DEFINE([OPEN_TRAILING_SLASH_BUG], [1],
57 [Define to 1 if open() fails to recognize a trailing slash.])
58 ;;
59 esac
60])
diff --git a/gl/m4/open.m4 b/gl/m4/open.m4
new file mode 100644
index 0000000..94fa2bb
--- /dev/null
+++ b/gl/m4/open.m4
@@ -0,0 +1,56 @@
1# open.m4 serial 15
2dnl Copyright (C) 2007-2023 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_OPEN],
8[
9 AC_REQUIRE([AC_CANONICAL_HOST])
10 AC_REQUIRE([gl_PREPROC_O_CLOEXEC])
11 case "$host_os" in
12 mingw* | pw*)
13 REPLACE_OPEN=1
14 ;;
15 *)
16 dnl open("foo/") should not create a file when the file name has a
17 dnl trailing slash. FreeBSD only has the problem on symlinks.
18 AC_CHECK_FUNCS_ONCE([lstat])
19 if test "$gl_cv_macro_O_CLOEXEC" != yes; then
20 REPLACE_OPEN=1
21 fi
22 gl_OPEN_TRAILING_SLASH_BUG
23 case "$gl_cv_func_open_slash" in
24 *no)
25 REPLACE_OPEN=1
26 ;;
27 esac
28 ;;
29 esac
30 dnl Replace open() for supporting the gnulib-defined fchdir() function,
31 dnl to keep fchdir's bookkeeping up-to-date.
32 m4_ifdef([gl_FUNC_FCHDIR], [
33 if test $REPLACE_OPEN = 0; then
34 gl_TEST_FCHDIR
35 if test $HAVE_FCHDIR = 0; then
36 REPLACE_OPEN=1
37 fi
38 fi
39 ])
40 dnl Replace open() for supporting the gnulib-defined O_NONBLOCK flag.
41 m4_ifdef([gl_NONBLOCKING_IO], [
42 if test $REPLACE_OPEN = 0; then
43 gl_NONBLOCKING_IO
44 if test $gl_cv_have_open_O_NONBLOCK != yes; then
45 REPLACE_OPEN=1
46 fi
47 fi
48 ])
49])
50
51# Prerequisites of lib/open.c.
52AC_DEFUN([gl_PREREQ_OPEN],
53[
54 AC_REQUIRE([gl_PROMOTED_TYPE_MODE_T])
55 :
56])
diff --git a/gl/m4/pathmax.m4 b/gl/m4/pathmax.m4
new file mode 100644
index 0000000..6d47d2c
--- /dev/null
+++ b/gl/m4/pathmax.m4
@@ -0,0 +1,42 @@
1# pathmax.m4 serial 11
2dnl Copyright (C) 2002-2003, 2005-2006, 2009-2023 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_PATHMAX],
9[
10 dnl Prerequisites of lib/pathmax.h.
11 AC_CHECK_HEADERS_ONCE([sys/param.h])
12])
13
14# Expands to a piece of C program that defines PATH_MAX in the same way as
15# "pathmax.h" will do.
16AC_DEFUN([gl_PATHMAX_SNIPPET], [[
17/* Arrange to define PATH_MAX, like "pathmax.h" does. */
18#if HAVE_UNISTD_H
19# include <unistd.h>
20#endif
21#include <limits.h>
22#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
23# include <sys/param.h>
24#endif
25#if !defined PATH_MAX && defined MAXPATHLEN
26# define PATH_MAX MAXPATHLEN
27#endif
28#ifdef __hpux
29# undef PATH_MAX
30# define PATH_MAX 1024
31#endif
32#if defined _WIN32 && ! defined __CYGWIN__
33# undef PATH_MAX
34# define PATH_MAX 260
35#endif
36]])
37
38# Prerequisites of gl_PATHMAX_SNIPPET.
39AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ],
40[
41 AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
42])
diff --git a/gl/m4/pid_t.m4 b/gl/m4/pid_t.m4
new file mode 100644
index 0000000..0fd7d0a
--- /dev/null
+++ b/gl/m4/pid_t.m4
@@ -0,0 +1,38 @@
1# pid_t.m4 serial 4
2dnl Copyright (C) 2020-2023 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# The following implementation works around a problem in autoconf <= 2.69.
8m4_version_prereq([2.70], [], [
9
10dnl Define pid_t if the headers don't define it.
11AC_DEFUN([AC_TYPE_PID_T],
12[
13 AC_CHECK_TYPE([pid_t],
14 [],
15 [dnl On 64-bit native Windows, define it to the equivalent of 'intptr_t'
16 dnl (= 'long long' = '__int64'), because that is the return type
17 dnl of the _spawnv* functions
18 dnl <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/spawnvp-wspawnvp>
19 dnl and the argument type of the _cwait function
20 dnl <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/cwait>.
21 dnl Otherwise (on 32-bit Windows and on old Unix platforms), define it
22 dnl to 'int'.
23 AC_COMPILE_IFELSE(
24 [AC_LANG_PROGRAM([[
25 #if defined _WIN64 && !defined __CYGWIN__
26 LLP64
27 #endif
28 ]])
29 ],
30 [gl_pid_type='int'],
31 [gl_pid_type='__int64'])
32 AC_DEFINE_UNQUOTED([pid_t], [$gl_pid_type],
33 [Define as a signed integer type capable of holding a process identifier.])
34 ],
35 [AC_INCLUDES_DEFAULT])
36])
37
38])# m4_version_prereq 2.70
diff --git a/gl/m4/po.m4 b/gl/m4/po.m4
deleted file mode 100644
index 1c70b6c..0000000
--- a/gl/m4/po.m4
+++ /dev/null
@@ -1,453 +0,0 @@
1# po.m4 serial 21 (gettext-0.18.3)
2dnl Copyright (C) 1995-2013 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 Authors:
17dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
18dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
19
20AC_PREREQ([2.60])
21
22dnl Checks for all prerequisites of the po subdirectory.
23AC_DEFUN([AM_PO_SUBDIRS],
24[
25 AC_REQUIRE([AC_PROG_MAKE_SET])dnl
26 AC_REQUIRE([AC_PROG_INSTALL])dnl
27 AC_REQUIRE([AC_PROG_MKDIR_P])dnl
28 AC_REQUIRE([AC_PROG_SED])dnl
29 AC_REQUIRE([AM_NLS])dnl
30
31 dnl Release version of the gettext macros. This is used to ensure that
32 dnl the gettext macros and po/Makefile.in.in are in sync.
33 AC_SUBST([GETTEXT_MACRO_VERSION], [0.18])
34
35 dnl Perform the following tests also if --disable-nls has been given,
36 dnl because they are needed for "make dist" to work.
37
38 dnl Search for GNU msgfmt in the PATH.
39 dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions.
40 dnl The second test excludes FreeBSD msgfmt.
41 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
42 [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
43 (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
44 :)
45 AC_PATH_PROG([GMSGFMT], [gmsgfmt], [$MSGFMT])
46
47 dnl Test whether it is GNU msgfmt >= 0.15.
48changequote(,)dnl
49 case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in
50 '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;;
51 *) MSGFMT_015=$MSGFMT ;;
52 esac
53changequote([,])dnl
54 AC_SUBST([MSGFMT_015])
55changequote(,)dnl
56 case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in
57 '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;;
58 *) GMSGFMT_015=$GMSGFMT ;;
59 esac
60changequote([,])dnl
61 AC_SUBST([GMSGFMT_015])
62
63 dnl Search for GNU xgettext 0.12 or newer in the PATH.
64 dnl The first test excludes Solaris xgettext and early GNU xgettext versions.
65 dnl The second test excludes FreeBSD xgettext.
66 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
67 [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 &&
68 (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
69 :)
70 dnl Remove leftover from FreeBSD xgettext call.
71 rm -f messages.po
72
73 dnl Test whether it is GNU xgettext >= 0.15.
74changequote(,)dnl
75 case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in
76 '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;;
77 *) XGETTEXT_015=$XGETTEXT ;;
78 esac
79changequote([,])dnl
80 AC_SUBST([XGETTEXT_015])
81
82 dnl Search for GNU msgmerge 0.11 or newer in the PATH.
83 AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
84 [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :)
85
86 dnl Installation directories.
87 dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we
88 dnl have to define it here, so that it can be used in po/Makefile.
89 test -n "$localedir" || localedir='${datadir}/locale'
90 AC_SUBST([localedir])
91
92 dnl Support for AM_XGETTEXT_OPTION.
93 test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS=
94 AC_SUBST([XGETTEXT_EXTRA_OPTIONS])
95
96 AC_CONFIG_COMMANDS([po-directories], [[
97 for ac_file in $CONFIG_FILES; do
98 # Support "outfile[:infile[:infile...]]"
99 case "$ac_file" in
100 *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
101 esac
102 # PO directories have a Makefile.in generated from Makefile.in.in.
103 case "$ac_file" in */Makefile.in)
104 # Adjust a relative srcdir.
105 ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
106 ac_dir_suffix=/`echo "$ac_dir"|sed 's%^\./%%'`
107 ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
108 # In autoconf-2.13 it is called $ac_given_srcdir.
109 # In autoconf-2.50 it is called $srcdir.
110 test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
111 case "$ac_given_srcdir" in
112 .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
113 /*) top_srcdir="$ac_given_srcdir" ;;
114 *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
115 esac
116 # Treat a directory as a PO directory if and only if it has a
117 # POTFILES.in file. This allows packages to have multiple PO
118 # directories under different names or in different locations.
119 if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
120 rm -f "$ac_dir/POTFILES"
121 test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
122 gt_tab=`printf '\t'`
123 cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ${gt_tab}]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
124 POMAKEFILEDEPS="POTFILES.in"
125 # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
126 # on $ac_dir but don't depend on user-specified configuration
127 # parameters.
128 if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
129 # The LINGUAS file contains the set of available languages.
130 if test -n "$OBSOLETE_ALL_LINGUAS"; then
131 test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
132 fi
133 ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
134 # Hide the ALL_LINGUAS assignment from automake < 1.5.
135 eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
136 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
137 else
138 # The set of available languages was given in configure.in.
139 # Hide the ALL_LINGUAS assignment from automake < 1.5.
140 eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
141 fi
142 # Compute POFILES
143 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
144 # Compute UPDATEPOFILES
145 # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
146 # Compute DUMMYPOFILES
147 # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
148 # Compute GMOFILES
149 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
150 case "$ac_given_srcdir" in
151 .) srcdirpre= ;;
152 *) srcdirpre='$(srcdir)/' ;;
153 esac
154 POFILES=
155 UPDATEPOFILES=
156 DUMMYPOFILES=
157 GMOFILES=
158 for lang in $ALL_LINGUAS; do
159 POFILES="$POFILES $srcdirpre$lang.po"
160 UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
161 DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
162 GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
163 done
164 # CATALOGS depends on both $ac_dir and the user's LINGUAS
165 # environment variable.
166 INST_LINGUAS=
167 if test -n "$ALL_LINGUAS"; then
168 for presentlang in $ALL_LINGUAS; do
169 useit=no
170 if test "%UNSET%" != "$LINGUAS"; then
171 desiredlanguages="$LINGUAS"
172 else
173 desiredlanguages="$ALL_LINGUAS"
174 fi
175 for desiredlang in $desiredlanguages; do
176 # Use the presentlang catalog if desiredlang is
177 # a. equal to presentlang, or
178 # b. a variant of presentlang (because in this case,
179 # presentlang can be used as a fallback for messages
180 # which are not translated in the desiredlang catalog).
181 case "$desiredlang" in
182 "$presentlang"*) useit=yes;;
183 esac
184 done
185 if test $useit = yes; then
186 INST_LINGUAS="$INST_LINGUAS $presentlang"
187 fi
188 done
189 fi
190 CATALOGS=
191 if test -n "$INST_LINGUAS"; then
192 for lang in $INST_LINGUAS; do
193 CATALOGS="$CATALOGS $lang.gmo"
194 done
195 fi
196 test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
197 sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
198 for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
199 if test -f "$f"; then
200 case "$f" in
201 *.orig | *.bak | *~) ;;
202 *) cat "$f" >> "$ac_dir/Makefile" ;;
203 esac
204 fi
205 done
206 fi
207 ;;
208 esac
209 done]],
210 [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
211 # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
212 # from automake < 1.5.
213 eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
214 # Capture the value of LINGUAS because we need it to compute CATALOGS.
215 LINGUAS="${LINGUAS-%UNSET%}"
216 ])
217])
218
219dnl Postprocesses a Makefile in a directory containing PO files.
220AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE],
221[
222 # When this code is run, in config.status, two variables have already been
223 # set:
224 # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in,
225 # - LINGUAS is the value of the environment variable LINGUAS at configure
226 # time.
227
228changequote(,)dnl
229 # Adjust a relative srcdir.
230 ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
231 ac_dir_suffix=/`echo "$ac_dir"|sed 's%^\./%%'`
232 ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
233 # In autoconf-2.13 it is called $ac_given_srcdir.
234 # In autoconf-2.50 it is called $srcdir.
235 test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
236 case "$ac_given_srcdir" in
237 .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
238 /*) top_srcdir="$ac_given_srcdir" ;;
239 *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
240 esac
241
242 # Find a way to echo strings without interpreting backslash.
243 if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
244 gt_echo='echo'
245 else
246 if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
247 gt_echo='printf %s\n'
248 else
249 echo_func () {
250 cat <<EOT
251$*
252EOT
253 }
254 gt_echo='echo_func'
255 fi
256 fi
257
258 # A sed script that extracts the value of VARIABLE from a Makefile.
259 tab=`printf '\t'`
260 sed_x_variable='
261# Test if the hold space is empty.
262x
263s/P/P/
264x
265ta
266# Yes it was empty. Look if we have the expected variable definition.
267/^['"${tab}"' ]*VARIABLE['"${tab}"' ]*=/{
268 # Seen the first line of the variable definition.
269 s/^['"${tab}"' ]*VARIABLE['"${tab}"' ]*=//
270 ba
271}
272bd
273:a
274# Here we are processing a line from the variable definition.
275# Remove comment, more precisely replace it with a space.
276s/#.*$/ /
277# See if the line ends in a backslash.
278tb
279:b
280s/\\$//
281# Print the line, without the trailing backslash.
282p
283tc
284# There was no trailing backslash. The end of the variable definition is
285# reached. Clear the hold space.
286s/^.*$//
287x
288bd
289:c
290# A trailing backslash means that the variable definition continues in the
291# next line. Put a nonempty string into the hold space to indicate this.
292s/^.*$/P/
293x
294:d
295'
296changequote([,])dnl
297
298 # Set POTFILES to the value of the Makefile variable POTFILES.
299 sed_x_POTFILES=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`
300 POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"`
301 # Compute POTFILES_DEPS as
302 # $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
303 POTFILES_DEPS=
304 for file in $POTFILES; do
305 POTFILES_DEPS="$POTFILES_DEPS "'$(top_srcdir)/'"$file"
306 done
307 POMAKEFILEDEPS=""
308
309 if test -n "$OBSOLETE_ALL_LINGUAS"; then
310 test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
311 fi
312 if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
313 # The LINGUAS file contains the set of available languages.
314 ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
315 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
316 else
317 # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS.
318 sed_x_LINGUAS=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`
319 ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
320 fi
321 # Hide the ALL_LINGUAS assignment from automake < 1.5.
322 eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
323 # Compute POFILES
324 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
325 # Compute UPDATEPOFILES
326 # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
327 # Compute DUMMYPOFILES
328 # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
329 # Compute GMOFILES
330 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
331 # Compute PROPERTIESFILES
332 # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties)
333 # Compute CLASSFILES
334 # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class)
335 # Compute QMFILES
336 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
337 # Compute MSGFILES
338 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang)).msg)
339 # Compute RESOURCESDLLFILES
340 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang))/$(DOMAIN).resources.dll)
341 case "$ac_given_srcdir" in
342 .) srcdirpre= ;;
343 *) srcdirpre='$(srcdir)/' ;;
344 esac
345 POFILES=
346 UPDATEPOFILES=
347 DUMMYPOFILES=
348 GMOFILES=
349 PROPERTIESFILES=
350 CLASSFILES=
351 QMFILES=
352 MSGFILES=
353 RESOURCESDLLFILES=
354 for lang in $ALL_LINGUAS; do
355 POFILES="$POFILES $srcdirpre$lang.po"
356 UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
357 DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
358 GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
359 PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties"
360 CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class"
361 QMFILES="$QMFILES $srcdirpre$lang.qm"
362 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
363 MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
364 frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
365 RESOURCESDLLFILES="$RESOURCESDLLFILES $srcdirpre$frobbedlang/\$(DOMAIN).resources.dll"
366 done
367 # CATALOGS depends on both $ac_dir and the user's LINGUAS
368 # environment variable.
369 INST_LINGUAS=
370 if test -n "$ALL_LINGUAS"; then
371 for presentlang in $ALL_LINGUAS; do
372 useit=no
373 if test "%UNSET%" != "$LINGUAS"; then
374 desiredlanguages="$LINGUAS"
375 else
376 desiredlanguages="$ALL_LINGUAS"
377 fi
378 for desiredlang in $desiredlanguages; do
379 # Use the presentlang catalog if desiredlang is
380 # a. equal to presentlang, or
381 # b. a variant of presentlang (because in this case,
382 # presentlang can be used as a fallback for messages
383 # which are not translated in the desiredlang catalog).
384 case "$desiredlang" in
385 "$presentlang"*) useit=yes;;
386 esac
387 done
388 if test $useit = yes; then
389 INST_LINGUAS="$INST_LINGUAS $presentlang"
390 fi
391 done
392 fi
393 CATALOGS=
394 JAVACATALOGS=
395 QTCATALOGS=
396 TCLCATALOGS=
397 CSHARPCATALOGS=
398 if test -n "$INST_LINGUAS"; then
399 for lang in $INST_LINGUAS; do
400 CATALOGS="$CATALOGS $lang.gmo"
401 JAVACATALOGS="$JAVACATALOGS \$(DOMAIN)_$lang.properties"
402 QTCATALOGS="$QTCATALOGS $lang.qm"
403 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
404 TCLCATALOGS="$TCLCATALOGS $frobbedlang.msg"
405 frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
406 CSHARPCATALOGS="$CSHARPCATALOGS $frobbedlang/\$(DOMAIN).resources.dll"
407 done
408 fi
409
410 sed -e "s|@POTFILES_DEPS@|$POTFILES_DEPS|g" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@PROPERTIESFILES@|$PROPERTIESFILES|g" -e "s|@CLASSFILES@|$CLASSFILES|g" -e "s|@QMFILES@|$QMFILES|g" -e "s|@MSGFILES@|$MSGFILES|g" -e "s|@RESOURCESDLLFILES@|$RESOURCESDLLFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@JAVACATALOGS@|$JAVACATALOGS|g" -e "s|@QTCATALOGS@|$QTCATALOGS|g" -e "s|@TCLCATALOGS@|$TCLCATALOGS|g" -e "s|@CSHARPCATALOGS@|$CSHARPCATALOGS|g" -e 's,^#distdir:,distdir:,' < "$ac_file" > "$ac_file.tmp"
411 tab=`printf '\t'`
412 if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then
413 # Add dependencies that cannot be formulated as a simple suffix rule.
414 for lang in $ALL_LINGUAS; do
415 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
416 cat >> "$ac_file.tmp" <<EOF
417$frobbedlang.msg: $lang.po
418${tab}@echo "\$(MSGFMT) -c --tcl -d \$(srcdir) -l $lang $srcdirpre$lang.po"; \
419${tab}\$(MSGFMT) -c --tcl -d "\$(srcdir)" -l $lang $srcdirpre$lang.po || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
420EOF
421 done
422 fi
423 if grep -l '@CSHARPCATALOGS@' "$ac_file" > /dev/null; then
424 # Add dependencies that cannot be formulated as a simple suffix rule.
425 for lang in $ALL_LINGUAS; do
426 frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'`
427 cat >> "$ac_file.tmp" <<EOF
428$frobbedlang/\$(DOMAIN).resources.dll: $lang.po
429${tab}@echo "\$(MSGFMT) -c --csharp -d \$(srcdir) -l $lang $srcdirpre$lang.po -r \$(DOMAIN)"; \
430${tab}\$(MSGFMT) -c --csharp -d "\$(srcdir)" -l $lang $srcdirpre$lang.po -r "\$(DOMAIN)" || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
431EOF
432 done
433 fi
434 if test -n "$POMAKEFILEDEPS"; then
435 cat >> "$ac_file.tmp" <<EOF
436Makefile: $POMAKEFILEDEPS
437EOF
438 fi
439 mv "$ac_file.tmp" "$ac_file"
440])
441
442dnl Initializes the accumulator used by AM_XGETTEXT_OPTION.
443AC_DEFUN([AM_XGETTEXT_OPTION_INIT],
444[
445 XGETTEXT_EXTRA_OPTIONS=
446])
447
448dnl Registers an option to be passed to xgettext in the po subdirectory.
449AC_DEFUN([AM_XGETTEXT_OPTION],
450[
451 AC_REQUIRE([AM_XGETTEXT_OPTION_INIT])
452 XGETTEXT_EXTRA_OPTIONS="$XGETTEXT_EXTRA_OPTIONS $1"
453])
diff --git a/gl/m4/printf-posix.m4 b/gl/m4/printf-posix.m4
deleted file mode 100644
index d7dfb60..0000000
--- a/gl/m4/printf-posix.m4
+++ /dev/null
@@ -1,48 +0,0 @@
1# printf-posix.m4 serial 6 (gettext-0.18.2)
2dnl Copyright (C) 2003, 2007, 2009-2013 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 printf() function supports POSIX/XSI format strings with
9dnl positions.
10
11AC_DEFUN([gt_PRINTF_POSIX],
12[
13 AC_REQUIRE([AC_PROG_CC])
14 AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings],
15 gt_cv_func_printf_posix,
16 [
17 AC_RUN_IFELSE(
18 [AC_LANG_SOURCE([[
19#include <stdio.h>
20#include <string.h>
21/* The string "%2$d %1$d", with dollar characters protected from the shell's
22 dollar expansion (possibly an autoconf bug). */
23static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
24static char buf[100];
25int main ()
26{
27 sprintf (buf, format, 33, 55);
28 return (strcmp (buf, "55 33") != 0);
29}]])],
30 [gt_cv_func_printf_posix=yes],
31 [gt_cv_func_printf_posix=no],
32 [
33 AC_EGREP_CPP([notposix], [
34#if defined __NetBSD__ || defined __BEOS__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__
35 notposix
36#endif
37 ],
38 [gt_cv_func_printf_posix="guessing no"],
39 [gt_cv_func_printf_posix="guessing yes"])
40 ])
41 ])
42 case $gt_cv_func_printf_posix in
43 *yes)
44 AC_DEFINE([HAVE_POSIX_PRINTF], [1],
45 [Define if your printf() function supports format strings with positions.])
46 ;;
47 esac
48])
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4
index ef44f78..4e65abc 100644
--- a/gl/m4/printf.m4
+++ b/gl/m4/printf.m4
@@ -1,5 +1,5 @@
1# printf.m4 serial 50 1# printf.m4 serial 73
2dnl Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007-2023 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.
@@ -38,6 +38,8 @@ int main ()
38 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0 38 if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
39 || strcmp (buf, "12345671 33") != 0) 39 || strcmp (buf, "12345671 33") != 0)
40 result |= 1; 40 result |= 1;
41#else
42 result |= 1;
41#endif 43#endif
42 buf[0] = '\0'; 44 buf[0] = '\0';
43 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0 45 if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
@@ -56,13 +58,16 @@ int main ()
56 [gl_cv_func_printf_sizes_c99=yes], 58 [gl_cv_func_printf_sizes_c99=yes],
57 [gl_cv_func_printf_sizes_c99=no], 59 [gl_cv_func_printf_sizes_c99=no],
58 [ 60 [
59changequote(,)dnl
60 case "$host_os" in 61 case "$host_os" in
62changequote(,)dnl
61 # Guess yes on glibc systems. 63 # Guess yes on glibc systems.
62 *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";; 64 *-gnu* | gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
65 # Guess yes on musl systems.
66 *-musl*) gl_cv_func_printf_sizes_c99="guessing yes";;
63 # Guess yes on FreeBSD >= 5. 67 # Guess yes on FreeBSD >= 5.
64 freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";; 68 freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
65 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";; 69 freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
70 midnightbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
66 # Guess yes on Mac OS X >= 10.3. 71 # Guess yes on Mac OS X >= 10.3.
67 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";; 72 darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
68 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";; 73 darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
@@ -77,10 +82,21 @@ changequote(,)dnl
77 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 82 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
78 gl_cv_func_printf_sizes_c99="guessing no";; 83 gl_cv_func_printf_sizes_c99="guessing no";;
79 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; 84 netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
80 # If we don't know, assume the worst. 85 # Guess yes on Android.
81 *) gl_cv_func_printf_sizes_c99="guessing no";; 86 linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";;
82 esac
83changequote([,])dnl 87changequote([,])dnl
88 # Guess yes on MSVC, no on mingw.
89 mingw*) AC_EGREP_CPP([Known], [
90#ifdef _MSC_VER
91 Known
92#endif
93 ],
94 [gl_cv_func_printf_sizes_c99="guessing yes"],
95 [gl_cv_func_printf_sizes_c99="guessing no"])
96 ;;
97 # If we don't know, obey --enable-cross-guesses.
98 *) gl_cv_func_printf_sizes_c99="$gl_cross_guess_normal";;
99 esac
84 ]) 100 ])
85 ]) 101 ])
86]) 102])
@@ -120,14 +136,22 @@ int main ()
120}]])], 136}]])],
121 [gl_cv_func_printf_long_double=yes], 137 [gl_cv_func_printf_long_double=yes],
122 [gl_cv_func_printf_long_double=no], 138 [gl_cv_func_printf_long_double=no],
123 [ 139 [case "$host_os" in
124changequote(,)dnl 140 # Guess no on BeOS.
125 case "$host_os" in 141 beos*) gl_cv_func_printf_long_double="guessing no";;
126 beos*) gl_cv_func_printf_long_double="guessing no";; 142 # Guess yes on Android.
127 mingw* | pw*) gl_cv_func_printf_long_double="guessing no";; 143 linux*-android*) gl_cv_func_printf_long_double="guessing yes";;
128 *) gl_cv_func_printf_long_double="guessing yes";; 144 # Guess yes on MSVC, no on mingw.
145 mingw*) AC_EGREP_CPP([Known], [
146#ifdef _MSC_VER
147 Known
148#endif
149 ],
150 [gl_cv_func_printf_long_double="guessing yes"],
151 [gl_cv_func_printf_long_double="guessing no"])
152 ;;
153 *) gl_cv_func_printf_long_double="guessing yes";;
129 esac 154 esac
130changequote([,])dnl
131 ]) 155 ])
132 ]) 156 ])
133]) 157])
@@ -215,13 +239,16 @@ int main ()
215 [gl_cv_func_printf_infinite=yes], 239 [gl_cv_func_printf_infinite=yes],
216 [gl_cv_func_printf_infinite=no], 240 [gl_cv_func_printf_infinite=no],
217 [ 241 [
218changequote(,)dnl
219 case "$host_os" in 242 case "$host_os" in
243changequote(,)dnl
220 # Guess yes on glibc systems. 244 # Guess yes on glibc systems.
221 *-gnu*) gl_cv_func_printf_infinite="guessing yes";; 245 *-gnu* | gnu*) gl_cv_func_printf_infinite="guessing yes";;
246 # Guess yes on musl systems.
247 *-musl*) gl_cv_func_printf_infinite="guessing yes";;
222 # Guess yes on FreeBSD >= 6. 248 # Guess yes on FreeBSD >= 6.
223 freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";; 249 freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
224 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";; 250 freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
251 midnightbsd*) gl_cv_func_printf_infinite="guessing yes";;
225 # Guess yes on Mac OS X >= 10.3. 252 # Guess yes on Mac OS X >= 10.3.
226 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";; 253 darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
227 darwin*) gl_cv_func_printf_infinite="guessing yes";; 254 darwin*) gl_cv_func_printf_infinite="guessing yes";;
@@ -232,12 +259,26 @@ changequote(,)dnl
232 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) 259 netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
233 gl_cv_func_printf_infinite="guessing no";; 260 gl_cv_func_printf_infinite="guessing no";;
234 netbsd*) gl_cv_func_printf_infinite="guessing yes";; 261 netbsd*) gl_cv_func_printf_infinite="guessing yes";;
262 # Guess yes on OpenBSD >= 6.0.
263 openbsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
264 openbsd*) gl_cv_func_printf_infinite="guessing yes";;
235 # Guess yes on BeOS. 265 # Guess yes on BeOS.
236 beos*) gl_cv_func_printf_infinite="guessing yes";; 266 beos*) gl_cv_func_printf_infinite="guessing yes";;
237 # If we don't know, assume the worst. 267 # Guess no on Android.
238 *) gl_cv_func_printf_infinite="guessing no";; 268 linux*-android*) gl_cv_func_printf_infinite="guessing no";;
239 esac
240changequote([,])dnl 269changequote([,])dnl
270 # Guess yes on MSVC, no on mingw.
271 mingw*) AC_EGREP_CPP([Known], [
272#ifdef _MSC_VER
273 Known
274#endif
275 ],
276 [gl_cv_func_printf_infinite="guessing yes"],
277 [gl_cv_func_printf_infinite="guessing no"])
278 ;;
279 # If we don't know, obey --enable-cross-guesses.
280 *) gl_cv_func_printf_infinite="$gl_cross_guess_normal";;
281 esac
241 ]) 282 ])
242 ]) 283 ])
243]) 284])
@@ -328,7 +369,7 @@ int main ()
328# ifdef WORDS_BIGENDIAN 369# ifdef WORDS_BIGENDIAN
329# define LDBL80_WORDS(exponent,manthi,mantlo) \ 370# define LDBL80_WORDS(exponent,manthi,mantlo) \
330 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ 371 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
331 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \ 372 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
332 (unsigned int) (mantlo) << 16 \ 373 (unsigned int) (mantlo) << 16 \
333 } 374 }
334# else 375# else
@@ -365,66 +406,51 @@ int main ()
365 { /* Pseudo-NaN. */ 406 { /* Pseudo-NaN. */
366 static union { unsigned int word[4]; long double value; } x = 407 static union { unsigned int word[4]; long double value; } x =
367 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; 408 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
368 if (sprintf (buf, "%Lf", x.value) < 0 409 if (sprintf (buf, "%Lf", x.value) <= 0)
369 || !strisnan (buf, 0, strlen (buf)))
370 result |= 4; 410 result |= 4;
371 if (sprintf (buf, "%Le", x.value) < 0 411 if (sprintf (buf, "%Le", x.value) <= 0)
372 || !strisnan (buf, 0, strlen (buf)))
373 result |= 4; 412 result |= 4;
374 if (sprintf (buf, "%Lg", x.value) < 0 413 if (sprintf (buf, "%Lg", x.value) <= 0)
375 || !strisnan (buf, 0, strlen (buf)))
376 result |= 4; 414 result |= 4;
377 } 415 }
378 { /* Pseudo-Infinity. */ 416 { /* Pseudo-Infinity. */
379 static union { unsigned int word[4]; long double value; } x = 417 static union { unsigned int word[4]; long double value; } x =
380 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; 418 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
381 if (sprintf (buf, "%Lf", x.value) < 0 419 if (sprintf (buf, "%Lf", x.value) <= 0)
382 || !strisnan (buf, 0, strlen (buf)))
383 result |= 8; 420 result |= 8;
384 if (sprintf (buf, "%Le", x.value) < 0 421 if (sprintf (buf, "%Le", x.value) <= 0)
385 || !strisnan (buf, 0, strlen (buf)))
386 result |= 8; 422 result |= 8;
387 if (sprintf (buf, "%Lg", x.value) < 0 423 if (sprintf (buf, "%Lg", x.value) <= 0)
388 || !strisnan (buf, 0, strlen (buf)))
389 result |= 8; 424 result |= 8;
390 } 425 }
391 { /* Pseudo-Zero. */ 426 { /* Pseudo-Zero. */
392 static union { unsigned int word[4]; long double value; } x = 427 static union { unsigned int word[4]; long double value; } x =
393 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; 428 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
394 if (sprintf (buf, "%Lf", x.value) < 0 429 if (sprintf (buf, "%Lf", x.value) <= 0)
395 || !strisnan (buf, 0, strlen (buf)))
396 result |= 16; 430 result |= 16;
397 if (sprintf (buf, "%Le", x.value) < 0 431 if (sprintf (buf, "%Le", x.value) <= 0)
398 || !strisnan (buf, 0, strlen (buf)))
399 result |= 16; 432 result |= 16;
400 if (sprintf (buf, "%Lg", x.value) < 0 433 if (sprintf (buf, "%Lg", x.value) <= 0)
401 || !strisnan (buf, 0, strlen (buf)))
402 result |= 16; 434 result |= 16;
403 } 435 }
404 { /* Unnormalized number. */ 436 { /* Unnormalized number. */
405 static union { unsigned int word[4]; long double value; } x = 437 static union { unsigned int word[4]; long double value; } x =
406 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; 438 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
407 if (sprintf (buf, "%Lf", x.value) < 0 439 if (sprintf (buf, "%Lf", x.value) <= 0)
408 || !strisnan (buf, 0, strlen (buf)))
409 result |= 32; 440 result |= 32;
410 if (sprintf (buf, "%Le", x.value) < 0 441 if (sprintf (buf, "%Le", x.value) <= 0)
411 || !strisnan (buf, 0, strlen (buf)))
412 result |= 32; 442 result |= 32;
413 if (sprintf (buf, "%Lg", x.value) < 0 443 if (sprintf (buf, "%Lg", x.value) <= 0)
414 || !strisnan (buf, 0, strlen (buf)))
415 result |= 32; 444 result |= 32;
416 } 445 }
417 { /* Pseudo-Denormal. */ 446 { /* Pseudo-Denormal. */
418 static union { unsigned int word[4]; long double value; } x = 447 static union { unsigned int word[4]; long double value; } x =
419 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; 448 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
420 if (sprintf (buf, "%Lf", x.value) < 0 449 if (sprintf (buf, "%Lf", x.value) <= 0)
421 || !strisnan (buf, 0, strlen (buf)))
422 result |= 64; 450 result |= 64;
423 if (sprintf (buf, "%Le", x.value) < 0 451 if (sprintf (buf, "%Le", x.value) <= 0)
424 || !strisnan (buf, 0, strlen (buf)))
425 result |= 64; 452 result |= 64;
426 if (sprintf (buf, "%Lg", x.value) < 0 453 if (sprintf (buf, "%Lg", x.value) <= 0)
427 || !strisnan (buf, 0, strlen (buf)))
428 result |= 64; 454 result |= 64;
429 } 455 }
430#endif 456#endif
@@ -432,27 +458,43 @@ int main ()
432}]])], 458}]])],
433 [gl_cv_func_printf_infinite_long_double=yes], 459 [gl_cv_func_printf_infinite_long_double=yes],
434 [gl_cv_func_printf_infinite_long_double=no], 460 [gl_cv_func_printf_infinite_long_double=no],
435 [ 461 [case "$host_cpu" in
436changequote(,)dnl
437 case "$host_cpu" in
438 # Guess no on ia64, x86_64, i386. 462 # Guess no on ia64, x86_64, i386.
439 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";; 463 ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
440 *) 464 *)
441 case "$host_os" in 465 case "$host_os" in
466changequote(,)dnl
442 # Guess yes on glibc systems. 467 # Guess yes on glibc systems.
443 *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";; 468 *-gnu* | gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
469 # Guess yes on musl systems.
470 *-musl*) gl_cv_func_printf_infinite_long_double="guessing yes";;
444 # Guess yes on FreeBSD >= 6. 471 # Guess yes on FreeBSD >= 6.
445 freebsd[1-5]*) gl_cv_func_printf_infinite_long_double="guessing no";; 472 freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
446 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";; 473 freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
474 midnightbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
447 # Guess yes on HP-UX >= 11. 475 # Guess yes on HP-UX >= 11.
448 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";; 476 hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
449 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";; 477 hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
450 # If we don't know, assume the worst. 478 # Guess yes on OpenBSD >= 6.0.
451 *) gl_cv_func_printf_infinite_long_double="guessing no";; 479 openbsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
480 openbsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
481 # Guess no on Android.
482 linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";;
483changequote([,])dnl
484 # Guess yes on MSVC, no on mingw.
485 mingw*) AC_EGREP_CPP([Known], [
486#ifdef _MSC_VER
487 Known
488#endif
489 ],
490 [gl_cv_func_printf_infinite_long_double="guessing yes"],
491 [gl_cv_func_printf_infinite_long_double="guessing no"])
492 ;;
493 # If we don't know, obey --enable-cross-guesses.
494 *) gl_cv_func_printf_infinite_long_double="$gl_cross_guess_normal";;
452 esac 495 esac
453 ;; 496 ;;
454 esac 497 esac
455changequote([,])dnl
456 ]) 498 ])
457 ]) 499 ])
458 ;; 500 ;;
@@ -495,15 +537,22 @@ int main ()
495 && strcmp (buf, "-0X6.488P-1 33") != 0 537 && strcmp (buf, "-0X6.488P-1 33") != 0
496 && strcmp (buf, "-0XC.91P-2 33") != 0)) 538 && strcmp (buf, "-0XC.91P-2 33") != 0))
497 result |= 2; 539 result |= 2;
498 /* This catches a FreeBSD 6.1 bug: it doesn't round. */ 540 /* This catches a FreeBSD 13.0 bug: it doesn't round. */
499 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0 541 if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
500 || (strcmp (buf, "0x1.83p+0 33") != 0 542 || (strcmp (buf, "0x1.83p+0 33") != 0
501 && strcmp (buf, "0x3.05p-1 33") != 0 543 && strcmp (buf, "0x3.05p-1 33") != 0
502 && strcmp (buf, "0x6.0ap-2 33") != 0 544 && strcmp (buf, "0x6.0ap-2 33") != 0
503 && strcmp (buf, "0xc.14p-3 33") != 0)) 545 && strcmp (buf, "0xc.14p-3 33") != 0))
504 result |= 4; 546 result |= 4;
547 /* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
548 if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
549 || (strcmp (buf, "0x2p+0 33") != 0
550 && strcmp (buf, "0x3p-1 33") != 0
551 && strcmp (buf, "0x6p-2 33") != 0
552 && strcmp (buf, "0xcp-3 33") != 0))
553 result |= 4;
505 /* This catches a FreeBSD 6.1 bug. See 554 /* This catches a FreeBSD 6.1 bug. See
506 <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ 555 <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
507 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0 556 if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
508 || buf[0] == '0') 557 || buf[0] == '0')
509 result |= 8; 558 result |= 8;
@@ -515,7 +564,7 @@ int main ()
515 && strcmp (buf, "0x8.0p-2") != 0)) 564 && strcmp (buf, "0x8.0p-2") != 0))
516 result |= 16; 565 result |= 16;
517 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a 566 /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
518 glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */ 567 glibc 2.4 bug <https://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
519 if (sprintf (buf, "%.1La", 1.999L) < 0 568 if (sprintf (buf, "%.1La", 1.999L) < 0
520 || (strcmp (buf, "0x1.0p+1") != 0 569 || (strcmp (buf, "0x1.0p+1") != 0
521 && strcmp (buf, "0x2.0p+0") != 0 570 && strcmp (buf, "0x2.0p+0") != 0
@@ -529,7 +578,7 @@ int main ()
529 [ 578 [
530 case "$host_os" in 579 case "$host_os" in
531 # Guess yes on glibc >= 2.5 systems. 580 # Guess yes on glibc >= 2.5 systems.
532 *-gnu*) 581 *-gnu* | gnu*)
533 AC_EGREP_CPP([BZ2908], [ 582 AC_EGREP_CPP([BZ2908], [
534 #include <features.h> 583 #include <features.h>
535 #ifdef __GNU_LIBRARY__ 584 #ifdef __GNU_LIBRARY__
@@ -541,8 +590,14 @@ int main ()
541 [gl_cv_func_printf_directive_a="guessing yes"], 590 [gl_cv_func_printf_directive_a="guessing yes"],
542 [gl_cv_func_printf_directive_a="guessing no"]) 591 [gl_cv_func_printf_directive_a="guessing no"])
543 ;; 592 ;;
544 # If we don't know, assume the worst. 593 # Guess yes on musl systems.
545 *) gl_cv_func_printf_directive_a="guessing no";; 594 *-musl*) gl_cv_func_printf_directive_a="guessing yes";;
595 # Guess no on Android.
596 linux*-android*) gl_cv_func_printf_directive_a="guessing no";;
597 # Guess no on native Windows.
598 mingw*) gl_cv_func_printf_directive_a="guessing no";;
599 # If we don't know, obey --enable-cross-guesses.
600 *) gl_cv_func_printf_directive_a="$gl_cross_guess_normal";;
546 esac 601 esac
547 ]) 602 ])
548 ]) 603 ])
@@ -583,23 +638,40 @@ int main ()
583 [gl_cv_func_printf_directive_f=yes], 638 [gl_cv_func_printf_directive_f=yes],
584 [gl_cv_func_printf_directive_f=no], 639 [gl_cv_func_printf_directive_f=no],
585 [ 640 [
586changequote(,)dnl
587 case "$host_os" in 641 case "$host_os" in
642changequote(,)dnl
588 # Guess yes on glibc systems. 643 # Guess yes on glibc systems.
589 *-gnu*) gl_cv_func_printf_directive_f="guessing yes";; 644 *-gnu* | gnu*) gl_cv_func_printf_directive_f="guessing yes";;
645 # Guess yes on musl systems.
646 *-musl*) gl_cv_func_printf_directive_f="guessing yes";;
590 # Guess yes on FreeBSD >= 6. 647 # Guess yes on FreeBSD >= 6.
591 freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";; 648 freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
592 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";; 649 freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
650 midnightbsd*) gl_cv_func_printf_directive_f="guessing yes";;
593 # Guess yes on Mac OS X >= 10.3. 651 # Guess yes on Mac OS X >= 10.3.
594 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";; 652 darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
595 darwin*) gl_cv_func_printf_directive_f="guessing yes";; 653 darwin*) gl_cv_func_printf_directive_f="guessing yes";;
654 # Guess yes on OpenBSD >= 6.0.
655 openbsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
656 openbsd*) gl_cv_func_printf_directive_f="guessing yes";;
596 # Guess yes on Solaris >= 2.10. 657 # Guess yes on Solaris >= 2.10.
597 solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";; 658 solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";;
598 solaris*) gl_cv_func_printf_sizes_c99="guessing no";; 659 solaris*) gl_cv_func_printf_directive_f="guessing no";;
599 # If we don't know, assume the worst. 660 # Guess no on Android.
600 *) gl_cv_func_printf_directive_f="guessing no";; 661 linux*-android*) gl_cv_func_printf_directive_f="guessing no";;
601 esac
602changequote([,])dnl 662changequote([,])dnl
663 # Guess yes on MSVC, no on mingw.
664 mingw*) AC_EGREP_CPP([Known], [
665#ifdef _MSC_VER
666 Known
667#endif
668 ],
669 [gl_cv_func_printf_directive_f="guessing yes"],
670 [gl_cv_func_printf_directive_f="guessing no"])
671 ;;
672 # If we don't know, obey --enable-cross-guesses.
673 *) gl_cv_func_printf_directive_f="$gl_cross_guess_normal";;
674 esac
603 ]) 675 ])
604 ]) 676 ])
605]) 677])
@@ -621,7 +693,10 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
621#include <stdlib.h> 693#include <stdlib.h>
622#include <string.h> 694#include <string.h>
623#ifdef _MSC_VER 695#ifdef _MSC_VER
624/* See page about "Parameter Validation" on msdn.microsoft.com. */ 696#include <inttypes.h>
697/* See page about "Parameter Validation" on msdn.microsoft.com.
698 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation>
699 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler> */
625static void cdecl 700static void cdecl
626invalid_parameter_handler (const wchar_t *expression, 701invalid_parameter_handler (const wchar_t *expression,
627 const wchar_t *function, 702 const wchar_t *function,
@@ -651,13 +726,23 @@ int main ()
651}]])], 726}]])],
652 [gl_cv_func_printf_directive_n=yes], 727 [gl_cv_func_printf_directive_n=yes],
653 [gl_cv_func_printf_directive_n=no], 728 [gl_cv_func_printf_directive_n=no],
654 [ 729 [case "$host_os" in
655changequote(,)dnl 730 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
656 case "$host_os" in 731 *-gnu* | gnu*) AC_COMPILE_IFELSE(
657 mingw*) gl_cv_func_printf_directive_n="guessing no";; 732 [AC_LANG_SOURCE(
658 *) gl_cv_func_printf_directive_n="guessing yes";; 733 [[#if _FORTIFY_SOURCE >= 2
734 error fail
735 #endif
736 ]])],
737 [gl_cv_func_printf_directive_n="guessing yes"],
738 [gl_cv_func_printf_directive_n="guessing no"])
739 ;;
740 # Guess no on Android.
741 linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
742 # Guess no on native Windows.
743 mingw*) gl_cv_func_printf_directive_n="guessing no";;
744 *) gl_cv_func_printf_directive_n="guessing yes";;
659 esac 745 esac
660changequote([,])dnl
661 ]) 746 ])
662 ]) 747 ])
663]) 748])
@@ -678,13 +763,7 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
678 [ 763 [
679 AC_RUN_IFELSE( 764 AC_RUN_IFELSE(
680 [AC_LANG_SOURCE([[ 765 [AC_LANG_SOURCE([[
681/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
682 <wchar.h>.
683 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
684 included before <wchar.h>. */
685#include <stddef.h>
686#include <stdio.h> 766#include <stdio.h>
687#include <time.h>
688#include <wchar.h> 767#include <wchar.h>
689#include <string.h> 768#include <string.h>
690int main () 769int main ()
@@ -732,11 +811,17 @@ int main ()
732 [ 811 [
733changequote(,)dnl 812changequote(,)dnl
734 case "$host_os" in 813 case "$host_os" in
735 openbsd*) gl_cv_func_printf_directive_ls="guessing no";; 814 # Guess yes on OpenBSD >= 6.0.
815 openbsd[1-5].*) gl_cv_func_printf_directive_ls="guessing no";;
816 openbsd*) gl_cv_func_printf_directive_ls="guessing yes";;
736 irix*) gl_cv_func_printf_directive_ls="guessing no";; 817 irix*) gl_cv_func_printf_directive_ls="guessing no";;
737 solaris*) gl_cv_func_printf_directive_ls="guessing no";; 818 solaris*) gl_cv_func_printf_directive_ls="guessing no";;
738 cygwin*) gl_cv_func_printf_directive_ls="guessing no";; 819 cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
739 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";; 820 beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
821 # Guess no on Android.
822 linux*-android*) gl_cv_func_printf_directive_ls="guessing no";;
823 # Guess yes on native Windows.
824 mingw*) gl_cv_func_printf_directive_ls="guessing yes";;
740 *) gl_cv_func_printf_directive_ls="guessing yes";; 825 *) gl_cv_func_printf_directive_ls="guessing yes";;
741 esac 826 esac
742changequote([,])dnl 827changequote([,])dnl
@@ -774,10 +859,13 @@ int main ()
774changequote(,)dnl 859changequote(,)dnl
775 case "$host_os" in 860 case "$host_os" in
776 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*) 861 netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
777 gl_cv_func_printf_positions="guessing no";; 862 gl_cv_func_printf_positions="guessing no";;
778 beos*) gl_cv_func_printf_positions="guessing no";; 863 beos*) gl_cv_func_printf_positions="guessing no";;
779 mingw* | pw*) gl_cv_func_printf_positions="guessing no";; 864 # Guess yes on Android.
780 *) gl_cv_func_printf_positions="guessing yes";; 865 linux*-android*) gl_cv_func_printf_positions="guessing yes";;
866 # Guess no on native Windows.
867 mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
868 *) gl_cv_func_printf_positions="guessing yes";;
781 esac 869 esac
782changequote([,])dnl 870changequote([,])dnl
783 ]) 871 ])
@@ -812,10 +900,13 @@ int main ()
812 [ 900 [
813changequote(,)dnl 901changequote(,)dnl
814 case "$host_os" in 902 case "$host_os" in
815 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";; 903 cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
816 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; 904 netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
817 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; 905 # Guess no on Android.
818 *) gl_cv_func_printf_flag_grouping="guessing yes";; 906 linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";;
907 # Guess no on native Windows.
908 mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
909 *) gl_cv_func_printf_flag_grouping="guessing yes";;
819 esac 910 esac
820changequote([,])dnl 911changequote([,])dnl
821 ]) 912 ])
@@ -824,7 +915,7 @@ changequote([,])dnl
824 915
825dnl Test whether the *printf family of functions supports the - flag correctly. 916dnl Test whether the *printf family of functions supports the - flag correctly.
826dnl (ISO C99.) See 917dnl (ISO C99.) See
827dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html> 918dnl <https://lists.gnu.org/r/bug-coreutils/2008-02/msg00035.html>
828dnl Result is gl_cv_func_printf_flag_leftadjust. 919dnl Result is gl_cv_func_printf_flag_leftadjust.
829 920
830AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST], 921AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
@@ -852,12 +943,16 @@ int main ()
852 [ 943 [
853changequote(,)dnl 944changequote(,)dnl
854 case "$host_os" in 945 case "$host_os" in
855 # Guess yes on HP-UX 11. 946 # Guess yes on HP-UX 11.
856 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";; 947 hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
857 # Guess no on HP-UX 10 and older. 948 # Guess no on HP-UX 10 and older.
858 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";; 949 hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
859 # Guess yes otherwise. 950 # Guess yes on Android.
860 *) gl_cv_func_printf_flag_leftadjust="guessing yes";; 951 linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
952 # Guess yes on native Windows.
953 mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
954 # Guess yes otherwise.
955 *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
861 esac 956 esac
862changequote([,])dnl 957changequote([,])dnl
863 ]) 958 ])
@@ -866,7 +961,7 @@ changequote([,])dnl
866 961
867dnl Test whether the *printf family of functions supports padding of non-finite 962dnl Test whether the *printf family of functions supports padding of non-finite
868dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See 963dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
869dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> 964dnl <https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html>
870dnl Result is gl_cv_func_printf_flag_zero. 965dnl Result is gl_cv_func_printf_flag_zero.
871 966
872AC_DEFUN([gl_PRINTF_FLAG_ZERO], 967AC_DEFUN([gl_PRINTF_FLAG_ZERO],
@@ -895,12 +990,18 @@ int main ()
895 [ 990 [
896changequote(,)dnl 991changequote(,)dnl
897 case "$host_os" in 992 case "$host_os" in
898 # Guess yes on glibc systems. 993 # Guess yes on glibc systems.
899 *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";; 994 *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
900 # Guess yes on BeOS. 995 # Guess yes on musl systems.
901 beos*) gl_cv_func_printf_flag_zero="guessing yes";; 996 *-musl*) gl_cv_func_printf_flag_zero="guessing yes";;
902 # If we don't know, assume the worst. 997 # Guess yes on BeOS.
903 *) gl_cv_func_printf_flag_zero="guessing no";; 998 beos*) gl_cv_func_printf_flag_zero="guessing yes";;
999 # Guess no on Android.
1000 linux*-android*) gl_cv_func_printf_flag_zero="guessing no";;
1001 # Guess no on native Windows.
1002 mingw*) gl_cv_func_printf_flag_zero="guessing no";;
1003 # If we don't know, obey --enable-cross-guesses.
1004 *) gl_cv_func_printf_flag_zero="$gl_cross_guess_normal";;
904 esac 1005 esac
905changequote([,])dnl 1006changequote([,])dnl
906 ]) 1007 ])
@@ -953,10 +1054,12 @@ int main ()
953changequote(,)dnl 1054changequote(,)dnl
954 case "$host_os" in 1055 case "$host_os" in
955 # Guess no only on Solaris, native Windows, and BeOS systems. 1056 # Guess no only on Solaris, native Windows, and BeOS systems.
956 solaris*) gl_cv_func_printf_precision="guessing no" ;; 1057 solaris*) gl_cv_func_printf_precision="guessing no" ;;
957 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; 1058 mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
958 beos*) gl_cv_func_printf_precision="guessing no" ;; 1059 beos*) gl_cv_func_printf_precision="guessing no" ;;
959 *) gl_cv_func_printf_precision="guessing yes" ;; 1060 # Guess yes on Android.
1061 linux*-android*) gl_cv_func_printf_precision="guessing yes" ;;
1062 *) gl_cv_func_printf_precision="guessing yes" ;;
960 esac 1063 esac
961changequote([,])dnl 1064changequote([,])dnl
962 ]) 1065 ])
@@ -978,9 +1081,8 @@ AC_DEFUN([gl_PRINTF_ENOMEM],
978 gl_cv_func_printf_enomem="guessing no" 1081 gl_cv_func_printf_enomem="guessing no"
979 if test "$cross_compiling" = no; then 1082 if test "$cross_compiling" = no; then
980 if test $APPLE_UNIVERSAL_BUILD = 0; then 1083 if test $APPLE_UNIVERSAL_BUILD = 0; then
981 AC_LANG_CONFTEST([AC_LANG_SOURCE([ 1084 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
982]GL_NOCRASH[ 1085]GL_NOCRASH[
983changequote(,)dnl
984#include <stdio.h> 1086#include <stdio.h>
985#include <sys/types.h> 1087#include <sys/types.h>
986#include <sys/time.h> 1088#include <sys/time.h>
@@ -1025,8 +1127,7 @@ int main()
1025 ret = printf ("%.5000000f", 1.0); 1127 ret = printf ("%.5000000f", 1.0);
1026 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM)); 1128 return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
1027} 1129}
1028changequote([,])dnl 1130 ]])])
1029 ])])
1030 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then 1131 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
1031 (./conftest 2>&AS_MESSAGE_LOG_FD 1132 (./conftest 2>&AS_MESSAGE_LOG_FD
1032 result=$? 1133 result=$?
@@ -1053,28 +1154,30 @@ changequote([,])dnl
1053 if test "$gl_cv_func_printf_enomem" = "guessing no"; then 1154 if test "$gl_cv_func_printf_enomem" = "guessing no"; then
1054changequote(,)dnl 1155changequote(,)dnl
1055 case "$host_os" in 1156 case "$host_os" in
1056 # Guess yes on glibc systems. 1157 # Guess yes on glibc systems.
1057 *-gnu*) gl_cv_func_printf_enomem="guessing yes";; 1158 *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";;
1058 # Guess yes on Solaris. 1159 # Guess yes on Solaris.
1059 solaris*) gl_cv_func_printf_enomem="guessing yes";; 1160 solaris*) gl_cv_func_printf_enomem="guessing yes";;
1060 # Guess yes on AIX. 1161 # Guess yes on AIX.
1061 aix*) gl_cv_func_printf_enomem="guessing yes";; 1162 aix*) gl_cv_func_printf_enomem="guessing yes";;
1062 # Guess yes on HP-UX/hppa. 1163 # Guess yes on HP-UX/hppa.
1063 hpux*) case "$host_cpu" in 1164 hpux*) case "$host_cpu" in
1064 hppa*) gl_cv_func_printf_enomem="guessing yes";; 1165 hppa*) gl_cv_func_printf_enomem="guessing yes";;
1065 *) gl_cv_func_printf_enomem="guessing no";; 1166 *) gl_cv_func_printf_enomem="guessing no";;
1066 esac 1167 esac
1067 ;; 1168 ;;
1068 # Guess yes on IRIX. 1169 # Guess yes on IRIX.
1069 irix*) gl_cv_func_printf_enomem="guessing yes";; 1170 irix*) gl_cv_func_printf_enomem="guessing yes";;
1070 # Guess yes on OSF/1. 1171 # Guess yes on OSF/1.
1071 osf*) gl_cv_func_printf_enomem="guessing yes";; 1172 osf*) gl_cv_func_printf_enomem="guessing yes";;
1072 # Guess yes on BeOS. 1173 # Guess yes on BeOS.
1073 beos*) gl_cv_func_printf_enomem="guessing yes";; 1174 beos*) gl_cv_func_printf_enomem="guessing yes";;
1074 # Guess yes on Haiku. 1175 # Guess yes on Haiku.
1075 haiku*) gl_cv_func_printf_enomem="guessing yes";; 1176 haiku*) gl_cv_func_printf_enomem="guessing yes";;
1076 # If we don't know, assume the worst. 1177 # Guess no on Android.
1077 *) gl_cv_func_printf_enomem="guessing no";; 1178 linux*-android*) gl_cv_func_printf_enomem="guessing no";;
1179 # If we don't know, obey --enable-cross-guesses.
1180 *) gl_cv_func_printf_enomem="$gl_cross_guess_normal";;
1078 esac 1181 esac
1079changequote([,])dnl 1182changequote([,])dnl
1080 fi 1183 fi
@@ -1093,7 +1196,7 @@ dnl Test whether the string produced by the snprintf function is always NUL
1093dnl terminated. (ISO C99, POSIX:2001) 1196dnl terminated. (ISO C99, POSIX:2001)
1094dnl Result is gl_cv_func_snprintf_truncation_c99. 1197dnl Result is gl_cv_func_snprintf_truncation_c99.
1095 1198
1096AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99], 1199AC_DEFUN_ONCE([gl_SNPRINTF_TRUNCATION_C99],
1097[ 1200[
1098 AC_REQUIRE([AC_PROG_CC]) 1201 AC_REQUIRE([AC_PROG_CC])
1099 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 1202 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
@@ -1134,10 +1237,13 @@ int main ()
1134changequote(,)dnl 1237changequote(,)dnl
1135 case "$host_os" in 1238 case "$host_os" in
1136 # Guess yes on glibc systems. 1239 # Guess yes on glibc systems.
1137 *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1240 *-gnu* | gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1241 # Guess yes on musl systems.
1242 *-musl*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1138 # Guess yes on FreeBSD >= 5. 1243 # Guess yes on FreeBSD >= 5.
1139 freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1244 freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1140 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1245 freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1246 midnightbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1141 # Guess yes on Mac OS X >= 10.3. 1247 # Guess yes on Mac OS X >= 10.3.
1142 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";; 1248 darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1143 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1249 darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
@@ -1166,8 +1272,12 @@ changequote(,)dnl
1166 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1272 netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1167 # Guess yes on BeOS. 1273 # Guess yes on BeOS.
1168 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";; 1274 beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1169 # If we don't know, assume the worst. 1275 # Guess yes on Android.
1170 *) gl_cv_func_snprintf_truncation_c99="guessing no";; 1276 linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
1277 # Guess no on native Windows.
1278 mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";;
1279 # If we don't know, obey --enable-cross-guesses.
1280 *) gl_cv_func_snprintf_truncation_c99="$gl_cross_guess_normal";;
1171 esac 1281 esac
1172changequote([,])dnl 1282changequote([,])dnl
1173 ]) 1283 ])
@@ -1229,14 +1339,16 @@ int main ()
1229}]])], 1339}]])],
1230 [gl_cv_func_snprintf_retval_c99=yes], 1340 [gl_cv_func_snprintf_retval_c99=yes],
1231 [gl_cv_func_snprintf_retval_c99=no], 1341 [gl_cv_func_snprintf_retval_c99=no],
1232 [ 1342 [case "$host_os" in
1233changequote(,)dnl 1343changequote(,)dnl
1234 case "$host_os" in
1235 # Guess yes on glibc systems. 1344 # Guess yes on glibc systems.
1236 *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1345 *-gnu* | gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1346 # Guess yes on musl systems.
1347 *-musl*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1237 # Guess yes on FreeBSD >= 5. 1348 # Guess yes on FreeBSD >= 5.
1238 freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";; 1349 freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1239 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1350 freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1351 midnightbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1240 # Guess yes on Mac OS X >= 10.3. 1352 # Guess yes on Mac OS X >= 10.3.
1241 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";; 1353 darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
1242 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1354 darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
@@ -1256,10 +1368,21 @@ changequote(,)dnl
1256 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1368 netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1257 # Guess yes on BeOS. 1369 # Guess yes on BeOS.
1258 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";; 1370 beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1259 # If we don't know, assume the worst. 1371 # Guess yes on Android.
1260 *) gl_cv_func_snprintf_retval_c99="guessing no";; 1372 linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";;
1261 esac
1262changequote([,])dnl 1373changequote([,])dnl
1374 # Guess yes on MSVC, no on mingw.
1375 mingw*) AC_EGREP_CPP([Known], [
1376#ifdef _MSC_VER
1377 Known
1378#endif
1379 ],
1380 [gl_cv_func_snprintf_retval_c99="guessing yes"],
1381 [gl_cv_func_snprintf_retval_c99="guessing no"])
1382 ;;
1383 # If we don't know, obey --enable-cross-guesses.
1384 *) gl_cv_func_snprintf_retval_c99="$gl_cross_guess_normal";;
1385 esac
1263 ]) 1386 ])
1264 ]) 1387 ])
1265]) 1388])
@@ -1311,13 +1434,24 @@ int main ()
1311 [gl_cv_func_snprintf_directive_n=yes], 1434 [gl_cv_func_snprintf_directive_n=yes],
1312 [gl_cv_func_snprintf_directive_n=no], 1435 [gl_cv_func_snprintf_directive_n=no],
1313 [ 1436 [
1314changequote(,)dnl
1315 case "$host_os" in 1437 case "$host_os" in
1316 # Guess yes on glibc systems. 1438 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
1317 *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";; 1439 *-gnu* | gnu*) AC_COMPILE_IFELSE(
1440 [AC_LANG_SOURCE(
1441 [[#if _FORTIFY_SOURCE >= 2
1442 error fail
1443 #endif
1444 ]])],
1445 [gl_cv_func_snprintf_directive_n="guessing yes"],
1446 [gl_cv_func_snprintf_directive_n="guessing no"])
1447 ;;
1448changequote(,)dnl
1449 # Guess yes on musl systems.
1450 *-musl*) gl_cv_func_snprintf_directive_n="guessing yes";;
1318 # Guess yes on FreeBSD >= 5. 1451 # Guess yes on FreeBSD >= 5.
1319 freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";; 1452 freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
1320 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";; 1453 freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1454 midnightbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1321 # Guess yes on Mac OS X >= 10.3. 1455 # Guess yes on Mac OS X >= 10.3.
1322 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";; 1456 darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
1323 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";; 1457 darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
@@ -1339,10 +1473,14 @@ changequote(,)dnl
1339 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";; 1473 netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
1340 # Guess yes on BeOS. 1474 # Guess yes on BeOS.
1341 beos*) gl_cv_func_snprintf_directive_n="guessing yes";; 1475 beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
1342 # If we don't know, assume the worst. 1476 # Guess no on Android.
1343 *) gl_cv_func_snprintf_directive_n="guessing no";; 1477 linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";;
1344 esac 1478 # Guess no on native Windows.
1479 mingw*) gl_cv_func_snprintf_directive_n="guessing no";;
1480 # If we don't know, obey --enable-cross-guesses.
1481 *) gl_cv_func_snprintf_directive_n="$gl_cross_guess_normal";;
1345changequote([,])dnl 1482changequote([,])dnl
1483 esac
1346 ]) 1484 ])
1347 ]) 1485 ])
1348]) 1486])
@@ -1355,6 +1493,7 @@ dnl Result is gl_cv_func_snprintf_size1.
1355AC_DEFUN([gl_SNPRINTF_SIZE1], 1493AC_DEFUN([gl_SNPRINTF_SIZE1],
1356[ 1494[
1357 AC_REQUIRE([AC_PROG_CC]) 1495 AC_REQUIRE([AC_PROG_CC])
1496 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
1358 AC_REQUIRE([gl_SNPRINTF_PRESENCE]) 1497 AC_REQUIRE([gl_SNPRINTF_PRESENCE])
1359 AC_CACHE_CHECK([whether snprintf respects a size of 1], 1498 AC_CACHE_CHECK([whether snprintf respects a size of 1],
1360 [gl_cv_func_snprintf_size1], 1499 [gl_cv_func_snprintf_size1],
@@ -1384,7 +1523,14 @@ int main()
1384}]])], 1523}]])],
1385 [gl_cv_func_snprintf_size1=yes], 1524 [gl_cv_func_snprintf_size1=yes],
1386 [gl_cv_func_snprintf_size1=no], 1525 [gl_cv_func_snprintf_size1=no],
1387 [gl_cv_func_snprintf_size1="guessing yes"]) 1526 [case "$host_os" in
1527 # Guess yes on Android.
1528 linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;;
1529 # Guess yes on native Windows.
1530 mingw*) gl_cv_func_snprintf_size1="guessing yes" ;;
1531 *) gl_cv_func_snprintf_size1="guessing yes" ;;
1532 esac
1533 ])
1388 ]) 1534 ])
1389]) 1535])
1390 1536
@@ -1456,10 +1602,13 @@ int main()
1456changequote(,)dnl 1602changequote(,)dnl
1457 case "$host_os" in 1603 case "$host_os" in
1458 # Guess yes on glibc systems. 1604 # Guess yes on glibc systems.
1459 *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1605 *-gnu* | gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1606 # Guess yes on musl systems.
1607 *-musl*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1460 # Guess yes on FreeBSD >= 5. 1608 # Guess yes on FreeBSD >= 5.
1461 freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1609 freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1462 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1610 freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1611 midnightbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1463 # Guess yes on Mac OS X >= 10.3. 1612 # Guess yes on Mac OS X >= 10.3.
1464 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1613 darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
1465 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1614 darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
@@ -1480,10 +1629,12 @@ changequote(,)dnl
1480 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1629 netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1481 # Guess yes on BeOS. 1630 # Guess yes on BeOS.
1482 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1631 beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1483 # Guess yes on mingw. 1632 # Guess yes on Android.
1633 linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1634 # Guess yes on native Windows.
1484 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; 1635 mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
1485 # If we don't know, assume the worst. 1636 # If we don't know, obey --enable-cross-guesses.
1486 *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; 1637 *) gl_cv_func_vsnprintf_zerosize_c99="$gl_cross_guess_normal";;
1487 esac 1638 esac
1488changequote([,])dnl 1639changequote([,])dnl
1489 ]) 1640 ])
@@ -1539,14 +1690,19 @@ dnl
1539dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1690dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1540dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . . 1691dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
1541dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . . 1692dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
1693dnl FreeBSD 13.0 . . . . # . . . . . . . . # . . . . . .
1542dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . . 1694dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
1695dnl Mac OS X 10.13.5 . . . # # . # . . . . . . . . . . # . .
1543dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . . 1696dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
1544dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . . 1697dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
1698dnl OpenBSD 6.0, 6.7 . . . . # . . . . . . . . # . . . . . .
1545dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . . 1699dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
1546dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . . 1700dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
1547dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . . 1701dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
1548dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . 1702dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
1549dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . . 1703dnl Solaris 11.4 . . # # # . . # . . . # . . . . . . . .
1704dnl Solaris 11.3 . . . . # . . # . . . . . . . . . . . .
1705dnl Solaris 11.0 . . # # # . . # . . . # . . . . . . . .
1550dnl Solaris 10 . . # # # . . # . . . # # . . . . . . . 1706dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
1551dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . . 1707dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
1552dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # 1708dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
@@ -1559,11 +1715,13 @@ dnl HP-UX 10.20 # . # . # # . ? . . # # . . .
1559dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . . 1715dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
1560dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . # 1716dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
1561dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # # 1717dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
1718dnl NetBSD 9.0 . . . . # . . . . . . . . . . . . . . .
1562dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . . 1719dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
1563dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ? 1720dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
1564dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . . 1721dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
1565dnl Haiku . . . # # # . # . . . . . ? . . ? . . . 1722dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
1566dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . . 1723dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
1724dnl Android 4.3 . . # # # # # # . # . # . # . . . # . .
1567dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . . 1725dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
1568dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . . 1726dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
1569dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . . 1727dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
diff --git a/gl/m4/progtest.m4 b/gl/m4/progtest.m4
deleted file mode 100644
index 7b39123..0000000
--- a/gl/m4/progtest.m4
+++ /dev/null
@@ -1,91 +0,0 @@
1# progtest.m4 serial 7 (gettext-0.18.2)
2dnl Copyright (C) 1996-2003, 2005, 2008-2013 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 Authors:
17dnl Ulrich Drepper <drepper@cygnus.com>, 1996.
18
19AC_PREREQ([2.50])
20
21# Search path for a program which passes the given test.
22
23dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
24dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
25AC_DEFUN([AM_PATH_PROG_WITH_TEST],
26[
27# Prepare PATH_SEPARATOR.
28# The user is always right.
29if test "${PATH_SEPARATOR+set}" != set; then
30 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
31 # contains only /bin. Note that ksh looks also at the FPATH variable,
32 # so we have to set that as well for the test.
33 PATH_SEPARATOR=:
34 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
35 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
36 || PATH_SEPARATOR=';'
37 }
38fi
39
40# Find out how to test for executable files. Don't use a zero-byte file,
41# as systems may use methods other than mode bits to determine executability.
42cat >conf$$.file <<_ASEOF
43#! /bin/sh
44exit 0
45_ASEOF
46chmod +x conf$$.file
47if test -x conf$$.file >/dev/null 2>&1; then
48 ac_executable_p="test -x"
49else
50 ac_executable_p="test -f"
51fi
52rm -f conf$$.file
53
54# Extract the first word of "$2", so it can be a program name with args.
55set dummy $2; ac_word=[$]2
56AC_MSG_CHECKING([for $ac_word])
57AC_CACHE_VAL([ac_cv_path_$1],
58[case "[$]$1" in
59 [[\\/]]* | ?:[[\\/]]*)
60 ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
61 ;;
62 *)
63 ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
64 for ac_dir in ifelse([$5], , $PATH, [$5]); do
65 IFS="$ac_save_IFS"
66 test -z "$ac_dir" && ac_dir=.
67 for ac_exec_ext in '' $ac_executable_extensions; do
68 if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
69 echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD
70 if [$3]; then
71 ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext"
72 break 2
73 fi
74 fi
75 done
76 done
77 IFS="$ac_save_IFS"
78dnl If no 4th arg is given, leave the cache variable unset,
79dnl so AC_PATH_PROGS will keep looking.
80ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
81])dnl
82 ;;
83esac])dnl
84$1="$ac_cv_path_$1"
85if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
86 AC_MSG_RESULT([$][$1])
87else
88 AC_MSG_RESULT([no])
89fi
90AC_SUBST([$1])dnl
91])
diff --git a/gl/m4/pthread_rwlock_rdlock.m4 b/gl/m4/pthread_rwlock_rdlock.m4
new file mode 100644
index 0000000..ae6a885
--- /dev/null
+++ b/gl/m4/pthread_rwlock_rdlock.m4
@@ -0,0 +1,185 @@
1# pthread_rwlock_rdlock.m4 serial 4
2dnl Copyright (C) 2017-2023 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 Inspired by
9dnl https://github.com/linux-test-project/ltp/blob/master/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c
10dnl by Intel Corporation.
11
12dnl Test whether in a situation where
13dnl - an rwlock is taken by a reader and has a writer waiting,
14dnl - an additional reader requests the lock,
15dnl - the waiting writer and the requesting reader threads have the same
16dnl priority,
17dnl the requesting reader thread gets blocked, so that at some point the
18dnl waiting writer can acquire the lock.
19dnl Without such a guarantee, when there a N readers and each of the readers
20dnl spends more than 1/Nth of the time with the lock held, there is a high
21dnl probability that the waiting writer will not get the lock in a given finite
22dnl time, a phenomenon called "writer starvation".
23dnl Without such a guarantee, applications have a hard time avoiding writer
24dnl starvation.
25dnl
26dnl POSIX:2017 makes this requirement only for implementations that support TPS
27dnl (Thread Priority Scheduling) and only for the scheduling policies SCHED_FIFO
28dnl and SCHED_RR, see
29dnl https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_rdlock.html
30dnl but this test verifies the guarantee regardless of TPS and regardless of
31dnl scheduling policy.
32dnl Glibc does not provide this guarantee (and never will on Linux), see
33dnl https://sourceware.org/bugzilla/show_bug.cgi?id=13701
34dnl https://bugzilla.redhat.com/show_bug.cgi?id=1410052
35AC_DEFUN([gl_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER],
36[
37 AC_REQUIRE([gl_THREADLIB_EARLY])
38 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
39 AC_CACHE_CHECK([whether pthread_rwlock_rdlock prefers a writer to a reader],
40 [gl_cv_pthread_rwlock_rdlock_prefer_writer],
41 [save_LIBS="$LIBS"
42 LIBS="$LIBS $LIBMULTITHREAD"
43 AC_RUN_IFELSE(
44 [AC_LANG_SOURCE([[
45#include <errno.h>
46#include <pthread.h>
47#include <stdlib.h>
48#include <unistd.h>
49
50#define SUCCEED() exit (0)
51#define FAILURE() exit (1)
52#define UNEXPECTED(n) (exit (10 + (n)))
53
54/* The main thread creates the waiting writer and the requesting reader threads
55 in the default way; this guarantees that they have the same priority.
56 We can reuse the main thread as first reader thread. */
57
58static pthread_rwlock_t lock;
59static pthread_t reader1;
60static pthread_t writer;
61static pthread_t reader2;
62static pthread_t timer;
63/* Used to pass control from writer to reader2 and from reader2 to timer,
64 as in a relay race.
65 Passing control from one running thread to another running thread
66 is most likely faster than to create the second thread. */
67static pthread_mutex_t baton;
68
69static void *
70timer_func (void *ignored)
71{
72 /* Step 13 (can be before or after step 12):
73 The timer thread takes the baton, then waits a moment to make sure
74 it can tell whether the second reader thread is blocked at step 12. */
75 if (pthread_mutex_lock (&baton))
76 UNEXPECTED (13);
77 usleep (100000);
78 /* By the time we get here, it's clear that the second reader thread is
79 blocked at step 12. This is the desired behaviour. */
80 SUCCEED ();
81}
82
83static void *
84reader2_func (void *ignored)
85{
86 int err;
87
88 /* Step 8 (can be before or after step 7):
89 The second reader thread takes the baton, then waits a moment to make sure
90 the writer thread has reached step 7. */
91 if (pthread_mutex_lock (&baton))
92 UNEXPECTED (8);
93 usleep (100000);
94 /* Step 9: The second reader thread requests the lock. */
95 err = pthread_rwlock_tryrdlock (&lock);
96 if (err == 0)
97 FAILURE ();
98 else if (err != EBUSY)
99 UNEXPECTED (9);
100 /* Step 10: Launch a timer, to test whether the next call blocks. */
101 if (pthread_create (&timer, NULL, timer_func, NULL))
102 UNEXPECTED (10);
103 /* Step 11: Release the baton. */
104 if (pthread_mutex_unlock (&baton))
105 UNEXPECTED (11);
106 /* Step 12: The second reader thread requests the lock. */
107 err = pthread_rwlock_rdlock (&lock);
108 if (err == 0)
109 FAILURE ();
110 else
111 UNEXPECTED (12);
112}
113
114static void *
115writer_func (void *ignored)
116{
117 /* Step 4: Take the baton, so that the second reader thread does not go ahead
118 too early. */
119 if (pthread_mutex_lock (&baton))
120 UNEXPECTED (4);
121 /* Step 5: Create the second reader thread. */
122 if (pthread_create (&reader2, NULL, reader2_func, NULL))
123 UNEXPECTED (5);
124 /* Step 6: Release the baton. */
125 if (pthread_mutex_unlock (&baton))
126 UNEXPECTED (6);
127 /* Step 7: The writer thread requests the lock. */
128 if (pthread_rwlock_wrlock (&lock))
129 UNEXPECTED (7);
130 return NULL;
131}
132
133int
134main ()
135{
136 reader1 = pthread_self ();
137
138 /* Step 1: The main thread initializes the lock and the baton. */
139 if (pthread_rwlock_init (&lock, NULL))
140 UNEXPECTED (1);
141 if (pthread_mutex_init (&baton, NULL))
142 UNEXPECTED (1);
143 /* Step 2: The main thread acquires the lock as a reader. */
144 if (pthread_rwlock_rdlock (&lock))
145 UNEXPECTED (2);
146 /* Step 3: Create the writer thread. */
147 if (pthread_create (&writer, NULL, writer_func, NULL))
148 UNEXPECTED (3);
149 /* Job done. Go to sleep. */
150 for (;;)
151 {
152 sleep (1);
153 }
154}
155]])],
156 [gl_cv_pthread_rwlock_rdlock_prefer_writer=yes],
157 [gl_cv_pthread_rwlock_rdlock_prefer_writer=no],
158 [case "$host_os" in
159 # Guess no on glibc systems.
160 *-gnu* | gnu*) gl_cv_pthread_rwlock_rdlock_prefer_writer="guessing no" ;;
161 # Guess no on musl systems.
162 *-musl*) gl_cv_pthread_rwlock_rdlock_prefer_writer="guessing no" ;;
163 # Guess no on bionic systems.
164 *-android*) gl_cv_pthread_rwlock_rdlock_prefer_writer="guessing no" ;;
165 # Guess yes on native Windows with the mingw-w64 winpthreads library.
166 # Guess no on native Windows with the gnulib windows-rwlock module.
167 mingw*) if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
168 gl_cv_pthread_rwlock_rdlock_prefer_writer="guessing yes"
169 else
170 gl_cv_pthread_rwlock_rdlock_prefer_writer="guessing no"
171 fi
172 ;;
173 # If we don't know, obey --enable-cross-guesses.
174 *) gl_cv_pthread_rwlock_rdlock_prefer_writer="$gl_cross_guess_normal" ;;
175 esac
176 ])
177 LIBS="$save_LIBS"
178 ])
179 case "$gl_cv_pthread_rwlock_rdlock_prefer_writer" in
180 *yes)
181 AC_DEFINE([HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER], [1],
182 [Define if the 'pthread_rwlock_rdlock' function prefers a writer to a reader.])
183 ;;
184 esac
185])
diff --git a/gl/m4/read.m4 b/gl/m4/read.m4
deleted file mode 100644
index 81f0f3a..0000000
--- a/gl/m4/read.m4
+++ /dev/null
@@ -1,26 +0,0 @@
1# read.m4 serial 4
2dnl Copyright (C) 2011-2013 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_READ],
8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([gl_MSVC_INVAL])
11 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
12 REPLACE_READ=1
13 fi
14 dnl This ifdef is just an optimization, to avoid performing a configure
15 dnl check whose result is not used. It does not make the test of
16 dnl GNULIB_UNISTD_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
17 m4_ifdef([gl_NONBLOCKING_IO], [
18 gl_NONBLOCKING_IO
19 if test $gl_cv_have_nonblocking != yes; then
20 REPLACE_READ=1
21 fi
22 ])
23])
24
25# Prerequisites of lib/read.c.
26AC_DEFUN([gl_PREREQ_READ], [:])
diff --git a/gl/m4/realloc.m4 b/gl/m4/realloc.m4
new file mode 100644
index 0000000..d22138f
--- /dev/null
+++ b/gl/m4/realloc.m4
@@ -0,0 +1,63 @@
1# realloc.m4 serial 26
2dnl Copyright (C) 2007, 2009-2023 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# This is adapted with modifications from upstream Autoconf here:
8# https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n1455
9AC_DEFUN([_AC_FUNC_REALLOC_IF],
10[
11 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
12 AC_CACHE_CHECK([whether realloc (0, 0) returns nonnull],
13 [ac_cv_func_realloc_0_nonnull],
14 [AC_RUN_IFELSE(
15 [AC_LANG_PROGRAM(
16 [[#include <stdlib.h>
17 ]],
18 [[void *p = realloc (0, 0);
19 int result = !p;
20 free (p);
21 return result;]])
22 ],
23 [ac_cv_func_realloc_0_nonnull=yes],
24 [ac_cv_func_realloc_0_nonnull=no],
25 [case "$host_os" in
26 # Guess yes on platforms where we know the result.
27 *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
28 | gnu* | *-musl* | midnightbsd* \
29 | hpux* | solaris* | cygwin* | mingw* | msys* )
30 ac_cv_func_realloc_0_nonnull="guessing yes" ;;
31 # If we don't know, obey --enable-cross-guesses.
32 *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
33 esac
34 ])
35 ])
36 AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
37])# AC_FUNC_REALLOC
38
39# gl_FUNC_REALLOC_GNU
40# -------------------
41# Replace realloc if it is not compatible with GNU libc.
42AC_DEFUN([gl_FUNC_REALLOC_GNU],
43[
44 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
45 AC_REQUIRE([gl_FUNC_REALLOC_POSIX])
46 if test $REPLACE_REALLOC_FOR_REALLOC_GNU = 0; then
47 _AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC_FOR_REALLOC_GNU=1])
48 fi
49])# gl_FUNC_REALLOC_GNU
50
51# gl_FUNC_REALLOC_POSIX
52# ---------------------
53# Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
54# fails, and doesn't mess up with ptrdiff_t overflow),
55# and replace realloc if it is not.
56AC_DEFUN([gl_FUNC_REALLOC_POSIX],
57[
58 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
59 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
60 if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then
61 REPLACE_REALLOC_FOR_REALLOC_POSIX=1
62 fi
63])
diff --git a/gl/m4/reallocarray.m4 b/gl/m4/reallocarray.m4
new file mode 100644
index 0000000..1607b7a
--- /dev/null
+++ b/gl/m4/reallocarray.m4
@@ -0,0 +1,23 @@
1# reallocarray.m4 serial 3
2dnl Copyright (C) 2017-2023 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_REALLOCARRAY],
8[
9 dnl Persuade glibc <stdlib.h> to declare reallocarray.
10 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
11
12 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
13 AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF])
14 AC_CHECK_FUNCS([reallocarray])
15 if test "$ac_cv_func_reallocarray" = no; then
16 HAVE_REALLOCARRAY=0
17 elif test "$gl_cv_malloc_ptrdiff" = no; then
18 REPLACE_REALLOCARRAY=1
19 fi
20])
21
22# Prerequisites of lib/reallocarray.c.
23AC_DEFUN([gl_PREREQ_REALLOCARRAY], [:])
diff --git a/gl/m4/regex.m4 b/gl/m4/regex.m4
index 0945c11..c89a143 100644
--- a/gl/m4/regex.m4
+++ b/gl/m4/regex.m4
@@ -1,6 +1,6 @@
1# serial 64 1# serial 73
2 2
3# Copyright (C) 1996-2001, 2003-2013 Free Software Foundation, Inc. 3# Copyright (C) 1996-2001, 2003-2023 Free Software Foundation, Inc.
4# 4#
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,
@@ -13,6 +13,7 @@ AC_PREREQ([2.50])
13 13
14AC_DEFUN([gl_REGEX], 14AC_DEFUN([gl_REGEX],
15[ 15[
16 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16 AC_ARG_WITH([included-regex], 17 AC_ARG_WITH([included-regex],
17 [AS_HELP_STRING([--without-included-regex], 18 [AS_HELP_STRING([--without-included-regex],
18 [don't compile regex; this is the default on systems 19 [don't compile regex; this is the default on systems
@@ -28,6 +29,7 @@ AC_DEFUN([gl_REGEX],
28 # If cross compiling, assume the test would fail and use the included 29 # If cross compiling, assume the test would fail and use the included
29 # regex.c. 30 # regex.c.
30 AC_CHECK_DECLS_ONCE([alarm]) 31 AC_CHECK_DECLS_ONCE([alarm])
32 AC_CHECK_HEADERS_ONCE([malloc.h])
31 AC_CACHE_CHECK([for working re_compile_pattern], 33 AC_CACHE_CHECK([for working re_compile_pattern],
32 [gl_cv_func_re_compile_pattern_working], 34 [gl_cv_func_re_compile_pattern_working],
33 [AC_RUN_IFELSE( 35 [AC_RUN_IFELSE(
@@ -37,9 +39,19 @@ AC_DEFUN([gl_REGEX],
37 #include <locale.h> 39 #include <locale.h>
38 #include <limits.h> 40 #include <limits.h>
39 #include <string.h> 41 #include <string.h>
40 #if HAVE_DECL_ALARM 42
41 # include <unistd.h> 43 #if defined M_CHECK_ACTION || HAVE_DECL_ALARM
42 # include <signal.h> 44 # include <signal.h>
45 # include <unistd.h>
46 #endif
47
48 #if HAVE_MALLOC_H
49 # include <malloc.h>
50 #endif
51
52 #ifdef M_CHECK_ACTION
53 /* Exit with distinguishable exit code. */
54 static void sigabrt_no_core (int sig) { raise (SIGTERM); }
43 #endif 55 #endif
44 ]], 56 ]],
45 [[int result = 0; 57 [[int result = 0;
@@ -49,15 +61,22 @@ AC_DEFUN([gl_REGEX],
49 const char *s; 61 const char *s;
50 struct re_registers regs; 62 struct re_registers regs;
51 63
64 /* Some builds of glibc go into an infinite loop on this
65 test. Use alarm to force death, and mallopt to avoid
66 malloc recursion in diagnosing the corrupted heap. */
52#if HAVE_DECL_ALARM 67#if HAVE_DECL_ALARM
53 /* Some builds of glibc go into an infinite loop on this test. */
54 signal (SIGALRM, SIG_DFL); 68 signal (SIGALRM, SIG_DFL);
55 alarm (2); 69 alarm (2);
56#endif 70#endif
71#ifdef M_CHECK_ACTION
72 signal (SIGABRT, sigabrt_no_core);
73 mallopt (M_CHECK_ACTION, 2);
74#endif
75
57 if (setlocale (LC_ALL, "en_US.UTF-8")) 76 if (setlocale (LC_ALL, "en_US.UTF-8"))
58 { 77 {
59 { 78 {
60 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html 79 /* https://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
61 This test needs valgrind to catch the bug on Debian 80 This test needs valgrind to catch the bug on Debian
62 GNU/Linux 3.1 x86, but it might catch the bug better 81 GNU/Linux 3.1 x86, but it might catch the bug better
63 on other platforms and it shouldn't hurt to try the 82 on other platforms and it shouldn't hurt to try the
@@ -71,16 +90,20 @@ AC_DEFUN([gl_REGEX],
71 s = re_compile_pattern (pat, sizeof pat - 1, &regex); 90 s = re_compile_pattern (pat, sizeof pat - 1, &regex);
72 if (s) 91 if (s)
73 result |= 1; 92 result |= 1;
74 else if (re_search (&regex, data, sizeof data - 1, 93 else
75 0, sizeof data - 1, &regs) 94 {
76 != -1) 95 if (re_search (&regex, data, sizeof data - 1,
77 result |= 1; 96 0, sizeof data - 1, &regs)
97 != -1)
98 result |= 1;
99 regfree (&regex);
100 }
78 } 101 }
79 102
80 { 103 {
81 /* This test is from glibc bug 15078. 104 /* This test is from glibc bug 15078.
82 The test case is from Andreas Schwab in 105 The test case is from Andreas Schwab in
83 <http://www.sourceware.org/ml/libc-alpha/2013-01/msg00967.html>. 106 <https://sourceware.org/ml/libc-alpha/2013-01/msg00967.html>.
84 */ 107 */
85 static char const pat[] = "[^x]x"; 108 static char const pat[] = "[^x]x";
86 static char const data[] = 109 static char const data[] =
@@ -105,6 +128,7 @@ AC_DEFUN([gl_REGEX],
105 0, sizeof data - 1, 0); 128 0, sizeof data - 1, 0);
106 if (i != 0 && i != 21) 129 if (i != 0 && i != 21)
107 result |= 1; 130 result |= 1;
131 regfree (&regex);
108 } 132 }
109 } 133 }
110 134
@@ -118,9 +142,13 @@ AC_DEFUN([gl_REGEX],
118 s = re_compile_pattern ("a[^x]b", 6, &regex); 142 s = re_compile_pattern ("a[^x]b", 6, &regex);
119 if (s) 143 if (s)
120 result |= 2; 144 result |= 2;
121 /* This should fail, but succeeds for glibc-2.5. */ 145 else
122 else if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1) 146 {
123 result |= 2; 147 /* This should fail, but succeeds for glibc-2.5. */
148 if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
149 result |= 2;
150 regfree (&regex);
151 }
124 152
125 /* This regular expression is from Spencer ere test number 75 153 /* This regular expression is from Spencer ere test number 75
126 in grep-2.3. */ 154 in grep-2.3. */
@@ -132,7 +160,10 @@ AC_DEFUN([gl_REGEX],
132 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex); 160 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
133 /* This should fail with _Invalid character class name_ error. */ 161 /* This should fail with _Invalid character class name_ error. */
134 if (!s) 162 if (!s)
135 result |= 4; 163 {
164 result |= 4;
165 regfree (&regex);
166 }
136 167
137 /* Ensure that [b-a] is diagnosed as invalid, when 168 /* Ensure that [b-a] is diagnosed as invalid, when
138 using RE_NO_EMPTY_RANGES. */ 169 using RE_NO_EMPTY_RANGES. */
@@ -140,13 +171,18 @@ AC_DEFUN([gl_REGEX],
140 memset (&regex, 0, sizeof regex); 171 memset (&regex, 0, sizeof regex);
141 s = re_compile_pattern ("a[b-a]", 6, &regex); 172 s = re_compile_pattern ("a[b-a]", 6, &regex);
142 if (s == 0) 173 if (s == 0)
143 result |= 8; 174 {
175 result |= 8;
176 regfree (&regex);
177 }
144 178
145 /* This should succeed, but does not for glibc-2.1.3. */ 179 /* This should succeed, but does not for glibc-2.1.3. */
146 memset (&regex, 0, sizeof regex); 180 memset (&regex, 0, sizeof regex);
147 s = re_compile_pattern ("{1", 2, &regex); 181 s = re_compile_pattern ("{1", 2, &regex);
148 if (s) 182 if (s)
149 result |= 8; 183 result |= 8;
184 else
185 regfree (&regex);
150 186
151 /* The following example is derived from a problem report 187 /* The following example is derived from a problem report
152 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ 188 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
@@ -154,17 +190,35 @@ AC_DEFUN([gl_REGEX],
154 s = re_compile_pattern ("[an\371]*n", 7, &regex); 190 s = re_compile_pattern ("[an\371]*n", 7, &regex);
155 if (s) 191 if (s)
156 result |= 8; 192 result |= 8;
157 /* This should match, but does not for glibc-2.2.1. */ 193 else
158 else if (re_match (&regex, "an", 2, 0, &regs) != 2) 194 {
159 result |= 8; 195 /* This should match, but does not for glibc-2.2.1. */
196 if (re_match (&regex, "an", 2, 0, &regs) != 2)
197 result |= 8;
198 else
199 {
200 free (regs.start);
201 free (regs.end);
202 }
203 regfree (&regex);
204 }
160 205
161 memset (&regex, 0, sizeof regex); 206 memset (&regex, 0, sizeof regex);
162 s = re_compile_pattern ("x", 1, &regex); 207 s = re_compile_pattern ("x", 1, &regex);
163 if (s) 208 if (s)
164 result |= 8; 209 result |= 8;
165 /* glibc-2.2.93 does not work with a negative RANGE argument. */ 210 else
166 else if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1) 211 {
167 result |= 8; 212 /* glibc-2.2.93 does not work with a negative RANGE argument. */
213 if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
214 result |= 8;
215 else
216 {
217 free (regs.start);
218 free (regs.end);
219 }
220 regfree (&regex);
221 }
168 222
169 /* The version of regex.c in older versions of gnulib 223 /* The version of regex.c in older versions of gnulib
170 ignored RE_ICASE. Detect that problem too. */ 224 ignored RE_ICASE. Detect that problem too. */
@@ -173,25 +227,89 @@ AC_DEFUN([gl_REGEX],
173 s = re_compile_pattern ("x", 1, &regex); 227 s = re_compile_pattern ("x", 1, &regex);
174 if (s) 228 if (s)
175 result |= 16; 229 result |= 16;
176 else if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0) 230 else
177 result |= 16; 231 {
232 if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
233 result |= 16;
234 else
235 {
236 free (regs.start);
237 free (regs.end);
238 }
239 regfree (&regex);
240 }
178 241
179 /* Catch a bug reported by Vin Shelton in 242 /* Catch a bug reported by Vin Shelton in
180 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html 243 https://lists.gnu.org/r/bug-coreutils/2007-06/msg00089.html
181 */ 244 */
182 re_set_syntax (RE_SYNTAX_POSIX_BASIC 245 re_set_syntax (RE_SYNTAX_POSIX_BASIC
183 & ~RE_CONTEXT_INVALID_DUP 246 & ~RE_CONTEXT_INVALID_DUP
184 & ~RE_NO_EMPTY_RANGES); 247 & ~RE_NO_EMPTY_RANGES);
185 memset (&regex, 0, sizeof regex); 248 memset (&regex, 0, sizeof regex);
186 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex); 249 s = re_compile_pattern ("[[:alnum:]_-]\\\\+\$", 16, &regex);
187 if (s) 250 if (s)
188 result |= 32; 251 result |= 32;
252 else
253 regfree (&regex);
189 254
190 /* REG_STARTEND was added to glibc on 2004-01-15. 255 /* REG_STARTEND was added to glibc on 2004-01-15.
191 Reject older versions. */ 256 Reject older versions. */
192 if (! REG_STARTEND) 257 if (! REG_STARTEND)
193 result |= 64; 258 result |= 64;
194 259
260 /* Matching with the compiled form of this regexp would provoke
261 an assertion failure prior to glibc-2.28:
262 regexec.c:1375: pop_fail_stack: Assertion 'num >= 0' failed
263 With glibc-2.28, compilation fails and reports the invalid
264 back reference. */
265 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
266 memset (&regex, 0, sizeof regex);
267 s = re_compile_pattern ("0|()0|\\\\1|0", 10, &regex);
268 if (!s)
269 {
270 memset (&regs, 0, sizeof regs);
271 i = re_search (&regex, "x", 1, 0, 1, &regs);
272 if (i != -1)
273 result |= 64;
274 if (0 <= i)
275 {
276 free (regs.start);
277 free (regs.end);
278 }
279 regfree (&regex);
280 }
281 else
282 {
283 if (strcmp (s, "Invalid back reference"))
284 result |= 64;
285 }
286
287 /* glibc bug 11053. */
288 re_set_syntax (RE_SYNTAX_POSIX_BASIC);
289 memset (&regex, 0, sizeof regex);
290 static char const pat_sub2[] = "\\\\(a*\\\\)*a*\\\\1";
291 s = re_compile_pattern (pat_sub2, sizeof pat_sub2 - 1, &regex);
292 if (s)
293 result |= 64;
294 else
295 {
296 memset (&regs, 0, sizeof regs);
297 static char const data[] = "a";
298 int datalen = sizeof data - 1;
299 i = re_search (&regex, data, datalen, 0, datalen, &regs);
300 if (i != 0)
301 result |= 64;
302 else if (regs.num_regs < 2)
303 result |= 64;
304 else if (! (regs.start[0] == 0 && regs.end[0] == 1))
305 result |= 64;
306 else if (! (regs.start[1] == 0 && regs.end[1] == 0))
307 result |= 64;
308 regfree (&regex);
309 free (regs.start);
310 free (regs.end);
311 }
312
195#if 0 313#if 0
196 /* It would be nice to reject hosts whose regoff_t values are too 314 /* It would be nice to reject hosts whose regoff_t values are too
197 narrow (including glibc on hosts with 64-bit ptrdiff_t and 315 narrow (including glibc on hosts with 64-bit ptrdiff_t and
@@ -206,13 +324,19 @@ AC_DEFUN([gl_REGEX],
206 324
207 return result; 325 return result;
208 ]])], 326 ]])],
209 [gl_cv_func_re_compile_pattern_working=yes], 327 [gl_cv_func_re_compile_pattern_working=yes],
210 [gl_cv_func_re_compile_pattern_working=no], 328 [gl_cv_func_re_compile_pattern_working=no],
211 dnl When crosscompiling, assume it is not working. 329 [case "$host_os" in
212 [gl_cv_func_re_compile_pattern_working=no])]) 330 # Guess no on native Windows.
213 case $gl_cv_func_re_compile_pattern_working in #( 331 mingw*) gl_cv_func_re_compile_pattern_working="guessing no" ;;
214 yes) ac_use_included_regex=no;; #( 332 # Otherwise obey --enable-cross-guesses.
215 no) ac_use_included_regex=yes;; 333 *) gl_cv_func_re_compile_pattern_working="$gl_cross_guess_normal" ;;
334 esac
335 ])
336 ])
337 case "$gl_cv_func_re_compile_pattern_working" in #(
338 *yes) ac_use_included_regex=no;; #(
339 *no) ac_use_included_regex=yes;;
216 esac 340 esac
217 ;; 341 ;;
218 *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex]) 342 *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
@@ -266,8 +390,7 @@ AC_DEFUN([gl_PREREQ_REGEX],
266 AC_REQUIRE([AC_C_RESTRICT]) 390 AC_REQUIRE([AC_C_RESTRICT])
267 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 391 AC_REQUIRE([AC_TYPE_MBSTATE_T])
268 AC_REQUIRE([gl_EEMALLOC]) 392 AC_REQUIRE([gl_EEMALLOC])
269 AC_REQUIRE([gl_GLIBC21])
270 AC_CHECK_HEADERS([libintl.h]) 393 AC_CHECK_HEADERS([libintl.h])
271 AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll]) 394 AC_CHECK_FUNCS_ONCE([isblank iswctype])
272 AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]]) 395 AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
273]) 396])
diff --git a/gl/m4/safe-read.m4 b/gl/m4/safe-read.m4
deleted file mode 100644
index be5207a..0000000
--- a/gl/m4/safe-read.m4
+++ /dev/null
@@ -1,12 +0,0 @@
1# safe-read.m4 serial 6
2dnl Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8# Prerequisites of lib/safe-read.c.
9AC_DEFUN([gl_PREREQ_SAFE_READ],
10[
11 AC_REQUIRE([gt_TYPE_SSIZE_T])
12])
diff --git a/gl/m4/servent.m4 b/gl/m4/servent.m4
index 01c037a..0f35b8b 100644
--- a/gl/m4/servent.m4
+++ b/gl/m4/servent.m4
@@ -1,5 +1,5 @@
1# servent.m4 serial 2 1# servent.m4 serial 4
2dnl Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008, 2010-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -10,12 +10,12 @@ AC_DEFUN([gl_SERVENT],
10 dnl getservbyport() defined? 10 dnl getservbyport() defined?
11 dnl Where are getprotoent(), setprotoent(), endprotoent(), getprotobyname(), 11 dnl Where are getprotoent(), setprotoent(), endprotoent(), getprotobyname(),
12 dnl getprotobynumber() defined? 12 dnl getprotobynumber() defined?
13 dnl - On Solaris, they are in libsocket. Ignore libxnet. 13 dnl - On Solaris < 11.4, they are in libsocket. Ignore libxnet.
14 dnl - On Haiku, they are in libnetwork. 14 dnl - On Haiku, they are in libnetwork.
15 dnl - On BeOS, they are in libnet. 15 dnl - On BeOS, they are in libnet.
16 dnl - On native Windows, they are in ws2_32.dll. 16 dnl - On native Windows, they are in ws2_32.dll.
17 dnl - Otherwise they are in libc. 17 dnl - Otherwise they are in libc.
18 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H 18 AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
19 SERVENT_LIB= 19 SERVENT_LIB=
20 gl_saved_libs="$LIBS" 20 gl_saved_libs="$LIBS"
21 AC_SEARCH_LIBS([getservbyname], [socket network net], 21 AC_SEARCH_LIBS([getservbyname], [socket network net],
diff --git a/gl/m4/setenv.m4 b/gl/m4/setenv.m4
index cb5351a..16f9eb5 100644
--- a/gl/m4/setenv.m4
+++ b/gl/m4/setenv.m4
@@ -1,5 +1,5 @@
1# setenv.m4 serial 26 1# setenv.m4 serial 30
2dnl Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2004, 2006-2023 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,10 +35,12 @@ AC_DEFUN([gl_FUNC_SETENV],
35 ]])], 35 ]])],
36 [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no], 36 [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no],
37 [case "$host_os" in 37 [case "$host_os" in
38 # Guess yes on glibc systems. 38 # Guess yes on glibc systems.
39 *-gnu*) gl_cv_func_setenv_works="guessing yes" ;; 39 *-gnu* | gnu*) gl_cv_func_setenv_works="guessing yes" ;;
40 # If we don't know, assume the worst. 40 # Guess yes on musl systems.
41 *) gl_cv_func_setenv_works="guessing no" ;; 41 *-musl*) gl_cv_func_setenv_works="guessing yes" ;;
42 # If we don't know, obey --enable-cross-guesses.
43 *) gl_cv_func_setenv_works="$gl_cross_guess_normal" ;;
42 esac 44 esac
43 ])]) 45 ])])
44 case "$gl_cv_func_setenv_works" in 46 case "$gl_cv_func_setenv_works" in
@@ -104,35 +106,39 @@ int unsetenv (const char *name);
104 dnl OpenBSD 4.7 unsetenv("") does not fail. 106 dnl OpenBSD 4.7 unsetenv("") does not fail.
105 AC_CACHE_CHECK([whether unsetenv obeys POSIX], 107 AC_CACHE_CHECK([whether unsetenv obeys POSIX],
106 [gl_cv_func_unsetenv_works], 108 [gl_cv_func_unsetenv_works],
107 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 109 [AC_RUN_IFELSE(
108 #include <stdlib.h> 110 [AC_LANG_PROGRAM([[
109 #include <errno.h> 111 #include <stdlib.h>
110 extern char **environ; 112 #include <errno.h>
111 ]], [[ 113 extern char **environ;
112 char entry1[] = "a=1"; 114 ]GL_MDA_DEFINES],
113 char entry2[] = "b=2"; 115 [[
114 char *env[] = { entry1, entry2, NULL }; 116 char entry1[] = "a=1";
115 if (putenv ((char *) "a=1")) return 1; 117 char entry2[] = "b=2";
116 if (putenv (entry2)) return 2; 118 char *env[] = { entry1, entry2, NULL };
117 entry2[0] = 'a'; 119 if (putenv ((char *) "a=1")) return 1;
118 unsetenv ("a"); 120 if (putenv (entry2)) return 2;
119 if (getenv ("a")) return 3; 121 entry2[0] = 'a';
120 if (!unsetenv ("") || errno != EINVAL) return 4; 122 unsetenv ("a");
121 entry2[0] = 'b'; 123 if (getenv ("a")) return 3;
122 environ = env; 124 if (!unsetenv ("") || errno != EINVAL) return 4;
123 if (!getenv ("a")) return 5; 125 entry2[0] = 'b';
124 entry2[0] = 'a'; 126 environ = env;
125 unsetenv ("a"); 127 if (!getenv ("a")) return 5;
126 if (getenv ("a")) return 6; 128 entry2[0] = 'a';
127 ]])], 129 unsetenv ("a");
128 [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no], 130 if (getenv ("a")) return 6;
129 [case "$host_os" in 131 ]])],
130 # Guess yes on glibc systems. 132 [gl_cv_func_unsetenv_works=yes],
131 *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;; 133 [gl_cv_func_unsetenv_works=no],
132 # If we don't know, assume the worst. 134 [case "$host_os" in
133 *) gl_cv_func_unsetenv_works="guessing no" ;; 135 # Guess yes on glibc systems.
134 esac 136 *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;;
135 ])]) 137 # If we don't know, obey --enable-cross-guesses.
138 *) gl_cv_func_unsetenv_works="$gl_cross_guess_normal" ;;
139 esac
140 ])
141 ])
136 case "$gl_cv_func_unsetenv_works" in 142 case "$gl_cv_func_unsetenv_works" in
137 *yes) ;; 143 *yes) ;;
138 *) 144 *)
diff --git a/gl/m4/setlocale_null.m4 b/gl/m4/setlocale_null.m4
new file mode 100644
index 0000000..032119d
--- /dev/null
+++ b/gl/m4/setlocale_null.m4
@@ -0,0 +1,98 @@
1# setlocale_null.m4 serial 5
2dnl Copyright (C) 2019-2023 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_SETLOCALE_NULL],
8[
9 AC_REQUIRE([AC_CANONICAL_HOST])
10 AC_REQUIRE([gl_PTHREADLIB])
11 AC_CHECK_HEADERS_ONCE([threads.h])
12
13 AC_CACHE_CHECK([whether setlocale (LC_ALL, NULL) is multithread-safe],
14 [gl_cv_func_setlocale_null_all_mtsafe],
15 [case "$host_os" in
16 # Guess no on musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin.
17 *-musl* | darwin* | freebsd* | midnightbsd* | netbsd* | openbsd* | aix* | haiku* | cygwin*)
18 gl_cv_func_setlocale_null_all_mtsafe=no ;;
19 # Guess yes on glibc, HP-UX, IRIX, Solaris, native Windows.
20 *-gnu* | gnu* | hpux* | irix* | solaris* | mingw*)
21 gl_cv_func_setlocale_null_all_mtsafe=yes ;;
22 # If we don't know, obey --enable-cross-guesses.
23 *)
24 gl_cv_func_setlocale_null_all_mtsafe="$gl_cross_guess_normal" ;;
25 esac
26 ])
27 dnl On platforms without multithreading, there is no issue.
28 case "$host_os" in
29 mingw*) ;;
30 *)
31 if test $gl_pthread_api = no && test $ac_cv_header_threads_h = no; then
32 gl_cv_func_setlocale_null_all_mtsafe="trivially yes"
33 fi
34 ;;
35 esac
36 case "$gl_cv_func_setlocale_null_all_mtsafe" in
37 *yes) SETLOCALE_NULL_ALL_MTSAFE=1 ;;
38 *) SETLOCALE_NULL_ALL_MTSAFE=0 ;;
39 esac
40 AC_DEFINE_UNQUOTED([SETLOCALE_NULL_ALL_MTSAFE], [$SETLOCALE_NULL_ALL_MTSAFE],
41 [Define to 1 if setlocale (LC_ALL, NULL) is multithread-safe.])
42
43 dnl This is about a single category (not LC_ALL).
44 AC_CACHE_CHECK([whether setlocale (category, NULL) is multithread-safe],
45 [gl_cv_func_setlocale_null_one_mtsafe],
46 [case "$host_os" in
47 # Guess no on OpenBSD, AIX.
48 openbsd* | aix*)
49 gl_cv_func_setlocale_null_one_mtsafe=no ;;
50 # Guess yes on glibc, musl libc, macOS, FreeBSD, NetBSD, HP-UX, IRIX, Solaris, Haiku, Cygwin, native Windows.
51 *-gnu* | gnu* | *-musl* | darwin* | freebsd* | midnightbsd* | netbsd* | hpux* | irix* | solaris* | haiku* | cygwin* | mingw*)
52 gl_cv_func_setlocale_null_one_mtsafe=yes ;;
53 # If we don't know, obey --enable-cross-guesses.
54 *)
55 gl_cv_func_setlocale_null_one_mtsafe="$gl_cross_guess_normal" ;;
56 esac
57 ])
58 dnl On platforms without multithreading, there is no issue.
59 case "$host_os" in
60 mingw*) ;;
61 *)
62 if test $gl_pthread_api = no && test $ac_cv_header_threads_h = no; then
63 gl_cv_func_setlocale_null_one_mtsafe="trivially yes"
64 fi
65 ;;
66 esac
67 case "$gl_cv_func_setlocale_null_one_mtsafe" in
68 *yes) SETLOCALE_NULL_ONE_MTSAFE=1 ;;
69 *) SETLOCALE_NULL_ONE_MTSAFE=0 ;;
70 esac
71 AC_DEFINE_UNQUOTED([SETLOCALE_NULL_ONE_MTSAFE], [$SETLOCALE_NULL_ONE_MTSAFE],
72 [Define to 1 if setlocale (category, NULL) is multithread-safe.])
73
74 dnl Determine link dependencies of lib/setlocale_null.c and lib/setlocale-lock.c.
75 if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then
76 case "$host_os" in
77 mingw*) LIB_SETLOCALE_NULL= ;;
78 *)
79 gl_WEAK_SYMBOLS
80 case "$gl_cv_have_weak" in
81 *yes) LIB_SETLOCALE_NULL= ;;
82 *) LIB_SETLOCALE_NULL="$LIBPTHREAD" ;;
83 esac
84 ;;
85 esac
86 else
87 LIB_SETLOCALE_NULL=
88 fi
89 dnl LIB_SETLOCALE_NULL is expected to be '-pthread' or '-lpthread' on AIX
90 dnl with gcc or xlc, and empty otherwise.
91 AC_SUBST([LIB_SETLOCALE_NULL])
92])
93
94# Prerequisites of lib/setlocale-lock.c.
95AC_DEFUN([gl_PREREQ_SETLOCALE_LOCK],
96[
97 gl_VISIBILITY
98])
diff --git a/gl/m4/sha256.m4 b/gl/m4/sha256.m4
new file mode 100644
index 0000000..4d1d1dd
--- /dev/null
+++ b/gl/m4/sha256.m4
@@ -0,0 +1,14 @@
1# sha256.m4 serial 8
2dnl Copyright (C) 2005, 2008-2023 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_SHA256],
8[
9 dnl Prerequisites of lib/sha256.c.
10 AC_REQUIRE([gl_BIGENDIAN])
11
12 dnl Determine HAVE_OPENSSL_SHA256 and LIB_CRYPTO
13 gl_CRYPTO_CHECK([SHA256])
14])
diff --git a/gl/m4/size_max.m4 b/gl/m4/size_max.m4
index 4b247ab..0763366 100644
--- a/gl/m4/size_max.m4
+++ b/gl/m4/size_max.m4
@@ -1,17 +1,19 @@
1# size_max.m4 serial 10 1# size_max.m4 serial 12
2dnl Copyright (C) 2003, 2005-2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2005-2006, 2008-2023 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 From Bruno Haible. 7dnl From Bruno Haible.
8 8
9AC_PREREQ([2.61])
10
9AC_DEFUN([gl_SIZE_MAX], 11AC_DEFUN([gl_SIZE_MAX],
10[ 12[
11 AC_CHECK_HEADERS([stdint.h]) 13 AC_CHECK_HEADERS([stdint.h])
12 dnl First test whether the system already has SIZE_MAX. 14 dnl First test whether the system already has SIZE_MAX.
13 AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [ 15 AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [
14 gl_cv_size_max= 16 gl_cv_size_max=no
15 AC_EGREP_CPP([Found it], [ 17 AC_EGREP_CPP([Found it], [
16#include <limits.h> 18#include <limits.h>
17#if HAVE_STDINT_H 19#if HAVE_STDINT_H
@@ -21,7 +23,7 @@ AC_DEFUN([gl_SIZE_MAX],
21Found it 23Found it
22#endif 24#endif
23], [gl_cv_size_max=yes]) 25], [gl_cv_size_max=yes])
24 if test -z "$gl_cv_size_max"; then 26 if test $gl_cv_size_max != yes; then
25 dnl Define it ourselves. Here we assume that the type 'size_t' is not wider 27 dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
26 dnl than the type 'unsigned long'. Try hard to find a definition that can 28 dnl than the type 'unsigned long'. Try hard to find a definition that can
27 dnl be used in a preprocessor #if, i.e. doesn't contain a cast. 29 dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
@@ -71,9 +73,3 @@ Found it
71# undef SIZE_MAX 73# undef SIZE_MAX
72#endif]) 74#endif])
73]) 75])
74
75dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
76dnl Remove this when we can assume autoconf >= 2.61.
77m4_ifdef([AC_COMPUTE_INT], [], [
78 AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
79])
diff --git a/gl/m4/snprintf.m4 b/gl/m4/snprintf.m4
index 3698e84..4b5fbdb 100644
--- a/gl/m4/snprintf.m4
+++ b/gl/m4/snprintf.m4
@@ -1,5 +1,5 @@
1# snprintf.m4 serial 6 1# snprintf.m4 serial 7
2dnl Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2007-2023 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.
@@ -46,6 +46,14 @@ AC_DEFUN([gl_REPLACE_SNPRINTF],
46 AC_LIBOBJ([snprintf]) 46 AC_LIBOBJ([snprintf])
47 if test $ac_cv_func_snprintf = yes; then 47 if test $ac_cv_func_snprintf = yes; then
48 REPLACE_SNPRINTF=1 48 REPLACE_SNPRINTF=1
49 else
50 AC_CHECK_DECLS_ONCE([snprintf])
51 if test $ac_cv_have_decl_snprintf = yes; then
52 dnl If the function is declared but does not appear to exist, it may be
53 dnl defined as an inline function. In order to avoid a conflict, we have
54 dnl to define rpl_snprintf, not snprintf.
55 REPLACE_SNPRINTF=1
56 fi
49 fi 57 fi
50 gl_PREREQ_SNPRINTF 58 gl_PREREQ_SNPRINTF
51]) 59])
diff --git a/gl/m4/socketlib.m4 b/gl/m4/socketlib.m4
index b08a72f..a556af1 100644
--- a/gl/m4/socketlib.m4
+++ b/gl/m4/socketlib.m4
@@ -1,5 +1,5 @@
1# socketlib.m4 serial 1 1# socketlib.m4 serial 3
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 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,21 +14,27 @@ AC_DEFUN([gl_SOCKETLIB],
14 LIBSOCKET= 14 LIBSOCKET=
15 if test $HAVE_WINSOCK2_H = 1; then 15 if test $HAVE_WINSOCK2_H = 1; then
16 dnl Native Windows API (not Cygwin). 16 dnl Native Windows API (not Cygwin).
17 AC_CACHE_CHECK([if we need to call WSAStartup in winsock2.h and -lws2_32], 17 dnl If the function WSAStartup exists (declared in <winsock2.h> and
18 [gl_cv_func_wsastartup], [ 18 dnl defined through -lws2_32), we need to call it.
19 gl_save_LIBS="$LIBS" 19 AC_CACHE_CHECK([for WSAStartup],
20 LIBS="$LIBS -lws2_32" 20 [gl_cv_func_wsastartup], [
21 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 21 gl_save_LIBS="$LIBS"
22 LIBS="$LIBS -lws2_32"
23 AC_LINK_IFELSE(
24 [AC_LANG_PROGRAM([[
22#ifdef HAVE_WINSOCK2_H 25#ifdef HAVE_WINSOCK2_H
23# include <winsock2.h> 26# include <winsock2.h>
24#endif]], [[ 27#endif]], [[
25 WORD wVersionRequested = MAKEWORD(1, 1); 28 WORD wVersionRequested = MAKEWORD(1, 1);
26 WSADATA wsaData; 29 WSADATA wsaData;
27 int err = WSAStartup(wVersionRequested, &wsaData); 30 int err = WSAStartup(wVersionRequested, &wsaData);
28 WSACleanup ();]])], 31 WSACleanup ();
29 gl_cv_func_wsastartup=yes, gl_cv_func_wsastartup=no) 32 ]])
30 LIBS="$gl_save_LIBS" 33 ],
31 ]) 34 [gl_cv_func_wsastartup=yes],
35 [gl_cv_func_wsastartup=no])
36 LIBS="$gl_save_LIBS"
37 ])
32 if test "$gl_cv_func_wsastartup" = "yes"; then 38 if test "$gl_cv_func_wsastartup" = "yes"; then
33 AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.]) 39 AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
34 LIBSOCKET='-lws2_32' 40 LIBSOCKET='-lws2_32'
@@ -38,6 +44,10 @@ AC_DEFUN([gl_SOCKETLIB],
38 dnl Solaris has most socket functions in libsocket. 44 dnl Solaris has most socket functions in libsocket.
39 dnl Haiku has most socket functions in libnetwork. 45 dnl Haiku has most socket functions in libnetwork.
40 dnl BeOS has most socket functions in libnet. 46 dnl BeOS has most socket functions in libnet.
47 dnl On HP-UX, do NOT link with libxnet, because in 64-bit mode this would
48 dnl break code (e.g. in libraries) that invokes accept(), getpeername(),
49 dnl getsockname(), getsockopt(), or recvfrom() with a 32-bit addrlen. See
50 dnl "man xopen_networking" for details.
41 AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [ 51 AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
42 gl_cv_lib_socket= 52 gl_cv_lib_socket=
43 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern 53 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
diff --git a/gl/m4/sockets.m4 b/gl/m4/sockets.m4
index b407391..ed9cb87 100644
--- a/gl/m4/sockets.m4
+++ b/gl/m4/sockets.m4
@@ -1,5 +1,5 @@
1# sockets.m4 serial 7 1# sockets.m4 serial 7
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4
index e3efd6e..1c63a85 100644
--- a/gl/m4/socklen.m4
+++ b/gl/m4/socklen.m4
@@ -1,5 +1,5 @@
1# socklen.m4 serial 10 1# socklen.m4 serial 11
2dnl Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2007, 2009-2023 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.
@@ -15,8 +15,8 @@ dnl So we have to test to find something that will work.
15AC_DEFUN([gl_TYPE_SOCKLEN_T], 15AC_DEFUN([gl_TYPE_SOCKLEN_T],
16 [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl 16 [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
17 AC_CHECK_TYPE([socklen_t], , 17 AC_CHECK_TYPE([socklen_t], ,
18 [AC_MSG_CHECKING([for socklen_t equivalent]) 18 [AC_CACHE_CHECK([for socklen_t equivalent],
19 AC_CACHE_VAL([gl_cv_socklen_t_equiv], 19 [gl_cv_socklen_t_equiv],
20 [# Systems have either "struct sockaddr *" or 20 [# Systems have either "struct sockaddr *" or
21 # "void *" as the second argument to getpeername 21 # "void *" as the second argument to getpeername
22 gl_cv_socklen_t_equiv= 22 gl_cv_socklen_t_equiv=
@@ -34,11 +34,10 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T],
34 done 34 done
35 test "$gl_cv_socklen_t_equiv" != "" && break 35 test "$gl_cv_socklen_t_equiv" != "" && break
36 done 36 done
37 ]) 37 if test "$gl_cv_socklen_t_equiv" = ""; then
38 if test "$gl_cv_socklen_t_equiv" = ""; then 38 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
39 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 39 fi
40 fi 40 ])
41 AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
42 AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], 41 AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
43 [type to use in place of socklen_t if not defined])], 42 [type to use in place of socklen_t if not defined])],
44 [gl_SOCKET_HEADERS])]) 43 [gl_SOCKET_HEADERS])])
diff --git a/gl/m4/sockpfaf.m4 b/gl/m4/sockpfaf.m4
index 89557b1..6c6dc2f 100644
--- a/gl/m4/sockpfaf.m4
+++ b/gl/m4/sockpfaf.m4
@@ -1,5 +1,5 @@
1# sockpfaf.m4 serial 8 1# sockpfaf.m4 serial 10
2dnl Copyright (C) 2004, 2006, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -13,11 +13,11 @@ dnl From Bruno Haible.
13 13
14AC_DEFUN([gl_SOCKET_FAMILIES], 14AC_DEFUN([gl_SOCKET_FAMILIES],
15[ 15[
16 AC_REQUIRE([gl_HEADER_SYS_SOCKET]) 16 AC_REQUIRE([gl_SYS_SOCKET_H])
17 AC_CHECK_HEADERS_ONCE([netinet/in.h]) 17 AC_CHECK_HEADERS_ONCE([netinet/in.h])
18 18
19 AC_MSG_CHECKING([for IPv4 sockets]) 19 AC_CACHE_CHECK([for IPv4 sockets],
20 AC_CACHE_VAL([gl_cv_socket_ipv4], 20 [gl_cv_socket_ipv4],
21 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> 21 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
22#ifdef HAVE_SYS_SOCKET_H 22#ifdef HAVE_SYS_SOCKET_H
23#include <sys/socket.h> 23#include <sys/socket.h>
@@ -31,13 +31,12 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
31[[int x = AF_INET; struct in_addr y; struct sockaddr_in z; 31[[int x = AF_INET; struct in_addr y; struct sockaddr_in z;
32 if (&x && &y && &z) return 0;]])], 32 if (&x && &y && &z) return 0;]])],
33 gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)]) 33 gl_cv_socket_ipv4=yes, gl_cv_socket_ipv4=no)])
34 AC_MSG_RESULT([$gl_cv_socket_ipv4])
35 if test $gl_cv_socket_ipv4 = yes; then 34 if test $gl_cv_socket_ipv4 = yes; then
36 AC_DEFINE([HAVE_IPV4], [1], [Define to 1 if <sys/socket.h> defines AF_INET.]) 35 AC_DEFINE([HAVE_IPV4], [1], [Define to 1 if <sys/socket.h> defines AF_INET.])
37 fi 36 fi
38 37
39 AC_MSG_CHECKING([for IPv6 sockets]) 38 AC_CACHE_CHECK([for IPv6 sockets],
40 AC_CACHE_VAL([gl_cv_socket_ipv6], 39 [gl_cv_socket_ipv6],
41 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> 40 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
42#ifdef HAVE_SYS_SOCKET_H 41#ifdef HAVE_SYS_SOCKET_H
43#include <sys/socket.h> 42#include <sys/socket.h>
@@ -54,7 +53,6 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
54[[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z; 53[[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;
55 if (&x && &y && &z) return 0;]])], 54 if (&x && &y && &z) return 0;]])],
56 gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)]) 55 gl_cv_socket_ipv6=yes, gl_cv_socket_ipv6=no)])
57 AC_MSG_RESULT([$gl_cv_socket_ipv6])
58 if test $gl_cv_socket_ipv6 = yes; then 56 if test $gl_cv_socket_ipv6 = yes; then
59 AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines AF_INET6.]) 57 AC_DEFINE([HAVE_IPV6], [1], [Define to 1 if <sys/socket.h> defines AF_INET6.])
60 fi 58 fi
@@ -62,11 +60,11 @@ AC_DEFUN([gl_SOCKET_FAMILIES],
62 60
63AC_DEFUN([gl_SOCKET_FAMILY_UNIX], 61AC_DEFUN([gl_SOCKET_FAMILY_UNIX],
64[ 62[
65 AC_REQUIRE([gl_HEADER_SYS_SOCKET]) 63 AC_REQUIRE([gl_SYS_SOCKET_H])
66 AC_CHECK_HEADERS_ONCE([sys/un.h]) 64 AC_CHECK_HEADERS_ONCE([sys/un.h])
67 65
68 AC_MSG_CHECKING([for UNIX domain sockets]) 66 AC_CACHE_CHECK([for UNIX domain sockets],
69 AC_CACHE_VAL([gl_cv_socket_unix], 67 [gl_cv_socket_unix],
70 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> 68 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
71#ifdef HAVE_SYS_SOCKET_H 69#ifdef HAVE_SYS_SOCKET_H
72#include <sys/socket.h> 70#include <sys/socket.h>
@@ -80,7 +78,6 @@ AC_DEFUN([gl_SOCKET_FAMILY_UNIX],
80[[int x = AF_UNIX; struct sockaddr_un y; 78[[int x = AF_UNIX; struct sockaddr_un y;
81 if (&x && &y) return 0;]])], 79 if (&x && &y) return 0;]])],
82 gl_cv_socket_unix=yes, gl_cv_socket_unix=no)]) 80 gl_cv_socket_unix=yes, gl_cv_socket_unix=no)])
83 AC_MSG_RESULT([$gl_cv_socket_unix])
84 if test $gl_cv_socket_unix = yes; then 81 if test $gl_cv_socket_unix = yes; then
85 AC_DEFINE([HAVE_UNIXSOCKET], [1], [Define to 1 if <sys/socket.h> defines AF_UNIX.]) 82 AC_DEFINE([HAVE_UNIXSOCKET], [1], [Define to 1 if <sys/socket.h> defines AF_UNIX.])
86 fi 83 fi
diff --git a/gl/m4/ssize_t.m4 b/gl/m4/ssize_t.m4
index 6338134..1c12c33 100644
--- a/gl/m4/ssize_t.m4
+++ b/gl/m4/ssize_t.m4
@@ -1,5 +1,5 @@
1# ssize_t.m4 serial 5 (gettext-0.18.2) 1# ssize_t.m4 serial 5 (gettext-0.18.2)
2dnl Copyright (C) 2001-2003, 2006, 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2003, 2006, 2010-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/stat-time.m4 b/gl/m4/stat-time.m4
new file mode 100644
index 0000000..40993d5
--- /dev/null
+++ b/gl/m4/stat-time.m4
@@ -0,0 +1,83 @@
1# Checks for stat-related time functions.
2
3# Copyright (C) 1998-1999, 2001, 2003, 2005-2007, 2009-2023 Free Software
4# Foundation, Inc.
5
6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved.
9
10dnl From Paul Eggert.
11
12# st_atim.tv_nsec - Linux, Solaris, Cygwin
13# st_atimespec.tv_nsec - FreeBSD, NetBSD, if ! defined _POSIX_SOURCE
14# st_atimensec - FreeBSD, NetBSD, if defined _POSIX_SOURCE
15# st_atim.st__tim.tv_nsec - UnixWare (at least 2.1.2 through 7.1)
16
17# st_birthtimespec - FreeBSD, NetBSD (hidden on OpenBSD 3.9, anyway)
18# st_birthtim - Cygwin 1.7.0+
19
20AC_DEFUN([gl_STAT_TIME],
21[
22 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
23 AC_CHECK_HEADERS_ONCE([sys/time.h])
24
25 AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec],
26 [AC_CACHE_CHECK([whether struct stat.st_atim is of type struct timespec],
27 [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec],
28 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
29 [[
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #if HAVE_SYS_TIME_H
33 # include <sys/time.h>
34 #endif
35 #include <time.h>
36 struct timespec ts;
37 struct stat st;
38 ]],
39 [[
40 st.st_atim = ts;
41 ]])],
42 [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=yes],
43 [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=no])])
44 if test $ac_cv_typeof_struct_stat_st_atim_is_struct_timespec = yes; then
45 AC_DEFINE([TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC], [1],
46 [Define to 1 if the type of the st_atim member of a struct stat is
47 struct timespec.])
48 fi],
49 [AC_CHECK_MEMBERS([struct stat.st_atimespec.tv_nsec], [],
50 [AC_CHECK_MEMBERS([struct stat.st_atimensec], [],
51 [AC_CHECK_MEMBERS([struct stat.st_atim.st__tim.tv_nsec], [], [],
52 [#include <sys/types.h>
53 #include <sys/stat.h>])],
54 [#include <sys/types.h>
55 #include <sys/stat.h>])],
56 [#include <sys/types.h>
57 #include <sys/stat.h>])],
58 [#include <sys/types.h>
59 #include <sys/stat.h>])
60])
61
62# Check for st_birthtime, a feature from UFS2 (FreeBSD, NetBSD, OpenBSD, etc.)
63# and NTFS (Cygwin).
64# There was a time when this field was named st_createtime (21 June
65# 2002 to 16 July 2002) But that window is very small and applied only
66# to development code, so systems still using that configuration are
67# not supported. See revisions 1.10 and 1.11 of FreeBSD's
68# src/sys/ufs/ufs/dinode.h.
69#
70AC_DEFUN([gl_STAT_BIRTHTIME],
71[
72 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
73 AC_CHECK_HEADERS_ONCE([sys/time.h])
74 AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec], [],
75 [AC_CHECK_MEMBERS([struct stat.st_birthtimensec], [],
76 [AC_CHECK_MEMBERS([struct stat.st_birthtim.tv_nsec], [], [],
77 [#include <sys/types.h>
78 #include <sys/stat.h>])],
79 [#include <sys/types.h>
80 #include <sys/stat.h>])],
81 [#include <sys/types.h>
82 #include <sys/stat.h>])
83])
diff --git a/gl/m4/stat.m4 b/gl/m4/stat.m4
new file mode 100644
index 0000000..4d241e2
--- /dev/null
+++ b/gl/m4/stat.m4
@@ -0,0 +1,85 @@
1# serial 18
2
3# Copyright (C) 2009-2023 Free Software Foundation, Inc.
4#
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9AC_DEFUN([gl_FUNC_STAT],
10[
11 AC_REQUIRE([AC_CANONICAL_HOST])
12 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
13 AC_CHECK_FUNCS_ONCE([lstat])
14 case "$host_os" in
15 mingw*)
16 dnl On this platform, the original stat() returns st_atime, st_mtime,
17 dnl st_ctime values that are affected by the time zone.
18 REPLACE_STAT=1
19 ;;
20 *)
21 dnl AIX 7.1, Solaris 9, mingw64 mistakenly succeed on stat("file/").
22 dnl (For mingw, this is due to a broken stat() override in libmingwex.a.)
23 dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/").
24 AC_CACHE_CHECK([whether stat handles trailing slashes on files],
25 [gl_cv_func_stat_file_slash],
26 [touch conftest.tmp
27 # Assume that if we have lstat, we can also check symlinks.
28 if test $ac_cv_func_lstat = yes; then
29 ln -s conftest.tmp conftest.lnk
30 fi
31 AC_RUN_IFELSE(
32 [AC_LANG_PROGRAM(
33 [[#include <sys/stat.h>
34]], [[int result = 0;
35 struct stat st;
36 if (!stat ("conftest.tmp/", &st))
37 result |= 1;
38#if HAVE_LSTAT
39 if (!stat ("conftest.lnk/", &st))
40 result |= 2;
41#endif
42 return result;
43 ]])],
44 [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
45 [case "$host_os" in
46 # Guess yes on Linux systems.
47 linux-* | linux) gl_cv_func_stat_file_slash="guessing yes" ;;
48 # Guess yes on glibc systems.
49 *-gnu* | gnu*) gl_cv_func_stat_file_slash="guessing yes" ;;
50 # If we don't know, obey --enable-cross-guesses.
51 *) gl_cv_func_stat_file_slash="$gl_cross_guess_normal" ;;
52 esac
53 ])
54 rm -f conftest.tmp conftest.lnk])
55 case $gl_cv_func_stat_file_slash in
56 *no)
57 REPLACE_STAT=1
58 AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
59 help when passed a file name with a trailing slash]);;
60 esac
61 case $host_os in
62 dnl Solaris stat can return a negative tv_nsec.
63 solaris*)
64 REPLACE_FSTAT=1 ;;
65 esac
66 ;;
67 esac
68])
69
70# Prerequisites of lib/stat.c and lib/stat-w32.c.
71AC_DEFUN([gl_PREREQ_STAT], [
72 AC_REQUIRE([gl_SYS_STAT_H])
73 AC_REQUIRE([gl_PREREQ_STAT_W32])
74 :
75])
76
77# Prerequisites of lib/stat-w32.c.
78AC_DEFUN([gl_PREREQ_STAT_W32], [
79 AC_REQUIRE([AC_CANONICAL_HOST])
80 case "$host_os" in
81 mingw*)
82 AC_CHECK_HEADERS([sdkddkver.h])
83 ;;
84 esac
85])
diff --git a/gl/m4/std-gnu11.m4 b/gl/m4/std-gnu11.m4
new file mode 100644
index 0000000..4179470
--- /dev/null
+++ b/gl/m4/std-gnu11.m4
@@ -0,0 +1,829 @@
1# Prefer GNU C11 and C++11 to earlier versions. -*- coding: utf-8 -*-
2
3# This implementation is taken from GNU Autoconf lib/autoconf/c.m4
4# commit 017d5ddd82854911f0119691d91ea8a1438824d6
5# dated Sun Apr 3 13:57:17 2016 -0700
6# This implementation will be obsolete once we can assume Autoconf 2.70
7# or later is installed everywhere a Gnulib program might be developed.
8
9m4_version_prereq([2.70], [], [
10
11
12# Copyright (C) 2001-2023 Free Software Foundation, Inc.
13
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation, either version 3 of the License, or
17# (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program. If not, see <https://www.gnu.org/licenses/>.
26
27# Written by David MacKenzie, with help from
28# Akim Demaille, Paul Eggert,
29# François Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
30# Roland McGrath, Noah Friedman, david d zuhn, and many others.
31
32
33# AC_PROG_CC([COMPILER ...])
34# --------------------------
35# COMPILER ... is a space separated list of C compilers to search for.
36# This just gives the user an opportunity to specify an alternative
37# search list for the C compiler.
38AC_DEFUN_ONCE([AC_PROG_CC],
39[AC_LANG_PUSH(C)dnl
40AC_ARG_VAR([CC], [C compiler command])dnl
41AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
42_AC_ARG_VAR_LDFLAGS()dnl
43_AC_ARG_VAR_LIBS()dnl
44_AC_ARG_VAR_CPPFLAGS()dnl
45m4_ifval([$1],
46 [AC_CHECK_TOOLS(CC, [$1])],
47[AC_CHECK_TOOL(CC, gcc)
48if test -z "$CC"; then
49 dnl Here we want:
50 dnl AC_CHECK_TOOL(CC, cc)
51 dnl but without the check for a tool without the prefix.
52 dnl Until the check is removed from there, copy the code:
53 if test -n "$ac_tool_prefix"; then
54 AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
55 fi
56fi
57if test -z "$CC"; then
58 AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
59fi
60if test -z "$CC"; then
61 AC_CHECK_TOOLS(CC, cl.exe)
62fi
63if test -z "$CC"; then
64 AC_CHECK_TOOL(CC, clang)
65fi
66])
67
68test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
69
70# Provide some information about the compiler.
71_AS_ECHO_LOG([checking for _AC_LANG compiler version])
72set X $ac_compile
73ac_compiler=$[2]
74for ac_option in --version -v -V -qversion -version; do
75 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
76done
77
78m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
79m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
80_AC_LANG_COMPILER_GNU
81if test $ac_compiler_gnu = yes; then
82 GCC=yes
83else
84 GCC=
85fi
86_AC_PROG_CC_G
87dnl
88dnl Set ac_prog_cc_stdc to the supported C version.
89dnl Also set the documented variable ac_cv_prog_cc_stdc;
90dnl its name was chosen when it was cached, but it is no longer cached.
91_AC_PROG_CC_C11([ac_prog_cc_stdc=c11
92 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
93 [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
94 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
95 [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
96 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
97 [ac_prog_cc_stdc=no
98 ac_cv_prog_cc_stdc=no])])])
99dnl
100AC_LANG_POP(C)dnl
101])# AC_PROG_CC
102
103
104
105# AC_PROG_CXX([LIST-OF-COMPILERS])
106# --------------------------------
107# LIST-OF-COMPILERS is a space separated list of C++ compilers to search
108# for (if not specified, a default list is used). This just gives the
109# user an opportunity to specify an alternative search list for the C++
110# compiler.
111# aCC HP-UX C++ compiler much better than `CC', so test before.
112# FCC Fujitsu C++ compiler
113# KCC KAI C++ compiler
114# RCC Rational C++
115# xlC_r AIX C Set++ (with support for reentrant code)
116# xlC AIX C Set++
117AC_DEFUN([AC_PROG_CXX],
118[AC_LANG_PUSH(C++)dnl
119AC_ARG_VAR([CXX], [C++ compiler command])dnl
120AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
121_AC_ARG_VAR_LDFLAGS()dnl
122_AC_ARG_VAR_LIBS()dnl
123_AC_ARG_VAR_CPPFLAGS()dnl
124_AC_ARG_VAR_PRECIOUS([CCC])dnl
125if test -z "$CXX"; then
126 if test -n "$CCC"; then
127 CXX=$CCC
128 else
129 AC_CHECK_TOOLS(CXX,
130 [m4_default([$1],
131 [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++])],
132 g++)
133 fi
134fi
135# Provide some information about the compiler.
136_AS_ECHO_LOG([checking for _AC_LANG compiler version])
137set X $ac_compile
138ac_compiler=$[2]
139for ac_option in --version -v -V -qversion; do
140 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
141done
142
143m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
144m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
145_AC_LANG_COMPILER_GNU
146if test $ac_compiler_gnu = yes; then
147 GXX=yes
148else
149 GXX=
150fi
151_AC_PROG_CXX_G
152_AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
153 ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11
154 ac_cv_prog_cxx_cxx98=$ac_cv_prog_cxx_cxx11],
155 [_AC_PROG_CXX_CXX98([ac_prog_cxx_stdcxx=cxx98
156 ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
157 [ac_prog_cxx_stdcxx=no
158 ac_cv_prog_cxx_stdcxx=no])])
159AC_LANG_POP(C++)dnl
160])# AC_PROG_CXX
161
162
163# _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
164# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
165# --------------------------------------------------------------
166# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
167# by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
168# try again with each compiler option in the space-separated OPTION-LIST; if one
169# helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
170# else ACTION-IF-UNAVAILABLE.
171AC_DEFUN([_AC_C_STD_TRY],
172[AC_MSG_CHECKING([for $CC option to enable ]m4_translit($1, [c], [C])[ features])
173AC_CACHE_VAL(ac_cv_prog_cc_$1,
174[ac_cv_prog_cc_$1=no
175ac_save_CC=$CC
176AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
177for ac_arg in '' $4
178do
179 CC="$ac_save_CC $ac_arg"
180 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
181 test "x$ac_cv_prog_cc_$1" != "xno" && break
182done
183rm -f conftest.$ac_ext
184CC=$ac_save_CC
185])# AC_CACHE_VAL
186ac_prog_cc_stdc_options=
187case "x$ac_cv_prog_cc_$1" in
188 x)
189 AC_MSG_RESULT([none needed]) ;;
190 xno)
191 AC_MSG_RESULT([unsupported]) ;;
192 *)
193 ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
194 CC=$CC$ac_prog_cc_stdc_options
195 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
196esac
197AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
198])# _AC_C_STD_TRY
199
200# _AC_C_C99_TEST_HEADER
201# ---------------------
202# A C header suitable for testing for C99.
203AC_DEFUN([_AC_C_C99_TEST_HEADER],
204[[#include <stdarg.h>
205#include <stdbool.h>
206#include <stddef.h>
207#include <stdlib.h>
208#include <wchar.h>
209#include <stdio.h>
210
211// Check varargs macros. These examples are taken from C99 6.10.3.5.
212#define debug(...) fprintf (stderr, __VA_ARGS__)
213#define showlist(...) puts (#__VA_ARGS__)
214#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
215static void
216test_varargs_macros (void)
217{
218 int x = 1234;
219 int y = 5678;
220 debug ("Flag");
221 debug ("X = %d\n", x);
222 showlist (The first, second, and third items.);
223 report (x>y, "x is %d but y is %d", x, y);
224}
225
226// Check long long types.
227#define BIG64 18446744073709551615ull
228#define BIG32 4294967295ul
229#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
230#if !BIG_OK
231 your preprocessor is broken;
232#endif
233#if BIG_OK
234#else
235 your preprocessor is broken;
236#endif
237static long long int bignum = -9223372036854775807LL;
238static unsigned long long int ubignum = BIG64;
239
240struct incomplete_array
241{
242 int datasize;
243 double data[];
244};
245
246struct named_init {
247 int number;
248 const wchar_t *name;
249 double average;
250};
251
252typedef const char *ccp;
253
254static inline int
255test_restrict (ccp restrict text)
256{
257 // See if C++-style comments work.
258 // Iterate through items via the restricted pointer.
259 // Also check for declarations in for loops.
260 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
261 continue;
262 return 0;
263}
264
265// Check varargs and va_copy.
266static bool
267test_varargs (const char *format, ...)
268{
269 va_list args;
270 va_start (args, format);
271 va_list args_copy;
272 va_copy (args_copy, args);
273
274 const char *str = "";
275 int number = 0;
276 float fnumber = 0;
277
278 while (*format)
279 {
280 switch (*format++)
281 {
282 case 's': // string
283 str = va_arg (args_copy, const char *);
284 break;
285 case 'd': // int
286 number = va_arg (args_copy, int);
287 break;
288 case 'f': // float
289 fnumber = va_arg (args_copy, double);
290 break;
291 default:
292 break;
293 }
294 }
295 va_end (args_copy);
296 va_end (args);
297
298 return *str && number && fnumber;
299}]])# _AC_C_C99_TEST_HEADER
300
301# _AC_C_C99_TEST_BODY
302# -------------------
303# A C body suitable for testing for C99, assuming the corresponding header.
304AC_DEFUN([_AC_C_C99_TEST_BODY],
305[[
306 // Check bool.
307 _Bool success = false;
308
309 // Check restrict.
310 if (test_restrict ("String literal") == 0)
311 success = true;
312 char *restrict newvar = "Another string";
313
314 // Check varargs.
315 success &= test_varargs ("s, d' f .", "string", 65, 34.234);
316 test_varargs_macros ();
317
318 // Check flexible array members.
319 struct incomplete_array *ia =
320 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
321 ia->datasize = 10;
322 for (int i = 0; i < ia->datasize; ++i)
323 ia->data[i] = i * 1.234;
324
325 // Check named initializers.
326 struct named_init ni = {
327 .number = 34,
328 .name = L"Test wide string",
329 .average = 543.34343,
330 };
331
332 ni.number = 58;
333
334 int dynamic_array[ni.number];
335 dynamic_array[ni.number - 1] = 543;
336
337 // work around unused variable warnings
338 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
339 || dynamic_array[ni.number - 1] != 543);
340]])
341
342# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
343# ----------------------------------------------------------------
344# If the C compiler is not in ISO C99 mode by default, try to add an
345# option to output variable CC to make it so. This macro tries
346# various options that select ISO C99 on some system or another. It
347# considers the compiler to be in ISO C99 mode if it handles _Bool,
348# // comments, flexible array members, inline, long long int, mixed
349# code and declarations, named initialization of structs, restrict,
350# va_copy, varargs macros, variable declarations in for loops and
351# variable length arrays.
352AC_DEFUN([_AC_PROG_CC_C99],
353[_AC_C_STD_TRY([c99],
354[_AC_C_C99_TEST_HEADER],
355[_AC_C_C99_TEST_BODY],
356dnl Try
357dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
358dnl IBM XL C -qlanglvl=extc1x (V12.1; does not pass C11 test)
359dnl IBM XL C -qlanglvl=extc99
360dnl (pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
361dnl HP cc -AC99
362dnl Intel ICC -std=c99, -c99 (deprecated)
363dnl IRIX -c99
364dnl Solaris -D_STDC_C99=
365dnl cc's -xc99 option uses linker magic to define the external
366dnl symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
367dnl behavior for C library functions. This is not wanted here,
368dnl because it means that a single module compiled with -xc99
369dnl alters C runtime behavior for the entire program, not for
370dnl just the module. Instead, define the (private) symbol
371dnl _STDC_C99, which suppresses a bogus failure in <stdbool.h>.
372dnl The resulting compiler passes the test case here, and that's
373dnl good enough. For more, please see the thread starting at:
374dnl https://lists.gnu.org/r/autoconf/2010-12/msg00059.html
375dnl Tru64 -c99
376dnl with extended modes being tried first.
377[[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
378])# _AC_PROG_CC_C99
379
380
381# _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
382# ----------------------------------------------------------------
383# If the C compiler is not in ISO C11 mode by default, try to add an
384# option to output variable CC to make it so. This macro tries
385# various options that select ISO C11 on some system or another. It
386# considers the compiler to be in ISO C11 mode if it handles _Alignas,
387# _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
388# duplicate typedefs, and anonymous structures and unions.
389AC_DEFUN([_AC_PROG_CC_C11],
390[_AC_C_STD_TRY([c11],
391[_AC_C_C99_TEST_HEADER[
392// Check _Alignas.
393char _Alignas (double) aligned_as_double;
394char _Alignas (0) no_special_alignment;
395extern char aligned_as_int;
396char _Alignas (0) _Alignas (int) aligned_as_int;
397
398// Check _Alignof.
399enum
400{
401 int_alignment = _Alignof (int),
402 int_array_alignment = _Alignof (int[100]),
403 char_alignment = _Alignof (char)
404};
405_Static_assert (0 < -_Alignof (int), "_Alignof is signed");
406
407// Check _Noreturn.
408int _Noreturn does_not_return (void) { for (;;) continue; }
409
410// Check _Static_assert.
411struct test_static_assert
412{
413 int x;
414 _Static_assert (sizeof (int) <= sizeof (long int),
415 "_Static_assert does not work in struct");
416 long int y;
417};
418
419// Check UTF-8 literals.
420#define u8 syntax error!
421char const utf8_literal[] = u8"happens to be ASCII" "another string";
422
423// Check duplicate typedefs.
424typedef long *long_ptr;
425typedef long int *long_ptr;
426typedef long_ptr long_ptr;
427
428// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
429struct anonymous
430{
431 union {
432 struct { int i; int j; };
433 struct { int k; long int l; } w;
434 };
435 int m;
436} v1;
437]],
438[_AC_C_C99_TEST_BODY[
439 v1.i = 2;
440 v1.w.k = 5;
441 _Static_assert ((offsetof (struct anonymous, i)
442 == offsetof (struct anonymous, w.k)),
443 "Anonymous union alignment botch");
444]],
445dnl Try
446dnl GCC -std=gnu11 (unused restrictive mode: -std=c11)
447dnl with extended modes being tried first.
448dnl
449dnl Do not try -qlanglvl=extc1x, because IBM XL C V12.1 (the latest version as
450dnl of September 2012) does not pass the C11 test. For now, try extc1x when
451dnl compiling the C99 test instead, since it enables _Static_assert and
452dnl _Noreturn, which is a win. If -qlanglvl=extc11 or -qlanglvl=extc1x passes
453dnl the C11 test in some future version of IBM XL C, we'll add it here,
454dnl preferably extc11.
455[[-std=gnu11]], [$1], [$2])[]dnl
456])# _AC_PROG_CC_C11
457
458
459# AC_PROG_CC_C89
460# --------------
461# Do not use AU_ALIAS here and in AC_PROG_CC_C99 and AC_PROG_CC_STDC,
462# as that'd be incompatible with how Automake redefines AC_PROG_CC. See
463# <https://lists.gnu.org/r/autoconf/2012-10/msg00048.html>.
464AU_DEFUN([AC_PROG_CC_C89],
465 [AC_REQUIRE([AC_PROG_CC])],
466 [$0 is obsolete; use AC_PROG_CC]
467)
468
469# AC_PROG_CC_C99
470# --------------
471AU_DEFUN([AC_PROG_CC_C99],
472 [AC_REQUIRE([AC_PROG_CC])],
473 [$0 is obsolete; use AC_PROG_CC]
474)
475
476# AC_PROG_CC_STDC
477# ---------------
478AU_DEFUN([AC_PROG_CC_STDC],
479 [AC_REQUIRE([AC_PROG_CC])],
480 [$0 is obsolete; use AC_PROG_CC]
481)
482
483
484# AC_C_PROTOTYPES
485# ---------------
486# Check if the C compiler supports prototypes, included if it needs
487# options.
488AC_DEFUN([AC_C_PROTOTYPES],
489[AC_REQUIRE([AC_PROG_CC])dnl
490if test "$ac_prog_cc_stdc" != no; then
491 AC_DEFINE(PROTOTYPES, 1,
492 [Define to 1 if the C compiler supports function prototypes.])
493 AC_DEFINE(__PROTOTYPES, 1,
494 [Define like PROTOTYPES; this can be used by system headers.])
495fi
496])# AC_C_PROTOTYPES
497
498
499# _AC_CXX_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
500# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
501# ----------------------------------------------------------------
502# Check whether the C++ compiler accepts features of STANDARD (e.g
503# `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE
504# and TEST-BODY. If this fails, try again with each compiler option
505# in the space-separated OPTION-LIST; if one helps, append it to CXX.
506# If eventually successful, run ACTION-IF-AVAILABLE, else
507# ACTION-IF-UNAVAILABLE.
508AC_DEFUN([_AC_CXX_STD_TRY],
509[AC_MSG_CHECKING([for $CXX option to enable ]m4_translit(m4_translit($1, [x], [+]), [a-z], [A-Z])[ features])
510AC_LANG_PUSH(C++)dnl
511AC_CACHE_VAL(ac_cv_prog_cxx_$1,
512[ac_cv_prog_cxx_$1=no
513ac_save_CXX=$CXX
514AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
515for ac_arg in '' $4
516do
517 CXX="$ac_save_CXX $ac_arg"
518 _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg])
519 test "x$ac_cv_prog_cxx_$1" != "xno" && break
520done
521rm -f conftest.$ac_ext
522CXX=$ac_save_CXX
523])# AC_CACHE_VAL
524ac_prog_cxx_stdcxx_options=
525case "x$ac_cv_prog_cxx_$1" in
526 x)
527 AC_MSG_RESULT([none needed]) ;;
528 xno)
529 AC_MSG_RESULT([unsupported]) ;;
530 *)
531 ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1"
532 CXX=$CXX$ac_prog_cxx_stdcxx_options
533 AC_MSG_RESULT([$ac_cv_prog_cxx_$1]) ;;
534esac
535AC_LANG_POP(C++)dnl
536AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$5], [$6])
537])# _AC_CXX_STD_TRY
538
539# _AC_CXX_CXX98_TEST_HEADER
540# -------------------------
541# A C++ header suitable for testing for CXX98.
542AC_DEFUN([_AC_CXX_CXX98_TEST_HEADER],
543[[
544#include <algorithm>
545#include <cstdlib>
546#include <fstream>
547#include <iomanip>
548#include <iostream>
549#include <list>
550#include <map>
551#include <set>
552#include <sstream>
553#include <stdexcept>
554#include <string>
555#include <utility>
556#include <vector>
557
558namespace test {
559 typedef std::vector<std::string> string_vec;
560 typedef std::pair<int,bool> map_value;
561 typedef std::map<std::string,map_value> map_type;
562 typedef std::set<int> set_type;
563
564 template<typename T>
565 class printer {
566 public:
567 printer(std::ostringstream& os): os(os) {}
568 void operator() (T elem) { os << elem << std::endl; }
569 private:
570 std::ostringstream& os;
571 };
572}
573]])# _AC_CXX_CXX98_TEST_HEADER
574
575# _AC_CXX_CXX98_TEST_BODY
576# -----------------------
577# A C++ body suitable for testing for CXX98, assuming the corresponding header.
578AC_DEFUN([_AC_CXX_CXX98_TEST_BODY],
579[[
580
581try {
582 // Basic string.
583 std::string teststr("ASCII text");
584 teststr += " string";
585
586 // Simple vector.
587 test::string_vec testvec;
588 testvec.push_back(teststr);
589 testvec.push_back("foo");
590 testvec.push_back("bar");
591 if (testvec.size() != 3) {
592 throw std::runtime_error("vector size is not 1");
593 }
594
595 // Dump vector into stringstream and obtain string.
596 std::ostringstream os;
597 for (test::string_vec::const_iterator i = testvec.begin();
598 i != testvec.end(); ++i) {
599 if (i + 1 != testvec.end()) {
600 os << teststr << '\n';
601 }
602 }
603 // Check algorithms work.
604 std::for_each(testvec.begin(), testvec.end(), test::printer<std::string>(os));
605 std::string os_out = os.str();
606
607 // Test pair and map.
608 test::map_type testmap;
609 testmap.insert(std::make_pair(std::string("key"),
610 std::make_pair(53,false)));
611
612 // Test set.
613 int values[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
614 test::set_type testset(values, values + sizeof(values)/sizeof(values[0]));
615 std::list<int> testlist(testset.begin(), testset.end());
616 std::copy(testset.begin(), testset.end(), std::back_inserter(testlist));
617} catch (const std::exception& e) {
618 std::cerr << "Caught exception: " << e.what() << std::endl;
619
620 // Test fstream
621 std::ofstream of("test.txt");
622 of << "Test ASCII text\n" << std::flush;
623 of << "N= " << std::hex << std::setw(8) << std::left << 534 << std::endl;
624 of.close();
625}
626std::exit(0);
627]])
628
629# _AC_CXX_CXX11_TEST_HEADER
630# -------------------------
631# A C++ header suitable for testing for CXX11.
632AC_DEFUN([_AC_CXX_CXX11_TEST_HEADER],
633[[
634#include <deque>
635#include <functional>
636#include <memory>
637#include <tuple>
638#include <array>
639#include <regex>
640#include <iostream>
641
642namespace cxx11test
643{
644 typedef std::shared_ptr<std::string> sptr;
645 typedef std::weak_ptr<std::string> wptr;
646
647 typedef std::tuple<std::string,int,double> tp;
648 typedef std::array<int, 20> int_array;
649
650 constexpr int get_val() { return 20; }
651
652 struct testinit
653 {
654 int i;
655 double d;
656 };
657
658 class delegate {
659 public:
660 delegate(int n) : n(n) {}
661 delegate(): delegate(2354) {}
662
663 virtual int getval() { return this->n; };
664 protected:
665 int n;
666 };
667
668 class overridden : public delegate {
669 public:
670 overridden(int n): delegate(n) {}
671 virtual int getval() override final { return this->n * 2; }
672 };
673
674 class nocopy {
675 public:
676 nocopy(int i): i(i) {}
677 nocopy() = default;
678 nocopy(const nocopy&) = delete;
679 nocopy & operator=(const nocopy&) = delete;
680 private:
681 int i;
682 };
683}
684]])# _AC_CXX_CXX11_TEST_HEADER
685
686# _AC_CXX_CXX11_TEST_BODY
687# -----------------------
688# A C++ body suitable for testing for CXX11, assuming the corresponding header.
689AC_DEFUN([_AC_CXX_CXX11_TEST_BODY],
690[[
691{
692 // Test auto and decltype
693 std::deque<int> d;
694 d.push_front(43);
695 d.push_front(484);
696 d.push_front(3);
697 d.push_front(844);
698 int total = 0;
699 for (auto i = d.begin(); i != d.end(); ++i) { total += *i; }
700
701 auto a1 = 6538;
702 auto a2 = 48573953.4;
703 auto a3 = "String literal";
704
705 decltype(a2) a4 = 34895.034;
706}
707{
708 // Test constexpr
709 short sa[cxx11test::get_val()] = { 0 };
710}
711{
712 // Test initializer lists
713 cxx11test::testinit il = { 4323, 435234.23544 };
714}
715{
716 // Test range-based for and lambda
717 cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
718 for (int &x : array) { x += 23; }
719 std::for_each(array.begin(), array.end(), [](int v1){ std::cout << v1; });
720}
721{
722 using cxx11test::sptr;
723 using cxx11test::wptr;
724
725 sptr sp(new std::string("ASCII string"));
726 wptr wp(sp);
727 sptr sp2(wp);
728}
729{
730 cxx11test::tp tuple("test", 54, 45.53434);
731 double d = std::get<2>(tuple);
732 std::string s;
733 int i;
734 std::tie(s,i,d) = tuple;
735}
736{
737 static std::regex filename_regex("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
738 std::string testmatch("Test if this string matches");
739 bool match = std::regex_search(testmatch, filename_regex);
740}
741{
742 cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
743 cxx11test::int_array::size_type size = array.size();
744}
745{
746 // Test constructor delegation
747 cxx11test::delegate d1;
748 cxx11test::delegate d2();
749 cxx11test::delegate d3(45);
750}
751{
752 // Test override and final
753 cxx11test::overridden o1(55464);
754}
755{
756 // Test nullptr
757 char *c = nullptr;
758}
759{
760 // Test template brackets
761 std::vector<std::pair<int,char*>> v1;
762}
763{
764 // Unicode literals
765 char const *utf8 = u8"UTF-8 string \u2500";
766 char16_t const *utf16 = u"UTF-8 string \u2500";
767 char32_t const *utf32 = U"UTF-32 string \u2500";
768}
769]])
770
771# _AC_PROG_CXX_CXX98 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
772# -------------------------------------------------------------------
773
774# If the C++ compiler is not in ISO C++98 mode by default, try to add
775# an option to output variable CXX to make it so. This macro tries
776# various options that select ISO C++98 on some system or another. It
777# considers the compiler to be in ISO C++98 mode if it handles basic
778# features of the std namespace including: string, containers (list,
779# map, set, vector), streams (fstreams, iostreams, stringstreams,
780# iomanip), pair, exceptions and algorithms.
781
782
783AC_DEFUN([_AC_PROG_CXX_CXX98],
784[_AC_CXX_STD_TRY([cxx98],
785[_AC_CXX_CXX98_TEST_HEADER],
786[_AC_CXX_CXX98_TEST_BODY],
787dnl Try
788dnl GCC -std=gnu++98 (unused restrictive mode: -std=c++98)
789dnl IBM XL C -qlanglvl=extended
790dnl HP aC++ -AA
791dnl Intel ICC -std=gnu++98
792dnl Solaris N/A (default)
793dnl Tru64 N/A (default, but -std gnu could be used)
794dnl with extended modes being tried first.
795[[-std=gnu++98 -std=c++98 -qlanglvl=extended -AA]], [$1], [$2])[]dnl
796])# _AC_PROG_CXX_CXX98
797
798# _AC_PROG_CXX_CXX11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
799# -------------------------------------------------------------------
800# If the C++ compiler is not in ISO CXX11 mode by default, try to add
801# an option to output variable CXX to make it so. This macro tries
802# various options that select ISO C++11 on some system or another. It
803# considers the compiler to be in ISO C++11 mode if it handles all the
804# tests from the C++98 checks, plus the following: Language features
805# (auto, constexpr, decltype, default/deleted constructors, delegate
806# constructors, final, initializer lists, lambda functions, nullptr,
807# override, range-based for loops, template brackets without spaces,
808# unicode literals) and library features (array, memory (shared_ptr,
809# weak_ptr), regex and tuple types).
810AC_DEFUN([_AC_PROG_CXX_CXX11],
811[_AC_CXX_STD_TRY([cxx11],
812[_AC_CXX_CXX11_TEST_HEADER
813_AC_CXX_CXX98_TEST_HEADER],
814[_AC_CXX_CXX11_TEST_BODY
815_AC_CXX_CXX98_TEST_BODY],
816dnl Try
817dnl GCC -std=gnu++11 (unused restrictive mode: -std=c++11) [and 0x variants]
818dnl IBM XL C -qlanglvl=extended0x
819dnl (pre-V12.1; unused restrictive mode: -qlanglvl=stdcxx11)
820dnl HP aC++ -AA
821dnl Intel ICC -std=c++11 -std=c++0x
822dnl Solaris N/A (no support)
823dnl Tru64 N/A (no support)
824dnl with extended modes being tried first.
825[[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
826])# _AC_PROG_CXX_CXX11
827
828
829])# m4_version_prereq
diff --git a/gl/m4/stdalign.m4 b/gl/m4/stdalign.m4
index 20be01a..dc29717 100644
--- a/gl/m4/stdalign.m4
+++ b/gl/m4/stdalign.m4
@@ -1,6 +1,6 @@
1# Check for stdalign.h that conforms to C11. 1# Check for alignas and alignof that conform to C23.
2 2
3dnl Copyright 2011-2013 Free Software Foundation, Inc. 3dnl Copyright 2011-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -9,16 +9,23 @@ dnl with or without modifications, as long as this notice is preserved.
9 9
10AC_DEFUN([gl_STDALIGN_H], 10AC_DEFUN([gl_STDALIGN_H],
11[ 11[
12 AC_CACHE_CHECK([for working stdalign.h], 12 AC_CACHE_CHECK([for alignas and alignof],
13 [gl_cv_header_working_stdalign_h], 13 [gl_cv_header_working_stdalign_h],
14 [AC_COMPILE_IFELSE( 14 [gl_save_CFLAGS=$CFLAGS
15 for gl_working in "yes, keywords" "yes, <stdalign.h> macros"; do
16 AS_CASE([$gl_working],
17 [*stdalign.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_STDALIGN_H"])
18 AC_COMPILE_IFELSE(
15 [AC_LANG_PROGRAM( 19 [AC_LANG_PROGRAM(
16 [[#include <stdalign.h> 20 [[#include <stdint.h>
21 #ifdef INCLUDE_STDALIGN_H
22 #include <stdalign.h>
23 #endif
17 #include <stddef.h> 24 #include <stddef.h>
18 25
19 /* Test that alignof yields a result consistent with offsetof. 26 /* Test that alignof yields a result consistent with offsetof.
20 This catches GCC bug 52023 27 This catches GCC bug 52023
21 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */ 28 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */
22 #ifdef __cplusplus 29 #ifdef __cplusplus
23 template <class t> struct alignof_helper { char a; t b; }; 30 template <class t> struct alignof_helper { char a; t b; };
24 # define ao(type) offsetof (alignof_helper<type>, b) 31 # define ao(type) offsetof (alignof_helper<type>, b)
@@ -29,25 +36,103 @@ AC_DEFUN([gl_STDALIGN_H],
29 char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1]; 36 char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
30 char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1]; 37 char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
31 38
32 /* Test _Alignas only on platforms where gnulib can help. */ 39 /* Test alignas only on platforms where gnulib can help. */
33 #if \ 40 #if \
34 ((defined __cplusplus && 201103 <= __cplusplus) \ 41 ((defined __cplusplus && 201103 <= __cplusplus) \
35 || __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC \ 42 || (__TINYC__ && defined __attribute__) \
36 || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) 43 || (defined __APPLE__ && defined __MACH__ \
44 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
45 : __GNUC__) \
46 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
47 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__ \
48 || 1300 <= _MSC_VER)
37 struct alignas_test { char c; char alignas (8) alignas_8; }; 49 struct alignas_test { char c; char alignas (8) alignas_8; };
38 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8 50 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8
39 ? 1 : -1]; 51 ? 1 : -1];
40 #endif 52 #endif
41 ]])], 53 ]])],
42 [gl_cv_header_working_stdalign_h=yes], 54 [gl_cv_header_working_stdalign_h=$gl_working],
43 [gl_cv_header_working_stdalign_h=no])]) 55 [gl_cv_header_working_stdalign_h=no])
56
57 CFLAGS=$gl_save_CFLAGS
58 test "$gl_cv_header_working_stdalign_h" != no && break
59 done])
60
61 GL_GENERATE_STDALIGN_H=false
62 AS_CASE([$gl_cv_header_working_stdalign_h],
63 [no],
64 [GL_GENERATE_STDALIGN_H=true],
65 [yes*keyword*],
66 [AC_DEFINE([HAVE_C_ALIGNASOF], [1],
67 [Define to 1 if the alignas and alignof keywords work.])])
44 68
45 if test $gl_cv_header_working_stdalign_h = yes; then 69 AC_CHECK_HEADERS_ONCE([stdalign.h])
46 STDALIGN_H=''
47 else
48 STDALIGN_H='stdalign.h'
49 fi
50 70
51 AC_SUBST([STDALIGN_H]) 71 dnl The "zz" puts this toward config.h's end, to avoid potential
52 AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"]) 72 dnl collisions with other definitions.
73 AH_VERBATIM([zzalignas],
74[#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof
75# if HAVE_STDALIGN_H
76# include <stdalign.h>
77# else
78 /* Substitute. Keep consistent with gnulib/lib/stdalign.in.h. */
79# ifndef _GL_STDALIGN_H
80# define _GL_STDALIGN_H
81# undef _Alignas
82# undef _Alignof
83# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
84 || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
85 && !defined __clang__) \
86 || (defined __clang__ && __clang_major__ < 8))
87# ifdef __cplusplus
88# if (201103 <= __cplusplus || defined _MSC_VER)
89# define _Alignof(type) alignof (type)
90# else
91 template <class __t> struct __alignof_helper { char __a; __t __b; };
92# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
93# define _GL_STDALIGN_NEEDS_STDDEF 1
94# endif
95# else
96# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
97# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
98# else
99# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
100# define _GL_STDALIGN_NEEDS_STDDEF 1
101# endif
102# endif
103# endif
104# if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
105# define alignof _Alignof
106# endif
107# define __alignof_is_defined 1
108# if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
109# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
110# define _Alignas(a) alignas (a)
111# elif (!defined __attribute__ \
112 && ((defined __APPLE__ && defined __MACH__ \
113 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
114 : __GNUC__ && !defined __ibmxl__) \
115 || (4 <= __clang_major__) \
116 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
117 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
118# define _Alignas(a) __attribute__ ((__aligned__ (a)))
119# elif 1300 <= _MSC_VER
120# define _Alignas(a) __declspec (align (a))
121# endif
122# endif
123# if ((defined _Alignas \
124 && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \
125 || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
126# define alignas _Alignas
127# endif
128# if (defined alignas \
129 || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)))
130# define __alignas_is_defined 1
131# endif
132# if _GL_STDALIGN_NEEDS_STDDEF
133# include <stddef.h>
134# endif
135# endif /* _GL_STDALIGN_H */
136# endif
137#endif])
53]) 138])
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4
deleted file mode 100644
index 80d5559..0000000
--- a/gl/m4/stdbool.m4
+++ /dev/null
@@ -1,100 +0,0 @@
1# Check for stdbool.h that conforms to C99.
2
3dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8#serial 5
9
10# Prepare for substituting <stdbool.h> if it is not supported.
11
12AC_DEFUN([AM_STDBOOL_H],
13[
14 AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
15
16 # Define two additional variables used in the Makefile substitution.
17
18 if test "$ac_cv_header_stdbool_h" = yes; then
19 STDBOOL_H=''
20 else
21 STDBOOL_H='stdbool.h'
22 fi
23 AC_SUBST([STDBOOL_H])
24 AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
25
26 if test "$ac_cv_type__Bool" = yes; then
27 HAVE__BOOL=1
28 else
29 HAVE__BOOL=0
30 fi
31 AC_SUBST([HAVE__BOOL])
32])
33
34# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
35AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
36
37# This version of the macro is needed in autoconf <= 2.68.
38
39AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
40 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
41 [ac_cv_header_stdbool_h],
42 [AC_COMPILE_IFELSE(
43 [AC_LANG_PROGRAM(
44 [[
45 #include <stdbool.h>
46 #ifndef bool
47 "error: bool is not defined"
48 #endif
49 #ifndef false
50 "error: false is not defined"
51 #endif
52 #if false
53 "error: false is not 0"
54 #endif
55 #ifndef true
56 "error: true is not defined"
57 #endif
58 #if true != 1
59 "error: true is not 1"
60 #endif
61 #ifndef __bool_true_false_are_defined
62 "error: __bool_true_false_are_defined is not defined"
63 #endif
64
65 struct s { _Bool s: 1; _Bool t; } s;
66
67 char a[true == 1 ? 1 : -1];
68 char b[false == 0 ? 1 : -1];
69 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
70 char d[(bool) 0.5 == true ? 1 : -1];
71 /* See body of main program for 'e'. */
72 char f[(_Bool) 0.0 == false ? 1 : -1];
73 char g[true];
74 char h[sizeof (_Bool)];
75 char i[sizeof s.t];
76 enum { j = false, k = true, l = false * true, m = true * 256 };
77 /* The following fails for
78 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
79 _Bool n[m];
80 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
81 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
82 /* Catch a bug in an HP-UX C compiler. See
83 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
84 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
85 */
86 _Bool q = true;
87 _Bool *pq = &q;
88 ]],
89 [[
90 bool e = &s;
91 *pq |= q;
92 *pq |= ! q;
93 /* Refer to every declared value, to avoid compiler optimizations. */
94 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
95 + !m + !n + !o + !p + !q + !pq);
96 ]])],
97 [ac_cv_header_stdbool_h=yes],
98 [ac_cv_header_stdbool_h=no])])
99 AC_CHECK_TYPES([_Bool])
100])
diff --git a/gl/m4/stddef_h.m4 b/gl/m4/stddef_h.m4
index 5da8ab1..a2322eb 100644
--- a/gl/m4/stddef_h.m4
+++ b/gl/m4/stddef_h.m4
@@ -1,19 +1,61 @@
1dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues. 1# stddef_h.m4 serial 13
2# stddef_h.m4 serial 4 2dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
3dnl Copyright (C) 2009-2013 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
7 6
8AC_DEFUN([gl_STDDEF_H], 7dnl A placeholder for <stddef.h>, for platforms that have issues.
8
9AC_DEFUN_ONCE([gl_STDDEF_H],
9[ 10[
10 AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 11 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
11 AC_REQUIRE([gt_TYPE_WCHAR_T]) 12 AC_REQUIRE([gt_TYPE_WCHAR_T])
12 STDDEF_H= 13
14 dnl Persuade OpenBSD <stddef.h> to declare max_align_t.
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17 GL_GENERATE_STDDEF_H=false
18
19 dnl Test whether the type max_align_t exists and whether its alignment
20 dnl "is as great as is supported by the implementation in all contexts".
21 AC_CACHE_CHECK([for good max_align_t],
22 [gl_cv_type_max_align_t],
23 [AC_COMPILE_IFELSE(
24 [AC_LANG_PROGRAM(
25 [[/* On FreeBSD 12.0/x86, max_align_t defined by <stddef.h> has
26 the correct alignment with the default (wrong) definition of
27 _Alignof, but a wrong alignment as soon as we activate an
28 ISO C compliant _Alignof definition. */
29 #if ((defined __GNUC__ && 4 <= __GNUC__) || defined __clang__) && !defined __cplusplus
30 #define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
31 #endif
32 #include <stddef.h>
33 unsigned int s = sizeof (max_align_t);
34 #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
35 int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
36 int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
37 #endif
38 typedef struct { char a; max_align_t b; } max_helper;
39 typedef struct { char a; long b; } long_helper;
40 typedef struct { char a; double b; } double_helper;
41 typedef struct { char a; long double b; } long_double_helper;
42 int check3[2 * (offsetof (long_helper, b) <= offsetof (max_helper, b)) - 1];
43 int check4[2 * (offsetof (double_helper, b) <= offsetof (max_helper, b)) - 1];
44 int check5[2 * (offsetof (long_double_helper, b) <= offsetof (max_helper, b)) - 1];
45 ]])],
46 [gl_cv_type_max_align_t=yes],
47 [gl_cv_type_max_align_t=no])
48 ])
49 if test $gl_cv_type_max_align_t = no; then
50 HAVE_MAX_ALIGN_T=0
51 GL_GENERATE_STDDEF_H=true
52 fi
53
13 if test $gt_cv_c_wchar_t = no; then 54 if test $gt_cv_c_wchar_t = no; then
14 HAVE_WCHAR_T=0 55 HAVE_WCHAR_T=0
15 STDDEF_H=stddef.h 56 GL_GENERATE_STDDEF_H=true
16 fi 57 fi
58
17 AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], 59 AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
18 [gl_cv_decl_null_works], 60 [gl_cv_decl_null_works],
19 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h> 61 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
@@ -23,25 +65,40 @@ AC_DEFUN([gl_STDDEF_H],
23 [gl_cv_decl_null_works=no])]) 65 [gl_cv_decl_null_works=no])])
24 if test $gl_cv_decl_null_works = no; then 66 if test $gl_cv_decl_null_works = no; then
25 REPLACE_NULL=1 67 REPLACE_NULL=1
26 STDDEF_H=stddef.h 68 GL_GENERATE_STDDEF_H=true
27 fi 69 fi
28 AC_SUBST([STDDEF_H]) 70
29 AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) 71 if $GL_GENERATE_STDDEF_H; then
30 if test -n "$STDDEF_H"; then
31 gl_NEXT_HEADERS([stddef.h]) 72 gl_NEXT_HEADERS([stddef.h])
32 fi 73 fi
33]) 74])
34 75
76# gl_STDDEF_MODULE_INDICATOR([modulename])
77# sets the shell variable that indicates the presence of the given module
78# to a C preprocessor expression that will evaluate to 1.
79# This macro invocation must not occur in macros that are AC_REQUIREd.
35AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], 80AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
36[ 81[
37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 82 dnl Ensure to expand the default settings once only.
38 AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 83 gl_STDDEF_H_REQUIRE_DEFAULTS
39 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 84 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
40]) 85])
41 86
87# Initializes the default values for AC_SUBSTed shell variables.
88# This macro must not be AC_REQUIREd. It must only be invoked, and only
89# outside of macros or in macros that are not AC_REQUIREd.
90AC_DEFUN([gl_STDDEF_H_REQUIRE_DEFAULTS],
91[
92 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS], [
93 ])
94 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS])
95 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
96])
97
42AC_DEFUN([gl_STDDEF_H_DEFAULTS], 98AC_DEFUN([gl_STDDEF_H_DEFAULTS],
43[ 99[
44 dnl Assume proper GNU behavior unless another module says otherwise. 100 dnl Assume proper GNU behavior unless another module says otherwise.
45 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) 101 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
102 HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T])
46 HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) 103 HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T])
47]) 104])
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4
index 27cdcdb..d6961b0 100644
--- a/gl/m4/stdint.m4
+++ b/gl/m4/stdint.m4
@@ -1,5 +1,5 @@
1# stdint.m4 serial 43 1# stdint.m4 serial 61
2dnl Copyright (C) 2001-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2023 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,25 +7,22 @@ dnl with or without modifications, as long as this notice is preserved.
7dnl From Paul Eggert and Bruno Haible. 7dnl From Paul Eggert and Bruno Haible.
8dnl Test whether <stdint.h> is supported or must be substituted. 8dnl Test whether <stdint.h> is supported or must be substituted.
9 9
10AC_PREREQ([2.61])
11
10AC_DEFUN_ONCE([gl_STDINT_H], 12AC_DEFUN_ONCE([gl_STDINT_H],
11[ 13[
12 AC_PREREQ([2.59])dnl 14 AC_PREREQ([2.59])dnl
15 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 16
14 dnl Check for long long int and unsigned long long int. 17 AC_REQUIRE([gl_LIMITS_H])
15 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 18 AC_REQUIRE([gt_TYPE_WINT_T])
16 if test $ac_cv_type_long_long_int = yes; then 19
17 HAVE_LONG_LONG_INT=1 20 dnl For backward compatibility. Some packages may still be testing these
18 else 21 dnl macros.
19 HAVE_LONG_LONG_INT=0 22 AC_DEFINE([HAVE_LONG_LONG_INT], [1],
20 fi 23 [Define to 1 if the system has the type 'long long int'.])
21 AC_SUBST([HAVE_LONG_LONG_INT]) 24 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
22 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) 25 [Define to 1 if the system has the type 'unsigned long long int'.])
23 if test $ac_cv_type_unsigned_long_long_int = yes; then
24 HAVE_UNSIGNED_LONG_LONG_INT=1
25 else
26 HAVE_UNSIGNED_LONG_LONG_INT=0
27 fi
28 AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT])
29 26
30 dnl Check for <wchar.h>, in the same way as gl_WCHAR_H does. 27 dnl Check for <wchar.h>, in the same way as gl_WCHAR_H does.
31 AC_CHECK_HEADERS_ONCE([wchar.h]) 28 AC_CHECK_HEADERS_ONCE([wchar.h])
@@ -37,7 +34,7 @@ AC_DEFUN_ONCE([gl_STDINT_H],
37 AC_SUBST([HAVE_WCHAR_H]) 34 AC_SUBST([HAVE_WCHAR_H])
38 35
39 dnl Check for <inttypes.h>. 36 dnl Check for <inttypes.h>.
40 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. 37 AC_CHECK_HEADERS_ONCE([inttypes.h])
41 if test $ac_cv_header_inttypes_h = yes; then 38 if test $ac_cv_header_inttypes_h = yes; then
42 HAVE_INTTYPES_H=1 39 HAVE_INTTYPES_H=1
43 else 40 else
@@ -46,7 +43,7 @@ AC_DEFUN_ONCE([gl_STDINT_H],
46 AC_SUBST([HAVE_INTTYPES_H]) 43 AC_SUBST([HAVE_INTTYPES_H])
47 44
48 dnl Check for <sys/types.h>. 45 dnl Check for <sys/types.h>.
49 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. 46 AC_CHECK_HEADERS_ONCE([sys/types.h])
50 if test $ac_cv_header_sys_types_h = yes; then 47 if test $ac_cv_header_sys_types_h = yes; then
51 HAVE_SYS_TYPES_H=1 48 HAVE_SYS_TYPES_H=1
52 else 49 else
@@ -70,6 +67,8 @@ AC_DEFUN_ONCE([gl_STDINT_H],
70 AC_COMPILE_IFELSE([ 67 AC_COMPILE_IFELSE([
71 AC_LANG_PROGRAM([[ 68 AC_LANG_PROGRAM([[
72#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ 69#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
70#define __STDC_CONSTANT_MACROS 1
71#define __STDC_LIMIT_MACROS 1
73#include <stdint.h> 72#include <stdint.h>
74/* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */ 73/* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */
75#if !(defined WCHAR_MIN && defined WCHAR_MAX) 74#if !(defined WCHAR_MIN && defined WCHAR_MAX)
@@ -150,6 +149,15 @@ uintptr_t h = UINTPTR_MAX;
150intmax_t i = INTMAX_MAX; 149intmax_t i = INTMAX_MAX;
151uintmax_t j = UINTMAX_MAX; 150uintmax_t j = UINTMAX_MAX;
152 151
152/* Check that SIZE_MAX has the correct type, if possible. */
153#if 201112 <= __STDC_VERSION__
154int k = _Generic (SIZE_MAX, size_t: 0);
155#elif (2 <= __GNUC__ || 4 <= __clang_major__ || defined __IBM__TYPEOF__ \
156 || (0x5110 <= __SUNPRO_C && !__STDC__))
157extern size_t k;
158extern __typeof__ (SIZE_MAX) k;
159#endif
160
153#include <limits.h> /* for CHAR_BIT */ 161#include <limits.h> /* for CHAR_BIT */
154#define TYPE_MINIMUM(t) \ 162#define TYPE_MINIMUM(t) \
155 ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t))) 163 ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t)))
@@ -162,7 +170,7 @@ struct s {
162 PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t) 170 PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t)
163 && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t) 171 && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t)
164 ? 1 : -1; 172 ? 1 : -1;
165 /* Detect bug in FreeBSD 6.0 / ia64. */ 173 /* Detect bug in FreeBSD 6.0/ia64 and FreeBSD 13.0/arm64. */
166 int check_SIG_ATOMIC: 174 int check_SIG_ATOMIC:
167 SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t) 175 SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t)
168 && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t) 176 && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t)
@@ -218,6 +226,8 @@ struct s {
218 AC_RUN_IFELSE([ 226 AC_RUN_IFELSE([
219 AC_LANG_PROGRAM([[ 227 AC_LANG_PROGRAM([[
220#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ 228#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
229#define __STDC_CONSTANT_MACROS 1
230#define __STDC_LIMIT_MACROS 1
221#include <stdint.h> 231#include <stdint.h>
222] 232]
223gl_STDINT_INCLUDES 233gl_STDINT_INCLUDES
@@ -272,36 +282,88 @@ static const char *macro_values[] =
272]])], 282]])],
273 [gl_cv_header_working_stdint_h=yes], 283 [gl_cv_header_working_stdint_h=yes],
274 [], 284 [],
275 [dnl When cross-compiling, assume it works. 285 [case "$host_os" in
276 gl_cv_header_working_stdint_h=yes 286 # Guess yes on native Windows.
287 mingw*) gl_cv_header_working_stdint_h="guessing yes" ;;
288 # In general, assume it works.
289 *) gl_cv_header_working_stdint_h="guessing yes" ;;
290 esac
277 ]) 291 ])
278 ]) 292 ])
279 ]) 293 ])
280 fi 294 fi
281 if test "$gl_cv_header_working_stdint_h" = yes; then
282 STDINT_H=
283 else
284 dnl Check for <sys/inttypes.h>, and for
285 dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
286 AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h])
287 if test $ac_cv_header_sys_inttypes_h = yes; then
288 HAVE_SYS_INTTYPES_H=1
289 else
290 HAVE_SYS_INTTYPES_H=0
291 fi
292 AC_SUBST([HAVE_SYS_INTTYPES_H])
293 if test $ac_cv_header_sys_bitypes_h = yes; then
294 HAVE_SYS_BITYPES_H=1
295 else
296 HAVE_SYS_BITYPES_H=0
297 fi
298 AC_SUBST([HAVE_SYS_BITYPES_H])
299 295
300 gl_STDINT_TYPE_PROPERTIES 296 HAVE_C99_STDINT_H=0
301 STDINT_H=stdint.h 297 HAVE_SYS_BITYPES_H=0
302 fi 298 HAVE_SYS_INTTYPES_H=0
303 AC_SUBST([STDINT_H]) 299 GL_GENERATE_STDINT_H=true
304 AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"]) 300 case "$gl_cv_header_working_stdint_h" in
301 *yes)
302 HAVE_C99_STDINT_H=1
303 dnl Now see whether the system <stdint.h> works without
304 dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
305 dnl If not, there would be problems when stdint.h is included from C++.
306 AC_CACHE_CHECK([whether stdint.h works without ISO C predefines],
307 [gl_cv_header_stdint_without_STDC_macros],
308 [gl_cv_header_stdint_without_STDC_macros=no
309 AC_COMPILE_IFELSE([
310 AC_LANG_PROGRAM([[
311#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
312#include <stdint.h>
313]
314gl_STDINT_INCLUDES
315[
316intmax_t im = INTMAX_MAX;
317int32_t i32 = INT32_C (0x7fffffff);
318 ]])],
319 [gl_cv_header_stdint_without_STDC_macros=yes])
320 ])
321
322 if test $gl_cv_header_stdint_without_STDC_macros = no; then
323 AC_DEFINE([__STDC_CONSTANT_MACROS], [1],
324 [Define to 1 if the system <stdint.h> predates C++11.])
325 AC_DEFINE([__STDC_LIMIT_MACROS], [1],
326 [Define to 1 if the system <stdint.h> predates C++11.])
327 fi
328 AC_CACHE_CHECK([whether stdint.h has UINTMAX_WIDTH etc.],
329 [gl_cv_header_stdint_width],
330 [gl_cv_header_stdint_width=no
331 AC_COMPILE_IFELSE(
332 [AC_LANG_PROGRAM([[
333 /* Work if build is not clean. */
334 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1
335 #ifndef __STDC_WANT_IEC_60559_BFP_EXT__
336 #define __STDC_WANT_IEC_60559_BFP_EXT__ 1
337 #endif
338 #include <stdint.h>
339 ]gl_STDINT_INCLUDES[
340 int iw = UINTMAX_WIDTH;
341 ]])],
342 [gl_cv_header_stdint_width=yes])])
343 if test "$gl_cv_header_stdint_width" = yes; then
344 GL_GENERATE_STDINT_H=false
345 fi
346 ;;
347 *)
348 dnl Check for <sys/inttypes.h>, and for
349 dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
350 AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h])
351 if test $ac_cv_header_sys_inttypes_h = yes; then
352 HAVE_SYS_INTTYPES_H=1
353 fi
354 if test $ac_cv_header_sys_bitypes_h = yes; then
355 HAVE_SYS_BITYPES_H=1
356 fi
357 gl_STDINT_TYPE_PROPERTIES
358 ;;
359 esac
360
361 dnl The substitute stdint.h needs the substitute limit.h's _GL_INTEGER_WIDTH.
362 gl_REPLACE_LIMITS_H
363
364 AC_SUBST([HAVE_C99_STDINT_H])
365 AC_SUBST([HAVE_SYS_BITYPES_H])
366 AC_SUBST([HAVE_SYS_INTTYPES_H])
305]) 367])
306 368
307dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) 369dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
@@ -429,13 +491,9 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX],
429dnl gl_STDINT_INCLUDES 491dnl gl_STDINT_INCLUDES
430AC_DEFUN([gl_STDINT_INCLUDES], 492AC_DEFUN([gl_STDINT_INCLUDES],
431[[ 493[[
432 /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
433 included before <wchar.h>. */
434 #include <stddef.h> 494 #include <stddef.h>
435 #include <signal.h> 495 #include <signal.h>
436 #if HAVE_WCHAR_H 496 #if HAVE_WCHAR_H
437 # include <stdio.h>
438 # include <time.h>
439 # include <wchar.h> 497 # include <wchar.h>
440 #endif 498 #endif
441]]) 499]])
@@ -467,18 +525,7 @@ AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
467 dnl requirement that wint_t is "unchanged by default argument promotions". 525 dnl requirement that wint_t is "unchanged by default argument promotions".
468 dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t. 526 dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
469 dnl Set the variable BITSIZEOF_WINT_T accordingly. 527 dnl Set the variable BITSIZEOF_WINT_T accordingly.
470 if test $BITSIZEOF_WINT_T -lt 32; then 528 if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
471 BITSIZEOF_WINT_T=32 529 BITSIZEOF_WINT_T=32
472 fi 530 fi
473]) 531])
474
475dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
476dnl Remove this when we can assume autoconf >= 2.61.
477m4_ifdef([AC_COMPUTE_INT], [], [
478 AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
479])
480
481# Hey Emacs!
482# Local Variables:
483# indent-tabs-mode: nil
484# End:
diff --git a/gl/m4/stdint_h.m4 b/gl/m4/stdint_h.m4
index 511ab4e..70349f6 100644
--- a/gl/m4/stdint_h.m4
+++ b/gl/m4/stdint_h.m4
@@ -1,5 +1,5 @@
1# stdint_h.m4 serial 9 1# stdint_h.m4 serial 9
2dnl Copyright (C) 1997-2004, 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 1997-2004, 2006, 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
index ebade06..94271e1 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,72 +1,71 @@
1# stdio_h.m4 serial 43 1# stdio_h.m4 serial 59
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2023 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_STDIO_H], 7AC_DEFUN_ONCE([gl_STDIO_H],
8[ 8[
9 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 9 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
10 AH_VERBATIM([MINGW_ANSI_STDIO],
11[/* Use GNU style printf and scanf. */
12#ifndef __USE_MINGW_ANSI_STDIO
13# undef __USE_MINGW_ANSI_STDIO
14#endif
15])
16 AC_DEFINE([__USE_MINGW_ANSI_STDIO])
10 gl_NEXT_HEADERS([stdio.h]) 17 gl_NEXT_HEADERS([stdio.h])
11 18
12 dnl No need to create extra modules for these functions. Everyone who uses 19 dnl Determine whether __USE_MINGW_ANSI_STDIO makes printf and
13 dnl <stdio.h> likely needs them. 20 dnl inttypes.h behave like gnu instead of system; we must give our
14 GNULIB_FSCANF=1 21 dnl printf wrapper the right attribute to match.
15 gl_MODULE_INDICATOR([fscanf]) 22 AC_CACHE_CHECK([which flavor of printf attribute matches inttypes macros],
16 GNULIB_SCANF=1 23 [gl_cv_func_printf_attribute_flavor],
17 gl_MODULE_INDICATOR([scanf]) 24 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
18 GNULIB_FGETC=1 25 #define __STDC_FORMAT_MACROS 1
19 GNULIB_GETC=1 26 #include <stdio.h>
20 GNULIB_GETCHAR=1 27 #include <inttypes.h>
21 GNULIB_FGETS=1 28 /* For non-mingw systems, compilation will trivially succeed.
22 GNULIB_FREAD=1 29 For mingw, compilation will succeed for older mingw (system
23 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c" 30 printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
24 dnl "expected source file, required through AC_LIBSOURCES, not found". It is 31 #if (defined _WIN32 && ! defined __CYGWIN__) && \
25 dnl also an optimization, to avoid performing a configure check whose result 32 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
26 dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING 33 extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
27 dnl or GNULIB_NONBLOCKING redundant. 34 #endif
35 ]])], [gl_cv_func_printf_attribute_flavor=system],
36 [gl_cv_func_printf_attribute_flavor=gnu])])
37 if test "$gl_cv_func_printf_attribute_flavor" = gnu; then
38 AC_DEFINE([GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU], [1],
39 [Define to 1 if printf and friends should be labeled with
40 attribute "__gnu_printf__" instead of "__printf__"])
41 fi
42
43 dnl This ifdef is an optimization, to avoid performing a configure check whose
44 dnl result is not used. But it does not make the test of
45 dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
28 m4_ifdef([gl_NONBLOCKING_IO], [ 46 m4_ifdef([gl_NONBLOCKING_IO], [
29 gl_NONBLOCKING_IO 47 gl_NONBLOCKING_IO
30 if test $gl_cv_have_nonblocking != yes; then 48 if test $gl_cv_have_nonblocking != yes; then
31 REPLACE_STDIO_READ_FUNCS=1 49 REPLACE_STDIO_READ_FUNCS=1
32 AC_LIBOBJ([stdio-read])
33 fi 50 fi
34 ]) 51 ])
35 52
36 dnl No need to create extra modules for these functions. Everyone who uses 53 dnl This ifdef is an optimization, to avoid performing a configure check whose
37 dnl <stdio.h> likely needs them. 54 dnl result is not used. But it does not make the test of
38 GNULIB_FPRINTF=1 55 dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
39 GNULIB_PRINTF=1
40 GNULIB_VFPRINTF=1
41 GNULIB_VPRINTF=1
42 GNULIB_FPUTC=1
43 GNULIB_PUTC=1
44 GNULIB_PUTCHAR=1
45 GNULIB_FPUTS=1
46 GNULIB_PUTS=1
47 GNULIB_FWRITE=1
48 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c"
49 dnl "expected source file, required through AC_LIBSOURCES, not found". It is
50 dnl also an optimization, to avoid performing a configure check whose result
51 dnl is not used. But it does not make the test of GNULIB_STDIO_H_SIGPIPE or
52 dnl GNULIB_SIGPIPE redundant.
53 m4_ifdef([gl_SIGNAL_SIGPIPE], [ 56 m4_ifdef([gl_SIGNAL_SIGPIPE], [
54 gl_SIGNAL_SIGPIPE 57 gl_SIGNAL_SIGPIPE
55 if test $gl_cv_header_signal_h_SIGPIPE != yes; then 58 if test $gl_cv_header_signal_h_SIGPIPE != yes; then
56 REPLACE_STDIO_WRITE_FUNCS=1 59 REPLACE_STDIO_WRITE_FUNCS=1
57 AC_LIBOBJ([stdio-write])
58 fi 60 fi
59 ]) 61 ])
60 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c" 62 dnl This ifdef is an optimization, to avoid performing a configure check whose
61 dnl "expected source file, required through AC_LIBSOURCES, not found". It is 63 dnl result is not used. But it does not make the test of
62 dnl also an optimization, to avoid performing a configure check whose result 64 dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
63 dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING
64 dnl or GNULIB_NONBLOCKING redundant.
65 m4_ifdef([gl_NONBLOCKING_IO], [ 65 m4_ifdef([gl_NONBLOCKING_IO], [
66 gl_NONBLOCKING_IO 66 gl_NONBLOCKING_IO
67 if test $gl_cv_have_nonblocking != yes; then 67 if test $gl_cv_have_nonblocking != yes; then
68 REPLACE_STDIO_WRITE_FUNCS=1 68 REPLACE_STDIO_WRITE_FUNCS=1
69 AC_LIBOBJ([stdio-write])
70 fi 69 fi
71 ]) 70 ])
72 71
@@ -76,73 +75,104 @@ AC_DEFUN([gl_STDIO_H],
76 gl_WARN_ON_USE_PREPARE([[#include <stdio.h> 75 gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
77 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen 76 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
78 renameat snprintf tmpfile vdprintf vsnprintf]) 77 renameat snprintf tmpfile vdprintf vsnprintf])
78
79 AC_REQUIRE([AC_C_RESTRICT])
80
81 AC_CHECK_DECLS_ONCE([fcloseall])
82 if test $ac_cv_have_decl_fcloseall = no; then
83 HAVE_DECL_FCLOSEALL=0
84 fi
79]) 85])
80 86
87# gl_STDIO_MODULE_INDICATOR([modulename])
88# sets the shell variable that indicates the presence of the given module
89# to a C preprocessor expression that will evaluate to 1.
90# This macro invocation must not occur in macros that are AC_REQUIREd.
81AC_DEFUN([gl_STDIO_MODULE_INDICATOR], 91AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
82[ 92[
83 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 93 dnl Ensure to expand the default settings once only.
84 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 94 gl_STDIO_H_REQUIRE_DEFAULTS
85 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 95 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
86 dnl Define it also as a C macro, for the benefit of the unit tests. 96 dnl Define it also as a C macro, for the benefit of the unit tests.
87 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 97 gl_MODULE_INDICATOR_FOR_TESTS([$1])
88]) 98])
89 99
100# Initializes the default values for AC_SUBSTed shell variables.
101# This macro must not be AC_REQUIREd. It must only be invoked, and only
102# outside of macros or in macros that are not AC_REQUIREd.
103AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
104[
105 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS], [
106 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DPRINTF])
107 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCLOSE])
108 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDOPEN])
109 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFLUSH])
110 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETC])
111 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETS])
112 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN])
113 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN_GNU])
114 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF])
115 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF_POSIX])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPURGE])
117 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTC])
118 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTS])
119 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREAD])
120 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREOPEN])
121 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSCANF])
122 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEK])
123 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEKO])
124 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELL])
125 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELLO])
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FWRITE])
127 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETC])
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETCHAR])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDELIM])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLINE])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF_POSIX])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PCLOSE])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PERROR])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POPEN])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF_POSIX])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTC])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTCHAR])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTS])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMOVE])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAME])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAMEAT])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SCANF])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNPRINTF])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SPRINTF_POSIX])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_NONBLOCKING])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF_POSIX])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
160 dnl Support Microsoft deprecated alias function names by default.
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FILENO], [1])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETW], [1])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTW], [1])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TEMPNAM], [1])
167 ])
168 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS])
169 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
170])
171
90AC_DEFUN([gl_STDIO_H_DEFAULTS], 172AC_DEFUN([gl_STDIO_H_DEFAULTS],
91[ 173[
92 GNULIB_DPRINTF=0; AC_SUBST([GNULIB_DPRINTF])
93 GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE])
94 GNULIB_FDOPEN=0; AC_SUBST([GNULIB_FDOPEN])
95 GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
96 GNULIB_FGETC=0; AC_SUBST([GNULIB_FGETC])
97 GNULIB_FGETS=0; AC_SUBST([GNULIB_FGETS])
98 GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN])
99 GNULIB_FPRINTF=0; AC_SUBST([GNULIB_FPRINTF])
100 GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX])
101 GNULIB_FPURGE=0; AC_SUBST([GNULIB_FPURGE])
102 GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC])
103 GNULIB_FPUTS=0; AC_SUBST([GNULIB_FPUTS])
104 GNULIB_FREAD=0; AC_SUBST([GNULIB_FREAD])
105 GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN])
106 GNULIB_FSCANF=0; AC_SUBST([GNULIB_FSCANF])
107 GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK])
108 GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO])
109 GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL])
110 GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
111 GNULIB_FWRITE=0; AC_SUBST([GNULIB_FWRITE])
112 GNULIB_GETC=0; AC_SUBST([GNULIB_GETC])
113 GNULIB_GETCHAR=0; AC_SUBST([GNULIB_GETCHAR])
114 GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM])
115 GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE])
116 GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF])
117 GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
118 GNULIB_PCLOSE=0; AC_SUBST([GNULIB_PCLOSE])
119 GNULIB_PERROR=0; AC_SUBST([GNULIB_PERROR])
120 GNULIB_POPEN=0; AC_SUBST([GNULIB_POPEN])
121 GNULIB_PRINTF=0; AC_SUBST([GNULIB_PRINTF])
122 GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX])
123 GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC])
124 GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR])
125 GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS])
126 GNULIB_REMOVE=0; AC_SUBST([GNULIB_REMOVE])
127 GNULIB_RENAME=0; AC_SUBST([GNULIB_RENAME])
128 GNULIB_RENAMEAT=0; AC_SUBST([GNULIB_RENAMEAT])
129 GNULIB_SCANF=0; AC_SUBST([GNULIB_SCANF])
130 GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
131 GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX])
132 GNULIB_STDIO_H_NONBLOCKING=0; AC_SUBST([GNULIB_STDIO_H_NONBLOCKING])
133 GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
134 GNULIB_TMPFILE=0; AC_SUBST([GNULIB_TMPFILE])
135 GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF])
136 GNULIB_VFSCANF=0; AC_SUBST([GNULIB_VFSCANF])
137 GNULIB_VSCANF=0; AC_SUBST([GNULIB_VSCANF])
138 GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF])
139 GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF])
140 GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
141 GNULIB_VPRINTF=0; AC_SUBST([GNULIB_VPRINTF])
142 GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX])
143 GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
144 GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
145 dnl Assume proper GNU behavior unless another module says otherwise. 174 dnl Assume proper GNU behavior unless another module says otherwise.
175 HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL])
146 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE]) 176 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
147 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO]) 177 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO])
148 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO]) 178 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO])
@@ -164,6 +194,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
164 REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN]) 194 REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN])
165 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) 195 REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
166 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN]) 196 REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
197 REPLACE_FOPEN_FOR_FOPEN_GNU=0; AC_SUBST([REPLACE_FOPEN_FOR_FOPEN_GNU])
167 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) 198 REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
168 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE]) 199 REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
169 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN]) 200 REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index 2027ab3..e96be22 100644
--- a/gl/m4/stdlib_h.m4
+++ b/gl/m4/stdlib_h.m4
@@ -1,10 +1,10 @@
1# stdlib_h.m4 serial 42 1# stdlib_h.m4 serial 66
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2023 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_STDLIB_H], 7AC_DEFUN_ONCE([gl_STDLIB_H],
8[ 8[
9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10 gl_NEXT_HEADERS([stdlib.h]) 10 gl_NEXT_HEADERS([stdlib.h])
@@ -14,104 +14,187 @@ AC_DEFUN([gl_STDLIB_H],
14 dnl guaranteed by C89. 14 dnl guaranteed by C89.
15 gl_WARN_ON_USE_PREPARE([[#include <stdlib.h> 15 gl_WARN_ON_USE_PREPARE([[#include <stdlib.h>
16#if HAVE_SYS_LOADAVG_H 16#if HAVE_SYS_LOADAVG_H
17/* OpenIndiana has a bug: <sys/time.h> must be included before
18 <sys/loadavg.h>. */
19# include <sys/time.h>
17# include <sys/loadavg.h> 20# include <sys/loadavg.h>
18#endif 21#endif
19#if HAVE_RANDOM_H 22#if HAVE_RANDOM_H
20# include <random.h> 23# include <random.h>
21#endif 24#endif
22 ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt 25 ]], [_Exit aligned_alloc atoll canonicalize_file_name free
23 initstate initstate_r mkdtemp mkostemp mkostemps mkstemp mkstemps 26 getloadavg getsubopt grantpt
24 posix_openpt ptsname ptsname_r random random_r realpath rpmatch 27 initstate initstate_r mbtowc mkdtemp mkostemp mkostemps mkstemp mkstemps
25 secure_getenv setenv setstate setstate_r srandom srandom_r 28 posix_memalign posix_openpt ptsname ptsname_r qsort_r
26 strtod strtoll strtoull unlockpt unsetenv]) 29 random random_r reallocarray realpath rpmatch secure_getenv setenv
30 setstate setstate_r srandom srandom_r
31 strtod strtol strtold strtoll strtoul strtoull unlockpt unsetenv])
32
33 AC_REQUIRE([AC_C_RESTRICT])
34
35 AC_CHECK_DECLS_ONCE([ecvt])
36 if test $ac_cv_have_decl_ecvt = no; then
37 HAVE_DECL_ECVT=0
38 fi
39 AC_CHECK_DECLS_ONCE([fcvt])
40 if test $ac_cv_have_decl_fcvt = no; then
41 HAVE_DECL_FCVT=0
42 fi
43 AC_CHECK_DECLS_ONCE([gcvt])
44 if test $ac_cv_have_decl_gcvt = no; then
45 HAVE_DECL_GCVT=0
46 fi
27]) 47])
28 48
49# gl_STDLIB_MODULE_INDICATOR([modulename])
50# sets the shell variable that indicates the presence of the given module
51# to a C preprocessor expression that will evaluate to 1.
52# This macro invocation must not occur in macros that are AC_REQUIREd.
29AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], 53AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
30[ 54[
31 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 55 dnl Ensure to expand the default settings once only.
32 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 56 gl_STDLIB_H_REQUIRE_DEFAULTS
33 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 57 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
34 dnl Define it also as a C macro, for the benefit of the unit tests. 58 dnl Define it also as a C macro, for the benefit of the unit tests.
35 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 59 gl_MODULE_INDICATOR_FOR_TESTS([$1])
36]) 60])
37 61
62# Initializes the default values for AC_SUBSTed shell variables.
63# This macro must not be AC_REQUIREd. It must only be invoked, and only
64# outside of macros or in macros that are not AC_REQUIREd.
65AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS],
66[
67 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS], [
68 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB__EXIT])
69 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ALIGNED_ALLOC])
70 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ATOLL])
71 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CALLOC_GNU])
72 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CALLOC_POSIX])
73 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CANONICALIZE_FILE_NAME])
74 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREE_POSIX])
75 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOADAVG])
76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSUBOPT])
77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GRANTPT])
78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_GNU])
79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_POSIX])
80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBTOWC])
81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDTEMP])
82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKOSTEMP])
83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKOSTEMPS])
84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKSTEMP])
85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKSTEMPS])
86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_MEMALIGN])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_OPENPT])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTSNAME])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTSNAME_R])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTENV])
91 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_QSORT_R])
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM])
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM_R])
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOCARRAY])
95 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOC_GNU])
96 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOC_POSIX])
97 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALPATH])
98 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RPMATCH])
99 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SECURE_GETENV])
100 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETENV])
101 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOD])
102 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOL])
103 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOLD])
104 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOLL])
105 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOUL])
106 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOULL])
107 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SYSTEM_POSIX])
108 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNLOCKPT])
109 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNSETENV])
110 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOMB])
111 dnl Support Microsoft deprecated alias function names by default.
112 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_ECVT], [1])
113 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCVT], [1])
114 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GCVT], [1])
115 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_MKTEMP], [1])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTENV], [1])
117 ])
118 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS])
119 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
120])
121
38AC_DEFUN([gl_STDLIB_H_DEFAULTS], 122AC_DEFUN([gl_STDLIB_H_DEFAULTS],
39[ 123[
40 GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT])
41 GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL])
42 GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
43 GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
44 GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG])
45 GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT])
46 GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT])
47 GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX])
48 GNULIB_MBTOWC=0; AC_SUBST([GNULIB_MBTOWC])
49 GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
50 GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP])
51 GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS])
52 GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
53 GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS])
54 GNULIB_POSIX_OPENPT=0; AC_SUBST([GNULIB_POSIX_OPENPT])
55 GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME])
56 GNULIB_PTSNAME_R=0; AC_SUBST([GNULIB_PTSNAME_R])
57 GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
58 GNULIB_RANDOM=0; AC_SUBST([GNULIB_RANDOM])
59 GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R])
60 GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
61 GNULIB_REALPATH=0; AC_SUBST([GNULIB_REALPATH])
62 GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH])
63 GNULIB_SECURE_GETENV=0; AC_SUBST([GNULIB_SECURE_GETENV])
64 GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
65 GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD])
66 GNULIB_STRTOLL=0; AC_SUBST([GNULIB_STRTOLL])
67 GNULIB_STRTOULL=0; AC_SUBST([GNULIB_STRTOULL])
68 GNULIB_SYSTEM_POSIX=0; AC_SUBST([GNULIB_SYSTEM_POSIX])
69 GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
70 GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
71 GNULIB_WCTOMB=0; AC_SUBST([GNULIB_WCTOMB])
72 dnl Assume proper GNU behavior unless another module says otherwise. 124 dnl Assume proper GNU behavior unless another module says otherwise.
73 HAVE__EXIT=1; AC_SUBST([HAVE__EXIT]) 125 HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
126 HAVE_ALIGNED_ALLOC=1; AC_SUBST([HAVE_ALIGNED_ALLOC])
74 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) 127 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
75 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) 128 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
129 HAVE_DECL_ECVT=1; AC_SUBST([HAVE_DECL_ECVT])
130 HAVE_DECL_FCVT=1; AC_SUBST([HAVE_DECL_FCVT])
131 HAVE_DECL_GCVT=1; AC_SUBST([HAVE_DECL_GCVT])
76 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) 132 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
77 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) 133 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
78 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT]) 134 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT])
135 HAVE_INITSTATE=1; AC_SUBST([HAVE_INITSTATE])
136 HAVE_DECL_INITSTATE=1; AC_SUBST([HAVE_DECL_INITSTATE])
137 HAVE_MBTOWC=1; AC_SUBST([HAVE_MBTOWC])
79 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) 138 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
80 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP]) 139 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
81 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS]) 140 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
82 HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP]) 141 HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP])
83 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) 142 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
143 HAVE_POSIX_MEMALIGN=1; AC_SUBST([HAVE_POSIX_MEMALIGN])
84 HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT]) 144 HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT])
85 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) 145 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
86 HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R]) 146 HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R])
147 HAVE_QSORT_R=1; AC_SUBST([HAVE_QSORT_R])
87 HAVE_RANDOM=1; AC_SUBST([HAVE_RANDOM]) 148 HAVE_RANDOM=1; AC_SUBST([HAVE_RANDOM])
88 HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H]) 149 HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H])
89 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) 150 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
151 HAVE_REALLOCARRAY=1; AC_SUBST([HAVE_REALLOCARRAY])
90 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH]) 152 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
91 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH]) 153 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
92 HAVE_SECURE_GETENV=1; AC_SUBST([HAVE_SECURE_GETENV]) 154 HAVE_SECURE_GETENV=1; AC_SUBST([HAVE_SECURE_GETENV])
93 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) 155 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
94 HAVE_DECL_SETENV=1; AC_SUBST([HAVE_DECL_SETENV]) 156 HAVE_DECL_SETENV=1; AC_SUBST([HAVE_DECL_SETENV])
157 HAVE_SETSTATE=1; AC_SUBST([HAVE_SETSTATE])
158 HAVE_DECL_SETSTATE=1; AC_SUBST([HAVE_DECL_SETSTATE])
95 HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD]) 159 HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD])
160 HAVE_STRTOL=1; AC_SUBST([HAVE_STRTOL])
161 HAVE_STRTOLD=1; AC_SUBST([HAVE_STRTOLD])
96 HAVE_STRTOLL=1; AC_SUBST([HAVE_STRTOLL]) 162 HAVE_STRTOLL=1; AC_SUBST([HAVE_STRTOLL])
163 HAVE_STRTOUL=1; AC_SUBST([HAVE_STRTOUL])
97 HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL]) 164 HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL])
98 HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA]) 165 HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA])
99 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) 166 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
100 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) 167 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
101 HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV]) 168 HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV])
102 REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC]) 169 REPLACE_ALIGNED_ALLOC=0; AC_SUBST([REPLACE_ALIGNED_ALLOC])
170 REPLACE_CALLOC_FOR_CALLOC_GNU=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_GNU])
171 REPLACE_CALLOC_FOR_CALLOC_POSIX=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_POSIX])
103 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) 172 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
104 REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) 173 REPLACE_FREE=0; AC_SUBST([REPLACE_FREE])
174 REPLACE_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE])
175 REPLACE_MALLOC_FOR_MALLOC_GNU=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_GNU])
176 REPLACE_MALLOC_FOR_MALLOC_POSIX=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_POSIX])
105 REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC]) 177 REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC])
106 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) 178 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
179 REPLACE_POSIX_MEMALIGN=0; AC_SUBST([REPLACE_POSIX_MEMALIGN])
107 REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME]) 180 REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME])
108 REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R]) 181 REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R])
109 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) 182 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
183 REPLACE_QSORT_R=0; AC_SUBST([REPLACE_QSORT_R])
184 REPLACE_RANDOM=0; AC_SUBST([REPLACE_RANDOM])
110 REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R]) 185 REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R])
111 REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC]) 186 REPLACE_REALLOC_FOR_REALLOC_GNU=0; AC_SUBST([REPLACE_REALLOC_FOR_REALLOC_GNU])
187 REPLACE_REALLOC_FOR_REALLOC_POSIX=0; AC_SUBST([REPLACE_REALLOC_FOR_REALLOC_POSIX])
188 REPLACE_REALLOCARRAY=0; AC_SUBST([REPLACE_REALLOCARRAY])
112 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH]) 189 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
113 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV]) 190 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
191 REPLACE_SETSTATE=0; AC_SUBST([REPLACE_SETSTATE])
114 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD]) 192 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
193 REPLACE_STRTOL=0; AC_SUBST([REPLACE_STRTOL])
194 REPLACE_STRTOLD=0; AC_SUBST([REPLACE_STRTOLD])
195 REPLACE_STRTOLL=0; AC_SUBST([REPLACE_STRTOLL])
196 REPLACE_STRTOUL=0; AC_SUBST([REPLACE_STRTOUL])
197 REPLACE_STRTOULL=0; AC_SUBST([REPLACE_STRTOULL])
115 REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV]) 198 REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV])
116 REPLACE_WCTOMB=0; AC_SUBST([REPLACE_WCTOMB]) 199 REPLACE_WCTOMB=0; AC_SUBST([REPLACE_WCTOMB])
117]) 200])
diff --git a/gl/m4/strcase.m4 b/gl/m4/strcase.m4
index 22bf57c..3cf740d 100644
--- a/gl/m4/strcase.m4
+++ b/gl/m4/strcase.m4
@@ -1,5 +1,5 @@
1# strcase.m4 serial 11 1# strcase.m4 serial 12
2dnl Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2005-2023 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,7 +12,7 @@ AC_DEFUN([gl_STRCASE],
12 12
13AC_DEFUN([gl_FUNC_STRCASECMP], 13AC_DEFUN([gl_FUNC_STRCASECMP],
14[ 14[
15 AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) 15 AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
16 AC_CHECK_FUNCS([strcasecmp]) 16 AC_CHECK_FUNCS([strcasecmp])
17 if test $ac_cv_func_strcasecmp = no; then 17 if test $ac_cv_func_strcasecmp = no; then
18 HAVE_STRCASECMP=0 18 HAVE_STRCASECMP=0
@@ -21,7 +21,7 @@ AC_DEFUN([gl_FUNC_STRCASECMP],
21 21
22AC_DEFUN([gl_FUNC_STRNCASECMP], 22AC_DEFUN([gl_FUNC_STRNCASECMP],
23[ 23[
24 AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) 24 AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
25 AC_CHECK_FUNCS([strncasecmp]) 25 AC_CHECK_FUNCS([strncasecmp])
26 if test $ac_cv_func_strncasecmp = yes; then 26 if test $ac_cv_func_strncasecmp = yes; then
27 HAVE_STRNCASECMP=1 27 HAVE_STRNCASECMP=1
diff --git a/gl/m4/strcasestr.m4 b/gl/m4/strcasestr.m4
index 8681a6a..971e0b2 100644
--- a/gl/m4/strcasestr.m4
+++ b/gl/m4/strcasestr.m4
@@ -1,5 +1,5 @@
1# strcasestr.m4 serial 21 1# strcasestr.m4 serial 28
2dnl Copyright (C) 2005, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2007-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
7dnl Check that strcasestr is present and works. 7dnl Check that strcasestr is present and works.
8AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE], 8AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE],
9[ 9[
10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 10 AC_REQUIRE([gl_STRING_H_DEFAULTS])
11 11
12 dnl Persuade glibc <string.h> to declare strcasestr(). 12 dnl Persuade glibc <string.h> to declare strcasestr().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
@@ -17,28 +17,38 @@ AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE],
17 if test $ac_cv_func_strcasestr = no; then 17 if test $ac_cv_func_strcasestr = no; then
18 HAVE_STRCASESTR=0 18 HAVE_STRCASESTR=0
19 else 19 else
20 if test "$gl_cv_func_memchr_works" != yes; then 20 if test $REPLACE_MEMCHR = 1; then
21 REPLACE_STRCASESTR=1 21 REPLACE_STRCASESTR=1
22 else 22 else
23 dnl Detect http://sourceware.org/bugzilla/show_bug.cgi?id=12092. 23 dnl Detect https://sourceware.org/bugzilla/show_bug.cgi?id=12092
24 dnl and https://sourceware.org/bugzilla/show_bug.cgi?id=23637.
24 AC_CACHE_CHECK([whether strcasestr works], 25 AC_CACHE_CHECK([whether strcasestr works],
25 [gl_cv_func_strcasestr_works_always], 26 [gl_cv_func_strcasestr_works_always],
26 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 27 [AC_RUN_IFELSE(
27#include <string.h> /* for strcasestr */ 28 [AC_LANG_PROGRAM([[
29#include <string.h> /* for __GNU_LIBRARY__, strcasestr */
30#ifdef __GNU_LIBRARY__
31 #include <features.h>
32 #if __GLIBC__ == 2 && __GLIBC_MINOR__ == 28
33 Unlucky user
34 #endif
35#endif
28#define P "_EF_BF_BD" 36#define P "_EF_BF_BD"
29#define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P 37#define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P
30#define NEEDLE P P P P P 38#define NEEDLE P P P P P
31]], [[return !!strcasestr (HAYSTACK, NEEDLE); 39]],
32 ]])], 40 [[return !!strcasestr (HAYSTACK, NEEDLE);
33 [gl_cv_func_strcasestr_works_always=yes], 41 ]])],
34 [gl_cv_func_strcasestr_works_always=no], 42 [gl_cv_func_strcasestr_works_always=yes],
35 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not 43 [gl_cv_func_strcasestr_works_always=no],
36 dnl affected, since it uses different source code for strcasestr 44 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not
37 dnl than glibc. 45 dnl affected, since it uses different source code for strcasestr
38 dnl Assume that it works on all other platforms, even if it is not 46 dnl than glibc.
39 dnl linear. 47 dnl Assume that it works on all other platforms, even if it is not
40 AC_EGREP_CPP([Lucky user], 48 dnl linear.
41 [ 49 AC_EGREP_CPP([Lucky user],
50 [
51#include <string.h> /* for __GNU_LIBRARY__ */
42#ifdef __GNU_LIBRARY__ 52#ifdef __GNU_LIBRARY__
43 #include <features.h> 53 #include <features.h>
44 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \ 54 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
@@ -53,10 +63,10 @@ AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE],
53#else 63#else
54 Lucky user 64 Lucky user
55#endif 65#endif
56 ], 66 ],
57 [gl_cv_func_strcasestr_works_always="guessing yes"], 67 [gl_cv_func_strcasestr_works_always="guessing yes"],
58 [gl_cv_func_strcasestr_works_always="guessing no"]) 68 [gl_cv_func_strcasestr_works_always="$gl_cross_guess_normal"])
59 ]) 69 ])
60 ]) 70 ])
61 case "$gl_cv_func_strcasestr_works_always" in 71 case "$gl_cv_func_strcasestr_works_always" in
62 *yes) ;; 72 *yes) ;;
@@ -80,7 +90,7 @@ AC_DEFUN([gl_FUNC_STRCASESTR],
80#include <string.h> /* for strcasestr */ 90#include <string.h> /* for strcasestr */
81#include <stdlib.h> /* for malloc */ 91#include <stdlib.h> /* for malloc */
82#include <unistd.h> /* for alarm */ 92#include <unistd.h> /* for alarm */
83static void quit (int sig) { exit (sig + 128); } 93static void quit (int sig) { _exit (sig + 128); }
84]], [[ 94]], [[
85 int result = 0; 95 int result = 0;
86 size_t m = 1000000; 96 size_t m = 1000000;
@@ -102,6 +112,9 @@ static void quit (int sig) { exit (sig + 128); }
102 if (!strcasestr (haystack, needle)) 112 if (!strcasestr (haystack, needle))
103 result |= 1; 113 result |= 1;
104 } 114 }
115 /* Free allocated memory, in case some sanitizer is watching. */
116 free (haystack);
117 free (needle);
105 return result; 118 return result;
106 ]])], 119 ]])],
107 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no], 120 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
@@ -124,7 +137,7 @@ static void quit (int sig) { exit (sig + 128); }
124#endif 137#endif
125 ], 138 ],
126 [gl_cv_func_strcasestr_linear="guessing yes"], 139 [gl_cv_func_strcasestr_linear="guessing yes"],
127 [gl_cv_func_strcasestr_linear="guessing no"]) 140 [gl_cv_func_strcasestr_linear="$gl_cross_guess_normal"])
128 ]) 141 ])
129 ]) 142 ])
130 case "$gl_cv_func_strcasestr_linear" in 143 case "$gl_cv_func_strcasestr_linear" in
diff --git a/gl/m4/strerror.m4 b/gl/m4/strerror.m4
index 3989844..8879eb0 100644
--- a/gl/m4/strerror.m4
+++ b/gl/m4/strerror.m4
@@ -1,19 +1,19 @@
1# strerror.m4 serial 17 1# strerror.m4 serial 23
2dnl Copyright (C) 2002, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2007-2023 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_STRERROR], 7AC_DEFUN([gl_FUNC_STRERROR],
8[ 8[
9 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 9 AC_REQUIRE([gl_STRING_H_DEFAULTS])
10 AC_REQUIRE([gl_HEADER_ERRNO_H]) 10 AC_REQUIRE([gl_HEADER_ERRNO_H])
11 AC_REQUIRE([gl_FUNC_STRERROR_0]) 11 AC_REQUIRE([gl_FUNC_STRERROR_0])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [ 13 m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
14 AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS]) 14 AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
15 ]) 15 ])
16 if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then 16 if test "$GL_GENERATE_ERRNO_H:$REPLACE_STRERROR_0" = false:0; then
17 AC_CACHE_CHECK([for working strerror function], 17 AC_CACHE_CHECK([for working strerror function],
18 [gl_cv_func_working_strerror], 18 [gl_cv_func_working_strerror],
19 [AC_RUN_IFELSE( 19 [AC_RUN_IFELSE(
@@ -24,10 +24,12 @@ AC_DEFUN([gl_FUNC_STRERROR],
24 [gl_cv_func_working_strerror=yes], 24 [gl_cv_func_working_strerror=yes],
25 [gl_cv_func_working_strerror=no], 25 [gl_cv_func_working_strerror=no],
26 [case "$host_os" in 26 [case "$host_os" in
27 # Guess yes on glibc systems. 27 # Guess yes on glibc systems.
28 *-gnu*) gl_cv_func_working_strerror="guessing yes" ;; 28 *-gnu* | gnu*) gl_cv_func_working_strerror="guessing yes" ;;
29 # If we don't know, assume the worst. 29 # Guess yes on musl systems.
30 *) gl_cv_func_working_strerror="guessing no" ;; 30 *-musl*) gl_cv_func_working_strerror="guessing yes" ;;
31 # If we don't know, obey --enable-cross-guesses.
32 *) gl_cv_func_working_strerror="$gl_cross_guess_normal" ;;
31 esac 33 esac
32 ]) 34 ])
33 ]) 35 ])
@@ -78,10 +80,14 @@ AC_DEFUN([gl_FUNC_STRERROR_0],
78 [gl_cv_func_strerror_0_works=yes], 80 [gl_cv_func_strerror_0_works=yes],
79 [gl_cv_func_strerror_0_works=no], 81 [gl_cv_func_strerror_0_works=no],
80 [case "$host_os" in 82 [case "$host_os" in
81 # Guess yes on glibc systems. 83 # Guess yes on glibc systems.
82 *-gnu*) gl_cv_func_strerror_0_works="guessing yes" ;; 84 *-gnu* | gnu*) gl_cv_func_strerror_0_works="guessing yes" ;;
83 # If we don't know, assume the worst. 85 # Guess yes on musl systems.
84 *) gl_cv_func_strerror_0_works="guessing no" ;; 86 *-musl*) gl_cv_func_strerror_0_works="guessing yes" ;;
87 # Guess yes on native Windows.
88 mingw*) gl_cv_func_strerror_0_works="guessing yes" ;;
89 # If we don't know, obey --enable-cross-guesses.
90 *) gl_cv_func_strerror_0_works="$gl_cross_guess_normal" ;;
85 esac 91 esac
86 ]) 92 ])
87 ]) 93 ])
diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4
index cc5fbbb..5da3cc2 100644
--- a/gl/m4/string_h.m4
+++ b/gl/m4/string_h.m4
@@ -1,25 +1,19 @@
1# Configure a GNU-like replacement for <string.h>. 1# Configure a GNU-like replacement for <string.h>.
2 2
3# Copyright (C) 2007-2013 Free Software Foundation, Inc. 3# Copyright (C) 2007-2023 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation 4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it, 5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved. 6# with or without modifications, as long as this notice is preserved.
7 7
8# serial 21 8# serial 35
9 9
10# Written by Paul Eggert. 10# Written by Paul Eggert.
11 11
12AC_DEFUN([gl_HEADER_STRING_H], 12AC_DEFUN_ONCE([gl_STRING_H],
13[ 13[
14 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 14 dnl Ensure to expand the default settings once only, before all statements
15 dnl once only, before all statements that occur in other macros. 15 dnl that occur in other macros.
16 AC_REQUIRE([gl_HEADER_STRING_H_BODY]) 16 AC_REQUIRE([gl_STRING_H_DEFAULTS])
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_NEXT_HEADERS([string.h]) 17 gl_NEXT_HEADERS([string.h])
24 18
25 dnl Check for declarations of anything we want to poison if the 19 dnl Check for declarations of anything we want to poison if the
@@ -27,66 +21,95 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY],
27 dnl guaranteed by C89. 21 dnl guaranteed by C89.
28 gl_WARN_ON_USE_PREPARE([[#include <string.h> 22 gl_WARN_ON_USE_PREPARE([[#include <string.h>
29 ]], 23 ]],
30 [ffsl ffsll memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul 24 [explicit_bzero ffsl ffsll memmem mempcpy memrchr memset_explicit
25 rawmemchr stpcpy stpncpy strchrnul
31 strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r 26 strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r
32 strerror_r strsignal strverscmp]) 27 strerror_r strerrorname_np sigabbrev_np sigdescr_np strsignal strverscmp])
28
29 AC_REQUIRE([AC_C_RESTRICT])
33]) 30])
34 31
32# gl_STRING_MODULE_INDICATOR([modulename])
33# sets the shell variable that indicates the presence of the given module
34# to a C preprocessor expression that will evaluate to 1.
35# This macro invocation must not occur in macros that are AC_REQUIREd.
35AC_DEFUN([gl_STRING_MODULE_INDICATOR], 36AC_DEFUN([gl_STRING_MODULE_INDICATOR],
36[ 37[
37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 38 dnl Ensure to expand the default settings once only.
38 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 39 gl_STRING_H_REQUIRE_DEFAULTS
39 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 40 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
40 dnl Define it also as a C macro, for the benefit of the unit tests. 41 dnl Define it also as a C macro, for the benefit of the unit tests.
41 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 42 gl_MODULE_INDICATOR_FOR_TESTS([$1])
42]) 43])
43 44
44AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], 45# Initializes the default values for AC_SUBSTed shell variables.
46# This macro must not be AC_REQUIREd. It must only be invoked, and only
47# outside of macros or in macros that are not AC_REQUIREd.
48AC_DEFUN([gl_STRING_H_REQUIRE_DEFAULTS],
45[ 49[
46 GNULIB_FFSL=0; AC_SUBST([GNULIB_FFSL]) 50 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STRING_H_MODULE_INDICATOR_DEFAULTS], [
47 GNULIB_FFSLL=0; AC_SUBST([GNULIB_FFSLL]) 51 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPLICIT_BZERO])
48 GNULIB_MEMCHR=0; AC_SUBST([GNULIB_MEMCHR]) 52 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFSL])
49 GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) 53 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFSLL])
50 GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) 54 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMCHR])
51 GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) 55 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMMEM])
52 GNULIB_RAWMEMCHR=0; AC_SUBST([GNULIB_RAWMEMCHR]) 56 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMPCPY])
53 GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY]) 57 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMRCHR])
54 GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) 58 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMSET_EXPLICIT])
55 GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) 59 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RAWMEMCHR])
56 GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) 60 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STPCPY])
57 GNULIB_STRNCAT=0; AC_SUBST([GNULIB_STRNCAT]) 61 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STPNCPY])
58 GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) 62 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCHRNUL])
59 GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) 63 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRDUP])
60 GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) 64 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNCAT])
61 GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) 65 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNDUP])
62 GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR]) 66 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNLEN])
63 GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) 67 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPBRK])
64 GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) 68 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSEP])
65 GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN]) 69 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSTR])
66 GNULIB_MBSNLEN=0; AC_SUBST([GNULIB_MBSNLEN]) 70 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASESTR])
67 GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR]) 71 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOK_R])
68 GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR]) 72 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSLEN])
69 GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR]) 73 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNLEN])
70 GNULIB_MBSCASECMP=0; AC_SUBST([GNULIB_MBSCASECMP]) 74 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCHR])
71 GNULIB_MBSNCASECMP=0; AC_SUBST([GNULIB_MBSNCASECMP]) 75 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRCHR])
72 GNULIB_MBSPCASECMP=0; AC_SUBST([GNULIB_MBSPCASECMP]) 76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSTR])
73 GNULIB_MBSCASESTR=0; AC_SUBST([GNULIB_MBSCASESTR]) 77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCASECMP])
74 GNULIB_MBSCSPN=0; AC_SUBST([GNULIB_MBSCSPN]) 78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNCASECMP])
75 GNULIB_MBSPBRK=0; AC_SUBST([GNULIB_MBSPBRK]) 79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSPCASECMP])
76 GNULIB_MBSSPN=0; AC_SUBST([GNULIB_MBSSPN]) 80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCASESTR])
77 GNULIB_MBSSEP=0; AC_SUBST([GNULIB_MBSSEP]) 81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCSPN])
78 GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R]) 82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSPBRK])
79 GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR]) 83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSPN])
80 GNULIB_STRERROR_R=0; AC_SUBST([GNULIB_STRERROR_R]) 84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSEP])
81 GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL]) 85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSTOK_R])
82 GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP]) 86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERROR])
83 HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN]) 87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERROR_R])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERRORNAME_NP])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGABBREV_NP])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGDESCR_NP])
91 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSIGNAL])
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRVERSCMP])
93 dnl Support Microsoft deprecated alias function names by default.
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_MEMCCPY], [1])
95 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_STRDUP], [1])
96 ])
97 m4_require(GL_MODULE_INDICATOR_PREFIX[_STRING_H_MODULE_INDICATOR_DEFAULTS])
98 dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
99 gl_STDLIB_H_REQUIRE_DEFAULTS
100 AC_REQUIRE([gl_STRING_H_DEFAULTS])
101])
102
103AC_DEFUN([gl_STRING_H_DEFAULTS],
104[
105 HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN])
84 dnl Assume proper GNU behavior unless another module says otherwise. 106 dnl Assume proper GNU behavior unless another module says otherwise.
107 HAVE_EXPLICIT_BZERO=1; AC_SUBST([HAVE_EXPLICIT_BZERO])
85 HAVE_FFSL=1; AC_SUBST([HAVE_FFSL]) 108 HAVE_FFSL=1; AC_SUBST([HAVE_FFSL])
86 HAVE_FFSLL=1; AC_SUBST([HAVE_FFSLL]) 109 HAVE_FFSLL=1; AC_SUBST([HAVE_FFSLL])
87 HAVE_MEMCHR=1; AC_SUBST([HAVE_MEMCHR])
88 HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM]) 110 HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM])
89 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) 111 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY])
112 HAVE_MEMSET_EXPLICIT=1; AC_SUBST([HAVE_MEMSET_EXPLICIT])
90 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) 113 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR])
91 HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR]) 114 HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR])
92 HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY]) 115 HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY])
@@ -100,21 +123,26 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
100 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) 123 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR])
101 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) 124 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R])
102 HAVE_DECL_STRERROR_R=1; AC_SUBST([HAVE_DECL_STRERROR_R]) 125 HAVE_DECL_STRERROR_R=1; AC_SUBST([HAVE_DECL_STRERROR_R])
126 HAVE_STRERRORNAME_NP=1; AC_SUBST([HAVE_STRERRORNAME_NP])
127 HAVE_SIGABBREV_NP=1; AC_SUBST([HAVE_SIGABBREV_NP])
128 HAVE_SIGDESCR_NP=1; AC_SUBST([HAVE_SIGDESCR_NP])
103 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) 129 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL])
104 HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) 130 HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP])
131 REPLACE_FFSLL=0; AC_SUBST([REPLACE_FFSLL])
105 REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) 132 REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR])
106 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) 133 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM])
107 REPLACE_STPNCPY=0; AC_SUBST([REPLACE_STPNCPY]) 134 REPLACE_STPNCPY=0; AC_SUBST([REPLACE_STPNCPY])
135 REPLACE_STRCHRNUL=0; AC_SUBST([REPLACE_STRCHRNUL])
108 REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) 136 REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP])
137 REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT])
138 REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP])
139 REPLACE_STRNLEN=0; AC_SUBST([REPLACE_STRNLEN])
109 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) 140 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR])
110 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) 141 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR])
111 REPLACE_STRCHRNUL=0; AC_SUBST([REPLACE_STRCHRNUL]) 142 REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R])
112 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) 143 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
113 REPLACE_STRERROR_R=0; AC_SUBST([REPLACE_STRERROR_R]) 144 REPLACE_STRERROR_R=0; AC_SUBST([REPLACE_STRERROR_R])
114 REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT]) 145 REPLACE_STRERRORNAME_NP=0; AC_SUBST([REPLACE_STRERRORNAME_NP])
115 REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP])
116 REPLACE_STRNLEN=0; AC_SUBST([REPLACE_STRNLEN])
117 REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) 146 REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL])
118 REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R])
119 UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) 147 UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R])
120]) 148])
diff --git a/gl/m4/strings_h.m4 b/gl/m4/strings_h.m4
index 76ef242..4c41221 100644
--- a/gl/m4/strings_h.m4
+++ b/gl/m4/strings_h.m4
@@ -1,21 +1,16 @@
1# Configure a replacement for <strings.h>. 1# Configure a replacement for <strings.h>.
2# serial 6 2# serial 9
3 3
4# Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 4# Copyright (C) 2007, 2009-2023 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
9AC_DEFUN([gl_HEADER_STRINGS_H], 9AC_DEFUN_ONCE([gl_STRINGS_H],
10[ 10[
11 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 11 dnl Ensure to expand the default settings once only, before all statements
12 dnl once only, before all statements that occur in other macros. 12 dnl that occur in other macros.
13 AC_REQUIRE([gl_HEADER_STRINGS_H_BODY]) 13 AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
14])
15
16AC_DEFUN([gl_HEADER_STRINGS_H_BODY],
17[
18 AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
19 14
20 gl_CHECK_NEXT_HEADERS([strings.h]) 15 gl_CHECK_NEXT_HEADERS([strings.h])
21 if test $ac_cv_header_strings_h = yes; then 16 if test $ac_cv_header_strings_h = yes; then
@@ -35,16 +30,31 @@ AC_DEFUN([gl_HEADER_STRINGS_H_BODY],
35 ]], [ffs strcasecmp strncasecmp]) 30 ]], [ffs strcasecmp strncasecmp])
36]) 31])
37 32
33# gl_STRINGS_MODULE_INDICATOR([modulename])
34# sets the shell variable that indicates the presence of the given module
35# to a C preprocessor expression that will evaluate to 1.
36# This macro invocation must not occur in macros that are AC_REQUIREd.
38AC_DEFUN([gl_STRINGS_MODULE_INDICATOR], 37AC_DEFUN([gl_STRINGS_MODULE_INDICATOR],
39[ 38[
40 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 39 dnl Ensure to expand the default settings once only.
41 AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) 40 gl_STRINGS_H_REQUIRE_DEFAULTS
42 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 41 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
43]) 42])
44 43
45AC_DEFUN([gl_HEADER_STRINGS_H_DEFAULTS], 44# Initializes the default values for AC_SUBSTed shell variables.
45# This macro must not be AC_REQUIREd. It must only be invoked, and only
46# outside of macros or in macros that are not AC_REQUIREd.
47AC_DEFUN([gl_STRINGS_H_REQUIRE_DEFAULTS],
48[
49 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS], [
50 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFS])
51 ])
52 m4_require(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS])
53 AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
54])
55
56AC_DEFUN([gl_STRINGS_H_DEFAULTS],
46[ 57[
47 GNULIB_FFS=0; AC_SUBST([GNULIB_FFS])
48 dnl Assume proper GNU behavior unless another module says otherwise. 58 dnl Assume proper GNU behavior unless another module says otherwise.
49 HAVE_FFS=1; AC_SUBST([HAVE_FFS]) 59 HAVE_FFS=1; AC_SUBST([HAVE_FFS])
50 HAVE_STRCASECMP=1; AC_SUBST([HAVE_STRCASECMP]) 60 HAVE_STRCASECMP=1; AC_SUBST([HAVE_STRCASECMP])
diff --git a/gl/m4/strndup.m4 b/gl/m4/strndup.m4
deleted file mode 100644
index a1f8274..0000000
--- a/gl/m4/strndup.m4
+++ /dev/null
@@ -1,55 +0,0 @@
1# strndup.m4 serial 21
2dnl Copyright (C) 2002-2003, 2005-2013 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_STRNDUP],
8[
9 dnl Persuade glibc <string.h> to declare strndup().
10 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
14 AC_CHECK_DECLS_ONCE([strndup])
15 AC_CHECK_FUNCS_ONCE([strndup])
16 if test $ac_cv_have_decl_strndup = no; then
17 HAVE_DECL_STRNDUP=0
18 fi
19
20 if test $ac_cv_func_strndup = yes; then
21 HAVE_STRNDUP=1
22 # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
23 AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
24 [AC_RUN_IFELSE([
25 AC_LANG_PROGRAM([[#include <string.h>
26 #include <stdlib.h>]], [[
27#if !HAVE_DECL_STRNDUP
28 extern
29 #ifdef __cplusplus
30 "C"
31 #endif
32 char *strndup (const char *, size_t);
33#endif
34 char *s;
35 s = strndup ("some longer string", 15);
36 free (s);
37 s = strndup ("shorter string", 13);
38 return s[13] != '\0';]])],
39 [gl_cv_func_strndup_works=yes],
40 [gl_cv_func_strndup_works=no],
41 [
42changequote(,)dnl
43 case $host_os in
44 aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";;
45 *) gl_cv_func_strndup_works="guessing yes";;
46 esac
47changequote([,])dnl
48 ])])
49 case $gl_cv_func_strndup_works in
50 *no) REPLACE_STRNDUP=1 ;;
51 esac
52 else
53 HAVE_STRNDUP=0
54 fi
55])
diff --git a/gl/m4/strnlen.m4 b/gl/m4/strnlen.m4
deleted file mode 100644
index eae82b7..0000000
--- a/gl/m4/strnlen.m4
+++ /dev/null
@@ -1,30 +0,0 @@
1# strnlen.m4 serial 13
2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_DEFUN([gl_FUNC_STRNLEN],
9[
10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
11
12 dnl Persuade glibc <string.h> to declare strnlen().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14
15 AC_CHECK_DECLS_ONCE([strnlen])
16 if test $ac_cv_have_decl_strnlen = no; then
17 HAVE_DECL_STRNLEN=0
18 else
19 m4_pushdef([AC_LIBOBJ], [:])
20 dnl Note: AC_FUNC_STRNLEN does AC_LIBOBJ([strnlen]).
21 AC_FUNC_STRNLEN
22 m4_popdef([AC_LIBOBJ])
23 if test $ac_cv_func_strnlen_working = no; then
24 REPLACE_STRNLEN=1
25 fi
26 fi
27])
28
29# Prerequisites of lib/strnlen.c.
30AC_DEFUN([gl_PREREQ_STRNLEN], [:])
diff --git a/gl/m4/strsep.m4 b/gl/m4/strsep.m4
index 825fdb8..e0da09a 100644
--- a/gl/m4/strsep.m4
+++ b/gl/m4/strsep.m4
@@ -1,5 +1,5 @@
1# strsep.m4 serial 10 1# strsep.m4 serial 11
2dnl Copyright (C) 2002-2004, 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2007, 2009-2023 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,7 +12,7 @@ AC_DEFUN([gl_FUNC_STRSEP],
12 dnl The strsep() declaration in lib/string.in.h uses 'restrict'. 12 dnl The strsep() declaration in lib/string.in.h uses 'restrict'.
13 AC_REQUIRE([AC_C_RESTRICT]) 13 AC_REQUIRE([AC_C_RESTRICT])
14 14
15 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 15 AC_REQUIRE([gl_STRING_H_DEFAULTS])
16 AC_CHECK_FUNCS([strsep]) 16 AC_CHECK_FUNCS([strsep])
17 if test $ac_cv_func_strsep = no; then 17 if test $ac_cv_func_strsep = no; then
18 HAVE_STRSEP=0 18 HAVE_STRSEP=0
diff --git a/gl/m4/strstr.m4 b/gl/m4/strstr.m4
index c486bdb..7de203a 100644
--- a/gl/m4/strstr.m4
+++ b/gl/m4/strstr.m4
@@ -1,5 +1,5 @@
1# strstr.m4 serial 16 1# strstr.m4 serial 24
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 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,30 +7,40 @@ dnl with or without modifications, as long as this notice is preserved.
7dnl Check that strstr works. 7dnl Check that strstr works.
8AC_DEFUN([gl_FUNC_STRSTR_SIMPLE], 8AC_DEFUN([gl_FUNC_STRSTR_SIMPLE],
9[ 9[
10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 10 AC_REQUIRE([gl_STRING_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_MEMCHR]) 11 AC_REQUIRE([gl_FUNC_MEMCHR])
12 if test "$gl_cv_func_memchr_works" != yes; then 12 if test $REPLACE_MEMCHR = 1; then
13 REPLACE_STRSTR=1 13 REPLACE_STRSTR=1
14 else 14 else
15 dnl Detect http://sourceware.org/bugzilla/show_bug.cgi?id=12092. 15 dnl Detect https://sourceware.org/bugzilla/show_bug.cgi?id=12092
16 dnl and https://sourceware.org/bugzilla/show_bug.cgi?id=23637.
16 AC_CACHE_CHECK([whether strstr works], 17 AC_CACHE_CHECK([whether strstr works],
17 [gl_cv_func_strstr_works_always], 18 [gl_cv_func_strstr_works_always],
18 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 19 [AC_RUN_IFELSE(
19#include <string.h> /* for strstr */ 20 [AC_LANG_PROGRAM([[
21#include <string.h> /* for __GNU_LIBRARY__, strstr */
22#ifdef __GNU_LIBRARY__
23 #include <features.h>
24 #if __GLIBC__ == 2 && __GLIBC_MINOR__ == 28
25 Unlucky user
26 #endif
27#endif
20#define P "_EF_BF_BD" 28#define P "_EF_BF_BD"
21#define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P 29#define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P
22#define NEEDLE P P P P P 30#define NEEDLE P P P P P
23]], [[return !!strstr (HAYSTACK, NEEDLE); 31]],
24 ]])], 32 [[return !!strstr (HAYSTACK, NEEDLE);
25 [gl_cv_func_strstr_works_always=yes], 33 ]])],
26 [gl_cv_func_strstr_works_always=no], 34 [gl_cv_func_strstr_works_always=yes],
27 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not 35 [gl_cv_func_strstr_works_always=no],
28 dnl affected, since it uses different source code for strstr than 36 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not
29 dnl glibc. 37 dnl affected, since it uses different source code for strstr than
30 dnl Assume that it works on all other platforms, even if it is not 38 dnl glibc.
31 dnl linear. 39 dnl Assume that it works on all other platforms, even if it is not
32 AC_EGREP_CPP([Lucky user], 40 dnl linear.
33 [ 41 AC_EGREP_CPP([Lucky user],
42 [
43#include <string.h> /* for __GNU_LIBRARY__ */
34#ifdef __GNU_LIBRARY__ 44#ifdef __GNU_LIBRARY__
35 #include <features.h> 45 #include <features.h>
36 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \ 46 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
@@ -45,10 +55,10 @@ AC_DEFUN([gl_FUNC_STRSTR_SIMPLE],
45#else 55#else
46 Lucky user 56 Lucky user
47#endif 57#endif
48 ], 58 ],
49 [gl_cv_func_strstr_works_always="guessing yes"], 59 [gl_cv_func_strstr_works_always="guessing yes"],
50 [gl_cv_func_strstr_works_always="guessing no"]) 60 [gl_cv_func_strstr_works_always="$gl_cross_guess_normal"])
51 ]) 61 ])
52 ]) 62 ])
53 case "$gl_cv_func_strstr_works_always" in 63 case "$gl_cv_func_strstr_works_always" in
54 *yes) ;; 64 *yes) ;;
@@ -67,11 +77,17 @@ AC_DEFUN([gl_FUNC_STRSTR],
67 AC_CACHE_CHECK([whether strstr works in linear time], 77 AC_CACHE_CHECK([whether strstr works in linear time],
68 [gl_cv_func_strstr_linear], 78 [gl_cv_func_strstr_linear],
69 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 79 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
80#ifdef __MVS__
81/* z/OS does not deliver signals while strstr() is running (thanks to
82 restrictions on its LE runtime), which prevents us from limiting the
83 running time of this test. */
84# error "This test does not work properly on z/OS"
85#endif
70#include <signal.h> /* for signal */ 86#include <signal.h> /* for signal */
71#include <string.h> /* for strstr */ 87#include <string.h> /* for strstr */
72#include <stdlib.h> /* for malloc */ 88#include <stdlib.h> /* for malloc */
73#include <unistd.h> /* for alarm */ 89#include <unistd.h> /* for alarm */
74static void quit (int sig) { exit (sig + 128); } 90static void quit (int sig) { _exit (sig + 128); }
75]], [[ 91]], [[
76 int result = 0; 92 int result = 0;
77 size_t m = 1000000; 93 size_t m = 1000000;
@@ -93,6 +109,9 @@ static void quit (int sig) { exit (sig + 128); }
93 if (!strstr (haystack, needle)) 109 if (!strstr (haystack, needle))
94 result |= 1; 110 result |= 1;
95 } 111 }
112 /* Free allocated memory, in case some sanitizer is watching. */
113 free (haystack);
114 free (needle);
96 return result; 115 return result;
97 ]])], 116 ]])],
98 [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no], 117 [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no],
@@ -117,7 +136,7 @@ static void quit (int sig) { exit (sig + 128); }
117#endif 136#endif
118 ], 137 ],
119 [gl_cv_func_strstr_linear="guessing yes"], 138 [gl_cv_func_strstr_linear="guessing yes"],
120 [gl_cv_func_strstr_linear="guessing no"]) 139 [gl_cv_func_strstr_linear="$gl_cross_guess_normal"])
121 ]) 140 ])
122 ]) 141 ])
123 case "$gl_cv_func_strstr_linear" in 142 case "$gl_cv_func_strstr_linear" in
diff --git a/gl/m4/sys_socket_h.m4 b/gl/m4/sys_socket_h.m4
index 9486377..98a1041 100644
--- a/gl/m4/sys_socket_h.m4
+++ b/gl/m4/sys_socket_h.m4
@@ -1,12 +1,12 @@
1# sys_socket_h.m4 serial 23 1# sys_socket_h.m4 serial 29
2dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2023 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 From Simon Josefsson. 7dnl From Simon Josefsson.
8 8
9AC_DEFUN([gl_HEADER_SYS_SOCKET], 9AC_DEFUN_ONCE([gl_SYS_SOCKET_H],
10[ 10[
11 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS]) 11 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
12 AC_REQUIRE([AC_CANONICAL_HOST]) 12 AC_REQUIRE([AC_CANONICAL_HOST])
@@ -22,6 +22,7 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
22 ;; 22 ;;
23 esac 23 esac
24 24
25 GL_GENERATE_SYS_SOCKET_H=false
25 AC_CACHE_CHECK([whether <sys/socket.h> is self-contained], 26 AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
26 [gl_cv_header_sys_socket_h_selfcontained], 27 [gl_cv_header_sys_socket_h_selfcontained],
27 [ 28 [
@@ -44,7 +45,7 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
44 [gl_cv_header_sys_socket_h_shut=no]) 45 [gl_cv_header_sys_socket_h_shut=no])
45 ]) 46 ])
46 if test $gl_cv_header_sys_socket_h_shut = no; then 47 if test $gl_cv_header_sys_socket_h_shut = no; then
47 SYS_SOCKET_H='sys/socket.h' 48 GL_GENERATE_SYS_SOCKET_H=true
48 fi 49 fi
49 fi 50 fi
50 fi 51 fi
@@ -83,7 +84,7 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
83 fi 84 fi
84 if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \ 85 if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
85 || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then 86 || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
86 SYS_SOCKET_H='sys/socket.h' 87 GL_GENERATE_SYS_SOCKET_H=true
87 fi 88 fi
88 gl_PREREQ_SYS_H_WINSOCK2 89 gl_PREREQ_SYS_H_WINSOCK2
89 90
@@ -95,6 +96,8 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
95#include <sys/socket.h> 96#include <sys/socket.h>
96 ]], [socket connect accept bind getpeername getsockname getsockopt 97 ]], [socket connect accept bind getpeername getsockname getsockopt
97 listen recv send recvfrom sendto setsockopt shutdown accept4]) 98 listen recv send recvfrom sendto setsockopt shutdown accept4])
99
100 AC_REQUIRE([AC_C_RESTRICT])
98]) 101])
99 102
100AC_DEFUN([gl_PREREQ_SYS_H_SOCKET], 103AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
@@ -104,17 +107,11 @@ AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
104 gl_CHECK_NEXT_HEADERS([sys/socket.h]) 107 gl_CHECK_NEXT_HEADERS([sys/socket.h])
105 if test $ac_cv_header_sys_socket_h = yes; then 108 if test $ac_cv_header_sys_socket_h = yes; then
106 HAVE_SYS_SOCKET_H=1 109 HAVE_SYS_SOCKET_H=1
107 HAVE_WS2TCPIP_H=0
108 else 110 else
109 HAVE_SYS_SOCKET_H=0 111 HAVE_SYS_SOCKET_H=0
110 if test $ac_cv_header_ws2tcpip_h = yes; then
111 HAVE_WS2TCPIP_H=1
112 else
113 HAVE_WS2TCPIP_H=0
114 fi
115 fi 112 fi
116 AC_SUBST([HAVE_SYS_SOCKET_H]) 113 AC_SUBST([HAVE_SYS_SOCKET_H])
117 AC_SUBST([HAVE_WS2TCPIP_H]) 114 gl_PREREQ_SYS_H_WS2TCPIP
118]) 115])
119 116
120# Common prerequisites of the <sys/socket.h> replacement and of the 117# Common prerequisites of the <sys/socket.h> replacement and of the
@@ -142,32 +139,65 @@ AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
142 AC_SUBST([HAVE_WINSOCK2_H]) 139 AC_SUBST([HAVE_WINSOCK2_H])
143]) 140])
144 141
142# Common prerequisites of the <sys/socket.h> replacement and of the
143# <arpa/inet.h> replacement.
144# Sets and substitutes HAVE_WS2TCPIP_H.
145AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP],
146[
147 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
148 if test $ac_cv_header_sys_socket_h = yes; then
149 HAVE_WS2TCPIP_H=0
150 else
151 if test $ac_cv_header_ws2tcpip_h = yes; then
152 HAVE_WS2TCPIP_H=1
153 else
154 HAVE_WS2TCPIP_H=0
155 fi
156 fi
157 AC_SUBST([HAVE_WS2TCPIP_H])
158])
159
160# gl_SYS_SOCKET_MODULE_INDICATOR([modulename])
161# sets the shell variable that indicates the presence of the given module
162# to a C preprocessor expression that will evaluate to 1.
163# This macro invocation must not occur in macros that are AC_REQUIREd.
145AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR], 164AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
146[ 165[
147 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 166 dnl Ensure to expand the default settings once only.
148 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS]) 167 gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
149 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 168 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
150 dnl Define it also as a C macro, for the benefit of the unit tests. 169 dnl Define it also as a C macro, for the benefit of the unit tests.
151 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 170 gl_MODULE_INDICATOR_FOR_TESTS([$1])
152]) 171])
153 172
173# Initializes the default values for AC_SUBSTed shell variables.
174# This macro must not be AC_REQUIREd. It must only be invoked, and only
175# outside of macros or in macros that are not AC_REQUIREd.
176AC_DEFUN([gl_SYS_SOCKET_H_REQUIRE_DEFAULTS],
177[
178 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS], [
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SOCKET])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CONNECT])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BIND])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPEERNAME])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKNAME])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKOPT])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LISTEN])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECV])
188 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SEND])
189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECVFROM])
190 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SENDTO])
191 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETSOCKOPT])
192 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SHUTDOWN])
193 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT4])
194 ])
195 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS])
196 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
197])
198
154AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS], 199AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
155[ 200[
156 GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
157 GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
158 GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
159 GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
160 GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
161 GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
162 GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
163 GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
164 GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
165 GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
166 GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
167 GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
168 GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
169 GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
170 GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
171 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE]) 201 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
172 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1; 202 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
173 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY]) 203 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
diff --git a/gl/m4/sys_stat_h.m4 b/gl/m4/sys_stat_h.m4
new file mode 100644
index 0000000..ca57398
--- /dev/null
+++ b/gl/m4/sys_stat_h.m4
@@ -0,0 +1,129 @@
1# sys_stat_h.m4 serial 42 -*- Autoconf -*-
2dnl Copyright (C) 2006-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Eric Blake.
8dnl Provide a GNU-like <sys/stat.h>.
9
10AC_DEFUN_ONCE([gl_SYS_STAT_H],
11[
12 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
13
14 dnl Check for broken stat macros.
15 AC_REQUIRE([AC_HEADER_STAT])
16
17 gl_CHECK_NEXT_HEADERS([sys/stat.h])
18
19 dnl Ensure the type mode_t gets defined.
20 AC_REQUIRE([AC_TYPE_MODE_T])
21
22 dnl Whether to enable precise timestamps in 'struct stat'.
23 m4_ifdef([gl_WINDOWS_STAT_TIMESPEC], [
24 AC_REQUIRE([gl_WINDOWS_STAT_TIMESPEC])
25 ], [
26 WINDOWS_STAT_TIMESPEC=0
27 ])
28 AC_SUBST([WINDOWS_STAT_TIMESPEC])
29
30 dnl Whether to ensure that struct stat.st_size is 64-bit wide.
31 m4_ifdef([gl_LARGEFILE], [
32 AC_REQUIRE([gl_LARGEFILE])
33 ], [
34 WINDOWS_64_BIT_ST_SIZE=0
35 ])
36 AC_SUBST([WINDOWS_64_BIT_ST_SIZE])
37
38 dnl Define types that are supposed to be defined in <sys/types.h> or
39 dnl <sys/stat.h>.
40 AC_CHECK_TYPE([nlink_t], [],
41 [AC_DEFINE([nlink_t], [int],
42 [Define to the type of st_nlink in struct stat, or a supertype.])],
43 [#include <sys/types.h>
44 #include <sys/stat.h>])
45
46 dnl Check for declarations of anything we want to poison if the
47 dnl corresponding gnulib module is not in use.
48 gl_WARN_ON_USE_PREPARE([[#include <sys/stat.h>
49 ]], [chmod fchmodat fstat fstatat futimens getumask lchmod lstat
50 mkdirat mkfifo mkfifoat mknod mknodat stat utimensat])
51
52 AC_REQUIRE([AC_C_RESTRICT])
53])
54
55# gl_SYS_STAT_MODULE_INDICATOR([modulename])
56# sets the shell variable that indicates the presence of the given module
57# to a C preprocessor expression that will evaluate to 1.
58# This macro invocation must not occur in macros that are AC_REQUIREd.
59AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
60[
61 dnl Ensure to expand the default settings once only.
62 gl_SYS_STAT_H_REQUIRE_DEFAULTS
63 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
64 dnl Define it also as a C macro, for the benefit of the unit tests.
65 gl_MODULE_INDICATOR_FOR_TESTS([$1])
66])
67
68# Initializes the default values for AC_SUBSTed shell variables.
69# This macro must not be AC_REQUIREd. It must only be invoked, and only
70# outside of macros or in macros that are not AC_REQUIREd.
71AC_DEFUN([gl_SYS_STAT_H_REQUIRE_DEFAULTS],
72[
73 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_STAT_H_MODULE_INDICATOR_DEFAULTS], [
74 gl_UNISTD_H_REQUIRE_DEFAULTS dnl for REPLACE_FCHDIR
75 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CHMOD])
76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCHMODAT])
77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSTAT])
78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSTATAT])
79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FUTIMENS])
80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETUMASK])
81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LCHMOD])
82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LSTAT])
83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDIR])
84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDIRAT])
85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKFIFO])
86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKFIFOAT])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKNOD])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKNODAT])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STAT])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UTIMENSAT])
91 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OVERRIDES_STRUCT_STAT])
92 dnl Support Microsoft deprecated alias function names by default.
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CHMOD], [1])
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_MKDIR], [1])
95 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_UMASK], [1])
96 ])
97 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_STAT_H_MODULE_INDICATOR_DEFAULTS])
98 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
99])
100
101AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
102[
103 dnl Assume proper GNU behavior unless another module says otherwise.
104 HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT])
105 HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT])
106 HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS])
107 HAVE_GETUMASK=1; AC_SUBST([HAVE_GETUMASK])
108 HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD])
109 HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT])
110 HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT])
111 HAVE_MKFIFO=1; AC_SUBST([HAVE_MKFIFO])
112 HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT])
113 HAVE_MKNOD=1; AC_SUBST([HAVE_MKNOD])
114 HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT])
115 HAVE_UTIMENSAT=1; AC_SUBST([HAVE_UTIMENSAT])
116 REPLACE_CHMOD=0; AC_SUBST([REPLACE_CHMOD])
117 REPLACE_FCHMODAT=0; AC_SUBST([REPLACE_FCHMODAT])
118 REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT])
119 REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT])
120 REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS])
121 REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
122 REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
123 REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO])
124 REPLACE_MKFIFOAT=0; AC_SUBST([REPLACE_MKFIFOAT])
125 REPLACE_MKNOD=0; AC_SUBST([REPLACE_MKNOD])
126 REPLACE_MKNODAT=0; AC_SUBST([REPLACE_MKNODAT])
127 REPLACE_STAT=0; AC_SUBST([REPLACE_STAT])
128 REPLACE_UTIMENSAT=0; AC_SUBST([REPLACE_UTIMENSAT])
129])
diff --git a/gl/m4/sys_types_h.m4 b/gl/m4/sys_types_h.m4
index d15c1b3..627671f 100644
--- a/gl/m4/sys_types_h.m4
+++ b/gl/m4/sys_types_h.m4
@@ -1,5 +1,5 @@
1# sys_types_h.m4 serial 5 1# sys_types_h.m4 serial 13
2dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2011-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -7,6 +7,10 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN_ONCE([gl_SYS_TYPES_H], 7AC_DEFUN_ONCE([gl_SYS_TYPES_H],
8[ 8[
9 AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS]) 9 AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS])
10
11 dnl Use sane struct stat types in OpenVMS 8.2 and later.
12 AC_DEFINE([_USE_STD_STAT], 1, [For standard stat data types on VMS.])
13
10 gl_NEXT_HEADERS([sys/types.h]) 14 gl_NEXT_HEADERS([sys/types.h])
11 15
12 dnl Ensure the type pid_t gets defined. 16 dnl Ensure the type pid_t gets defined.
@@ -17,8 +21,50 @@ AC_DEFUN_ONCE([gl_SYS_TYPES_H],
17 21
18 dnl Whether to override the 'off_t' type. 22 dnl Whether to override the 'off_t' type.
19 AC_REQUIRE([gl_TYPE_OFF_T]) 23 AC_REQUIRE([gl_TYPE_OFF_T])
24
25 dnl Whether to override the 'dev_t' and 'ino_t' types.
26 m4_ifdef([gl_WINDOWS_STAT_INODES], [
27 AC_REQUIRE([gl_WINDOWS_STAT_INODES])
28 ], [
29 WINDOWS_STAT_INODES=0
30 ])
31 AC_SUBST([WINDOWS_STAT_INODES])
32])
33
34# Initializes the default values for AC_SUBSTed shell variables.
35# This macro must not be AC_REQUIREd. It must only be invoked, and only
36# outside of macros or in macros that are not AC_REQUIREd.
37AC_DEFUN([gl_SYS_TYPES_H_REQUIRE_DEFAULTS],
38[
39 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_TYPE_H_MODULE_INDICATOR_DEFAULTS], [
40 ])
41 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_TYPE_H_MODULE_INDICATOR_DEFAULTS])
42 AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS])
20]) 43])
21 44
22AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS], 45AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS],
23[ 46[
24]) 47])
48
49# This works around a buggy version in autoconf <= 2.69.
50# See <https://lists.gnu.org/r/autoconf/2016-08/msg00014.html>
51# The 2.70 version isn't quoted properly, so override it too.
52
53m4_version_prereq([2.70.1], [], [
54
55m4_undefine([AC_HEADER_MAJOR])
56AC_DEFUN([AC_HEADER_MAJOR],
57[AC_CHECK_HEADERS_ONCE([sys/types.h])
58AC_CHECK_HEADER([sys/mkdev.h],
59 [AC_DEFINE([MAJOR_IN_MKDEV], [1],
60 [Define to 1 if `major', `minor', and `makedev' are
61 declared in <mkdev.h>.])])
62if test $ac_cv_header_sys_mkdev_h = no; then
63 AC_CHECK_HEADER([sys/sysmacros.h],
64 [AC_DEFINE([MAJOR_IN_SYSMACROS], [1],
65 [Define to 1 if `major', `minor', and `makedev'
66 are declared in <sysmacros.h>.])])
67fi
68])# AC_HEADER_MAJOR
69
70])
diff --git a/gl/m4/sys_uio_h.m4 b/gl/m4/sys_uio_h.m4
index c75cbbd..93a65d2 100644
--- a/gl/m4/sys_uio_h.m4
+++ b/gl/m4/sys_uio_h.m4
@@ -1,10 +1,10 @@
1# sys_uio_h.m4 serial 1 1# sys_uio_h.m4 serial 3
2dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2011-2023 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_HEADER_SYS_UIO], 7AC_DEFUN_ONCE([gl_SYS_UIO_H],
8[ 8[
9 AC_REQUIRE([gl_SYS_UIO_H_DEFAULTS]) 9 AC_REQUIRE([gl_SYS_UIO_H_DEFAULTS])
10 dnl <sys/uio.h> is always overridden, because of GNULIB_POSIXCHECK. 10 dnl <sys/uio.h> is always overridden, because of GNULIB_POSIXCHECK.
@@ -17,15 +17,30 @@ AC_DEFUN([gl_HEADER_SYS_UIO],
17 AC_SUBST([HAVE_SYS_UIO_H]) 17 AC_SUBST([HAVE_SYS_UIO_H])
18]) 18])
19 19
20# gl_SYS_UIO_MODULE_INDICATOR([modulename])
21# sets the shell variable that indicates the presence of the given module
22# to a C preprocessor expression that will evaluate to 1.
23# This macro invocation must not occur in macros that are AC_REQUIREd.
20AC_DEFUN([gl_SYS_UIO_MODULE_INDICATOR], 24AC_DEFUN([gl_SYS_UIO_MODULE_INDICATOR],
21[ 25[
22 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 26 dnl Ensure to expand the default settings once only.
23 AC_REQUIRE([gl_SYS_UIO_H_DEFAULTS]) 27 gl_SYS_UIO_H_REQUIRE_DEFAULTS
24 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 28 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
25 dnl Define it also as a C macro, for the benefit of the unit tests. 29 dnl Define it also as a C macro, for the benefit of the unit tests.
26 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 30 gl_MODULE_INDICATOR_FOR_TESTS([$1])
27]) 31])
28 32
33# Initializes the default values for AC_SUBSTed shell variables.
34# This macro must not be AC_REQUIREd. It must only be invoked, and only
35# outside of macros or in macros that are not AC_REQUIREd.
36AC_DEFUN([gl_SYS_UIO_H_REQUIRE_DEFAULTS],
37[
38 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_UIO_H_MODULE_INDICATOR_DEFAULTS], [
39 ])
40 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_UIO_H_MODULE_INDICATOR_DEFAULTS])
41 AC_REQUIRE([gl_SYS_UIO_H_DEFAULTS])
42])
43
29AC_DEFUN([gl_SYS_UIO_H_DEFAULTS], 44AC_DEFUN([gl_SYS_UIO_H_DEFAULTS],
30[ 45[
31]) 46])
diff --git a/gl/m4/threadlib.m4 b/gl/m4/threadlib.m4
index 26bdeb5..b536b04 100644
--- a/gl/m4/threadlib.m4
+++ b/gl/m4/threadlib.m4
@@ -1,11 +1,390 @@
1# threadlib.m4 serial 10 (gettext-0.18.2) 1# threadlib.m4 serial 32a
2dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2023 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 From Bruno Haible. 7dnl From Bruno Haible.
8 8
9AC_PREREQ([2.60])
10
11dnl The general structure of the multithreading modules in gnulib is that we
12dnl have three set of modules:
13dnl
14dnl * POSIX API:
15dnl pthread, which combines
16dnl pthread-h
17dnl pthread-thread
18dnl pthread-once
19dnl pthread-mutex
20dnl pthread-rwlock
21dnl pthread-cond
22dnl pthread-tss
23dnl pthread-spin
24dnl sched_yield
25dnl
26dnl * ISO C API:
27dnl threads, which combines
28dnl threads-h
29dnl thrd
30dnl mtx
31dnl cnd
32dnl tss
33dnl
34dnl * Gnulib API, with an implementation that can be chosen at configure
35dnl time through the option --enable-threads=...
36dnl thread
37dnl lock
38dnl cond
39dnl tls
40dnl yield
41dnl
42dnl They are independent, except for the fact that
43dnl - the implementation of the ISO C API may use the POSIX (or some other
44dnl platform dependent) API,
45dnl - the implementation of the Gnulib API may use the POSIX or ISO C or
46dnl some other platform dependent API, depending on the --enable-threads
47dnl option.
48dnl
49dnl This file contains macros for all of these APIs!
50
51dnl ============================================================================
52dnl Macros for all thread APIs
53
54AC_DEFUN([gl_ANYTHREADLIB_EARLY],
55[
56 AC_REQUIRE([AC_CANONICAL_HOST])
57 if test -z "$gl_anythreadlib_early_done"; then
58 case "$host_os" in
59 osf*)
60 # On OSF/1, the compiler needs the flag -D_REENTRANT so that it
61 # groks <pthread.h>. cc also understands the flag -pthread, but
62 # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
63 # 2. putting a flag into CPPFLAGS that has an effect on the linker
64 # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
65 # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
66 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
67 ;;
68 esac
69 # Some systems optimize for single-threaded programs by default, and
70 # need special flags to disable these optimizations. For example, the
71 # definition of 'errno' in <errno.h>.
72 case "$host_os" in
73 aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
74 solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
75 esac
76 gl_anythreadlib_early_done=done
77 fi
78])
79
80dnl Checks whether the compiler and linker support weak declarations of symbols.
81
82AC_DEFUN([gl_WEAK_SYMBOLS],
83[
84 AC_REQUIRE([AC_CANONICAL_HOST])
85 AC_CACHE_CHECK([whether imported symbols can be declared weak],
86 [gl_cv_have_weak],
87 [case "$host_os" in
88 cygwin*)
89 dnl On Cygwin 3.2.0 with gcc 10.2, the test below would succeed, but
90 dnl programs that use pthread_in_use() with weak symbol references
91 dnl crash miserably at runtime.
92 gl_cv_have_weak="guessing no"
93 ;;
94 *)
95 gl_cv_have_weak=no
96 dnl First, test whether the compiler accepts it syntactically.
97 AC_LINK_IFELSE(
98 [AC_LANG_PROGRAM(
99 [[extern void xyzzy ();
100#pragma weak xyzzy]],
101 [[xyzzy();]])],
102 [gl_cv_have_weak=maybe])
103 if test $gl_cv_have_weak = maybe; then
104 dnl Second, test whether it actually works. On Cygwin 1.7.2, with
105 dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
106 AC_RUN_IFELSE(
107 [AC_LANG_SOURCE([[
108#include <stdio.h>
109#pragma weak fputs
110int main ()
111{
112 return (fputs == NULL);
113}]])],
114 [gl_cv_have_weak=yes],
115 [gl_cv_have_weak=no],
116 [dnl When cross-compiling, assume that only ELF platforms support
117 dnl weak symbols.
118 AC_EGREP_CPP([Extensible Linking Format],
119 [#ifdef __ELF__
120 Extensible Linking Format
121 #endif
122 ],
123 [gl_cv_have_weak="guessing yes"],
124 [gl_cv_have_weak="guessing no"])
125 ])
126 fi
127 ;;
128 esac
129 dnl But when linking statically, weak symbols don't work.
130 case " $LDFLAGS " in
131 *" -static "*) gl_cv_have_weak=no ;;
132 esac
133 dnl Test for a bug in FreeBSD 11: A link error occurs when using a weak
134 dnl symbol and linking against a shared library that has a dependency on
135 dnl the shared library that defines the symbol.
136 case "$gl_cv_have_weak" in
137 *yes)
138 case "$host_os" in
139 freebsd* | dragonfly* | midnightbsd*)
140 : > conftest1.c
141 $CC $CPPFLAGS $CFLAGS $LDFLAGS -fPIC -shared -o libempty.so conftest1.c -lpthread >&AS_MESSAGE_LOG_FD 2>&1
142 cat <<EOF > conftest2.c
143#include <pthread.h>
144#pragma weak pthread_mutexattr_gettype
145int main ()
146{
147 return (pthread_mutexattr_gettype != NULL);
148}
149EOF
150 $CC $CPPFLAGS $CFLAGS $LDFLAGS -o conftest conftest2.c libempty.so >&AS_MESSAGE_LOG_FD 2>&1 \
151 || gl_cv_have_weak=no
152 rm -f conftest1.c libempty.so conftest2.c conftest
153 ;;
154 esac
155 ;;
156 esac
157 ])
158 case "$gl_cv_have_weak" in
159 *yes)
160 AC_DEFINE([HAVE_WEAK_SYMBOLS], [1],
161 [Define to 1 if the compiler and linker support weak declarations of symbols.])
162 ;;
163 esac
164])
165
166dnl ============================================================================
167dnl Macros for the POSIX API
168
169dnl gl_PTHREADLIB
170dnl -------------
171dnl Tests for the libraries needs for using the POSIX threads API.
172dnl Sets the variable LIBPTHREAD to the linker options for use in a Makefile.
173dnl Sets the variable LIBPMULTITHREAD, for programs that really need
174dnl multithread functionality. The difference between LIBPTHREAD and
175dnl LIBPMULTITHREAD is that on platforms supporting weak symbols, typically
176dnl LIBPTHREAD is empty whereas LIBPMULTITHREAD is not.
177dnl Sets the variable LIB_SCHED_YIELD to the linker options needed to use the
178dnl sched_yield() function.
179dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
180dnl multithread-safe programs.
181dnl Defines the C macro HAVE_PTHREAD_API if (at least parts of) the POSIX
182dnl threads API is available.
183
184dnl The guts of gl_PTHREADLIB. Needs to be expanded only once.
185
186AC_DEFUN([gl_PTHREADLIB_BODY],
187[
188 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
189 if test -z "$gl_pthreadlib_body_done"; then
190 gl_pthread_api=no
191 LIBPTHREAD=
192 LIBPMULTITHREAD=
193 # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
194 # it groks <pthread.h>. It's added above, in gl_ANYTHREADLIB_EARLY.
195 AC_CHECK_HEADER([pthread.h],
196 [gl_have_pthread_h=yes], [gl_have_pthread_h=no])
197 if test "$gl_have_pthread_h" = yes; then
198 # Other possible tests:
199 # -lpthreads (FSU threads, PCthreads)
200 # -lgthreads
201 # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
202 # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
203 # the second one only in libpthread, and lock.c needs it.
204 #
205 # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
206 # needs -pthread for some reason. See:
207 # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html
208 save_LIBS=$LIBS
209 for gl_pthread in '' '-pthread'; do
210 LIBS="$LIBS $gl_pthread"
211 AC_LINK_IFELSE(
212 [AC_LANG_PROGRAM(
213 [[#include <pthread.h>
214 pthread_mutex_t m;
215 pthread_mutexattr_t ma;
216 ]],
217 [[pthread_mutex_lock (&m);
218 pthread_mutexattr_init (&ma);]])],
219 [gl_pthread_api=yes
220 LIBPTHREAD=$gl_pthread
221 LIBPMULTITHREAD=$gl_pthread])
222 LIBS=$save_LIBS
223 test $gl_pthread_api = yes && break
224 done
225 echo "$as_me:__oline__: gl_pthread_api=$gl_pthread_api" >&AS_MESSAGE_LOG_FD
226 echo "$as_me:__oline__: LIBPTHREAD=$LIBPTHREAD" >&AS_MESSAGE_LOG_FD
227
228 gl_pthread_in_glibc=no
229 # On Linux with glibc >= 2.34, libc contains the fully functional
230 # pthread functions.
231 case "$host_os" in
232 linux*)
233 AC_EGREP_CPP([Lucky user],
234 [#include <features.h>
235 #ifdef __GNU_LIBRARY__
236 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34) || (__GLIBC__ > 2)
237 Lucky user
238 #endif
239 #endif
240 ],
241 [gl_pthread_in_glibc=yes],
242 [])
243 ;;
244 esac
245 echo "$as_me:__oline__: gl_pthread_in_glibc=$gl_pthread_in_glibc" >&AS_MESSAGE_LOG_FD
246
247 # Test for libpthread by looking for pthread_kill. (Not pthread_self,
248 # since it is defined as a macro on OSF/1.)
249 if test $gl_pthread_api = yes && test -z "$LIBPTHREAD"; then
250 # The program links fine without libpthread. But it may actually
251 # need to link with libpthread in order to create multiple threads.
252 AC_CHECK_LIB([pthread], [pthread_kill],
253 [if test $gl_pthread_in_glibc = yes; then
254 LIBPMULTITHREAD=
255 else
256 LIBPMULTITHREAD=-lpthread
257 # On Solaris and HP-UX, most pthread functions exist also in libc.
258 # Therefore pthread_in_use() needs to actually try to create a
259 # thread: pthread_create from libc will fail, whereas
260 # pthread_create will actually create a thread.
261 # On Solaris 10 or newer, this test is no longer needed, because
262 # libc contains the fully functional pthread functions.
263 case "$host_os" in
264changequote(,)dnl
265 solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
266changequote([,])dnl
267 AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
268 [Define if the pthread_in_use() detection is hard.])
269 esac
270 fi
271 ])
272 elif test $gl_pthread_api != yes; then
273 # Some library is needed. Try libpthread and libc_r.
274 AC_CHECK_LIB([pthread], [pthread_kill],
275 [gl_pthread_api=yes
276 LIBPTHREAD=-lpthread
277 LIBPMULTITHREAD=-lpthread])
278 if test $gl_pthread_api != yes; then
279 # For FreeBSD 4.
280 AC_CHECK_LIB([c_r], [pthread_kill],
281 [gl_pthread_api=yes
282 LIBPTHREAD=-lc_r
283 LIBPMULTITHREAD=-lc_r])
284 fi
285 fi
286 echo "$as_me:__oline__: LIBPMULTITHREAD=$LIBPMULTITHREAD" >&AS_MESSAGE_LOG_FD
287 fi
288 AC_MSG_CHECKING([whether POSIX threads API is available])
289 AC_MSG_RESULT([$gl_pthread_api])
290 AC_SUBST([LIBPTHREAD])
291 AC_SUBST([LIBPMULTITHREAD])
292 if test $gl_pthread_api = yes; then
293 AC_DEFINE([HAVE_PTHREAD_API], [1],
294 [Define if you have the <pthread.h> header and the POSIX threads API.])
295 fi
296
297 dnl On some systems, sched_yield is in librt, rather than in libpthread.
298 AC_LINK_IFELSE(
299 [AC_LANG_PROGRAM(
300 [[#include <sched.h>]],
301 [[sched_yield ();]])],
302 [LIB_SCHED_YIELD=
303 ],
304 [dnl Solaris 7...10 has sched_yield in librt, not in libpthread or libc.
305 AC_CHECK_LIB([rt], [sched_yield], [LIB_SCHED_YIELD=-lrt],
306 [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt.
307 AC_CHECK_LIB([posix4], [sched_yield], [LIB_SCHED_YIELD=-lposix4])])
308 ])
309 AC_SUBST([LIB_SCHED_YIELD])
310
311 gl_pthreadlib_body_done=done
312 fi
313])
314
315AC_DEFUN([gl_PTHREADLIB],
316[
317 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
318 gl_PTHREADLIB_BODY
319])
320
321dnl ============================================================================
322dnl Macros for the ISO C API
323
324dnl gl_STDTHREADLIB
325dnl ---------------
326dnl Tests for the libraries needs for using the ISO C threads API.
327dnl Sets the variable LIBSTDTHREAD to the linker options for use in a Makefile.
328dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
329dnl multithread-safe programs.
330dnl Defines the C macro HAVE_THREADS_H if (at least parts of) the ISO C threads
331dnl API is available.
332
333dnl The guts of gl_STDTHREADLIB. Needs to be expanded only once.
334
335AC_DEFUN([gl_STDTHREADLIB_BODY],
336[
337 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
338 AC_REQUIRE([AC_CANONICAL_HOST])
339 if test -z "$gl_stdthreadlib_body_done"; then
340 AC_CHECK_HEADERS_ONCE([threads.h])
341
342 case "$host_os" in
343 mingw*)
344 LIBSTDTHREAD=
345 ;;
346 *)
347 gl_PTHREADLIB_BODY
348 if test $ac_cv_header_threads_h = yes; then
349 dnl glibc >= 2.29 has thrd_create in libpthread.
350 dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
351 dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
352 dnl glibc >= 2.34, AIX >= 7.1, and Solaris >= 11.4 have thrd_create in
353 dnl libc.
354 AC_CHECK_FUNCS([thrd_create])
355 if test $ac_cv_func_thrd_create = yes; then
356 LIBSTDTHREAD=
357 else
358 AC_CHECK_LIB([stdthreads], [thrd_create], [
359 LIBSTDTHREAD='-lstdthreads -lpthread'
360 ], [
361 dnl Guess that thrd_create is in libpthread.
362 LIBSTDTHREAD="$LIBPMULTITHREAD"
363 ])
364 fi
365 else
366 dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
367 LIBSTDTHREAD="$LIBPMULTITHREAD $LIB_SCHED_YIELD"
368 fi
369 ;;
370 esac
371 AC_SUBST([LIBSTDTHREAD])
372
373 AC_MSG_CHECKING([whether ISO C threads API is available])
374 AC_MSG_RESULT([$ac_cv_header_threads_h])
375 gl_stdthreadlib_body_done=done
376 fi
377])
378
379AC_DEFUN([gl_STDTHREADLIB],
380[
381 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
382 gl_STDTHREADLIB_BODY
383])
384
385dnl ============================================================================
386dnl Macros for the Gnulib API
387
9dnl gl_THREADLIB 388dnl gl_THREADLIB
10dnl ------------ 389dnl ------------
11dnl Tests for a multithreading library to be used. 390dnl Tests for a multithreading library to be used.
@@ -14,17 +393,25 @@ dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the
14dnl default is 'no', otherwise it is system dependent. In both cases, the user 393dnl default is 'no', otherwise it is system dependent. In both cases, the user
15dnl can change the choice through the options --enable-threads=choice or 394dnl can change the choice through the options --enable-threads=choice or
16dnl --disable-threads. 395dnl --disable-threads.
17dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, 396dnl Defines at most one of the macros USE_ISOC_THREADS, USE_POSIX_THREADS,
18dnl USE_PTH_THREADS, USE_WINDOWS_THREADS 397dnl USE_ISOC_AND_POSIX_THREADS, USE_WINDOWS_THREADS.
398dnl The choice --enable-threads=isoc+posix is available only on platforms that
399dnl have both the ISO C and the POSIX threads APIs. It has the effect of using
400dnl the ISO C API for most things and the POSIX API only for creating and
401dnl controlling threads (because there is no equivalent to pthread_atfork in
402dnl the ISO C API).
19dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use 403dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use
20dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with 404dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with
21dnl libtool). 405dnl libtool).
22dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for 406dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
23dnl programs that really need multithread functionality. The difference 407dnl programs that really need multithread functionality. The difference
24dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak 408dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
25dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". 409dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
26dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for 410dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
27dnl multithread-safe programs. 411dnl multithread-safe programs.
412dnl Since support for GNU pth was removed, $LTLIBTHREAD and $LIBTHREAD have the
413dnl same value, and similarly $LTLIBMULTITHREAD and $LIBMULTITHREAD have the
414dnl same value. Only system libraries are needed.
28 415
29AC_DEFUN([gl_THREADLIB_EARLY], 416AC_DEFUN([gl_THREADLIB_EARLY],
30[ 417[
@@ -43,18 +430,15 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY],
43 430
44 AC_REQUIRE([AC_CANONICAL_HOST]) 431 AC_REQUIRE([AC_CANONICAL_HOST])
45 dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. 432 dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems.
46 dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes 433 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
47 dnl AC_GNU_SOURCE.
48 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
49 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
50 [AC_REQUIRE([AC_GNU_SOURCE])])
51 dnl Check for multithreading. 434 dnl Check for multithreading.
52 m4_ifdef([gl_THREADLIB_DEFAULT_NO], 435 m4_ifdef([gl_THREADLIB_DEFAULT_NO],
53 [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], 436 [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])],
54 [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) 437 [m4_divert_text([DEFAULTS], [gl_use_threads_default=])])
438 m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=])
55 AC_ARG_ENABLE([threads], 439 AC_ARG_ENABLE([threads],
56AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ 440AS_HELP_STRING([--enable-threads={isoc|posix|isoc+posix|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [
57AC_HELP_STRING([--disable-threads], [build without multithread safety])]), 441AS_HELP_STRING([--disable-threads], [build without multithread safety])]),
58 [gl_use_threads=$enableval], 442 [gl_use_threads=$enableval],
59 [if test -n "$gl_use_threads_default"; then 443 [if test -n "$gl_use_threads_default"; then
60 gl_use_threads="$gl_use_threads_default" 444 gl_use_threads="$gl_use_threads_default"
@@ -64,41 +448,35 @@ changequote(,)dnl
64 dnl Disable multithreading by default on OSF/1, because it interferes 448 dnl Disable multithreading by default on OSF/1, because it interferes
65 dnl with fork()/exec(): When msgexec is linked with -lpthread, its 449 dnl with fork()/exec(): When msgexec is linked with -lpthread, its
66 dnl child process gets an endless segmentation fault inside execvp(). 450 dnl child process gets an endless segmentation fault inside execvp().
451 osf*) gl_use_threads=no ;;
67 dnl Disable multithreading by default on Cygwin 1.5.x, because it has 452 dnl Disable multithreading by default on Cygwin 1.5.x, because it has
68 dnl bugs that lead to endless loops or crashes. See 453 dnl bugs that lead to endless loops or crashes. See
69 dnl <http://cygwin.com/ml/cygwin/2009-08/msg00283.html>. 454 dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
70 osf*) gl_use_threads=no ;;
71 cygwin*) 455 cygwin*)
72 case `uname -r` in 456 case `uname -r` in
73 1.[0-5].*) gl_use_threads=no ;; 457 1.[0-5].*) gl_use_threads=no ;;
74 *) gl_use_threads=yes ;; 458 *) gl_use_threads=yes ;;
75 esac 459 esac
76 ;; 460 ;;
461 dnl Obey gl_AVOID_WINPTHREAD on mingw.
462 mingw*)
463 case "$gl_use_winpthreads_default" in
464 yes) gl_use_threads=posix ;;
465 no) gl_use_threads=windows ;;
466 *) gl_use_threads=yes ;;
467 esac
468 ;;
77 *) gl_use_threads=yes ;; 469 *) gl_use_threads=yes ;;
78 esac 470 esac
79changequote([,])dnl 471changequote([,])dnl
80 fi 472 fi
81 ]) 473 ])
82 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then 474 if test "$gl_use_threads" = yes \
83 # For using <pthread.h>: 475 || test "$gl_use_threads" = isoc \
84 case "$host_os" in 476 || test "$gl_use_threads" = posix \
85 osf*) 477 || test "$gl_use_threads" = isoc+posix; then
86 # On OSF/1, the compiler needs the flag -D_REENTRANT so that it 478 # For using <threads.h> or <pthread.h>:
87 # groks <pthread.h>. cc also understands the flag -pthread, but 479 gl_ANYTHREADLIB_EARLY
88 # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
89 # 2. putting a flag into CPPFLAGS that has an effect on the linker
90 # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
91 # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
92 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
93 ;;
94 esac
95 # Some systems optimize for single-threaded programs by default, and
96 # need special flags to disable these optimizations. For example, the
97 # definition of 'errno' in <errno.h>.
98 case "$host_os" in
99 aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
100 solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
101 esac
102 fi 480 fi
103]) 481])
104 482
@@ -114,168 +492,69 @@ AC_DEFUN([gl_THREADLIB_BODY],
114 LTLIBMULTITHREAD= 492 LTLIBMULTITHREAD=
115 if test "$gl_use_threads" != no; then 493 if test "$gl_use_threads" != no; then
116 dnl Check whether the compiler and linker support weak declarations. 494 dnl Check whether the compiler and linker support weak declarations.
117 AC_CACHE_CHECK([whether imported symbols can be declared weak], 495 gl_WEAK_SYMBOLS
118 [gl_cv_have_weak], 496 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
119 [gl_cv_have_weak=no 497 dnl If we use weak symbols to implement pthread_in_use / pth_in_use /
120 dnl First, test whether the compiler accepts it syntactically. 498 dnl thread_in_use, we also need to test whether the ISO C 11 thrd_create
121 AC_LINK_IFELSE( 499 dnl facility is in use.
122 [AC_LANG_PROGRAM( 500 AC_CHECK_HEADERS_ONCE([threads.h])
123 [[extern void xyzzy (); 501 :
124#pragma weak xyzzy]], 502 fi
125 [[xyzzy();]])], 503 if test "$gl_use_threads" = isoc || test "$gl_use_threads" = isoc+posix; then
126 [gl_cv_have_weak=maybe]) 504 AC_CHECK_HEADERS_ONCE([threads.h])
127 if test $gl_cv_have_weak = maybe; then 505 gl_have_isoc_threads="$ac_cv_header_threads_h"
128 dnl Second, test whether it actually works. On Cygwin 1.7.2, with 506 fi
129 dnl gcc 4.3, symbols declared weak always evaluate to the address 0. 507 if test "$gl_use_threads" = yes \
130 AC_RUN_IFELSE( 508 || test "$gl_use_threads" = posix \
131 [AC_LANG_SOURCE([[ 509 || test "$gl_use_threads" = isoc+posix; then
132#include <stdio.h> 510 gl_PTHREADLIB_BODY
133#pragma weak fputs 511 LIBTHREAD=$LIBPTHREAD LTLIBTHREAD=$LIBPTHREAD
134int main () 512 LIBMULTITHREAD=$LIBPMULTITHREAD LTLIBMULTITHREAD=$LIBPMULTITHREAD
135{ 513 if test $gl_pthread_api = yes; then
136 return (fputs == NULL); 514 if test "$gl_use_threads" = isoc+posix && test "$gl_have_isoc_threads" = yes; then
137}]])], 515 gl_threads_api='isoc+posix'
138 [gl_cv_have_weak=yes], 516 AC_DEFINE([USE_ISOC_AND_POSIX_THREADS], [1],
139 [gl_cv_have_weak=no], 517 [Define if the combination of the ISO C and POSIX multithreading APIs can be used.])
140 [dnl When cross-compiling, assume that only ELF platforms support 518 LIBTHREAD= LTLIBTHREAD=
141 dnl weak symbols.
142 AC_EGREP_CPP([Extensible Linking Format],
143 [#ifdef __ELF__
144 Extensible Linking Format
145 #endif
146 ],
147 [gl_cv_have_weak="guessing yes"],
148 [gl_cv_have_weak="guessing no"])
149 ])
150 fi
151 ])
152 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
153 # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
154 # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.
155 AC_CHECK_HEADER([pthread.h],
156 [gl_have_pthread_h=yes], [gl_have_pthread_h=no])
157 if test "$gl_have_pthread_h" = yes; then
158 # Other possible tests:
159 # -lpthreads (FSU threads, PCthreads)
160 # -lgthreads
161 gl_have_pthread=
162 # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
163 # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
164 # the second one only in libpthread, and lock.c needs it.
165 AC_LINK_IFELSE(
166 [AC_LANG_PROGRAM(
167 [[#include <pthread.h>]],
168 [[pthread_mutex_lock((pthread_mutex_t*)0);
169 pthread_mutexattr_init((pthread_mutexattr_t*)0);]])],
170 [gl_have_pthread=yes])
171 # Test for libpthread by looking for pthread_kill. (Not pthread_self,
172 # since it is defined as a macro on OSF/1.)
173 if test -n "$gl_have_pthread"; then
174 # The program links fine without libpthread. But it may actually
175 # need to link with libpthread in order to create multiple threads.
176 AC_CHECK_LIB([pthread], [pthread_kill],
177 [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread
178 # On Solaris and HP-UX, most pthread functions exist also in libc.
179 # Therefore pthread_in_use() needs to actually try to create a
180 # thread: pthread_create from libc will fail, whereas
181 # pthread_create will actually create a thread.
182 case "$host_os" in
183 solaris* | hpux*)
184 AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
185 [Define if the pthread_in_use() detection is hard.])
186 esac
187 ])
188 else 519 else
189 # Some library is needed. Try libpthread and libc_r.
190 AC_CHECK_LIB([pthread], [pthread_kill],
191 [gl_have_pthread=yes
192 LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread
193 LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread])
194 if test -z "$gl_have_pthread"; then
195 # For FreeBSD 4.
196 AC_CHECK_LIB([c_r], [pthread_kill],
197 [gl_have_pthread=yes
198 LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r
199 LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r])
200 fi
201 fi
202 if test -n "$gl_have_pthread"; then
203 gl_threads_api=posix 520 gl_threads_api=posix
204 AC_DEFINE([USE_POSIX_THREADS], [1], 521 AC_DEFINE([USE_POSIX_THREADS], [1],
205 [Define if the POSIX multithreading library can be used.]) 522 [Define if the POSIX multithreading library can be used.])
206 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then 523 if test -z "$LIBMULTITHREAD" && test -z "$LTLIBMULTITHREAD"; then
524 AC_DEFINE([USE_POSIX_THREADS_FROM_LIBC], [1],
525 [Define if references to the POSIX multithreading library are satisfied by libc.])
526 else
207 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then 527 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
208 AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], 528 AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
209 [Define if references to the POSIX multithreading library should be made weak.]) 529 [Define if references to the POSIX multithreading library should be made weak.])
210 LIBTHREAD= 530 LIBTHREAD= LTLIBTHREAD=
211 LTLIBTHREAD= 531 else
532 case "$host_os" in
533 freebsd* | dragonfly* | midnightbsd*)
534 if test "x$LIBTHREAD" != "x$LIBMULTITHREAD"; then
535 dnl If weak symbols can't tell whether pthread_create(), pthread_key_create()
536 dnl etc. will succeed, we need a runtime test.
537 AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
538 [Define if the pthread_in_use() detection is hard.])
539 fi
540 ;;
541 esac
212 fi 542 fi
213 fi 543 fi
214 fi 544 fi
215 fi 545 fi
216 fi 546 fi
217 if test -z "$gl_have_pthread"; then 547 if test $gl_threads_api = none; then
218 if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then 548 if test "$gl_use_threads" = isoc && test "$gl_have_isoc_threads" = yes; then
219 gl_have_solaristhread= 549 gl_STDTHREADLIB_BODY
220 gl_save_LIBS="$LIBS" 550 LIBTHREAD=$LIBSTDTHREAD LTLIBTHREAD=$LIBSTDTHREAD
221 LIBS="$LIBS -lthread" 551 LIBMULTITHREAD=$LIBSTDTHREAD LTLIBMULTITHREAD=$LIBSTDTHREAD
222 AC_LINK_IFELSE( 552 gl_threads_api=isoc
223 [AC_LANG_PROGRAM( 553 AC_DEFINE([USE_ISOC_THREADS], [1],
224 [[ 554 [Define if the ISO C multithreading library can be used.])
225#include <thread.h>
226#include <synch.h>
227 ]],
228 [[thr_self();]])],
229 [gl_have_solaristhread=yes])
230 LIBS="$gl_save_LIBS"
231 if test -n "$gl_have_solaristhread"; then
232 gl_threads_api=solaris
233 LIBTHREAD=-lthread
234 LTLIBTHREAD=-lthread
235 LIBMULTITHREAD="$LIBTHREAD"
236 LTLIBMULTITHREAD="$LTLIBTHREAD"
237 AC_DEFINE([USE_SOLARIS_THREADS], [1],
238 [Define if the old Solaris multithreading library can be used.])
239 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
240 AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1],
241 [Define if references to the old Solaris multithreading library should be made weak.])
242 LIBTHREAD=
243 LTLIBTHREAD=
244 fi
245 fi
246 fi 555 fi
247 fi 556 fi
248 if test "$gl_use_threads" = pth; then 557 if test $gl_threads_api = none; then
249 gl_save_CPPFLAGS="$CPPFLAGS"
250 AC_LIB_LINKFLAGS([pth])
251 gl_have_pth=
252 gl_save_LIBS="$LIBS"
253 LIBS="$LIBS $LIBPTH"
254 AC_LINK_IFELSE(
255 [AC_LANG_PROGRAM([[#include <pth.h>]], [[pth_self();]])],
256 [gl_have_pth=yes])
257 LIBS="$gl_save_LIBS"
258 if test -n "$gl_have_pth"; then
259 gl_threads_api=pth
260 LIBTHREAD="$LIBPTH"
261 LTLIBTHREAD="$LTLIBPTH"
262 LIBMULTITHREAD="$LIBTHREAD"
263 LTLIBMULTITHREAD="$LTLIBTHREAD"
264 AC_DEFINE([USE_PTH_THREADS], [1],
265 [Define if the GNU Pth multithreading library can be used.])
266 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
267 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
268 AC_DEFINE([USE_PTH_THREADS_WEAK], [1],
269 [Define if references to the GNU Pth multithreading library should be made weak.])
270 LIBTHREAD=
271 LTLIBTHREAD=
272 fi
273 fi
274 else
275 CPPFLAGS="$gl_save_CPPFLAGS"
276 fi
277 fi
278 if test -z "$gl_have_pthread"; then
279 case "$gl_use_threads" in 558 case "$gl_use_threads" in
280 yes | windows | win32) # The 'win32' is for backward compatibility. 559 yes | windows | win32) # The 'win32' is for backward compatibility.
281 if { case "$host_os" in 560 if { case "$host_os" in
@@ -317,6 +596,21 @@ AC_DEFUN([gl_DISABLE_THREADS], [
317]) 596])
318 597
319 598
599dnl gl_AVOID_WINPTHREAD
600dnl -------------------
601dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the
602dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided.
603dnl The user can still override it at installation time, by using the
604dnl configure option '--enable-threads'.
605
606AC_DEFUN([gl_AVOID_WINPTHREAD], [
607 m4_divert_text([INIT_PREPARE], [gl_use_winpthreads_default=no])
608])
609
610
611dnl ============================================================================
612
613
320dnl Survey of platforms: 614dnl Survey of platforms:
321dnl 615dnl
322dnl Platform Available Compiler Supports test-lock 616dnl Platform Available Compiler Supports test-lock
@@ -324,7 +618,11 @@ dnl flavours option weak result
324dnl --------------- --------- --------- -------- --------- 618dnl --------------- --------- --------- -------- ---------
325dnl Linux 2.4/glibc posix -lpthread Y OK 619dnl Linux 2.4/glibc posix -lpthread Y OK
326dnl 620dnl
327dnl GNU Hurd/glibc posix 621dnl Linux/glibc 2.34 posix Y OK
622dnl
623dnl GNU Hurd/glibc posix -lpthread Y OK
624dnl
625dnl Ubuntu 14.04 posix -pthread Y OK
328dnl 626dnl
329dnl FreeBSD 5.3 posix -lc_r Y 627dnl FreeBSD 5.3 posix -lc_r Y
330dnl posix -lkse ? Y 628dnl posix -lkse ? Y
@@ -344,7 +642,6 @@ dnl
344dnl Mac OS X 10.[123] posix -lpthread Y OK 642dnl Mac OS X 10.[123] posix -lpthread Y OK
345dnl 643dnl
346dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK 644dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK
347dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK
348dnl 645dnl
349dnl HP-UX 11 posix -lpthread N (cc) OK 646dnl HP-UX 11 posix -lpthread N (cc) OK
350dnl Y (gcc) 647dnl Y (gcc)
@@ -358,8 +655,6 @@ dnl -lpthread (gcc) Y
358dnl 655dnl
359dnl Cygwin posix -lpthread Y OK 656dnl Cygwin posix -lpthread Y OK
360dnl 657dnl
361dnl Any of the above pth -lpth 0.0
362dnl
363dnl Mingw windows N OK 658dnl Mingw windows N OK
364dnl 659dnl
365dnl BeOS 5 -- 660dnl BeOS 5 --
diff --git a/gl/m4/time_h.m4 b/gl/m4/time_h.m4
index 3b83900..f6bf3a4 100644
--- a/gl/m4/time_h.m4
+++ b/gl/m4/time_h.m4
@@ -1,8 +1,8 @@
1# Configure a more-standard replacement for <time.h>. 1# Configure a more-standard replacement for <time.h>.
2 2
3# Copyright (C) 2000-2001, 2003-2007, 2009-2013 Free Software Foundation, Inc. 3# Copyright (C) 2000-2001, 2003-2007, 2009-2023 Free Software Foundation, Inc.
4 4
5# serial 7 5# serial 20
6 6
7# This file is free software; the Free Software Foundation 7# This file is free software; the Free Software Foundation
8# gives unlimited permission to copy and/or distribute it, 8# gives unlimited permission to copy and/or distribute it,
@@ -10,23 +10,42 @@
10 10
11# Written by Paul Eggert and Jim Meyering. 11# Written by Paul Eggert and Jim Meyering.
12 12
13AC_DEFUN([gl_HEADER_TIME_H], 13AC_DEFUN_ONCE([gl_TIME_H],
14[ 14[
15 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 15 dnl Ensure to expand the default settings once only, before all statements
16 dnl once only, before all statements that occur in other macros. 16 dnl that occur in other macros.
17 AC_REQUIRE([gl_HEADER_TIME_H_BODY]) 17 AC_REQUIRE([gl_TIME_H_DEFAULTS])
18])
19 18
20AC_DEFUN([gl_HEADER_TIME_H_BODY],
21[
22 AC_REQUIRE([AC_C_RESTRICT])
23 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
24 gl_NEXT_HEADERS([time.h]) 19 gl_NEXT_HEADERS([time.h])
25 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) 20 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
21
22 dnl Check for declarations of anything we want to poison if the
23 dnl corresponding gnulib module is not in use.
24 gl_WARN_ON_USE_PREPARE([[
25#include <time.h>
26 ]], [asctime_r ctime_r])
27
28 AC_REQUIRE([AC_C_RESTRICT])
29
30 AC_CACHE_CHECK([for TIME_UTC in <time.h>],
31 [gl_cv_time_h_has_TIME_UTC],
32 [AC_COMPILE_IFELSE(
33 [AC_LANG_PROGRAM(
34 [[#include <time.h>
35 ]],
36 [[static int x = TIME_UTC; x++;]])],
37 [gl_cv_time_h_has_TIME_UTC=yes],
38 [gl_cv_time_h_has_TIME_UTC=no])])
39 if test $gl_cv_time_h_has_TIME_UTC = yes; then
40 TIME_H_DEFINES_TIME_UTC=1
41 else
42 TIME_H_DEFINES_TIME_UTC=0
43 fi
44 AC_SUBST([TIME_H_DEFINES_TIME_UTC])
26]) 45])
27 46
28dnl Check whether 'struct timespec' is declared 47dnl Check whether 'struct timespec' is declared
29dnl in time.h, sys/time.h, or pthread.h. 48dnl in time.h, sys/time.h, pthread.h, or unistd.h.
30 49
31AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], 50AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
32[ 51[
@@ -44,6 +63,7 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
44 TIME_H_DEFINES_STRUCT_TIMESPEC=0 63 TIME_H_DEFINES_STRUCT_TIMESPEC=0
45 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 64 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
46 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 65 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
66 UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
47 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then 67 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
48 TIME_H_DEFINES_STRUCT_TIMESPEC=1 68 TIME_H_DEFINES_STRUCT_TIMESPEC=1
49 else 69 else
@@ -70,40 +90,94 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
70 [gl_cv_sys_struct_timespec_in_pthread_h=no])]) 90 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
71 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then 91 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
72 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 92 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
93 else
94 AC_CACHE_CHECK([for struct timespec in <unistd.h>],
95 [gl_cv_sys_struct_timespec_in_unistd_h],
96 [AC_COMPILE_IFELSE(
97 [AC_LANG_PROGRAM(
98 [[#include <unistd.h>
99 ]],
100 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
101 [gl_cv_sys_struct_timespec_in_unistd_h=yes],
102 [gl_cv_sys_struct_timespec_in_unistd_h=no])])
103 if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
104 UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
105 fi
73 fi 106 fi
74 fi 107 fi
75 fi 108 fi
76 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) 109 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
77 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) 110 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
78 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) 111 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
112 AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
79]) 113])
80 114
115# gl_TIME_MODULE_INDICATOR([modulename])
116# sets the shell variable that indicates the presence of the given module
117# to a C preprocessor expression that will evaluate to 1.
118# This macro invocation must not occur in macros that are AC_REQUIREd.
81AC_DEFUN([gl_TIME_MODULE_INDICATOR], 119AC_DEFUN([gl_TIME_MODULE_INDICATOR],
82[ 120[
83 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 121 dnl Ensure to expand the default settings once only.
84 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 122 gl_TIME_H_REQUIRE_DEFAULTS
85 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 123 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
86 dnl Define it also as a C macro, for the benefit of the unit tests. 124 dnl Define it also as a C macro, for the benefit of the unit tests.
87 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 125 gl_MODULE_INDICATOR_FOR_TESTS([$1])
88]) 126])
89 127
90AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], 128# Initializes the default values for AC_SUBSTed shell variables.
129# This macro must not be AC_REQUIREd. It must only be invoked, and only
130# outside of macros or in macros that are not AC_REQUIREd.
131AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS],
132[
133 m4_defun(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS], [
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CTIME])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKTIME])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALTIME])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NANOSLEEP])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRFTIME])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPTIME])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMEGM])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GET])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GETRES])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET])
146 dnl Support Microsoft deprecated alias function names by default.
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1])
148 ])
149 m4_require(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS])
150 AC_REQUIRE([gl_TIME_H_DEFAULTS])
151])
152
153AC_DEFUN([gl_TIME_H_DEFAULTS],
91[ 154[
92 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
93 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
94 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
95 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
96 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
97 dnl Assume proper GNU behavior unless another module says otherwise. 155 dnl Assume proper GNU behavior unless another module says otherwise.
98 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) 156 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
99 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) 157 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
100 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) 158 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
101 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) 159 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
160 HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET])
161 HAVE_TIMESPEC_GETRES=1; AC_SUBST([HAVE_TIMESPEC_GETRES])
162 dnl Even GNU libc does not have timezone_t yet.
163 HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
102 dnl If another module says to replace or to not replace, do that. 164 dnl If another module says to replace or to not replace, do that.
103 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; 165 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
104 dnl this lets maintainers check for portability. 166 dnl this lets maintainers check for portability.
167 REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME])
105 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) 168 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
106 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) 169 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
107 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) 170 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
171 REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME])
108 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) 172 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
173 REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET])
174
175 dnl Hack so that the time module doesn't depend on the sys_time module.
176 dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
177 : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY])
178 dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
179 dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
180 dnl is no longer a big deal.
181 REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME])
182 REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME])
109]) 183])
diff --git a/gl/m4/time_r.m4 b/gl/m4/time_r.m4
index c388a83..adce438 100644
--- a/gl/m4/time_r.m4
+++ b/gl/m4/time_r.m4
@@ -1,6 +1,6 @@
1dnl Reentrant time functions: localtime_r, gmtime_r. 1dnl Reentrant time functions: localtime_r, gmtime_r.
2 2
3dnl Copyright (C) 2003, 2006-2013 Free Software Foundation, Inc. 3dnl Copyright (C) 2003, 2006-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -12,12 +12,20 @@ AC_DEFUN([gl_TIME_R],
12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r. 12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 14
15 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 15 AC_REQUIRE([gl_TIME_H_DEFAULTS])
16 AC_REQUIRE([AC_C_RESTRICT]) 16 AC_REQUIRE([AC_C_RESTRICT])
17 17
18 dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is 18 dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
19 dnl not defined. 19 dnl not defined.
20 AC_CHECK_DECLS([localtime_r], [], [], [[#include <time.h>]]) 20 AC_CHECK_DECLS([localtime_r], [], [],
21 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
22 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
23 been included before. */
24 #if defined __MINGW32__
25 # include <unistd.h>
26 #endif
27 #include <time.h>
28 ]])
21 if test $ac_cv_have_decl_localtime_r = no; then 29 if test $ac_cv_have_decl_localtime_r = no; then
22 HAVE_DECL_LOCALTIME_R=0 30 HAVE_DECL_LOCALTIME_R=0
23 fi 31 fi
@@ -29,7 +37,14 @@ AC_DEFUN([gl_TIME_R],
29 [gl_cv_time_r_posix], 37 [gl_cv_time_r_posix],
30 [AC_COMPILE_IFELSE( 38 [AC_COMPILE_IFELSE(
31 [AC_LANG_PROGRAM( 39 [AC_LANG_PROGRAM(
32 [[#include <time.h>]], 40 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
41 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
42 been included before. */
43 #if defined __MINGW32__
44 # include <unistd.h>
45 #endif
46 #include <time.h>
47 ]],
33 [[/* We don't need to append 'restrict's to the argument types, 48 [[/* We don't need to append 'restrict's to the argument types,
34 even though the POSIX signature has the 'restrict's, 49 even though the POSIX signature has the 'restrict's,
35 since C99 says they can't affect type compatibility. */ 50 since C99 says they can't affect type compatibility. */
@@ -49,6 +64,32 @@ AC_DEFUN([gl_TIME_R],
49 fi 64 fi
50 else 65 else
51 HAVE_LOCALTIME_R=0 66 HAVE_LOCALTIME_R=0
67 dnl On mingw, localtime_r() is defined as an inline function; use through a
68 dnl direct function call works but the use as a function pointer leads to a
69 dnl link error.
70 AC_CACHE_CHECK([whether localtime_r exists as an inline function],
71 [gl_cv_func_localtime_r_inline],
72 [AC_LINK_IFELSE(
73 [AC_LANG_PROGRAM(
74 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
75 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
76 been included before. */
77 #if defined __MINGW32__
78 # include <unistd.h>
79 #endif
80 #include <time.h>
81 ]],
82 [[time_t a;
83 struct tm r;
84 localtime_r (&a, &r);
85 ]])
86 ],
87 [gl_cv_func_localtime_r_inline=yes],
88 [gl_cv_func_localtime_r_inline=no])
89 ])
90 if test $gl_cv_func_localtime_r_inline = yes; then
91 REPLACE_LOCALTIME_R=1
92 fi
52 fi 93 fi
53]) 94])
54 95
diff --git a/gl/m4/timegm.m4 b/gl/m4/timegm.m4
index 997953c..6079f1a 100644
--- a/gl/m4/timegm.m4
+++ b/gl/m4/timegm.m4
@@ -1,17 +1,17 @@
1# timegm.m4 serial 11 1# timegm.m4 serial 13
2dnl Copyright (C) 2003, 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007, 2009-2023 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_TIMEGM], 7AC_DEFUN([gl_FUNC_TIMEGM],
8[ 8[
9 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 9 AC_REQUIRE([gl_TIME_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_MKTIME]) 10 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
11 REPLACE_TIMEGM=0 11 REPLACE_TIMEGM=0
12 AC_CHECK_FUNCS_ONCE([timegm]) 12 AC_CHECK_FUNCS_ONCE([timegm])
13 if test $ac_cv_func_timegm = yes; then 13 if test $ac_cv_func_timegm = yes; then
14 if test $gl_cv_func_working_mktime = no; then 14 if test "$gl_cv_func_working_mktime" != yes; then
15 # Assume that timegm is buggy if mktime is. 15 # Assume that timegm is buggy if mktime is.
16 REPLACE_TIMEGM=1 16 REPLACE_TIMEGM=1
17 fi 17 fi
diff --git a/gl/m4/uintmax_t.m4 b/gl/m4/uintmax_t.m4
deleted file mode 100644
index c6ff800..0000000
--- a/gl/m4/uintmax_t.m4
+++ /dev/null
@@ -1,30 +0,0 @@
1# uintmax_t.m4 serial 12
2dnl Copyright (C) 1997-2004, 2007-2013 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
9AC_PREREQ([2.13])
10
11# Define uintmax_t to 'unsigned long' or 'unsigned long long'
12# if it is not already defined in <stdint.h> or <inttypes.h>.
13
14AC_DEFUN([gl_AC_TYPE_UINTMAX_T],
15[
16 AC_REQUIRE([gl_AC_HEADER_INTTYPES_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
19 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
20 test $ac_cv_type_unsigned_long_long_int = yes \
21 && ac_type='unsigned long long' \
22 || ac_type='unsigned long'
23 AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
24 [Define to unsigned long or unsigned long long
25 if <stdint.h> and <inttypes.h> don't define.])
26 else
27 AC_DEFINE([HAVE_UINTMAX_T], [1],
28 [Define if you have the 'uintmax_t' type in <stdint.h> or <inttypes.h>.])
29 fi
30])
diff --git a/gl/m4/ungetc.m4 b/gl/m4/ungetc.m4
new file mode 100644
index 0000000..8977a34
--- /dev/null
+++ b/gl/m4/ungetc.m4
@@ -0,0 +1,73 @@
1# ungetc.m4 serial 10
2dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS],
8[
9 AC_REQUIRE([AC_PROG_CC])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11
12 AC_CACHE_CHECK([whether ungetc works on arbitrary bytes],
13 [gl_cv_func_ungetc_works],
14 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
15#include <stdio.h>
16 ]], [[FILE *f;
17 if (!(f = fopen ("conftest.tmp", "w+")))
18 return 1;
19 if (fputs ("abc", f) < 0)
20 { fclose (f); return 2; }
21 rewind (f);
22 if (fgetc (f) != 'a')
23 { fclose (f); return 3; }
24 if (fgetc (f) != 'b')
25 { fclose (f); return 4; }
26 if (ungetc ('d', f) != 'd')
27 { fclose (f); return 5; }
28 if (ftell (f) != 1)
29 { fclose (f); return 6; }
30 if (fgetc (f) != 'd')
31 { fclose (f); return 7; }
32 if (ftell (f) != 2)
33 { fclose (f); return 8; }
34 if (fseek (f, 0, SEEK_CUR) != 0)
35 { fclose (f); return 9; }
36 if (ftell (f) != 2)
37 { fclose (f); return 10; }
38 if (fgetc (f) != 'c')
39 { fclose (f); return 11; }
40 fclose (f);
41 remove ("conftest.tmp");
42 ]])],
43 [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
44 [case "$host_os" in
45 # Guess yes on glibc systems.
46 *-gnu* | gnu*) gl_cv_func_ungetc_works="guessing yes" ;;
47 # Guess yes on musl systems.
48 *-musl*) gl_cv_func_ungetc_works="guessing yes" ;;
49 # Guess yes on bionic systems.
50 *-android*) gl_cv_func_ungetc_works="guessing yes" ;;
51 # Guess yes on native Windows.
52 mingw*) gl_cv_func_ungetc_works="guessing yes" ;;
53 # If we don't know, obey --enable-cross-guesses.
54 *) gl_cv_func_ungetc_works="$gl_cross_guess_normal" ;;
55 esac
56 ])
57 ])
58 gl_ftello_broken_after_ungetc=no
59 case "$gl_cv_func_ungetc_works" in
60 *yes) ;;
61 *)
62 dnl On macOS >= 10.15, where the above program fails with exit code 6,
63 dnl we fix it through an ftello override.
64 case "$host_os" in
65 darwin*) gl_ftello_broken_after_ungetc=yes ;;
66 *)
67 AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
68 [Define to 1 if ungetc is broken when used on arbitrary bytes.])
69 ;;
70 esac
71 ;;
72 esac
73])
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4
index 32dcfa5..f438402 100644
--- a/gl/m4/unistd_h.m4
+++ b/gl/m4/unistd_h.m4
@@ -1,15 +1,15 @@
1# unistd_h.m4 serial 66 1# unistd_h.m4 serial 90
2dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2023 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, Bruno Haible. 7dnl Written by Simon Josefsson, Bruno Haible.
8 8
9AC_DEFUN([gl_UNISTD_H], 9AC_DEFUN_ONCE([gl_UNISTD_H],
10[ 10[
11 dnl Use AC_REQUIRE here, so that the default behavior below is expanded 11 dnl Ensure to expand the default settings once only, before all statements
12 dnl once only, before all statements that occur in other macros. 12 dnl that occur in other macros.
13 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 13 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
14 14
15 gl_CHECK_NEXT_HEADERS([unistd.h]) 15 gl_CHECK_NEXT_HEADERS([unistd.h])
@@ -37,150 +37,234 @@ AC_DEFUN([gl_UNISTD_H],
37# include <fcntl.h> 37# include <fcntl.h>
38# include <stdio.h> 38# include <stdio.h>
39# include <stdlib.h> 39# include <stdlib.h>
40# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 40# if defined _WIN32 && ! defined __CYGWIN__
41# include <io.h> 41# include <io.h>
42# endif 42# endif
43#endif 43#endif
44 ]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat 44 ]], [access chdir chown copy_file_range dup dup2 dup3 environ euidaccess
45 fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups 45 execl execle execlp execv execve execvp execvpe
46 gethostname getlogin getlogin_r getpagesize 46 faccessat fchdir
47 fchownat fdatasync fsync ftruncate getcwd getdomainname getdtablesize
48 getentropy getgroups gethostname getlogin getlogin_r getpagesize getpass
47 getusershell setusershell endusershell 49 getusershell setusershell endusershell
48 group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite 50 group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite
49 readlink readlinkat rmdir sethostname sleep symlink symlinkat ttyname_r 51 readlink readlinkat rmdir sethostname sleep symlink symlinkat
50 unlink unlinkat usleep]) 52 truncate ttyname_r unlink unlinkat usleep])
53
54 AC_REQUIRE([AC_C_RESTRICT])
55
56 AC_CHECK_DECLS_ONCE([execvpe])
57 if test $ac_cv_have_decl_execvpe = no; then
58 HAVE_DECL_EXECVPE=0
59 fi
51]) 60])
52 61
62# gl_UNISTD_MODULE_INDICATOR([modulename])
63# sets the shell variable that indicates the presence of the given module
64# to a C preprocessor expression that will evaluate to 1.
65# This macro invocation must not occur in macros that are AC_REQUIREd.
53AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], 66AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
54[ 67[
55 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 68 dnl Ensure to expand the default settings once only.
56 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 69 gl_UNISTD_H_REQUIRE_DEFAULTS
57 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 70 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
58 dnl Define it also as a C macro, for the benefit of the unit tests. 71 dnl Define it also as a C macro, for the benefit of the unit tests.
59 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 72 gl_MODULE_INDICATOR_FOR_TESTS([$1])
60]) 73])
61 74
75# Initializes the default values for AC_SUBSTed shell variables.
76# This macro must not be AC_REQUIREd. It must only be invoked, and only
77# outside of macros or in macros that are not AC_REQUIREd.
78AC_DEFUN([gl_UNISTD_H_REQUIRE_DEFAULTS],
79[
80 m4_defun(GL_MODULE_INDICATOR_PREFIX[_UNISTD_H_MODULE_INDICATOR_DEFAULTS], [
81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCESS])
82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CHDIR])
83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CHOWN])
84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CLOSE])
85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_COPY_FILE_RANGE])
86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DUP])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DUP2])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DUP3])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ENVIRON])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EUIDACCESS])
91 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECL])
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECLE])
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECLP])
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECV])
95 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECVE])
96 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECVP])
97 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXECVPE])
98 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FACCESSAT])
99 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCHDIR])
100 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCHOWNAT])
101 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDATASYNC])
102 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSYNC])
103 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTRUNCATE])
104 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETCWD])
105 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDOMAINNAME])
106 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDTABLESIZE])
107 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETENTROPY])
108 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETGROUPS])
109 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETHOSTNAME])
110 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOGIN])
111 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOGIN_R])
112 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETOPT_POSIX])
113 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPAGESIZE])
114 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPASS])
115 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPASS_GNU])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETUSERSHELL])
117 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GROUP_MEMBER])
118 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISATTY])
119 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LCHOWN])
120 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LINK])
121 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LINKAT])
122 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LSEEK])
123 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PIPE])
124 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PIPE2])
125 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PREAD])
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PWRITE])
127 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_READ])
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_READLINK])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_READLINKAT])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RMDIR])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETHOSTNAME])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SLEEP])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SYMLINK])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SYMLINKAT])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCATE])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TTYNAME_R])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_GETOPT])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_NONBLOCKING])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_SIGPIPE])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNLINK])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNLINKAT])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_USLEEP])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WRITE])
144 dnl Support Microsoft deprecated alias function names by default.
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_ACCESS], [1])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CHDIR], [1])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CLOSE], [1])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_DUP], [1])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_DUP2], [1])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECL], [1])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECLE], [1])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECLP], [1])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECV], [1])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECVE], [1])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECVP], [1])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECVPE], [1])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETCWD], [1])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETPID], [1])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_ISATTY], [1])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_LSEEK], [1])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_READ], [1])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_RMDIR], [1])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_SWAB], [1])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_UNLINK], [1])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WRITE], [1])
166 ])
167 m4_require(GL_MODULE_INDICATOR_PREFIX[_UNISTD_H_MODULE_INDICATOR_DEFAULTS])
168 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
169])
170
62AC_DEFUN([gl_UNISTD_H_DEFAULTS], 171AC_DEFUN([gl_UNISTD_H_DEFAULTS],
63[ 172[
64 GNULIB_CHDIR=0; AC_SUBST([GNULIB_CHDIR])
65 GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN])
66 GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE])
67 GNULIB_DUP=0; AC_SUBST([GNULIB_DUP])
68 GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2])
69 GNULIB_DUP3=0; AC_SUBST([GNULIB_DUP3])
70 GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON])
71 GNULIB_EUIDACCESS=0; AC_SUBST([GNULIB_EUIDACCESS])
72 GNULIB_FACCESSAT=0; AC_SUBST([GNULIB_FACCESSAT])
73 GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR])
74 GNULIB_FCHOWNAT=0; AC_SUBST([GNULIB_FCHOWNAT])
75 GNULIB_FDATASYNC=0; AC_SUBST([GNULIB_FDATASYNC])
76 GNULIB_FSYNC=0; AC_SUBST([GNULIB_FSYNC])
77 GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE])
78 GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
79 GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME])
80 GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE])
81 GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS])
82 GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME])
83 GNULIB_GETLOGIN=0; AC_SUBST([GNULIB_GETLOGIN])
84 GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
85 GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE])
86 GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL])
87 GNULIB_GROUP_MEMBER=0; AC_SUBST([GNULIB_GROUP_MEMBER])
88 GNULIB_ISATTY=0; AC_SUBST([GNULIB_ISATTY])
89 GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN])
90 GNULIB_LINK=0; AC_SUBST([GNULIB_LINK])
91 GNULIB_LINKAT=0; AC_SUBST([GNULIB_LINKAT])
92 GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK])
93 GNULIB_PIPE=0; AC_SUBST([GNULIB_PIPE])
94 GNULIB_PIPE2=0; AC_SUBST([GNULIB_PIPE2])
95 GNULIB_PREAD=0; AC_SUBST([GNULIB_PREAD])
96 GNULIB_PWRITE=0; AC_SUBST([GNULIB_PWRITE])
97 GNULIB_READ=0; AC_SUBST([GNULIB_READ])
98 GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
99 GNULIB_READLINKAT=0; AC_SUBST([GNULIB_READLINKAT])
100 GNULIB_RMDIR=0; AC_SUBST([GNULIB_RMDIR])
101 GNULIB_SETHOSTNAME=0; AC_SUBST([GNULIB_SETHOSTNAME])
102 GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
103 GNULIB_SYMLINK=0; AC_SUBST([GNULIB_SYMLINK])
104 GNULIB_SYMLINKAT=0; AC_SUBST([GNULIB_SYMLINKAT])
105 GNULIB_TTYNAME_R=0; AC_SUBST([GNULIB_TTYNAME_R])
106 GNULIB_UNISTD_H_NONBLOCKING=0; AC_SUBST([GNULIB_UNISTD_H_NONBLOCKING])
107 GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE])
108 GNULIB_UNLINK=0; AC_SUBST([GNULIB_UNLINK])
109 GNULIB_UNLINKAT=0; AC_SUBST([GNULIB_UNLINKAT])
110 GNULIB_USLEEP=0; AC_SUBST([GNULIB_USLEEP])
111 GNULIB_WRITE=0; AC_SUBST([GNULIB_WRITE])
112 dnl Assume proper GNU behavior unless another module says otherwise. 173 dnl Assume proper GNU behavior unless another module says otherwise.
113 HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN]) 174 HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN])
114 HAVE_DUP2=1; AC_SUBST([HAVE_DUP2]) 175 HAVE_COPY_FILE_RANGE=1; AC_SUBST([HAVE_COPY_FILE_RANGE])
115 HAVE_DUP3=1; AC_SUBST([HAVE_DUP3]) 176 HAVE_DUP3=1; AC_SUBST([HAVE_DUP3])
116 HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS]) 177 HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS])
117 HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT]) 178 HAVE_EXECVPE=1; AC_SUBST([HAVE_EXECVPE])
118 HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR]) 179 HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT])
119 HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT]) 180 HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR])
120 HAVE_FDATASYNC=1; AC_SUBST([HAVE_FDATASYNC]) 181 HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT])
121 HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC]) 182 HAVE_FDATASYNC=1; AC_SUBST([HAVE_FDATASYNC])
122 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) 183 HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC])
123 HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) 184 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
124 HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS]) 185 HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE])
125 HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) 186 HAVE_GETENTROPY=1; AC_SUBST([HAVE_GETENTROPY])
126 HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN]) 187 HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS])
127 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) 188 HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME])
128 HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER]) 189 HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN])
129 HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN]) 190 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
130 HAVE_LINK=1; AC_SUBST([HAVE_LINK]) 191 HAVE_GETPASS=1; AC_SUBST([HAVE_GETPASS])
131 HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT]) 192 HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER])
132 HAVE_PIPE=1; AC_SUBST([HAVE_PIPE]) 193 HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN])
133 HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2]) 194 HAVE_LINK=1; AC_SUBST([HAVE_LINK])
134 HAVE_PREAD=1; AC_SUBST([HAVE_PREAD]) 195 HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT])
135 HAVE_PWRITE=1; AC_SUBST([HAVE_PWRITE]) 196 HAVE_PIPE=1; AC_SUBST([HAVE_PIPE])
136 HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) 197 HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2])
137 HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT]) 198 HAVE_PREAD=1; AC_SUBST([HAVE_PREAD])
138 HAVE_SETHOSTNAME=1; AC_SUBST([HAVE_SETHOSTNAME]) 199 HAVE_PWRITE=1; AC_SUBST([HAVE_PWRITE])
139 HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) 200 HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
140 HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK]) 201 HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT])
141 HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT]) 202 HAVE_SETHOSTNAME=1; AC_SUBST([HAVE_SETHOSTNAME])
142 HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) 203 HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
143 HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) 204 HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK])
144 HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) 205 HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT])
145 HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR]) 206 HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT])
146 HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC]) 207 HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP])
147 HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME]) 208 HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON])
148 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) 209 HAVE_DECL_EXECVPE=1; AC_SUBST([HAVE_DECL_EXECVPE])
149 HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE]) 210 HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR])
150 HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL]) 211 HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC])
151 HAVE_DECL_SETHOSTNAME=1; AC_SUBST([HAVE_DECL_SETHOSTNAME]) 212 HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME])
152 HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R]) 213 HAVE_DECL_GETLOGIN=1; AC_SUBST([HAVE_DECL_GETLOGIN])
153 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) 214 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
154 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) 215 HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
155 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) 216 HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL])
156 REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) 217 HAVE_DECL_SETHOSTNAME=1; AC_SUBST([HAVE_DECL_SETHOSTNAME])
157 REPLACE_DUP=0; AC_SUBST([REPLACE_DUP]) 218 HAVE_DECL_TRUNCATE=1; AC_SUBST([HAVE_DECL_TRUNCATE])
158 REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2]) 219 HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R])
159 REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) 220 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H])
160 REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE]) 221 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H])
161 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) 222 REPLACE_ACCESS=0; AC_SUBST([REPLACE_ACCESS])
162 REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME]) 223 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
163 REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R]) 224 REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE])
164 REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS]) 225 REPLACE_COPY_FILE_RANGE=0; AC_SUBST([REPLACE_COPY_FILE_RANGE])
165 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) 226 REPLACE_DUP=0; AC_SUBST([REPLACE_DUP])
166 REPLACE_ISATTY=0; AC_SUBST([REPLACE_ISATTY]) 227 REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2])
167 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) 228 REPLACE_EXECL=0; AC_SUBST([REPLACE_EXECL])
168 REPLACE_LINK=0; AC_SUBST([REPLACE_LINK]) 229 REPLACE_EXECLE=0; AC_SUBST([REPLACE_EXECLE])
169 REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT]) 230 REPLACE_EXECLP=0; AC_SUBST([REPLACE_EXECLP])
170 REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) 231 REPLACE_EXECV=0; AC_SUBST([REPLACE_EXECV])
171 REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD]) 232 REPLACE_EXECVE=0; AC_SUBST([REPLACE_EXECVE])
172 REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE]) 233 REPLACE_EXECVP=0; AC_SUBST([REPLACE_EXECVP])
173 REPLACE_READ=0; AC_SUBST([REPLACE_READ]) 234 REPLACE_EXECVPE=0; AC_SUBST([REPLACE_EXECVPE])
174 REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK]) 235 REPLACE_FACCESSAT=0; AC_SUBST([REPLACE_FACCESSAT])
175 REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR]) 236 REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT])
176 REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP]) 237 REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE])
177 REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK]) 238 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
178 REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R]) 239 REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME])
179 REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK]) 240 REPLACE_GETDTABLESIZE=0; AC_SUBST([REPLACE_GETDTABLESIZE])
180 REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT]) 241 REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R])
181 REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP]) 242 REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS])
182 REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE]) 243 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
183 UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H]) 244 REPLACE_GETPASS=0; AC_SUBST([REPLACE_GETPASS])
245 REPLACE_GETPASS_FOR_GETPASS_GNU=0; AC_SUBST([REPLACE_GETPASS_FOR_GETPASS_GNU])
246 REPLACE_ISATTY=0; AC_SUBST([REPLACE_ISATTY])
247 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
248 REPLACE_LINK=0; AC_SUBST([REPLACE_LINK])
249 REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT])
250 REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
251 REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD])
252 REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE])
253 REPLACE_READ=0; AC_SUBST([REPLACE_READ])
254 REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK])
255 REPLACE_READLINKAT=0; AC_SUBST([REPLACE_READLINKAT])
256 REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR])
257 REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP])
258 REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK])
259 REPLACE_SYMLINKAT=0; AC_SUBST([REPLACE_SYMLINKAT])
260 REPLACE_TRUNCATE=0; AC_SUBST([REPLACE_TRUNCATE])
261 REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R])
262 REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK])
263 REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT])
264 REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP])
265 REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE])
266 UNISTD_H_HAVE_SYS_RANDOM_H=0; AC_SUBST([UNISTD_H_HAVE_SYS_RANDOM_H])
267 UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
184 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0; 268 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
185 AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS]) 269 AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
186]) 270])
diff --git a/gl/m4/unlocked-io.m4 b/gl/m4/unlocked-io.m4
new file mode 100644
index 0000000..407c0ba
--- /dev/null
+++ b/gl/m4/unlocked-io.m4
@@ -0,0 +1,36 @@
1# unlocked-io.m4 serial 16
2
3# Copyright (C) 1998-2006, 2009-2023 Free Software Foundation, Inc.
4#
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9dnl From Jim Meyering.
10dnl
11dnl See if the glibc *_unlocked I/O macros or functions are available.
12dnl Use only those *_unlocked macros or functions that are declared
13dnl (because some of them were declared in Solaris 2.5.1 but were removed
14dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run
15dnl on Solaris 2.6).
16
17AC_DEFUN([gl_FUNC_GLIBC_UNLOCKED_IO],
18[
19 dnl Persuade glibc and Solaris <stdio.h> to declare
20 dnl fgets_unlocked(), fputs_unlocked() etc.
21 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
22
23 AC_CHECK_DECLS_ONCE([clearerr_unlocked])
24 AC_CHECK_DECLS_ONCE([feof_unlocked])
25 AC_CHECK_DECLS_ONCE([ferror_unlocked])
26 AC_CHECK_DECLS_ONCE([fflush_unlocked])
27 AC_CHECK_DECLS_ONCE([fgets_unlocked])
28 AC_CHECK_DECLS_ONCE([fputc_unlocked])
29 AC_CHECK_DECLS_ONCE([fputs_unlocked])
30 AC_CHECK_DECLS_ONCE([fread_unlocked])
31 AC_CHECK_DECLS_ONCE([fwrite_unlocked])
32 AC_CHECK_DECLS_ONCE([getc_unlocked])
33 AC_CHECK_DECLS_ONCE([getchar_unlocked])
34 AC_CHECK_DECLS_ONCE([putc_unlocked])
35 AC_CHECK_DECLS_ONCE([putchar_unlocked])
36])
diff --git a/gl/m4/vararrays.m4 b/gl/m4/vararrays.m4
new file mode 100644
index 0000000..fd6230c
--- /dev/null
+++ b/gl/m4/vararrays.m4
@@ -0,0 +1,72 @@
1# Check for variable-length arrays.
2
3# serial 6
4
5# From Paul Eggert
6
7# Copyright (C) 2001, 2009-2023 Free Software Foundation, Inc.
8# This file is free software; the Free Software Foundation
9# gives unlimited permission to copy and/or distribute it,
10# with or without modifications, as long as this notice is preserved.
11
12m4_version_prereq([2.70], [], [
13
14# AC_C_VARARRAYS
15# --------------
16# Check whether the C compiler supports variable-length arrays.
17AC_DEFUN([AC_C_VARARRAYS],
18[
19 AC_CACHE_CHECK([for variable-length arrays],
20 ac_cv_c_vararrays,
21 [AC_EGREP_CPP([defined],
22 [#ifdef __STDC_NO_VLA__
23 defined
24 #endif
25 ],
26 [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
27 [AC_COMPILE_IFELSE(
28 [AC_LANG_PROGRAM(
29 [[/* Test for VLA support. This test is partly inspired
30 from examples in the C standard. Use at least two VLA
31 functions to detect the GCC 3.4.3 bug described in:
32 https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
33 */
34 #ifdef __STDC_NO_VLA__
35 syntax error;
36 #else
37 extern int n;
38 int B[100];
39 int fvla (int m, int C[m][m]);
40
41 int
42 simple (int count, int all[static count])
43 {
44 return all[count - 1];
45 }
46
47 int
48 fvla (int m, int C[m][m])
49 {
50 typedef int VLA[m][m];
51 VLA x;
52 int D[m];
53 static int (*q)[m] = &B;
54 int (*s)[n] = q;
55 return C && &x[0][0] == &D[0] && &D[0] == s[0];
56 }
57 #endif
58 ]])],
59 [ac_cv_c_vararrays=yes],
60 [ac_cv_c_vararrays=no])])])
61 if test "$ac_cv_c_vararrays" = yes; then
62 dnl This is for compatibility with Autoconf 2.61-2.69.
63 AC_DEFINE([HAVE_C_VARARRAYS], 1,
64 [Define to 1 if C supports variable-length arrays.])
65 elif test "$ac_cv_c_vararrays" = no; then
66 AC_DEFINE([__STDC_NO_VLA__], 1,
67 [Define to 1 if C does not support variable-length arrays, and
68 if the compiler does not already define this.])
69 fi
70])
71
72])
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index d730e43..6361c84 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,5 +1,5 @@
1# vasnprintf.m4 serial 36 1# vasnprintf.m4 serial 38
2dnl Copyright (C) 2002-2004, 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2006-2023 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,6 @@ AC_DEFUN([gl_REPLACE_VASNPRINTF],
32# Prerequisites of lib/printf-args.h, lib/printf-args.c. 32# Prerequisites of lib/printf-args.h, lib/printf-args.c.
33AC_DEFUN([gl_PREREQ_PRINTF_ARGS], 33AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
34[ 34[
35 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
36 AC_REQUIRE([gt_TYPE_WCHAR_T]) 35 AC_REQUIRE([gt_TYPE_WCHAR_T])
37 AC_REQUIRE([gt_TYPE_WINT_T]) 36 AC_REQUIRE([gt_TYPE_WINT_T])
38]) 37])
@@ -41,7 +40,6 @@ AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
41AC_DEFUN([gl_PREREQ_PRINTF_PARSE], 40AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
42[ 41[
43 AC_REQUIRE([gl_FEATURES_H]) 42 AC_REQUIRE([gl_FEATURES_H])
44 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
45 AC_REQUIRE([gt_TYPE_WCHAR_T]) 43 AC_REQUIRE([gt_TYPE_WCHAR_T])
46 AC_REQUIRE([gt_TYPE_WINT_T]) 44 AC_REQUIRE([gt_TYPE_WINT_T])
47 AC_REQUIRE([AC_TYPE_SIZE_T]) 45 AC_REQUIRE([AC_TYPE_SIZE_T])
@@ -56,7 +54,6 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
56AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], 54AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
57[ 55[
58 AC_REQUIRE([AC_FUNC_ALLOCA]) 56 AC_REQUIRE([AC_FUNC_ALLOCA])
59 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
60 AC_REQUIRE([gt_TYPE_WCHAR_T]) 57 AC_REQUIRE([gt_TYPE_WCHAR_T])
61 AC_REQUIRE([gt_TYPE_WINT_T]) 58 AC_REQUIRE([gt_TYPE_WINT_T])
62 AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb]) 59 AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
@@ -77,6 +74,16 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
77 if the buffer had been large enough.]) 74 if the buffer had been large enough.])
78 ;; 75 ;;
79 esac 76 esac
77 dnl Additionally, the use of %n can be eliminated by assuming that snprintf
78 dnl always produces NUL-terminated strings (no truncation).
79 AC_REQUIRE([gl_SNPRINTF_TRUNCATION_C99])
80 case "$gl_cv_func_snprintf_truncation_c99" in
81 *yes)
82 AC_DEFINE([HAVE_SNPRINTF_TRUNCATION_C99], [1],
83 [Define if the string produced by the snprintf function is always NUL
84 terminated.])
85 ;;
86 esac
80]) 87])
81 88
82# Extra prerequisites of lib/vasnprintf.c for supporting 'long double' 89# Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
diff --git a/gl/m4/vasprintf.m4 b/gl/m4/vasprintf.m4
index c214ff1..6e6156a 100644
--- a/gl/m4/vasprintf.m4
+++ b/gl/m4/vasprintf.m4
@@ -1,5 +1,5 @@
1# vasprintf.m4 serial 6 1# vasprintf.m4 serial 6
2dnl Copyright (C) 2002-2003, 2006-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2002-2003, 2006-2007, 2009-2023 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
diff --git a/gl/m4/visibility.m4 b/gl/m4/visibility.m4
index 6cbd7e5..f0468e8 100644
--- a/gl/m4/visibility.m4
+++ b/gl/m4/visibility.m4
@@ -1,5 +1,5 @@
1# visibility.m4 serial 5 (gettext-0.18.2) 1# visibility.m4 serial 8
2dnl Copyright (C) 2005, 2008, 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005, 2008, 2010-2023 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.
@@ -29,42 +29,47 @@ AC_DEFUN([gl_VISIBILITY],
29 dnl First, check whether -Werror can be added to the command line, or 29 dnl First, check whether -Werror can be added to the command line, or
30 dnl whether it leads to an error because of some other option that the 30 dnl whether it leads to an error because of some other option that the
31 dnl user has put into $CC $CFLAGS $CPPFLAGS. 31 dnl user has put into $CC $CFLAGS $CPPFLAGS.
32 AC_MSG_CHECKING([whether the -Werror option is usable]) 32 AC_CACHE_CHECK([whether the -Werror option is usable],
33 AC_CACHE_VAL([gl_cv_cc_vis_werror], [ 33 [gl_cv_cc_vis_werror],
34 gl_save_CFLAGS="$CFLAGS" 34 [gl_save_CFLAGS="$CFLAGS"
35 CFLAGS="$CFLAGS -Werror" 35 CFLAGS="$CFLAGS -Werror"
36 AC_COMPILE_IFELSE( 36 AC_COMPILE_IFELSE(
37 [AC_LANG_PROGRAM([[]], [[]])], 37 [AC_LANG_PROGRAM([[]], [[]])],
38 [gl_cv_cc_vis_werror=yes], 38 [gl_cv_cc_vis_werror=yes],
39 [gl_cv_cc_vis_werror=no]) 39 [gl_cv_cc_vis_werror=no])
40 CFLAGS="$gl_save_CFLAGS"]) 40 CFLAGS="$gl_save_CFLAGS"
41 AC_MSG_RESULT([$gl_cv_cc_vis_werror]) 41 ])
42 dnl Now check whether visibility declarations are supported. 42 dnl Now check whether visibility declarations are supported.
43 AC_MSG_CHECKING([for simple visibility declarations]) 43 AC_CACHE_CHECK([for simple visibility declarations],
44 AC_CACHE_VAL([gl_cv_cc_visibility], [ 44 [gl_cv_cc_visibility],
45 gl_save_CFLAGS="$CFLAGS" 45 [gl_save_CFLAGS="$CFLAGS"
46 CFLAGS="$CFLAGS -fvisibility=hidden" 46 CFLAGS="$CFLAGS -fvisibility=hidden"
47 dnl We use the option -Werror and a function dummyfunc, because on some 47 dnl We use the option -Werror and a function dummyfunc, because on some
48 dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning 48 dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
49 dnl "visibility attribute not supported in this configuration; ignored" 49 dnl "visibility attribute not supported in this configuration; ignored"
50 dnl at the first function definition in every compilation unit, and we 50 dnl at the first function definition in every compilation unit, and we
51 dnl don't want to use the option in this case. 51 dnl don't want to use the option in this case.
52 if test $gl_cv_cc_vis_werror = yes; then 52 if test $gl_cv_cc_vis_werror = yes; then
53 CFLAGS="$CFLAGS -Werror" 53 CFLAGS="$CFLAGS -Werror"
54 fi 54 fi
55 AC_COMPILE_IFELSE( 55 AC_COMPILE_IFELSE(
56 [AC_LANG_PROGRAM( 56 [AC_LANG_PROGRAM(
57 [[extern __attribute__((__visibility__("hidden"))) int hiddenvar; 57 [[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
58 extern __attribute__((__visibility__("default"))) int exportedvar; 58 extern __attribute__((__visibility__("default"))) int exportedvar;
59 extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); 59 extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
60 extern __attribute__((__visibility__("default"))) int exportedfunc (void); 60 extern __attribute__((__visibility__("default"))) int exportedfunc (void);
61 void dummyfunc (void) {} 61 void dummyfunc (void);
62 ]], 62 int hiddenvar;
63 [[]])], 63 int exportedvar;
64 [gl_cv_cc_visibility=yes], 64 int hiddenfunc (void) { return 51; }
65 [gl_cv_cc_visibility=no]) 65 int exportedfunc (void) { return 1225736919; }
66 CFLAGS="$gl_save_CFLAGS"]) 66 void dummyfunc (void) {}
67 AC_MSG_RESULT([$gl_cv_cc_visibility]) 67 ]],
68 [[]])],
69 [gl_cv_cc_visibility=yes],
70 [gl_cv_cc_visibility=no])
71 CFLAGS="$gl_save_CFLAGS"
72 ])
68 if test $gl_cv_cc_visibility = yes; then 73 if test $gl_cv_cc_visibility = yes; then
69 CFLAG_VISIBILITY="-fvisibility=hidden" 74 CFLAG_VISIBILITY="-fvisibility=hidden"
70 HAVE_VISIBILITY=1 75 HAVE_VISIBILITY=1
diff --git a/gl/m4/vsnprintf.m4 b/gl/m4/vsnprintf.m4
index 4900764..7fbb11c 100644
--- a/gl/m4/vsnprintf.m4
+++ b/gl/m4/vsnprintf.m4
@@ -1,5 +1,5 @@
1# vsnprintf.m4 serial 6 1# vsnprintf.m4 serial 7
2dnl Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2004, 2007-2023 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.
@@ -46,6 +46,14 @@ AC_DEFUN([gl_REPLACE_VSNPRINTF],
46 AC_LIBOBJ([vsnprintf]) 46 AC_LIBOBJ([vsnprintf])
47 if test $ac_cv_func_vsnprintf = yes; then 47 if test $ac_cv_func_vsnprintf = yes; then
48 REPLACE_VSNPRINTF=1 48 REPLACE_VSNPRINTF=1
49 else
50 AC_CHECK_DECLS_ONCE([vsnprintf])
51 if test $ac_cv_have_decl_vsnprintf = yes; then
52 dnl If the function is declared but does not appear to exist, it may be
53 dnl defined as an inline function. In order to avoid a conflict, we have
54 dnl to define rpl_vsnprintf, not vsnprintf.
55 REPLACE_VSNPRINTF=1
56 fi
49 fi 57 fi
50 gl_PREREQ_VSNPRINTF 58 gl_PREREQ_VSNPRINTF
51]) 59])
diff --git a/gl/m4/warn-on-use.m4 b/gl/m4/warn-on-use.m4
index e43beeb..10649c5 100644
--- a/gl/m4/warn-on-use.m4
+++ b/gl/m4/warn-on-use.m4
@@ -1,11 +1,13 @@
1# warn-on-use.m4 serial 5 1# warn-on-use.m4 serial 10
2dnl Copyright (C) 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2010-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
6 6
7# gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES) 7# gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES)
8# --------------------------------------- 8# ---------------------------------------
9# If the module 'posixcheck' is in use:
10#
9# For each whitespace-separated element in the list of NAMES, define 11# For each whitespace-separated element in the list of NAMES, define
10# HAVE_RAW_DECL_name if the function has a declaration among INCLUDES 12# HAVE_RAW_DECL_name if the function has a declaration among INCLUDES
11# even after being undefined as a macro. 13# even after being undefined as a macro.
@@ -23,25 +25,38 @@ dnl with or without modifications, as long as this notice is preserved.
23# needing gl_WARN_ON_USE_PREPARE. 25# needing gl_WARN_ON_USE_PREPARE.
24AC_DEFUN([gl_WARN_ON_USE_PREPARE], 26AC_DEFUN([gl_WARN_ON_USE_PREPARE],
25[ 27[
26 m4_foreach_w([gl_decl], [$2], 28 m4_ifdef([gl_POSIXCHECK],
27 [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])), 29 [m4_foreach_w([gl_decl], [$2],
28 [Define to 1 if ]m4_defn([gl_decl])[ is declared even after 30 [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
29 undefining macros.])])dnl 31 [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
30dnl FIXME: gl_Symbol must be used unquoted until we can assume 32 undefining macros.])])dnl
31dnl autoconf 2.64 or newer. 33 for gl_func in m4_flatten([$2]); do
32 for gl_func in m4_flatten([$2]); do 34 AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
33 AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl 35 dnl As a workaround to implicit built-in function declarations in
34 AC_CACHE_CHECK([whether $gl_func is declared without a macro], 36 dnl clang (e.g. strndup), reference ac_compile_for_check_decl instead
35 gl_Symbol, 37 dnl of ac_compile. If, for whatever reason, the override of AC_PROG_CC
36 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1], 38 dnl in zzgnulib.m4 is inactive, use the original ac_compile.
37[@%:@undef $gl_func 39 ac_save_ac_compile="$ac_compile"
38 (void) $gl_func;])], 40 if test -n "$ac_compile_for_check_decl"; then
39 [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])]) 41 ac_compile="$ac_compile_for_check_decl"
40 AS_VAR_IF(gl_Symbol, [yes], 42 fi
41 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1]) 43 AC_CACHE_CHECK([whether $gl_func is declared without a macro],
42 dnl shortcut - if the raw declaration exists, then set a cache 44 [gl_Symbol],
43 dnl variable to allow skipping any later AC_CHECK_DECL efforts 45 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
44 eval ac_cv_have_decl_$gl_func=yes]) 46[[#undef $gl_func
45 AS_VAR_POPDEF([gl_Symbol])dnl 47 (void) $gl_func;]])],
46 done 48 [AS_VAR_SET([gl_Symbol], [yes])], [AS_VAR_SET([gl_Symbol], [no])])])
49 ac_compile="$ac_save_ac_compile"
50 AS_VAR_IF([gl_Symbol], [yes],
51 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
52 dnl Shortcut for an AC_CHECK_DECL invocation that may come later:
53 dnl If the raw declaration exists with the given includes, then
54 dnl AC_CHECK_DECL with its many includes would see it as well.
55 dnl So, set a cache variable to allow skipping any later
56 dnl AC_CHECK_DECL invocation for $gl_func.
57 eval "ac_cv_have_decl_$gl_func=yes"
58 ])
59 AS_VAR_POPDEF([gl_Symbol])dnl
60 done
61 ])
47]) 62])
diff --git a/gl/m4/wchar_h.m4 b/gl/m4/wchar_h.m4
index bedb15a..8ec6619 100644
--- a/gl/m4/wchar_h.m4
+++ b/gl/m4/wchar_h.m4
@@ -1,15 +1,15 @@
1dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues. 1dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2 2
3dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 3dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7 7
8dnl Written by Eric Blake. 8dnl Written by Eric Blake.
9 9
10# wchar_h.m4 serial 39 10# wchar_h.m4 serial 55
11 11
12AC_DEFUN([gl_WCHAR_H], 12AC_DEFUN_ONCE([gl_WCHAR_H],
13[ 13[
14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
15 AC_REQUIRE([gl_WCHAR_H_INLINE_OK]) 15 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
@@ -35,76 +35,82 @@ AC_DEFUN([gl_WCHAR_H],
35 fi 35 fi
36 AC_SUBST([HAVE_WINT_T]) 36 AC_SUBST([HAVE_WINT_T])
37 37
38 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
39
38 dnl Check for declarations of anything we want to poison if the 40 dnl Check for declarations of anything we want to poison if the
39 dnl corresponding gnulib module is not in use. 41 dnl corresponding gnulib module is not in use.
40 gl_WARN_ON_USE_PREPARE([[ 42 gl_WARN_ON_USE_PREPARE([[
41/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 43 #include <wchar.h>
42 <wchar.h>.
43 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
44 included before <wchar.h>. */
45#if !(defined __GLIBC__ && !defined __UCLIBC__)
46# include <stddef.h>
47# include <stdio.h>
48# include <time.h>
49#endif
50#include <wchar.h>
51 ]], 44 ]],
52 [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb 45 [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
53 wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset 46 wcsrtombs wcsnrtombs wcwidth
47 wmemchr wmemcmp wmemcpy wmemmove wmempcpy wmemset
54 wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp 48 wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
55 wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr 49 wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
56 wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth 50 wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
57 ]) 51 ])
52
53 AC_REQUIRE([AC_C_RESTRICT])
54
55 AC_CHECK_DECLS([wcsdup], [], [], [[
56 #include <wchar.h>
57 ]])
58 if test $ac_cv_have_decl_wcsdup = no; then
59 HAVE_DECL_WCSDUP=0
60 fi
58]) 61])
59 62
60dnl Check whether <wchar.h> is usable at all. 63dnl Check whether <wchar.h> is usable at all.
61AC_DEFUN([gl_WCHAR_H_INLINE_OK], 64AC_DEFUN([gl_WCHAR_H_INLINE_OK],
62[ 65[
63 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to 66 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
64 dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022> 67 dnl 'gnu_inline'. See <https://sourceware.org/bugzilla/show_bug.cgi?id=4022>
65 dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary, 68 dnl and <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
66 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and 69 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
67 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>. 70 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
71 AC_REQUIRE([AC_CANONICAL_HOST])
68 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly], 72 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
69 [gl_cv_header_wchar_h_correct_inline], 73 [gl_cv_header_wchar_h_correct_inline],
70 [gl_cv_header_wchar_h_correct_inline=yes 74 [gl_cv_header_wchar_h_correct_inline=yes
71 AC_LANG_CONFTEST([ 75 case "$host_os" in
72 AC_LANG_SOURCE([[#define wcstod renamed_wcstod 76 *-gnu* | gnu*)
73/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 77 AC_LANG_CONFTEST([
74 <wchar.h>. 78 AC_LANG_SOURCE([[
75 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 79 #define wcstod renamed_wcstod
76 included before <wchar.h>. */ 80 #include <wchar.h>
77#include <stddef.h> 81 extern int zero (void);
78#include <stdio.h> 82 int main () { return zero(); }
79#include <time.h> 83 ]])])
80#include <wchar.h> 84 dnl Do not rename the object file from conftest.$ac_objext to
81extern int zero (void); 85 dnl conftest1.$ac_objext, as this will cause the link to fail on
82int main () { return zero(); } 86 dnl z/OS when using the XPLINK object format (due to duplicate
83]])]) 87 dnl CSECT names). Instead, temporarily redefine $ac_compile so
84 if AC_TRY_EVAL([ac_compile]); then 88 dnl that the object file has the latter name from the start.
85 mv conftest.$ac_objext conftest1.$ac_objext 89 save_ac_compile="$ac_compile"
86 AC_LANG_CONFTEST([ 90 ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest1/`
87 AC_LANG_SOURCE([[#define wcstod renamed_wcstod 91 if echo '#include "conftest.c"' >conftest1.c \
88/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 92 && AC_TRY_EVAL([ac_compile]); then
89 <wchar.h>. 93 AC_LANG_CONFTEST([
90 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 94 AC_LANG_SOURCE([[
91 included before <wchar.h>. */ 95 #define wcstod renamed_wcstod
92#include <stddef.h> 96 #include <wchar.h>
93#include <stdio.h> 97 int zero (void) { return 0; }
94#include <time.h> 98 ]])])
95#include <wchar.h> 99 dnl See note above about renaming object files.
96int zero (void) { return 0; } 100 ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest2/`
97]])]) 101 if echo '#include "conftest.c"' >conftest2.c \
98 if AC_TRY_EVAL([ac_compile]); then 102 && AC_TRY_EVAL([ac_compile]); then
99 mv conftest.$ac_objext conftest2.$ac_objext 103 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
100 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then 104 :
101 : 105 else
102 else 106 gl_cv_header_wchar_h_correct_inline=no
103 gl_cv_header_wchar_h_correct_inline=no 107 fi
108 fi
104 fi 109 fi
105 fi 110 ac_compile="$save_ac_compile"
106 fi 111 rm -f conftest[12].c conftest[12].$ac_objext conftest$ac_exeext
107 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext 112 ;;
113 esac
108 ]) 114 ])
109 if test $gl_cv_header_wchar_h_correct_inline = no; then 115 if test $gl_cv_header_wchar_h_correct_inline = no; then
110 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS). 116 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
@@ -112,63 +118,84 @@ This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
112C99 mode. You have four options: 118C99 mode. You have four options:
113 - Add the flag -fgnu89-inline to CC and reconfigure, or 119 - Add the flag -fgnu89-inline to CC and reconfigure, or
114 - Fix your include files, using parts of 120 - Fix your include files, using parts of
115 <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or 121 <https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
116 - Use a gcc version older than 4.3, or 122 - Use a gcc version older than 4.3, or
117 - Don't use the flags -std=c99 or -std=gnu99. 123 - Don't use the flags -std=c99 or -std=gnu99.
118Configuration aborted.]) 124Configuration aborted.])
119 fi 125 fi
120]) 126])
121 127
128# gl_WCHAR_MODULE_INDICATOR([modulename])
129# sets the shell variable that indicates the presence of the given module
130# to a C preprocessor expression that will evaluate to 1.
131# This macro invocation must not occur in macros that are AC_REQUIREd.
122AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], 132AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
123[ 133[
124 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 134 dnl Ensure to expand the default settings once only.
125 AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) 135 gl_WCHAR_H_REQUIRE_DEFAULTS
126 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 136 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
127 dnl Define it also as a C macro, for the benefit of the unit tests. 137 dnl Define it also as a C macro, for the benefit of the unit tests.
128 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 138 gl_MODULE_INDICATOR_FOR_TESTS([$1])
129]) 139])
130 140
141# Initializes the default values for AC_SUBSTed shell variables.
142# This macro must not be AC_REQUIREd. It must only be invoked, and only
143# outside of macros or in macros that are not AC_REQUIREd.
144AC_DEFUN([gl_WCHAR_H_REQUIRE_DEFAULTS],
145[
146 m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS], [
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BTOWC])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOB])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSINIT])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRTOWC])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBRLEN])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRTOWCS])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNRTOWCS])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCRTOMB])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRTOMBS])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNRTOMBS])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCWIDTH])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCHR])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCMP])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMCPY])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMMOVE])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMPCPY])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WMEMSET])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSLEN])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNLEN])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCPY])
167 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPCPY])
168 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCPY])
169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCPNCPY])
170 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCAT])
171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCAT])
172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCMP])
173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCMP])
174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCASECMP])
175 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSNCASECMP])
176 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCOLL])
177 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSXFRM])
178 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSDUP])
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCHR])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSRCHR])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSCSPN])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSPN])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSPBRK])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSSTR])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSTOK])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSWIDTH])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCSFTIME])
188 dnl Support Microsoft deprecated alias function names by default.
189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WCSDUP], [1])
190 ])
191 m4_require(GL_MODULE_INDICATOR_PREFIX[_WCHAR_H_MODULE_INDICATOR_DEFAULTS])
192 dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
193 gl_STDLIB_H_REQUIRE_DEFAULTS
194 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
195])
196
131AC_DEFUN([gl_WCHAR_H_DEFAULTS], 197AC_DEFUN([gl_WCHAR_H_DEFAULTS],
132[ 198[
133 GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
134 GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
135 GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
136 GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
137 GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
138 GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
139 GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
140 GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
141 GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
142 GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
143 GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
144 GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR])
145 GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP])
146 GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY])
147 GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE])
148 GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET])
149 GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN])
150 GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN])
151 GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY])
152 GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY])
153 GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY])
154 GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY])
155 GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT])
156 GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT])
157 GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP])
158 GNULIB_WCSNCMP=0; AC_SUBST([GNULIB_WCSNCMP])
159 GNULIB_WCSCASECMP=0; AC_SUBST([GNULIB_WCSCASECMP])
160 GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP])
161 GNULIB_WCSCOLL=0; AC_SUBST([GNULIB_WCSCOLL])
162 GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM])
163 GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP])
164 GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR])
165 GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR])
166 GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN])
167 GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN])
168 GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK])
169 GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR])
170 GNULIB_WCSTOK=0; AC_SUBST([GNULIB_WCSTOK])
171 GNULIB_WCSWIDTH=0; AC_SUBST([GNULIB_WCSWIDTH])
172 dnl Assume proper GNU behavior unless another module says otherwise. 199 dnl Assume proper GNU behavior unless another module says otherwise.
173 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) 200 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
174 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) 201 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
@@ -183,6 +210,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
183 HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP]) 210 HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP])
184 HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY]) 211 HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY])
185 HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE]) 212 HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE])
213 HAVE_WMEMPCPY=1; AC_SUBST([HAVE_WMEMPCPY])
186 HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET]) 214 HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET])
187 HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN]) 215 HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN])
188 HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN]) 216 HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN])
@@ -207,7 +235,9 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
207 HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR]) 235 HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR])
208 HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK]) 236 HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK])
209 HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH]) 237 HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH])
238 HAVE_WCSFTIME=1; AC_SUBST([HAVE_WCSFTIME])
210 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB]) 239 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
240 HAVE_DECL_WCSDUP=1; AC_SUBST([HAVE_DECL_WCSDUP])
211 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) 241 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
212 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T]) 242 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
213 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC]) 243 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
@@ -222,4 +252,6 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
222 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS]) 252 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
223 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) 253 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
224 REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) 254 REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH])
255 REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME])
256 REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK])
225]) 257])
diff --git a/gl/m4/wchar_t.m4 b/gl/m4/wchar_t.m4
index e1e1e69..50bde08 100644
--- a/gl/m4/wchar_t.m4
+++ b/gl/m4/wchar_t.m4
@@ -1,5 +1,5 @@
1# wchar_t.m4 serial 4 (gettext-0.18.2) 1# wchar_t.m4 serial 4 (gettext-0.18.2)
2dnl Copyright (C) 2002-2003, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2003, 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/wcrtomb.m4 b/gl/m4/wcrtomb.m4
index f56b5ba..d51b36e 100644
--- a/gl/m4/wcrtomb.m4
+++ b/gl/m4/wcrtomb.m4
@@ -1,5 +1,5 @@
1# wcrtomb.m4 serial 11 1# wcrtomb.m4 serial 17
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2023 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.
@@ -15,15 +15,8 @@ AC_DEFUN([gl_FUNC_WCRTOMB],
15 if test $ac_cv_func_wcrtomb = no; then 15 if test $ac_cv_func_wcrtomb = no; then
16 HAVE_WCRTOMB=0 16 HAVE_WCRTOMB=0
17 AC_CHECK_DECLS([wcrtomb],,, [[ 17 AC_CHECK_DECLS([wcrtomb],,, [[
18/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 18 #include <wchar.h>
19 <wchar.h>. 19 ]])
20 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
21 included before <wchar.h>. */
22#include <stddef.h>
23#include <stdio.h>
24#include <time.h>
25#include <wchar.h>
26]])
27 if test $ac_cv_have_decl_wcrtomb = yes; then 20 if test $ac_cv_have_decl_wcrtomb = yes; then
28 dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although 21 dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
29 dnl it does not have the function. Avoid a collision with gnulib's 22 dnl it does not have the function. Avoid a collision with gnulib's
@@ -31,17 +24,56 @@ AC_DEFUN([gl_FUNC_WCRTOMB],
31 REPLACE_WCRTOMB=1 24 REPLACE_WCRTOMB=1
32 fi 25 fi
33 else 26 else
34 if test $REPLACE_MBSTATE_T = 1; then 27 dnl We don't actually need to override wcrtomb when redefining the semantics
35 REPLACE_WCRTOMB=1 28 dnl of the mbstate_t type. Tested on 32-bit AIX.
36 else 29 dnl if test $REPLACE_MBSTATE_T = 1; then
37 dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes 30 dnl REPLACE_WCRTOMB=1
38 dnl returns 0 instead of 1. 31 dnl fi
32 if test $REPLACE_WCRTOMB = 0; then
33 dnl On Android 4.3, wcrtomb produces wrong characters in the C locale.
34 dnl On AIX 4.3, OSF/1 5.1 and Solaris <= 11.3, wcrtomb (NULL, 0, NULL)
35 dnl sometimes returns 0 instead of 1.
39 AC_REQUIRE([AC_PROG_CC]) 36 AC_REQUIRE([AC_PROG_CC])
40 AC_REQUIRE([gt_LOCALE_FR]) 37 AC_REQUIRE([gt_LOCALE_FR])
41 AC_REQUIRE([gt_LOCALE_FR_UTF8]) 38 AC_REQUIRE([gt_LOCALE_FR_UTF8])
42 AC_REQUIRE([gt_LOCALE_JA]) 39 AC_REQUIRE([gt_LOCALE_JA])
43 AC_REQUIRE([gt_LOCALE_ZH_CN]) 40 AC_REQUIRE([gt_LOCALE_ZH_CN])
44 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 41 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42 AC_CACHE_CHECK([whether wcrtomb works in the C locale],
43 [gl_cv_func_wcrtomb_works],
44 [AC_RUN_IFELSE(
45 [AC_LANG_SOURCE([[
46#include <string.h>
47#include <stdlib.h>
48#include <wchar.h>
49int main ()
50{
51 mbstate_t state;
52 char out[64];
53 int count;
54 memset (&state, 0, sizeof (state));
55 out[0] = 'x';
56 count = wcrtomb (out, L'a', &state);
57 return !(count == 1 && out[0] == 'a');
58}]])],
59 [gl_cv_func_wcrtomb_works=yes],
60 [gl_cv_func_wcrtomb_works=no],
61 [case "$host_os" in
62 # Guess no on Android.
63 linux*-android*) gl_cv_func_wcrtomb_works="guessing no";;
64 # Guess yes otherwise.
65 *) gl_cv_func_wcrtomb_works="guessing yes";;
66 esac
67 ])
68 ])
69 case "$gl_cv_func_wcrtomb_works" in
70 *yes) ;;
71 *) AC_DEFINE([WCRTOMB_C_LOCALE_BUG], [1],
72 [Define if the wcrtomb function does not work in the C locale.])
73 REPLACE_WCRTOMB=1 ;;
74 esac
75 fi
76 if test $REPLACE_WCRTOMB = 0; then
45 AC_CACHE_CHECK([whether wcrtomb return value is correct], 77 AC_CACHE_CHECK([whether wcrtomb return value is correct],
46 [gl_cv_func_wcrtomb_retval], 78 [gl_cv_func_wcrtomb_retval],
47 [ 79 [
@@ -49,10 +81,10 @@ AC_DEFUN([gl_FUNC_WCRTOMB],
49 dnl is present. 81 dnl is present.
50changequote(,)dnl 82changequote(,)dnl
51 case "$host_os" in 83 case "$host_os" in
52 # Guess no on AIX 4, OSF/1 and Solaris. 84 # Guess no on AIX 4, OSF/1, Solaris, native Windows.
53 aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;; 85 aix4* | osf* | solaris* | mingw*) gl_cv_func_wcrtomb_retval="guessing no" ;;
54 # Guess yes otherwise. 86 # Guess yes otherwise.
55 *) gl_cv_func_wcrtomb_retval="guessing yes" ;; 87 *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
56 esac 88 esac
57changequote([,])dnl 89changequote([,])dnl
58 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then 90 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
@@ -60,14 +92,8 @@ changequote([,])dnl
60 [AC_LANG_SOURCE([[ 92 [AC_LANG_SOURCE([[
61#include <locale.h> 93#include <locale.h>
62#include <string.h> 94#include <string.h>
63/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
64 <wchar.h>.
65 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
66 included before <wchar.h>. */
67#include <stddef.h>
68#include <stdio.h>
69#include <time.h>
70#include <wchar.h> 95#include <wchar.h>
96#include <stdlib.h>
71int main () 97int main ()
72{ 98{
73 int result = 0; 99 int result = 0;
@@ -80,6 +106,12 @@ int main ()
80 { 106 {
81 if (wcrtomb (NULL, 0, NULL) != 1) 107 if (wcrtomb (NULL, 0, NULL) != 1)
82 result |= 2; 108 result |= 2;
109 {
110 wchar_t wc = (wchar_t) 0xBADFACE;
111 if (mbtowc (&wc, "\303\274", 2) == 2)
112 if (wcrtomb (NULL, wc, NULL) != 1)
113 result |= 2;
114 }
83 } 115 }
84 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) 116 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
85 { 117 {
@@ -100,7 +132,9 @@ int main ()
100 ]) 132 ])
101 case "$gl_cv_func_wcrtomb_retval" in 133 case "$gl_cv_func_wcrtomb_retval" in
102 *yes) ;; 134 *yes) ;;
103 *) REPLACE_WCRTOMB=1 ;; 135 *) AC_DEFINE([WCRTOMB_RETVAL_BUG], [1],
136 [Define if the wcrtomb function has an incorrect return value.])
137 REPLACE_WCRTOMB=1 ;;
104 esac 138 esac
105 fi 139 fi
106 fi 140 fi
diff --git a/gl/m4/wctype_h.m4 b/gl/m4/wctype_h.m4
index 82ada0e..6856a73 100644
--- a/gl/m4/wctype_h.m4
+++ b/gl/m4/wctype_h.m4
@@ -1,15 +1,15 @@
1# wctype_h.m4 serial 18 1# wctype_h.m4 serial 30
2 2
3dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it. 3dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
4 4
5dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. 5dnl Copyright (C) 2006-2023 Free Software Foundation, Inc.
6dnl This file is free software; the Free Software Foundation 6dnl This file is free software; the Free Software Foundation
7dnl gives unlimited permission to copy and/or distribute it, 7dnl gives unlimited permission to copy and/or distribute it,
8dnl with or without modifications, as long as this notice is preserved. 8dnl with or without modifications, as long as this notice is preserved.
9 9
10dnl Written by Paul Eggert. 10dnl Written by Paul Eggert.
11 11
12AC_DEFUN([gl_WCTYPE_H], 12AC_DEFUN_ONCE([gl_WCTYPE_H],
13[ 13[
14 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) 14 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
15 AC_REQUIRE([AC_PROG_CC]) 15 AC_REQUIRE([AC_PROG_CC])
@@ -30,6 +30,8 @@ AC_DEFUN([gl_WCTYPE_H],
30 fi 30 fi
31 AC_SUBST([HAVE_WINT_T]) 31 AC_SUBST([HAVE_WINT_T])
32 32
33 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
34
33 gl_CHECK_NEXT_HEADERS([wctype.h]) 35 gl_CHECK_NEXT_HEADERS([wctype.h])
34 if test $ac_cv_header_wctype_h = yes; then 36 if test $ac_cv_header_wctype_h = yes; then
35 if test $ac_cv_func_iswcntrl = yes; then 37 if test $ac_cv_func_iswcntrl = yes; then
@@ -39,22 +41,16 @@ AC_DEFUN([gl_WCTYPE_H],
39 [ 41 [
40 AC_RUN_IFELSE( 42 AC_RUN_IFELSE(
41 [AC_LANG_SOURCE([[ 43 [AC_LANG_SOURCE([[
42 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
43 included before <wchar.h>.
44 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
45 must be included before <wchar.h>. */
46 #include <stddef.h>
47 #include <stdio.h>
48 #include <time.h>
49 #include <wchar.h> 44 #include <wchar.h>
50 #include <wctype.h> 45 #include <wctype.h>
51 int main () { return iswprint ('x') == 0; } 46 int main () { return iswprint ('x') == 0; }
52 ]])], 47 ]])],
53 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no], 48 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
54 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h> 49 [dnl Guess no on Linux libc5, yes otherwise.
50 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
55 #if __GNU_LIBRARY__ == 1 51 #if __GNU_LIBRARY__ == 1
56 Linux libc5 i18n is broken. 52 Linux libc5 i18n is broken.
57 #endif]], [])], 53 #endif]], [[]])],
58 [gl_cv_func_iswcntrl_works="guessing yes"], 54 [gl_cv_func_iswcntrl_works="guessing yes"],
59 [gl_cv_func_iswcntrl_works="guessing no"]) 55 [gl_cv_func_iswcntrl_works="guessing no"])
60 ]) 56 ])
@@ -66,10 +62,14 @@ AC_DEFUN([gl_WCTYPE_H],
66 fi 62 fi
67 AC_SUBST([HAVE_WCTYPE_H]) 63 AC_SUBST([HAVE_WCTYPE_H])
68 64
69 case "$gl_cv_func_iswcntrl_works" in 65 if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
70 *yes) REPLACE_ISWCNTRL=0 ;; 66 REPLACE_ISWCNTRL=1
71 *) REPLACE_ISWCNTRL=1 ;; 67 else
72 esac 68 case "$gl_cv_func_iswcntrl_works" in
69 *yes) REPLACE_ISWCNTRL=0 ;;
70 *) REPLACE_ISWCNTRL=1 ;;
71 esac
72 fi
73 AC_SUBST([REPLACE_ISWCNTRL]) 73 AC_SUBST([REPLACE_ISWCNTRL])
74 74
75 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then 75 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
@@ -85,14 +85,7 @@ AC_DEFUN([gl_WCTYPE_H],
85 REPLACE_TOWLOWER=0 85 REPLACE_TOWLOWER=0
86 else 86 else
87 AC_CHECK_DECLS([towlower],,, 87 AC_CHECK_DECLS([towlower],,,
88 [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be 88 [[#include <wchar.h>
89 included before <wchar.h>.
90 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
91 must be included before <wchar.h>. */
92 #include <stddef.h>
93 #include <stdio.h>
94 #include <time.h>
95 #include <wchar.h>
96 #if HAVE_WCTYPE_H 89 #if HAVE_WCTYPE_H
97 # include <wctype.h> 90 # include <wctype.h>
98 #endif 91 #endif
@@ -121,14 +114,7 @@ AC_DEFUN([gl_WCTYPE_H],
121 AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t], 114 AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
122 [AC_COMPILE_IFELSE( 115 [AC_COMPILE_IFELSE(
123 [AC_LANG_PROGRAM( 116 [AC_LANG_PROGRAM(
124 [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be 117 [[#include <wchar.h>
125 included before <wchar.h>.
126 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
127 must be included before <wchar.h>. */
128 #include <stddef.h>
129 #include <stdio.h>
130 #include <time.h>
131 #include <wchar.h>
132 #if HAVE_WCTYPE_H 118 #if HAVE_WCTYPE_H
133 # include <wctype.h> 119 # include <wctype.h>
134 #endif 120 #endif
@@ -147,14 +133,7 @@ AC_DEFUN([gl_WCTYPE_H],
147 AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t], 133 AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
148 [AC_COMPILE_IFELSE( 134 [AC_COMPILE_IFELSE(
149 [AC_LANG_PROGRAM( 135 [AC_LANG_PROGRAM(
150 [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be 136 [[#include <wchar.h>
151 included before <wchar.h>.
152 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
153 must be included before <wchar.h>. */
154 #include <stddef.h>
155 #include <stdio.h>
156 #include <time.h>
157 #include <wchar.h>
158 #include <wctype.h> 137 #include <wctype.h>
159 wctrans_t a; 138 wctrans_t a;
160 ]], 139 ]],
@@ -169,14 +148,7 @@ AC_DEFUN([gl_WCTYPE_H],
169 dnl Check for declarations of anything we want to poison if the 148 dnl Check for declarations of anything we want to poison if the
170 dnl corresponding gnulib module is not in use. 149 dnl corresponding gnulib module is not in use.
171 gl_WARN_ON_USE_PREPARE([[ 150 gl_WARN_ON_USE_PREPARE([[
172/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
173 <wchar.h>.
174 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
175 included before <wchar.h>. */
176#if !(defined __GLIBC__ && !defined __UCLIBC__) 151#if !(defined __GLIBC__ && !defined __UCLIBC__)
177# include <stddef.h>
178# include <stdio.h>
179# include <time.h>
180# include <wchar.h> 152# include <wchar.h>
181#endif 153#endif
182#include <wctype.h> 154#include <wctype.h>
@@ -185,25 +157,44 @@ AC_DEFUN([gl_WCTYPE_H],
185 ]) 157 ])
186]) 158])
187 159
160# gl_WCTYPE_MODULE_INDICATOR([modulename])
161# sets the shell variable that indicates the presence of the given module
162# to a C preprocessor expression that will evaluate to 1.
163# This macro invocation must not occur in macros that are AC_REQUIREd.
188AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR], 164AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
189[ 165[
190 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 166 dnl Ensure to expand the default settings once only.
191 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) 167 gl_WCTYPE_H_REQUIRE_DEFAULTS
192 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 168 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
193 dnl Define it also as a C macro, for the benefit of the unit tests. 169 dnl Define it also as a C macro, for the benefit of the unit tests.
194 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 170 gl_MODULE_INDICATOR_FOR_TESTS([$1])
195]) 171])
196 172
173# Initializes the default values for AC_SUBSTed shell variables.
174# This macro must not be AC_REQUIREd. It must only be invoked, and only
175# outside of macros or in macros that are not AC_REQUIREd.
176AC_DEFUN([gl_WCTYPE_H_REQUIRE_DEFAULTS],
177[
178 m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS], [
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWBLANK])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWDIGIT])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWXDIGIT])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTYPE])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWCTYPE])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTRANS])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOWCTRANS])
186 ])
187 m4_require(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS])
188 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
189])
190
197AC_DEFUN([gl_WCTYPE_H_DEFAULTS], 191AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
198[ 192[
199 GNULIB_ISWBLANK=0; AC_SUBST([GNULIB_ISWBLANK])
200 GNULIB_WCTYPE=0; AC_SUBST([GNULIB_WCTYPE])
201 GNULIB_ISWCTYPE=0; AC_SUBST([GNULIB_ISWCTYPE])
202 GNULIB_WCTRANS=0; AC_SUBST([GNULIB_WCTRANS])
203 GNULIB_TOWCTRANS=0; AC_SUBST([GNULIB_TOWCTRANS])
204 dnl Assume proper GNU behavior unless another module says otherwise. 193 dnl Assume proper GNU behavior unless another module says otherwise.
205 HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK]) 194 HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK])
206 HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T]) 195 HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T])
207 HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T]) 196 HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T])
208 REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK]) 197 REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK])
198 REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT])
199 REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT])
209]) 200])
diff --git a/gl/m4/wint_t.m4 b/gl/m4/wint_t.m4
index d7cd3db..dfd743b 100644
--- a/gl/m4/wint_t.m4
+++ b/gl/m4/wint_t.m4
@@ -1,11 +1,12 @@
1# wint_t.m4 serial 5 (gettext-0.18.2) 1# wint_t.m4 serial 11
2dnl Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007-2023 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 From Bruno Haible. 7dnl From Bruno Haible.
8dnl Test whether <wchar.h> has the 'wint_t' type. 8dnl Test whether <wchar.h> has the 'wint_t' type and whether gnulib's
9dnl <wchar.h> or <wctype.h> would, if present, override 'wint_t'.
9dnl Prerequisite: AC_PROG_CC 10dnl Prerequisite: AC_PROG_CC
10 11
11AC_DEFUN([gt_TYPE_WINT_T], 12AC_DEFUN([gt_TYPE_WINT_T],
@@ -13,20 +14,44 @@ AC_DEFUN([gt_TYPE_WINT_T],
13 AC_CACHE_CHECK([for wint_t], [gt_cv_c_wint_t], 14 AC_CACHE_CHECK([for wint_t], [gt_cv_c_wint_t],
14 [AC_COMPILE_IFELSE( 15 [AC_COMPILE_IFELSE(
15 [AC_LANG_PROGRAM( 16 [AC_LANG_PROGRAM(
16 [[ 17 [[#include <wchar.h>
17/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
18 <wchar.h>.
19 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
20 before <wchar.h>. */
21#include <stddef.h>
22#include <stdio.h>
23#include <time.h>
24#include <wchar.h>
25 wint_t foo = (wchar_t)'\0';]], 18 wint_t foo = (wchar_t)'\0';]],
26 [[]])], 19 [[]])],
27 [gt_cv_c_wint_t=yes], 20 [gt_cv_c_wint_t=yes],
28 [gt_cv_c_wint_t=no])]) 21 [gt_cv_c_wint_t=no])])
29 if test $gt_cv_c_wint_t = yes; then 22 if test $gt_cv_c_wint_t = yes; then
30 AC_DEFINE([HAVE_WINT_T], [1], [Define if you have the 'wint_t' type.]) 23 AC_DEFINE([HAVE_WINT_T], [1], [Define if you have the 'wint_t' type.])
24
25 dnl Determine whether gnulib's <wchar.h> or <wctype.h> would, if present,
26 dnl override 'wint_t'.
27 AC_CACHE_CHECK([whether wint_t is large enough],
28 [gl_cv_type_wint_t_large_enough],
29 [AC_COMPILE_IFELSE(
30 [AC_LANG_PROGRAM(
31 [[#include <wchar.h>
32 int verify[sizeof (wint_t) < sizeof (int) ? -1 : 1];
33 ]])],
34 [gl_cv_type_wint_t_large_enough=yes],
35 [gl_cv_type_wint_t_large_enough=no])])
36 if test $gl_cv_type_wint_t_large_enough = no; then
37 GNULIBHEADERS_OVERRIDE_WINT_T=1
38 else
39 GNULIBHEADERS_OVERRIDE_WINT_T=0
40 fi
41 else
42 GNULIBHEADERS_OVERRIDE_WINT_T=0
43 fi
44 AC_SUBST([GNULIBHEADERS_OVERRIDE_WINT_T])
45])
46
47dnl Prerequisites of the 'wint_t' override.
48AC_DEFUN([gl_TYPE_WINT_T_PREREQ],
49[
50 AC_CHECK_HEADERS_ONCE([crtdefs.h])
51 if test $ac_cv_header_crtdefs_h = yes; then
52 HAVE_CRTDEFS_H=1
53 else
54 HAVE_CRTDEFS_H=0
31 fi 55 fi
56 AC_SUBST([HAVE_CRTDEFS_H])
32]) 57])
diff --git a/gl/m4/xalloc.m4 b/gl/m4/xalloc.m4
index 64ca701..fc56f59 100644
--- a/gl/m4/xalloc.m4
+++ b/gl/m4/xalloc.m4
@@ -1,5 +1,5 @@
1# xalloc.m4 serial 18 1# xalloc.m4 serial 18
2dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/xsize.m4 b/gl/m4/xsize.m4
index 8ea9f2c..649db9c 100644
--- a/gl/m4/xsize.m4
+++ b/gl/m4/xsize.m4
@@ -1,5 +1,5 @@
1# xsize.m4 serial 5 1# xsize.m4 serial 5
2dnl Copyright (C) 2003-2004, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2003-2004, 2008-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/xstrndup.m4 b/gl/m4/xstrndup.m4
deleted file mode 100644
index 4a9330b..0000000
--- a/gl/m4/xstrndup.m4
+++ /dev/null
@@ -1,15 +0,0 @@
1# xstrndup.m4 serial 2
2dnl Copyright (C) 2003, 2009-2013 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_XSTRNDUP],
8[
9 gl_PREREQ_XSTRNDUP
10])
11
12# Prerequisites of lib/xstrndup.c.
13AC_DEFUN([gl_PREREQ_XSTRNDUP], [
14 :
15])
diff --git a/gl/m4/zzgnulib.m4 b/gl/m4/zzgnulib.m4
new file mode 100644
index 0000000..362102b
--- /dev/null
+++ b/gl/m4/zzgnulib.m4
@@ -0,0 +1,23 @@
1# zzgnulib.m4 serial 1
2dnl Copyright (C) 2020-2023 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 This file must be named something that sorts after all other
8dnl package- or gnulib-provided .m4 files - at least for those packages
9dnl that redefine AC_PROG_CC.
10
11dnl Redefine AC_PROG_CC so that it ends with invocations of gl_COMPILER_CLANG
12dnl and gl_COMPILER_PREPARE_CHECK_DECL.
13m4_define([AC_PROG_CC],
14 m4_defn([AC_PROG_CC])[
15gl_COMPILER_CLANG
16gl_COMPILER_PREPARE_CHECK_DECL
17])
18
19# gl_ZZGNULIB
20# -----------
21# Witness macro that this file has been included. Needed to force
22# Automake to include this file after all other gnulib .m4 files.
23AC_DEFUN([gl_ZZGNULIB])
diff --git a/gl/malloc.c b/gl/malloc.c
index 908735d..3ade35c 100644
--- a/gl/malloc.c
+++ b/gl/malloc.c
@@ -1,51 +1,46 @@
1/* malloc() function that is glibc compatible. 1/* malloc() function that is glibc compatible.
2 2
3 Copyright (C) 1997-1998, 2006-2007, 2009-2013 Free Software Foundation, Inc. 3 Copyright (C) 1997-1998, 2006-2007, 2009-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* written by Jim Meyering and Bruno Haible */ 18/* written by Jim Meyering and Bruno Haible */
19 19
20#define _GL_USE_STDLIB_ALLOC 1 20#define _GL_USE_STDLIB_ALLOC 1
21#include <config.h> 21#include <config.h>
22/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
23#ifdef malloc
24# define NEED_MALLOC_GNU 1
25# undef malloc
26/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
27#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU
28# define NEED_MALLOC_GNU 1
29#endif
30 22
31#include <stdlib.h> 23#include <stdlib.h>
32 24
33#include <errno.h> 25#include <errno.h>
34 26
35/* Allocate an N-byte block of memory from the heap. 27#include "xalloc-oversized.h"
36 If N is zero, allocate a 1-byte block. */ 28
29/* Allocate an N-byte block of memory from the heap, even if N is 0. */
37 30
38void * 31void *
39rpl_malloc (size_t n) 32rpl_malloc (size_t n)
40{ 33{
41 void *result;
42
43#if NEED_MALLOC_GNU
44 if (n == 0) 34 if (n == 0)
45 n = 1; 35 n = 1;
46#endif
47 36
48 result = malloc (n); 37 if (xalloc_oversized (n, 1))
38 {
39 errno = ENOMEM;
40 return NULL;
41 }
42
43 void *result = malloc (n);
49 44
50#if !HAVE_MALLOC_POSIX 45#if !HAVE_MALLOC_POSIX
51 if (result == NULL) 46 if (result == NULL)
diff --git a/gl/malloc/dynarray-skeleton.c b/gl/malloc/dynarray-skeleton.c
new file mode 100644
index 0000000..580c278
--- /dev/null
+++ b/gl/malloc/dynarray-skeleton.c
@@ -0,0 +1,528 @@
1/* Type-safe arrays which grow dynamically.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19/* Pre-processor macros which act as parameters:
20
21 DYNARRAY_STRUCT
22 The struct tag of dynamic array to be defined.
23 DYNARRAY_ELEMENT
24 The type name of the element type. Elements are copied
25 as if by memcpy, and can change address as the dynamic
26 array grows.
27 DYNARRAY_PREFIX
28 The prefix of the functions which are defined.
29
30 The following parameters are optional:
31
32 DYNARRAY_ELEMENT_FREE
33 DYNARRAY_ELEMENT_FREE (E) is evaluated to deallocate the
34 contents of elements. E is of type DYNARRAY_ELEMENT *.
35 DYNARRAY_ELEMENT_INIT
36 DYNARRAY_ELEMENT_INIT (E) is evaluated to initialize a new
37 element. E is of type DYNARRAY_ELEMENT *.
38 If DYNARRAY_ELEMENT_FREE but not DYNARRAY_ELEMENT_INIT is
39 defined, new elements are automatically zero-initialized.
40 Otherwise, new elements have undefined contents.
41 DYNARRAY_INITIAL_SIZE
42 The size of the statically allocated array (default:
43 at least 2, more elements if they fit into 128 bytes).
44 Must be a preprocessor constant. If DYNARRAY_INITIAL_SIZE is 0,
45 there is no statically allocated array at, and all non-empty
46 arrays are heap-allocated.
47 DYNARRAY_FINAL_TYPE
48 The name of the type which holds the final array. If not
49 defined, is PREFIX##finalize not provided. DYNARRAY_FINAL_TYPE
50 must be a struct type, with members of type DYNARRAY_ELEMENT and
51 size_t at the start (in this order).
52
53 These macros are undefined after this header file has been
54 included.
55
56 The following types are provided (their members are private to the
57 dynarray implementation):
58
59 struct DYNARRAY_STRUCT
60
61 The following functions are provided:
62
63 void DYNARRAY_PREFIX##init (struct DYNARRAY_STRUCT *);
64 void DYNARRAY_PREFIX##free (struct DYNARRAY_STRUCT *);
65 bool DYNARRAY_PREFIX##has_failed (const struct DYNARRAY_STRUCT *);
66 void DYNARRAY_PREFIX##mark_failed (struct DYNARRAY_STRUCT *);
67 size_t DYNARRAY_PREFIX##size (const struct DYNARRAY_STRUCT *);
68 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##begin (const struct DYNARRAY_STRUCT *);
69 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##end (const struct DYNARRAY_STRUCT *);
70 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##at (struct DYNARRAY_STRUCT *, size_t);
71 void DYNARRAY_PREFIX##add (struct DYNARRAY_STRUCT *, DYNARRAY_ELEMENT);
72 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##emplace (struct DYNARRAY_STRUCT *);
73 bool DYNARRAY_PREFIX##resize (struct DYNARRAY_STRUCT *, size_t);
74 void DYNARRAY_PREFIX##remove_last (struct DYNARRAY_STRUCT *);
75 void DYNARRAY_PREFIX##clear (struct DYNARRAY_STRUCT *);
76
77 The following functions are provided are provided if the
78 prerequisites are met:
79
80 bool DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *,
81 DYNARRAY_FINAL_TYPE *);
82 (if DYNARRAY_FINAL_TYPE is defined)
83 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *,
84 size_t *);
85 (if DYNARRAY_FINAL_TYPE is not defined)
86*/
87
88#include <malloc/dynarray.h>
89
90#include <errno.h>
91#include <stdlib.h>
92#include <string.h>
93
94#ifndef DYNARRAY_STRUCT
95# error "DYNARRAY_STRUCT must be defined"
96#endif
97
98#ifndef DYNARRAY_ELEMENT
99# error "DYNARRAY_ELEMENT must be defined"
100#endif
101
102#ifndef DYNARRAY_PREFIX
103# error "DYNARRAY_PREFIX must be defined"
104#endif
105
106#ifdef DYNARRAY_INITIAL_SIZE
107# if DYNARRAY_INITIAL_SIZE < 0
108# error "DYNARRAY_INITIAL_SIZE must be non-negative"
109# endif
110# if DYNARRAY_INITIAL_SIZE > 0
111# define DYNARRAY_HAVE_SCRATCH 1
112# else
113# define DYNARRAY_HAVE_SCRATCH 0
114# endif
115#else
116/* Provide a reasonable default which limits the size of
117 DYNARRAY_STRUCT. */
118# define DYNARRAY_INITIAL_SIZE \
119 (sizeof (DYNARRAY_ELEMENT) > 64 ? 2 : 128 / sizeof (DYNARRAY_ELEMENT))
120# define DYNARRAY_HAVE_SCRATCH 1
121#endif
122
123/* Public type definitions. */
124
125/* All fields of this struct are private to the implementation. */
126struct DYNARRAY_STRUCT
127{
128 union
129 {
130 struct dynarray_header dynarray_abstract;
131 struct
132 {
133 /* These fields must match struct dynarray_header. */
134 size_t used;
135 size_t allocated;
136 DYNARRAY_ELEMENT *array;
137 } dynarray_header;
138 } u;
139
140#if DYNARRAY_HAVE_SCRATCH
141 /* Initial inline allocation. */
142 DYNARRAY_ELEMENT scratch[DYNARRAY_INITIAL_SIZE];
143#endif
144};
145
146/* Internal use only: Helper macros. */
147
148/* Ensure macro-expansion of DYNARRAY_PREFIX. */
149#define DYNARRAY_CONCAT0(prefix, name) prefix##name
150#define DYNARRAY_CONCAT1(prefix, name) DYNARRAY_CONCAT0(prefix, name)
151#define DYNARRAY_NAME(name) DYNARRAY_CONCAT1(DYNARRAY_PREFIX, name)
152
153/* Use DYNARRAY_FREE instead of DYNARRAY_NAME (free),
154 so that Gnulib does not change 'free' to 'rpl_free'. */
155#define DYNARRAY_FREE DYNARRAY_CONCAT1 (DYNARRAY_NAME (f), ree)
156
157/* Address of the scratch buffer if any. */
158#if DYNARRAY_HAVE_SCRATCH
159# define DYNARRAY_SCRATCH(list) (list)->scratch
160#else
161# define DYNARRAY_SCRATCH(list) NULL
162#endif
163
164/* Internal use only: Helper functions. */
165
166/* Internal function. Call DYNARRAY_ELEMENT_FREE with the array
167 elements. Name mangling needed due to the DYNARRAY_ELEMENT_FREE
168 macro expansion. */
169static inline void
170DYNARRAY_NAME (free__elements__) (DYNARRAY_ELEMENT *__dynarray_array,
171 size_t __dynarray_used)
172{
173#ifdef DYNARRAY_ELEMENT_FREE
174 for (size_t __dynarray_i = 0; __dynarray_i < __dynarray_used; ++__dynarray_i)
175 DYNARRAY_ELEMENT_FREE (&__dynarray_array[__dynarray_i]);
176#endif /* DYNARRAY_ELEMENT_FREE */
177}
178
179/* Internal function. Free the non-scratch array allocation. */
180static inline void
181DYNARRAY_NAME (free__array__) (struct DYNARRAY_STRUCT *list)
182{
183#if DYNARRAY_HAVE_SCRATCH
184 if (list->u.dynarray_header.array != list->scratch)
185 free (list->u.dynarray_header.array);
186#else
187 free (list->u.dynarray_header.array);
188#endif
189}
190
191/* Public functions. */
192
193/* Initialize a dynamic array object. This must be called before any
194 use of the object. */
195__attribute_nonnull__ ((1))
196static void
197DYNARRAY_NAME (init) (struct DYNARRAY_STRUCT *list)
198{
199 list->u.dynarray_header.used = 0;
200 list->u.dynarray_header.allocated = DYNARRAY_INITIAL_SIZE;
201 list->u.dynarray_header.array = DYNARRAY_SCRATCH (list);
202}
203
204/* Deallocate the dynamic array and its elements. */
205__attribute_maybe_unused__ __attribute_nonnull__ ((1))
206static void
207DYNARRAY_FREE (struct DYNARRAY_STRUCT *list)
208{
209 DYNARRAY_NAME (free__elements__)
210 (list->u.dynarray_header.array, list->u.dynarray_header.used);
211 DYNARRAY_NAME (free__array__) (list);
212 DYNARRAY_NAME (init) (list);
213}
214
215/* Return true if the dynamic array is in an error state. */
216__attribute_nonnull__ ((1))
217static inline bool
218DYNARRAY_NAME (has_failed) (const struct DYNARRAY_STRUCT *list)
219{
220 return list->u.dynarray_header.allocated == __dynarray_error_marker ();
221}
222
223/* Mark the dynamic array as failed. All elements are deallocated as
224 a side effect. */
225__attribute_nonnull__ ((1))
226static void
227DYNARRAY_NAME (mark_failed) (struct DYNARRAY_STRUCT *list)
228{
229 DYNARRAY_NAME (free__elements__)
230 (list->u.dynarray_header.array, list->u.dynarray_header.used);
231 DYNARRAY_NAME (free__array__) (list);
232 list->u.dynarray_header.array = DYNARRAY_SCRATCH (list);
233 list->u.dynarray_header.used = 0;
234 list->u.dynarray_header.allocated = __dynarray_error_marker ();
235}
236
237/* Return the number of elements which have been added to the dynamic
238 array. */
239__attribute_nonnull__ ((1))
240static inline size_t
241DYNARRAY_NAME (size) (const struct DYNARRAY_STRUCT *list)
242{
243 return list->u.dynarray_header.used;
244}
245
246/* Return a pointer to the array element at INDEX. Terminate the
247 process if INDEX is out of bounds. */
248__attribute_nonnull__ ((1))
249static inline DYNARRAY_ELEMENT *
250DYNARRAY_NAME (at) (struct DYNARRAY_STRUCT *list, size_t index)
251{
252 if (__glibc_unlikely (index >= DYNARRAY_NAME (size) (list)))
253 __libc_dynarray_at_failure (DYNARRAY_NAME (size) (list), index);
254 return list->u.dynarray_header.array + index;
255}
256
257/* Return a pointer to the first array element, if any. For a
258 zero-length array, the pointer can be NULL even though the dynamic
259 array has not entered the failure state. */
260__attribute_nonnull__ ((1))
261static inline DYNARRAY_ELEMENT *
262DYNARRAY_NAME (begin) (struct DYNARRAY_STRUCT *list)
263{
264 return list->u.dynarray_header.array;
265}
266
267/* Return a pointer one element past the last array element. For a
268 zero-length array, the pointer can be NULL even though the dynamic
269 array has not entered the failure state. */
270__attribute_nonnull__ ((1))
271static inline DYNARRAY_ELEMENT *
272DYNARRAY_NAME (end) (struct DYNARRAY_STRUCT *list)
273{
274 return list->u.dynarray_header.array + list->u.dynarray_header.used;
275}
276
277/* Internal function. Slow path for the add function below. */
278static void
279DYNARRAY_NAME (add__) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)
280{
281 if (__glibc_unlikely
282 (!__libc_dynarray_emplace_enlarge (&list->u.dynarray_abstract,
283 DYNARRAY_SCRATCH (list),
284 sizeof (DYNARRAY_ELEMENT))))
285 {
286 DYNARRAY_NAME (mark_failed) (list);
287 return;
288 }
289
290 /* Copy the new element and increase the array length. */
291 list->u.dynarray_header.array[list->u.dynarray_header.used++] = item;
292}
293
294/* Add ITEM at the end of the array, enlarging it by one element.
295 Mark *LIST as failed if the dynamic array allocation size cannot be
296 increased. */
297__attribute_nonnull__ ((1))
298static inline void
299DYNARRAY_NAME (add) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)
300{
301 /* Do nothing in case of previous error. */
302 if (DYNARRAY_NAME (has_failed) (list))
303 return;
304
305 /* Enlarge the array if necessary. */
306 if (__glibc_unlikely (list->u.dynarray_header.used
307 == list->u.dynarray_header.allocated))
308 {
309 DYNARRAY_NAME (add__) (list, item);
310 return;
311 }
312
313 /* Copy the new element and increase the array length. */
314 list->u.dynarray_header.array[list->u.dynarray_header.used++] = item;
315}
316
317/* Internal function. Building block for the emplace functions below.
318 Assumes space for one more element in *LIST. */
319static inline DYNARRAY_ELEMENT *
320DYNARRAY_NAME (emplace__tail__) (struct DYNARRAY_STRUCT *list)
321{
322 DYNARRAY_ELEMENT *result
323 = &list->u.dynarray_header.array[list->u.dynarray_header.used];
324 ++list->u.dynarray_header.used;
325#if defined (DYNARRAY_ELEMENT_INIT)
326 DYNARRAY_ELEMENT_INIT (result);
327#elif defined (DYNARRAY_ELEMENT_FREE)
328 memset (result, 0, sizeof (*result));
329#endif
330 return result;
331}
332
333/* Internal function. Slow path for the emplace function below. */
334static DYNARRAY_ELEMENT *
335DYNARRAY_NAME (emplace__) (struct DYNARRAY_STRUCT *list)
336{
337 if (__glibc_unlikely
338 (!__libc_dynarray_emplace_enlarge (&list->u.dynarray_abstract,
339 DYNARRAY_SCRATCH (list),
340 sizeof (DYNARRAY_ELEMENT))))
341 {
342 DYNARRAY_NAME (mark_failed) (list);
343 return NULL;
344 }
345 return DYNARRAY_NAME (emplace__tail__) (list);
346}
347
348/* Allocate a place for a new element in *LIST and return a pointer to
349 it. The pointer can be NULL if the dynamic array cannot be
350 enlarged due to a memory allocation failure. */
351__attribute_maybe_unused__ __attribute_warn_unused_result__
352__attribute_nonnull__ ((1))
353static
354/* Avoid inlining with the larger initialization code. */
355#if !(defined (DYNARRAY_ELEMENT_INIT) || defined (DYNARRAY_ELEMENT_FREE))
356inline
357#endif
358DYNARRAY_ELEMENT *
359DYNARRAY_NAME (emplace) (struct DYNARRAY_STRUCT *list)
360{
361 /* Do nothing in case of previous error. */
362 if (DYNARRAY_NAME (has_failed) (list))
363 return NULL;
364
365 /* Enlarge the array if necessary. */
366 if (__glibc_unlikely (list->u.dynarray_header.used
367 == list->u.dynarray_header.allocated))
368 return (DYNARRAY_NAME (emplace__) (list));
369 return DYNARRAY_NAME (emplace__tail__) (list);
370}
371
372/* Change the size of *LIST to SIZE. If SIZE is larger than the
373 existing size, new elements are added (which can be initialized).
374 Otherwise, the list is truncated, and elements are freed. Return
375 false on memory allocation failure (and mark *LIST as failed). */
376__attribute_maybe_unused__ __attribute_nonnull__ ((1))
377static bool
378DYNARRAY_NAME (resize) (struct DYNARRAY_STRUCT *list, size_t size)
379{
380 if (size > list->u.dynarray_header.used)
381 {
382 bool ok;
383#if defined (DYNARRAY_ELEMENT_INIT)
384 /* The new elements have to be initialized. */
385 size_t old_size = list->u.dynarray_header.used;
386 ok = __libc_dynarray_resize (&list->u.dynarray_abstract,
387 size, DYNARRAY_SCRATCH (list),
388 sizeof (DYNARRAY_ELEMENT));
389 if (ok)
390 for (size_t i = old_size; i < size; ++i)
391 {
392 DYNARRAY_ELEMENT_INIT (&list->u.dynarray_header.array[i]);
393 }
394#elif defined (DYNARRAY_ELEMENT_FREE)
395 /* Zero initialization is needed so that the elements can be
396 safely freed. */
397 ok = __libc_dynarray_resize_clear
398 (&list->u.dynarray_abstract, size,
399 DYNARRAY_SCRATCH (list), sizeof (DYNARRAY_ELEMENT));
400#else
401 ok = __libc_dynarray_resize (&list->u.dynarray_abstract,
402 size, DYNARRAY_SCRATCH (list),
403 sizeof (DYNARRAY_ELEMENT));
404#endif
405 if (__glibc_unlikely (!ok))
406 DYNARRAY_NAME (mark_failed) (list);
407 return ok;
408 }
409 else
410 {
411 /* The list has shrunk in size. Free the removed elements. */
412 DYNARRAY_NAME (free__elements__)
413 (list->u.dynarray_header.array + size,
414 list->u.dynarray_header.used - size);
415 list->u.dynarray_header.used = size;
416 return true;
417 }
418}
419
420/* Remove the last element of LIST if it is present. */
421__attribute_maybe_unused__ __attribute_nonnull__ ((1))
422static void
423DYNARRAY_NAME (remove_last) (struct DYNARRAY_STRUCT *list)
424{
425 /* used > 0 implies that the array is the non-failed state. */
426 if (list->u.dynarray_header.used > 0)
427 {
428 size_t new_length = list->u.dynarray_header.used - 1;
429#ifdef DYNARRAY_ELEMENT_FREE
430 DYNARRAY_ELEMENT_FREE (&list->u.dynarray_header.array[new_length]);
431#endif
432 list->u.dynarray_header.used = new_length;
433 }
434}
435
436/* Remove all elements from the list. The elements are freed, but the
437 list itself is not. */
438__attribute_maybe_unused__ __attribute_nonnull__ ((1))
439static void
440DYNARRAY_NAME (clear) (struct DYNARRAY_STRUCT *list)
441{
442 /* free__elements__ does nothing if the list is in the failed
443 state. */
444 DYNARRAY_NAME (free__elements__)
445 (list->u.dynarray_header.array, list->u.dynarray_header.used);
446 list->u.dynarray_header.used = 0;
447}
448
449#ifdef DYNARRAY_FINAL_TYPE
450/* Transfer the dynamic array to a permanent location at *RESULT.
451 Returns true on success on false on allocation failure. In either
452 case, *LIST is re-initialized and can be reused. A NULL pointer is
453 stored in *RESULT if LIST refers to an empty list. On success, the
454 pointer in *RESULT is heap-allocated and must be deallocated using
455 free. */
456__attribute_maybe_unused__ __attribute_warn_unused_result__
457__attribute_nonnull__ ((1, 2))
458static bool
459DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list,
460 DYNARRAY_FINAL_TYPE *result)
461{
462 struct dynarray_finalize_result res;
463 if (__libc_dynarray_finalize (&list->u.dynarray_abstract,
464 DYNARRAY_SCRATCH (list),
465 sizeof (DYNARRAY_ELEMENT), &res))
466 {
467 /* On success, the result owns all the data. */
468 DYNARRAY_NAME (init) (list);
469 *result = (DYNARRAY_FINAL_TYPE) { res.array, res.length };
470 return true;
471 }
472 else
473 {
474 /* On error, we need to free all data. */
475 DYNARRAY_FREE (list);
476 errno = ENOMEM;
477 return false;
478 }
479}
480#else /* !DYNARRAY_FINAL_TYPE */
481/* Transfer the dynamic array to a heap-allocated array and return a
482 pointer to it. The pointer is NULL if memory allocation fails, or
483 if the array is empty, so this function should be used only for
484 arrays which are known not be empty (usually because they always
485 have a sentinel at the end). If LENGTHP is not NULL, the array
486 length is written to *LENGTHP. *LIST is re-initialized and can be
487 reused. */
488__attribute_maybe_unused__ __attribute_warn_unused_result__
489__attribute_nonnull__ ((1))
490static DYNARRAY_ELEMENT *
491DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list, size_t *lengthp)
492{
493 struct dynarray_finalize_result res;
494 if (__libc_dynarray_finalize (&list->u.dynarray_abstract,
495 DYNARRAY_SCRATCH (list),
496 sizeof (DYNARRAY_ELEMENT), &res))
497 {
498 /* On success, the result owns all the data. */
499 DYNARRAY_NAME (init) (list);
500 if (lengthp != NULL)
501 *lengthp = res.length;
502 return res.array;
503 }
504 else
505 {
506 /* On error, we need to free all data. */
507 DYNARRAY_FREE (list);
508 errno = ENOMEM;
509 return NULL;
510 }
511}
512#endif /* !DYNARRAY_FINAL_TYPE */
513
514/* Undo macro definitions. */
515
516#undef DYNARRAY_CONCAT0
517#undef DYNARRAY_CONCAT1
518#undef DYNARRAY_NAME
519#undef DYNARRAY_SCRATCH
520#undef DYNARRAY_HAVE_SCRATCH
521
522#undef DYNARRAY_STRUCT
523#undef DYNARRAY_ELEMENT
524#undef DYNARRAY_PREFIX
525#undef DYNARRAY_ELEMENT_FREE
526#undef DYNARRAY_ELEMENT_INIT
527#undef DYNARRAY_INITIAL_SIZE
528#undef DYNARRAY_FINAL_TYPE
diff --git a/gl/malloc/dynarray.h b/gl/malloc/dynarray.h
new file mode 100644
index 0000000..a9a3b08
--- /dev/null
+++ b/gl/malloc/dynarray.h
@@ -0,0 +1,177 @@
1/* Type-safe arrays which grow dynamically. Shared definitions.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19/* To use the dynarray facility, you need to include
20 <malloc/dynarray-skeleton.c> and define the parameter macros
21 documented in that file.
22
23 A minimal example which provides a growing list of integers can be
24 defined like this:
25
26 struct int_array
27 {
28 // Pointer to result array followed by its length,
29 // as required by DYNARRAY_FINAL_TYPE.
30 int *array;
31 size_t length;
32 };
33
34 #define DYNARRAY_STRUCT dynarray_int
35 #define DYNARRAY_ELEMENT int
36 #define DYNARRAY_PREFIX dynarray_int_
37 #define DYNARRAY_FINAL_TYPE struct int_array
38 #include <malloc/dynarray-skeleton.c>
39
40 To create a three-element array with elements 1, 2, 3, use this
41 code:
42
43 struct dynarray_int dyn;
44 dynarray_int_init (&dyn);
45 for (int i = 1; i <= 3; ++i)
46 {
47 int *place = dynarray_int_emplace (&dyn);
48 assert (place != NULL);
49 *place = i;
50 }
51 struct int_array result;
52 bool ok = dynarray_int_finalize (&dyn, &result);
53 assert (ok);
54 assert (result.length == 3);
55 assert (result.array[0] == 1);
56 assert (result.array[1] == 2);
57 assert (result.array[2] == 3);
58 free (result.array);
59
60 If the elements contain resources which must be freed, define
61 DYNARRAY_ELEMENT_FREE appropriately, like this:
62
63 struct str_array
64 {
65 char **array;
66 size_t length;
67 };
68
69 #define DYNARRAY_STRUCT dynarray_str
70 #define DYNARRAY_ELEMENT char *
71 #define DYNARRAY_ELEMENT_FREE(ptr) free (*ptr)
72 #define DYNARRAY_PREFIX dynarray_str_
73 #define DYNARRAY_FINAL_TYPE struct str_array
74 #include <malloc/dynarray-skeleton.c>
75
76 Compared to scratch buffers, dynamic arrays have the following
77 features:
78
79 - They have an element type, and are not just an untyped buffer of
80 bytes.
81
82 - When growing, previously stored elements are preserved. (It is
83 expected that scratch_buffer_grow_preserve and
84 scratch_buffer_set_array_size eventually go away because all
85 current users are moved to dynamic arrays.)
86
87 - Scratch buffers have a more aggressive growth policy because
88 growing them typically means a retry of an operation (across an
89 NSS service module boundary), which is expensive.
90
91 - For the same reason, scratch buffers have a much larger initial
92 stack allocation. */
93
94#ifndef _DYNARRAY_H
95#define _DYNARRAY_H
96
97#include <stddef.h>
98#include <string.h>
99
100struct dynarray_header
101{
102 size_t used;
103 size_t allocated;
104 void *array;
105};
106
107/* Marker used in the allocated member to indicate that an error was
108 encountered. */
109static inline size_t
110__dynarray_error_marker (void)
111{
112 return -1;
113}
114
115/* Internal function. See the has_failed function in
116 dynarray-skeleton.c. */
117static inline bool
118__dynarray_error (struct dynarray_header *list)
119{
120 return list->allocated == __dynarray_error_marker ();
121}
122
123/* Internal function. Enlarge the dynamically allocated area of the
124 array to make room for one more element. SCRATCH is a pointer to
125 the scratch area (which is not heap-allocated and must not be
126 freed). ELEMENT_SIZE is the size, in bytes, of one element.
127 Return false on failure, true on success. */
128bool __libc_dynarray_emplace_enlarge (struct dynarray_header *,
129 void *scratch, size_t element_size);
130
131/* Internal function. Enlarge the dynamically allocated area of the
132 array to make room for at least SIZE elements (which must be larger
133 than the existing used part of the dynamic array). SCRATCH is a
134 pointer to the scratch area (which is not heap-allocated and must
135 not be freed). ELEMENT_SIZE is the size, in bytes, of one element.
136 Return false on failure, true on success. */
137bool __libc_dynarray_resize (struct dynarray_header *, size_t size,
138 void *scratch, size_t element_size);
139
140/* Internal function. Like __libc_dynarray_resize, but clear the new
141 part of the dynamic array. */
142bool __libc_dynarray_resize_clear (struct dynarray_header *, size_t size,
143 void *scratch, size_t element_size);
144
145/* Internal type. */
146struct dynarray_finalize_result
147{
148 void *array;
149 size_t length;
150};
151
152/* Internal function. Copy the dynamically-allocated area to an
153 explicitly-sized heap allocation. SCRATCH is a pointer to the
154 embedded scratch space. ELEMENT_SIZE is the size, in bytes, of the
155 element type. On success, true is returned, and pointer and length
156 are written to *RESULT. On failure, false is returned. The caller
157 has to take care of some of the memory management; this function is
158 expected to be called from dynarray-skeleton.c. */
159bool __libc_dynarray_finalize (struct dynarray_header *list, void *scratch,
160 size_t element_size,
161 struct dynarray_finalize_result *result);
162
163
164/* Internal function. Terminate the process after an index error.
165 SIZE is the number of elements of the dynamic array. INDEX is the
166 lookup index which triggered the failure. */
167_Noreturn void __libc_dynarray_at_failure (size_t size, size_t index);
168
169#ifndef _ISOMAC
170libc_hidden_proto (__libc_dynarray_emplace_enlarge)
171libc_hidden_proto (__libc_dynarray_resize)
172libc_hidden_proto (__libc_dynarray_resize_clear)
173libc_hidden_proto (__libc_dynarray_finalize)
174libc_hidden_proto (__libc_dynarray_at_failure)
175#endif
176
177#endif /* _DYNARRAY_H */
diff --git a/gl/malloc/dynarray_at_failure.c b/gl/malloc/dynarray_at_failure.c
new file mode 100644
index 0000000..ebc9310
--- /dev/null
+++ b/gl/malloc/dynarray_at_failure.c
@@ -0,0 +1,40 @@
1/* Report an dynamic array index out of bounds condition.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21# include <stdlib.h>
22#endif
23
24#include <dynarray.h>
25#include <stdio.h>
26
27void
28__libc_dynarray_at_failure (size_t size, size_t index)
29{
30#ifdef _LIBC
31 char buf[200];
32 __snprintf (buf, sizeof (buf), "Fatal glibc error: "
33 "array index %zu not less than array length %zu\n",
34 index, size);
35 __libc_fatal (buf);
36#else
37 abort ();
38#endif
39}
40libc_hidden_def (__libc_dynarray_at_failure)
diff --git a/gl/malloc/dynarray_emplace_enlarge.c b/gl/malloc/dynarray_emplace_enlarge.c
new file mode 100644
index 0000000..7da5393
--- /dev/null
+++ b/gl/malloc/dynarray_emplace_enlarge.c
@@ -0,0 +1,77 @@
1/* Increase the size of a dynamic array in preparation of an emplace operation.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <dynarray.h>
24#include <errno.h>
25#include <intprops.h>
26#include <stdlib.h>
27#include <string.h>
28
29bool
30__libc_dynarray_emplace_enlarge (struct dynarray_header *list,
31 void *scratch, size_t element_size)
32{
33 size_t new_allocated;
34 if (list->allocated == 0)
35 {
36 /* No scratch buffer provided. Choose a reasonable default
37 size. */
38 if (element_size < 4)
39 new_allocated = 16;
40 else if (element_size < 8)
41 new_allocated = 8;
42 else
43 new_allocated = 4;
44 }
45 else
46 /* Increase the allocated size, using an exponential growth
47 policy. */
48 {
49 new_allocated = list->allocated + list->allocated / 2 + 1;
50 if (new_allocated <= list->allocated)
51 {
52 /* Overflow. */
53 __set_errno (ENOMEM);
54 return false;
55 }
56 }
57
58 size_t new_size;
59 if (INT_MULTIPLY_WRAPV (new_allocated, element_size, &new_size))
60 return false;
61 void *new_array;
62 if (list->array == scratch)
63 {
64 /* The previous array was not heap-allocated. */
65 new_array = malloc (new_size);
66 if (new_array != NULL && list->array != NULL)
67 memcpy (new_array, list->array, list->used * element_size);
68 }
69 else
70 new_array = realloc (list->array, new_size);
71 if (new_array == NULL)
72 return false;
73 list->array = new_array;
74 list->allocated = new_allocated;
75 return true;
76}
77libc_hidden_def (__libc_dynarray_emplace_enlarge)
diff --git a/gl/malloc/dynarray_finalize.c b/gl/malloc/dynarray_finalize.c
new file mode 100644
index 0000000..673595a
--- /dev/null
+++ b/gl/malloc/dynarray_finalize.c
@@ -0,0 +1,66 @@
1/* Copy the dynamically-allocated area to an explicitly-sized heap allocation.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <dynarray.h>
24#include <stdlib.h>
25#include <string.h>
26
27bool
28__libc_dynarray_finalize (struct dynarray_header *list,
29 void *scratch, size_t element_size,
30 struct dynarray_finalize_result *result)
31{
32 if (__dynarray_error (list))
33 /* The caller will reported the deferred error. */
34 return false;
35
36 size_t used = list->used;
37
38 /* Empty list. */
39 if (used == 0)
40 {
41 /* An empty list could still be backed by a heap-allocated
42 array. Free it if necessary. */
43 if (list->array != scratch)
44 free (list->array);
45 *result = (struct dynarray_finalize_result) { NULL, 0 };
46 return true;
47 }
48
49 size_t allocation_size = used * element_size;
50 void *heap_array = malloc (allocation_size);
51 if (heap_array != NULL)
52 {
53 /* The new array takes ownership of the strings. */
54 if (list->array != NULL)
55 memcpy (heap_array, list->array, allocation_size);
56 if (list->array != scratch)
57 free (list->array);
58 *result = (struct dynarray_finalize_result)
59 { .array = heap_array, .length = used };
60 return true;
61 }
62 else
63 /* The caller will perform the freeing operation. */
64 return false;
65}
66libc_hidden_def (__libc_dynarray_finalize)
diff --git a/gl/malloc/dynarray_resize.c b/gl/malloc/dynarray_resize.c
new file mode 100644
index 0000000..7ecd4de
--- /dev/null
+++ b/gl/malloc/dynarray_resize.c
@@ -0,0 +1,68 @@
1/* Increase the size of a dynamic array.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <dynarray.h>
24#include <errno.h>
25#include <intprops.h>
26#include <stdlib.h>
27#include <string.h>
28
29bool
30__libc_dynarray_resize (struct dynarray_header *list, size_t size,
31 void *scratch, size_t element_size)
32{
33 /* The existing allocation provides sufficient room. */
34 if (size <= list->allocated)
35 {
36 list->used = size;
37 return true;
38 }
39
40 /* Otherwise, use size as the new allocation size. The caller is
41 expected to provide the final size of the array, so there is no
42 over-allocation here. */
43
44 size_t new_size_bytes;
45 if (INT_MULTIPLY_WRAPV (size, element_size, &new_size_bytes))
46 {
47 /* Overflow. */
48 __set_errno (ENOMEM);
49 return false;
50 }
51 void *new_array;
52 if (list->array == scratch)
53 {
54 /* The previous array was not heap-allocated. */
55 new_array = malloc (new_size_bytes);
56 if (new_array != NULL && list->array != NULL)
57 memcpy (new_array, list->array, list->used * element_size);
58 }
59 else
60 new_array = realloc (list->array, new_size_bytes);
61 if (new_array == NULL)
62 return false;
63 list->array = new_array;
64 list->allocated = size;
65 list->used = size;
66 return true;
67}
68libc_hidden_def (__libc_dynarray_resize)
diff --git a/gl/malloc/dynarray_resize_clear.c b/gl/malloc/dynarray_resize_clear.c
new file mode 100644
index 0000000..bb23c52
--- /dev/null
+++ b/gl/malloc/dynarray_resize_clear.c
@@ -0,0 +1,39 @@
1/* Increase the size of a dynamic array and clear the new part.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _LIBC
20# include <libc-config.h>
21#endif
22
23#include <dynarray.h>
24#include <string.h>
25
26bool
27__libc_dynarray_resize_clear (struct dynarray_header *list, size_t size,
28 void *scratch, size_t element_size)
29{
30 size_t old_size = list->used;
31 if (!__libc_dynarray_resize (list, size, scratch, element_size))
32 return false;
33 /* __libc_dynarray_resize already checked for overflow. */
34 char *array = list->array;
35 memset (array + (old_size * element_size), 0,
36 (size - old_size) * element_size);
37 return true;
38}
39libc_hidden_def (__libc_dynarray_resize_clear)
diff --git a/gl/malloca.c b/gl/malloca.c
index 311be56..f055b1e 100644
--- a/gl/malloca.c
+++ b/gl/malloca.c
@@ -1,19 +1,19 @@
1/* Safe automatic memory allocation. 1/* Safe automatic memory allocation.
2 Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2003, 2006-2007, 2009-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003. 3 Written by Bruno Haible <bruno@clisp.org>, 2003, 2018.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#define _GL_USE_STDLIB_ALLOC 1 18#define _GL_USE_STDLIB_ALLOC 1
19#include <config.h> 19#include <config.h>
@@ -21,82 +21,56 @@
21/* Specification. */ 21/* Specification. */
22#include "malloca.h" 22#include "malloca.h"
23 23
24#include <stdint.h> 24#include <stdckdint.h>
25 25
26#include "verify.h" 26#include "idx.h"
27 27
28/* The speed critical point in this file is freea() applied to an alloca() 28/* The speed critical point in this file is freea() applied to an alloca()
29 result: it must be fast, to match the speed of alloca(). The speed of 29 result: it must be fast, to match the speed of alloca(). The speed of
30 mmalloca() and freea() in the other case are not critical, because they 30 mmalloca() and freea() in the other case are not critical, because they
31 are only invoked for big memory sizes. */ 31 are only invoked for big memory sizes.
32 32 Here we use a bit in the address as an indicator, an idea by Ondřej Bílka.
33#if HAVE_ALLOCA 33 malloca() can return three types of pointers:
34 34 - Pointers ≡ 0 mod 2*sa_alignment_max come from stack allocation.
35/* Store the mmalloca() results in a hash table. This is needed to reliably 35 - Pointers ≡ sa_alignment_max mod 2*sa_alignment_max come from heap
36 distinguish a mmalloca() result and an alloca() result. 36 allocation.
37 37 - NULL comes from a failed heap allocation. */
38 Although it is possible that the same pointer is returned by alloca() and 38
39 by mmalloca() at different times in the same application, it does not lead 39/* Type for holding very small pointer differences. */
40 to a bug in freea(), because: 40typedef unsigned char small_t;
41 - Before a pointer returned by alloca() can point into malloc()ed memory, 41/* Verify that it is wide enough. */
42 the function must return, and once this has happened the programmer must 42static_assert (2 * sa_alignment_max - 1 <= (small_t) -1);
43 not call freea() on it anyway.
44 - Before a pointer returned by mmalloca() can point into the stack, it
45 must be freed. The only function that can free it is freea(), and
46 when freea() frees it, it also removes it from the hash table. */
47
48#define MAGIC_NUMBER 0x1415fb4a
49#define MAGIC_SIZE sizeof (int)
50/* This is how the header info would look like without any alignment
51 considerations. */
52struct preliminary_header { void *next; int magic; };
53/* But the header's size must be a multiple of sa_alignment_max. */
54#define HEADER_SIZE \
55 (((sizeof (struct preliminary_header) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max)
56union header {
57 void *next;
58 struct {
59 char room[HEADER_SIZE - MAGIC_SIZE];
60 int word;
61 } magic;
62};
63verify (HEADER_SIZE == sizeof (union header));
64/* We make the hash table quite big, so that during lookups the probability
65 of empty hash buckets is quite high. There is no need to make the hash
66 table resizable, because when the hash table gets filled so much that the
67 lookup becomes slow, it means that the application has memory leaks. */
68#define HASH_TABLE_SIZE 257
69static void * mmalloca_results[HASH_TABLE_SIZE];
70
71#endif
72 43
73void * 44void *
74mmalloca (size_t n) 45mmalloca (size_t n)
75{ 46{
76#if HAVE_ALLOCA 47#if HAVE_ALLOCA
77 /* Allocate one more word, that serves as an indicator for malloc()ed 48 /* Allocate one more word, used to determine the address to pass to freea(),
78 memory, so that freea() of an alloca() result is fast. */ 49 and room for the alignment ≡ sa_alignment_max mod 2*sa_alignment_max. */
79 size_t nplus = n + HEADER_SIZE; 50 uintptr_t alignment2_mask = 2 * sa_alignment_max - 1;
80 51 int plus = sizeof (small_t) + alignment2_mask;
81 if (nplus >= n) 52 idx_t nplus;
53 if (!ckd_add (&nplus, n, plus) && !xalloc_oversized (nplus, 1))
82 { 54 {
83 void *p = malloc (nplus); 55 char *mem = (char *) malloc (nplus);
84 56
85 if (p != NULL) 57 if (mem != NULL)
86 { 58 {
87 size_t slot; 59 uintptr_t umem = (uintptr_t)mem, umemplus;
88 union header *h = p; 60 /* The ckd_add avoids signed integer overflow on
89 61 theoretical platforms where UINTPTR_MAX <= INT_MAX. */
90 p = h + 1; 62 ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
91 63 idx_t offset = ((umemplus & ~alignment2_mask)
92 /* Put a magic number into the indicator word. */ 64 + sa_alignment_max - umem);
93 h->magic.word = MAGIC_NUMBER; 65 void *vp = mem + offset;
94 66 small_t *p = vp;
95 /* Enter p into the hash table. */ 67 /* Here p >= mem + sizeof (small_t),
96 slot = (uintptr_t) p % HASH_TABLE_SIZE; 68 and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
97 h->next = mmalloca_results[slot]; 69 hence p + n <= mem + nplus.
98 mmalloca_results[slot] = p; 70 So, the memory range [p, p+n) lies in the allocated memory range
99 71 [mem, mem + nplus). */
72 p[-1] = offset;
73 /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
100 return p; 74 return p;
101 } 75 }
102 } 76 }
@@ -115,35 +89,24 @@ mmalloca (size_t n)
115void 89void
116freea (void *p) 90freea (void *p)
117{ 91{
118 /* mmalloca() may have returned NULL. */ 92 /* Check argument. */
119 if (p != NULL) 93 if ((uintptr_t) p & (sa_alignment_max - 1))
120 { 94 {
121 /* Attempt to quickly distinguish the mmalloca() result - which has 95 /* p was not the result of a malloca() call. Invalid argument. */
122 a magic indicator word - and the alloca() result - which has an 96 abort ();
123 uninitialized indicator word. It is for this test that sa_increment 97 }
124 additional bytes are allocated in the alloca() case. */ 98 /* Determine whether p was a non-NULL pointer returned by mmalloca(). */
125 if (((int *) p)[-1] == MAGIC_NUMBER) 99 if ((uintptr_t) p & sa_alignment_max)
126 { 100 {
127 /* Looks like a mmalloca() result. To see whether it really is one, 101 void *mem = (char *) p - ((small_t *) p)[-1];
128 perform a lookup in the hash table. */ 102 free (mem);
129 size_t slot = (uintptr_t) p % HASH_TABLE_SIZE;
130 void **chain = &mmalloca_results[slot];
131 for (; *chain != NULL;)
132 {
133 union header *h = p;
134 if (*chain == p)
135 {
136 /* Found it. Remove it from the hash table and free it. */
137 union header *p_begin = h - 1;
138 *chain = p_begin->next;
139 free (p_begin);
140 return;
141 }
142 h = *chain;
143 chain = &h[-1].next;
144 }
145 }
146 /* At this point, we know it was not a mmalloca() result. */
147 } 103 }
148} 104}
149#endif 105#endif
106
107/*
108 * Hey Emacs!
109 * Local Variables:
110 * coding: utf-8
111 * End:
112 */
diff --git a/gl/malloca.h b/gl/malloca.h
index 6fbe45e..325c727 100644
--- a/gl/malloca.h
+++ b/gl/malloca.h
@@ -1,19 +1,19 @@
1/* Safe automatic memory allocation. 1/* Safe automatic memory allocation.
2 Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2003-2007, 2009-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003. 3 Written by Bruno Haible <bruno@clisp.org>, 2003.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _MALLOCA_H 18#ifndef _MALLOCA_H
19#define _MALLOCA_H 19#define _MALLOCA_H
@@ -21,6 +21,9 @@
21#include <alloca.h> 21#include <alloca.h>
22#include <stddef.h> 22#include <stddef.h>
23#include <stdlib.h> 23#include <stdlib.h>
24#include <stdint.h>
25
26#include "xalloc-oversized.h"
24 27
25 28
26#ifdef __cplusplus 29#ifdef __cplusplus
@@ -48,40 +51,37 @@ extern "C" {
48# define safe_alloca(N) ((void) (N), NULL) 51# define safe_alloca(N) ((void) (N), NULL)
49#endif 52#endif
50 53
54/* Free a block of memory allocated through malloca(). */
55#if HAVE_ALLOCA
56extern void freea (void *p);
57#else
58# define freea free
59#endif
60
51/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of 61/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
52 memory allocated on the stack, that must be freed using freea() before 62 memory allocated on the stack, that must be freed using freea() before
53 the function returns. Upon failure, it returns NULL. */ 63 the function returns. Upon failure, it returns NULL. */
54#if HAVE_ALLOCA 64#if HAVE_ALLOCA
55# define malloca(N) \ 65# define malloca(N) \
56 ((N) < 4032 - sa_increment \ 66 ((N) < 4032 - (2 * sa_alignment_max - 1) \
57 ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \ 67 ? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
68 + (2 * sa_alignment_max - 1)) \
69 & ~(uintptr_t)(2 * sa_alignment_max - 1)) \
58 : mmalloca (N)) 70 : mmalloca (N))
59#else 71#else
60# define malloca(N) \ 72# define malloca(N) \
61 mmalloca (N) 73 mmalloca (N)
62#endif 74#endif
63extern void * mmalloca (size_t n); 75extern void *mmalloca (size_t n)
64 76 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (freea, 1)
65/* Free a block of memory allocated through malloca(). */ 77 _GL_ATTRIBUTE_ALLOC_SIZE ((1));
66#if HAVE_ALLOCA
67extern void freea (void *p);
68#else
69# define freea free
70#endif
71 78
72/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S). 79/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
73 It allocates an array of N objects, each with S bytes of memory, 80 It allocates an array of N objects, each with S bytes of memory,
74 on the stack. S must be positive and N must be nonnegative. 81 on the stack. N and S should be nonnegative and free of side effects.
75 The array must be freed using freea() before the function returns. */ 82 The array must be freed using freea() before the function returns. */
76#if 1 83#define nmalloca(n, s) \
77/* Cf. the definition of xalloc_oversized. */ 84 (xalloc_oversized (n, s) ? NULL : malloca ((n) * (size_t) (s)))
78# define nmalloca(n, s) \
79 ((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \
80 ? NULL \
81 : malloca ((n) * (s)))
82#else
83extern void * nmalloca (size_t n, size_t s);
84#endif
85 85
86 86
87#ifdef __cplusplus 87#ifdef __cplusplus
@@ -92,7 +92,7 @@ extern void * nmalloca (size_t n, size_t s);
92/* ------------------- Auxiliary, non-public definitions ------------------- */ 92/* ------------------- Auxiliary, non-public definitions ------------------- */
93 93
94/* Determine the alignment of a type at compile time. */ 94/* Determine the alignment of a type at compile time. */
95#if defined __GNUC__ || defined __IBM__ALIGNOF__ 95#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
96# define sa_alignof __alignof__ 96# define sa_alignof __alignof__
97#elif defined __cplusplus 97#elif defined __cplusplus
98 template <class type> struct sa_alignof_helper { char __slot1; type __slot2; }; 98 template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
@@ -115,19 +115,12 @@ enum
115 among all elementary types. */ 115 among all elementary types. */
116 sa_alignment_long = sa_alignof (long), 116 sa_alignment_long = sa_alignof (long),
117 sa_alignment_double = sa_alignof (double), 117 sa_alignment_double = sa_alignof (double),
118#if HAVE_LONG_LONG_INT
119 sa_alignment_longlong = sa_alignof (long long), 118 sa_alignment_longlong = sa_alignof (long long),
120#endif
121 sa_alignment_longdouble = sa_alignof (long double), 119 sa_alignment_longdouble = sa_alignof (long double),
122 sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1) 120 sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
123#if HAVE_LONG_LONG_INT
124 | (sa_alignment_longlong - 1) 121 | (sa_alignment_longlong - 1)
125#endif
126 | (sa_alignment_longdouble - 1) 122 | (sa_alignment_longdouble - 1)
127 ) + 1, 123 ) + 1
128/* The increment that guarantees room for a magic word must be >= sizeof (int)
129 and a multiple of sa_alignment_max. */
130 sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
131}; 124};
132 125
133#endif /* _MALLOCA_H */ 126#endif /* _MALLOCA_H */
diff --git a/gl/malloca.valgrind b/gl/malloca.valgrind
deleted file mode 100644
index 52f0a50..0000000
--- a/gl/malloca.valgrind
+++ /dev/null
@@ -1,7 +0,0 @@
1# Suppress a valgrind message about use of uninitialized memory in freea().
2# This use is OK because it provides only a speedup.
3{
4 freea
5 Memcheck:Cond
6 fun:freea
7}
diff --git a/gl/math.c b/gl/math.c
index ddb2ded..67cabbc 100644
--- a/gl/math.c
+++ b/gl/math.c
@@ -1,3 +1,22 @@
1/* Inline functions for <math.h>.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
1#include <config.h> 18#include <config.h>
19
2#define _GL_MATH_INLINE _GL_EXTERN_INLINE 20#define _GL_MATH_INLINE _GL_EXTERN_INLINE
3#include "math.h" 21#include "math.h"
22typedef int dummy;
diff --git a/gl/math.in.h b/gl/math.in.h
index 7189819..f3d58af 100644
--- a/gl/math.in.h
+++ b/gl/math.in.h
@@ -1,19 +1,19 @@
1/* A GNU-like <math.h>. 1/* A GNU-like <math.h>.
2 2
3 Copyright (C) 2002-2003, 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2002-2003, 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _@GUARD_PREFIX@_MATH_H 18#ifndef _@GUARD_PREFIX@_MATH_H
19 19
@@ -22,17 +22,50 @@
22#endif 22#endif
23@PRAGMA_COLUMNS@ 23@PRAGMA_COLUMNS@
24 24
25#if defined _GL_INCLUDING_MATH_H
26/* Special invocation convention:
27 - On FreeBSD 12.2 we have a sequence of nested includes
28 <math.h> -> <stdlib.h> -> <sys/wait.h> -> <sys/types.h> -> <sys/select.h>
29 -> <signal.h> -> <pthread.h> -> <stdlib.h> -> <math.h>
30 In this situation, the functions are not yet declared, therefore we cannot
31 provide the C++ aliases. */
32
33#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
34
35#else
36/* Normal invocation convention. */
37
25/* The include_next requires a split double-inclusion guard. */ 38/* The include_next requires a split double-inclusion guard. */
39#define _GL_INCLUDING_MATH_H
26#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@ 40#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
41#undef _GL_INCLUDING_MATH_H
27 42
28#ifndef _@GUARD_PREFIX@_MATH_H 43#ifndef _@GUARD_PREFIX@_MATH_H
29#define _@GUARD_PREFIX@_MATH_H 44#define _@GUARD_PREFIX@_MATH_H
30 45
46/* On OpenVMS, NAN, INFINITY, and HUGEVAL macros are defined in <fp.h>. */
47#if defined __VMS && ! defined NAN
48# include <fp.h>
49#endif
50
51#ifndef _GL_INLINE_HEADER_BEGIN
52 #error "Please include config.h first."
53#endif
31_GL_INLINE_HEADER_BEGIN 54_GL_INLINE_HEADER_BEGIN
32#ifndef _GL_MATH_INLINE 55#ifndef _GL_MATH_INLINE
33# define _GL_MATH_INLINE _GL_INLINE 56# define _GL_MATH_INLINE _GL_INLINE
34#endif 57#endif
35 58
59/* The __attribute__ feature is available in gcc versions 2.5 and later.
60 The attribute __const__ was added in gcc 2.95. */
61#ifndef _GL_ATTRIBUTE_CONST
62# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) || defined __clang__
63# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
64# else
65# define _GL_ATTRIBUTE_CONST /* empty */
66# endif
67#endif
68
36/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 69/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
37 70
38/* The definition of _GL_ARG_NONNULL is copied here. */ 71/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -59,22 +92,24 @@ _gl_cxx_ ## func ## l (long double l) \
59{ \ 92{ \
60 return func (l); \ 93 return func (l); \
61} 94}
62# define _GL_MATH_CXX_REAL_FLOATING_DECL_2(func) \ 95# define _GL_MATH_CXX_REAL_FLOATING_DECL_2(func,rpl_func,rettype) \
63inline int \ 96_GL_BEGIN_NAMESPACE \
64func (float f) \ 97inline rettype \
98rpl_func (float f) \
65{ \ 99{ \
66 return _gl_cxx_ ## func ## f (f); \ 100 return _gl_cxx_ ## func ## f (f); \
67} \ 101} \
68inline int \ 102inline rettype \
69func (double d) \ 103rpl_func (double d) \
70{ \ 104{ \
71 return _gl_cxx_ ## func ## d (d); \ 105 return _gl_cxx_ ## func ## d (d); \
72} \ 106} \
73inline int \ 107inline rettype \
74func (long double l) \ 108rpl_func (long double l) \
75{ \ 109{ \
76 return _gl_cxx_ ## func ## l (l); \ 110 return _gl_cxx_ ## func ## l (l); \
77} 111} \
112_GL_END_NAMESPACE
78#endif 113#endif
79 114
80/* Helper macros to define a portability warning for the 115/* Helper macros to define a portability warning for the
@@ -82,27 +117,27 @@ func (long double l) \
82 classification macros with an argument of real-floating (that is, 117 classification macros with an argument of real-floating (that is,
83 one of float, double, or long double). */ 118 one of float, double, or long double). */
84#define _GL_WARN_REAL_FLOATING_DECL(func) \ 119#define _GL_WARN_REAL_FLOATING_DECL(func) \
85_GL_MATH_INLINE int \ 120_GL_MATH_INLINE int \
86rpl_ ## func ## f (float f) \ 121_GL_WARN_ON_USE_ATTRIBUTE (#func " is unportable - " \
87{ \ 122 "use gnulib module " #func " for portability") \
88 return func (f); \ 123rpl_ ## func ## f (float f) \
89} \ 124{ \
90_GL_MATH_INLINE int \ 125 return func (f); \
91rpl_ ## func ## d (double d) \ 126} \
92{ \ 127_GL_MATH_INLINE int \
93 return func (d); \ 128_GL_WARN_ON_USE_ATTRIBUTE (#func " is unportable - " \
94} \ 129 "use gnulib module " #func " for portability") \
95_GL_MATH_INLINE int \ 130rpl_ ## func ## d (double d) \
96rpl_ ## func ## l (long double l) \ 131{ \
97{ \ 132 return func (d); \
98 return func (l); \ 133} \
99} \ 134_GL_MATH_INLINE int \
100_GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \ 135_GL_WARN_ON_USE_ATTRIBUTE (#func " is unportable - " \
101 "use gnulib module " #func " for portability"); \ 136 "use gnulib module " #func " for portability") \
102_GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \ 137rpl_ ## func ## l (long double l) \
103 "use gnulib module " #func " for portability"); \ 138{ \
104_GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \ 139 return func (l); \
105 "use gnulib module " #func " for portability") 140}
106#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \ 141#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \
107 (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \ 142 (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \
108 : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \ 143 : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \
@@ -184,8 +219,17 @@ _NaN ()
184#endif 219#endif
185 220
186 221
187/* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined. */ 222#if defined FP_ILOGB0 && defined FP_ILOGBNAN
188#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN) 223 /* Ensure FP_ILOGB0 and FP_ILOGBNAN are correct. */
224# if defined __HAIKU__
225 /* Haiku: match what ilogb() does */
226# undef FP_ILOGB0
227# undef FP_ILOGBNAN
228# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
229# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
230# endif
231#else
232 /* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined. */
189# if defined __NetBSD__ || defined __sgi 233# if defined __NetBSD__ || defined __sgi
190 /* NetBSD, IRIX 6.5: match what ilogb() does */ 234 /* NetBSD, IRIX 6.5: match what ilogb() does */
191# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */ 235# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
@@ -207,11 +251,20 @@ _NaN ()
207 251
208 252
209#if @GNULIB_ACOSF@ 253#if @GNULIB_ACOSF@
210# if !@HAVE_ACOSF@ 254# if @REPLACE_ACOSF@
211# undef acosf 255# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
256# undef acosf
257# define acosf rpl_acosf
258# endif
259_GL_FUNCDECL_RPL (acosf, float, (float x));
260_GL_CXXALIAS_RPL (acosf, float, (float x));
261# else
262# if !@HAVE_ACOSF@
263# undef acosf
212_GL_FUNCDECL_SYS (acosf, float, (float x)); 264_GL_FUNCDECL_SYS (acosf, float, (float x));
213# endif 265# endif
214_GL_CXXALIAS_SYS (acosf, float, (float x)); 266_GL_CXXALIAS_SYS (acosf, float, (float x));
267# endif
215_GL_CXXALIASWARN (acosf); 268_GL_CXXALIASWARN (acosf);
216#elif defined GNULIB_POSIXCHECK 269#elif defined GNULIB_POSIXCHECK
217# undef acosf 270# undef acosf
@@ -227,7 +280,9 @@ _GL_WARN_ON_USE (acosf, "acosf is unportable - "
227_GL_FUNCDECL_SYS (acosl, long double, (long double x)); 280_GL_FUNCDECL_SYS (acosl, long double, (long double x));
228# endif 281# endif
229_GL_CXXALIAS_SYS (acosl, long double, (long double x)); 282_GL_CXXALIAS_SYS (acosl, long double, (long double x));
283# if __GLIBC__ >= 2
230_GL_CXXALIASWARN (acosl); 284_GL_CXXALIASWARN (acosl);
285# endif
231#elif defined GNULIB_POSIXCHECK 286#elif defined GNULIB_POSIXCHECK
232# undef acosl 287# undef acosl
233# if HAVE_RAW_DECL_ACOSL 288# if HAVE_RAW_DECL_ACOSL
@@ -238,11 +293,20 @@ _GL_WARN_ON_USE (acosl, "acosl is unportable - "
238 293
239 294
240#if @GNULIB_ASINF@ 295#if @GNULIB_ASINF@
241# if !@HAVE_ASINF@ 296# if @REPLACE_ASINF@
242# undef asinf 297# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
298# undef asinf
299# define asinf rpl_asinf
300# endif
301_GL_FUNCDECL_RPL (asinf, float, (float x));
302_GL_CXXALIAS_RPL (asinf, float, (float x));
303# else
304# if !@HAVE_ASINF@
305# undef asinf
243_GL_FUNCDECL_SYS (asinf, float, (float x)); 306_GL_FUNCDECL_SYS (asinf, float, (float x));
244# endif 307# endif
245_GL_CXXALIAS_SYS (asinf, float, (float x)); 308_GL_CXXALIAS_SYS (asinf, float, (float x));
309# endif
246_GL_CXXALIASWARN (asinf); 310_GL_CXXALIASWARN (asinf);
247#elif defined GNULIB_POSIXCHECK 311#elif defined GNULIB_POSIXCHECK
248# undef asinf 312# undef asinf
@@ -258,7 +322,9 @@ _GL_WARN_ON_USE (asinf, "asinf is unportable - "
258_GL_FUNCDECL_SYS (asinl, long double, (long double x)); 322_GL_FUNCDECL_SYS (asinl, long double, (long double x));
259# endif 323# endif
260_GL_CXXALIAS_SYS (asinl, long double, (long double x)); 324_GL_CXXALIAS_SYS (asinl, long double, (long double x));
325# if __GLIBC__ >= 2
261_GL_CXXALIASWARN (asinl); 326_GL_CXXALIASWARN (asinl);
327# endif
262#elif defined GNULIB_POSIXCHECK 328#elif defined GNULIB_POSIXCHECK
263# undef asinl 329# undef asinl
264# if HAVE_RAW_DECL_ASINL 330# if HAVE_RAW_DECL_ASINL
@@ -269,11 +335,20 @@ _GL_WARN_ON_USE (asinl, "asinl is unportable - "
269 335
270 336
271#if @GNULIB_ATANF@ 337#if @GNULIB_ATANF@
272# if !@HAVE_ATANF@ 338# if @REPLACE_ATANF@
273# undef atanf 339# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
340# undef atanf
341# define atanf rpl_atanf
342# endif
343_GL_FUNCDECL_RPL (atanf, float, (float x));
344_GL_CXXALIAS_RPL (atanf, float, (float x));
345# else
346# if !@HAVE_ATANF@
347# undef atanf
274_GL_FUNCDECL_SYS (atanf, float, (float x)); 348_GL_FUNCDECL_SYS (atanf, float, (float x));
275# endif 349# endif
276_GL_CXXALIAS_SYS (atanf, float, (float x)); 350_GL_CXXALIAS_SYS (atanf, float, (float x));
351# endif
277_GL_CXXALIASWARN (atanf); 352_GL_CXXALIASWARN (atanf);
278#elif defined GNULIB_POSIXCHECK 353#elif defined GNULIB_POSIXCHECK
279# undef atanf 354# undef atanf
@@ -289,7 +364,9 @@ _GL_WARN_ON_USE (atanf, "atanf is unportable - "
289_GL_FUNCDECL_SYS (atanl, long double, (long double x)); 364_GL_FUNCDECL_SYS (atanl, long double, (long double x));
290# endif 365# endif
291_GL_CXXALIAS_SYS (atanl, long double, (long double x)); 366_GL_CXXALIAS_SYS (atanl, long double, (long double x));
367# if __GLIBC__ >= 2
292_GL_CXXALIASWARN (atanl); 368_GL_CXXALIASWARN (atanl);
369# endif
293#elif defined GNULIB_POSIXCHECK 370#elif defined GNULIB_POSIXCHECK
294# undef atanl 371# undef atanl
295# if HAVE_RAW_DECL_ATANL 372# if HAVE_RAW_DECL_ATANL
@@ -300,11 +377,20 @@ _GL_WARN_ON_USE (atanl, "atanl is unportable - "
300 377
301 378
302#if @GNULIB_ATAN2F@ 379#if @GNULIB_ATAN2F@
303# if !@HAVE_ATAN2F@ 380# if @REPLACE_ATAN2F@
304# undef atan2f 381# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
382# undef atan2f
383# define atan2f rpl_atan2f
384# endif
385_GL_FUNCDECL_RPL (atan2f, float, (float y, float x));
386_GL_CXXALIAS_RPL (atan2f, float, (float y, float x));
387# else
388# if !@HAVE_ATAN2F@
389# undef atan2f
305_GL_FUNCDECL_SYS (atan2f, float, (float y, float x)); 390_GL_FUNCDECL_SYS (atan2f, float, (float y, float x));
306# endif 391# endif
307_GL_CXXALIAS_SYS (atan2f, float, (float y, float x)); 392_GL_CXXALIAS_SYS (atan2f, float, (float y, float x));
393# endif
308_GL_CXXALIASWARN (atan2f); 394_GL_CXXALIASWARN (atan2f);
309#elif defined GNULIB_POSIXCHECK 395#elif defined GNULIB_POSIXCHECK
310# undef atan2f 396# undef atan2f
@@ -343,7 +429,9 @@ _GL_WARN_ON_USE (cbrtf, "cbrtf is unportable - "
343_GL_FUNCDECL_SYS (cbrt, double, (double x)); 429_GL_FUNCDECL_SYS (cbrt, double, (double x));
344# endif 430# endif
345_GL_CXXALIAS_SYS (cbrt, double, (double x)); 431_GL_CXXALIAS_SYS (cbrt, double, (double x));
346_GL_CXXALIASWARN (cbrt); 432# if __GLIBC__ >= 2
433_GL_CXXALIASWARN1 (cbrt, double, (double x));
434# endif
347#elif defined GNULIB_POSIXCHECK 435#elif defined GNULIB_POSIXCHECK
348# undef cbrt 436# undef cbrt
349# if HAVE_RAW_DECL_CBRT 437# if HAVE_RAW_DECL_CBRT
@@ -366,7 +454,9 @@ _GL_FUNCDECL_SYS (cbrtl, long double, (long double x));
366# endif 454# endif
367_GL_CXXALIAS_SYS (cbrtl, long double, (long double x)); 455_GL_CXXALIAS_SYS (cbrtl, long double, (long double x));
368# endif 456# endif
457# if __GLIBC__ >= 2
369_GL_CXXALIASWARN (cbrtl); 458_GL_CXXALIASWARN (cbrtl);
459# endif
370#elif defined GNULIB_POSIXCHECK 460#elif defined GNULIB_POSIXCHECK
371# undef cbrtl 461# undef cbrtl
372# if HAVE_RAW_DECL_CBRTL 462# if HAVE_RAW_DECL_CBRTL
@@ -403,6 +493,7 @@ _GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
403#if @GNULIB_CEIL@ 493#if @GNULIB_CEIL@
404# if @REPLACE_CEIL@ 494# if @REPLACE_CEIL@
405# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 495# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
496# undef ceil
406# define ceil rpl_ceil 497# define ceil rpl_ceil
407# endif 498# endif
408_GL_FUNCDECL_RPL (ceil, double, (double x)); 499_GL_FUNCDECL_RPL (ceil, double, (double x));
@@ -410,7 +501,9 @@ _GL_CXXALIAS_RPL (ceil, double, (double x));
410# else 501# else
411_GL_CXXALIAS_SYS (ceil, double, (double x)); 502_GL_CXXALIAS_SYS (ceil, double, (double x));
412# endif 503# endif
413_GL_CXXALIASWARN (ceil); 504# if __GLIBC__ >= 2
505_GL_CXXALIASWARN1 (ceil, double, (double x));
506# endif
414#endif 507#endif
415 508
416#if @GNULIB_CEILL@ 509#if @GNULIB_CEILL@
@@ -428,7 +521,9 @@ _GL_FUNCDECL_SYS (ceill, long double, (long double x));
428# endif 521# endif
429_GL_CXXALIAS_SYS (ceill, long double, (long double x)); 522_GL_CXXALIAS_SYS (ceill, long double, (long double x));
430# endif 523# endif
524# if __GLIBC__ >= 2
431_GL_CXXALIASWARN (ceill); 525_GL_CXXALIASWARN (ceill);
526# endif
432#elif defined GNULIB_POSIXCHECK 527#elif defined GNULIB_POSIXCHECK
433# undef ceill 528# undef ceill
434# if HAVE_RAW_DECL_CEILL 529# if HAVE_RAW_DECL_CEILL
@@ -440,6 +535,7 @@ _GL_WARN_ON_USE (ceill, "ceill is unportable - "
440 535
441#if @GNULIB_COPYSIGNF@ 536#if @GNULIB_COPYSIGNF@
442# if !@HAVE_DECL_COPYSIGNF@ 537# if !@HAVE_DECL_COPYSIGNF@
538# undef copysignf
443_GL_FUNCDECL_SYS (copysignf, float, (float x, float y)); 539_GL_FUNCDECL_SYS (copysignf, float, (float x, float y));
444# endif 540# endif
445_GL_CXXALIAS_SYS (copysignf, float, (float x, float y)); 541_GL_CXXALIAS_SYS (copysignf, float, (float x, float y));
@@ -457,7 +553,9 @@ _GL_WARN_ON_USE (copysignf, "copysignf is unportable - "
457_GL_FUNCDECL_SYS (copysign, double, (double x, double y)); 553_GL_FUNCDECL_SYS (copysign, double, (double x, double y));
458# endif 554# endif
459_GL_CXXALIAS_SYS (copysign, double, (double x, double y)); 555_GL_CXXALIAS_SYS (copysign, double, (double x, double y));
460_GL_CXXALIASWARN (copysign); 556# if __GLIBC__ >= 2
557_GL_CXXALIASWARN1 (copysign, double, (double x, double y));
558# endif
461#elif defined GNULIB_POSIXCHECK 559#elif defined GNULIB_POSIXCHECK
462# undef copysign 560# undef copysign
463# if HAVE_RAW_DECL_COPYSIGN 561# if HAVE_RAW_DECL_COPYSIGN
@@ -471,7 +569,9 @@ _GL_WARN_ON_USE (copysign, "copysign is unportable - "
471_GL_FUNCDECL_SYS (copysignl, long double, (long double x, long double y)); 569_GL_FUNCDECL_SYS (copysignl, long double, (long double x, long double y));
472# endif 570# endif
473_GL_CXXALIAS_SYS (copysignl, long double, (long double x, long double y)); 571_GL_CXXALIAS_SYS (copysignl, long double, (long double x, long double y));
572# if __GLIBC__ >= 2
474_GL_CXXALIASWARN (copysignl); 573_GL_CXXALIASWARN (copysignl);
574# endif
475#elif defined GNULIB_POSIXCHECK 575#elif defined GNULIB_POSIXCHECK
476# undef copysignl 576# undef copysignl
477# if HAVE_RAW_DECL_COPYSIGNL 577# if HAVE_RAW_DECL_COPYSIGNL
@@ -482,11 +582,20 @@ _GL_WARN_ON_USE (copysign, "copysignl is unportable - "
482 582
483 583
484#if @GNULIB_COSF@ 584#if @GNULIB_COSF@
485# if !@HAVE_COSF@ 585# if @REPLACE_COSF@
486# undef cosf 586# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
587# undef cosf
588# define cosf rpl_cosf
589# endif
590_GL_FUNCDECL_RPL (cosf, float, (float x));
591_GL_CXXALIAS_RPL (cosf, float, (float x));
592# else
593# if !@HAVE_COSF@
594# undef cosf
487_GL_FUNCDECL_SYS (cosf, float, (float x)); 595_GL_FUNCDECL_SYS (cosf, float, (float x));
488# endif 596# endif
489_GL_CXXALIAS_SYS (cosf, float, (float x)); 597_GL_CXXALIAS_SYS (cosf, float, (float x));
598# endif
490_GL_CXXALIASWARN (cosf); 599_GL_CXXALIASWARN (cosf);
491#elif defined GNULIB_POSIXCHECK 600#elif defined GNULIB_POSIXCHECK
492# undef cosf 601# undef cosf
@@ -502,7 +611,9 @@ _GL_WARN_ON_USE (cosf, "cosf is unportable - "
502_GL_FUNCDECL_SYS (cosl, long double, (long double x)); 611_GL_FUNCDECL_SYS (cosl, long double, (long double x));
503# endif 612# endif
504_GL_CXXALIAS_SYS (cosl, long double, (long double x)); 613_GL_CXXALIAS_SYS (cosl, long double, (long double x));
614# if __GLIBC__ >= 2
505_GL_CXXALIASWARN (cosl); 615_GL_CXXALIASWARN (cosl);
616# endif
506#elif defined GNULIB_POSIXCHECK 617#elif defined GNULIB_POSIXCHECK
507# undef cosl 618# undef cosl
508# if HAVE_RAW_DECL_COSL 619# if HAVE_RAW_DECL_COSL
@@ -513,11 +624,20 @@ _GL_WARN_ON_USE (cosl, "cosl is unportable - "
513 624
514 625
515#if @GNULIB_COSHF@ 626#if @GNULIB_COSHF@
516# if !@HAVE_COSHF@ 627# if @REPLACE_COSHF@
517# undef coshf 628# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
629# undef coshf
630# define coshf rpl_coshf
631# endif
632_GL_FUNCDECL_RPL (coshf, float, (float x));
633_GL_CXXALIAS_RPL (coshf, float, (float x));
634# else
635# if !@HAVE_COSHF@
636# undef coshf
518_GL_FUNCDECL_SYS (coshf, float, (float x)); 637_GL_FUNCDECL_SYS (coshf, float, (float x));
519# endif 638# endif
520_GL_CXXALIAS_SYS (coshf, float, (float x)); 639_GL_CXXALIAS_SYS (coshf, float, (float x));
640# endif
521_GL_CXXALIASWARN (coshf); 641_GL_CXXALIASWARN (coshf);
522#elif defined GNULIB_POSIXCHECK 642#elif defined GNULIB_POSIXCHECK
523# undef coshf 643# undef coshf
@@ -529,11 +649,20 @@ _GL_WARN_ON_USE (coshf, "coshf is unportable - "
529 649
530 650
531#if @GNULIB_EXPF@ 651#if @GNULIB_EXPF@
532# if !@HAVE_EXPF@ 652# if @REPLACE_EXPF@
533# undef expf 653# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
654# undef expf
655# define expf rpl_expf
656# endif
657_GL_FUNCDECL_RPL (expf, float, (float x));
658_GL_CXXALIAS_RPL (expf, float, (float x));
659# else
660# if !@HAVE_EXPF@
661# undef expf
534_GL_FUNCDECL_SYS (expf, float, (float x)); 662_GL_FUNCDECL_SYS (expf, float, (float x));
535# endif 663# endif
536_GL_CXXALIAS_SYS (expf, float, (float x)); 664_GL_CXXALIAS_SYS (expf, float, (float x));
665# endif
537_GL_CXXALIASWARN (expf); 666_GL_CXXALIASWARN (expf);
538#elif defined GNULIB_POSIXCHECK 667#elif defined GNULIB_POSIXCHECK
539# undef expf 668# undef expf
@@ -544,12 +673,23 @@ _GL_WARN_ON_USE (expf, "expf is unportable - "
544#endif 673#endif
545 674
546#if @GNULIB_EXPL@ 675#if @GNULIB_EXPL@
547# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@ 676# if @REPLACE_EXPL@
548# undef expl 677# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
678# undef expl
679# define expl rpl_expl
680# endif
681_GL_FUNCDECL_RPL (expl, long double, (long double x));
682_GL_CXXALIAS_RPL (expl, long double, (long double x));
683# else
684# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
685# undef expl
549_GL_FUNCDECL_SYS (expl, long double, (long double x)); 686_GL_FUNCDECL_SYS (expl, long double, (long double x));
550# endif 687# endif
551_GL_CXXALIAS_SYS (expl, long double, (long double x)); 688_GL_CXXALIAS_SYS (expl, long double, (long double x));
689# endif
690# if __GLIBC__ >= 2
552_GL_CXXALIASWARN (expl); 691_GL_CXXALIASWARN (expl);
692# endif
553#elif defined GNULIB_POSIXCHECK 693#elif defined GNULIB_POSIXCHECK
554# undef expl 694# undef expl
555# if HAVE_RAW_DECL_EXPL 695# if HAVE_RAW_DECL_EXPL
@@ -587,7 +727,9 @@ _GL_FUNCDECL_SYS (exp2, double, (double x));
587# endif 727# endif
588_GL_CXXALIAS_SYS (exp2, double, (double x)); 728_GL_CXXALIAS_SYS (exp2, double, (double x));
589# endif 729# endif
590_GL_CXXALIASWARN (exp2); 730# if __GLIBC__ >= 2
731_GL_CXXALIASWARN1 (exp2, double, (double x));
732# endif
591#elif defined GNULIB_POSIXCHECK 733#elif defined GNULIB_POSIXCHECK
592# undef exp2 734# undef exp2
593# if HAVE_RAW_DECL_EXP2 735# if HAVE_RAW_DECL_EXP2
@@ -611,7 +753,9 @@ _GL_FUNCDECL_SYS (exp2l, long double, (long double x));
611# endif 753# endif
612_GL_CXXALIAS_SYS (exp2l, long double, (long double x)); 754_GL_CXXALIAS_SYS (exp2l, long double, (long double x));
613# endif 755# endif
756# if __GLIBC__ >= 2
614_GL_CXXALIASWARN (exp2l); 757_GL_CXXALIASWARN (exp2l);
758# endif
615#elif defined GNULIB_POSIXCHECK 759#elif defined GNULIB_POSIXCHECK
616# undef exp2l 760# undef exp2l
617# if HAVE_RAW_DECL_EXP2L 761# if HAVE_RAW_DECL_EXP2L
@@ -658,7 +802,9 @@ _GL_FUNCDECL_SYS (expm1, double, (double x));
658# endif 802# endif
659_GL_CXXALIAS_SYS (expm1, double, (double x)); 803_GL_CXXALIAS_SYS (expm1, double, (double x));
660# endif 804# endif
661_GL_CXXALIASWARN (expm1); 805# if __GLIBC__ >= 2
806_GL_CXXALIASWARN1 (expm1, double, (double x));
807# endif
662#elif defined GNULIB_POSIXCHECK 808#elif defined GNULIB_POSIXCHECK
663# undef expm1 809# undef expm1
664# if HAVE_RAW_DECL_EXPM1 810# if HAVE_RAW_DECL_EXPM1
@@ -668,12 +814,25 @@ _GL_WARN_ON_USE (expm1, "expm1 is unportable - "
668#endif 814#endif
669 815
670#if @GNULIB_EXPM1L@ 816#if @GNULIB_EXPM1L@
671# if !@HAVE_DECL_EXPM1L@ 817# if @REPLACE_EXPM1L@
672# undef expm1l 818# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
819# undef expm1l
820# define expm1l rpl_expm1l
821# endif
822_GL_FUNCDECL_RPL (expm1l, long double, (long double x));
823_GL_CXXALIAS_RPL (expm1l, long double, (long double x));
824# else
825# if !@HAVE_DECL_EXPM1L@
826# undef expm1l
827# if !(defined __cplusplus && defined _AIX)
673_GL_FUNCDECL_SYS (expm1l, long double, (long double x)); 828_GL_FUNCDECL_SYS (expm1l, long double, (long double x));
674# endif 829# endif
830# endif
675_GL_CXXALIAS_SYS (expm1l, long double, (long double x)); 831_GL_CXXALIAS_SYS (expm1l, long double, (long double x));
832# endif
833# if __GLIBC__ >= 2
676_GL_CXXALIASWARN (expm1l); 834_GL_CXXALIASWARN (expm1l);
835# endif
677#elif defined GNULIB_POSIXCHECK 836#elif defined GNULIB_POSIXCHECK
678# undef expm1l 837# undef expm1l
679# if HAVE_RAW_DECL_EXPM1L 838# if HAVE_RAW_DECL_EXPM1L
@@ -689,7 +848,9 @@ _GL_WARN_ON_USE (expm1l, "expm1l is unportable - "
689_GL_FUNCDECL_SYS (fabsf, float, (float x)); 848_GL_FUNCDECL_SYS (fabsf, float, (float x));
690# endif 849# endif
691_GL_CXXALIAS_SYS (fabsf, float, (float x)); 850_GL_CXXALIAS_SYS (fabsf, float, (float x));
851# if __GLIBC__ >= 2
692_GL_CXXALIASWARN (fabsf); 852_GL_CXXALIASWARN (fabsf);
853# endif
693#elif defined GNULIB_POSIXCHECK 854#elif defined GNULIB_POSIXCHECK
694# undef fabsf 855# undef fabsf
695# if HAVE_RAW_DECL_FABSF 856# if HAVE_RAW_DECL_FABSF
@@ -713,7 +874,9 @@ _GL_FUNCDECL_SYS (fabsl, long double, (long double x));
713# endif 874# endif
714_GL_CXXALIAS_SYS (fabsl, long double, (long double x)); 875_GL_CXXALIAS_SYS (fabsl, long double, (long double x));
715# endif 876# endif
877# if __GLIBC__ >= 2
716_GL_CXXALIASWARN (fabsl); 878_GL_CXXALIASWARN (fabsl);
879# endif
717#elif defined GNULIB_POSIXCHECK 880#elif defined GNULIB_POSIXCHECK
718# undef fabsl 881# undef fabsl
719# if HAVE_RAW_DECL_FABSL 882# if HAVE_RAW_DECL_FABSL
@@ -750,6 +913,7 @@ _GL_WARN_ON_USE (floorf, "floorf is unportable - "
750#if @GNULIB_FLOOR@ 913#if @GNULIB_FLOOR@
751# if @REPLACE_FLOOR@ 914# if @REPLACE_FLOOR@
752# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 915# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
916# undef floor
753# define floor rpl_floor 917# define floor rpl_floor
754# endif 918# endif
755_GL_FUNCDECL_RPL (floor, double, (double x)); 919_GL_FUNCDECL_RPL (floor, double, (double x));
@@ -757,7 +921,9 @@ _GL_CXXALIAS_RPL (floor, double, (double x));
757# else 921# else
758_GL_CXXALIAS_SYS (floor, double, (double x)); 922_GL_CXXALIAS_SYS (floor, double, (double x));
759# endif 923# endif
760_GL_CXXALIASWARN (floor); 924# if __GLIBC__ >= 2
925_GL_CXXALIASWARN1 (floor, double, (double x));
926# endif
761#endif 927#endif
762 928
763#if @GNULIB_FLOORL@ 929#if @GNULIB_FLOORL@
@@ -775,7 +941,9 @@ _GL_FUNCDECL_SYS (floorl, long double, (long double x));
775# endif 941# endif
776_GL_CXXALIAS_SYS (floorl, long double, (long double x)); 942_GL_CXXALIAS_SYS (floorl, long double, (long double x));
777# endif 943# endif
944# if __GLIBC__ >= 2
778_GL_CXXALIASWARN (floorl); 945_GL_CXXALIASWARN (floorl);
946# endif
779#elif defined GNULIB_POSIXCHECK 947#elif defined GNULIB_POSIXCHECK
780# undef floorl 948# undef floorl
781# if HAVE_RAW_DECL_FLOORL 949# if HAVE_RAW_DECL_FLOORL
@@ -795,6 +963,7 @@ _GL_FUNCDECL_RPL (fmaf, float, (float x, float y, float z));
795_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z)); 963_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z));
796# else 964# else
797# if !@HAVE_FMAF@ 965# if !@HAVE_FMAF@
966# undef fmaf
798_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z)); 967_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z));
799# endif 968# endif
800_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z)); 969_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z));
@@ -818,11 +987,14 @@ _GL_FUNCDECL_RPL (fma, double, (double x, double y, double z));
818_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z)); 987_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z));
819# else 988# else
820# if !@HAVE_FMA@ 989# if !@HAVE_FMA@
990# undef fma
821_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z)); 991_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z));
822# endif 992# endif
823_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z)); 993_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z));
824# endif 994# endif
825_GL_CXXALIASWARN (fma); 995# if __GLIBC__ >= 2
996_GL_CXXALIASWARN1 (fma, double, (double x, double y, double z));
997# endif
826#elif defined GNULIB_POSIXCHECK 998#elif defined GNULIB_POSIXCHECK
827# undef fma 999# undef fma
828# if HAVE_RAW_DECL_FMA 1000# if HAVE_RAW_DECL_FMA
@@ -844,13 +1016,17 @@ _GL_CXXALIAS_RPL (fmal, long double,
844# else 1016# else
845# if !@HAVE_FMAL@ 1017# if !@HAVE_FMAL@
846# undef fmal 1018# undef fmal
1019# if !(defined __cplusplus && defined _AIX)
847_GL_FUNCDECL_SYS (fmal, long double, 1020_GL_FUNCDECL_SYS (fmal, long double,
848 (long double x, long double y, long double z)); 1021 (long double x, long double y, long double z));
1022# endif
849# endif 1023# endif
850_GL_CXXALIAS_SYS (fmal, long double, 1024_GL_CXXALIAS_SYS (fmal, long double,
851 (long double x, long double y, long double z)); 1025 (long double x, long double y, long double z));
852# endif 1026# endif
1027# if __GLIBC__ >= 2
853_GL_CXXALIASWARN (fmal); 1028_GL_CXXALIASWARN (fmal);
1029# endif
854#elif defined GNULIB_POSIXCHECK 1030#elif defined GNULIB_POSIXCHECK
855# undef fmal 1031# undef fmal
856# if HAVE_RAW_DECL_FMAL 1032# if HAVE_RAW_DECL_FMAL
@@ -895,7 +1071,9 @@ _GL_CXXALIAS_RPL (fmod, double, (double x, double y));
895# else 1071# else
896_GL_CXXALIAS_SYS (fmod, double, (double x, double y)); 1072_GL_CXXALIAS_SYS (fmod, double, (double x, double y));
897# endif 1073# endif
898_GL_CXXALIASWARN (fmod); 1074# if __GLIBC__ >= 2
1075_GL_CXXALIASWARN1 (fmod, double, (double x, double y));
1076# endif
899#elif defined GNULIB_POSIXCHECK 1077#elif defined GNULIB_POSIXCHECK
900# undef fmod 1078# undef fmod
901# if HAVE_RAW_DECL_FMOD 1079# if HAVE_RAW_DECL_FMOD
@@ -919,7 +1097,9 @@ _GL_FUNCDECL_SYS (fmodl, long double, (long double x, long double y));
919# endif 1097# endif
920_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y)); 1098_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y));
921# endif 1099# endif
1100# if __GLIBC__ >= 2
922_GL_CXXALIASWARN (fmodl); 1101_GL_CXXALIASWARN (fmodl);
1102# endif
923#elif defined GNULIB_POSIXCHECK 1103#elif defined GNULIB_POSIXCHECK
924# undef fmodl 1104# undef fmodl
925# if HAVE_RAW_DECL_FMODL 1105# if HAVE_RAW_DECL_FMODL
@@ -951,7 +1131,9 @@ _GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
951# endif 1131# endif
952_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr)); 1132_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr));
953# endif 1133# endif
1134# if __GLIBC__ >= 2
954_GL_CXXALIASWARN (frexpf); 1135_GL_CXXALIASWARN (frexpf);
1136# endif
955#elif defined GNULIB_POSIXCHECK 1137#elif defined GNULIB_POSIXCHECK
956# undef frexpf 1138# undef frexpf
957# if HAVE_RAW_DECL_FREXPF 1139# if HAVE_RAW_DECL_FREXPF
@@ -970,6 +1152,7 @@ _GL_WARN_ON_USE (frexpf, "frexpf is unportable - "
970#if @GNULIB_FREXP@ 1152#if @GNULIB_FREXP@
971# if @REPLACE_FREXP@ 1153# if @REPLACE_FREXP@
972# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1154# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1155# undef frexp
973# define frexp rpl_frexp 1156# define frexp rpl_frexp
974# endif 1157# endif
975_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2))); 1158_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
@@ -977,7 +1160,9 @@ _GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
977# else 1160# else
978_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr)); 1161_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
979# endif 1162# endif
980_GL_CXXALIASWARN (frexp); 1163# if __GLIBC__ >= 2
1164_GL_CXXALIASWARN1 (frexp, double, (double x, int *expptr));
1165# endif
981#elif defined GNULIB_POSIXCHECK 1166#elif defined GNULIB_POSIXCHECK
982# undef frexp 1167# undef frexp
983/* Assume frexp is always declared. */ 1168/* Assume frexp is always declared. */
@@ -1010,7 +1195,9 @@ _GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
1010# endif 1195# endif
1011#endif 1196#endif
1012#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@) 1197#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@)
1198# if __GLIBC__ >= 2
1013_GL_CXXALIASWARN (frexpl); 1199_GL_CXXALIASWARN (frexpl);
1200# endif
1014#endif 1201#endif
1015#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK 1202#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
1016# undef frexpl 1203# undef frexpl
@@ -1036,7 +1223,9 @@ _GL_FUNCDECL_SYS (hypotf, float, (float x, float y));
1036# endif 1223# endif
1037_GL_CXXALIAS_SYS (hypotf, float, (float x, float y)); 1224_GL_CXXALIAS_SYS (hypotf, float, (float x, float y));
1038# endif 1225# endif
1226# if __GLIBC__ >= 2
1039_GL_CXXALIASWARN (hypotf); 1227_GL_CXXALIASWARN (hypotf);
1228# endif
1040#elif defined GNULIB_POSIXCHECK 1229#elif defined GNULIB_POSIXCHECK
1041# undef hypotf 1230# undef hypotf
1042# if HAVE_RAW_DECL_HYPOTF 1231# if HAVE_RAW_DECL_HYPOTF
@@ -1057,7 +1246,9 @@ _GL_CXXALIAS_RPL (hypot, double, (double x, double y));
1057# else 1246# else
1058_GL_CXXALIAS_SYS (hypot, double, (double x, double y)); 1247_GL_CXXALIAS_SYS (hypot, double, (double x, double y));
1059# endif 1248# endif
1060_GL_CXXALIASWARN (hypot); 1249# if __GLIBC__ >= 2
1250_GL_CXXALIASWARN1 (hypot, double, (double x, double y));
1251# endif
1061#elif defined GNULIB_POSIXCHECK 1252#elif defined GNULIB_POSIXCHECK
1062# undef hypot 1253# undef hypot
1063# if HAVE_RAW_DECL_HYPOT 1254# if HAVE_RAW_DECL_HYPOT
@@ -1081,7 +1272,9 @@ _GL_FUNCDECL_SYS (hypotl, long double, (long double x, long double y));
1081# endif 1272# endif
1082_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y)); 1273_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y));
1083# endif 1274# endif
1275# if __GLIBC__ >= 2
1084_GL_CXXALIASWARN (hypotl); 1276_GL_CXXALIASWARN (hypotl);
1277# endif
1085#elif defined GNULIB_POSIXCHECK 1278#elif defined GNULIB_POSIXCHECK
1086# undef hypotl 1279# undef hypotl
1087# if HAVE_RAW_DECL_HYPOTL 1280# if HAVE_RAW_DECL_HYPOTL
@@ -1128,7 +1321,9 @@ _GL_FUNCDECL_SYS (ilogb, int, (double x));
1128# endif 1321# endif
1129_GL_CXXALIAS_SYS (ilogb, int, (double x)); 1322_GL_CXXALIAS_SYS (ilogb, int, (double x));
1130# endif 1323# endif
1131_GL_CXXALIASWARN (ilogb); 1324# if __GLIBC__ >= 2
1325_GL_CXXALIASWARN1 (ilogb, int, (double x));
1326# endif
1132#elif defined GNULIB_POSIXCHECK 1327#elif defined GNULIB_POSIXCHECK
1133# undef ilogb 1328# undef ilogb
1134# if HAVE_RAW_DECL_ILOGB 1329# if HAVE_RAW_DECL_ILOGB
@@ -1138,11 +1333,23 @@ _GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
1138#endif 1333#endif
1139 1334
1140#if @GNULIB_ILOGBL@ 1335#if @GNULIB_ILOGBL@
1141# if !@HAVE_ILOGBL@ 1336# if @REPLACE_ILOGBL@
1337# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1338# undef ilogbl
1339# define ilogbl rpl_ilogbl
1340# endif
1341_GL_FUNCDECL_RPL (ilogbl, int, (long double x));
1342_GL_CXXALIAS_RPL (ilogbl, int, (long double x));
1343# else
1344# if !@HAVE_ILOGBL@
1345# undef ilogbl
1142_GL_FUNCDECL_SYS (ilogbl, int, (long double x)); 1346_GL_FUNCDECL_SYS (ilogbl, int, (long double x));
1143# endif 1347# endif
1144_GL_CXXALIAS_SYS (ilogbl, int, (long double x)); 1348_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
1349# endif
1350# if __GLIBC__ >= 2
1145_GL_CXXALIASWARN (ilogbl); 1351_GL_CXXALIASWARN (ilogbl);
1352# endif
1146#elif defined GNULIB_POSIXCHECK 1353#elif defined GNULIB_POSIXCHECK
1147# undef ilogbl 1354# undef ilogbl
1148# if HAVE_RAW_DECL_ILOGBL 1355# if HAVE_RAW_DECL_ILOGBL
@@ -1152,6 +1359,55 @@ _GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
1152#endif 1359#endif
1153 1360
1154 1361
1362#if @GNULIB_MDA_J0@
1363/* On native Windows, map 'j0' to '_j0', so that -loldnames is not
1364 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1365 platforms by defining GNULIB_NAMESPACE::j0 always. */
1366# if defined _WIN32 && !defined __CYGWIN__
1367# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1368# undef j0
1369# define j0 _j0
1370# endif
1371_GL_CXXALIAS_MDA (j0, double, (double x));
1372# else
1373_GL_CXXALIAS_SYS (j0, double, (double x));
1374# endif
1375_GL_CXXALIASWARN (j0);
1376#endif
1377
1378#if @GNULIB_MDA_J1@
1379/* On native Windows, map 'j1' to '_j1', so that -loldnames is not
1380 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1381 platforms by defining GNULIB_NAMESPACE::j1 always. */
1382# if defined _WIN32 && !defined __CYGWIN__
1383# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1384# undef j1
1385# define j1 _j1
1386# endif
1387_GL_CXXALIAS_MDA (j1, double, (double x));
1388# else
1389_GL_CXXALIAS_SYS (j1, double, (double x));
1390# endif
1391_GL_CXXALIASWARN (j1);
1392#endif
1393
1394#if @GNULIB_MDA_JN@
1395/* On native Windows, map 'jn' to '_jn', so that -loldnames is not
1396 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1397 platforms by defining GNULIB_NAMESPACE::jn always. */
1398# if defined _WIN32 && !defined __CYGWIN__
1399# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1400# undef jn
1401# define jn _jn
1402# endif
1403_GL_CXXALIAS_MDA (jn, double, (int n, double x));
1404# else
1405_GL_CXXALIAS_SYS (jn, double, (int n, double x));
1406# endif
1407_GL_CXXALIASWARN (jn);
1408#endif
1409
1410
1155/* Return x * 2^exp. */ 1411/* Return x * 2^exp. */
1156#if @GNULIB_LDEXPF@ 1412#if @GNULIB_LDEXPF@
1157# if !@HAVE_LDEXPF@ 1413# if !@HAVE_LDEXPF@
@@ -1159,7 +1415,9 @@ _GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
1159_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp)); 1415_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp));
1160# endif 1416# endif
1161_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp)); 1417_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp));
1418# if __GLIBC__ >= 2
1162_GL_CXXALIASWARN (ldexpf); 1419_GL_CXXALIASWARN (ldexpf);
1420# endif
1163#elif defined GNULIB_POSIXCHECK 1421#elif defined GNULIB_POSIXCHECK
1164# undef ldexpf 1422# undef ldexpf
1165# if HAVE_RAW_DECL_LDEXPF 1423# if HAVE_RAW_DECL_LDEXPF
@@ -1185,7 +1443,9 @@ _GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
1185# endif 1443# endif
1186#endif 1444#endif
1187#if @GNULIB_LDEXPL@ 1445#if @GNULIB_LDEXPL@
1446# if __GLIBC__ >= 2
1188_GL_CXXALIASWARN (ldexpl); 1447_GL_CXXALIASWARN (ldexpl);
1448# endif
1189#endif 1449#endif
1190#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK 1450#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
1191# undef ldexpl 1451# undef ldexpl
@@ -1231,7 +1491,9 @@ _GL_CXXALIAS_RPL (log, double, (double x));
1231# else 1491# else
1232_GL_CXXALIAS_SYS (log, double, (double x)); 1492_GL_CXXALIAS_SYS (log, double, (double x));
1233# endif 1493# endif
1234_GL_CXXALIASWARN (log); 1494# if __GLIBC__ >= 2
1495_GL_CXXALIASWARN1 (log, double, (double x));
1496# endif
1235#elif defined GNULIB_POSIXCHECK 1497#elif defined GNULIB_POSIXCHECK
1236# undef log 1498# undef log
1237# if HAVE_RAW_DECL_LOG 1499# if HAVE_RAW_DECL_LOG
@@ -1255,7 +1517,9 @@ _GL_FUNCDECL_SYS (logl, long double, (long double x));
1255# endif 1517# endif
1256_GL_CXXALIAS_SYS (logl, long double, (long double x)); 1518_GL_CXXALIAS_SYS (logl, long double, (long double x));
1257# endif 1519# endif
1520# if __GLIBC__ >= 2
1258_GL_CXXALIASWARN (logl); 1521_GL_CXXALIASWARN (logl);
1522# endif
1259#elif defined GNULIB_POSIXCHECK 1523#elif defined GNULIB_POSIXCHECK
1260# undef logl 1524# undef logl
1261# if HAVE_RAW_DECL_LOGL 1525# if HAVE_RAW_DECL_LOGL
@@ -1300,7 +1564,9 @@ _GL_CXXALIAS_RPL (log10, double, (double x));
1300# else 1564# else
1301_GL_CXXALIAS_SYS (log10, double, (double x)); 1565_GL_CXXALIAS_SYS (log10, double, (double x));
1302# endif 1566# endif
1303_GL_CXXALIASWARN (log10); 1567# if __GLIBC__ >= 2
1568_GL_CXXALIASWARN1 (log10, double, (double x));
1569# endif
1304#elif defined GNULIB_POSIXCHECK 1570#elif defined GNULIB_POSIXCHECK
1305# undef log10 1571# undef log10
1306# if HAVE_RAW_DECL_LOG10 1572# if HAVE_RAW_DECL_LOG10
@@ -1324,7 +1590,9 @@ _GL_FUNCDECL_SYS (log10l, long double, (long double x));
1324# endif 1590# endif
1325_GL_CXXALIAS_SYS (log10l, long double, (long double x)); 1591_GL_CXXALIAS_SYS (log10l, long double, (long double x));
1326# endif 1592# endif
1593# if __GLIBC__ >= 2
1327_GL_CXXALIASWARN (log10l); 1594_GL_CXXALIASWARN (log10l);
1595# endif
1328#elif defined GNULIB_POSIXCHECK 1596#elif defined GNULIB_POSIXCHECK
1329# undef log10l 1597# undef log10l
1330# if HAVE_RAW_DECL_LOG10L 1598# if HAVE_RAW_DECL_LOG10L
@@ -1371,7 +1639,9 @@ _GL_FUNCDECL_SYS (log1p, double, (double x));
1371# endif 1639# endif
1372_GL_CXXALIAS_SYS (log1p, double, (double x)); 1640_GL_CXXALIAS_SYS (log1p, double, (double x));
1373# endif 1641# endif
1374_GL_CXXALIASWARN (log1p); 1642# if __GLIBC__ >= 2
1643_GL_CXXALIASWARN1 (log1p, double, (double x));
1644# endif
1375#elif defined GNULIB_POSIXCHECK 1645#elif defined GNULIB_POSIXCHECK
1376# undef log1p 1646# undef log1p
1377# if HAVE_RAW_DECL_LOG1P 1647# if HAVE_RAW_DECL_LOG1P
@@ -1394,7 +1664,9 @@ _GL_FUNCDECL_SYS (log1pl, long double, (long double x));
1394# endif 1664# endif
1395_GL_CXXALIAS_SYS (log1pl, long double, (long double x)); 1665_GL_CXXALIAS_SYS (log1pl, long double, (long double x));
1396# endif 1666# endif
1667# if __GLIBC__ >= 2
1397_GL_CXXALIASWARN (log1pl); 1668_GL_CXXALIASWARN (log1pl);
1669# endif
1398#elif defined GNULIB_POSIXCHECK 1670#elif defined GNULIB_POSIXCHECK
1399# undef log1pl 1671# undef log1pl
1400# if HAVE_RAW_DECL_LOG1PL 1672# if HAVE_RAW_DECL_LOG1PL
@@ -1443,7 +1715,9 @@ _GL_FUNCDECL_SYS (log2, double, (double x));
1443# endif 1715# endif
1444_GL_CXXALIAS_SYS (log2, double, (double x)); 1716_GL_CXXALIAS_SYS (log2, double, (double x));
1445# endif 1717# endif
1446_GL_CXXALIASWARN (log2); 1718# if __GLIBC__ >= 2
1719_GL_CXXALIASWARN1 (log2, double, (double x));
1720# endif
1447#elif defined GNULIB_POSIXCHECK 1721#elif defined GNULIB_POSIXCHECK
1448# undef log2 1722# undef log2
1449# if HAVE_RAW_DECL_LOG2 1723# if HAVE_RAW_DECL_LOG2
@@ -1466,7 +1740,9 @@ _GL_FUNCDECL_SYS (log2l, long double, (long double x));
1466# endif 1740# endif
1467_GL_CXXALIAS_SYS (log2l, long double, (long double x)); 1741_GL_CXXALIAS_SYS (log2l, long double, (long double x));
1468# endif 1742# endif
1743# if __GLIBC__ >= 2
1469_GL_CXXALIASWARN (log2l); 1744_GL_CXXALIASWARN (log2l);
1745# endif
1470#elif defined GNULIB_POSIXCHECK 1746#elif defined GNULIB_POSIXCHECK
1471# undef log2l 1747# undef log2l
1472# if HAVE_RAW_DECL_LOG2L 1748# if HAVE_RAW_DECL_LOG2L
@@ -1513,7 +1789,9 @@ _GL_FUNCDECL_SYS (logb, double, (double x));
1513# endif 1789# endif
1514_GL_CXXALIAS_SYS (logb, double, (double x)); 1790_GL_CXXALIAS_SYS (logb, double, (double x));
1515# endif 1791# endif
1516_GL_CXXALIASWARN (logb); 1792# if __GLIBC__ >= 2
1793_GL_CXXALIASWARN1 (logb, double, (double x));
1794# endif
1517#elif defined GNULIB_POSIXCHECK 1795#elif defined GNULIB_POSIXCHECK
1518# undef logb 1796# undef logb
1519# if HAVE_RAW_DECL_LOGB 1797# if HAVE_RAW_DECL_LOGB
@@ -1536,7 +1814,9 @@ _GL_FUNCDECL_SYS (logbl, long double, (long double x));
1536# endif 1814# endif
1537_GL_CXXALIAS_SYS (logbl, long double, (long double x)); 1815_GL_CXXALIAS_SYS (logbl, long double, (long double x));
1538# endif 1816# endif
1817# if __GLIBC__ >= 2
1539_GL_CXXALIASWARN (logbl); 1818_GL_CXXALIASWARN (logbl);
1819# endif
1540#elif defined GNULIB_POSIXCHECK 1820#elif defined GNULIB_POSIXCHECK
1541# undef logbl 1821# undef logbl
1542# if HAVE_RAW_DECL_LOGBL 1822# if HAVE_RAW_DECL_LOGBL
@@ -1581,7 +1861,9 @@ _GL_CXXALIAS_RPL (modf, double, (double x, double *iptr));
1581# else 1861# else
1582_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr)); 1862_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr));
1583# endif 1863# endif
1584_GL_CXXALIASWARN (modf); 1864# if __GLIBC__ >= 2
1865_GL_CXXALIASWARN1 (modf, double, (double x, double *iptr));
1866# endif
1585#elif defined GNULIB_POSIXCHECK 1867#elif defined GNULIB_POSIXCHECK
1586# undef modf 1868# undef modf
1587# if HAVE_RAW_DECL_MODF 1869# if HAVE_RAW_DECL_MODF
@@ -1607,7 +1889,9 @@ _GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
1607# endif 1889# endif
1608_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr)); 1890_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
1609# endif 1891# endif
1892# if __GLIBC__ >= 2
1610_GL_CXXALIASWARN (modfl); 1893_GL_CXXALIASWARN (modfl);
1894# endif
1611#elif defined GNULIB_POSIXCHECK 1895#elif defined GNULIB_POSIXCHECK
1612# undef modfl 1896# undef modfl
1613# if HAVE_RAW_DECL_MODFL 1897# if HAVE_RAW_DECL_MODFL
@@ -1670,7 +1954,9 @@ _GL_FUNCDECL_SYS (remainder, double, (double x, double y));
1670# endif 1954# endif
1671_GL_CXXALIAS_SYS (remainder, double, (double x, double y)); 1955_GL_CXXALIAS_SYS (remainder, double, (double x, double y));
1672# endif 1956# endif
1673_GL_CXXALIASWARN (remainder); 1957# if __GLIBC__ >= 2
1958_GL_CXXALIASWARN1 (remainder, double, (double x, double y));
1959# endif
1674#elif defined GNULIB_POSIXCHECK 1960#elif defined GNULIB_POSIXCHECK
1675# undef remainder 1961# undef remainder
1676# if HAVE_RAW_DECL_REMAINDER 1962# if HAVE_RAW_DECL_REMAINDER
@@ -1690,11 +1976,15 @@ _GL_CXXALIAS_RPL (remainderl, long double, (long double x, long double y));
1690# else 1976# else
1691# if !@HAVE_DECL_REMAINDERL@ 1977# if !@HAVE_DECL_REMAINDERL@
1692# undef remainderl 1978# undef remainderl
1979# if !(defined __cplusplus && defined _AIX)
1693_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y)); 1980_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y));
1981# endif
1694# endif 1982# endif
1695_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y)); 1983_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y));
1696# endif 1984# endif
1985# if __GLIBC__ >= 2
1697_GL_CXXALIASWARN (remainderl); 1986_GL_CXXALIASWARN (remainderl);
1987# endif
1698#elif defined GNULIB_POSIXCHECK 1988#elif defined GNULIB_POSIXCHECK
1699# undef remainderl 1989# undef remainderl
1700# if HAVE_RAW_DECL_REMAINDERL 1990# if HAVE_RAW_DECL_REMAINDERL
@@ -1723,7 +2013,9 @@ _GL_WARN_ON_USE (rintf, "rintf is unportable - "
1723_GL_FUNCDECL_SYS (rint, double, (double x)); 2013_GL_FUNCDECL_SYS (rint, double, (double x));
1724# endif 2014# endif
1725_GL_CXXALIAS_SYS (rint, double, (double x)); 2015_GL_CXXALIAS_SYS (rint, double, (double x));
1726_GL_CXXALIASWARN (rint); 2016# if __GLIBC__ >= 2
2017_GL_CXXALIASWARN1 (rint, double, (double x));
2018# endif
1727#elif defined GNULIB_POSIXCHECK 2019#elif defined GNULIB_POSIXCHECK
1728# undef rint 2020# undef rint
1729# if HAVE_RAW_DECL_RINT 2021# if HAVE_RAW_DECL_RINT
@@ -1733,11 +2025,22 @@ _GL_WARN_ON_USE (rint, "rint is unportable - "
1733#endif 2025#endif
1734 2026
1735#if @GNULIB_RINTL@ 2027#if @GNULIB_RINTL@
1736# if !@HAVE_RINTL@ 2028# if @REPLACE_RINTL@
2029# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2030# undef rintl
2031# define rintl rpl_rintl
2032# endif
2033_GL_FUNCDECL_RPL (rintl, long double, (long double x));
2034_GL_CXXALIAS_RPL (rintl, long double, (long double x));
2035# else
2036# if !@HAVE_RINTL@
1737_GL_FUNCDECL_SYS (rintl, long double, (long double x)); 2037_GL_FUNCDECL_SYS (rintl, long double, (long double x));
1738# endif 2038# endif
1739_GL_CXXALIAS_SYS (rintl, long double, (long double x)); 2039_GL_CXXALIAS_SYS (rintl, long double, (long double x));
2040# endif
2041# if __GLIBC__ >= 2
1740_GL_CXXALIASWARN (rintl); 2042_GL_CXXALIASWARN (rintl);
2043# endif
1741#elif defined GNULIB_POSIXCHECK 2044#elif defined GNULIB_POSIXCHECK
1742# undef rintl 2045# undef rintl
1743# if HAVE_RAW_DECL_RINTL 2046# if HAVE_RAW_DECL_RINTL
@@ -1784,7 +2087,9 @@ _GL_FUNCDECL_SYS (round, double, (double x));
1784# endif 2087# endif
1785_GL_CXXALIAS_SYS (round, double, (double x)); 2088_GL_CXXALIAS_SYS (round, double, (double x));
1786# endif 2089# endif
1787_GL_CXXALIASWARN (round); 2090# if __GLIBC__ >= 2
2091_GL_CXXALIASWARN1 (round, double, (double x));
2092# endif
1788#elif defined GNULIB_POSIXCHECK 2093#elif defined GNULIB_POSIXCHECK
1789# undef round 2094# undef round
1790# if HAVE_RAW_DECL_ROUND 2095# if HAVE_RAW_DECL_ROUND
@@ -1804,11 +2109,15 @@ _GL_CXXALIAS_RPL (roundl, long double, (long double x));
1804# else 2109# else
1805# if !@HAVE_DECL_ROUNDL@ 2110# if !@HAVE_DECL_ROUNDL@
1806# undef roundl 2111# undef roundl
2112# if !(defined __cplusplus && defined _AIX)
1807_GL_FUNCDECL_SYS (roundl, long double, (long double x)); 2113_GL_FUNCDECL_SYS (roundl, long double, (long double x));
2114# endif
1808# endif 2115# endif
1809_GL_CXXALIAS_SYS (roundl, long double, (long double x)); 2116_GL_CXXALIAS_SYS (roundl, long double, (long double x));
1810# endif 2117# endif
2118# if __GLIBC__ >= 2
1811_GL_CXXALIASWARN (roundl); 2119_GL_CXXALIASWARN (roundl);
2120# endif
1812#elif defined GNULIB_POSIXCHECK 2121#elif defined GNULIB_POSIXCHECK
1813# undef roundl 2122# undef roundl
1814# if HAVE_RAW_DECL_ROUNDL 2123# if HAVE_RAW_DECL_ROUNDL
@@ -1819,11 +2128,20 @@ _GL_WARN_ON_USE (roundl, "roundl is unportable - "
1819 2128
1820 2129
1821#if @GNULIB_SINF@ 2130#if @GNULIB_SINF@
1822# if !@HAVE_SINF@ 2131# if @REPLACE_SINF@
1823# undef sinf 2132# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2133# undef sinf
2134# define sinf rpl_sinf
2135# endif
2136_GL_FUNCDECL_RPL (sinf, float, (float x));
2137_GL_CXXALIAS_RPL (sinf, float, (float x));
2138# else
2139# if !@HAVE_SINF@
2140# undef sinf
1824_GL_FUNCDECL_SYS (sinf, float, (float x)); 2141_GL_FUNCDECL_SYS (sinf, float, (float x));
1825# endif 2142# endif
1826_GL_CXXALIAS_SYS (sinf, float, (float x)); 2143_GL_CXXALIAS_SYS (sinf, float, (float x));
2144# endif
1827_GL_CXXALIASWARN (sinf); 2145_GL_CXXALIASWARN (sinf);
1828#elif defined GNULIB_POSIXCHECK 2146#elif defined GNULIB_POSIXCHECK
1829# undef sinf 2147# undef sinf
@@ -1839,7 +2157,9 @@ _GL_WARN_ON_USE (sinf, "sinf is unportable - "
1839_GL_FUNCDECL_SYS (sinl, long double, (long double x)); 2157_GL_FUNCDECL_SYS (sinl, long double, (long double x));
1840# endif 2158# endif
1841_GL_CXXALIAS_SYS (sinl, long double, (long double x)); 2159_GL_CXXALIAS_SYS (sinl, long double, (long double x));
2160# if __GLIBC__ >= 2
1842_GL_CXXALIASWARN (sinl); 2161_GL_CXXALIASWARN (sinl);
2162# endif
1843#elif defined GNULIB_POSIXCHECK 2163#elif defined GNULIB_POSIXCHECK
1844# undef sinl 2164# undef sinl
1845# if HAVE_RAW_DECL_SINL 2165# if HAVE_RAW_DECL_SINL
@@ -1850,11 +2170,20 @@ _GL_WARN_ON_USE (sinl, "sinl is unportable - "
1850 2170
1851 2171
1852#if @GNULIB_SINHF@ 2172#if @GNULIB_SINHF@
1853# if !@HAVE_SINHF@ 2173# if @REPLACE_SINHF@
1854# undef sinhf 2174# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2175# undef sinhf
2176# define sinhf rpl_sinhf
2177# endif
2178_GL_FUNCDECL_RPL (sinhf, float, (float x));
2179_GL_CXXALIAS_RPL (sinhf, float, (float x));
2180# else
2181# if !@HAVE_SINHF@
2182# undef sinhf
1855_GL_FUNCDECL_SYS (sinhf, float, (float x)); 2183_GL_FUNCDECL_SYS (sinhf, float, (float x));
1856# endif 2184# endif
1857_GL_CXXALIAS_SYS (sinhf, float, (float x)); 2185_GL_CXXALIAS_SYS (sinhf, float, (float x));
2186# endif
1858_GL_CXXALIASWARN (sinhf); 2187_GL_CXXALIASWARN (sinhf);
1859#elif defined GNULIB_POSIXCHECK 2188#elif defined GNULIB_POSIXCHECK
1860# undef sinhf 2189# undef sinhf
@@ -1866,11 +2195,20 @@ _GL_WARN_ON_USE (sinhf, "sinhf is unportable - "
1866 2195
1867 2196
1868#if @GNULIB_SQRTF@ 2197#if @GNULIB_SQRTF@
1869# if !@HAVE_SQRTF@ 2198# if @REPLACE_SQRTF@
1870# undef sqrtf 2199# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2200# undef sqrtf
2201# define sqrtf rpl_sqrtf
2202# endif
2203_GL_FUNCDECL_RPL (sqrtf, float, (float x));
2204_GL_CXXALIAS_RPL (sqrtf, float, (float x));
2205# else
2206# if !@HAVE_SQRTF@
2207# undef sqrtf
1871_GL_FUNCDECL_SYS (sqrtf, float, (float x)); 2208_GL_FUNCDECL_SYS (sqrtf, float, (float x));
1872# endif 2209# endif
1873_GL_CXXALIAS_SYS (sqrtf, float, (float x)); 2210_GL_CXXALIAS_SYS (sqrtf, float, (float x));
2211# endif
1874_GL_CXXALIASWARN (sqrtf); 2212_GL_CXXALIASWARN (sqrtf);
1875#elif defined GNULIB_POSIXCHECK 2213#elif defined GNULIB_POSIXCHECK
1876# undef sqrtf 2214# undef sqrtf
@@ -1895,7 +2233,9 @@ _GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
1895# endif 2233# endif
1896_GL_CXXALIAS_SYS (sqrtl, long double, (long double x)); 2234_GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
1897# endif 2235# endif
2236# if __GLIBC__ >= 2
1898_GL_CXXALIASWARN (sqrtl); 2237_GL_CXXALIASWARN (sqrtl);
2238# endif
1899#elif defined GNULIB_POSIXCHECK 2239#elif defined GNULIB_POSIXCHECK
1900# undef sqrtl 2240# undef sqrtl
1901# if HAVE_RAW_DECL_SQRTL 2241# if HAVE_RAW_DECL_SQRTL
@@ -1906,11 +2246,20 @@ _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
1906 2246
1907 2247
1908#if @GNULIB_TANF@ 2248#if @GNULIB_TANF@
1909# if !@HAVE_TANF@ 2249# if @REPLACE_TANF@
1910# undef tanf 2250# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2251# undef tanf
2252# define tanf rpl_tanf
2253# endif
2254_GL_FUNCDECL_RPL (tanf, float, (float x));
2255_GL_CXXALIAS_RPL (tanf, float, (float x));
2256# else
2257# if !@HAVE_TANF@
2258# undef tanf
1911_GL_FUNCDECL_SYS (tanf, float, (float x)); 2259_GL_FUNCDECL_SYS (tanf, float, (float x));
1912# endif 2260# endif
1913_GL_CXXALIAS_SYS (tanf, float, (float x)); 2261_GL_CXXALIAS_SYS (tanf, float, (float x));
2262# endif
1914_GL_CXXALIASWARN (tanf); 2263_GL_CXXALIASWARN (tanf);
1915#elif defined GNULIB_POSIXCHECK 2264#elif defined GNULIB_POSIXCHECK
1916# undef tanf 2265# undef tanf
@@ -1926,7 +2275,9 @@ _GL_WARN_ON_USE (tanf, "tanf is unportable - "
1926_GL_FUNCDECL_SYS (tanl, long double, (long double x)); 2275_GL_FUNCDECL_SYS (tanl, long double, (long double x));
1927# endif 2276# endif
1928_GL_CXXALIAS_SYS (tanl, long double, (long double x)); 2277_GL_CXXALIAS_SYS (tanl, long double, (long double x));
2278# if __GLIBC__ >= 2
1929_GL_CXXALIASWARN (tanl); 2279_GL_CXXALIASWARN (tanl);
2280# endif
1930#elif defined GNULIB_POSIXCHECK 2281#elif defined GNULIB_POSIXCHECK
1931# undef tanl 2282# undef tanl
1932# if HAVE_RAW_DECL_TANL 2283# if HAVE_RAW_DECL_TANL
@@ -1937,11 +2288,20 @@ _GL_WARN_ON_USE (tanl, "tanl is unportable - "
1937 2288
1938 2289
1939#if @GNULIB_TANHF@ 2290#if @GNULIB_TANHF@
1940# if !@HAVE_TANHF@ 2291# if @REPLACE_TANHF@
1941# undef tanhf 2292# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2293# undef tanhf
2294# define tanhf rpl_tanhf
2295# endif
2296_GL_FUNCDECL_RPL (tanhf, float, (float x));
2297_GL_CXXALIAS_RPL (tanhf, float, (float x));
2298# else
2299# if !@HAVE_TANHF@
2300# undef tanhf
1942_GL_FUNCDECL_SYS (tanhf, float, (float x)); 2301_GL_FUNCDECL_SYS (tanhf, float, (float x));
1943# endif 2302# endif
1944_GL_CXXALIAS_SYS (tanhf, float, (float x)); 2303_GL_CXXALIAS_SYS (tanhf, float, (float x));
2304# endif
1945_GL_CXXALIASWARN (tanhf); 2305_GL_CXXALIASWARN (tanhf);
1946#elif defined GNULIB_POSIXCHECK 2306#elif defined GNULIB_POSIXCHECK
1947# undef tanhf 2307# undef tanhf
@@ -1955,6 +2315,7 @@ _GL_WARN_ON_USE (tanhf, "tanhf is unportable - "
1955#if @GNULIB_TRUNCF@ 2315#if @GNULIB_TRUNCF@
1956# if @REPLACE_TRUNCF@ 2316# if @REPLACE_TRUNCF@
1957# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2317# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2318# undef truncf
1958# define truncf rpl_truncf 2319# define truncf rpl_truncf
1959# endif 2320# endif
1960_GL_FUNCDECL_RPL (truncf, float, (float x)); 2321_GL_FUNCDECL_RPL (truncf, float, (float x));
@@ -1977,6 +2338,7 @@ _GL_WARN_ON_USE (truncf, "truncf is unportable - "
1977#if @GNULIB_TRUNC@ 2338#if @GNULIB_TRUNC@
1978# if @REPLACE_TRUNC@ 2339# if @REPLACE_TRUNC@
1979# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2340# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2341# undef trunc
1980# define trunc rpl_trunc 2342# define trunc rpl_trunc
1981# endif 2343# endif
1982_GL_FUNCDECL_RPL (trunc, double, (double x)); 2344_GL_FUNCDECL_RPL (trunc, double, (double x));
@@ -1987,7 +2349,9 @@ _GL_FUNCDECL_SYS (trunc, double, (double x));
1987# endif 2349# endif
1988_GL_CXXALIAS_SYS (trunc, double, (double x)); 2350_GL_CXXALIAS_SYS (trunc, double, (double x));
1989# endif 2351# endif
1990_GL_CXXALIASWARN (trunc); 2352# if __GLIBC__ >= 2
2353_GL_CXXALIASWARN1 (trunc, double, (double x));
2354# endif
1991#elif defined GNULIB_POSIXCHECK 2355#elif defined GNULIB_POSIXCHECK
1992# undef trunc 2356# undef trunc
1993# if HAVE_RAW_DECL_TRUNC 2357# if HAVE_RAW_DECL_TRUNC
@@ -2010,7 +2374,9 @@ _GL_FUNCDECL_SYS (truncl, long double, (long double x));
2010# endif 2374# endif
2011_GL_CXXALIAS_SYS (truncl, long double, (long double x)); 2375_GL_CXXALIAS_SYS (truncl, long double, (long double x));
2012# endif 2376# endif
2377# if __GLIBC__ >= 2
2013_GL_CXXALIASWARN (truncl); 2378_GL_CXXALIASWARN (truncl);
2379# endif
2014#elif defined GNULIB_POSIXCHECK 2380#elif defined GNULIB_POSIXCHECK
2015# undef truncl 2381# undef truncl
2016# if HAVE_RAW_DECL_TRUNCL 2382# if HAVE_RAW_DECL_TRUNCL
@@ -2020,6 +2386,55 @@ _GL_WARN_ON_USE (truncl, "truncl is unportable - "
2020#endif 2386#endif
2021 2387
2022 2388
2389#if @GNULIB_MDA_Y0@
2390/* On native Windows, map 'y0' to '_y0', so that -loldnames is not
2391 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2392 platforms by defining GNULIB_NAMESPACE::y0 always. */
2393# if defined _WIN32 && !defined __CYGWIN__
2394# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2395# undef y0
2396# define y0 _y0
2397# endif
2398_GL_CXXALIAS_MDA (y0, double, (double x));
2399# else
2400_GL_CXXALIAS_SYS (y0, double, (double x));
2401# endif
2402_GL_CXXALIASWARN (y0);
2403#endif
2404
2405#if @GNULIB_MDA_Y1@
2406/* On native Windows, map 'y1' to '_y1', so that -loldnames is not
2407 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2408 platforms by defining GNULIB_NAMESPACE::y1 always. */
2409# if defined _WIN32 && !defined __CYGWIN__
2410# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2411# undef y1
2412# define y1 _y1
2413# endif
2414_GL_CXXALIAS_MDA (y1, double, (double x));
2415# else
2416_GL_CXXALIAS_SYS (y1, double, (double x));
2417# endif
2418_GL_CXXALIASWARN (y1);
2419#endif
2420
2421#if @GNULIB_MDA_YN@
2422/* On native Windows, map 'yn' to '_yn', so that -loldnames is not
2423 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2424 platforms by defining GNULIB_NAMESPACE::yn always. */
2425# if defined _WIN32 && !defined __CYGWIN__
2426# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2427# undef yn
2428# define yn _yn
2429# endif
2430_GL_CXXALIAS_MDA (yn, double, (int n, double x));
2431# else
2432_GL_CXXALIAS_SYS (yn, double, (int n, double x));
2433# endif
2434_GL_CXXALIASWARN (yn);
2435#endif
2436
2437
2023/* Definitions of function-like macros come here, after the function 2438/* Definitions of function-like macros come here, after the function
2024 declarations. */ 2439 declarations. */
2025 2440
@@ -2036,10 +2451,18 @@ _GL_EXTERN_C int gl_isfinitel (long double x);
2036 gl_isfinitef (x)) 2451 gl_isfinitef (x))
2037# endif 2452# endif
2038# ifdef __cplusplus 2453# ifdef __cplusplus
2039# ifdef isfinite 2454# if defined isfinite || defined GNULIB_NAMESPACE
2040_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite) 2455_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite)
2041# undef isfinite 2456# undef isfinite
2042_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite) 2457# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined _AIX || (defined _WIN32 && !defined __CYGWIN__)))
2458 /* This platform's <cmath> possibly defines isfinite through a set of inline
2459 functions. */
2460_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite, rpl_isfinite, bool)
2461# define isfinite rpl_isfinite
2462# define GNULIB_NAMESPACE_LACKS_ISFINITE 1
2463# else
2464_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite, isfinite, bool)
2465# endif
2043# endif 2466# endif
2044# endif 2467# endif
2045#elif defined GNULIB_POSIXCHECK 2468#elif defined GNULIB_POSIXCHECK
@@ -2063,10 +2486,18 @@ _GL_EXTERN_C int gl_isinfl (long double x);
2063 gl_isinff (x)) 2486 gl_isinff (x))
2064# endif 2487# endif
2065# ifdef __cplusplus 2488# ifdef __cplusplus
2066# ifdef isinf 2489# if defined isinf || defined GNULIB_NAMESPACE
2067_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf) 2490_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf)
2068# undef isinf 2491# undef isinf
2069_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf) 2492# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || (defined _WIN32 && !defined __CYGWIN__)))
2493 /* This platform's <cmath> possibly defines isinf through a set of inline
2494 functions. */
2495_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf, rpl_isinf, bool)
2496# define isinf rpl_isinf
2497# define GNULIB_NAMESPACE_LACKS_ISINF 1
2498# else
2499_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf, isinf, bool)
2500# endif
2070# endif 2501# endif
2071# endif 2502# endif
2072#elif defined GNULIB_POSIXCHECK 2503#elif defined GNULIB_POSIXCHECK
@@ -2083,10 +2514,11 @@ _GL_WARN_REAL_FLOATING_DECL (isinf);
2083# if @HAVE_ISNANF@ 2514# if @HAVE_ISNANF@
2084/* The original <math.h> included above provides a declaration of isnan macro 2515/* The original <math.h> included above provides a declaration of isnan macro
2085 or (older) isnanf function. */ 2516 or (older) isnanf function. */
2086# if __GNUC__ >= 4 2517# if (__GNUC__ >= 4) || (__clang_major__ >= 4)
2087 /* GCC 4.0 and newer provides three built-ins for isnan. */ 2518 /* GCC >= 4.0 and clang provide a type-generic built-in for isnan.
2519 GCC >= 4.0 also provides __builtin_isnanf, but clang doesn't. */
2088# undef isnanf 2520# undef isnanf
2089# define isnanf(x) __builtin_isnanf ((float)(x)) 2521# define isnanf(x) __builtin_isnan ((float)(x))
2090# elif defined isnan 2522# elif defined isnan
2091# undef isnanf 2523# undef isnanf
2092# define isnanf(x) isnan ((float)(x)) 2524# define isnanf(x) isnan ((float)(x))
@@ -2106,8 +2538,8 @@ _GL_EXTERN_C int isnanf (float x);
2106# if @HAVE_ISNAND@ 2538# if @HAVE_ISNAND@
2107/* The original <math.h> included above provides a declaration of isnan 2539/* The original <math.h> included above provides a declaration of isnan
2108 macro. */ 2540 macro. */
2109# if __GNUC__ >= 4 2541# if (__GNUC__ >= 4) || (__clang_major__ >= 4)
2110 /* GCC 4.0 and newer provides three built-ins for isnan. */ 2542 /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. */
2111# undef isnand 2543# undef isnand
2112# define isnand(x) __builtin_isnan ((double)(x)) 2544# define isnand(x) __builtin_isnan ((double)(x))
2113# else 2545# else
@@ -2127,10 +2559,11 @@ _GL_EXTERN_C int isnand (double x);
2127# if @HAVE_ISNANL@ 2559# if @HAVE_ISNANL@
2128/* The original <math.h> included above provides a declaration of isnan 2560/* The original <math.h> included above provides a declaration of isnan
2129 macro or (older) isnanl function. */ 2561 macro or (older) isnanl function. */
2130# if __GNUC__ >= 4 2562# if (__GNUC__ >= 4) || (__clang_major__ >= 4)
2131 /* GCC 4.0 and newer provides three built-ins for isnan. */ 2563 /* GCC >= 4.0 and clang provide a type-generic built-in for isnan.
2564 GCC >= 4.0 also provides __builtin_isnanl, but clang doesn't. */
2132# undef isnanl 2565# undef isnanl
2133# define isnanl(x) __builtin_isnanl ((long double)(x)) 2566# define isnanl(x) __builtin_isnan ((long double)(x))
2134# elif defined isnan 2567# elif defined isnan
2135# undef isnanl 2568# undef isnanl
2136# define isnanl(x) isnan ((long double)(x)) 2569# define isnanl(x) isnan ((long double)(x))
@@ -2150,20 +2583,20 @@ _GL_EXTERN_C int isnanl (long double x) _GL_ATTRIBUTE_CONST;
2150 isnanf.h (e.g.) here, because those may end up being macros 2583 isnanf.h (e.g.) here, because those may end up being macros
2151 that recursively expand back to isnan. So use the gnulib 2584 that recursively expand back to isnan. So use the gnulib
2152 replacements for them directly. */ 2585 replacements for them directly. */
2153# if @HAVE_ISNANF@ && __GNUC__ >= 4 2586# if @HAVE_ISNANF@ && (__GNUC__ >= 4) || (__clang_major__ >= 4)
2154# define gl_isnan_f(x) __builtin_isnanf ((float)(x)) 2587# define gl_isnan_f(x) __builtin_isnan ((float)(x))
2155# else 2588# else
2156_GL_EXTERN_C int rpl_isnanf (float x); 2589_GL_EXTERN_C int rpl_isnanf (float x);
2157# define gl_isnan_f(x) rpl_isnanf (x) 2590# define gl_isnan_f(x) rpl_isnanf (x)
2158# endif 2591# endif
2159# if @HAVE_ISNAND@ && __GNUC__ >= 4 2592# if @HAVE_ISNAND@ && (__GNUC__ >= 4) || (__clang_major__ >= 4)
2160# define gl_isnan_d(x) __builtin_isnan ((double)(x)) 2593# define gl_isnan_d(x) __builtin_isnan ((double)(x))
2161# else 2594# else
2162_GL_EXTERN_C int rpl_isnand (double x); 2595_GL_EXTERN_C int rpl_isnand (double x);
2163# define gl_isnan_d(x) rpl_isnand (x) 2596# define gl_isnan_d(x) rpl_isnand (x)
2164# endif 2597# endif
2165# if @HAVE_ISNANL@ && __GNUC__ >= 4 2598# if @HAVE_ISNANL@ && (__GNUC__ >= 4) || (__clang_major__ >= 4)
2166# define gl_isnan_l(x) __builtin_isnanl ((long double)(x)) 2599# define gl_isnan_l(x) __builtin_isnan ((long double)(x))
2167# else 2600# else
2168_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; 2601_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
2169# define gl_isnan_l(x) rpl_isnanl (x) 2602# define gl_isnan_l(x) rpl_isnanl (x)
@@ -2173,18 +2606,26 @@ _GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
2173 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \ 2606 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
2174 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \ 2607 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
2175 gl_isnan_f (x)) 2608 gl_isnan_f (x))
2176# elif __GNUC__ >= 4 2609# elif (__GNUC__ >= 4) || (__clang_major__ >= 4)
2177# undef isnan 2610# undef isnan
2178# define isnan(x) \ 2611# define isnan(x) \
2179 (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \ 2612 (sizeof (x) == sizeof (long double) ? __builtin_isnan ((long double)(x)) : \
2180 sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \ 2613 sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
2181 __builtin_isnanf ((float)(x))) 2614 __builtin_isnan ((float)(x)))
2182# endif 2615# endif
2183# ifdef __cplusplus 2616# ifdef __cplusplus
2184# ifdef isnan 2617# if defined isnan || defined GNULIB_NAMESPACE
2185_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan) 2618_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan)
2186# undef isnan 2619# undef isnan
2187_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan) 2620# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__ && __clang_major__ < 12) || (defined __FreeBSD__ && (__clang_major__ < 7 || __clang_major__ >= 11)) || defined __OpenBSD__ || (defined _WIN32 && !defined __CYGWIN__)))
2621 /* This platform's <cmath> possibly defines isnan through a set of inline
2622 functions. */
2623_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, rpl_isnan, bool)
2624# define isnan rpl_isnan
2625# define GNULIB_NAMESPACE_LACKS_ISNAN 1
2626# else
2627_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, isnan, bool)
2628# endif
2188# endif 2629# endif
2189# else 2630# else
2190/* Ensure isnan is a macro. */ 2631/* Ensure isnan is a macro. */
@@ -2202,20 +2643,21 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
2202 2643
2203 2644
2204#if @GNULIB_SIGNBIT@ 2645#if @GNULIB_SIGNBIT@
2205# if @REPLACE_SIGNBIT_USING_GCC@ 2646# if (@REPLACE_SIGNBIT_USING_BUILTINS@ \
2647 && (!defined __cplusplus || __cplusplus < 201103))
2206# undef signbit 2648# undef signbit
2207 /* GCC 4.0 and newer provides three built-ins for signbit. */ 2649 /* GCC >= 4.0 and clang provide three built-ins for signbit. */
2208# define signbit(x) \ 2650# define signbit(x) \
2209 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \ 2651 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
2210 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \ 2652 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
2211 __builtin_signbitf (x)) 2653 __builtin_signbitf (x))
2212# endif 2654# endif
2213# if @REPLACE_SIGNBIT@ 2655# if @REPLACE_SIGNBIT@ && !GNULIB_defined_signbit
2214# undef signbit 2656# undef signbit
2215_GL_EXTERN_C int gl_signbitf (float arg); 2657_GL_EXTERN_C int gl_signbitf (float arg);
2216_GL_EXTERN_C int gl_signbitd (double arg); 2658_GL_EXTERN_C int gl_signbitd (double arg);
2217_GL_EXTERN_C int gl_signbitl (long double arg); 2659_GL_EXTERN_C int gl_signbitl (long double arg);
2218# if __GNUC__ >= 2 && !defined __STRICT_ANSI__ 2660# if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
2219# define _GL_NUM_UINT_WORDS(type) \ 2661# define _GL_NUM_UINT_WORDS(type) \
2220 ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) 2662 ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
2221# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf 2663# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
@@ -2253,12 +2695,21 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
2253 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \ 2695 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
2254 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \ 2696 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
2255 gl_signbitf (x)) 2697 gl_signbitf (x))
2698# define GNULIB_defined_signbit 1
2256# endif 2699# endif
2257# ifdef __cplusplus 2700# ifdef __cplusplus
2258# ifdef signbit 2701# if defined signbit || defined GNULIB_NAMESPACE
2259_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit) 2702_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
2260# undef signbit 2703# undef signbit
2261_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit) 2704# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined _AIX || (defined _WIN32 && !defined __CYGWIN__)))
2705 /* This platform's <cmath> possibly defines signbit through a set of inline
2706 functions. */
2707_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit, rpl_signbit, bool)
2708# define signbit rpl_signbit
2709# define GNULIB_NAMESPACE_LACKS_SIGNBIT 1
2710# else
2711_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit, signbit, bool)
2712# endif
2262# endif 2713# endif
2263# endif 2714# endif
2264#elif defined GNULIB_POSIXCHECK 2715#elif defined GNULIB_POSIXCHECK
@@ -2272,4 +2723,5 @@ _GL_WARN_REAL_FLOATING_DECL (signbit);
2272_GL_INLINE_HEADER_END 2723_GL_INLINE_HEADER_END
2273 2724
2274#endif /* _@GUARD_PREFIX@_MATH_H */ 2725#endif /* _@GUARD_PREFIX@_MATH_H */
2726#endif /* _GL_INCLUDING_MATH_H */
2275#endif /* _@GUARD_PREFIX@_MATH_H */ 2727#endif /* _@GUARD_PREFIX@_MATH_H */
diff --git a/gl/mbrtowc-impl-utf8.h b/gl/mbrtowc-impl-utf8.h
new file mode 100644
index 0000000..4fdd65d
--- /dev/null
+++ b/gl/mbrtowc-impl-utf8.h
@@ -0,0 +1,138 @@
1/* Convert multibyte character to wide character.
2 Copyright (C) 1999-2002, 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
18
19/* This file contains the part of the body of the mbrtowc and mbrtoc32 functions
20 that handles the special case of the UTF-8 encoding. */
21
22 /* Cf. unistr/u8-mbtouc.c. */
23 unsigned char c = (unsigned char) p[0];
24
25 if (c < 0x80)
26 {
27 if (pwc != NULL)
28 *pwc = c;
29 res = (c == 0 ? 0 : 1);
30 goto success;
31 }
32 if (c >= 0xc2)
33 {
34 if (c < 0xe0)
35 {
36 if (m == 1)
37 goto incomplete;
38 else /* m >= 2 */
39 {
40 unsigned char c2 = (unsigned char) p[1];
41
42 if ((c2 ^ 0x80) < 0x40)
43 {
44 if (pwc != NULL)
45 *pwc = ((unsigned int) (c & 0x1f) << 6)
46 | (unsigned int) (c2 ^ 0x80);
47 res = 2;
48 goto success;
49 }
50 }
51 }
52 else if (c < 0xf0)
53 {
54 if (m == 1)
55 goto incomplete;
56 else
57 {
58 unsigned char c2 = (unsigned char) p[1];
59
60 if ((c2 ^ 0x80) < 0x40
61 && (c >= 0xe1 || c2 >= 0xa0)
62 && (c != 0xed || c2 < 0xa0))
63 {
64 if (m == 2)
65 goto incomplete;
66 else /* m >= 3 */
67 {
68 unsigned char c3 = (unsigned char) p[2];
69
70 if ((c3 ^ 0x80) < 0x40)
71 {
72 unsigned int wc =
73 (((unsigned int) (c & 0x0f) << 12)
74 | ((unsigned int) (c2 ^ 0x80) << 6)
75 | (unsigned int) (c3 ^ 0x80));
76
77 if (FITS_IN_CHAR_TYPE (wc))
78 {
79 if (pwc != NULL)
80 *pwc = wc;
81 res = 3;
82 goto success;
83 }
84 }
85 }
86 }
87 }
88 }
89 else if (c <= 0xf4)
90 {
91 if (m == 1)
92 goto incomplete;
93 else
94 {
95 unsigned char c2 = (unsigned char) p[1];
96
97 if ((c2 ^ 0x80) < 0x40
98 && (c >= 0xf1 || c2 >= 0x90)
99 && (c < 0xf4 || (/* c == 0xf4 && */ c2 < 0x90)))
100 {
101 if (m == 2)
102 goto incomplete;
103 else
104 {
105 unsigned char c3 = (unsigned char) p[2];
106
107 if ((c3 ^ 0x80) < 0x40)
108 {
109 if (m == 3)
110 goto incomplete;
111 else /* m >= 4 */
112 {
113 unsigned char c4 = (unsigned char) p[3];
114
115 if ((c4 ^ 0x80) < 0x40)
116 {
117 unsigned int wc =
118 (((unsigned int) (c & 0x07) << 18)
119 | ((unsigned int) (c2 ^ 0x80) << 12)
120 | ((unsigned int) (c3 ^ 0x80) << 6)
121 | (unsigned int) (c4 ^ 0x80));
122
123 if (FITS_IN_CHAR_TYPE (wc))
124 {
125 if (pwc != NULL)
126 *pwc = wc;
127 res = 4;
128 goto success;
129 }
130 }
131 }
132 }
133 }
134 }
135 }
136 }
137 }
138 goto invalid;
diff --git a/gl/mbrtowc-impl.h b/gl/mbrtowc-impl.h
new file mode 100644
index 0000000..e9c04ed
--- /dev/null
+++ b/gl/mbrtowc-impl.h
@@ -0,0 +1,262 @@
1/* Convert multibyte character to wide character.
2 Copyright (C) 1999-2002, 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
18
19/* This file contains the body of the mbrtowc and mbrtoc32 functions,
20 when GNULIB_defined_mbstate_t is defined. */
21
22 char *pstate = (char *)ps;
23
24 if (s == NULL)
25 {
26 pwc = NULL;
27 s = "";
28 n = 1;
29 }
30
31 if (n == 0)
32 return (size_t)(-2);
33
34 /* Here n > 0. */
35
36 if (pstate == NULL)
37 pstate = internal_state;
38
39 {
40 size_t nstate = pstate[0];
41 char buf[4];
42 const char *p;
43 size_t m;
44 enc_t enc;
45 int res;
46
47 switch (nstate)
48 {
49 case 0:
50 p = s;
51 m = n;
52 break;
53 case 3:
54 buf[2] = pstate[3];
55 FALLTHROUGH;
56 case 2:
57 buf[1] = pstate[2];
58 FALLTHROUGH;
59 case 1:
60 buf[0] = pstate[1];
61 p = buf;
62 m = nstate;
63 buf[m++] = s[0];
64 if (n >= 2 && m < 4)
65 {
66 buf[m++] = s[1];
67 if (n >= 3 && m < 4)
68 buf[m++] = s[2];
69 }
70 break;
71 default:
72 errno = EINVAL;
73 return (size_t)(-1);
74 }
75
76 /* Here m > 0. */
77
78 enc = locale_encoding_classification ();
79
80 if (enc == enc_utf8) /* UTF-8 */
81 {
82 /* Achieve
83 - multi-thread safety and
84 - the ability to produce wide character values > WCHAR_MAX
85 by not calling mbtowc() at all. */
86#include "mbrtowc-impl-utf8.h"
87 }
88 else
89 {
90 /* The hidden internal state of mbtowc would make this function not
91 multi-thread safe. Achieve multi-thread safety through a lock. */
92 wchar_t wc;
93 res = mbtowc_with_lock (&wc, p, m);
94
95 if (res >= 0)
96 {
97 if ((wc == 0) != (res == 0))
98 abort ();
99 if (pwc != NULL)
100 *pwc = wc;
101 goto success;
102 }
103
104 /* mbtowc does not distinguish between invalid and incomplete multibyte
105 sequences. But mbrtowc needs to make this distinction.
106 There are two possible approaches:
107 - Use iconv() and its return value.
108 - Use built-in knowledge about the possible encodings.
109 Given the low quality of implementation of iconv() on the systems
110 that lack mbrtowc(), we use the second approach.
111 The possible encodings are:
112 - 8-bit encodings,
113 - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
114 - UTF-8 (already handled above).
115 Use specialized code for each. */
116 if (m >= 4 || m >= MB_CUR_MAX)
117 goto invalid;
118 /* Here MB_CUR_MAX > 1 and 0 < m < 4. */
119 switch (enc)
120 {
121 /* As a reference for this code, you can use the GNU libiconv
122 implementation. Look for uses of the RET_TOOFEW macro. */
123
124 case enc_eucjp: /* EUC-JP */
125 {
126 if (m == 1)
127 {
128 unsigned char c = (unsigned char) p[0];
129
130 if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
131 goto incomplete;
132 }
133 if (m == 2)
134 {
135 unsigned char c = (unsigned char) p[0];
136
137 if (c == 0x8f)
138 {
139 unsigned char c2 = (unsigned char) p[1];
140
141 if (c2 >= 0xa1 && c2 < 0xff)
142 goto incomplete;
143 }
144 }
145 goto invalid;
146 }
147
148 case enc_94: /* EUC-KR, GB2312, BIG5 */
149 {
150 if (m == 1)
151 {
152 unsigned char c = (unsigned char) p[0];
153
154 if (c >= 0xa1 && c < 0xff)
155 goto incomplete;
156 }
157 goto invalid;
158 }
159
160 case enc_euctw: /* EUC-TW */
161 {
162 if (m == 1)
163 {
164 unsigned char c = (unsigned char) p[0];
165
166 if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
167 goto incomplete;
168 }
169 else /* m == 2 || m == 3 */
170 {
171 unsigned char c = (unsigned char) p[0];
172
173 if (c == 0x8e)
174 goto incomplete;
175 }
176 goto invalid;
177 }
178
179 case enc_gb18030: /* GB18030 */
180 {
181 if (m == 1)
182 {
183 unsigned char c = (unsigned char) p[0];
184
185 if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
186 goto incomplete;
187 }
188 else /* m == 2 || m == 3 */
189 {
190 unsigned char c = (unsigned char) p[0];
191
192 if (c >= 0x90 && c <= 0xe3)
193 {
194 unsigned char c2 = (unsigned char) p[1];
195
196 if (c2 >= 0x30 && c2 <= 0x39)
197 {
198 if (m == 2)
199 goto incomplete;
200 else /* m == 3 */
201 {
202 unsigned char c3 = (unsigned char) p[2];
203
204 if (c3 >= 0x81 && c3 <= 0xfe)
205 goto incomplete;
206 }
207 }
208 }
209 }
210 goto invalid;
211 }
212
213 case enc_sjis: /* SJIS */
214 {
215 if (m == 1)
216 {
217 unsigned char c = (unsigned char) p[0];
218
219 if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
220 || (c >= 0xf0 && c <= 0xf9))
221 goto incomplete;
222 }
223 goto invalid;
224 }
225
226 default:
227 /* An unknown multibyte encoding. */
228 goto incomplete;
229 }
230 }
231
232 success:
233 /* res >= 0 is the corrected return value of
234 mbtowc_with_lock (&wc, p, m). */
235 if (nstate >= (res > 0 ? res : 1))
236 abort ();
237 res -= nstate;
238 pstate[0] = 0;
239 return res;
240
241 incomplete:
242 {
243 size_t k = nstate;
244 /* Here 0 <= k < m < 4. */
245 pstate[++k] = s[0];
246 if (k < m)
247 {
248 pstate[++k] = s[1];
249 if (k < m)
250 pstate[++k] = s[2];
251 }
252 if (k != m)
253 abort ();
254 }
255 pstate[0] = m;
256 return (size_t)(-2);
257
258 invalid:
259 errno = EILSEQ;
260 /* The conversion state is undefined, says POSIX. */
261 return (size_t)(-1);
262 }
diff --git a/gl/mbrtowc.c b/gl/mbrtowc.c
index 5ee44ae..c1a689a 100644
--- a/gl/mbrtowc.c
+++ b/gl/mbrtowc.c
@@ -1,19 +1,19 @@
1/* Convert multibyte character to wide character. 1/* Convert multibyte character to wide character.
2 Copyright (C) 1999-2002, 2005-2013 Free Software Foundation, Inc. 2 Copyright (C) 1999-2002, 2005-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -21,314 +21,66 @@
21#include <wchar.h> 21#include <wchar.h>
22 22
23#if GNULIB_defined_mbstate_t 23#if GNULIB_defined_mbstate_t
24/* Implement mbrtowc() on top of mbtowc(). */ 24/* Implement mbrtowc() on top of mbtowc() for the non-UTF-8 locales
25 and directly for the UTF-8 locales. */
25 26
26# include <errno.h> 27# include <errno.h>
28# include <stdint.h>
27# include <stdlib.h> 29# include <stdlib.h>
28 30
29# include "localcharset.h" 31# if defined _WIN32 && !defined __CYGWIN__
30# include "streq.h"
31# include "verify.h"
32 32
33# define WIN32_LEAN_AND_MEAN /* avoid including junk */
34# include <windows.h>
33 35
34verify (sizeof (mbstate_t) >= 4); 36# elif HAVE_PTHREAD_API
35 37
36static char internal_state[4]; 38# include <pthread.h>
39# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS
40# include <threads.h>
41# pragma weak thrd_exit
42# define c11_threads_in_use() (thrd_exit != NULL)
43# else
44# define c11_threads_in_use() 0
45# endif
37 46
38size_t 47# elif HAVE_THREADS_H
39mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
40{
41 char *pstate = (char *)ps;
42
43 if (s == NULL)
44 {
45 pwc = NULL;
46 s = "";
47 n = 1;
48 }
49
50 if (n == 0)
51 return (size_t)(-2);
52 48
53 /* Here n > 0. */ 49# include <threads.h>
54 50
55 if (pstate == NULL)
56 pstate = internal_state;
57
58 {
59 size_t nstate = pstate[0];
60 char buf[4];
61 const char *p;
62 size_t m;
63
64 switch (nstate)
65 {
66 case 0:
67 p = s;
68 m = n;
69 break;
70 case 3:
71 buf[2] = pstate[3];
72 /*FALLTHROUGH*/
73 case 2:
74 buf[1] = pstate[2];
75 /*FALLTHROUGH*/
76 case 1:
77 buf[0] = pstate[1];
78 p = buf;
79 m = nstate;
80 buf[m++] = s[0];
81 if (n >= 2 && m < 4)
82 {
83 buf[m++] = s[1];
84 if (n >= 3 && m < 4)
85 buf[m++] = s[2];
86 }
87 break;
88 default:
89 errno = EINVAL;
90 return (size_t)(-1);
91 }
92
93 /* Here m > 0. */
94
95# if __GLIBC__ || defined __UCLIBC__
96 /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
97 mbtowc (NULL, NULL, 0);
98# endif 51# endif
99 {
100 int res = mbtowc (pwc, p, m);
101
102 if (res >= 0)
103 {
104 if (pwc != NULL && ((*pwc == 0) != (res == 0)))
105 abort ();
106 if (nstate >= (res > 0 ? res : 1))
107 abort ();
108 res -= nstate;
109 pstate[0] = 0;
110 return res;
111 }
112
113 /* mbtowc does not distinguish between invalid and incomplete multibyte
114 sequences. But mbrtowc needs to make this distinction.
115 There are two possible approaches:
116 - Use iconv() and its return value.
117 - Use built-in knowledge about the possible encodings.
118 Given the low quality of implementation of iconv() on the systems that
119 lack mbrtowc(), we use the second approach.
120 The possible encodings are:
121 - 8-bit encodings,
122 - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
123 - UTF-8.
124 Use specialized code for each. */
125 if (m >= 4 || m >= MB_CUR_MAX)
126 goto invalid;
127 /* Here MB_CUR_MAX > 1 and 0 < m < 4. */
128 {
129 const char *encoding = locale_charset ();
130
131 if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
132 {
133 /* Cf. unistr/u8-mblen.c. */
134 unsigned char c = (unsigned char) p[0];
135
136 if (c >= 0xc2)
137 {
138 if (c < 0xe0)
139 {
140 if (m == 1)
141 goto incomplete;
142 }
143 else if (c < 0xf0)
144 {
145 if (m == 1)
146 goto incomplete;
147 if (m == 2)
148 {
149 unsigned char c2 = (unsigned char) p[1];
150
151 if ((c2 ^ 0x80) < 0x40
152 && (c >= 0xe1 || c2 >= 0xa0)
153 && (c != 0xed || c2 < 0xa0))
154 goto incomplete;
155 }
156 }
157 else if (c <= 0xf4)
158 {
159 if (m == 1)
160 goto incomplete;
161 else /* m == 2 || m == 3 */
162 {
163 unsigned char c2 = (unsigned char) p[1];
164
165 if ((c2 ^ 0x80) < 0x40
166 && (c >= 0xf1 || c2 >= 0x90)
167 && (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
168 {
169 if (m == 2)
170 goto incomplete;
171 else /* m == 3 */
172 {
173 unsigned char c3 = (unsigned char) p[2];
174
175 if ((c3 ^ 0x80) < 0x40)
176 goto incomplete;
177 }
178 }
179 }
180 }
181 }
182 goto invalid;
183 }
184
185 /* As a reference for this code, you can use the GNU libiconv
186 implementation. Look for uses of the RET_TOOFEW macro. */
187
188 if (STREQ_OPT (encoding,
189 "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
190 {
191 if (m == 1)
192 {
193 unsigned char c = (unsigned char) p[0];
194
195 if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
196 goto incomplete;
197 }
198 if (m == 2)
199 {
200 unsigned char c = (unsigned char) p[0];
201
202 if (c == 0x8f)
203 {
204 unsigned char c2 = (unsigned char) p[1];
205
206 if (c2 >= 0xa1 && c2 < 0xff)
207 goto incomplete;
208 }
209 }
210 goto invalid;
211 }
212 if (STREQ_OPT (encoding,
213 "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
214 || STREQ_OPT (encoding,
215 "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
216 || STREQ_OPT (encoding,
217 "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
218 {
219 if (m == 1)
220 {
221 unsigned char c = (unsigned char) p[0];
222
223 if (c >= 0xa1 && c < 0xff)
224 goto incomplete;
225 }
226 goto invalid;
227 }
228 if (STREQ_OPT (encoding,
229 "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
230 {
231 if (m == 1)
232 {
233 unsigned char c = (unsigned char) p[0];
234
235 if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
236 goto incomplete;
237 }
238 else /* m == 2 || m == 3 */
239 {
240 unsigned char c = (unsigned char) p[0];
241
242 if (c == 0x8e)
243 goto incomplete;
244 }
245 goto invalid;
246 }
247 if (STREQ_OPT (encoding,
248 "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
249 {
250 if (m == 1)
251 {
252 unsigned char c = (unsigned char) p[0];
253 52
254 if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) 53# include "attribute.h"
255 goto incomplete; 54# include "lc-charset-dispatch.h"
256 } 55# include "mbtowc-lock.h"
257 else /* m == 2 || m == 3 */
258 {
259 unsigned char c = (unsigned char) p[0];
260
261 if (c >= 0x90 && c <= 0xe3)
262 {
263 unsigned char c2 = (unsigned char) p[1];
264
265 if (c2 >= 0x30 && c2 <= 0x39)
266 {
267 if (m == 2)
268 goto incomplete;
269 else /* m == 3 */
270 {
271 unsigned char c3 = (unsigned char) p[2];
272
273 if (c3 >= 0x81 && c3 <= 0xfe)
274 goto incomplete;
275 }
276 }
277 }
278 }
279 goto invalid;
280 }
281 if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
282 {
283 if (m == 1)
284 {
285 unsigned char c = (unsigned char) p[0];
286 56
287 if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) 57static_assert (sizeof (mbstate_t) >= 4);
288 || (c >= 0xf0 && c <= 0xf9)) 58static char internal_state[4];
289 goto incomplete;
290 }
291 goto invalid;
292 }
293
294 /* An unknown multibyte encoding. */
295 goto incomplete;
296 }
297
298 incomplete:
299 {
300 size_t k = nstate;
301 /* Here 0 <= k < m < 4. */
302 pstate[++k] = s[0];
303 if (k < m)
304 {
305 pstate[++k] = s[1];
306 if (k < m)
307 pstate[++k] = s[2];
308 }
309 if (k != m)
310 abort ();
311 }
312 pstate[0] = m;
313 return (size_t)(-2);
314 59
315 invalid: 60size_t
316 errno = EILSEQ; 61mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
317 /* The conversion state is undefined, says POSIX. */ 62{
318 return (size_t)(-1); 63# define FITS_IN_CHAR_TYPE(wc) ((wc) <= WCHAR_MAX)
319 } 64# include "mbrtowc-impl.h"
320 }
321} 65}
322 66
323#else 67#else
324/* Override the system's mbrtowc() function. */ 68/* Override the system's mbrtowc() function. */
325 69
70# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ
71# include "hard-locale.h"
72# include <locale.h>
73# endif
74
326# undef mbrtowc 75# undef mbrtowc
327 76
328size_t 77size_t
329rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) 78rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
330{ 79{
331# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG 80 size_t ret;
81 wchar_t wc;
82
83# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG || MBRTOWC_EMPTY_INPUT_BUG
332 if (s == NULL) 84 if (s == NULL)
333 { 85 {
334 pwc = NULL; 86 pwc = NULL;
@@ -337,6 +89,14 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
337 } 89 }
338# endif 90# endif
339 91
92# if MBRTOWC_EMPTY_INPUT_BUG
93 if (n == 0)
94 return (size_t) -2;
95# endif
96
97 if (! pwc)
98 pwc = &wc;
99
340# if MBRTOWC_RETVAL_BUG 100# if MBRTOWC_RETVAL_BUG
341 { 101 {
342 static mbstate_t internal_state; 102 static mbstate_t internal_state;
@@ -352,8 +112,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
352 size_t count = 0; 112 size_t count = 0;
353 for (; n > 0; s++, n--) 113 for (; n > 0; s++, n--)
354 { 114 {
355 wchar_t wc; 115 ret = mbrtowc (&wc, s, 1, ps);
356 size_t ret = mbrtowc (&wc, s, 1, ps);
357 116
358 if (ret == (size_t)(-1)) 117 if (ret == (size_t)(-1))
359 return (size_t)(-1); 118 return (size_t)(-1);
@@ -361,8 +120,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
361 if (ret != (size_t)(-2)) 120 if (ret != (size_t)(-2))
362 { 121 {
363 /* The multibyte character has been completed. */ 122 /* The multibyte character has been completed. */
364 if (pwc != NULL) 123 *pwc = wc;
365 *pwc = wc;
366 return (wc == 0 ? 0 : count); 124 return (wc == 0 ? 0 : count);
367 } 125 }
368 } 126 }
@@ -371,32 +129,29 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
371 } 129 }
372# endif 130# endif
373 131
374# if MBRTOWC_NUL_RETVAL_BUG 132# if MBRTOWC_STORES_INCOMPLETE_BUG
375 { 133 ret = mbrtowc (&wc, s, n, ps);
376 wchar_t wc; 134 if (ret < (size_t) -2 && pwc != NULL)
377 size_t ret = mbrtowc (&wc, s, n, ps); 135 *pwc = wc;
378
379 if (ret != (size_t)(-1) && ret != (size_t)(-2))
380 {
381 if (pwc != NULL)
382 *pwc = wc;
383 if (wc == 0)
384 ret = 0;
385 }
386 return ret;
387 }
388# else 136# else
389 { 137 ret = mbrtowc (pwc, s, n, ps);
390# if MBRTOWC_NULL_ARG1_BUG 138# endif
391 wchar_t dummy;
392 139
393 if (pwc == NULL) 140# if MBRTOWC_NUL_RETVAL_BUG
394 pwc = &dummy; 141 if (ret < (size_t) -2 && !*pwc)
395# endif 142 return 0;
143# endif
396 144
397 return mbrtowc (pwc, s, n, ps); 145# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ
398 } 146 if ((size_t) -2 <= ret && n != 0 && ! hard_locale (LC_CTYPE))
147 {
148 unsigned char uc = *s;
149 *pwc = uc;
150 return 1;
151 }
399# endif 152# endif
153
154 return ret;
400} 155}
401 156
402#endif 157#endif
diff --git a/gl/mbsinit.c b/gl/mbsinit.c
index 26fbb7f..6e60079 100644
--- a/gl/mbsinit.c
+++ b/gl/mbsinit.c
@@ -1,38 +1,27 @@
1/* Test for initial conversion state. 1/* Test for initial conversion state.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
20/* Specification. */ 20/* Specification. */
21#include <wchar.h> 21#include <wchar.h>
22 22
23#include "verify.h"
24 23
25#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 24#if GNULIB_defined_mbstate_t
26
27/* On native Windows, 'mbstate_t' is defined as 'int'. */
28
29int
30mbsinit (const mbstate_t *ps)
31{
32 return ps == NULL || *ps == 0;
33}
34
35#else
36 25
37/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs() 26/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
38 and wcrtomb(), wcsrtombs(). 27 and wcrtomb(), wcsrtombs().
@@ -45,10 +34,11 @@ mbsinit (const mbstate_t *ps)
45 We define the meaning of mbstate_t as follows: 34 We define the meaning of mbstate_t as follows:
46 - In mb -> wc direction, mbstate_t's first byte contains the number of 35 - In mb -> wc direction, mbstate_t's first byte contains the number of
47 buffered bytes (in the range 0..3), followed by up to 3 buffered bytes. 36 buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
37 See mbrtowc.c.
48 - In wc -> mb direction, mbstate_t contains no information. In other 38 - In wc -> mb direction, mbstate_t contains no information. In other
49 words, it is always in the initial state. */ 39 words, it is always in the initial state. */
50 40
51verify (sizeof (mbstate_t) >= 4); 41static_assert (sizeof (mbstate_t) >= 4);
52 42
53int 43int
54mbsinit (const mbstate_t *ps) 44mbsinit (const mbstate_t *ps)
@@ -58,4 +48,22 @@ mbsinit (const mbstate_t *ps)
58 return pstate == NULL || pstate[0] == 0; 48 return pstate == NULL || pstate[0] == 0;
59} 49}
60 50
51#else
52
53int
54mbsinit (const mbstate_t *ps)
55{
56# if defined _WIN32 && !defined __CYGWIN__
57 /* Native Windows. */
58 /* MSVC defines 'mbstate_t' as an 8-byte struct; the first 4 bytes matter.
59 On mingw, 'mbstate_t' is sometimes defined as 'int', sometimes defined as
60 an 8-byte struct, of which the first 4 bytes matter. */
61 return ps == NULL || *(const unsigned int *)ps == 0;
62# else
63 /* Minix, HP-UX 11.00, Solaris 2.6, Interix, ... */
64 /* Maybe this definition works, maybe not... */
65 return ps == NULL || *(const char *)ps == 0;
66# endif
67}
68
61#endif 69#endif
diff --git a/gl/mbtowc-impl.h b/gl/mbtowc-impl.h
index 767ab39..39b977b 100644
--- a/gl/mbtowc-impl.h
+++ b/gl/mbtowc-impl.h
@@ -1,19 +1,19 @@
1/* Convert multibyte character to wide character. 1/* Convert multibyte character to wide character.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011. 3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* We don't need a static internal state, because the encoding is not state 18/* We don't need a static internal state, because the encoding is not state
19 dependent, and when mbrtowc returns (size_t)(-2). we throw the result 19 dependent, and when mbrtowc returns (size_t)(-2). we throw the result
diff --git a/gl/mbtowc-lock.c b/gl/mbtowc-lock.c
new file mode 100644
index 0000000..6ca6e10
--- /dev/null
+++ b/gl/mbtowc-lock.c
@@ -0,0 +1,150 @@
1/* Return the internal lock used by mbrtowc and mbrtoc32.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019-2020. */
18
19#include <config.h>
20
21/* When it is known that the gl_get_mbtowc_lock function is defined
22 by a dependency library, it should not be defined here. */
23#if OMIT_MBTOWC_LOCK
24
25/* This declaration is solely to ensure that after preprocessing
26 this file is never empty. */
27typedef int dummy;
28
29#else
30
31/* This file defines the internal lock used by mbrtowc and mbrtoc32.
32 It is a separate compilation unit, so that only one copy of it is
33 present when linking statically. */
34
35/* Prohibit renaming this symbol. */
36# undef gl_get_mbtowc_lock
37
38/* Macro for exporting a symbol (function, not variable) defined in this file,
39 when compiled into a shared library. */
40# ifndef DLL_EXPORTED
41# if HAVE_VISIBILITY
42 /* Override the effect of the compiler option '-fvisibility=hidden'. */
43# define DLL_EXPORTED __attribute__((__visibility__("default")))
44# elif defined _WIN32 || defined __CYGWIN__
45# define DLL_EXPORTED __declspec(dllexport)
46# else
47# define DLL_EXPORTED
48# endif
49# endif
50
51# if defined _WIN32 && !defined __CYGWIN__
52
53# define WIN32_LEAN_AND_MEAN /* avoid including junk */
54# include <windows.h>
55
56# include "windows-initguard.h"
57
58/* The return type is a 'CRITICAL_SECTION *', not a 'glwthread_mutex_t *',
59 because the latter is not guaranteed to be a stable ABI in the future. */
60
61/* Make sure the function gets exported from DLLs. */
62DLL_EXPORTED CRITICAL_SECTION *gl_get_mbtowc_lock (void);
63
64static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT;
65static CRITICAL_SECTION lock;
66
67/* Returns the internal lock used by mbrtowc and mbrtoc32. */
68CRITICAL_SECTION *
69gl_get_mbtowc_lock (void)
70{
71 if (!guard.done)
72 {
73 if (InterlockedIncrement (&guard.started) == 0)
74 {
75 /* This thread is the first one to need the lock. Initialize it. */
76 InitializeCriticalSection (&lock);
77 guard.done = 1;
78 }
79 else
80 {
81 /* Don't let guard.started grow and wrap around. */
82 InterlockedDecrement (&guard.started);
83 /* Yield the CPU while waiting for another thread to finish
84 initializing this mutex. */
85 while (!guard.done)
86 Sleep (0);
87 }
88 }
89 return &lock;
90}
91
92# elif HAVE_PTHREAD_API
93
94# include <pthread.h>
95
96static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
97
98/* Make sure the function gets exported from shared libraries. */
99DLL_EXPORTED pthread_mutex_t *gl_get_mbtowc_lock (void);
100
101/* Returns the internal lock used by mbrtowc and mbrtoc32. */
102pthread_mutex_t *
103gl_get_mbtowc_lock (void)
104{
105 return &mutex;
106}
107
108# elif HAVE_THREADS_H
109
110# include <threads.h>
111# include <stdlib.h>
112
113static int volatile init_needed = 1;
114static once_flag init_once = ONCE_FLAG_INIT;
115static mtx_t mutex;
116
117static void
118atomic_init (void)
119{
120 if (mtx_init (&mutex, mtx_plain) != thrd_success)
121 abort ();
122 init_needed = 0;
123}
124
125/* Make sure the function gets exported from shared libraries. */
126DLL_EXPORTED mtx_t *gl_get_mbtowc_lock (void);
127
128/* Returns the internal lock used by mbrtowc and mbrtoc32. */
129mtx_t *
130gl_get_mbtowc_lock (void)
131{
132 if (init_needed)
133 call_once (&init_once, atomic_init);
134 return &mutex;
135}
136
137# endif
138
139# if (defined _WIN32 || defined __CYGWIN__) && !defined _MSC_VER
140/* Make sure the '__declspec(dllimport)' in mbrtowc.c and mbrtoc32.c does not
141 cause a link failure when no DLLs are involved. */
142# if defined _WIN64 || defined _LP64
143# define IMP(x) __imp_##x
144# else
145# define IMP(x) _imp__##x
146# endif
147void * IMP(gl_get_mbtowc_lock) = &gl_get_mbtowc_lock;
148# endif
149
150#endif
diff --git a/gl/mbtowc-lock.h b/gl/mbtowc-lock.h
new file mode 100644
index 0000000..2dc22ac
--- /dev/null
+++ b/gl/mbtowc-lock.h
@@ -0,0 +1,125 @@
1/* Use the internal lock used by mbrtowc and mbrtoc32.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019-2020. */
18
19/* Use a lock, so that no two threads can invoke mbtowc at the same time. */
20
21static inline int
22mbtowc_unlocked (wchar_t *pwc, const char *p, size_t m)
23{
24 /* Put the hidden internal state of mbtowc into its initial state.
25 This is needed at least with glibc, uClibc, and MSVC CRT.
26 See <https://sourceware.org/bugzilla/show_bug.cgi?id=9674>. */
27 mbtowc (NULL, NULL, 0);
28
29 return mbtowc (pwc, p, m);
30}
31
32/* Prohibit renaming this symbol. */
33#undef gl_get_mbtowc_lock
34
35#if GNULIB_MBRTOWC_SINGLE_THREAD
36
37/* All uses of this function are in a single thread. No locking needed. */
38
39static int
40mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
41{
42 return mbtowc_unlocked (pwc, p, m);
43}
44
45#elif defined _WIN32 && !defined __CYGWIN__
46
47extern __declspec(dllimport) CRITICAL_SECTION *gl_get_mbtowc_lock (void);
48
49static int
50mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
51{
52 CRITICAL_SECTION *lock = gl_get_mbtowc_lock ();
53 int ret;
54
55 EnterCriticalSection (lock);
56 ret = mbtowc_unlocked (pwc, p, m);
57 LeaveCriticalSection (lock);
58
59 return ret;
60}
61
62#elif HAVE_PTHREAD_API /* AIX, IRIX, Cygwin */
63
64extern
65# if defined _WIN32 || defined __CYGWIN__
66 __declspec(dllimport)
67# endif
68 pthread_mutex_t *gl_get_mbtowc_lock (void);
69
70# if HAVE_WEAK_SYMBOLS /* IRIX */
71
72 /* Avoid the need to link with '-lpthread'. */
73# pragma weak pthread_mutex_lock
74# pragma weak pthread_mutex_unlock
75
76 /* Determine whether libpthread is in use. */
77# pragma weak pthread_mutexattr_gettype
78 /* See the comments in lock.h. */
79# define pthread_in_use() \
80 (pthread_mutexattr_gettype != NULL || c11_threads_in_use ())
81
82# else
83# define pthread_in_use() 1
84# endif
85
86static int
87mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
88{
89 if (pthread_in_use())
90 {
91 pthread_mutex_t *lock = gl_get_mbtowc_lock ();
92 int ret;
93
94 if (pthread_mutex_lock (lock))
95 abort ();
96 ret = mbtowc_unlocked (pwc, p, m);
97 if (pthread_mutex_unlock (lock))
98 abort ();
99
100 return ret;
101 }
102 else
103 return mbtowc_unlocked (pwc, p, m);
104}
105
106#elif HAVE_THREADS_H
107
108extern mtx_t *gl_get_mbtowc_lock (void);
109
110static int
111mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
112{
113 mtx_t *lock = gl_get_mbtowc_lock ();
114 int ret;
115
116 if (mtx_lock (lock) != thrd_success)
117 abort ();
118 ret = mbtowc_unlocked (pwc, p, m);
119 if (mtx_unlock (lock) != thrd_success)
120 abort ();
121
122 return ret;
123}
124
125#endif
diff --git a/gl/mbtowc.c b/gl/mbtowc.c
index 632f2e1..8d9b06d 100644
--- a/gl/mbtowc.c
+++ b/gl/mbtowc.c
@@ -1,19 +1,19 @@
1/* Convert multibyte character to wide character. 1/* Convert multibyte character to wide character.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011. 3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/memchr.c b/gl/memchr.c
index 3db38a9..8e95579 100644
--- a/gl/memchr.c
+++ b/gl/memchr.c
@@ -1,4 +1,4 @@
1/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013 1/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2023
2 Free Software Foundation, Inc. 2 Free Software Foundation, Inc.
3 3
4 Based on strlen implementation by Torbjorn Granlund (tege@sics.se), 4 Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
@@ -7,21 +7,21 @@
7 adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), 7 adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
8 and implemented by Roland McGrath (roland@ai.mit.edu). 8 and implemented by Roland McGrath (roland@ai.mit.edu).
9 9
10NOTE: The canonical source of this file is maintained with the GNU C Library. 10 NOTE: The canonical source of this file is maintained with the GNU C Library.
11Bugs can be reported to bug-glibc@prep.ai.mit.edu. 11 Bugs can be reported to bug-glibc@prep.ai.mit.edu.
12 12
13This program is free software: you can redistribute it and/or modify it 13 This file is free software: you can redistribute it and/or modify
14under the terms of the GNU General Public License as published by the 14 it under the terms of the GNU Lesser General Public License as
15Free Software Foundation; either version 3 of the License, or any 15 published by the Free Software Foundation; either version 2.1 of the
16later version. 16 License, or (at your option) any later version.
17 17
18This program is distributed in the hope that it will be useful, 18 This file is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of 19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details. 21 GNU Lesser General Public License for more details.
22 22
23You should have received a copy of the GNU General Public License 23 You should have received a copy of the GNU Lesser General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>. */ 24 along with this program. If not, see <https://www.gnu.org/licenses/>. */
25 25
26#ifndef _LIBC 26#ifndef _LIBC
27# include <config.h> 27# include <config.h>
diff --git a/gl/memchr.valgrind b/gl/memchr.valgrind
index 60f247e..97690f2 100644
--- a/gl/memchr.valgrind
+++ b/gl/memchr.valgrind
@@ -1,4 +1,20 @@
1# Suppress a valgrind message about use of uninitialized memory in memchr(). 1# Suppress a valgrind message about use of uninitialized memory in memchr().
2
3# Copyright (C) 2009-2023 Free Software Foundation, Inc.
4#
5# This file is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as
7# published by the Free Software Foundation; either version 2.1 of the
8# License, or (at your option) any later version.
9#
10# This file 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 Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
2# POSIX states that when the character is found, memchr must not read extra 18# POSIX states that when the character is found, memchr must not read extra
3# bytes in an overestimated length (for example, where memchr is used to 19# bytes in an overestimated length (for example, where memchr is used to
4# implement strnlen). However, we use a safe word read to provide a speedup. 20# implement strnlen). However, we use a safe word read to provide a speedup.
diff --git a/gl/minmax.h b/gl/minmax.h
new file mode 100644
index 0000000..1fbfc66
--- /dev/null
+++ b/gl/minmax.h
@@ -0,0 +1,60 @@
1/* MIN, MAX macros.
2 Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2023 Free Software
3 Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
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/mktime-internal.h b/gl/mktime-internal.h
index 4287acf..709c36b 100644
--- a/gl/mktime-internal.h
+++ b/gl/mktime-internal.h
@@ -1,4 +1,79 @@
1#include <time.h> 1/* Internals of mktime and related functions
2time_t mktime_internal (struct tm *, 2 Copyright 2016-2023 Free Software Foundation, Inc.
3 struct tm * (*) (time_t const *, struct tm *), 3 This file is part of the GNU C Library.
4 time_t *); 4 Contributed by Paul Eggert <eggert@cs.ucla.edu>.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library 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 GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#ifndef _LIBC
21# include <time.h>
22#endif
23
24/* mktime_offset_t is a signed type wide enough to hold a UTC offset
25 in seconds, and used as part of the type of the offset-guess
26 argument to mktime_internal. In Glibc, it is always long int.
27 When in Gnulib, use time_t on platforms where time_t
28 is signed, to be compatible with platforms like BeOS that export
29 this implementation detail of mktime. On platforms where time_t is
30 unsigned, GNU and POSIX code can assume 'int' is at least 32 bits
31 which is wide enough for a UTC offset. */
32#ifdef _LIBC
33typedef long int mktime_offset_t;
34#elif defined TIME_T_IS_SIGNED
35typedef time_t mktime_offset_t;
36#else
37typedef int mktime_offset_t;
38#endif
39
40/* The source code uses identifiers like __time64_t for glibc
41 timestamps that can contain 64-bit values even when time_t is only
42 32 bits. These are just macros for the ordinary identifiers unless
43 compiling within glibc when time_t is 32 bits. */
44#if ! (defined _LIBC && __TIMESIZE != 64)
45# undef __time64_t
46# define __time64_t time_t
47# define __gmtime64_r __gmtime_r
48# define __localtime64_r __localtime_r
49# define __mktime64 mktime
50# define __timegm64 timegm
51#endif
52
53#ifndef _LIBC
54
55/* Although glibc source code uses leading underscores, Gnulib wants
56 ordinary names.
57
58 Portable standalone applications should supply a <time.h> that
59 declares a POSIX-compliant localtime_r, for the benefit of older
60 implementations that lack localtime_r or have a nonstandard one.
61 Similarly for gmtime_r. See the gnulib time_r module for one way
62 to implement this. */
63
64# undef __gmtime_r
65# undef __localtime_r
66# define __gmtime_r gmtime_r
67# define __localtime_r localtime_r
68
69# define __mktime_internal mktime_internal
70
71#endif
72
73/* Subroutine of mktime. Return the time_t representation of TP and
74 normalize TP, given that a struct tm * maps to a time_t as performed
75 by FUNC. Record next guess for localtime-gmtime offset in *OFFSET. */
76extern __time64_t __mktime_internal (struct tm *tp,
77 struct tm *(*func) (__time64_t const *,
78 struct tm *),
79 mktime_offset_t *offset) attribute_hidden;
diff --git a/gl/mktime.c b/gl/mktime.c
index e660a23..94a4320 100644
--- a/gl/mktime.c
+++ b/gl/mktime.c
@@ -1,28 +1,37 @@
1/* Convert a 'struct tm' to a time_t value. 1/* Convert a 'struct tm' to a time_t value.
2 Copyright (C) 1993-2013 Free Software Foundation, Inc. 2 Copyright (C) 1993-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 Contributed by Paul Eggert <eggert@twinsun.com>. 4 Contributed by Paul Eggert <eggert@twinsun.com>.
5 5
6 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
19 19
20/* Define this to have a standalone program to test this implementation of 20/* The following macros influence what gets defined when this file is compiled:
21 mktime. */ 21
22/* #define DEBUG 1 */ 22 Macro/expression Which gnulib module This compilation unit
23 should define
24
25 _LIBC (glibc proper) mktime
26
27 NEED_MKTIME_WORKING mktime rpl_mktime
28 || NEED_MKTIME_WINDOWS
29
30 NEED_MKTIME_INTERNAL mktime-internal mktime_internal
31 */
23 32
24#ifndef _LIBC 33#ifndef _LIBC
25# include <config.h> 34# include <libc-config.h>
26#endif 35#endif
27 36
28/* Assume that leap seconds are possible, unless told otherwise. 37/* Assume that leap seconds are possible, unless told otherwise.
@@ -34,115 +43,123 @@
34 43
35#include <time.h> 44#include <time.h>
36 45
46#include <errno.h>
37#include <limits.h> 47#include <limits.h>
48#include <stdbool.h>
49#include <stdlib.h>
50#include <string.h>
51
52#include <intprops.h>
53#include <verify.h>
54
55#ifndef NEED_MKTIME_INTERNAL
56# define NEED_MKTIME_INTERNAL 0
57#endif
58#ifndef NEED_MKTIME_WINDOWS
59# define NEED_MKTIME_WINDOWS 0
60#endif
61#ifndef NEED_MKTIME_WORKING
62# define NEED_MKTIME_WORKING 0
63#endif
64
65#include "mktime-internal.h"
38 66
39#include <string.h> /* For the real memcpy prototype. */ 67#if !defined _LIBC && (NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS)
40 68static void
41#if DEBUG 69my_tzset (void)
42# include <stdio.h> 70{
43# include <stdlib.h> 71# if NEED_MKTIME_WINDOWS
44/* Make it work even if the system's libc has its own mktime routine. */ 72 /* Rectify the value of the environment variable TZ.
45# undef mktime 73 There are four possible kinds of such values:
46# define mktime my_mktime 74 - Traditional US time zone names, e.g. "PST8PDT". Syntax: see
47#endif /* DEBUG */ 75 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/tzset>
48 76 - Time zone names based on geography, that contain one or more
49/* Some of the code in this file assumes that signed integer overflow 77 slashes, e.g. "Europe/Moscow".
50 silently wraps around. This assumption can't easily be programmed 78 - Time zone names based on geography, without slashes, e.g.
51 around, nor can it be checked for portably at compile-time or 79 "Singapore".
52 easily eliminated at run-time. 80 - Time zone names that contain explicit DST rules. Syntax: see
53 81 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03>
54 Define WRAPV to 1 if the assumption is valid and if 82 The Microsoft CRT understands only the first kind. It produces incorrect
55 #pragma GCC optimize ("wrapv") 83 results if the value of TZ is of the other kinds.
56 does not trigger GCC bug 51793 84 But in a Cygwin environment, /etc/profile.d/tzset.sh sets TZ to a value
57 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51793>. 85 of the second kind for most geographies, or of the first kind in a few
58 Otherwise, define it to 0; this forces the use of slower code that, 86 other geographies. If it is of the second kind, neutralize it. For the
59 while not guaranteed by the C Standard, works on all production 87 Microsoft CRT, an absent or empty TZ means the time zone that the user
60 platforms that we know about. */ 88 has set in the Windows Control Panel.
61#ifndef WRAPV 89 If the value of TZ is of the third or fourth kind -- Cygwin programs
62# if (((__GNUC__ == 4 && 4 <= __GNUC_MINOR__) || 4 < __GNUC__) \ 90 understand these syntaxes as well --, it does not matter whether we
63 && defined __GLIBC__) 91 neutralize it or not, since these values occur only when a Cygwin user
64# pragma GCC optimize ("wrapv") 92 has set TZ explicitly; this case is 1. rare and 2. under the user's
65# define WRAPV 1 93 responsibility. */
94 const char *tz = getenv ("TZ");
95 if (tz != NULL && strchr (tz, '/') != NULL)
96 _putenv ("TZ=");
66# else 97# else
67# define WRAPV 0 98 tzset ();
68# endif 99# endif
100}
101# undef __tzset
102# define __tzset() my_tzset ()
69#endif 103#endif
70 104
71/* Verify a requirement at compile-time (unlike assert, which is runtime). */ 105#if defined _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL
72#define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; } 106
107/* A signed type that can represent an integer number of years
108 multiplied by four times the number of seconds in a year. It is
109 needed when converting a tm_year value times the number of seconds
110 in a year. The factor of four comes because these products need
111 to be subtracted from each other, and sometimes with an offset
112 added to them, and then with another timestamp added, without
113 worrying about overflow.
73 114
74/* A signed type that is at least one bit wider than int. */ 115 Much of the code uses long_int to represent __time64_t values, to
75#if INT_MAX <= LONG_MAX / 2 116 lessen the hassle of dealing with platforms where __time64_t is
117 unsigned, and because long_int should suffice to represent all
118 __time64_t values that mktime can generate even on platforms where
119 __time64_t is wider than the int components of struct tm. */
120
121#if INT_MAX <= LONG_MAX / 4 / 366 / 24 / 60 / 60
76typedef long int long_int; 122typedef long int long_int;
77#else 123#else
78typedef long long int long_int; 124typedef long long int long_int;
79#endif 125#endif
80verify (long_int_is_wide_enough, INT_MAX == INT_MAX * (long_int) 2 / 2); 126verify (INT_MAX <= TYPE_MAXIMUM (long_int) / 4 / 366 / 24 / 60 / 60);
81 127
82/* Shift A right by B bits portably, by dividing A by 2**B and 128/* Shift A right by B bits portably, by dividing A by 2**B and
83 truncating towards minus infinity. A and B should be free of side 129 truncating towards minus infinity. B should be in the range 0 <= B
84 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where 130 <= LONG_INT_BITS - 2, where LONG_INT_BITS is the number of useful
85 INT_BITS is the number of useful bits in an int. GNU code can 131 bits in a long_int. LONG_INT_BITS is at least 32.
86 assume that INT_BITS is at least 32.
87 132
88 ISO C99 says that A >> B is implementation-defined if A < 0. Some 133 ISO C99 says that A >> B is implementation-defined if A < 0. Some
89 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift 134 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
90 right in the usual way when A < 0, so SHR falls back on division if 135 right in the usual way when A < 0, so SHR falls back on division if
91 ordinary A >> B doesn't seem to be the usual signed shift. */ 136 ordinary A >> B doesn't seem to be the usual signed shift. */
92#define SHR(a, b) \
93 ((-1 >> 1 == -1 \
94 && (long_int) -1 >> 1 == -1 \
95 && ((time_t) -1 >> 1 == -1 || ! TYPE_SIGNED (time_t))) \
96 ? (a) >> (b) \
97 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
98
99/* The extra casts in the following macros work around compiler bugs,
100 e.g., in Cray C 5.0.3.0. */
101
102/* True if the arithmetic type T is an integer type. bool counts as
103 an integer. */
104#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
105
106/* True if negative values of the signed integer type T use two's
107 complement, or if T is an unsigned integer type. */
108#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
109
110/* True if the arithmetic type T is signed. */
111#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
112
113/* The maximum and minimum values for the integer type T. These
114 macros have undefined behavior if T is signed and has padding bits.
115 If this is a problem for you, please let us know how to fix it for
116 your host. */
117#define TYPE_MINIMUM(t) \
118 ((t) (! TYPE_SIGNED (t) \
119 ? (t) 0 \
120 : ~ TYPE_MAXIMUM (t)))
121#define TYPE_MAXIMUM(t) \
122 ((t) (! TYPE_SIGNED (t) \
123 ? (t) -1 \
124 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
125
126#ifndef TIME_T_MIN
127# define TIME_T_MIN TYPE_MINIMUM (time_t)
128#endif
129#ifndef TIME_T_MAX
130# define TIME_T_MAX TYPE_MAXIMUM (time_t)
131#endif
132#define TIME_T_MIDPOINT (SHR (TIME_T_MIN + TIME_T_MAX, 1) + 1)
133 137
134verify (time_t_is_integer, TYPE_IS_INTEGER (time_t)); 138static long_int
135verify (twos_complement_arithmetic, 139shr (long_int a, int b)
136 (TYPE_TWOS_COMPLEMENT (int) 140{
137 && TYPE_TWOS_COMPLEMENT (long_int) 141 long_int one = 1;
138 && TYPE_TWOS_COMPLEMENT (time_t))); 142 return (-one >> 1 == -1
143 ? a >> b
144 : (a + (a < 0)) / (one << b) - (a < 0));
145}
146
147/* Bounds for the intersection of __time64_t and long_int. */
148
149static long_int const mktime_min
150 = ((TYPE_SIGNED (__time64_t)
151 && TYPE_MINIMUM (__time64_t) < TYPE_MINIMUM (long_int))
152 ? TYPE_MINIMUM (long_int) : TYPE_MINIMUM (__time64_t));
153static long_int const mktime_max
154 = (TYPE_MAXIMUM (long_int) < TYPE_MAXIMUM (__time64_t)
155 ? TYPE_MAXIMUM (long_int) : TYPE_MAXIMUM (__time64_t));
139 156
140#define EPOCH_YEAR 1970 157#define EPOCH_YEAR 1970
141#define TM_YEAR_BASE 1900 158#define TM_YEAR_BASE 1900
142verify (base_year_is_a_multiple_of_100, TM_YEAR_BASE % 100 == 0); 159verify (TM_YEAR_BASE % 100 == 0);
143 160
144/* Return 1 if YEAR + TM_YEAR_BASE is a leap year. */ 161/* Is YEAR + TM_YEAR_BASE a leap year? */
145static int 162static bool
146leapyear (long_int year) 163leapyear (long_int year)
147{ 164{
148 /* Don't add YEAR to TM_YEAR_BASE, as that might overflow. 165 /* Don't add YEAR to TM_YEAR_BASE, as that might overflow.
@@ -166,20 +183,9 @@ const unsigned short int __mon_yday[2][13] =
166 }; 183 };
167 184
168 185
169#ifndef _LIBC 186/* Do the values A and B differ according to the rules for tm_isdst?
170/* Portable standalone applications should supply a <time.h> that 187 A and B differ if one is zero and the other positive. */
171 declares a POSIX-compliant localtime_r, for the benefit of older 188static bool
172 implementations that lack localtime_r or have a nonstandard one.
173 See the gnulib time_r module for one way to implement this. */
174# undef __localtime_r
175# define __localtime_r localtime_r
176# define __mktime_internal mktime_internal
177# include "mktime-internal.h"
178#endif
179
180/* Return 1 if the values A and B differ according to the rules for
181 tm_isdst: A and B differ if one is zero and the other positive. */
182static int
183isdst_differ (int a, int b) 189isdst_differ (int a, int b)
184{ 190{
185 return (!a != !b) && (0 <= a) && (0 <= b); 191 return (!a != !b) && (0 <= a) && (0 <= b);
@@ -187,171 +193,135 @@ isdst_differ (int a, int b)
187 193
188/* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) - 194/* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) -
189 (YEAR0-YDAY0 HOUR0:MIN0:SEC0) in seconds, assuming that the clocks 195 (YEAR0-YDAY0 HOUR0:MIN0:SEC0) in seconds, assuming that the clocks
190 were not adjusted between the time stamps. 196 were not adjusted between the timestamps.
191 197
192 The YEAR values uses the same numbering as TP->tm_year. Values 198 The YEAR values uses the same numbering as TP->tm_year. Values
193 need not be in the usual range. However, YEAR1 must not be less 199 need not be in the usual range. However, YEAR1 - YEAR0 must not
194 than 2 * INT_MIN or greater than 2 * INT_MAX. 200 overflow even when multiplied by three times the number of seconds
201 in a year, and likewise for YDAY1 - YDAY0 and three times the
202 number of seconds in a day. */
195 203
196 The result may overflow. It is the caller's responsibility to 204static long_int
197 detect overflow. */
198
199static time_t
200ydhms_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1, 205ydhms_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1,
201 int year0, int yday0, int hour0, int min0, int sec0) 206 int year0, int yday0, int hour0, int min0, int sec0)
202{ 207{
203 verify (C99_integer_division, -1 / 2 == 0); 208 verify (-1 / 2 == 0);
204 209
205 /* Compute intervening leap days correctly even if year is negative. 210 /* Compute intervening leap days correctly even if year is negative.
206 Take care to avoid integer overflow here. */ 211 Take care to avoid integer overflow here. */
207 int a4 = SHR (year1, 2) + SHR (TM_YEAR_BASE, 2) - ! (year1 & 3); 212 int a4 = shr (year1, 2) + shr (TM_YEAR_BASE, 2) - ! (year1 & 3);
208 int b4 = SHR (year0, 2) + SHR (TM_YEAR_BASE, 2) - ! (year0 & 3); 213 int b4 = shr (year0, 2) + shr (TM_YEAR_BASE, 2) - ! (year0 & 3);
209 int a100 = a4 / 25 - (a4 % 25 < 0); 214 int a100 = (a4 + (a4 < 0)) / 25 - (a4 < 0);
210 int b100 = b4 / 25 - (b4 % 25 < 0); 215 int b100 = (b4 + (b4 < 0)) / 25 - (b4 < 0);
211 int a400 = SHR (a100, 2); 216 int a400 = shr (a100, 2);
212 int b400 = SHR (b100, 2); 217 int b400 = shr (b100, 2);
213 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); 218 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
214 219
215 /* Compute the desired time in time_t precision. Overflow might 220 /* Compute the desired time without overflowing. */
216 occur here. */ 221 long_int years = year1 - year0;
217 time_t tyear1 = year1; 222 long_int days = 365 * years + yday1 - yday0 + intervening_leap_days;
218 time_t years = tyear1 - year0; 223 long_int hours = 24 * days + hour1 - hour0;
219 time_t days = 365 * years + yday1 - yday0 + intervening_leap_days; 224 long_int minutes = 60 * hours + min1 - min0;
220 time_t hours = 24 * days + hour1 - hour0; 225 long_int seconds = 60 * minutes + sec1 - sec0;
221 time_t minutes = 60 * hours + min1 - min0;
222 time_t seconds = 60 * minutes + sec1 - sec0;
223 return seconds; 226 return seconds;
224} 227}
225 228
226/* Return the average of A and B, even if A + B would overflow. */ 229/* Return the average of A and B, even if A + B would overflow.
227static time_t 230 Round toward positive infinity. */
228time_t_avg (time_t a, time_t b) 231static long_int
232long_int_avg (long_int a, long_int b)
229{ 233{
230 return SHR (a, 1) + SHR (b, 1) + (a & b & 1); 234 return shr (a, 1) + shr (b, 1) + ((a | b) & 1);
231} 235}
232 236
233/* Return 1 if A + B does not overflow. If time_t is unsigned and if 237/* Return a long_int value corresponding to (YEAR-YDAY HOUR:MIN:SEC)
234 B's top bit is set, assume that the sum represents A - -B, and 238 minus *TP seconds, assuming no clock adjustments occurred between
235 return 1 if the subtraction does not wrap around. */ 239 the two timestamps.
236static int
237time_t_add_ok (time_t a, time_t b)
238{
239 if (! TYPE_SIGNED (time_t))
240 {
241 time_t sum = a + b;
242 return (sum < a) == (TIME_T_MIDPOINT <= b);
243 }
244 else if (WRAPV)
245 {
246 time_t sum = a + b;
247 return (sum < a) == (b < 0);
248 }
249 else
250 {
251 time_t avg = time_t_avg (a, b);
252 return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
253 }
254}
255 240
256/* Return 1 if A + B does not overflow. */ 241 YEAR and YDAY must not be so large that multiplying them by three times the
257static int 242 number of seconds in a year (or day, respectively) would overflow long_int.
258time_t_int_add_ok (time_t a, int b) 243 *TP should be in the usual range. */
244static long_int
245tm_diff (long_int year, long_int yday, int hour, int min, int sec,
246 struct tm const *tp)
259{ 247{
260 verify (int_no_wider_than_time_t, INT_MAX <= TIME_T_MAX); 248 return ydhms_diff (year, yday, hour, min, sec,
261 if (WRAPV) 249 tp->tm_year, tp->tm_yday,
262 { 250 tp->tm_hour, tp->tm_min, tp->tm_sec);
263 time_t sum = a + b;
264 return (sum < a) == (b < 0);
265 }
266 else
267 {
268 int a_odd = a & 1;
269 time_t avg = SHR (a, 1) + (SHR (b, 1) + (a_odd & b));
270 return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
271 }
272} 251}
273 252
274/* Return a time_t value corresponding to (YEAR-YDAY HOUR:MIN:SEC), 253/* Use CONVERT to convert T to a struct tm value in *TM. T must be in
275 assuming that *T corresponds to *TP and that no clock adjustments 254 range for __time64_t. Return TM if successful, NULL (setting errno) on
276 occurred between *TP and the desired time. 255 failure. */
277 If TP is null, return a value not equal to *T; this avoids false matches. 256static struct tm *
278 If overflow occurs, yield the minimal or maximal value, except do not 257convert_time (struct tm *(*convert) (const __time64_t *, struct tm *),
279 yield a value equal to *T. */ 258 long_int t, struct tm *tm)
280static time_t
281guess_time_tm (long_int year, long_int yday, int hour, int min, int sec,
282 const time_t *t, const struct tm *tp)
283{ 259{
284 if (tp) 260 __time64_t x = t;
285 { 261 return convert (&x, tm);
286 time_t d = ydhms_diff (year, yday, hour, min, sec,
287 tp->tm_year, tp->tm_yday,
288 tp->tm_hour, tp->tm_min, tp->tm_sec);
289 if (time_t_add_ok (*t, d))
290 return *t + d;
291 }
292
293 /* Overflow occurred one way or another. Return the nearest result
294 that is actually in range, except don't report a zero difference
295 if the actual difference is nonzero, as that would cause a false
296 match; and don't oscillate between two values, as that would
297 confuse the spring-forward gap detector. */
298 return (*t < TIME_T_MIDPOINT
299 ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN)
300 : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX));
301} 262}
302 263
303/* Use CONVERT to convert *T to a broken down time in *TP. 264/* Use CONVERT to convert *T to a broken down time in *TP.
304 If *T is out of range for conversion, adjust it so that 265 If *T is out of range for conversion, adjust it so that
305 it is the nearest in-range value and then convert that. */ 266 it is the nearest in-range value and then convert that.
267 A value is in range if it fits in both __time64_t and long_int.
268 Return TP on success, NULL (setting errno) on failure. */
306static struct tm * 269static struct tm *
307ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), 270ranged_convert (struct tm *(*convert) (const __time64_t *, struct tm *),
308 time_t *t, struct tm *tp) 271 long_int *t, struct tm *tp)
309{ 272{
310 struct tm *r = convert (t, tp); 273 long_int t1 = (*t < mktime_min ? mktime_min
311 274 : *t <= mktime_max ? *t : mktime_max);
312 if (!r && *t) 275 struct tm *r = convert_time (convert, t1, tp);
276 if (r)
313 { 277 {
314 time_t bad = *t; 278 *t = t1;
315 time_t ok = 0; 279 return r;
280 }
281 if (errno != EOVERFLOW)
282 return NULL;
316 283
317 /* BAD is a known unconvertible time_t, and OK is a known good one. 284 long_int bad = t1;
318 Use binary search to narrow the range between BAD and OK until 285 long_int ok = 0;
319 they differ by 1. */ 286 struct tm oktm; oktm.tm_sec = -1;
320 while (bad != ok + (bad < 0 ? -1 : 1))
321 {
322 time_t mid = *t = time_t_avg (ok, bad);
323 r = convert (t, tp);
324 if (r)
325 ok = mid;
326 else
327 bad = mid;
328 }
329 287
330 if (!r && ok) 288 /* BAD is a known out-of-range value, and OK is a known in-range one.
331 { 289 Use binary search to narrow the range between BAD and OK until
332 /* The last conversion attempt failed; 290 they differ by 1. */
333 revert to the most recent successful attempt. */ 291 while (true)
334 *t = ok; 292 {
335 r = convert (t, tp); 293 long_int mid = long_int_avg (ok, bad);
336 } 294 if (mid == ok || mid == bad)
295 break;
296 if (convert_time (convert, mid, tp))
297 ok = mid, oktm = *tp;
298 else if (errno != EOVERFLOW)
299 return NULL;
300 else
301 bad = mid;
337 } 302 }
338 303
339 return r; 304 if (oktm.tm_sec < 0)
305 return NULL;
306 *t = ok;
307 *tp = oktm;
308 return tp;
340} 309}
341 310
342 311
343/* Convert *TP to a time_t value, inverting 312/* Convert *TP to a __time64_t value, inverting
344 the monotonic and mostly-unit-linear conversion function CONVERT. 313 the monotonic and mostly-unit-linear conversion function CONVERT.
345 Use *OFFSET to keep track of a guess at the offset of the result, 314 Use *OFFSET to keep track of a guess at the offset of the result,
346 compared to what the result would be for UTC without leap seconds. 315 compared to what the result would be for UTC without leap seconds.
347 If *OFFSET's guess is correct, only one CONVERT call is needed. 316 If *OFFSET's guess is correct, only one CONVERT call is needed.
317 If successful, set *TP to the canonicalized struct tm;
318 otherwise leave *TP alone, return ((time_t) -1) and set errno.
348 This function is external because it is used also by timegm.c. */ 319 This function is external because it is used also by timegm.c. */
349time_t 320__time64_t
350__mktime_internal (struct tm *tp, 321__mktime_internal (struct tm *tp,
351 struct tm *(*convert) (const time_t *, struct tm *), 322 struct tm *(*convert) (const __time64_t *, struct tm *),
352 time_t *offset) 323 mktime_offset_t *offset)
353{ 324{
354 time_t t, gt, t0, t1, t2;
355 struct tm tm; 325 struct tm tm;
356 326
357 /* The maximum number of probes (calls to CONVERT) should be enough 327 /* The maximum number of probes (calls to CONVERT) should be enough
@@ -371,7 +341,7 @@ __mktime_internal (struct tm *tp,
371 int isdst = tp->tm_isdst; 341 int isdst = tp->tm_isdst;
372 342
373 /* 1 if the previous probe was DST. */ 343 /* 1 if the previous probe was DST. */
374 int dst2; 344 int dst2 = 0;
375 345
376 /* Ensure that mon is in range, and set year accordingly. */ 346 /* Ensure that mon is in range, and set year accordingly. */
377 int mon_remainder = mon % 12; 347 int mon_remainder = mon % 12;
@@ -381,9 +351,7 @@ __mktime_internal (struct tm *tp,
381 long_int year = lyear_requested + mon_years; 351 long_int year = lyear_requested + mon_years;
382 352
383 /* The other values need not be in range: 353 /* The other values need not be in range:
384 the remaining code handles minor overflows correctly, 354 the remaining code handles overflows correctly. */
385 assuming int and time_t arithmetic wraps around.
386 Major overflows are caught at the end. */
387 355
388 /* Calculate day of year from year, month, and day of month. 356 /* Calculate day of year from year, month, and day of month.
389 The result need not be in range. */ 357 The result need not be in range. */
@@ -393,14 +361,15 @@ __mktime_internal (struct tm *tp,
393 long_int lmday = mday; 361 long_int lmday = mday;
394 long_int yday = mon_yday + lmday; 362 long_int yday = mon_yday + lmday;
395 363
396 time_t guessed_offset = *offset; 364 mktime_offset_t off = *offset;
365 int negative_offset_guess;
397 366
398 int sec_requested = sec; 367 int sec_requested = sec;
399 368
400 if (LEAP_SECONDS_POSSIBLE) 369 if (LEAP_SECONDS_POSSIBLE)
401 { 370 {
402 /* Handle out-of-range seconds specially, 371 /* Handle out-of-range seconds specially,
403 since ydhms_tm_diff assumes every minute has 60 seconds. */ 372 since ydhms_diff assumes every minute has 60 seconds. */
404 if (sec < 0) 373 if (sec < 0)
405 sec = 0; 374 sec = 0;
406 if (59 < sec) 375 if (59 < sec)
@@ -410,91 +379,47 @@ __mktime_internal (struct tm *tp,
410 /* Invert CONVERT by probing. First assume the same offset as last 379 /* Invert CONVERT by probing. First assume the same offset as last
411 time. */ 380 time. */
412 381
413 t0 = ydhms_diff (year, yday, hour, min, sec, 382 INT_SUBTRACT_WRAPV (0, off, &negative_offset_guess);
414 EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset); 383 long_int t0 = ydhms_diff (year, yday, hour, min, sec,
384 EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0,
385 negative_offset_guess);
386 long_int t = t0, t1 = t0, t2 = t0;
387
388 /* Repeatedly use the error to improve the guess. */
415 389
416 if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3) 390 while (true)
417 { 391 {
418 /* time_t isn't large enough to rule out overflows, so check 392 if (! ranged_convert (convert, &t, &tm))
419 for major overflows. A gross check suffices, since if t0 393 return -1;
420 has overflowed, it is off by a multiple of TIME_T_MAX - 394 long_int dt = tm_diff (year, yday, hour, min, sec, &tm);
421 TIME_T_MIN + 1. So ignore any component of the difference 395 if (dt == 0)
422 that is bounded by a small value. */ 396 break;
423 397
424 /* Approximate log base 2 of the number of time units per 398 if (t == t1 && t != t2
425 biennium. A biennium is 2 years; use this unit instead of 399 && (tm.tm_isdst < 0
426 years to avoid integer overflow. For example, 2 average 400 || (isdst < 0
427 Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds, 401 ? dst2 <= (tm.tm_isdst != 0)
428 which is 63113904 seconds, and rint (log2 (63113904)) is 402 : (isdst != 0) != (tm.tm_isdst != 0))))
429 26. */ 403 /* We can't possibly find a match, as we are oscillating
430 int ALOG2_SECONDS_PER_BIENNIUM = 26; 404 between two values. The requested time probably falls
431 int ALOG2_MINUTES_PER_BIENNIUM = 20; 405 within a spring-forward gap of size DT. Follow the common
432 int ALOG2_HOURS_PER_BIENNIUM = 14; 406 practice in this case, which is to return a time that is DT
433 int ALOG2_DAYS_PER_BIENNIUM = 10; 407 away from the requested time, preferring a time whose
434 int LOG2_YEARS_PER_BIENNIUM = 1; 408 tm_isdst differs from the requested value. (If no tm_isdst
435 409 was requested and only one of the two values has a nonzero
436 int approx_requested_biennia = 410 tm_isdst, prefer that value.) In practice, this is more
437 (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM) 411 useful than returning -1. */
438 - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM) 412 goto offset_found;
439 + SHR (mday, ALOG2_DAYS_PER_BIENNIUM) 413
440 + SHR (hour, ALOG2_HOURS_PER_BIENNIUM) 414 remaining_probes--;
441 + SHR (min, ALOG2_MINUTES_PER_BIENNIUM) 415 if (remaining_probes == 0)
442 + (LEAP_SECONDS_POSSIBLE
443 ? 0
444 : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM)));
445
446 int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM);
447 int diff = approx_biennia - approx_requested_biennia;
448 int approx_abs_diff = diff < 0 ? -1 - diff : diff;
449
450 /* IRIX 4.0.5 cc miscalculates TIME_T_MIN / 3: it erroneously
451 gives a positive value of 715827882. Setting a variable
452 first then doing math on it seems to work.
453 (ghazi@caip.rutgers.edu) */
454 time_t time_t_max = TIME_T_MAX;
455 time_t time_t_min = TIME_T_MIN;
456 time_t overflow_threshold =
457 (time_t_max / 3 - time_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM;
458
459 if (overflow_threshold < approx_abs_diff)
460 { 416 {
461 /* Overflow occurred. Try repairing it; this might work if 417 __set_errno (EOVERFLOW);
462 the time zone offset is enough to undo the overflow. */ 418 return -1;
463 time_t repaired_t0 = -1 - t0;
464 approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM);
465 diff = approx_biennia - approx_requested_biennia;
466 approx_abs_diff = diff < 0 ? -1 - diff : diff;
467 if (overflow_threshold < approx_abs_diff)
468 return -1;
469 guessed_offset += repaired_t0 - t0;
470 t0 = repaired_t0;
471 } 419 }
472 }
473
474 /* Repeatedly use the error to improve the guess. */
475 420
476 for (t = t1 = t2 = t0, dst2 = 0; 421 t1 = t2, t2 = t, t += dt, dst2 = tm.tm_isdst != 0;
477 (gt = guess_time_tm (year, yday, hour, min, sec, &t, 422 }
478 ranged_convert (convert, &t, &tm)),
479 t != gt);
480 t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0)
481 if (t == t1 && t != t2
482 && (tm.tm_isdst < 0
483 || (isdst < 0
484 ? dst2 <= (tm.tm_isdst != 0)
485 : (isdst != 0) != (tm.tm_isdst != 0))))
486 /* We can't possibly find a match, as we are oscillating
487 between two values. The requested time probably falls
488 within a spring-forward gap of size GT - T. Follow the common
489 practice in this case, which is to return a time that is GT - T
490 away from the requested time, preferring a time whose
491 tm_isdst differs from the requested value. (If no tm_isdst
492 was requested and only one of the two values has a nonzero
493 tm_isdst, prefer that value.) In practice, this is more
494 useful than returning -1. */
495 goto offset_found;
496 else if (--remaining_probes == 0)
497 return -1;
498 423
499 /* We have a match. Check whether tm.tm_isdst has the requested 424 /* We have a match. Check whether tm.tm_isdst has the requested
500 value, if any. */ 425 value, if any. */
@@ -504,8 +429,13 @@ __mktime_internal (struct tm *tp,
504 time with the right value, and use its UTC offset. 429 time with the right value, and use its UTC offset.
505 430
506 Heuristic: probe the adjacent timestamps in both directions, 431 Heuristic: probe the adjacent timestamps in both directions,
507 looking for the desired isdst. This should work for all real 432 looking for the desired isdst. If none is found within a
508 time zone histories in the tz database. */ 433 reasonable duration bound, assume a one-hour DST difference.
434 This should work for all real time zone histories in the tz
435 database. */
436
437 /* +1 if we wanted standard time but got DST, -1 if the reverse. */
438 int dst_difference = (isdst == 0) - (tm.tm_isdst == 0);
509 439
510 /* Distance between probes when looking for a DST boundary. In 440 /* Distance between probes when looking for a DST boundary. In
511 tzdata2003a, the shortest period of DST is 601200 seconds 441 tzdata2003a, the shortest period of DST is 601200 seconds
@@ -516,12 +446,14 @@ __mktime_internal (struct tm *tp,
516 periods when probing. */ 446 periods when probing. */
517 int stride = 601200; 447 int stride = 601200;
518 448
519 /* The longest period of DST in tzdata2003a is 536454000 seconds 449 /* In TZDB 2021e, the longest period of DST (or of non-DST), in
520 (e.g., America/Jujuy starting 1946-10-01 01:00). The longest 450 which the DST (or adjacent DST) difference is not one hour,
521 period of non-DST is much longer, but it makes no real sense 451 is 457243209 seconds: e.g., America/Cambridge_Bay with leap
522 to search for more than a year of non-DST, so use the DST 452 seconds, starting 1965-10-31 00:00 in a switch from
523 max. */ 453 double-daylight time (-05) to standard time (-07), and
524 int duration_max = 536454000; 454 continuing to 1980-04-27 02:00 in a switch from standard time
455 (-07) to daylight time (-06). */
456 int duration_max = 457243209;
525 457
526 /* Search in both directions, so the maximum distance is half 458 /* Search in both directions, so the maximum distance is half
527 the duration; add the stride to avoid off-by-1 problems. */ 459 the duration; add the stride to avoid off-by-1 problems. */
@@ -531,211 +463,116 @@ __mktime_internal (struct tm *tp,
531 463
532 for (delta = stride; delta < delta_bound; delta += stride) 464 for (delta = stride; delta < delta_bound; delta += stride)
533 for (direction = -1; direction <= 1; direction += 2) 465 for (direction = -1; direction <= 1; direction += 2)
534 if (time_t_int_add_ok (t, delta * direction)) 466 {
535 { 467 long_int ot;
536 time_t ot = t + delta * direction; 468 if (! INT_ADD_WRAPV (t, delta * direction, &ot))
537 struct tm otm; 469 {
538 ranged_convert (convert, &ot, &otm); 470 struct tm otm;
539 if (! isdst_differ (isdst, otm.tm_isdst)) 471 if (! ranged_convert (convert, &ot, &otm))
540 { 472 return -1;
541 /* We found the desired tm_isdst. 473 if (! isdst_differ (isdst, otm.tm_isdst))
542 Extrapolate back to the desired time. */ 474 {
543 t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm); 475 /* We found the desired tm_isdst.
544 ranged_convert (convert, &t, &tm); 476 Extrapolate back to the desired time. */
545 goto offset_found; 477 long_int gt = ot + tm_diff (year, yday, hour, min, sec,
546 } 478 &otm);
547 } 479 if (mktime_min <= gt && gt <= mktime_max)
480 {
481 if (convert_time (convert, gt, &tm))
482 {
483 t = gt;
484 goto offset_found;
485 }
486 if (errno != EOVERFLOW)
487 return -1;
488 }
489 }
490 }
491 }
492
493 /* No unusual DST offset was found nearby. Assume one-hour DST. */
494 t += 60 * 60 * dst_difference;
495 if (mktime_min <= t && t <= mktime_max && convert_time (convert, t, &tm))
496 goto offset_found;
497
498 __set_errno (EOVERFLOW);
499 return -1;
548 } 500 }
549 501
550 offset_found: 502 offset_found:
551 *offset = guessed_offset + t - t0; 503 /* Set *OFFSET to the low-order bits of T - T0 - NEGATIVE_OFFSET_GUESS.
504 This is just a heuristic to speed up the next mktime call, and
505 correctness is unaffected if integer overflow occurs here. */
506 INT_SUBTRACT_WRAPV (t, t0, offset);
507 INT_SUBTRACT_WRAPV (*offset, negative_offset_guess, offset);
552 508
553 if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) 509 if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec)
554 { 510 {
555 /* Adjust time to reflect the tm_sec requested, not the normalized value. 511 /* Adjust time to reflect the tm_sec requested, not the normalized value.
556 Also, repair any damage from a false match due to a leap second. */ 512 Also, repair any damage from a false match due to a leap second. */
557 int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec; 513 long_int sec_adjustment = sec == 0 && tm.tm_sec == 60;
558 if (! time_t_int_add_ok (t, sec_requested)) 514 sec_adjustment -= sec;
559 return -1; 515 sec_adjustment += sec_requested;
560 t1 = t + sec_requested; 516 if (INT_ADD_WRAPV (t, sec_adjustment, &t)
561 if (! time_t_int_add_ok (t1, sec_adjustment)) 517 || ! (mktime_min <= t && t <= mktime_max))
562 return -1; 518 {
563 t2 = t1 + sec_adjustment; 519 __set_errno (EOVERFLOW);
564 if (! convert (&t2, &tm)) 520 return -1;
521 }
522 if (! convert_time (convert, t, &tm))
565 return -1; 523 return -1;
566 t = t2;
567 } 524 }
568 525
569 *tp = tm; 526 *tp = tm;
570 return t; 527 return t;
571} 528}
572 529
530#endif /* _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL */
573 531
574/* FIXME: This should use a signed type wide enough to hold any UTC 532#if defined _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS
575 offset in seconds. 'int' should be good enough for GNU code. We
576 can't fix this unilaterally though, as other modules invoke
577 __mktime_internal. */
578static time_t localtime_offset;
579 533
580/* Convert *TP to a time_t value. */ 534/* Convert *TP to a __time64_t value. */
581time_t 535__time64_t
582mktime (struct tm *tp) 536__mktime64 (struct tm *tp)
583{ 537{
584#ifdef _LIBC
585 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the 538 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
586 time zone names contained in the external variable 'tzname' shall 539 time zone names contained in the external variable 'tzname' shall
587 be set as if the tzset() function had been called. */ 540 be set as if the tzset() function had been called. */
588 __tzset (); 541 __tzset ();
589#endif
590 542
591 return __mktime_internal (tp, __localtime_r, &localtime_offset); 543# if defined _LIBC || NEED_MKTIME_WORKING
544 static mktime_offset_t localtime_offset;
545 return __mktime_internal (tp, __localtime64_r, &localtime_offset);
546# else
547# undef mktime
548 return mktime (tp);
549# endif
592} 550}
551#endif /* _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS */
593 552
594#ifdef weak_alias 553#if defined _LIBC && __TIMESIZE != 64
595weak_alias (mktime, timelocal)
596#endif
597
598#ifdef _LIBC
599libc_hidden_def (mktime)
600libc_hidden_weak (timelocal)
601#endif
602
603#if DEBUG
604 554
605static int 555libc_hidden_def (__mktime64)
606not_equal_tm (const struct tm *a, const struct tm *b)
607{
608 return ((a->tm_sec ^ b->tm_sec)
609 | (a->tm_min ^ b->tm_min)
610 | (a->tm_hour ^ b->tm_hour)
611 | (a->tm_mday ^ b->tm_mday)
612 | (a->tm_mon ^ b->tm_mon)
613 | (a->tm_year ^ b->tm_year)
614 | (a->tm_yday ^ b->tm_yday)
615 | isdst_differ (a->tm_isdst, b->tm_isdst));
616}
617 556
618static void 557time_t
619print_tm (const struct tm *tp) 558mktime (struct tm *tp)
620{
621 if (tp)
622 printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d",
623 tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday,
624 tp->tm_hour, tp->tm_min, tp->tm_sec,
625 tp->tm_yday, tp->tm_wday, tp->tm_isdst);
626 else
627 printf ("0");
628}
629
630static int
631check_result (time_t tk, struct tm tmk, time_t tl, const struct tm *lt)
632{
633 if (tk != tl || !lt || not_equal_tm (&tmk, lt))
634 {
635 printf ("mktime (");
636 print_tm (lt);
637 printf (")\nyields (");
638 print_tm (&tmk);
639 printf (") == %ld, should be %ld\n", (long int) tk, (long int) tl);
640 return 1;
641 }
642
643 return 0;
644}
645
646int
647main (int argc, char **argv)
648{ 559{
649 int status = 0; 560 struct tm tm = *tp;
650 struct tm tm, tmk, tml; 561 __time64_t t = __mktime64 (&tm);
651 struct tm *lt; 562 if (in_time_t_range (t))
652 time_t tk, tl, tl1;
653 char trailer;
654
655 if ((argc == 3 || argc == 4)
656 && (sscanf (argv[1], "%d-%d-%d%c",
657 &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer)
658 == 3)
659 && (sscanf (argv[2], "%d:%d:%d%c",
660 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer)
661 == 3))
662 { 563 {
663 tm.tm_year -= TM_YEAR_BASE; 564 *tp = tm;
664 tm.tm_mon--; 565 return t;
665 tm.tm_isdst = argc == 3 ? -1 : atoi (argv[3]);
666 tmk = tm;
667 tl = mktime (&tmk);
668 lt = localtime (&tl);
669 if (lt)
670 {
671 tml = *lt;
672 lt = &tml;
673 }
674 printf ("mktime returns %ld == ", (long int) tl);
675 print_tm (&tmk);
676 printf ("\n");
677 status = check_result (tl, tmk, tl, lt);
678 } 566 }
679 else if (argc == 4 || (argc == 5 && strcmp (argv[4], "-") == 0)) 567 else
680 { 568 {
681 time_t from = atol (argv[1]); 569 __set_errno (EOVERFLOW);
682 time_t by = atol (argv[2]); 570 return -1;
683 time_t to = atol (argv[3]);
684
685 if (argc == 4)
686 for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
687 {
688 lt = localtime (&tl);
689 if (lt)
690 {
691 tmk = tml = *lt;
692 tk = mktime (&tmk);
693 status |= check_result (tk, tmk, tl, &tml);
694 }
695 else
696 {
697 printf ("localtime (%ld) yields 0\n", (long int) tl);
698 status = 1;
699 }
700 tl1 = tl + by;
701 if ((tl1 < tl) != (by < 0))
702 break;
703 }
704 else
705 for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
706 {
707 /* Null benchmark. */
708 lt = localtime (&tl);
709 if (lt)
710 {
711 tmk = tml = *lt;
712 tk = tl;
713 status |= check_result (tk, tmk, tl, &tml);
714 }
715 else
716 {
717 printf ("localtime (%ld) yields 0\n", (long int) tl);
718 status = 1;
719 }
720 tl1 = tl + by;
721 if ((tl1 < tl) != (by < 0))
722 break;
723 }
724 } 571 }
725 else
726 printf ("Usage:\
727\t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\
728\t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\
729\t%s FROM BY TO - # Do not test those values (for benchmark).\n",
730 argv[0], argv[0], argv[0]);
731
732 return status;
733} 572}
734 573
735#endif /* DEBUG */ 574#endif
736 575
737/* 576weak_alias (mktime, timelocal)
738Local Variables: 577libc_hidden_def (mktime)
739compile-command: "gcc -DDEBUG -I. -Wall -W -O2 -g mktime.c -o mktime" 578libc_hidden_weak (timelocal)
740End:
741*/
diff --git a/gl/mountlist.c b/gl/mountlist.c
index 30f4286..6d38481 100644
--- a/gl/mountlist.c
+++ b/gl/mountlist.c
@@ -1,10 +1,10 @@
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-2013 Free Software Foundation, Inc. 3 Copyright (C) 1991-1992, 1997-2023 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 3 of the License, or 7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) 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,
@@ -13,7 +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, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -37,7 +37,13 @@
37# include <sys/param.h> 37# include <sys/param.h>
38#endif 38#endif
39 39
40#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ 40#if MAJOR_IN_MKDEV
41# include <sys/mkdev.h>
42#elif MAJOR_IN_SYSMACROS
43# include <sys/sysmacros.h>
44#endif
45
46#if defined MOUNTED_GETFSSTAT /* OSF/1, also (obsolete) Apple Darwin 1.3 */
41# if HAVE_SYS_UCRED_H 47# if HAVE_SYS_UCRED_H
42# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS, 48# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS,
43 NGROUPS is used as an array dimension in ucred.h */ 49 NGROUPS is used as an array dimension in ucred.h */
@@ -56,102 +62,104 @@
56# endif 62# endif
57#endif /* MOUNTED_GETFSSTAT */ 63#endif /* MOUNTED_GETFSSTAT */
58 64
59#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ 65#ifdef MOUNTED_GETMNTENT1 /* glibc, HP-UX, IRIX, Cygwin, Android,
66 also (obsolete) 4.3BSD, SunOS */
60# include <mntent.h> 67# include <mntent.h>
61# if !defined MOUNTED 68# include <sys/types.h>
69# if defined __ANDROID__ /* Android */
70 /* Bionic versions from between 2014-01-09 and 2015-01-08 define MOUNTED to
71 an incorrect value; older Bionic versions don't define it at all. */
72# undef MOUNTED
73# define MOUNTED "/proc/mounts"
74# elif !defined MOUNTED
62# if defined _PATH_MOUNTED /* GNU libc */ 75# if defined _PATH_MOUNTED /* GNU libc */
63# define MOUNTED _PATH_MOUNTED 76# define MOUNTED _PATH_MOUNTED
64# endif 77# endif
65# if defined MNT_MNTTAB /* HP-UX. */ 78# if defined MNT_MNTTAB /* HP-UX. */
66# define MOUNTED MNT_MNTTAB 79# define MOUNTED MNT_MNTTAB
67# endif 80# endif
68# if defined MNTTABNAME /* Dynix. */
69# define MOUNTED MNTTABNAME
70# endif
71# endif 81# endif
72#endif 82#endif
73 83
74#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ 84#ifdef MOUNTED_GETMNTINFO /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */
75# include <sys/mount.h> 85# include <sys/mount.h>
76#endif 86#endif
77 87
78#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ 88#ifdef MOUNTED_GETMNTINFO2 /* NetBSD, Minix */
79# include <sys/statvfs.h> 89# include <sys/statvfs.h>
80#endif 90#endif
81 91
82#ifdef MOUNTED_GETMNT /* Ultrix. */ 92#ifdef MOUNTED_FS_STAT_DEV /* Haiku, also (obsolete) BeOS */
83# include <sys/mount.h>
84# include <sys/fs_types.h>
85#endif
86
87#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */
88# include <fs_info.h> 93# include <fs_info.h>
89# include <dirent.h> 94# include <dirent.h>
90#endif 95#endif
91 96
92#ifdef MOUNTED_FREAD /* SVR2. */ 97#ifdef MOUNTED_FREAD_FSTYP /* (obsolete) SVR3 */
93# include <mnttab.h>
94#endif
95
96#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
97# include <mnttab.h> 98# include <mnttab.h>
98# include <sys/fstyp.h> 99# include <sys/fstyp.h>
99# include <sys/statfs.h> 100# include <sys/statfs.h>
100#endif 101#endif
101 102
102#ifdef MOUNTED_LISTMNTENT 103#ifdef MOUNTED_GETEXTMNTENT /* Solaris >= 8 */
103# include <mntent.h> 104# include <sys/mnttab.h>
104#endif 105#endif
105 106
106#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ 107#ifdef MOUNTED_GETMNTENT2 /* Solaris < 8, also (obsolete) SVR4 */
107# include <sys/mnttab.h> 108# include <sys/mnttab.h>
108#endif 109#endif
109 110
110#ifdef MOUNTED_VMOUNT /* AIX. */ 111#ifdef MOUNTED_VMOUNT /* AIX */
111# include <fshelp.h> 112# include <fshelp.h>
112# include <sys/vfs.h> 113# include <sys/vfs.h>
113#endif 114#endif
114 115
115#ifdef MOUNTED_INTERIX_STATVFS /* Interix. */ 116#ifdef MOUNTED_INTERIX_STATVFS /* Interix */
116# include <sys/statvfs.h> 117# include <sys/statvfs.h>
117# include <dirent.h> 118# include <dirent.h>
118#endif 119#endif
119 120
120#ifdef DOLPHIN
121/* So special that it's not worth putting this in autoconf. */
122# undef MOUNTED_FREAD_FSTYP
123# define MOUNTED_GETMNTTBL
124#endif
125
126#if HAVE_SYS_MNTENT_H 121#if HAVE_SYS_MNTENT_H
127/* This is to get MNTOPT_IGNORE on e.g. SVR4. */ 122/* This is to get MNTOPT_IGNORE on e.g. SVR4. */
128# include <sys/mntent.h> 123# include <sys/mntent.h>
129#endif 124#endif
130 125
126#ifdef MOUNTED_GETMNTENT1
127# if !HAVE_SETMNTENT /* Android <= 4.4 */
128# define setmntent(fp,mode) fopen (fp, mode "e")
129# endif
130# if !HAVE_ENDMNTENT /* Android <= 4.4 */
131# define endmntent(fp) fclose (fp)
132# endif
133#endif
134
131#ifndef HAVE_HASMNTOPT 135#ifndef HAVE_HASMNTOPT
132# define hasmntopt(mnt, opt) ((char *) 0) 136# define hasmntopt(mnt, opt) ((char *) 0)
133#endif 137#endif
134 138
135#undef MNT_IGNORE 139#undef MNT_IGNORE
136#ifdef MNTOPT_IGNORE 140#ifdef MNTOPT_IGNORE
137# define MNT_IGNORE(M) hasmntopt (M, MNTOPT_IGNORE) 141# if defined __sun && defined __SVR4
142/* Solaris defines hasmntopt(struct mnttab *, char *)
143 while it is otherwise hasmntopt(struct mnttab *, const char *). */
144# define MNT_IGNORE(M) hasmntopt (M, (char *) MNTOPT_IGNORE)
145# else
146# define MNT_IGNORE(M) hasmntopt (M, MNTOPT_IGNORE)
147# endif
138#else 148#else
139# define MNT_IGNORE(M) 0 149# define MNT_IGNORE(M) 0
140#endif 150#endif
141 151
142#if USE_UNLOCKED_IO 152/* Each of the FILE streams in this file is only used in a single thread. */
143# include "unlocked-io.h" 153#include "unlocked-io.h"
144#endif
145
146/* The results of open() in this file are not used with fchdir,
147 therefore save some unnecessary work in fchdir.c. */
148#undef open
149#undef close
150 154
151/* The results of opendir() in this file are not used with dirfd and fchdir, 155/* The results of opendir() in this file are not used with dirfd and fchdir,
152 therefore save some unnecessary work in fchdir.c. */ 156 therefore save some unnecessary work in fchdir.c. */
153#undef opendir 157#ifdef GNULIB_defined_opendir
154#undef closedir 158# undef opendir
159#endif
160#ifdef GNULIB_defined_closedir
161# undef closedir
162#endif
155 163
156#define ME_DUMMY_0(Fs_name, Fs_type) \ 164#define ME_DUMMY_0(Fs_name, Fs_type) \
157 (strcmp (Fs_type, "autofs") == 0 \ 165 (strcmp (Fs_type, "autofs") == 0 \
@@ -161,6 +169,7 @@
161 || strcmp (Fs_type, "debugfs") == 0 \ 169 || strcmp (Fs_type, "debugfs") == 0 \
162 || strcmp (Fs_type, "devpts") == 0 \ 170 || strcmp (Fs_type, "devpts") == 0 \
163 || strcmp (Fs_type, "fusectl") == 0 \ 171 || strcmp (Fs_type, "fusectl") == 0 \
172 || strcmp (Fs_type, "fuse.portal") == 0 \
164 || strcmp (Fs_type, "mqueue") == 0 \ 173 || strcmp (Fs_type, "mqueue") == 0 \
165 || strcmp (Fs_type, "rpc_pipefs") == 0 \ 174 || strcmp (Fs_type, "rpc_pipefs") == 0 \
166 || strcmp (Fs_type, "sysfs") == 0 \ 175 || strcmp (Fs_type, "sysfs") == 0 \
@@ -176,10 +185,9 @@
176 we grant an exception to any with "bind" in its list of mount options. 185 we grant an exception to any with "bind" in its list of mount options.
177 I.e., those are *not* dummy entries. */ 186 I.e., those are *not* dummy entries. */
178#ifdef MOUNTED_GETMNTENT1 187#ifdef MOUNTED_GETMNTENT1
179# define ME_DUMMY(Fs_name, Fs_type, Fs_ent) \ 188# define ME_DUMMY(Fs_name, Fs_type, Bind) \
180 (ME_DUMMY_0 (Fs_name, Fs_type) \ 189 (ME_DUMMY_0 (Fs_name, Fs_type) \
181 || (strcmp (Fs_type, "none") == 0 \ 190 || (strcmp (Fs_type, "none") == 0 && !Bind))
182 && !hasmntopt (Fs_ent, "bind")))
183#else 191#else
184# define ME_DUMMY(Fs_name, Fs_type) \ 192# define ME_DUMMY(Fs_name, Fs_type) \
185 (ME_DUMMY_0 (Fs_name, Fs_type) || strcmp (Fs_type, "none") == 0) 193 (ME_DUMMY_0 (Fs_name, Fs_type) || strcmp (Fs_type, "none") == 0)
@@ -187,11 +195,14 @@
187 195
188#ifdef __CYGWIN__ 196#ifdef __CYGWIN__
189# include <windows.h> 197# include <windows.h>
198/* Don't assume that UNICODE is not defined. */
199# undef GetDriveType
200# define GetDriveType GetDriveTypeA
190# define ME_REMOTE me_remote 201# define ME_REMOTE me_remote
191/* All cygwin mount points include ':' or start with '//'; so it 202/* All cygwin mount points include ':' or start with '//'; so it
192 requires a native Windows call to determine remote disks. */ 203 requires a native Windows call to determine remote disks. */
193static bool 204static bool
194me_remote (char const *fs_name, char const *fs_type _GL_UNUSED) 205me_remote (char const *fs_name, _GL_UNUSED char const *fs_type)
195{ 206{
196 if (fs_name[0] && fs_name[1] == ':') 207 if (fs_name[0] && fs_name[1] == ':')
197 { 208 {
@@ -212,16 +223,30 @@ me_remote (char const *fs_name, char const *fs_type _GL_UNUSED)
212 223
213#ifndef ME_REMOTE 224#ifndef ME_REMOTE
214/* A file system is "remote" if its Fs_name contains a ':' 225/* A file system is "remote" if its Fs_name contains a ':'
215 or if (it is of type (smbfs or cifs) and its Fs_name starts with '//'). */ 226 or if (it is of type (smbfs or cifs) and its Fs_name starts with '//')
227 or if it is of any other of the listed types
228 or Fs_name is equal to "-hosts" (used by autofs to mount remote fs).
229 "VM" file systems like prl_fs or vboxsf are not considered remote here. */
216# define ME_REMOTE(Fs_name, Fs_type) \ 230# define ME_REMOTE(Fs_name, Fs_type) \
217 (strchr (Fs_name, ':') != NULL \ 231 (strchr (Fs_name, ':') != NULL \
218 || ((Fs_name)[0] == '/' \ 232 || ((Fs_name)[0] == '/' \
219 && (Fs_name)[1] == '/' \ 233 && (Fs_name)[1] == '/' \
220 && (strcmp (Fs_type, "smbfs") == 0 \ 234 && (strcmp (Fs_type, "smbfs") == 0 \
221 || strcmp (Fs_type, "cifs") == 0))) 235 || strcmp (Fs_type, "smb3") == 0 \
236 || strcmp (Fs_type, "cifs") == 0)) \
237 || strcmp (Fs_type, "acfs") == 0 \
238 || strcmp (Fs_type, "afs") == 0 \
239 || strcmp (Fs_type, "coda") == 0 \
240 || strcmp (Fs_type, "auristorfs") == 0 \
241 || strcmp (Fs_type, "fhgfs") == 0 \
242 || strcmp (Fs_type, "gpfs") == 0 \
243 || strcmp (Fs_type, "ibrix") == 0 \
244 || strcmp (Fs_type, "ocfs2") == 0 \
245 || strcmp (Fs_type, "vxfs") == 0 \
246 || strcmp ("-hosts", Fs_name) == 0)
222#endif 247#endif
223 248
224#if MOUNTED_GETMNTINFO 249#if MOUNTED_GETMNTINFO /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */
225 250
226# if ! HAVE_STRUCT_STATFS_F_FSTYPENAME 251# if ! HAVE_STRUCT_STATFS_F_FSTYPENAME
227static char * 252static char *
@@ -331,7 +356,7 @@ fsp_to_string (const struct statfs *fsp)
331 356
332#endif /* MOUNTED_GETMNTINFO */ 357#endif /* MOUNTED_GETMNTINFO */
333 358
334#ifdef MOUNTED_VMOUNT /* AIX. */ 359#ifdef MOUNTED_VMOUNT /* AIX */
335static char * 360static char *
336fstype_to_string (int t) 361fstype_to_string (int t)
337{ 362{
@@ -382,6 +407,46 @@ dev_from_mount_options (char const *mount_options)
382 407
383#endif 408#endif
384 409
410#if defined MOUNTED_GETMNTENT1 && (defined __linux__ || defined __ANDROID__) /* GNU/Linux, Android */
411
412/* Unescape the paths in mount tables.
413 STR is updated in place. */
414
415static void
416unescape_tab (char *str)
417{
418 size_t i, j = 0;
419 size_t len = strlen (str) + 1;
420 for (i = 0; i < len; i++)
421 {
422 if (str[i] == '\\' && (i + 4 < len)
423 && str[i + 1] >= '0' && str[i + 1] <= '3'
424 && str[i + 2] >= '0' && str[i + 2] <= '7'
425 && str[i + 3] >= '0' && str[i + 3] <= '7')
426 {
427 str[j++] = (str[i + 1] - '0') * 64 +
428 (str[i + 2] - '0') * 8 +
429 (str[i + 3] - '0');
430 i += 3;
431 }
432 else
433 str[j++] = str[i];
434 }
435}
436
437/* Find the next space in STR, terminate the string there in place,
438 and return that position. Otherwise return NULL. */
439
440static char *
441terminate_at_blank (char *str)
442{
443 char *s = strchr (str, ' ');
444 if (s)
445 *s = '\0';
446 return s;
447}
448#endif
449
385/* Return a list of the currently mounted file systems, or NULL on error. 450/* Return a list of the currently mounted file systems, or NULL on error.
386 Add each entry to the tail of the list so that they stay in order. 451 Add each entry to the tail of the list so that they stay in order.
387 If NEED_FS_TYPE is true, ensure that the file system type fields in 452 If NEED_FS_TYPE is true, ensure that the file system type fields in
@@ -395,69 +460,141 @@ read_file_system_list (bool need_fs_type)
395 struct mount_entry **mtail = &mount_list; 460 struct mount_entry **mtail = &mount_list;
396 (void) need_fs_type; 461 (void) need_fs_type;
397 462
398#ifdef MOUNTED_LISTMNTENT 463#ifdef MOUNTED_GETMNTENT1 /* glibc, HP-UX, IRIX, Cygwin, Android,
464 also (obsolete) 4.3BSD, SunOS */
399 { 465 {
400 struct tabmntent *mntlist, *p; 466 FILE *fp;
401 struct mntent *mnt;
402 struct mount_entry *me;
403
404 /* the third and fourth arguments could be used to filter mounts,
405 but Crays doesn't seem to have any mounts that we want to
406 remove. Specifically, automount create normal NFS mounts.
407 */
408 467
409 if (listmntent (&mntlist, KMTAB, NULL, NULL) < 0) 468# if defined __linux__ || defined __ANDROID__
410 return NULL; 469 /* Try parsing mountinfo first, as that make device IDs available.
411 for (p = mntlist; p; p = p->next) 470 Note we could use libmount routines to simplify this parsing a little
471 (and that code is in previous versions of this function), however
472 libmount depends on libselinux which pulls in many dependencies. */
473 char const *mountinfo = "/proc/self/mountinfo";
474 fp = fopen (mountinfo, "re");
475 if (fp != NULL)
412 { 476 {
413 mnt = p->ment; 477 char *line = NULL;
414 me = xmalloc (sizeof *me); 478 size_t buf_size = 0;
415 me->me_devname = xstrdup (mnt->mnt_fsname);
416 me->me_mountdir = xstrdup (mnt->mnt_dir);
417 me->me_type = xstrdup (mnt->mnt_type);
418 me->me_type_malloced = 1;
419 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
420 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
421 me->me_dev = -1;
422 *mtail = me;
423 mtail = &me->me_next;
424 }
425 freemntlist (mntlist);
426 }
427#endif
428 479
429#ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ 480 while (getline (&line, &buf_size, fp) != -1)
430 { 481 {
431 struct mntent *mnt; 482 unsigned int devmaj, devmin;
432 char const *table = MOUNTED; 483 int rc, mntroot_s;
433 FILE *fp;
434 484
435 fp = setmntent (table, "r"); 485 rc = sscanf(line, "%*u " /* id - discarded */
436 if (fp == NULL) 486 "%*u " /* parent - discarded */
437 return NULL; 487 "%u:%u " /* dev major:minor */
488 "%n", /* mountroot (start) */
489 &devmaj, &devmin,
490 &mntroot_s);
438 491
439 while ((mnt = getmntent (fp))) 492 if (rc != 2 && rc != 3) /* 3 if %n included in count. */
440 { 493 continue;
441 me = xmalloc (sizeof *me);
442 me->me_devname = xstrdup (mnt->mnt_fsname);
443 me->me_mountdir = xstrdup (mnt->mnt_dir);
444 me->me_type = xstrdup (mnt->mnt_type);
445 me->me_type_malloced = 1;
446 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, mnt);
447 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
448 me->me_dev = dev_from_mount_options (mnt->mnt_opts);
449 494
450 /* Add to the linked list. */ 495 /* find end of MNTROOT. */
451 *mtail = me; 496 char *mntroot = line + mntroot_s;
452 mtail = &me->me_next; 497 char *blank = terminate_at_blank (mntroot);
498 if (! blank)
499 continue;
500
501 /* find end of TARGET. */
502 char *target = blank + 1;
503 blank = terminate_at_blank (target);
504 if (! blank)
505 continue;
506
507 /* skip optional fields, terminated by " - " */
508 char *dash = strstr (blank + 1, " - ");
509 if (! dash)
510 continue;
511
512 /* advance past the " - " separator. */
513 char *fstype = dash + 3;
514 blank = terminate_at_blank (fstype);
515 if (! blank)
516 continue;
517
518 /* find end of SOURCE. */
519 char *source = blank + 1;
520 if (! terminate_at_blank (source))
521 continue;
522
523 /* manipulate the sub-strings in place. */
524 unescape_tab (source);
525 unescape_tab (target);
526 unescape_tab (mntroot);
527 unescape_tab (fstype);
528
529 me = xmalloc (sizeof *me);
530
531 me->me_devname = xstrdup (source);
532 me->me_mountdir = xstrdup (target);
533 me->me_mntroot = xstrdup (mntroot);
534 me->me_type = xstrdup (fstype);
535 me->me_type_malloced = 1;
536 me->me_dev = makedev (devmaj, devmin);
537 /* we pass "false" for the "Bind" option as that's only
538 significant when the Fs_type is "none" which will not be
539 the case when parsing "/proc/self/mountinfo", and only
540 applies for static /etc/mtab files. */
541 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, false);
542 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
543
544 /* Add to the linked list. */
545 *mtail = me;
546 mtail = &me->me_next;
547 }
548
549 free (line);
550
551 if (ferror (fp))
552 {
553 int saved_errno = errno;
554 fclose (fp);
555 errno = saved_errno;
556 goto free_then_fail;
557 }
558
559 if (fclose (fp) == EOF)
560 goto free_then_fail;
453 } 561 }
562 else /* fallback to /proc/self/mounts (/etc/mtab). */
563# endif /* __linux __ || __ANDROID__ */
564 {
565 struct mntent *mnt;
566 char const *table = MOUNTED;
454 567
455 if (endmntent (fp) == 0) 568 fp = setmntent (table, "r");
456 goto free_then_fail; 569 if (fp == NULL)
570 return NULL;
571
572 while ((mnt = getmntent (fp)))
573 {
574 bool bind = hasmntopt (mnt, "bind");
575
576 me = xmalloc (sizeof *me);
577 me->me_devname = xstrdup (mnt->mnt_fsname);
578 me->me_mountdir = xstrdup (mnt->mnt_dir);
579 me->me_mntroot = NULL;
580 me->me_type = xstrdup (mnt->mnt_type);
581 me->me_type_malloced = 1;
582 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, bind);
583 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
584 me->me_dev = dev_from_mount_options (mnt->mnt_opts);
585
586 /* Add to the linked list. */
587 *mtail = me;
588 mtail = &me->me_next;
589 }
590
591 if (endmntent (fp) == 0)
592 goto free_then_fail;
593 }
457 } 594 }
458#endif /* MOUNTED_GETMNTENT1. */ 595#endif /* MOUNTED_GETMNTENT1. */
459 596
460#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ 597#ifdef MOUNTED_GETMNTINFO /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */
461 { 598 {
462 struct statfs *fsp; 599 struct statfs *fsp;
463 int entries; 600 int entries;
@@ -472,6 +609,7 @@ read_file_system_list (bool need_fs_type)
472 me = xmalloc (sizeof *me); 609 me = xmalloc (sizeof *me);
473 me->me_devname = xstrdup (fsp->f_mntfromname); 610 me->me_devname = xstrdup (fsp->f_mntfromname);
474 me->me_mountdir = xstrdup (fsp->f_mntonname); 611 me->me_mountdir = xstrdup (fsp->f_mntonname);
612 me->me_mntroot = NULL;
475 me->me_type = fs_type; 613 me->me_type = fs_type;
476 me->me_type_malloced = 0; 614 me->me_type_malloced = 0;
477 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 615 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -485,7 +623,7 @@ read_file_system_list (bool need_fs_type)
485 } 623 }
486#endif /* MOUNTED_GETMNTINFO */ 624#endif /* MOUNTED_GETMNTINFO */
487 625
488#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ 626#ifdef MOUNTED_GETMNTINFO2 /* NetBSD, Minix */
489 { 627 {
490 struct statvfs *fsp; 628 struct statvfs *fsp;
491 int entries; 629 int entries;
@@ -498,6 +636,7 @@ read_file_system_list (bool need_fs_type)
498 me = xmalloc (sizeof *me); 636 me = xmalloc (sizeof *me);
499 me->me_devname = xstrdup (fsp->f_mntfromname); 637 me->me_devname = xstrdup (fsp->f_mntfromname);
500 me->me_mountdir = xstrdup (fsp->f_mntonname); 638 me->me_mountdir = xstrdup (fsp->f_mntonname);
639 me->me_mntroot = NULL;
501 me->me_type = xstrdup (fsp->f_fstypename); 640 me->me_type = xstrdup (fsp->f_fstypename);
502 me->me_type_malloced = 1; 641 me->me_type_malloced = 1;
503 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 642 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -511,35 +650,7 @@ read_file_system_list (bool need_fs_type)
511 } 650 }
512#endif /* MOUNTED_GETMNTINFO2 */ 651#endif /* MOUNTED_GETMNTINFO2 */
513 652
514#ifdef MOUNTED_GETMNT /* Ultrix. */ 653#if defined MOUNTED_FS_STAT_DEV /* Haiku, also (obsolete) BeOS */
515 {
516 int offset = 0;
517 int val;
518 struct fs_data fsd;
519
520 while (errno = 0,
521 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
522 (char *) 0)))
523 {
524 me = xmalloc (sizeof *me);
525 me->me_devname = xstrdup (fsd.fd_req.devname);
526 me->me_mountdir = xstrdup (fsd.fd_req.path);
527 me->me_type = gt_names[fsd.fd_req.fstype];
528 me->me_type_malloced = 0;
529 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
530 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
531 me->me_dev = fsd.fd_req.dev;
532
533 /* Add to the linked list. */
534 *mtail = me;
535 mtail = &me->me_next;
536 }
537 if (val < 0)
538 goto free_then_fail;
539 }
540#endif /* MOUNTED_GETMNT. */
541
542#if defined MOUNTED_FS_STAT_DEV /* BeOS */
543 { 654 {
544 /* The next_dev() and fs_stat_dev() system calls give the list of 655 /* The next_dev() and fs_stat_dev() system calls give the list of
545 all file systems, including the information returned by statvfs() 656 all file systems, including the information returned by statvfs()
@@ -622,6 +733,7 @@ read_file_system_list (bool need_fs_type)
622 me->me_devname = xstrdup (fi.device_name[0] != '\0' 733 me->me_devname = xstrdup (fi.device_name[0] != '\0'
623 ? fi.device_name : fi.fsh_name); 734 ? fi.device_name : fi.fsh_name);
624 me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); 735 me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
736 me->me_mntroot = NULL;
625 me->me_type = xstrdup (fi.fsh_name); 737 me->me_type = xstrdup (fi.fsh_name);
626 me->me_type_malloced = 1; 738 me->me_type_malloced = 1;
627 me->me_dev = fi.dev; 739 me->me_dev = fi.dev;
@@ -644,7 +756,7 @@ read_file_system_list (bool need_fs_type)
644 } 756 }
645#endif /* MOUNTED_FS_STAT_DEV */ 757#endif /* MOUNTED_FS_STAT_DEV */
646 758
647#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ 759#if defined MOUNTED_GETFSSTAT /* OSF/1, also (obsolete) Apple Darwin 1.3 */
648 { 760 {
649 int numsys, counter; 761 int numsys, counter;
650 size_t bufsize; 762 size_t bufsize;
@@ -671,6 +783,7 @@ read_file_system_list (bool need_fs_type)
671 me = xmalloc (sizeof *me); 783 me = xmalloc (sizeof *me);
672 me->me_devname = xstrdup (stats[counter].f_mntfromname); 784 me->me_devname = xstrdup (stats[counter].f_mntfromname);
673 me->me_mountdir = xstrdup (stats[counter].f_mntonname); 785 me->me_mountdir = xstrdup (stats[counter].f_mntonname);
786 me->me_mntroot = NULL;
674 me->me_type = xstrdup (FS_TYPE (stats[counter])); 787 me->me_type = xstrdup (FS_TYPE (stats[counter]));
675 me->me_type_malloced = 1; 788 me->me_type_malloced = 1;
676 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 789 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -686,31 +799,25 @@ read_file_system_list (bool need_fs_type)
686 } 799 }
687#endif /* MOUNTED_GETFSSTAT */ 800#endif /* MOUNTED_GETFSSTAT */
688 801
689#if defined MOUNTED_FREAD || defined MOUNTED_FREAD_FSTYP /* SVR[23]. */ 802#if defined MOUNTED_FREAD_FSTYP /* (obsolete) SVR3 */
690 { 803 {
691 struct mnttab mnt; 804 struct mnttab mnt;
692 char *table = "/etc/mnttab"; 805 char *table = "/etc/mnttab";
693 FILE *fp; 806 FILE *fp;
694 807
695 fp = fopen (table, "r"); 808 fp = fopen (table, "re");
696 if (fp == NULL) 809 if (fp == NULL)
697 return NULL; 810 return NULL;
698 811
699 while (fread (&mnt, sizeof mnt, 1, fp) > 0) 812 while (fread (&mnt, sizeof mnt, 1, fp) > 0)
700 { 813 {
701 me = xmalloc (sizeof *me); 814 me = xmalloc (sizeof *me);
702# ifdef GETFSTYP /* SVR3. */
703 me->me_devname = xstrdup (mnt.mt_dev); 815 me->me_devname = xstrdup (mnt.mt_dev);
704# else
705 me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
706 strcpy (me->me_devname, "/dev/");
707 strcpy (me->me_devname + 5, mnt.mt_dev);
708# endif
709 me->me_mountdir = xstrdup (mnt.mt_filsys); 816 me->me_mountdir = xstrdup (mnt.mt_filsys);
817 me->me_mntroot = NULL;
710 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 818 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
711 me->me_type = ""; 819 me->me_type = "";
712 me->me_type_malloced = 0; 820 me->me_type_malloced = 0;
713# ifdef GETFSTYP /* SVR3. */
714 if (need_fs_type) 821 if (need_fs_type)
715 { 822 {
716 struct statfs fsd; 823 struct statfs fsd;
@@ -723,7 +830,6 @@ read_file_system_list (bool need_fs_type)
723 me->me_type_malloced = 1; 830 me->me_type_malloced = 1;
724 } 831 }
725 } 832 }
726# endif
727 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 833 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
728 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 834 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
729 835
@@ -744,34 +850,57 @@ read_file_system_list (bool need_fs_type)
744 if (fclose (fp) == EOF) 850 if (fclose (fp) == EOF)
745 goto free_then_fail; 851 goto free_then_fail;
746 } 852 }
747#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ 853#endif /* MOUNTED_FREAD_FSTYP. */
748 854
749#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ 855#ifdef MOUNTED_GETEXTMNTENT /* Solaris >= 8 */
750 { 856 {
751 struct mntent **mnttbl = getmnttbl (), **ent; 857 struct extmnttab mnt;
752 for (ent = mnttbl; *ent; ent++) 858 const char *table = MNTTAB;
859 FILE *fp;
860 int ret;
861
862 /* No locking is needed, because the contents of /etc/mnttab is generated
863 by the kernel. */
864
865 errno = 0;
866 fp = fopen (table, "re");
867 if (fp == NULL)
868 ret = errno;
869 else
753 { 870 {
754 me = xmalloc (sizeof *me); 871 while ((ret = getextmntent (fp, &mnt, 1)) == 0)
755 me->me_devname = xstrdup ((*ent)->mt_resource); 872 {
756 me->me_mountdir = xstrdup ((*ent)->mt_directory); 873 me = xmalloc (sizeof *me);
757 me->me_type = xstrdup ((*ent)->mt_fstype); 874 me->me_devname = xstrdup (mnt.mnt_special);
758 me->me_type_malloced = 1; 875 me->me_mountdir = xstrdup (mnt.mnt_mountp);
759 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 876 me->me_mntroot = NULL;
760 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 877 me->me_type = xstrdup (mnt.mnt_fstype);
761 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 878 me->me_type_malloced = 1;
879 me->me_dummy = MNT_IGNORE (&mnt) != 0;
880 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
881 me->me_dev = makedev (mnt.mnt_major, mnt.mnt_minor);
762 882
763 /* Add to the linked list. */ 883 /* Add to the linked list. */
764 *mtail = me; 884 *mtail = me;
765 mtail = &me->me_next; 885 mtail = &me->me_next;
886 }
887
888 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
889 /* Here ret = -1 means success, ret >= 0 means failure. */
890 }
891
892 if (0 <= ret)
893 {
894 errno = ret;
895 goto free_then_fail;
766 } 896 }
767 endmnttbl ();
768 } 897 }
769#endif 898#endif /* MOUNTED_GETEXTMNTENT */
770 899
771#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ 900#ifdef MOUNTED_GETMNTENT2 /* Solaris < 8, also (obsolete) SVR4 */
772 { 901 {
773 struct mnttab mnt; 902 struct mnttab mnt;
774 char *table = MNTTAB; 903 const char *table = MNTTAB;
775 FILE *fp; 904 FILE *fp;
776 int ret; 905 int ret;
777 int lockfd = -1; 906 int lockfd = -1;
@@ -784,7 +913,7 @@ read_file_system_list (bool need_fs_type)
784# ifndef MNTTAB_LOCK 913# ifndef MNTTAB_LOCK
785# define MNTTAB_LOCK "/etc/.mnttab.lock" 914# define MNTTAB_LOCK "/etc/.mnttab.lock"
786# endif 915# endif
787 lockfd = open (MNTTAB_LOCK, O_RDONLY); 916 lockfd = open (MNTTAB_LOCK, O_RDONLY | O_CLOEXEC);
788 if (0 <= lockfd) 917 if (0 <= lockfd)
789 { 918 {
790 struct flock flock; 919 struct flock flock;
@@ -806,7 +935,7 @@ read_file_system_list (bool need_fs_type)
806# endif 935# endif
807 936
808 errno = 0; 937 errno = 0;
809 fp = fopen (table, "r"); 938 fp = fopen (table, "re");
810 if (fp == NULL) 939 if (fp == NULL)
811 ret = errno; 940 ret = errno;
812 else 941 else
@@ -816,6 +945,7 @@ read_file_system_list (bool need_fs_type)
816 me = xmalloc (sizeof *me); 945 me = xmalloc (sizeof *me);
817 me->me_devname = xstrdup (mnt.mnt_special); 946 me->me_devname = xstrdup (mnt.mnt_special);
818 me->me_mountdir = xstrdup (mnt.mnt_mountp); 947 me->me_mountdir = xstrdup (mnt.mnt_mountp);
948 me->me_mntroot = NULL;
819 me->me_type = xstrdup (mnt.mnt_fstype); 949 me->me_type = xstrdup (mnt.mnt_fstype);
820 me->me_type_malloced = 1; 950 me->me_type_malloced = 1;
821 me->me_dummy = MNT_IGNORE (&mnt) != 0; 951 me->me_dummy = MNT_IGNORE (&mnt) != 0;
@@ -828,6 +958,7 @@ read_file_system_list (bool need_fs_type)
828 } 958 }
829 959
830 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1; 960 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
961 /* Here ret = -1 means success, ret >= 0 means failure. */
831 } 962 }
832 963
833 if (0 <= lockfd && close (lockfd) != 0) 964 if (0 <= lockfd && close (lockfd) != 0)
@@ -841,26 +972,26 @@ read_file_system_list (bool need_fs_type)
841 } 972 }
842#endif /* MOUNTED_GETMNTENT2. */ 973#endif /* MOUNTED_GETMNTENT2. */
843 974
844#ifdef MOUNTED_VMOUNT /* AIX. */ 975#ifdef MOUNTED_VMOUNT /* AIX */
845 { 976 {
846 int bufsize; 977 int bufsize;
847 char *entries, *thisent; 978 void *entries;
979 char *thisent;
848 struct vmount *vmp; 980 struct vmount *vmp;
849 int n_entries; 981 int n_entries;
850 int i; 982 int i;
851 983
852 /* Ask how many bytes to allocate for the mounted file system info. */ 984 /* Ask how many bytes to allocate for the mounted file system info. */
853 if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0) 985 entries = &bufsize;
986 if (mntctl (MCTL_QUERY, sizeof bufsize, entries) != 0)
854 return NULL; 987 return NULL;
855 entries = xmalloc (bufsize); 988 entries = xmalloc (bufsize);
856 989
857 /* Get the list of mounted file systems. */ 990 /* Get the list of mounted file systems. */
858 n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); 991 n_entries = mntctl (MCTL_QUERY, bufsize, entries);
859 if (n_entries < 0) 992 if (n_entries < 0)
860 { 993 {
861 int saved_errno = errno;
862 free (entries); 994 free (entries);
863 errno = saved_errno;
864 return NULL; 995 return NULL;
865 } 996 }
866 997
@@ -892,6 +1023,7 @@ read_file_system_list (bool need_fs_type)
892 vmp->vmt_data[VMT_OBJECT].vmt_off); 1023 vmp->vmt_data[VMT_OBJECT].vmt_off);
893 } 1024 }
894 me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); 1025 me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
1026 me->me_mntroot = NULL;
895 me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); 1027 me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
896 me->me_type_malloced = 1; 1028 me->me_type_malloced = 1;
897 options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; 1029 options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
@@ -910,7 +1042,7 @@ read_file_system_list (bool need_fs_type)
910 } 1042 }
911#endif /* MOUNTED_VMOUNT. */ 1043#endif /* MOUNTED_VMOUNT. */
912 1044
913#ifdef MOUNTED_INTERIX_STATVFS 1045#ifdef MOUNTED_INTERIX_STATVFS /* Interix */
914 { 1046 {
915 DIR *dirp = opendir ("/dev/fs"); 1047 DIR *dirp = opendir ("/dev/fs");
916 char node[9 + NAME_MAX]; 1048 char node[9 + NAME_MAX];
@@ -924,6 +1056,8 @@ read_file_system_list (bool need_fs_type)
924 struct dirent entry; 1056 struct dirent entry;
925 struct dirent *result; 1057 struct dirent *result;
926 1058
1059 /* FIXME: readdir_r is planned to be withdrawn from POSIX and
1060 marked obsolescent in glibc. Use readdir instead. */
927 if (readdir_r (dirp, &entry, &result) || result == NULL) 1061 if (readdir_r (dirp, &entry, &result) || result == NULL)
928 break; 1062 break;
929 1063
@@ -935,6 +1069,7 @@ read_file_system_list (bool need_fs_type)
935 me = xmalloc (sizeof *me); 1069 me = xmalloc (sizeof *me);
936 me->me_devname = xstrdup (dev.f_mntfromname); 1070 me->me_devname = xstrdup (dev.f_mntfromname);
937 me->me_mountdir = xstrdup (dev.f_mntonname); 1071 me->me_mountdir = xstrdup (dev.f_mntonname);
1072 me->me_mntroot = NULL;
938 me->me_type = xstrdup (dev.f_fstypename); 1073 me->me_type = xstrdup (dev.f_fstypename);
939 me->me_type_malloced = 1; 1074 me->me_type_malloced = 1;
940 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 1075 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -946,6 +1081,7 @@ read_file_system_list (bool need_fs_type)
946 mtail = &me->me_next; 1081 mtail = &me->me_next;
947 } 1082 }
948 } 1083 }
1084 closedir (dirp);
949 } 1085 }
950#endif /* MOUNTED_INTERIX_STATVFS */ 1086#endif /* MOUNTED_INTERIX_STATVFS */
951 1087
@@ -953,7 +1089,7 @@ read_file_system_list (bool need_fs_type)
953 return mount_list; 1089 return mount_list;
954 1090
955 1091
956 free_then_fail: 1092 free_then_fail: _GL_UNUSED_LABEL;
957 { 1093 {
958 int saved_errno = errno; 1094 int saved_errno = errno;
959 *mtail = NULL; 1095 *mtail = NULL;
@@ -972,10 +1108,12 @@ read_file_system_list (bool need_fs_type)
972 1108
973/* Free a mount entry as returned from read_file_system_list (). */ 1109/* Free a mount entry as returned from read_file_system_list (). */
974 1110
975void free_mount_entry (struct mount_entry *me) 1111void
1112free_mount_entry (struct mount_entry *me)
976{ 1113{
977 free (me->me_devname); 1114 free (me->me_devname);
978 free (me->me_mountdir); 1115 free (me->me_mountdir);
1116 free (me->me_mntroot);
979 if (me->me_type_malloced) 1117 if (me->me_type_malloced)
980 free (me->me_type); 1118 free (me->me_type);
981 free (me); 1119 free (me);
diff --git a/gl/mountlist.h b/gl/mountlist.h
index 55877e2..aed7f88 100644
--- a/gl/mountlist.h
+++ b/gl/mountlist.h
@@ -1,11 +1,11 @@
1/* mountlist.h -- declarations for list of mounted file systems 1/* mountlist.h -- declarations for list of mounted file systems
2 2
3 Copyright (C) 1991-1992, 1998, 2000-2005, 2009-2013 Free Software 3 Copyright (C) 1991-1992, 1998, 2000-2005, 2009-2023 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 3 of the License, or 8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) 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,
@@ -14,12 +14,11 @@
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, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#ifndef MOUNTLIST_H_ 19#ifndef MOUNTLIST_H_
20# define MOUNTLIST_H_ 20# define MOUNTLIST_H_
21 21
22# include <stdbool.h>
23# include <sys/types.h> 22# include <sys/types.h>
24 23
25/* A mount table entry. */ 24/* A mount table entry. */
@@ -27,15 +26,18 @@ struct mount_entry
27{ 26{
28 char *me_devname; /* Device node name, including "/dev/". */ 27 char *me_devname; /* Device node name, including "/dev/". */
29 char *me_mountdir; /* Mount point directory name. */ 28 char *me_mountdir; /* Mount point directory name. */
29 char *me_mntroot; /* Directory on filesystem of device used */
30 /* as root for the (bind) mount. */
30 char *me_type; /* "nfs", "4.2", etc. */ 31 char *me_type; /* "nfs", "4.2", etc. */
31 dev_t me_dev; /* Device number of me_mountdir. */ 32 dev_t me_dev; /* Device number of me_mountdir. */
32 unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */ 33 unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */
33 unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ 34 unsigned int me_remote : 1; /* Nonzero for remote file systems. */
34 unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */ 35 unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */
35 struct mount_entry *me_next; 36 struct mount_entry *me_next;
36}; 37};
37 38
38struct mount_entry *read_file_system_list (bool need_fs_type); 39struct mount_entry *read_file_system_list (bool need_fs_type)
40 _GL_ATTRIBUTE_MALLOC;
39void free_mount_entry (struct mount_entry *entry); 41void free_mount_entry (struct mount_entry *entry);
40 42
41#endif 43#endif
diff --git a/gl/msvc-inval.c b/gl/msvc-inval.c
index 396031e..c5149a8 100644
--- a/gl/msvc-inval.c
+++ b/gl/msvc-inval.c
@@ -1,18 +1,18 @@
1/* Invalid parameter handler for MSVC runtime libraries. 1/* Invalid parameter handler for MSVC runtime libraries.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
diff --git a/gl/msvc-inval.h b/gl/msvc-inval.h
index dcb0353..ed00461 100644
--- a/gl/msvc-inval.h
+++ b/gl/msvc-inval.h
@@ -1,18 +1,18 @@
1/* Invalid parameter handler for MSVC runtime libraries. 1/* Invalid parameter handler for MSVC runtime libraries.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#ifndef _MSVC_INVAL_H 17#ifndef _MSVC_INVAL_H
18#define _MSVC_INVAL_H 18#define _MSVC_INVAL_H
@@ -95,7 +95,7 @@ extern void gl_msvc_inval_ensure_handler (void);
95 95
96/* Gnulib can define its own status codes, as described in the page 96/* Gnulib can define its own status codes, as described in the page
97 "Raising Software Exceptions" on microsoft.com 97 "Raising Software Exceptions" on microsoft.com
98 <http://msdn.microsoft.com/en-us/library/het71c37.aspx>. 98 <https://docs.microsoft.com/en-us/cpp/cpp/raising-software-exceptions>.
99 Our status codes are composed of 99 Our status codes are composed of
100 - 0xE0000000, mandatory for all user-defined status codes, 100 - 0xE0000000, mandatory for all user-defined status codes,
101 - 0x474E550, a API identifier ("GNU"), 101 - 0x474E550, a API identifier ("GNU"),
@@ -106,7 +106,7 @@ extern void gl_msvc_inval_ensure_handler (void);
106# if defined _MSC_VER 106# if defined _MSC_VER
107/* A compiler that supports __try/__except, as described in the page 107/* A compiler that supports __try/__except, as described in the page
108 "try-except statement" on microsoft.com 108 "try-except statement" on microsoft.com
109 <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>. 109 <https://docs.microsoft.com/en-us/cpp/cpp/try-except-statement>.
110 With __try/__except, we can use the multithread-safe exception handling. */ 110 With __try/__except, we can use the multithread-safe exception handling. */
111 111
112# ifdef __cplusplus 112# ifdef __cplusplus
diff --git a/gl/msvc-nothrow.c b/gl/msvc-nothrow.c
index 8d65472..f729fe6 100644
--- a/gl/msvc-nothrow.c
+++ b/gl/msvc-nothrow.c
@@ -1,19 +1,19 @@
1/* Wrappers that don't throw invalid parameter notifications 1/* Wrappers that don't throw invalid parameter notifications
2 with MSVC runtime libraries. 2 with MSVC runtime libraries.
3 Copyright (C) 2011-2013 Free Software Foundation, Inc. 3 Copyright (C) 2011-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -24,7 +24,9 @@
24#define WIN32_LEAN_AND_MEAN 24#define WIN32_LEAN_AND_MEAN
25#include <windows.h> 25#include <windows.h>
26 26
27#include "msvc-inval.h" 27#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
28# include "msvc-inval.h"
29#endif
28 30
29#undef _get_osfhandle 31#undef _get_osfhandle
30 32
diff --git a/gl/msvc-nothrow.h b/gl/msvc-nothrow.h
index 5f52181..82d3f6a 100644
--- a/gl/msvc-nothrow.h
+++ b/gl/msvc-nothrow.h
@@ -1,19 +1,19 @@
1/* Wrappers that don't throw invalid parameter notifications 1/* Wrappers that don't throw invalid parameter notifications
2 with MSVC runtime libraries. 2 with MSVC runtime libraries.
3 Copyright (C) 2011-2013 Free Software Foundation, Inc. 3 Copyright (C) 2011-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _MSVC_NOTHROW_H 18#ifndef _MSVC_NOTHROW_H
19#define _MSVC_NOTHROW_H 19#define _MSVC_NOTHROW_H
@@ -25,7 +25,7 @@
25 This file defines wrappers that turn such an invalid parameter notification 25 This file defines wrappers that turn such an invalid parameter notification
26 into an error code. */ 26 into an error code. */
27 27
28#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 28#if defined _WIN32 && ! defined __CYGWIN__
29 29
30/* Get original declaration of _get_osfhandle. */ 30/* Get original declaration of _get_osfhandle. */
31# include <io.h> 31# include <io.h>
diff --git a/gl/netdb.in.h b/gl/netdb.in.h
index 0da1800..9549cd7 100644
--- a/gl/netdb.in.h
+++ b/gl/netdb.in.h
@@ -1,19 +1,19 @@
1/* Provide a netdb.h header file for systems lacking it (read: MinGW). 1/* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008-2023 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* This file is supposed to be used on platforms that lack <netdb.h>. 18/* This file is supposed to be used on platforms that lack <netdb.h>.
19 It is intended to provide definitions and prototypes needed by an 19 It is intended to provide definitions and prototypes needed by an
@@ -158,33 +158,61 @@ struct addrinfo
158# endif 158# endif
159# endif 159# endif
160 160
161# if !@HAVE_DECL_GETADDRINFO@
162/* Translate name of a service location and/or a service name to set of 161/* Translate name of a service location and/or a service name to set of
163 socket addresses. 162 socket addresses.
164 For more details, see the POSIX:2001 specification 163 For more details, see the POSIX:2008 specification
165 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ 164 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
165# if @REPLACE_GETADDRINFO@
166# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
167# undef getaddrinfo
168# define getaddrinfo rpl_getaddrinfo
169# endif
170_GL_FUNCDECL_RPL (getaddrinfo, int,
171 (const char *restrict nodename,
172 const char *restrict servname,
173 const struct addrinfo *restrict hints,
174 struct addrinfo **restrict res)
175 _GL_ARG_NONNULL ((4)));
176_GL_CXXALIAS_RPL (getaddrinfo, int,
177 (const char *restrict nodename,
178 const char *restrict servname,
179 const struct addrinfo *restrict hints,
180 struct addrinfo **restrict res));
181# else
182# if !@HAVE_DECL_GETADDRINFO@
166_GL_FUNCDECL_SYS (getaddrinfo, int, 183_GL_FUNCDECL_SYS (getaddrinfo, int,
167 (const char *restrict nodename, 184 (const char *restrict nodename,
168 const char *restrict servname, 185 const char *restrict servname,
169 const struct addrinfo *restrict hints, 186 const struct addrinfo *restrict hints,
170 struct addrinfo **restrict res) 187 struct addrinfo **restrict res)
171 _GL_ARG_NONNULL ((4))); 188 _GL_ARG_NONNULL ((4)));
172# endif 189# endif
173_GL_CXXALIAS_SYS (getaddrinfo, int, 190_GL_CXXALIAS_SYS (getaddrinfo, int,
174 (const char *restrict nodename, 191 (const char *restrict nodename,
175 const char *restrict servname, 192 const char *restrict servname,
176 const struct addrinfo *restrict hints, 193 const struct addrinfo *restrict hints,
177 struct addrinfo **restrict res)); 194 struct addrinfo **restrict res));
195# endif
178_GL_CXXALIASWARN (getaddrinfo); 196_GL_CXXALIASWARN (getaddrinfo);
179 197
180# if !@HAVE_DECL_FREEADDRINFO@
181/* Free 'addrinfo' structure AI including associated storage. 198/* Free 'addrinfo' structure AI including associated storage.
182 For more details, see the POSIX:2001 specification 199 For more details, see the POSIX:2008 specification
183 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ 200 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
201# if @REPLACE_GETADDRINFO@
202# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
203# undef freeaddrinfo
204# define freeaddrinfo rpl_freeaddrinfo
205# endif
206_GL_FUNCDECL_RPL (freeaddrinfo, void, (struct addrinfo *ai)
207 _GL_ARG_NONNULL ((1)));
208_GL_CXXALIAS_RPL (freeaddrinfo, void, (struct addrinfo *ai));
209# else
210# if !@HAVE_DECL_FREEADDRINFO@
184_GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai) 211_GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai)
185 _GL_ARG_NONNULL ((1))); 212 _GL_ARG_NONNULL ((1)));
186# endif 213# endif
187_GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai)); 214_GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
215# endif
188_GL_CXXALIASWARN (freeaddrinfo); 216_GL_CXXALIASWARN (freeaddrinfo);
189 217
190# if @REPLACE_GAI_STRERROR@ 218# if @REPLACE_GAI_STRERROR@
@@ -197,18 +225,20 @@ _GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
197# else 225# else
198# if !@HAVE_DECL_GAI_STRERROR@ 226# if !@HAVE_DECL_GAI_STRERROR@
199/* Convert error return from getaddrinfo() to a string. 227/* Convert error return from getaddrinfo() to a string.
200 For more details, see the POSIX:2001 specification 228 For more details, see the POSIX:2008 specification
201 <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */ 229 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>. */
202_GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode)); 230_GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode));
203# endif 231# endif
204_GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode)); 232_GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
205# endif 233# endif
234# if __GLIBC__ >= 2
206_GL_CXXALIASWARN (gai_strerror); 235_GL_CXXALIASWARN (gai_strerror);
236# endif
207 237
208# if !@HAVE_DECL_GETNAMEINFO@ 238# if !@HAVE_DECL_GETNAMEINFO@
209/* Convert socket address to printable node and service names. 239/* Convert socket address to printable node and service names.
210 For more details, see the POSIX:2001 specification 240 For more details, see the POSIX:2008 specification
211 <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */ 241 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>. */
212_GL_FUNCDECL_SYS (getnameinfo, int, 242_GL_FUNCDECL_SYS (getnameinfo, int,
213 (const struct sockaddr *restrict sa, socklen_t salen, 243 (const struct sockaddr *restrict sa, socklen_t salen,
214 char *restrict node, socklen_t nodelen, 244 char *restrict node, socklen_t nodelen,
diff --git a/gl/netinet_in.in.h b/gl/netinet_in.in.h
index b456c4f..f88923a 100644
--- a/gl/netinet_in.in.h
+++ b/gl/netinet_in.in.h
@@ -1,18 +1,18 @@
1/* Substitute for <netinet/in.h>. 1/* Substitute for <netinet/in.h>.
2 Copyright (C) 2007-2013 Free Software Foundation, Inc. 2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#ifndef _@GUARD_PREFIX@_NETINET_IN_H 17#ifndef _@GUARD_PREFIX@_NETINET_IN_H
18 18
diff --git a/gl/nl_langinfo-lock.c b/gl/nl_langinfo-lock.c
new file mode 100644
index 0000000..e5cdcd3
--- /dev/null
+++ b/gl/nl_langinfo-lock.c
@@ -0,0 +1,150 @@
1/* Return the internal lock used by nl_langinfo.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019-2020. */
18
19#include <config.h>
20
21/* When it is known that the gl_get_nl_langinfo_lock function is defined
22 by a dependency library, it should not be defined here. */
23#if OMIT_NL_LANGINFO_LOCK
24
25/* This declaration is solely to ensure that after preprocessing
26 this file is never empty. */
27typedef int dummy;
28
29#else
30
31/* This file defines the internal lock used by nl_langinfo.
32 It is a separate compilation unit, so that only one copy of it is
33 present when linking statically. */
34
35/* Prohibit renaming this symbol. */
36# undef gl_get_nl_langinfo_lock
37
38/* Macro for exporting a symbol (function, not variable) defined in this file,
39 when compiled into a shared library. */
40# ifndef DLL_EXPORTED
41# if HAVE_VISIBILITY
42 /* Override the effect of the compiler option '-fvisibility=hidden'. */
43# define DLL_EXPORTED __attribute__((__visibility__("default")))
44# elif defined _WIN32 || defined __CYGWIN__
45# define DLL_EXPORTED __declspec(dllexport)
46# else
47# define DLL_EXPORTED
48# endif
49# endif
50
51# if defined _WIN32 && !defined __CYGWIN__
52
53# define WIN32_LEAN_AND_MEAN /* avoid including junk */
54# include <windows.h>
55
56# include "windows-initguard.h"
57
58/* The return type is a 'CRITICAL_SECTION *', not a 'glwthread_mutex_t *',
59 because the latter is not guaranteed to be a stable ABI in the future. */
60
61/* Make sure the function gets exported from DLLs. */
62DLL_EXPORTED CRITICAL_SECTION *gl_get_nl_langinfo_lock (void);
63
64static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT;
65static CRITICAL_SECTION lock;
66
67/* Returns the internal lock used by nl_langinfo. */
68CRITICAL_SECTION *
69gl_get_nl_langinfo_lock (void)
70{
71 if (!guard.done)
72 {
73 if (InterlockedIncrement (&guard.started) == 0)
74 {
75 /* This thread is the first one to need the lock. Initialize it. */
76 InitializeCriticalSection (&lock);
77 guard.done = 1;
78 }
79 else
80 {
81 /* Don't let guard.started grow and wrap around. */
82 InterlockedDecrement (&guard.started);
83 /* Yield the CPU while waiting for another thread to finish
84 initializing this mutex. */
85 while (!guard.done)
86 Sleep (0);
87 }
88 }
89 return &lock;
90}
91
92# elif HAVE_PTHREAD_API
93
94# include <pthread.h>
95
96static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
97
98/* Make sure the function gets exported from shared libraries. */
99DLL_EXPORTED pthread_mutex_t *gl_get_nl_langinfo_lock (void);
100
101/* Returns the internal lock used by nl_langinfo. */
102pthread_mutex_t *
103gl_get_nl_langinfo_lock (void)
104{
105 return &mutex;
106}
107
108# elif HAVE_THREADS_H
109
110# include <threads.h>
111# include <stdlib.h>
112
113static int volatile init_needed = 1;
114static once_flag init_once = ONCE_FLAG_INIT;
115static mtx_t mutex;
116
117static void
118atomic_init (void)
119{
120 if (mtx_init (&mutex, mtx_plain) != thrd_success)
121 abort ();
122 init_needed = 0;
123}
124
125/* Make sure the function gets exported from shared libraries. */
126DLL_EXPORTED mtx_t *gl_get_nl_langinfo_lock (void);
127
128/* Returns the internal lock used by nl_langinfo. */
129mtx_t *
130gl_get_nl_langinfo_lock (void)
131{
132 if (init_needed)
133 call_once (&init_once, atomic_init);
134 return &mutex;
135}
136
137# endif
138
139# if (defined _WIN32 || defined __CYGWIN__) && !defined _MSC_VER
140/* Make sure the '__declspec(dllimport)' in nl_langinfo.c does not cause
141 a link failure when no DLLs are involved. */
142# if defined _WIN64 || defined _LP64
143# define IMP(x) __imp_##x
144# else
145# define IMP(x) _imp__##x
146# endif
147void * IMP(gl_get_nl_langinfo_lock) = &gl_get_nl_langinfo_lock;
148# endif
149
150#endif
diff --git a/gl/nl_langinfo.c b/gl/nl_langinfo.c
index 771c953..131166f 100644
--- a/gl/nl_langinfo.c
+++ b/gl/nl_langinfo.c
@@ -1,34 +1,278 @@
1/* nl_langinfo() replacement: query locale dependent information. 1/* nl_langinfo() replacement: query locale dependent information.
2 2
3 Copyright (C) 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
20/* Specification. */ 20/* Specification. */
21#include <langinfo.h> 21#include <langinfo.h>
22 22
23#include <locale.h>
24#include <stdlib.h>
25#include <string.h>
26#if defined _WIN32 && ! defined __CYGWIN__
27# define WIN32_LEAN_AND_MEAN /* avoid including junk */
28# include <windows.h>
29# include <stdio.h>
30#endif
31
32#if REPLACE_NL_LANGINFO && !NL_LANGINFO_MTSAFE
33# if defined _WIN32 && !defined __CYGWIN__
34
35# define WIN32_LEAN_AND_MEAN /* avoid including junk */
36# include <windows.h>
37
38# elif HAVE_PTHREAD_API
39
40# include <pthread.h>
41# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS
42# include <threads.h>
43# pragma weak thrd_exit
44# define c11_threads_in_use() (thrd_exit != NULL)
45# else
46# define c11_threads_in_use() 0
47# endif
48
49# elif HAVE_THREADS_H
50
51# include <threads.h>
52
53# endif
54#endif
55
56/* nl_langinfo() must be multithread-safe. To achieve this without using
57 thread-local storage:
58 1. We use a specific static buffer for each possible argument.
59 So that different threads can call nl_langinfo with different arguments,
60 without interfering.
61 2. We use a simple strcpy or memcpy to fill this static buffer. Filling it
62 through, for example, strcpy + strcat would not be guaranteed to leave
63 the buffer's contents intact if another thread is currently accessing
64 it. If necessary, the contents is first assembled in a stack-allocated
65 buffer. */
66
67#if !REPLACE_NL_LANGINFO || GNULIB_defined_CODESET
68/* Return the codeset of the current locale, if this is easily deducible.
69 Otherwise, return "". */
70static char *
71ctype_codeset (void)
72{
73 static char result[2 + 10 + 1];
74 char buf[2 + 10 + 1];
75 char locale[SETLOCALE_NULL_MAX];
76 char *codeset;
77 size_t codesetlen;
78
79 if (setlocale_null_r (LC_CTYPE, locale, sizeof (locale)))
80 locale[0] = '\0';
81
82 codeset = buf;
83 codeset[0] = '\0';
84
85 if (locale[0])
86 {
87 /* If the locale name contains an encoding after the dot, return it. */
88 char *dot = strchr (locale, '.');
89
90 if (dot)
91 {
92 /* Look for the possible @... trailer and remove it, if any. */
93 char *codeset_start = dot + 1;
94 char const *modifier = strchr (codeset_start, '@');
95
96 if (! modifier)
97 codeset = codeset_start;
98 else
99 {
100 codesetlen = modifier - codeset_start;
101 if (codesetlen < sizeof buf)
102 {
103 codeset = memcpy (buf, codeset_start, codesetlen);
104 codeset[codesetlen] = '\0';
105 }
106 }
107 }
108 }
109
110# if defined _WIN32 && ! defined __CYGWIN__
111 /* If setlocale is successful, it returns the number of the
112 codepage, as a string. Otherwise, fall back on Windows API
113 GetACP, which returns the locale's codepage as a number (although
114 this doesn't change according to what the 'setlocale' call specified).
115 Either way, prepend "CP" to make it a valid codeset name. */
116 codesetlen = strlen (codeset);
117 if (0 < codesetlen && codesetlen < sizeof buf - 2)
118 memmove (buf + 2, codeset, codesetlen + 1);
119 else
120 sprintf (buf + 2, "%u", GetACP ());
121 /* For a locale name such as "French_France.65001", in Windows 10,
122 setlocale now returns "French_France.utf8" instead. */
123 if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0)
124 return (char *) "UTF-8";
125 else
126 {
127 memcpy (buf, "CP", 2);
128 strcpy (result, buf);
129 return result;
130 }
131# else
132 strcpy (result, codeset);
133 return result;
134#endif
135}
136#endif
137
138
23#if REPLACE_NL_LANGINFO 139#if REPLACE_NL_LANGINFO
24 140
25/* Override nl_langinfo with support for added nl_item values. */ 141/* Override nl_langinfo with support for added nl_item values. */
26 142
27# include <locale.h>
28# include <string.h>
29
30# undef nl_langinfo 143# undef nl_langinfo
31 144
145/* Without locking, on Solaris 11.3, test-nl_langinfo-mt fails, with message
146 "thread5 disturbed by threadN!", even when threadN invokes only
147 nl_langinfo (CODESET);
148 nl_langinfo (CRNCYSTR);
149 Similarly on Solaris 10. */
150
151# if !NL_LANGINFO_MTSAFE /* Solaris */
152
153# define ITEMS (MAXSTRMSG + 1)
154# define MAX_RESULT_LEN 80
155
156static char *
157nl_langinfo_unlocked (nl_item item)
158{
159 static char result[ITEMS][MAX_RESULT_LEN];
160
161 /* The result of nl_langinfo is in storage that can be overwritten by
162 other calls to nl_langinfo. */
163 char *tmp = nl_langinfo (item);
164 if (item >= 0 && item < ITEMS && tmp != NULL)
165 {
166 size_t tmp_len = strlen (tmp);
167 if (tmp_len < MAX_RESULT_LEN)
168 strcpy (result[item], tmp);
169 else
170 {
171 /* Produce a truncated result. Oh well... */
172 result[item][MAX_RESULT_LEN - 1] = '\0';
173 memcpy (result[item], tmp, MAX_RESULT_LEN - 1);
174 }
175 return result[item];
176 }
177 else
178 return tmp;
179}
180
181/* Use a lock, so that no two threads can invoke nl_langinfo_unlocked
182 at the same time. */
183
184/* Prohibit renaming this symbol. */
185# undef gl_get_nl_langinfo_lock
186
187# if defined _WIN32 && !defined __CYGWIN__
188
189extern __declspec(dllimport) CRITICAL_SECTION *gl_get_nl_langinfo_lock (void);
190
191static char *
192nl_langinfo_with_lock (nl_item item)
193{
194 CRITICAL_SECTION *lock = gl_get_nl_langinfo_lock ();
195 char *ret;
196
197 EnterCriticalSection (lock);
198 ret = nl_langinfo_unlocked (item);
199 LeaveCriticalSection (lock);
200
201 return ret;
202}
203
204# elif HAVE_PTHREAD_API
205
206extern
207# if defined _WIN32 || defined __CYGWIN__
208 __declspec(dllimport)
209# endif
210 pthread_mutex_t *gl_get_nl_langinfo_lock (void);
211
212# if HAVE_WEAK_SYMBOLS /* musl libc, FreeBSD, NetBSD, OpenBSD, Haiku */
213
214 /* Avoid the need to link with '-lpthread'. */
215# pragma weak pthread_mutex_lock
216# pragma weak pthread_mutex_unlock
217
218 /* Determine whether libpthread is in use. */
219# pragma weak pthread_mutexattr_gettype
220 /* See the comments in lock.h. */
221# define pthread_in_use() \
222 (pthread_mutexattr_gettype != NULL || c11_threads_in_use ())
223
224# else
225# define pthread_in_use() 1
226# endif
227
228static char *
229nl_langinfo_with_lock (nl_item item)
230{
231 if (pthread_in_use())
232 {
233 pthread_mutex_t *lock = gl_get_nl_langinfo_lock ();
234 char *ret;
235
236 if (pthread_mutex_lock (lock))
237 abort ();
238 ret = nl_langinfo_unlocked (item);
239 if (pthread_mutex_unlock (lock))
240 abort ();
241
242 return ret;
243 }
244 else
245 return nl_langinfo_unlocked (item);
246}
247
248# elif HAVE_THREADS_H
249
250extern mtx_t *gl_get_nl_langinfo_lock (void);
251
252static char *
253nl_langinfo_with_lock (nl_item item)
254{
255 mtx_t *lock = gl_get_nl_langinfo_lock ();
256 char *ret;
257
258 if (mtx_lock (lock) != thrd_success)
259 abort ();
260 ret = nl_langinfo_unlocked (item);
261 if (mtx_unlock (lock) != thrd_success)
262 abort ();
263
264 return ret;
265}
266
267# endif
268
269# else
270
271/* On other platforms, no lock is needed. */
272# define nl_langinfo_with_lock nl_langinfo
273
274# endif
275
32char * 276char *
33rpl_nl_langinfo (nl_item item) 277rpl_nl_langinfo (nl_item item)
34{ 278{
@@ -36,47 +280,36 @@ rpl_nl_langinfo (nl_item item)
36 { 280 {
37# if GNULIB_defined_CODESET 281# if GNULIB_defined_CODESET
38 case CODESET: 282 case CODESET:
39 { 283 return ctype_codeset ();
40 const char *locale;
41 static char buf[2 + 10 + 1];
42
43 locale = setlocale (LC_CTYPE, NULL);
44 if (locale != NULL && locale[0] != '\0')
45 {
46 /* If the locale name contains an encoding after the dot, return
47 it. */
48 const char *dot = strchr (locale, '.');
49
50 if (dot != NULL)
51 {
52 const char *modifier;
53
54 dot++;
55 /* Look for the possible @... trailer and remove it, if any. */
56 modifier = strchr (dot, '@');
57 if (modifier == NULL)
58 return dot;
59 if (modifier - dot < sizeof (buf))
60 {
61 memcpy (buf, dot, modifier - dot);
62 buf [modifier - dot] = '\0';
63 return buf;
64 }
65 }
66 }
67 return "";
68 }
69# endif 284# endif
70# if GNULIB_defined_T_FMT_AMPM 285# if GNULIB_defined_T_FMT_AMPM
71 case T_FMT_AMPM: 286 case T_FMT_AMPM:
72 return "%I:%M:%S %p"; 287 return (char *) "%I:%M:%S %p";
288# endif
289# if GNULIB_defined_ALTMON
290 case ALTMON_1:
291 case ALTMON_2:
292 case ALTMON_3:
293 case ALTMON_4:
294 case ALTMON_5:
295 case ALTMON_6:
296 case ALTMON_7:
297 case ALTMON_8:
298 case ALTMON_9:
299 case ALTMON_10:
300 case ALTMON_11:
301 case ALTMON_12:
302 /* We don't ship the appropriate localizations with gnulib. Therefore,
303 treat ALTMON_i like MON_i. */
304 item = item - ALTMON_1 + MON_1;
305 break;
73# endif 306# endif
74# if GNULIB_defined_ERA 307# if GNULIB_defined_ERA
75 case ERA: 308 case ERA:
76 /* The format is not standardized. In glibc it is a sequence of strings 309 /* The format is not standardized. In glibc it is a sequence of strings
77 of the form "direction:offset:start_date:end_date:era_name:era_format" 310 of the form "direction:offset:start_date:end_date:era_name:era_format"
78 with an empty string at the end. */ 311 with an empty string at the end. */
79 return ""; 312 return (char *) "";
80 case ERA_D_FMT: 313 case ERA_D_FMT:
81 /* The %Ex conversion in strftime behaves like %x if the locale does not 314 /* The %Ex conversion in strftime behaves like %x if the locale does not
82 have an alternative time format. */ 315 have an alternative time format. */
@@ -95,176 +328,244 @@ rpl_nl_langinfo (nl_item item)
95 case ALT_DIGITS: 328 case ALT_DIGITS:
96 /* The format is not standardized. In glibc it is a sequence of 10 329 /* The format is not standardized. In glibc it is a sequence of 10
97 strings, appended in memory. */ 330 strings, appended in memory. */
98 return "\0\0\0\0\0\0\0\0\0\0"; 331 return (char *) "\0\0\0\0\0\0\0\0\0\0";
99# endif 332# endif
100# if GNULIB_defined_YESEXPR || !FUNC_NL_LANGINFO_YESEXPR_WORKS 333# if GNULIB_defined_YESEXPR || !FUNC_NL_LANGINFO_YESEXPR_WORKS
101 case YESEXPR: 334 case YESEXPR:
102 return "^[yY]"; 335 return (char *) "^[yY]";
103 case NOEXPR: 336 case NOEXPR:
104 return "^[nN]"; 337 return (char *) "^[nN]";
105# endif 338# endif
106 default: 339 default:
107 break; 340 break;
108 } 341 }
109 return nl_langinfo (item); 342 return nl_langinfo_with_lock (item);
110} 343}
111 344
112#else 345#else
113 346
114/* Provide nl_langinfo from scratch. */ 347/* Provide nl_langinfo from scratch, either for native MS-Windows, or
115 348 for old Unix platforms without locales, such as Linux libc5 or
116# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 349 BeOS. */
117 350
118/* Native Windows platforms. */ 351# include <time.h>
119
120# define WIN32_LEAN_AND_MEAN /* avoid including junk */
121# include <windows.h>
122
123# include <stdio.h>
124
125# else
126
127/* An old Unix platform without locales, such as Linux libc5 or BeOS. */
128
129# endif
130
131# include <locale.h>
132 352
133char * 353char *
134nl_langinfo (nl_item item) 354nl_langinfo (nl_item item)
135{ 355{
356 char buf[100];
357 struct tm tmm = { 0 };
358
136 switch (item) 359 switch (item)
137 { 360 {
138 /* nl_langinfo items of the LC_CTYPE category */ 361 /* nl_langinfo items of the LC_CTYPE category */
139 case CODESET: 362 case CODESET:
140# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
141 { 363 {
142 static char buf[2 + 10 + 1]; 364 char *codeset = ctype_codeset ();
143 365 if (*codeset)
144 /* The Windows API has a function returning the locale's codepage as 366 return codeset;
145 a number. */
146 sprintf (buf, "CP%u", GetACP ());
147 return buf;
148 } 367 }
149# elif defined __BEOS__ 368# ifdef __BEOS__
150 return "UTF-8"; 369 return (char *) "UTF-8";
151# else 370# else
152 return "ISO-8859-1"; 371 return (char *) "ISO-8859-1";
153# endif 372# endif
154 /* nl_langinfo items of the LC_NUMERIC category */ 373 /* nl_langinfo items of the LC_NUMERIC category */
155 case RADIXCHAR: 374 case RADIXCHAR:
156 return localeconv () ->decimal_point; 375 return localeconv () ->decimal_point;
157 case THOUSEP: 376 case THOUSEP:
158 return localeconv () ->thousands_sep; 377 return localeconv () ->thousands_sep;
378# ifdef GROUPING
379 case GROUPING:
380 return localeconv () ->grouping;
381# endif
159 /* nl_langinfo items of the LC_TIME category. 382 /* nl_langinfo items of the LC_TIME category.
160 TODO: Really use the locale. */ 383 TODO: Really use the locale. */
161 case D_T_FMT: 384 case D_T_FMT:
162 case ERA_D_T_FMT: 385 case ERA_D_T_FMT:
163 return "%a %b %e %H:%M:%S %Y"; 386 return (char *) "%a %b %e %H:%M:%S %Y";
164 case D_FMT: 387 case D_FMT:
165 case ERA_D_FMT: 388 case ERA_D_FMT:
166 return "%m/%d/%y"; 389 return (char *) "%m/%d/%y";
167 case T_FMT: 390 case T_FMT:
168 case ERA_T_FMT: 391 case ERA_T_FMT:
169 return "%H:%M:%S"; 392 return (char *) "%H:%M:%S";
170 case T_FMT_AMPM: 393 case T_FMT_AMPM:
171 return "%I:%M:%S %p"; 394 return (char *) "%I:%M:%S %p";
172 case AM_STR: 395 case AM_STR:
173 return "AM"; 396 {
397 static char result[80];
398 if (!strftime (buf, sizeof result, "%p", &tmm))
399 return (char *) "AM";
400 strcpy (result, buf);
401 return result;
402 }
174 case PM_STR: 403 case PM_STR:
175 return "PM"; 404 {
405 static char result[80];
406 tmm.tm_hour = 12;
407 if (!strftime (buf, sizeof result, "%p", &tmm))
408 return (char *) "PM";
409 strcpy (result, buf);
410 return result;
411 }
176 case DAY_1: 412 case DAY_1:
177 return "Sunday";
178 case DAY_2: 413 case DAY_2:
179 return "Monday";
180 case DAY_3: 414 case DAY_3:
181 return "Tuesday";
182 case DAY_4: 415 case DAY_4:
183 return "Wednesday";
184 case DAY_5: 416 case DAY_5:
185 return "Thursday";
186 case DAY_6: 417 case DAY_6:
187 return "Friday";
188 case DAY_7: 418 case DAY_7:
189 return "Saturday"; 419 {
420 static char result[7][50];
421 static char const days[][sizeof "Wednesday"] = {
422 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
423 "Friday", "Saturday"
424 };
425 tmm.tm_wday = item - DAY_1;
426 if (!strftime (buf, sizeof result[0], "%A", &tmm))
427 return (char *) days[item - DAY_1];
428 strcpy (result[item - DAY_1], buf);
429 return result[item - DAY_1];
430 }
190 case ABDAY_1: 431 case ABDAY_1:
191 return "Sun";
192 case ABDAY_2: 432 case ABDAY_2:
193 return "Mon";
194 case ABDAY_3: 433 case ABDAY_3:
195 return "Tue";
196 case ABDAY_4: 434 case ABDAY_4:
197 return "Wed";
198 case ABDAY_5: 435 case ABDAY_5:
199 return "Thu";
200 case ABDAY_6: 436 case ABDAY_6:
201 return "Fri";
202 case ABDAY_7: 437 case ABDAY_7:
203 return "Sat"; 438 {
204 case MON_1: 439 static char result[7][30];
205 return "January"; 440 static char const abdays[][sizeof "Sun"] = {
206 case MON_2: 441 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
207 return "February"; 442 };
208 case MON_3: 443 tmm.tm_wday = item - ABDAY_1;
209 return "March"; 444 if (!strftime (buf, sizeof result[0], "%a", &tmm))
210 case MON_4: 445 return (char *) abdays[item - ABDAY_1];
211 return "April"; 446 strcpy (result[item - ABDAY_1], buf);
212 case MON_5: 447 return result[item - ABDAY_1];
213 return "May"; 448 }
214 case MON_6: 449 {
215 return "June"; 450 static char const months[][sizeof "September"] = {
216 case MON_7: 451 "January", "February", "March", "April", "May", "June", "July",
217 return "July"; 452 "September", "October", "November", "December"
218 case MON_8: 453 };
219 return "August"; 454 case MON_1:
220 case MON_9: 455 case MON_2:
221 return "September"; 456 case MON_3:
222 case MON_10: 457 case MON_4:
223 return "October"; 458 case MON_5:
224 case MON_11: 459 case MON_6:
225 return "November"; 460 case MON_7:
226 case MON_12: 461 case MON_8:
227 return "December"; 462 case MON_9:
463 case MON_10:
464 case MON_11:
465 case MON_12:
466 {
467 static char result[12][50];
468 tmm.tm_mon = item - MON_1;
469 if (!strftime (buf, sizeof result[0], "%B", &tmm))
470 return (char *) months[item - MON_1];
471 strcpy (result[item - MON_1], buf);
472 return result[item - MON_1];
473 }
474 case ALTMON_1:
475 case ALTMON_2:
476 case ALTMON_3:
477 case ALTMON_4:
478 case ALTMON_5:
479 case ALTMON_6:
480 case ALTMON_7:
481 case ALTMON_8:
482 case ALTMON_9:
483 case ALTMON_10:
484 case ALTMON_11:
485 case ALTMON_12:
486 {
487 static char result[12][50];
488 tmm.tm_mon = item - ALTMON_1;
489 /* The platforms without nl_langinfo() don't support strftime with
490 %OB. We don't even need to try. */
491 #if 0
492 if (!strftime (buf, sizeof result[0], "%OB", &tmm))
493 #endif
494 if (!strftime (buf, sizeof result[0], "%B", &tmm))
495 return (char *) months[item - ALTMON_1];
496 strcpy (result[item - ALTMON_1], buf);
497 return result[item - ALTMON_1];
498 }
499 }
228 case ABMON_1: 500 case ABMON_1:
229 return "Jan";
230 case ABMON_2: 501 case ABMON_2:
231 return "Feb";
232 case ABMON_3: 502 case ABMON_3:
233 return "Mar";
234 case ABMON_4: 503 case ABMON_4:
235 return "Apr";
236 case ABMON_5: 504 case ABMON_5:
237 return "May";
238 case ABMON_6: 505 case ABMON_6:
239 return "Jun";
240 case ABMON_7: 506 case ABMON_7:
241 return "Jul";
242 case ABMON_8: 507 case ABMON_8:
243 return "Aug";
244 case ABMON_9: 508 case ABMON_9:
245 return "Sep";
246 case ABMON_10: 509 case ABMON_10:
247 return "Oct";
248 case ABMON_11: 510 case ABMON_11:
249 return "Nov";
250 case ABMON_12: 511 case ABMON_12:
251 return "Dec"; 512 {
513 static char result[12][30];
514 static char const abmonths[][sizeof "Jan"] = {
515 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
516 "Sep", "Oct", "Nov", "Dec"
517 };
518 tmm.tm_mon = item - ABMON_1;
519 if (!strftime (buf, sizeof result[0], "%b", &tmm))
520 return (char *) abmonths[item - ABMON_1];
521 strcpy (result[item - ABMON_1], buf);
522 return result[item - ABMON_1];
523 }
252 case ERA: 524 case ERA:
253 return ""; 525 return (char *) "";
254 case ALT_DIGITS: 526 case ALT_DIGITS:
255 return "\0\0\0\0\0\0\0\0\0\0"; 527 return (char *) "\0\0\0\0\0\0\0\0\0\0";
256 /* nl_langinfo items of the LC_MONETARY category 528 /* nl_langinfo items of the LC_MONETARY category. */
257 TODO: Really use the locale. */
258 case CRNCYSTR: 529 case CRNCYSTR:
259 return "-"; 530 return localeconv () ->currency_symbol;
531# ifdef INT_CURR_SYMBOL
532 case INT_CURR_SYMBOL:
533 return localeconv () ->int_curr_symbol;
534 case MON_DECIMAL_POINT:
535 return localeconv () ->mon_decimal_point;
536 case MON_THOUSANDS_SEP:
537 return localeconv () ->mon_thousands_sep;
538 case MON_GROUPING:
539 return localeconv () ->mon_grouping;
540 case POSITIVE_SIGN:
541 return localeconv () ->positive_sign;
542 case NEGATIVE_SIGN:
543 return localeconv () ->negative_sign;
544 case FRAC_DIGITS:
545 return & localeconv () ->frac_digits;
546 case INT_FRAC_DIGITS:
547 return & localeconv () ->int_frac_digits;
548 case P_CS_PRECEDES:
549 return & localeconv () ->p_cs_precedes;
550 case N_CS_PRECEDES:
551 return & localeconv () ->n_cs_precedes;
552 case P_SEP_BY_SPACE:
553 return & localeconv () ->p_sep_by_space;
554 case N_SEP_BY_SPACE:
555 return & localeconv () ->n_sep_by_space;
556 case P_SIGN_POSN:
557 return & localeconv () ->p_sign_posn;
558 case N_SIGN_POSN:
559 return & localeconv () ->n_sign_posn;
560# endif
260 /* nl_langinfo items of the LC_MESSAGES category 561 /* nl_langinfo items of the LC_MESSAGES category
261 TODO: Really use the locale. */ 562 TODO: Really use the locale. */
262 case YESEXPR: 563 case YESEXPR:
263 return "^[yY]"; 564 return (char *) "^[yY]";
264 case NOEXPR: 565 case NOEXPR:
265 return "^[nN]"; 566 return (char *) "^[nN]";
266 default: 567 default:
267 return ""; 568 return (char *) "";
268 } 569 }
269} 570}
270 571
diff --git a/gl/open.c b/gl/open.c
new file mode 100644
index 0000000..7ec8fdc
--- /dev/null
+++ b/gl/open.c
@@ -0,0 +1,209 @@
1/* Open a descriptor to a file.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
18
19/* If the user's config.h happens to include <fcntl.h>, let it include only
20 the system's <fcntl.h> here, so that orig_open doesn't recurse to
21 rpl_open. */
22#define __need_system_fcntl_h
23#include <config.h>
24
25/* Get the original definition of open. It might be defined as a macro. */
26#include <fcntl.h>
27#include <sys/types.h>
28#undef __need_system_fcntl_h
29
30static int
31orig_open (const char *filename, int flags, mode_t mode)
32{
33#if defined _WIN32 && !defined __CYGWIN__
34 return _open (filename, flags, mode);
35#else
36 return open (filename, flags, mode);
37#endif
38}
39
40/* Specification. */
41/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates
42 this include because of the preliminary #include <fcntl.h> above. */
43#include "fcntl.h"
44
45#include "cloexec.h"
46
47#include <errno.h>
48#include <stdarg.h>
49#include <string.h>
50#include <sys/types.h>
51#include <sys/stat.h>
52#include <unistd.h>
53
54#ifndef REPLACE_OPEN_DIRECTORY
55# define REPLACE_OPEN_DIRECTORY 0
56#endif
57
58int
59open (const char *filename, int flags, ...)
60{
61 /* 0 = unknown, 1 = yes, -1 = no. */
62#if GNULIB_defined_O_CLOEXEC
63 int have_cloexec = -1;
64#else
65 static int have_cloexec;
66#endif
67
68 mode_t mode;
69 int fd;
70
71 mode = 0;
72 if (flags & O_CREAT)
73 {
74 va_list arg;
75 va_start (arg, flags);
76
77 /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
78 creates crashing code when 'mode_t' is smaller than 'int'. */
79 mode = va_arg (arg, PROMOTED_MODE_T);
80
81 va_end (arg);
82 }
83
84#if GNULIB_defined_O_NONBLOCK
85 /* The only known platform that lacks O_NONBLOCK is mingw, but it
86 also lacks named pipes and Unix sockets, which are the only two
87 file types that require non-blocking handling in open().
88 Therefore, it is safe to ignore O_NONBLOCK here. It is handy
89 that mingw also lacks openat(), so that is also covered here. */
90 flags &= ~O_NONBLOCK;
91#endif
92
93#if defined _WIN32 && ! defined __CYGWIN__
94 if (strcmp (filename, "/dev/null") == 0)
95 filename = "NUL";
96#endif
97
98#if OPEN_TRAILING_SLASH_BUG
99 /* Fail if one of O_CREAT, O_WRONLY, O_RDWR is specified and the filename
100 ends in a slash, as POSIX says such a filename must name a directory
101 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
102 "A pathname that contains at least one non-<slash> character and that
103 ends with one or more trailing <slash> characters shall not be resolved
104 successfully unless the last pathname component before the trailing
105 <slash> characters names an existing directory"
106 If the named file already exists as a directory, then
107 - if O_CREAT is specified, open() must fail because of the semantics
108 of O_CREAT,
109 - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
110 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html>
111 says that it fails with errno = EISDIR in this case.
112 If the named file does not exist or does not name a directory, then
113 - if O_CREAT is specified, open() must fail since open() cannot create
114 directories,
115 - if O_WRONLY or O_RDWR is specified, open() must fail because the
116 file does not contain a '.' directory. */
117 if ((flags & O_CREAT)
118 || (flags & O_ACCMODE) == O_RDWR
119 || (flags & O_ACCMODE) == O_WRONLY)
120 {
121 size_t len = strlen (filename);
122 if (len > 0 && filename[len - 1] == '/')
123 {
124 errno = EISDIR;
125 return -1;
126 }
127 }
128#endif
129
130 fd = orig_open (filename,
131 flags & ~(have_cloexec < 0 ? O_CLOEXEC : 0), mode);
132
133 if (flags & O_CLOEXEC)
134 {
135 if (! have_cloexec)
136 {
137 if (0 <= fd)
138 have_cloexec = 1;
139 else if (errno == EINVAL)
140 {
141 fd = orig_open (filename, flags & ~O_CLOEXEC, mode);
142 have_cloexec = -1;
143 }
144 }
145 if (have_cloexec < 0 && 0 <= fd)
146 set_cloexec_flag (fd, true);
147 }
148
149
150#if REPLACE_FCHDIR
151 /* Implementing fchdir and fdopendir requires the ability to open a
152 directory file descriptor. If open doesn't support that (as on
153 mingw), we use a dummy file that behaves the same as directories
154 on Linux (ie. always reports EOF on attempts to read()), and
155 override fstat() in fchdir.c to hide the fact that we have a
156 dummy. */
157 if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
158 && ((flags & O_ACCMODE) == O_RDONLY
159 || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
160 {
161 struct stat statbuf;
162 if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
163 {
164 /* Maximum recursion depth of 1. */
165 fd = open ("/dev/null", flags, mode);
166 if (0 <= fd)
167 fd = _gl_register_fd (fd, filename);
168 }
169 else
170 errno = EACCES;
171 }
172#endif
173
174#if OPEN_TRAILING_SLASH_BUG
175 /* If the filename ends in a slash and fd does not refer to a directory,
176 then fail.
177 Rationale: POSIX says such a filename must name a directory
178 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
179 "A pathname that contains at least one non-<slash> character and that
180 ends with one or more trailing <slash> characters shall not be resolved
181 successfully unless the last pathname component before the trailing
182 <slash> characters names an existing directory"
183 If the named file without the slash is not a directory, open() must fail
184 with ENOTDIR. */
185 if (fd >= 0)
186 {
187 /* We know len is positive, since open did not fail with ENOENT. */
188 size_t len = strlen (filename);
189 if (filename[len - 1] == '/')
190 {
191 struct stat statbuf;
192
193 if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
194 {
195 close (fd);
196 errno = ENOTDIR;
197 return -1;
198 }
199 }
200 }
201#endif
202
203#if REPLACE_FCHDIR
204 if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
205 fd = _gl_register_fd (fd, filename);
206#endif
207
208 return fd;
209}
diff --git a/gl/pathmax.h b/gl/pathmax.h
new file mode 100644
index 0000000..0dd8f3b
--- /dev/null
+++ b/gl/pathmax.h
@@ -0,0 +1,83 @@
1/* Define PATH_MAX somehow. Requires sys/types.h.
2 Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2023 Free Software
3 Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _PATHMAX_H
19# define _PATHMAX_H
20
21/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
22 including the terminating NUL byte.
23 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
24 PATH_MAX is not defined on systems which have no limit on filename length,
25 such as GNU/Hurd.
26
27 This file does *not* define PATH_MAX always. Programs that use this file
28 can handle the GNU/Hurd case in several ways:
29 - Either with a package-wide handling, or with a per-file handling,
30 - Either through a
31 #ifdef PATH_MAX
32 or through a fallback like
33 #ifndef PATH_MAX
34 # define PATH_MAX 8192
35 #endif
36 or through a fallback like
37 #ifndef PATH_MAX
38 # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
39 #endif
40 */
41
42# include <unistd.h>
43
44# include <limits.h>
45
46# ifndef _POSIX_PATH_MAX
47# define _POSIX_PATH_MAX 256
48# endif
49
50/* Don't include sys/param.h if it already has been. */
51# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
52# include <sys/param.h>
53# endif
54
55# if !defined PATH_MAX && defined MAXPATHLEN
56# define PATH_MAX MAXPATHLEN
57# endif
58
59# ifdef __hpux
60/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
61 *not* including the terminating NUL byte, and is set to 1023.
62 Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
63 not defined at all any more. */
64# undef PATH_MAX
65# define PATH_MAX 1024
66# endif
67
68# if defined _WIN32 && ! defined __CYGWIN__
69/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
70 section "Maximum Path Length Limitation",
71 <https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation>
72 explains that the maximum size of a filename, including the terminating
73 NUL byte, is 260 = 3 + 256 + 1.
74 This is the same value as
75 - FILENAME_MAX in <stdio.h>,
76 - _MAX_PATH in <stdlib.h>,
77 - MAX_PATH in <windef.h>.
78 Undefine the original value, because mingw's <limits.h> gets it wrong. */
79# undef PATH_MAX
80# define PATH_MAX 260
81# endif
82
83#endif /* _PATHMAX_H */
diff --git a/gl/printf-args.c b/gl/printf-args.c
index c27e6bc..5e14f65 100644
--- a/gl/printf-args.c
+++ b/gl/printf-args.c
@@ -1,19 +1,19 @@
1/* Decomposed printf argument list. 1/* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2013 Free Software 2 Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2023 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* This file can be parametrized with the following macros: 18/* This file can be parametrized with the following macros:
19 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. 19 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
@@ -65,14 +65,12 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
65 case TYPE_ULONGINT: 65 case TYPE_ULONGINT:
66 ap->a.a_ulongint = va_arg (args, unsigned long int); 66 ap->a.a_ulongint = va_arg (args, unsigned long int);
67 break; 67 break;
68#if HAVE_LONG_LONG_INT
69 case TYPE_LONGLONGINT: 68 case TYPE_LONGLONGINT:
70 ap->a.a_longlongint = va_arg (args, long long int); 69 ap->a.a_longlongint = va_arg (args, long long int);
71 break; 70 break;
72 case TYPE_ULONGLONGINT: 71 case TYPE_ULONGLONGINT:
73 ap->a.a_ulonglongint = va_arg (args, unsigned long long int); 72 ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
74 break; 73 break;
75#endif
76 case TYPE_DOUBLE: 74 case TYPE_DOUBLE:
77 ap->a.a_double = va_arg (args, double); 75 ap->a.a_double = va_arg (args, double);
78 break; 76 break;
@@ -135,11 +133,9 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
135 case TYPE_COUNT_LONGINT_POINTER: 133 case TYPE_COUNT_LONGINT_POINTER:
136 ap->a.a_count_longint_pointer = va_arg (args, long int *); 134 ap->a.a_count_longint_pointer = va_arg (args, long int *);
137 break; 135 break;
138#if HAVE_LONG_LONG_INT
139 case TYPE_COUNT_LONGLONGINT_POINTER: 136 case TYPE_COUNT_LONGLONGINT_POINTER:
140 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); 137 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
141 break; 138 break;
142#endif
143#if ENABLE_UNISTDIO 139#if ENABLE_UNISTDIO
144 /* The unistdio extensions. */ 140 /* The unistdio extensions. */
145 case TYPE_U8_STRING: 141 case TYPE_U8_STRING:
diff --git a/gl/printf-args.h b/gl/printf-args.h
index 2a9c2a3..f303cb1 100644
--- a/gl/printf-args.h
+++ b/gl/printf-args.h
@@ -1,19 +1,19 @@
1/* Decomposed printf argument list. 1/* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2013 Free Software 2 Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2023 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _PRINTF_ARGS_H 18#ifndef _PRINTF_ARGS_H
19#define _PRINTF_ARGS_H 19#define _PRINTF_ARGS_H
@@ -57,10 +57,8 @@ typedef enum
57 TYPE_UINT, 57 TYPE_UINT,
58 TYPE_LONGINT, 58 TYPE_LONGINT,
59 TYPE_ULONGINT, 59 TYPE_ULONGINT,
60#if HAVE_LONG_LONG_INT
61 TYPE_LONGLONGINT, 60 TYPE_LONGLONGINT,
62 TYPE_ULONGLONGINT, 61 TYPE_ULONGLONGINT,
63#endif
64 TYPE_DOUBLE, 62 TYPE_DOUBLE,
65 TYPE_LONGDOUBLE, 63 TYPE_LONGDOUBLE,
66 TYPE_CHAR, 64 TYPE_CHAR,
@@ -75,10 +73,8 @@ typedef enum
75 TYPE_COUNT_SCHAR_POINTER, 73 TYPE_COUNT_SCHAR_POINTER,
76 TYPE_COUNT_SHORT_POINTER, 74 TYPE_COUNT_SHORT_POINTER,
77 TYPE_COUNT_INT_POINTER, 75 TYPE_COUNT_INT_POINTER,
78 TYPE_COUNT_LONGINT_POINTER 76 TYPE_COUNT_LONGINT_POINTER,
79#if HAVE_LONG_LONG_INT 77 TYPE_COUNT_LONGLONGINT_POINTER
80, TYPE_COUNT_LONGLONGINT_POINTER
81#endif
82#if ENABLE_UNISTDIO 78#if ENABLE_UNISTDIO
83 /* The unistdio extensions. */ 79 /* The unistdio extensions. */
84, TYPE_U8_STRING 80, TYPE_U8_STRING
@@ -101,10 +97,8 @@ typedef struct
101 unsigned int a_uint; 97 unsigned int a_uint;
102 long int a_longint; 98 long int a_longint;
103 unsigned long int a_ulongint; 99 unsigned long int a_ulongint;
104#if HAVE_LONG_LONG_INT
105 long long int a_longlongint; 100 long long int a_longlongint;
106 unsigned long long int a_ulonglongint; 101 unsigned long long int a_ulonglongint;
107#endif
108 float a_float; 102 float a_float;
109 double a_double; 103 double a_double;
110 long double a_longdouble; 104 long double a_longdouble;
@@ -121,9 +115,7 @@ typedef struct
121 short * a_count_short_pointer; 115 short * a_count_short_pointer;
122 int * a_count_int_pointer; 116 int * a_count_int_pointer;
123 long int * a_count_longint_pointer; 117 long int * a_count_longint_pointer;
124#if HAVE_LONG_LONG_INT
125 long long int * a_count_longlongint_pointer; 118 long long int * a_count_longlongint_pointer;
126#endif
127#if ENABLE_UNISTDIO 119#if ENABLE_UNISTDIO
128 /* The unistdio extensions. */ 120 /* The unistdio extensions. */
129 const uint8_t * a_u8_string; 121 const uint8_t * a_u8_string;
diff --git a/gl/printf-parse.c b/gl/printf-parse.c
index 23cacc1..3040749 100644
--- a/gl/printf-parse.c
+++ b/gl/printf-parse.c
@@ -1,18 +1,18 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999-2000, 2002-2003, 2006-2013 Free Software Foundation, Inc. 2 Copyright (C) 1999-2000, 2002-2003, 2006-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* This file can be parametrized with the following macros: 17/* This file can be parametrized with the following macros:
18 CHAR_T The element type of the format string. 18 CHAR_T The element type of the format string.
@@ -48,16 +48,7 @@
48#include <stddef.h> 48#include <stddef.h>
49 49
50/* Get intmax_t. */ 50/* Get intmax_t. */
51#if defined IN_LIBINTL || defined IN_LIBASPRINTF 51#include <stdint.h>
52# if HAVE_STDINT_H_WITH_UINTMAX
53# include <stdint.h>
54# endif
55# if HAVE_INTTYPES_H_WITH_UINTMAX
56# include <inttypes.h>
57# endif
58#else
59# include <stdint.h>
60#endif
61 52
62/* malloc(), realloc(), free(). */ 53/* malloc(), realloc(), free(). */
63#include <stdlib.h> 54#include <stdlib.h>
@@ -419,7 +410,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
419 cp++; 410 cp++;
420 } 411 }
421#endif 412#endif
422#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 413#if defined _WIN32 && ! defined __CYGWIN__
423 /* On native Windows, PRIdMAX is defined as "I64d". 414 /* On native Windows, PRIdMAX is defined as "I64d".
424 We cannot change it to "lld" because PRIdMAX must also 415 We cannot change it to "lld" because PRIdMAX must also
425 be understood by the system's printf routines. */ 416 be understood by the system's printf routines. */
@@ -447,14 +438,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
447 switch (c) 438 switch (c)
448 { 439 {
449 case 'd': case 'i': 440 case 'd': case 'i':
450#if HAVE_LONG_LONG_INT 441 /* If 'long long' is larger than 'long': */
451 /* If 'long long' exists and is larger than 'long': */
452 if (flags >= 16 || (flags & 4)) 442 if (flags >= 16 || (flags & 4))
453 type = TYPE_LONGLONGINT; 443 type = TYPE_LONGLONGINT;
454 else 444 else
455#endif 445 /* If 'long long' is the same as 'long', we parse "lld" into
456 /* If 'long long' exists and is the same as 'long', we parse 446 TYPE_LONGINT. */
457 "lld" into TYPE_LONGINT. */
458 if (flags >= 8) 447 if (flags >= 8)
459 type = TYPE_LONGINT; 448 type = TYPE_LONGINT;
460 else if (flags & 2) 449 else if (flags & 2)
@@ -465,14 +454,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
465 type = TYPE_INT; 454 type = TYPE_INT;
466 break; 455 break;
467 case 'o': case 'u': case 'x': case 'X': 456 case 'o': case 'u': case 'x': case 'X':
468#if HAVE_LONG_LONG_INT 457 /* If 'unsigned long long' is larger than 'unsigned long': */
469 /* If 'long long' exists and is larger than 'long': */
470 if (flags >= 16 || (flags & 4)) 458 if (flags >= 16 || (flags & 4))
471 type = TYPE_ULONGLONGINT; 459 type = TYPE_ULONGLONGINT;
472 else 460 else
473#endif 461 /* If 'unsigned long long' is the same as 'unsigned long', we
474 /* If 'unsigned long long' exists and is the same as 462 parse "llu" into TYPE_ULONGINT. */
475 'unsigned long', we parse "llu" into TYPE_ULONGINT. */
476 if (flags >= 8) 463 if (flags >= 8)
477 type = TYPE_ULONGINT; 464 type = TYPE_ULONGINT;
478 else if (flags & 2) 465 else if (flags & 2)
@@ -525,14 +512,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
525 type = TYPE_POINTER; 512 type = TYPE_POINTER;
526 break; 513 break;
527 case 'n': 514 case 'n':
528#if HAVE_LONG_LONG_INT 515 /* If 'long long' is larger than 'long': */
529 /* If 'long long' exists and is larger than 'long': */
530 if (flags >= 16 || (flags & 4)) 516 if (flags >= 16 || (flags & 4))
531 type = TYPE_COUNT_LONGLONGINT_POINTER; 517 type = TYPE_COUNT_LONGLONGINT_POINTER;
532 else 518 else
533#endif 519 /* If 'long long' is the same as 'long', we parse "lln" into
534 /* If 'long long' exists and is the same as 'long', we parse 520 TYPE_COUNT_LONGINT_POINTER. */
535 "lln" into TYPE_COUNT_LONGINT_POINTER. */
536 if (flags >= 8) 521 if (flags >= 8)
537 type = TYPE_COUNT_LONGINT_POINTER; 522 type = TYPE_COUNT_LONGINT_POINTER;
538 else if (flags & 2) 523 else if (flags & 2)
diff --git a/gl/printf-parse.h b/gl/printf-parse.h
index d8474be..1f86e32 100644
--- a/gl/printf-parse.h
+++ b/gl/printf-parse.h
@@ -1,19 +1,19 @@
1/* Parse printf format string. 1/* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2013 Free Software 2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2023 Free Software
3 Foundation, Inc. 3 Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _PRINTF_PARSE_H 18#ifndef _PRINTF_PARSE_H
19#define _PRINTF_PARSE_H 19#define _PRINTF_PARSE_H
diff --git a/gl/read.c b/gl/read.c
deleted file mode 100644
index 0fe0306..0000000
--- a/gl/read.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/* POSIX compatible read() function.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#include <unistd.h>
22
23#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
24
25# include <errno.h>
26# include <io.h>
27
28# define WIN32_LEAN_AND_MEAN /* avoid including junk */
29# include <windows.h>
30
31# include "msvc-inval.h"
32# include "msvc-nothrow.h"
33
34# undef read
35
36# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
37static ssize_t
38read_nothrow (int fd, void *buf, size_t count)
39{
40 ssize_t result;
41
42 TRY_MSVC_INVAL
43 {
44 result = read (fd, buf, count);
45 }
46 CATCH_MSVC_INVAL
47 {
48 result = -1;
49 errno = EBADF;
50 }
51 DONE_MSVC_INVAL;
52
53 return result;
54}
55# else
56# define read_nothrow read
57# endif
58
59ssize_t
60rpl_read (int fd, void *buf, size_t count)
61{
62 ssize_t ret = read_nothrow (fd, buf, count);
63
64# if GNULIB_NONBLOCKING
65 if (ret < 0
66 && GetLastError () == ERROR_NO_DATA)
67 {
68 HANDLE h = (HANDLE) _get_osfhandle (fd);
69 if (GetFileType (h) == FILE_TYPE_PIPE)
70 {
71 /* h is a pipe or socket. */
72 DWORD state;
73 if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0)
74 && (state & PIPE_NOWAIT) != 0)
75 /* h is a pipe in non-blocking mode.
76 Change errno from EINVAL to EAGAIN. */
77 errno = EAGAIN;
78 }
79 }
80# endif
81
82 return ret;
83}
84
85#endif
diff --git a/gl/realloc.c b/gl/realloc.c
new file mode 100644
index 0000000..1063eb0
--- /dev/null
+++ b/gl/realloc.c
@@ -0,0 +1,63 @@
1/* realloc() function that is glibc compatible.
2
3 Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2023 Free Software
4 Foundation, Inc.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file 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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19/* written by Jim Meyering and Bruno Haible */
20
21#include <config.h>
22
23#include <stdlib.h>
24
25#include <errno.h>
26
27#include "xalloc-oversized.h"
28
29/* Call the system's realloc below. This file does not define
30 _GL_USE_STDLIB_ALLOC because it needs Gnulib's malloc if present. */
31#undef realloc
32
33/* Change the size of an allocated block of memory P to N bytes,
34 with error checking. If P is NULL, use malloc. Otherwise if N is zero,
35 free P and return NULL. */
36
37void *
38rpl_realloc (void *p, size_t n)
39{
40 if (p == NULL)
41 return malloc (n);
42
43 if (n == 0)
44 {
45 free (p);
46 return NULL;
47 }
48
49 if (xalloc_oversized (n, 1))
50 {
51 errno = ENOMEM;
52 return NULL;
53 }
54
55 void *result = realloc (p, n);
56
57#if !HAVE_MALLOC_POSIX
58 if (result == NULL)
59 errno = ENOMEM;
60#endif
61
62 return result;
63}
diff --git a/gl/reallocarray.c b/gl/reallocarray.c
new file mode 100644
index 0000000..8c99250
--- /dev/null
+++ b/gl/reallocarray.c
@@ -0,0 +1,38 @@
1/* reallocarray function that is glibc compatible.
2
3 Copyright (C) 2017-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* written by Darshit Shah */
19
20#include <config.h>
21
22#include <stdckdint.h>
23#include <stdlib.h>
24#include <errno.h>
25
26void *
27reallocarray (void *ptr, size_t nmemb, size_t size)
28{
29 size_t nbytes;
30 if (ckd_mul (&nbytes, nmemb, size))
31 {
32 errno = ENOMEM;
33 return NULL;
34 }
35
36 /* Rely on the semantics of GNU realloc. */
37 return realloc (ptr, nbytes);
38}
diff --git a/gl/ref-add.sin b/gl/ref-add.sin
deleted file mode 100644
index 112bcdc64..0000000
--- a/gl/ref-add.sin
+++ /dev/null
@@ -1,29 +0,0 @@
1# Add this package to a list of references stored in a text file.
2#
3# Copyright (C) 2000, 2009-2013 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, see <http://www.gnu.org/licenses/>.
17#
18# Written by Bruno Haible <haible@clisp.cons.org>.
19#
20/^# Packages using this file: / {
21 s/# Packages using this file://
22 ta
23 :a
24 s/ @PACKAGE@ / @PACKAGE@ /
25 tb
26 s/ $/ @PACKAGE@ /
27 :b
28 s/^/# Packages using this file:/
29}
diff --git a/gl/ref-del.sin b/gl/ref-del.sin
deleted file mode 100644
index 6f73868..0000000
--- a/gl/ref-del.sin
+++ /dev/null
@@ -1,24 +0,0 @@
1# Remove this package from a list of references stored in a text file.
2#
3# Copyright (C) 2000, 2009-2013 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, see <http://www.gnu.org/licenses/>.
17#
18# Written by Bruno Haible <haible@clisp.cons.org>.
19#
20/^# Packages using this file: / {
21 s/# Packages using this file://
22 s/ @PACKAGE@ / /
23 s/^/# Packages using this file:/
24}
diff --git a/gl/regcomp.c b/gl/regcomp.c
index f0b2e52..8947839 100644
--- a/gl/regcomp.c
+++ b/gl/regcomp.c
@@ -1,21 +1,25 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc. 2 Copyright (C) 2002-2023 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 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
19
20#ifdef _LIBC
21# include <locale/weight.h>
22#endif
19 23
20static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, 24static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
21 size_t length, reg_syntax_t syntax); 25 size_t length, reg_syntax_t syntax);
@@ -23,14 +27,10 @@ static void re_compile_fastmap_iter (regex_t *bufp,
23 const re_dfastate_t *init_state, 27 const re_dfastate_t *init_state,
24 char *fastmap); 28 char *fastmap);
25static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len); 29static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
26#ifdef RE_ENABLE_I18N
27static void free_charset (re_charset_t *cset); 30static void free_charset (re_charset_t *cset);
28#endif /* RE_ENABLE_I18N */
29static void free_workarea_compile (regex_t *preg); 31static void free_workarea_compile (regex_t *preg);
30static reg_errcode_t create_initial_state (re_dfa_t *dfa); 32static reg_errcode_t create_initial_state (re_dfa_t *dfa);
31#ifdef RE_ENABLE_I18N
32static void optimize_utf8 (re_dfa_t *dfa); 33static void optimize_utf8 (re_dfa_t *dfa);
33#endif
34static reg_errcode_t analyze (regex_t *preg); 34static reg_errcode_t analyze (regex_t *preg);
35static reg_errcode_t preorder (bin_tree_t *root, 35static reg_errcode_t preorder (bin_tree_t *root,
36 reg_errcode_t (fn (void *, bin_tree_t *)), 36 reg_errcode_t (fn (void *, bin_tree_t *)),
@@ -55,7 +55,7 @@ static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
55static Idx fetch_number (re_string_t *input, re_token_t *token, 55static Idx fetch_number (re_string_t *input, re_token_t *token,
56 reg_syntax_t syntax); 56 reg_syntax_t syntax);
57static int peek_token (re_token_t *token, re_string_t *input, 57static int peek_token (re_token_t *token, re_string_t *input,
58 reg_syntax_t syntax) internal_function; 58 reg_syntax_t syntax);
59static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, 59static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
60 reg_syntax_t syntax, reg_errcode_t *err); 60 reg_syntax_t syntax, reg_errcode_t *err);
61static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg, 61static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
@@ -85,7 +85,6 @@ static reg_errcode_t parse_bracket_element (bracket_elem_t *elem,
85static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem, 85static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
86 re_string_t *regexp, 86 re_string_t *regexp,
87 re_token_t *token); 87 re_token_t *token);
88#ifdef RE_ENABLE_I18N
89static reg_errcode_t build_equiv_class (bitset_t sbcset, 88static reg_errcode_t build_equiv_class (bitset_t sbcset,
90 re_charset_t *mbcset, 89 re_charset_t *mbcset,
91 Idx *equiv_class_alloc, 90 Idx *equiv_class_alloc,
@@ -96,14 +95,6 @@ static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
96 Idx *char_class_alloc, 95 Idx *char_class_alloc,
97 const char *class_name, 96 const char *class_name,
98 reg_syntax_t syntax); 97 reg_syntax_t syntax);
99#else /* not RE_ENABLE_I18N */
100static reg_errcode_t build_equiv_class (bitset_t sbcset,
101 const unsigned char *name);
102static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
103 bitset_t sbcset,
104 const char *class_name,
105 reg_syntax_t syntax);
106#endif /* not RE_ENABLE_I18N */
107static bin_tree_t *build_charclass_op (re_dfa_t *dfa, 98static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
108 RE_TRANSLATE_TYPE trans, 99 RE_TRANSLATE_TYPE trans,
109 const char *class_name, 100 const char *class_name,
@@ -149,9 +140,9 @@ static const char __re_error_msgid[] =
149 gettext_noop ("Invalid back reference") /* REG_ESUBREG */ 140 gettext_noop ("Invalid back reference") /* REG_ESUBREG */
150 "\0" 141 "\0"
151#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference") 142#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference")
152 gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */ 143 gettext_noop ("Unmatched [, [^, [:, [., or [=") /* REG_EBRACK */
153 "\0" 144 "\0"
154#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^") 145#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [, [^, [:, [., or [=")
155 gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */ 146 gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */
156 "\0" 147 "\0"
157#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(") 148#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
@@ -209,17 +200,9 @@ static const size_t __re_error_msgid_idx[] =
209 Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields 200 Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields
210 are set in BUFP on entry. */ 201 are set in BUFP on entry. */
211 202
212#ifdef _LIBC
213const char *
214re_compile_pattern (pattern, length, bufp)
215 const char *pattern;
216 size_t length;
217 struct re_pattern_buffer *bufp;
218#else /* size_t might promote */
219const char * 203const char *
220re_compile_pattern (const char *pattern, size_t length, 204re_compile_pattern (const char *pattern, size_t length,
221 struct re_pattern_buffer *bufp) 205 struct re_pattern_buffer *bufp)
222#endif
223{ 206{
224 reg_errcode_t ret; 207 reg_errcode_t ret;
225 208
@@ -237,9 +220,7 @@ re_compile_pattern (const char *pattern, size_t length,
237 return NULL; 220 return NULL;
238 return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]); 221 return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
239} 222}
240#ifdef _LIBC
241weak_alias (__re_compile_pattern, re_compile_pattern) 223weak_alias (__re_compile_pattern, re_compile_pattern)
242#endif
243 224
244/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can 225/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can
245 also be assigned to arbitrarily: each pattern buffer stores its own 226 also be assigned to arbitrarily: each pattern buffer stores its own
@@ -257,21 +238,17 @@ reg_syntax_t re_syntax_options;
257 defined in regex.h. We return the old syntax. */ 238 defined in regex.h. We return the old syntax. */
258 239
259reg_syntax_t 240reg_syntax_t
260re_set_syntax (syntax) 241re_set_syntax (reg_syntax_t syntax)
261 reg_syntax_t syntax;
262{ 242{
263 reg_syntax_t ret = re_syntax_options; 243 reg_syntax_t ret = re_syntax_options;
264 244
265 re_syntax_options = syntax; 245 re_syntax_options = syntax;
266 return ret; 246 return ret;
267} 247}
268#ifdef _LIBC
269weak_alias (__re_set_syntax, re_set_syntax) 248weak_alias (__re_set_syntax, re_set_syntax)
270#endif
271 249
272int 250int
273re_compile_fastmap (bufp) 251re_compile_fastmap (struct re_pattern_buffer *bufp)
274 struct re_pattern_buffer *bufp;
275{ 252{
276 re_dfa_t *dfa = bufp->buffer; 253 re_dfa_t *dfa = bufp->buffer;
277 char *fastmap = bufp->fastmap; 254 char *fastmap = bufp->fastmap;
@@ -287,12 +264,9 @@ re_compile_fastmap (bufp)
287 bufp->fastmap_accurate = 1; 264 bufp->fastmap_accurate = 1;
288 return 0; 265 return 0;
289} 266}
290#ifdef _LIBC
291weak_alias (__re_compile_fastmap, re_compile_fastmap) 267weak_alias (__re_compile_fastmap, re_compile_fastmap)
292#endif
293 268
294static inline void 269static __always_inline void
295__attribute__ ((always_inline))
296re_set_fastmap (char *fastmap, bool icase, int ch) 270re_set_fastmap (char *fastmap, bool icase, int ch)
297{ 271{
298 fastmap[ch] = 1; 272 fastmap[ch] = 1;
@@ -318,7 +292,6 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
318 if (type == CHARACTER) 292 if (type == CHARACTER)
319 { 293 {
320 re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c); 294 re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
321#ifdef RE_ENABLE_I18N
322 if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) 295 if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
323 { 296 {
324 unsigned char buf[MB_LEN_MAX]; 297 unsigned char buf[MB_LEN_MAX];
@@ -335,11 +308,10 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
335 memset (&state, '\0', sizeof (state)); 308 memset (&state, '\0', sizeof (state));
336 if (__mbrtowc (&wc, (const char *) buf, p - buf, 309 if (__mbrtowc (&wc, (const char *) buf, p - buf,
337 &state) == p - buf 310 &state) == p - buf
338 && (__wcrtomb ((char *) buf, towlower (wc), &state) 311 && (__wcrtomb ((char *) buf, __towlower (wc), &state)
339 != (size_t) -1)) 312 != (size_t) -1))
340 re_set_fastmap (fastmap, false, buf[0]); 313 re_set_fastmap (fastmap, false, buf[0]);
341 } 314 }
342#endif
343 } 315 }
344 else if (type == SIMPLE_BRACKET) 316 else if (type == SIMPLE_BRACKET)
345 { 317 {
@@ -353,13 +325,12 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
353 re_set_fastmap (fastmap, icase, ch); 325 re_set_fastmap (fastmap, icase, ch);
354 } 326 }
355 } 327 }
356#ifdef RE_ENABLE_I18N
357 else if (type == COMPLEX_BRACKET) 328 else if (type == COMPLEX_BRACKET)
358 { 329 {
359 re_charset_t *cset = dfa->nodes[node].opr.mbcset; 330 re_charset_t *cset = dfa->nodes[node].opr.mbcset;
360 Idx i; 331 Idx i;
361 332
362# ifdef _LIBC 333#ifdef _LIBC
363 /* See if we have to try all bytes which start multiple collation 334 /* See if we have to try all bytes which start multiple collation
364 elements. 335 elements.
365 e.g. In da_DK, we want to catch 'a' since "aa" is a valid 336 e.g. In da_DK, we want to catch 'a' since "aa" is a valid
@@ -375,7 +346,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
375 if (table[i] < 0) 346 if (table[i] < 0)
376 re_set_fastmap (fastmap, icase, i); 347 re_set_fastmap (fastmap, icase, i);
377 } 348 }
378# endif /* _LIBC */ 349#endif /* _LIBC */
379 350
380 /* See if we have to start the match at all multibyte characters, 351 /* See if we have to start the match at all multibyte characters,
381 i.e. where we would not find an invalid sequence. This only 352 i.e. where we would not find an invalid sequence. This only
@@ -383,9 +354,9 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
383 sets, the SIMPLE_BRACKET again suffices. */ 354 sets, the SIMPLE_BRACKET again suffices. */
384 if (dfa->mb_cur_max > 1 355 if (dfa->mb_cur_max > 1
385 && (cset->nchar_classes || cset->non_match || cset->nranges 356 && (cset->nchar_classes || cset->non_match || cset->nranges
386# ifdef _LIBC 357#ifdef _LIBC
387 || cset->nequiv_classes 358 || cset->nequiv_classes
388# endif /* _LIBC */ 359#endif /* _LIBC */
389 )) 360 ))
390 { 361 {
391 unsigned char c = 0; 362 unsigned char c = 0;
@@ -411,19 +382,14 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
411 re_set_fastmap (fastmap, icase, *(unsigned char *) buf); 382 re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
412 if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) 383 if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
413 { 384 {
414 if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) 385 if (__wcrtomb (buf, __towlower (cset->mbchars[i]), &state)
415 != (size_t) -1) 386 != (size_t) -1)
416 re_set_fastmap (fastmap, false, *(unsigned char *) buf); 387 re_set_fastmap (fastmap, false, *(unsigned char *) buf);
417 } 388 }
418 } 389 }
419 } 390 }
420 } 391 }
421#endif /* RE_ENABLE_I18N */ 392 else if (type == OP_PERIOD || type == OP_UTF8_PERIOD || type == END_OF_RE)
422 else if (type == OP_PERIOD
423#ifdef RE_ENABLE_I18N
424 || type == OP_UTF8_PERIOD
425#endif /* RE_ENABLE_I18N */
426 || type == END_OF_RE)
427 { 393 {
428 memset (fastmap, '\1', sizeof (char) * SBC_MAX); 394 memset (fastmap, '\1', sizeof (char) * SBC_MAX);
429 if (type == END_OF_RE) 395 if (type == END_OF_RE)
@@ -470,10 +436,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
470 the return codes and their meanings.) */ 436 the return codes and their meanings.) */
471 437
472int 438int
473regcomp (preg, pattern, cflags) 439regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
474 regex_t *_Restrict_ preg;
475 const char *_Restrict_ pattern;
476 int cflags;
477{ 440{
478 reg_errcode_t ret; 441 reg_errcode_t ret;
479 reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED 442 reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
@@ -485,7 +448,7 @@ regcomp (preg, pattern, cflags)
485 448
486 /* Try to allocate space for the fastmap. */ 449 /* Try to allocate space for the fastmap. */
487 preg->fastmap = re_malloc (char, SBC_MAX); 450 preg->fastmap = re_malloc (char, SBC_MAX);
488 if (BE (preg->fastmap == NULL, 0)) 451 if (__glibc_unlikely (preg->fastmap == NULL))
489 return REG_ESPACE; 452 return REG_ESPACE;
490 453
491 syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0; 454 syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
@@ -511,7 +474,7 @@ regcomp (preg, pattern, cflags)
511 ret = REG_EPAREN; 474 ret = REG_EPAREN;
512 475
513 /* We have already checked preg->fastmap != NULL. */ 476 /* We have already checked preg->fastmap != NULL. */
514 if (BE (ret == REG_NOERROR, 1)) 477 if (__glibc_likely (ret == REG_NOERROR))
515 /* Compute the fastmap now, since regexec cannot modify the pattern 478 /* Compute the fastmap now, since regexec cannot modify the pattern
516 buffer. This function never fails in this implementation. */ 479 buffer. This function never fails in this implementation. */
517 (void) re_compile_fastmap (preg); 480 (void) re_compile_fastmap (preg);
@@ -524,32 +487,21 @@ regcomp (preg, pattern, cflags)
524 487
525 return (int) ret; 488 return (int) ret;
526} 489}
527#ifdef _LIBC 490libc_hidden_def (__regcomp)
528weak_alias (__regcomp, regcomp) 491weak_alias (__regcomp, regcomp)
529#endif
530 492
531/* Returns a message corresponding to an error code, ERRCODE, returned 493/* Returns a message corresponding to an error code, ERRCODE, returned
532 from either regcomp or regexec. We don't use PREG here. */ 494 from either regcomp or regexec. We don't use PREG here. */
533 495
534#ifdef _LIBC
535size_t
536regerror (errcode, preg, errbuf, errbuf_size)
537 int errcode;
538 const regex_t *_Restrict_ preg;
539 char *_Restrict_ errbuf;
540 size_t errbuf_size;
541#else /* size_t might promote */
542size_t 496size_t
543regerror (int errcode, const regex_t *_Restrict_ preg, 497regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf,
544 char *_Restrict_ errbuf, size_t errbuf_size) 498 size_t errbuf_size)
545#endif
546{ 499{
547 const char *msg; 500 const char *msg;
548 size_t msg_size; 501 size_t msg_size;
502 int nerrcodes = sizeof __re_error_msgid_idx / sizeof __re_error_msgid_idx[0];
549 503
550 if (BE (errcode < 0 504 if (__glibc_unlikely (errcode < 0 || errcode >= nerrcodes))
551 || errcode >= (int) (sizeof (__re_error_msgid_idx)
552 / sizeof (__re_error_msgid_idx[0])), 0))
553 /* Only error codes returned by the rest of the code should be passed 505 /* Only error codes returned by the rest of the code should be passed
554 to this routine. If we are given anything else, or if other regex 506 to this routine. If we are given anything else, or if other regex
555 code generates an invalid error code, then the program has a bug. 507 code generates an invalid error code, then the program has a bug.
@@ -560,10 +512,10 @@ regerror (int errcode, const regex_t *_Restrict_ preg,
560 512
561 msg_size = strlen (msg) + 1; /* Includes the null. */ 513 msg_size = strlen (msg) + 1; /* Includes the null. */
562 514
563 if (BE (errbuf_size != 0, 1)) 515 if (__glibc_likely (errbuf_size != 0))
564 { 516 {
565 size_t cpy_size = msg_size; 517 size_t cpy_size = msg_size;
566 if (BE (msg_size > errbuf_size, 0)) 518 if (__glibc_unlikely (msg_size > errbuf_size))
567 { 519 {
568 cpy_size = errbuf_size - 1; 520 cpy_size = errbuf_size - 1;
569 errbuf[cpy_size] = '\0'; 521 errbuf[cpy_size] = '\0';
@@ -573,12 +525,9 @@ regerror (int errcode, const regex_t *_Restrict_ preg,
573 525
574 return msg_size; 526 return msg_size;
575} 527}
576#ifdef _LIBC
577weak_alias (__regerror, regerror) 528weak_alias (__regerror, regerror)
578#endif
579 529
580 530
581#ifdef RE_ENABLE_I18N
582/* This static array is used for the map to single-byte characters when 531/* This static array is used for the map to single-byte characters when
583 UTF-8 is used. Otherwise we would allocate memory just to initialize 532 UTF-8 is used. Otherwise we would allocate memory just to initialize
584 it the same all the time. UTF-8 is the preferred encoding so this is 533 it the same all the time. UTF-8 is the preferred encoding so this is
@@ -586,25 +535,24 @@ weak_alias (__regerror, regerror)
586static const bitset_t utf8_sb_map = 535static const bitset_t utf8_sb_map =
587{ 536{
588 /* Set the first 128 bits. */ 537 /* Set the first 128 bits. */
589# if defined __GNUC__ && !defined __STRICT_ANSI__ 538#if (defined __GNUC__ || __clang_major__ >= 4) && !defined __STRICT_ANSI__
590 [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX 539 [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
591# else 540#else
592# if 4 * BITSET_WORD_BITS < ASCII_CHARS 541# if 4 * BITSET_WORD_BITS < ASCII_CHARS
593# error "bitset_word_t is narrower than 32 bits" 542# error "bitset_word_t is narrower than 32 bits"
594# elif 3 * BITSET_WORD_BITS < ASCII_CHARS 543# elif 3 * BITSET_WORD_BITS < ASCII_CHARS
595 BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX, 544 BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
596# elif 2 * BITSET_WORD_BITS < ASCII_CHARS 545# elif 2 * BITSET_WORD_BITS < ASCII_CHARS
597 BITSET_WORD_MAX, BITSET_WORD_MAX, 546 BITSET_WORD_MAX, BITSET_WORD_MAX,
598# elif 1 * BITSET_WORD_BITS < ASCII_CHARS 547# elif 1 * BITSET_WORD_BITS < ASCII_CHARS
599 BITSET_WORD_MAX, 548 BITSET_WORD_MAX,
600# endif 549# endif
601 (BITSET_WORD_MAX 550 (BITSET_WORD_MAX
602 >> (SBC_MAX % BITSET_WORD_BITS == 0 551 >> (SBC_MAX % BITSET_WORD_BITS == 0
603 ? 0 552 ? 0
604 : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS)) 553 : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS))
605# endif
606};
607#endif 554#endif
555};
608 556
609 557
610static void 558static void
@@ -642,10 +590,8 @@ free_dfa_content (re_dfa_t *dfa)
642 re_free (entry->array); 590 re_free (entry->array);
643 } 591 }
644 re_free (dfa->state_table); 592 re_free (dfa->state_table);
645#ifdef RE_ENABLE_I18N
646 if (dfa->sb_char != utf8_sb_map) 593 if (dfa->sb_char != utf8_sb_map)
647 re_free (dfa->sb_char); 594 re_free (dfa->sb_char);
648#endif
649 re_free (dfa->subexp_map); 595 re_free (dfa->subexp_map);
650#ifdef DEBUG 596#ifdef DEBUG
651 re_free (dfa->re_str); 597 re_free (dfa->re_str);
@@ -658,11 +604,10 @@ free_dfa_content (re_dfa_t *dfa)
658/* Free dynamically allocated space used by PREG. */ 604/* Free dynamically allocated space used by PREG. */
659 605
660void 606void
661regfree (preg) 607regfree (regex_t *preg)
662 regex_t *preg;
663{ 608{
664 re_dfa_t *dfa = preg->buffer; 609 re_dfa_t *dfa = preg->buffer;
665 if (BE (dfa != NULL, 1)) 610 if (__glibc_likely (dfa != NULL))
666 { 611 {
667 lock_fini (dfa->lock); 612 lock_fini (dfa->lock);
668 free_dfa_content (dfa); 613 free_dfa_content (dfa);
@@ -676,9 +621,8 @@ regfree (preg)
676 re_free (preg->translate); 621 re_free (preg->translate);
677 preg->translate = NULL; 622 preg->translate = NULL;
678} 623}
679#ifdef _LIBC 624libc_hidden_def (__regfree)
680weak_alias (__regfree, regfree) 625weak_alias (__regfree, regfree)
681#endif
682 626
683/* Entry points compatible with 4.2 BSD regex library. We don't define 627/* Entry points compatible with 4.2 BSD regex library. We don't define
684 them unless specifically requested. */ 628 them unless specifically requested. */
@@ -695,8 +639,7 @@ char *
695 regcomp/regexec above without link errors. */ 639 regcomp/regexec above without link errors. */
696weak_function 640weak_function
697# endif 641# endif
698re_comp (s) 642re_comp (const char *s)
699 const char *s;
700{ 643{
701 reg_errcode_t ret; 644 reg_errcode_t ret;
702 char *fastmap; 645 char *fastmap;
@@ -719,7 +662,7 @@ re_comp (s)
719 662
720 if (re_comp_buf.fastmap == NULL) 663 if (re_comp_buf.fastmap == NULL)
721 { 664 {
722 re_comp_buf.fastmap = (char *) malloc (SBC_MAX); 665 re_comp_buf.fastmap = re_malloc (char, SBC_MAX);
723 if (re_comp_buf.fastmap == NULL) 666 if (re_comp_buf.fastmap == NULL)
724 return (char *) gettext (__re_error_msgid 667 return (char *) gettext (__re_error_msgid
725 + __re_error_msgid_idx[(int) REG_ESPACE]); 668 + __re_error_msgid_idx[(int) REG_ESPACE]);
@@ -772,7 +715,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
772 715
773 /* Initialize the dfa. */ 716 /* Initialize the dfa. */
774 dfa = preg->buffer; 717 dfa = preg->buffer;
775 if (BE (preg->allocated < sizeof (re_dfa_t), 0)) 718 if (__glibc_unlikely (preg->allocated < sizeof (re_dfa_t)))
776 { 719 {
777 /* If zero allocated, but buffer is non-null, try to realloc 720 /* If zero allocated, but buffer is non-null, try to realloc
778 enough space. This loses if buffer's address is bogus, but 721 enough space. This loses if buffer's address is bogus, but
@@ -787,9 +730,9 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
787 preg->used = sizeof (re_dfa_t); 730 preg->used = sizeof (re_dfa_t);
788 731
789 err = init_dfa (dfa, length); 732 err = init_dfa (dfa, length);
790 if (BE (err == REG_NOERROR && lock_init (dfa->lock) != 0, 0)) 733 if (__glibc_unlikely (err == REG_NOERROR && lock_init (dfa->lock) != 0))
791 err = REG_ESPACE; 734 err = REG_ESPACE;
792 if (BE (err != REG_NOERROR, 0)) 735 if (__glibc_unlikely (err != REG_NOERROR))
793 { 736 {
794 free_dfa_content (dfa); 737 free_dfa_content (dfa);
795 preg->buffer = NULL; 738 preg->buffer = NULL;
@@ -804,7 +747,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
804 747
805 err = re_string_construct (&regexp, pattern, length, preg->translate, 748 err = re_string_construct (&regexp, pattern, length, preg->translate,
806 (syntax & RE_ICASE) != 0, dfa); 749 (syntax & RE_ICASE) != 0, dfa);
807 if (BE (err != REG_NOERROR, 0)) 750 if (__glibc_unlikely (err != REG_NOERROR))
808 { 751 {
809 re_compile_internal_free_return: 752 re_compile_internal_free_return:
810 free_workarea_compile (preg); 753 free_workarea_compile (preg);
@@ -819,19 +762,17 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
819 /* Parse the regular expression, and build a structure tree. */ 762 /* Parse the regular expression, and build a structure tree. */
820 preg->re_nsub = 0; 763 preg->re_nsub = 0;
821 dfa->str_tree = parse (&regexp, preg, syntax, &err); 764 dfa->str_tree = parse (&regexp, preg, syntax, &err);
822 if (BE (dfa->str_tree == NULL, 0)) 765 if (__glibc_unlikely (dfa->str_tree == NULL))
823 goto re_compile_internal_free_return; 766 goto re_compile_internal_free_return;
824 767
825 /* Analyze the tree and create the nfa. */ 768 /* Analyze the tree and create the nfa. */
826 err = analyze (preg); 769 err = analyze (preg);
827 if (BE (err != REG_NOERROR, 0)) 770 if (__glibc_unlikely (err != REG_NOERROR))
828 goto re_compile_internal_free_return; 771 goto re_compile_internal_free_return;
829 772
830#ifdef RE_ENABLE_I18N
831 /* If possible, do searching in single byte encoding to speed things up. */ 773 /* If possible, do searching in single byte encoding to speed things up. */
832 if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL) 774 if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
833 optimize_utf8 (dfa); 775 optimize_utf8 (dfa);
834#endif
835 776
836 /* Then create the initial state of the dfa. */ 777 /* Then create the initial state of the dfa. */
837 err = create_initial_state (dfa); 778 err = create_initial_state (dfa);
@@ -840,7 +781,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
840 free_workarea_compile (preg); 781 free_workarea_compile (preg);
841 re_string_destruct (&regexp); 782 re_string_destruct (&regexp);
842 783
843 if (BE (err != REG_NOERROR, 0)) 784 if (__glibc_unlikely (err != REG_NOERROR))
844 { 785 {
845 lock_fini (dfa->lock); 786 lock_fini (dfa->lock);
846 free_dfa_content (dfa); 787 free_dfa_content (dfa);
@@ -861,11 +802,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
861#ifndef _LIBC 802#ifndef _LIBC
862 const char *codeset_name; 803 const char *codeset_name;
863#endif 804#endif
864#ifdef RE_ENABLE_I18N
865 size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t)); 805 size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
866#else
867 size_t max_i18n_object_size = 0;
868#endif
869 size_t max_object_size = 806 size_t max_object_size =
870 MAX (sizeof (struct re_state_table_entry), 807 MAX (sizeof (struct re_state_table_entry),
871 MAX (sizeof (re_token_t), 808 MAX (sizeof (re_token_t),
@@ -882,7 +819,8 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
882 calculation below, and for similar doubling calculations 819 calculation below, and for similar doubling calculations
883 elsewhere. And it's <= rather than <, because some of the 820 elsewhere. And it's <= rather than <, because some of the
884 doubling calculations add 1 afterwards. */ 821 doubling calculations add 1 afterwards. */
885 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2 <= pat_len, 0)) 822 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2
823 <= pat_len))
886 return REG_ESPACE; 824 return REG_ESPACE;
887 825
888 dfa->nodes_alloc = pat_len + 1; 826 dfa->nodes_alloc = pat_len + 1;
@@ -916,7 +854,6 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
916 dfa->map_notascii = 0; 854 dfa->map_notascii = 0;
917#endif 855#endif
918 856
919#ifdef RE_ENABLE_I18N
920 if (dfa->mb_cur_max > 1) 857 if (dfa->mb_cur_max > 1)
921 { 858 {
922 if (dfa->is_utf8) 859 if (dfa->is_utf8)
@@ -926,7 +863,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
926 int i, j, ch; 863 int i, j, ch;
927 864
928 dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 865 dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
929 if (BE (dfa->sb_char == NULL, 0)) 866 if (__glibc_unlikely (dfa->sb_char == NULL))
930 return REG_ESPACE; 867 return REG_ESPACE;
931 868
932 /* Set the bits corresponding to single byte chars. */ 869 /* Set the bits corresponding to single byte chars. */
@@ -936,16 +873,15 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
936 wint_t wch = __btowc (ch); 873 wint_t wch = __btowc (ch);
937 if (wch != WEOF) 874 if (wch != WEOF)
938 dfa->sb_char[i] |= (bitset_word_t) 1 << j; 875 dfa->sb_char[i] |= (bitset_word_t) 1 << j;
939# ifndef _LIBC 876#ifndef _LIBC
940 if (isascii (ch) && wch != ch) 877 if (isascii (ch) && wch != ch)
941 dfa->map_notascii = 1; 878 dfa->map_notascii = 1;
942# endif 879#endif
943 } 880 }
944 } 881 }
945 } 882 }
946#endif
947 883
948 if (BE (dfa->nodes == NULL || dfa->state_table == NULL, 0)) 884 if (__glibc_unlikely (dfa->nodes == NULL || dfa->state_table == NULL))
949 return REG_ESPACE; 885 return REG_ESPACE;
950 return REG_NOERROR; 886 return REG_NOERROR;
951} 887}
@@ -955,14 +891,13 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
955 character used by some operators like "\<", "\>", etc. */ 891 character used by some operators like "\<", "\>", etc. */
956 892
957static void 893static void
958internal_function
959init_word_char (re_dfa_t *dfa) 894init_word_char (re_dfa_t *dfa)
960{ 895{
961 int i = 0; 896 int i = 0;
962 int j; 897 int j;
963 int ch = 0; 898 int ch = 0;
964 dfa->word_ops_used = 1; 899 dfa->word_ops_used = 1;
965 if (BE (dfa->map_notascii == 0, 1)) 900 if (__glibc_likely (dfa->map_notascii == 0))
966 { 901 {
967 bitset_word_t bits0 = 0x00000000; 902 bitset_word_t bits0 = 0x00000000;
968 bitset_word_t bits1 = 0x03ff0000; 903 bitset_word_t bits1 = 0x03ff0000;
@@ -970,6 +905,7 @@ init_word_char (re_dfa_t *dfa)
970 bitset_word_t bits3 = 0x07fffffe; 905 bitset_word_t bits3 = 0x07fffffe;
971 if (BITSET_WORD_BITS == 64) 906 if (BITSET_WORD_BITS == 64)
972 { 907 {
908 /* Pacify gcc -Woverflow on 32-bit platformns. */
973 dfa->word_char[0] = bits1 << 31 << 1 | bits0; 909 dfa->word_char[0] = bits1 << 31 << 1 | bits0;
974 dfa->word_char[1] = bits3 << 31 << 1 | bits2; 910 dfa->word_char[1] = bits3 << 31 << 1 | bits2;
975 i = 2; 911 i = 2;
@@ -986,7 +922,7 @@ init_word_char (re_dfa_t *dfa)
986 goto general_case; 922 goto general_case;
987 ch = 128; 923 ch = 128;
988 924
989 if (BE (dfa->is_utf8, 1)) 925 if (__glibc_likely (dfa->is_utf8))
990 { 926 {
991 memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8); 927 memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8);
992 return; 928 return;
@@ -1033,7 +969,7 @@ create_initial_state (re_dfa_t *dfa)
1033 first = dfa->str_tree->first->node_idx; 969 first = dfa->str_tree->first->node_idx;
1034 dfa->init_node = first; 970 dfa->init_node = first;
1035 err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first); 971 err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first);
1036 if (BE (err != REG_NOERROR, 0)) 972 if (__glibc_unlikely (err != REG_NOERROR))
1037 return err; 973 return err;
1038 974
1039 /* The back-references which are in initial states can epsilon transit, 975 /* The back-references which are in initial states can epsilon transit,
@@ -1077,7 +1013,7 @@ create_initial_state (re_dfa_t *dfa)
1077 /* It must be the first time to invoke acquire_state. */ 1013 /* It must be the first time to invoke acquire_state. */
1078 dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0); 1014 dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0);
1079 /* We don't check ERR here, since the initial state must not be NULL. */ 1015 /* We don't check ERR here, since the initial state must not be NULL. */
1080 if (BE (dfa->init_state == NULL, 0)) 1016 if (__glibc_unlikely (dfa->init_state == NULL))
1081 return err; 1017 return err;
1082 if (dfa->init_state->has_constraint) 1018 if (dfa->init_state->has_constraint)
1083 { 1019 {
@@ -1089,8 +1025,9 @@ create_initial_state (re_dfa_t *dfa)
1089 &init_nodes, 1025 &init_nodes,
1090 CONTEXT_NEWLINE 1026 CONTEXT_NEWLINE
1091 | CONTEXT_BEGBUF); 1027 | CONTEXT_BEGBUF);
1092 if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL 1028 if (__glibc_unlikely (dfa->init_state_word == NULL
1093 || dfa->init_state_begbuf == NULL, 0)) 1029 || dfa->init_state_nl == NULL
1030 || dfa->init_state_begbuf == NULL))
1094 return err; 1031 return err;
1095 } 1032 }
1096 else 1033 else
@@ -1101,7 +1038,6 @@ create_initial_state (re_dfa_t *dfa)
1101 return REG_NOERROR; 1038 return REG_NOERROR;
1102} 1039}
1103 1040
1104#ifdef RE_ENABLE_I18N
1105/* If it is possible to do searching in single byte encoding instead of UTF-8 1041/* If it is possible to do searching in single byte encoding instead of UTF-8
1106 to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change 1042 to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change
1107 DFA nodes where needed. */ 1043 DFA nodes where needed. */
@@ -1181,7 +1117,6 @@ optimize_utf8 (re_dfa_t *dfa)
1181 dfa->is_utf8 = 0; 1117 dfa->is_utf8 = 0;
1182 dfa->has_mb_node = dfa->nbackref > 0 || has_period; 1118 dfa->has_mb_node = dfa->nbackref > 0 || has_period;
1183} 1119}
1184#endif
1185 1120
1186/* Analyze the structure tree, and calculate "first", "next", "edest", 1121/* Analyze the structure tree, and calculate "first", "next", "edest",
1187 "eclosure", and "inveclosure". */ 1122 "eclosure", and "inveclosure". */
@@ -1197,8 +1132,8 @@ analyze (regex_t *preg)
1197 dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc); 1132 dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
1198 dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc); 1133 dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
1199 dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc); 1134 dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
1200 if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL 1135 if (__glibc_unlikely (dfa->nexts == NULL || dfa->org_indices == NULL
1201 || dfa->eclosures == NULL, 0)) 1136 || dfa->edests == NULL || dfa->eclosures == NULL))
1202 return REG_ESPACE; 1137 return REG_ESPACE;
1203 1138
1204 dfa->subexp_map = re_malloc (Idx, preg->re_nsub); 1139 dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
@@ -1213,23 +1148,23 @@ analyze (regex_t *preg)
1213 break; 1148 break;
1214 if (i == preg->re_nsub) 1149 if (i == preg->re_nsub)
1215 { 1150 {
1216 free (dfa->subexp_map); 1151 re_free (dfa->subexp_map);
1217 dfa->subexp_map = NULL; 1152 dfa->subexp_map = NULL;
1218 } 1153 }
1219 } 1154 }
1220 1155
1221 ret = postorder (dfa->str_tree, lower_subexps, preg); 1156 ret = postorder (dfa->str_tree, lower_subexps, preg);
1222 if (BE (ret != REG_NOERROR, 0)) 1157 if (__glibc_unlikely (ret != REG_NOERROR))
1223 return ret; 1158 return ret;
1224 ret = postorder (dfa->str_tree, calc_first, dfa); 1159 ret = postorder (dfa->str_tree, calc_first, dfa);
1225 if (BE (ret != REG_NOERROR, 0)) 1160 if (__glibc_unlikely (ret != REG_NOERROR))
1226 return ret; 1161 return ret;
1227 preorder (dfa->str_tree, calc_next, dfa); 1162 preorder (dfa->str_tree, calc_next, dfa);
1228 ret = preorder (dfa->str_tree, link_nfa_nodes, dfa); 1163 ret = preorder (dfa->str_tree, link_nfa_nodes, dfa);
1229 if (BE (ret != REG_NOERROR, 0)) 1164 if (__glibc_unlikely (ret != REG_NOERROR))
1230 return ret; 1165 return ret;
1231 ret = calc_eclosure (dfa); 1166 ret = calc_eclosure (dfa);
1232 if (BE (ret != REG_NOERROR, 0)) 1167 if (__glibc_unlikely (ret != REG_NOERROR))
1233 return ret; 1168 return ret;
1234 1169
1235 /* We only need this during the prune_impossible_nodes pass in regexec.c; 1170 /* We only need this during the prune_impossible_nodes pass in regexec.c;
@@ -1238,7 +1173,7 @@ analyze (regex_t *preg)
1238 || dfa->nbackref) 1173 || dfa->nbackref)
1239 { 1174 {
1240 dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len); 1175 dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
1241 if (BE (dfa->inveclosures == NULL, 0)) 1176 if (__glibc_unlikely (dfa->inveclosures == NULL))
1242 return REG_ESPACE; 1177 return REG_ESPACE;
1243 ret = calc_inveclosure (dfa); 1178 ret = calc_inveclosure (dfa);
1244 } 1179 }
@@ -1268,7 +1203,7 @@ postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
1268 do 1203 do
1269 { 1204 {
1270 reg_errcode_t err = fn (extra, node); 1205 reg_errcode_t err = fn (extra, node);
1271 if (BE (err != REG_NOERROR, 0)) 1206 if (__glibc_unlikely (err != REG_NOERROR))
1272 return err; 1207 return err;
1273 if (node->parent == NULL) 1208 if (node->parent == NULL)
1274 return REG_NOERROR; 1209 return REG_NOERROR;
@@ -1290,7 +1225,7 @@ preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
1290 for (node = root; ; ) 1225 for (node = root; ; )
1291 { 1226 {
1292 reg_errcode_t err = fn (extra, node); 1227 reg_errcode_t err = fn (extra, node);
1293 if (BE (err != REG_NOERROR, 0)) 1228 if (__glibc_unlikely (err != REG_NOERROR))
1294 return err; 1229 return err;
1295 1230
1296 /* Go to the left node, or up and to the right. */ 1231 /* Go to the left node, or up and to the right. */
@@ -1391,7 +1326,8 @@ lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
1391 cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP); 1326 cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP);
1392 tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls; 1327 tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls;
1393 tree = create_tree (dfa, op, tree1, CONCAT); 1328 tree = create_tree (dfa, op, tree1, CONCAT);
1394 if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0)) 1329 if (__glibc_unlikely (tree == NULL || tree1 == NULL
1330 || op == NULL || cls == NULL))
1395 { 1331 {
1396 *err = REG_ESPACE; 1332 *err = REG_ESPACE;
1397 return NULL; 1333 return NULL;
@@ -1417,7 +1353,7 @@ calc_first (void *extra, bin_tree_t *node)
1417 { 1353 {
1418 node->first = node; 1354 node->first = node;
1419 node->node_idx = re_dfa_add_node (dfa, node->token); 1355 node->node_idx = re_dfa_add_node (dfa, node->token);
1420 if (BE (node->node_idx == REG_MISSING, 0)) 1356 if (__glibc_unlikely (node->node_idx == -1))
1421 return REG_ESPACE; 1357 return REG_ESPACE;
1422 if (node->token.type == ANCHOR) 1358 if (node->token.type == ANCHOR)
1423 dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type; 1359 dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type;
@@ -1462,7 +1398,7 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1462 break; 1398 break;
1463 1399
1464 case END_OF_RE: 1400 case END_OF_RE:
1465 assert (node->next == NULL); 1401 DEBUG_ASSERT (node->next == NULL);
1466 break; 1402 break;
1467 1403
1468 case OP_DUP_ASTERISK: 1404 case OP_DUP_ASTERISK:
@@ -1478,8 +1414,8 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1478 right = node->right->first->node_idx; 1414 right = node->right->first->node_idx;
1479 else 1415 else
1480 right = node->next->node_idx; 1416 right = node->next->node_idx;
1481 assert (REG_VALID_INDEX (left)); 1417 DEBUG_ASSERT (left > -1);
1482 assert (REG_VALID_INDEX (right)); 1418 DEBUG_ASSERT (right > -1);
1483 err = re_node_set_init_2 (dfa->edests + idx, left, right); 1419 err = re_node_set_init_2 (dfa->edests + idx, left, right);
1484 } 1420 }
1485 break; 1421 break;
@@ -1497,7 +1433,7 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1497 break; 1433 break;
1498 1434
1499 default: 1435 default:
1500 assert (!IS_EPSILON_NODE (node->token.type)); 1436 DEBUG_ASSERT (!IS_EPSILON_NODE (node->token.type));
1501 dfa->nexts[idx] = node->next->node_idx; 1437 dfa->nexts[idx] = node->next->node_idx;
1502 break; 1438 break;
1503 } 1439 }
@@ -1510,7 +1446,6 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1510 to their own constraint. */ 1446 to their own constraint. */
1511 1447
1512static reg_errcode_t 1448static reg_errcode_t
1513internal_function
1514duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node, 1449duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1515 Idx root_node, unsigned int init_constraint) 1450 Idx root_node, unsigned int init_constraint)
1516{ 1451{
@@ -1529,11 +1464,11 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1529 org_dest = dfa->nexts[org_node]; 1464 org_dest = dfa->nexts[org_node];
1530 re_node_set_empty (dfa->edests + clone_node); 1465 re_node_set_empty (dfa->edests + clone_node);
1531 clone_dest = duplicate_node (dfa, org_dest, constraint); 1466 clone_dest = duplicate_node (dfa, org_dest, constraint);
1532 if (BE (clone_dest == REG_MISSING, 0)) 1467 if (__glibc_unlikely (clone_dest == -1))
1533 return REG_ESPACE; 1468 return REG_ESPACE;
1534 dfa->nexts[clone_node] = dfa->nexts[org_node]; 1469 dfa->nexts[clone_node] = dfa->nexts[org_node];
1535 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1470 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1536 if (BE (! ok, 0)) 1471 if (__glibc_unlikely (! ok))
1537 return REG_ESPACE; 1472 return REG_ESPACE;
1538 } 1473 }
1539 else if (dfa->edests[org_node].nelem == 0) 1474 else if (dfa->edests[org_node].nelem == 0)
@@ -1555,17 +1490,17 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1555 if (org_node == root_node && clone_node != org_node) 1490 if (org_node == root_node && clone_node != org_node)
1556 { 1491 {
1557 ok = re_node_set_insert (dfa->edests + clone_node, org_dest); 1492 ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
1558 if (BE (! ok, 0)) 1493 if (__glibc_unlikely (! ok))
1559 return REG_ESPACE; 1494 return REG_ESPACE;
1560 break; 1495 break;
1561 } 1496 }
1562 /* In case the node has another constraint, append it. */ 1497 /* In case the node has another constraint, append it. */
1563 constraint |= dfa->nodes[org_node].constraint; 1498 constraint |= dfa->nodes[org_node].constraint;
1564 clone_dest = duplicate_node (dfa, org_dest, constraint); 1499 clone_dest = duplicate_node (dfa, org_dest, constraint);
1565 if (BE (clone_dest == REG_MISSING, 0)) 1500 if (__glibc_unlikely (clone_dest == -1))
1566 return REG_ESPACE; 1501 return REG_ESPACE;
1567 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1502 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1568 if (BE (! ok, 0)) 1503 if (__glibc_unlikely (! ok))
1569 return REG_ESPACE; 1504 return REG_ESPACE;
1570 } 1505 }
1571 else /* dfa->edests[org_node].nelem == 2 */ 1506 else /* dfa->edests[org_node].nelem == 2 */
@@ -1576,19 +1511,19 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1576 re_node_set_empty (dfa->edests + clone_node); 1511 re_node_set_empty (dfa->edests + clone_node);
1577 /* Search for a duplicated node which satisfies the constraint. */ 1512 /* Search for a duplicated node which satisfies the constraint. */
1578 clone_dest = search_duplicated_node (dfa, org_dest, constraint); 1513 clone_dest = search_duplicated_node (dfa, org_dest, constraint);
1579 if (clone_dest == REG_MISSING) 1514 if (clone_dest == -1)
1580 { 1515 {
1581 /* There is no such duplicated node, create a new one. */ 1516 /* There is no such duplicated node, create a new one. */
1582 reg_errcode_t err; 1517 reg_errcode_t err;
1583 clone_dest = duplicate_node (dfa, org_dest, constraint); 1518 clone_dest = duplicate_node (dfa, org_dest, constraint);
1584 if (BE (clone_dest == REG_MISSING, 0)) 1519 if (__glibc_unlikely (clone_dest == -1))
1585 return REG_ESPACE; 1520 return REG_ESPACE;
1586 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1521 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1587 if (BE (! ok, 0)) 1522 if (__glibc_unlikely (! ok))
1588 return REG_ESPACE; 1523 return REG_ESPACE;
1589 err = duplicate_node_closure (dfa, org_dest, clone_dest, 1524 err = duplicate_node_closure (dfa, org_dest, clone_dest,
1590 root_node, constraint); 1525 root_node, constraint);
1591 if (BE (err != REG_NOERROR, 0)) 1526 if (__glibc_unlikely (err != REG_NOERROR))
1592 return err; 1527 return err;
1593 } 1528 }
1594 else 1529 else
@@ -1596,16 +1531,16 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1596 /* There is a duplicated node which satisfies the constraint, 1531 /* There is a duplicated node which satisfies the constraint,
1597 use it to avoid infinite loop. */ 1532 use it to avoid infinite loop. */
1598 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1533 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1599 if (BE (! ok, 0)) 1534 if (__glibc_unlikely (! ok))
1600 return REG_ESPACE; 1535 return REG_ESPACE;
1601 } 1536 }
1602 1537
1603 org_dest = dfa->edests[org_node].elems[1]; 1538 org_dest = dfa->edests[org_node].elems[1];
1604 clone_dest = duplicate_node (dfa, org_dest, constraint); 1539 clone_dest = duplicate_node (dfa, org_dest, constraint);
1605 if (BE (clone_dest == REG_MISSING, 0)) 1540 if (__glibc_unlikely (clone_dest == -1))
1606 return REG_ESPACE; 1541 return REG_ESPACE;
1607 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1542 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1608 if (BE (! ok, 0)) 1543 if (__glibc_unlikely (! ok))
1609 return REG_ESPACE; 1544 return REG_ESPACE;
1610 } 1545 }
1611 org_node = org_dest; 1546 org_node = org_dest;
@@ -1628,18 +1563,18 @@ search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
1628 && constraint == dfa->nodes[idx].constraint) 1563 && constraint == dfa->nodes[idx].constraint)
1629 return idx; /* Found. */ 1564 return idx; /* Found. */
1630 } 1565 }
1631 return REG_MISSING; /* Not found. */ 1566 return -1; /* Not found. */
1632} 1567}
1633 1568
1634/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT. 1569/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT.
1635 Return the index of the new node, or REG_MISSING if insufficient storage is 1570 Return the index of the new node, or -1 if insufficient storage is
1636 available. */ 1571 available. */
1637 1572
1638static Idx 1573static Idx
1639duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint) 1574duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint)
1640{ 1575{
1641 Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]); 1576 Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
1642 if (BE (dup_idx != REG_MISSING, 1)) 1577 if (__glibc_likely (dup_idx != -1))
1643 { 1578 {
1644 dfa->nodes[dup_idx].constraint = constraint; 1579 dfa->nodes[dup_idx].constraint = constraint;
1645 dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint; 1580 dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint;
@@ -1665,7 +1600,7 @@ calc_inveclosure (re_dfa_t *dfa)
1665 for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx) 1600 for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
1666 { 1601 {
1667 ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src); 1602 ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
1668 if (BE (! ok, 0)) 1603 if (__glibc_unlikely (! ok))
1669 return REG_ESPACE; 1604 return REG_ESPACE;
1670 } 1605 }
1671 } 1606 }
@@ -1680,9 +1615,7 @@ calc_eclosure (re_dfa_t *dfa)
1680{ 1615{
1681 Idx node_idx; 1616 Idx node_idx;
1682 bool incomplete; 1617 bool incomplete;
1683#ifdef DEBUG 1618 DEBUG_ASSERT (dfa->nodes_len > 0);
1684 assert (dfa->nodes_len > 0);
1685#endif
1686 incomplete = false; 1619 incomplete = false;
1687 /* For each nodes, calculate epsilon closure. */ 1620 /* For each nodes, calculate epsilon closure. */
1688 for (node_idx = 0; ; ++node_idx) 1621 for (node_idx = 0; ; ++node_idx)
@@ -1697,16 +1630,14 @@ calc_eclosure (re_dfa_t *dfa)
1697 node_idx = 0; 1630 node_idx = 0;
1698 } 1631 }
1699 1632
1700#ifdef DEBUG 1633 DEBUG_ASSERT (dfa->eclosures[node_idx].nelem != -1);
1701 assert (dfa->eclosures[node_idx].nelem != REG_MISSING);
1702#endif
1703 1634
1704 /* If we have already calculated, skip it. */ 1635 /* If we have already calculated, skip it. */
1705 if (dfa->eclosures[node_idx].nelem != 0) 1636 if (dfa->eclosures[node_idx].nelem != 0)
1706 continue; 1637 continue;
1707 /* Calculate epsilon closure of 'node_idx'. */ 1638 /* Calculate epsilon closure of 'node_idx'. */
1708 err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true); 1639 err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
1709 if (BE (err != REG_NOERROR, 0)) 1640 if (__glibc_unlikely (err != REG_NOERROR))
1710 return err; 1641 return err;
1711 1642
1712 if (dfa->eclosures[node_idx].nelem == 0) 1643 if (dfa->eclosures[node_idx].nelem == 0)
@@ -1726,15 +1657,17 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1726 reg_errcode_t err; 1657 reg_errcode_t err;
1727 Idx i; 1658 Idx i;
1728 re_node_set eclosure; 1659 re_node_set eclosure;
1729 bool ok;
1730 bool incomplete = false; 1660 bool incomplete = false;
1731 err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1); 1661 err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
1732 if (BE (err != REG_NOERROR, 0)) 1662 if (__glibc_unlikely (err != REG_NOERROR))
1733 return err; 1663 return err;
1734 1664
1665 /* An epsilon closure includes itself. */
1666 eclosure.elems[eclosure.nelem++] = node;
1667
1735 /* This indicates that we are calculating this node now. 1668 /* This indicates that we are calculating this node now.
1736 We reference this value to avoid infinite loop. */ 1669 We reference this value to avoid infinite loop. */
1737 dfa->eclosures[node].nelem = REG_MISSING; 1670 dfa->eclosures[node].nelem = -1;
1738 1671
1739 /* If the current node has constraints, duplicate all nodes 1672 /* If the current node has constraints, duplicate all nodes
1740 since they must inherit the constraints. */ 1673 since they must inherit the constraints. */
@@ -1744,7 +1677,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1744 { 1677 {
1745 err = duplicate_node_closure (dfa, node, node, node, 1678 err = duplicate_node_closure (dfa, node, node, node,
1746 dfa->nodes[node].constraint); 1679 dfa->nodes[node].constraint);
1747 if (BE (err != REG_NOERROR, 0)) 1680 if (__glibc_unlikely (err != REG_NOERROR))
1748 return err; 1681 return err;
1749 } 1682 }
1750 1683
@@ -1756,7 +1689,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1756 Idx edest = dfa->edests[node].elems[i]; 1689 Idx edest = dfa->edests[node].elems[i];
1757 /* If calculating the epsilon closure of 'edest' is in progress, 1690 /* If calculating the epsilon closure of 'edest' is in progress,
1758 return intermediate result. */ 1691 return intermediate result. */
1759 if (dfa->eclosures[edest].nelem == REG_MISSING) 1692 if (dfa->eclosures[edest].nelem == -1)
1760 { 1693 {
1761 incomplete = true; 1694 incomplete = true;
1762 continue; 1695 continue;
@@ -1766,14 +1699,14 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1766 if (dfa->eclosures[edest].nelem == 0) 1699 if (dfa->eclosures[edest].nelem == 0)
1767 { 1700 {
1768 err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false); 1701 err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
1769 if (BE (err != REG_NOERROR, 0)) 1702 if (__glibc_unlikely (err != REG_NOERROR))
1770 return err; 1703 return err;
1771 } 1704 }
1772 else 1705 else
1773 eclosure_elem = dfa->eclosures[edest]; 1706 eclosure_elem = dfa->eclosures[edest];
1774 /* Merge the epsilon closure of 'edest'. */ 1707 /* Merge the epsilon closure of 'edest'. */
1775 err = re_node_set_merge (&eclosure, &eclosure_elem); 1708 err = re_node_set_merge (&eclosure, &eclosure_elem);
1776 if (BE (err != REG_NOERROR, 0)) 1709 if (__glibc_unlikely (err != REG_NOERROR))
1777 return err; 1710 return err;
1778 /* If the epsilon closure of 'edest' is incomplete, 1711 /* If the epsilon closure of 'edest' is incomplete,
1779 the epsilon closure of this node is also incomplete. */ 1712 the epsilon closure of this node is also incomplete. */
@@ -1784,10 +1717,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1784 } 1717 }
1785 } 1718 }
1786 1719
1787 /* An epsilon closure includes itself. */
1788 ok = re_node_set_insert (&eclosure, node);
1789 if (BE (! ok, 0))
1790 return REG_ESPACE;
1791 if (incomplete && !root) 1720 if (incomplete && !root)
1792 dfa->eclosures[node].nelem = 0; 1721 dfa->eclosures[node].nelem = 0;
1793 else 1722 else
@@ -1802,7 +1731,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1802 We must not use this function inside bracket expressions. */ 1731 We must not use this function inside bracket expressions. */
1803 1732
1804static void 1733static void
1805internal_function
1806fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) 1734fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
1807{ 1735{
1808 re_string_skip_bytes (input, peek_token (result, input, syntax)); 1736 re_string_skip_bytes (input, peek_token (result, input, syntax));
@@ -1812,7 +1740,6 @@ fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
1812 We must not use this function inside bracket expressions. */ 1740 We must not use this function inside bracket expressions. */
1813 1741
1814static int 1742static int
1815internal_function
1816peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) 1743peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1817{ 1744{
1818 unsigned char c; 1745 unsigned char c;
@@ -1827,16 +1754,14 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1827 token->opr.c = c; 1754 token->opr.c = c;
1828 1755
1829 token->word_char = 0; 1756 token->word_char = 0;
1830#ifdef RE_ENABLE_I18N
1831 token->mb_partial = 0; 1757 token->mb_partial = 0;
1832 if (input->mb_cur_max > 1 && 1758 if (input->mb_cur_max > 1
1833 !re_string_first_byte (input, re_string_cur_idx (input))) 1759 && !re_string_first_byte (input, re_string_cur_idx (input)))
1834 { 1760 {
1835 token->type = CHARACTER; 1761 token->type = CHARACTER;
1836 token->mb_partial = 1; 1762 token->mb_partial = 1;
1837 return 1; 1763 return 1;
1838 } 1764 }
1839#endif
1840 if (c == '\\') 1765 if (c == '\\')
1841 { 1766 {
1842 unsigned char c2; 1767 unsigned char c2;
@@ -1849,7 +1774,6 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1849 c2 = re_string_peek_byte_case (input, 1); 1774 c2 = re_string_peek_byte_case (input, 1);
1850 token->opr.c = c2; 1775 token->opr.c = c2;
1851 token->type = CHARACTER; 1776 token->type = CHARACTER;
1852#ifdef RE_ENABLE_I18N
1853 if (input->mb_cur_max > 1) 1777 if (input->mb_cur_max > 1)
1854 { 1778 {
1855 wint_t wc = re_string_wchar_at (input, 1779 wint_t wc = re_string_wchar_at (input,
@@ -1857,7 +1781,6 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1857 token->word_char = IS_WIDE_WORD_CHAR (wc) != 0; 1781 token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
1858 } 1782 }
1859 else 1783 else
1860#endif
1861 token->word_char = IS_WORD_CHAR (c2) != 0; 1784 token->word_char = IS_WORD_CHAR (c2) != 0;
1862 1785
1863 switch (c2) 1786 switch (c2)
@@ -1963,14 +1886,12 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1963 } 1886 }
1964 1887
1965 token->type = CHARACTER; 1888 token->type = CHARACTER;
1966#ifdef RE_ENABLE_I18N
1967 if (input->mb_cur_max > 1) 1889 if (input->mb_cur_max > 1)
1968 { 1890 {
1969 wint_t wc = re_string_wchar_at (input, re_string_cur_idx (input)); 1891 wint_t wc = re_string_wchar_at (input, re_string_cur_idx (input));
1970 token->word_char = IS_WIDE_WORD_CHAR (wc) != 0; 1892 token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
1971 } 1893 }
1972 else 1894 else
1973#endif
1974 token->word_char = IS_WORD_CHAR (token->opr.c); 1895 token->word_char = IS_WORD_CHAR (token->opr.c);
1975 1896
1976 switch (c) 1897 switch (c)
@@ -2017,8 +1938,8 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2017 token->type = OP_PERIOD; 1938 token->type = OP_PERIOD;
2018 break; 1939 break;
2019 case '^': 1940 case '^':
2020 if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) && 1941 if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE))
2021 re_string_cur_idx (input) != 0) 1942 && re_string_cur_idx (input) != 0)
2022 { 1943 {
2023 char prev = re_string_peek_byte (input, -1); 1944 char prev = re_string_peek_byte (input, -1);
2024 if (!(syntax & RE_NEWLINE_ALT) || prev != '\n') 1945 if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
@@ -2028,8 +1949,8 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2028 token->opr.ctx_type = LINE_FIRST; 1949 token->opr.ctx_type = LINE_FIRST;
2029 break; 1950 break;
2030 case '$': 1951 case '$':
2031 if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) && 1952 if (!(syntax & RE_CONTEXT_INDEP_ANCHORS)
2032 re_string_cur_idx (input) + 1 != re_string_length (input)) 1953 && re_string_cur_idx (input) + 1 != re_string_length (input))
2033 { 1954 {
2034 re_token_t next; 1955 re_token_t next;
2035 re_string_skip_bytes (input, 1); 1956 re_string_skip_bytes (input, 1);
@@ -2051,7 +1972,6 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2051 We must not use this function out of bracket expressions. */ 1972 We must not use this function out of bracket expressions. */
2052 1973
2053static int 1974static int
2054internal_function
2055peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) 1975peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2056{ 1976{
2057 unsigned char c; 1977 unsigned char c;
@@ -2063,14 +1983,12 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2063 c = re_string_peek_byte (input, 0); 1983 c = re_string_peek_byte (input, 0);
2064 token->opr.c = c; 1984 token->opr.c = c;
2065 1985
2066#ifdef RE_ENABLE_I18N 1986 if (input->mb_cur_max > 1
2067 if (input->mb_cur_max > 1 && 1987 && !re_string_first_byte (input, re_string_cur_idx (input)))
2068 !re_string_first_byte (input, re_string_cur_idx (input)))
2069 { 1988 {
2070 token->type = CHARACTER; 1989 token->type = CHARACTER;
2071 return 1; 1990 return 1;
2072 } 1991 }
2073#endif /* RE_ENABLE_I18N */
2074 1992
2075 if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) 1993 if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
2076 && re_string_cur_idx (input) + 1 < re_string_length (input)) 1994 && re_string_cur_idx (input) + 1 < re_string_length (input))
@@ -2098,16 +2016,18 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2098 case '.': 2016 case '.':
2099 token->type = OP_OPEN_COLL_ELEM; 2017 token->type = OP_OPEN_COLL_ELEM;
2100 break; 2018 break;
2019
2101 case '=': 2020 case '=':
2102 token->type = OP_OPEN_EQUIV_CLASS; 2021 token->type = OP_OPEN_EQUIV_CLASS;
2103 break; 2022 break;
2023
2104 case ':': 2024 case ':':
2105 if (syntax & RE_CHAR_CLASSES) 2025 if (syntax & RE_CHAR_CLASSES)
2106 { 2026 {
2107 token->type = OP_OPEN_CHAR_CLASS; 2027 token->type = OP_OPEN_CHAR_CLASS;
2108 break; 2028 break;
2109 } 2029 }
2110 /* else fall through. */ 2030 FALLTHROUGH;
2111 default: 2031 default:
2112 token->type = CHARACTER; 2032 token->type = CHARACTER;
2113 token->opr.c = c; 2033 token->opr.c = c;
@@ -2118,15 +2038,25 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2118 } 2038 }
2119 switch (c) 2039 switch (c)
2120 { 2040 {
2121 case '-':
2122 token->type = OP_CHARSET_RANGE;
2123 break;
2124 case ']': 2041 case ']':
2125 token->type = OP_CLOSE_BRACKET; 2042 token->type = OP_CLOSE_BRACKET;
2126 break; 2043 break;
2127 case '^': 2044 case '^':
2128 token->type = OP_NON_MATCH_LIST; 2045 token->type = OP_NON_MATCH_LIST;
2129 break; 2046 break;
2047 case '-':
2048 /* In V7 Unix grep and Unix awk and mawk, [...---...]
2049 (3 adjacent minus signs) stands for a single minus sign.
2050 Support that without breaking anything else. */
2051 if (! (re_string_cur_idx (input) + 2 < re_string_length (input)
2052 && re_string_peek_byte (input, 1) == '-'
2053 && re_string_peek_byte (input, 2) == '-'))
2054 {
2055 token->type = OP_CHARSET_RANGE;
2056 break;
2057 }
2058 re_string_skip_bytes (input, 2);
2059 FALLTHROUGH;
2130 default: 2060 default:
2131 token->type = CHARACTER; 2061 token->type = CHARACTER;
2132 } 2062 }
@@ -2157,14 +2087,14 @@ parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
2157 dfa->syntax = syntax; 2087 dfa->syntax = syntax;
2158 fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE); 2088 fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
2159 tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err); 2089 tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
2160 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2090 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2161 return NULL; 2091 return NULL;
2162 eor = create_tree (dfa, NULL, NULL, END_OF_RE); 2092 eor = create_tree (dfa, NULL, NULL, END_OF_RE);
2163 if (tree != NULL) 2093 if (tree != NULL)
2164 root = create_tree (dfa, tree, eor, CONCAT); 2094 root = create_tree (dfa, tree, eor, CONCAT);
2165 else 2095 else
2166 root = eor; 2096 root = eor;
2167 if (BE (eor == NULL || root == NULL, 0)) 2097 if (__glibc_unlikely (eor == NULL || root == NULL))
2168 { 2098 {
2169 *err = REG_ESPACE; 2099 *err = REG_ESPACE;
2170 return NULL; 2100 return NULL;
@@ -2187,8 +2117,9 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2187{ 2117{
2188 re_dfa_t *dfa = preg->buffer; 2118 re_dfa_t *dfa = preg->buffer;
2189 bin_tree_t *tree, *branch = NULL; 2119 bin_tree_t *tree, *branch = NULL;
2120 bitset_word_t initial_bkref_map = dfa->completed_bkref_map;
2190 tree = parse_branch (regexp, preg, token, syntax, nest, err); 2121 tree = parse_branch (regexp, preg, token, syntax, nest, err);
2191 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2122 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2192 return NULL; 2123 return NULL;
2193 2124
2194 while (token->type == OP_ALT) 2125 while (token->type == OP_ALT)
@@ -2197,14 +2128,21 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2197 if (token->type != OP_ALT && token->type != END_OF_RE 2128 if (token->type != OP_ALT && token->type != END_OF_RE
2198 && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) 2129 && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
2199 { 2130 {
2131 bitset_word_t accumulated_bkref_map = dfa->completed_bkref_map;
2132 dfa->completed_bkref_map = initial_bkref_map;
2200 branch = parse_branch (regexp, preg, token, syntax, nest, err); 2133 branch = parse_branch (regexp, preg, token, syntax, nest, err);
2201 if (BE (*err != REG_NOERROR && branch == NULL, 0)) 2134 if (__glibc_unlikely (*err != REG_NOERROR && branch == NULL))
2202 return NULL; 2135 {
2136 if (tree != NULL)
2137 postorder (tree, free_tree, NULL);
2138 return NULL;
2139 }
2140 dfa->completed_bkref_map |= accumulated_bkref_map;
2203 } 2141 }
2204 else 2142 else
2205 branch = NULL; 2143 branch = NULL;
2206 tree = create_tree (dfa, tree, branch, OP_ALT); 2144 tree = create_tree (dfa, tree, branch, OP_ALT);
2207 if (BE (tree == NULL, 0)) 2145 if (__glibc_unlikely (tree == NULL))
2208 { 2146 {
2209 *err = REG_ESPACE; 2147 *err = REG_ESPACE;
2210 return NULL; 2148 return NULL;
@@ -2229,14 +2167,14 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
2229 bin_tree_t *tree, *expr; 2167 bin_tree_t *tree, *expr;
2230 re_dfa_t *dfa = preg->buffer; 2168 re_dfa_t *dfa = preg->buffer;
2231 tree = parse_expression (regexp, preg, token, syntax, nest, err); 2169 tree = parse_expression (regexp, preg, token, syntax, nest, err);
2232 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2170 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2233 return NULL; 2171 return NULL;
2234 2172
2235 while (token->type != OP_ALT && token->type != END_OF_RE 2173 while (token->type != OP_ALT && token->type != END_OF_RE
2236 && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) 2174 && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
2237 { 2175 {
2238 expr = parse_expression (regexp, preg, token, syntax, nest, err); 2176 expr = parse_expression (regexp, preg, token, syntax, nest, err);
2239 if (BE (*err != REG_NOERROR && expr == NULL, 0)) 2177 if (__glibc_unlikely (*err != REG_NOERROR && expr == NULL))
2240 { 2178 {
2241 if (tree != NULL) 2179 if (tree != NULL)
2242 postorder (tree, free_tree, NULL); 2180 postorder (tree, free_tree, NULL);
@@ -2277,12 +2215,11 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2277 { 2215 {
2278 case CHARACTER: 2216 case CHARACTER:
2279 tree = create_token_tree (dfa, NULL, NULL, token); 2217 tree = create_token_tree (dfa, NULL, NULL, token);
2280 if (BE (tree == NULL, 0)) 2218 if (__glibc_unlikely (tree == NULL))
2281 { 2219 {
2282 *err = REG_ESPACE; 2220 *err = REG_ESPACE;
2283 return NULL; 2221 return NULL;
2284 } 2222 }
2285#ifdef RE_ENABLE_I18N
2286 if (dfa->mb_cur_max > 1) 2223 if (dfa->mb_cur_max > 1)
2287 { 2224 {
2288 while (!re_string_eoi (regexp) 2225 while (!re_string_eoi (regexp)
@@ -2292,34 +2229,36 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2292 fetch_token (token, regexp, syntax); 2229 fetch_token (token, regexp, syntax);
2293 mbc_remain = create_token_tree (dfa, NULL, NULL, token); 2230 mbc_remain = create_token_tree (dfa, NULL, NULL, token);
2294 tree = create_tree (dfa, tree, mbc_remain, CONCAT); 2231 tree = create_tree (dfa, tree, mbc_remain, CONCAT);
2295 if (BE (mbc_remain == NULL || tree == NULL, 0)) 2232 if (__glibc_unlikely (mbc_remain == NULL || tree == NULL))
2296 { 2233 {
2297 *err = REG_ESPACE; 2234 *err = REG_ESPACE;
2298 return NULL; 2235 return NULL;
2299 } 2236 }
2300 } 2237 }
2301 } 2238 }
2302#endif
2303 break; 2239 break;
2240
2304 case OP_OPEN_SUBEXP: 2241 case OP_OPEN_SUBEXP:
2305 tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err); 2242 tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err);
2306 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2243 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2307 return NULL; 2244 return NULL;
2308 break; 2245 break;
2246
2309 case OP_OPEN_BRACKET: 2247 case OP_OPEN_BRACKET:
2310 tree = parse_bracket_exp (regexp, dfa, token, syntax, err); 2248 tree = parse_bracket_exp (regexp, dfa, token, syntax, err);
2311 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2249 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2312 return NULL; 2250 return NULL;
2313 break; 2251 break;
2252
2314 case OP_BACK_REF: 2253 case OP_BACK_REF:
2315 if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1)) 2254 if (!__glibc_likely (dfa->completed_bkref_map & (1 << token->opr.idx)))
2316 { 2255 {
2317 *err = REG_ESUBREG; 2256 *err = REG_ESUBREG;
2318 return NULL; 2257 return NULL;
2319 } 2258 }
2320 dfa->used_bkref_map |= 1 << token->opr.idx; 2259 dfa->used_bkref_map |= 1 << token->opr.idx;
2321 tree = create_token_tree (dfa, NULL, NULL, token); 2260 tree = create_token_tree (dfa, NULL, NULL, token);
2322 if (BE (tree == NULL, 0)) 2261 if (__glibc_unlikely (tree == NULL))
2323 { 2262 {
2324 *err = REG_ESPACE; 2263 *err = REG_ESPACE;
2325 return NULL; 2264 return NULL;
@@ -2327,13 +2266,14 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2327 ++dfa->nbackref; 2266 ++dfa->nbackref;
2328 dfa->has_mb_node = 1; 2267 dfa->has_mb_node = 1;
2329 break; 2268 break;
2269
2330 case OP_OPEN_DUP_NUM: 2270 case OP_OPEN_DUP_NUM:
2331 if (syntax & RE_CONTEXT_INVALID_DUP) 2271 if (syntax & RE_CONTEXT_INVALID_DUP)
2332 { 2272 {
2333 *err = REG_BADRPT; 2273 *err = REG_BADRPT;
2334 return NULL; 2274 return NULL;
2335 } 2275 }
2336 /* FALLTHROUGH */ 2276 FALLTHROUGH;
2337 case OP_DUP_ASTERISK: 2277 case OP_DUP_ASTERISK:
2338 case OP_DUP_PLUS: 2278 case OP_DUP_PLUS:
2339 case OP_DUP_QUESTION: 2279 case OP_DUP_QUESTION:
@@ -2347,15 +2287,15 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2347 fetch_token (token, regexp, syntax); 2287 fetch_token (token, regexp, syntax);
2348 return parse_expression (regexp, preg, token, syntax, nest, err); 2288 return parse_expression (regexp, preg, token, syntax, nest, err);
2349 } 2289 }
2350 /* else fall through */ 2290 FALLTHROUGH;
2351 case OP_CLOSE_SUBEXP: 2291 case OP_CLOSE_SUBEXP:
2352 if ((token->type == OP_CLOSE_SUBEXP) && 2292 if ((token->type == OP_CLOSE_SUBEXP)
2353 !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)) 2293 && !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
2354 { 2294 {
2355 *err = REG_ERPAREN; 2295 *err = REG_ERPAREN;
2356 return NULL; 2296 return NULL;
2357 } 2297 }
2358 /* else fall through */ 2298 FALLTHROUGH;
2359 case OP_CLOSE_DUP_NUM: 2299 case OP_CLOSE_DUP_NUM:
2360 /* We treat it as a normal character. */ 2300 /* We treat it as a normal character. */
2361 2301
@@ -2364,12 +2304,13 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2364 /* mb_partial and word_char bits should be initialized already 2304 /* mb_partial and word_char bits should be initialized already
2365 by peek_token. */ 2305 by peek_token. */
2366 tree = create_token_tree (dfa, NULL, NULL, token); 2306 tree = create_token_tree (dfa, NULL, NULL, token);
2367 if (BE (tree == NULL, 0)) 2307 if (__glibc_unlikely (tree == NULL))
2368 { 2308 {
2369 *err = REG_ESPACE; 2309 *err = REG_ESPACE;
2370 return NULL; 2310 return NULL;
2371 } 2311 }
2372 break; 2312 break;
2313
2373 case ANCHOR: 2314 case ANCHOR:
2374 if ((token->opr.ctx_type 2315 if ((token->opr.ctx_type
2375 & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST)) 2316 & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST))
@@ -2393,7 +2334,8 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2393 } 2334 }
2394 tree_last = create_token_tree (dfa, NULL, NULL, token); 2335 tree_last = create_token_tree (dfa, NULL, NULL, token);
2395 tree = create_tree (dfa, tree_first, tree_last, OP_ALT); 2336 tree = create_tree (dfa, tree_first, tree_last, OP_ALT);
2396 if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0)) 2337 if (__glibc_unlikely (tree_first == NULL || tree_last == NULL
2338 || tree == NULL))
2397 { 2339 {
2398 *err = REG_ESPACE; 2340 *err = REG_ESPACE;
2399 return NULL; 2341 return NULL;
@@ -2402,7 +2344,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2402 else 2344 else
2403 { 2345 {
2404 tree = create_token_tree (dfa, NULL, NULL, token); 2346 tree = create_token_tree (dfa, NULL, NULL, token);
2405 if (BE (tree == NULL, 0)) 2347 if (__glibc_unlikely (tree == NULL))
2406 { 2348 {
2407 *err = REG_ESPACE; 2349 *err = REG_ESPACE;
2408 return NULL; 2350 return NULL;
@@ -2414,9 +2356,10 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2414 it must not be "<ANCHOR(^)><REPEAT(*)>". */ 2356 it must not be "<ANCHOR(^)><REPEAT(*)>". */
2415 fetch_token (token, regexp, syntax); 2357 fetch_token (token, regexp, syntax);
2416 return tree; 2358 return tree;
2359
2417 case OP_PERIOD: 2360 case OP_PERIOD:
2418 tree = create_token_tree (dfa, NULL, NULL, token); 2361 tree = create_token_tree (dfa, NULL, NULL, token);
2419 if (BE (tree == NULL, 0)) 2362 if (__glibc_unlikely (tree == NULL))
2420 { 2363 {
2421 *err = REG_ESPACE; 2364 *err = REG_ESPACE;
2422 return NULL; 2365 return NULL;
@@ -2424,35 +2367,38 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2424 if (dfa->mb_cur_max > 1) 2367 if (dfa->mb_cur_max > 1)
2425 dfa->has_mb_node = 1; 2368 dfa->has_mb_node = 1;
2426 break; 2369 break;
2370
2427 case OP_WORD: 2371 case OP_WORD:
2428 case OP_NOTWORD: 2372 case OP_NOTWORD:
2429 tree = build_charclass_op (dfa, regexp->trans, 2373 tree = build_charclass_op (dfa, regexp->trans,
2430 "alnum", 2374 "alnum",
2431 "_", 2375 "_",
2432 token->type == OP_NOTWORD, err); 2376 token->type == OP_NOTWORD, err);
2433 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2377 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2434 return NULL; 2378 return NULL;
2435 break; 2379 break;
2380
2436 case OP_SPACE: 2381 case OP_SPACE:
2437 case OP_NOTSPACE: 2382 case OP_NOTSPACE:
2438 tree = build_charclass_op (dfa, regexp->trans, 2383 tree = build_charclass_op (dfa, regexp->trans,
2439 "space", 2384 "space",
2440 "", 2385 "",
2441 token->type == OP_NOTSPACE, err); 2386 token->type == OP_NOTSPACE, err);
2442 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2387 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2443 return NULL; 2388 return NULL;
2444 break; 2389 break;
2390
2445 case OP_ALT: 2391 case OP_ALT:
2446 case END_OF_RE: 2392 case END_OF_RE:
2447 return NULL; 2393 return NULL;
2394
2448 case BACK_SLASH: 2395 case BACK_SLASH:
2449 *err = REG_EESCAPE; 2396 *err = REG_EESCAPE;
2450 return NULL; 2397 return NULL;
2398
2451 default: 2399 default:
2452 /* Must not happen? */ 2400 /* Must not happen? */
2453#ifdef DEBUG 2401 DEBUG_ASSERT (false);
2454 assert (0);
2455#endif
2456 return NULL; 2402 return NULL;
2457 } 2403 }
2458 fetch_token (token, regexp, syntax); 2404 fetch_token (token, regexp, syntax);
@@ -2460,14 +2406,22 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2460 while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS 2406 while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
2461 || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM) 2407 || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
2462 { 2408 {
2463 tree = parse_dup_op (tree, regexp, dfa, token, syntax, err); 2409 bin_tree_t *dup_tree = parse_dup_op (tree, regexp, dfa, token,
2464 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2410 syntax, err);
2465 return NULL; 2411 if (__glibc_unlikely (*err != REG_NOERROR && dup_tree == NULL))
2412 {
2413 if (tree != NULL)
2414 postorder (tree, free_tree, NULL);
2415 return NULL;
2416 }
2417 tree = dup_tree;
2466 /* In BRE consecutive duplications are not allowed. */ 2418 /* In BRE consecutive duplications are not allowed. */
2467 if ((syntax & RE_CONTEXT_INVALID_DUP) 2419 if ((syntax & RE_CONTEXT_INVALID_DUP)
2468 && (token->type == OP_DUP_ASTERISK 2420 && (token->type == OP_DUP_ASTERISK
2469 || token->type == OP_OPEN_DUP_NUM)) 2421 || token->type == OP_OPEN_DUP_NUM))
2470 { 2422 {
2423 if (tree != NULL)
2424 postorder (tree, free_tree, NULL);
2471 *err = REG_BADRPT; 2425 *err = REG_BADRPT;
2472 return NULL; 2426 return NULL;
2473 } 2427 }
@@ -2500,13 +2454,14 @@ parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2500 else 2454 else
2501 { 2455 {
2502 tree = parse_reg_exp (regexp, preg, token, syntax, nest, err); 2456 tree = parse_reg_exp (regexp, preg, token, syntax, nest, err);
2503 if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0)) 2457 if (__glibc_unlikely (*err == REG_NOERROR
2458 && token->type != OP_CLOSE_SUBEXP))
2504 { 2459 {
2505 if (tree != NULL) 2460 if (tree != NULL)
2506 postorder (tree, free_tree, NULL); 2461 postorder (tree, free_tree, NULL);
2507 *err = REG_EPAREN; 2462 *err = REG_EPAREN;
2508 } 2463 }
2509 if (BE (*err != REG_NOERROR, 0)) 2464 if (__glibc_unlikely (*err != REG_NOERROR))
2510 return NULL; 2465 return NULL;
2511 } 2466 }
2512 2467
@@ -2514,7 +2469,7 @@ parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2514 dfa->completed_bkref_map |= 1 << cur_nsub; 2469 dfa->completed_bkref_map |= 1 << cur_nsub;
2515 2470
2516 tree = create_tree (dfa, tree, NULL, SUBEXP); 2471 tree = create_tree (dfa, tree, NULL, SUBEXP);
2517 if (BE (tree == NULL, 0)) 2472 if (__glibc_unlikely (tree == NULL))
2518 { 2473 {
2519 *err = REG_ESPACE; 2474 *err = REG_ESPACE;
2520 return NULL; 2475 return NULL;
@@ -2537,7 +2492,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2537 { 2492 {
2538 end = 0; 2493 end = 0;
2539 start = fetch_number (regexp, token, syntax); 2494 start = fetch_number (regexp, token, syntax);
2540 if (start == REG_MISSING) 2495 if (start == -1)
2541 { 2496 {
2542 if (token->type == CHARACTER && token->opr.c == ',') 2497 if (token->type == CHARACTER && token->opr.c == ',')
2543 start = 0; /* We treat "{,m}" as "{0,m}". */ 2498 start = 0; /* We treat "{,m}" as "{0,m}". */
@@ -2547,17 +2502,17 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2547 return NULL; 2502 return NULL;
2548 } 2503 }
2549 } 2504 }
2550 if (BE (start != REG_ERROR, 1)) 2505 if (__glibc_likely (start != -2))
2551 { 2506 {
2552 /* We treat "{n}" as "{n,n}". */ 2507 /* We treat "{n}" as "{n,n}". */
2553 end = ((token->type == OP_CLOSE_DUP_NUM) ? start 2508 end = ((token->type == OP_CLOSE_DUP_NUM) ? start
2554 : ((token->type == CHARACTER && token->opr.c == ',') 2509 : ((token->type == CHARACTER && token->opr.c == ',')
2555 ? fetch_number (regexp, token, syntax) : REG_ERROR)); 2510 ? fetch_number (regexp, token, syntax) : -2));
2556 } 2511 }
2557 if (BE (start == REG_ERROR || end == REG_ERROR, 0)) 2512 if (__glibc_unlikely (start == -2 || end == -2))
2558 { 2513 {
2559 /* Invalid sequence. */ 2514 /* Invalid sequence. */
2560 if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0)) 2515 if (__glibc_unlikely (!(syntax & RE_INVALID_INTERVAL_ORD)))
2561 { 2516 {
2562 if (token->type == END_OF_RE) 2517 if (token->type == END_OF_RE)
2563 *err = REG_EBRACE; 2518 *err = REG_EBRACE;
@@ -2576,15 +2531,15 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2576 return elem; 2531 return elem;
2577 } 2532 }
2578 2533
2579 if (BE ((end != REG_MISSING && start > end) 2534 if (__glibc_unlikely ((end != -1 && start > end)
2580 || token->type != OP_CLOSE_DUP_NUM, 0)) 2535 || token->type != OP_CLOSE_DUP_NUM))
2581 { 2536 {
2582 /* First number greater than second. */ 2537 /* First number greater than second. */
2583 *err = REG_BADBR; 2538 *err = REG_BADBR;
2584 return NULL; 2539 return NULL;
2585 } 2540 }
2586 2541
2587 if (BE (RE_DUP_MAX < (end == REG_MISSING ? start : end), 0)) 2542 if (__glibc_unlikely (RE_DUP_MAX < (end == -1 ? start : end)))
2588 { 2543 {
2589 *err = REG_ESIZE; 2544 *err = REG_ESIZE;
2590 return NULL; 2545 return NULL;
@@ -2593,28 +2548,28 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2593 else 2548 else
2594 { 2549 {
2595 start = (token->type == OP_DUP_PLUS) ? 1 : 0; 2550 start = (token->type == OP_DUP_PLUS) ? 1 : 0;
2596 end = (token->type == OP_DUP_QUESTION) ? 1 : REG_MISSING; 2551 end = (token->type == OP_DUP_QUESTION) ? 1 : -1;
2597 } 2552 }
2598 2553
2599 fetch_token (token, regexp, syntax); 2554 fetch_token (token, regexp, syntax);
2600 2555
2601 if (BE (elem == NULL, 0)) 2556 if (__glibc_unlikely (elem == NULL))
2602 return NULL; 2557 return NULL;
2603 if (BE (start == 0 && end == 0, 0)) 2558 if (__glibc_unlikely (start == 0 && end == 0))
2604 { 2559 {
2605 postorder (elem, free_tree, NULL); 2560 postorder (elem, free_tree, NULL);
2606 return NULL; 2561 return NULL;
2607 } 2562 }
2608 2563
2609 /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */ 2564 /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */
2610 if (BE (start > 0, 0)) 2565 if (__glibc_unlikely (start > 0))
2611 { 2566 {
2612 tree = elem; 2567 tree = elem;
2613 for (i = 2; i <= start; ++i) 2568 for (i = 2; i <= start; ++i)
2614 { 2569 {
2615 elem = duplicate_tree (elem, dfa); 2570 elem = duplicate_tree (elem, dfa);
2616 tree = create_tree (dfa, tree, elem, CONCAT); 2571 tree = create_tree (dfa, tree, elem, CONCAT);
2617 if (BE (elem == NULL || tree == NULL, 0)) 2572 if (__glibc_unlikely (elem == NULL || tree == NULL))
2618 goto parse_dup_op_espace; 2573 goto parse_dup_op_espace;
2619 } 2574 }
2620 2575
@@ -2623,6 +2578,8 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2623 2578
2624 /* Duplicate ELEM before it is marked optional. */ 2579 /* Duplicate ELEM before it is marked optional. */
2625 elem = duplicate_tree (elem, dfa); 2580 elem = duplicate_tree (elem, dfa);
2581 if (__glibc_unlikely (elem == NULL))
2582 goto parse_dup_op_espace;
2626 old_tree = tree; 2583 old_tree = tree;
2627 } 2584 }
2628 else 2585 else
@@ -2635,27 +2592,23 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2635 } 2592 }
2636 2593
2637 tree = create_tree (dfa, elem, NULL, 2594 tree = create_tree (dfa, elem, NULL,
2638 (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT)); 2595 (end == -1 ? OP_DUP_ASTERISK : OP_ALT));
2639 if (BE (tree == NULL, 0)) 2596 if (__glibc_unlikely (tree == NULL))
2640 goto parse_dup_op_espace; 2597 goto parse_dup_op_espace;
2641 2598
2642/* From gnulib's "intprops.h": 2599 /* This loop is actually executed only when end != -1,
2643 True if the arithmetic type T is signed. */
2644#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
2645
2646 /* This loop is actually executed only when end != REG_MISSING,
2647 to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have 2600 to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
2648 already created the start+1-th copy. */ 2601 already created the start+1-th copy. */
2649 if (TYPE_SIGNED (Idx) || end != REG_MISSING) 2602 if (TYPE_SIGNED (Idx) || end != -1)
2650 for (i = start + 2; i <= end; ++i) 2603 for (i = start + 2; i <= end; ++i)
2651 { 2604 {
2652 elem = duplicate_tree (elem, dfa); 2605 elem = duplicate_tree (elem, dfa);
2653 tree = create_tree (dfa, tree, elem, CONCAT); 2606 tree = create_tree (dfa, tree, elem, CONCAT);
2654 if (BE (elem == NULL || tree == NULL, 0)) 2607 if (__glibc_unlikely (elem == NULL || tree == NULL))
2655 goto parse_dup_op_espace; 2608 goto parse_dup_op_espace;
2656 2609
2657 tree = create_tree (dfa, tree, NULL, OP_ALT); 2610 tree = create_tree (dfa, tree, NULL, OP_ALT);
2658 if (BE (tree == NULL, 0)) 2611 if (__glibc_unlikely (tree == NULL))
2659 goto parse_dup_op_espace; 2612 goto parse_dup_op_espace;
2660 } 2613 }
2661 2614
@@ -2674,146 +2627,131 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2674#define BRACKET_NAME_BUF_SIZE 32 2627#define BRACKET_NAME_BUF_SIZE 32
2675 2628
2676#ifndef _LIBC 2629#ifndef _LIBC
2677 /* Local function for parse_bracket_exp only used in case of NOT _LIBC. 2630
2678 Build the range expression which starts from START_ELEM, and ends 2631/* Convert the byte B to the corresponding wide character. In a
2679 at END_ELEM. The result are written to MBCSET and SBCSET. 2632 unibyte locale, treat B as itself. In a multibyte locale, return
2680 RANGE_ALLOC is the allocated size of mbcset->range_starts, and 2633 WEOF if B is an encoding error. */
2681 mbcset->range_ends, is a pointer argument since we may 2634static wint_t
2682 update it. */ 2635parse_byte (unsigned char b, re_dfa_t const *dfa)
2636{
2637 return dfa->mb_cur_max > 1 ? __btowc (b) : b;
2638}
2639
2640/* Local function for parse_bracket_exp used in _LIBC environment.
2641 Build the range expression which starts from START_ELEM, and ends
2642 at END_ELEM. The result are written to MBCSET and SBCSET.
2643 RANGE_ALLOC is the allocated size of mbcset->range_starts, and
2644 mbcset->range_ends, is a pointer argument since we may
2645 update it. */
2683 2646
2684static reg_errcode_t 2647static reg_errcode_t
2685internal_function 2648build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc,
2686# ifdef RE_ENABLE_I18N 2649 bracket_elem_t *start_elem, bracket_elem_t *end_elem,
2687build_range_exp (const reg_syntax_t syntax, 2650 re_dfa_t *dfa, reg_syntax_t syntax, uint_fast32_t nrules,
2688 bitset_t sbcset, 2651 const unsigned char *collseqmb, const char *collseqwc,
2689 re_charset_t *mbcset, 2652 int_fast32_t table_size, const void *symb_table,
2690 Idx *range_alloc, 2653 const unsigned char *extra)
2691 const bracket_elem_t *start_elem,
2692 const bracket_elem_t *end_elem)
2693# else /* not RE_ENABLE_I18N */
2694build_range_exp (const reg_syntax_t syntax,
2695 bitset_t sbcset,
2696 const bracket_elem_t *start_elem,
2697 const bracket_elem_t *end_elem)
2698# endif /* not RE_ENABLE_I18N */
2699{ 2654{
2700 unsigned int start_ch, end_ch;
2701 /* Equivalence Classes and Character Classes can't be a range start/end. */ 2655 /* Equivalence Classes and Character Classes can't be a range start/end. */
2702 if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS 2656 if (__glibc_unlikely (start_elem->type == EQUIV_CLASS
2703 || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS, 2657 || start_elem->type == CHAR_CLASS
2704 0)) 2658 || end_elem->type == EQUIV_CLASS
2659 || end_elem->type == CHAR_CLASS))
2705 return REG_ERANGE; 2660 return REG_ERANGE;
2706 2661
2707 /* We can handle no multi character collating elements without libc 2662 /* We can handle no multi character collating elements without libc
2708 support. */ 2663 support. */
2709 if (BE ((start_elem->type == COLL_SYM 2664 if (__glibc_unlikely ((start_elem->type == COLL_SYM
2710 && strlen ((char *) start_elem->opr.name) > 1) 2665 && strlen ((char *) start_elem->opr.name) > 1)
2711 || (end_elem->type == COLL_SYM 2666 || (end_elem->type == COLL_SYM
2712 && strlen ((char *) end_elem->opr.name) > 1), 0)) 2667 && strlen ((char *) end_elem->opr.name) > 1)))
2713 return REG_ECOLLATE; 2668 return REG_ECOLLATE;
2714 2669
2715# ifdef RE_ENABLE_I18N 2670 unsigned int
2716 {
2717 wchar_t wc;
2718 wint_t start_wc;
2719 wint_t end_wc;
2720
2721 start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch 2671 start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
2722 : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0] 2672 : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
2723 : 0)); 2673 : 0)),
2724 end_ch = ((end_elem->type == SB_CHAR) ? end_elem->opr.ch 2674 end_ch = ((end_elem->type == SB_CHAR) ? end_elem->opr.ch
2725 : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0] 2675 : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
2726 : 0)); 2676 : 0));
2677 wint_t
2727 start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM) 2678 start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM)
2728 ? __btowc (start_ch) : start_elem->opr.wch); 2679 ? parse_byte (start_ch, dfa) : start_elem->opr.wch),
2729 end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM) 2680 end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM)
2730 ? __btowc (end_ch) : end_elem->opr.wch); 2681 ? parse_byte (end_ch, dfa) : end_elem->opr.wch);
2731 if (start_wc == WEOF || end_wc == WEOF)
2732 return REG_ECOLLATE;
2733 else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0))
2734 return REG_ERANGE;
2735
2736 /* Got valid collation sequence values, add them as a new entry.
2737 However, for !_LIBC we have no collation elements: if the
2738 character set is single byte, the single byte character set
2739 that we build below suffices. parse_bracket_exp passes
2740 no MBCSET if dfa->mb_cur_max == 1. */
2741 if (mbcset)
2742 {
2743 /* Check the space of the arrays. */
2744 if (BE (*range_alloc == mbcset->nranges, 0))
2745 {
2746 /* There is not enough space, need realloc. */
2747 wchar_t *new_array_start, *new_array_end;
2748 Idx new_nranges;
2749
2750 /* +1 in case of mbcset->nranges is 0. */
2751 new_nranges = 2 * mbcset->nranges + 1;
2752 /* Use realloc since mbcset->range_starts and mbcset->range_ends
2753 are NULL if *range_alloc == 0. */
2754 new_array_start = re_realloc (mbcset->range_starts, wchar_t,
2755 new_nranges);
2756 new_array_end = re_realloc (mbcset->range_ends, wchar_t,
2757 new_nranges);
2758 2682
2759 if (BE (new_array_start == NULL || new_array_end == NULL, 0)) 2683 if (start_wc == WEOF || end_wc == WEOF)
2760 return REG_ESPACE; 2684 return REG_ECOLLATE;
2685 else if (__glibc_unlikely ((syntax & RE_NO_EMPTY_RANGES)
2686 && start_wc > end_wc))
2687 return REG_ERANGE;
2761 2688
2762 mbcset->range_starts = new_array_start; 2689 /* Got valid collation sequence values, add them as a new entry.
2763 mbcset->range_ends = new_array_end; 2690 However, for !_LIBC we have no collation elements: if the
2764 *range_alloc = new_nranges; 2691 character set is single byte, the single byte character set
2765 } 2692 that we build below suffices. parse_bracket_exp passes
2693 no MBCSET if dfa->mb_cur_max == 1. */
2694 if (dfa->mb_cur_max > 1)
2695 {
2696 /* Check the space of the arrays. */
2697 if (__glibc_unlikely (*range_alloc == mbcset->nranges))
2698 {
2699 /* There is not enough space, need realloc. */
2700 wchar_t *new_array_start, *new_array_end;
2701 Idx new_nranges;
2766 2702
2767 mbcset->range_starts[mbcset->nranges] = start_wc; 2703 /* +1 in case of mbcset->nranges is 0. */
2768 mbcset->range_ends[mbcset->nranges++] = end_wc; 2704 new_nranges = 2 * mbcset->nranges + 1;
2769 } 2705 /* Use realloc since mbcset->range_starts and mbcset->range_ends
2706 are NULL if *range_alloc == 0. */
2707 new_array_start = re_realloc (mbcset->range_starts, wchar_t,
2708 new_nranges);
2709 new_array_end = re_realloc (mbcset->range_ends, wchar_t,
2710 new_nranges);
2711
2712 if (__glibc_unlikely (new_array_start == NULL
2713 || new_array_end == NULL))
2714 {
2715 re_free (new_array_start);
2716 re_free (new_array_end);
2717 return REG_ESPACE;
2718 }
2719
2720 mbcset->range_starts = new_array_start;
2721 mbcset->range_ends = new_array_end;
2722 *range_alloc = new_nranges;
2723 }
2724
2725 mbcset->range_starts[mbcset->nranges] = start_wc;
2726 mbcset->range_ends[mbcset->nranges++] = end_wc;
2727 }
2728
2729 /* Build the table for single byte characters. */
2730 for (wchar_t wc = 0; wc < SBC_MAX; ++wc)
2731 {
2732 if (start_wc <= wc && wc <= end_wc)
2733 bitset_set (sbcset, wc);
2734 }
2770 2735
2771 /* Build the table for single byte characters. */
2772 for (wc = 0; wc < SBC_MAX; ++wc)
2773 {
2774 if (start_wc <= wc && wc <= end_wc)
2775 bitset_set (sbcset, wc);
2776 }
2777 }
2778# else /* not RE_ENABLE_I18N */
2779 {
2780 unsigned int ch;
2781 start_ch = ((start_elem->type == SB_CHAR ) ? start_elem->opr.ch
2782 : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
2783 : 0));
2784 end_ch = ((end_elem->type == SB_CHAR ) ? end_elem->opr.ch
2785 : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
2786 : 0));
2787 if (start_ch > end_ch)
2788 return REG_ERANGE;
2789 /* Build the table for single byte characters. */
2790 for (ch = 0; ch < SBC_MAX; ++ch)
2791 if (start_ch <= ch && ch <= end_ch)
2792 bitset_set (sbcset, ch);
2793 }
2794# endif /* not RE_ENABLE_I18N */
2795 return REG_NOERROR; 2736 return REG_NOERROR;
2796} 2737}
2797#endif /* not _LIBC */ 2738#endif /* not _LIBC */
2798 2739
2799#ifndef _LIBC 2740#ifndef _LIBC
2800/* Helper function for parse_bracket_exp only used in case of NOT _LIBC.. 2741/* Helper function for parse_bracket_exp only used in case of NOT _LIBC.
2801 Build the collating element which is represented by NAME. 2742 Build the collating element which is represented by NAME.
2802 The result are written to MBCSET and SBCSET. 2743 The result are written to MBCSET and SBCSET.
2803 COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a 2744 COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
2804 pointer argument since we may update it. */ 2745 pointer argument since we may update it. */
2805 2746
2806static reg_errcode_t 2747static reg_errcode_t
2807internal_function
2808# ifdef RE_ENABLE_I18N
2809build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, 2748build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
2810 Idx *coll_sym_alloc, const unsigned char *name) 2749 Idx *coll_sym_alloc, const unsigned char *name,
2811# else /* not RE_ENABLE_I18N */ 2750 uint_fast32_t nrules, int_fast32_t table_size,
2812build_collating_symbol (bitset_t sbcset, const unsigned char *name) 2751 const void *symb_table, const unsigned char *extra)
2813# endif /* not RE_ENABLE_I18N */
2814{ 2752{
2815 size_t name_len = strlen ((const char *) name); 2753 size_t name_len = strlen ((const char *) name);
2816 if (BE (name_len != 1, 0)) 2754 if (__glibc_unlikely (name_len != 1))
2817 return REG_ECOLLATE; 2755 return REG_ECOLLATE;
2818 else 2756 else
2819 { 2757 {
@@ -2823,267 +2761,280 @@ build_collating_symbol (bitset_t sbcset, const unsigned char *name)
2823} 2761}
2824#endif /* not _LIBC */ 2762#endif /* not _LIBC */
2825 2763
2826/* This function parse bracket expression like "[abc]", "[a-c]",
2827 "[[.a-a.]]" etc. */
2828
2829static bin_tree_t *
2830parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2831 reg_syntax_t syntax, reg_errcode_t *err)
2832{
2833#ifdef _LIBC 2764#ifdef _LIBC
2834 const unsigned char *collseqmb; 2765/* Local function for parse_bracket_exp used in _LIBC environment.
2835 const char *collseqwc; 2766 Seek the collating symbol entry corresponding to NAME.
2836 uint32_t nrules; 2767 Return the index of the symbol in the SYMB_TABLE,
2837 int32_t table_size; 2768 or -1 if not found. */
2838 const int32_t *symb_table; 2769
2839 const unsigned char *extra; 2770static __always_inline int32_t
2840 2771seek_collating_symbol_entry (const unsigned char *name, size_t name_len,
2841 /* Local function for parse_bracket_exp used in _LIBC environment. 2772 const int32_t *symb_table,
2842 Seek the collating symbol entry corresponding to NAME. 2773 int_fast32_t table_size,
2843 Return the index of the symbol in the SYMB_TABLE, 2774 const unsigned char *extra)
2844 or -1 if not found. */ 2775{
2845 2776 int_fast32_t elem;
2846 auto inline int32_t
2847 __attribute__ ((always_inline))
2848 seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
2849 {
2850 int32_t elem;
2851
2852 for (elem = 0; elem < table_size; elem++)
2853 if (symb_table[2 * elem] != 0)
2854 {
2855 int32_t idx = symb_table[2 * elem + 1];
2856 /* Skip the name of collating element name. */
2857 idx += 1 + extra[idx];
2858 if (/* Compare the length of the name. */
2859 name_len == extra[idx]
2860 /* Compare the name. */
2861 && memcmp (name, &extra[idx + 1], name_len) == 0)
2862 /* Yep, this is the entry. */
2863 return elem;
2864 }
2865 return -1;
2866 }
2867 2777
2868 /* Local function for parse_bracket_exp used in _LIBC environment. 2778 for (elem = 0; elem < table_size; elem++)
2869 Look up the collation sequence value of BR_ELEM. 2779 if (symb_table[2 * elem] != 0)
2870 Return the value if succeeded, UINT_MAX otherwise. */ 2780 {
2781 int32_t idx = symb_table[2 * elem + 1];
2782 /* Skip the name of collating element name. */
2783 idx += 1 + extra[idx];
2784 if (/* Compare the length of the name. */
2785 name_len == extra[idx]
2786 /* Compare the name. */
2787 && memcmp (name, &extra[idx + 1], name_len) == 0)
2788 /* Yep, this is the entry. */
2789 return elem;
2790 }
2791 return -1;
2792}
2871 2793
2872 auto inline unsigned int 2794/* Local function for parse_bracket_exp used in _LIBC environment.
2873 __attribute__ ((always_inline)) 2795 Look up the collation sequence value of BR_ELEM.
2874 lookup_collation_sequence_value (bracket_elem_t *br_elem) 2796 Return the value if succeeded, UINT_MAX otherwise. */
2797
2798static __always_inline unsigned int
2799lookup_collation_sequence_value (bracket_elem_t *br_elem, uint32_t nrules,
2800 const unsigned char *collseqmb,
2801 const char *collseqwc,
2802 int_fast32_t table_size,
2803 const int32_t *symb_table,
2804 const unsigned char *extra)
2805{
2806 if (br_elem->type == SB_CHAR)
2875 { 2807 {
2876 if (br_elem->type == SB_CHAR) 2808 /* if (MB_CUR_MAX == 1) */
2877 { 2809 if (nrules == 0)
2878 /* 2810 return collseqmb[br_elem->opr.ch];
2879 if (MB_CUR_MAX == 1) 2811 else
2880 */
2881 if (nrules == 0)
2882 return collseqmb[br_elem->opr.ch];
2883 else
2884 {
2885 wint_t wc = __btowc (br_elem->opr.ch);
2886 return __collseq_table_lookup (collseqwc, wc);
2887 }
2888 }
2889 else if (br_elem->type == MB_CHAR)
2890 { 2812 {
2891 if (nrules != 0) 2813 wint_t wc = __btowc (br_elem->opr.ch);
2892 return __collseq_table_lookup (collseqwc, br_elem->opr.wch); 2814 return __collseq_table_lookup (collseqwc, wc);
2893 } 2815 }
2894 else if (br_elem->type == COLL_SYM) 2816 }
2817 else if (br_elem->type == MB_CHAR)
2818 {
2819 if (nrules != 0)
2820 return __collseq_table_lookup (collseqwc, br_elem->opr.wch);
2821 }
2822 else if (br_elem->type == COLL_SYM)
2823 {
2824 size_t sym_name_len = strlen ((char *) br_elem->opr.name);
2825 if (nrules != 0)
2895 { 2826 {
2896 size_t sym_name_len = strlen ((char *) br_elem->opr.name); 2827 int32_t elem, idx;
2897 if (nrules != 0) 2828 elem = seek_collating_symbol_entry (br_elem->opr.name,
2829 sym_name_len,
2830 symb_table, table_size,
2831 extra);
2832 if (elem != -1)
2898 { 2833 {
2899 int32_t elem, idx; 2834 /* We found the entry. */
2900 elem = seek_collating_symbol_entry (br_elem->opr.name, 2835 idx = symb_table[2 * elem + 1];
2901 sym_name_len); 2836 /* Skip the name of collating element name. */
2902 if (elem != -1) 2837 idx += 1 + extra[idx];
2903 { 2838 /* Skip the byte sequence of the collating element. */
2904 /* We found the entry. */ 2839 idx += 1 + extra[idx];
2905 idx = symb_table[2 * elem + 1]; 2840 /* Adjust for the alignment. */
2906 /* Skip the name of collating element name. */ 2841 idx = (idx + 3) & ~3;
2907 idx += 1 + extra[idx]; 2842 /* Skip the multibyte collation sequence value. */
2908 /* Skip the byte sequence of the collating element. */ 2843 idx += sizeof (unsigned int);
2909 idx += 1 + extra[idx]; 2844 /* Skip the wide char sequence of the collating element. */
2910 /* Adjust for the alignment. */ 2845 idx += sizeof (unsigned int) *
2911 idx = (idx + 3) & ~3; 2846 (1 + *(unsigned int *) (extra + idx));
2912 /* Skip the multibyte collation sequence value. */ 2847 /* Return the collation sequence value. */
2913 idx += sizeof (unsigned int); 2848 return *(unsigned int *) (extra + idx);
2914 /* Skip the wide char sequence of the collating element. */
2915 idx += sizeof (unsigned int) *
2916 (1 + *(unsigned int *) (extra + idx));
2917 /* Return the collation sequence value. */
2918 return *(unsigned int *) (extra + idx);
2919 }
2920 else if (sym_name_len == 1)
2921 {
2922 /* No valid character. Match it as a single byte
2923 character. */
2924 return collseqmb[br_elem->opr.name[0]];
2925 }
2926 } 2849 }
2927 else if (sym_name_len == 1) 2850 else if (sym_name_len == 1)
2928 return collseqmb[br_elem->opr.name[0]]; 2851 {
2852 /* No valid character. Match it as a single byte
2853 character. */
2854 return collseqmb[br_elem->opr.name[0]];
2855 }
2929 } 2856 }
2930 return UINT_MAX; 2857 else if (sym_name_len == 1)
2858 return collseqmb[br_elem->opr.name[0]];
2931 } 2859 }
2860 return UINT_MAX;
2861}
2932 2862
2933 /* Local function for parse_bracket_exp used in _LIBC environment. 2863/* Local function for parse_bracket_exp used in _LIBC environment.
2934 Build the range expression which starts from START_ELEM, and ends 2864 Build the range expression which starts from START_ELEM, and ends
2935 at END_ELEM. The result are written to MBCSET and SBCSET. 2865 at END_ELEM. The result are written to MBCSET and SBCSET.
2936 RANGE_ALLOC is the allocated size of mbcset->range_starts, and 2866 RANGE_ALLOC is the allocated size of mbcset->range_starts, and
2937 mbcset->range_ends, is a pointer argument since we may 2867 mbcset->range_ends, is a pointer argument since we may
2938 update it. */ 2868 update it. */
2939 2869
2940 auto inline reg_errcode_t 2870static __always_inline reg_errcode_t
2941 __attribute__ ((always_inline)) 2871build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc,
2942 build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc, 2872 bracket_elem_t *start_elem, bracket_elem_t *end_elem,
2943 bracket_elem_t *start_elem, bracket_elem_t *end_elem) 2873 re_dfa_t *dfa, reg_syntax_t syntax, uint32_t nrules,
2944 { 2874 const unsigned char *collseqmb, const char *collseqwc,
2945 unsigned int ch; 2875 int_fast32_t table_size, const int32_t *symb_table,
2946 uint32_t start_collseq; 2876 const unsigned char *extra)
2947 uint32_t end_collseq; 2877{
2948 2878 unsigned int ch;
2949 /* Equivalence Classes and Character Classes can't be a range 2879 uint32_t start_collseq;
2950 start/end. */ 2880 uint32_t end_collseq;
2951 if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS 2881
2952 || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS, 2882 /* Equivalence Classes and Character Classes can't be a range
2953 0)) 2883 start/end. */
2954 return REG_ERANGE; 2884 if (__glibc_unlikely (start_elem->type == EQUIV_CLASS
2885 || start_elem->type == CHAR_CLASS
2886 || end_elem->type == EQUIV_CLASS
2887 || end_elem->type == CHAR_CLASS))
2888 return REG_ERANGE;
2955 2889
2956 /* FIXME: Implement rational ranges here, too. */ 2890 /* FIXME: Implement rational ranges here, too. */
2957 start_collseq = lookup_collation_sequence_value (start_elem); 2891 start_collseq = lookup_collation_sequence_value (start_elem, nrules, collseqmb, collseqwc,
2958 end_collseq = lookup_collation_sequence_value (end_elem); 2892 table_size, symb_table, extra);
2959 /* Check start/end collation sequence values. */ 2893 end_collseq = lookup_collation_sequence_value (end_elem, nrules, collseqmb, collseqwc,
2960 if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0)) 2894 table_size, symb_table, extra);
2961 return REG_ECOLLATE; 2895 /* Check start/end collation sequence values. */
2962 if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) 2896 if (__glibc_unlikely (start_collseq == UINT_MAX
2963 return REG_ERANGE; 2897 || end_collseq == UINT_MAX))
2898 return REG_ECOLLATE;
2899 if (__glibc_unlikely ((syntax & RE_NO_EMPTY_RANGES)
2900 && start_collseq > end_collseq))
2901 return REG_ERANGE;
2964 2902
2965 /* Got valid collation sequence values, add them as a new entry. 2903 /* Got valid collation sequence values, add them as a new entry.
2966 However, if we have no collation elements, and the character set 2904 However, if we have no collation elements, and the character set
2967 is single byte, the single byte character set that we 2905 is single byte, the single byte character set that we
2968 build below suffices. */ 2906 build below suffices. */
2969 if (nrules > 0 || dfa->mb_cur_max > 1) 2907 if (nrules > 0 || dfa->mb_cur_max > 1)
2908 {
2909 /* Check the space of the arrays. */
2910 if (__glibc_unlikely (*range_alloc == mbcset->nranges))
2970 { 2911 {
2971 /* Check the space of the arrays. */ 2912 /* There is not enough space, need realloc. */
2972 if (BE (*range_alloc == mbcset->nranges, 0)) 2913 uint32_t *new_array_start;
2973 { 2914 uint32_t *new_array_end;
2974 /* There is not enough space, need realloc. */ 2915 int new_nranges;
2975 uint32_t *new_array_start;
2976 uint32_t *new_array_end;
2977 Idx new_nranges;
2978
2979 /* +1 in case of mbcset->nranges is 0. */
2980 new_nranges = 2 * mbcset->nranges + 1;
2981 new_array_start = re_realloc (mbcset->range_starts, uint32_t,
2982 new_nranges);
2983 new_array_end = re_realloc (mbcset->range_ends, uint32_t,
2984 new_nranges);
2985
2986 if (BE (new_array_start == NULL || new_array_end == NULL, 0))
2987 return REG_ESPACE;
2988 2916
2989 mbcset->range_starts = new_array_start; 2917 /* +1 in case of mbcset->nranges is 0. */
2990 mbcset->range_ends = new_array_end; 2918 new_nranges = 2 * mbcset->nranges + 1;
2991 *range_alloc = new_nranges; 2919 new_array_start = re_realloc (mbcset->range_starts, uint32_t,
2992 } 2920 new_nranges);
2921 new_array_end = re_realloc (mbcset->range_ends, uint32_t,
2922 new_nranges);
2993 2923
2994 mbcset->range_starts[mbcset->nranges] = start_collseq; 2924 if (__glibc_unlikely (new_array_start == NULL
2995 mbcset->range_ends[mbcset->nranges++] = end_collseq; 2925 || new_array_end == NULL))
2996 } 2926 return REG_ESPACE;
2997 2927
2998 /* Build the table for single byte characters. */ 2928 mbcset->range_starts = new_array_start;
2999 for (ch = 0; ch < SBC_MAX; ch++) 2929 mbcset->range_ends = new_array_end;
3000 { 2930 *range_alloc = new_nranges;
3001 uint32_t ch_collseq;
3002 /*
3003 if (MB_CUR_MAX == 1)
3004 */
3005 if (nrules == 0)
3006 ch_collseq = collseqmb[ch];
3007 else
3008 ch_collseq = __collseq_table_lookup (collseqwc, __btowc (ch));
3009 if (start_collseq <= ch_collseq && ch_collseq <= end_collseq)
3010 bitset_set (sbcset, ch);
3011 } 2931 }
3012 return REG_NOERROR; 2932
2933 mbcset->range_starts[mbcset->nranges] = start_collseq;
2934 mbcset->range_ends[mbcset->nranges++] = end_collseq;
3013 } 2935 }
3014 2936
3015 /* Local function for parse_bracket_exp used in _LIBC environment. 2937 /* Build the table for single byte characters. */
3016 Build the collating element which is represented by NAME. 2938 for (ch = 0; ch < SBC_MAX; ch++)
3017 The result are written to MBCSET and SBCSET. 2939 {
3018 COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a 2940 uint32_t ch_collseq;
3019 pointer argument since we may update it. */ 2941 /* if (MB_CUR_MAX == 1) */
2942 if (nrules == 0)
2943 ch_collseq = collseqmb[ch];
2944 else
2945 ch_collseq = __collseq_table_lookup (collseqwc, __btowc (ch));
2946 if (start_collseq <= ch_collseq && ch_collseq <= end_collseq)
2947 bitset_set (sbcset, ch);
2948 }
2949 return REG_NOERROR;
2950}
3020 2951
3021 auto inline reg_errcode_t 2952/* Local function for parse_bracket_exp used in _LIBC environment.
3022 __attribute__ ((always_inline)) 2953 Build the collating element which is represented by NAME.
3023 build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, 2954 The result are written to MBCSET and SBCSET.
3024 Idx *coll_sym_alloc, const unsigned char *name) 2955 COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
2956 pointer argument since we may update it. */
2957
2958static __always_inline reg_errcode_t
2959build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
2960 Idx *coll_sym_alloc, const unsigned char *name,
2961 uint_fast32_t nrules, int_fast32_t table_size,
2962 const int32_t *symb_table, const unsigned char *extra)
2963{
2964 int32_t elem, idx;
2965 size_t name_len = strlen ((const char *) name);
2966 if (nrules != 0)
3025 { 2967 {
3026 int32_t elem, idx; 2968 elem = seek_collating_symbol_entry (name, name_len, symb_table,
3027 size_t name_len = strlen ((const char *) name); 2969 table_size, extra);
3028 if (nrules != 0) 2970 if (elem != -1)
3029 { 2971 {
3030 elem = seek_collating_symbol_entry (name, name_len); 2972 /* We found the entry. */
3031 if (elem != -1) 2973 idx = symb_table[2 * elem + 1];
3032 { 2974 /* Skip the name of collating element name. */
3033 /* We found the entry. */ 2975 idx += 1 + extra[idx];
3034 idx = symb_table[2 * elem + 1]; 2976 }
3035 /* Skip the name of collating element name. */ 2977 else if (name_len == 1)
3036 idx += 1 + extra[idx]; 2978 {
3037 } 2979 /* No valid character, treat it as a normal
3038 else if (name_len == 1) 2980 character. */
3039 { 2981 bitset_set (sbcset, name[0]);
3040 /* No valid character, treat it as a normal
3041 character. */
3042 bitset_set (sbcset, name[0]);
3043 return REG_NOERROR;
3044 }
3045 else
3046 return REG_ECOLLATE;
3047
3048 /* Got valid collation sequence, add it as a new entry. */
3049 /* Check the space of the arrays. */
3050 if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0))
3051 {
3052 /* Not enough, realloc it. */
3053 /* +1 in case of mbcset->ncoll_syms is 0. */
3054 Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
3055 /* Use realloc since mbcset->coll_syms is NULL
3056 if *alloc == 0. */
3057 int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
3058 new_coll_sym_alloc);
3059 if (BE (new_coll_syms == NULL, 0))
3060 return REG_ESPACE;
3061 mbcset->coll_syms = new_coll_syms;
3062 *coll_sym_alloc = new_coll_sym_alloc;
3063 }
3064 mbcset->coll_syms[mbcset->ncoll_syms++] = idx;
3065 return REG_NOERROR; 2982 return REG_NOERROR;
3066 } 2983 }
3067 else 2984 else
2985 return REG_ECOLLATE;
2986
2987 /* Got valid collation sequence, add it as a new entry. */
2988 /* Check the space of the arrays. */
2989 if (__glibc_unlikely (*coll_sym_alloc == mbcset->ncoll_syms))
3068 { 2990 {
3069 if (BE (name_len != 1, 0)) 2991 /* Not enough, realloc it. */
3070 return REG_ECOLLATE; 2992 /* +1 in case of mbcset->ncoll_syms is 0. */
3071 else 2993 int new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
3072 { 2994 /* Use realloc since mbcset->coll_syms is NULL
3073 bitset_set (sbcset, name[0]); 2995 if *alloc == 0. */
3074 return REG_NOERROR; 2996 int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
3075 } 2997 new_coll_sym_alloc);
2998 if (__glibc_unlikely (new_coll_syms == NULL))
2999 return REG_ESPACE;
3000 mbcset->coll_syms = new_coll_syms;
3001 *coll_sym_alloc = new_coll_sym_alloc;
3076 } 3002 }
3003 mbcset->coll_syms[mbcset->ncoll_syms++] = idx;
3004 return REG_NOERROR;
3077 } 3005 }
3078#endif 3006 else
3007 {
3008 if (__glibc_unlikely (name_len != 1))
3009 return REG_ECOLLATE;
3010 else
3011 {
3012 bitset_set (sbcset, name[0]);
3013 return REG_NOERROR;
3014 }
3015 }
3016}
3017#endif /* _LIBC */
3018
3019/* This function parse bracket expression like "[abc]", "[a-c]",
3020 "[[.a-a.]]" etc. */
3021
3022static bin_tree_t *
3023parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3024 reg_syntax_t syntax, reg_errcode_t *err)
3025{
3026 const unsigned char *collseqmb = NULL;
3027 const char *collseqwc = NULL;
3028 uint_fast32_t nrules = 0;
3029 int_fast32_t table_size = 0;
3030 const void *symb_table = NULL;
3031 const unsigned char *extra = NULL;
3079 3032
3080 re_token_t br_token; 3033 re_token_t br_token;
3081 re_bitset_ptr_t sbcset; 3034 re_bitset_ptr_t sbcset;
3082#ifdef RE_ENABLE_I18N
3083 re_charset_t *mbcset; 3035 re_charset_t *mbcset;
3084 Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0; 3036 Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
3085 Idx equiv_class_alloc = 0, char_class_alloc = 0; 3037 Idx equiv_class_alloc = 0, char_class_alloc = 0;
3086#endif /* not RE_ENABLE_I18N */
3087 bool non_match = false; 3038 bool non_match = false;
3088 bin_tree_t *work_tree; 3039 bin_tree_t *work_tree;
3089 int token_len; 3040 int token_len;
@@ -3099,47 +3050,36 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3099 */ 3050 */
3100 collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); 3051 collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
3101 table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB); 3052 table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB);
3102 symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE, 3053 symb_table = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_TABLEMB);
3103 _NL_COLLATE_SYMB_TABLEMB);
3104 extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE, 3054 extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
3105 _NL_COLLATE_SYMB_EXTRAMB); 3055 _NL_COLLATE_SYMB_EXTRAMB);
3106 } 3056 }
3107#endif 3057#endif
3108 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 3058 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
3109#ifdef RE_ENABLE_I18N
3110 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); 3059 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3111#endif /* RE_ENABLE_I18N */ 3060 if (__glibc_unlikely (sbcset == NULL || mbcset == NULL))
3112#ifdef RE_ENABLE_I18N
3113 if (BE (sbcset == NULL || mbcset == NULL, 0))
3114#else
3115 if (BE (sbcset == NULL, 0))
3116#endif /* RE_ENABLE_I18N */
3117 { 3061 {
3118 re_free (sbcset); 3062 re_free (sbcset);
3119#ifdef RE_ENABLE_I18N
3120 re_free (mbcset); 3063 re_free (mbcset);
3121#endif
3122 *err = REG_ESPACE; 3064 *err = REG_ESPACE;
3123 return NULL; 3065 return NULL;
3124 } 3066 }
3125 3067
3126 token_len = peek_token_bracket (token, regexp, syntax); 3068 token_len = peek_token_bracket (token, regexp, syntax);
3127 if (BE (token->type == END_OF_RE, 0)) 3069 if (__glibc_unlikely (token->type == END_OF_RE))
3128 { 3070 {
3129 *err = REG_BADPAT; 3071 *err = REG_BADPAT;
3130 goto parse_bracket_exp_free_return; 3072 goto parse_bracket_exp_free_return;
3131 } 3073 }
3132 if (token->type == OP_NON_MATCH_LIST) 3074 if (token->type == OP_NON_MATCH_LIST)
3133 { 3075 {
3134#ifdef RE_ENABLE_I18N
3135 mbcset->non_match = 1; 3076 mbcset->non_match = 1;
3136#endif /* not RE_ENABLE_I18N */
3137 non_match = true; 3077 non_match = true;
3138 if (syntax & RE_HAT_LISTS_NOT_NEWLINE) 3078 if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
3139 bitset_set (sbcset, '\n'); 3079 bitset_set (sbcset, '\n');
3140 re_string_skip_bytes (regexp, token_len); /* Skip a token. */ 3080 re_string_skip_bytes (regexp, token_len); /* Skip a token. */
3141 token_len = peek_token_bracket (token, regexp, syntax); 3081 token_len = peek_token_bracket (token, regexp, syntax);
3142 if (BE (token->type == END_OF_RE, 0)) 3082 if (__glibc_unlikely (token->type == END_OF_RE))
3143 { 3083 {
3144 *err = REG_BADPAT; 3084 *err = REG_BADPAT;
3145 goto parse_bracket_exp_free_return; 3085 goto parse_bracket_exp_free_return;
@@ -3161,9 +3101,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3161 re_token_t token2; 3101 re_token_t token2;
3162 3102
3163 start_elem.opr.name = start_name_buf; 3103 start_elem.opr.name = start_name_buf;
3104 start_elem.type = COLL_SYM;
3164 ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa, 3105 ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa,
3165 syntax, first_round); 3106 syntax, first_round);
3166 if (BE (ret != REG_NOERROR, 0)) 3107 if (__glibc_unlikely (ret != REG_NOERROR))
3167 { 3108 {
3168 *err = ret; 3109 *err = ret;
3169 goto parse_bracket_exp_free_return; 3110 goto parse_bracket_exp_free_return;
@@ -3176,7 +3117,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3176 /* Do not check for ranges if we know they are not allowed. */ 3117 /* Do not check for ranges if we know they are not allowed. */
3177 if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS) 3118 if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS)
3178 { 3119 {
3179 if (BE (token->type == END_OF_RE, 0)) 3120 if (__glibc_unlikely (token->type == END_OF_RE))
3180 { 3121 {
3181 *err = REG_EBRACK; 3122 *err = REG_EBRACK;
3182 goto parse_bracket_exp_free_return; 3123 goto parse_bracket_exp_free_return;
@@ -3185,7 +3126,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3185 { 3126 {
3186 re_string_skip_bytes (regexp, token_len); /* Skip '-'. */ 3127 re_string_skip_bytes (regexp, token_len); /* Skip '-'. */
3187 token_len2 = peek_token_bracket (&token2, regexp, syntax); 3128 token_len2 = peek_token_bracket (&token2, regexp, syntax);
3188 if (BE (token2.type == END_OF_RE, 0)) 3129 if (__glibc_unlikely (token2.type == END_OF_RE))
3189 { 3130 {
3190 *err = REG_EBRACK; 3131 *err = REG_EBRACK;
3191 goto parse_bracket_exp_free_return; 3132 goto parse_bracket_exp_free_return;
@@ -3204,9 +3145,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3204 if (is_range_exp == true) 3145 if (is_range_exp == true)
3205 { 3146 {
3206 end_elem.opr.name = end_name_buf; 3147 end_elem.opr.name = end_name_buf;
3148 end_elem.type = COLL_SYM;
3207 ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2, 3149 ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
3208 dfa, syntax, true); 3150 dfa, syntax, true);
3209 if (BE (ret != REG_NOERROR, 0)) 3151 if (__glibc_unlikely (ret != REG_NOERROR))
3210 { 3152 {
3211 *err = ret; 3153 *err = ret;
3212 goto parse_bracket_exp_free_return; 3154 goto parse_bracket_exp_free_return;
@@ -3214,19 +3156,11 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3214 3156
3215 token_len = peek_token_bracket (token, regexp, syntax); 3157 token_len = peek_token_bracket (token, regexp, syntax);
3216 3158
3217#ifdef _LIBC
3218 *err = build_range_exp (sbcset, mbcset, &range_alloc, 3159 *err = build_range_exp (sbcset, mbcset, &range_alloc,
3219 &start_elem, &end_elem); 3160 &start_elem, &end_elem,
3220#else 3161 dfa, syntax, nrules, collseqmb, collseqwc,
3221# ifdef RE_ENABLE_I18N 3162 table_size, symb_table, extra);
3222 *err = build_range_exp (syntax, sbcset, 3163 if (__glibc_unlikely (*err != REG_NOERROR))
3223 dfa->mb_cur_max > 1 ? mbcset : NULL,
3224 &range_alloc, &start_elem, &end_elem);
3225# else
3226 *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
3227# endif
3228#endif /* RE_ENABLE_I18N */
3229 if (BE (*err != REG_NOERROR, 0))
3230 goto parse_bracket_exp_free_return; 3164 goto parse_bracket_exp_free_return;
3231 } 3165 }
3232 else 3166 else
@@ -3236,10 +3170,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3236 case SB_CHAR: 3170 case SB_CHAR:
3237 bitset_set (sbcset, start_elem.opr.ch); 3171 bitset_set (sbcset, start_elem.opr.ch);
3238 break; 3172 break;
3239#ifdef RE_ENABLE_I18N
3240 case MB_CHAR: 3173 case MB_CHAR:
3241 /* Check whether the array has enough space. */ 3174 /* Check whether the array has enough space. */
3242 if (BE (mbchar_alloc == mbcset->nmbchars, 0)) 3175 if (__glibc_unlikely (mbchar_alloc == mbcset->nmbchars))
3243 { 3176 {
3244 wchar_t *new_mbchars; 3177 wchar_t *new_mbchars;
3245 /* Not enough, realloc it. */ 3178 /* Not enough, realloc it. */
@@ -3248,47 +3181,41 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3248 /* Use realloc since array is NULL if *alloc == 0. */ 3181 /* Use realloc since array is NULL if *alloc == 0. */
3249 new_mbchars = re_realloc (mbcset->mbchars, wchar_t, 3182 new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
3250 mbchar_alloc); 3183 mbchar_alloc);
3251 if (BE (new_mbchars == NULL, 0)) 3184 if (__glibc_unlikely (new_mbchars == NULL))
3252 goto parse_bracket_exp_espace; 3185 goto parse_bracket_exp_espace;
3253 mbcset->mbchars = new_mbchars; 3186 mbcset->mbchars = new_mbchars;
3254 } 3187 }
3255 mbcset->mbchars[mbcset->nmbchars++] = start_elem.opr.wch; 3188 mbcset->mbchars[mbcset->nmbchars++] = start_elem.opr.wch;
3256 break; 3189 break;
3257#endif /* RE_ENABLE_I18N */
3258 case EQUIV_CLASS: 3190 case EQUIV_CLASS:
3259 *err = build_equiv_class (sbcset, 3191 *err = build_equiv_class (sbcset,
3260#ifdef RE_ENABLE_I18N
3261 mbcset, &equiv_class_alloc, 3192 mbcset, &equiv_class_alloc,
3262#endif /* RE_ENABLE_I18N */
3263 start_elem.opr.name); 3193 start_elem.opr.name);
3264 if (BE (*err != REG_NOERROR, 0)) 3194 if (__glibc_unlikely (*err != REG_NOERROR))
3265 goto parse_bracket_exp_free_return; 3195 goto parse_bracket_exp_free_return;
3266 break; 3196 break;
3267 case COLL_SYM: 3197 case COLL_SYM:
3268 *err = build_collating_symbol (sbcset, 3198 *err = build_collating_symbol (sbcset,
3269#ifdef RE_ENABLE_I18N
3270 mbcset, &coll_sym_alloc, 3199 mbcset, &coll_sym_alloc,
3271#endif /* RE_ENABLE_I18N */ 3200 start_elem.opr.name,
3272 start_elem.opr.name); 3201 nrules, table_size, symb_table, extra);
3273 if (BE (*err != REG_NOERROR, 0)) 3202 if (__glibc_unlikely (*err != REG_NOERROR))
3274 goto parse_bracket_exp_free_return; 3203 goto parse_bracket_exp_free_return;
3275 break; 3204 break;
3276 case CHAR_CLASS: 3205 case CHAR_CLASS:
3277 *err = build_charclass (regexp->trans, sbcset, 3206 *err = build_charclass (regexp->trans, sbcset,
3278#ifdef RE_ENABLE_I18N
3279 mbcset, &char_class_alloc, 3207 mbcset, &char_class_alloc,
3280#endif /* RE_ENABLE_I18N */
3281 (const char *) start_elem.opr.name, 3208 (const char *) start_elem.opr.name,
3282 syntax); 3209 syntax);
3283 if (BE (*err != REG_NOERROR, 0)) 3210 if (__glibc_unlikely (*err != REG_NOERROR))
3284 goto parse_bracket_exp_free_return; 3211 goto parse_bracket_exp_free_return;
3285 break; 3212 break;
3286 default: 3213 default:
3287 assert (0); 3214 DEBUG_ASSERT (false);
3288 break; 3215 break;
3289 } 3216 }
3290 } 3217 }
3291 if (BE (token->type == END_OF_RE, 0)) 3218 if (__glibc_unlikely (token->type == END_OF_RE))
3292 { 3219 {
3293 *err = REG_EBRACK; 3220 *err = REG_EBRACK;
3294 goto parse_bracket_exp_free_return; 3221 goto parse_bracket_exp_free_return;
@@ -3303,7 +3230,6 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3303 if (non_match) 3230 if (non_match)
3304 bitset_not (sbcset); 3231 bitset_not (sbcset);
3305 3232
3306#ifdef RE_ENABLE_I18N
3307 /* Ensure only single byte characters are set. */ 3233 /* Ensure only single byte characters are set. */
3308 if (dfa->mb_cur_max > 1) 3234 if (dfa->mb_cur_max > 1)
3309 bitset_mask (sbcset, dfa->sb_char); 3235 bitset_mask (sbcset, dfa->sb_char);
@@ -3319,7 +3245,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3319 br_token.type = COMPLEX_BRACKET; 3245 br_token.type = COMPLEX_BRACKET;
3320 br_token.opr.mbcset = mbcset; 3246 br_token.opr.mbcset = mbcset;
3321 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3247 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3322 if (BE (mbc_tree == NULL, 0)) 3248 if (__glibc_unlikely (mbc_tree == NULL))
3323 goto parse_bracket_exp_espace; 3249 goto parse_bracket_exp_espace;
3324 for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx) 3250 for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx)
3325 if (sbcset[sbc_idx]) 3251 if (sbcset[sbc_idx])
@@ -3332,12 +3258,12 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3332 br_token.type = SIMPLE_BRACKET; 3258 br_token.type = SIMPLE_BRACKET;
3333 br_token.opr.sbcset = sbcset; 3259 br_token.opr.sbcset = sbcset;
3334 work_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3260 work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3335 if (BE (work_tree == NULL, 0)) 3261 if (__glibc_unlikely (work_tree == NULL))
3336 goto parse_bracket_exp_espace; 3262 goto parse_bracket_exp_espace;
3337 3263
3338 /* Then join them by ALT node. */ 3264 /* Then join them by ALT node. */
3339 work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT); 3265 work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT);
3340 if (BE (work_tree == NULL, 0)) 3266 if (__glibc_unlikely (work_tree == NULL))
3341 goto parse_bracket_exp_espace; 3267 goto parse_bracket_exp_espace;
3342 } 3268 }
3343 else 3269 else
@@ -3347,16 +3273,13 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3347 } 3273 }
3348 } 3274 }
3349 else 3275 else
3350#endif /* not RE_ENABLE_I18N */
3351 { 3276 {
3352#ifdef RE_ENABLE_I18N
3353 free_charset (mbcset); 3277 free_charset (mbcset);
3354#endif
3355 /* Build a tree for simple bracket. */ 3278 /* Build a tree for simple bracket. */
3356 br_token.type = SIMPLE_BRACKET; 3279 br_token.type = SIMPLE_BRACKET;
3357 br_token.opr.sbcset = sbcset; 3280 br_token.opr.sbcset = sbcset;
3358 work_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3281 work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3359 if (BE (work_tree == NULL, 0)) 3282 if (__glibc_unlikely (work_tree == NULL))
3360 goto parse_bracket_exp_espace; 3283 goto parse_bracket_exp_espace;
3361 } 3284 }
3362 return work_tree; 3285 return work_tree;
@@ -3365,9 +3288,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3365 *err = REG_ESPACE; 3288 *err = REG_ESPACE;
3366 parse_bracket_exp_free_return: 3289 parse_bracket_exp_free_return:
3367 re_free (sbcset); 3290 re_free (sbcset);
3368#ifdef RE_ENABLE_I18N
3369 free_charset (mbcset); 3291 free_charset (mbcset);
3370#endif /* RE_ENABLE_I18N */
3371 return NULL; 3292 return NULL;
3372} 3293}
3373 3294
@@ -3378,7 +3299,6 @@ parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
3378 re_token_t *token, int token_len, re_dfa_t *dfa, 3299 re_token_t *token, int token_len, re_dfa_t *dfa,
3379 reg_syntax_t syntax, bool accept_hyphen) 3300 reg_syntax_t syntax, bool accept_hyphen)
3380{ 3301{
3381#ifdef RE_ENABLE_I18N
3382 int cur_char_size; 3302 int cur_char_size;
3383 cur_char_size = re_string_char_size_at (regexp, re_string_cur_idx (regexp)); 3303 cur_char_size = re_string_char_size_at (regexp, re_string_cur_idx (regexp));
3384 if (cur_char_size > 1) 3304 if (cur_char_size > 1)
@@ -3388,12 +3308,11 @@ parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
3388 re_string_skip_bytes (regexp, cur_char_size); 3308 re_string_skip_bytes (regexp, cur_char_size);
3389 return REG_NOERROR; 3309 return REG_NOERROR;
3390 } 3310 }
3391#endif /* RE_ENABLE_I18N */
3392 re_string_skip_bytes (regexp, token_len); /* Skip a token. */ 3311 re_string_skip_bytes (regexp, token_len); /* Skip a token. */
3393 if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS 3312 if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS
3394 || token->type == OP_OPEN_EQUIV_CLASS) 3313 || token->type == OP_OPEN_EQUIV_CLASS)
3395 return parse_bracket_symbol (elem, regexp, token); 3314 return parse_bracket_symbol (elem, regexp, token);
3396 if (BE (token->type == OP_CHARSET_RANGE, 0) && !accept_hyphen) 3315 if (__glibc_unlikely (token->type == OP_CHARSET_RANGE) && !accept_hyphen)
3397 { 3316 {
3398 /* A '-' must only appear as anything but a range indicator before 3317 /* A '-' must only appear as anything but a range indicator before
3399 the closing bracket. Everything else is an error. */ 3318 the closing bracket. Everything else is an error. */
@@ -3461,12 +3380,8 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
3461 is a pointer argument since we may update it. */ 3380 is a pointer argument since we may update it. */
3462 3381
3463static reg_errcode_t 3382static reg_errcode_t
3464#ifdef RE_ENABLE_I18N
3465build_equiv_class (bitset_t sbcset, re_charset_t *mbcset, 3383build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
3466 Idx *equiv_class_alloc, const unsigned char *name) 3384 Idx *equiv_class_alloc, const unsigned char *name)
3467#else /* not RE_ENABLE_I18N */
3468build_equiv_class (bitset_t sbcset, const unsigned char *name)
3469#endif /* not RE_ENABLE_I18N */
3470{ 3385{
3471#ifdef _LIBC 3386#ifdef _LIBC
3472 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 3387 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
@@ -3478,8 +3393,6 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3478 int32_t idx1, idx2; 3393 int32_t idx1, idx2;
3479 unsigned int ch; 3394 unsigned int ch;
3480 size_t len; 3395 size_t len;
3481 /* This #include defines a local function! */
3482# include <locale/weight.h>
3483 /* Calculate the index for equivalence class. */ 3396 /* Calculate the index for equivalence class. */
3484 cp = name; 3397 cp = name;
3485 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); 3398 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
@@ -3489,8 +3402,8 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3489 _NL_COLLATE_EXTRAMB); 3402 _NL_COLLATE_EXTRAMB);
3490 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, 3403 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
3491 _NL_COLLATE_INDIRECTMB); 3404 _NL_COLLATE_INDIRECTMB);
3492 idx1 = findidx (&cp, -1); 3405 idx1 = findidx (table, indirect, extra, &cp, -1);
3493 if (BE (idx1 == 0 || *cp != '\0', 0)) 3406 if (__glibc_unlikely (idx1 == 0 || *cp != '\0'))
3494 /* This isn't a valid character. */ 3407 /* This isn't a valid character. */
3495 return REG_ECOLLATE; 3408 return REG_ECOLLATE;
3496 3409
@@ -3500,7 +3413,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3500 { 3413 {
3501 char_buf[0] = ch; 3414 char_buf[0] = ch;
3502 cp = char_buf; 3415 cp = char_buf;
3503 idx2 = findidx (&cp, 1); 3416 idx2 = findidx (table, indirect, extra, &cp, 1);
3504/* 3417/*
3505 idx2 = table[ch]; 3418 idx2 = table[ch];
3506*/ 3419*/
@@ -3509,21 +3422,13 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3509 continue; 3422 continue;
3510 /* Compare only if the length matches and the collation rule 3423 /* Compare only if the length matches and the collation rule
3511 index is the same. */ 3424 index is the same. */
3512 if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24)) 3425 if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24)
3513 { 3426 && memcmp (weights + (idx1 & 0xffffff) + 1,
3514 int cnt = 0; 3427 weights + (idx2 & 0xffffff) + 1, len) == 0)
3515 3428 bitset_set (sbcset, ch);
3516 while (cnt <= len &&
3517 weights[(idx1 & 0xffffff) + 1 + cnt]
3518 == weights[(idx2 & 0xffffff) + 1 + cnt])
3519 ++cnt;
3520
3521 if (cnt > len)
3522 bitset_set (sbcset, ch);
3523 }
3524 } 3429 }
3525 /* Check whether the array has enough space. */ 3430 /* Check whether the array has enough space. */
3526 if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0)) 3431 if (__glibc_unlikely (*equiv_class_alloc == mbcset->nequiv_classes))
3527 { 3432 {
3528 /* Not enough, realloc it. */ 3433 /* Not enough, realloc it. */
3529 /* +1 in case of mbcset->nequiv_classes is 0. */ 3434 /* +1 in case of mbcset->nequiv_classes is 0. */
@@ -3532,7 +3437,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3532 int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes, 3437 int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
3533 int32_t, 3438 int32_t,
3534 new_equiv_class_alloc); 3439 new_equiv_class_alloc);
3535 if (BE (new_equiv_classes == NULL, 0)) 3440 if (__glibc_unlikely (new_equiv_classes == NULL))
3536 return REG_ESPACE; 3441 return REG_ESPACE;
3537 mbcset->equiv_classes = new_equiv_classes; 3442 mbcset->equiv_classes = new_equiv_classes;
3538 *equiv_class_alloc = new_equiv_class_alloc; 3443 *equiv_class_alloc = new_equiv_class_alloc;
@@ -3542,7 +3447,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3542 else 3447 else
3543#endif /* _LIBC */ 3448#endif /* _LIBC */
3544 { 3449 {
3545 if (BE (strlen ((const char *) name) != 1, 0)) 3450 if (__glibc_unlikely (strlen ((const char *) name) != 1))
3546 return REG_ECOLLATE; 3451 return REG_ECOLLATE;
3547 bitset_set (sbcset, *name); 3452 bitset_set (sbcset, *name);
3548 } 3453 }
@@ -3556,14 +3461,9 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3556 is a pointer argument since we may update it. */ 3461 is a pointer argument since we may update it. */
3557 3462
3558static reg_errcode_t 3463static reg_errcode_t
3559#ifdef RE_ENABLE_I18N
3560build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, 3464build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3561 re_charset_t *mbcset, Idx *char_class_alloc, 3465 re_charset_t *mbcset, Idx *char_class_alloc,
3562 const char *class_name, reg_syntax_t syntax) 3466 const char *class_name, reg_syntax_t syntax)
3563#else /* not RE_ENABLE_I18N */
3564build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3565 const char *class_name, reg_syntax_t syntax)
3566#endif /* not RE_ENABLE_I18N */
3567{ 3467{
3568 int i; 3468 int i;
3569 const char *name = class_name; 3469 const char *name = class_name;
@@ -3574,9 +3474,8 @@ build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3574 && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0)) 3474 && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
3575 name = "alpha"; 3475 name = "alpha";
3576 3476
3577#ifdef RE_ENABLE_I18N
3578 /* Check the space of the arrays. */ 3477 /* Check the space of the arrays. */
3579 if (BE (*char_class_alloc == mbcset->nchar_classes, 0)) 3478 if (__glibc_unlikely (*char_class_alloc == mbcset->nchar_classes))
3580 { 3479 {
3581 /* Not enough, realloc it. */ 3480 /* Not enough, realloc it. */
3582 /* +1 in case of mbcset->nchar_classes is 0. */ 3481 /* +1 in case of mbcset->nchar_classes is 0. */
@@ -3584,17 +3483,16 @@ build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3584 /* Use realloc since array is NULL if *alloc == 0. */ 3483 /* Use realloc since array is NULL if *alloc == 0. */
3585 wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t, 3484 wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
3586 new_char_class_alloc); 3485 new_char_class_alloc);
3587 if (BE (new_char_classes == NULL, 0)) 3486 if (__glibc_unlikely (new_char_classes == NULL))
3588 return REG_ESPACE; 3487 return REG_ESPACE;
3589 mbcset->char_classes = new_char_classes; 3488 mbcset->char_classes = new_char_classes;
3590 *char_class_alloc = new_char_class_alloc; 3489 *char_class_alloc = new_char_class_alloc;
3591 } 3490 }
3592 mbcset->char_classes[mbcset->nchar_classes++] = __wctype (name); 3491 mbcset->char_classes[mbcset->nchar_classes++] = __wctype (name);
3593#endif /* RE_ENABLE_I18N */
3594 3492
3595#define BUILD_CHARCLASS_LOOP(ctype_func) \ 3493#define BUILD_CHARCLASS_LOOP(ctype_func) \
3596 do { \ 3494 do { \
3597 if (BE (trans != NULL, 0)) \ 3495 if (__glibc_unlikely (trans != NULL)) \
3598 { \ 3496 { \
3599 for (i = 0; i < SBC_MAX; ++i) \ 3497 for (i = 0; i < SBC_MAX; ++i) \
3600 if (ctype_func (i)) \ 3498 if (ctype_func (i)) \
@@ -3645,49 +3543,33 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3645 reg_errcode_t *err) 3543 reg_errcode_t *err)
3646{ 3544{
3647 re_bitset_ptr_t sbcset; 3545 re_bitset_ptr_t sbcset;
3648#ifdef RE_ENABLE_I18N
3649 re_charset_t *mbcset; 3546 re_charset_t *mbcset;
3650 Idx alloc = 0; 3547 Idx alloc = 0;
3651#endif /* not RE_ENABLE_I18N */
3652 reg_errcode_t ret; 3548 reg_errcode_t ret;
3653 re_token_t br_token;
3654 bin_tree_t *tree; 3549 bin_tree_t *tree;
3655 3550
3656 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 3551 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
3657#ifdef RE_ENABLE_I18N 3552 if (__glibc_unlikely (sbcset == NULL))
3658 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3659#endif /* RE_ENABLE_I18N */
3660
3661#ifdef RE_ENABLE_I18N
3662 if (BE (sbcset == NULL || mbcset == NULL, 0))
3663#else /* not RE_ENABLE_I18N */
3664 if (BE (sbcset == NULL, 0))
3665#endif /* not RE_ENABLE_I18N */
3666 { 3553 {
3667 *err = REG_ESPACE; 3554 *err = REG_ESPACE;
3668 return NULL; 3555 return NULL;
3669 } 3556 }
3670 3557 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3671 if (non_match) 3558 if (__glibc_unlikely (mbcset == NULL))
3672 { 3559 {
3673#ifdef RE_ENABLE_I18N 3560 re_free (sbcset);
3674 mbcset->non_match = 1; 3561 *err = REG_ESPACE;
3675#endif /* not RE_ENABLE_I18N */ 3562 return NULL;
3676 } 3563 }
3564 mbcset->non_match = non_match;
3677 3565
3678 /* We don't care the syntax in this case. */ 3566 /* We don't care the syntax in this case. */
3679 ret = build_charclass (trans, sbcset, 3567 ret = build_charclass (trans, sbcset, mbcset, &alloc, class_name, 0);
3680#ifdef RE_ENABLE_I18N
3681 mbcset, &alloc,
3682#endif /* RE_ENABLE_I18N */
3683 class_name, 0);
3684 3568
3685 if (BE (ret != REG_NOERROR, 0)) 3569 if (__glibc_unlikely (ret != REG_NOERROR))
3686 { 3570 {
3687 re_free (sbcset); 3571 re_free (sbcset);
3688#ifdef RE_ENABLE_I18N
3689 free_charset (mbcset); 3572 free_charset (mbcset);
3690#endif /* RE_ENABLE_I18N */
3691 *err = ret; 3573 *err = ret;
3692 return NULL; 3574 return NULL;
3693 } 3575 }
@@ -3699,20 +3581,16 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3699 if (non_match) 3581 if (non_match)
3700 bitset_not (sbcset); 3582 bitset_not (sbcset);
3701 3583
3702#ifdef RE_ENABLE_I18N
3703 /* Ensure only single byte characters are set. */ 3584 /* Ensure only single byte characters are set. */
3704 if (dfa->mb_cur_max > 1) 3585 if (dfa->mb_cur_max > 1)
3705 bitset_mask (sbcset, dfa->sb_char); 3586 bitset_mask (sbcset, dfa->sb_char);
3706#endif
3707 3587
3708 /* Build a tree for simple bracket. */ 3588 /* Build a tree for simple bracket. */
3709 br_token.type = SIMPLE_BRACKET; 3589 re_token_t br_token = { .type = SIMPLE_BRACKET, .opr.sbcset = sbcset };
3710 br_token.opr.sbcset = sbcset;
3711 tree = create_token_tree (dfa, NULL, NULL, &br_token); 3590 tree = create_token_tree (dfa, NULL, NULL, &br_token);
3712 if (BE (tree == NULL, 0)) 3591 if (__glibc_unlikely (tree == NULL))
3713 goto build_word_op_espace; 3592 goto build_word_op_espace;
3714 3593
3715#ifdef RE_ENABLE_I18N
3716 if (dfa->mb_cur_max > 1) 3594 if (dfa->mb_cur_max > 1)
3717 { 3595 {
3718 bin_tree_t *mbc_tree; 3596 bin_tree_t *mbc_tree;
@@ -3721,11 +3599,11 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3721 br_token.opr.mbcset = mbcset; 3599 br_token.opr.mbcset = mbcset;
3722 dfa->has_mb_node = 1; 3600 dfa->has_mb_node = 1;
3723 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3601 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3724 if (BE (mbc_tree == NULL, 0)) 3602 if (__glibc_unlikely (mbc_tree == NULL))
3725 goto build_word_op_espace; 3603 goto build_word_op_espace;
3726 /* Then join them by ALT node. */ 3604 /* Then join them by ALT node. */
3727 tree = create_tree (dfa, tree, mbc_tree, OP_ALT); 3605 tree = create_tree (dfa, tree, mbc_tree, OP_ALT);
3728 if (BE (mbc_tree != NULL, 1)) 3606 if (__glibc_likely (mbc_tree != NULL))
3729 return tree; 3607 return tree;
3730 } 3608 }
3731 else 3609 else
@@ -3733,63 +3611,55 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3733 free_charset (mbcset); 3611 free_charset (mbcset);
3734 return tree; 3612 return tree;
3735 } 3613 }
3736#else /* not RE_ENABLE_I18N */
3737 return tree;
3738#endif /* not RE_ENABLE_I18N */
3739 3614
3740 build_word_op_espace: 3615 build_word_op_espace:
3741 re_free (sbcset); 3616 re_free (sbcset);
3742#ifdef RE_ENABLE_I18N
3743 free_charset (mbcset); 3617 free_charset (mbcset);
3744#endif /* RE_ENABLE_I18N */
3745 *err = REG_ESPACE; 3618 *err = REG_ESPACE;
3746 return NULL; 3619 return NULL;
3747} 3620}
3748 3621
3749/* This is intended for the expressions like "a{1,3}". 3622/* This is intended for the expressions like "a{1,3}".
3750 Fetch a number from 'input', and return the number. 3623 Fetch a number from 'input', and return the number.
3751 Return REG_MISSING if the number field is empty like "{,1}". 3624 Return -1 if the number field is empty like "{,1}".
3752 Return RE_DUP_MAX + 1 if the number field is too large. 3625 Return RE_DUP_MAX + 1 if the number field is too large.
3753 Return REG_ERROR if an error occurred. */ 3626 Return -2 if an error occurred. */
3754 3627
3755static Idx 3628static Idx
3756fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) 3629fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
3757{ 3630{
3758 Idx num = REG_MISSING; 3631 Idx num = -1;
3759 unsigned char c; 3632 unsigned char c;
3760 while (1) 3633 while (1)
3761 { 3634 {
3762 fetch_token (token, input, syntax); 3635 fetch_token (token, input, syntax);
3763 c = token->opr.c; 3636 c = token->opr.c;
3764 if (BE (token->type == END_OF_RE, 0)) 3637 if (__glibc_unlikely (token->type == END_OF_RE))
3765 return REG_ERROR; 3638 return -2;
3766 if (token->type == OP_CLOSE_DUP_NUM || c == ',') 3639 if (token->type == OP_CLOSE_DUP_NUM || c == ',')
3767 break; 3640 break;
3768 num = ((token->type != CHARACTER || c < '0' || '9' < c 3641 num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2)
3769 || num == REG_ERROR) 3642 ? -2
3770 ? REG_ERROR 3643 : num == -1
3771 : num == REG_MISSING
3772 ? c - '0' 3644 ? c - '0'
3773 : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); 3645 : MIN (RE_DUP_MAX + 1, num * 10 + c - '0'));
3774 } 3646 }
3775 return num; 3647 return num;
3776} 3648}
3777 3649
3778#ifdef RE_ENABLE_I18N
3779static void 3650static void
3780free_charset (re_charset_t *cset) 3651free_charset (re_charset_t *cset)
3781{ 3652{
3782 re_free (cset->mbchars); 3653 re_free (cset->mbchars);
3783# ifdef _LIBC 3654#ifdef _LIBC
3784 re_free (cset->coll_syms); 3655 re_free (cset->coll_syms);
3785 re_free (cset->equiv_classes); 3656 re_free (cset->equiv_classes);
3657#endif
3786 re_free (cset->range_starts); 3658 re_free (cset->range_starts);
3787 re_free (cset->range_ends); 3659 re_free (cset->range_ends);
3788# endif
3789 re_free (cset->char_classes); 3660 re_free (cset->char_classes);
3790 re_free (cset); 3661 re_free (cset);
3791} 3662}
3792#endif /* RE_ENABLE_I18N */
3793 3663
3794/* Functions for binary tree operation. */ 3664/* Functions for binary tree operation. */
3795 3665
@@ -3799,8 +3669,7 @@ static bin_tree_t *
3799create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, 3669create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3800 re_token_type_t type) 3670 re_token_type_t type)
3801{ 3671{
3802 re_token_t t; 3672 re_token_t t = { .type = type };
3803 t.type = type;
3804 return create_token_tree (dfa, left, right, &t); 3673 return create_token_tree (dfa, left, right, &t);
3805} 3674}
3806 3675
@@ -3809,7 +3678,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3809 const re_token_t *token) 3678 const re_token_t *token)
3810{ 3679{
3811 bin_tree_t *tree; 3680 bin_tree_t *tree;
3812 if (BE (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE, 0)) 3681 if (__glibc_unlikely (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE))
3813 { 3682 {
3814 bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1); 3683 bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1);
3815 3684
@@ -3829,7 +3698,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3829 tree->token.opt_subexp = 0; 3698 tree->token.opt_subexp = 0;
3830 tree->first = NULL; 3699 tree->first = NULL;
3831 tree->next = NULL; 3700 tree->next = NULL;
3832 tree->node_idx = REG_MISSING; 3701 tree->node_idx = -1;
3833 3702
3834 if (left != NULL) 3703 if (left != NULL)
3835 left->parent = tree; 3704 left->parent = tree;
@@ -3856,13 +3725,10 @@ mark_opt_subexp (void *extra, bin_tree_t *node)
3856static void 3725static void
3857free_token (re_token_t *node) 3726free_token (re_token_t *node)
3858{ 3727{
3859#ifdef RE_ENABLE_I18N
3860 if (node->type == COMPLEX_BRACKET && node->duplicated == 0) 3728 if (node->type == COMPLEX_BRACKET && node->duplicated == 0)
3861 free_charset (node->opr.mbcset); 3729 free_charset (node->opr.mbcset);
3862 else 3730 else if (node->type == SIMPLE_BRACKET && node->duplicated == 0)
3863#endif /* RE_ENABLE_I18N */ 3731 re_free (node->opr.sbcset);
3864 if (node->type == SIMPLE_BRACKET && node->duplicated == 0)
3865 re_free (node->opr.sbcset);
3866} 3732}
3867 3733
3868/* Worker function for tree walking. Free the allocated memory inside NODE 3734/* Worker function for tree walking. Free the allocated memory inside NODE
diff --git a/gl/regex.c b/gl/regex.c
index 5a0332e..3beb0de 100644
--- a/gl/regex.c
+++ b/gl/regex.c
@@ -1,29 +1,32 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc. 2 Copyright (C) 2002-2023 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 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
19
20#define __STDC_WANT_IEC_60559_BFP_EXT__
19 21
20#ifndef _LIBC 22#ifndef _LIBC
21# include <config.h> 23# include <libc-config.h>
22 24
23# if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 25# if __GNUC_PREREQ (4, 6)
24# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" 26# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
27# pragma GCC diagnostic ignored "-Wvla"
25# endif 28# endif
26# if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ 29# if __GNUC_PREREQ (4, 3)
27# pragma GCC diagnostic ignored "-Wold-style-definition" 30# pragma GCC diagnostic ignored "-Wold-style-definition"
28# pragma GCC diagnostic ignored "-Wtype-limits" 31# pragma GCC diagnostic ignored "-Wtype-limits"
29# endif 32# endif
diff --git a/gl/regex.h b/gl/regex.h
index 854c6ed..9ef0252 100644
--- a/gl/regex.h
+++ b/gl/regex.h
@@ -1,22 +1,21 @@
1/* Definitions for data structures and routines for the regular 1/* Definitions for data structures and routines for the regular
2 expression library. 2 expression library.
3 Copyright (C) 1985, 1989-1993, 1995-1998, 2000-2003, 2005-2013 Free Software 3 Copyright (C) 1985, 1989-2023 Free Software Foundation, Inc.
4 Foundation, Inc.
5 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
6 5
7 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
11 10
12 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 14 Lesser General Public License for more details.
16 15
17 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
20 19
21#ifndef _REGEX_H 20#ifndef _REGEX_H
22#define _REGEX_H 1 21#define _REGEX_H 1
@@ -42,11 +41,6 @@ extern "C" {
42 supported within glibc itself, and glibc users should not define 41 supported within glibc itself, and glibc users should not define
43 _REGEX_LARGE_OFFSETS. */ 42 _REGEX_LARGE_OFFSETS. */
44 43
45/* The type of nonnegative object indexes. Traditionally, GNU regex
46 uses 'int' for these. Code that uses __re_idx_t should work
47 regardless of whether the type is signed. */
48typedef size_t __re_idx_t;
49
50/* The type of object sizes. */ 44/* The type of object sizes. */
51typedef size_t __re_size_t; 45typedef size_t __re_size_t;
52 46
@@ -58,7 +52,6 @@ typedef size_t __re_long_size_t;
58 52
59/* The traditional GNU regex implementation mishandles strings longer 53/* The traditional GNU regex implementation mishandles strings longer
60 than INT_MAX. */ 54 than INT_MAX. */
61typedef int __re_idx_t;
62typedef unsigned int __re_size_t; 55typedef unsigned int __re_size_t;
63typedef unsigned long int __re_long_size_t; 56typedef unsigned long int __re_long_size_t;
64 57
@@ -244,19 +237,16 @@ extern reg_syntax_t re_syntax_options;
244 | RE_INVALID_INTERVAL_ORD) 237 | RE_INVALID_INTERVAL_ORD)
245 238
246# define RE_SYNTAX_GREP \ 239# define RE_SYNTAX_GREP \
247 (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ 240 ((RE_SYNTAX_POSIX_BASIC | RE_NEWLINE_ALT) \
248 | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ 241 & ~(RE_CONTEXT_INVALID_DUP | RE_DOT_NOT_NULL))
249 | RE_NEWLINE_ALT)
250 242
251# define RE_SYNTAX_EGREP \ 243# define RE_SYNTAX_EGREP \
252 (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ 244 ((RE_SYNTAX_POSIX_EXTENDED | RE_INVALID_INTERVAL_ORD | RE_NEWLINE_ALT) \
253 | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ 245 & ~(RE_CONTEXT_INVALID_OPS | RE_DOT_NOT_NULL))
254 | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
255 | RE_NO_BK_VBAR)
256 246
247/* POSIX grep -E behavior is no longer incompatible with GNU. */
257# define RE_SYNTAX_POSIX_EGREP \ 248# define RE_SYNTAX_POSIX_EGREP \
258 (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ 249 RE_SYNTAX_EGREP
259 | RE_INVALID_INTERVAL_ORD)
260 250
261/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ 251/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
262# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC 252# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
@@ -491,7 +481,8 @@ typedef struct re_pattern_buffer regex_t;
491#ifdef _REGEX_LARGE_OFFSETS 481#ifdef _REGEX_LARGE_OFFSETS
492/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as 482/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as
493 ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t 483 ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t
494 is wider than ssize_t, so ssize_t is safe. */ 484 is wider than ssize_t, so ssize_t is safe. ptrdiff_t is not
485 visible here, so use ssize_t. */
495typedef ssize_t regoff_t; 486typedef ssize_t regoff_t;
496#else 487#else
497/* The traditional GNU regex implementation mishandles strings longer 488/* The traditional GNU regex implementation mishandles strings longer
@@ -531,6 +522,30 @@ typedef struct
531 522
532/* Declarations for routines. */ 523/* Declarations for routines. */
533 524
525#ifndef _REGEX_NELTS
526# if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
527 && !defined __STDC_NO_VLA__)
528# define _REGEX_NELTS(n) n
529# else
530# define _REGEX_NELTS(n)
531# endif
532#endif
533
534#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
535# pragma GCC diagnostic push
536# pragma GCC diagnostic ignored "-Wvla"
537#endif
538
539#ifndef _Attr_access_
540# ifdef __attr_access
541# define _Attr_access_(arg) __attr_access (arg)
542# elif defined __GNUC__ && 10 <= __GNUC__
543# define _Attr_access_(x) __attribute__ ((__access__ x))
544# else
545# define _Attr_access_(x)
546# endif
547#endif
548
534#ifdef __USE_GNU 549#ifdef __USE_GNU
535/* Sets the current default syntax to SYNTAX, and return the old syntax. 550/* Sets the current default syntax to SYNTAX, and return the old syntax.
536 You can also simply assign to the 're_syntax_options' variable. */ 551 You can also simply assign to the 're_syntax_options' variable. */
@@ -541,11 +556,12 @@ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
541 BUFFER. Return NULL if successful, and an error string if not. 556 BUFFER. Return NULL if successful, and an error string if not.
542 557
543 To free the allocated storage, you must call 'regfree' on BUFFER. 558 To free the allocated storage, you must call 'regfree' on BUFFER.
544 Note that the translate table must either have been initialised by 559 Note that the translate table must either have been initialized by
545 'regcomp', with a malloc'ed value, or set to NULL before calling 560 'regcomp', with a malloc'ed value, or set to NULL before calling
546 'regfree'. */ 561 'regfree'. */
547extern const char *re_compile_pattern (const char *__pattern, size_t __length, 562extern const char *re_compile_pattern (const char *__pattern, size_t __length,
548 struct re_pattern_buffer *__buffer); 563 struct re_pattern_buffer *__buffer)
564 _Attr_access_ ((__read_only__, 1, 2));
549 565
550 566
551/* Compile a fastmap for the compiled pattern in BUFFER; used to 567/* Compile a fastmap for the compiled pattern in BUFFER; used to
@@ -560,34 +576,40 @@ extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
560 match, or -2 for an internal error. Also return register 576 match, or -2 for an internal error. Also return register
561 information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 577 information in REGS (if REGS and BUFFER->no_sub are nonzero). */
562extern regoff_t re_search (struct re_pattern_buffer *__buffer, 578extern regoff_t re_search (struct re_pattern_buffer *__buffer,
563 const char *__string, __re_idx_t __length, 579 const char *__String, regoff_t __length,
564 __re_idx_t __start, regoff_t __range, 580 regoff_t __start, regoff_t __range,
565 struct re_registers *__regs); 581 struct re_registers *__regs)
582 _Attr_access_ ((__read_only__, 2, 3));
566 583
567 584
568/* Like 're_search', but search in the concatenation of STRING1 and 585/* Like 're_search', but search in the concatenation of STRING1 and
569 STRING2. Also, stop searching at index START + STOP. */ 586 STRING2. Also, stop searching at index START + STOP. */
570extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, 587extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
571 const char *__string1, __re_idx_t __length1, 588 const char *__string1, regoff_t __length1,
572 const char *__string2, __re_idx_t __length2, 589 const char *__string2, regoff_t __length2,
573 __re_idx_t __start, regoff_t __range, 590 regoff_t __start, regoff_t __range,
574 struct re_registers *__regs, 591 struct re_registers *__regs,
575 __re_idx_t __stop); 592 regoff_t __stop)
593 _Attr_access_ ((__read_only__, 2, 3))
594 _Attr_access_ ((__read_only__, 4, 5));
576 595
577 596
578/* Like 're_search', but return how many characters in STRING the regexp 597/* Like 're_search', but return how many characters in STRING the regexp
579 in BUFFER matched, starting at position START. */ 598 in BUFFER matched, starting at position START. */
580extern regoff_t re_match (struct re_pattern_buffer *__buffer, 599extern regoff_t re_match (struct re_pattern_buffer *__buffer,
581 const char *__string, __re_idx_t __length, 600 const char *__String, regoff_t __length,
582 __re_idx_t __start, struct re_registers *__regs); 601 regoff_t __start, struct re_registers *__regs)
602 _Attr_access_ ((__read_only__, 2, 3));
583 603
584 604
585/* Relates to 're_match' as 're_search_2' relates to 're_search'. */ 605/* Relates to 're_match' as 're_search_2' relates to 're_search'. */
586extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, 606extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
587 const char *__string1, __re_idx_t __length1, 607 const char *__string1, regoff_t __length1,
588 const char *__string2, __re_idx_t __length2, 608 const char *__string2, regoff_t __length2,
589 __re_idx_t __start, struct re_registers *__regs, 609 regoff_t __start, struct re_registers *__regs,
590 __re_idx_t __stop); 610 regoff_t __stop)
611 _Attr_access_ ((__read_only__, 2, 3))
612 _Attr_access_ ((__read_only__, 4, 5));
591 613
592 614
593/* Set REGS to hold NUM_REGS registers, storing them in STARTS and 615/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
@@ -608,36 +630,41 @@ extern void re_set_registers (struct re_pattern_buffer *__buffer,
608 regoff_t *__starts, regoff_t *__ends); 630 regoff_t *__starts, regoff_t *__ends);
609#endif /* Use GNU */ 631#endif /* Use GNU */
610 632
611#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_BSD) 633#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_MISC)
612# ifndef _CRAY
613/* 4.2 bsd compatibility. */ 634/* 4.2 bsd compatibility. */
614extern char *re_comp (const char *); 635extern char *re_comp (const char *);
615extern int re_exec (const char *); 636extern int re_exec (const char *);
616# endif
617#endif 637#endif
618 638
619/* GCC 2.95 and later have "__restrict"; C99 compilers have 639/* For plain 'restrict', use glibc's __restrict if defined.
640 Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have
620 "restrict", and "configure" may have defined "restrict". 641 "restrict", and "configure" may have defined "restrict".
621 Other compilers use __restrict, __restrict__, and _Restrict, and 642 Other compilers use __restrict, __restrict__, and _Restrict, and
622 'configure' might #define 'restrict' to those words, so pick a 643 'configure' might #define 'restrict' to those words, so pick a
623 different name. */ 644 different name. */
624#ifndef _Restrict_ 645#ifndef _Restrict_
625# if 199901L <= __STDC_VERSION__ 646# if defined __restrict \
626# define _Restrict_ restrict 647 || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
627# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) 648 || __clang_major__ >= 3
628# define _Restrict_ __restrict 649# define _Restrict_ __restrict
650# elif 199901L <= __STDC_VERSION__ || defined restrict
651# define _Restrict_ restrict
629# else 652# else
630# define _Restrict_ 653# define _Restrict_
631# endif 654# endif
632#endif 655#endif
633/* gcc 3.1 and up support the [restrict] syntax. Don't trust 656/* For the ISO C99 syntax
634 sys/cdefs.h's definition of __restrict_arr, though, as it 657 array_name[restrict]
635 mishandles gcc -ansi -pedantic. */ 658 use glibc's __restrict_arr if available.
659 Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode).
660 Other ISO C99 compilers support it as well. */
636#ifndef _Restrict_arr_ 661#ifndef _Restrict_arr_
637# if ((199901L <= __STDC_VERSION__ \ 662# ifdef __restrict_arr
638 || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ 663# define _Restrict_arr_ __restrict_arr
639 && !defined __STRICT_ANSI__)) \ 664# elif ((199901L <= __STDC_VERSION__ \
640 && !defined __GNUG__) 665 || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
666 || __clang_major__ >= 3) \
667 && !defined __cplusplus)
641# define _Restrict_arr_ _Restrict_ 668# define _Restrict_arr_ _Restrict_
642# else 669# else
643# define _Restrict_arr_ 670# define _Restrict_arr_
@@ -650,15 +677,20 @@ extern int regcomp (regex_t *_Restrict_ __preg,
650 int __cflags); 677 int __cflags);
651 678
652extern int regexec (const regex_t *_Restrict_ __preg, 679extern int regexec (const regex_t *_Restrict_ __preg,
653 const char *_Restrict_ __string, size_t __nmatch, 680 const char *_Restrict_ __String, size_t __nmatch,
654 regmatch_t __pmatch[_Restrict_arr_], 681 regmatch_t __pmatch[_Restrict_arr_
682 _REGEX_NELTS (__nmatch)],
655 int __eflags); 683 int __eflags);
656 684
657extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, 685extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
658 char *_Restrict_ __errbuf, size_t __errbuf_size); 686 char *_Restrict_ __errbuf, size_t __errbuf_size)
687 _Attr_access_ ((__write_only__, 3, 4));
659 688
660extern void regfree (regex_t *__preg); 689extern void regfree (regex_t *__preg);
661 690
691#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
692# pragma GCC diagnostic pop
693#endif
662 694
663#ifdef __cplusplus 695#ifdef __cplusplus
664} 696}
diff --git a/gl/regex_internal.c b/gl/regex_internal.c
index 899b0ae..998a19b 100644
--- a/gl/regex_internal.c
+++ b/gl/regex_internal.c
@@ -1,33 +1,41 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc. 2 Copyright (C) 2002-2023 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 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
19 19
20static void re_string_construct_common (const char *str, Idx len, 20static void re_string_construct_common (const char *str, Idx len,
21 re_string_t *pstr, 21 re_string_t *pstr,
22 RE_TRANSLATE_TYPE trans, bool icase, 22 RE_TRANSLATE_TYPE trans, bool icase,
23 const re_dfa_t *dfa) internal_function; 23 const re_dfa_t *dfa);
24static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa, 24static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
25 const re_node_set *nodes, 25 const re_node_set *nodes,
26 re_hashval_t hash) internal_function; 26 re_hashval_t hash);
27static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, 27static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
28 const re_node_set *nodes, 28 const re_node_set *nodes,
29 unsigned int context, 29 unsigned int context,
30 re_hashval_t hash) internal_function; 30 re_hashval_t hash);
31static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
32 Idx new_buf_len);
33static void build_wcs_buffer (re_string_t *pstr);
34static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr);
35static void build_upper_buffer (re_string_t *pstr);
36static void re_string_translate_buffer (re_string_t *pstr);
37static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
38 int eflags) __attribute__ ((pure));
31 39
32/* Functions for string operation. */ 40/* Functions for string operation. */
33 41
@@ -35,7 +43,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
35 re_string_reconstruct before using the object. */ 43 re_string_reconstruct before using the object. */
36 44
37static reg_errcode_t 45static reg_errcode_t
38internal_function __attribute_warn_unused_result__ 46__attribute_warn_unused_result__
39re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, 47re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
40 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) 48 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
41{ 49{
@@ -49,7 +57,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
49 re_string_construct_common (str, len, pstr, trans, icase, dfa); 57 re_string_construct_common (str, len, pstr, trans, icase, dfa);
50 58
51 ret = re_string_realloc_buffers (pstr, init_buf_len); 59 ret = re_string_realloc_buffers (pstr, init_buf_len);
52 if (BE (ret != REG_NOERROR, 0)) 60 if (__glibc_unlikely (ret != REG_NOERROR))
53 return ret; 61 return ret;
54 62
55 pstr->word_char = dfa->word_char; 63 pstr->word_char = dfa->word_char;
@@ -63,7 +71,7 @@ re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
63/* This function allocate the buffers, and initialize them. */ 71/* This function allocate the buffers, and initialize them. */
64 72
65static reg_errcode_t 73static reg_errcode_t
66internal_function __attribute_warn_unused_result__ 74__attribute_warn_unused_result__
67re_string_construct (re_string_t *pstr, const char *str, Idx len, 75re_string_construct (re_string_t *pstr, const char *str, Idx len,
68 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) 76 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
69{ 77{
@@ -74,41 +82,37 @@ re_string_construct (re_string_t *pstr, const char *str, Idx len,
74 if (len > 0) 82 if (len > 0)
75 { 83 {
76 ret = re_string_realloc_buffers (pstr, len + 1); 84 ret = re_string_realloc_buffers (pstr, len + 1);
77 if (BE (ret != REG_NOERROR, 0)) 85 if (__glibc_unlikely (ret != REG_NOERROR))
78 return ret; 86 return ret;
79 } 87 }
80 pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str; 88 pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
81 89
82 if (icase) 90 if (icase)
83 { 91 {
84#ifdef RE_ENABLE_I18N
85 if (dfa->mb_cur_max > 1) 92 if (dfa->mb_cur_max > 1)
86 { 93 {
87 while (1) 94 while (1)
88 { 95 {
89 ret = build_wcs_upper_buffer (pstr); 96 ret = build_wcs_upper_buffer (pstr);
90 if (BE (ret != REG_NOERROR, 0)) 97 if (__glibc_unlikely (ret != REG_NOERROR))
91 return ret; 98 return ret;
92 if (pstr->valid_raw_len >= len) 99 if (pstr->valid_raw_len >= len)
93 break; 100 break;
94 if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max) 101 if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max)
95 break; 102 break;
96 ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); 103 ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
97 if (BE (ret != REG_NOERROR, 0)) 104 if (__glibc_unlikely (ret != REG_NOERROR))
98 return ret; 105 return ret;
99 } 106 }
100 } 107 }
101 else 108 else
102#endif /* RE_ENABLE_I18N */
103 build_upper_buffer (pstr); 109 build_upper_buffer (pstr);
104 } 110 }
105 else 111 else
106 { 112 {
107#ifdef RE_ENABLE_I18N
108 if (dfa->mb_cur_max > 1) 113 if (dfa->mb_cur_max > 1)
109 build_wcs_buffer (pstr); 114 build_wcs_buffer (pstr);
110 else 115 else
111#endif /* RE_ENABLE_I18N */
112 { 116 {
113 if (trans != NULL) 117 if (trans != NULL)
114 re_string_translate_buffer (pstr); 118 re_string_translate_buffer (pstr);
@@ -126,37 +130,36 @@ re_string_construct (re_string_t *pstr, const char *str, Idx len,
126/* Helper functions for re_string_allocate, and re_string_construct. */ 130/* Helper functions for re_string_allocate, and re_string_construct. */
127 131
128static reg_errcode_t 132static reg_errcode_t
129internal_function __attribute_warn_unused_result__ 133__attribute_warn_unused_result__
130re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) 134re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
131{ 135{
132#ifdef RE_ENABLE_I18N
133 if (pstr->mb_cur_max > 1) 136 if (pstr->mb_cur_max > 1)
134 { 137 {
135 wint_t *new_wcs; 138 wint_t *new_wcs;
136 139
137 /* Avoid overflow in realloc. */ 140 /* Avoid overflow in realloc. */
138 const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx)); 141 const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
139 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_buf_len, 0)) 142 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size)
143 < new_buf_len))
140 return REG_ESPACE; 144 return REG_ESPACE;
141 145
142 new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); 146 new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
143 if (BE (new_wcs == NULL, 0)) 147 if (__glibc_unlikely (new_wcs == NULL))
144 return REG_ESPACE; 148 return REG_ESPACE;
145 pstr->wcs = new_wcs; 149 pstr->wcs = new_wcs;
146 if (pstr->offsets != NULL) 150 if (pstr->offsets != NULL)
147 { 151 {
148 Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len); 152 Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
149 if (BE (new_offsets == NULL, 0)) 153 if (__glibc_unlikely (new_offsets == NULL))
150 return REG_ESPACE; 154 return REG_ESPACE;
151 pstr->offsets = new_offsets; 155 pstr->offsets = new_offsets;
152 } 156 }
153 } 157 }
154#endif /* RE_ENABLE_I18N */
155 if (pstr->mbs_allocated) 158 if (pstr->mbs_allocated)
156 { 159 {
157 unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char, 160 unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char,
158 new_buf_len); 161 new_buf_len);
159 if (BE (new_mbs == NULL, 0)) 162 if (__glibc_unlikely (new_mbs == NULL))
160 return REG_ESPACE; 163 return REG_ESPACE;
161 pstr->mbs = new_mbs; 164 pstr->mbs = new_mbs;
162 } 165 }
@@ -166,7 +169,6 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
166 169
167 170
168static void 171static void
169internal_function
170re_string_construct_common (const char *str, Idx len, re_string_t *pstr, 172re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
171 RE_TRANSLATE_TYPE trans, bool icase, 173 RE_TRANSLATE_TYPE trans, bool icase,
172 const re_dfa_t *dfa) 174 const re_dfa_t *dfa)
@@ -184,7 +186,6 @@ re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
184 pstr->raw_stop = pstr->stop; 186 pstr->raw_stop = pstr->stop;
185} 187}
186 188
187#ifdef RE_ENABLE_I18N
188 189
189/* Build wide character buffer PSTR->WCS. 190/* Build wide character buffer PSTR->WCS.
190 If the byte sequence of the string are: 191 If the byte sequence of the string are:
@@ -198,12 +199,11 @@ re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
198 built and starts from PSTR->VALID_LEN. */ 199 built and starts from PSTR->VALID_LEN. */
199 200
200static void 201static void
201internal_function
202build_wcs_buffer (re_string_t *pstr) 202build_wcs_buffer (re_string_t *pstr)
203{ 203{
204#ifdef _LIBC 204#ifdef _LIBC
205 unsigned char buf[MB_LEN_MAX]; 205 unsigned char buf[MB_LEN_MAX];
206 assert (MB_LEN_MAX >= pstr->mb_cur_max); 206 DEBUG_ASSERT (MB_LEN_MAX >= pstr->mb_cur_max);
207#else 207#else
208 unsigned char buf[64]; 208 unsigned char buf[64];
209#endif 209#endif
@@ -222,7 +222,7 @@ build_wcs_buffer (re_string_t *pstr)
222 remain_len = end_idx - byte_idx; 222 remain_len = end_idx - byte_idx;
223 prev_st = pstr->cur_state; 223 prev_st = pstr->cur_state;
224 /* Apply the translation if we need. */ 224 /* Apply the translation if we need. */
225 if (BE (pstr->trans != NULL, 0)) 225 if (__glibc_unlikely (pstr->trans != NULL))
226 { 226 {
227 int i, ch; 227 int i, ch;
228 228
@@ -236,17 +236,18 @@ build_wcs_buffer (re_string_t *pstr)
236 else 236 else
237 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx; 237 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx;
238 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state); 238 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
239 if (BE (mbclen == (size_t) -1 || mbclen == 0 239 if (__glibc_unlikely (mbclen == (size_t) -1 || mbclen == 0
240 || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len), 0)) 240 || (mbclen == (size_t) -2
241 && pstr->bufs_len >= pstr->len)))
241 { 242 {
242 /* We treat these cases as a singlebyte character. */ 243 /* We treat these cases as a singlebyte character. */
243 mbclen = 1; 244 mbclen = 1;
244 wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]; 245 wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
245 if (BE (pstr->trans != NULL, 0)) 246 if (__glibc_unlikely (pstr->trans != NULL))
246 wc = pstr->trans[wc]; 247 wc = pstr->trans[wc];
247 pstr->cur_state = prev_st; 248 pstr->cur_state = prev_st;
248 } 249 }
249 else if (BE (mbclen == (size_t) -2, 0)) 250 else if (__glibc_unlikely (mbclen == (size_t) -2))
250 { 251 {
251 /* The buffer doesn't have enough space, finish to build. */ 252 /* The buffer doesn't have enough space, finish to build. */
252 pstr->cur_state = prev_st; 253 pstr->cur_state = prev_st;
@@ -267,7 +268,7 @@ build_wcs_buffer (re_string_t *pstr)
267 but for REG_ICASE. */ 268 but for REG_ICASE. */
268 269
269static reg_errcode_t 270static reg_errcode_t
270internal_function __attribute_warn_unused_result__ 271__attribute_warn_unused_result__
271build_wcs_upper_buffer (re_string_t *pstr) 272build_wcs_upper_buffer (re_string_t *pstr)
272{ 273{
273 mbstate_t prev_st; 274 mbstate_t prev_st;
@@ -275,7 +276,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
275 size_t mbclen; 276 size_t mbclen;
276#ifdef _LIBC 277#ifdef _LIBC
277 char buf[MB_LEN_MAX]; 278 char buf[MB_LEN_MAX];
278 assert (MB_LEN_MAX >= pstr->mb_cur_max); 279 DEBUG_ASSERT (pstr->mb_cur_max <= MB_LEN_MAX);
279#else 280#else
280 char buf[64]; 281 char buf[64];
281#endif 282#endif
@@ -290,18 +291,20 @@ build_wcs_upper_buffer (re_string_t *pstr)
290 while (byte_idx < end_idx) 291 while (byte_idx < end_idx)
291 { 292 {
292 wchar_t wc; 293 wchar_t wc;
294 unsigned char ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
293 295
294 if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]) 296 if (isascii (ch) && mbsinit (&pstr->cur_state))
295 && mbsinit (&pstr->cur_state))
296 { 297 {
297 /* In case of a singlebyte character. */
298 pstr->mbs[byte_idx]
299 = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
300 /* The next step uses the assumption that wchar_t is encoded 298 /* The next step uses the assumption that wchar_t is encoded
301 ASCII-safe: all ASCII values can be converted like this. */ 299 ASCII-safe: all ASCII values can be converted like this. */
302 pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx]; 300 wchar_t wcu = __towupper (ch);
303 ++byte_idx; 301 if (isascii (wcu))
304 continue; 302 {
303 pstr->mbs[byte_idx] = wcu;
304 pstr->wcs[byte_idx] = wcu;
305 byte_idx++;
306 continue;
307 }
305 } 308 }
306 309
307 remain_len = end_idx - byte_idx; 310 remain_len = end_idx - byte_idx;
@@ -309,16 +312,15 @@ build_wcs_upper_buffer (re_string_t *pstr)
309 mbclen = __mbrtowc (&wc, 312 mbclen = __mbrtowc (&wc,
310 ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx 313 ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
311 + byte_idx), remain_len, &pstr->cur_state); 314 + byte_idx), remain_len, &pstr->cur_state);
312 if (BE (mbclen < (size_t) -2, 1)) 315 if (__glibc_likely (0 < mbclen && mbclen < (size_t) -2))
313 { 316 {
314 wchar_t wcu = wc; 317 wchar_t wcu = __towupper (wc);
315 if (iswlower (wc)) 318 if (wcu != wc)
316 { 319 {
317 size_t mbcdlen; 320 size_t mbcdlen;
318 321
319 wcu = towupper (wc); 322 mbcdlen = __wcrtomb (buf, wcu, &prev_st);
320 mbcdlen = wcrtomb (buf, wcu, &prev_st); 323 if (__glibc_likely (mbclen == mbcdlen))
321 if (BE (mbclen == mbcdlen, 1))
322 memcpy (pstr->mbs + byte_idx, buf, mbclen); 324 memcpy (pstr->mbs + byte_idx, buf, mbclen);
323 else 325 else
324 { 326 {
@@ -339,11 +341,10 @@ build_wcs_upper_buffer (re_string_t *pstr)
339 { 341 {
340 /* It is an invalid character, an incomplete character 342 /* It is an invalid character, an incomplete character
341 at the end of the string, or '\0'. Just use the byte. */ 343 at the end of the string, or '\0'. Just use the byte. */
342 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
343 pstr->mbs[byte_idx] = ch; 344 pstr->mbs[byte_idx] = ch;
344 /* And also cast it to wide char. */ 345 /* And also cast it to wide char. */
345 pstr->wcs[byte_idx++] = (wchar_t) ch; 346 pstr->wcs[byte_idx++] = (wchar_t) ch;
346 if (BE (mbclen == (size_t) -1, 0)) 347 if (__glibc_unlikely (mbclen == (size_t) -1))
347 pstr->cur_state = prev_st; 348 pstr->cur_state = prev_st;
348 } 349 }
349 else 350 else
@@ -365,7 +366,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
365 offsets_needed: 366 offsets_needed:
366 remain_len = end_idx - byte_idx; 367 remain_len = end_idx - byte_idx;
367 prev_st = pstr->cur_state; 368 prev_st = pstr->cur_state;
368 if (BE (pstr->trans != NULL, 0)) 369 if (__glibc_unlikely (pstr->trans != NULL))
369 { 370 {
370 int i, ch; 371 int i, ch;
371 372
@@ -379,16 +380,15 @@ build_wcs_upper_buffer (re_string_t *pstr)
379 else 380 else
380 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx; 381 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
381 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state); 382 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
382 if (BE (mbclen < (size_t) -2, 1)) 383 if (__glibc_likely (0 < mbclen && mbclen < (size_t) -2))
383 { 384 {
384 wchar_t wcu = wc; 385 wchar_t wcu = __towupper (wc);
385 if (iswlower (wc)) 386 if (wcu != wc)
386 { 387 {
387 size_t mbcdlen; 388 size_t mbcdlen;
388 389
389 wcu = towupper (wc); 390 mbcdlen = __wcrtomb ((char *) buf, wcu, &prev_st);
390 mbcdlen = wcrtomb ((char *) buf, wcu, &prev_st); 391 if (__glibc_likely (mbclen == mbcdlen))
391 if (BE (mbclen == mbcdlen, 1))
392 memcpy (pstr->mbs + byte_idx, buf, mbclen); 392 memcpy (pstr->mbs + byte_idx, buf, mbclen);
393 else if (mbcdlen != (size_t) -1) 393 else if (mbcdlen != (size_t) -1)
394 { 394 {
@@ -438,7 +438,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
438 else 438 else
439 memcpy (pstr->mbs + byte_idx, p, mbclen); 439 memcpy (pstr->mbs + byte_idx, p, mbclen);
440 440
441 if (BE (pstr->offsets_needed != 0, 0)) 441 if (__glibc_unlikely (pstr->offsets_needed != 0))
442 { 442 {
443 size_t i; 443 size_t i;
444 for (i = 0; i < mbclen; ++i) 444 for (i = 0; i < mbclen; ++i)
@@ -457,17 +457,17 @@ build_wcs_upper_buffer (re_string_t *pstr)
457 /* It is an invalid character or '\0'. Just use the byte. */ 457 /* It is an invalid character or '\0'. Just use the byte. */
458 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx]; 458 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx];
459 459
460 if (BE (pstr->trans != NULL, 0)) 460 if (__glibc_unlikely (pstr->trans != NULL))
461 ch = pstr->trans [ch]; 461 ch = pstr->trans [ch];
462 pstr->mbs[byte_idx] = ch; 462 pstr->mbs[byte_idx] = ch;
463 463
464 if (BE (pstr->offsets_needed != 0, 0)) 464 if (__glibc_unlikely (pstr->offsets_needed != 0))
465 pstr->offsets[byte_idx] = src_idx; 465 pstr->offsets[byte_idx] = src_idx;
466 ++src_idx; 466 ++src_idx;
467 467
468 /* And also cast it to wide char. */ 468 /* And also cast it to wide char. */
469 pstr->wcs[byte_idx++] = (wchar_t) ch; 469 pstr->wcs[byte_idx++] = (wchar_t) ch;
470 if (BE (mbclen == (size_t) -1, 0)) 470 if (__glibc_unlikely (mbclen == (size_t) -1))
471 pstr->cur_state = prev_st; 471 pstr->cur_state = prev_st;
472 } 472 }
473 else 473 else
@@ -486,7 +486,6 @@ build_wcs_upper_buffer (re_string_t *pstr)
486 Return the index. */ 486 Return the index. */
487 487
488static Idx 488static Idx
489internal_function
490re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc) 489re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
491{ 490{
492 mbstate_t prev_st; 491 mbstate_t prev_st;
@@ -503,7 +502,8 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
503 prev_st = pstr->cur_state; 502 prev_st = pstr->cur_state;
504 mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx, 503 mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
505 remain_len, &pstr->cur_state); 504 remain_len, &pstr->cur_state);
506 if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) 505 if (__glibc_unlikely (mbclen == (size_t) -2 || mbclen == (size_t) -1
506 || mbclen == 0))
507 { 507 {
508 /* We treat these cases as a single byte character. */ 508 /* We treat these cases as a single byte character. */
509 if (mbclen == 0 || remain_len == 0) 509 if (mbclen == 0 || remain_len == 0)
@@ -521,13 +521,11 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
521 *last_wc = wc; 521 *last_wc = wc;
522 return rawbuf_idx; 522 return rawbuf_idx;
523} 523}
524#endif /* RE_ENABLE_I18N */
525 524
526/* Build the buffer PSTR->MBS, and apply the translation if we need. 525/* Build the buffer PSTR->MBS, and apply the translation if we need.
527 This function is used in case of REG_ICASE. */ 526 This function is used in case of REG_ICASE. */
528 527
529static void 528static void
530internal_function
531build_upper_buffer (re_string_t *pstr) 529build_upper_buffer (re_string_t *pstr)
532{ 530{
533 Idx char_idx, end_idx; 531 Idx char_idx, end_idx;
@@ -536,12 +534,9 @@ build_upper_buffer (re_string_t *pstr)
536 for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx) 534 for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx)
537 { 535 {
538 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx]; 536 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx];
539 if (BE (pstr->trans != NULL, 0)) 537 if (__glibc_unlikely (pstr->trans != NULL))
540 ch = pstr->trans[ch]; 538 ch = pstr->trans[ch];
541 if (islower (ch)) 539 pstr->mbs[char_idx] = toupper (ch);
542 pstr->mbs[char_idx] = toupper (ch);
543 else
544 pstr->mbs[char_idx] = ch;
545 } 540 }
546 pstr->valid_len = char_idx; 541 pstr->valid_len = char_idx;
547 pstr->valid_raw_len = char_idx; 542 pstr->valid_raw_len = char_idx;
@@ -550,7 +545,6 @@ build_upper_buffer (re_string_t *pstr)
550/* Apply TRANS to the buffer in PSTR. */ 545/* Apply TRANS to the buffer in PSTR. */
551 546
552static void 547static void
553internal_function
554re_string_translate_buffer (re_string_t *pstr) 548re_string_translate_buffer (re_string_t *pstr)
555{ 549{
556 Idx buf_idx, end_idx; 550 Idx buf_idx, end_idx;
@@ -571,20 +565,18 @@ re_string_translate_buffer (re_string_t *pstr)
571 convert to upper case in case of REG_ICASE, apply translation. */ 565 convert to upper case in case of REG_ICASE, apply translation. */
572 566
573static reg_errcode_t 567static reg_errcode_t
574internal_function __attribute_warn_unused_result__ 568__attribute_warn_unused_result__
575re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) 569re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
576{ 570{
577 Idx offset; 571 Idx offset;
578 572
579 if (BE (pstr->raw_mbs_idx <= idx, 0)) 573 if (__glibc_unlikely (pstr->raw_mbs_idx <= idx))
580 offset = idx - pstr->raw_mbs_idx; 574 offset = idx - pstr->raw_mbs_idx;
581 else 575 else
582 { 576 {
583 /* Reset buffer. */ 577 /* Reset buffer. */
584#ifdef RE_ENABLE_I18N
585 if (pstr->mb_cur_max > 1) 578 if (pstr->mb_cur_max > 1)
586 memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); 579 memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
587#endif /* RE_ENABLE_I18N */
588 pstr->len = pstr->raw_len; 580 pstr->len = pstr->raw_len;
589 pstr->stop = pstr->raw_stop; 581 pstr->stop = pstr->raw_stop;
590 pstr->valid_len = 0; 582 pstr->valid_len = 0;
@@ -598,14 +590,13 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
598 offset = idx; 590 offset = idx;
599 } 591 }
600 592
601 if (BE (offset != 0, 1)) 593 if (__glibc_likely (offset != 0))
602 { 594 {
603 /* Should the already checked characters be kept? */ 595 /* Should the already checked characters be kept? */
604 if (BE (offset < pstr->valid_raw_len, 1)) 596 if (__glibc_likely (offset < pstr->valid_raw_len))
605 { 597 {
606 /* Yes, move them to the front of the buffer. */ 598 /* Yes, move them to the front of the buffer. */
607#ifdef RE_ENABLE_I18N 599 if (__glibc_unlikely (pstr->offsets_needed))
608 if (BE (pstr->offsets_needed, 0))
609 { 600 {
610 Idx low = 0, high = pstr->valid_len, mid; 601 Idx low = 0, high = pstr->valid_len, mid;
611 do 602 do
@@ -668,40 +659,32 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
668 } 659 }
669 } 660 }
670 else 661 else
671#endif
672 { 662 {
673 pstr->tip_context = re_string_context_at (pstr, offset - 1, 663 pstr->tip_context = re_string_context_at (pstr, offset - 1,
674 eflags); 664 eflags);
675#ifdef RE_ENABLE_I18N
676 if (pstr->mb_cur_max > 1) 665 if (pstr->mb_cur_max > 1)
677 memmove (pstr->wcs, pstr->wcs + offset, 666 memmove (pstr->wcs, pstr->wcs + offset,
678 (pstr->valid_len - offset) * sizeof (wint_t)); 667 (pstr->valid_len - offset) * sizeof (wint_t));
679#endif /* RE_ENABLE_I18N */ 668 if (__glibc_unlikely (pstr->mbs_allocated))
680 if (BE (pstr->mbs_allocated, 0))
681 memmove (pstr->mbs, pstr->mbs + offset, 669 memmove (pstr->mbs, pstr->mbs + offset,
682 pstr->valid_len - offset); 670 pstr->valid_len - offset);
683 pstr->valid_len -= offset; 671 pstr->valid_len -= offset;
684 pstr->valid_raw_len -= offset; 672 pstr->valid_raw_len -= offset;
685#if DEBUG 673 DEBUG_ASSERT (pstr->valid_len > 0);
686 assert (pstr->valid_len > 0);
687#endif
688 } 674 }
689 } 675 }
690 else 676 else
691 { 677 {
692#ifdef RE_ENABLE_I18N
693 /* No, skip all characters until IDX. */ 678 /* No, skip all characters until IDX. */
694 Idx prev_valid_len = pstr->valid_len; 679 Idx prev_valid_len = pstr->valid_len;
695 680
696 if (BE (pstr->offsets_needed, 0)) 681 if (__glibc_unlikely (pstr->offsets_needed))
697 { 682 {
698 pstr->len = pstr->raw_len - idx + offset; 683 pstr->len = pstr->raw_len - idx + offset;
699 pstr->stop = pstr->raw_stop - idx + offset; 684 pstr->stop = pstr->raw_stop - idx + offset;
700 pstr->offsets_needed = 0; 685 pstr->offsets_needed = 0;
701 } 686 }
702#endif
703 pstr->valid_len = 0; 687 pstr->valid_len = 0;
704#ifdef RE_ENABLE_I18N
705 if (pstr->mb_cur_max > 1) 688 if (pstr->mb_cur_max > 1)
706 { 689 {
707 Idx wcs_idx; 690 Idx wcs_idx;
@@ -721,7 +704,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
721#ifdef _LIBC 704#ifdef _LIBC
722 /* We know the wchar_t encoding is UCS4, so for the simple 705 /* We know the wchar_t encoding is UCS4, so for the simple
723 case, ASCII characters, skip the conversion step. */ 706 case, ASCII characters, skip the conversion step. */
724 if (isascii (*p) && BE (pstr->trans == NULL, 1)) 707 if (isascii (*p) && __glibc_likely (pstr->trans == NULL))
725 { 708 {
726 memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); 709 memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
727 /* pstr->valid_len = 0; */ 710 /* pstr->valid_len = 0; */
@@ -739,7 +722,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
739 size_t mbclen; 722 size_t mbclen;
740 723
741 const unsigned char *pp = p; 724 const unsigned char *pp = p;
742 if (BE (pstr->trans != NULL, 0)) 725 if (__glibc_unlikely (pstr->trans != NULL))
743 { 726 {
744 int i = mlen < 6 ? mlen : 6; 727 int i = mlen < 6 ? mlen : 6;
745 while (--i >= 0) 728 while (--i >= 0)
@@ -769,13 +752,13 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
769 pstr->tip_context 752 pstr->tip_context
770 = re_string_context_at (pstr, prev_valid_len - 1, eflags); 753 = re_string_context_at (pstr, prev_valid_len - 1, eflags);
771 else 754 else
772 pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) 755 pstr->tip_context = ((__glibc_unlikely (pstr->word_ops_used != 0)
773 && IS_WIDE_WORD_CHAR (wc)) 756 && IS_WIDE_WORD_CHAR (wc))
774 ? CONTEXT_WORD 757 ? CONTEXT_WORD
775 : ((IS_WIDE_NEWLINE (wc) 758 : ((IS_WIDE_NEWLINE (wc)
776 && pstr->newline_anchor) 759 && pstr->newline_anchor)
777 ? CONTEXT_NEWLINE : 0)); 760 ? CONTEXT_NEWLINE : 0));
778 if (BE (pstr->valid_len, 0)) 761 if (__glibc_unlikely (pstr->valid_len))
779 { 762 {
780 for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx) 763 for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
781 pstr->wcs[wcs_idx] = WEOF; 764 pstr->wcs[wcs_idx] = WEOF;
@@ -785,7 +768,6 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
785 pstr->valid_raw_len = pstr->valid_len; 768 pstr->valid_raw_len = pstr->valid_len;
786 } 769 }
787 else 770 else
788#endif /* RE_ENABLE_I18N */
789 { 771 {
790 int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1]; 772 int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1];
791 pstr->valid_raw_len = 0; 773 pstr->valid_raw_len = 0;
@@ -797,7 +779,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
797 ? CONTEXT_NEWLINE : 0)); 779 ? CONTEXT_NEWLINE : 0));
798 } 780 }
799 } 781 }
800 if (!BE (pstr->mbs_allocated, 0)) 782 if (!__glibc_unlikely (pstr->mbs_allocated))
801 pstr->mbs += offset; 783 pstr->mbs += offset;
802 } 784 }
803 pstr->raw_mbs_idx = idx; 785 pstr->raw_mbs_idx = idx;
@@ -805,21 +787,19 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
805 pstr->stop -= offset; 787 pstr->stop -= offset;
806 788
807 /* Then build the buffers. */ 789 /* Then build the buffers. */
808#ifdef RE_ENABLE_I18N
809 if (pstr->mb_cur_max > 1) 790 if (pstr->mb_cur_max > 1)
810 { 791 {
811 if (pstr->icase) 792 if (pstr->icase)
812 { 793 {
813 reg_errcode_t ret = build_wcs_upper_buffer (pstr); 794 reg_errcode_t ret = build_wcs_upper_buffer (pstr);
814 if (BE (ret != REG_NOERROR, 0)) 795 if (__glibc_unlikely (ret != REG_NOERROR))
815 return ret; 796 return ret;
816 } 797 }
817 else 798 else
818 build_wcs_buffer (pstr); 799 build_wcs_buffer (pstr);
819 } 800 }
820 else 801 else
821#endif /* RE_ENABLE_I18N */ 802 if (__glibc_unlikely (pstr->mbs_allocated))
822 if (BE (pstr->mbs_allocated, 0))
823 { 803 {
824 if (pstr->icase) 804 if (pstr->icase)
825 build_upper_buffer (pstr); 805 build_upper_buffer (pstr);
@@ -834,50 +814,42 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
834} 814}
835 815
836static unsigned char 816static unsigned char
837internal_function __attribute__ ((pure)) 817__attribute__ ((pure))
838re_string_peek_byte_case (const re_string_t *pstr, Idx idx) 818re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
839{ 819{
840 int ch; 820 int ch;
841 Idx off; 821 Idx off;
842 822
843 /* Handle the common (easiest) cases first. */ 823 /* Handle the common (easiest) cases first. */
844 if (BE (!pstr->mbs_allocated, 1)) 824 if (__glibc_likely (!pstr->mbs_allocated))
845 return re_string_peek_byte (pstr, idx); 825 return re_string_peek_byte (pstr, idx);
846 826
847#ifdef RE_ENABLE_I18N
848 if (pstr->mb_cur_max > 1 827 if (pstr->mb_cur_max > 1
849 && ! re_string_is_single_byte_char (pstr, pstr->cur_idx + idx)) 828 && ! re_string_is_single_byte_char (pstr, pstr->cur_idx + idx))
850 return re_string_peek_byte (pstr, idx); 829 return re_string_peek_byte (pstr, idx);
851#endif
852 830
853 off = pstr->cur_idx + idx; 831 off = pstr->cur_idx + idx;
854#ifdef RE_ENABLE_I18N
855 if (pstr->offsets_needed) 832 if (pstr->offsets_needed)
856 off = pstr->offsets[off]; 833 off = pstr->offsets[off];
857#endif
858 834
859 ch = pstr->raw_mbs[pstr->raw_mbs_idx + off]; 835 ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
860 836
861#ifdef RE_ENABLE_I18N
862 /* Ensure that e.g. for tr_TR.UTF-8 BACKSLASH DOTLESS SMALL LETTER I 837 /* Ensure that e.g. for tr_TR.UTF-8 BACKSLASH DOTLESS SMALL LETTER I
863 this function returns CAPITAL LETTER I instead of first byte of 838 this function returns CAPITAL LETTER I instead of first byte of
864 DOTLESS SMALL LETTER I. The latter would confuse the parser, 839 DOTLESS SMALL LETTER I. The latter would confuse the parser,
865 since peek_byte_case doesn't advance cur_idx in any way. */ 840 since peek_byte_case doesn't advance cur_idx in any way. */
866 if (pstr->offsets_needed && !isascii (ch)) 841 if (pstr->offsets_needed && !isascii (ch))
867 return re_string_peek_byte (pstr, idx); 842 return re_string_peek_byte (pstr, idx);
868#endif
869 843
870 return ch; 844 return ch;
871} 845}
872 846
873static unsigned char 847static unsigned char
874internal_function
875re_string_fetch_byte_case (re_string_t *pstr) 848re_string_fetch_byte_case (re_string_t *pstr)
876{ 849{
877 if (BE (!pstr->mbs_allocated, 1)) 850 if (__glibc_likely (!pstr->mbs_allocated))
878 return re_string_fetch_byte (pstr); 851 return re_string_fetch_byte (pstr);
879 852
880#ifdef RE_ENABLE_I18N
881 if (pstr->offsets_needed) 853 if (pstr->offsets_needed)
882 { 854 {
883 Idx off; 855 Idx off;
@@ -903,19 +875,15 @@ re_string_fetch_byte_case (re_string_t *pstr)
903 re_string_char_size_at (pstr, pstr->cur_idx)); 875 re_string_char_size_at (pstr, pstr->cur_idx));
904 return ch; 876 return ch;
905 } 877 }
906#endif
907 878
908 return pstr->raw_mbs[pstr->raw_mbs_idx + pstr->cur_idx++]; 879 return pstr->raw_mbs[pstr->raw_mbs_idx + pstr->cur_idx++];
909} 880}
910 881
911static void 882static void
912internal_function
913re_string_destruct (re_string_t *pstr) 883re_string_destruct (re_string_t *pstr)
914{ 884{
915#ifdef RE_ENABLE_I18N
916 re_free (pstr->wcs); 885 re_free (pstr->wcs);
917 re_free (pstr->offsets); 886 re_free (pstr->offsets);
918#endif /* RE_ENABLE_I18N */
919 if (pstr->mbs_allocated) 887 if (pstr->mbs_allocated)
920 re_free (pstr->mbs); 888 re_free (pstr->mbs);
921} 889}
@@ -923,40 +891,35 @@ re_string_destruct (re_string_t *pstr)
923/* Return the context at IDX in INPUT. */ 891/* Return the context at IDX in INPUT. */
924 892
925static unsigned int 893static unsigned int
926internal_function
927re_string_context_at (const re_string_t *input, Idx idx, int eflags) 894re_string_context_at (const re_string_t *input, Idx idx, int eflags)
928{ 895{
929 int c; 896 int c;
930 if (BE (! REG_VALID_INDEX (idx), 0)) 897 if (__glibc_unlikely (idx < 0))
931 /* In this case, we use the value stored in input->tip_context, 898 /* In this case, we use the value stored in input->tip_context,
932 since we can't know the character in input->mbs[-1] here. */ 899 since we can't know the character in input->mbs[-1] here. */
933 return input->tip_context; 900 return input->tip_context;
934 if (BE (idx == input->len, 0)) 901 if (__glibc_unlikely (idx == input->len))
935 return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF 902 return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF
936 : CONTEXT_NEWLINE | CONTEXT_ENDBUF); 903 : CONTEXT_NEWLINE | CONTEXT_ENDBUF);
937#ifdef RE_ENABLE_I18N
938 if (input->mb_cur_max > 1) 904 if (input->mb_cur_max > 1)
939 { 905 {
940 wint_t wc; 906 wint_t wc;
941 Idx wc_idx = idx; 907 Idx wc_idx = idx;
942 while(input->wcs[wc_idx] == WEOF) 908 while(input->wcs[wc_idx] == WEOF)
943 { 909 {
944#ifdef DEBUG 910 DEBUG_ASSERT (wc_idx >= 0);
945 /* It must not happen. */
946 assert (REG_VALID_INDEX (wc_idx));
947#endif
948 --wc_idx; 911 --wc_idx;
949 if (! REG_VALID_INDEX (wc_idx)) 912 if (wc_idx < 0)
950 return input->tip_context; 913 return input->tip_context;
951 } 914 }
952 wc = input->wcs[wc_idx]; 915 wc = input->wcs[wc_idx];
953 if (BE (input->word_ops_used != 0, 0) && IS_WIDE_WORD_CHAR (wc)) 916 if (__glibc_unlikely (input->word_ops_used != 0)
917 && IS_WIDE_WORD_CHAR (wc))
954 return CONTEXT_WORD; 918 return CONTEXT_WORD;
955 return (IS_WIDE_NEWLINE (wc) && input->newline_anchor 919 return (IS_WIDE_NEWLINE (wc) && input->newline_anchor
956 ? CONTEXT_NEWLINE : 0); 920 ? CONTEXT_NEWLINE : 0);
957 } 921 }
958 else 922 else
959#endif
960 { 923 {
961 c = re_string_byte_at (input, idx); 924 c = re_string_byte_at (input, idx);
962 if (bitset_contain (input->word_char, c)) 925 if (bitset_contain (input->word_char, c))
@@ -968,25 +931,26 @@ re_string_context_at (const re_string_t *input, Idx idx, int eflags)
968/* Functions for set operation. */ 931/* Functions for set operation. */
969 932
970static reg_errcode_t 933static reg_errcode_t
971internal_function __attribute_warn_unused_result__ 934__attribute_warn_unused_result__
972re_node_set_alloc (re_node_set *set, Idx size) 935re_node_set_alloc (re_node_set *set, Idx size)
973{ 936{
974 set->alloc = size; 937 set->alloc = size;
975 set->nelem = 0; 938 set->nelem = 0;
976 set->elems = re_malloc (Idx, size); 939 set->elems = re_malloc (Idx, size);
977 if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0)) 940 if (__glibc_unlikely (set->elems == NULL)
941 && (MALLOC_0_IS_NONNULL || size != 0))
978 return REG_ESPACE; 942 return REG_ESPACE;
979 return REG_NOERROR; 943 return REG_NOERROR;
980} 944}
981 945
982static reg_errcode_t 946static reg_errcode_t
983internal_function __attribute_warn_unused_result__ 947__attribute_warn_unused_result__
984re_node_set_init_1 (re_node_set *set, Idx elem) 948re_node_set_init_1 (re_node_set *set, Idx elem)
985{ 949{
986 set->alloc = 1; 950 set->alloc = 1;
987 set->nelem = 1; 951 set->nelem = 1;
988 set->elems = re_malloc (Idx, 1); 952 set->elems = re_malloc (Idx, 1);
989 if (BE (set->elems == NULL, 0)) 953 if (__glibc_unlikely (set->elems == NULL))
990 { 954 {
991 set->alloc = set->nelem = 0; 955 set->alloc = set->nelem = 0;
992 return REG_ESPACE; 956 return REG_ESPACE;
@@ -996,12 +960,12 @@ re_node_set_init_1 (re_node_set *set, Idx elem)
996} 960}
997 961
998static reg_errcode_t 962static reg_errcode_t
999internal_function __attribute_warn_unused_result__ 963__attribute_warn_unused_result__
1000re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2) 964re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
1001{ 965{
1002 set->alloc = 2; 966 set->alloc = 2;
1003 set->elems = re_malloc (Idx, 2); 967 set->elems = re_malloc (Idx, 2);
1004 if (BE (set->elems == NULL, 0)) 968 if (__glibc_unlikely (set->elems == NULL))
1005 return REG_ESPACE; 969 return REG_ESPACE;
1006 if (elem1 == elem2) 970 if (elem1 == elem2)
1007 { 971 {
@@ -1026,7 +990,7 @@ re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
1026} 990}
1027 991
1028static reg_errcode_t 992static reg_errcode_t
1029internal_function __attribute_warn_unused_result__ 993__attribute_warn_unused_result__
1030re_node_set_init_copy (re_node_set *dest, const re_node_set *src) 994re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1031{ 995{
1032 dest->nelem = src->nelem; 996 dest->nelem = src->nelem;
@@ -1034,7 +998,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1034 { 998 {
1035 dest->alloc = dest->nelem; 999 dest->alloc = dest->nelem;
1036 dest->elems = re_malloc (Idx, dest->alloc); 1000 dest->elems = re_malloc (Idx, dest->alloc);
1037 if (BE (dest->elems == NULL, 0)) 1001 if (__glibc_unlikely (dest->elems == NULL))
1038 { 1002 {
1039 dest->alloc = dest->nelem = 0; 1003 dest->alloc = dest->nelem = 0;
1040 return REG_ESPACE; 1004 return REG_ESPACE;
@@ -1051,7 +1015,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1051 Note: We assume dest->elems is NULL, when dest->alloc is 0. */ 1015 Note: We assume dest->elems is NULL, when dest->alloc is 0. */
1052 1016
1053static reg_errcode_t 1017static reg_errcode_t
1054internal_function __attribute_warn_unused_result__ 1018__attribute_warn_unused_result__
1055re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, 1019re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1056 const re_node_set *src2) 1020 const re_node_set *src2)
1057{ 1021{
@@ -1065,7 +1029,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1065 { 1029 {
1066 Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; 1030 Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
1067 Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc); 1031 Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
1068 if (BE (new_elems == NULL, 0)) 1032 if (__glibc_unlikely (new_elems == NULL))
1069 return REG_ESPACE; 1033 return REG_ESPACE;
1070 dest->elems = new_elems; 1034 dest->elems = new_elems;
1071 dest->alloc = new_alloc; 1035 dest->alloc = new_alloc;
@@ -1082,25 +1046,25 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1082 if (src1->elems[i1] == src2->elems[i2]) 1046 if (src1->elems[i1] == src2->elems[i2])
1083 { 1047 {
1084 /* Try to find the item in DEST. Maybe we could binary search? */ 1048 /* Try to find the item in DEST. Maybe we could binary search? */
1085 while (REG_VALID_INDEX (id) && dest->elems[id] > src1->elems[i1]) 1049 while (id >= 0 && dest->elems[id] > src1->elems[i1])
1086 --id; 1050 --id;
1087 1051
1088 if (! REG_VALID_INDEX (id) || dest->elems[id] != src1->elems[i1]) 1052 if (id < 0 || dest->elems[id] != src1->elems[i1])
1089 dest->elems[--sbase] = src1->elems[i1]; 1053 dest->elems[--sbase] = src1->elems[i1];
1090 1054
1091 if (! REG_VALID_INDEX (--i1) || ! REG_VALID_INDEX (--i2)) 1055 if (--i1 < 0 || --i2 < 0)
1092 break; 1056 break;
1093 } 1057 }
1094 1058
1095 /* Lower the highest of the two items. */ 1059 /* Lower the highest of the two items. */
1096 else if (src1->elems[i1] < src2->elems[i2]) 1060 else if (src1->elems[i1] < src2->elems[i2])
1097 { 1061 {
1098 if (! REG_VALID_INDEX (--i2)) 1062 if (--i2 < 0)
1099 break; 1063 break;
1100 } 1064 }
1101 else 1065 else
1102 { 1066 {
1103 if (! REG_VALID_INDEX (--i1)) 1067 if (--i1 < 0)
1104 break; 1068 break;
1105 } 1069 }
1106 } 1070 }
@@ -1113,7 +1077,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1113 DEST elements are already in place; this is more or 1077 DEST elements are already in place; this is more or
1114 less the same loop that is in re_node_set_merge. */ 1078 less the same loop that is in re_node_set_merge. */
1115 dest->nelem += delta; 1079 dest->nelem += delta;
1116 if (delta > 0 && REG_VALID_INDEX (id)) 1080 if (delta > 0 && id >= 0)
1117 for (;;) 1081 for (;;)
1118 { 1082 {
1119 if (dest->elems[is] > dest->elems[id]) 1083 if (dest->elems[is] > dest->elems[id])
@@ -1127,7 +1091,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1127 { 1091 {
1128 /* Slide from the bottom. */ 1092 /* Slide from the bottom. */
1129 dest->elems[id + delta] = dest->elems[id]; 1093 dest->elems[id + delta] = dest->elems[id];
1130 if (! REG_VALID_INDEX (--id)) 1094 if (--id < 0)
1131 break; 1095 break;
1132 } 1096 }
1133 } 1097 }
@@ -1142,7 +1106,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1142 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */ 1106 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1143 1107
1144static reg_errcode_t 1108static reg_errcode_t
1145internal_function __attribute_warn_unused_result__ 1109__attribute_warn_unused_result__
1146re_node_set_init_union (re_node_set *dest, const re_node_set *src1, 1110re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1147 const re_node_set *src2) 1111 const re_node_set *src2)
1148{ 1112{
@@ -1151,7 +1115,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1151 { 1115 {
1152 dest->alloc = src1->nelem + src2->nelem; 1116 dest->alloc = src1->nelem + src2->nelem;
1153 dest->elems = re_malloc (Idx, dest->alloc); 1117 dest->elems = re_malloc (Idx, dest->alloc);
1154 if (BE (dest->elems == NULL, 0)) 1118 if (__glibc_unlikely (dest->elems == NULL))
1155 return REG_ESPACE; 1119 return REG_ESPACE;
1156 } 1120 }
1157 else 1121 else
@@ -1195,7 +1159,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1195 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */ 1159 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1196 1160
1197static reg_errcode_t 1161static reg_errcode_t
1198internal_function __attribute_warn_unused_result__ 1162__attribute_warn_unused_result__
1199re_node_set_merge (re_node_set *dest, const re_node_set *src) 1163re_node_set_merge (re_node_set *dest, const re_node_set *src)
1200{ 1164{
1201 Idx is, id, sbase, delta; 1165 Idx is, id, sbase, delta;
@@ -1205,14 +1169,18 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1205 { 1169 {
1206 Idx new_alloc = 2 * (src->nelem + dest->alloc); 1170 Idx new_alloc = 2 * (src->nelem + dest->alloc);
1207 Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc); 1171 Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
1208 if (BE (new_buffer == NULL, 0)) 1172 if (__glibc_unlikely (new_buffer == NULL))
1209 return REG_ESPACE; 1173 return REG_ESPACE;
1210 dest->elems = new_buffer; 1174 dest->elems = new_buffer;
1211 dest->alloc = new_alloc; 1175 dest->alloc = new_alloc;
1212 } 1176 }
1213 1177
1214 if (BE (dest->nelem == 0, 0)) 1178 if (__glibc_unlikely (dest->nelem == 0))
1215 { 1179 {
1180 /* Although we already guaranteed above that dest->alloc != 0 and
1181 therefore dest->elems != NULL, add a debug assertion to pacify
1182 GCC 11.2.1's -fanalyzer. */
1183 DEBUG_ASSERT (dest->elems);
1216 dest->nelem = src->nelem; 1184 dest->nelem = src->nelem;
1217 memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); 1185 memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
1218 return REG_NOERROR; 1186 return REG_NOERROR;
@@ -1221,8 +1189,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1221 /* Copy into the top of DEST the items of SRC that are not 1189 /* Copy into the top of DEST the items of SRC that are not
1222 found in DEST. Maybe we could binary search in DEST? */ 1190 found in DEST. Maybe we could binary search in DEST? */
1223 for (sbase = dest->nelem + 2 * src->nelem, 1191 for (sbase = dest->nelem + 2 * src->nelem,
1224 is = src->nelem - 1, id = dest->nelem - 1; 1192 is = src->nelem - 1, id = dest->nelem - 1; is >= 0 && id >= 0; )
1225 REG_VALID_INDEX (is) && REG_VALID_INDEX (id); )
1226 { 1193 {
1227 if (dest->elems[id] == src->elems[is]) 1194 if (dest->elems[id] == src->elems[is])
1228 is--, id--; 1195 is--, id--;
@@ -1232,7 +1199,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1232 --id; 1199 --id;
1233 } 1200 }
1234 1201
1235 if (REG_VALID_INDEX (is)) 1202 if (is >= 0)
1236 { 1203 {
1237 /* If DEST is exhausted, the remaining items of SRC must be unique. */ 1204 /* If DEST is exhausted, the remaining items of SRC must be unique. */
1238 sbase -= is + 1; 1205 sbase -= is + 1;
@@ -1261,7 +1228,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1261 { 1228 {
1262 /* Slide from the bottom. */ 1229 /* Slide from the bottom. */
1263 dest->elems[id + delta] = dest->elems[id]; 1230 dest->elems[id + delta] = dest->elems[id];
1264 if (! REG_VALID_INDEX (--id)) 1231 if (--id < 0)
1265 { 1232 {
1266 /* Copy remaining SRC elements. */ 1233 /* Copy remaining SRC elements. */
1267 memcpy (dest->elems, dest->elems + sbase, 1234 memcpy (dest->elems, dest->elems + sbase,
@@ -1279,17 +1246,20 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1279 Return true if successful. */ 1246 Return true if successful. */
1280 1247
1281static bool 1248static bool
1282internal_function __attribute_warn_unused_result__ 1249__attribute_warn_unused_result__
1283re_node_set_insert (re_node_set *set, Idx elem) 1250re_node_set_insert (re_node_set *set, Idx elem)
1284{ 1251{
1285 Idx idx; 1252 Idx idx;
1286 /* In case the set is empty. */ 1253 /* In case the set is empty. */
1287 if (set->alloc == 0) 1254 if (set->alloc == 0)
1288 return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1); 1255 return __glibc_likely (re_node_set_init_1 (set, elem) == REG_NOERROR);
1289 1256
1290 if (BE (set->nelem, 0) == 0) 1257 if (__glibc_unlikely (set->nelem) == 0)
1291 { 1258 {
1292 /* We already guaranteed above that set->alloc != 0. */ 1259 /* Although we already guaranteed above that set->alloc != 0 and
1260 therefore set->elems != NULL, add a debug assertion to pacify
1261 GCC 11.2 -fanalyzer. */
1262 DEBUG_ASSERT (set->elems);
1293 set->elems[0] = elem; 1263 set->elems[0] = elem;
1294 ++set->nelem; 1264 ++set->nelem;
1295 return true; 1265 return true;
@@ -1301,7 +1271,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1301 Idx *new_elems; 1271 Idx *new_elems;
1302 set->alloc = set->alloc * 2; 1272 set->alloc = set->alloc * 2;
1303 new_elems = re_realloc (set->elems, Idx, set->alloc); 1273 new_elems = re_realloc (set->elems, Idx, set->alloc);
1304 if (BE (new_elems == NULL, 0)) 1274 if (__glibc_unlikely (new_elems == NULL))
1305 return false; 1275 return false;
1306 set->elems = new_elems; 1276 set->elems = new_elems;
1307 } 1277 }
@@ -1310,7 +1280,6 @@ re_node_set_insert (re_node_set *set, Idx elem)
1310 first element separately to skip a check in the inner loop. */ 1280 first element separately to skip a check in the inner loop. */
1311 if (elem < set->elems[0]) 1281 if (elem < set->elems[0])
1312 { 1282 {
1313 idx = 0;
1314 for (idx = set->nelem; idx > 0; idx--) 1283 for (idx = set->nelem; idx > 0; idx--)
1315 set->elems[idx] = set->elems[idx - 1]; 1284 set->elems[idx] = set->elems[idx - 1];
1316 } 1285 }
@@ -1318,6 +1287,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1318 { 1287 {
1319 for (idx = set->nelem; set->elems[idx - 1] > elem; idx--) 1288 for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
1320 set->elems[idx] = set->elems[idx - 1]; 1289 set->elems[idx] = set->elems[idx - 1];
1290 DEBUG_ASSERT (set->elems[idx - 1] < elem);
1321 } 1291 }
1322 1292
1323 /* Insert the new element. */ 1293 /* Insert the new element. */
@@ -1331,7 +1301,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1331 Return true if successful. */ 1301 Return true if successful. */
1332 1302
1333static bool 1303static bool
1334internal_function __attribute_warn_unused_result__ 1304__attribute_warn_unused_result__
1335re_node_set_insert_last (re_node_set *set, Idx elem) 1305re_node_set_insert_last (re_node_set *set, Idx elem)
1336{ 1306{
1337 /* Realloc if we need. */ 1307 /* Realloc if we need. */
@@ -1340,7 +1310,7 @@ re_node_set_insert_last (re_node_set *set, Idx elem)
1340 Idx *new_elems; 1310 Idx *new_elems;
1341 set->alloc = (set->alloc + 1) * 2; 1311 set->alloc = (set->alloc + 1) * 2;
1342 new_elems = re_realloc (set->elems, Idx, set->alloc); 1312 new_elems = re_realloc (set->elems, Idx, set->alloc);
1343 if (BE (new_elems == NULL, 0)) 1313 if (__glibc_unlikely (new_elems == NULL))
1344 return false; 1314 return false;
1345 set->elems = new_elems; 1315 set->elems = new_elems;
1346 } 1316 }
@@ -1354,13 +1324,13 @@ re_node_set_insert_last (re_node_set *set, Idx elem)
1354 Return true if SET1 and SET2 are equivalent. */ 1324 Return true if SET1 and SET2 are equivalent. */
1355 1325
1356static bool 1326static bool
1357internal_function __attribute__ ((pure)) 1327__attribute__ ((pure))
1358re_node_set_compare (const re_node_set *set1, const re_node_set *set2) 1328re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
1359{ 1329{
1360 Idx i; 1330 Idx i;
1361 if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem) 1331 if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
1362 return false; 1332 return false;
1363 for (i = set1->nelem ; REG_VALID_INDEX (--i) ; ) 1333 for (i = set1->nelem ; --i >= 0 ; )
1364 if (set1->elems[i] != set2->elems[i]) 1334 if (set1->elems[i] != set2->elems[i])
1365 return false; 1335 return false;
1366 return true; 1336 return true;
@@ -1369,11 +1339,11 @@ re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
1369/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */ 1339/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */
1370 1340
1371static Idx 1341static Idx
1372internal_function __attribute__ ((pure)) 1342__attribute__ ((pure))
1373re_node_set_contains (const re_node_set *set, Idx elem) 1343re_node_set_contains (const re_node_set *set, Idx elem)
1374{ 1344{
1375 __re_size_t idx, right, mid; 1345 __re_size_t idx, right, mid;
1376 if (! REG_VALID_NONZERO_INDEX (set->nelem)) 1346 if (set->nelem <= 0)
1377 return 0; 1347 return 0;
1378 1348
1379 /* Binary search the element. */ 1349 /* Binary search the element. */
@@ -1391,7 +1361,6 @@ re_node_set_contains (const re_node_set *set, Idx elem)
1391} 1361}
1392 1362
1393static void 1363static void
1394internal_function
1395re_node_set_remove_at (re_node_set *set, Idx idx) 1364re_node_set_remove_at (re_node_set *set, Idx idx)
1396{ 1365{
1397 if (idx < 0 || idx >= set->nelem) 1366 if (idx < 0 || idx >= set->nelem)
@@ -1403,13 +1372,12 @@ re_node_set_remove_at (re_node_set *set, Idx idx)
1403 1372
1404 1373
1405/* Add the token TOKEN to dfa->nodes, and return the index of the token. 1374/* Add the token TOKEN to dfa->nodes, and return the index of the token.
1406 Or return REG_MISSING if an error occurred. */ 1375 Or return -1 if an error occurred. */
1407 1376
1408static Idx 1377static Idx
1409internal_function
1410re_dfa_add_node (re_dfa_t *dfa, re_token_t token) 1378re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
1411{ 1379{
1412 if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) 1380 if (__glibc_unlikely (dfa->nodes_len >= dfa->nodes_alloc))
1413 { 1381 {
1414 size_t new_nodes_alloc = dfa->nodes_alloc * 2; 1382 size_t new_nodes_alloc = dfa->nodes_alloc * 2;
1415 Idx *new_nexts, *new_indices; 1383 Idx *new_nexts, *new_indices;
@@ -1420,41 +1388,43 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
1420 const size_t max_object_size = MAX (sizeof (re_token_t), 1388 const size_t max_object_size = MAX (sizeof (re_token_t),
1421 MAX (sizeof (re_node_set), 1389 MAX (sizeof (re_node_set),
1422 sizeof (Idx))); 1390 sizeof (Idx)));
1423 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0)) 1391 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size)
1424 return REG_MISSING; 1392 < new_nodes_alloc))
1393 return -1;
1425 1394
1426 new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc); 1395 new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
1427 if (BE (new_nodes == NULL, 0)) 1396 if (__glibc_unlikely (new_nodes == NULL))
1428 return REG_MISSING; 1397 return -1;
1429 dfa->nodes = new_nodes; 1398 dfa->nodes = new_nodes;
1399 dfa->nodes_alloc = new_nodes_alloc;
1430 new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); 1400 new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
1401 if (new_nexts != NULL)
1402 dfa->nexts = new_nexts;
1431 new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); 1403 new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
1404 if (new_indices != NULL)
1405 dfa->org_indices = new_indices;
1432 new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc); 1406 new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
1407 if (new_edests != NULL)
1408 dfa->edests = new_edests;
1433 new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); 1409 new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
1434 if (BE (new_nexts == NULL || new_indices == NULL 1410 if (new_eclosures != NULL)
1435 || new_edests == NULL || new_eclosures == NULL, 0)) 1411 dfa->eclosures = new_eclosures;
1436 return REG_MISSING; 1412 if (__glibc_unlikely (new_nexts == NULL || new_indices == NULL
1437 dfa->nexts = new_nexts; 1413 || new_edests == NULL || new_eclosures == NULL))
1438 dfa->org_indices = new_indices; 1414 return -1;
1439 dfa->edests = new_edests;
1440 dfa->eclosures = new_eclosures;
1441 dfa->nodes_alloc = new_nodes_alloc;
1442 } 1415 }
1443 dfa->nodes[dfa->nodes_len] = token; 1416 dfa->nodes[dfa->nodes_len] = token;
1444 dfa->nodes[dfa->nodes_len].constraint = 0; 1417 dfa->nodes[dfa->nodes_len].constraint = 0;
1445#ifdef RE_ENABLE_I18N
1446 dfa->nodes[dfa->nodes_len].accept_mb = 1418 dfa->nodes[dfa->nodes_len].accept_mb =
1447 ((token.type == OP_PERIOD && dfa->mb_cur_max > 1) 1419 ((token.type == OP_PERIOD && dfa->mb_cur_max > 1)
1448 || token.type == COMPLEX_BRACKET); 1420 || token.type == COMPLEX_BRACKET);
1449#endif 1421 dfa->nexts[dfa->nodes_len] = -1;
1450 dfa->nexts[dfa->nodes_len] = REG_MISSING;
1451 re_node_set_init_empty (dfa->edests + dfa->nodes_len); 1422 re_node_set_init_empty (dfa->edests + dfa->nodes_len);
1452 re_node_set_init_empty (dfa->eclosures + dfa->nodes_len); 1423 re_node_set_init_empty (dfa->eclosures + dfa->nodes_len);
1453 return dfa->nodes_len++; 1424 return dfa->nodes_len++;
1454} 1425}
1455 1426
1456static re_hashval_t 1427static re_hashval_t
1457internal_function
1458calc_state_hash (const re_node_set *nodes, unsigned int context) 1428calc_state_hash (const re_node_set *nodes, unsigned int context)
1459{ 1429{
1460 re_hashval_t hash = nodes->nelem + context; 1430 re_hashval_t hash = nodes->nelem + context;
@@ -1474,7 +1444,7 @@ calc_state_hash (const re_node_set *nodes, unsigned int context)
1474 optimization. */ 1444 optimization. */
1475 1445
1476static re_dfastate_t * 1446static re_dfastate_t *
1477internal_function __attribute_warn_unused_result__ 1447__attribute_warn_unused_result__
1478re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, 1448re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1479 const re_node_set *nodes) 1449 const re_node_set *nodes)
1480{ 1450{
@@ -1482,11 +1452,11 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1482 re_dfastate_t *new_state; 1452 re_dfastate_t *new_state;
1483 struct re_state_table_entry *spot; 1453 struct re_state_table_entry *spot;
1484 Idx i; 1454 Idx i;
1485#ifdef lint 1455#if defined GCC_LINT || defined lint
1486 /* Suppress bogus uninitialized-variable warnings. */ 1456 /* Suppress bogus uninitialized-variable warnings. */
1487 *err = REG_NOERROR; 1457 *err = REG_NOERROR;
1488#endif 1458#endif
1489 if (BE (nodes->nelem == 0, 0)) 1459 if (__glibc_unlikely (nodes->nelem == 0))
1490 { 1460 {
1491 *err = REG_NOERROR; 1461 *err = REG_NOERROR;
1492 return NULL; 1462 return NULL;
@@ -1505,7 +1475,7 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1505 1475
1506 /* There are no appropriate state in the dfa, create the new one. */ 1476 /* There are no appropriate state in the dfa, create the new one. */
1507 new_state = create_ci_newstate (dfa, nodes, hash); 1477 new_state = create_ci_newstate (dfa, nodes, hash);
1508 if (BE (new_state == NULL, 0)) 1478 if (__glibc_unlikely (new_state == NULL))
1509 *err = REG_ESPACE; 1479 *err = REG_ESPACE;
1510 1480
1511 return new_state; 1481 return new_state;
@@ -1522,7 +1492,7 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1522 optimization. */ 1492 optimization. */
1523 1493
1524static re_dfastate_t * 1494static re_dfastate_t *
1525internal_function __attribute_warn_unused_result__ 1495__attribute_warn_unused_result__
1526re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, 1496re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1527 const re_node_set *nodes, unsigned int context) 1497 const re_node_set *nodes, unsigned int context)
1528{ 1498{
@@ -1530,7 +1500,7 @@ re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1530 re_dfastate_t *new_state; 1500 re_dfastate_t *new_state;
1531 struct re_state_table_entry *spot; 1501 struct re_state_table_entry *spot;
1532 Idx i; 1502 Idx i;
1533#ifdef lint 1503#if defined GCC_LINT || defined lint
1534 /* Suppress bogus uninitialized-variable warnings. */ 1504 /* Suppress bogus uninitialized-variable warnings. */
1535 *err = REG_NOERROR; 1505 *err = REG_NOERROR;
1536#endif 1506#endif
@@ -1552,7 +1522,7 @@ re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1552 } 1522 }
1553 /* There are no appropriate state in 'dfa', create the new one. */ 1523 /* There are no appropriate state in 'dfa', create the new one. */
1554 new_state = create_cd_newstate (dfa, nodes, context, hash); 1524 new_state = create_cd_newstate (dfa, nodes, context, hash);
1555 if (BE (new_state == NULL, 0)) 1525 if (__glibc_unlikely (new_state == NULL))
1556 *err = REG_ESPACE; 1526 *err = REG_ESPACE;
1557 1527
1558 return new_state; 1528 return new_state;
@@ -1573,7 +1543,7 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
1573 1543
1574 newstate->hash = hash; 1544 newstate->hash = hash;
1575 err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem); 1545 err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem);
1576 if (BE (err != REG_NOERROR, 0)) 1546 if (__glibc_unlikely (err != REG_NOERROR))
1577 return REG_ESPACE; 1547 return REG_ESPACE;
1578 for (i = 0; i < newstate->nodes.nelem; i++) 1548 for (i = 0; i < newstate->nodes.nelem; i++)
1579 { 1549 {
@@ -1584,12 +1554,12 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
1584 } 1554 }
1585 1555
1586 spot = dfa->state_table + (hash & dfa->state_hash_mask); 1556 spot = dfa->state_table + (hash & dfa->state_hash_mask);
1587 if (BE (spot->alloc <= spot->num, 0)) 1557 if (__glibc_unlikely (spot->alloc <= spot->num))
1588 { 1558 {
1589 Idx new_alloc = 2 * spot->num + 2; 1559 Idx new_alloc = 2 * spot->num + 2;
1590 re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *, 1560 re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
1591 new_alloc); 1561 new_alloc);
1592 if (BE (new_array == NULL, 0)) 1562 if (__glibc_unlikely (new_array == NULL))
1593 return REG_ESPACE; 1563 return REG_ESPACE;
1594 spot->array = new_array; 1564 spot->array = new_array;
1595 spot->alloc = new_alloc; 1565 spot->alloc = new_alloc;
@@ -1618,7 +1588,7 @@ free_state (re_dfastate_t *state)
1618 Return the new state if succeeded, otherwise return NULL. */ 1588 Return the new state if succeeded, otherwise return NULL. */
1619 1589
1620static re_dfastate_t * 1590static re_dfastate_t *
1621internal_function __attribute_warn_unused_result__ 1591__attribute_warn_unused_result__
1622create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1592create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1623 re_hashval_t hash) 1593 re_hashval_t hash)
1624{ 1594{
@@ -1627,10 +1597,10 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1627 re_dfastate_t *newstate; 1597 re_dfastate_t *newstate;
1628 1598
1629 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); 1599 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
1630 if (BE (newstate == NULL, 0)) 1600 if (__glibc_unlikely (newstate == NULL))
1631 return NULL; 1601 return NULL;
1632 err = re_node_set_init_copy (&newstate->nodes, nodes); 1602 err = re_node_set_init_copy (&newstate->nodes, nodes);
1633 if (BE (err != REG_NOERROR, 0)) 1603 if (__glibc_unlikely (err != REG_NOERROR))
1634 { 1604 {
1635 re_free (newstate); 1605 re_free (newstate);
1636 return NULL; 1606 return NULL;
@@ -1643,9 +1613,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1643 re_token_type_t type = node->type; 1613 re_token_type_t type = node->type;
1644 if (type == CHARACTER && !node->constraint) 1614 if (type == CHARACTER && !node->constraint)
1645 continue; 1615 continue;
1646#ifdef RE_ENABLE_I18N
1647 newstate->accept_mb |= node->accept_mb; 1616 newstate->accept_mb |= node->accept_mb;
1648#endif /* RE_ENABLE_I18N */
1649 1617
1650 /* If the state has the halt node, the state is a halt state. */ 1618 /* If the state has the halt node, the state is a halt state. */
1651 if (type == END_OF_RE) 1619 if (type == END_OF_RE)
@@ -1656,7 +1624,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1656 newstate->has_constraint = 1; 1624 newstate->has_constraint = 1;
1657 } 1625 }
1658 err = register_state (dfa, newstate, hash); 1626 err = register_state (dfa, newstate, hash);
1659 if (BE (err != REG_NOERROR, 0)) 1627 if (__glibc_unlikely (err != REG_NOERROR))
1660 { 1628 {
1661 free_state (newstate); 1629 free_state (newstate);
1662 newstate = NULL; 1630 newstate = NULL;
@@ -1668,7 +1636,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1668 Return the new state if succeeded, otherwise return NULL. */ 1636 Return the new state if succeeded, otherwise return NULL. */
1669 1637
1670static re_dfastate_t * 1638static re_dfastate_t *
1671internal_function __attribute_warn_unused_result__ 1639__attribute_warn_unused_result__
1672create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1640create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1673 unsigned int context, re_hashval_t hash) 1641 unsigned int context, re_hashval_t hash)
1674{ 1642{
@@ -1677,10 +1645,10 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1677 re_dfastate_t *newstate; 1645 re_dfastate_t *newstate;
1678 1646
1679 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); 1647 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
1680 if (BE (newstate == NULL, 0)) 1648 if (__glibc_unlikely (newstate == NULL))
1681 return NULL; 1649 return NULL;
1682 err = re_node_set_init_copy (&newstate->nodes, nodes); 1650 err = re_node_set_init_copy (&newstate->nodes, nodes);
1683 if (BE (err != REG_NOERROR, 0)) 1651 if (__glibc_unlikely (err != REG_NOERROR))
1684 { 1652 {
1685 re_free (newstate); 1653 re_free (newstate);
1686 return NULL; 1654 return NULL;
@@ -1697,9 +1665,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1697 1665
1698 if (type == CHARACTER && !constraint) 1666 if (type == CHARACTER && !constraint)
1699 continue; 1667 continue;
1700#ifdef RE_ENABLE_I18N
1701 newstate->accept_mb |= node->accept_mb; 1668 newstate->accept_mb |= node->accept_mb;
1702#endif /* RE_ENABLE_I18N */
1703 1669
1704 /* If the state has the halt node, the state is a halt state. */ 1670 /* If the state has the halt node, the state is a halt state. */
1705 if (type == END_OF_RE) 1671 if (type == END_OF_RE)
@@ -1711,15 +1677,19 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1711 { 1677 {
1712 if (newstate->entrance_nodes == &newstate->nodes) 1678 if (newstate->entrance_nodes == &newstate->nodes)
1713 { 1679 {
1714 newstate->entrance_nodes = re_malloc (re_node_set, 1); 1680 re_node_set *entrance_nodes = re_malloc (re_node_set, 1);
1715 if (BE (newstate->entrance_nodes == NULL, 0)) 1681 if (__glibc_unlikely (entrance_nodes == NULL))
1716 { 1682 {
1717 free_state (newstate); 1683 free_state (newstate);
1718 return NULL; 1684 return NULL;
1719 } 1685 }
1686 newstate->entrance_nodes = entrance_nodes;
1720 if (re_node_set_init_copy (newstate->entrance_nodes, nodes) 1687 if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
1721 != REG_NOERROR) 1688 != REG_NOERROR)
1722 return NULL; 1689 {
1690 free_state (newstate);
1691 return NULL;
1692 }
1723 nctx_nodes = 0; 1693 nctx_nodes = 0;
1724 newstate->has_constraint = 1; 1694 newstate->has_constraint = 1;
1725 } 1695 }
@@ -1732,7 +1702,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1732 } 1702 }
1733 } 1703 }
1734 err = register_state (dfa, newstate, hash); 1704 err = register_state (dfa, newstate, hash);
1735 if (BE (err != REG_NOERROR, 0)) 1705 if (__glibc_unlikely (err != REG_NOERROR))
1736 { 1706 {
1737 free_state (newstate); 1707 free_state (newstate);
1738 newstate = NULL; 1708 newstate = NULL;
diff --git a/gl/regex_internal.h b/gl/regex_internal.h
index a2b8f16..149ec2e 100644
--- a/gl/regex_internal.h
+++ b/gl/regex_internal.h
@@ -1,26 +1,25 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc. 2 Copyright (C) 2002-2023 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 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
19 19
20#ifndef _REGEX_INTERNAL_H 20#ifndef _REGEX_INTERNAL_H
21#define _REGEX_INTERNAL_H 1 21#define _REGEX_INTERNAL_H 1
22 22
23#include <assert.h>
24#include <ctype.h> 23#include <ctype.h>
25#include <stdio.h> 24#include <stdio.h>
26#include <stdlib.h> 25#include <stdlib.h>
@@ -30,39 +29,37 @@
30#include <locale.h> 29#include <locale.h>
31#include <wchar.h> 30#include <wchar.h>
32#include <wctype.h> 31#include <wctype.h>
33#include <stdbool.h>
34#include <stdint.h> 32#include <stdint.h>
35 33
34#ifndef _LIBC
35# include <dynarray.h>
36#endif
37
38#include <intprops.h>
39#include <verify.h>
40
41#if defined DEBUG && DEBUG != 0
42# include <assert.h>
43# define DEBUG_ASSERT(x) assert (x)
44#else
45# define DEBUG_ASSERT(x) assume (x)
46#endif
47
36#ifdef _LIBC 48#ifdef _LIBC
37# include <bits/libc-lock.h> 49# include <libc-lock.h>
38# define lock_define(name) __libc_lock_define (, name) 50# define lock_define(name) __libc_lock_define (, name)
39# define lock_init(lock) (__libc_lock_init (lock), 0) 51# define lock_init(lock) (__libc_lock_init (lock), 0)
40# define lock_fini(lock) 0 52# define lock_fini(lock) ((void) 0)
41# define lock_lock(lock) __libc_lock_lock (lock) 53# define lock_lock(lock) __libc_lock_lock (lock)
42# define lock_unlock(lock) __libc_lock_unlock (lock) 54# define lock_unlock(lock) __libc_lock_unlock (lock)
43#elif defined GNULIB_LOCK 55#elif defined GNULIB_LOCK && !defined GNULIB_REGEX_SINGLE_THREAD
44# include "glthread/lock.h" 56# include "glthread/lock.h"
45 /* Use gl_lock_define if empty macro arguments are known to work. 57# define lock_define(name) gl_lock_define (, name)
46 Otherwise, fall back on less-portable substitutes. */
47# if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
48 || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
49# define lock_define(name) gl_lock_define (, name)
50# elif USE_POSIX_THREADS
51# define lock_define(name) pthread_mutex_t name;
52# elif USE_PTH_THREADS
53# define lock_define(name) pth_mutex_t name;
54# elif USE_SOLARIS_THREADS
55# define lock_define(name) mutex_t name;
56# elif USE_WINDOWS_THREADS
57# define lock_define(name) gl_lock_t name;
58# else
59# define lock_define(name)
60# endif
61# define lock_init(lock) glthread_lock_init (&(lock)) 58# define lock_init(lock) glthread_lock_init (&(lock))
62# define lock_fini(lock) glthread_lock_destroy (&(lock)) 59# define lock_fini(lock) glthread_lock_destroy (&(lock))
63# define lock_lock(lock) glthread_lock_lock (&(lock)) 60# define lock_lock(lock) glthread_lock_lock (&(lock))
64# define lock_unlock(lock) glthread_lock_unlock (&(lock)) 61# define lock_unlock(lock) glthread_lock_unlock (&(lock))
65#elif defined GNULIB_PTHREAD 62#elif defined GNULIB_PTHREAD && !defined GNULIB_REGEX_SINGLE_THREAD
66# include <pthread.h> 63# include <pthread.h>
67# define lock_define(name) pthread_mutex_t name; 64# define lock_define(name) pthread_mutex_t name;
68# define lock_init(lock) pthread_mutex_init (&(lock), 0) 65# define lock_init(lock) pthread_mutex_init (&(lock), 0)
@@ -83,11 +80,18 @@
83# define isblank(ch) ((ch) == ' ' || (ch) == '\t') 80# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
84#endif 81#endif
85 82
83/* regex code assumes isascii has its usual numeric meaning,
84 even if the portable character set uses EBCDIC encoding,
85 and even if wint_t is wider than int. */
86#ifndef _LIBC
87# undef isascii
88# define isascii(c) (((c) & ~0x7f) == 0)
89#endif
90
86#ifdef _LIBC 91#ifdef _LIBC
87# ifndef _RE_DEFINE_LOCALE_FUNCTIONS 92# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
88# define _RE_DEFINE_LOCALE_FUNCTIONS 1 93# define _RE_DEFINE_LOCALE_FUNCTIONS 1
89# include <locale/localeinfo.h> 94# include <locale/localeinfo.h>
90# include <locale/elem-hash.h>
91# include <locale/coll-lookup.h> 95# include <locale/coll-lookup.h>
92# endif 96# endif
93#endif 97#endif
@@ -101,6 +105,7 @@
101 __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) 105 __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
102# endif 106# endif
103#else 107#else
108# undef gettext
104# define gettext(msgid) (msgid) 109# define gettext(msgid) (msgid)
105#endif 110#endif
106 111
@@ -110,16 +115,6 @@
110# define gettext_noop(String) String 115# define gettext_noop(String) String
111#endif 116#endif
112 117
113#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC
114# define RE_ENABLE_I18N
115#endif
116
117#if __GNUC__ >= 3
118# define BE(expr, val) __builtin_expect (expr, val)
119#else
120# define BE(expr, val) (expr)
121#endif
122
123/* Number of ASCII characters. */ 118/* Number of ASCII characters. */
124#define ASCII_CHARS 0x80 119#define ASCII_CHARS 0x80
125 120
@@ -135,45 +130,60 @@
135/* Rename to standard API for using out of glibc. */ 130/* Rename to standard API for using out of glibc. */
136#ifndef _LIBC 131#ifndef _LIBC
137# undef __wctype 132# undef __wctype
133# undef __iswalnum
138# undef __iswctype 134# undef __iswctype
135# undef __towlower
136# undef __towupper
139# define __wctype wctype 137# define __wctype wctype
138# define __iswalnum iswalnum
140# define __iswctype iswctype 139# define __iswctype iswctype
140# define __towlower towlower
141# define __towupper towupper
141# define __btowc btowc 142# define __btowc btowc
142# define __mbrtowc mbrtowc 143# define __mbrtowc mbrtowc
143# define __wcrtomb wcrtomb 144# define __wcrtomb wcrtomb
144# define __regfree regfree 145# define __regfree regfree
145# define attribute_hidden
146#endif /* not _LIBC */ 146#endif /* not _LIBC */
147 147
148#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) 148/* Types related to integers. Unless protected by #ifdef _LIBC, the
149# define __attribute__(arg) 149 regex code should avoid exact-width types like int32_t and uint64_t
150#endif 150 as some non-GCC platforms lack them, an issue when this code is
151 used in Gnulib. */
151 152
152typedef __re_idx_t Idx; 153#ifndef SSIZE_MAX
153#ifdef _REGEX_LARGE_OFFSETS 154# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
154# define IDX_MAX (SIZE_MAX - 2)
155#else
156# define IDX_MAX INT_MAX
157#endif 155#endif
158 156#ifndef ULONG_WIDTH
159/* Special return value for failure to match. */ 157# define ULONG_WIDTH REGEX_UINTEGER_WIDTH (ULONG_MAX)
160#define REG_MISSING ((Idx) -1) 158/* The number of usable bits in an unsigned integer type with maximum
161 159 value MAX, as an int expression suitable in #if. Cover all known
162/* Special return value for internal error. */ 160 practical hosts. This implementation exploits the fact that MAX is
163#define REG_ERROR ((Idx) -2) 161 1 less than a power of 2, and merely counts the number of 1 bits in
164 162 MAX; "COBn" means "count the number of 1 bits in the low-order n bits". */
165/* Test whether N is a valid index, and is not one of the above. */ 163# define REGEX_UINTEGER_WIDTH(max) REGEX_COB128 (max)
166#ifdef _REGEX_LARGE_OFFSETS 164# define REGEX_COB128(n) (REGEX_COB64 ((n) >> 31 >> 31 >> 2) + REGEX_COB64 (n))
167# define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR) 165# define REGEX_COB64(n) (REGEX_COB32 ((n) >> 31 >> 1) + REGEX_COB32 (n))
168#else 166# define REGEX_COB32(n) (REGEX_COB16 ((n) >> 16) + REGEX_COB16 (n))
169# define REG_VALID_INDEX(n) (0 <= (n)) 167# define REGEX_COB16(n) (REGEX_COB8 ((n) >> 8) + REGEX_COB8 (n))
168# define REGEX_COB8(n) (REGEX_COB4 ((n) >> 4) + REGEX_COB4 (n))
169# define REGEX_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + ((n) & 1))
170# if ULONG_MAX / 2 + 1 != 1ul << (ULONG_WIDTH - 1)
171# error "ULONG_MAX out of range"
172# endif
170#endif 173#endif
171 174
172/* Test whether N is a valid nonzero index. */ 175/* The type of indexes into strings. This is signed, not size_t,
176 since the API requires indexes to fit in regoff_t anyway, and using
177 signed integers makes the code a bit smaller and presumably faster.
178 The traditional GNU regex implementation uses int for indexes.
179 The POSIX-compatible implementation uses a possibly-wider type.
180 The name 'Idx' is three letters to minimize the hassle of
181 reindenting a lot of regex code that formerly used 'int'. */
182typedef regoff_t Idx;
173#ifdef _REGEX_LARGE_OFFSETS 183#ifdef _REGEX_LARGE_OFFSETS
174# define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1)) 184# define IDX_MAX SSIZE_MAX
175#else 185#else
176# define REG_VALID_NONZERO_INDEX(n) (0 < (n)) 186# define IDX_MAX INT_MAX
177#endif 187#endif
178 188
179/* A hash value, suitable for computing hash tables. */ 189/* A hash value, suitable for computing hash tables. */
@@ -184,36 +194,8 @@ typedef __re_size_t re_hashval_t;
184typedef unsigned long int bitset_word_t; 194typedef unsigned long int bitset_word_t;
185/* All bits set in a bitset_word_t. */ 195/* All bits set in a bitset_word_t. */
186#define BITSET_WORD_MAX ULONG_MAX 196#define BITSET_WORD_MAX ULONG_MAX
187 197/* Number of bits in a bitset_word_t. */
188/* Number of bits in a bitset_word_t. For portability to hosts with 198#define BITSET_WORD_BITS ULONG_WIDTH
189 padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
190 instead, deduce it directly from BITSET_WORD_MAX. Avoid
191 greater-than-32-bit integers and unconditional shifts by more than
192 31 bits, as they're not portable. */
193#if BITSET_WORD_MAX == 0xffffffffUL
194# define BITSET_WORD_BITS 32
195#elif BITSET_WORD_MAX >> 31 >> 4 == 1
196# define BITSET_WORD_BITS 36
197#elif BITSET_WORD_MAX >> 31 >> 16 == 1
198# define BITSET_WORD_BITS 48
199#elif BITSET_WORD_MAX >> 31 >> 28 == 1
200# define BITSET_WORD_BITS 60
201#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
202# define BITSET_WORD_BITS 64
203#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
204# define BITSET_WORD_BITS 72
205#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
206# define BITSET_WORD_BITS 128
207#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
208# define BITSET_WORD_BITS 256
209#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
210# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
211# if BITSET_WORD_BITS <= SBC_MAX
212# error "Invalid SBC_MAX"
213# endif
214#else
215# error "Add case for new bitset_word_t size"
216#endif
217 199
218/* Number of bitset_word_t values in a bitset_t. */ 200/* Number of bitset_word_t values in a bitset_t. */
219#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) 201#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
@@ -264,10 +246,8 @@ typedef enum
264 SIMPLE_BRACKET = 3, 246 SIMPLE_BRACKET = 3,
265 OP_BACK_REF = 4, 247 OP_BACK_REF = 4,
266 OP_PERIOD = 5, 248 OP_PERIOD = 5,
267#ifdef RE_ENABLE_I18N
268 COMPLEX_BRACKET = 6, 249 COMPLEX_BRACKET = 6,
269 OP_UTF8_PERIOD = 7, 250 OP_UTF8_PERIOD = 7,
270#endif /* RE_ENABLE_I18N */
271 251
272 /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used 252 /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
273 when the debugger shows values of this enum type. */ 253 when the debugger shows values of this enum type. */
@@ -305,30 +285,29 @@ typedef enum
305 285
306} re_token_type_t; 286} re_token_type_t;
307 287
308#ifdef RE_ENABLE_I18N
309typedef struct 288typedef struct
310{ 289{
311 /* Multibyte characters. */ 290 /* Multibyte characters. */
312 wchar_t *mbchars; 291 wchar_t *mbchars;
313 292
293#ifdef _LIBC
314 /* Collating symbols. */ 294 /* Collating symbols. */
315# ifdef _LIBC
316 int32_t *coll_syms; 295 int32_t *coll_syms;
317# endif 296#endif
318 297
298#ifdef _LIBC
319 /* Equivalence classes. */ 299 /* Equivalence classes. */
320# ifdef _LIBC
321 int32_t *equiv_classes; 300 int32_t *equiv_classes;
322# endif 301#endif
323 302
324 /* Range expressions. */ 303 /* Range expressions. */
325# ifdef _LIBC 304#ifdef _LIBC
326 uint32_t *range_starts; 305 uint32_t *range_starts;
327 uint32_t *range_ends; 306 uint32_t *range_ends;
328# else /* not _LIBC */ 307#else
329 wchar_t *range_starts; 308 wchar_t *range_starts;
330 wchar_t *range_ends; 309 wchar_t *range_ends;
331# endif /* not _LIBC */ 310#endif
332 311
333 /* Character classes. */ 312 /* Character classes. */
334 wctype_t *char_classes; 313 wctype_t *char_classes;
@@ -351,7 +330,6 @@ typedef struct
351 /* # of character classes. */ 330 /* # of character classes. */
352 Idx nchar_classes; 331 Idx nchar_classes;
353} re_charset_t; 332} re_charset_t;
354#endif /* RE_ENABLE_I18N */
355 333
356typedef struct 334typedef struct
357{ 335{
@@ -359,13 +337,11 @@ typedef struct
359 { 337 {
360 unsigned char c; /* for CHARACTER */ 338 unsigned char c; /* for CHARACTER */
361 re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */ 339 re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
362#ifdef RE_ENABLE_I18N
363 re_charset_t *mbcset; /* for COMPLEX_BRACKET */ 340 re_charset_t *mbcset; /* for COMPLEX_BRACKET */
364#endif /* RE_ENABLE_I18N */
365 Idx idx; /* for BACK_REF */ 341 Idx idx; /* for BACK_REF */
366 re_context_type ctx_type; /* for ANCHOR */ 342 re_context_type ctx_type; /* for ANCHOR */
367 } opr; 343 } opr;
368#if __GNUC__ >= 2 && !defined __STRICT_ANSI__ 344#if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
369 re_token_type_t type : 8; 345 re_token_type_t type : 8;
370#else 346#else
371 re_token_type_t type; 347 re_token_type_t type;
@@ -373,12 +349,10 @@ typedef struct
373 unsigned int constraint : 10; /* context constraint */ 349 unsigned int constraint : 10; /* context constraint */
374 unsigned int duplicated : 1; 350 unsigned int duplicated : 1;
375 unsigned int opt_subexp : 1; 351 unsigned int opt_subexp : 1;
376#ifdef RE_ENABLE_I18N
377 unsigned int accept_mb : 1; 352 unsigned int accept_mb : 1;
378 /* These 2 bits can be moved into the union if needed (e.g. if running out 353 /* These 2 bits can be moved into the union if needed (e.g. if running out
379 of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */ 354 of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */
380 unsigned int mb_partial : 1; 355 unsigned int mb_partial : 1;
381#endif
382 unsigned int word_char : 1; 356 unsigned int word_char : 1;
383} re_token_t; 357} re_token_t;
384 358
@@ -393,12 +367,10 @@ struct re_string_t
393 REG_ICASE, upper cases of the string are stored, otherwise MBS points 367 REG_ICASE, upper cases of the string are stored, otherwise MBS points
394 the same address that RAW_MBS points. */ 368 the same address that RAW_MBS points. */
395 unsigned char *mbs; 369 unsigned char *mbs;
396#ifdef RE_ENABLE_I18N
397 /* Store the wide character string which is corresponding to MBS. */ 370 /* Store the wide character string which is corresponding to MBS. */
398 wint_t *wcs; 371 wint_t *wcs;
399 Idx *offsets; 372 Idx *offsets;
400 mbstate_t cur_state; 373 mbstate_t cur_state;
401#endif
402 /* Index in RAW_MBS. Each character mbs[i] corresponds to 374 /* Index in RAW_MBS. Each character mbs[i] corresponds to
403 raw_mbs[raw_mbs_idx + i]. */ 375 raw_mbs[raw_mbs_idx + i]. */
404 Idx raw_mbs_idx; 376 Idx raw_mbs_idx;
@@ -446,24 +418,9 @@ struct re_dfa_t;
446typedef struct re_dfa_t re_dfa_t; 418typedef struct re_dfa_t re_dfa_t;
447 419
448#ifndef _LIBC 420#ifndef _LIBC
449# define internal_function 421# define IS_IN(libc) false
450#endif 422#endif
451 423
452#ifndef NOT_IN_libc
453static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
454 Idx new_buf_len)
455 internal_function;
456# ifdef RE_ENABLE_I18N
457static void build_wcs_buffer (re_string_t *pstr) internal_function;
458static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
459 internal_function;
460# endif /* RE_ENABLE_I18N */
461static void build_upper_buffer (re_string_t *pstr) internal_function;
462static void re_string_translate_buffer (re_string_t *pstr) internal_function;
463static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
464 int eflags)
465 internal_function __attribute__ ((pure));
466#endif
467#define re_string_peek_byte(pstr, offset) \ 424#define re_string_peek_byte(pstr, offset) \
468 ((pstr)->mbs[(pstr)->cur_idx + offset]) 425 ((pstr)->mbs[(pstr)->cur_idx + offset])
469#define re_string_fetch_byte(pstr) \ 426#define re_string_fetch_byte(pstr) \
@@ -481,25 +438,6 @@ static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
481#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) 438#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
482#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) 439#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
483 440
484#if defined _LIBC || HAVE_ALLOCA
485# include <alloca.h>
486#endif
487
488#ifndef _LIBC
489# if HAVE_ALLOCA
490/* The OS usually guarantees only one guard page at the bottom of the stack,
491 and a page size can be as small as 4096 bytes. So we cannot safely
492 allocate anything larger than 4096 bytes. Also care for the possibility
493 of a few compiler-allocated temporary stack slots. */
494# define __libc_use_alloca(n) ((n) < 4032)
495# else
496/* alloca is implemented with malloc, so just use malloc. */
497# define __libc_use_alloca(n) 0
498# undef alloca
499# define alloca(n) malloc (n)
500# endif
501#endif
502
503#ifdef _LIBC 441#ifdef _LIBC
504# define MALLOC_0_IS_NONNULL 1 442# define MALLOC_0_IS_NONNULL 1
505#elif !defined MALLOC_0_IS_NONNULL 443#elif !defined MALLOC_0_IS_NONNULL
@@ -556,7 +494,7 @@ typedef struct bin_tree_storage_t bin_tree_storage_t;
556 494
557#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') 495#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
558#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) 496#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
559#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_') 497#define IS_WIDE_WORD_CHAR(ch) (__iswalnum (ch) || (ch) == L'_')
560#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) 498#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
561 499
562#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ 500#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
@@ -636,20 +574,15 @@ struct re_backref_cache_entry
636 Idx str_idx; 574 Idx str_idx;
637 Idx subexp_from; 575 Idx subexp_from;
638 Idx subexp_to; 576 Idx subexp_to;
577 bitset_word_t eps_reachable_subexps_map;
639 char more; 578 char more;
640 char unused;
641 unsigned short int eps_reachable_subexps_map;
642}; 579};
643 580
644typedef struct 581typedef struct
645{ 582{
646 /* The string object corresponding to the input string. */ 583 /* The string object corresponding to the input string. */
647 re_string_t input; 584 re_string_t input;
648#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
649 const re_dfa_t *const dfa; 585 const re_dfa_t *const dfa;
650#else
651 const re_dfa_t *dfa;
652#endif
653 /* EFLAGS of the argument of regexec. */ 586 /* EFLAGS of the argument of regexec. */
654 int eflags; 587 int eflags;
655 /* Where the matching ends. */ 588 /* Where the matching ends. */
@@ -769,31 +702,31 @@ typedef struct
769 702
770/* Functions for bitset_t operation. */ 703/* Functions for bitset_t operation. */
771 704
772static void 705static inline void
773bitset_set (bitset_t set, Idx i) 706bitset_set (bitset_t set, Idx i)
774{ 707{
775 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; 708 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
776} 709}
777 710
778static void 711static inline void
779bitset_clear (bitset_t set, Idx i) 712bitset_clear (bitset_t set, Idx i)
780{ 713{
781 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); 714 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
782} 715}
783 716
784static bool 717static inline bool
785bitset_contain (const bitset_t set, Idx i) 718bitset_contain (const bitset_t set, Idx i)
786{ 719{
787 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; 720 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
788} 721}
789 722
790static void 723static inline void
791bitset_empty (bitset_t set) 724bitset_empty (bitset_t set)
792{ 725{
793 memset (set, '\0', sizeof (bitset_t)); 726 memset (set, '\0', sizeof (bitset_t));
794} 727}
795 728
796static void 729static inline void
797bitset_set_all (bitset_t set) 730bitset_set_all (bitset_t set)
798{ 731{
799 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); 732 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
@@ -802,13 +735,13 @@ bitset_set_all (bitset_t set)
802 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; 735 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
803} 736}
804 737
805static void 738static inline void
806bitset_copy (bitset_t dest, const bitset_t src) 739bitset_copy (bitset_t dest, const bitset_t src)
807{ 740{
808 memcpy (dest, src, sizeof (bitset_t)); 741 memcpy (dest, src, sizeof (bitset_t));
809} 742}
810 743
811static void __attribute__ ((unused)) 744static inline void
812bitset_not (bitset_t set) 745bitset_not (bitset_t set)
813{ 746{
814 int bitset_i; 747 int bitset_i;
@@ -820,7 +753,7 @@ bitset_not (bitset_t set)
820 & ~set[BITSET_WORDS - 1]); 753 & ~set[BITSET_WORDS - 1]);
821} 754}
822 755
823static void __attribute__ ((unused)) 756static inline void
824bitset_merge (bitset_t dest, const bitset_t src) 757bitset_merge (bitset_t dest, const bitset_t src)
825{ 758{
826 int bitset_i; 759 int bitset_i;
@@ -828,7 +761,7 @@ bitset_merge (bitset_t dest, const bitset_t src)
828 dest[bitset_i] |= src[bitset_i]; 761 dest[bitset_i] |= src[bitset_i];
829} 762}
830 763
831static void __attribute__ ((unused)) 764static inline void
832bitset_mask (bitset_t dest, const bitset_t src) 765bitset_mask (bitset_t dest, const bitset_t src)
833{ 766{
834 int bitset_i; 767 int bitset_i;
@@ -836,10 +769,9 @@ bitset_mask (bitset_t dest, const bitset_t src)
836 dest[bitset_i] &= src[bitset_i]; 769 dest[bitset_i] &= src[bitset_i];
837} 770}
838 771
839#ifdef RE_ENABLE_I18N
840/* Functions for re_string. */ 772/* Functions for re_string. */
841static int 773static int
842internal_function __attribute__ ((pure, unused)) 774__attribute__ ((pure, unused))
843re_string_char_size_at (const re_string_t *pstr, Idx idx) 775re_string_char_size_at (const re_string_t *pstr, Idx idx)
844{ 776{
845 int byte_idx; 777 int byte_idx;
@@ -852,7 +784,7 @@ re_string_char_size_at (const re_string_t *pstr, Idx idx)
852} 784}
853 785
854static wint_t 786static wint_t
855internal_function __attribute__ ((pure, unused)) 787__attribute__ ((pure, unused))
856re_string_wchar_at (const re_string_t *pstr, Idx idx) 788re_string_wchar_at (const re_string_t *pstr, Idx idx)
857{ 789{
858 if (pstr->mb_cur_max == 1) 790 if (pstr->mb_cur_max == 1)
@@ -860,15 +792,17 @@ re_string_wchar_at (const re_string_t *pstr, Idx idx)
860 return (wint_t) pstr->wcs[idx]; 792 return (wint_t) pstr->wcs[idx];
861} 793}
862 794
863# ifndef NOT_IN_libc 795#ifdef _LIBC
796# include <locale/weight.h>
797#endif
798
864static int 799static int
865internal_function __attribute__ ((pure, unused)) 800__attribute__ ((pure, unused))
866re_string_elem_size_at (const re_string_t *pstr, Idx idx) 801re_string_elem_size_at (const re_string_t *pstr, Idx idx)
867{ 802{
868# ifdef _LIBC 803#ifdef _LIBC
869 const unsigned char *p, *extra; 804 const unsigned char *p, *extra;
870 const int32_t *table, *indirect; 805 const int32_t *table, *indirect;
871# include <locale/weight.h>
872 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 806 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
873 807
874 if (nrules != 0) 808 if (nrules != 0)
@@ -879,31 +813,22 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
879 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, 813 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
880 _NL_COLLATE_INDIRECTMB); 814 _NL_COLLATE_INDIRECTMB);
881 p = pstr->mbs + idx; 815 p = pstr->mbs + idx;
882 findidx (&p, pstr->len - idx); 816 findidx (table, indirect, extra, &p, pstr->len - idx);
883 return p - pstr->mbs - idx; 817 return p - pstr->mbs - idx;
884 } 818 }
885 else 819#endif /* _LIBC */
886# endif /* _LIBC */ 820
887 return 1; 821 return 1;
888} 822}
889# endif
890#endif /* RE_ENABLE_I18N */
891 823
892#ifndef __GNUC_PREREQ 824#ifdef _LIBC
893# if defined __GNUC__ && defined __GNUC_MINOR__ 825# if __GNUC__ >= 7
894# define __GNUC_PREREQ(maj, min) \ 826# define FALLTHROUGH __attribute__ ((__fallthrough__))
895 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
896# else 827# else
897# define __GNUC_PREREQ(maj, min) 0 828# define FALLTHROUGH ((void) 0)
898# endif 829# endif
899#endif
900
901#if __GNUC_PREREQ (3,4)
902# undef __attribute_warn_unused_result__
903# define __attribute_warn_unused_result__ \
904 __attribute__ ((__warn_unused_result__))
905#else 830#else
906# define __attribute_warn_unused_result__ /* empty */ 831# include "attribute.h"
907#endif 832#endif
908 833
909#endif /* _REGEX_INTERNAL_H */ 834#endif /* _REGEX_INTERNAL_H */
diff --git a/gl/regexec.c b/gl/regexec.c
index d29d442..13e0349 100644
--- a/gl/regexec.c
+++ b/gl/regexec.c
@@ -1,206 +1,170 @@
1/* Extended regular expression matching and search library. 1/* Extended regular expression matching and search library.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc. 2 Copyright (C) 2002-2023 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 The GNU C Library is free software; you can redistribute it and/or 6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public 7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 The GNU C Library is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details. 14 Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public 16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <https://www.gnu.org/licenses/>. */
19 19
20static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags, 20static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
21 Idx n) internal_function; 21 Idx n);
22static void match_ctx_clean (re_match_context_t *mctx) internal_function; 22static void match_ctx_clean (re_match_context_t *mctx);
23static void match_ctx_free (re_match_context_t *cache) internal_function; 23static void match_ctx_free (re_match_context_t *cache);
24static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node, 24static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node,
25 Idx str_idx, Idx from, Idx to) 25 Idx str_idx, Idx from, Idx to);
26 internal_function; 26static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx);
27static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
28 internal_function;
29static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node, 27static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
30 Idx str_idx) internal_function; 28 Idx str_idx);
31static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop, 29static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop,
32 Idx node, Idx str_idx) 30 Idx node, Idx str_idx);
33 internal_function;
34static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, 31static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
35 re_dfastate_t **limited_sts, Idx last_node, 32 re_dfastate_t **limited_sts, Idx last_node,
36 Idx last_str_idx) 33 Idx last_str_idx);
37 internal_function;
38static reg_errcode_t re_search_internal (const regex_t *preg, 34static reg_errcode_t re_search_internal (const regex_t *preg,
39 const char *string, Idx length, 35 const char *string, Idx length,
40 Idx start, Idx last_start, Idx stop, 36 Idx start, Idx last_start, Idx stop,
41 size_t nmatch, regmatch_t pmatch[], 37 size_t nmatch, regmatch_t pmatch[],
42 int eflags) internal_function; 38 int eflags);
43static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp, 39static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp,
44 const char *string1, Idx length1, 40 const char *string1, Idx length1,
45 const char *string2, Idx length2, 41 const char *string2, Idx length2,
46 Idx start, regoff_t range, 42 Idx start, regoff_t range,
47 struct re_registers *regs, 43 struct re_registers *regs,
48 Idx stop, bool ret_len) internal_function; 44 Idx stop, bool ret_len);
49static regoff_t re_search_stub (struct re_pattern_buffer *bufp, 45static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
50 const char *string, Idx length, Idx start, 46 const char *string, Idx length, Idx start,
51 regoff_t range, Idx stop, 47 regoff_t range, Idx stop,
52 struct re_registers *regs, 48 struct re_registers *regs,
53 bool ret_len) internal_function; 49 bool ret_len);
54static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, 50static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
55 Idx nregs, int regs_allocated) internal_function; 51 Idx nregs, int regs_allocated);
56static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx) 52static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx);
57 internal_function;
58static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match, 53static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
59 Idx *p_match_first) internal_function; 54 Idx *p_match_first);
60static Idx check_halt_state_context (const re_match_context_t *mctx, 55static Idx check_halt_state_context (const re_match_context_t *mctx,
61 const re_dfastate_t *state, Idx idx) 56 const re_dfastate_t *state, Idx idx);
62 internal_function;
63static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, 57static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
64 regmatch_t *prev_idx_match, Idx cur_node, 58 regmatch_t *prev_idx_match, Idx cur_node,
65 Idx cur_idx, Idx nmatch) internal_function; 59 Idx cur_idx, Idx nmatch);
66static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, 60static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
67 Idx str_idx, Idx dest_node, Idx nregs, 61 Idx str_idx, Idx dest_node, Idx nregs,
68 regmatch_t *regs, 62 regmatch_t *regs, regmatch_t *prevregs,
69 re_node_set *eps_via_nodes) 63 re_node_set *eps_via_nodes);
70 internal_function;
71static reg_errcode_t set_regs (const regex_t *preg, 64static reg_errcode_t set_regs (const regex_t *preg,
72 const re_match_context_t *mctx, 65 const re_match_context_t *mctx,
73 size_t nmatch, regmatch_t *pmatch, 66 size_t nmatch, regmatch_t *pmatch,
74 bool fl_backtrack) internal_function; 67 bool fl_backtrack);
75static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) 68static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs);
76 internal_function;
77 69
78#ifdef RE_ENABLE_I18N
79static int sift_states_iter_mb (const re_match_context_t *mctx, 70static int sift_states_iter_mb (const re_match_context_t *mctx,
80 re_sift_context_t *sctx, 71 re_sift_context_t *sctx,
81 Idx node_idx, Idx str_idx, Idx max_str_idx) 72 Idx node_idx, Idx str_idx, Idx max_str_idx);
82 internal_function;
83#endif /* RE_ENABLE_I18N */
84static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, 73static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
85 re_sift_context_t *sctx) 74 re_sift_context_t *sctx);
86 internal_function;
87static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, 75static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
88 re_sift_context_t *sctx, Idx str_idx, 76 re_sift_context_t *sctx, Idx str_idx,
89 re_node_set *cur_dest) 77 re_node_set *cur_dest);
90 internal_function;
91static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, 78static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
92 re_sift_context_t *sctx, 79 re_sift_context_t *sctx,
93 Idx str_idx, 80 Idx str_idx,
94 re_node_set *dest_nodes) 81 re_node_set *dest_nodes);
95 internal_function;
96static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, 82static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
97 re_node_set *dest_nodes, 83 re_node_set *dest_nodes,
98 const re_node_set *candidates) 84 const re_node_set *candidates);
99 internal_function;
100static bool check_dst_limits (const re_match_context_t *mctx, 85static bool check_dst_limits (const re_match_context_t *mctx,
101 const re_node_set *limits, 86 const re_node_set *limits,
102 Idx dst_node, Idx dst_idx, Idx src_node, 87 Idx dst_node, Idx dst_idx, Idx src_node,
103 Idx src_idx) internal_function; 88 Idx src_idx);
104static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, 89static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
105 int boundaries, Idx subexp_idx, 90 int boundaries, Idx subexp_idx,
106 Idx from_node, Idx bkref_idx) 91 Idx from_node, Idx bkref_idx);
107 internal_function;
108static int check_dst_limits_calc_pos (const re_match_context_t *mctx, 92static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
109 Idx limit, Idx subexp_idx, 93 Idx limit, Idx subexp_idx,
110 Idx node, Idx str_idx, 94 Idx node, Idx str_idx,
111 Idx bkref_idx) internal_function; 95 Idx bkref_idx);
112static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, 96static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
113 re_node_set *dest_nodes, 97 re_node_set *dest_nodes,
114 const re_node_set *candidates, 98 const re_node_set *candidates,
115 re_node_set *limits, 99 re_node_set *limits,
116 struct re_backref_cache_entry *bkref_ents, 100 struct re_backref_cache_entry *bkref_ents,
117 Idx str_idx) internal_function; 101 Idx str_idx);
118static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, 102static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
119 re_sift_context_t *sctx, 103 re_sift_context_t *sctx,
120 Idx str_idx, const re_node_set *candidates) 104 Idx str_idx, const re_node_set *candidates);
121 internal_function;
122static reg_errcode_t merge_state_array (const re_dfa_t *dfa, 105static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
123 re_dfastate_t **dst, 106 re_dfastate_t **dst,
124 re_dfastate_t **src, Idx num) 107 re_dfastate_t **src, Idx num);
125 internal_function;
126static re_dfastate_t *find_recover_state (reg_errcode_t *err, 108static re_dfastate_t *find_recover_state (reg_errcode_t *err,
127 re_match_context_t *mctx) internal_function; 109 re_match_context_t *mctx);
128static re_dfastate_t *transit_state (reg_errcode_t *err, 110static re_dfastate_t *transit_state (reg_errcode_t *err,
129 re_match_context_t *mctx, 111 re_match_context_t *mctx,
130 re_dfastate_t *state) internal_function; 112 re_dfastate_t *state);
131static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, 113static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
132 re_match_context_t *mctx, 114 re_match_context_t *mctx,
133 re_dfastate_t *next_state) 115 re_dfastate_t *next_state);
134 internal_function;
135static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, 116static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
136 re_node_set *cur_nodes, 117 re_node_set *cur_nodes,
137 Idx str_idx) internal_function; 118 Idx str_idx);
138#if 0 119#if 0
139static re_dfastate_t *transit_state_sb (reg_errcode_t *err, 120static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
140 re_match_context_t *mctx, 121 re_match_context_t *mctx,
141 re_dfastate_t *pstate) 122 re_dfastate_t *pstate);
142 internal_function;
143#endif 123#endif
144#ifdef RE_ENABLE_I18N
145static reg_errcode_t transit_state_mb (re_match_context_t *mctx, 124static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
146 re_dfastate_t *pstate) 125 re_dfastate_t *pstate);
147 internal_function;
148#endif /* RE_ENABLE_I18N */
149static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, 126static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
150 const re_node_set *nodes) 127 const re_node_set *nodes);
151 internal_function;
152static reg_errcode_t get_subexp (re_match_context_t *mctx, 128static reg_errcode_t get_subexp (re_match_context_t *mctx,
153 Idx bkref_node, Idx bkref_str_idx) 129 Idx bkref_node, Idx bkref_str_idx);
154 internal_function;
155static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, 130static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
156 const re_sub_match_top_t *sub_top, 131 const re_sub_match_top_t *sub_top,
157 re_sub_match_last_t *sub_last, 132 re_sub_match_last_t *sub_last,
158 Idx bkref_node, Idx bkref_str) 133 Idx bkref_node, Idx bkref_str);
159 internal_function;
160static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, 134static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
161 Idx subexp_idx, int type) internal_function; 135 Idx subexp_idx, int type);
162static reg_errcode_t check_arrival (re_match_context_t *mctx, 136static reg_errcode_t check_arrival (re_match_context_t *mctx,
163 state_array_t *path, Idx top_node, 137 state_array_t *path, Idx top_node,
164 Idx top_str, Idx last_node, Idx last_str, 138 Idx top_str, Idx last_node, Idx last_str,
165 int type) internal_function; 139 int type);
166static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, 140static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
167 Idx str_idx, 141 Idx str_idx,
168 re_node_set *cur_nodes, 142 re_node_set *cur_nodes,
169 re_node_set *next_nodes) 143 re_node_set *next_nodes);
170 internal_function;
171static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, 144static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
172 re_node_set *cur_nodes, 145 re_node_set *cur_nodes,
173 Idx ex_subexp, int type) 146 Idx ex_subexp, int type);
174 internal_function;
175static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, 147static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
176 re_node_set *dst_nodes, 148 re_node_set *dst_nodes,
177 Idx target, Idx ex_subexp, 149 Idx target, Idx ex_subexp,
178 int type) internal_function; 150 int type);
179static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, 151static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
180 re_node_set *cur_nodes, Idx cur_str, 152 re_node_set *cur_nodes, Idx cur_str,
181 Idx subexp_num, int type) 153 Idx subexp_num, int type);
182 internal_function; 154static bool build_trtable (const re_dfa_t *dfa, re_dfastate_t *state);
183static bool build_trtable (const re_dfa_t *dfa,
184 re_dfastate_t *state) internal_function;
185#ifdef RE_ENABLE_I18N
186static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, 155static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
187 const re_string_t *input, Idx idx) 156 const re_string_t *input, Idx idx);
188 internal_function; 157#ifdef _LIBC
189# ifdef _LIBC
190static unsigned int find_collation_sequence_value (const unsigned char *mbs, 158static unsigned int find_collation_sequence_value (const unsigned char *mbs,
191 size_t name_len) 159 size_t name_len);
192 internal_function; 160#endif
193# endif /* _LIBC */
194#endif /* RE_ENABLE_I18N */
195static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa, 161static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
196 const re_dfastate_t *state, 162 const re_dfastate_t *state,
197 re_node_set *states_node, 163 re_node_set *states_node,
198 bitset_t *states_ch) internal_function; 164 bitset_t *states_ch);
199static bool check_node_accept (const re_match_context_t *mctx, 165static bool check_node_accept (const re_match_context_t *mctx,
200 const re_token_t *node, Idx idx) 166 const re_token_t *node, Idx idx);
201 internal_function; 167static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len);
202static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
203 internal_function;
204 168
205/* Entry point for POSIX code. */ 169/* Entry point for POSIX code. */
206 170
@@ -216,15 +180,12 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
216 REG_NOTBOL is set, then ^ does not match at the beginning of the 180 REG_NOTBOL is set, then ^ does not match at the beginning of the
217 string; if REG_NOTEOL is set, then $ does not match at the end. 181 string; if REG_NOTEOL is set, then $ does not match at the end.
218 182
219 We return 0 if we find a match and REG_NOMATCH if not. */ 183 Return 0 if a match is found, REG_NOMATCH if not, REG_BADPAT if
184 EFLAGS is invalid. */
220 185
221int 186int
222regexec (preg, string, nmatch, pmatch, eflags) 187regexec (const regex_t *__restrict preg, const char *__restrict string,
223 const regex_t *_Restrict_ preg; 188 size_t nmatch, regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags)
224 const char *_Restrict_ string;
225 size_t nmatch;
226 regmatch_t pmatch[_Restrict_arr_];
227 int eflags;
228{ 189{
229 reg_errcode_t err; 190 reg_errcode_t err;
230 Idx start, length; 191 Idx start, length;
@@ -256,6 +217,8 @@ regexec (preg, string, nmatch, pmatch, eflags)
256} 217}
257 218
258#ifdef _LIBC 219#ifdef _LIBC
220libc_hidden_def (__regexec)
221
259# include <shlib-compat.h> 222# include <shlib-compat.h>
260versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4); 223versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4);
261 224
@@ -264,9 +227,9 @@ __typeof__ (__regexec) __compat_regexec;
264 227
265int 228int
266attribute_compat_text_section 229attribute_compat_text_section
267__compat_regexec (const regex_t *_Restrict_ preg, 230__compat_regexec (const regex_t *__restrict preg,
268 const char *_Restrict_ string, size_t nmatch, 231 const char *__restrict string, size_t nmatch,
269 regmatch_t pmatch[], int eflags) 232 regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags)
270{ 233{
271 return regexec (preg, string, nmatch, pmatch, 234 return regexec (preg, string, nmatch, pmatch,
272 eflags & (REG_NOTBOL | REG_NOTEOL)); 235 eflags & (REG_NOTBOL | REG_NOTEOL));
@@ -301,15 +264,12 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
301 strings.) 264 strings.)
302 265
303 On success, re_match* functions return the length of the match, re_search* 266 On success, re_match* functions return the length of the match, re_search*
304 return the position of the start of the match. Return value -1 means no 267 return the position of the start of the match. They return -1 on
305 match was found and -2 indicates an internal error. */ 268 match failure, -2 on error. */
306 269
307regoff_t 270regoff_t
308re_match (bufp, string, length, start, regs) 271re_match (struct re_pattern_buffer *bufp, const char *string, Idx length,
309 struct re_pattern_buffer *bufp; 272 Idx start, struct re_registers *regs)
310 const char *string;
311 Idx length, start;
312 struct re_registers *regs;
313{ 273{
314 return re_search_stub (bufp, string, length, start, 0, length, regs, true); 274 return re_search_stub (bufp, string, length, start, 0, length, regs, true);
315} 275}
@@ -318,12 +278,8 @@ weak_alias (__re_match, re_match)
318#endif 278#endif
319 279
320regoff_t 280regoff_t
321re_search (bufp, string, length, start, range, regs) 281re_search (struct re_pattern_buffer *bufp, const char *string, Idx length,
322 struct re_pattern_buffer *bufp; 282 Idx start, regoff_t range, struct re_registers *regs)
323 const char *string;
324 Idx length, start;
325 regoff_t range;
326 struct re_registers *regs;
327{ 283{
328 return re_search_stub (bufp, string, length, start, range, length, regs, 284 return re_search_stub (bufp, string, length, start, range, length, regs,
329 false); 285 false);
@@ -333,11 +289,9 @@ weak_alias (__re_search, re_search)
333#endif 289#endif
334 290
335regoff_t 291regoff_t
336re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop) 292re_match_2 (struct re_pattern_buffer *bufp, const char *string1, Idx length1,
337 struct re_pattern_buffer *bufp; 293 const char *string2, Idx length2, Idx start,
338 const char *string1, *string2; 294 struct re_registers *regs, Idx stop)
339 Idx length1, length2, start, stop;
340 struct re_registers *regs;
341{ 295{
342 return re_search_2_stub (bufp, string1, length1, string2, length2, 296 return re_search_2_stub (bufp, string1, length1, string2, length2,
343 start, 0, regs, stop, true); 297 start, 0, regs, stop, true);
@@ -347,12 +301,9 @@ weak_alias (__re_match_2, re_match_2)
347#endif 301#endif
348 302
349regoff_t 303regoff_t
350re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop) 304re_search_2 (struct re_pattern_buffer *bufp, const char *string1, Idx length1,
351 struct re_pattern_buffer *bufp; 305 const char *string2, Idx length2, Idx start, regoff_t range,
352 const char *string1, *string2; 306 struct re_registers *regs, Idx stop)
353 Idx length1, length2, start, stop;
354 regoff_t range;
355 struct re_registers *regs;
356{ 307{
357 return re_search_2_stub (bufp, string1, length1, string2, length2, 308 return re_search_2_stub (bufp, string1, length1, string2, length2,
358 start, range, regs, stop, false); 309 start, range, regs, stop, false);
@@ -362,18 +313,18 @@ weak_alias (__re_search_2, re_search_2)
362#endif 313#endif
363 314
364static regoff_t 315static regoff_t
365re_search_2_stub (struct re_pattern_buffer *bufp, 316re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1,
366 const char *string1, Idx length1, 317 Idx length1, const char *string2, Idx length2, Idx start,
367 const char *string2, Idx length2, 318 regoff_t range, struct re_registers *regs,
368 Idx start, regoff_t range, struct re_registers *regs,
369 Idx stop, bool ret_len) 319 Idx stop, bool ret_len)
370{ 320{
371 const char *str; 321 const char *str;
372 regoff_t rval; 322 regoff_t rval;
373 Idx len = length1 + length2; 323 Idx len;
374 char *s = NULL; 324 char *s = NULL;
375 325
376 if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0)) 326 if (__glibc_unlikely ((length1 < 0 || length2 < 0 || stop < 0
327 || INT_ADD_WRAPV (length1, length2, &len))))
377 return -2; 328 return -2;
378 329
379 /* Concatenate the strings. */ 330 /* Concatenate the strings. */
@@ -382,7 +333,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
382 { 333 {
383 s = re_malloc (char, len); 334 s = re_malloc (char, len);
384 335
385 if (BE (s == NULL, 0)) 336 if (__glibc_unlikely (s == NULL))
386 return -2; 337 return -2;
387#ifdef _LIBC 338#ifdef _LIBC
388 memcpy (__mempcpy (s, string1, length1), string2, length2); 339 memcpy (__mempcpy (s, string1, length1), string2, length2);
@@ -409,8 +360,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
409 otherwise the position of the match is returned. */ 360 otherwise the position of the match is returned. */
410 361
411static regoff_t 362static regoff_t
412re_search_stub (struct re_pattern_buffer *bufp, 363re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length,
413 const char *string, Idx length,
414 Idx start, regoff_t range, Idx stop, struct re_registers *regs, 364 Idx start, regoff_t range, Idx stop, struct re_registers *regs,
415 bool ret_len) 365 bool ret_len)
416{ 366{
@@ -423,11 +373,13 @@ re_search_stub (struct re_pattern_buffer *bufp,
423 Idx last_start = start + range; 373 Idx last_start = start + range;
424 374
425 /* Check for out-of-range. */ 375 /* Check for out-of-range. */
426 if (BE (start < 0 || start > length, 0)) 376 if (__glibc_unlikely (start < 0 || start > length))
427 return -1; 377 return -1;
428 if (BE (length < last_start || (0 <= range && last_start < start), 0)) 378 if (__glibc_unlikely (length < last_start
379 || (0 <= range && last_start < start)))
429 last_start = length; 380 last_start = length;
430 else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) 381 else if (__glibc_unlikely (last_start < 0
382 || (range < 0 && start <= last_start)))
431 last_start = 0; 383 last_start = 0;
432 384
433 lock_lock (dfa->lock); 385 lock_lock (dfa->lock);
@@ -439,17 +391,17 @@ re_search_stub (struct re_pattern_buffer *bufp,
439 if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) 391 if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
440 re_compile_fastmap (bufp); 392 re_compile_fastmap (bufp);
441 393
442 if (BE (bufp->no_sub, 0)) 394 if (__glibc_unlikely (bufp->no_sub))
443 regs = NULL; 395 regs = NULL;
444 396
445 /* We need at least 1 register. */ 397 /* We need at least 1 register. */
446 if (regs == NULL) 398 if (regs == NULL)
447 nregs = 1; 399 nregs = 1;
448 else if (BE (bufp->regs_allocated == REGS_FIXED 400 else if (__glibc_unlikely (bufp->regs_allocated == REGS_FIXED
449 && regs->num_regs <= bufp->re_nsub, 0)) 401 && regs->num_regs <= bufp->re_nsub))
450 { 402 {
451 nregs = regs->num_regs; 403 nregs = regs->num_regs;
452 if (BE (nregs < 1, 0)) 404 if (__glibc_unlikely (nregs < 1))
453 { 405 {
454 /* Nothing can be copied to regs. */ 406 /* Nothing can be copied to regs. */
455 regs = NULL; 407 regs = NULL;
@@ -459,7 +411,7 @@ re_search_stub (struct re_pattern_buffer *bufp,
459 else 411 else
460 nregs = bufp->re_nsub + 1; 412 nregs = bufp->re_nsub + 1;
461 pmatch = re_malloc (regmatch_t, nregs); 413 pmatch = re_malloc (regmatch_t, nregs);
462 if (BE (pmatch == NULL, 0)) 414 if (__glibc_unlikely (pmatch == NULL))
463 { 415 {
464 rval = -2; 416 rval = -2;
465 goto out; 417 goto out;
@@ -478,15 +430,15 @@ re_search_stub (struct re_pattern_buffer *bufp,
478 /* If caller wants register contents data back, copy them. */ 430 /* If caller wants register contents data back, copy them. */
479 bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, 431 bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
480 bufp->regs_allocated); 432 bufp->regs_allocated);
481 if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0)) 433 if (__glibc_unlikely (bufp->regs_allocated == REGS_UNALLOCATED))
482 rval = -2; 434 rval = -2;
483 } 435 }
484 436
485 if (BE (rval == 0, 1)) 437 if (__glibc_likely (rval == 0))
486 { 438 {
487 if (ret_len) 439 if (ret_len)
488 { 440 {
489 assert (pmatch[0].rm_so == start); 441 DEBUG_ASSERT (pmatch[0].rm_so == start);
490 rval = pmatch[0].rm_eo - start; 442 rval = pmatch[0].rm_eo - start;
491 } 443 }
492 else 444 else
@@ -512,10 +464,10 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
512 if (regs_allocated == REGS_UNALLOCATED) 464 if (regs_allocated == REGS_UNALLOCATED)
513 { /* No. So allocate them with malloc. */ 465 { /* No. So allocate them with malloc. */
514 regs->start = re_malloc (regoff_t, need_regs); 466 regs->start = re_malloc (regoff_t, need_regs);
515 if (BE (regs->start == NULL, 0)) 467 if (__glibc_unlikely (regs->start == NULL))
516 return REGS_UNALLOCATED; 468 return REGS_UNALLOCATED;
517 regs->end = re_malloc (regoff_t, need_regs); 469 regs->end = re_malloc (regoff_t, need_regs);
518 if (BE (regs->end == NULL, 0)) 470 if (__glibc_unlikely (regs->end == NULL))
519 { 471 {
520 re_free (regs->start); 472 re_free (regs->start);
521 return REGS_UNALLOCATED; 473 return REGS_UNALLOCATED;
@@ -526,14 +478,14 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
526 { /* Yes. If we need more elements than were already 478 { /* Yes. If we need more elements than were already
527 allocated, reallocate them. If we need fewer, just 479 allocated, reallocate them. If we need fewer, just
528 leave it alone. */ 480 leave it alone. */
529 if (BE (need_regs > regs->num_regs, 0)) 481 if (__glibc_unlikely (need_regs > regs->num_regs))
530 { 482 {
531 regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); 483 regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
532 regoff_t *new_end; 484 regoff_t *new_end;
533 if (BE (new_start == NULL, 0)) 485 if (__glibc_unlikely (new_start == NULL))
534 return REGS_UNALLOCATED; 486 return REGS_UNALLOCATED;
535 new_end = re_realloc (regs->end, regoff_t, need_regs); 487 new_end = re_realloc (regs->end, regoff_t, need_regs);
536 if (BE (new_end == NULL, 0)) 488 if (__glibc_unlikely (new_end == NULL))
537 { 489 {
538 re_free (new_start); 490 re_free (new_start);
539 return REGS_UNALLOCATED; 491 return REGS_UNALLOCATED;
@@ -545,9 +497,9 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
545 } 497 }
546 else 498 else
547 { 499 {
548 assert (regs_allocated == REGS_FIXED); 500 DEBUG_ASSERT (regs_allocated == REGS_FIXED);
549 /* This function may not be called with REGS_FIXED and nregs too big. */ 501 /* This function may not be called with REGS_FIXED and nregs too big. */
550 assert (regs->num_regs >= nregs); 502 DEBUG_ASSERT (nregs <= regs->num_regs);
551 rval = REGS_FIXED; 503 rval = REGS_FIXED;
552 } 504 }
553 505
@@ -577,11 +529,8 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
577 freeing the old data. */ 529 freeing the old data. */
578 530
579void 531void
580re_set_registers (bufp, regs, num_regs, starts, ends) 532re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
581 struct re_pattern_buffer *bufp; 533 __re_size_t num_regs, regoff_t *starts, regoff_t *ends)
582 struct re_registers *regs;
583 __re_size_t num_regs;
584 regoff_t *starts, *ends;
585{ 534{
586 if (num_regs) 535 if (num_regs)
587 { 536 {
@@ -609,8 +558,7 @@ int
609# ifdef _LIBC 558# ifdef _LIBC
610weak_function 559weak_function
611# endif 560# endif
612re_exec (s) 561re_exec (const char *s)
613 const char *s;
614{ 562{
615 return 0 == regexec (&re_comp_buf, s, 0, NULL, 0); 563 return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
616} 564}
@@ -629,11 +577,9 @@ re_exec (s)
629 577
630static reg_errcode_t 578static reg_errcode_t
631__attribute_warn_unused_result__ 579__attribute_warn_unused_result__
632re_search_internal (const regex_t *preg, 580re_search_internal (const regex_t *preg, const char *string, Idx length,
633 const char *string, Idx length, 581 Idx start, Idx last_start, Idx stop, size_t nmatch,
634 Idx start, Idx last_start, Idx stop, 582 regmatch_t pmatch[], int eflags)
635 size_t nmatch, regmatch_t pmatch[],
636 int eflags)
637{ 583{
638 reg_errcode_t err; 584 reg_errcode_t err;
639 const re_dfa_t *dfa = preg->buffer; 585 const re_dfa_t *dfa = preg->buffer;
@@ -642,38 +588,28 @@ re_search_internal (const regex_t *preg,
642 bool fl_longest_match; 588 bool fl_longest_match;
643 int match_kind; 589 int match_kind;
644 Idx match_first; 590 Idx match_first;
645 Idx match_last = REG_MISSING; 591 Idx match_last = -1;
646 Idx extra_nmatch; 592 Idx extra_nmatch;
647 bool sb; 593 bool sb;
648 int ch; 594 int ch;
649#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
650 re_match_context_t mctx = { .dfa = dfa }; 595 re_match_context_t mctx = { .dfa = dfa };
651#else
652 re_match_context_t mctx;
653#endif
654 char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate 596 char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
655 && start != last_start && !preg->can_be_null) 597 && start != last_start && !preg->can_be_null)
656 ? preg->fastmap : NULL); 598 ? preg->fastmap : NULL);
657 RE_TRANSLATE_TYPE t = preg->translate; 599 RE_TRANSLATE_TYPE t = preg->translate;
658 600
659#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
660 memset (&mctx, '\0', sizeof (re_match_context_t));
661 mctx.dfa = dfa;
662#endif
663
664 extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0; 601 extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
665 nmatch -= extra_nmatch; 602 nmatch -= extra_nmatch;
666 603
667 /* Check if the DFA haven't been compiled. */ 604 /* Check if the DFA haven't been compiled. */
668 if (BE (preg->used == 0 || dfa->init_state == NULL 605 if (__glibc_unlikely (preg->used == 0 || dfa->init_state == NULL
669 || dfa->init_state_word == NULL || dfa->init_state_nl == NULL 606 || dfa->init_state_word == NULL
670 || dfa->init_state_begbuf == NULL, 0)) 607 || dfa->init_state_nl == NULL
608 || dfa->init_state_begbuf == NULL))
671 return REG_NOMATCH; 609 return REG_NOMATCH;
672 610
673#ifdef DEBUG
674 /* We assume front-end functions already check them. */ 611 /* We assume front-end functions already check them. */
675 assert (0 <= last_start && last_start <= length); 612 DEBUG_ASSERT (0 <= last_start && last_start <= length);
676#endif
677 613
678 /* If initial states with non-begbuf contexts have no elements, 614 /* If initial states with non-begbuf contexts have no elements,
679 the regex must be anchored. If preg->newline_anchor is set, 615 the regex must be anchored. If preg->newline_anchor is set,
@@ -694,14 +630,14 @@ re_search_internal (const regex_t *preg,
694 err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, 630 err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
695 preg->translate, (preg->syntax & RE_ICASE) != 0, 631 preg->translate, (preg->syntax & RE_ICASE) != 0,
696 dfa); 632 dfa);
697 if (BE (err != REG_NOERROR, 0)) 633 if (__glibc_unlikely (err != REG_NOERROR))
698 goto free_return; 634 goto free_return;
699 mctx.input.stop = stop; 635 mctx.input.stop = stop;
700 mctx.input.raw_stop = stop; 636 mctx.input.raw_stop = stop;
701 mctx.input.newline_anchor = preg->newline_anchor; 637 mctx.input.newline_anchor = preg->newline_anchor;
702 638
703 err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); 639 err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
704 if (BE (err != REG_NOERROR, 0)) 640 if (__glibc_unlikely (err != REG_NOERROR))
705 goto free_return; 641 goto free_return;
706 642
707 /* We will log all the DFA states through which the dfa pass, 643 /* We will log all the DFA states through which the dfa pass,
@@ -711,22 +647,20 @@ re_search_internal (const regex_t *preg,
711 if (nmatch > 1 || dfa->has_mb_node) 647 if (nmatch > 1 || dfa->has_mb_node)
712 { 648 {
713 /* Avoid overflow. */ 649 /* Avoid overflow. */
714 if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) 650 if (__glibc_unlikely ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
715 <= mctx.input.bufs_len), 0)) 651 <= mctx.input.bufs_len)))
716 { 652 {
717 err = REG_ESPACE; 653 err = REG_ESPACE;
718 goto free_return; 654 goto free_return;
719 } 655 }
720 656
721 mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); 657 mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
722 if (BE (mctx.state_log == NULL, 0)) 658 if (__glibc_unlikely (mctx.state_log == NULL))
723 { 659 {
724 err = REG_ESPACE; 660 err = REG_ESPACE;
725 goto free_return; 661 goto free_return;
726 } 662 }
727 } 663 }
728 else
729 mctx.state_log = NULL;
730 664
731 match_first = start; 665 match_first = start;
732 mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF 666 mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
@@ -763,19 +697,19 @@ re_search_internal (const regex_t *preg,
763 697
764 case 7: 698 case 7:
765 /* Fastmap with single-byte translation, match forward. */ 699 /* Fastmap with single-byte translation, match forward. */
766 while (BE (match_first < right_lim, 1) 700 while (__glibc_likely (match_first < right_lim)
767 && !fastmap[t[(unsigned char) string[match_first]]]) 701 && !fastmap[t[(unsigned char) string[match_first]]])
768 ++match_first; 702 ++match_first;
769 goto forward_match_found_start_or_reached_end; 703 goto forward_match_found_start_or_reached_end;
770 704
771 case 6: 705 case 6:
772 /* Fastmap without translation, match forward. */ 706 /* Fastmap without translation, match forward. */
773 while (BE (match_first < right_lim, 1) 707 while (__glibc_likely (match_first < right_lim)
774 && !fastmap[(unsigned char) string[match_first]]) 708 && !fastmap[(unsigned char) string[match_first]])
775 ++match_first; 709 ++match_first;
776 710
777 forward_match_found_start_or_reached_end: 711 forward_match_found_start_or_reached_end:
778 if (BE (match_first == right_lim, 0)) 712 if (__glibc_unlikely (match_first == right_lim))
779 { 713 {
780 ch = match_first >= length 714 ch = match_first >= length
781 ? 0 : (unsigned char) string[match_first]; 715 ? 0 : (unsigned char) string[match_first];
@@ -808,19 +742,19 @@ re_search_internal (const regex_t *preg,
808 /* If MATCH_FIRST is out of the valid range, reconstruct the 742 /* If MATCH_FIRST is out of the valid range, reconstruct the
809 buffers. */ 743 buffers. */
810 __re_size_t offset = match_first - mctx.input.raw_mbs_idx; 744 __re_size_t offset = match_first - mctx.input.raw_mbs_idx;
811 if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0)) 745 if (__glibc_unlikely (offset
746 >= (__re_size_t) mctx.input.valid_raw_len))
812 { 747 {
813 err = re_string_reconstruct (&mctx.input, match_first, 748 err = re_string_reconstruct (&mctx.input, match_first,
814 eflags); 749 eflags);
815 if (BE (err != REG_NOERROR, 0)) 750 if (__glibc_unlikely (err != REG_NOERROR))
816 goto free_return; 751 goto free_return;
817 752
818 offset = match_first - mctx.input.raw_mbs_idx; 753 offset = match_first - mctx.input.raw_mbs_idx;
819 } 754 }
820 /* If MATCH_FIRST is out of the buffer, leave it as '\0'. 755 /* Use buffer byte if OFFSET is in buffer, otherwise '\0'. */
821 Note that MATCH_FIRST must not be smaller than 0. */ 756 ch = (offset < mctx.input.valid_len
822 ch = (match_first >= length 757 ? re_string_byte_at (&mctx.input, offset) : 0);
823 ? 0 : re_string_byte_at (&mctx.input, offset));
824 if (fastmap[ch]) 758 if (fastmap[ch])
825 break; 759 break;
826 match_first += incr; 760 match_first += incr;
@@ -836,24 +770,22 @@ re_search_internal (const regex_t *preg,
836 /* Reconstruct the buffers so that the matcher can assume that 770 /* Reconstruct the buffers so that the matcher can assume that
837 the matching starts from the beginning of the buffer. */ 771 the matching starts from the beginning of the buffer. */
838 err = re_string_reconstruct (&mctx.input, match_first, eflags); 772 err = re_string_reconstruct (&mctx.input, match_first, eflags);
839 if (BE (err != REG_NOERROR, 0)) 773 if (__glibc_unlikely (err != REG_NOERROR))
840 goto free_return; 774 goto free_return;
841 775
842#ifdef RE_ENABLE_I18N 776 /* Don't consider this char as a possible match start if it part,
843 /* Don't consider this char as a possible match start if it part, 777 yet isn't the head, of a multibyte character. */
844 yet isn't the head, of a multibyte character. */
845 if (!sb && !re_string_first_byte (&mctx.input, 0)) 778 if (!sb && !re_string_first_byte (&mctx.input, 0))
846 continue; 779 continue;
847#endif
848 780
849 /* It seems to be appropriate one, then use the matcher. */ 781 /* It seems to be appropriate one, then use the matcher. */
850 /* We assume that the matching starts from 0. */ 782 /* We assume that the matching starts from 0. */
851 mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0; 783 mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0;
852 match_last = check_matching (&mctx, fl_longest_match, 784 match_last = check_matching (&mctx, fl_longest_match,
853 start <= last_start ? &match_first : NULL); 785 start <= last_start ? &match_first : NULL);
854 if (match_last != REG_MISSING) 786 if (match_last != -1)
855 { 787 {
856 if (BE (match_last == REG_ERROR, 0)) 788 if (__glibc_unlikely (match_last == -2))
857 { 789 {
858 err = REG_ESPACE; 790 err = REG_ESPACE;
859 goto free_return; 791 goto free_return;
@@ -873,9 +805,9 @@ re_search_internal (const regex_t *preg,
873 err = prune_impossible_nodes (&mctx); 805 err = prune_impossible_nodes (&mctx);
874 if (err == REG_NOERROR) 806 if (err == REG_NOERROR)
875 break; 807 break;
876 if (BE (err != REG_NOMATCH, 0)) 808 if (__glibc_unlikely (err != REG_NOMATCH))
877 goto free_return; 809 goto free_return;
878 match_last = REG_MISSING; 810 match_last = -1;
879 } 811 }
880 else 812 else
881 break; /* We found a match. */ 813 break; /* We found a match. */
@@ -885,10 +817,8 @@ re_search_internal (const regex_t *preg,
885 match_ctx_clean (&mctx); 817 match_ctx_clean (&mctx);
886 } 818 }
887 819
888#ifdef DEBUG 820 DEBUG_ASSERT (match_last != -1);
889 assert (match_last != REG_MISSING); 821 DEBUG_ASSERT (err == REG_NOERROR);
890 assert (err == REG_NOERROR);
891#endif
892 822
893 /* Set pmatch[] if we need. */ 823 /* Set pmatch[] if we need. */
894 if (nmatch > 0) 824 if (nmatch > 0)
@@ -910,7 +840,7 @@ re_search_internal (const regex_t *preg,
910 { 840 {
911 err = set_regs (preg, &mctx, nmatch, pmatch, 841 err = set_regs (preg, &mctx, nmatch, pmatch,
912 dfa->has_plural_match && dfa->nbackref > 0); 842 dfa->has_plural_match && dfa->nbackref > 0);
913 if (BE (err != REG_NOERROR, 0)) 843 if (__glibc_unlikely (err != REG_NOERROR))
914 goto free_return; 844 goto free_return;
915 } 845 }
916 846
@@ -920,8 +850,7 @@ re_search_internal (const regex_t *preg,
920 for (reg_idx = 0; reg_idx < nmatch; ++reg_idx) 850 for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
921 if (pmatch[reg_idx].rm_so != -1) 851 if (pmatch[reg_idx].rm_so != -1)
922 { 852 {
923#ifdef RE_ENABLE_I18N 853 if (__glibc_unlikely (mctx.input.offsets_needed != 0))
924 if (BE (mctx.input.offsets_needed != 0, 0))
925 { 854 {
926 pmatch[reg_idx].rm_so = 855 pmatch[reg_idx].rm_so =
927 (pmatch[reg_idx].rm_so == mctx.input.valid_len 856 (pmatch[reg_idx].rm_so == mctx.input.valid_len
@@ -932,9 +861,6 @@ re_search_internal (const regex_t *preg,
932 ? mctx.input.valid_raw_len 861 ? mctx.input.valid_raw_len
933 : mctx.input.offsets[pmatch[reg_idx].rm_eo]); 862 : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
934 } 863 }
935#else
936 assert (mctx.input.offsets_needed == 0);
937#endif
938 pmatch[reg_idx].rm_so += match_first; 864 pmatch[reg_idx].rm_so += match_first;
939 pmatch[reg_idx].rm_eo += match_first; 865 pmatch[reg_idx].rm_eo += match_first;
940 } 866 }
@@ -973,18 +899,17 @@ prune_impossible_nodes (re_match_context_t *mctx)
973 re_dfastate_t **sifted_states; 899 re_dfastate_t **sifted_states;
974 re_dfastate_t **lim_states = NULL; 900 re_dfastate_t **lim_states = NULL;
975 re_sift_context_t sctx; 901 re_sift_context_t sctx;
976#ifdef DEBUG 902 DEBUG_ASSERT (mctx->state_log != NULL);
977 assert (mctx->state_log != NULL);
978#endif
979 match_last = mctx->match_last; 903 match_last = mctx->match_last;
980 halt_node = mctx->last_node; 904 halt_node = mctx->last_node;
981 905
982 /* Avoid overflow. */ 906 /* Avoid overflow. */
983 if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0)) 907 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
908 <= match_last))
984 return REG_ESPACE; 909 return REG_ESPACE;
985 910
986 sifted_states = re_malloc (re_dfastate_t *, match_last + 1); 911 sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
987 if (BE (sifted_states == NULL, 0)) 912 if (__glibc_unlikely (sifted_states == NULL))
988 { 913 {
989 ret = REG_ESPACE; 914 ret = REG_ESPACE;
990 goto free_return; 915 goto free_return;
@@ -992,7 +917,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
992 if (dfa->nbackref) 917 if (dfa->nbackref)
993 { 918 {
994 lim_states = re_malloc (re_dfastate_t *, match_last + 1); 919 lim_states = re_malloc (re_dfastate_t *, match_last + 1);
995 if (BE (lim_states == NULL, 0)) 920 if (__glibc_unlikely (lim_states == NULL))
996 { 921 {
997 ret = REG_ESPACE; 922 ret = REG_ESPACE;
998 goto free_return; 923 goto free_return;
@@ -1005,14 +930,14 @@ prune_impossible_nodes (re_match_context_t *mctx)
1005 match_last); 930 match_last);
1006 ret = sift_states_backward (mctx, &sctx); 931 ret = sift_states_backward (mctx, &sctx);
1007 re_node_set_free (&sctx.limits); 932 re_node_set_free (&sctx.limits);
1008 if (BE (ret != REG_NOERROR, 0)) 933 if (__glibc_unlikely (ret != REG_NOERROR))
1009 goto free_return; 934 goto free_return;
1010 if (sifted_states[0] != NULL || lim_states[0] != NULL) 935 if (sifted_states[0] != NULL || lim_states[0] != NULL)
1011 break; 936 break;
1012 do 937 do
1013 { 938 {
1014 --match_last; 939 --match_last;
1015 if (! REG_VALID_INDEX (match_last)) 940 if (match_last < 0)
1016 { 941 {
1017 ret = REG_NOMATCH; 942 ret = REG_NOMATCH;
1018 goto free_return; 943 goto free_return;
@@ -1027,7 +952,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
1027 match_last + 1); 952 match_last + 1);
1028 re_free (lim_states); 953 re_free (lim_states);
1029 lim_states = NULL; 954 lim_states = NULL;
1030 if (BE (ret != REG_NOERROR, 0)) 955 if (__glibc_unlikely (ret != REG_NOERROR))
1031 goto free_return; 956 goto free_return;
1032 } 957 }
1033 else 958 else
@@ -1035,7 +960,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
1035 sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last); 960 sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last);
1036 ret = sift_states_backward (mctx, &sctx); 961 ret = sift_states_backward (mctx, &sctx);
1037 re_node_set_free (&sctx.limits); 962 re_node_set_free (&sctx.limits);
1038 if (BE (ret != REG_NOERROR, 0)) 963 if (__glibc_unlikely (ret != REG_NOERROR))
1039 goto free_return; 964 goto free_return;
1040 if (sifted_states[0] == NULL) 965 if (sifted_states[0] == NULL)
1041 { 966 {
@@ -1059,8 +984,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
1059 We must select appropriate initial state depending on the context, 984 We must select appropriate initial state depending on the context,
1060 since initial states may have constraints like "\<", "^", etc.. */ 985 since initial states may have constraints like "\<", "^", etc.. */
1061 986
1062static inline re_dfastate_t * 987static __always_inline re_dfastate_t *
1063__attribute__ ((always_inline)) internal_function
1064acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, 988acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1065 Idx idx) 989 Idx idx)
1066{ 990{
@@ -1093,8 +1017,8 @@ acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1093} 1017}
1094 1018
1095/* Check whether the regular expression match input string INPUT or not, 1019/* Check whether the regular expression match input string INPUT or not,
1096 and return the index where the matching end. Return REG_MISSING if 1020 and return the index where the matching end. Return -1 if
1097 there is no match, and return REG_ERROR in case of an error. 1021 there is no match, and return -2 in case of an error.
1098 FL_LONGEST_MATCH means we want the POSIX longest matching. 1022 FL_LONGEST_MATCH means we want the POSIX longest matching.
1099 If P_MATCH_FIRST is not NULL, and the match fails, it is set to the 1023 If P_MATCH_FIRST is not NULL, and the match fails, it is set to the
1100 next place where we may want to try matching. 1024 next place where we may want to try matching.
@@ -1102,14 +1026,14 @@ acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1102 index of the buffer. */ 1026 index of the buffer. */
1103 1027
1104static Idx 1028static Idx
1105internal_function __attribute_warn_unused_result__ 1029__attribute_warn_unused_result__
1106check_matching (re_match_context_t *mctx, bool fl_longest_match, 1030check_matching (re_match_context_t *mctx, bool fl_longest_match,
1107 Idx *p_match_first) 1031 Idx *p_match_first)
1108{ 1032{
1109 const re_dfa_t *const dfa = mctx->dfa; 1033 const re_dfa_t *const dfa = mctx->dfa;
1110 reg_errcode_t err; 1034 reg_errcode_t err;
1111 Idx match = 0; 1035 Idx match = 0;
1112 Idx match_last = REG_MISSING; 1036 Idx match_last = -1;
1113 Idx cur_str_idx = re_string_cur_idx (&mctx->input); 1037 Idx cur_str_idx = re_string_cur_idx (&mctx->input);
1114 re_dfastate_t *cur_state; 1038 re_dfastate_t *cur_state;
1115 bool at_init_state = p_match_first != NULL; 1039 bool at_init_state = p_match_first != NULL;
@@ -1118,10 +1042,10 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1118 err = REG_NOERROR; 1042 err = REG_NOERROR;
1119 cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); 1043 cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
1120 /* An initial state must not be NULL (invalid). */ 1044 /* An initial state must not be NULL (invalid). */
1121 if (BE (cur_state == NULL, 0)) 1045 if (__glibc_unlikely (cur_state == NULL))
1122 { 1046 {
1123 assert (err == REG_ESPACE); 1047 DEBUG_ASSERT (err == REG_ESPACE);
1124 return REG_ERROR; 1048 return -2;
1125 } 1049 }
1126 1050
1127 if (mctx->state_log != NULL) 1051 if (mctx->state_log != NULL)
@@ -1130,24 +1054,24 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1130 1054
1131 /* Check OP_OPEN_SUBEXP in the initial state in case that we use them 1055 /* Check OP_OPEN_SUBEXP in the initial state in case that we use them
1132 later. E.g. Processing back references. */ 1056 later. E.g. Processing back references. */
1133 if (BE (dfa->nbackref, 0)) 1057 if (__glibc_unlikely (dfa->nbackref))
1134 { 1058 {
1135 at_init_state = false; 1059 at_init_state = false;
1136 err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); 1060 err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
1137 if (BE (err != REG_NOERROR, 0)) 1061 if (__glibc_unlikely (err != REG_NOERROR))
1138 return err; 1062 return err;
1139 1063
1140 if (cur_state->has_backref) 1064 if (cur_state->has_backref)
1141 { 1065 {
1142 err = transit_state_bkref (mctx, &cur_state->nodes); 1066 err = transit_state_bkref (mctx, &cur_state->nodes);
1143 if (BE (err != REG_NOERROR, 0)) 1067 if (__glibc_unlikely (err != REG_NOERROR))
1144 return err; 1068 return err;
1145 } 1069 }
1146 } 1070 }
1147 } 1071 }
1148 1072
1149 /* If the RE accepts NULL string. */ 1073 /* If the RE accepts NULL string. */
1150 if (BE (cur_state->halt, 0)) 1074 if (__glibc_unlikely (cur_state->halt))
1151 { 1075 {
1152 if (!cur_state->has_constraint 1076 if (!cur_state->has_constraint
1153 || check_halt_state_context (mctx, cur_state, cur_str_idx)) 1077 || check_halt_state_context (mctx, cur_state, cur_str_idx))
@@ -1167,16 +1091,16 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1167 re_dfastate_t *old_state = cur_state; 1091 re_dfastate_t *old_state = cur_state;
1168 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; 1092 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
1169 1093
1170 if ((BE (next_char_idx >= mctx->input.bufs_len, 0) 1094 if ((__glibc_unlikely (next_char_idx >= mctx->input.bufs_len)
1171 && mctx->input.bufs_len < mctx->input.len) 1095 && mctx->input.bufs_len < mctx->input.len)
1172 || (BE (next_char_idx >= mctx->input.valid_len, 0) 1096 || (__glibc_unlikely (next_char_idx >= mctx->input.valid_len)
1173 && mctx->input.valid_len < mctx->input.len)) 1097 && mctx->input.valid_len < mctx->input.len))
1174 { 1098 {
1175 err = extend_buffers (mctx, next_char_idx + 1); 1099 err = extend_buffers (mctx, next_char_idx + 1);
1176 if (BE (err != REG_NOERROR, 0)) 1100 if (__glibc_unlikely (err != REG_NOERROR))
1177 { 1101 {
1178 assert (err == REG_ESPACE); 1102 DEBUG_ASSERT (err == REG_ESPACE);
1179 return REG_ERROR; 1103 return -2;
1180 } 1104 }
1181 } 1105 }
1182 1106
@@ -1189,8 +1113,8 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1189 /* Reached the invalid state or an error. Try to recover a valid 1113 /* Reached the invalid state or an error. Try to recover a valid
1190 state using the state log, if available and if we have not 1114 state using the state log, if available and if we have not
1191 already found a valid (even if not the longest) match. */ 1115 already found a valid (even if not the longest) match. */
1192 if (BE (err != REG_NOERROR, 0)) 1116 if (__glibc_unlikely (err != REG_NOERROR))
1193 return REG_ERROR; 1117 return -2;
1194 1118
1195 if (mctx->state_log == NULL 1119 if (mctx->state_log == NULL
1196 || (match && !fl_longest_match) 1120 || (match && !fl_longest_match)
@@ -1198,7 +1122,7 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1198 break; 1122 break;
1199 } 1123 }
1200 1124
1201 if (BE (at_init_state, 0)) 1125 if (__glibc_unlikely (at_init_state))
1202 { 1126 {
1203 if (old_state == cur_state) 1127 if (old_state == cur_state)
1204 next_start_idx = next_char_idx; 1128 next_start_idx = next_char_idx;
@@ -1235,7 +1159,6 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1235/* Check NODE match the current context. */ 1159/* Check NODE match the current context. */
1236 1160
1237static bool 1161static bool
1238internal_function
1239check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context) 1162check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
1240{ 1163{
1241 re_token_type_t type = dfa->nodes[node].type; 1164 re_token_type_t type = dfa->nodes[node].type;
@@ -1254,15 +1177,12 @@ check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
1254 match the context, return the node. */ 1177 match the context, return the node. */
1255 1178
1256static Idx 1179static Idx
1257internal_function
1258check_halt_state_context (const re_match_context_t *mctx, 1180check_halt_state_context (const re_match_context_t *mctx,
1259 const re_dfastate_t *state, Idx idx) 1181 const re_dfastate_t *state, Idx idx)
1260{ 1182{
1261 Idx i; 1183 Idx i;
1262 unsigned int context; 1184 unsigned int context;
1263#ifdef DEBUG 1185 DEBUG_ASSERT (state->halt);
1264 assert (state->halt);
1265#endif
1266 context = re_string_context_at (&mctx->input, idx, mctx->eflags); 1186 context = re_string_context_at (&mctx->input, idx, mctx->eflags);
1267 for (i = 0; i < state->nodes.nelem; ++i) 1187 for (i = 0; i < state->nodes.nelem; ++i)
1268 if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context)) 1188 if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context))
@@ -1273,33 +1193,35 @@ check_halt_state_context (const re_match_context_t *mctx,
1273/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA 1193/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
1274 corresponding to the DFA). 1194 corresponding to the DFA).
1275 Return the destination node, and update EPS_VIA_NODES; 1195 Return the destination node, and update EPS_VIA_NODES;
1276 return REG_MISSING in case of errors. */ 1196 return -1 on match failure, -2 on error. */
1277 1197
1278static Idx 1198static Idx
1279internal_function
1280proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, 1199proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1200 regmatch_t *prevregs,
1281 Idx *pidx, Idx node, re_node_set *eps_via_nodes, 1201 Idx *pidx, Idx node, re_node_set *eps_via_nodes,
1282 struct re_fail_stack_t *fs) 1202 struct re_fail_stack_t *fs)
1283{ 1203{
1284 const re_dfa_t *const dfa = mctx->dfa; 1204 const re_dfa_t *const dfa = mctx->dfa;
1285 Idx i;
1286 bool ok;
1287 if (IS_EPSILON_NODE (dfa->nodes[node].type)) 1205 if (IS_EPSILON_NODE (dfa->nodes[node].type))
1288 { 1206 {
1289 re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes; 1207 re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
1290 re_node_set *edests = &dfa->edests[node]; 1208 re_node_set *edests = &dfa->edests[node];
1291 Idx dest_node; 1209
1292 ok = re_node_set_insert (eps_via_nodes, node); 1210 if (! re_node_set_contains (eps_via_nodes, node))
1293 if (BE (! ok, 0)) 1211 {
1294 return REG_ERROR; 1212 bool ok = re_node_set_insert (eps_via_nodes, node);
1295 /* Pick up a valid destination, or return REG_MISSING if none 1213 if (__glibc_unlikely (! ok))
1296 is found. */ 1214 return -2;
1297 for (dest_node = REG_MISSING, i = 0; i < edests->nelem; ++i) 1215 }
1216
1217 /* Pick a valid destination, or return -1 if none is found. */
1218 Idx dest_node = -1;
1219 for (Idx i = 0; i < edests->nelem; i++)
1298 { 1220 {
1299 Idx candidate = edests->elems[i]; 1221 Idx candidate = edests->elems[i];
1300 if (!re_node_set_contains (cur_nodes, candidate)) 1222 if (!re_node_set_contains (cur_nodes, candidate))
1301 continue; 1223 continue;
1302 if (dest_node == REG_MISSING) 1224 if (dest_node == -1)
1303 dest_node = candidate; 1225 dest_node = candidate;
1304 1226
1305 else 1227 else
@@ -1312,8 +1234,8 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1312 /* Otherwise, push the second epsilon-transition on the fail stack. */ 1234 /* Otherwise, push the second epsilon-transition on the fail stack. */
1313 else if (fs != NULL 1235 else if (fs != NULL
1314 && push_fail_stack (fs, *pidx, candidate, nregs, regs, 1236 && push_fail_stack (fs, *pidx, candidate, nregs, regs,
1315 eps_via_nodes)) 1237 prevregs, eps_via_nodes))
1316 return REG_ERROR; 1238 return -2;
1317 1239
1318 /* We know we are going to exit. */ 1240 /* We know we are going to exit. */
1319 break; 1241 break;
@@ -1326,34 +1248,36 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1326 Idx naccepted = 0; 1248 Idx naccepted = 0;
1327 re_token_type_t type = dfa->nodes[node].type; 1249 re_token_type_t type = dfa->nodes[node].type;
1328 1250
1329#ifdef RE_ENABLE_I18N
1330 if (dfa->nodes[node].accept_mb) 1251 if (dfa->nodes[node].accept_mb)
1331 naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx); 1252 naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx);
1332 else 1253 else if (type == OP_BACK_REF)
1333#endif /* RE_ENABLE_I18N */
1334 if (type == OP_BACK_REF)
1335 { 1254 {
1336 Idx subexp_idx = dfa->nodes[node].opr.idx + 1; 1255 Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
1337 naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so; 1256 if (subexp_idx < nregs)
1257 naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
1338 if (fs != NULL) 1258 if (fs != NULL)
1339 { 1259 {
1340 if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1) 1260 if (subexp_idx >= nregs
1341 return REG_MISSING; 1261 || regs[subexp_idx].rm_so == -1
1262 || regs[subexp_idx].rm_eo == -1)
1263 return -1;
1342 else if (naccepted) 1264 else if (naccepted)
1343 { 1265 {
1344 char *buf = (char *) re_string_get_buffer (&mctx->input); 1266 char *buf = (char *) re_string_get_buffer (&mctx->input);
1345 if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx, 1267 if (mctx->input.valid_len - *pidx < naccepted
1346 naccepted) != 0) 1268 || (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
1347 return REG_MISSING; 1269 naccepted)
1270 != 0))
1271 return -1;
1348 } 1272 }
1349 } 1273 }
1350 1274
1351 if (naccepted == 0) 1275 if (naccepted == 0)
1352 { 1276 {
1353 Idx dest_node; 1277 Idx dest_node;
1354 ok = re_node_set_insert (eps_via_nodes, node); 1278 bool ok = re_node_set_insert (eps_via_nodes, node);
1355 if (BE (! ok, 0)) 1279 if (__glibc_unlikely (! ok))
1356 return REG_ERROR; 1280 return -2;
1357 dest_node = dfa->edests[node].elems[0]; 1281 dest_node = dfa->edests[node].elems[0];
1358 if (re_node_set_contains (&mctx->state_log[*pidx]->nodes, 1282 if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
1359 dest_node)) 1283 dest_node))
@@ -1369,26 +1293,27 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1369 if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL 1293 if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
1370 || !re_node_set_contains (&mctx->state_log[*pidx]->nodes, 1294 || !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
1371 dest_node))) 1295 dest_node)))
1372 return REG_MISSING; 1296 return -1;
1373 re_node_set_empty (eps_via_nodes); 1297 re_node_set_empty (eps_via_nodes);
1374 return dest_node; 1298 return dest_node;
1375 } 1299 }
1376 } 1300 }
1377 return REG_MISSING; 1301 return -1;
1378} 1302}
1379 1303
1380static reg_errcode_t 1304static reg_errcode_t
1381internal_function __attribute_warn_unused_result__ 1305__attribute_warn_unused_result__
1382push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, 1306push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
1383 Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes) 1307 Idx nregs, regmatch_t *regs, regmatch_t *prevregs,
1308 re_node_set *eps_via_nodes)
1384{ 1309{
1385 reg_errcode_t err; 1310 reg_errcode_t err;
1386 Idx num = fs->num++; 1311 Idx num = fs->num;
1387 if (fs->num == fs->alloc) 1312 if (num == fs->alloc)
1388 { 1313 {
1389 struct re_fail_stack_ent_t *new_array; 1314 struct re_fail_stack_ent_t *new_array;
1390 new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t) 1315 new_array = re_realloc (fs->stack, struct re_fail_stack_ent_t,
1391 * fs->alloc * 2)); 1316 fs->alloc * 2);
1392 if (new_array == NULL) 1317 if (new_array == NULL)
1393 return REG_ESPACE; 1318 return REG_ESPACE;
1394 fs->alloc *= 2; 1319 fs->alloc *= 2;
@@ -1396,36 +1321,47 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
1396 } 1321 }
1397 fs->stack[num].idx = str_idx; 1322 fs->stack[num].idx = str_idx;
1398 fs->stack[num].node = dest_node; 1323 fs->stack[num].node = dest_node;
1399 fs->stack[num].regs = re_malloc (regmatch_t, nregs); 1324 fs->stack[num].regs = re_malloc (regmatch_t, 2 * nregs);
1400 if (fs->stack[num].regs == NULL) 1325 if (fs->stack[num].regs == NULL)
1401 return REG_ESPACE; 1326 return REG_ESPACE;
1327 fs->num = num + 1;
1402 memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs); 1328 memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
1329 memcpy (fs->stack[num].regs + nregs, prevregs, sizeof (regmatch_t) * nregs);
1403 err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes); 1330 err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes);
1404 return err; 1331 return err;
1405} 1332}
1406 1333
1407static Idx 1334static Idx
1408internal_function
1409pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, 1335pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
1410 regmatch_t *regs, re_node_set *eps_via_nodes) 1336 regmatch_t *regs, regmatch_t *prevregs,
1337 re_node_set *eps_via_nodes)
1411{ 1338{
1339 if (fs == NULL || fs->num == 0)
1340 return -1;
1412 Idx num = --fs->num; 1341 Idx num = --fs->num;
1413 assert (REG_VALID_INDEX (num));
1414 *pidx = fs->stack[num].idx; 1342 *pidx = fs->stack[num].idx;
1415 memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs); 1343 memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
1344 memcpy (prevregs, fs->stack[num].regs + nregs, sizeof (regmatch_t) * nregs);
1416 re_node_set_free (eps_via_nodes); 1345 re_node_set_free (eps_via_nodes);
1417 re_free (fs->stack[num].regs); 1346 re_free (fs->stack[num].regs);
1418 *eps_via_nodes = fs->stack[num].eps_via_nodes; 1347 *eps_via_nodes = fs->stack[num].eps_via_nodes;
1348 DEBUG_ASSERT (0 <= fs->stack[num].node);
1419 return fs->stack[num].node; 1349 return fs->stack[num].node;
1420} 1350}
1421 1351
1352
1353#define DYNARRAY_STRUCT regmatch_list
1354#define DYNARRAY_ELEMENT regmatch_t
1355#define DYNARRAY_PREFIX regmatch_list_
1356#include <malloc/dynarray-skeleton.c>
1357
1422/* Set the positions where the subexpressions are starts/ends to registers 1358/* Set the positions where the subexpressions are starts/ends to registers
1423 PMATCH. 1359 PMATCH.
1424 Note: We assume that pmatch[0] is already set, and 1360 Note: We assume that pmatch[0] is already set, and
1425 pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */ 1361 pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */
1426 1362
1427static reg_errcode_t 1363static reg_errcode_t
1428internal_function __attribute_warn_unused_result__ 1364__attribute_warn_unused_result__
1429set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, 1365set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1430 regmatch_t *pmatch, bool fl_backtrack) 1366 regmatch_t *pmatch, bool fl_backtrack)
1431{ 1367{
@@ -1434,13 +1370,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1434 re_node_set eps_via_nodes; 1370 re_node_set eps_via_nodes;
1435 struct re_fail_stack_t *fs; 1371 struct re_fail_stack_t *fs;
1436 struct re_fail_stack_t fs_body = { 0, 2, NULL }; 1372 struct re_fail_stack_t fs_body = { 0, 2, NULL };
1437 regmatch_t *prev_idx_match; 1373 struct regmatch_list prev_match;
1438 bool prev_idx_match_malloced = false; 1374 regmatch_list_init (&prev_match);
1439 1375
1440#ifdef DEBUG 1376 DEBUG_ASSERT (nmatch > 1);
1441 assert (nmatch > 1); 1377 DEBUG_ASSERT (mctx->state_log != NULL);
1442 assert (mctx->state_log != NULL);
1443#endif
1444 if (fl_backtrack) 1378 if (fl_backtrack)
1445 { 1379 {
1446 fs = &fs_body; 1380 fs = &fs_body;
@@ -1454,85 +1388,73 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1454 cur_node = dfa->init_node; 1388 cur_node = dfa->init_node;
1455 re_node_set_init_empty (&eps_via_nodes); 1389 re_node_set_init_empty (&eps_via_nodes);
1456 1390
1457 if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) 1391 if (!regmatch_list_resize (&prev_match, nmatch))
1458 prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
1459 else
1460 { 1392 {
1461 prev_idx_match = re_malloc (regmatch_t, nmatch); 1393 regmatch_list_free (&prev_match);
1462 if (prev_idx_match == NULL) 1394 free_fail_stack_return (fs);
1463 { 1395 return REG_ESPACE;
1464 free_fail_stack_return (fs);
1465 return REG_ESPACE;
1466 }
1467 prev_idx_match_malloced = true;
1468 } 1396 }
1397 regmatch_t *prev_idx_match = regmatch_list_begin (&prev_match);
1469 memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); 1398 memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
1470 1399
1471 for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) 1400 for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
1472 { 1401 {
1473 update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); 1402 update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch);
1474 1403
1475 if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) 1404 if ((idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
1405 || (fs && re_node_set_contains (&eps_via_nodes, cur_node)))
1476 { 1406 {
1477 Idx reg_idx; 1407 Idx reg_idx;
1408 cur_node = -1;
1478 if (fs) 1409 if (fs)
1479 { 1410 {
1480 for (reg_idx = 0; reg_idx < nmatch; ++reg_idx) 1411 for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
1481 if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1) 1412 if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1)
1482 break; 1413 {
1483 if (reg_idx == nmatch) 1414 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
1484 { 1415 prev_idx_match, &eps_via_nodes);
1485 re_node_set_free (&eps_via_nodes); 1416 break;
1486 if (prev_idx_match_malloced) 1417 }
1487 re_free (prev_idx_match);
1488 return free_fail_stack_return (fs);
1489 }
1490 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
1491 &eps_via_nodes);
1492 } 1418 }
1493 else 1419 if (cur_node < 0)
1494 { 1420 {
1495 re_node_set_free (&eps_via_nodes); 1421 re_node_set_free (&eps_via_nodes);
1496 if (prev_idx_match_malloced) 1422 regmatch_list_free (&prev_match);
1497 re_free (prev_idx_match); 1423 return free_fail_stack_return (fs);
1498 return REG_NOERROR;
1499 } 1424 }
1500 } 1425 }
1501 1426
1502 /* Proceed to next node. */ 1427 /* Proceed to next node. */
1503 cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node, 1428 cur_node = proceed_next_node (mctx, nmatch, pmatch, prev_idx_match,
1429 &idx, cur_node,
1504 &eps_via_nodes, fs); 1430 &eps_via_nodes, fs);
1505 1431
1506 if (BE (! REG_VALID_INDEX (cur_node), 0)) 1432 if (__glibc_unlikely (cur_node < 0))
1507 { 1433 {
1508 if (BE (cur_node == REG_ERROR, 0)) 1434 if (__glibc_unlikely (cur_node == -2))
1509 { 1435 {
1510 re_node_set_free (&eps_via_nodes); 1436 re_node_set_free (&eps_via_nodes);
1511 if (prev_idx_match_malloced) 1437 regmatch_list_free (&prev_match);
1512 re_free (prev_idx_match);
1513 free_fail_stack_return (fs); 1438 free_fail_stack_return (fs);
1514 return REG_ESPACE; 1439 return REG_ESPACE;
1515 } 1440 }
1516 if (fs) 1441 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
1517 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch, 1442 prev_idx_match, &eps_via_nodes);
1518 &eps_via_nodes); 1443 if (cur_node < 0)
1519 else
1520 { 1444 {
1521 re_node_set_free (&eps_via_nodes); 1445 re_node_set_free (&eps_via_nodes);
1522 if (prev_idx_match_malloced) 1446 regmatch_list_free (&prev_match);
1523 re_free (prev_idx_match); 1447 free_fail_stack_return (fs);
1524 return REG_NOMATCH; 1448 return REG_NOMATCH;
1525 } 1449 }
1526 } 1450 }
1527 } 1451 }
1528 re_node_set_free (&eps_via_nodes); 1452 re_node_set_free (&eps_via_nodes);
1529 if (prev_idx_match_malloced) 1453 regmatch_list_free (&prev_match);
1530 re_free (prev_idx_match);
1531 return free_fail_stack_return (fs); 1454 return free_fail_stack_return (fs);
1532} 1455}
1533 1456
1534static reg_errcode_t 1457static reg_errcode_t
1535internal_function
1536free_fail_stack_return (struct re_fail_stack_t *fs) 1458free_fail_stack_return (struct re_fail_stack_t *fs)
1537{ 1459{
1538 if (fs) 1460 if (fs)
@@ -1549,7 +1471,6 @@ free_fail_stack_return (struct re_fail_stack_t *fs)
1549} 1471}
1550 1472
1551static void 1473static void
1552internal_function
1553update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, 1474update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
1554 regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch) 1475 regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
1555{ 1476{
@@ -1567,10 +1488,10 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
1567 } 1488 }
1568 else if (type == OP_CLOSE_SUBEXP) 1489 else if (type == OP_CLOSE_SUBEXP)
1569 { 1490 {
1491 /* We are at the last node of this sub expression. */
1570 Idx reg_num = dfa->nodes[cur_node].opr.idx + 1; 1492 Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
1571 if (reg_num < nmatch) 1493 if (reg_num < nmatch)
1572 { 1494 {
1573 /* We are at the last node of this sub expression. */
1574 if (pmatch[reg_num].rm_so < cur_idx) 1495 if (pmatch[reg_num].rm_so < cur_idx)
1575 { 1496 {
1576 pmatch[reg_num].rm_eo = cur_idx; 1497 pmatch[reg_num].rm_eo = cur_idx;
@@ -1621,7 +1542,6 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
1621 ((state) != NULL && re_node_set_contains (&(state)->nodes, node)) 1542 ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
1622 1543
1623static reg_errcode_t 1544static reg_errcode_t
1624internal_function
1625sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) 1545sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1626{ 1546{
1627 reg_errcode_t err; 1547 reg_errcode_t err;
@@ -1629,17 +1549,15 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1629 Idx str_idx = sctx->last_str_idx; 1549 Idx str_idx = sctx->last_str_idx;
1630 re_node_set cur_dest; 1550 re_node_set cur_dest;
1631 1551
1632#ifdef DEBUG 1552 DEBUG_ASSERT (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
1633 assert (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
1634#endif
1635 1553
1636 /* Build sifted state_log[str_idx]. It has the nodes which can epsilon 1554 /* Build sifted state_log[str_idx]. It has the nodes which can epsilon
1637 transit to the last_node and the last_node itself. */ 1555 transit to the last_node and the last_node itself. */
1638 err = re_node_set_init_1 (&cur_dest, sctx->last_node); 1556 err = re_node_set_init_1 (&cur_dest, sctx->last_node);
1639 if (BE (err != REG_NOERROR, 0)) 1557 if (__glibc_unlikely (err != REG_NOERROR))
1640 return err; 1558 return err;
1641 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); 1559 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
1642 if (BE (err != REG_NOERROR, 0)) 1560 if (__glibc_unlikely (err != REG_NOERROR))
1643 goto free_return; 1561 goto free_return;
1644 1562
1645 /* Then check each states in the state_log. */ 1563 /* Then check each states in the state_log. */
@@ -1660,7 +1578,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1660 if (mctx->state_log[str_idx]) 1578 if (mctx->state_log[str_idx])
1661 { 1579 {
1662 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); 1580 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest);
1663 if (BE (err != REG_NOERROR, 0)) 1581 if (__glibc_unlikely (err != REG_NOERROR))
1664 goto free_return; 1582 goto free_return;
1665 } 1583 }
1666 1584
@@ -1669,7 +1587,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1669 - It is in CUR_SRC. 1587 - It is in CUR_SRC.
1670 And update state_log. */ 1588 And update state_log. */
1671 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); 1589 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
1672 if (BE (err != REG_NOERROR, 0)) 1590 if (__glibc_unlikely (err != REG_NOERROR))
1673 goto free_return; 1591 goto free_return;
1674 } 1592 }
1675 err = REG_NOERROR; 1593 err = REG_NOERROR;
@@ -1679,7 +1597,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1679} 1597}
1680 1598
1681static reg_errcode_t 1599static reg_errcode_t
1682internal_function __attribute_warn_unused_result__ 1600__attribute_warn_unused_result__
1683build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, 1601build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1684 Idx str_idx, re_node_set *cur_dest) 1602 Idx str_idx, re_node_set *cur_dest)
1685{ 1603{
@@ -1699,17 +1617,12 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1699 Idx prev_node = cur_src->elems[i]; 1617 Idx prev_node = cur_src->elems[i];
1700 int naccepted = 0; 1618 int naccepted = 0;
1701 bool ok; 1619 bool ok;
1620 DEBUG_ASSERT (!IS_EPSILON_NODE (dfa->nodes[prev_node].type));
1702 1621
1703#ifdef DEBUG
1704 re_token_type_t type = dfa->nodes[prev_node].type;
1705 assert (!IS_EPSILON_NODE (type));
1706#endif
1707#ifdef RE_ENABLE_I18N
1708 /* If the node may accept "multi byte". */ 1622 /* If the node may accept "multi byte". */
1709 if (dfa->nodes[prev_node].accept_mb) 1623 if (dfa->nodes[prev_node].accept_mb)
1710 naccepted = sift_states_iter_mb (mctx, sctx, prev_node, 1624 naccepted = sift_states_iter_mb (mctx, sctx, prev_node,
1711 str_idx, sctx->last_str_idx); 1625 str_idx, sctx->last_str_idx);
1712#endif /* RE_ENABLE_I18N */
1713 1626
1714 /* We don't check backreferences here. 1627 /* We don't check backreferences here.
1715 See update_cur_sifted_state(). */ 1628 See update_cur_sifted_state(). */
@@ -1731,7 +1644,7 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1731 continue; 1644 continue;
1732 } 1645 }
1733 ok = re_node_set_insert (cur_dest, prev_node); 1646 ok = re_node_set_insert (cur_dest, prev_node);
1734 if (BE (! ok, 0)) 1647 if (__glibc_unlikely (! ok))
1735 return REG_ESPACE; 1648 return REG_ESPACE;
1736 } 1649 }
1737 1650
@@ -1741,7 +1654,6 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1741/* Helper functions. */ 1654/* Helper functions. */
1742 1655
1743static reg_errcode_t 1656static reg_errcode_t
1744internal_function
1745clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx) 1657clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
1746{ 1658{
1747 Idx top = mctx->state_log_top; 1659 Idx top = mctx->state_log_top;
@@ -1753,12 +1665,13 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
1753 { 1665 {
1754 reg_errcode_t err; 1666 reg_errcode_t err;
1755 err = extend_buffers (mctx, next_state_log_idx + 1); 1667 err = extend_buffers (mctx, next_state_log_idx + 1);
1756 if (BE (err != REG_NOERROR, 0)) 1668 if (__glibc_unlikely (err != REG_NOERROR))
1757 return err; 1669 return err;
1758 } 1670 }
1759 1671
1760 if (top < next_state_log_idx) 1672 if (top < next_state_log_idx)
1761 { 1673 {
1674 DEBUG_ASSERT (mctx->state_log != NULL);
1762 memset (mctx->state_log + top + 1, '\0', 1675 memset (mctx->state_log + top + 1, '\0',
1763 sizeof (re_dfastate_t *) * (next_state_log_idx - top)); 1676 sizeof (re_dfastate_t *) * (next_state_log_idx - top));
1764 mctx->state_log_top = next_state_log_idx; 1677 mctx->state_log_top = next_state_log_idx;
@@ -1767,7 +1680,6 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
1767} 1680}
1768 1681
1769static reg_errcode_t 1682static reg_errcode_t
1770internal_function
1771merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, 1683merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
1772 re_dfastate_t **src, Idx num) 1684 re_dfastate_t **src, Idx num)
1773{ 1685{
@@ -1782,11 +1694,11 @@ merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
1782 re_node_set merged_set; 1694 re_node_set merged_set;
1783 err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes, 1695 err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes,
1784 &src[st_idx]->nodes); 1696 &src[st_idx]->nodes);
1785 if (BE (err != REG_NOERROR, 0)) 1697 if (__glibc_unlikely (err != REG_NOERROR))
1786 return err; 1698 return err;
1787 dst[st_idx] = re_acquire_state (&err, dfa, &merged_set); 1699 dst[st_idx] = re_acquire_state (&err, dfa, &merged_set);
1788 re_node_set_free (&merged_set); 1700 re_node_set_free (&merged_set);
1789 if (BE (err != REG_NOERROR, 0)) 1701 if (__glibc_unlikely (err != REG_NOERROR))
1790 return err; 1702 return err;
1791 } 1703 }
1792 } 1704 }
@@ -1794,7 +1706,6 @@ merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
1794} 1706}
1795 1707
1796static reg_errcode_t 1708static reg_errcode_t
1797internal_function
1798update_cur_sifted_state (const re_match_context_t *mctx, 1709update_cur_sifted_state (const re_match_context_t *mctx,
1799 re_sift_context_t *sctx, Idx str_idx, 1710 re_sift_context_t *sctx, Idx str_idx,
1800 re_node_set *dest_nodes) 1711 re_node_set *dest_nodes)
@@ -1814,7 +1725,7 @@ update_cur_sifted_state (const re_match_context_t *mctx,
1814 /* At first, add the nodes which can epsilon transit to a node in 1725 /* At first, add the nodes which can epsilon transit to a node in
1815 DEST_NODE. */ 1726 DEST_NODE. */
1816 err = add_epsilon_src_nodes (dfa, dest_nodes, candidates); 1727 err = add_epsilon_src_nodes (dfa, dest_nodes, candidates);
1817 if (BE (err != REG_NOERROR, 0)) 1728 if (__glibc_unlikely (err != REG_NOERROR))
1818 return err; 1729 return err;
1819 1730
1820 /* Then, check the limitations in the current sift_context. */ 1731 /* Then, check the limitations in the current sift_context. */
@@ -1822,27 +1733,27 @@ update_cur_sifted_state (const re_match_context_t *mctx,
1822 { 1733 {
1823 err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits, 1734 err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits,
1824 mctx->bkref_ents, str_idx); 1735 mctx->bkref_ents, str_idx);
1825 if (BE (err != REG_NOERROR, 0)) 1736 if (__glibc_unlikely (err != REG_NOERROR))
1826 return err; 1737 return err;
1827 } 1738 }
1828 } 1739 }
1829 1740
1830 sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes); 1741 sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes);
1831 if (BE (err != REG_NOERROR, 0)) 1742 if (__glibc_unlikely (err != REG_NOERROR))
1832 return err; 1743 return err;
1833 } 1744 }
1834 1745
1835 if (candidates && mctx->state_log[str_idx]->has_backref) 1746 if (candidates && mctx->state_log[str_idx]->has_backref)
1836 { 1747 {
1837 err = sift_states_bkref (mctx, sctx, str_idx, candidates); 1748 err = sift_states_bkref (mctx, sctx, str_idx, candidates);
1838 if (BE (err != REG_NOERROR, 0)) 1749 if (__glibc_unlikely (err != REG_NOERROR))
1839 return err; 1750 return err;
1840 } 1751 }
1841 return REG_NOERROR; 1752 return REG_NOERROR;
1842} 1753}
1843 1754
1844static reg_errcode_t 1755static reg_errcode_t
1845internal_function __attribute_warn_unused_result__ 1756__attribute_warn_unused_result__
1846add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, 1757add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1847 const re_node_set *candidates) 1758 const re_node_set *candidates)
1848{ 1759{
@@ -1850,19 +1761,19 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1850 Idx i; 1761 Idx i;
1851 1762
1852 re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes); 1763 re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
1853 if (BE (err != REG_NOERROR, 0)) 1764 if (__glibc_unlikely (err != REG_NOERROR))
1854 return err; 1765 return err;
1855 1766
1856 if (!state->inveclosure.alloc) 1767 if (!state->inveclosure.alloc)
1857 { 1768 {
1858 err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem); 1769 err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
1859 if (BE (err != REG_NOERROR, 0)) 1770 if (__glibc_unlikely (err != REG_NOERROR))
1860 return REG_ESPACE; 1771 return REG_ESPACE;
1861 for (i = 0; i < dest_nodes->nelem; i++) 1772 for (i = 0; i < dest_nodes->nelem; i++)
1862 { 1773 {
1863 err = re_node_set_merge (&state->inveclosure, 1774 err = re_node_set_merge (&state->inveclosure,
1864 dfa->inveclosures + dest_nodes->elems[i]); 1775 dfa->inveclosures + dest_nodes->elems[i]);
1865 if (BE (err != REG_NOERROR, 0)) 1776 if (__glibc_unlikely (err != REG_NOERROR))
1866 return REG_ESPACE; 1777 return REG_ESPACE;
1867 } 1778 }
1868 } 1779 }
@@ -1871,7 +1782,6 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1871} 1782}
1872 1783
1873static reg_errcode_t 1784static reg_errcode_t
1874internal_function
1875sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, 1785sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
1876 const re_node_set *candidates) 1786 const re_node_set *candidates)
1877{ 1787{
@@ -1889,16 +1799,16 @@ sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
1889 { 1799 {
1890 Idx edst1 = dfa->edests[cur_node].elems[0]; 1800 Idx edst1 = dfa->edests[cur_node].elems[0];
1891 Idx edst2 = ((dfa->edests[cur_node].nelem > 1) 1801 Idx edst2 = ((dfa->edests[cur_node].nelem > 1)
1892 ? dfa->edests[cur_node].elems[1] : REG_MISSING); 1802 ? dfa->edests[cur_node].elems[1] : -1);
1893 if ((!re_node_set_contains (inv_eclosure, edst1) 1803 if ((!re_node_set_contains (inv_eclosure, edst1)
1894 && re_node_set_contains (dest_nodes, edst1)) 1804 && re_node_set_contains (dest_nodes, edst1))
1895 || (REG_VALID_NONZERO_INDEX (edst2) 1805 || (edst2 > 0
1896 && !re_node_set_contains (inv_eclosure, edst2) 1806 && !re_node_set_contains (inv_eclosure, edst2)
1897 && re_node_set_contains (dest_nodes, edst2))) 1807 && re_node_set_contains (dest_nodes, edst2)))
1898 { 1808 {
1899 err = re_node_set_add_intersect (&except_nodes, candidates, 1809 err = re_node_set_add_intersect (&except_nodes, candidates,
1900 dfa->inveclosures + cur_node); 1810 dfa->inveclosures + cur_node);
1901 if (BE (err != REG_NOERROR, 0)) 1811 if (__glibc_unlikely (err != REG_NOERROR))
1902 { 1812 {
1903 re_node_set_free (&except_nodes); 1813 re_node_set_free (&except_nodes);
1904 return err; 1814 return err;
@@ -1920,7 +1830,6 @@ sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
1920} 1830}
1921 1831
1922static bool 1832static bool
1923internal_function
1924check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, 1833check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
1925 Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx) 1834 Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
1926{ 1835{
@@ -1956,7 +1865,6 @@ check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
1956} 1865}
1957 1866
1958static int 1867static int
1959internal_function
1960check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, 1868check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
1961 Idx subexp_idx, Idx from_node, Idx bkref_idx) 1869 Idx subexp_idx, Idx from_node, Idx bkref_idx)
1962{ 1870{
@@ -1972,7 +1880,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
1972 switch (dfa->nodes[node].type) 1880 switch (dfa->nodes[node].type)
1973 { 1881 {
1974 case OP_BACK_REF: 1882 case OP_BACK_REF:
1975 if (bkref_idx != REG_MISSING) 1883 if (bkref_idx != -1)
1976 { 1884 {
1977 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx; 1885 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
1978 do 1886 do
@@ -2038,7 +1946,6 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
2038} 1946}
2039 1947
2040static int 1948static int
2041internal_function
2042check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, 1949check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
2043 Idx subexp_idx, Idx from_node, Idx str_idx, 1950 Idx subexp_idx, Idx from_node, Idx str_idx,
2044 Idx bkref_idx) 1951 Idx bkref_idx)
@@ -2068,7 +1975,6 @@ check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
2068 which are against limitations from DEST_NODES. */ 1975 which are against limitations from DEST_NODES. */
2069 1976
2070static reg_errcode_t 1977static reg_errcode_t
2071internal_function
2072check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, 1978check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2073 const re_node_set *candidates, re_node_set *limits, 1979 const re_node_set *candidates, re_node_set *limits,
2074 struct re_backref_cache_entry *bkref_ents, Idx str_idx) 1980 struct re_backref_cache_entry *bkref_ents, Idx str_idx)
@@ -2088,8 +1994,8 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2088 subexp_idx = dfa->nodes[ent->node].opr.idx; 1994 subexp_idx = dfa->nodes[ent->node].opr.idx;
2089 if (ent->subexp_to == str_idx) 1995 if (ent->subexp_to == str_idx)
2090 { 1996 {
2091 Idx ops_node = REG_MISSING; 1997 Idx ops_node = -1;
2092 Idx cls_node = REG_MISSING; 1998 Idx cls_node = -1;
2093 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) 1999 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
2094 { 2000 {
2095 Idx node = dest_nodes->elems[node_idx]; 2001 Idx node = dest_nodes->elems[node_idx];
@@ -2104,16 +2010,16 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2104 2010
2105 /* Check the limitation of the open subexpression. */ 2011 /* Check the limitation of the open subexpression. */
2106 /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */ 2012 /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */
2107 if (REG_VALID_INDEX (ops_node)) 2013 if (ops_node >= 0)
2108 { 2014 {
2109 err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes, 2015 err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes,
2110 candidates); 2016 candidates);
2111 if (BE (err != REG_NOERROR, 0)) 2017 if (__glibc_unlikely (err != REG_NOERROR))
2112 return err; 2018 return err;
2113 } 2019 }
2114 2020
2115 /* Check the limitation of the close subexpression. */ 2021 /* Check the limitation of the close subexpression. */
2116 if (REG_VALID_INDEX (cls_node)) 2022 if (cls_node >= 0)
2117 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) 2023 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
2118 { 2024 {
2119 Idx node = dest_nodes->elems[node_idx]; 2025 Idx node = dest_nodes->elems[node_idx];
@@ -2126,7 +2032,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2126 Remove it form the current sifted state. */ 2032 Remove it form the current sifted state. */
2127 err = sub_epsilon_src_nodes (dfa, node, dest_nodes, 2033 err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
2128 candidates); 2034 candidates);
2129 if (BE (err != REG_NOERROR, 0)) 2035 if (__glibc_unlikely (err != REG_NOERROR))
2130 return err; 2036 return err;
2131 --node_idx; 2037 --node_idx;
2132 } 2038 }
@@ -2146,7 +2052,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2146 Remove it form the current sifted state. */ 2052 Remove it form the current sifted state. */
2147 err = sub_epsilon_src_nodes (dfa, node, dest_nodes, 2053 err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
2148 candidates); 2054 candidates);
2149 if (BE (err != REG_NOERROR, 0)) 2055 if (__glibc_unlikely (err != REG_NOERROR))
2150 return err; 2056 return err;
2151 } 2057 }
2152 } 2058 }
@@ -2156,7 +2062,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2156} 2062}
2157 2063
2158static reg_errcode_t 2064static reg_errcode_t
2159internal_function __attribute_warn_unused_result__ 2065__attribute_warn_unused_result__
2160sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, 2066sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2161 Idx str_idx, const re_node_set *candidates) 2067 Idx str_idx, const re_node_set *candidates)
2162{ 2068{
@@ -2166,7 +2072,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2166 re_sift_context_t local_sctx; 2072 re_sift_context_t local_sctx;
2167 Idx first_idx = search_cur_bkref_entry (mctx, str_idx); 2073 Idx first_idx = search_cur_bkref_entry (mctx, str_idx);
2168 2074
2169 if (first_idx == REG_MISSING) 2075 if (first_idx == -1)
2170 return REG_NOERROR; 2076 return REG_NOERROR;
2171 2077
2172 local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */ 2078 local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */
@@ -2212,27 +2118,27 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2212 { 2118 {
2213 local_sctx = *sctx; 2119 local_sctx = *sctx;
2214 err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits); 2120 err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits);
2215 if (BE (err != REG_NOERROR, 0)) 2121 if (__glibc_unlikely (err != REG_NOERROR))
2216 goto free_return; 2122 goto free_return;
2217 } 2123 }
2218 local_sctx.last_node = node; 2124 local_sctx.last_node = node;
2219 local_sctx.last_str_idx = str_idx; 2125 local_sctx.last_str_idx = str_idx;
2220 ok = re_node_set_insert (&local_sctx.limits, enabled_idx); 2126 ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
2221 if (BE (! ok, 0)) 2127 if (__glibc_unlikely (! ok))
2222 { 2128 {
2223 err = REG_ESPACE; 2129 err = REG_ESPACE;
2224 goto free_return; 2130 goto free_return;
2225 } 2131 }
2226 cur_state = local_sctx.sifted_states[str_idx]; 2132 cur_state = local_sctx.sifted_states[str_idx];
2227 err = sift_states_backward (mctx, &local_sctx); 2133 err = sift_states_backward (mctx, &local_sctx);
2228 if (BE (err != REG_NOERROR, 0)) 2134 if (__glibc_unlikely (err != REG_NOERROR))
2229 goto free_return; 2135 goto free_return;
2230 if (sctx->limited_states != NULL) 2136 if (sctx->limited_states != NULL)
2231 { 2137 {
2232 err = merge_state_array (dfa, sctx->limited_states, 2138 err = merge_state_array (dfa, sctx->limited_states,
2233 local_sctx.sifted_states, 2139 local_sctx.sifted_states,
2234 str_idx + 1); 2140 str_idx + 1);
2235 if (BE (err != REG_NOERROR, 0)) 2141 if (__glibc_unlikely (err != REG_NOERROR))
2236 goto free_return; 2142 goto free_return;
2237 } 2143 }
2238 local_sctx.sifted_states[str_idx] = cur_state; 2144 local_sctx.sifted_states[str_idx] = cur_state;
@@ -2254,9 +2160,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2254} 2160}
2255 2161
2256 2162
2257#ifdef RE_ENABLE_I18N
2258static int 2163static int
2259internal_function
2260sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, 2164sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
2261 Idx node_idx, Idx str_idx, Idx max_str_idx) 2165 Idx node_idx, Idx str_idx, Idx max_str_idx)
2262{ 2166{
@@ -2264,44 +2168,41 @@ sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
2264 int naccepted; 2168 int naccepted;
2265 /* Check the node can accept "multi byte". */ 2169 /* Check the node can accept "multi byte". */
2266 naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); 2170 naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
2267 if (naccepted > 0 && str_idx + naccepted <= max_str_idx && 2171 if (naccepted > 0 && str_idx + naccepted <= max_str_idx
2268 !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted], 2172 && !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted],
2269 dfa->nexts[node_idx])) 2173 dfa->nexts[node_idx]))
2270 /* The node can't accept the "multi byte", or the 2174 /* The node can't accept the "multi byte", or the
2271 destination was already thrown away, then the node 2175 destination was already thrown away, then the node
2272 could't accept the current input "multi byte". */ 2176 couldn't accept the current input "multi byte". */
2273 naccepted = 0; 2177 naccepted = 0;
2274 /* Otherwise, it is sure that the node could accept 2178 /* Otherwise, it is sure that the node could accept
2275 'naccepted' bytes input. */ 2179 'naccepted' bytes input. */
2276 return naccepted; 2180 return naccepted;
2277} 2181}
2278#endif /* RE_ENABLE_I18N */
2279
2280 2182
2281/* Functions for state transition. */ 2183/* Functions for state transition. */
2282 2184
2283/* Return the next state to which the current state STATE will transit by 2185/* Return the next state to which the current state STATE will transit by
2284 accepting the current input byte, and update STATE_LOG if necessary. 2186 accepting the current input byte, and update STATE_LOG if necessary.
2187 Return NULL on failure.
2285 If STATE can accept a multibyte char/collating element/back reference 2188 If STATE can accept a multibyte char/collating element/back reference
2286 update the destination of STATE_LOG. */ 2189 update the destination of STATE_LOG. */
2287 2190
2288static re_dfastate_t * 2191static re_dfastate_t *
2289internal_function __attribute_warn_unused_result__ 2192__attribute_warn_unused_result__
2290transit_state (reg_errcode_t *err, re_match_context_t *mctx, 2193transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2291 re_dfastate_t *state) 2194 re_dfastate_t *state)
2292{ 2195{
2293 re_dfastate_t **trtable; 2196 re_dfastate_t **trtable;
2294 unsigned char ch; 2197 unsigned char ch;
2295 2198
2296#ifdef RE_ENABLE_I18N
2297 /* If the current state can accept multibyte. */ 2199 /* If the current state can accept multibyte. */
2298 if (BE (state->accept_mb, 0)) 2200 if (__glibc_unlikely (state->accept_mb))
2299 { 2201 {
2300 *err = transit_state_mb (mctx, state); 2202 *err = transit_state_mb (mctx, state);
2301 if (BE (*err != REG_NOERROR, 0)) 2203 if (__glibc_unlikely (*err != REG_NOERROR))
2302 return NULL; 2204 return NULL;
2303 } 2205 }
2304#endif /* RE_ENABLE_I18N */
2305 2206
2306 /* Then decide the next state with the single byte. */ 2207 /* Then decide the next state with the single byte. */
2307#if 0 2208#if 0
@@ -2315,11 +2216,11 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2315 for (;;) 2216 for (;;)
2316 { 2217 {
2317 trtable = state->trtable; 2218 trtable = state->trtable;
2318 if (BE (trtable != NULL, 1)) 2219 if (__glibc_likely (trtable != NULL))
2319 return trtable[ch]; 2220 return trtable[ch];
2320 2221
2321 trtable = state->word_trtable; 2222 trtable = state->word_trtable;
2322 if (BE (trtable != NULL, 1)) 2223 if (__glibc_likely (trtable != NULL))
2323 { 2224 {
2324 unsigned int context; 2225 unsigned int context;
2325 context 2226 context
@@ -2344,7 +2245,6 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2344 2245
2345/* Update the state_log if we need */ 2246/* Update the state_log if we need */
2346static re_dfastate_t * 2247static re_dfastate_t *
2347internal_function
2348merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, 2248merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2349 re_dfastate_t *next_state) 2249 re_dfastate_t *next_state)
2350{ 2250{
@@ -2376,7 +2276,7 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2376 table_nodes = next_state->entrance_nodes; 2276 table_nodes = next_state->entrance_nodes;
2377 *err = re_node_set_init_union (&next_nodes, table_nodes, 2277 *err = re_node_set_init_union (&next_nodes, table_nodes,
2378 log_nodes); 2278 log_nodes);
2379 if (BE (*err != REG_NOERROR, 0)) 2279 if (__glibc_unlikely (*err != REG_NOERROR))
2380 return NULL; 2280 return NULL;
2381 } 2281 }
2382 else 2282 else
@@ -2396,21 +2296,21 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2396 re_node_set_free (&next_nodes); 2296 re_node_set_free (&next_nodes);
2397 } 2297 }
2398 2298
2399 if (BE (dfa->nbackref, 0) && next_state != NULL) 2299 if (__glibc_unlikely (dfa->nbackref) && next_state != NULL)
2400 { 2300 {
2401 /* Check OP_OPEN_SUBEXP in the current state in case that we use them 2301 /* Check OP_OPEN_SUBEXP in the current state in case that we use them
2402 later. We must check them here, since the back references in the 2302 later. We must check them here, since the back references in the
2403 next state might use them. */ 2303 next state might use them. */
2404 *err = check_subexp_matching_top (mctx, &next_state->nodes, 2304 *err = check_subexp_matching_top (mctx, &next_state->nodes,
2405 cur_idx); 2305 cur_idx);
2406 if (BE (*err != REG_NOERROR, 0)) 2306 if (__glibc_unlikely (*err != REG_NOERROR))
2407 return NULL; 2307 return NULL;
2408 2308
2409 /* If the next state has back references. */ 2309 /* If the next state has back references. */
2410 if (next_state->has_backref) 2310 if (next_state->has_backref)
2411 { 2311 {
2412 *err = transit_state_bkref (mctx, &next_state->nodes); 2312 *err = transit_state_bkref (mctx, &next_state->nodes);
2413 if (BE (*err != REG_NOERROR, 0)) 2313 if (__glibc_unlikely (*err != REG_NOERROR))
2414 return NULL; 2314 return NULL;
2415 next_state = mctx->state_log[cur_idx]; 2315 next_state = mctx->state_log[cur_idx];
2416 } 2316 }
@@ -2423,7 +2323,6 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2423 multi-byte match, then look in the log for a state 2323 multi-byte match, then look in the log for a state
2424 from which to restart matching. */ 2324 from which to restart matching. */
2425static re_dfastate_t * 2325static re_dfastate_t *
2426internal_function
2427find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) 2326find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
2428{ 2327{
2429 re_dfastate_t *cur_state; 2328 re_dfastate_t *cur_state;
@@ -2454,7 +2353,6 @@ find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
2454 corresponding back references. */ 2353 corresponding back references. */
2455 2354
2456static reg_errcode_t 2355static reg_errcode_t
2457internal_function
2458check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, 2356check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
2459 Idx str_idx) 2357 Idx str_idx)
2460{ 2358{
@@ -2476,7 +2374,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
2476 & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) 2374 & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
2477 { 2375 {
2478 err = match_ctx_add_subtop (mctx, node, str_idx); 2376 err = match_ctx_add_subtop (mctx, node, str_idx);
2479 if (BE (err != REG_NOERROR, 0)) 2377 if (__glibc_unlikely (err != REG_NOERROR))
2480 return err; 2378 return err;
2481 } 2379 }
2482 } 2380 }
@@ -2485,7 +2383,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
2485 2383
2486#if 0 2384#if 0
2487/* Return the next state to which the current state STATE will transit by 2385/* Return the next state to which the current state STATE will transit by
2488 accepting the current input byte. */ 2386 accepting the current input byte. Return NULL on failure. */
2489 2387
2490static re_dfastate_t * 2388static re_dfastate_t *
2491transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, 2389transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
@@ -2498,7 +2396,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2498 unsigned int context; 2396 unsigned int context;
2499 2397
2500 *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1); 2398 *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1);
2501 if (BE (*err != REG_NOERROR, 0)) 2399 if (__glibc_unlikely (*err != REG_NOERROR))
2502 return NULL; 2400 return NULL;
2503 for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt) 2401 for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt)
2504 { 2402 {
@@ -2507,7 +2405,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2507 { 2405 {
2508 *err = re_node_set_merge (&next_nodes, 2406 *err = re_node_set_merge (&next_nodes,
2509 dfa->eclosures + dfa->nexts[cur_node]); 2407 dfa->eclosures + dfa->nexts[cur_node]);
2510 if (BE (*err != REG_NOERROR, 0)) 2408 if (__glibc_unlikely (*err != REG_NOERROR))
2511 { 2409 {
2512 re_node_set_free (&next_nodes); 2410 re_node_set_free (&next_nodes);
2513 return NULL; 2411 return NULL;
@@ -2525,9 +2423,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2525} 2423}
2526#endif 2424#endif
2527 2425
2528#ifdef RE_ENABLE_I18N
2529static reg_errcode_t 2426static reg_errcode_t
2530internal_function
2531transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) 2427transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2532{ 2428{
2533 const re_dfa_t *const dfa = mctx->dfa; 2429 const re_dfa_t *const dfa = mctx->dfa;
@@ -2567,11 +2463,9 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2567 mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted 2463 mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
2568 : mctx->max_mb_elem_len); 2464 : mctx->max_mb_elem_len);
2569 err = clean_state_log_if_needed (mctx, dest_idx); 2465 err = clean_state_log_if_needed (mctx, dest_idx);
2570 if (BE (err != REG_NOERROR, 0)) 2466 if (__glibc_unlikely (err != REG_NOERROR))
2571 return err; 2467 return err;
2572#ifdef DEBUG 2468 DEBUG_ASSERT (dfa->nexts[cur_node_idx] != -1);
2573 assert (dfa->nexts[cur_node_idx] != REG_MISSING);
2574#endif
2575 new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx]; 2469 new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx];
2576 2470
2577 dest_state = mctx->state_log[dest_idx]; 2471 dest_state = mctx->state_log[dest_idx];
@@ -2581,7 +2475,7 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2581 { 2475 {
2582 err = re_node_set_init_union (&dest_nodes, 2476 err = re_node_set_init_union (&dest_nodes,
2583 dest_state->entrance_nodes, new_nodes); 2477 dest_state->entrance_nodes, new_nodes);
2584 if (BE (err != REG_NOERROR, 0)) 2478 if (__glibc_unlikely (err != REG_NOERROR))
2585 return err; 2479 return err;
2586 } 2480 }
2587 context = re_string_context_at (&mctx->input, dest_idx - 1, 2481 context = re_string_context_at (&mctx->input, dest_idx - 1,
@@ -2590,15 +2484,14 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2590 = re_acquire_state_context (&err, dfa, &dest_nodes, context); 2484 = re_acquire_state_context (&err, dfa, &dest_nodes, context);
2591 if (dest_state != NULL) 2485 if (dest_state != NULL)
2592 re_node_set_free (&dest_nodes); 2486 re_node_set_free (&dest_nodes);
2593 if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0)) 2487 if (__glibc_unlikely (mctx->state_log[dest_idx] == NULL
2488 && err != REG_NOERROR))
2594 return err; 2489 return err;
2595 } 2490 }
2596 return REG_NOERROR; 2491 return REG_NOERROR;
2597} 2492}
2598#endif /* RE_ENABLE_I18N */
2599 2493
2600static reg_errcode_t 2494static reg_errcode_t
2601internal_function
2602transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) 2495transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2603{ 2496{
2604 const re_dfa_t *const dfa = mctx->dfa; 2497 const re_dfa_t *const dfa = mctx->dfa;
@@ -2630,14 +2523,12 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2630 Check the substring which the substring matched. */ 2523 Check the substring which the substring matched. */
2631 bkc_idx = mctx->nbkref_ents; 2524 bkc_idx = mctx->nbkref_ents;
2632 err = get_subexp (mctx, node_idx, cur_str_idx); 2525 err = get_subexp (mctx, node_idx, cur_str_idx);
2633 if (BE (err != REG_NOERROR, 0)) 2526 if (__glibc_unlikely (err != REG_NOERROR))
2634 goto free_return; 2527 goto free_return;
2635 2528
2636 /* And add the epsilon closures (which is 'new_dest_nodes') of 2529 /* And add the epsilon closures (which is 'new_dest_nodes') of
2637 the backreference to appropriate state_log. */ 2530 the backreference to appropriate state_log. */
2638#ifdef DEBUG 2531 DEBUG_ASSERT (dfa->nexts[node_idx] != -1);
2639 assert (dfa->nexts[node_idx] != REG_MISSING);
2640#endif
2641 for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx) 2532 for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
2642 { 2533 {
2643 Idx subexp_len; 2534 Idx subexp_len;
@@ -2663,8 +2554,8 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2663 mctx->state_log[dest_str_idx] 2554 mctx->state_log[dest_str_idx]
2664 = re_acquire_state_context (&err, dfa, new_dest_nodes, 2555 = re_acquire_state_context (&err, dfa, new_dest_nodes,
2665 context); 2556 context);
2666 if (BE (mctx->state_log[dest_str_idx] == NULL 2557 if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL
2667 && err != REG_NOERROR, 0)) 2558 && err != REG_NOERROR))
2668 goto free_return; 2559 goto free_return;
2669 } 2560 }
2670 else 2561 else
@@ -2673,7 +2564,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2673 err = re_node_set_init_union (&dest_nodes, 2564 err = re_node_set_init_union (&dest_nodes,
2674 dest_state->entrance_nodes, 2565 dest_state->entrance_nodes,
2675 new_dest_nodes); 2566 new_dest_nodes);
2676 if (BE (err != REG_NOERROR, 0)) 2567 if (__glibc_unlikely (err != REG_NOERROR))
2677 { 2568 {
2678 re_node_set_free (&dest_nodes); 2569 re_node_set_free (&dest_nodes);
2679 goto free_return; 2570 goto free_return;
@@ -2681,8 +2572,8 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2681 mctx->state_log[dest_str_idx] 2572 mctx->state_log[dest_str_idx]
2682 = re_acquire_state_context (&err, dfa, &dest_nodes, context); 2573 = re_acquire_state_context (&err, dfa, &dest_nodes, context);
2683 re_node_set_free (&dest_nodes); 2574 re_node_set_free (&dest_nodes);
2684 if (BE (mctx->state_log[dest_str_idx] == NULL 2575 if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL
2685 && err != REG_NOERROR, 0)) 2576 && err != REG_NOERROR))
2686 goto free_return; 2577 goto free_return;
2687 } 2578 }
2688 /* We need to check recursively if the backreference can epsilon 2579 /* We need to check recursively if the backreference can epsilon
@@ -2692,10 +2583,10 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2692 { 2583 {
2693 err = check_subexp_matching_top (mctx, new_dest_nodes, 2584 err = check_subexp_matching_top (mctx, new_dest_nodes,
2694 cur_str_idx); 2585 cur_str_idx);
2695 if (BE (err != REG_NOERROR, 0)) 2586 if (__glibc_unlikely (err != REG_NOERROR))
2696 goto free_return; 2587 goto free_return;
2697 err = transit_state_bkref (mctx, new_dest_nodes); 2588 err = transit_state_bkref (mctx, new_dest_nodes);
2698 if (BE (err != REG_NOERROR, 0)) 2589 if (__glibc_unlikely (err != REG_NOERROR))
2699 goto free_return; 2590 goto free_return;
2700 } 2591 }
2701 } 2592 }
@@ -2712,7 +2603,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2712 delay these checking for prune_impossible_nodes(). */ 2603 delay these checking for prune_impossible_nodes(). */
2713 2604
2714static reg_errcode_t 2605static reg_errcode_t
2715internal_function __attribute_warn_unused_result__ 2606__attribute_warn_unused_result__
2716get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) 2607get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2717{ 2608{
2718 const re_dfa_t *const dfa = mctx->dfa; 2609 const re_dfa_t *const dfa = mctx->dfa;
@@ -2720,7 +2611,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2720 const char *buf = (const char *) re_string_get_buffer (&mctx->input); 2611 const char *buf = (const char *) re_string_get_buffer (&mctx->input);
2721 /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */ 2612 /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
2722 Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); 2613 Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
2723 if (cache_idx != REG_MISSING) 2614 if (cache_idx != -1)
2724 { 2615 {
2725 const struct re_backref_cache_entry *entry 2616 const struct re_backref_cache_entry *entry
2726 = mctx->bkref_ents + cache_idx; 2617 = mctx->bkref_ents + cache_idx;
@@ -2756,7 +2647,8 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2756 at the back reference? */ 2647 at the back reference? */
2757 if (sl_str_diff > 0) 2648 if (sl_str_diff > 0)
2758 { 2649 {
2759 if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0)) 2650 if (__glibc_unlikely (bkref_str_off + sl_str_diff
2651 > mctx->input.valid_len))
2760 { 2652 {
2761 /* Not enough chars for a successful match. */ 2653 /* Not enough chars for a successful match. */
2762 if (bkref_str_off + sl_str_diff > mctx->input.len) 2654 if (bkref_str_off + sl_str_diff > mctx->input.len)
@@ -2765,7 +2657,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2765 err = clean_state_log_if_needed (mctx, 2657 err = clean_state_log_if_needed (mctx,
2766 bkref_str_off 2658 bkref_str_off
2767 + sl_str_diff); 2659 + sl_str_diff);
2768 if (BE (err != REG_NOERROR, 0)) 2660 if (__glibc_unlikely (err != REG_NOERROR))
2769 return err; 2661 return err;
2770 buf = (const char *) re_string_get_buffer (&mctx->input); 2662 buf = (const char *) re_string_get_buffer (&mctx->input);
2771 } 2663 }
@@ -2784,7 +2676,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2784 2676
2785 if (err == REG_NOMATCH) 2677 if (err == REG_NOMATCH)
2786 continue; 2678 continue;
2787 if (BE (err != REG_NOERROR, 0)) 2679 if (__glibc_unlikely (err != REG_NOERROR))
2788 return err; 2680 return err;
2789 } 2681 }
2790 2682
@@ -2803,14 +2695,14 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2803 at the back reference? */ 2695 at the back reference? */
2804 if (sl_str_off > 0) 2696 if (sl_str_off > 0)
2805 { 2697 {
2806 if (BE (bkref_str_off >= mctx->input.valid_len, 0)) 2698 if (__glibc_unlikely (bkref_str_off >= mctx->input.valid_len))
2807 { 2699 {
2808 /* If we are at the end of the input, we cannot match. */ 2700 /* If we are at the end of the input, we cannot match. */
2809 if (bkref_str_off >= mctx->input.len) 2701 if (bkref_str_off >= mctx->input.len)
2810 break; 2702 break;
2811 2703
2812 err = extend_buffers (mctx, bkref_str_off + 1); 2704 err = extend_buffers (mctx, bkref_str_off + 1);
2813 if (BE (err != REG_NOERROR, 0)) 2705 if (__glibc_unlikely (err != REG_NOERROR))
2814 return err; 2706 return err;
2815 2707
2816 buf = (const char *) re_string_get_buffer (&mctx->input); 2708 buf = (const char *) re_string_get_buffer (&mctx->input);
@@ -2825,7 +2717,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2825 nodes = &mctx->state_log[sl_str]->nodes; 2717 nodes = &mctx->state_log[sl_str]->nodes;
2826 cls_node = find_subexp_node (dfa, nodes, subexp_num, 2718 cls_node = find_subexp_node (dfa, nodes, subexp_num,
2827 OP_CLOSE_SUBEXP); 2719 OP_CLOSE_SUBEXP);
2828 if (cls_node == REG_MISSING) 2720 if (cls_node == -1)
2829 continue; /* No. */ 2721 continue; /* No. */
2830 if (sub_top->path == NULL) 2722 if (sub_top->path == NULL)
2831 { 2723 {
@@ -2841,15 +2733,18 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2841 OP_CLOSE_SUBEXP); 2733 OP_CLOSE_SUBEXP);
2842 if (err == REG_NOMATCH) 2734 if (err == REG_NOMATCH)
2843 continue; 2735 continue;
2844 if (BE (err != REG_NOERROR, 0)) 2736 if (__glibc_unlikely (err != REG_NOERROR))
2845 return err; 2737 return err;
2846 sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str); 2738 sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str);
2847 if (BE (sub_last == NULL, 0)) 2739 if (__glibc_unlikely (sub_last == NULL))
2848 return REG_ESPACE; 2740 return REG_ESPACE;
2849 err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, 2741 err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
2850 bkref_str_idx); 2742 bkref_str_idx);
2743 buf = (const char *) re_string_get_buffer (&mctx->input);
2851 if (err == REG_NOMATCH) 2744 if (err == REG_NOMATCH)
2852 continue; 2745 continue;
2746 if (__glibc_unlikely (err != REG_NOERROR))
2747 return err;
2853 } 2748 }
2854 } 2749 }
2855 return REG_NOERROR; 2750 return REG_NOERROR;
@@ -2862,7 +2757,6 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2862 and SUB_LAST. */ 2757 and SUB_LAST. */
2863 2758
2864static reg_errcode_t 2759static reg_errcode_t
2865internal_function
2866get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, 2760get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
2867 re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str) 2761 re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str)
2868{ 2762{
@@ -2876,7 +2770,7 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
2876 return err; 2770 return err;
2877 err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, 2771 err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
2878 sub_last->str_idx); 2772 sub_last->str_idx);
2879 if (BE (err != REG_NOERROR, 0)) 2773 if (__glibc_unlikely (err != REG_NOERROR))
2880 return err; 2774 return err;
2881 to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx; 2775 to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx;
2882 return clean_state_log_if_needed (mctx, to_idx); 2776 return clean_state_log_if_needed (mctx, to_idx);
@@ -2891,7 +2785,6 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
2891 E.g. RE: (a){2} */ 2785 E.g. RE: (a){2} */
2892 2786
2893static Idx 2787static Idx
2894internal_function
2895find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, 2788find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
2896 Idx subexp_idx, int type) 2789 Idx subexp_idx, int type)
2897{ 2790{
@@ -2904,16 +2797,17 @@ find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
2904 && node->opr.idx == subexp_idx) 2797 && node->opr.idx == subexp_idx)
2905 return cls_node; 2798 return cls_node;
2906 } 2799 }
2907 return REG_MISSING; 2800 return -1;
2908} 2801}
2909 2802
2910/* Check whether the node TOP_NODE at TOP_STR can arrive to the node 2803/* Check whether the node TOP_NODE at TOP_STR can arrive to the node
2911 LAST_NODE at LAST_STR. We record the path onto PATH since it will be 2804 LAST_NODE at LAST_STR. We record the path onto PATH since it will be
2912 heavily reused. 2805 heavily reused.
2913 Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */ 2806 Return REG_NOERROR if it can arrive, REG_NOMATCH if it cannot,
2807 REG_ESPACE if memory is exhausted. */
2914 2808
2915static reg_errcode_t 2809static reg_errcode_t
2916internal_function __attribute_warn_unused_result__ 2810__attribute_warn_unused_result__
2917check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, 2811check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2918 Idx top_str, Idx last_node, Idx last_str, int type) 2812 Idx top_str, Idx last_node, Idx last_str, int type)
2919{ 2813{
@@ -2927,19 +2821,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2927 2821
2928 subexp_num = dfa->nodes[top_node].opr.idx; 2822 subexp_num = dfa->nodes[top_node].opr.idx;
2929 /* Extend the buffer if we need. */ 2823 /* Extend the buffer if we need. */
2930 if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0)) 2824 if (__glibc_unlikely (path->alloc < last_str + mctx->max_mb_elem_len + 1))
2931 { 2825 {
2932 re_dfastate_t **new_array; 2826 re_dfastate_t **new_array;
2933 Idx old_alloc = path->alloc; 2827 Idx old_alloc = path->alloc;
2934 Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1; 2828 Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1;
2935 Idx new_alloc; 2829 Idx new_alloc;
2936 if (BE (IDX_MAX - old_alloc < incr_alloc, 0)) 2830 if (__glibc_unlikely (IDX_MAX - old_alloc < incr_alloc))
2937 return REG_ESPACE; 2831 return REG_ESPACE;
2938 new_alloc = old_alloc + incr_alloc; 2832 new_alloc = old_alloc + incr_alloc;
2939 if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0)) 2833 if (__glibc_unlikely (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc))
2940 return REG_ESPACE; 2834 return REG_ESPACE;
2941 new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); 2835 new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
2942 if (BE (new_array == NULL, 0)) 2836 if (__glibc_unlikely (new_array == NULL))
2943 return REG_ESPACE; 2837 return REG_ESPACE;
2944 path->array = new_array; 2838 path->array = new_array;
2945 path->alloc = new_alloc; 2839 path->alloc = new_alloc;
@@ -2960,10 +2854,10 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2960 if (str_idx == top_str) 2854 if (str_idx == top_str)
2961 { 2855 {
2962 err = re_node_set_init_1 (&next_nodes, top_node); 2856 err = re_node_set_init_1 (&next_nodes, top_node);
2963 if (BE (err != REG_NOERROR, 0)) 2857 if (__glibc_unlikely (err != REG_NOERROR))
2964 return err; 2858 return err;
2965 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); 2859 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
2966 if (BE (err != REG_NOERROR, 0)) 2860 if (__glibc_unlikely (err != REG_NOERROR))
2967 { 2861 {
2968 re_node_set_free (&next_nodes); 2862 re_node_set_free (&next_nodes);
2969 return err; 2863 return err;
@@ -2975,7 +2869,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2975 if (cur_state && cur_state->has_backref) 2869 if (cur_state && cur_state->has_backref)
2976 { 2870 {
2977 err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); 2871 err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
2978 if (BE (err != REG_NOERROR, 0)) 2872 if (__glibc_unlikely (err != REG_NOERROR))
2979 return err; 2873 return err;
2980 } 2874 }
2981 else 2875 else
@@ -2987,14 +2881,14 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2987 { 2881 {
2988 err = expand_bkref_cache (mctx, &next_nodes, str_idx, 2882 err = expand_bkref_cache (mctx, &next_nodes, str_idx,
2989 subexp_num, type); 2883 subexp_num, type);
2990 if (BE (err != REG_NOERROR, 0)) 2884 if (__glibc_unlikely (err != REG_NOERROR))
2991 { 2885 {
2992 re_node_set_free (&next_nodes); 2886 re_node_set_free (&next_nodes);
2993 return err; 2887 return err;
2994 } 2888 }
2995 } 2889 }
2996 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); 2890 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
2997 if (BE (cur_state == NULL && err != REG_NOERROR, 0)) 2891 if (__glibc_unlikely (cur_state == NULL && err != REG_NOERROR))
2998 { 2892 {
2999 re_node_set_free (&next_nodes); 2893 re_node_set_free (&next_nodes);
3000 return err; 2894 return err;
@@ -3009,7 +2903,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3009 { 2903 {
3010 err = re_node_set_merge (&next_nodes, 2904 err = re_node_set_merge (&next_nodes,
3011 &mctx->state_log[str_idx + 1]->nodes); 2905 &mctx->state_log[str_idx + 1]->nodes);
3012 if (BE (err != REG_NOERROR, 0)) 2906 if (__glibc_unlikely (err != REG_NOERROR))
3013 { 2907 {
3014 re_node_set_free (&next_nodes); 2908 re_node_set_free (&next_nodes);
3015 return err; 2909 return err;
@@ -3020,7 +2914,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3020 err = check_arrival_add_next_nodes (mctx, str_idx, 2914 err = check_arrival_add_next_nodes (mctx, str_idx,
3021 &cur_state->non_eps_nodes, 2915 &cur_state->non_eps_nodes,
3022 &next_nodes); 2916 &next_nodes);
3023 if (BE (err != REG_NOERROR, 0)) 2917 if (__glibc_unlikely (err != REG_NOERROR))
3024 { 2918 {
3025 re_node_set_free (&next_nodes); 2919 re_node_set_free (&next_nodes);
3026 return err; 2920 return err;
@@ -3030,14 +2924,14 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3030 if (next_nodes.nelem) 2924 if (next_nodes.nelem)
3031 { 2925 {
3032 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); 2926 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
3033 if (BE (err != REG_NOERROR, 0)) 2927 if (__glibc_unlikely (err != REG_NOERROR))
3034 { 2928 {
3035 re_node_set_free (&next_nodes); 2929 re_node_set_free (&next_nodes);
3036 return err; 2930 return err;
3037 } 2931 }
3038 err = expand_bkref_cache (mctx, &next_nodes, str_idx, 2932 err = expand_bkref_cache (mctx, &next_nodes, str_idx,
3039 subexp_num, type); 2933 subexp_num, type);
3040 if (BE (err != REG_NOERROR, 0)) 2934 if (__glibc_unlikely (err != REG_NOERROR))
3041 { 2935 {
3042 re_node_set_free (&next_nodes); 2936 re_node_set_free (&next_nodes);
3043 return err; 2937 return err;
@@ -3045,7 +2939,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3045 } 2939 }
3046 context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); 2940 context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
3047 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); 2941 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
3048 if (BE (cur_state == NULL && err != REG_NOERROR, 0)) 2942 if (__glibc_unlikely (cur_state == NULL && err != REG_NOERROR))
3049 { 2943 {
3050 re_node_set_free (&next_nodes); 2944 re_node_set_free (&next_nodes);
3051 return err; 2945 return err;
@@ -3078,27 +2972,22 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3078 Can't we unify them? */ 2972 Can't we unify them? */
3079 2973
3080static reg_errcode_t 2974static reg_errcode_t
3081internal_function __attribute_warn_unused_result__ 2975__attribute_warn_unused_result__
3082check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, 2976check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3083 re_node_set *cur_nodes, re_node_set *next_nodes) 2977 re_node_set *cur_nodes, re_node_set *next_nodes)
3084{ 2978{
3085 const re_dfa_t *const dfa = mctx->dfa; 2979 const re_dfa_t *const dfa = mctx->dfa;
3086 bool ok; 2980 bool ok;
3087 Idx cur_idx; 2981 Idx cur_idx;
3088#ifdef RE_ENABLE_I18N
3089 reg_errcode_t err = REG_NOERROR; 2982 reg_errcode_t err = REG_NOERROR;
3090#endif
3091 re_node_set union_set; 2983 re_node_set union_set;
3092 re_node_set_init_empty (&union_set); 2984 re_node_set_init_empty (&union_set);
3093 for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx) 2985 for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
3094 { 2986 {
3095 int naccepted = 0; 2987 int naccepted = 0;
3096 Idx cur_node = cur_nodes->elems[cur_idx]; 2988 Idx cur_node = cur_nodes->elems[cur_idx];
3097#ifdef DEBUG 2989 DEBUG_ASSERT (!IS_EPSILON_NODE (dfa->nodes[cur_node].type));
3098 re_token_type_t type = dfa->nodes[cur_node].type; 2990
3099 assert (!IS_EPSILON_NODE (type));
3100#endif
3101#ifdef RE_ENABLE_I18N
3102 /* If the node may accept "multi byte". */ 2991 /* If the node may accept "multi byte". */
3103 if (dfa->nodes[cur_node].accept_mb) 2992 if (dfa->nodes[cur_node].accept_mb)
3104 { 2993 {
@@ -3114,34 +3003,34 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3114 if (dest_state) 3003 if (dest_state)
3115 { 3004 {
3116 err = re_node_set_merge (&union_set, &dest_state->nodes); 3005 err = re_node_set_merge (&union_set, &dest_state->nodes);
3117 if (BE (err != REG_NOERROR, 0)) 3006 if (__glibc_unlikely (err != REG_NOERROR))
3118 { 3007 {
3119 re_node_set_free (&union_set); 3008 re_node_set_free (&union_set);
3120 return err; 3009 return err;
3121 } 3010 }
3122 } 3011 }
3123 ok = re_node_set_insert (&union_set, next_node); 3012 ok = re_node_set_insert (&union_set, next_node);
3124 if (BE (! ok, 0)) 3013 if (__glibc_unlikely (! ok))
3125 { 3014 {
3126 re_node_set_free (&union_set); 3015 re_node_set_free (&union_set);
3127 return REG_ESPACE; 3016 return REG_ESPACE;
3128 } 3017 }
3129 mctx->state_log[next_idx] = re_acquire_state (&err, dfa, 3018 mctx->state_log[next_idx] = re_acquire_state (&err, dfa,
3130 &union_set); 3019 &union_set);
3131 if (BE (mctx->state_log[next_idx] == NULL 3020 if (__glibc_unlikely (mctx->state_log[next_idx] == NULL
3132 && err != REG_NOERROR, 0)) 3021 && err != REG_NOERROR))
3133 { 3022 {
3134 re_node_set_free (&union_set); 3023 re_node_set_free (&union_set);
3135 return err; 3024 return err;
3136 } 3025 }
3137 } 3026 }
3138 } 3027 }
3139#endif /* RE_ENABLE_I18N */ 3028
3140 if (naccepted 3029 if (naccepted
3141 || check_node_accept (mctx, dfa->nodes + cur_node, str_idx)) 3030 || check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
3142 { 3031 {
3143 ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]); 3032 ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
3144 if (BE (! ok, 0)) 3033 if (__glibc_unlikely (! ok))
3145 { 3034 {
3146 re_node_set_free (&union_set); 3035 re_node_set_free (&union_set);
3147 return REG_ESPACE; 3036 return REG_ESPACE;
@@ -3159,18 +3048,15 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3159*/ 3048*/
3160 3049
3161static reg_errcode_t 3050static reg_errcode_t
3162internal_function
3163check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, 3051check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3164 Idx ex_subexp, int type) 3052 Idx ex_subexp, int type)
3165{ 3053{
3166 reg_errcode_t err; 3054 reg_errcode_t err;
3167 Idx idx, outside_node; 3055 Idx idx, outside_node;
3168 re_node_set new_nodes; 3056 re_node_set new_nodes;
3169#ifdef DEBUG 3057 DEBUG_ASSERT (cur_nodes->nelem);
3170 assert (cur_nodes->nelem);
3171#endif
3172 err = re_node_set_alloc (&new_nodes, cur_nodes->nelem); 3058 err = re_node_set_alloc (&new_nodes, cur_nodes->nelem);
3173 if (BE (err != REG_NOERROR, 0)) 3059 if (__glibc_unlikely (err != REG_NOERROR))
3174 return err; 3060 return err;
3175 /* Create a new node set NEW_NODES with the nodes which are epsilon 3061 /* Create a new node set NEW_NODES with the nodes which are epsilon
3176 closures of the node in CUR_NODES. */ 3062 closures of the node in CUR_NODES. */
@@ -3180,11 +3066,11 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3180 Idx cur_node = cur_nodes->elems[idx]; 3066 Idx cur_node = cur_nodes->elems[idx];
3181 const re_node_set *eclosure = dfa->eclosures + cur_node; 3067 const re_node_set *eclosure = dfa->eclosures + cur_node;
3182 outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); 3068 outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
3183 if (outside_node == REG_MISSING) 3069 if (outside_node == -1)
3184 { 3070 {
3185 /* There are no problematic nodes, just merge them. */ 3071 /* There are no problematic nodes, just merge them. */
3186 err = re_node_set_merge (&new_nodes, eclosure); 3072 err = re_node_set_merge (&new_nodes, eclosure);
3187 if (BE (err != REG_NOERROR, 0)) 3073 if (__glibc_unlikely (err != REG_NOERROR))
3188 { 3074 {
3189 re_node_set_free (&new_nodes); 3075 re_node_set_free (&new_nodes);
3190 return err; 3076 return err;
@@ -3195,7 +3081,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3195 /* There are problematic nodes, re-calculate incrementally. */ 3081 /* There are problematic nodes, re-calculate incrementally. */
3196 err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node, 3082 err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node,
3197 ex_subexp, type); 3083 ex_subexp, type);
3198 if (BE (err != REG_NOERROR, 0)) 3084 if (__glibc_unlikely (err != REG_NOERROR))
3199 { 3085 {
3200 re_node_set_free (&new_nodes); 3086 re_node_set_free (&new_nodes);
3201 return err; 3087 return err;
@@ -3212,7 +3098,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3212 problematic append it to DST_NODES. */ 3098 problematic append it to DST_NODES. */
3213 3099
3214static reg_errcode_t 3100static reg_errcode_t
3215internal_function __attribute_warn_unused_result__ 3101__attribute_warn_unused_result__
3216check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, 3102check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3217 Idx target, Idx ex_subexp, int type) 3103 Idx target, Idx ex_subexp, int type)
3218{ 3104{
@@ -3227,13 +3113,13 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3227 if (type == OP_CLOSE_SUBEXP) 3113 if (type == OP_CLOSE_SUBEXP)
3228 { 3114 {
3229 ok = re_node_set_insert (dst_nodes, cur_node); 3115 ok = re_node_set_insert (dst_nodes, cur_node);
3230 if (BE (! ok, 0)) 3116 if (__glibc_unlikely (! ok))
3231 return REG_ESPACE; 3117 return REG_ESPACE;
3232 } 3118 }
3233 break; 3119 break;
3234 } 3120 }
3235 ok = re_node_set_insert (dst_nodes, cur_node); 3121 ok = re_node_set_insert (dst_nodes, cur_node);
3236 if (BE (! ok, 0)) 3122 if (__glibc_unlikely (! ok))
3237 return REG_ESPACE; 3123 return REG_ESPACE;
3238 if (dfa->edests[cur_node].nelem == 0) 3124 if (dfa->edests[cur_node].nelem == 0)
3239 break; 3125 break;
@@ -3243,7 +3129,7 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3243 err = check_arrival_expand_ecl_sub (dfa, dst_nodes, 3129 err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
3244 dfa->edests[cur_node].elems[1], 3130 dfa->edests[cur_node].elems[1],
3245 ex_subexp, type); 3131 ex_subexp, type);
3246 if (BE (err != REG_NOERROR, 0)) 3132 if (__glibc_unlikely (err != REG_NOERROR))
3247 return err; 3133 return err;
3248 } 3134 }
3249 cur_node = dfa->edests[cur_node].elems[0]; 3135 cur_node = dfa->edests[cur_node].elems[0];
@@ -3257,7 +3143,7 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3257 in MCTX->BKREF_ENTS. */ 3143 in MCTX->BKREF_ENTS. */
3258 3144
3259static reg_errcode_t 3145static reg_errcode_t
3260internal_function __attribute_warn_unused_result__ 3146__attribute_warn_unused_result__
3261expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, 3147expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3262 Idx cur_str, Idx subexp_num, int type) 3148 Idx cur_str, Idx subexp_num, int type)
3263{ 3149{
@@ -3266,7 +3152,7 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3266 Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str); 3152 Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
3267 struct re_backref_cache_entry *ent; 3153 struct re_backref_cache_entry *ent;
3268 3154
3269 if (cache_idx_start == REG_MISSING) 3155 if (cache_idx_start == -1)
3270 return REG_NOERROR; 3156 return REG_NOERROR;
3271 3157
3272 restart: 3158 restart:
@@ -3295,8 +3181,8 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3295 err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type); 3181 err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type);
3296 err3 = re_node_set_merge (cur_nodes, &new_dests); 3182 err3 = re_node_set_merge (cur_nodes, &new_dests);
3297 re_node_set_free (&new_dests); 3183 re_node_set_free (&new_dests);
3298 if (BE (err != REG_NOERROR || err2 != REG_NOERROR 3184 if (__glibc_unlikely (err != REG_NOERROR || err2 != REG_NOERROR
3299 || err3 != REG_NOERROR, 0)) 3185 || err3 != REG_NOERROR))
3300 { 3186 {
3301 err = (err != REG_NOERROR ? err 3187 err = (err != REG_NOERROR ? err
3302 : (err2 != REG_NOERROR ? err2 : err3)); 3188 : (err2 != REG_NOERROR ? err2 : err3));
@@ -3318,7 +3204,7 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3318 err = re_node_set_init_copy (&union_set, 3204 err = re_node_set_init_copy (&union_set,
3319 &mctx->state_log[to_idx]->nodes); 3205 &mctx->state_log[to_idx]->nodes);
3320 ok = re_node_set_insert (&union_set, next_node); 3206 ok = re_node_set_insert (&union_set, next_node);
3321 if (BE (err != REG_NOERROR || ! ok, 0)) 3207 if (__glibc_unlikely (err != REG_NOERROR || ! ok))
3322 { 3208 {
3323 re_node_set_free (&union_set); 3209 re_node_set_free (&union_set);
3324 err = err != REG_NOERROR ? err : REG_ESPACE; 3210 err = err != REG_NOERROR ? err : REG_ESPACE;
@@ -3328,13 +3214,13 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3328 else 3214 else
3329 { 3215 {
3330 err = re_node_set_init_1 (&union_set, next_node); 3216 err = re_node_set_init_1 (&union_set, next_node);
3331 if (BE (err != REG_NOERROR, 0)) 3217 if (__glibc_unlikely (err != REG_NOERROR))
3332 return err; 3218 return err;
3333 } 3219 }
3334 mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set); 3220 mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set);
3335 re_node_set_free (&union_set); 3221 re_node_set_free (&union_set);
3336 if (BE (mctx->state_log[to_idx] == NULL 3222 if (__glibc_unlikely (mctx->state_log[to_idx] == NULL
3337 && err != REG_NOERROR, 0)) 3223 && err != REG_NOERROR))
3338 return err; 3224 return err;
3339 } 3225 }
3340 } 3226 }
@@ -3345,8 +3231,7 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3345/* Build transition table for the state. 3231/* Build transition table for the state.
3346 Return true if successful. */ 3232 Return true if successful. */
3347 3233
3348static bool 3234static bool __attribute_noinline__
3349internal_function
3350build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) 3235build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3351{ 3236{
3352 reg_errcode_t err; 3237 reg_errcode_t err;
@@ -3354,36 +3239,20 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3354 int ch; 3239 int ch;
3355 bool need_word_trtable = false; 3240 bool need_word_trtable = false;
3356 bitset_word_t elem, mask; 3241 bitset_word_t elem, mask;
3357 bool dests_node_malloced = false;
3358 bool dest_states_malloced = false;
3359 Idx ndests; /* Number of the destination states from 'state'. */ 3242 Idx ndests; /* Number of the destination states from 'state'. */
3360 re_dfastate_t **trtable; 3243 re_dfastate_t **trtable;
3361 re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; 3244 re_dfastate_t *dest_states[SBC_MAX];
3362 re_node_set follows, *dests_node; 3245 re_dfastate_t *dest_states_word[SBC_MAX];
3363 bitset_t *dests_ch; 3246 re_dfastate_t *dest_states_nl[SBC_MAX];
3247 re_node_set follows;
3364 bitset_t acceptable; 3248 bitset_t acceptable;
3365 3249
3366 struct dests_alloc
3367 {
3368 re_node_set dests_node[SBC_MAX];
3369 bitset_t dests_ch[SBC_MAX];
3370 } *dests_alloc;
3371
3372 /* We build DFA states which corresponds to the destination nodes 3250 /* We build DFA states which corresponds to the destination nodes
3373 from 'state'. 'dests_node[i]' represents the nodes which i-th 3251 from 'state'. 'dests_node[i]' represents the nodes which i-th
3374 destination state contains, and 'dests_ch[i]' represents the 3252 destination state contains, and 'dests_ch[i]' represents the
3375 characters which i-th destination state accepts. */ 3253 characters which i-th destination state accepts. */
3376 if (__libc_use_alloca (sizeof (struct dests_alloc))) 3254 re_node_set dests_node[SBC_MAX];
3377 dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); 3255 bitset_t dests_ch[SBC_MAX];
3378 else
3379 {
3380 dests_alloc = re_malloc (struct dests_alloc, 1);
3381 if (BE (dests_alloc == NULL, 0))
3382 return false;
3383 dests_node_malloced = true;
3384 }
3385 dests_node = dests_alloc->dests_node;
3386 dests_ch = dests_alloc->dests_ch;
3387 3256
3388 /* Initialize transition table. */ 3257 /* Initialize transition table. */
3389 state->word_trtable = state->trtable = NULL; 3258 state->word_trtable = state->trtable = NULL;
@@ -3391,16 +3260,14 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3391 /* At first, group all nodes belonging to 'state' into several 3260 /* At first, group all nodes belonging to 'state' into several
3392 destinations. */ 3261 destinations. */
3393 ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); 3262 ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
3394 if (BE (! REG_VALID_NONZERO_INDEX (ndests), 0)) 3263 if (__glibc_unlikely (ndests <= 0))
3395 { 3264 {
3396 if (dests_node_malloced)
3397 free (dests_alloc);
3398 /* Return false in case of an error, true otherwise. */ 3265 /* Return false in case of an error, true otherwise. */
3399 if (ndests == 0) 3266 if (ndests == 0)
3400 { 3267 {
3401 state->trtable = (re_dfastate_t **) 3268 state->trtable = (re_dfastate_t **)
3402 calloc (sizeof (re_dfastate_t *), SBC_MAX); 3269 calloc (sizeof (re_dfastate_t *), SBC_MAX);
3403 if (BE (state->trtable == NULL, 0)) 3270 if (__glibc_unlikely (state->trtable == NULL))
3404 return false; 3271 return false;
3405 return true; 3272 return true;
3406 } 3273 }
@@ -3408,40 +3275,15 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3408 } 3275 }
3409 3276
3410 err = re_node_set_alloc (&follows, ndests + 1); 3277 err = re_node_set_alloc (&follows, ndests + 1);
3411 if (BE (err != REG_NOERROR, 0)) 3278 if (__glibc_unlikely (err != REG_NOERROR))
3412 goto out_free;
3413
3414 /* Avoid arithmetic overflow in size calculation. */
3415 if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
3416 / (3 * sizeof (re_dfastate_t *)))
3417 < ndests),
3418 0))
3419 goto out_free;
3420
3421 if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX
3422 + ndests * 3 * sizeof (re_dfastate_t *)))
3423 dest_states = (re_dfastate_t **)
3424 alloca (ndests * 3 * sizeof (re_dfastate_t *));
3425 else
3426 { 3279 {
3427 dest_states = (re_dfastate_t **) 3280 out_free:
3428 malloc (ndests * 3 * sizeof (re_dfastate_t *)); 3281 re_node_set_free (&follows);
3429 if (BE (dest_states == NULL, 0)) 3282 for (i = 0; i < ndests; ++i)
3430 { 3283 re_node_set_free (dests_node + i);
3431out_free: 3284 return false;
3432 if (dest_states_malloced)
3433 free (dest_states);
3434 re_node_set_free (&follows);
3435 for (i = 0; i < ndests; ++i)
3436 re_node_set_free (dests_node + i);
3437 if (dests_node_malloced)
3438 free (dests_alloc);
3439 return false;
3440 }
3441 dest_states_malloced = true;
3442 } 3285 }
3443 dest_states_word = dest_states + ndests; 3286
3444 dest_states_nl = dest_states_word + ndests;
3445 bitset_empty (acceptable); 3287 bitset_empty (acceptable);
3446 3288
3447 /* Then build the states for all destinations. */ 3289 /* Then build the states for all destinations. */
@@ -3453,15 +3295,15 @@ out_free:
3453 for (j = 0; j < dests_node[i].nelem; ++j) 3295 for (j = 0; j < dests_node[i].nelem; ++j)
3454 { 3296 {
3455 next_node = dfa->nexts[dests_node[i].elems[j]]; 3297 next_node = dfa->nexts[dests_node[i].elems[j]];
3456 if (next_node != REG_MISSING) 3298 if (next_node != -1)
3457 { 3299 {
3458 err = re_node_set_merge (&follows, dfa->eclosures + next_node); 3300 err = re_node_set_merge (&follows, dfa->eclosures + next_node);
3459 if (BE (err != REG_NOERROR, 0)) 3301 if (__glibc_unlikely (err != REG_NOERROR))
3460 goto out_free; 3302 goto out_free;
3461 } 3303 }
3462 } 3304 }
3463 dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0); 3305 dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0);
3464 if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0)) 3306 if (__glibc_unlikely (dest_states[i] == NULL && err != REG_NOERROR))
3465 goto out_free; 3307 goto out_free;
3466 /* If the new state has context constraint, 3308 /* If the new state has context constraint,
3467 build appropriate states for these contexts. */ 3309 build appropriate states for these contexts. */
@@ -3469,7 +3311,8 @@ out_free:
3469 { 3311 {
3470 dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows, 3312 dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows,
3471 CONTEXT_WORD); 3313 CONTEXT_WORD);
3472 if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0)) 3314 if (__glibc_unlikely (dest_states_word[i] == NULL
3315 && err != REG_NOERROR))
3473 goto out_free; 3316 goto out_free;
3474 3317
3475 if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1) 3318 if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
@@ -3477,7 +3320,7 @@ out_free:
3477 3320
3478 dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows, 3321 dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
3479 CONTEXT_NEWLINE); 3322 CONTEXT_NEWLINE);
3480 if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0)) 3323 if (__glibc_unlikely (dest_states_nl[i] == NULL && err != REG_NOERROR))
3481 goto out_free; 3324 goto out_free;
3482 } 3325 }
3483 else 3326 else
@@ -3488,7 +3331,7 @@ out_free:
3488 bitset_merge (acceptable, dests_ch[i]); 3331 bitset_merge (acceptable, dests_ch[i]);
3489 } 3332 }
3490 3333
3491 if (!BE (need_word_trtable, 0)) 3334 if (!__glibc_unlikely (need_word_trtable))
3492 { 3335 {
3493 /* We don't care about whether the following character is a word 3336 /* We don't care about whether the following character is a word
3494 character, or we are in a single-byte character set so we can 3337 character, or we are in a single-byte character set so we can
@@ -3496,7 +3339,7 @@ out_free:
3496 256-entry transition table. */ 3339 256-entry transition table. */
3497 trtable = state->trtable = 3340 trtable = state->trtable =
3498 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); 3341 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
3499 if (BE (trtable == NULL, 0)) 3342 if (__glibc_unlikely (trtable == NULL))
3500 goto out_free; 3343 goto out_free;
3501 3344
3502 /* For all characters ch...: */ 3345 /* For all characters ch...: */
@@ -3504,7 +3347,7 @@ out_free:
3504 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; 3347 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
3505 elem; 3348 elem;
3506 mask <<= 1, elem >>= 1, ++ch) 3349 mask <<= 1, elem >>= 1, ++ch)
3507 if (BE (elem & 1, 0)) 3350 if (__glibc_unlikely (elem & 1))
3508 { 3351 {
3509 /* There must be exactly one destination which accepts 3352 /* There must be exactly one destination which accepts
3510 character ch. See group_nodes_into_DFAstates. */ 3353 character ch. See group_nodes_into_DFAstates. */
@@ -3527,7 +3370,7 @@ out_free:
3527 starting at trtable[SBC_MAX]. */ 3370 starting at trtable[SBC_MAX]. */
3528 trtable = state->word_trtable = 3371 trtable = state->word_trtable =
3529 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); 3372 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
3530 if (BE (trtable == NULL, 0)) 3373 if (__glibc_unlikely (trtable == NULL))
3531 goto out_free; 3374 goto out_free;
3532 3375
3533 /* For all characters ch...: */ 3376 /* For all characters ch...: */
@@ -3535,7 +3378,7 @@ out_free:
3535 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; 3378 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
3536 elem; 3379 elem;
3537 mask <<= 1, elem >>= 1, ++ch) 3380 mask <<= 1, elem >>= 1, ++ch)
3538 if (BE (elem & 1, 0)) 3381 if (__glibc_unlikely (elem & 1))
3539 { 3382 {
3540 /* There must be exactly one destination which accepts 3383 /* There must be exactly one destination which accepts
3541 character ch. See group_nodes_into_DFAstates. */ 3384 character ch. See group_nodes_into_DFAstates. */
@@ -3565,26 +3408,19 @@ out_free:
3565 } 3408 }
3566 } 3409 }
3567 3410
3568 if (dest_states_malloced)
3569 free (dest_states);
3570
3571 re_node_set_free (&follows); 3411 re_node_set_free (&follows);
3572 for (i = 0; i < ndests; ++i) 3412 for (i = 0; i < ndests; ++i)
3573 re_node_set_free (dests_node + i); 3413 re_node_set_free (dests_node + i);
3574
3575 if (dests_node_malloced)
3576 free (dests_alloc);
3577
3578 return true; 3414 return true;
3579} 3415}
3580 3416
3581/* Group all nodes belonging to STATE into several destinations. 3417/* Group all nodes belonging to STATE into several destinations.
3582 Then for all destinations, set the nodes belonging to the destination 3418 Then for all destinations, set the nodes belonging to the destination
3583 to DESTS_NODE[i] and set the characters accepted by the destination 3419 to DESTS_NODE[i] and set the characters accepted by the destination
3584 to DEST_CH[i]. This function return the number of destinations. */ 3420 to DEST_CH[i]. Return the number of destinations if successful,
3421 -1 on internal error. */
3585 3422
3586static Idx 3423static Idx
3587internal_function
3588group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, 3424group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3589 re_node_set *dests_node, bitset_t *dests_ch) 3425 re_node_set *dests_node, bitset_t *dests_ch)
3590{ 3426{
@@ -3613,18 +3449,15 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3613 } 3449 }
3614 else if (type == OP_PERIOD) 3450 else if (type == OP_PERIOD)
3615 { 3451 {
3616#ifdef RE_ENABLE_I18N
3617 if (dfa->mb_cur_max > 1) 3452 if (dfa->mb_cur_max > 1)
3618 bitset_merge (accepts, dfa->sb_char); 3453 bitset_merge (accepts, dfa->sb_char);
3619 else 3454 else
3620#endif
3621 bitset_set_all (accepts); 3455 bitset_set_all (accepts);
3622 if (!(dfa->syntax & RE_DOT_NEWLINE)) 3456 if (!(dfa->syntax & RE_DOT_NEWLINE))
3623 bitset_clear (accepts, '\n'); 3457 bitset_clear (accepts, '\n');
3624 if (dfa->syntax & RE_DOT_NOT_NULL) 3458 if (dfa->syntax & RE_DOT_NOT_NULL)
3625 bitset_clear (accepts, '\0'); 3459 bitset_clear (accepts, '\0');
3626 } 3460 }
3627#ifdef RE_ENABLE_I18N
3628 else if (type == OP_UTF8_PERIOD) 3461 else if (type == OP_UTF8_PERIOD)
3629 { 3462 {
3630 if (ASCII_CHARS % BITSET_WORD_BITS == 0) 3463 if (ASCII_CHARS % BITSET_WORD_BITS == 0)
@@ -3636,7 +3469,6 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3636 if (dfa->syntax & RE_DOT_NOT_NULL) 3469 if (dfa->syntax & RE_DOT_NOT_NULL)
3637 bitset_clear (accepts, '\0'); 3470 bitset_clear (accepts, '\0');
3638 } 3471 }
3639#endif
3640 else 3472 else
3641 continue; 3473 continue;
3642 3474
@@ -3667,12 +3499,10 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3667 bitset_empty (accepts); 3499 bitset_empty (accepts);
3668 continue; 3500 continue;
3669 } 3501 }
3670#ifdef RE_ENABLE_I18N
3671 if (dfa->mb_cur_max > 1) 3502 if (dfa->mb_cur_max > 1)
3672 for (j = 0; j < BITSET_WORDS; ++j) 3503 for (j = 0; j < BITSET_WORDS; ++j)
3673 any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j])); 3504 any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j]));
3674 else 3505 else
3675#endif
3676 for (j = 0; j < BITSET_WORDS; ++j) 3506 for (j = 0; j < BITSET_WORDS; ++j)
3677 any_set |= (accepts[j] &= dfa->word_char[j]); 3507 any_set |= (accepts[j] &= dfa->word_char[j]);
3678 if (!any_set) 3508 if (!any_set)
@@ -3686,12 +3516,10 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3686 bitset_empty (accepts); 3516 bitset_empty (accepts);
3687 continue; 3517 continue;
3688 } 3518 }
3689#ifdef RE_ENABLE_I18N
3690 if (dfa->mb_cur_max > 1) 3519 if (dfa->mb_cur_max > 1)
3691 for (j = 0; j < BITSET_WORDS; ++j) 3520 for (j = 0; j < BITSET_WORDS; ++j)
3692 any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j])); 3521 any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j]));
3693 else 3522 else
3694#endif
3695 for (j = 0; j < BITSET_WORDS; ++j) 3523 for (j = 0; j < BITSET_WORDS; ++j)
3696 any_set |= (accepts[j] &= ~dfa->word_char[j]); 3524 any_set |= (accepts[j] &= ~dfa->word_char[j]);
3697 if (!any_set) 3525 if (!any_set)
@@ -3735,14 +3563,14 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3735 bitset_copy (dests_ch[ndests], remains); 3563 bitset_copy (dests_ch[ndests], remains);
3736 bitset_copy (dests_ch[j], intersec); 3564 bitset_copy (dests_ch[j], intersec);
3737 err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]); 3565 err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]);
3738 if (BE (err != REG_NOERROR, 0)) 3566 if (__glibc_unlikely (err != REG_NOERROR))
3739 goto error_return; 3567 goto error_return;
3740 ++ndests; 3568 ++ndests;
3741 } 3569 }
3742 3570
3743 /* Put the position in the current group. */ 3571 /* Put the position in the current group. */
3744 ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]); 3572 ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
3745 if (BE (! ok, 0)) 3573 if (__glibc_unlikely (! ok))
3746 goto error_return; 3574 goto error_return;
3747 3575
3748 /* If all characters are consumed, go to next node. */ 3576 /* If all characters are consumed, go to next node. */
@@ -3754,20 +3582,20 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3754 { 3582 {
3755 bitset_copy (dests_ch[ndests], accepts); 3583 bitset_copy (dests_ch[ndests], accepts);
3756 err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]); 3584 err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]);
3757 if (BE (err != REG_NOERROR, 0)) 3585 if (__glibc_unlikely (err != REG_NOERROR))
3758 goto error_return; 3586 goto error_return;
3759 ++ndests; 3587 ++ndests;
3760 bitset_empty (accepts); 3588 bitset_empty (accepts);
3761 } 3589 }
3762 } 3590 }
3591 assume (ndests <= SBC_MAX);
3763 return ndests; 3592 return ndests;
3764 error_return: 3593 error_return:
3765 for (j = 0; j < ndests; ++j) 3594 for (j = 0; j < ndests; ++j)
3766 re_node_set_free (dests_node + j); 3595 re_node_set_free (dests_node + j);
3767 return REG_MISSING; 3596 return -1;
3768} 3597}
3769 3598
3770#ifdef RE_ENABLE_I18N
3771/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts. 3599/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts.
3772 Return the number of the bytes the node accepts. 3600 Return the number of the bytes the node accepts.
3773 STR_IDX is the current index of the input string. 3601 STR_IDX is the current index of the input string.
@@ -3776,8 +3604,11 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3776 one collating element like '.', '[a-z]', opposite to the other nodes 3604 one collating element like '.', '[a-z]', opposite to the other nodes
3777 can only accept one byte. */ 3605 can only accept one byte. */
3778 3606
3607#ifdef _LIBC
3608# include <locale/weight.h>
3609#endif
3610
3779static int 3611static int
3780internal_function
3781check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, 3612check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3782 const re_string_t *input, Idx str_idx) 3613 const re_string_t *input, Idx str_idx)
3783{ 3614{
@@ -3785,10 +3616,10 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3785 int char_len, elem_len; 3616 int char_len, elem_len;
3786 Idx i; 3617 Idx i;
3787 3618
3788 if (BE (node->type == OP_UTF8_PERIOD, 0)) 3619 if (__glibc_unlikely (node->type == OP_UTF8_PERIOD))
3789 { 3620 {
3790 unsigned char c = re_string_byte_at (input, str_idx), d; 3621 unsigned char c = re_string_byte_at (input, str_idx), d;
3791 if (BE (c < 0xc2, 1)) 3622 if (__glibc_likely (c < 0xc2))
3792 return 0; 3623 return 0;
3793 3624
3794 if (str_idx + 2 > input->len) 3625 if (str_idx + 2 > input->len)
@@ -3844,10 +3675,10 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3844 /* FIXME: I don't think this if is needed, as both '\n' 3675 /* FIXME: I don't think this if is needed, as both '\n'
3845 and '\0' are char_len == 1. */ 3676 and '\0' are char_len == 1. */
3846 /* '.' accepts any one character except the following two cases. */ 3677 /* '.' accepts any one character except the following two cases. */
3847 if ((!(dfa->syntax & RE_DOT_NEWLINE) && 3678 if ((!(dfa->syntax & RE_DOT_NEWLINE)
3848 re_string_byte_at (input, str_idx) == '\n') || 3679 && re_string_byte_at (input, str_idx) == '\n')
3849 ((dfa->syntax & RE_DOT_NOT_NULL) && 3680 || ((dfa->syntax & RE_DOT_NOT_NULL)
3850 re_string_byte_at (input, str_idx) == '\0')) 3681 && re_string_byte_at (input, str_idx) == '\0'))
3851 return 0; 3682 return 0;
3852 return char_len; 3683 return char_len;
3853 } 3684 }
@@ -3859,12 +3690,12 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3859 if (node->type == COMPLEX_BRACKET) 3690 if (node->type == COMPLEX_BRACKET)
3860 { 3691 {
3861 const re_charset_t *cset = node->opr.mbcset; 3692 const re_charset_t *cset = node->opr.mbcset;
3862# ifdef _LIBC 3693#ifdef _LIBC
3863 const unsigned char *pin 3694 const unsigned char *pin
3864 = ((const unsigned char *) re_string_get_buffer (input) + str_idx); 3695 = ((const unsigned char *) re_string_get_buffer (input) + str_idx);
3865 Idx j; 3696 Idx j;
3866 uint32_t nrules; 3697 uint32_t nrules;
3867# endif /* _LIBC */ 3698#endif
3868 int match_len = 0; 3699 int match_len = 0;
3869 wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars) 3700 wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars)
3870 ? re_string_wchar_at (input, str_idx) : 0); 3701 ? re_string_wchar_at (input, str_idx) : 0);
@@ -3887,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3887 } 3718 }
3888 } 3719 }
3889 3720
3890# ifdef _LIBC 3721#ifdef _LIBC
3891 nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 3722 nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
3892 if (nrules != 0) 3723 if (nrules != 0)
3893 { 3724 {
@@ -3895,8 +3726,6 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3895 const int32_t *table, *indirect; 3726 const int32_t *table, *indirect;
3896 const unsigned char *weights, *extra; 3727 const unsigned char *weights, *extra;
3897 const char *collseqwc; 3728 const char *collseqwc;
3898 /* This #include defines a local function! */
3899# include <locale/weight.h>
3900 3729
3901 /* match with collating_symbol? */ 3730 /* match with collating_symbol? */
3902 if (cset->ncoll_syms) 3731 if (cset->ncoll_syms)
@@ -3953,35 +3782,32 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3953 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB); 3782 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
3954 indirect = (const int32_t *) 3783 indirect = (const int32_t *)
3955 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB); 3784 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
3956 int32_t idx = findidx (&cp, elem_len); 3785 int32_t idx = findidx (table, indirect, extra, &cp, elem_len);
3786 int32_t rule = idx >> 24;
3787 idx &= 0xffffff;
3957 if (idx > 0) 3788 if (idx > 0)
3958 for (i = 0; i < cset->nequiv_classes; ++i) 3789 {
3959 { 3790 size_t weight_len = weights[idx];
3960 int32_t equiv_class_idx = cset->equiv_classes[i]; 3791 for (i = 0; i < cset->nequiv_classes; ++i)
3961 size_t weight_len = weights[idx & 0xffffff]; 3792 {
3962 if (weight_len == weights[equiv_class_idx & 0xffffff] 3793 int32_t equiv_class_idx = cset->equiv_classes[i];
3963 && (idx >> 24) == (equiv_class_idx >> 24)) 3794 int32_t equiv_class_rule = equiv_class_idx >> 24;
3964 { 3795 equiv_class_idx &= 0xffffff;
3965 Idx cnt = 0; 3796 if (weights[equiv_class_idx] == weight_len
3966 3797 && equiv_class_rule == rule
3967 idx &= 0xffffff; 3798 && memcmp (weights + idx + 1,
3968 equiv_class_idx &= 0xffffff; 3799 weights + equiv_class_idx + 1,
3969 3800 weight_len) == 0)
3970 while (cnt <= weight_len 3801 {
3971 && (weights[equiv_class_idx + 1 + cnt] 3802 match_len = elem_len;
3972 == weights[idx + 1 + cnt])) 3803 goto check_node_accept_bytes_match;
3973 ++cnt; 3804 }
3974 if (cnt > weight_len) 3805 }
3975 { 3806 }
3976 match_len = elem_len;
3977 goto check_node_accept_bytes_match;
3978 }
3979 }
3980 }
3981 } 3807 }
3982 } 3808 }
3983 else 3809 else
3984# endif /* _LIBC */ 3810#endif /* _LIBC */
3985 { 3811 {
3986 /* match with range expression? */ 3812 /* match with range expression? */
3987 for (i = 0; i < cset->nranges; ++i) 3813 for (i = 0; i < cset->nranges; ++i)
@@ -4007,9 +3833,8 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
4007 return 0; 3833 return 0;
4008} 3834}
4009 3835
4010# ifdef _LIBC 3836#ifdef _LIBC
4011static unsigned int 3837static unsigned int
4012internal_function
4013find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) 3838find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
4014{ 3839{
4015 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 3840 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
@@ -4066,14 +3891,12 @@ find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
4066 return UINT_MAX; 3891 return UINT_MAX;
4067 } 3892 }
4068} 3893}
4069# endif /* _LIBC */ 3894#endif /* _LIBC */
4070#endif /* RE_ENABLE_I18N */
4071 3895
4072/* Check whether the node accepts the byte which is IDX-th 3896/* Check whether the node accepts the byte which is IDX-th
4073 byte of the INPUT. */ 3897 byte of the INPUT. */
4074 3898
4075static bool 3899static bool
4076internal_function
4077check_node_accept (const re_match_context_t *mctx, const re_token_t *node, 3900check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
4078 Idx idx) 3901 Idx idx)
4079{ 3902{
@@ -4091,12 +3914,10 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
4091 return false; 3914 return false;
4092 break; 3915 break;
4093 3916
4094#ifdef RE_ENABLE_I18N
4095 case OP_UTF8_PERIOD: 3917 case OP_UTF8_PERIOD:
4096 if (ch >= ASCII_CHARS) 3918 if (ch >= ASCII_CHARS)
4097 return false; 3919 return false;
4098 /* FALLTHROUGH */ 3920 FALLTHROUGH;
4099#endif
4100 case OP_PERIOD: 3921 case OP_PERIOD:
4101 if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) 3922 if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
4102 || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL))) 3923 || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
@@ -4123,22 +3944,22 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
4123/* Extend the buffers, if the buffers have run out. */ 3944/* Extend the buffers, if the buffers have run out. */
4124 3945
4125static reg_errcode_t 3946static reg_errcode_t
4126internal_function __attribute_warn_unused_result__ 3947__attribute_warn_unused_result__
4127extend_buffers (re_match_context_t *mctx, int min_len) 3948extend_buffers (re_match_context_t *mctx, int min_len)
4128{ 3949{
4129 reg_errcode_t ret; 3950 reg_errcode_t ret;
4130 re_string_t *pstr = &mctx->input; 3951 re_string_t *pstr = &mctx->input;
4131 3952
4132 /* Avoid overflow. */ 3953 /* Avoid overflow. */
4133 if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2 3954 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2
4134 <= pstr->bufs_len, 0)) 3955 <= pstr->bufs_len))
4135 return REG_ESPACE; 3956 return REG_ESPACE;
4136 3957
4137 /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ 3958 /* Double the lengths of the buffers, but allocate at least MIN_LEN. */
4138 ret = re_string_realloc_buffers (pstr, 3959 ret = re_string_realloc_buffers (pstr,
4139 MAX (min_len, 3960 MAX (min_len,
4140 MIN (pstr->len, pstr->bufs_len * 2))); 3961 MIN (pstr->len, pstr->bufs_len * 2)));
4141 if (BE (ret != REG_NOERROR, 0)) 3962 if (__glibc_unlikely (ret != REG_NOERROR))
4142 return ret; 3963 return ret;
4143 3964
4144 if (mctx->state_log != NULL) 3965 if (mctx->state_log != NULL)
@@ -4149,7 +3970,7 @@ extend_buffers (re_match_context_t *mctx, int min_len)
4149 does not have the right size. */ 3970 does not have the right size. */
4150 re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, 3971 re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
4151 pstr->bufs_len + 1); 3972 pstr->bufs_len + 1);
4152 if (BE (new_array == NULL, 0)) 3973 if (__glibc_unlikely (new_array == NULL))
4153 return REG_ESPACE; 3974 return REG_ESPACE;
4154 mctx->state_log = new_array; 3975 mctx->state_log = new_array;
4155 } 3976 }
@@ -4157,24 +3978,20 @@ extend_buffers (re_match_context_t *mctx, int min_len)
4157 /* Then reconstruct the buffers. */ 3978 /* Then reconstruct the buffers. */
4158 if (pstr->icase) 3979 if (pstr->icase)
4159 { 3980 {
4160#ifdef RE_ENABLE_I18N
4161 if (pstr->mb_cur_max > 1) 3981 if (pstr->mb_cur_max > 1)
4162 { 3982 {
4163 ret = build_wcs_upper_buffer (pstr); 3983 ret = build_wcs_upper_buffer (pstr);
4164 if (BE (ret != REG_NOERROR, 0)) 3984 if (__glibc_unlikely (ret != REG_NOERROR))
4165 return ret; 3985 return ret;
4166 } 3986 }
4167 else 3987 else
4168#endif /* RE_ENABLE_I18N */
4169 build_upper_buffer (pstr); 3988 build_upper_buffer (pstr);
4170 } 3989 }
4171 else 3990 else
4172 { 3991 {
4173#ifdef RE_ENABLE_I18N
4174 if (pstr->mb_cur_max > 1) 3992 if (pstr->mb_cur_max > 1)
4175 build_wcs_buffer (pstr); 3993 build_wcs_buffer (pstr);
4176 else 3994 else
4177#endif /* RE_ENABLE_I18N */
4178 { 3995 {
4179 if (pstr->trans != NULL) 3996 if (pstr->trans != NULL)
4180 re_string_translate_buffer (pstr); 3997 re_string_translate_buffer (pstr);
@@ -4189,23 +4006,23 @@ extend_buffers (re_match_context_t *mctx, int min_len)
4189/* Initialize MCTX. */ 4006/* Initialize MCTX. */
4190 4007
4191static reg_errcode_t 4008static reg_errcode_t
4192internal_function __attribute_warn_unused_result__ 4009__attribute_warn_unused_result__
4193match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) 4010match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
4194{ 4011{
4195 mctx->eflags = eflags; 4012 mctx->eflags = eflags;
4196 mctx->match_last = REG_MISSING; 4013 mctx->match_last = -1;
4197 if (n > 0) 4014 if (n > 0)
4198 { 4015 {
4199 /* Avoid overflow. */ 4016 /* Avoid overflow. */
4200 size_t max_object_size = 4017 size_t max_object_size =
4201 MAX (sizeof (struct re_backref_cache_entry), 4018 MAX (sizeof (struct re_backref_cache_entry),
4202 sizeof (re_sub_match_top_t *)); 4019 sizeof (re_sub_match_top_t *));
4203 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0)) 4020 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n))
4204 return REG_ESPACE; 4021 return REG_ESPACE;
4205 4022
4206 mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); 4023 mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
4207 mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); 4024 mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
4208 if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) 4025 if (__glibc_unlikely (mctx->bkref_ents == NULL || mctx->sub_tops == NULL))
4209 return REG_ESPACE; 4026 return REG_ESPACE;
4210 } 4027 }
4211 /* Already zero-ed by the caller. 4028 /* Already zero-ed by the caller.
@@ -4224,7 +4041,6 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
4224 of the input, or changes the input string. */ 4041 of the input, or changes the input string. */
4225 4042
4226static void 4043static void
4227internal_function
4228match_ctx_clean (re_match_context_t *mctx) 4044match_ctx_clean (re_match_context_t *mctx)
4229{ 4045{
4230 Idx st_idx; 4046 Idx st_idx;
@@ -4244,7 +4060,7 @@ match_ctx_clean (re_match_context_t *mctx)
4244 re_free (top->path->array); 4060 re_free (top->path->array);
4245 re_free (top->path); 4061 re_free (top->path);
4246 } 4062 }
4247 free (top); 4063 re_free (top);
4248 } 4064 }
4249 4065
4250 mctx->nsub_tops = 0; 4066 mctx->nsub_tops = 0;
@@ -4254,7 +4070,6 @@ match_ctx_clean (re_match_context_t *mctx)
4254/* Free all the memory associated with MCTX. */ 4070/* Free all the memory associated with MCTX. */
4255 4071
4256static void 4072static void
4257internal_function
4258match_ctx_free (re_match_context_t *mctx) 4073match_ctx_free (re_match_context_t *mctx)
4259{ 4074{
4260 /* First, free all the memory associated with MCTX->SUB_TOPS. */ 4075 /* First, free all the memory associated with MCTX->SUB_TOPS. */
@@ -4269,7 +4084,7 @@ match_ctx_free (re_match_context_t *mctx)
4269*/ 4084*/
4270 4085
4271static reg_errcode_t 4086static reg_errcode_t
4272internal_function __attribute_warn_unused_result__ 4087__attribute_warn_unused_result__
4273match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, 4088match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
4274 Idx to) 4089 Idx to)
4275{ 4090{
@@ -4278,7 +4093,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
4278 struct re_backref_cache_entry* new_entry; 4093 struct re_backref_cache_entry* new_entry;
4279 new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, 4094 new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
4280 mctx->abkref_ents * 2); 4095 mctx->abkref_ents * 2);
4281 if (BE (new_entry == NULL, 0)) 4096 if (__glibc_unlikely (new_entry == NULL))
4282 { 4097 {
4283 re_free (mctx->bkref_ents); 4098 re_free (mctx->bkref_ents);
4284 return REG_ESPACE; 4099 return REG_ESPACE;
@@ -4314,11 +4129,10 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
4314 return REG_NOERROR; 4129 return REG_NOERROR;
4315} 4130}
4316 4131
4317/* Return the first entry with the same str_idx, or REG_MISSING if none is 4132/* Return the first entry with the same str_idx, or -1 if none is
4318 found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */ 4133 found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */
4319 4134
4320static Idx 4135static Idx
4321internal_function
4322search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx) 4136search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
4323{ 4137{
4324 Idx left, right, mid, last; 4138 Idx left, right, mid, last;
@@ -4334,33 +4148,31 @@ search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
4334 if (left < last && mctx->bkref_ents[left].str_idx == str_idx) 4148 if (left < last && mctx->bkref_ents[left].str_idx == str_idx)
4335 return left; 4149 return left;
4336 else 4150 else
4337 return REG_MISSING; 4151 return -1;
4338} 4152}
4339 4153
4340/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches 4154/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches
4341 at STR_IDX. */ 4155 at STR_IDX. */
4342 4156
4343static reg_errcode_t 4157static reg_errcode_t
4344internal_function __attribute_warn_unused_result__ 4158__attribute_warn_unused_result__
4345match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) 4159match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
4346{ 4160{
4347#ifdef DEBUG 4161 DEBUG_ASSERT (mctx->sub_tops != NULL);
4348 assert (mctx->sub_tops != NULL); 4162 DEBUG_ASSERT (mctx->asub_tops > 0);
4349 assert (mctx->asub_tops > 0); 4163 if (__glibc_unlikely (mctx->nsub_tops == mctx->asub_tops))
4350#endif
4351 if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
4352 { 4164 {
4353 Idx new_asub_tops = mctx->asub_tops * 2; 4165 Idx new_asub_tops = mctx->asub_tops * 2;
4354 re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, 4166 re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
4355 re_sub_match_top_t *, 4167 re_sub_match_top_t *,
4356 new_asub_tops); 4168 new_asub_tops);
4357 if (BE (new_array == NULL, 0)) 4169 if (__glibc_unlikely (new_array == NULL))
4358 return REG_ESPACE; 4170 return REG_ESPACE;
4359 mctx->sub_tops = new_array; 4171 mctx->sub_tops = new_array;
4360 mctx->asub_tops = new_asub_tops; 4172 mctx->asub_tops = new_asub_tops;
4361 } 4173 }
4362 mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); 4174 mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
4363 if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0)) 4175 if (__glibc_unlikely (mctx->sub_tops[mctx->nsub_tops] == NULL))
4364 return REG_ESPACE; 4176 return REG_ESPACE;
4365 mctx->sub_tops[mctx->nsub_tops]->node = node; 4177 mctx->sub_tops[mctx->nsub_tops]->node = node;
4366 mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx; 4178 mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx;
@@ -4368,26 +4180,26 @@ match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
4368} 4180}
4369 4181
4370/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches 4182/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches
4371 at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP. */ 4183 at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP.
4184 Return the new entry if successful, NULL if memory is exhausted. */
4372 4185
4373static re_sub_match_last_t * 4186static re_sub_match_last_t *
4374internal_function
4375match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) 4187match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
4376{ 4188{
4377 re_sub_match_last_t *new_entry; 4189 re_sub_match_last_t *new_entry;
4378 if (BE (subtop->nlasts == subtop->alasts, 0)) 4190 if (__glibc_unlikely (subtop->nlasts == subtop->alasts))
4379 { 4191 {
4380 Idx new_alasts = 2 * subtop->alasts + 1; 4192 Idx new_alasts = 2 * subtop->alasts + 1;
4381 re_sub_match_last_t **new_array = re_realloc (subtop->lasts, 4193 re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
4382 re_sub_match_last_t *, 4194 re_sub_match_last_t *,
4383 new_alasts); 4195 new_alasts);
4384 if (BE (new_array == NULL, 0)) 4196 if (__glibc_unlikely (new_array == NULL))
4385 return NULL; 4197 return NULL;
4386 subtop->lasts = new_array; 4198 subtop->lasts = new_array;
4387 subtop->alasts = new_alasts; 4199 subtop->alasts = new_alasts;
4388 } 4200 }
4389 new_entry = calloc (1, sizeof (re_sub_match_last_t)); 4201 new_entry = calloc (1, sizeof (re_sub_match_last_t));
4390 if (BE (new_entry != NULL, 1)) 4202 if (__glibc_likely (new_entry != NULL))
4391 { 4203 {
4392 subtop->lasts[subtop->nlasts] = new_entry; 4204 subtop->lasts[subtop->nlasts] = new_entry;
4393 new_entry->node = node; 4205 new_entry->node = node;
@@ -4398,7 +4210,6 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
4398} 4210}
4399 4211
4400static void 4212static void
4401internal_function
4402sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, 4213sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
4403 re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx) 4214 re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
4404{ 4215{
diff --git a/gl/safe-read.c b/gl/safe-read.c
deleted file mode 100644
index 6a48c0c..0000000
--- a/gl/safe-read.c
+++ /dev/null
@@ -1,77 +0,0 @@
1/* An interface to read and write that retries after interrupts.
2
3 Copyright (C) 1993-1994, 1998, 2002-2006, 2009-2013 Free Software
4 Foundation, Inc.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21/* Specification. */
22#ifdef SAFE_WRITE
23# include "safe-write.h"
24#else
25# include "safe-read.h"
26#endif
27
28/* Get ssize_t. */
29#include <sys/types.h>
30#include <unistd.h>
31
32#include <errno.h>
33
34#ifdef EINTR
35# define IS_EINTR(x) ((x) == EINTR)
36#else
37# define IS_EINTR(x) 0
38#endif
39
40#include <limits.h>
41
42#ifdef SAFE_WRITE
43# define safe_rw safe_write
44# define rw write
45#else
46# define safe_rw safe_read
47# define rw read
48# undef const
49# define const /* empty */
50#endif
51
52/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if
53 interrupted. Return the actual number of bytes read(written), zero for EOF,
54 or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */
55size_t
56safe_rw (int fd, void const *buf, size_t count)
57{
58 /* Work around a bug in Tru64 5.1. Attempting to read more than
59 INT_MAX bytes fails with errno == EINVAL. See
60 <http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00010.html>.
61 When decreasing COUNT, keep it block-aligned. */
62 enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
63
64 for (;;)
65 {
66 ssize_t result = rw (fd, buf, count);
67
68 if (0 <= result)
69 return result;
70 else if (IS_EINTR (errno))
71 continue;
72 else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
73 count = BUGGY_READ_MAXIMUM;
74 else
75 return result;
76 }
77}
diff --git a/gl/safe-read.h b/gl/safe-read.h
deleted file mode 100644
index 992b7a6..0000000
--- a/gl/safe-read.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/* An interface to read() that retries after interrupts.
2 Copyright (C) 2002, 2006, 2009-2013 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* Some system calls may be interrupted and fail with errno = EINTR in the
18 following situations:
19 - The process is stopped and restarted (signal SIGSTOP and SIGCONT, user
20 types Ctrl-Z) on some platforms: Mac OS X.
21 - The process receives a signal for which a signal handler was installed
22 with sigaction() with an sa_flags field that does not contain
23 SA_RESTART.
24 - The process receives a signal for which a signal handler was installed
25 with signal() and for which no call to siginterrupt(sig,0) was done,
26 on some platforms: AIX, HP-UX, IRIX, OSF/1, Solaris.
27
28 This module provides a wrapper around read() that handles EINTR. */
29
30#include <stddef.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36
37#define SAFE_READ_ERROR ((size_t) -1)
38
39/* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted.
40 Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR
41 upon error. */
42extern size_t safe_read (int fd, void *buf, size_t count);
43
44
45#ifdef __cplusplus
46}
47#endif
diff --git a/gl/setenv.c b/gl/setenv.c
index 995a0f2..f0b8899 100644
--- a/gl/setenv.c
+++ b/gl/setenv.c
@@ -1,18 +1,18 @@
1/* Copyright (C) 1992, 1995-2003, 2005-2013 Free Software Foundation, Inc. 1/* Copyright (C) 1992, 1995-2003, 2005-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library. 2 This file is part of the GNU C Library.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation; either version 2.1 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#if !_LIBC 17#if !_LIBC
18/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc 18/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
@@ -72,7 +72,7 @@ __libc_lock_define_initialized (static, envlock)
72 values are from a small set. Outside glibc this will eat up all 72 values are from a small set. Outside glibc this will eat up all
73 memory after a while. */ 73 memory after a while. */
74#if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \ 74#if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \
75 && defined __GNUC__) 75 && (defined __GNUC__ || defined __clang__))
76# define USE_TSEARCH 1 76# define USE_TSEARCH 1
77# include <search.h> 77# include <search.h>
78typedef int (*compar_fn_t) (const void *, const void *); 78typedef int (*compar_fn_t) (const void *, const void *);
diff --git a/gl/setlocale-lock.c b/gl/setlocale-lock.c
new file mode 100644
index 0000000..b70ba09
--- /dev/null
+++ b/gl/setlocale-lock.c
@@ -0,0 +1,150 @@
1/* Return the internal lock used by setlocale_null_r.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019. */
18
19#include <config.h>
20
21/* When it is known that the gl_get_setlocale_null_lock function is defined
22 by a dependency library, it should not be defined here. */
23#if OMIT_SETLOCALE_LOCK
24
25/* This declaration is solely to ensure that after preprocessing
26 this file is never empty. */
27typedef int dummy;
28
29#else
30
31/* This file defines the internal lock used by setlocale_null_r.
32 It is a separate compilation unit, so that only one copy of it is
33 present when linking statically. */
34
35/* Prohibit renaming this symbol. */
36# undef gl_get_setlocale_null_lock
37
38/* Macro for exporting a symbol (function, not variable) defined in this file,
39 when compiled into a shared library. */
40# ifndef DLL_EXPORTED
41# if HAVE_VISIBILITY
42 /* Override the effect of the compiler option '-fvisibility=hidden'. */
43# define DLL_EXPORTED __attribute__((__visibility__("default")))
44# elif defined _WIN32 || defined __CYGWIN__
45# define DLL_EXPORTED __declspec(dllexport)
46# else
47# define DLL_EXPORTED
48# endif
49# endif
50
51# if defined _WIN32 && !defined __CYGWIN__
52
53# define WIN32_LEAN_AND_MEAN /* avoid including junk */
54# include <windows.h>
55
56# include "windows-initguard.h"
57
58/* The return type is a 'CRITICAL_SECTION *', not a 'glwthread_mutex_t *',
59 because the latter is not guaranteed to be a stable ABI in the future. */
60
61/* Make sure the function gets exported from DLLs. */
62DLL_EXPORTED CRITICAL_SECTION *gl_get_setlocale_null_lock (void);
63
64static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT;
65static CRITICAL_SECTION lock;
66
67/* Returns the internal lock used by setlocale_null_r. */
68CRITICAL_SECTION *
69gl_get_setlocale_null_lock (void)
70{
71 if (!guard.done)
72 {
73 if (InterlockedIncrement (&guard.started) == 0)
74 {
75 /* This thread is the first one to need the lock. Initialize it. */
76 InitializeCriticalSection (&lock);
77 guard.done = 1;
78 }
79 else
80 {
81 /* Don't let guard.started grow and wrap around. */
82 InterlockedDecrement (&guard.started);
83 /* Yield the CPU while waiting for another thread to finish
84 initializing this mutex. */
85 while (!guard.done)
86 Sleep (0);
87 }
88 }
89 return &lock;
90}
91
92# elif HAVE_PTHREAD_API
93
94# include <pthread.h>
95
96static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
97
98/* Make sure the function gets exported from shared libraries. */
99DLL_EXPORTED pthread_mutex_t *gl_get_setlocale_null_lock (void);
100
101/* Returns the internal lock used by setlocale_null_r. */
102pthread_mutex_t *
103gl_get_setlocale_null_lock (void)
104{
105 return &mutex;
106}
107
108# elif HAVE_THREADS_H
109
110# include <threads.h>
111# include <stdlib.h>
112
113static int volatile init_needed = 1;
114static once_flag init_once = ONCE_FLAG_INIT;
115static mtx_t mutex;
116
117static void
118atomic_init (void)
119{
120 if (mtx_init (&mutex, mtx_plain) != thrd_success)
121 abort ();
122 init_needed = 0;
123}
124
125/* Make sure the function gets exported from shared libraries. */
126DLL_EXPORTED mtx_t *gl_get_setlocale_null_lock (void);
127
128/* Returns the internal lock used by setlocale_null_r. */
129mtx_t *
130gl_get_setlocale_null_lock (void)
131{
132 if (init_needed)
133 call_once (&init_once, atomic_init);
134 return &mutex;
135}
136
137# endif
138
139# if (defined _WIN32 || defined __CYGWIN__) && !defined _MSC_VER
140/* Make sure the '__declspec(dllimport)' in setlocale_null.c does not cause
141 a link failure when no DLLs are involved. */
142# if defined _WIN64 || defined _LP64
143# define IMP(x) __imp_##x
144# else
145# define IMP(x) _imp__##x
146# endif
147void * IMP(gl_get_setlocale_null_lock) = &gl_get_setlocale_null_lock;
148# endif
149
150#endif
diff --git a/gl/setlocale_null.c b/gl/setlocale_null.c
new file mode 100644
index 0000000..6ac563d
--- /dev/null
+++ b/gl/setlocale_null.c
@@ -0,0 +1,411 @@
1/* Query the name of the current global locale.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019. */
18
19#include <config.h>
20
21/* Specification. */
22#include "setlocale_null.h"
23
24#include <errno.h>
25#include <locale.h>
26#include <stdlib.h>
27#include <string.h>
28#if defined _WIN32 && !defined __CYGWIN__
29# include <wchar.h>
30#endif
31
32#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE)
33# if defined _WIN32 && !defined __CYGWIN__
34
35# define WIN32_LEAN_AND_MEAN /* avoid including junk */
36# include <windows.h>
37
38# elif HAVE_PTHREAD_API
39
40# include <pthread.h>
41# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS
42# include <threads.h>
43# pragma weak thrd_exit
44# define c11_threads_in_use() (thrd_exit != NULL)
45# else
46# define c11_threads_in_use() 0
47# endif
48
49# elif HAVE_THREADS_H
50
51# include <threads.h>
52
53# endif
54#endif
55
56/* Use the system's setlocale() function, not the gnulib override, here. */
57#undef setlocale
58
59static const char *
60setlocale_null_androidfix (int category)
61{
62 const char *result = setlocale (category, NULL);
63
64#ifdef __ANDROID__
65 if (result == NULL)
66 switch (category)
67 {
68 case LC_CTYPE:
69 case LC_NUMERIC:
70 case LC_TIME:
71 case LC_COLLATE:
72 case LC_MONETARY:
73 case LC_MESSAGES:
74 case LC_ALL:
75 case LC_PAPER:
76 case LC_NAME:
77 case LC_ADDRESS:
78 case LC_TELEPHONE:
79 case LC_MEASUREMENT:
80 result = "C";
81 break;
82 default:
83 break;
84 }
85#endif
86
87 return result;
88}
89
90static int
91setlocale_null_unlocked (int category, char *buf, size_t bufsize)
92{
93#if defined _WIN32 && !defined __CYGWIN__ && defined _MSC_VER
94 /* On native Windows, nowadays, the setlocale() implementation is based
95 on _wsetlocale() and uses malloc() for the result. We are better off
96 using _wsetlocale() directly. */
97 const wchar_t *result = _wsetlocale (category, NULL);
98
99 if (result == NULL)
100 {
101 /* CATEGORY is invalid. */
102 if (bufsize > 0)
103 /* Return an empty string in BUF.
104 This is a convenience for callers that don't want to write explicit
105 code for handling EINVAL. */
106 buf[0] = '\0';
107 return EINVAL;
108 }
109 else
110 {
111 size_t length = wcslen (result);
112 if (length < bufsize)
113 {
114 size_t i;
115
116 /* Convert wchar_t[] -> char[], assuming plain ASCII. */
117 for (i = 0; i <= length; i++)
118 buf[i] = result[i];
119
120 return 0;
121 }
122 else
123 {
124 if (bufsize > 0)
125 {
126 /* Return a truncated result in BUF.
127 This is a convenience for callers that don't want to write
128 explicit code for handling ERANGE. */
129 size_t i;
130
131 /* Convert wchar_t[] -> char[], assuming plain ASCII. */
132 for (i = 0; i < bufsize; i++)
133 buf[i] = result[i];
134 buf[bufsize - 1] = '\0';
135 }
136 return ERANGE;
137 }
138 }
139#else
140 const char *result = setlocale_null_androidfix (category);
141
142 if (result == NULL)
143 {
144 /* CATEGORY is invalid. */
145 if (bufsize > 0)
146 /* Return an empty string in BUF.
147 This is a convenience for callers that don't want to write explicit
148 code for handling EINVAL. */
149 buf[0] = '\0';
150 return EINVAL;
151 }
152 else
153 {
154 size_t length = strlen (result);
155 if (length < bufsize)
156 {
157 memcpy (buf, result, length + 1);
158 return 0;
159 }
160 else
161 {
162 if (bufsize > 0)
163 {
164 /* Return a truncated result in BUF.
165 This is a convenience for callers that don't want to write
166 explicit code for handling ERANGE. */
167 memcpy (buf, result, bufsize - 1);
168 buf[bufsize - 1] = '\0';
169 }
170 return ERANGE;
171 }
172 }
173#endif
174}
175
176#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */
177
178/* Use a lock, so that no two threads can invoke setlocale_null_unlocked
179 at the same time. */
180
181/* Prohibit renaming this symbol. */
182# undef gl_get_setlocale_null_lock
183
184# if defined _WIN32 && !defined __CYGWIN__
185
186extern __declspec(dllimport) CRITICAL_SECTION *gl_get_setlocale_null_lock (void);
187
188static int
189setlocale_null_with_lock (int category, char *buf, size_t bufsize)
190{
191 CRITICAL_SECTION *lock = gl_get_setlocale_null_lock ();
192 int ret;
193
194 EnterCriticalSection (lock);
195 ret = setlocale_null_unlocked (category, buf, bufsize);
196 LeaveCriticalSection (lock);
197
198 return ret;
199}
200
201# elif HAVE_PTHREAD_API /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */
202
203extern
204# if defined _WIN32 || defined __CYGWIN__
205 __declspec(dllimport)
206# endif
207 pthread_mutex_t *gl_get_setlocale_null_lock (void);
208
209# if HAVE_WEAK_SYMBOLS /* musl libc, FreeBSD, NetBSD, OpenBSD, Haiku */
210
211 /* Avoid the need to link with '-lpthread'. */
212# pragma weak pthread_mutex_lock
213# pragma weak pthread_mutex_unlock
214
215 /* Determine whether libpthread is in use. */
216# pragma weak pthread_mutexattr_gettype
217 /* See the comments in lock.h. */
218# define pthread_in_use() \
219 (pthread_mutexattr_gettype != NULL || c11_threads_in_use ())
220
221# else
222# define pthread_in_use() 1
223# endif
224
225static int
226setlocale_null_with_lock (int category, char *buf, size_t bufsize)
227{
228 if (pthread_in_use())
229 {
230 pthread_mutex_t *lock = gl_get_setlocale_null_lock ();
231 int ret;
232
233 if (pthread_mutex_lock (lock))
234 abort ();
235 ret = setlocale_null_unlocked (category, buf, bufsize);
236 if (pthread_mutex_unlock (lock))
237 abort ();
238
239 return ret;
240 }
241 else
242 return setlocale_null_unlocked (category, buf, bufsize);
243}
244
245# elif HAVE_THREADS_H
246
247extern mtx_t *gl_get_setlocale_null_lock (void);
248
249static int
250setlocale_null_with_lock (int category, char *buf, size_t bufsize)
251{
252 mtx_t *lock = gl_get_setlocale_null_lock ();
253 int ret;
254
255 if (mtx_lock (lock) != thrd_success)
256 abort ();
257 ret = setlocale_null_unlocked (category, buf, bufsize);
258 if (mtx_unlock (lock) != thrd_success)
259 abort ();
260
261 return ret;
262}
263
264# endif
265
266#endif
267
268int
269setlocale_null_r (int category, char *buf, size_t bufsize)
270{
271#if SETLOCALE_NULL_ALL_MTSAFE
272# if SETLOCALE_NULL_ONE_MTSAFE
273
274 return setlocale_null_unlocked (category, buf, bufsize);
275
276# else
277
278 if (category == LC_ALL)
279 return setlocale_null_unlocked (category, buf, bufsize);
280 else
281 return setlocale_null_with_lock (category, buf, bufsize);
282
283# endif
284#else
285# if SETLOCALE_NULL_ONE_MTSAFE
286
287 if (category == LC_ALL)
288 return setlocale_null_with_lock (category, buf, bufsize);
289 else
290 return setlocale_null_unlocked (category, buf, bufsize);
291
292# else
293
294 return setlocale_null_with_lock (category, buf, bufsize);
295
296# endif
297#endif
298}
299
300const char *
301setlocale_null (int category)
302{
303#if SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE
304 return setlocale_null_androidfix (category);
305#else
306
307 /* This call must be multithread-safe. To achieve this without using
308 thread-local storage:
309 1. We use a specific static buffer for each possible CATEGORY
310 argument. So that different threads can call setlocale_mtsafe
311 with different CATEGORY arguments, without interfering.
312 2. We use a simple strcpy or memcpy to fill this static buffer.
313 Filling it through, for example, strcpy + strcat would not be
314 guaranteed to leave the buffer's contents intact if another thread
315 is currently accessing it. If necessary, the contents is first
316 assembled in a stack-allocated buffer. */
317 if (category == LC_ALL)
318 {
319# if SETLOCALE_NULL_ALL_MTSAFE
320 return setlocale_null_androidfix (LC_ALL);
321# else
322 char buf[SETLOCALE_NULL_ALL_MAX];
323 static char resultbuf[SETLOCALE_NULL_ALL_MAX];
324
325 if (setlocale_null_r (LC_ALL, buf, sizeof (buf)))
326 return "C";
327 strcpy (resultbuf, buf);
328 return resultbuf;
329# endif
330 }
331 else
332 {
333# if SETLOCALE_NULL_ONE_MTSAFE
334 return setlocale_null_androidfix (category);
335# else
336 enum
337 {
338 LC_CTYPE_INDEX,
339 LC_NUMERIC_INDEX,
340 LC_TIME_INDEX,
341 LC_COLLATE_INDEX,
342 LC_MONETARY_INDEX,
343 LC_MESSAGES_INDEX,
344# ifdef LC_PAPER
345 LC_PAPER_INDEX,
346# endif
347# ifdef LC_NAME
348 LC_NAME_INDEX,
349# endif
350# ifdef LC_ADDRESS
351 LC_ADDRESS_INDEX,
352# endif
353# ifdef LC_TELEPHONE
354 LC_TELEPHONE_INDEX,
355# endif
356# ifdef LC_MEASUREMENT
357 LC_MEASUREMENT_INDEX,
358# endif
359# ifdef LC_IDENTIFICATION
360 LC_IDENTIFICATION_INDEX,
361# endif
362 LC_INDICES_COUNT
363 }
364 i;
365 char buf[SETLOCALE_NULL_MAX];
366 static char resultbuf[LC_INDICES_COUNT][SETLOCALE_NULL_MAX];
367 int err;
368
369 err = setlocale_null_r (category, buf, sizeof (buf));
370 if (err == EINVAL)
371 return NULL;
372 if (err)
373 return "C";
374
375 switch (category)
376 {
377 case LC_CTYPE: i = LC_CTYPE_INDEX; break;
378 case LC_NUMERIC: i = LC_NUMERIC_INDEX; break;
379 case LC_TIME: i = LC_TIME_INDEX; break;
380 case LC_COLLATE: i = LC_COLLATE_INDEX; break;
381 case LC_MONETARY: i = LC_MONETARY_INDEX; break;
382 case LC_MESSAGES: i = LC_MESSAGES_INDEX; break;
383# ifdef LC_PAPER
384 case LC_PAPER: i = LC_PAPER_INDEX; break;
385# endif
386# ifdef LC_NAME
387 case LC_NAME: i = LC_NAME_INDEX; break;
388# endif
389# ifdef LC_ADDRESS
390 case LC_ADDRESS: i = LC_ADDRESS_INDEX; break;
391# endif
392# ifdef LC_TELEPHONE
393 case LC_TELEPHONE: i = LC_TELEPHONE_INDEX; break;
394# endif
395# ifdef LC_MEASUREMENT
396 case LC_MEASUREMENT: i = LC_MEASUREMENT_INDEX; break;
397# endif
398# ifdef LC_IDENTIFICATION
399 case LC_IDENTIFICATION: i = LC_IDENTIFICATION_INDEX; break;
400# endif
401 default:
402 /* If you get here, a #ifdef LC_xxx is missing. */
403 abort ();
404 }
405
406 strcpy (resultbuf[i], buf);
407 return resultbuf[i];
408# endif
409 }
410#endif
411}
diff --git a/gl/setlocale_null.h b/gl/setlocale_null.h
new file mode 100644
index 0000000..c740fa0
--- /dev/null
+++ b/gl/setlocale_null.h
@@ -0,0 +1,82 @@
1/* Query the name of the current global locale.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2019. */
18
19#ifndef _SETLOCALE_NULL_H
20#define _SETLOCALE_NULL_H
21
22#include <stddef.h>
23
24#include "arg-nonnull.h"
25
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31
32/* Recommended size of a buffer for a locale name for a single category.
33 On glibc systems, you can have locale names that are relative file names;
34 assume a maximum length 256.
35 In native Windows, in 2018 the longest locale name was of length 58
36 ("FYRO Macedonian_Former Yugoslav Republic of Macedonia.1251"). */
37#define SETLOCALE_NULL_MAX (256+1)
38
39/* Recommended size of a buffer for a locale name with all categories.
40 On glibc systems, you can have locale names that are relative file names;
41 assume maximum length 256 for each. There are 12 categories; so, the
42 maximum total length is 148+12*256.
43 In native Windows, there are 5 categories, and the maximum total length is
44 55+5*58. */
45#define SETLOCALE_NULL_ALL_MAX (148+12*256+1)
46
47/* setlocale_null_r (CATEGORY, BUF, BUFSIZE) is like setlocale (CATEGORY, NULL),
48 except that
49 - it is guaranteed to be multithread-safe,
50 - it returns the resulting locale category name or locale name in the
51 user-supplied buffer BUF, which must be BUFSIZE bytes long.
52 The recommended minimum buffer size is
53 - SETLOCALE_NULL_MAX for CATEGORY != LC_ALL, and
54 - SETLOCALE_NULL_ALL_MAX for CATEGORY == LC_ALL.
55 The return value is an error code: 0 if the call is successful, EINVAL if
56 CATEGORY is invalid, or ERANGE if BUFSIZE is smaller than the length needed
57 size (including the trailing NUL byte). In the latter case, a truncated
58 result is returned in BUF, but still NUL-terminated if BUFSIZE > 0.
59 For this call to be multithread-safe, *all* calls to
60 setlocale (CATEGORY, NULL) in all other threads must have been converted
61 to use setlocale_null_r or setlocale_null as well, and the other threads
62 must not make other setlocale invocations (since changing the global locale
63 has side effects on all threads). */
64extern int setlocale_null_r (int category, char *buf, size_t bufsize)
65 _GL_ARG_NONNULL ((2));
66
67/* setlocale_null (CATEGORY) is like setlocale (CATEGORY, NULL), except that
68 it is guaranteed to be multithread-safe.
69 The return value is NULL if CATEGORY is invalid.
70 For this call to be multithread-safe, *all* calls to
71 setlocale (CATEGORY, NULL) in all other threads must have been converted
72 to use setlocale_null_r or setlocale_null as well, and the other threads
73 must not make other setlocale invocations (since changing the global locale
74 has side effects on all threads). */
75extern const char *setlocale_null (int category);
76
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif /* _SETLOCALE_NULL_H */
diff --git a/gl/sha1.c b/gl/sha1.c
deleted file mode 100644
index 778389a..0000000
--- a/gl/sha1.c
+++ /dev/null
@@ -1,426 +0,0 @@
1/* sha1.c - Functions to compute SHA1 message digest of files or
2 memory blocks according to the NIST specification FIPS-180-1.
3
4 Copyright (C) 2000-2001, 2003-2006, 2008-2013 Free Software Foundation, Inc.
5
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
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
18
19/* Written by Scott G. Miller
20 Credits:
21 Robert Klep <robert@ilse.nl> -- Expansion function fix
22*/
23
24#include <config.h>
25
26#include "sha1.h"
27
28#include <stdalign.h>
29#include <stdint.h>
30#include <stdlib.h>
31#include <string.h>
32
33#if USE_UNLOCKED_IO
34# include "unlocked-io.h"
35#endif
36
37#ifdef WORDS_BIGENDIAN
38# define SWAP(n) (n)
39#else
40# define SWAP(n) \
41 (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
42#endif
43
44#define BLOCKSIZE 32768
45#if BLOCKSIZE % 64 != 0
46# error "invalid BLOCKSIZE"
47#endif
48
49/* This array contains the bytes used to pad the buffer to the next
50 64-byte boundary. (RFC 1321, 3.1: Step 1) */
51static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
52
53
54/* Take a pointer to a 160 bit block of data (five 32 bit ints) and
55 initialize it to the start constants of the SHA1 algorithm. This
56 must be called before using hash in the call to sha1_hash. */
57void
58sha1_init_ctx (struct sha1_ctx *ctx)
59{
60 ctx->A = 0x67452301;
61 ctx->B = 0xefcdab89;
62 ctx->C = 0x98badcfe;
63 ctx->D = 0x10325476;
64 ctx->E = 0xc3d2e1f0;
65
66 ctx->total[0] = ctx->total[1] = 0;
67 ctx->buflen = 0;
68}
69
70/* Copy the 4 byte value from v into the memory location pointed to by *cp,
71 If your architecture allows unaligned access this is equivalent to
72 * (uint32_t *) cp = v */
73static void
74set_uint32 (char *cp, uint32_t v)
75{
76 memcpy (cp, &v, sizeof v);
77}
78
79/* Put result from CTX in first 20 bytes following RESBUF. The result
80 must be in little endian byte order. */
81void *
82sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
83{
84 char *r = resbuf;
85 set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
86 set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B));
87 set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C));
88 set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D));
89 set_uint32 (r + 4 * sizeof ctx->E, SWAP (ctx->E));
90
91 return resbuf;
92}
93
94/* Process the remaining bytes in the internal buffer and the usual
95 prolog according to the standard and write the result to RESBUF. */
96void *
97sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
98{
99 /* Take yet unprocessed bytes into account. */
100 uint32_t bytes = ctx->buflen;
101 size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
102
103 /* Now count remaining bytes. */
104 ctx->total[0] += bytes;
105 if (ctx->total[0] < bytes)
106 ++ctx->total[1];
107
108 /* Put the 64-bit file length in *bits* at the end of the buffer. */
109 ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
110 ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);
111
112 memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
113
114 /* Process last bytes. */
115 sha1_process_block (ctx->buffer, size * 4, ctx);
116
117 return sha1_read_ctx (ctx, resbuf);
118}
119
120/* Compute SHA1 message digest for bytes read from STREAM. The
121 resulting message digest number will be written into the 16 bytes
122 beginning at RESBLOCK. */
123int
124sha1_stream (FILE *stream, void *resblock)
125{
126 struct sha1_ctx ctx;
127 size_t sum;
128
129 char *buffer = malloc (BLOCKSIZE + 72);
130 if (!buffer)
131 return 1;
132
133 /* Initialize the computation context. */
134 sha1_init_ctx (&ctx);
135
136 /* Iterate over full file contents. */
137 while (1)
138 {
139 /* We read the file in blocks of BLOCKSIZE bytes. One call of the
140 computation function processes the whole buffer so that with the
141 next round of the loop another block can be read. */
142 size_t n;
143 sum = 0;
144
145 /* Read block. Take care for partial reads. */
146 while (1)
147 {
148 n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
149
150 sum += n;
151
152 if (sum == BLOCKSIZE)
153 break;
154
155 if (n == 0)
156 {
157 /* Check for the error flag IFF N == 0, so that we don't
158 exit the loop after a partial read due to e.g., EAGAIN
159 or EWOULDBLOCK. */
160 if (ferror (stream))
161 {
162 free (buffer);
163 return 1;
164 }
165 goto process_partial_block;
166 }
167
168 /* We've read at least one byte, so ignore errors. But always
169 check for EOF, since feof may be true even though N > 0.
170 Otherwise, we could end up calling fread after EOF. */
171 if (feof (stream))
172 goto process_partial_block;
173 }
174
175 /* Process buffer with BLOCKSIZE bytes. Note that
176 BLOCKSIZE % 64 == 0
177 */
178 sha1_process_block (buffer, BLOCKSIZE, &ctx);
179 }
180
181 process_partial_block:;
182
183 /* Process any remaining bytes. */
184 if (sum > 0)
185 sha1_process_bytes (buffer, sum, &ctx);
186
187 /* Construct result in desired memory. */
188 sha1_finish_ctx (&ctx, resblock);
189 free (buffer);
190 return 0;
191}
192
193/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
194 result is always in little endian byte order, so that a byte-wise
195 output yields to the wanted ASCII representation of the message
196 digest. */
197void *
198sha1_buffer (const char *buffer, size_t len, void *resblock)
199{
200 struct sha1_ctx ctx;
201
202 /* Initialize the computation context. */
203 sha1_init_ctx (&ctx);
204
205 /* Process whole buffer but last len % 64 bytes. */
206 sha1_process_bytes (buffer, len, &ctx);
207
208 /* Put result in desired memory area. */
209 return sha1_finish_ctx (&ctx, resblock);
210}
211
212void
213sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
214{
215 /* When we already have some bits in our internal buffer concatenate
216 both inputs first. */
217 if (ctx->buflen != 0)
218 {
219 size_t left_over = ctx->buflen;
220 size_t add = 128 - left_over > len ? len : 128 - left_over;
221
222 memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
223 ctx->buflen += add;
224
225 if (ctx->buflen > 64)
226 {
227 sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
228
229 ctx->buflen &= 63;
230 /* The regions in the following copy operation cannot overlap. */
231 memcpy (ctx->buffer,
232 &((char *) ctx->buffer)[(left_over + add) & ~63],
233 ctx->buflen);
234 }
235
236 buffer = (const char *) buffer + add;
237 len -= add;
238 }
239
240 /* Process available complete blocks. */
241 if (len >= 64)
242 {
243#if !_STRING_ARCH_unaligned
244# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0)
245 if (UNALIGNED_P (buffer))
246 while (len > 64)
247 {
248 sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
249 buffer = (const char *) buffer + 64;
250 len -= 64;
251 }
252 else
253#endif
254 {
255 sha1_process_block (buffer, len & ~63, ctx);
256 buffer = (const char *) buffer + (len & ~63);
257 len &= 63;
258 }
259 }
260
261 /* Move remaining bytes in internal buffer. */
262 if (len > 0)
263 {
264 size_t left_over = ctx->buflen;
265
266 memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
267 left_over += len;
268 if (left_over >= 64)
269 {
270 sha1_process_block (ctx->buffer, 64, ctx);
271 left_over -= 64;
272 memcpy (ctx->buffer, &ctx->buffer[16], left_over);
273 }
274 ctx->buflen = left_over;
275 }
276}
277
278/* --- Code below is the primary difference between md5.c and sha1.c --- */
279
280/* SHA1 round constants */
281#define K1 0x5a827999
282#define K2 0x6ed9eba1
283#define K3 0x8f1bbcdc
284#define K4 0xca62c1d6
285
286/* Round functions. Note that F2 is the same as F4. */
287#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
288#define F2(B,C,D) (B ^ C ^ D)
289#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
290#define F4(B,C,D) (B ^ C ^ D)
291
292/* Process LEN bytes of BUFFER, accumulating context into CTX.
293 It is assumed that LEN % 64 == 0.
294 Most of this code comes from GnuPG's cipher/sha1.c. */
295
296void
297sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
298{
299 const uint32_t *words = buffer;
300 size_t nwords = len / sizeof (uint32_t);
301 const uint32_t *endp = words + nwords;
302 uint32_t x[16];
303 uint32_t a = ctx->A;
304 uint32_t b = ctx->B;
305 uint32_t c = ctx->C;
306 uint32_t d = ctx->D;
307 uint32_t e = ctx->E;
308 uint32_t lolen = len;
309
310 /* First increment the byte count. RFC 1321 specifies the possible
311 length of the file up to 2^64 bits. Here we only compute the
312 number of bytes. Do a double word increment. */
313 ctx->total[0] += lolen;
314 ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen);
315
316#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
317
318#define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \
319 ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
320 , (x[I&0x0f] = rol(tm, 1)) )
321
322#define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \
323 + F( B, C, D ) \
324 + K \
325 + M; \
326 B = rol( B, 30 ); \
327 } while(0)
328
329 while (words < endp)
330 {
331 uint32_t tm;
332 int t;
333 for (t = 0; t < 16; t++)
334 {
335 x[t] = SWAP (*words);
336 words++;
337 }
338
339 R( a, b, c, d, e, F1, K1, x[ 0] );
340 R( e, a, b, c, d, F1, K1, x[ 1] );
341 R( d, e, a, b, c, F1, K1, x[ 2] );
342 R( c, d, e, a, b, F1, K1, x[ 3] );
343 R( b, c, d, e, a, F1, K1, x[ 4] );
344 R( a, b, c, d, e, F1, K1, x[ 5] );
345 R( e, a, b, c, d, F1, K1, x[ 6] );
346 R( d, e, a, b, c, F1, K1, x[ 7] );
347 R( c, d, e, a, b, F1, K1, x[ 8] );
348 R( b, c, d, e, a, F1, K1, x[ 9] );
349 R( a, b, c, d, e, F1, K1, x[10] );
350 R( e, a, b, c, d, F1, K1, x[11] );
351 R( d, e, a, b, c, F1, K1, x[12] );
352 R( c, d, e, a, b, F1, K1, x[13] );
353 R( b, c, d, e, a, F1, K1, x[14] );
354 R( a, b, c, d, e, F1, K1, x[15] );
355 R( e, a, b, c, d, F1, K1, M(16) );
356 R( d, e, a, b, c, F1, K1, M(17) );
357 R( c, d, e, a, b, F1, K1, M(18) );
358 R( b, c, d, e, a, F1, K1, M(19) );
359 R( a, b, c, d, e, F2, K2, M(20) );
360 R( e, a, b, c, d, F2, K2, M(21) );
361 R( d, e, a, b, c, F2, K2, M(22) );
362 R( c, d, e, a, b, F2, K2, M(23) );
363 R( b, c, d, e, a, F2, K2, M(24) );
364 R( a, b, c, d, e, F2, K2, M(25) );
365 R( e, a, b, c, d, F2, K2, M(26) );
366 R( d, e, a, b, c, F2, K2, M(27) );
367 R( c, d, e, a, b, F2, K2, M(28) );
368 R( b, c, d, e, a, F2, K2, M(29) );
369 R( a, b, c, d, e, F2, K2, M(30) );
370 R( e, a, b, c, d, F2, K2, M(31) );
371 R( d, e, a, b, c, F2, K2, M(32) );
372 R( c, d, e, a, b, F2, K2, M(33) );
373 R( b, c, d, e, a, F2, K2, M(34) );
374 R( a, b, c, d, e, F2, K2, M(35) );
375 R( e, a, b, c, d, F2, K2, M(36) );
376 R( d, e, a, b, c, F2, K2, M(37) );
377 R( c, d, e, a, b, F2, K2, M(38) );
378 R( b, c, d, e, a, F2, K2, M(39) );
379 R( a, b, c, d, e, F3, K3, M(40) );
380 R( e, a, b, c, d, F3, K3, M(41) );
381 R( d, e, a, b, c, F3, K3, M(42) );
382 R( c, d, e, a, b, F3, K3, M(43) );
383 R( b, c, d, e, a, F3, K3, M(44) );
384 R( a, b, c, d, e, F3, K3, M(45) );
385 R( e, a, b, c, d, F3, K3, M(46) );
386 R( d, e, a, b, c, F3, K3, M(47) );
387 R( c, d, e, a, b, F3, K3, M(48) );
388 R( b, c, d, e, a, F3, K3, M(49) );
389 R( a, b, c, d, e, F3, K3, M(50) );
390 R( e, a, b, c, d, F3, K3, M(51) );
391 R( d, e, a, b, c, F3, K3, M(52) );
392 R( c, d, e, a, b, F3, K3, M(53) );
393 R( b, c, d, e, a, F3, K3, M(54) );
394 R( a, b, c, d, e, F3, K3, M(55) );
395 R( e, a, b, c, d, F3, K3, M(56) );
396 R( d, e, a, b, c, F3, K3, M(57) );
397 R( c, d, e, a, b, F3, K3, M(58) );
398 R( b, c, d, e, a, F3, K3, M(59) );
399 R( a, b, c, d, e, F4, K4, M(60) );
400 R( e, a, b, c, d, F4, K4, M(61) );
401 R( d, e, a, b, c, F4, K4, M(62) );
402 R( c, d, e, a, b, F4, K4, M(63) );
403 R( b, c, d, e, a, F4, K4, M(64) );
404 R( a, b, c, d, e, F4, K4, M(65) );
405 R( e, a, b, c, d, F4, K4, M(66) );
406 R( d, e, a, b, c, F4, K4, M(67) );
407 R( c, d, e, a, b, F4, K4, M(68) );
408 R( b, c, d, e, a, F4, K4, M(69) );
409 R( a, b, c, d, e, F4, K4, M(70) );
410 R( e, a, b, c, d, F4, K4, M(71) );
411 R( d, e, a, b, c, F4, K4, M(72) );
412 R( c, d, e, a, b, F4, K4, M(73) );
413 R( b, c, d, e, a, F4, K4, M(74) );
414 R( a, b, c, d, e, F4, K4, M(75) );
415 R( e, a, b, c, d, F4, K4, M(76) );
416 R( d, e, a, b, c, F4, K4, M(77) );
417 R( c, d, e, a, b, F4, K4, M(78) );
418 R( b, c, d, e, a, F4, K4, M(79) );
419
420 a = ctx->A += a;
421 b = ctx->B += b;
422 c = ctx->C += c;
423 d = ctx->D += d;
424 e = ctx->E += e;
425 }
426}
diff --git a/gl/sha1.h b/gl/sha1.h
deleted file mode 100644
index ddd386f..0000000
--- a/gl/sha1.h
+++ /dev/null
@@ -1,91 +0,0 @@
1/* Declarations of functions and data types used for SHA1 sum
2 library functions.
3 Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2013 Free Software
4 Foundation, Inc.
5
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
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef SHA1_H
20# define SHA1_H 1
21
22# include <stdio.h>
23# include <stdint.h>
24
25# ifdef __cplusplus
26extern "C" {
27# endif
28
29#define SHA1_DIGEST_SIZE 20
30
31/* Structure to save state of computation between the single steps. */
32struct sha1_ctx
33{
34 uint32_t A;
35 uint32_t B;
36 uint32_t C;
37 uint32_t D;
38 uint32_t E;
39
40 uint32_t total[2];
41 uint32_t buflen;
42 uint32_t buffer[32];
43};
44
45
46/* Initialize structure containing state of computation. */
47extern void sha1_init_ctx (struct sha1_ctx *ctx);
48
49/* Starting with the result of former calls of this function (or the
50 initialization function update the context for the next LEN bytes
51 starting at BUFFER.
52 It is necessary that LEN is a multiple of 64!!! */
53extern void sha1_process_block (const void *buffer, size_t len,
54 struct sha1_ctx *ctx);
55
56/* Starting with the result of former calls of this function (or the
57 initialization function update the context for the next LEN bytes
58 starting at BUFFER.
59 It is NOT required that LEN is a multiple of 64. */
60extern void sha1_process_bytes (const void *buffer, size_t len,
61 struct sha1_ctx *ctx);
62
63/* Process the remaining bytes in the buffer and put result from CTX
64 in first 20 bytes following RESBUF. The result is always in little
65 endian byte order, so that a byte-wise output yields to the wanted
66 ASCII representation of the message digest. */
67extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
68
69
70/* Put result from CTX in first 20 bytes following RESBUF. The result is
71 always in little endian byte order, so that a byte-wise output yields
72 to the wanted ASCII representation of the message digest. */
73extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
74
75
76/* Compute SHA1 message digest for bytes read from STREAM. The
77 resulting message digest number will be written into the 20 bytes
78 beginning at RESBLOCK. */
79extern int sha1_stream (FILE *stream, void *resblock);
80
81/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
82 result is always in little endian byte order, so that a byte-wise
83 output yields to the wanted ASCII representation of the message
84 digest. */
85extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
86
87# ifdef __cplusplus
88}
89# endif
90
91#endif
diff --git a/gl/sha256-stream.c b/gl/sha256-stream.c
new file mode 100644
index 0000000..0e83380
--- /dev/null
+++ b/gl/sha256-stream.c
@@ -0,0 +1,145 @@
1/* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or
2 memory blocks according to the NIST specification FIPS-180-2.
3
4 Copyright (C) 2005-2006, 2008-2023 Free Software Foundation, Inc.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file 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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19/* Written by David Madore, considerably copypasting from
20 Scott G. Miller's sha1.c
21*/
22
23#include <config.h>
24
25/* Specification. */
26#if HAVE_OPENSSL_SHA256
27# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
28#endif
29#include "sha256.h"
30
31#include <stdlib.h>
32
33#if USE_UNLOCKED_IO
34# include "unlocked-io.h"
35#endif
36
37#include "af_alg.h"
38
39#define BLOCKSIZE 32768
40#if BLOCKSIZE % 64 != 0
41# error "invalid BLOCKSIZE"
42#endif
43
44/* Compute message digest for bytes read from STREAM using algorithm ALG.
45 Write the message digest into RESBLOCK, which contains HASHLEN bytes.
46 The initial and finishing operations are INIT_CTX and FINISH_CTX.
47 Return zero if and only if successful. */
48static int
49shaxxx_stream (FILE *stream, char const *alg, void *resblock,
50 ssize_t hashlen, void (*init_ctx) (struct sha256_ctx *),
51 void *(*finish_ctx) (struct sha256_ctx *, void *))
52{
53 switch (afalg_stream (stream, alg, resblock, hashlen))
54 {
55 case 0: return 0;
56 case -EIO: return 1;
57 }
58
59 char *buffer = malloc (BLOCKSIZE + 72);
60 if (!buffer)
61 return 1;
62
63 struct sha256_ctx ctx;
64 init_ctx (&ctx);
65 size_t sum;
66
67 /* Iterate over full file contents. */
68 while (1)
69 {
70 /* We read the file in blocks of BLOCKSIZE bytes. One call of the
71 computation function processes the whole buffer so that with the
72 next round of the loop another block can be read. */
73 size_t n;
74 sum = 0;
75
76 /* Read block. Take care for partial reads. */
77 while (1)
78 {
79 /* Either process a partial fread() from this loop,
80 or the fread() in afalg_stream may have gotten EOF.
81 We need to avoid a subsequent fread() as EOF may
82 not be sticky. For details of such systems, see:
83 https://sourceware.org/bugzilla/show_bug.cgi?id=1190 */
84 if (feof (stream))
85 goto process_partial_block;
86
87 n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
88
89 sum += n;
90
91 if (sum == BLOCKSIZE)
92 break;
93
94 if (n == 0)
95 {
96 /* Check for the error flag IFF N == 0, so that we don't
97 exit the loop after a partial read due to e.g., EAGAIN
98 or EWOULDBLOCK. */
99 if (ferror (stream))
100 {
101 free (buffer);
102 return 1;
103 }
104 goto process_partial_block;
105 }
106 }
107
108 /* Process buffer with BLOCKSIZE bytes. Note that
109 BLOCKSIZE % 64 == 0
110 */
111 sha256_process_block (buffer, BLOCKSIZE, &ctx);
112 }
113
114 process_partial_block:;
115
116 /* Process any remaining bytes. */
117 if (sum > 0)
118 sha256_process_bytes (buffer, sum, &ctx);
119
120 /* Construct result in desired memory. */
121 finish_ctx (&ctx, resblock);
122 free (buffer);
123 return 0;
124}
125
126int
127sha256_stream (FILE *stream, void *resblock)
128{
129 return shaxxx_stream (stream, "sha256", resblock, SHA256_DIGEST_SIZE,
130 sha256_init_ctx, sha256_finish_ctx);
131}
132
133int
134sha224_stream (FILE *stream, void *resblock)
135{
136 return shaxxx_stream (stream, "sha224", resblock, SHA224_DIGEST_SIZE,
137 sha224_init_ctx, sha224_finish_ctx);
138}
139
140/*
141 * Hey Emacs!
142 * Local Variables:
143 * coding: utf-8
144 * End:
145 */
diff --git a/gl/sha256.c b/gl/sha256.c
new file mode 100644
index 0000000..e5fea02
--- /dev/null
+++ b/gl/sha256.c
@@ -0,0 +1,432 @@
1/* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or
2 memory blocks according to the NIST specification FIPS-180-2.
3
4 Copyright (C) 2005-2006, 2008-2023 Free Software Foundation, Inc.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file 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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19/* Written by David Madore, considerably copypasting from
20 Scott G. Miller's sha1.c
21*/
22
23#include <config.h>
24
25/* Specification. */
26#if HAVE_OPENSSL_SHA256
27# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
28#endif
29#include "sha256.h"
30
31#include <stdint.h>
32#include <string.h>
33
34#include <byteswap.h>
35#ifdef WORDS_BIGENDIAN
36# define SWAP(n) (n)
37#else
38# define SWAP(n) bswap_32 (n)
39#endif
40
41#if ! HAVE_OPENSSL_SHA256
42
43/* This array contains the bytes used to pad the buffer to the next
44 64-byte boundary. */
45static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
46
47
48/*
49 Takes a pointer to a 256 bit block of data (eight 32 bit ints) and
50 initializes it to the start constants of the SHA256 algorithm. This
51 must be called before using hash in the call to sha256_hash
52*/
53void
54sha256_init_ctx (struct sha256_ctx *ctx)
55{
56 ctx->state[0] = 0x6a09e667UL;
57 ctx->state[1] = 0xbb67ae85UL;
58 ctx->state[2] = 0x3c6ef372UL;
59 ctx->state[3] = 0xa54ff53aUL;
60 ctx->state[4] = 0x510e527fUL;
61 ctx->state[5] = 0x9b05688cUL;
62 ctx->state[6] = 0x1f83d9abUL;
63 ctx->state[7] = 0x5be0cd19UL;
64
65 ctx->total[0] = ctx->total[1] = 0;
66 ctx->buflen = 0;
67}
68
69void
70sha224_init_ctx (struct sha256_ctx *ctx)
71{
72 ctx->state[0] = 0xc1059ed8UL;
73 ctx->state[1] = 0x367cd507UL;
74 ctx->state[2] = 0x3070dd17UL;
75 ctx->state[3] = 0xf70e5939UL;
76 ctx->state[4] = 0xffc00b31UL;
77 ctx->state[5] = 0x68581511UL;
78 ctx->state[6] = 0x64f98fa7UL;
79 ctx->state[7] = 0xbefa4fa4UL;
80
81 ctx->total[0] = ctx->total[1] = 0;
82 ctx->buflen = 0;
83}
84
85/* Copy the value from v into the memory location pointed to by *CP,
86 If your architecture allows unaligned access, this is equivalent to
87 * (__typeof__ (v) *) cp = v */
88static void
89set_uint32 (char *cp, uint32_t v)
90{
91 memcpy (cp, &v, sizeof v);
92}
93
94/* Put result from CTX in first 32 bytes following RESBUF.
95 The result must be in little endian byte order. */
96void *
97sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
98{
99 int i;
100 char *r = resbuf;
101
102 for (i = 0; i < 8; i++)
103 set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
104
105 return resbuf;
106}
107
108void *
109sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
110{
111 int i;
112 char *r = resbuf;
113
114 for (i = 0; i < 7; i++)
115 set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
116
117 return resbuf;
118}
119
120/* Process the remaining bytes in the internal buffer and the usual
121 prolog according to the standard and write the result to RESBUF. */
122static void
123sha256_conclude_ctx (struct sha256_ctx *ctx)
124{
125 /* Take yet unprocessed bytes into account. */
126 size_t bytes = ctx->buflen;
127 size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
128
129 /* Now count remaining bytes. */
130 ctx->total[0] += bytes;
131 if (ctx->total[0] < bytes)
132 ++ctx->total[1];
133
134 /* Put the 64-bit file length in *bits* at the end of the buffer.
135 Use set_uint32 rather than a simple assignment, to avoid risk of
136 unaligned access. */
137 set_uint32 ((char *) &ctx->buffer[size - 2],
138 SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)));
139 set_uint32 ((char *) &ctx->buffer[size - 1],
140 SWAP (ctx->total[0] << 3));
141
142 memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
143
144 /* Process last bytes. */
145 sha256_process_block (ctx->buffer, size * 4, ctx);
146}
147
148void *
149sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
150{
151 sha256_conclude_ctx (ctx);
152 return sha256_read_ctx (ctx, resbuf);
153}
154
155void *
156sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
157{
158 sha256_conclude_ctx (ctx);
159 return sha224_read_ctx (ctx, resbuf);
160}
161
162/* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The
163 result is always in little endian byte order, so that a byte-wise
164 output yields to the wanted ASCII representation of the message
165 digest. */
166void *
167sha256_buffer (const char *buffer, size_t len, void *resblock)
168{
169 struct sha256_ctx ctx;
170
171 /* Initialize the computation context. */
172 sha256_init_ctx (&ctx);
173
174 /* Process whole buffer but last len % 64 bytes. */
175 sha256_process_bytes (buffer, len, &ctx);
176
177 /* Put result in desired memory area. */
178 return sha256_finish_ctx (&ctx, resblock);
179}
180
181void *
182sha224_buffer (const char *buffer, size_t len, void *resblock)
183{
184 struct sha256_ctx ctx;
185
186 /* Initialize the computation context. */
187 sha224_init_ctx (&ctx);
188
189 /* Process whole buffer but last len % 64 bytes. */
190 sha256_process_bytes (buffer, len, &ctx);
191
192 /* Put result in desired memory area. */
193 return sha224_finish_ctx (&ctx, resblock);
194}
195
196void
197sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
198{
199 /* When we already have some bits in our internal buffer concatenate
200 both inputs first. */
201 if (ctx->buflen != 0)
202 {
203 size_t left_over = ctx->buflen;
204 size_t add = 128 - left_over > len ? len : 128 - left_over;
205
206 memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
207 ctx->buflen += add;
208
209 if (ctx->buflen > 64)
210 {
211 sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
212
213 ctx->buflen &= 63;
214 /* The regions in the following copy operation cannot overlap,
215 because ctx->buflen < 64 ≤ (left_over + add) & ~63. */
216 memcpy (ctx->buffer,
217 &((char *) ctx->buffer)[(left_over + add) & ~63],
218 ctx->buflen);
219 }
220
221 buffer = (const char *) buffer + add;
222 len -= add;
223 }
224
225 /* Process available complete blocks. */
226 if (len >= 64)
227 {
228#if !(_STRING_ARCH_unaligned || _STRING_INLINE_unaligned)
229# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0)
230 if (UNALIGNED_P (buffer))
231 while (len > 64)
232 {
233 sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
234 buffer = (const char *) buffer + 64;
235 len -= 64;
236 }
237 else
238#endif
239 {
240 sha256_process_block (buffer, len & ~63, ctx);
241 buffer = (const char *) buffer + (len & ~63);
242 len &= 63;
243 }
244 }
245
246 /* Move remaining bytes in internal buffer. */
247 if (len > 0)
248 {
249 size_t left_over = ctx->buflen;
250
251 memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
252 left_over += len;
253 if (left_over >= 64)
254 {
255 sha256_process_block (ctx->buffer, 64, ctx);
256 left_over -= 64;
257 /* The regions in the following copy operation cannot overlap,
258 because left_over ≤ 64. */
259 memcpy (ctx->buffer, &ctx->buffer[16], left_over);
260 }
261 ctx->buflen = left_over;
262 }
263}
264
265/* --- Code below is the primary difference between sha1.c and sha256.c --- */
266
267/* SHA256 round constants */
268#define K(I) sha256_round_constants[I]
269static const uint32_t sha256_round_constants[64] = {
270 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
271 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
272 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
273 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
274 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
275 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
276 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
277 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
278 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
279 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
280 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
281 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
282 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
283 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
284 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
285 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL,
286};
287
288/* Round functions. */
289#define F2(A,B,C) ( ( A & B ) | ( C & ( A | B ) ) )
290#define F1(E,F,G) ( G ^ ( E & ( F ^ G ) ) )
291
292/* Process LEN bytes of BUFFER, accumulating context into CTX.
293 It is assumed that LEN % 64 == 0.
294 Most of this code comes from GnuPG's cipher/sha1.c. */
295
296void
297sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
298{
299 const uint32_t *words = buffer;
300 size_t nwords = len / sizeof (uint32_t);
301 const uint32_t *endp = words + nwords;
302 uint32_t x[16];
303 uint32_t a = ctx->state[0];
304 uint32_t b = ctx->state[1];
305 uint32_t c = ctx->state[2];
306 uint32_t d = ctx->state[3];
307 uint32_t e = ctx->state[4];
308 uint32_t f = ctx->state[5];
309 uint32_t g = ctx->state[6];
310 uint32_t h = ctx->state[7];
311 uint32_t lolen = len;
312
313 /* First increment the byte count. FIPS PUB 180-2 specifies the possible
314 length of the file up to 2^64 bits. Here we only compute the
315 number of bytes. Do a double word increment. */
316 ctx->total[0] += lolen;
317 ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen);
318
319#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
320#define S0(x) (rol(x,25)^rol(x,14)^(x>>3))
321#define S1(x) (rol(x,15)^rol(x,13)^(x>>10))
322#define SS0(x) (rol(x,30)^rol(x,19)^rol(x,10))
323#define SS1(x) (rol(x,26)^rol(x,21)^rol(x,7))
324
325#define M(I) ( tm = S1(x[(I-2)&0x0f]) + x[(I-7)&0x0f] \
326 + S0(x[(I-15)&0x0f]) + x[I&0x0f] \
327 , x[I&0x0f] = tm )
328
329#define R(A,B,C,D,E,F,G,H,K,M) do { t0 = SS0(A) + F2(A,B,C); \
330 t1 = H + SS1(E) \
331 + F1(E,F,G) \
332 + K \
333 + M; \
334 D += t1; H = t0 + t1; \
335 } while(0)
336
337 while (words < endp)
338 {
339 uint32_t tm;
340 uint32_t t0, t1;
341 int t;
342 /* FIXME: see sha1.c for a better implementation. */
343 for (t = 0; t < 16; t++)
344 {
345 x[t] = SWAP (*words);
346 words++;
347 }
348
349 R( a, b, c, d, e, f, g, h, K( 0), x[ 0] );
350 R( h, a, b, c, d, e, f, g, K( 1), x[ 1] );
351 R( g, h, a, b, c, d, e, f, K( 2), x[ 2] );
352 R( f, g, h, a, b, c, d, e, K( 3), x[ 3] );
353 R( e, f, g, h, a, b, c, d, K( 4), x[ 4] );
354 R( d, e, f, g, h, a, b, c, K( 5), x[ 5] );
355 R( c, d, e, f, g, h, a, b, K( 6), x[ 6] );
356 R( b, c, d, e, f, g, h, a, K( 7), x[ 7] );
357 R( a, b, c, d, e, f, g, h, K( 8), x[ 8] );
358 R( h, a, b, c, d, e, f, g, K( 9), x[ 9] );
359 R( g, h, a, b, c, d, e, f, K(10), x[10] );
360 R( f, g, h, a, b, c, d, e, K(11), x[11] );
361 R( e, f, g, h, a, b, c, d, K(12), x[12] );
362 R( d, e, f, g, h, a, b, c, K(13), x[13] );
363 R( c, d, e, f, g, h, a, b, K(14), x[14] );
364 R( b, c, d, e, f, g, h, a, K(15), x[15] );
365 R( a, b, c, d, e, f, g, h, K(16), M(16) );
366 R( h, a, b, c, d, e, f, g, K(17), M(17) );
367 R( g, h, a, b, c, d, e, f, K(18), M(18) );
368 R( f, g, h, a, b, c, d, e, K(19), M(19) );
369 R( e, f, g, h, a, b, c, d, K(20), M(20) );
370 R( d, e, f, g, h, a, b, c, K(21), M(21) );
371 R( c, d, e, f, g, h, a, b, K(22), M(22) );
372 R( b, c, d, e, f, g, h, a, K(23), M(23) );
373 R( a, b, c, d, e, f, g, h, K(24), M(24) );
374 R( h, a, b, c, d, e, f, g, K(25), M(25) );
375 R( g, h, a, b, c, d, e, f, K(26), M(26) );
376 R( f, g, h, a, b, c, d, e, K(27), M(27) );
377 R( e, f, g, h, a, b, c, d, K(28), M(28) );
378 R( d, e, f, g, h, a, b, c, K(29), M(29) );
379 R( c, d, e, f, g, h, a, b, K(30), M(30) );
380 R( b, c, d, e, f, g, h, a, K(31), M(31) );
381 R( a, b, c, d, e, f, g, h, K(32), M(32) );
382 R( h, a, b, c, d, e, f, g, K(33), M(33) );
383 R( g, h, a, b, c, d, e, f, K(34), M(34) );
384 R( f, g, h, a, b, c, d, e, K(35), M(35) );
385 R( e, f, g, h, a, b, c, d, K(36), M(36) );
386 R( d, e, f, g, h, a, b, c, K(37), M(37) );
387 R( c, d, e, f, g, h, a, b, K(38), M(38) );
388 R( b, c, d, e, f, g, h, a, K(39), M(39) );
389 R( a, b, c, d, e, f, g, h, K(40), M(40) );
390 R( h, a, b, c, d, e, f, g, K(41), M(41) );
391 R( g, h, a, b, c, d, e, f, K(42), M(42) );
392 R( f, g, h, a, b, c, d, e, K(43), M(43) );
393 R( e, f, g, h, a, b, c, d, K(44), M(44) );
394 R( d, e, f, g, h, a, b, c, K(45), M(45) );
395 R( c, d, e, f, g, h, a, b, K(46), M(46) );
396 R( b, c, d, e, f, g, h, a, K(47), M(47) );
397 R( a, b, c, d, e, f, g, h, K(48), M(48) );
398 R( h, a, b, c, d, e, f, g, K(49), M(49) );
399 R( g, h, a, b, c, d, e, f, K(50), M(50) );
400 R( f, g, h, a, b, c, d, e, K(51), M(51) );
401 R( e, f, g, h, a, b, c, d, K(52), M(52) );
402 R( d, e, f, g, h, a, b, c, K(53), M(53) );
403 R( c, d, e, f, g, h, a, b, K(54), M(54) );
404 R( b, c, d, e, f, g, h, a, K(55), M(55) );
405 R( a, b, c, d, e, f, g, h, K(56), M(56) );
406 R( h, a, b, c, d, e, f, g, K(57), M(57) );
407 R( g, h, a, b, c, d, e, f, K(58), M(58) );
408 R( f, g, h, a, b, c, d, e, K(59), M(59) );
409 R( e, f, g, h, a, b, c, d, K(60), M(60) );
410 R( d, e, f, g, h, a, b, c, K(61), M(61) );
411 R( c, d, e, f, g, h, a, b, K(62), M(62) );
412 R( b, c, d, e, f, g, h, a, K(63), M(63) );
413
414 a = ctx->state[0] += a;
415 b = ctx->state[1] += b;
416 c = ctx->state[2] += c;
417 d = ctx->state[3] += d;
418 e = ctx->state[4] += e;
419 f = ctx->state[5] += f;
420 g = ctx->state[6] += g;
421 h = ctx->state[7] += h;
422 }
423}
424
425#endif
426
427/*
428 * Hey Emacs!
429 * Local Variables:
430 * coding: utf-8
431 * End:
432 */
diff --git a/gl/sha256.h b/gl/sha256.h
new file mode 100644
index 0000000..2879477
--- /dev/null
+++ b/gl/sha256.h
@@ -0,0 +1,121 @@
1/* Declarations of functions and data types used for SHA256 and SHA224 sum
2 library functions.
3 Copyright (C) 2005-2006, 2008-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef SHA256_H
19# define SHA256_H 1
20
21# include <stdio.h>
22# include <stdint.h>
23
24# if HAVE_OPENSSL_SHA256
25# ifndef OPENSSL_API_COMPAT
26# define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */
27# endif
28# include <openssl/sha.h>
29# endif
30
31# ifdef __cplusplus
32extern "C" {
33# endif
34
35enum { SHA224_DIGEST_SIZE = 224 / 8 };
36enum { SHA256_DIGEST_SIZE = 256 / 8 };
37
38# if HAVE_OPENSSL_SHA256
39# define GL_OPENSSL_NAME 224
40# include "gl_openssl.h"
41# define GL_OPENSSL_NAME 256
42# include "gl_openssl.h"
43# else
44/* Structure to save state of computation between the single steps. */
45struct sha256_ctx
46{
47 uint32_t state[8];
48
49 uint32_t total[2];
50 size_t buflen; /* ≥ 0, ≤ 128 */
51 uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
52};
53
54/* Initialize structure containing state of computation. */
55extern void sha256_init_ctx (struct sha256_ctx *ctx);
56extern void sha224_init_ctx (struct sha256_ctx *ctx);
57
58/* Starting with the result of former calls of this function (or the
59 initialization function update the context for the next LEN bytes
60 starting at BUFFER.
61 It is necessary that LEN is a multiple of 64!!! */
62extern void sha256_process_block (const void *buffer, size_t len,
63 struct sha256_ctx *ctx);
64
65/* Starting with the result of former calls of this function (or the
66 initialization function update the context for the next LEN bytes
67 starting at BUFFER.
68 It is NOT required that LEN is a multiple of 64. */
69extern void sha256_process_bytes (const void *buffer, size_t len,
70 struct sha256_ctx *ctx);
71
72/* Process the remaining bytes in the buffer and put result from CTX
73 in first 32 (28) bytes following RESBUF. The result is always in little
74 endian byte order, so that a byte-wise output yields to the wanted
75 ASCII representation of the message digest. */
76extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf);
77extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf);
78
79
80/* Put result from CTX in first 32 (28) bytes following RESBUF. The result is
81 always in little endian byte order, so that a byte-wise output yields
82 to the wanted ASCII representation of the message digest. */
83extern void *sha256_read_ctx (const struct sha256_ctx *ctx,
84 void *restrict resbuf);
85extern void *sha224_read_ctx (const struct sha256_ctx *ctx,
86 void *restrict resbuf);
87
88
89/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER.
90 The result is always in little endian byte order, so that a byte-wise
91 output yields to the wanted ASCII representation of the message
92 digest. */
93extern void *sha256_buffer (const char *buffer, size_t len,
94 void *restrict resblock);
95extern void *sha224_buffer (const char *buffer, size_t len,
96 void *restrict resblock);
97
98# endif
99
100/* Compute SHA256 (SHA224) message digest for bytes read from STREAM.
101 STREAM is an open file stream. Regular files are handled more efficiently.
102 The contents of STREAM from its current position to its end will be read.
103 The case that the last operation on STREAM was an 'ungetc' is not supported.
104 The resulting message digest number will be written into the 32 (28) bytes
105 beginning at RESBLOCK. */
106extern int sha256_stream (FILE *stream, void *resblock);
107extern int sha224_stream (FILE *stream, void *resblock);
108
109
110# ifdef __cplusplus
111}
112# endif
113
114#endif
115
116/*
117 * Hey Emacs!
118 * Local Variables:
119 * coding: utf-8
120 * End:
121 */
diff --git a/gl/size_max.h b/gl/size_max.h
index 5f33124..48af025 100644
--- a/gl/size_max.h
+++ b/gl/size_max.h
@@ -1,19 +1,19 @@
1/* size_max.h -- declare SIZE_MAX through system headers 1/* size_max.h -- declare SIZE_MAX through system headers
2 Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2005-2006, 2009-2023 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef GNULIB_SIZE_MAX_H 18#ifndef GNULIB_SIZE_MAX_H
19#define GNULIB_SIZE_MAX_H 19#define GNULIB_SIZE_MAX_H
diff --git a/gl/snprintf.c b/gl/snprintf.c
index 9c4ab3f..cdff314 100644
--- a/gl/snprintf.c
+++ b/gl/snprintf.c
@@ -1,19 +1,19 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2006-2023 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
diff --git a/gl/sockets.c b/gl/sockets.c
index ae96148..ca99db8 100644
--- a/gl/sockets.c
+++ b/gl/sockets.c
@@ -1,19 +1,19 @@
1/* sockets.c --- wrappers for Windows socket functions 1/* sockets.c --- wrappers for Windows socket functions
2 2
3 Copyright (C) 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Simon Josefsson */ 18/* Written by Simon Josefsson */
19 19
@@ -28,7 +28,11 @@
28# include <sys/socket.h> 28# include <sys/socket.h>
29 29
30# include "fd-hook.h" 30# include "fd-hook.h"
31# include "msvc-nothrow.h" 31# if GNULIB_MSVC_NOTHROW
32# include "msvc-nothrow.h"
33# else
34# include <io.h>
35# endif
32 36
33/* Get set_winsock_errno, FD_TO_SOCKET etc. */ 37/* Get set_winsock_errno, FD_TO_SOCKET etc. */
34# include "w32sock.h" 38# include "w32sock.h"
@@ -109,7 +113,7 @@ static int initialized_sockets_version /* = 0 */;
109#endif /* WINDOWS_SOCKETS */ 113#endif /* WINDOWS_SOCKETS */
110 114
111int 115int
112gl_sockets_startup (int version _GL_UNUSED) 116gl_sockets_startup (_GL_UNUSED int version)
113{ 117{
114#if WINDOWS_SOCKETS 118#if WINDOWS_SOCKETS
115 if (version > initialized_sockets_version) 119 if (version > initialized_sockets_version)
@@ -121,8 +125,11 @@ gl_sockets_startup (int version _GL_UNUSED)
121 if (err != 0) 125 if (err != 0)
122 return 1; 126 return 1;
123 127
124 if (data.wVersion < version) 128 if (data.wVersion != version)
125 return 2; 129 {
130 WSACleanup ();
131 return 2;
132 }
126 133
127 if (initialized_sockets_version == 0) 134 if (initialized_sockets_version == 0)
128 register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket, 135 register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket,
diff --git a/gl/sockets.h b/gl/sockets.h
index 1570ad8..a0b1601 100644
--- a/gl/sockets.h
+++ b/gl/sockets.h
@@ -1,39 +1,39 @@
1/* sockets.h - wrappers for Windows socket functions 1/* sockets.h - wrappers for Windows socket functions
2 2
3 Copyright (C) 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Simon Josefsson */ 18/* Written by Simon Josefsson */
19 19
20#ifndef SOCKETS_H 20#ifndef SOCKETS_H
21# define SOCKETS_H 1 21#define SOCKETS_H 1
22 22
23#define SOCKETS_1_0 0x100 /* don't use - does not work on Windows XP */ 23#define SOCKETS_1_0 0x0001
24#define SOCKETS_1_1 0x101 24#define SOCKETS_1_1 0x0101
25#define SOCKETS_2_0 0x200 /* don't use - does not work on Windows XP */ 25#define SOCKETS_2_0 0x0002
26#define SOCKETS_2_1 0x201 26#define SOCKETS_2_1 0x0102
27#define SOCKETS_2_2 0x202 27#define SOCKETS_2_2 0x0202
28 28
29int gl_sockets_startup (int version) 29int gl_sockets_startup (int version)
30#if !WINDOWS_SOCKETS 30#ifndef WINDOWS_SOCKETS
31 _GL_ATTRIBUTE_CONST 31 _GL_ATTRIBUTE_CONST
32#endif 32#endif
33 ; 33 ;
34 34
35int gl_sockets_cleanup (void) 35int gl_sockets_cleanup (void)
36#if !WINDOWS_SOCKETS 36#ifndef WINDOWS_SOCKETS
37 _GL_ATTRIBUTE_CONST 37 _GL_ATTRIBUTE_CONST
38#endif 38#endif
39 ; 39 ;
@@ -41,11 +41,15 @@ int gl_sockets_cleanup (void)
41/* This function is useful it you create a socket using gnulib's 41/* This function is useful it you create a socket using gnulib's
42 Winsock wrappers but needs to pass on the socket handle to some 42 Winsock wrappers but needs to pass on the socket handle to some
43 other library that only accepts sockets. */ 43 other library that only accepts sockets. */
44#if WINDOWS_SOCKETS 44#ifdef WINDOWS_SOCKETS
45 45
46#include <sys/socket.h> 46# include <sys/socket.h>
47 47
48#include "msvc-nothrow.h" 48# if GNULIB_MSVC_NOTHROW
49# include "msvc-nothrow.h"
50# else
51# include <io.h>
52# endif
49 53
50static inline SOCKET 54static inline SOCKET
51gl_fd_to_handle (int fd) 55gl_fd_to_handle (int fd)
@@ -55,7 +59,7 @@ gl_fd_to_handle (int fd)
55 59
56#else 60#else
57 61
58#define gl_fd_to_handle(x) (x) 62# define gl_fd_to_handle(x) (x)
59 63
60#endif /* WINDOWS_SOCKETS */ 64#endif /* WINDOWS_SOCKETS */
61 65
diff --git a/gl/stat-time.c b/gl/stat-time.c
new file mode 100644
index 0000000..bc28223
--- /dev/null
+++ b/gl/stat-time.c
@@ -0,0 +1,21 @@
1/* stat-related time functions.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20#define _GL_STAT_TIME_INLINE _GL_EXTERN_INLINE
21#include "stat-time.h"
diff --git a/gl/stat-time.h b/gl/stat-time.h
new file mode 100644
index 0000000..92aa1e6
--- /dev/null
+++ b/gl/stat-time.h
@@ -0,0 +1,251 @@
1/* stat-related time functions.
2
3 Copyright (C) 2005, 2007, 2009-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20#ifndef STAT_TIME_H
21#define STAT_TIME_H 1
22
23#include <errno.h>
24#include <stdckdint.h>
25#include <stddef.h>
26#include <sys/stat.h>
27#include <time.h>
28
29#ifndef _GL_INLINE_HEADER_BEGIN
30 #error "Please include config.h first."
31#endif
32_GL_INLINE_HEADER_BEGIN
33#ifndef _GL_STAT_TIME_INLINE
34# define _GL_STAT_TIME_INLINE _GL_INLINE
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
42 struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
43 ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
44 if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
45 for access, status change, data modification, or birth (creation)
46 time respectively.
47
48 These macros are private to stat-time.h. */
49#if _GL_WINDOWS_STAT_TIMESPEC || defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
50# if _GL_WINDOWS_STAT_TIMESPEC || defined TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
51# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
52# else
53# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
54# endif
55#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
56# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
57#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
58# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
59#elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
60# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
61#endif
62
63/* Return the nanosecond component of *ST's access time. */
64_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
65get_stat_atime_ns (struct stat const *st)
66{
67# if defined STAT_TIMESPEC
68 return STAT_TIMESPEC (st, st_atim).tv_nsec;
69# elif defined STAT_TIMESPEC_NS
70 return STAT_TIMESPEC_NS (st, st_atim);
71# else
72 return 0;
73# endif
74}
75
76/* Return the nanosecond component of *ST's status change time. */
77_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
78get_stat_ctime_ns (struct stat const *st)
79{
80# if defined STAT_TIMESPEC
81 return STAT_TIMESPEC (st, st_ctim).tv_nsec;
82# elif defined STAT_TIMESPEC_NS
83 return STAT_TIMESPEC_NS (st, st_ctim);
84# else
85 return 0;
86# endif
87}
88
89/* Return the nanosecond component of *ST's data modification time. */
90_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
91get_stat_mtime_ns (struct stat const *st)
92{
93# if defined STAT_TIMESPEC
94 return STAT_TIMESPEC (st, st_mtim).tv_nsec;
95# elif defined STAT_TIMESPEC_NS
96 return STAT_TIMESPEC_NS (st, st_mtim);
97# else
98 return 0;
99# endif
100}
101
102/* Return the nanosecond component of *ST's birth time. */
103_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
104get_stat_birthtime_ns (_GL_UNUSED struct stat const *st)
105{
106# if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
107 return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
108# elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
109 return STAT_TIMESPEC_NS (st, st_birthtim);
110# else
111 return 0;
112# endif
113}
114
115/* Return *ST's access time. */
116_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
117get_stat_atime (struct stat const *st)
118{
119#ifdef STAT_TIMESPEC
120 return STAT_TIMESPEC (st, st_atim);
121#else
122 struct timespec t;
123 t.tv_sec = st->st_atime;
124 t.tv_nsec = get_stat_atime_ns (st);
125 return t;
126#endif
127}
128
129/* Return *ST's status change time. */
130_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
131get_stat_ctime (struct stat const *st)
132{
133#ifdef STAT_TIMESPEC
134 return STAT_TIMESPEC (st, st_ctim);
135#else
136 struct timespec t;
137 t.tv_sec = st->st_ctime;
138 t.tv_nsec = get_stat_ctime_ns (st);
139 return t;
140#endif
141}
142
143/* Return *ST's data modification time. */
144_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
145get_stat_mtime (struct stat const *st)
146{
147#ifdef STAT_TIMESPEC
148 return STAT_TIMESPEC (st, st_mtim);
149#else
150 struct timespec t;
151 t.tv_sec = st->st_mtime;
152 t.tv_nsec = get_stat_mtime_ns (st);
153 return t;
154#endif
155}
156
157/* Return *ST's birth time, if available; otherwise return a value
158 with tv_sec and tv_nsec both equal to -1. */
159_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
160get_stat_birthtime (_GL_UNUSED struct stat const *st)
161{
162 struct timespec t;
163
164#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
165 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
166 t = STAT_TIMESPEC (st, st_birthtim);
167#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
168 t.tv_sec = st->st_birthtime;
169 t.tv_nsec = st->st_birthtimensec;
170#elif defined _WIN32 && ! defined __CYGWIN__
171 /* Native Windows platforms (but not Cygwin) put the "file creation
172 time" in st_ctime (!). See
173 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions>. */
174# if _GL_WINDOWS_STAT_TIMESPEC
175 t = st->st_ctim;
176# else
177 t.tv_sec = st->st_ctime;
178 t.tv_nsec = 0;
179# endif
180#else
181 /* Birth time is not supported. */
182 t.tv_sec = -1;
183 t.tv_nsec = -1;
184#endif
185
186#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
187 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
188 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
189 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by
190 using zero. Attempt to work around this problem. Alas, this can
191 report failure even for valid timestamps. Also, NetBSD
192 sometimes returns junk in the birth time fields; work around this
193 bug if it is detected. */
194 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
195 {
196 t.tv_sec = -1;
197 t.tv_nsec = -1;
198 }
199#endif
200
201 return t;
202}
203
204/* If a stat-like function returned RESULT, normalize the timestamps
205 in *ST, in case this platform suffers from the Solaris 11 bug where
206 tv_nsec might be negative. Return the adjusted RESULT, setting
207 errno to EOVERFLOW if normalization overflowed. This function
208 is intended to be private to this .h file. */
209_GL_STAT_TIME_INLINE int
210stat_time_normalize (int result, _GL_UNUSED struct stat *st)
211{
212#if defined __sun && defined STAT_TIMESPEC
213 if (result == 0)
214 {
215 long int timespec_hz = 1000000000;
216 short int const ts_off[] = { offsetof (struct stat, st_atim),
217 offsetof (struct stat, st_mtim),
218 offsetof (struct stat, st_ctim) };
219 int i;
220 for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
221 {
222 struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]);
223 long int q = ts->tv_nsec / timespec_hz;
224 long int r = ts->tv_nsec % timespec_hz;
225 if (r < 0)
226 {
227 r += timespec_hz;
228 q--;
229 }
230 ts->tv_nsec = r;
231 /* Overflow is possible, as Solaris 11 stat can yield
232 tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000.
233 INT_ADD_WRAPV is OK, since time_t is signed on Solaris. */
234 if (ckd_add (&ts->tv_sec, q, ts->tv_sec))
235 {
236 errno = EOVERFLOW;
237 return -1;
238 }
239 }
240 }
241#endif
242 return result;
243}
244
245#ifdef __cplusplus
246}
247#endif
248
249_GL_INLINE_HEADER_END
250
251#endif
diff --git a/gl/stat-w32.c b/gl/stat-w32.c
new file mode 100644
index 0000000..2f01197
--- /dev/null
+++ b/gl/stat-w32.c
@@ -0,0 +1,460 @@
1/* Core of implementation of fstat and stat for native Windows.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible. */
18
19#include <config.h>
20
21#if defined _WIN32 && ! defined __CYGWIN__
22
23/* Attempt to make <windows.h> define FILE_ID_INFO.
24 But ensure that the redefinition of _WIN32_WINNT does not make us assume
25 Windows Vista or newer when building for an older version of Windows. */
26#if HAVE_SDKDDKVER_H
27# include <sdkddkver.h>
28# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
29# define WIN32_ASSUME_VISTA 1
30# else
31# define WIN32_ASSUME_VISTA 0
32# endif
33# if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
34# undef _WIN32_WINNT
35# define _WIN32_WINNT _WIN32_WINNT_WIN8
36# endif
37#else
38# define WIN32_ASSUME_VISTA (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
39#endif
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <errno.h>
44#include <limits.h>
45#include <string.h>
46#include <unistd.h>
47#include <windows.h>
48
49/* Specification. */
50#include "stat-w32.h"
51
52#include "pathmax.h"
53
54/* Don't assume that UNICODE is not defined. */
55#undef LoadLibrary
56#define LoadLibrary LoadLibraryA
57#undef GetFinalPathNameByHandle
58#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
59
60/* Older mingw headers do not define VOLUME_NAME_NONE. */
61#ifndef VOLUME_NAME_NONE
62# define VOLUME_NAME_NONE 4
63#endif
64
65#if !WIN32_ASSUME_VISTA
66
67/* Avoid warnings from gcc -Wcast-function-type. */
68# define GetProcAddress \
69 (void *) GetProcAddress
70
71# if _GL_WINDOWS_STAT_INODES == 2
72/* GetFileInformationByHandleEx was introduced only in Windows Vista. */
73typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile,
74 FILE_INFO_BY_HANDLE_CLASS fiClass,
75 LPVOID lpBuffer,
76 DWORD dwBufferSize);
77static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL;
78# endif
79/* GetFinalPathNameByHandle was introduced only in Windows Vista. */
80typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
81 LPSTR lpFilePath,
82 DWORD lenFilePath,
83 DWORD dwFlags);
84static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
85static BOOL initialized = FALSE;
86
87static void
88initialize (void)
89{
90 HMODULE kernel32 = LoadLibrary ("kernel32.dll");
91 if (kernel32 != NULL)
92 {
93# if _GL_WINDOWS_STAT_INODES == 2
94 GetFileInformationByHandleExFunc =
95 (GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx");
96# endif
97 GetFinalPathNameByHandleFunc =
98 (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
99 }
100 initialized = TRUE;
101}
102
103#else
104
105# define GetFileInformationByHandleExFunc GetFileInformationByHandleEx
106# define GetFinalPathNameByHandleFunc GetFinalPathNameByHandle
107
108#endif
109
110/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
111#if _GL_WINDOWS_STAT_TIMESPEC
112struct timespec
113_gl_convert_FILETIME_to_timespec (const FILETIME *ft)
114{
115 struct timespec result;
116 /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
117 unsigned long long since_1601 =
118 ((unsigned long long) ft->dwHighDateTime << 32)
119 | (unsigned long long) ft->dwLowDateTime;
120 if (since_1601 == 0)
121 {
122 result.tv_sec = 0;
123 result.tv_nsec = 0;
124 }
125 else
126 {
127 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
128 leap years, in total 134774 days. */
129 unsigned long long since_1970 =
130 since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
131 result.tv_sec = since_1970 / (unsigned long long) 10000000;
132 result.tv_nsec = (unsigned long) (since_1970 % (unsigned long long) 10000000) * 100;
133 }
134 return result;
135}
136#else
137time_t
138_gl_convert_FILETIME_to_POSIX (const FILETIME *ft)
139{
140 /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
141 unsigned long long since_1601 =
142 ((unsigned long long) ft->dwHighDateTime << 32)
143 | (unsigned long long) ft->dwLowDateTime;
144 if (since_1601 == 0)
145 return 0;
146 else
147 {
148 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
149 leap years, in total 134774 days. */
150 unsigned long long since_1970 =
151 since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
152 return since_1970 / (unsigned long long) 10000000;
153 }
154}
155#endif
156
157/* Fill *BUF with information about the file designated by H.
158 PATH is the file name, if known, otherwise NULL.
159 Return 0 if successful, or -1 with errno set upon failure. */
160int
161_gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
162{
163 /* GetFileType
164 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletype> */
165 DWORD type = GetFileType (h);
166 if (type == FILE_TYPE_DISK)
167 {
168#if !WIN32_ASSUME_VISTA
169 if (!initialized)
170 initialize ();
171#endif
172
173 /* st_mode can be determined through
174 GetFileAttributesEx
175 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
176 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
177 or through
178 GetFileInformationByHandle
179 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
180 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
181 or through
182 GetFileInformationByHandleEx with argument FileBasicInfo
183 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
184 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info>
185 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
186 BY_HANDLE_FILE_INFORMATION info;
187 if (! GetFileInformationByHandle (h, &info))
188 goto failed;
189
190 /* Test for error conditions before starting to fill *buf. */
191 if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
192 {
193 errno = EOVERFLOW;
194 return -1;
195 }
196
197#if _GL_WINDOWS_STAT_INODES
198 /* st_ino can be determined through
199 GetFileInformationByHandle
200 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
201 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
202 as 64 bits, or through
203 GetFileInformationByHandleEx with argument FileIdInfo
204 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
205 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_id_info>
206 as 128 bits.
207 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_WIN8 or higher. */
208 /* Experiments show that GetFileInformationByHandleEx does not provide
209 much more information than GetFileInformationByHandle:
210 * The dwVolumeSerialNumber from GetFileInformationByHandle is equal
211 to the low 32 bits of the 64-bit VolumeSerialNumber from
212 GetFileInformationByHandleEx, and is apparently sufficient for
213 identifying the device.
214 * The nFileIndex from GetFileInformationByHandle is equal to the low
215 64 bits of the 128-bit FileId from GetFileInformationByHandleEx,
216 and the high 64 bits of this 128-bit FileId are zero.
217 * On a FAT file system, GetFileInformationByHandleEx fails with error
218 ERROR_INVALID_PARAMETER, whereas GetFileInformationByHandle
219 succeeds.
220 * On a CIFS/SMB file system, GetFileInformationByHandleEx fails with
221 error ERROR_INVALID_LEVEL, whereas GetFileInformationByHandle
222 succeeds. */
223# if _GL_WINDOWS_STAT_INODES == 2
224 if (GetFileInformationByHandleExFunc != NULL)
225 {
226 FILE_ID_INFO id;
227 if (GetFileInformationByHandleExFunc (h, FileIdInfo, &id, sizeof (id)))
228 {
229 buf->st_dev = id.VolumeSerialNumber;
230 static_assert (sizeof (ino_t) == sizeof (id.FileId));
231 memcpy (&buf->st_ino, &id.FileId, sizeof (ino_t));
232 goto ino_done;
233 }
234 else
235 {
236 switch (GetLastError ())
237 {
238 case ERROR_INVALID_PARAMETER: /* older Windows version, or FAT */
239 case ERROR_INVALID_LEVEL: /* CIFS/SMB file system */
240 goto fallback;
241 default:
242 goto failed;
243 }
244 }
245 }
246 fallback: ;
247 /* Fallback for older Windows versions. */
248 buf->st_dev = info.dwVolumeSerialNumber;
249 buf->st_ino._gl_ino[0] = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
250 buf->st_ino._gl_ino[1] = 0;
251 ino_done: ;
252# else /* _GL_WINDOWS_STAT_INODES == 1 */
253 buf->st_dev = info.dwVolumeSerialNumber;
254 buf->st_ino = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
255# endif
256#else
257 /* st_ino is not wide enough for identifying a file on a device.
258 Without st_ino, st_dev is pointless. */
259 buf->st_dev = 0;
260 buf->st_ino = 0;
261#endif
262
263 /* st_mode. */
264 unsigned int mode =
265 /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
266 ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
267 | S_IREAD_UGO
268 | ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
269 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
270 {
271 /* Determine whether the file is executable by looking at the file
272 name suffix.
273 If the file name is already known, use it. Otherwise, for
274 non-empty files, it can be determined through
275 GetFinalPathNameByHandle
276 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea>
277 or through
278 GetFileInformationByHandleEx with argument FileNameInfo
279 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
280 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_name_info>
281 Both require -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
282 if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
283 {
284 char fpath[PATH_MAX];
285 if (path != NULL
286 || (GetFinalPathNameByHandleFunc != NULL
287 && GetFinalPathNameByHandleFunc (h, fpath, sizeof (fpath), VOLUME_NAME_NONE)
288 < sizeof (fpath)
289 && (path = fpath, 1)))
290 {
291 const char *last_dot = NULL;
292 const char *p;
293 for (p = path; *p != '\0'; p++)
294 if (*p == '.')
295 last_dot = p;
296 if (last_dot != NULL)
297 {
298 const char *suffix = last_dot + 1;
299 if (_stricmp (suffix, "exe") == 0
300 || _stricmp (suffix, "bat") == 0
301 || _stricmp (suffix, "cmd") == 0
302 || _stricmp (suffix, "com") == 0)
303 mode |= S_IEXEC_UGO;
304 }
305 }
306 else
307 /* Cannot determine file name. Pretend that it is executable. */
308 mode |= S_IEXEC_UGO;
309 }
310 }
311 buf->st_mode = mode;
312
313 /* st_nlink can be determined through
314 GetFileInformationByHandle
315 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
316 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
317 or through
318 GetFileInformationByHandleEx with argument FileStandardInfo
319 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
320 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info>
321 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
322 buf->st_nlink = (info.nNumberOfLinks > SHRT_MAX ? SHRT_MAX : info.nNumberOfLinks);
323
324 /* There's no easy way to map the Windows SID concept to an integer. */
325 buf->st_uid = 0;
326 buf->st_gid = 0;
327
328 /* st_rdev is irrelevant for normal files and directories. */
329 buf->st_rdev = 0;
330
331 /* st_size can be determined through
332 GetFileSizeEx
333 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfilesizeex>
334 or through
335 GetFileAttributesEx
336 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
337 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
338 or through
339 GetFileInformationByHandle
340 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
341 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
342 or through
343 GetFileInformationByHandleEx with argument FileStandardInfo
344 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
345 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info>
346 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
347 if (sizeof (buf->st_size) <= 4)
348 /* Range check already done above. */
349 buf->st_size = info.nFileSizeLow;
350 else
351 buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
352
353 /* st_atime, st_mtime, st_ctime can be determined through
354 GetFileTime
355 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletime>
356 or through
357 GetFileAttributesEx
358 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
359 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
360 or through
361 GetFileInformationByHandle
362 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
363 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
364 or through
365 GetFileInformationByHandleEx with argument FileBasicInfo
366 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
367 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info>
368 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
369#if _GL_WINDOWS_STAT_TIMESPEC
370 buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
371 buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
372 buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
373#else
374 buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
375 buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
376 buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
377#endif
378
379 return 0;
380 }
381 else if (type == FILE_TYPE_CHAR || type == FILE_TYPE_PIPE)
382 {
383 buf->st_dev = 0;
384#if _GL_WINDOWS_STAT_INODES == 2
385 buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
386#else
387 buf->st_ino = 0;
388#endif
389 buf->st_mode = (type == FILE_TYPE_PIPE ? _S_IFIFO : _S_IFCHR);
390 buf->st_nlink = 1;
391 buf->st_uid = 0;
392 buf->st_gid = 0;
393 buf->st_rdev = 0;
394 if (type == FILE_TYPE_PIPE)
395 {
396 /* PeekNamedPipe
397 <https://msdn.microsoft.com/en-us/library/aa365779.aspx> */
398 DWORD bytes_available;
399 if (PeekNamedPipe (h, NULL, 0, NULL, &bytes_available, NULL))
400 buf->st_size = bytes_available;
401 else
402 buf->st_size = 0;
403 }
404 else
405 buf->st_size = 0;
406#if _GL_WINDOWS_STAT_TIMESPEC
407 buf->st_atim.tv_sec = 0; buf->st_atim.tv_nsec = 0;
408 buf->st_mtim.tv_sec = 0; buf->st_mtim.tv_nsec = 0;
409 buf->st_ctim.tv_sec = 0; buf->st_ctim.tv_nsec = 0;
410#else
411 buf->st_atime = 0;
412 buf->st_mtime = 0;
413 buf->st_ctime = 0;
414#endif
415 return 0;
416 }
417 else
418 {
419 errno = ENOENT;
420 return -1;
421 }
422
423 failed:
424 {
425 DWORD error = GetLastError ();
426 #if 0
427 fprintf (stderr, "_gl_fstat_by_handle error 0x%x\n", (unsigned int) error);
428 #endif
429 switch (error)
430 {
431 case ERROR_ACCESS_DENIED:
432 case ERROR_SHARING_VIOLATION:
433 errno = EACCES;
434 break;
435
436 case ERROR_OUTOFMEMORY:
437 errno = ENOMEM;
438 break;
439
440 case ERROR_WRITE_FAULT:
441 case ERROR_READ_FAULT:
442 case ERROR_GEN_FAILURE:
443 errno = EIO;
444 break;
445
446 default:
447 errno = EINVAL;
448 break;
449 }
450 return -1;
451 }
452}
453
454#else
455
456/* This declaration is solely to ensure that after preprocessing
457 this file is never empty. */
458typedef int dummy;
459
460#endif
diff --git a/gl/stat-w32.h b/gl/stat-w32.h
new file mode 100644
index 0000000..c673874
--- /dev/null
+++ b/gl/stat-w32.h
@@ -0,0 +1,37 @@
1/* Core of implementation of fstat and stat for native Windows.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#ifndef _STAT_W32_H
18#define _STAT_W32_H 1
19
20/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
21#if _GL_WINDOWS_STAT_TIMESPEC
22extern struct timespec _gl_convert_FILETIME_to_timespec (const FILETIME *ft);
23#else
24extern time_t _gl_convert_FILETIME_to_POSIX (const FILETIME *ft);
25#endif
26
27/* Fill *BUF with information about the file designated by H.
28 PATH is the file name, if known, otherwise NULL.
29 Return 0 if successful, or -1 with errno set upon failure. */
30extern int _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf);
31
32/* Bitmasks for st_mode. */
33#define S_IREAD_UGO (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
34#define S_IWRITE_UGO (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
35#define S_IEXEC_UGO (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
36
37#endif /* _STAT_W32_H */
diff --git a/gl/stat.c b/gl/stat.c
new file mode 100644
index 0000000..7987e26
--- /dev/null
+++ b/gl/stat.c
@@ -0,0 +1,438 @@
1/* Work around platform bugs in stat.
2 Copyright (C) 2009-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Eric Blake and Bruno Haible. */
18
19/* If the user's config.h happens to include <sys/stat.h>, let it include only
20 the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
21 rpl_stat. */
22#define __need_system_sys_stat_h
23#include <config.h>
24
25/* Get the original definition of stat. It might be defined as a macro. */
26#include <sys/types.h>
27#include <sys/stat.h>
28#undef __need_system_sys_stat_h
29
30#if defined _WIN32 && ! defined __CYGWIN__
31# define WINDOWS_NATIVE
32#endif
33
34#if !defined WINDOWS_NATIVE
35
36static int
37orig_stat (const char *filename, struct stat *buf)
38{
39 return stat (filename, buf);
40}
41
42#endif
43
44/* Specification. */
45#ifdef __osf__
46/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
47 eliminates this include because of the preliminary #include <sys/stat.h>
48 above. */
49# include "sys/stat.h"
50#else
51# include <sys/stat.h>
52#endif
53
54#include "stat-time.h"
55
56#include <errno.h>
57#include <limits.h>
58#include <string.h>
59#include "filename.h"
60#include "malloca.h"
61
62#ifdef WINDOWS_NATIVE
63# define WIN32_LEAN_AND_MEAN
64# include <windows.h>
65# include "stat-w32.h"
66/* Don't assume that UNICODE is not defined. */
67# undef WIN32_FIND_DATA
68# define WIN32_FIND_DATA WIN32_FIND_DATAA
69# undef CreateFile
70# define CreateFile CreateFileA
71# undef FindFirstFile
72# define FindFirstFile FindFirstFileA
73#endif
74
75#ifdef WINDOWS_NATIVE
76/* Return TRUE if the given file name denotes an UNC root. */
77static BOOL
78is_unc_root (const char *rname)
79{
80 /* Test whether it has the syntax '\\server\share'. */
81 if (ISSLASH (rname[0]) && ISSLASH (rname[1]))
82 {
83 /* It starts with two slashes. Find the next slash. */
84 const char *p = rname + 2;
85 const char *q = p;
86 while (*q != '\0' && !ISSLASH (*q))
87 q++;
88 if (q > p && *q != '\0')
89 {
90 /* Found the next slash at q. */
91 q++;
92 const char *r = q;
93 while (*r != '\0' && !ISSLASH (*r))
94 r++;
95 if (r > q && *r == '\0')
96 return TRUE;
97 }
98 }
99 return FALSE;
100}
101#endif
102
103/* Store information about NAME into ST. Work around bugs with
104 trailing slashes. Mingw has other bugs (such as st_ino always
105 being 0 on success) which this wrapper does not work around. But
106 at least this implementation provides the ability to emulate fchdir
107 correctly. */
108
109int
110rpl_stat (char const *name, struct stat *buf)
111{
112#ifdef WINDOWS_NATIVE
113 /* Fill the fields ourselves, because the original stat function returns
114 values for st_atime, st_mtime, st_ctime that depend on the current time
115 zone. See
116 <https://lists.gnu.org/r/bug-gnulib/2017-04/msg00134.html> */
117 /* XXX Should we convert to wchar_t* and prepend '\\?\', in order to work
118 around length limitations
119 <https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file> ? */
120
121 /* POSIX <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>
122 specifies: "More than two leading <slash> characters shall be treated as
123 a single <slash> character." */
124 if (ISSLASH (name[0]) && ISSLASH (name[1]) && ISSLASH (name[2]))
125 {
126 name += 2;
127 while (ISSLASH (name[1]))
128 name++;
129 }
130
131 size_t len = strlen (name);
132 size_t drive_prefix_len = (HAS_DEVICE (name) ? 2 : 0);
133
134 /* Remove trailing slashes (except the very first one, at position
135 drive_prefix_len), but remember their presence. */
136 size_t rlen;
137 bool check_dir = false;
138
139 rlen = len;
140 while (rlen > drive_prefix_len && ISSLASH (name[rlen-1]))
141 {
142 check_dir = true;
143 if (rlen == drive_prefix_len + 1)
144 break;
145 rlen--;
146 }
147
148 /* Handle '' and 'C:'. */
149 if (!check_dir && rlen == drive_prefix_len)
150 {
151 errno = ENOENT;
152 return -1;
153 }
154
155 /* Handle '\\'. */
156 if (rlen == 1 && ISSLASH (name[0]) && len >= 2)
157 {
158 errno = ENOENT;
159 return -1;
160 }
161
162 const char *rname;
163 char *malloca_rname;
164 if (rlen == len)
165 {
166 rname = name;
167 malloca_rname = NULL;
168 }
169 else
170 {
171 malloca_rname = malloca (rlen + 1);
172 if (malloca_rname == NULL)
173 {
174 errno = ENOMEM;
175 return -1;
176 }
177 memcpy (malloca_rname, name, rlen);
178 malloca_rname[rlen] = '\0';
179 rname = malloca_rname;
180 }
181
182 /* There are two ways to get at the requested information:
183 - by scanning the parent directory and examining the relevant
184 directory entry,
185 - by opening the file directly.
186 The first approach fails for root directories (e.g. 'C:\') and
187 UNC root directories (e.g. '\\server\share').
188 The second approach fails for some system files (e.g. 'C:\pagefile.sys'
189 and 'C:\hiberfil.sys'): ERROR_SHARING_VIOLATION.
190 The second approach gives more information (in particular, correct
191 st_dev, st_ino, st_nlink fields).
192 So we use the second approach and, as a fallback except for root and
193 UNC root directories, also the first approach. */
194 {
195 int ret;
196
197 {
198 /* Approach based on the file. */
199
200 /* Open a handle to the file.
201 CreateFile
202 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createfilea>
203 <https://docs.microsoft.com/en-us/windows/desktop/FileIO/creating-and-opening-files> */
204 HANDLE h =
205 CreateFile (rname,
206 FILE_READ_ATTRIBUTES,
207 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
208 NULL,
209 OPEN_EXISTING,
210 /* FILE_FLAG_POSIX_SEMANTICS (treat file names that differ only
211 in case as different) makes sense only when applied to *all*
212 filesystem operations. */
213 FILE_FLAG_BACKUP_SEMANTICS /* | FILE_FLAG_POSIX_SEMANTICS */,
214 NULL);
215 if (h != INVALID_HANDLE_VALUE)
216 {
217 ret = _gl_fstat_by_handle (h, rname, buf);
218 CloseHandle (h);
219 goto done;
220 }
221 }
222
223 /* Test for root and UNC root directories. */
224 if ((rlen == drive_prefix_len + 1 && ISSLASH (rname[drive_prefix_len]))
225 || is_unc_root (rname))
226 goto failed;
227
228 /* Fallback. */
229 {
230 /* Approach based on the directory entry. */
231
232 if (strchr (rname, '?') != NULL || strchr (rname, '*') != NULL)
233 {
234 /* Other Windows API functions would fail with error
235 ERROR_INVALID_NAME. */
236 if (malloca_rname != NULL)
237 freea (malloca_rname);
238 errno = ENOENT;
239 return -1;
240 }
241
242 /* Get the details about the directory entry. This can be done through
243 FindFirstFile
244 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea>
245 <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-_win32_find_dataa>
246 or through
247 FindFirstFileEx with argument FindExInfoBasic
248 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfileexa>
249 <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ne-minwinbase-findex_info_levels>
250 <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-_win32_find_dataa> */
251 WIN32_FIND_DATA info;
252 HANDLE h = FindFirstFile (rname, &info);
253 if (h == INVALID_HANDLE_VALUE)
254 goto failed;
255
256 /* Test for error conditions before starting to fill *buf. */
257 if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
258 {
259 FindClose (h);
260 if (malloca_rname != NULL)
261 freea (malloca_rname);
262 errno = EOVERFLOW;
263 return -1;
264 }
265
266# if _GL_WINDOWS_STAT_INODES
267 buf->st_dev = 0;
268# if _GL_WINDOWS_STAT_INODES == 2
269 buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
270# else /* _GL_WINDOWS_STAT_INODES == 1 */
271 buf->st_ino = 0;
272# endif
273# else
274 /* st_ino is not wide enough for identifying a file on a device.
275 Without st_ino, st_dev is pointless. */
276 buf->st_dev = 0;
277 buf->st_ino = 0;
278# endif
279
280 /* st_mode. */
281 unsigned int mode =
282 /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
283 ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
284 | S_IREAD_UGO
285 | ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
286 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
287 {
288 /* Determine whether the file is executable by looking at the file
289 name suffix. */
290 if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
291 {
292 const char *last_dot = NULL;
293 const char *p;
294 for (p = info.cFileName; *p != '\0'; p++)
295 if (*p == '.')
296 last_dot = p;
297 if (last_dot != NULL)
298 {
299 const char *suffix = last_dot + 1;
300 if (_stricmp (suffix, "exe") == 0
301 || _stricmp (suffix, "bat") == 0
302 || _stricmp (suffix, "cmd") == 0
303 || _stricmp (suffix, "com") == 0)
304 mode |= S_IEXEC_UGO;
305 }
306 }
307 }
308 buf->st_mode = mode;
309
310 /* st_nlink. Ignore hard links here. */
311 buf->st_nlink = 1;
312
313 /* There's no easy way to map the Windows SID concept to an integer. */
314 buf->st_uid = 0;
315 buf->st_gid = 0;
316
317 /* st_rdev is irrelevant for normal files and directories. */
318 buf->st_rdev = 0;
319
320 /* st_size. */
321 if (sizeof (buf->st_size) <= 4)
322 /* Range check already done above. */
323 buf->st_size = info.nFileSizeLow;
324 else
325 buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
326
327 /* st_atime, st_mtime, st_ctime. */
328# if _GL_WINDOWS_STAT_TIMESPEC
329 buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
330 buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
331 buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
332# else
333 buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
334 buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
335 buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
336# endif
337
338 FindClose (h);
339
340 ret = 0;
341 }
342
343 done:
344 if (ret >= 0 && check_dir && !S_ISDIR (buf->st_mode))
345 {
346 errno = ENOTDIR;
347 ret = -1;
348 }
349 if (malloca_rname != NULL)
350 {
351 int saved_errno = errno;
352 freea (malloca_rname);
353 errno = saved_errno;
354 }
355 return ret;
356 }
357
358 failed:
359 {
360 DWORD error = GetLastError ();
361 #if 0
362 fprintf (stderr, "rpl_stat error 0x%x\n", (unsigned int) error);
363 #endif
364
365 if (malloca_rname != NULL)
366 freea (malloca_rname);
367
368 switch (error)
369 {
370 /* Some of these errors probably cannot happen with the specific flags
371 that we pass to CreateFile. But who knows... */
372 case ERROR_FILE_NOT_FOUND: /* The last component of rname does not exist. */
373 case ERROR_PATH_NOT_FOUND: /* Some directory component in rname does not exist. */
374 case ERROR_BAD_PATHNAME: /* rname is such as '\\server'. */
375 case ERROR_BAD_NET_NAME: /* rname is such as '\\server\nonexistentshare'. */
376 case ERROR_INVALID_NAME: /* rname contains wildcards, misplaced colon, etc. */
377 case ERROR_DIRECTORY:
378 errno = ENOENT;
379 break;
380
381 case ERROR_ACCESS_DENIED: /* rname is such as 'C:\System Volume Information\foo'. */
382 case ERROR_SHARING_VIOLATION: /* rname is such as 'C:\pagefile.sys' (second approach only). */
383 /* XXX map to EACCES or EPERM? */
384 errno = EACCES;
385 break;
386
387 case ERROR_OUTOFMEMORY:
388 errno = ENOMEM;
389 break;
390
391 case ERROR_WRITE_PROTECT:
392 errno = EROFS;
393 break;
394
395 case ERROR_WRITE_FAULT:
396 case ERROR_READ_FAULT:
397 case ERROR_GEN_FAILURE:
398 errno = EIO;
399 break;
400
401 case ERROR_BUFFER_OVERFLOW:
402 case ERROR_FILENAME_EXCED_RANGE:
403 errno = ENAMETOOLONG;
404 break;
405
406 case ERROR_DELETE_PENDING: /* XXX map to EACCES or EPERM? */
407 errno = EPERM;
408 break;
409
410 default:
411 errno = EINVAL;
412 break;
413 }
414
415 return -1;
416 }
417#else
418 int result = orig_stat (name, buf);
419 if (result == 0)
420 {
421# if REPLACE_FUNC_STAT_FILE
422 /* Solaris 9 mistakenly succeeds when given a non-directory with a
423 trailing slash. */
424 if (!S_ISDIR (buf->st_mode))
425 {
426 size_t len = strlen (name);
427 if (ISSLASH (name[len - 1]))
428 {
429 errno = ENOTDIR;
430 return -1;
431 }
432 }
433# endif /* REPLACE_FUNC_STAT_FILE */
434 result = stat_time_normalize (result, buf);
435 }
436 return result;
437#endif
438}
diff --git a/gl/stdalign.in.h b/gl/stdalign.in.h
index 7254a3d..7f9dbb4 100644
--- a/gl/stdalign.in.h
+++ b/gl/stdalign.in.h
@@ -1,19 +1,19 @@
1/* A substitute for ISO C11 <stdalign.h>. 1/* A substitute for ISO C11 <stdalign.h>.
2 2
3 Copyright 2011-2013 Free Software Foundation, Inc. 3 Copyright 2011-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Paul Eggert and Bruno Haible. */ 18/* Written by Paul Eggert and Bruno Haible. */
19 19
@@ -34,17 +34,15 @@
34 requirement of a structure member (i.e., slot or field) that is of 34 requirement of a structure member (i.e., slot or field) that is of
35 type TYPE, as an integer constant expression. 35 type TYPE, as an integer constant expression.
36 36
37 This differs from GCC's __alignof__ operator, which can yield a 37 This differs from GCC's and clang's __alignof__ operator, which can
38 better-performing alignment for an object of that type. For 38 yield a better-performing alignment for an object of that type. For
39 example, on x86 with GCC, __alignof__ (double) and __alignof__ 39 example, on x86 with GCC and on Linux/x86 with clang,
40 (long long) are 8, whereas alignof (double) and alignof (long long) 40 __alignof__ (double) and __alignof__ (long long) are 8, whereas
41 are 4 unless the option '-malign-double' is used. 41 alignof (double) and alignof (long long) are 4 unless the option
42 '-malign-double' is used.
42 43
43 The result cannot be used as a value for an 'enum' constant, if you 44 The result cannot be used as a value for an 'enum' constant, if you
44 want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. 45 want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */
45
46 Include <stddef.h> for offsetof. */
47#include <stddef.h>
48 46
49/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other 47/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
50 standard headers, defines conflicting implementations of _Alignas 48 standard headers, defines conflicting implementations of _Alignas
@@ -52,19 +50,33 @@
52#undef _Alignas 50#undef _Alignas
53#undef _Alignof 51#undef _Alignof
54 52
55#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 53/* GCC releases before GCC 4.9 had a bug in _Alignof. See GCC bug 52023
54 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
55 clang versions < 8.0.0 have the same bug. */
56#if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
57 || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
58 && !defined __clang__) \
59 || (defined __clang__ && __clang_major__ < 8))
56# ifdef __cplusplus 60# ifdef __cplusplus
57# if 201103 <= __cplusplus 61# if (201103 <= __cplusplus || defined _MSC_VER)
58# define _Alignof(type) alignof (type) 62# define _Alignof(type) alignof (type)
59# else 63# else
60 template <class __t> struct __alignof_helper { char __a; __t __b; }; 64 template <class __t> struct __alignof_helper { char __a; __t __b; };
61# define _Alignof(type) offsetof (__alignof_helper<type>, __b) 65# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
66# define _GL_STDALIGN_NEEDS_STDDEF 1
62# endif 67# endif
63# else 68# else
64# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) 69# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
70# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
71# else
72# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
73# define _GL_STDALIGN_NEEDS_STDDEF 1
74# endif
65# endif 75# endif
66#endif 76#endif
67#define alignof _Alignof 77#if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
78# define alignof _Alignof
79#endif
68#define __alignof_is_defined 1 80#define __alignof_is_defined 1
69 81
70/* alignas (A), also known as _Alignas (A), aligns a variable or type 82/* alignas (A), also known as _Alignas (A), aligns a variable or type
@@ -93,17 +105,33 @@
93 */ 105 */
94 106
95#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 107#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
96# if defined __cplusplus && 201103 <= __cplusplus 108# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
97# define _Alignas(a) alignas (a) 109# define _Alignas(a) alignas (a)
98# elif __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC || 0x5110 <= __SUNPRO_C 110# elif (!defined __attribute__ \
111 && ((defined __APPLE__ && defined __MACH__ \
112 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
113 : __GNUC__ && !defined __ibmxl__) \
114 || (4 <= __clang_major__) \
115 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
116 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
99# define _Alignas(a) __attribute__ ((__aligned__ (a))) 117# define _Alignas(a) __attribute__ ((__aligned__ (a)))
100# elif 1300 <= _MSC_VER 118# elif 1300 <= _MSC_VER
101# define _Alignas(a) __declspec (align (a)) 119# define _Alignas(a) __declspec (align (a))
102# endif 120# endif
103#endif 121#endif
104#if defined _Alignas || (defined __STDC_VERSION && 201112 <= __STDC_VERSION__) 122#if ((defined _Alignas \
123 && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \
124 || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
105# define alignas _Alignas 125# define alignas _Alignas
126#endif
127#if (defined alignas \
128 || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)))
106# define __alignas_is_defined 1 129# define __alignas_is_defined 1
107#endif 130#endif
108 131
132/* Include <stddef.h> if needed for offsetof. */
133#if _GL_STDALIGN_NEEDS_STDDEF
134# include <stddef.h>
135#endif
136
109#endif /* _GL_STDALIGN_H */ 137#endif /* _GL_STDALIGN_H */
diff --git a/gl/stdbool.in.h b/gl/stdbool.in.h
deleted file mode 100644
index 7c15772..0000000
--- a/gl/stdbool.in.h
+++ /dev/null
@@ -1,132 +0,0 @@
1/* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
2 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
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, see <http://www.gnu.org/licenses/>. */
16
17#ifndef _GL_STDBOOL_H
18#define _GL_STDBOOL_H
19
20/* ISO C 99 <stdbool.h> for platforms that lack it. */
21
22/* Usage suggestions:
23
24 Programs that use <stdbool.h> should be aware of some limitations
25 and standards compliance issues.
26
27 Standards compliance:
28
29 - <stdbool.h> must be #included before 'bool', 'false', 'true'
30 can be used.
31
32 - You cannot assume that sizeof (bool) == 1.
33
34 - Programs should not undefine the macros bool, true, and false,
35 as C99 lists that as an "obsolescent feature".
36
37 Limitations of this substitute, when used in a C89 environment:
38
39 - <stdbool.h> must be #included before the '_Bool' type can be used.
40
41 - You cannot assume that _Bool is a typedef; it might be a macro.
42
43 - Bit-fields of type 'bool' are not supported. Portable code
44 should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
45
46 - In C99, casts and automatic conversions to '_Bool' or 'bool' are
47 performed in such a way that every nonzero value gets converted
48 to 'true', and zero gets converted to 'false'. This doesn't work
49 with this substitute. With this substitute, only the values 0 and 1
50 give the expected result when converted to _Bool' or 'bool'.
51
52 - C99 allows the use of (_Bool)0.0 in constant expressions, but
53 this substitute cannot always provide this property.
54
55 Also, it is suggested that programs use 'bool' rather than '_Bool';
56 this isn't required, but 'bool' is more common. */
57
58
59/* 7.16. Boolean type and values */
60
61/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
62 definitions below, but temporarily we have to #undef them. */
63#if defined __BEOS__ && !defined __HAIKU__
64# include <OS.h> /* defines bool but not _Bool */
65# undef false
66# undef true
67#endif
68
69#ifdef __cplusplus
70# define _Bool bool
71# define bool bool
72#else
73# if defined __BEOS__ && !defined __HAIKU__
74 /* A compiler known to have 'bool'. */
75 /* If the compiler already has both 'bool' and '_Bool', we can assume they
76 are the same types. */
77# if !@HAVE__BOOL@
78typedef bool _Bool;
79# endif
80# else
81# if !defined __GNUC__
82 /* If @HAVE__BOOL@:
83 Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
84 the built-in _Bool type is used. See
85 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
86 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
87 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
88 Similar bugs are likely with other compilers as well; this file
89 wouldn't be used if <stdbool.h> was working.
90 So we override the _Bool type.
91 If !@HAVE__BOOL@:
92 Need to define _Bool ourselves. As 'signed char' or as an enum type?
93 Use of a typedef, with SunPRO C, leads to a stupid
94 "warning: _Bool is a keyword in ISO C99".
95 Use of an enum type, with IRIX cc, leads to a stupid
96 "warning(1185): enumerated type mixed with another type".
97 Even the existence of an enum type, without a typedef,
98 "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
99 The only benefit of the enum, debuggability, is not important
100 with these compilers. So use 'signed char' and no enum. */
101# define _Bool signed char
102# else
103 /* With this compiler, trust the _Bool type if the compiler has it. */
104# if !@HAVE__BOOL@
105 /* For the sake of symbolic names in gdb, define true and false as
106 enum constants, not only as macros.
107 It is tempting to write
108 typedef enum { false = 0, true = 1 } _Bool;
109 so that gdb prints values of type 'bool' symbolically. But then
110 values of type '_Bool' might promote to 'int' or 'unsigned int'
111 (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
112 (see ISO C 99 6.3.1.1.(2)). So add a negative value to the
113 enum; this ensures that '_Bool' promotes to 'int'. */
114typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
115# endif
116# endif
117# endif
118# define bool _Bool
119#endif
120
121/* The other macros must be usable in preprocessor directives. */
122#ifdef __cplusplus
123# define false false
124# define true true
125#else
126# define false 0
127# define true 1
128#endif
129
130#define __bool_true_false_are_defined 1
131
132#endif /* _GL_STDBOOL_H */
diff --git a/gl/stdckdint.in.h b/gl/stdckdint.in.h
new file mode 100644
index 0000000..71bab5f
--- /dev/null
+++ b/gl/stdckdint.in.h
@@ -0,0 +1,35 @@
1/* stdckdint.h -- checked integer arithmetic
2
3 Copyright 2022-2023 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _GL_STDCKDINT_H
19#define _GL_STDCKDINT_H
20
21#include "intprops-internal.h"
22
23/* Store into *R the low-order bits of A + B, A - B, A * B, respectively.
24 Return 1 if the result overflows, 0 otherwise.
25 A, B, and *R can have any integer type other than char, bool, a
26 bit-precise integer type, or an enumeration type.
27
28 These are like the standard macros introduced in C23, except that
29 arguments should not have side effects. */
30
31#define ckd_add(r, a, b) ((bool) _GL_INT_ADD_WRAPV (a, b, r))
32#define ckd_sub(r, a, b) ((bool) _GL_INT_SUBTRACT_WRAPV (a, b, r))
33#define ckd_mul(r, a, b) ((bool) _GL_INT_MULTIPLY_WRAPV (a, b, r))
34
35#endif /* _GL_STDCKDINT_H */
diff --git a/gl/stddef.in.h b/gl/stddef.in.h
index 40f0536..6eadcc3 100644
--- a/gl/stddef.in.h
+++ b/gl/stddef.in.h
@@ -1,25 +1,25 @@
1/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. 1/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
2 2
3 Copyright (C) 2009-2013 Free Software Foundation, Inc. 3 Copyright (C) 2009-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Eric Blake. */ 18/* Written by Eric Blake. */
19 19
20/* 20/*
21 * POSIX 2008 <stddef.h> for platforms that have issues. 21 * POSIX 2008 <stddef.h> for platforms that have issues.
22 * <http://www.opengroup.org/susv3xbd/stddef.h.html> 22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html>
23 */ 23 */
24 24
25#if __GNUC__ >= 3 25#if __GNUC__ >= 3
@@ -39,10 +39,16 @@
39 39
40# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) 40# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
41# ifdef __need_wint_t 41# ifdef __need_wint_t
42# undef _@GUARD_PREFIX@_STDDEF_H
43# define _GL_STDDEF_WINT_T 42# define _GL_STDDEF_WINT_T
44# endif 43# endif
45# @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 44# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
45 /* On TinyCC, make sure that the macros that indicate the special invocation
46 convention get undefined. */
47# undef __need_wchar_t
48# undef __need_size_t
49# undef __need_ptrdiff_t
50# undef __need_NULL
51# undef __need_wint_t
46# endif 52# endif
47 53
48#else 54#else
@@ -50,37 +56,92 @@
50 56
51# ifndef _@GUARD_PREFIX@_STDDEF_H 57# ifndef _@GUARD_PREFIX@_STDDEF_H
52 58
59/* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a
60 type with alignment 4, but 'long' has alignment 8. */
61# if defined _AIX && defined __LP64__
62# if !GNULIB_defined_max_align_t
63# ifdef _MAX_ALIGN_T
64/* /usr/include/stddef.h has already defined max_align_t. Override it. */
65typedef long rpl_max_align_t;
66# define max_align_t rpl_max_align_t
67# else
68/* Prevent /usr/include/stddef.h from defining max_align_t. */
69typedef long max_align_t;
70# define _MAX_ALIGN_T
71# endif
72# define GNULIB_defined_max_align_t 1
73# endif
74# endif
75
53/* The include_next requires a split double-inclusion guard. */ 76/* The include_next requires a split double-inclusion guard. */
54 77
55# @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 78# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
56 79
57# ifndef _@GUARD_PREFIX@_STDDEF_H
58# define _@GUARD_PREFIX@_STDDEF_H
59
60/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 80/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
61#if @REPLACE_NULL@ 81# if (@REPLACE_NULL@ \
62# undef NULL 82 && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T))
63# ifdef __cplusplus 83# undef NULL
84# ifdef __cplusplus
64 /* ISO C++ says that the macro NULL must expand to an integer constant 85 /* ISO C++ says that the macro NULL must expand to an integer constant
65 expression, hence '((void *) 0)' is not allowed in C++. */ 86 expression, hence '((void *) 0)' is not allowed in C++. */
66# if __GNUG__ >= 3 87# if __GNUG__ >= 3
67 /* GNU C++ has a __null macro that behaves like an integer ('int' or 88 /* GNU C++ has a __null macro that behaves like an integer ('int' or
68 'long') but has the same size as a pointer. Use that, to avoid 89 'long') but has the same size as a pointer. Use that, to avoid
69 warnings. */ 90 warnings. */
70# define NULL __null 91# define NULL __null
71# else 92# else
72# define NULL 0L 93# define NULL 0L
94# endif
95# else
96# define NULL ((void *) 0)
97# endif
73# endif 98# endif
74# else 99
75# define NULL ((void *) 0) 100# ifndef _@GUARD_PREFIX@_STDDEF_H
76# endif 101# define _@GUARD_PREFIX@_STDDEF_H
77#endif
78 102
79/* Some platforms lack wchar_t. */ 103/* Some platforms lack wchar_t. */
80#if !@HAVE_WCHAR_T@ 104#if !@HAVE_WCHAR_T@
81# define wchar_t int 105# define wchar_t int
82#endif 106#endif
83 107
108/* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is
109 a hack in case the configure-time test was done with g++ even though
110 we are currently compiling with gcc.
111 On MSVC, max_align_t is defined only in C++ mode, after <cstddef> was
112 included. Its definition is good since it has an alignment of 8 (on x86
113 and x86_64).
114 Similarly on OS/2 kLIBC. */
115#if (defined _MSC_VER || (defined __KLIBC__ && !defined __LIBCN__)) \
116 && defined __cplusplus
117# include <cstddef>
118#else
119# if ! (@HAVE_MAX_ALIGN_T@ || (defined _GCC_MAX_ALIGN_T && !defined __clang__))
120# if !GNULIB_defined_max_align_t
121/* On the x86, the maximum storage alignment of double, long, etc. is 4,
122 but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
123 and the C11 standard allows this. Work around this problem by
124 using __alignof__ (which returns 8 for double) rather than _Alignof
125 (which returns 4), and align each union member accordingly. */
126# if defined __GNUC__ || (__clang_major__ >= 4)
127# define _GL_STDDEF_ALIGNAS(type) \
128 __attribute__ ((__aligned__ (__alignof__ (type))))
129# else
130# define _GL_STDDEF_ALIGNAS(type) /* */
131# endif
132typedef union
133{
134 char *__p _GL_STDDEF_ALIGNAS (char *);
135 double __d _GL_STDDEF_ALIGNAS (double);
136 long double __ld _GL_STDDEF_ALIGNAS (long double);
137 long int __i _GL_STDDEF_ALIGNAS (long int);
138} rpl_max_align_t;
139# define max_align_t rpl_max_align_t
140# define GNULIB_defined_max_align_t 1
141# endif
142# endif
143#endif
144
84# endif /* _@GUARD_PREFIX@_STDDEF_H */ 145# endif /* _@GUARD_PREFIX@_STDDEF_H */
85# endif /* _@GUARD_PREFIX@_STDDEF_H */ 146# endif /* _@GUARD_PREFIX@_STDDEF_H */
86#endif /* __need_XXX */ 147#endif /* __need_XXX */
diff --git a/gl/stdint.in.h b/gl/stdint.in.h
index 2db8b2e..5ddc644 100644
--- a/gl/stdint.in.h
+++ b/gl/stdint.in.h
@@ -1,23 +1,23 @@
1/* Copyright (C) 2001-2002, 2004-2013 Free Software Foundation, Inc. 1/* Copyright (C) 2001-2002, 2004-2023 Free Software Foundation, Inc.
2 Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. 2 Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
3 This file is part of gnulib. 3 This file is part of gnulib.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* 18/*
19 * ISO C 99 <stdint.h> for platforms that lack it. 19 * ISO C 99 <stdint.h> for platforms that lack it.
20 * <http://www.opengroup.org/susv3xbd/stdint.h.html> 20 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html>
21 */ 21 */
22 22
23#ifndef _@GUARD_PREFIX@_STDINT_H 23#ifndef _@GUARD_PREFIX@_STDINT_H
@@ -38,8 +38,7 @@
38 other system header files; just include the system's <stdint.h>. 38 other system header files; just include the system's <stdint.h>.
39 Ideally we should test __BIONIC__ here, but it is only defined after 39 Ideally we should test __BIONIC__ here, but it is only defined after
40 <sys/cdefs.h> has been included; hence test __ANDROID__ instead. */ 40 <sys/cdefs.h> has been included; hence test __ANDROID__ instead. */
41#if defined __ANDROID__ \ 41#if defined __ANDROID__ && defined _GL_INCLUDING_SYS_TYPES_H
42 && defined _SYS_TYPES_H_ && !defined __need_size_t
43# @INCLUDE_NEXT@ @NEXT_STDINT_H@ 42# @INCLUDE_NEXT@ @NEXT_STDINT_H@
44#else 43#else
45 44
@@ -80,54 +79,65 @@
80#if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H 79#if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
81#define _@GUARD_PREFIX@_STDINT_H 80#define _@GUARD_PREFIX@_STDINT_H
82 81
82/* Get SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, INT_MIN, INT_MAX,
83 LONG_MIN, LONG_MAX, ULONG_MAX, _GL_INTEGER_WIDTH. */
84#include <limits.h>
85
86/* Override WINT_MIN and WINT_MAX if gnulib's <wchar.h> or <wctype.h> overrides
87 wint_t. */
88#if @GNULIBHEADERS_OVERRIDE_WINT_T@
89# undef WINT_MIN
90# undef WINT_MAX
91# define WINT_MIN 0x0U
92# define WINT_MAX 0xffffffffU
93#endif
94
95#if ! @HAVE_C99_STDINT_H@
96
83/* <sys/types.h> defines some of the stdint.h types as well, on glibc, 97/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
84 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>). 98 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
85 AIX 5.2 <sys/types.h> isn't needed and causes troubles. 99 AIX 5.2 <sys/types.h> isn't needed and causes troubles.
86 Mac OS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but 100 Mac OS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
87 relies on the system <stdint.h> definitions, so include 101 relies on the system <stdint.h> definitions, so include
88 <sys/types.h> after @NEXT_STDINT_H@. */ 102 <sys/types.h> after @NEXT_STDINT_H@. */
89#if @HAVE_SYS_TYPES_H@ && ! defined _AIX 103# if @HAVE_SYS_TYPES_H@ && ! defined _AIX
90# include <sys/types.h> 104# include <sys/types.h>
91#endif 105# endif
92
93/* Get SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, INT_MIN, INT_MAX,
94 LONG_MIN, LONG_MAX, ULONG_MAX. */
95#include <limits.h>
96 106
97#if @HAVE_INTTYPES_H@ 107# if @HAVE_INTTYPES_H@
98 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines 108 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
99 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. 109 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
100 <inttypes.h> also defines intptr_t and uintptr_t. */ 110 <inttypes.h> also defines intptr_t and uintptr_t. */
101# include <inttypes.h> 111# include <inttypes.h>
102#elif @HAVE_SYS_INTTYPES_H@ 112# elif @HAVE_SYS_INTTYPES_H@
103 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and 113 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
104 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ 114 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
105# include <sys/inttypes.h> 115# include <sys/inttypes.h>
106#endif 116# endif
107 117
108#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ 118# if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
109 /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines 119 /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
110 int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is 120 int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
111 included by <sys/types.h>. */ 121 included by <sys/types.h>. */
112# include <sys/bitypes.h> 122# include <sys/bitypes.h>
113#endif 123# endif
114 124
115#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H 125# undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
116 126
117/* Minimum and maximum values for an integer type under the usual assumption. 127/* Minimum and maximum values for an integer type under the usual assumption.
118 Return an unspecified value if BITS == 0, adding a check to pacify 128 Return an unspecified value if BITS == 0, adding a check to pacify
119 picky compilers. */ 129 picky compilers. */
120 130
121#define _STDINT_MIN(signed, bits, zero) \ 131/* These are separate macros, because if you try to merge these macros into
122 ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) 132 a single one, HP-UX cc rejects the resulting expression in constant
133 expressions. */
134# define _STDINT_UNSIGNED_MIN(bits, zero) \
135 (zero)
136# define _STDINT_SIGNED_MIN(bits, zero) \
137 (~ _STDINT_MAX (1, bits, zero))
123 138
124#define _STDINT_MAX(signed, bits, zero) \ 139# define _STDINT_MAX(signed, bits, zero) \
125 ((signed) \ 140 (((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
126 ? ~ _STDINT_MIN (signed, bits, zero) \
127 : /* The expression for the unsigned case. The subtraction of (signed) \
128 is a nop in the unsigned case and avoids "signed integer overflow" \
129 warnings in the signed case. */ \
130 ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
131 141
132#if !GNULIB_defined_stdint_types 142#if !GNULIB_defined_stdint_types
133 143
@@ -136,26 +146,26 @@
136/* Here we assume a standard architecture where the hardware integer 146/* Here we assume a standard architecture where the hardware integer
137 types have 8, 16, 32, optionally 64 bits. */ 147 types have 8, 16, 32, optionally 64 bits. */
138 148
139#undef int8_t 149# undef int8_t
140#undef uint8_t 150# undef uint8_t
141typedef signed char gl_int8_t; 151typedef signed char gl_int8_t;
142typedef unsigned char gl_uint8_t; 152typedef unsigned char gl_uint8_t;
143#define int8_t gl_int8_t 153# define int8_t gl_int8_t
144#define uint8_t gl_uint8_t 154# define uint8_t gl_uint8_t
145 155
146#undef int16_t 156# undef int16_t
147#undef uint16_t 157# undef uint16_t
148typedef short int gl_int16_t; 158typedef short int gl_int16_t;
149typedef unsigned short int gl_uint16_t; 159typedef unsigned short int gl_uint16_t;
150#define int16_t gl_int16_t 160# define int16_t gl_int16_t
151#define uint16_t gl_uint16_t 161# define uint16_t gl_uint16_t
152 162
153#undef int32_t 163# undef int32_t
154#undef uint32_t 164# undef uint32_t
155typedef int gl_int32_t; 165typedef int gl_int32_t;
156typedef unsigned int gl_uint32_t; 166typedef unsigned int gl_uint32_t;
157#define int32_t gl_int32_t 167# define int32_t gl_int32_t
158#define uint32_t gl_uint32_t 168# define uint32_t gl_uint32_t
159 169
160/* If the system defines INT64_MAX, assume int64_t works. That way, 170/* If the system defines INT64_MAX, assume int64_t works. That way,
161 if the underlying platform defines int64_t to be a 64-bit long long 171 if the underlying platform defines int64_t to be a 64-bit long long
@@ -163,54 +173,54 @@ typedef unsigned int gl_uint32_t;
163 int, which would mess up C++ name mangling. We must use #ifdef 173 int, which would mess up C++ name mangling. We must use #ifdef
164 rather than #if, to avoid an error with HP-UX 10.20 cc. */ 174 rather than #if, to avoid an error with HP-UX 10.20 cc. */
165 175
166#ifdef INT64_MAX 176# ifdef INT64_MAX
167# define GL_INT64_T 177# define GL_INT64_T
168#else 178# else
169/* Do not undefine int64_t if gnulib is not being used with 64-bit 179/* Do not undefine int64_t if gnulib is not being used with 64-bit
170 types, since otherwise it breaks platforms like Tandem/NSK. */ 180 types, since otherwise it breaks platforms like Tandem/NSK. */
171# if LONG_MAX >> 31 >> 31 == 1 181# if LONG_MAX >> 31 >> 31 == 1
172# undef int64_t 182# undef int64_t
173typedef long int gl_int64_t; 183typedef long int gl_int64_t;
174# define int64_t gl_int64_t 184# define int64_t gl_int64_t
175# define GL_INT64_T 185# define GL_INT64_T
176# elif defined _MSC_VER 186# elif defined _MSC_VER
177# undef int64_t 187# undef int64_t
178typedef __int64 gl_int64_t; 188typedef __int64 gl_int64_t;
179# define int64_t gl_int64_t 189# define int64_t gl_int64_t
180# define GL_INT64_T 190# define GL_INT64_T
181# elif @HAVE_LONG_LONG_INT@ 191# else
182# undef int64_t 192# undef int64_t
183typedef long long int gl_int64_t; 193typedef long long int gl_int64_t;
184# define int64_t gl_int64_t 194# define int64_t gl_int64_t
185# define GL_INT64_T 195# define GL_INT64_T
196# endif
186# endif 197# endif
187#endif
188 198
189#ifdef UINT64_MAX 199# ifdef UINT64_MAX
190# define GL_UINT64_T
191#else
192# if ULONG_MAX >> 31 >> 31 >> 1 == 1
193# undef uint64_t
194typedef unsigned long int gl_uint64_t;
195# define uint64_t gl_uint64_t
196# define GL_UINT64_T 200# define GL_UINT64_T
197# elif defined _MSC_VER 201# else
198# undef uint64_t 202# if ULONG_MAX >> 31 >> 31 >> 1 == 1
203# undef uint64_t
204typedef unsigned long int gl_uint64_t;
205# define uint64_t gl_uint64_t
206# define GL_UINT64_T
207# elif defined _MSC_VER
208# undef uint64_t
199typedef unsigned __int64 gl_uint64_t; 209typedef unsigned __int64 gl_uint64_t;
200# define uint64_t gl_uint64_t 210# define uint64_t gl_uint64_t
201# define GL_UINT64_T 211# define GL_UINT64_T
202# elif @HAVE_UNSIGNED_LONG_LONG_INT@ 212# else
203# undef uint64_t 213# undef uint64_t
204typedef unsigned long long int gl_uint64_t; 214typedef unsigned long long int gl_uint64_t;
205# define uint64_t gl_uint64_t 215# define uint64_t gl_uint64_t
206# define GL_UINT64_T 216# define GL_UINT64_T
217# endif
207# endif 218# endif
208#endif
209 219
210/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */ 220/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
211#define _UINT8_T 221# define _UINT8_T
212#define _UINT32_T 222# define _UINT32_T
213#define _UINT64_T 223# define _UINT64_T
214 224
215 225
216/* 7.18.1.2. Minimum-width integer types */ 226/* 7.18.1.2. Minimum-width integer types */
@@ -219,26 +229,26 @@ typedef unsigned long long int gl_uint64_t;
219 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types 229 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
220 are the same as the corresponding N_t types. */ 230 are the same as the corresponding N_t types. */
221 231
222#undef int_least8_t 232# undef int_least8_t
223#undef uint_least8_t 233# undef uint_least8_t
224#undef int_least16_t 234# undef int_least16_t
225#undef uint_least16_t 235# undef uint_least16_t
226#undef int_least32_t 236# undef int_least32_t
227#undef uint_least32_t 237# undef uint_least32_t
228#undef int_least64_t 238# undef int_least64_t
229#undef uint_least64_t 239# undef uint_least64_t
230#define int_least8_t int8_t 240# define int_least8_t int8_t
231#define uint_least8_t uint8_t 241# define uint_least8_t uint8_t
232#define int_least16_t int16_t 242# define int_least16_t int16_t
233#define uint_least16_t uint16_t 243# define uint_least16_t uint16_t
234#define int_least32_t int32_t 244# define int_least32_t int32_t
235#define uint_least32_t uint32_t 245# define uint_least32_t uint32_t
236#ifdef GL_INT64_T 246# ifdef GL_INT64_T
237# define int_least64_t int64_t 247# define int_least64_t int64_t
238#endif 248# endif
239#ifdef GL_UINT64_T 249# ifdef GL_UINT64_T
240# define uint_least64_t uint64_t 250# define uint_least64_t uint64_t
241#endif 251# endif
242 252
243/* 7.18.1.3. Fastest minimum-width integer types */ 253/* 7.18.1.3. Fastest minimum-width integer types */
244 254
@@ -251,50 +261,64 @@ typedef unsigned long long int gl_uint64_t;
251 uses types consistent with glibc, as that lessens the chance of 261 uses types consistent with glibc, as that lessens the chance of
252 incompatibility with older GNU hosts. */ 262 incompatibility with older GNU hosts. */
253 263
254#undef int_fast8_t 264# undef int_fast8_t
255#undef uint_fast8_t 265# undef uint_fast8_t
256#undef int_fast16_t 266# undef int_fast16_t
257#undef uint_fast16_t 267# undef uint_fast16_t
258#undef int_fast32_t 268# undef int_fast32_t
259#undef uint_fast32_t 269# undef uint_fast32_t
260#undef int_fast64_t 270# undef int_fast64_t
261#undef uint_fast64_t 271# undef uint_fast64_t
262typedef signed char gl_int_fast8_t; 272typedef signed char gl_int_fast8_t;
263typedef unsigned char gl_uint_fast8_t; 273typedef unsigned char gl_uint_fast8_t;
264 274
265#ifdef __sun 275# ifdef __sun
266/* Define types compatible with SunOS 5.10, so that code compiled under 276/* Define types compatible with SunOS 5.10, so that code compiled under
267 earlier SunOS versions works with code compiled under SunOS 5.10. */ 277 earlier SunOS versions works with code compiled under SunOS 5.10. */
268typedef int gl_int_fast32_t; 278typedef int gl_int_fast32_t;
269typedef unsigned int gl_uint_fast32_t; 279typedef unsigned int gl_uint_fast32_t;
270#else 280# else
271typedef long int gl_int_fast32_t; 281typedef long int gl_int_fast32_t;
272typedef unsigned long int gl_uint_fast32_t; 282typedef unsigned long int gl_uint_fast32_t;
273#endif 283# endif
274typedef gl_int_fast32_t gl_int_fast16_t; 284typedef gl_int_fast32_t gl_int_fast16_t;
275typedef gl_uint_fast32_t gl_uint_fast16_t; 285typedef gl_uint_fast32_t gl_uint_fast16_t;
276 286
277#define int_fast8_t gl_int_fast8_t 287# define int_fast8_t gl_int_fast8_t
278#define uint_fast8_t gl_uint_fast8_t 288# define uint_fast8_t gl_uint_fast8_t
279#define int_fast16_t gl_int_fast16_t 289# define int_fast16_t gl_int_fast16_t
280#define uint_fast16_t gl_uint_fast16_t 290# define uint_fast16_t gl_uint_fast16_t
281#define int_fast32_t gl_int_fast32_t 291# define int_fast32_t gl_int_fast32_t
282#define uint_fast32_t gl_uint_fast32_t 292# define uint_fast32_t gl_uint_fast32_t
283#ifdef GL_INT64_T 293# ifdef GL_INT64_T
284# define int_fast64_t int64_t 294# define int_fast64_t int64_t
285#endif 295# endif
286#ifdef GL_UINT64_T 296# ifdef GL_UINT64_T
287# define uint_fast64_t uint64_t 297# define uint_fast64_t uint64_t
288#endif 298# endif
289 299
290/* 7.18.1.4. Integer types capable of holding object pointers */ 300/* 7.18.1.4. Integer types capable of holding object pointers */
291 301
292#undef intptr_t 302/* kLIBC's <stdint.h> defines _INTPTR_T_DECLARED and needs its own
293#undef uintptr_t 303 definitions of intptr_t and uintptr_t (which use int and unsigned)
304 to avoid clashes with declarations of system functions like sbrk.
305 Similarly, MinGW WSL-5.4.1 <stdint.h> needs its own intptr_t and
306 uintptr_t to avoid conflicting declarations of system functions like
307 _findclose in <io.h>. */
308# if !((defined __KLIBC__ && defined _INTPTR_T_DECLARED) \
309 || defined __MINGW32__)
310# undef intptr_t
311# undef uintptr_t
312# ifdef _WIN64
313typedef long long int gl_intptr_t;
314typedef unsigned long long int gl_uintptr_t;
315# else
294typedef long int gl_intptr_t; 316typedef long int gl_intptr_t;
295typedef unsigned long int gl_uintptr_t; 317typedef unsigned long int gl_uintptr_t;
296#define intptr_t gl_intptr_t 318# endif
297#define uintptr_t gl_uintptr_t 319# define intptr_t gl_intptr_t
320# define uintptr_t gl_uintptr_t
321# endif
298 322
299/* 7.18.1.5. Greatest-width integer types */ 323/* 7.18.1.5. Greatest-width integer types */
300 324
@@ -305,33 +329,33 @@ typedef unsigned long int gl_uintptr_t;
305 similarly for UINTMAX_MAX and uintmax_t. This avoids problems with 329 similarly for UINTMAX_MAX and uintmax_t. This avoids problems with
306 assuming one type where another is used by the system. */ 330 assuming one type where another is used by the system. */
307 331
308#ifndef INTMAX_MAX 332# ifndef INTMAX_MAX
309# undef INTMAX_C 333# undef INTMAX_C
310# undef intmax_t 334# undef intmax_t
311# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 335# if LONG_MAX >> 30 == 1
312typedef long long int gl_intmax_t; 336typedef long long int gl_intmax_t;
313# define intmax_t gl_intmax_t 337# define intmax_t gl_intmax_t
314# elif defined GL_INT64_T 338# elif defined GL_INT64_T
315# define intmax_t int64_t 339# define intmax_t int64_t
316# else 340# else
317typedef long int gl_intmax_t; 341typedef long int gl_intmax_t;
318# define intmax_t gl_intmax_t 342# define intmax_t gl_intmax_t
343# endif
319# endif 344# endif
320#endif
321 345
322#ifndef UINTMAX_MAX 346# ifndef UINTMAX_MAX
323# undef UINTMAX_C 347# undef UINTMAX_C
324# undef uintmax_t 348# undef uintmax_t
325# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 349# if ULONG_MAX >> 31 == 1
326typedef unsigned long long int gl_uintmax_t; 350typedef unsigned long long int gl_uintmax_t;
327# define uintmax_t gl_uintmax_t 351# define uintmax_t gl_uintmax_t
328# elif defined GL_UINT64_T 352# elif defined GL_UINT64_T
329# define uintmax_t uint64_t 353# define uintmax_t uint64_t
330# else 354# else
331typedef unsigned long int gl_uintmax_t; 355typedef unsigned long int gl_uintmax_t;
332# define uintmax_t gl_uintmax_t 356# define uintmax_t gl_uintmax_t
357# endif
333# endif 358# endif
334#endif
335 359
336/* Verify that intmax_t and uintmax_t have the same size. Too much code 360/* Verify that intmax_t and uintmax_t have the same size. Too much code
337 breaks if this is not the case. If this check fails, the reason is likely 361 breaks if this is not the case. If this check fails, the reason is likely
@@ -339,8 +363,8 @@ typedef unsigned long int gl_uintmax_t;
339typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t) 363typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
340 ? 1 : -1]; 364 ? 1 : -1];
341 365
342#define GNULIB_defined_stdint_types 1 366# define GNULIB_defined_stdint_types 1
343#endif /* !GNULIB_defined_stdint_types */ 367# endif /* !GNULIB_defined_stdint_types */
344 368
345/* 7.18.2. Limits of specified-width integer types */ 369/* 7.18.2. Limits of specified-width integer types */
346 370
@@ -349,37 +373,37 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
349/* Here we assume a standard architecture where the hardware integer 373/* Here we assume a standard architecture where the hardware integer
350 types have 8, 16, 32, optionally 64 bits. */ 374 types have 8, 16, 32, optionally 64 bits. */
351 375
352#undef INT8_MIN 376# undef INT8_MIN
353#undef INT8_MAX 377# undef INT8_MAX
354#undef UINT8_MAX 378# undef UINT8_MAX
355#define INT8_MIN (~ INT8_MAX) 379# define INT8_MIN (~ INT8_MAX)
356#define INT8_MAX 127 380# define INT8_MAX 127
357#define UINT8_MAX 255 381# define UINT8_MAX 255
358 382
359#undef INT16_MIN 383# undef INT16_MIN
360#undef INT16_MAX 384# undef INT16_MAX
361#undef UINT16_MAX 385# undef UINT16_MAX
362#define INT16_MIN (~ INT16_MAX) 386# define INT16_MIN (~ INT16_MAX)
363#define INT16_MAX 32767 387# define INT16_MAX 32767
364#define UINT16_MAX 65535 388# define UINT16_MAX 65535
365 389
366#undef INT32_MIN 390# undef INT32_MIN
367#undef INT32_MAX 391# undef INT32_MAX
368#undef UINT32_MAX 392# undef UINT32_MAX
369#define INT32_MIN (~ INT32_MAX) 393# define INT32_MIN (~ INT32_MAX)
370#define INT32_MAX 2147483647 394# define INT32_MAX 2147483647
371#define UINT32_MAX 4294967295U 395# define UINT32_MAX 4294967295U
372 396
373#if defined GL_INT64_T && ! defined INT64_MAX 397# if defined GL_INT64_T && ! defined INT64_MAX
374/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0 398/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
375 evaluates the latter incorrectly in preprocessor expressions. */ 399 evaluates the latter incorrectly in preprocessor expressions. */
376# define INT64_MIN (- INTMAX_C (1) << 63) 400# define INT64_MIN (- INTMAX_C (1) << 63)
377# define INT64_MAX INTMAX_C (9223372036854775807) 401# define INT64_MAX INTMAX_C (9223372036854775807)
378#endif 402# endif
379 403
380#if defined GL_UINT64_T && ! defined UINT64_MAX 404# if defined GL_UINT64_T && ! defined UINT64_MAX
381# define UINT64_MAX UINTMAX_C (18446744073709551615) 405# define UINT64_MAX UINTMAX_C (18446744073709551615)
382#endif 406# endif
383 407
384/* 7.18.2.2. Limits of minimum-width integer types */ 408/* 7.18.2.2. Limits of minimum-width integer types */
385 409
@@ -387,38 +411,38 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
387 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types 411 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
388 are the same as the corresponding N_t types. */ 412 are the same as the corresponding N_t types. */
389 413
390#undef INT_LEAST8_MIN 414# undef INT_LEAST8_MIN
391#undef INT_LEAST8_MAX 415# undef INT_LEAST8_MAX
392#undef UINT_LEAST8_MAX 416# undef UINT_LEAST8_MAX
393#define INT_LEAST8_MIN INT8_MIN 417# define INT_LEAST8_MIN INT8_MIN
394#define INT_LEAST8_MAX INT8_MAX 418# define INT_LEAST8_MAX INT8_MAX
395#define UINT_LEAST8_MAX UINT8_MAX 419# define UINT_LEAST8_MAX UINT8_MAX
396 420
397#undef INT_LEAST16_MIN 421# undef INT_LEAST16_MIN
398#undef INT_LEAST16_MAX 422# undef INT_LEAST16_MAX
399#undef UINT_LEAST16_MAX 423# undef UINT_LEAST16_MAX
400#define INT_LEAST16_MIN INT16_MIN 424# define INT_LEAST16_MIN INT16_MIN
401#define INT_LEAST16_MAX INT16_MAX 425# define INT_LEAST16_MAX INT16_MAX
402#define UINT_LEAST16_MAX UINT16_MAX 426# define UINT_LEAST16_MAX UINT16_MAX
403 427
404#undef INT_LEAST32_MIN 428# undef INT_LEAST32_MIN
405#undef INT_LEAST32_MAX 429# undef INT_LEAST32_MAX
406#undef UINT_LEAST32_MAX 430# undef UINT_LEAST32_MAX
407#define INT_LEAST32_MIN INT32_MIN 431# define INT_LEAST32_MIN INT32_MIN
408#define INT_LEAST32_MAX INT32_MAX 432# define INT_LEAST32_MAX INT32_MAX
409#define UINT_LEAST32_MAX UINT32_MAX 433# define UINT_LEAST32_MAX UINT32_MAX
410 434
411#undef INT_LEAST64_MIN 435# undef INT_LEAST64_MIN
412#undef INT_LEAST64_MAX 436# undef INT_LEAST64_MAX
413#ifdef GL_INT64_T 437# ifdef GL_INT64_T
414# define INT_LEAST64_MIN INT64_MIN 438# define INT_LEAST64_MIN INT64_MIN
415# define INT_LEAST64_MAX INT64_MAX 439# define INT_LEAST64_MAX INT64_MAX
416#endif 440# endif
417 441
418#undef UINT_LEAST64_MAX 442# undef UINT_LEAST64_MAX
419#ifdef GL_UINT64_T 443# ifdef GL_UINT64_T
420# define UINT_LEAST64_MAX UINT64_MAX 444# define UINT_LEAST64_MAX UINT64_MAX
421#endif 445# endif
422 446
423/* 7.18.2.3. Limits of fastest minimum-width integer types */ 447/* 7.18.2.3. Limits of fastest minimum-width integer types */
424 448
@@ -426,117 +450,127 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
426 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types 450 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
427 are taken from the same list of types. */ 451 are taken from the same list of types. */
428 452
429#undef INT_FAST8_MIN 453# undef INT_FAST8_MIN
430#undef INT_FAST8_MAX 454# undef INT_FAST8_MAX
431#undef UINT_FAST8_MAX 455# undef UINT_FAST8_MAX
432#define INT_FAST8_MIN SCHAR_MIN 456# define INT_FAST8_MIN SCHAR_MIN
433#define INT_FAST8_MAX SCHAR_MAX 457# define INT_FAST8_MAX SCHAR_MAX
434#define UINT_FAST8_MAX UCHAR_MAX 458# define UINT_FAST8_MAX UCHAR_MAX
435 459
436#undef INT_FAST16_MIN 460# undef INT_FAST16_MIN
437#undef INT_FAST16_MAX 461# undef INT_FAST16_MAX
438#undef UINT_FAST16_MAX 462# undef UINT_FAST16_MAX
439#define INT_FAST16_MIN INT_FAST32_MIN 463# define INT_FAST16_MIN INT_FAST32_MIN
440#define INT_FAST16_MAX INT_FAST32_MAX 464# define INT_FAST16_MAX INT_FAST32_MAX
441#define UINT_FAST16_MAX UINT_FAST32_MAX 465# define UINT_FAST16_MAX UINT_FAST32_MAX
442 466
443#undef INT_FAST32_MIN 467# undef INT_FAST32_MIN
444#undef INT_FAST32_MAX 468# undef INT_FAST32_MAX
445#undef UINT_FAST32_MAX 469# undef UINT_FAST32_MAX
446#ifdef __sun 470# ifdef __sun
447# define INT_FAST32_MIN INT_MIN 471# define INT_FAST32_MIN INT_MIN
448# define INT_FAST32_MAX INT_MAX 472# define INT_FAST32_MAX INT_MAX
449# define UINT_FAST32_MAX UINT_MAX 473# define UINT_FAST32_MAX UINT_MAX
450#else 474# else
451# define INT_FAST32_MIN LONG_MIN 475# define INT_FAST32_MIN LONG_MIN
452# define INT_FAST32_MAX LONG_MAX 476# define INT_FAST32_MAX LONG_MAX
453# define UINT_FAST32_MAX ULONG_MAX 477# define UINT_FAST32_MAX ULONG_MAX
454#endif 478# endif
455 479
456#undef INT_FAST64_MIN 480# undef INT_FAST64_MIN
457#undef INT_FAST64_MAX 481# undef INT_FAST64_MAX
458#ifdef GL_INT64_T 482# ifdef GL_INT64_T
459# define INT_FAST64_MIN INT64_MIN 483# define INT_FAST64_MIN INT64_MIN
460# define INT_FAST64_MAX INT64_MAX 484# define INT_FAST64_MAX INT64_MAX
461#endif 485# endif
462 486
463#undef UINT_FAST64_MAX 487# undef UINT_FAST64_MAX
464#ifdef GL_UINT64_T 488# ifdef GL_UINT64_T
465# define UINT_FAST64_MAX UINT64_MAX 489# define UINT_FAST64_MAX UINT64_MAX
466#endif 490# endif
467 491
468/* 7.18.2.4. Limits of integer types capable of holding object pointers */ 492/* 7.18.2.4. Limits of integer types capable of holding object pointers */
469 493
470#undef INTPTR_MIN 494# undef INTPTR_MIN
471#undef INTPTR_MAX 495# undef INTPTR_MAX
472#undef UINTPTR_MAX 496# undef UINTPTR_MAX
473#define INTPTR_MIN LONG_MIN 497# ifdef _WIN64
474#define INTPTR_MAX LONG_MAX 498# define INTPTR_MIN LLONG_MIN
475#define UINTPTR_MAX ULONG_MAX 499# define INTPTR_MAX LLONG_MAX
500# define UINTPTR_MAX ULLONG_MAX
501# else
502# define INTPTR_MIN LONG_MIN
503# define INTPTR_MAX LONG_MAX
504# define UINTPTR_MAX ULONG_MAX
505# endif
476 506
477/* 7.18.2.5. Limits of greatest-width integer types */ 507/* 7.18.2.5. Limits of greatest-width integer types */
478 508
479#ifndef INTMAX_MAX 509# ifndef INTMAX_MAX
480# undef INTMAX_MIN 510# undef INTMAX_MIN
481# ifdef INT64_MAX 511# ifdef INT64_MAX
482# define INTMAX_MIN INT64_MIN 512# define INTMAX_MIN INT64_MIN
483# define INTMAX_MAX INT64_MAX 513# define INTMAX_MAX INT64_MAX
484# else 514# else
485# define INTMAX_MIN INT32_MIN 515# define INTMAX_MIN INT32_MIN
486# define INTMAX_MAX INT32_MAX 516# define INTMAX_MAX INT32_MAX
517# endif
487# endif 518# endif
488#endif
489 519
490#ifndef UINTMAX_MAX 520# ifndef UINTMAX_MAX
491# ifdef UINT64_MAX 521# ifdef UINT64_MAX
492# define UINTMAX_MAX UINT64_MAX 522# define UINTMAX_MAX UINT64_MAX
493# else 523# else
494# define UINTMAX_MAX UINT32_MAX 524# define UINTMAX_MAX UINT32_MAX
525# endif
495# endif 526# endif
496#endif
497 527
498/* 7.18.3. Limits of other integer types */ 528/* 7.18.3. Limits of other integer types */
499 529
500/* ptrdiff_t limits */ 530/* ptrdiff_t limits */
501#undef PTRDIFF_MIN 531# undef PTRDIFF_MIN
502#undef PTRDIFF_MAX 532# undef PTRDIFF_MAX
503#if @APPLE_UNIVERSAL_BUILD@ 533# if @APPLE_UNIVERSAL_BUILD@
504# ifdef _LP64 534# ifdef _LP64
505# define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l) 535# define PTRDIFF_MIN _STDINT_SIGNED_MIN (64, 0l)
506# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l) 536# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
537# else
538# define PTRDIFF_MIN _STDINT_SIGNED_MIN (32, 0)
539# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
540# endif
507# else 541# else
508# define PTRDIFF_MIN _STDINT_MIN (1, 32, 0) 542# define PTRDIFF_MIN \
509# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0) 543 _STDINT_SIGNED_MIN (@BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
510# endif 544# define PTRDIFF_MAX \
511#else
512# define PTRDIFF_MIN \
513 _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
514# define PTRDIFF_MAX \
515 _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) 545 _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
516#endif 546# endif
517 547
518/* sig_atomic_t limits */ 548/* sig_atomic_t limits */
519#undef SIG_ATOMIC_MIN 549# undef SIG_ATOMIC_MIN
520#undef SIG_ATOMIC_MAX 550# undef SIG_ATOMIC_MAX
521#define SIG_ATOMIC_MIN \ 551# if @HAVE_SIGNED_SIG_ATOMIC_T@
522 _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ 552# define SIG_ATOMIC_MIN \
523 0@SIG_ATOMIC_T_SUFFIX@) 553 _STDINT_SIGNED_MIN (@BITSIZEOF_SIG_ATOMIC_T@, 0@SIG_ATOMIC_T_SUFFIX@)
524#define SIG_ATOMIC_MAX \ 554# else
555# define SIG_ATOMIC_MIN \
556 _STDINT_UNSIGNED_MIN (@BITSIZEOF_SIG_ATOMIC_T@, 0@SIG_ATOMIC_T_SUFFIX@)
557# endif
558# define SIG_ATOMIC_MAX \
525 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ 559 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
526 0@SIG_ATOMIC_T_SUFFIX@) 560 0@SIG_ATOMIC_T_SUFFIX@)
527 561
528 562
529/* size_t limit */ 563/* size_t limit */
530#undef SIZE_MAX 564# undef SIZE_MAX
531#if @APPLE_UNIVERSAL_BUILD@ 565# if @APPLE_UNIVERSAL_BUILD@
532# ifdef _LP64 566# ifdef _LP64
533# define SIZE_MAX _STDINT_MAX (0, 64, 0ul) 567# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
568# else
569# define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
570# endif
534# else 571# else
535# define SIZE_MAX _STDINT_MAX (0, 32, 0ul) 572# define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
536# endif 573# endif
537#else
538# define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
539#endif
540 574
541/* wchar_t limits */ 575/* wchar_t limits */
542/* Get WCHAR_MIN, WCHAR_MAX. 576/* Get WCHAR_MIN, WCHAR_MAX.
@@ -544,30 +578,39 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
544 sequence of nested includes 578 sequence of nested includes
545 <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes 579 <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
546 <stdint.h> and assumes its types are already defined. */ 580 <stdint.h> and assumes its types are already defined. */
547#if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX) 581# if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
548 /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be 582# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
549 included before <wchar.h>. */ 583# include <wchar.h>
550# include <stddef.h> 584# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
551# include <stdio.h> 585# endif
552# include <time.h> 586# undef WCHAR_MIN
553# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H 587# undef WCHAR_MAX
554# include <wchar.h> 588# if @HAVE_SIGNED_WCHAR_T@
555# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H 589# define WCHAR_MIN \
556#endif 590 _STDINT_SIGNED_MIN (@BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
557#undef WCHAR_MIN 591# else
558#undef WCHAR_MAX 592# define WCHAR_MIN \
559#define WCHAR_MIN \ 593 _STDINT_UNSIGNED_MIN (@BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
560 _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) 594# endif
561#define WCHAR_MAX \ 595# define WCHAR_MAX \
562 _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) 596 _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
563 597
564/* wint_t limits */ 598/* wint_t limits */
565#undef WINT_MIN 599/* If gnulib's <wchar.h> or <wctype.h> overrides wint_t, @WINT_T_SUFFIX@ is not
566#undef WINT_MAX 600 accurate, therefore use the definitions from above. */
567#define WINT_MIN \ 601# if !@GNULIBHEADERS_OVERRIDE_WINT_T@
568 _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) 602# undef WINT_MIN
569#define WINT_MAX \ 603# undef WINT_MAX
570 _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) 604# if @HAVE_SIGNED_WINT_T@
605# define WINT_MIN \
606 _STDINT_SIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
607# else
608# define WINT_MIN \
609 _STDINT_UNSIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
610# endif
611# define WINT_MAX \
612 _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
613# endif
571 614
572/* 7.18.4. Macros for integer constants */ 615/* 7.18.4. Macros for integer constants */
573 616
@@ -577,59 +620,120 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
577/* Here we assume a standard architecture where the hardware integer 620/* Here we assume a standard architecture where the hardware integer
578 types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ 621 types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
579 622
580#undef INT8_C 623# undef INT8_C
581#undef UINT8_C 624# undef UINT8_C
582#define INT8_C(x) x 625# define INT8_C(x) x
583#define UINT8_C(x) x 626# define UINT8_C(x) x
584
585#undef INT16_C
586#undef UINT16_C
587#define INT16_C(x) x
588#define UINT16_C(x) x
589
590#undef INT32_C
591#undef UINT32_C
592#define INT32_C(x) x
593#define UINT32_C(x) x ## U
594
595#undef INT64_C
596#undef UINT64_C
597#if LONG_MAX >> 31 >> 31 == 1
598# define INT64_C(x) x##L
599#elif defined _MSC_VER
600# define INT64_C(x) x##i64
601#elif @HAVE_LONG_LONG_INT@
602# define INT64_C(x) x##LL
603#endif
604#if ULONG_MAX >> 31 >> 31 >> 1 == 1
605# define UINT64_C(x) x##UL
606#elif defined _MSC_VER
607# define UINT64_C(x) x##ui64
608#elif @HAVE_UNSIGNED_LONG_LONG_INT@
609# define UINT64_C(x) x##ULL
610#endif
611 627
612/* 7.18.4.2. Macros for greatest-width integer constants */ 628# undef INT16_C
629# undef UINT16_C
630# define INT16_C(x) x
631# define UINT16_C(x) x
632
633# undef INT32_C
634# undef UINT32_C
635# define INT32_C(x) x
636# define UINT32_C(x) x ## U
613 637
614#ifndef INTMAX_C 638# undef INT64_C
615# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 639# undef UINT64_C
616# define INTMAX_C(x) x##LL 640# if LONG_MAX >> 31 >> 31 == 1
617# elif defined GL_INT64_T 641# define INT64_C(x) x##L
618# define INTMAX_C(x) INT64_C(x) 642# elif defined _MSC_VER
643# define INT64_C(x) x##i64
619# else 644# else
620# define INTMAX_C(x) x##L 645# define INT64_C(x) x##LL
621# endif 646# endif
622#endif 647# if ULONG_MAX >> 31 >> 31 >> 1 == 1
623 648# define UINT64_C(x) x##UL
624#ifndef UINTMAX_C 649# elif defined _MSC_VER
625# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 650# define UINT64_C(x) x##ui64
626# define UINTMAX_C(x) x##ULL
627# elif defined GL_UINT64_T
628# define UINTMAX_C(x) UINT64_C(x)
629# else 651# else
630# define UINTMAX_C(x) x##UL 652# define UINT64_C(x) x##ULL
631# endif 653# endif
632#endif 654
655/* 7.18.4.2. Macros for greatest-width integer constants */
656
657# ifndef INTMAX_C
658# if LONG_MAX >> 30 == 1
659# define INTMAX_C(x) x##LL
660# elif defined GL_INT64_T
661# define INTMAX_C(x) INT64_C(x)
662# else
663# define INTMAX_C(x) x##L
664# endif
665# endif
666
667# ifndef UINTMAX_C
668# if ULONG_MAX >> 31 == 1
669# define UINTMAX_C(x) x##ULL
670# elif defined GL_UINT64_T
671# define UINTMAX_C(x) UINT64_C(x)
672# else
673# define UINTMAX_C(x) x##UL
674# endif
675# endif
676
677#endif /* !@HAVE_C99_STDINT_H@ */
678
679/* Macros specified by ISO/IEC TS 18661-1:2014. */
680
681#if (!defined UINTMAX_WIDTH \
682 && (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__))
683# ifdef INT8_MAX
684# define INT8_WIDTH _GL_INTEGER_WIDTH (INT8_MIN, INT8_MAX)
685# endif
686# ifdef UINT8_MAX
687# define UINT8_WIDTH _GL_INTEGER_WIDTH (0, UINT8_MAX)
688# endif
689# ifdef INT16_MAX
690# define INT16_WIDTH _GL_INTEGER_WIDTH (INT16_MIN, INT16_MAX)
691# endif
692# ifdef UINT16_MAX
693# define UINT16_WIDTH _GL_INTEGER_WIDTH (0, UINT16_MAX)
694# endif
695# ifdef INT32_MAX
696# define INT32_WIDTH _GL_INTEGER_WIDTH (INT32_MIN, INT32_MAX)
697# endif
698# ifdef UINT32_MAX
699# define UINT32_WIDTH _GL_INTEGER_WIDTH (0, UINT32_MAX)
700# endif
701# ifdef INT64_MAX
702# define INT64_WIDTH _GL_INTEGER_WIDTH (INT64_MIN, INT64_MAX)
703# endif
704# ifdef UINT64_MAX
705# define UINT64_WIDTH _GL_INTEGER_WIDTH (0, UINT64_MAX)
706# endif
707# define INT_LEAST8_WIDTH _GL_INTEGER_WIDTH (INT_LEAST8_MIN, INT_LEAST8_MAX)
708# define UINT_LEAST8_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST8_MAX)
709# define INT_LEAST16_WIDTH _GL_INTEGER_WIDTH (INT_LEAST16_MIN, INT_LEAST16_MAX)
710# define UINT_LEAST16_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST16_MAX)
711# define INT_LEAST32_WIDTH _GL_INTEGER_WIDTH (INT_LEAST32_MIN, INT_LEAST32_MAX)
712# define UINT_LEAST32_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST32_MAX)
713# define INT_LEAST64_WIDTH _GL_INTEGER_WIDTH (INT_LEAST64_MIN, INT_LEAST64_MAX)
714# define UINT_LEAST64_WIDTH _GL_INTEGER_WIDTH (0, UINT_LEAST64_MAX)
715# define INT_FAST8_WIDTH _GL_INTEGER_WIDTH (INT_FAST8_MIN, INT_FAST8_MAX)
716# define UINT_FAST8_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST8_MAX)
717# define INT_FAST16_WIDTH _GL_INTEGER_WIDTH (INT_FAST16_MIN, INT_FAST16_MAX)
718# define UINT_FAST16_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST16_MAX)
719# define INT_FAST32_WIDTH _GL_INTEGER_WIDTH (INT_FAST32_MIN, INT_FAST32_MAX)
720# define UINT_FAST32_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST32_MAX)
721# define INT_FAST64_WIDTH _GL_INTEGER_WIDTH (INT_FAST64_MIN, INT_FAST64_MAX)
722# define UINT_FAST64_WIDTH _GL_INTEGER_WIDTH (0, UINT_FAST64_MAX)
723# define INTPTR_WIDTH _GL_INTEGER_WIDTH (INTPTR_MIN, INTPTR_MAX)
724# define UINTPTR_WIDTH _GL_INTEGER_WIDTH (0, UINTPTR_MAX)
725# define INTMAX_WIDTH _GL_INTEGER_WIDTH (INTMAX_MIN, INTMAX_MAX)
726# define UINTMAX_WIDTH _GL_INTEGER_WIDTH (0, UINTMAX_MAX)
727# define PTRDIFF_WIDTH _GL_INTEGER_WIDTH (PTRDIFF_MIN, PTRDIFF_MAX)
728# define SIZE_WIDTH _GL_INTEGER_WIDTH (0, SIZE_MAX)
729# define WCHAR_WIDTH _GL_INTEGER_WIDTH (WCHAR_MIN, WCHAR_MAX)
730# ifdef WINT_MAX
731# define WINT_WIDTH _GL_INTEGER_WIDTH (WINT_MIN, WINT_MAX)
732# endif
733# ifdef SIG_ATOMIC_MAX
734# define SIG_ATOMIC_WIDTH _GL_INTEGER_WIDTH (SIG_ATOMIC_MIN, SIG_ATOMIC_MAX)
735# endif
736#endif /* !WINT_WIDTH && (_GNU_SOURCE || __STDC_WANT_IEC_60559_BFP_EXT__) */
633 737
634#endif /* _@GUARD_PREFIX@_STDINT_H */ 738#endif /* _@GUARD_PREFIX@_STDINT_H */
635#endif /* !(defined __ANDROID__ && ...) */ 739#endif /* !(defined __ANDROID__ && ...) */
diff --git a/gl/stdio-impl.h b/gl/stdio-impl.h
new file mode 100644
index 0000000..46608be
--- /dev/null
+++ b/gl/stdio-impl.h
@@ -0,0 +1,218 @@
1/* Implementation details of FILE streams.
2 Copyright (C) 2007-2008, 2010-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Many stdio implementations have the same logic and therefore can share
18 the same implementation of stdio extension API, except that some fields
19 have different naming conventions, or their access requires some casts. */
20
21/* Glibc 2.28 made _IO_UNBUFFERED and _IO_IN_BACKUP private. For now, work
22 around this problem by defining them ourselves. FIXME: Do not rely on glibc
23 internals. */
24#if defined _IO_EOF_SEEN
25# if !defined _IO_UNBUFFERED
26# define _IO_UNBUFFERED 0x2
27# endif
28# if !defined _IO_IN_BACKUP
29# define _IO_IN_BACKUP 0x100
30# endif
31#endif
32
33/* BSD stdio derived implementations. */
34
35#if defined __NetBSD__ /* NetBSD */
36/* Get __NetBSD_Version__. */
37# include <sys/param.h>
38#endif
39
40#include <errno.h> /* For detecting Plan9. */
41
42#if defined __sferror || defined __DragonFly__ || defined __ANDROID__
43 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
44
45# if defined __DragonFly__ /* DragonFly */
46 /* See <https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/lib/libc/stdio/priv_stdio.h>. */
47# define fp_ ((struct { struct __FILE_public pub; \
48 struct { unsigned char *_base; int _size; } _bf; \
49 void *cookie; \
50 void *_close; \
51 void *_read; \
52 void *_seek; \
53 void *_write; \
54 struct { unsigned char *_base; int _size; } _ub; \
55 int _ur; \
56 unsigned char _ubuf[3]; \
57 unsigned char _nbuf[1]; \
58 struct { unsigned char *_base; int _size; } _lb; \
59 int _blksize; \
60 fpos_t _offset; \
61 /* More fields, not relevant here. */ \
62 } *) fp)
63 /* See <https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/include/stdio.h>. */
64# define _p pub._p
65# define _flags pub._flags
66# define _r pub._r
67# define _w pub._w
68# elif defined __ANDROID__ /* Android */
69# ifdef __LP64__
70# define _gl_flags_file_t int
71# else
72# define _gl_flags_file_t short
73# endif
74# ifdef __LP64__
75# define _gl_file_offset_t int64_t
76# else
77 /* see https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
78# define _gl_file_offset_t __kernel_off_t
79# endif
80 /* Up to this commit from 2015-10-12
81 <https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a>
82 the innards of FILE were public, and fp_ub could be defined like for OpenBSD,
83 see <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/fileext.h>
84 and <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/local.h>.
85 After this commit, the innards of FILE are hidden. */
86# define fp_ ((struct { unsigned char *_p; \
87 int _r; \
88 int _w; \
89 _gl_flags_file_t _flags; \
90 _gl_flags_file_t _file; \
91 struct { unsigned char *_base; size_t _size; } _bf; \
92 int _lbfsize; \
93 void *_cookie; \
94 void *_close; \
95 void *_read; \
96 void *_seek; \
97 void *_write; \
98 struct { unsigned char *_base; size_t _size; } _ext; \
99 unsigned char *_up; \
100 int _ur; \
101 unsigned char _ubuf[3]; \
102 unsigned char _nbuf[1]; \
103 struct { unsigned char *_base; size_t _size; } _lb; \
104 int _blksize; \
105 _gl_file_offset_t _offset; \
106 /* More fields, not relevant here. */ \
107 } *) fp)
108# else
109# define fp_ fp
110# endif
111
112# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix /* NetBSD >= 1.5ZA, OpenBSD, Minix 3 */
113 /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
114 and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
115 and <https://github.com/Stichting-MINIX-Research-Foundation/minix/blob/master/lib/libc/stdio/fileext.h> */
116 struct __sfileext
117 {
118 struct __sbuf _ub; /* ungetc buffer */
119 /* More fields, not relevant here. */
120 };
121# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
122# elif defined __ANDROID__ /* Android */
123 struct __sfileext
124 {
125 struct { unsigned char *_base; size_t _size; } _ub; /* ungetc buffer */
126 /* More fields, not relevant here. */
127 };
128# define fp_ub ((struct __sfileext *) fp_->_ext._base)->_ub
129# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
130# define fp_ub fp_->_ub
131# endif
132
133# define HASUB(fp) (fp_ub._base != NULL)
134
135# if defined __ANDROID__ /* Android */
136 /* Needed after this commit from 2016-01-25
137 <https://android.googlesource.com/platform/bionic.git/+/e70e0e9267d069bf56a5078c99307e08a7280de7> */
138# ifndef __SEOF
139# define __SLBF 1
140# define __SNBF 2
141# define __SRD 4
142# define __SWR 8
143# define __SRW 0x10
144# define __SEOF 0x20
145# define __SERR 0x40
146# endif
147# ifndef __SOFF
148# define __SOFF 0x1000
149# endif
150# endif
151
152#endif
153
154
155/* SystemV derived implementations. */
156
157#ifdef __TANDEM /* NonStop Kernel */
158# ifndef _IOERR
159/* These values were determined by the program 'stdioext-flags' at
160 <https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */
161# define _IOERR 0x40
162# define _IOREAD 0x80
163# define _IOWRT 0x4
164# define _IORW 0x100
165# endif
166#endif
167
168#if defined _IOERR
169
170# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
171# define fp_ ((struct { unsigned char *_ptr; \
172 unsigned char *_base; \
173 unsigned char *_end; \
174 long _cnt; \
175 int _file; \
176 unsigned int _flag; \
177 } *) fp)
178# elif defined __VMS /* OpenVMS */
179# define fp_ ((struct _iobuf *) fp)
180# else
181# define fp_ fp
182# endif
183
184# if defined _SCO_DS || (defined __SCO_VERSION__ || defined __sysv5__) /* OpenServer 5, OpenServer 6, UnixWare 7 */
185# define _cnt __cnt
186# define _ptr __ptr
187# define _base __base
188# define _flag __flag
189# endif
190
191#elif defined _WIN32 && ! defined __CYGWIN__ /* newer Windows with MSVC */
192
193/* <stdio.h> does not define the innards of FILE any more. */
194# define WINDOWS_OPAQUE_FILE
195
196struct _gl_real_FILE
197{
198 /* Note: Compared to older Windows and to mingw, it has the fields
199 _base and _cnt swapped. */
200 unsigned char *_ptr;
201 unsigned char *_base;
202 int _cnt;
203 int _flag;
204 int _file;
205 int _charbuf;
206 int _bufsiz;
207};
208# define fp_ ((struct _gl_real_FILE *) fp)
209
210/* These values were determined by a program similar to the one at
211 <https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */
212# define _IOREAD 0x1
213# define _IOWRT 0x2
214# define _IORW 0x4
215# define _IOEOF 0x8
216# define _IOERR 0x10
217
218#endif
diff --git a/gl/stdio-read.c b/gl/stdio-read.c
new file mode 100644
index 0000000..6e2984c
--- /dev/null
+++ b/gl/stdio-read.c
@@ -0,0 +1,168 @@
1/* POSIX compatible FILE stream read function.
2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#include <stdio.h>
22
23/* Replace these functions only if module 'nonblocking' is requested. */
24#if GNULIB_NONBLOCKING
25
26/* On native Windows platforms, when read() is called on a non-blocking pipe
27 with an empty buffer, ReadFile() fails with error GetLastError() =
28 ERROR_NO_DATA, and read() in consequence fails with error EINVAL. This
29 read() function is at the basis of the function which fills the buffer of
30 a FILE stream. */
31
32# if defined _WIN32 && ! defined __CYGWIN__
33
34# include <errno.h>
35# include <io.h>
36
37# define WIN32_LEAN_AND_MEAN /* avoid including junk */
38# include <windows.h>
39
40# if GNULIB_MSVC_NOTHROW
41# include "msvc-nothrow.h"
42# else
43# include <io.h>
44# endif
45
46/* Don't assume that UNICODE is not defined. */
47# undef GetNamedPipeHandleState
48# define GetNamedPipeHandleState GetNamedPipeHandleStateA
49
50# define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \
51 if (ferror (stream)) \
52 return (EXPRESSION); \
53 else \
54 { \
55 RETTYPE ret; \
56 SetLastError (0); \
57 ret = (EXPRESSION); \
58 if (FAILED) \
59 { \
60 if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
61 { \
62 int fd = fileno (stream); \
63 if (fd >= 0) \
64 { \
65 HANDLE h = (HANDLE) _get_osfhandle (fd); \
66 if (GetFileType (h) == FILE_TYPE_PIPE) \
67 { \
68 /* h is a pipe or socket. */ \
69 DWORD state; \
70 if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
71 NULL, NULL, 0) \
72 && (state & PIPE_NOWAIT) != 0) \
73 /* h is a pipe in non-blocking mode. \
74 Change errno from EINVAL to EAGAIN. */ \
75 errno = EAGAIN; \
76 } \
77 } \
78 } \
79 } \
80 return ret; \
81 }
82
83/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
84 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
85# if GNULIB_SCANF
86int
87scanf (const char *format, ...)
88{
89 int retval;
90 va_list args;
91
92 va_start (args, format);
93 retval = vfscanf (stdin, format, args);
94 va_end (args);
95
96 return retval;
97}
98# endif
99
100/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
101 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
102# if GNULIB_FSCANF
103int
104fscanf (FILE *stream, const char *format, ...)
105{
106 int retval;
107 va_list args;
108
109 va_start (args, format);
110 retval = vfscanf (stream, format, args);
111 va_end (args);
112
113 return retval;
114}
115# endif
116
117/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
118 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
119# if GNULIB_VSCANF
120int
121vscanf (const char *format, va_list args)
122{
123 return vfscanf (stdin, format, args);
124}
125# endif
126
127/* Enable this function definition only if gnulib's <stdio.h> has prepared it.
128 Otherwise we get a function definition conflict with mingw64's <stdio.h>. */
129# if GNULIB_VFSCANF
130int
131vfscanf (FILE *stream, const char *format, va_list args)
132#undef vfscanf
133{
134 CALL_WITH_ERRNO_FIX (int, vfscanf (stream, format, args), ret == EOF)
135}
136# endif
137
138int
139getchar (void)
140{
141 return fgetc (stdin);
142}
143
144int
145fgetc (FILE *stream)
146#undef fgetc
147{
148 CALL_WITH_ERRNO_FIX (int, fgetc (stream), ret == EOF)
149}
150
151char *
152fgets (char *s, int n, FILE *stream)
153#undef fgets
154{
155 CALL_WITH_ERRNO_FIX (char *, fgets (s, n, stream), ret == NULL)
156}
157
158/* We intentionally don't bother to fix gets. */
159
160size_t
161fread (void *ptr, size_t s, size_t n, FILE *stream)
162#undef fread
163{
164 CALL_WITH_ERRNO_FIX (size_t, fread (ptr, s, n, stream), ret < n)
165}
166
167# endif
168#endif
diff --git a/gl/stdio-write.c b/gl/stdio-write.c
new file mode 100644
index 0000000..9cf36cc
--- /dev/null
+++ b/gl/stdio-write.c
@@ -0,0 +1,206 @@
1/* POSIX compatible FILE stream write function.
2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#include <stdio.h>
22
23/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
24 requested. */
25#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
26
27/* On native Windows platforms, SIGPIPE does not exist. When write() is
28 called on a pipe with no readers, WriteFile() fails with error
29 GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
30 error EINVAL. This write() function is at the basis of the function
31 which flushes the buffer of a FILE stream. */
32
33# if defined _WIN32 && ! defined __CYGWIN__
34
35# include <errno.h>
36# include <signal.h>
37# include <io.h>
38
39# define WIN32_LEAN_AND_MEAN /* avoid including junk */
40# include <windows.h>
41
42# if GNULIB_MSVC_NOTHROW
43# include "msvc-nothrow.h"
44# else
45# include <io.h>
46# endif
47
48/* Don't assume that UNICODE is not defined. */
49# undef GetNamedPipeHandleState
50# define GetNamedPipeHandleState GetNamedPipeHandleStateA
51
52# if GNULIB_NONBLOCKING
53# define CLEAR_ERRNO \
54 errno = 0;
55# define HANDLE_ENOSPC \
56 if (errno == ENOSPC && ferror (stream)) \
57 { \
58 int fd = fileno (stream); \
59 if (fd >= 0) \
60 { \
61 HANDLE h = (HANDLE) _get_osfhandle (fd); \
62 if (GetFileType (h) == FILE_TYPE_PIPE) \
63 { \
64 /* h is a pipe or socket. */ \
65 DWORD state; \
66 if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
67 NULL, NULL, 0) \
68 && (state & PIPE_NOWAIT) != 0) \
69 /* h is a pipe in non-blocking mode. \
70 Change errno from ENOSPC to EAGAIN. */ \
71 errno = EAGAIN; \
72 } \
73 } \
74 } \
75 else
76# else
77# define CLEAR_ERRNO
78# define HANDLE_ENOSPC
79# endif
80
81# if GNULIB_SIGPIPE
82# define CLEAR_LastError \
83 SetLastError (0);
84# define HANDLE_ERROR_NO_DATA \
85 if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
86 { \
87 int fd = fileno (stream); \
88 if (fd >= 0 \
89 && GetFileType ((HANDLE) _get_osfhandle (fd)) \
90 == FILE_TYPE_PIPE) \
91 { \
92 /* Try to raise signal SIGPIPE. */ \
93 raise (SIGPIPE); \
94 /* If it is currently blocked or ignored, change errno from \
95 EINVAL to EPIPE. */ \
96 errno = EPIPE; \
97 } \
98 } \
99 else
100# else
101# define CLEAR_LastError
102# define HANDLE_ERROR_NO_DATA
103# endif
104
105# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
106 if (ferror (stream)) \
107 return (EXPRESSION); \
108 else \
109 { \
110 RETTYPE ret; \
111 CLEAR_ERRNO \
112 CLEAR_LastError \
113 ret = (EXPRESSION); \
114 if (FAILED) \
115 { \
116 HANDLE_ENOSPC \
117 HANDLE_ERROR_NO_DATA \
118 ; \
119 } \
120 return ret; \
121 }
122
123# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
124int
125printf (const char *format, ...)
126{
127 int retval;
128 va_list args;
129
130 va_start (args, format);
131 retval = vfprintf (stdout, format, args);
132 va_end (args);
133
134 return retval;
135}
136# endif
137
138# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
139int
140fprintf (FILE *stream, const char *format, ...)
141{
142 int retval;
143 va_list args;
144
145 va_start (args, format);
146 retval = vfprintf (stream, format, args);
147 va_end (args);
148
149 return retval;
150}
151# endif
152
153# if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
154int
155vprintf (const char *format, va_list args)
156{
157 return vfprintf (stdout, format, args);
158}
159# endif
160
161# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
162int
163vfprintf (FILE *stream, const char *format, va_list args)
164#undef vfprintf
165{
166 CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
167}
168# endif
169
170int
171putchar (int c)
172{
173 return fputc (c, stdout);
174}
175
176int
177fputc (int c, FILE *stream)
178#undef fputc
179{
180 CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
181}
182
183int
184fputs (const char *string, FILE *stream)
185#undef fputs
186{
187 CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
188}
189
190int
191puts (const char *string)
192#undef puts
193{
194 FILE *stream = stdout;
195 CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
196}
197
198size_t
199fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
200#undef fwrite
201{
202 CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
203}
204
205# endif
206#endif
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index 06cbad0..59cbea3 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -1,19 +1,19 @@
1/* A GNU-like <stdio.h>. 1/* A GNU-like <stdio.h>.
2 2
3 Copyright (C) 2004, 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#if __GNUC__ >= 3 18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@ 19@PRAGMA_SYSTEM_HEADER@
@@ -56,36 +56,103 @@
56 May also define off_t to a 64-bit type on native Windows. */ 56 May also define off_t to a 64-bit type on native Windows. */
57#include <sys/types.h> 57#include <sys/types.h>
58 58
59/* Solaris 10 and NetBSD 7.0 declare renameat in <unistd.h>, not in <stdio.h>. */
60/* But in any case avoid namespace pollution on glibc systems. */
61#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && (defined __sun || defined __NetBSD__) \
62 && ! defined __GLIBC__
63# include <unistd.h>
64#endif
65
66/* Android 4.3 declares renameat in <sys/stat.h>, not in <stdio.h>. */
67/* But in any case avoid namespace pollution on glibc systems. */
68#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
69 && ! defined __GLIBC__
70# include <sys/stat.h>
71#endif
72
73/* MSVC declares 'perror' in <stdlib.h>, not in <stdio.h>. We must include
74 it before we #define perror rpl_perror. */
75/* But in any case avoid namespace pollution on glibc systems. */
76#if (@GNULIB_PERROR@ || defined GNULIB_POSIXCHECK) \
77 && (defined _WIN32 && ! defined __CYGWIN__) \
78 && ! defined __GLIBC__
79# include <stdlib.h>
80#endif
81
82/* MSVC declares 'remove' in <io.h>, not in <stdio.h>. We must include
83 it before we #define remove rpl_remove. */
84/* MSVC declares 'rename' in <io.h>, not in <stdio.h>. We must include
85 it before we #define rename rpl_rename. */
86/* But in any case avoid namespace pollution on glibc systems. */
87#if (@GNULIB_REMOVE@ || @GNULIB_RENAME@ || defined GNULIB_POSIXCHECK) \
88 && (defined _WIN32 && ! defined __CYGWIN__) \
89 && ! defined __GLIBC__
90# include <io.h>
91#endif
92
93
94/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
95 that can be freed by passing them as the Ith argument to the
96 function F. */
97#ifndef _GL_ATTRIBUTE_DEALLOC
98# if __GNUC__ >= 11
99# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
100# else
101# define _GL_ATTRIBUTE_DEALLOC(f, i)
102# endif
103#endif
104
59/* The __attribute__ feature is available in gcc versions 2.5 and later. 105/* The __attribute__ feature is available in gcc versions 2.5 and later.
60 The __-protected variants of the attributes 'format' and 'printf' are 106 The __-protected variants of the attributes 'format' and 'printf' are
61 accepted by gcc versions 2.6.4 (effectively 2.7) and later. 107 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
62 We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because 108 We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
63 gnulib and libintl do '#define printf __printf__' when they override 109 gnulib and libintl do '#define printf __printf__' when they override
64 the 'printf' function. */ 110 the 'printf' function. */
65#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 111#ifndef _GL_ATTRIBUTE_FORMAT
66# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) 112# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__
113# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
114# else
115# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
116# endif
117#endif
118
119/* An __attribute__ __format__ specifier for a function that takes a format
120 string and arguments, where the format string directives are the ones
121 standardized by ISO C99 and POSIX.
122 _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD */
123/* __gnu_printf__ is supported in GCC >= 4.4. */
124#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
125# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__
67#else 126#else
68# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ 127# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__
69#endif 128#endif
70 129
71/* _GL_ATTRIBUTE_FORMAT_PRINTF 130/* An __attribute__ __format__ specifier for a function that takes a format
131 string and arguments, where the format string directives are the ones of the
132 system printf(), rather than the ones standardized by ISO C99 and POSIX.
133 _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM */
134/* On mingw, Gnulib sets __USE_MINGW_ANSI_STDIO in order to get closer to
135 the standards. The macro GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU indicates
136 whether this change is effective. On older mingw, it is not. */
137#if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU
138# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD
139#else
140# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM __printf__
141#endif
142
143/* _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD
72 indicates to GCC that the function takes a format string and arguments, 144 indicates to GCC that the function takes a format string and arguments,
73 where the format string directives are the ones standardized by ISO C99 145 where the format string directives are the ones standardized by ISO C99
74 and POSIX. */ 146 and POSIX. */
75#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) 147#define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \
76# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ 148 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, formatstring_parameter, first_argument))
77 _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument))
78#else
79# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
80 _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
81#endif
82 149
83/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF, 150/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD,
84 except that it indicates to GCC that the supported format string directives 151 except that it indicates to GCC that the supported format string directives
85 are the ones of the system printf(), rather than the ones standardized by 152 are the ones of the system printf(), rather than the ones standardized by
86 ISO C99 and POSIX. */ 153 ISO C99 and POSIX. */
87#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ 154#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \
88 _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) 155 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, formatstring_parameter, first_argument))
89 156
90/* _GL_ATTRIBUTE_FORMAT_SCANF 157/* _GL_ATTRIBUTE_FORMAT_SCANF
91 indicates to GCC that the function takes a format string and arguments, 158 indicates to GCC that the function takes a format string and arguments,
@@ -106,14 +173,6 @@
106#define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \ 173#define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \
107 _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) 174 _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
108 175
109/* Solaris 10 declares renameat in <unistd.h>, not in <stdio.h>. */
110/* But in any case avoid namespace pollution on glibc systems. */
111#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __sun \
112 && ! defined __GLIBC__
113# include <unistd.h>
114#endif
115
116
117/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 176/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
118 177
119/* The definition of _GL_ARG_NONNULL is copied here. */ 178/* The definition of _GL_ARG_NONNULL is copied here. */
@@ -124,23 +183,32 @@
124#define _GL_STDIO_STRINGIZE(token) #token 183#define _GL_STDIO_STRINGIZE(token) #token
125#define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) 184#define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token)
126 185
186/* When also using extern inline, suppress the use of static inline in
187 standard headers of problematic Apple configurations, as Libc at
188 least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
189 <https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
190 Perhaps Apple will fix this some day. */
191#if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
192 && defined __GNUC__ && defined __STDC__)
193# undef putc_unlocked
194#endif
127 195
128#if @GNULIB_DPRINTF@ 196#if @GNULIB_DPRINTF@
129# if @REPLACE_DPRINTF@ 197# if @REPLACE_DPRINTF@
130# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 198# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
131# define dprintf rpl_dprintf 199# define dprintf rpl_dprintf
132# endif 200# endif
133_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...) 201_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *restrict format, ...)
134 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 202 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
135 _GL_ARG_NONNULL ((2))); 203 _GL_ARG_NONNULL ((2)));
136_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...)); 204_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *restrict format, ...));
137# else 205# else
138# if !@HAVE_DPRINTF@ 206# if !@HAVE_DPRINTF@
139_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...) 207_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...)
140 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 208 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
141 _GL_ARG_NONNULL ((2))); 209 _GL_ARG_NONNULL ((2)));
142# endif 210# endif
143_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...)); 211_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...));
144# endif 212# endif
145_GL_CXXALIASWARN (dprintf); 213_GL_CXXALIASWARN (dprintf);
146#elif defined GNULIB_POSIXCHECK 214#elif defined GNULIB_POSIXCHECK
@@ -162,7 +230,9 @@ _GL_CXXALIAS_RPL (fclose, int, (FILE *stream));
162# else 230# else
163_GL_CXXALIAS_SYS (fclose, int, (FILE *stream)); 231_GL_CXXALIAS_SYS (fclose, int, (FILE *stream));
164# endif 232# endif
233# if __GLIBC__ >= 2
165_GL_CXXALIASWARN (fclose); 234_GL_CXXALIASWARN (fclose);
235# endif
166#elif defined GNULIB_POSIXCHECK 236#elif defined GNULIB_POSIXCHECK
167# undef fclose 237# undef fclose
168/* Assume fclose is always declared. */ 238/* Assume fclose is always declared. */
@@ -170,24 +240,84 @@ _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - "
170 "use gnulib module fclose for portable POSIX compliance"); 240 "use gnulib module fclose for portable POSIX compliance");
171#endif 241#endif
172 242
243#if @GNULIB_MDA_FCLOSEALL@
244/* On native Windows, map 'fcloseall' to '_fcloseall', so that -loldnames is
245 not required. In C++ with GNULIB_NAMESPACE, avoid differences between
246 platforms by defining GNULIB_NAMESPACE::fcloseall on all platforms that have
247 it. */
248# if defined _WIN32 && !defined __CYGWIN__
249# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
250# undef fcloseall
251# define fcloseall _fcloseall
252# endif
253_GL_CXXALIAS_MDA (fcloseall, int, (void));
254# else
255# if @HAVE_DECL_FCLOSEALL@
256# if defined __FreeBSD__ || defined __DragonFly__
257_GL_CXXALIAS_SYS (fcloseall, void, (void));
258# else
259_GL_CXXALIAS_SYS (fcloseall, int, (void));
260# endif
261# endif
262# endif
263# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCLOSEALL@
264_GL_CXXALIASWARN (fcloseall);
265# endif
266#endif
267
173#if @GNULIB_FDOPEN@ 268#if @GNULIB_FDOPEN@
174# if @REPLACE_FDOPEN@ 269# if @REPLACE_FDOPEN@
175# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 270# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
176# undef fdopen 271# undef fdopen
177# define fdopen rpl_fdopen 272# define fdopen rpl_fdopen
178# endif 273# endif
179_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode) 274_GL_FUNCDECL_RPL (fdopen, FILE *,
180 _GL_ARG_NONNULL ((2))); 275 (int fd, const char *mode)
276 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
181_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode)); 277_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
278# elif defined _WIN32 && !defined __CYGWIN__
279# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
280# undef fdopen
281# define fdopen _fdopen
282# endif
283_GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode));
182# else 284# else
285# if __GNUC__ >= 11
286/* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */
287_GL_FUNCDECL_SYS (fdopen, FILE *,
288 (int fd, const char *mode)
289 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
290# endif
183_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode)); 291_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
184# endif 292# endif
185_GL_CXXALIASWARN (fdopen); 293_GL_CXXALIASWARN (fdopen);
186#elif defined GNULIB_POSIXCHECK 294#else
187# undef fdopen 295# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fdopen
296/* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */
297_GL_FUNCDECL_SYS (fdopen, FILE *,
298 (int fd, const char *mode)
299 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
300# endif
301# if defined GNULIB_POSIXCHECK
302# undef fdopen
188/* Assume fdopen is always declared. */ 303/* Assume fdopen is always declared. */
189_GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - " 304_GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - "
190 "use gnulib module fdopen for portability"); 305 "use gnulib module fdopen for portability");
306# elif @GNULIB_MDA_FDOPEN@
307/* On native Windows, map 'fdopen' to '_fdopen', so that -loldnames is not
308 required. In C++ with GNULIB_NAMESPACE, avoid differences between
309 platforms by defining GNULIB_NAMESPACE::fdopen always. */
310# if defined _WIN32 && !defined __CYGWIN__
311# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312# undef fdopen
313# define fdopen _fdopen
314# endif
315_GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode));
316# else
317_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
318# endif
319_GL_CXXALIASWARN (fdopen);
320# endif
191#endif 321#endif
192 322
193#if @GNULIB_FFLUSH@ 323#if @GNULIB_FFLUSH@
@@ -206,7 +336,9 @@ _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream));
206# else 336# else
207_GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream)); 337_GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream));
208# endif 338# endif
339# if __GLIBC__ >= 2
209_GL_CXXALIASWARN (fflush); 340_GL_CXXALIASWARN (fflush);
341# endif
210#elif defined GNULIB_POSIXCHECK 342#elif defined GNULIB_POSIXCHECK
211# undef fflush 343# undef fflush
212/* Assume fflush is always declared. */ 344/* Assume fflush is always declared. */
@@ -225,7 +357,9 @@ _GL_CXXALIAS_RPL (fgetc, int, (FILE *stream));
225# else 357# else
226_GL_CXXALIAS_SYS (fgetc, int, (FILE *stream)); 358_GL_CXXALIAS_SYS (fgetc, int, (FILE *stream));
227# endif 359# endif
360# if __GLIBC__ >= 2
228_GL_CXXALIASWARN (fgetc); 361_GL_CXXALIASWARN (fgetc);
362# endif
229#endif 363#endif
230 364
231#if @GNULIB_FGETS@ 365#if @GNULIB_FGETS@
@@ -234,33 +368,74 @@ _GL_CXXALIASWARN (fgetc);
234# undef fgets 368# undef fgets
235# define fgets rpl_fgets 369# define fgets rpl_fgets
236# endif 370# endif
237_GL_FUNCDECL_RPL (fgets, char *, (char *s, int n, FILE *stream) 371_GL_FUNCDECL_RPL (fgets, char *,
238 _GL_ARG_NONNULL ((1, 3))); 372 (char *restrict s, int n, FILE *restrict stream)
239_GL_CXXALIAS_RPL (fgets, char *, (char *s, int n, FILE *stream)); 373 _GL_ARG_NONNULL ((1, 3)));
374_GL_CXXALIAS_RPL (fgets, char *,
375 (char *restrict s, int n, FILE *restrict stream));
240# else 376# else
241_GL_CXXALIAS_SYS (fgets, char *, (char *s, int n, FILE *stream)); 377_GL_CXXALIAS_SYS (fgets, char *,
378 (char *restrict s, int n, FILE *restrict stream));
242# endif 379# endif
380# if __GLIBC__ >= 2
243_GL_CXXALIASWARN (fgets); 381_GL_CXXALIASWARN (fgets);
382# endif
383#endif
384
385#if @GNULIB_MDA_FILENO@
386/* On native Windows, map 'fileno' to '_fileno', so that -loldnames is not
387 required. In C++ with GNULIB_NAMESPACE, avoid differences between
388 platforms by defining GNULIB_NAMESPACE::fileno always. */
389# if defined _WIN32 && !defined __CYGWIN__
390# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
391# undef fileno
392# define fileno _fileno
393# endif
394_GL_CXXALIAS_MDA (fileno, int, (FILE *restrict stream));
395# else
396_GL_CXXALIAS_SYS (fileno, int, (FILE *restrict stream));
397# endif
398_GL_CXXALIASWARN (fileno);
244#endif 399#endif
245 400
246#if @GNULIB_FOPEN@ 401#if @GNULIB_FOPEN@
247# if @REPLACE_FOPEN@ 402# if (@GNULIB_FOPEN@ && @REPLACE_FOPEN@) \
403 || (@GNULIB_FOPEN_GNU@ && @REPLACE_FOPEN_FOR_FOPEN_GNU@)
248# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 404# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
249# undef fopen 405# undef fopen
250# define fopen rpl_fopen 406# define fopen rpl_fopen
251# endif 407# endif
252_GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode) 408_GL_FUNCDECL_RPL (fopen, FILE *,
253 _GL_ARG_NONNULL ((1, 2))); 409 (const char *restrict filename, const char *restrict mode)
254_GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode)); 410 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
411_GL_CXXALIAS_RPL (fopen, FILE *,
412 (const char *restrict filename, const char *restrict mode));
255# else 413# else
256_GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode)); 414# if __GNUC__ >= 11
415/* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose. */
416_GL_FUNCDECL_SYS (fopen, FILE *,
417 (const char *restrict filename, const char *restrict mode)
418 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
419# endif
420_GL_CXXALIAS_SYS (fopen, FILE *,
421 (const char *restrict filename, const char *restrict mode));
257# endif 422# endif
423# if __GLIBC__ >= 2
258_GL_CXXALIASWARN (fopen); 424_GL_CXXALIASWARN (fopen);
259#elif defined GNULIB_POSIXCHECK 425# endif
260# undef fopen 426#else
427# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fopen
428/* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose. */
429_GL_FUNCDECL_SYS (fopen, FILE *,
430 (const char *restrict filename, const char *restrict mode)
431 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
432# endif
433# if defined GNULIB_POSIXCHECK
434# undef fopen
261/* Assume fopen is always declared. */ 435/* Assume fopen is always declared. */
262_GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX compliant - " 436_GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX compliant - "
263 "use gnulib module fopen for portability"); 437 "use gnulib module fopen for portability");
438# endif
264#endif 439#endif
265 440
266#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@ 441#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
@@ -271,19 +446,25 @@ _GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX complian
271# endif 446# endif
272# define GNULIB_overrides_fprintf 1 447# define GNULIB_overrides_fprintf 1
273# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 448# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
274_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) 449_GL_FUNCDECL_RPL (fprintf, int,
275 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 450 (FILE *restrict fp, const char *restrict format, ...)
276 _GL_ARG_NONNULL ((1, 2))); 451 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
452 _GL_ARG_NONNULL ((1, 2)));
277# else 453# else
278_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) 454_GL_FUNCDECL_RPL (fprintf, int,
279 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3) 455 (FILE *restrict fp, const char *restrict format, ...)
280 _GL_ARG_NONNULL ((1, 2))); 456 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3)
457 _GL_ARG_NONNULL ((1, 2)));
281# endif 458# endif
282_GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...)); 459_GL_CXXALIAS_RPL (fprintf, int,
460 (FILE *restrict fp, const char *restrict format, ...));
283# else 461# else
284_GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...)); 462_GL_CXXALIAS_SYS (fprintf, int,
463 (FILE *restrict fp, const char *restrict format, ...));
285# endif 464# endif
465# if __GLIBC__ >= 2
286_GL_CXXALIASWARN (fprintf); 466_GL_CXXALIASWARN (fprintf);
467# endif
287#endif 468#endif
288#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK 469#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
289# if !GNULIB_overrides_fprintf 470# if !GNULIB_overrides_fprintf
@@ -334,7 +515,9 @@ _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
334# else 515# else
335_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream)); 516_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
336# endif 517# endif
518# if __GLIBC__ >= 2
337_GL_CXXALIASWARN (fputc); 519_GL_CXXALIASWARN (fputc);
520# endif
338#endif 521#endif
339 522
340#if @GNULIB_FPUTS@ 523#if @GNULIB_FPUTS@
@@ -343,13 +526,18 @@ _GL_CXXALIASWARN (fputc);
343# undef fputs 526# undef fputs
344# define fputs rpl_fputs 527# define fputs rpl_fputs
345# endif 528# endif
346_GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream) 529_GL_FUNCDECL_RPL (fputs, int,
347 _GL_ARG_NONNULL ((1, 2))); 530 (const char *restrict string, FILE *restrict stream)
348_GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream)); 531 _GL_ARG_NONNULL ((1, 2)));
532_GL_CXXALIAS_RPL (fputs, int,
533 (const char *restrict string, FILE *restrict stream));
349# else 534# else
350_GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream)); 535_GL_CXXALIAS_SYS (fputs, int,
536 (const char *restrict string, FILE *restrict stream));
351# endif 537# endif
538# if __GLIBC__ >= 2
352_GL_CXXALIASWARN (fputs); 539_GL_CXXALIASWARN (fputs);
540# endif
353#endif 541#endif
354 542
355#if @GNULIB_FREAD@ 543#if @GNULIB_FREAD@
@@ -358,13 +546,21 @@ _GL_CXXALIASWARN (fputs);
358# undef fread 546# undef fread
359# define fread rpl_fread 547# define fread rpl_fread
360# endif 548# endif
361_GL_FUNCDECL_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream) 549_GL_FUNCDECL_RPL (fread, size_t,
362 _GL_ARG_NONNULL ((4))); 550 (void *restrict ptr, size_t s, size_t n,
363_GL_CXXALIAS_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream)); 551 FILE *restrict stream)
552 _GL_ARG_NONNULL ((4)));
553_GL_CXXALIAS_RPL (fread, size_t,
554 (void *restrict ptr, size_t s, size_t n,
555 FILE *restrict stream));
364# else 556# else
365_GL_CXXALIAS_SYS (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream)); 557_GL_CXXALIAS_SYS (fread, size_t,
558 (void *restrict ptr, size_t s, size_t n,
559 FILE *restrict stream));
366# endif 560# endif
561# if __GLIBC__ >= 2
367_GL_CXXALIASWARN (fread); 562_GL_CXXALIASWARN (fread);
563# endif
368#endif 564#endif
369 565
370#if @GNULIB_FREOPEN@ 566#if @GNULIB_FREOPEN@
@@ -374,15 +570,20 @@ _GL_CXXALIASWARN (fread);
374# define freopen rpl_freopen 570# define freopen rpl_freopen
375# endif 571# endif
376_GL_FUNCDECL_RPL (freopen, FILE *, 572_GL_FUNCDECL_RPL (freopen, FILE *,
377 (const char *filename, const char *mode, FILE *stream) 573 (const char *restrict filename, const char *restrict mode,
574 FILE *restrict stream)
378 _GL_ARG_NONNULL ((2, 3))); 575 _GL_ARG_NONNULL ((2, 3)));
379_GL_CXXALIAS_RPL (freopen, FILE *, 576_GL_CXXALIAS_RPL (freopen, FILE *,
380 (const char *filename, const char *mode, FILE *stream)); 577 (const char *restrict filename, const char *restrict mode,
578 FILE *restrict stream));
381# else 579# else
382_GL_CXXALIAS_SYS (freopen, FILE *, 580_GL_CXXALIAS_SYS (freopen, FILE *,
383 (const char *filename, const char *mode, FILE *stream)); 581 (const char *restrict filename, const char *restrict mode,
582 FILE *restrict stream));
384# endif 583# endif
584# if __GLIBC__ >= 2
385_GL_CXXALIASWARN (freopen); 585_GL_CXXALIASWARN (freopen);
586# endif
386#elif defined GNULIB_POSIXCHECK 587#elif defined GNULIB_POSIXCHECK
387# undef freopen 588# undef freopen
388/* Assume freopen is always declared. */ 589/* Assume freopen is always declared. */
@@ -397,14 +598,19 @@ _GL_WARN_ON_USE (freopen,
397# undef fscanf 598# undef fscanf
398# define fscanf rpl_fscanf 599# define fscanf rpl_fscanf
399# endif 600# endif
400_GL_FUNCDECL_RPL (fscanf, int, (FILE *stream, const char *format, ...) 601_GL_FUNCDECL_RPL (fscanf, int,
401 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3) 602 (FILE *restrict stream, const char *restrict format, ...)
402 _GL_ARG_NONNULL ((1, 2))); 603 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3)
403_GL_CXXALIAS_RPL (fscanf, int, (FILE *stream, const char *format, ...)); 604 _GL_ARG_NONNULL ((1, 2)));
605_GL_CXXALIAS_RPL (fscanf, int,
606 (FILE *restrict stream, const char *restrict format, ...));
404# else 607# else
405_GL_CXXALIAS_SYS (fscanf, int, (FILE *stream, const char *format, ...)); 608_GL_CXXALIAS_SYS (fscanf, int,
609 (FILE *restrict stream, const char *restrict format, ...));
406# endif 610# endif
611# if __GLIBC__ >= 2
407_GL_CXXALIASWARN (fscanf); 612_GL_CXXALIASWARN (fscanf);
613# endif
408#endif 614#endif
409 615
410 616
@@ -455,7 +661,9 @@ _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
455# else 661# else
456_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence)); 662_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
457# endif 663# endif
664# if __GLIBC__ >= 2
458_GL_CXXALIASWARN (fseek); 665_GL_CXXALIASWARN (fseek);
666# endif
459#endif 667#endif
460 668
461#if @GNULIB_FSEEKO@ 669#if @GNULIB_FSEEKO@
@@ -518,7 +726,9 @@ _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
518# else 726# else
519_GL_CXXALIAS_SYS (ftell, long, (FILE *fp)); 727_GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
520# endif 728# endif
729# if __GLIBC__ >= 2
521_GL_CXXALIASWARN (ftell); 730_GL_CXXALIASWARN (ftell);
731# endif
522#endif 732#endif
523 733
524#if @GNULIB_FTELLO@ 734#if @GNULIB_FTELLO@
@@ -567,16 +777,19 @@ _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
567# define fwrite rpl_fwrite 777# define fwrite rpl_fwrite
568# endif 778# endif
569_GL_FUNCDECL_RPL (fwrite, size_t, 779_GL_FUNCDECL_RPL (fwrite, size_t,
570 (const void *ptr, size_t s, size_t n, FILE *stream) 780 (const void *restrict ptr, size_t s, size_t n,
781 FILE *restrict stream)
571 _GL_ARG_NONNULL ((1, 4))); 782 _GL_ARG_NONNULL ((1, 4)));
572_GL_CXXALIAS_RPL (fwrite, size_t, 783_GL_CXXALIAS_RPL (fwrite, size_t,
573 (const void *ptr, size_t s, size_t n, FILE *stream)); 784 (const void *restrict ptr, size_t s, size_t n,
785 FILE *restrict stream));
574# else 786# else
575_GL_CXXALIAS_SYS (fwrite, size_t, 787_GL_CXXALIAS_SYS (fwrite, size_t,
576 (const void *ptr, size_t s, size_t n, FILE *stream)); 788 (const void *restrict ptr, size_t s, size_t n,
789 FILE *restrict stream));
577 790
578/* Work around bug 11959 when fortifying glibc 2.4 through 2.15 791/* Work around bug 11959 when fortifying glibc 2.4 through 2.15
579 <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>, 792 <https://sourceware.org/bugzilla/show_bug.cgi?id=11959>,
580 which sometimes causes an unwanted diagnostic for fwrite calls. 793 which sometimes causes an unwanted diagnostic for fwrite calls.
581 This affects only function declaration attributes under certain 794 This affects only function declaration attributes under certain
582 versions of gcc and clang, and is not needed for C++. */ 795 versions of gcc and clang, and is not needed for C++. */
@@ -598,7 +811,9 @@ extern size_t __REDIRECT (rpl_fwrite_unlocked,
598# define fwrite_unlocked rpl_fwrite_unlocked 811# define fwrite_unlocked rpl_fwrite_unlocked
599# endif 812# endif
600# endif 813# endif
814# if __GLIBC__ >= 2
601_GL_CXXALIASWARN (fwrite); 815_GL_CXXALIASWARN (fwrite);
816# endif
602#endif 817#endif
603 818
604#if @GNULIB_GETC@ 819#if @GNULIB_GETC@
@@ -612,7 +827,9 @@ _GL_CXXALIAS_RPL_1 (getc, rpl_fgetc, int, (FILE *stream));
612# else 827# else
613_GL_CXXALIAS_SYS (getc, int, (FILE *stream)); 828_GL_CXXALIAS_SYS (getc, int, (FILE *stream));
614# endif 829# endif
830# if __GLIBC__ >= 2
615_GL_CXXALIASWARN (getc); 831_GL_CXXALIASWARN (getc);
832# endif
616#endif 833#endif
617 834
618#if @GNULIB_GETCHAR@ 835#if @GNULIB_GETCHAR@
@@ -626,7 +843,9 @@ _GL_CXXALIAS_RPL (getchar, int, (void));
626# else 843# else
627_GL_CXXALIAS_SYS (getchar, int, (void)); 844_GL_CXXALIAS_SYS (getchar, int, (void));
628# endif 845# endif
846# if __GLIBC__ >= 2
629_GL_CXXALIASWARN (getchar); 847_GL_CXXALIASWARN (getchar);
848# endif
630#endif 849#endif
631 850
632#if @GNULIB_GETDELIM@ 851#if @GNULIB_GETDELIM@
@@ -642,22 +861,26 @@ _GL_CXXALIASWARN (getchar);
642# define getdelim rpl_getdelim 861# define getdelim rpl_getdelim
643# endif 862# endif
644_GL_FUNCDECL_RPL (getdelim, ssize_t, 863_GL_FUNCDECL_RPL (getdelim, ssize_t,
645 (char **lineptr, size_t *linesize, int delimiter, 864 (char **restrict lineptr, size_t *restrict linesize,
646 FILE *stream) 865 int delimiter,
866 FILE *restrict stream)
647 _GL_ARG_NONNULL ((1, 2, 4))); 867 _GL_ARG_NONNULL ((1, 2, 4)));
648_GL_CXXALIAS_RPL (getdelim, ssize_t, 868_GL_CXXALIAS_RPL (getdelim, ssize_t,
649 (char **lineptr, size_t *linesize, int delimiter, 869 (char **restrict lineptr, size_t *restrict linesize,
650 FILE *stream)); 870 int delimiter,
871 FILE *restrict stream));
651# else 872# else
652# if !@HAVE_DECL_GETDELIM@ 873# if !@HAVE_DECL_GETDELIM@
653_GL_FUNCDECL_SYS (getdelim, ssize_t, 874_GL_FUNCDECL_SYS (getdelim, ssize_t,
654 (char **lineptr, size_t *linesize, int delimiter, 875 (char **restrict lineptr, size_t *restrict linesize,
655 FILE *stream) 876 int delimiter,
877 FILE *restrict stream)
656 _GL_ARG_NONNULL ((1, 2, 4))); 878 _GL_ARG_NONNULL ((1, 2, 4)));
657# endif 879# endif
658_GL_CXXALIAS_SYS (getdelim, ssize_t, 880_GL_CXXALIAS_SYS (getdelim, ssize_t,
659 (char **lineptr, size_t *linesize, int delimiter, 881 (char **restrict lineptr, size_t *restrict linesize,
660 FILE *stream)); 882 int delimiter,
883 FILE *restrict stream));
661# endif 884# endif
662_GL_CXXALIASWARN (getdelim); 885_GL_CXXALIASWARN (getdelim);
663#elif defined GNULIB_POSIXCHECK 886#elif defined GNULIB_POSIXCHECK
@@ -681,18 +904,22 @@ _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
681# define getline rpl_getline 904# define getline rpl_getline
682# endif 905# endif
683_GL_FUNCDECL_RPL (getline, ssize_t, 906_GL_FUNCDECL_RPL (getline, ssize_t,
684 (char **lineptr, size_t *linesize, FILE *stream) 907 (char **restrict lineptr, size_t *restrict linesize,
908 FILE *restrict stream)
685 _GL_ARG_NONNULL ((1, 2, 3))); 909 _GL_ARG_NONNULL ((1, 2, 3)));
686_GL_CXXALIAS_RPL (getline, ssize_t, 910_GL_CXXALIAS_RPL (getline, ssize_t,
687 (char **lineptr, size_t *linesize, FILE *stream)); 911 (char **restrict lineptr, size_t *restrict linesize,
912 FILE *restrict stream));
688# else 913# else
689# if !@HAVE_DECL_GETLINE@ 914# if !@HAVE_DECL_GETLINE@
690_GL_FUNCDECL_SYS (getline, ssize_t, 915_GL_FUNCDECL_SYS (getline, ssize_t,
691 (char **lineptr, size_t *linesize, FILE *stream) 916 (char **restrict lineptr, size_t *restrict linesize,
917 FILE *restrict stream)
692 _GL_ARG_NONNULL ((1, 2, 3))); 918 _GL_ARG_NONNULL ((1, 2, 3)));
693# endif 919# endif
694_GL_CXXALIAS_SYS (getline, ssize_t, 920_GL_CXXALIAS_SYS (getline, ssize_t,
695 (char **lineptr, size_t *linesize, FILE *stream)); 921 (char **restrict lineptr, size_t *restrict linesize,
922 FILE *restrict stream));
696# endif 923# endif
697# if @HAVE_DECL_GETLINE@ 924# if @HAVE_DECL_GETLINE@
698_GL_CXXALIASWARN (getline); 925_GL_CXXALIASWARN (getline);
@@ -709,10 +936,25 @@ _GL_WARN_ON_USE (getline, "getline is unportable - "
709 so any use of gets warrants an unconditional warning; besides, C11 936 so any use of gets warrants an unconditional warning; besides, C11
710 removed it. */ 937 removed it. */
711#undef gets 938#undef gets
712#if HAVE_RAW_DECL_GETS 939#if HAVE_RAW_DECL_GETS && !defined __cplusplus
713_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); 940_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
714#endif 941#endif
715 942
943#if @GNULIB_MDA_GETW@
944/* On native Windows, map 'getw' to '_getw', so that -loldnames is not
945 required. In C++ with GNULIB_NAMESPACE, avoid differences between
946 platforms by defining GNULIB_NAMESPACE::getw always. */
947# if defined _WIN32 && !defined __CYGWIN__
948# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
949# undef getw
950# define getw _getw
951# endif
952_GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream));
953# else
954_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
955# endif
956_GL_CXXALIASWARN (getw);
957#endif
716 958
717#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ 959#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
718struct obstack; 960struct obstack;
@@ -727,7 +969,7 @@ struct obstack;
727# endif 969# endif
728_GL_FUNCDECL_RPL (obstack_printf, int, 970_GL_FUNCDECL_RPL (obstack_printf, int,
729 (struct obstack *obs, const char *format, ...) 971 (struct obstack *obs, const char *format, ...)
730 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 972 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
731 _GL_ARG_NONNULL ((1, 2))); 973 _GL_ARG_NONNULL ((1, 2)));
732_GL_CXXALIAS_RPL (obstack_printf, int, 974_GL_CXXALIAS_RPL (obstack_printf, int,
733 (struct obstack *obs, const char *format, ...)); 975 (struct obstack *obs, const char *format, ...));
@@ -735,7 +977,7 @@ _GL_CXXALIAS_RPL (obstack_printf, int,
735# if !@HAVE_DECL_OBSTACK_PRINTF@ 977# if !@HAVE_DECL_OBSTACK_PRINTF@
736_GL_FUNCDECL_SYS (obstack_printf, int, 978_GL_FUNCDECL_SYS (obstack_printf, int,
737 (struct obstack *obs, const char *format, ...) 979 (struct obstack *obs, const char *format, ...)
738 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 980 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
739 _GL_ARG_NONNULL ((1, 2))); 981 _GL_ARG_NONNULL ((1, 2)));
740# endif 982# endif
741_GL_CXXALIAS_SYS (obstack_printf, int, 983_GL_CXXALIAS_SYS (obstack_printf, int,
@@ -748,7 +990,7 @@ _GL_CXXALIASWARN (obstack_printf);
748# endif 990# endif
749_GL_FUNCDECL_RPL (obstack_vprintf, int, 991_GL_FUNCDECL_RPL (obstack_vprintf, int,
750 (struct obstack *obs, const char *format, va_list args) 992 (struct obstack *obs, const char *format, va_list args)
751 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 993 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
752 _GL_ARG_NONNULL ((1, 2))); 994 _GL_ARG_NONNULL ((1, 2)));
753_GL_CXXALIAS_RPL (obstack_vprintf, int, 995_GL_CXXALIAS_RPL (obstack_vprintf, int,
754 (struct obstack *obs, const char *format, va_list args)); 996 (struct obstack *obs, const char *format, va_list args));
@@ -756,7 +998,7 @@ _GL_CXXALIAS_RPL (obstack_vprintf, int,
756# if !@HAVE_DECL_OBSTACK_PRINTF@ 998# if !@HAVE_DECL_OBSTACK_PRINTF@
757_GL_FUNCDECL_SYS (obstack_vprintf, int, 999_GL_FUNCDECL_SYS (obstack_vprintf, int,
758 (struct obstack *obs, const char *format, va_list args) 1000 (struct obstack *obs, const char *format, va_list args)
759 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1001 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
760 _GL_ARG_NONNULL ((1, 2))); 1002 _GL_ARG_NONNULL ((1, 2)));
761# endif 1003# endif
762_GL_CXXALIAS_SYS (obstack_vprintf, int, 1004_GL_CXXALIAS_SYS (obstack_vprintf, int,
@@ -792,7 +1034,9 @@ _GL_CXXALIAS_RPL (perror, void, (const char *string));
792# else 1034# else
793_GL_CXXALIAS_SYS (perror, void, (const char *string)); 1035_GL_CXXALIAS_SYS (perror, void, (const char *string));
794# endif 1036# endif
1037# if __GLIBC__ >= 2
795_GL_CXXALIASWARN (perror); 1038_GL_CXXALIASWARN (perror);
1039# endif
796#elif defined GNULIB_POSIXCHECK 1040#elif defined GNULIB_POSIXCHECK
797# undef perror 1041# undef perror
798/* Assume perror is always declared. */ 1042/* Assume perror is always declared. */
@@ -806,43 +1050,53 @@ _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
806# undef popen 1050# undef popen
807# define popen rpl_popen 1051# define popen rpl_popen
808# endif 1052# endif
809_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode) 1053_GL_FUNCDECL_RPL (popen, FILE *,
810 _GL_ARG_NONNULL ((1, 2))); 1054 (const char *cmd, const char *mode)
1055 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
811_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); 1056_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
812# else 1057# else
813# if !@HAVE_POPEN@ 1058# if !@HAVE_POPEN@ || __GNUC__ >= 11
814_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode) 1059_GL_FUNCDECL_SYS (popen, FILE *,
815 _GL_ARG_NONNULL ((1, 2))); 1060 (const char *cmd, const char *mode)
1061 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
816# endif 1062# endif
817_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); 1063_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
818# endif 1064# endif
819_GL_CXXALIASWARN (popen); 1065_GL_CXXALIASWARN (popen);
820#elif defined GNULIB_POSIXCHECK 1066#else
821# undef popen 1067# if @GNULIB_PCLOSE@ && __GNUC__ >= 11 && !defined popen
822# if HAVE_RAW_DECL_POPEN 1068/* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose. */
1069_GL_FUNCDECL_SYS (popen, FILE *,
1070 (const char *cmd, const char *mode)
1071 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
1072# endif
1073# if defined GNULIB_POSIXCHECK
1074# undef popen
1075# if HAVE_RAW_DECL_POPEN
823_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - " 1076_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
824 "use gnulib module popen or pipe for more portability"); 1077 "use gnulib module popen or pipe for more portability");
1078# endif
825# endif 1079# endif
826#endif 1080#endif
827 1081
828#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ 1082#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
829# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ 1083# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
830 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) 1084 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
831# if defined __GNUC__ 1085# if defined __GNUC__ || defined __clang__
832# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1086# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
833/* Don't break __attribute__((format(printf,M,N))). */ 1087/* Don't break __attribute__((format(printf,M,N))). */
834# define printf __printf__ 1088# define printf __printf__
835# endif 1089# endif
836# if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 1090# if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
837_GL_FUNCDECL_RPL_1 (__printf__, int, 1091_GL_FUNCDECL_RPL_1 (__printf__, int,
838 (const char *format, ...) 1092 (const char *restrict format, ...)
839 __asm__ (@ASM_SYMBOL_PREFIX@ 1093 __asm__ (@ASM_SYMBOL_PREFIX@
840 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) 1094 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
841 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) 1095 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
842 _GL_ARG_NONNULL ((1))); 1096 _GL_ARG_NONNULL ((1)));
843# else 1097# else
844_GL_FUNCDECL_RPL_1 (__printf__, int, 1098_GL_FUNCDECL_RPL_1 (__printf__, int,
845 (const char *format, ...) 1099 (const char *restrict format, ...)
846 __asm__ (@ASM_SYMBOL_PREFIX@ 1100 __asm__ (@ASM_SYMBOL_PREFIX@
847 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) 1101 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
848 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2) 1102 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2)
@@ -854,16 +1108,18 @@ _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
854# define printf rpl_printf 1108# define printf rpl_printf
855# endif 1109# endif
856_GL_FUNCDECL_RPL (printf, int, 1110_GL_FUNCDECL_RPL (printf, int,
857 (const char *format, ...) 1111 (const char *restrict format, ...)
858 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) 1112 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
859 _GL_ARG_NONNULL ((1))); 1113 _GL_ARG_NONNULL ((1)));
860_GL_CXXALIAS_RPL (printf, int, (const char *format, ...)); 1114_GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...));
861# endif 1115# endif
862# define GNULIB_overrides_printf 1 1116# define GNULIB_overrides_printf 1
863# else 1117# else
864_GL_CXXALIAS_SYS (printf, int, (const char *format, ...)); 1118_GL_CXXALIAS_SYS (printf, int, (const char *restrict format, ...));
865# endif 1119# endif
1120# if __GLIBC__ >= 2
866_GL_CXXALIASWARN (printf); 1121_GL_CXXALIASWARN (printf);
1122# endif
867#endif 1123#endif
868#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK 1124#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
869# if !GNULIB_overrides_printf 1125# if !GNULIB_overrides_printf
@@ -886,7 +1142,9 @@ _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
886# else 1142# else
887_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream)); 1143_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
888# endif 1144# endif
1145# if __GLIBC__ >= 2
889_GL_CXXALIASWARN (putc); 1146_GL_CXXALIASWARN (putc);
1147# endif
890#endif 1148#endif
891 1149
892#if @GNULIB_PUTCHAR@ 1150#if @GNULIB_PUTCHAR@
@@ -900,7 +1158,9 @@ _GL_CXXALIAS_RPL (putchar, int, (int c));
900# else 1158# else
901_GL_CXXALIAS_SYS (putchar, int, (int c)); 1159_GL_CXXALIAS_SYS (putchar, int, (int c));
902# endif 1160# endif
1161# if __GLIBC__ >= 2
903_GL_CXXALIASWARN (putchar); 1162_GL_CXXALIASWARN (putchar);
1163# endif
904#endif 1164#endif
905 1165
906#if @GNULIB_PUTS@ 1166#if @GNULIB_PUTS@
@@ -914,7 +1174,25 @@ _GL_CXXALIAS_RPL (puts, int, (const char *string));
914# else 1174# else
915_GL_CXXALIAS_SYS (puts, int, (const char *string)); 1175_GL_CXXALIAS_SYS (puts, int, (const char *string));
916# endif 1176# endif
1177# if __GLIBC__ >= 2
917_GL_CXXALIASWARN (puts); 1178_GL_CXXALIASWARN (puts);
1179# endif
1180#endif
1181
1182#if @GNULIB_MDA_PUTW@
1183/* On native Windows, map 'putw' to '_putw', so that -loldnames is not
1184 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1185 platforms by defining GNULIB_NAMESPACE::putw always. */
1186# if defined _WIN32 && !defined __CYGWIN__
1187# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1188# undef putw
1189# define putw _putw
1190# endif
1191_GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream));
1192# else
1193_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
1194# endif
1195_GL_CXXALIASWARN (putw);
918#endif 1196#endif
919 1197
920#if @GNULIB_REMOVE@ 1198#if @GNULIB_REMOVE@
@@ -928,7 +1206,9 @@ _GL_CXXALIAS_RPL (remove, int, (const char *name));
928# else 1206# else
929_GL_CXXALIAS_SYS (remove, int, (const char *name)); 1207_GL_CXXALIAS_SYS (remove, int, (const char *name));
930# endif 1208# endif
1209# if __GLIBC__ >= 2
931_GL_CXXALIASWARN (remove); 1210_GL_CXXALIASWARN (remove);
1211# endif
932#elif defined GNULIB_POSIXCHECK 1212#elif defined GNULIB_POSIXCHECK
933# undef remove 1213# undef remove
934/* Assume remove is always declared. */ 1214/* Assume remove is always declared. */
@@ -951,7 +1231,9 @@ _GL_CXXALIAS_RPL (rename, int,
951_GL_CXXALIAS_SYS (rename, int, 1231_GL_CXXALIAS_SYS (rename, int,
952 (const char *old_filename, const char *new_filename)); 1232 (const char *old_filename, const char *new_filename));
953# endif 1233# endif
1234# if __GLIBC__ >= 2
954_GL_CXXALIASWARN (rename); 1235_GL_CXXALIASWARN (rename);
1236# endif
955#elif defined GNULIB_POSIXCHECK 1237#elif defined GNULIB_POSIXCHECK
956# undef rename 1238# undef rename
957/* Assume rename is always declared. */ 1239/* Assume rename is always declared. */
@@ -990,33 +1272,35 @@ _GL_WARN_ON_USE (renameat, "renameat is not portable - "
990 1272
991#if @GNULIB_SCANF@ 1273#if @GNULIB_SCANF@
992# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ 1274# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
993# if defined __GNUC__ 1275# if defined __GNUC__ || defined __clang__
994# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1276# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
995# undef scanf 1277# undef scanf
996/* Don't break __attribute__((format(scanf,M,N))). */ 1278/* Don't break __attribute__((format(scanf,M,N))). */
997# define scanf __scanf__ 1279# define scanf __scanf__
998# endif 1280# endif
999_GL_FUNCDECL_RPL_1 (__scanf__, int, 1281_GL_FUNCDECL_RPL_1 (__scanf__, int,
1000 (const char *format, ...) 1282 (const char *restrict format, ...)
1001 __asm__ (@ASM_SYMBOL_PREFIX@ 1283 __asm__ (@ASM_SYMBOL_PREFIX@
1002 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf)) 1284 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf))
1003 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) 1285 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
1004 _GL_ARG_NONNULL ((1))); 1286 _GL_ARG_NONNULL ((1)));
1005_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *format, ...)); 1287_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *restrict format, ...));
1006# else 1288# else
1007# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1289# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1008# undef scanf 1290# undef scanf
1009# define scanf rpl_scanf 1291# define scanf rpl_scanf
1010# endif 1292# endif
1011_GL_FUNCDECL_RPL (scanf, int, (const char *format, ...) 1293_GL_FUNCDECL_RPL (scanf, int, (const char *restrict format, ...)
1012 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) 1294 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
1013 _GL_ARG_NONNULL ((1))); 1295 _GL_ARG_NONNULL ((1)));
1014_GL_CXXALIAS_RPL (scanf, int, (const char *format, ...)); 1296_GL_CXXALIAS_RPL (scanf, int, (const char *restrict format, ...));
1015# endif 1297# endif
1016# else 1298# else
1017_GL_CXXALIAS_SYS (scanf, int, (const char *format, ...)); 1299_GL_CXXALIAS_SYS (scanf, int, (const char *restrict format, ...));
1018# endif 1300# endif
1301# if __GLIBC__ >= 2
1019_GL_CXXALIASWARN (scanf); 1302_GL_CXXALIASWARN (scanf);
1303# endif
1020#endif 1304#endif
1021 1305
1022#if @GNULIB_SNPRINTF@ 1306#if @GNULIB_SNPRINTF@
@@ -1024,23 +1308,30 @@ _GL_CXXALIASWARN (scanf);
1024# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1308# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1025# define snprintf rpl_snprintf 1309# define snprintf rpl_snprintf
1026# endif 1310# endif
1311# define GNULIB_overrides_snprintf 1
1027_GL_FUNCDECL_RPL (snprintf, int, 1312_GL_FUNCDECL_RPL (snprintf, int,
1028 (char *str, size_t size, const char *format, ...) 1313 (char *restrict str, size_t size,
1029 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) 1314 const char *restrict format, ...)
1315 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1030 _GL_ARG_NONNULL ((3))); 1316 _GL_ARG_NONNULL ((3)));
1031_GL_CXXALIAS_RPL (snprintf, int, 1317_GL_CXXALIAS_RPL (snprintf, int,
1032 (char *str, size_t size, const char *format, ...)); 1318 (char *restrict str, size_t size,
1319 const char *restrict format, ...));
1033# else 1320# else
1034# if !@HAVE_DECL_SNPRINTF@ 1321# if !@HAVE_DECL_SNPRINTF@
1035_GL_FUNCDECL_SYS (snprintf, int, 1322_GL_FUNCDECL_SYS (snprintf, int,
1036 (char *str, size_t size, const char *format, ...) 1323 (char *restrict str, size_t size,
1037 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) 1324 const char *restrict format, ...)
1325 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1038 _GL_ARG_NONNULL ((3))); 1326 _GL_ARG_NONNULL ((3)));
1039# endif 1327# endif
1040_GL_CXXALIAS_SYS (snprintf, int, 1328_GL_CXXALIAS_SYS (snprintf, int,
1041 (char *str, size_t size, const char *format, ...)); 1329 (char *restrict str, size_t size,
1330 const char *restrict format, ...));
1042# endif 1331# endif
1332# if __GLIBC__ >= 2
1043_GL_CXXALIASWARN (snprintf); 1333_GL_CXXALIASWARN (snprintf);
1334# endif
1044#elif defined GNULIB_POSIXCHECK 1335#elif defined GNULIB_POSIXCHECK
1045# undef snprintf 1336# undef snprintf
1046# if HAVE_RAW_DECL_SNPRINTF 1337# if HAVE_RAW_DECL_SNPRINTF
@@ -1063,14 +1354,20 @@ _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
1063# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1354# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1064# define sprintf rpl_sprintf 1355# define sprintf rpl_sprintf
1065# endif 1356# endif
1066_GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...) 1357# define GNULIB_overrides_sprintf 1
1067 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1358_GL_FUNCDECL_RPL (sprintf, int,
1068 _GL_ARG_NONNULL ((1, 2))); 1359 (char *restrict str, const char *restrict format, ...)
1069_GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...)); 1360 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1361 _GL_ARG_NONNULL ((1, 2)));
1362_GL_CXXALIAS_RPL (sprintf, int,
1363 (char *restrict str, const char *restrict format, ...));
1070# else 1364# else
1071_GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...)); 1365_GL_CXXALIAS_SYS (sprintf, int,
1366 (char *restrict str, const char *restrict format, ...));
1072# endif 1367# endif
1368# if __GLIBC__ >= 2
1073_GL_CXXALIASWARN (sprintf); 1369_GL_CXXALIASWARN (sprintf);
1370# endif
1074#elif defined GNULIB_POSIXCHECK 1371#elif defined GNULIB_POSIXCHECK
1075# undef sprintf 1372# undef sprintf
1076/* Assume sprintf is always declared. */ 1373/* Assume sprintf is always declared. */
@@ -1079,22 +1376,53 @@ _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
1079 "POSIX compliance"); 1376 "POSIX compliance");
1080#endif 1377#endif
1081 1378
1379#if @GNULIB_MDA_TEMPNAM@
1380/* On native Windows, map 'tempnam' to '_tempnam', so that -loldnames is not
1381 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1382 platforms by defining GNULIB_NAMESPACE::tempnam always. */
1383# if defined _WIN32 && !defined __CYGWIN__
1384# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1385# undef tempnam
1386# define tempnam _tempnam
1387# endif
1388_GL_CXXALIAS_MDA (tempnam, char *, (const char *dir, const char *prefix));
1389# else
1390_GL_CXXALIAS_SYS (tempnam, char *, (const char *dir, const char *prefix));
1391# endif
1392_GL_CXXALIASWARN (tempnam);
1393#endif
1394
1082#if @GNULIB_TMPFILE@ 1395#if @GNULIB_TMPFILE@
1083# if @REPLACE_TMPFILE@ 1396# if @REPLACE_TMPFILE@
1084# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1397# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1085# define tmpfile rpl_tmpfile 1398# define tmpfile rpl_tmpfile
1086# endif 1399# endif
1087_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)); 1400_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)
1401 _GL_ATTRIBUTE_DEALLOC (fclose, 1));
1088_GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); 1402_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
1089# else 1403# else
1404# if __GNUC__ >= 11
1405/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1406_GL_FUNCDECL_SYS (tmpfile, FILE *, (void)
1407 _GL_ATTRIBUTE_DEALLOC (fclose, 1));
1408# endif
1090_GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); 1409_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
1091# endif 1410# endif
1411# if __GLIBC__ >= 2
1092_GL_CXXALIASWARN (tmpfile); 1412_GL_CXXALIASWARN (tmpfile);
1093#elif defined GNULIB_POSIXCHECK 1413# endif
1094# undef tmpfile 1414#else
1095# if HAVE_RAW_DECL_TMPFILE 1415# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile
1416/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1417_GL_FUNCDECL_SYS (tmpfile, FILE *, (void)
1418 _GL_ATTRIBUTE_DEALLOC (fclose, 1));
1419# endif
1420# if defined GNULIB_POSIXCHECK
1421# undef tmpfile
1422# if HAVE_RAW_DECL_TMPFILE
1096_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " 1423_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
1097 "use gnulib module tmpfile for portability"); 1424 "use gnulib module tmpfile for portability");
1425# endif
1098# endif 1426# endif
1099#endif 1427#endif
1100 1428
@@ -1107,9 +1435,10 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
1107# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1435# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1108# define asprintf rpl_asprintf 1436# define asprintf rpl_asprintf
1109# endif 1437# endif
1438# define GNULIB_overrides_asprintf
1110_GL_FUNCDECL_RPL (asprintf, int, 1439_GL_FUNCDECL_RPL (asprintf, int,
1111 (char **result, const char *format, ...) 1440 (char **result, const char *format, ...)
1112 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1441 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1113 _GL_ARG_NONNULL ((1, 2))); 1442 _GL_ARG_NONNULL ((1, 2)));
1114_GL_CXXALIAS_RPL (asprintf, int, 1443_GL_CXXALIAS_RPL (asprintf, int,
1115 (char **result, const char *format, ...)); 1444 (char **result, const char *format, ...));
@@ -1117,7 +1446,7 @@ _GL_CXXALIAS_RPL (asprintf, int,
1117# if !@HAVE_VASPRINTF@ 1446# if !@HAVE_VASPRINTF@
1118_GL_FUNCDECL_SYS (asprintf, int, 1447_GL_FUNCDECL_SYS (asprintf, int,
1119 (char **result, const char *format, ...) 1448 (char **result, const char *format, ...)
1120 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1449 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1121 _GL_ARG_NONNULL ((1, 2))); 1450 _GL_ARG_NONNULL ((1, 2)));
1122# endif 1451# endif
1123_GL_CXXALIAS_SYS (asprintf, int, 1452_GL_CXXALIAS_SYS (asprintf, int,
@@ -1128,9 +1457,10 @@ _GL_CXXALIASWARN (asprintf);
1128# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1457# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1129# define vasprintf rpl_vasprintf 1458# define vasprintf rpl_vasprintf
1130# endif 1459# endif
1460# define GNULIB_overrides_vasprintf 1
1131_GL_FUNCDECL_RPL (vasprintf, int, 1461_GL_FUNCDECL_RPL (vasprintf, int,
1132 (char **result, const char *format, va_list args) 1462 (char **result, const char *format, va_list args)
1133 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1463 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1134 _GL_ARG_NONNULL ((1, 2))); 1464 _GL_ARG_NONNULL ((1, 2)));
1135_GL_CXXALIAS_RPL (vasprintf, int, 1465_GL_CXXALIAS_RPL (vasprintf, int,
1136 (char **result, const char *format, va_list args)); 1466 (char **result, const char *format, va_list args));
@@ -1138,7 +1468,7 @@ _GL_CXXALIAS_RPL (vasprintf, int,
1138# if !@HAVE_VASPRINTF@ 1468# if !@HAVE_VASPRINTF@
1139_GL_FUNCDECL_SYS (vasprintf, int, 1469_GL_FUNCDECL_SYS (vasprintf, int,
1140 (char **result, const char *format, va_list args) 1470 (char **result, const char *format, va_list args)
1141 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1471 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1142 _GL_ARG_NONNULL ((1, 2))); 1472 _GL_ARG_NONNULL ((1, 2)));
1143# endif 1473# endif
1144_GL_CXXALIAS_SYS (vasprintf, int, 1474_GL_CXXALIAS_SYS (vasprintf, int,
@@ -1152,22 +1482,27 @@ _GL_CXXALIASWARN (vasprintf);
1152# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1482# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1153# define vdprintf rpl_vdprintf 1483# define vdprintf rpl_vdprintf
1154# endif 1484# endif
1155_GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args) 1485_GL_FUNCDECL_RPL (vdprintf, int,
1156 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1486 (int fd, const char *restrict format, va_list args)
1157 _GL_ARG_NONNULL ((2))); 1487 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1158_GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args)); 1488 _GL_ARG_NONNULL ((2)));
1489_GL_CXXALIAS_RPL (vdprintf, int,
1490 (int fd, const char *restrict format, va_list args));
1159# else 1491# else
1160# if !@HAVE_VDPRINTF@ 1492# if !@HAVE_VDPRINTF@
1161_GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args) 1493_GL_FUNCDECL_SYS (vdprintf, int,
1162 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1494 (int fd, const char *restrict format, va_list args)
1163 _GL_ARG_NONNULL ((2))); 1495 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1496 _GL_ARG_NONNULL ((2)));
1164# endif 1497# endif
1165/* Need to cast, because on Solaris, the third parameter will likely be 1498/* Need to cast, because on Solaris, the third parameter will likely be
1166 __va_list args. */ 1499 __va_list args. */
1167_GL_CXXALIAS_SYS_CAST (vdprintf, int, 1500_GL_CXXALIAS_SYS_CAST (vdprintf, int,
1168 (int fd, const char *format, va_list args)); 1501 (int fd, const char *restrict format, va_list args));
1169# endif 1502# endif
1503# if __GLIBC__ >= 2
1170_GL_CXXALIASWARN (vdprintf); 1504_GL_CXXALIASWARN (vdprintf);
1505# endif
1171#elif defined GNULIB_POSIXCHECK 1506#elif defined GNULIB_POSIXCHECK
1172# undef vdprintf 1507# undef vdprintf
1173# if HAVE_RAW_DECL_VDPRINTF 1508# if HAVE_RAW_DECL_VDPRINTF
@@ -1184,23 +1519,32 @@ _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
1184# endif 1519# endif
1185# define GNULIB_overrides_vfprintf 1 1520# define GNULIB_overrides_vfprintf 1
1186# if @GNULIB_VFPRINTF_POSIX@ 1521# if @GNULIB_VFPRINTF_POSIX@
1187_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) 1522_GL_FUNCDECL_RPL (vfprintf, int,
1188 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1523 (FILE *restrict fp,
1189 _GL_ARG_NONNULL ((1, 2))); 1524 const char *restrict format, va_list args)
1525 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1526 _GL_ARG_NONNULL ((1, 2)));
1190# else 1527# else
1191_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) 1528_GL_FUNCDECL_RPL (vfprintf, int,
1192 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0) 1529 (FILE *restrict fp,
1193 _GL_ARG_NONNULL ((1, 2))); 1530 const char *restrict format, va_list args)
1531 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0)
1532 _GL_ARG_NONNULL ((1, 2)));
1194# endif 1533# endif
1195_GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)); 1534_GL_CXXALIAS_RPL (vfprintf, int,
1535 (FILE *restrict fp,
1536 const char *restrict format, va_list args));
1196# else 1537# else
1197/* Need to cast, because on Solaris, the third parameter is 1538/* Need to cast, because on Solaris, the third parameter is
1198 __va_list args 1539 __va_list args
1199 and GCC's fixincludes did not change this to __gnuc_va_list. */ 1540 and GCC's fixincludes did not change this to __gnuc_va_list. */
1200_GL_CXXALIAS_SYS_CAST (vfprintf, int, 1541_GL_CXXALIAS_SYS_CAST (vfprintf, int,
1201 (FILE *fp, const char *format, va_list args)); 1542 (FILE *restrict fp,
1543 const char *restrict format, va_list args));
1202# endif 1544# endif
1545# if __GLIBC__ >= 2
1203_GL_CXXALIASWARN (vfprintf); 1546_GL_CXXALIASWARN (vfprintf);
1547# endif
1204#endif 1548#endif
1205#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK 1549#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1206# if !GNULIB_overrides_vfprintf 1550# if !GNULIB_overrides_vfprintf
@@ -1219,16 +1563,21 @@ _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
1219# define vfscanf rpl_vfscanf 1563# define vfscanf rpl_vfscanf
1220# endif 1564# endif
1221_GL_FUNCDECL_RPL (vfscanf, int, 1565_GL_FUNCDECL_RPL (vfscanf, int,
1222 (FILE *stream, const char *format, va_list args) 1566 (FILE *restrict stream,
1567 const char *restrict format, va_list args)
1223 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0) 1568 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0)
1224 _GL_ARG_NONNULL ((1, 2))); 1569 _GL_ARG_NONNULL ((1, 2)));
1225_GL_CXXALIAS_RPL (vfscanf, int, 1570_GL_CXXALIAS_RPL (vfscanf, int,
1226 (FILE *stream, const char *format, va_list args)); 1571 (FILE *restrict stream,
1572 const char *restrict format, va_list args));
1227# else 1573# else
1228_GL_CXXALIAS_SYS (vfscanf, int, 1574_GL_CXXALIAS_SYS (vfscanf, int,
1229 (FILE *stream, const char *format, va_list args)); 1575 (FILE *restrict stream,
1576 const char *restrict format, va_list args));
1230# endif 1577# endif
1578# if __GLIBC__ >= 2
1231_GL_CXXALIASWARN (vfscanf); 1579_GL_CXXALIASWARN (vfscanf);
1580# endif
1232#endif 1581#endif
1233 1582
1234#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@ 1583#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
@@ -1239,22 +1588,25 @@ _GL_CXXALIASWARN (vfscanf);
1239# endif 1588# endif
1240# define GNULIB_overrides_vprintf 1 1589# define GNULIB_overrides_vprintf 1
1241# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 1590# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
1242_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) 1591_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args)
1243 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) 1592 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0)
1244 _GL_ARG_NONNULL ((1))); 1593 _GL_ARG_NONNULL ((1)));
1245# else 1594# else
1246_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) 1595_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args)
1247 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0) 1596 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0)
1248 _GL_ARG_NONNULL ((1))); 1597 _GL_ARG_NONNULL ((1)));
1249# endif 1598# endif
1250_GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args)); 1599_GL_CXXALIAS_RPL (vprintf, int, (const char *restrict format, va_list args));
1251# else 1600# else
1252/* Need to cast, because on Solaris, the second parameter is 1601/* Need to cast, because on Solaris, the second parameter is
1253 __va_list args 1602 __va_list args
1254 and GCC's fixincludes did not change this to __gnuc_va_list. */ 1603 and GCC's fixincludes did not change this to __gnuc_va_list. */
1255_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args)); 1604_GL_CXXALIAS_SYS_CAST (vprintf, int,
1605 (const char *restrict format, va_list args));
1256# endif 1606# endif
1607# if __GLIBC__ >= 2
1257_GL_CXXALIASWARN (vprintf); 1608_GL_CXXALIASWARN (vprintf);
1609# endif
1258#endif 1610#endif
1259#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK 1611#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1260# if !GNULIB_overrides_vprintf 1612# if !GNULIB_overrides_vprintf
@@ -1272,14 +1624,16 @@ _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
1272# undef vscanf 1624# undef vscanf
1273# define vscanf rpl_vscanf 1625# define vscanf rpl_vscanf
1274# endif 1626# endif
1275_GL_FUNCDECL_RPL (vscanf, int, (const char *format, va_list args) 1627_GL_FUNCDECL_RPL (vscanf, int, (const char *restrict format, va_list args)
1276 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0) 1628 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0)
1277 _GL_ARG_NONNULL ((1))); 1629 _GL_ARG_NONNULL ((1)));
1278_GL_CXXALIAS_RPL (vscanf, int, (const char *format, va_list args)); 1630_GL_CXXALIAS_RPL (vscanf, int, (const char *restrict format, va_list args));
1279# else 1631# else
1280_GL_CXXALIAS_SYS (vscanf, int, (const char *format, va_list args)); 1632_GL_CXXALIAS_SYS (vscanf, int, (const char *restrict format, va_list args));
1281# endif 1633# endif
1634# if __GLIBC__ >= 2
1282_GL_CXXALIASWARN (vscanf); 1635_GL_CXXALIASWARN (vscanf);
1636# endif
1283#endif 1637#endif
1284 1638
1285#if @GNULIB_VSNPRINTF@ 1639#if @GNULIB_VSNPRINTF@
@@ -1287,23 +1641,30 @@ _GL_CXXALIASWARN (vscanf);
1287# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1641# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1288# define vsnprintf rpl_vsnprintf 1642# define vsnprintf rpl_vsnprintf
1289# endif 1643# endif
1644# define GNULIB_overrides_vsnprintf 1
1290_GL_FUNCDECL_RPL (vsnprintf, int, 1645_GL_FUNCDECL_RPL (vsnprintf, int,
1291 (char *str, size_t size, const char *format, va_list args) 1646 (char *restrict str, size_t size,
1292 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) 1647 const char *restrict format, va_list args)
1648 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
1293 _GL_ARG_NONNULL ((3))); 1649 _GL_ARG_NONNULL ((3)));
1294_GL_CXXALIAS_RPL (vsnprintf, int, 1650_GL_CXXALIAS_RPL (vsnprintf, int,
1295 (char *str, size_t size, const char *format, va_list args)); 1651 (char *restrict str, size_t size,
1652 const char *restrict format, va_list args));
1296# else 1653# else
1297# if !@HAVE_DECL_VSNPRINTF@ 1654# if !@HAVE_DECL_VSNPRINTF@
1298_GL_FUNCDECL_SYS (vsnprintf, int, 1655_GL_FUNCDECL_SYS (vsnprintf, int,
1299 (char *str, size_t size, const char *format, va_list args) 1656 (char *restrict str, size_t size,
1300 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) 1657 const char *restrict format, va_list args)
1658 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
1301 _GL_ARG_NONNULL ((3))); 1659 _GL_ARG_NONNULL ((3)));
1302# endif 1660# endif
1303_GL_CXXALIAS_SYS (vsnprintf, int, 1661_GL_CXXALIAS_SYS (vsnprintf, int,
1304 (char *str, size_t size, const char *format, va_list args)); 1662 (char *restrict str, size_t size,
1663 const char *restrict format, va_list args));
1305# endif 1664# endif
1665# if __GLIBC__ >= 2
1306_GL_CXXALIASWARN (vsnprintf); 1666_GL_CXXALIASWARN (vsnprintf);
1667# endif
1307#elif defined GNULIB_POSIXCHECK 1668#elif defined GNULIB_POSIXCHECK
1308# undef vsnprintf 1669# undef vsnprintf
1309# if HAVE_RAW_DECL_VSNPRINTF 1670# if HAVE_RAW_DECL_VSNPRINTF
@@ -1317,20 +1678,26 @@ _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1317# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1678# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1318# define vsprintf rpl_vsprintf 1679# define vsprintf rpl_vsprintf
1319# endif 1680# endif
1681# define GNULIB_overrides_vsprintf 1
1320_GL_FUNCDECL_RPL (vsprintf, int, 1682_GL_FUNCDECL_RPL (vsprintf, int,
1321 (char *str, const char *format, va_list args) 1683 (char *restrict str,
1322 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1684 const char *restrict format, va_list args)
1685 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1323 _GL_ARG_NONNULL ((1, 2))); 1686 _GL_ARG_NONNULL ((1, 2)));
1324_GL_CXXALIAS_RPL (vsprintf, int, 1687_GL_CXXALIAS_RPL (vsprintf, int,
1325 (char *str, const char *format, va_list args)); 1688 (char *restrict str,
1689 const char *restrict format, va_list args));
1326# else 1690# else
1327/* Need to cast, because on Solaris, the third parameter is 1691/* Need to cast, because on Solaris, the third parameter is
1328 __va_list args 1692 __va_list args
1329 and GCC's fixincludes did not change this to __gnuc_va_list. */ 1693 and GCC's fixincludes did not change this to __gnuc_va_list. */
1330_GL_CXXALIAS_SYS_CAST (vsprintf, int, 1694_GL_CXXALIAS_SYS_CAST (vsprintf, int,
1331 (char *str, const char *format, va_list args)); 1695 (char *restrict str,
1696 const char *restrict format, va_list args));
1332# endif 1697# endif
1698# if __GLIBC__ >= 2
1333_GL_CXXALIASWARN (vsprintf); 1699_GL_CXXALIASWARN (vsprintf);
1700# endif
1334#elif defined GNULIB_POSIXCHECK 1701#elif defined GNULIB_POSIXCHECK
1335# undef vsprintf 1702# undef vsprintf
1336/* Assume vsprintf is always declared. */ 1703/* Assume vsprintf is always declared. */
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index c955248..b79e5f7 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -1,19 +1,19 @@
1/* A GNU-like <stdlib.h>. 1/* A GNU-like <stdlib.h>.
2 2
3 Copyright (C) 1995, 2001-2004, 2006-2013 Free Software Foundation, Inc. 3 Copyright (C) 1995, 2001-2004, 2006-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#if __GNUC__ >= 3 18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@ 19@PRAGMA_SYSTEM_HEADER@
@@ -47,11 +47,14 @@
47 47
48/* Solaris declares getloadavg() in <sys/loadavg.h>. */ 48/* Solaris declares getloadavg() in <sys/loadavg.h>. */
49#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@ 49#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@
50/* OpenIndiana has a bug: <sys/time.h> must be included before
51 <sys/loadavg.h>. */
52# include <sys/time.h>
50# include <sys/loadavg.h> 53# include <sys/loadavg.h>
51#endif 54#endif
52 55
53/* Native Windows platforms declare mktemp() in <io.h>. */ 56/* Native Windows platforms declare _mktemp() in <io.h>. */
54#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) 57#if defined _WIN32 && !defined __CYGWIN__
55# include <io.h> 58# include <io.h>
56#endif 59#endif
57 60
@@ -87,20 +90,52 @@ struct random_data
87# endif 90# endif
88#endif 91#endif
89 92
90#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) 93#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_MKOSTEMP@ || @GNULIB_MKOSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !(defined _WIN32 && ! defined __CYGWIN__)
91/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */ 94/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */
92/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */ 95/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */
96/* On Mac OS X 10.13, only <unistd.h> declares mkostemp and mkostemps. */
93/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */ 97/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */
94/* But avoid namespace pollution on glibc systems and native Windows. */ 98/* But avoid namespace pollution on glibc systems and native Windows. */
95# include <unistd.h> 99# include <unistd.h>
96#endif 100#endif
97 101
102/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
103 that can be freed by passing them as the Ith argument to the
104 function F. */
105#ifndef _GL_ATTRIBUTE_DEALLOC
106# if __GNUC__ >= 11
107# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
108# else
109# define _GL_ATTRIBUTE_DEALLOC(f, i)
110# endif
111#endif
112
113/* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
114 can be freed via 'free'; it can be used only after declaring 'free'. */
115/* Applies to: functions. Cannot be used on inline functions. */
116#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
117# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
118#endif
119
120/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
121 allocated memory. */
122/* Applies to: functions. */
123#ifndef _GL_ATTRIBUTE_MALLOC
124# if __GNUC__ >= 3 || defined __clang__
125# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
126# else
127# define _GL_ATTRIBUTE_MALLOC
128# endif
129#endif
130
98/* The __attribute__ feature is available in gcc versions 2.5 and later. 131/* The __attribute__ feature is available in gcc versions 2.5 and later.
99 The attribute __pure__ was added in gcc 2.96. */ 132 The attribute __pure__ was added in gcc 2.96. */
100#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 133#ifndef _GL_ATTRIBUTE_PURE
101# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 134# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
102#else 135# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
103# define _GL_ATTRIBUTE_PURE /* empty */ 136# else
137# define _GL_ATTRIBUTE_PURE /* empty */
138# endif
104#endif 139#endif
105 140
106/* The definition of _Noreturn is copied here. */ 141/* The definition of _Noreturn is copied here. */
@@ -143,6 +178,73 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - "
143#endif 178#endif
144 179
145 180
181#if @GNULIB_FREE_POSIX@
182# if @REPLACE_FREE@
183# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
184# undef free
185# define free rpl_free
186# endif
187# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
188_GL_FUNCDECL_RPL (free, void, (void *ptr) throw ());
189# else
190_GL_FUNCDECL_RPL (free, void, (void *ptr));
191# endif
192_GL_CXXALIAS_RPL (free, void, (void *ptr));
193# else
194_GL_CXXALIAS_SYS (free, void, (void *ptr));
195# endif
196# if __GLIBC__ >= 2
197_GL_CXXALIASWARN (free);
198# endif
199#elif defined GNULIB_POSIXCHECK
200# undef free
201/* Assume free is always declared. */
202_GL_WARN_ON_USE (free, "free is not future POSIX compliant everywhere - "
203 "use gnulib module free for portability");
204#endif
205
206
207/* Allocate memory with indefinite extent and specified alignment. */
208#if @GNULIB_ALIGNED_ALLOC@
209# if @REPLACE_ALIGNED_ALLOC@
210# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
211# undef aligned_alloc
212# define aligned_alloc rpl_aligned_alloc
213# endif
214_GL_FUNCDECL_RPL (aligned_alloc, void *,
215 (size_t alignment, size_t size)
216 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
217_GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
218# else
219# if @HAVE_ALIGNED_ALLOC@
220# if __GNUC__ >= 11
221/* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free. */
222_GL_FUNCDECL_SYS (aligned_alloc, void *,
223 (size_t alignment, size_t size)
224 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
225# endif
226_GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size));
227# endif
228# endif
229# if (__GLIBC__ >= 2) && @HAVE_ALIGNED_ALLOC@
230_GL_CXXALIASWARN (aligned_alloc);
231# endif
232#else
233# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined aligned_alloc
234/* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free. */
235_GL_FUNCDECL_SYS (aligned_alloc, void *,
236 (size_t alignment, size_t size)
237 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
238# endif
239# if defined GNULIB_POSIXCHECK
240# undef aligned_alloc
241# if HAVE_RAW_DECL_ALIGNED_ALLOC
242_GL_WARN_ON_USE (aligned_alloc, "aligned_alloc is not portable - "
243 "use gnulib module aligned_alloc for portability");
244# endif
245# endif
246#endif
247
146#if @GNULIB_ATOLL@ 248#if @GNULIB_ATOLL@
147/* Parse a signed decimal integer. 249/* Parse a signed decimal integer.
148 Returns the value of the integer. Errors are not detected. */ 250 Returns the value of the integer. Errors are not detected. */
@@ -162,22 +264,41 @@ _GL_WARN_ON_USE (atoll, "atoll is unportable - "
162#endif 264#endif
163 265
164#if @GNULIB_CALLOC_POSIX@ 266#if @GNULIB_CALLOC_POSIX@
165# if @REPLACE_CALLOC@ 267# if (@GNULIB_CALLOC_POSIX@ && @REPLACE_CALLOC_FOR_CALLOC_POSIX@) \
268 || (@GNULIB_CALLOC_GNU@ && @REPLACE_CALLOC_FOR_CALLOC_GNU@)
166# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 269# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
167# undef calloc 270# undef calloc
168# define calloc rpl_calloc 271# define calloc rpl_calloc
169# endif 272# endif
170_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size)); 273_GL_FUNCDECL_RPL (calloc, void *,
274 (size_t nmemb, size_t size)
275 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
171_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size)); 276_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size));
172# else 277# else
278# if __GNUC__ >= 11
279/* For -Wmismatched-dealloc: Associate calloc with free or rpl_free. */
280_GL_FUNCDECL_SYS (calloc, void *,
281 (size_t nmemb, size_t size)
282 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
283# endif
173_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size)); 284_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size));
174# endif 285# endif
286# if __GLIBC__ >= 2
175_GL_CXXALIASWARN (calloc); 287_GL_CXXALIASWARN (calloc);
176#elif defined GNULIB_POSIXCHECK 288# endif
177# undef calloc 289#else
290# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined calloc
291/* For -Wmismatched-dealloc: Associate calloc with free or rpl_free. */
292_GL_FUNCDECL_SYS (calloc, void *,
293 (size_t nmemb, size_t size)
294 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
295# endif
296# if defined GNULIB_POSIXCHECK
297# undef calloc
178/* Assume calloc is always declared. */ 298/* Assume calloc is always declared. */
179_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - " 299_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
180 "use gnulib module calloc-posix for portability"); 300 "use gnulib module calloc-posix for portability");
301# endif
181#endif 302#endif
182 303
183#if @GNULIB_CANONICALIZE_FILE_NAME@ 304#if @GNULIB_CANONICALIZE_FILE_NAME@
@@ -185,23 +306,108 @@ _GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
185# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 306# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186# define canonicalize_file_name rpl_canonicalize_file_name 307# define canonicalize_file_name rpl_canonicalize_file_name
187# endif 308# endif
188_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name) 309_GL_FUNCDECL_RPL (canonicalize_file_name, char *,
189 _GL_ARG_NONNULL ((1))); 310 (const char *name)
311 _GL_ARG_NONNULL ((1))
312 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
190_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name)); 313_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name));
191# else 314# else
192# if !@HAVE_CANONICALIZE_FILE_NAME@ 315# if !@HAVE_CANONICALIZE_FILE_NAME@ || __GNUC__ >= 11
193_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) 316_GL_FUNCDECL_SYS (canonicalize_file_name, char *,
194 _GL_ARG_NONNULL ((1))); 317 (const char *name)
318 _GL_ARG_NONNULL ((1))
319 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
195# endif 320# endif
196_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name)); 321_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name));
197# endif 322# endif
323# ifndef GNULIB_defined_canonicalize_file_name
324# define GNULIB_defined_canonicalize_file_name \
325 (!@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@)
326# endif
198_GL_CXXALIASWARN (canonicalize_file_name); 327_GL_CXXALIASWARN (canonicalize_file_name);
199#elif defined GNULIB_POSIXCHECK 328#else
200# undef canonicalize_file_name 329# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined canonicalize_file_name
201# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME 330/* For -Wmismatched-dealloc: Associate canonicalize_file_name with free or
331 rpl_free. */
332_GL_FUNCDECL_SYS (canonicalize_file_name, char *,
333 (const char *name)
334 _GL_ARG_NONNULL ((1))
335 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
336# endif
337# if defined GNULIB_POSIXCHECK
338# undef canonicalize_file_name
339# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
202_GL_WARN_ON_USE (canonicalize_file_name, 340_GL_WARN_ON_USE (canonicalize_file_name,
203 "canonicalize_file_name is unportable - " 341 "canonicalize_file_name is unportable - "
204 "use gnulib module canonicalize-lgpl for portability"); 342 "use gnulib module canonicalize-lgpl for portability");
343# endif
344# endif
345#endif
346
347#if @GNULIB_MDA_ECVT@
348/* On native Windows, map 'ecvt' to '_ecvt', so that -loldnames is not
349 required. In C++ with GNULIB_NAMESPACE, avoid differences between
350 platforms by defining GNULIB_NAMESPACE::ecvt on all platforms that have
351 it. */
352# if defined _WIN32 && !defined __CYGWIN__
353# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
354# undef ecvt
355# define ecvt _ecvt
356# endif
357_GL_CXXALIAS_MDA (ecvt, char *,
358 (double number, int ndigits, int *decptp, int *signp));
359# else
360# if @HAVE_DECL_ECVT@
361_GL_CXXALIAS_SYS (ecvt, char *,
362 (double number, int ndigits, int *decptp, int *signp));
363# endif
364# endif
365# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_ECVT@
366_GL_CXXALIASWARN (ecvt);
367# endif
368#endif
369
370#if @GNULIB_MDA_FCVT@
371/* On native Windows, map 'fcvt' to '_fcvt', so that -loldnames is not
372 required. In C++ with GNULIB_NAMESPACE, avoid differences between
373 platforms by defining GNULIB_NAMESPACE::fcvt on all platforms that have
374 it. */
375# if defined _WIN32 && !defined __CYGWIN__
376# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
377# undef fcvt
378# define fcvt _fcvt
379# endif
380_GL_CXXALIAS_MDA (fcvt, char *,
381 (double number, int ndigits, int *decptp, int *signp));
382# else
383# if @HAVE_DECL_FCVT@
384_GL_CXXALIAS_SYS (fcvt, char *,
385 (double number, int ndigits, int *decptp, int *signp));
386# endif
387# endif
388# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCVT@
389_GL_CXXALIASWARN (fcvt);
390# endif
391#endif
392
393#if @GNULIB_MDA_GCVT@
394/* On native Windows, map 'gcvt' to '_gcvt', so that -loldnames is not
395 required. In C++ with GNULIB_NAMESPACE, avoid differences between
396 platforms by defining GNULIB_NAMESPACE::gcvt on all platforms that have
397 it. */
398# if defined _WIN32 && !defined __CYGWIN__
399# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
400# undef gcvt
401# define gcvt _gcvt
402# endif
403_GL_CXXALIAS_MDA (gcvt, char *, (double number, int ndigits, char *buf));
404# else
405# if @HAVE_DECL_GCVT@
406_GL_CXXALIAS_SYS (gcvt, char *, (double number, int ndigits, char *buf));
407# endif
408# endif
409# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_GCVT@
410_GL_CXXALIASWARN (gcvt);
205# endif 411# endif
206#endif 412#endif
207 413
@@ -234,8 +440,8 @@ _GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - "
234 element (or NULL if it doesn't contain an "=" sign), 440 element (or NULL if it doesn't contain an "=" sign),
235 - It returns the index of the "token" in the given array of tokens. 441 - It returns the index of the "token" in the given array of tokens.
236 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined. 442 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
237 For more details see the POSIX:2001 specification. 443 For more details see the POSIX specification.
238 http://www.opengroup.org/susv3xsh/getsubopt.html */ 444 https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsubopt.html */
239# if !@HAVE_GETSUBOPT@ 445# if !@HAVE_GETSUBOPT@
240_GL_FUNCDECL_SYS (getsubopt, int, 446_GL_FUNCDECL_SYS (getsubopt, int,
241 (char **optionp, char *const *tokens, char **valuep) 447 (char **optionp, char *const *tokens, char **valuep)
@@ -273,23 +479,42 @@ _GL_WARN_ON_USE (grantpt, "grantpt is not portable - "
273 by never specifying a zero size), so it does not need malloc or 479 by never specifying a zero size), so it does not need malloc or
274 realloc to be redefined. */ 480 realloc to be redefined. */
275#if @GNULIB_MALLOC_POSIX@ 481#if @GNULIB_MALLOC_POSIX@
276# if @REPLACE_MALLOC@ 482# if (@GNULIB_MALLOC_POSIX@ && @REPLACE_MALLOC_FOR_MALLOC_POSIX@) \
483 || (@GNULIB_MALLOC_GNU@ && @REPLACE_MALLOC_FOR_MALLOC_GNU@)
277# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \ 484# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
278 || _GL_USE_STDLIB_ALLOC) 485 || _GL_USE_STDLIB_ALLOC)
279# undef malloc 486# undef malloc
280# define malloc rpl_malloc 487# define malloc rpl_malloc
281# endif 488# endif
282_GL_FUNCDECL_RPL (malloc, void *, (size_t size)); 489_GL_FUNCDECL_RPL (malloc, void *,
490 (size_t size)
491 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
283_GL_CXXALIAS_RPL (malloc, void *, (size_t size)); 492_GL_CXXALIAS_RPL (malloc, void *, (size_t size));
284# else 493# else
494# if __GNUC__ >= 11
495/* For -Wmismatched-dealloc: Associate malloc with free or rpl_free. */
496_GL_FUNCDECL_SYS (malloc, void *,
497 (size_t size)
498 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
499# endif
285_GL_CXXALIAS_SYS (malloc, void *, (size_t size)); 500_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
286# endif 501# endif
502# if __GLIBC__ >= 2
287_GL_CXXALIASWARN (malloc); 503_GL_CXXALIASWARN (malloc);
288#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC 504# endif
289# undef malloc 505#else
506# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined malloc
507/* For -Wmismatched-dealloc: Associate malloc with free or rpl_free. */
508_GL_FUNCDECL_SYS (malloc, void *,
509 (size_t size)
510 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
511# endif
512# if defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
513# undef malloc
290/* Assume malloc is always declared. */ 514/* Assume malloc is always declared. */
291_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " 515_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
292 "use gnulib module malloc-posix for portability"); 516 "use gnulib module malloc-posix for portability");
517# endif
293#endif 518#endif
294 519
295/* Convert a multibyte character to a wide character. */ 520/* Convert a multibyte character to a wide character. */
@@ -299,12 +524,27 @@ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
299# undef mbtowc 524# undef mbtowc
300# define mbtowc rpl_mbtowc 525# define mbtowc rpl_mbtowc
301# endif 526# endif
302_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); 527_GL_FUNCDECL_RPL (mbtowc, int,
303_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); 528 (wchar_t *restrict pwc, const char *restrict s, size_t n));
529_GL_CXXALIAS_RPL (mbtowc, int,
530 (wchar_t *restrict pwc, const char *restrict s, size_t n));
304# else 531# else
305_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); 532# if !@HAVE_MBTOWC@
533_GL_FUNCDECL_SYS (mbtowc, int,
534 (wchar_t *restrict pwc, const char *restrict s, size_t n));
535# endif
536_GL_CXXALIAS_SYS (mbtowc, int,
537 (wchar_t *restrict pwc, const char *restrict s, size_t n));
306# endif 538# endif
539# if __GLIBC__ >= 2
307_GL_CXXALIASWARN (mbtowc); 540_GL_CXXALIASWARN (mbtowc);
541# endif
542#elif defined GNULIB_POSIXCHECK
543# undef mbtowc
544# if HAVE_RAW_DECL_MBTOWC
545_GL_WARN_ON_USE (mbtowc, "mbtowc is not portable - "
546 "use gnulib module mbtowc for portability");
547# endif
308#endif 548#endif
309 549
310#if @GNULIB_MKDTEMP@ 550#if @GNULIB_MKDTEMP@
@@ -439,6 +679,51 @@ _GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
439# endif 679# endif
440#endif 680#endif
441 681
682#if @GNULIB_MDA_MKTEMP@
683/* On native Windows, map 'mktemp' to '_mktemp', so that -loldnames is not
684 required. In C++ with GNULIB_NAMESPACE, avoid differences between
685 platforms by defining GNULIB_NAMESPACE::mktemp always. */
686# if defined _WIN32 && !defined __CYGWIN__
687# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
688# undef mktemp
689# define mktemp _mktemp
690# endif
691_GL_CXXALIAS_MDA (mktemp, char *, (char * /*template*/));
692# else
693_GL_CXXALIAS_SYS (mktemp, char *, (char * /*template*/));
694# endif
695_GL_CXXALIASWARN (mktemp);
696#endif
697
698/* Allocate memory with indefinite extent and specified alignment. */
699#if @GNULIB_POSIX_MEMALIGN@
700# if @REPLACE_POSIX_MEMALIGN@
701# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
702# undef posix_memalign
703# define posix_memalign rpl_posix_memalign
704# endif
705_GL_FUNCDECL_RPL (posix_memalign, int,
706 (void **memptr, size_t alignment, size_t size)
707 _GL_ARG_NONNULL ((1)));
708_GL_CXXALIAS_RPL (posix_memalign, int,
709 (void **memptr, size_t alignment, size_t size));
710# else
711# if @HAVE_POSIX_MEMALIGN@
712_GL_CXXALIAS_SYS (posix_memalign, int,
713 (void **memptr, size_t alignment, size_t size));
714# endif
715# endif
716# if @HAVE_POSIX_MEMALIGN@
717_GL_CXXALIASWARN (posix_memalign);
718# endif
719#elif defined GNULIB_POSIXCHECK
720# undef posix_memalign
721# if HAVE_RAW_DECL_POSIX_MEMALIGN
722_GL_WARN_ON_USE (posix_memalign, "posix_memalign is not portable - "
723 "use gnulib module posix_memalign for portability");
724# endif
725#endif
726
442#if @GNULIB_POSIX_OPENPT@ 727#if @GNULIB_POSIX_OPENPT@
443/* Return an FD open to the master side of a pseudo-terminal. Flags should 728/* Return an FD open to the master side of a pseudo-terminal. Flags should
444 include O_RDWR, and may also include O_NOCTTY. */ 729 include O_RDWR, and may also include O_NOCTTY. */
@@ -497,6 +782,9 @@ _GL_FUNCDECL_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
497# endif 782# endif
498_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); 783_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
499# endif 784# endif
785# ifndef GNULIB_defined_ptsname_r
786# define GNULIB_defined_ptsname_r (!@HAVE_PTSNAME_R@ || @REPLACE_PTSNAME_R@)
787# endif
500_GL_CXXALIASWARN (ptsname_r); 788_GL_CXXALIASWARN (ptsname_r);
501#elif defined GNULIB_POSIXCHECK 789#elif defined GNULIB_POSIXCHECK
502# undef ptsname_r 790# undef ptsname_r
@@ -514,12 +802,78 @@ _GL_WARN_ON_USE (ptsname_r, "ptsname_r is not portable - "
514# endif 802# endif
515_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1))); 803_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1)));
516_GL_CXXALIAS_RPL (putenv, int, (char *string)); 804_GL_CXXALIAS_RPL (putenv, int, (char *string));
805# elif defined _WIN32 && !defined __CYGWIN__
806# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
807# undef putenv
808# define putenv _putenv
809# endif
810_GL_CXXALIAS_MDA (putenv, int, (char *string));
811# else
812_GL_CXXALIAS_SYS (putenv, int, (char *string));
813# endif
814_GL_CXXALIASWARN (putenv);
815#elif @GNULIB_MDA_PUTENV@
816/* On native Windows, map 'putenv' to '_putenv', so that -loldnames is not
817 required. In C++ with GNULIB_NAMESPACE, avoid differences between
818 platforms by defining GNULIB_NAMESPACE::putenv always. */
819# if defined _WIN32 && !defined __CYGWIN__
820# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
821# undef putenv
822# define putenv _putenv
823# endif
824/* Need to cast, because on mingw, the parameter is either
825 'const char *string' or 'char *string'. */
826_GL_CXXALIAS_MDA_CAST (putenv, int, (char *string));
517# else 827# else
518_GL_CXXALIAS_SYS (putenv, int, (char *string)); 828_GL_CXXALIAS_SYS (putenv, int, (char *string));
519# endif 829# endif
520_GL_CXXALIASWARN (putenv); 830_GL_CXXALIASWARN (putenv);
521#endif 831#endif
522 832
833#if @GNULIB_QSORT_R@
834/* Sort an array of NMEMB elements, starting at address BASE, each element
835 occupying SIZE bytes, in ascending order according to the comparison
836 function COMPARE. */
837# ifdef __cplusplus
838extern "C" {
839# endif
840# if !GNULIB_defined_qsort_r_fn_types
841typedef int (*_gl_qsort_r_compar_fn) (void const *, void const *, void *);
842# define GNULIB_defined_qsort_r_fn_types 1
843# endif
844# ifdef __cplusplus
845}
846# endif
847# if @REPLACE_QSORT_R@
848# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
849# undef qsort_r
850# define qsort_r rpl_qsort_r
851# endif
852_GL_FUNCDECL_RPL (qsort_r, void, (void *base, size_t nmemb, size_t size,
853 _gl_qsort_r_compar_fn compare,
854 void *arg) _GL_ARG_NONNULL ((1, 4)));
855_GL_CXXALIAS_RPL (qsort_r, void, (void *base, size_t nmemb, size_t size,
856 _gl_qsort_r_compar_fn compare,
857 void *arg));
858# else
859# if !@HAVE_QSORT_R@
860_GL_FUNCDECL_SYS (qsort_r, void, (void *base, size_t nmemb, size_t size,
861 _gl_qsort_r_compar_fn compare,
862 void *arg) _GL_ARG_NONNULL ((1, 4)));
863# endif
864_GL_CXXALIAS_SYS (qsort_r, void, (void *base, size_t nmemb, size_t size,
865 _gl_qsort_r_compar_fn compare,
866 void *arg));
867# endif
868_GL_CXXALIASWARN (qsort_r);
869#elif defined GNULIB_POSIXCHECK
870# undef qsort_r
871# if HAVE_RAW_DECL_QSORT_R
872_GL_WARN_ON_USE (qsort_r, "qsort_r is not portable - "
873 "use gnulib module qsort_r for portability");
874# endif
875#endif
876
523 877
524#if @GNULIB_RANDOM_R@ 878#if @GNULIB_RANDOM_R@
525# if !@HAVE_RANDOM_R@ 879# if !@HAVE_RANDOM_R@
@@ -531,10 +885,21 @@ _GL_CXXALIASWARN (putenv);
531 885
532 886
533#if @GNULIB_RANDOM@ 887#if @GNULIB_RANDOM@
534# if !@HAVE_RANDOM@ 888# if @REPLACE_RANDOM@
889# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
890# undef random
891# define random rpl_random
892# endif
893_GL_FUNCDECL_RPL (random, long, (void));
894_GL_CXXALIAS_RPL (random, long, (void));
895# else
896# if !@HAVE_RANDOM@
535_GL_FUNCDECL_SYS (random, long, (void)); 897_GL_FUNCDECL_SYS (random, long, (void));
898# endif
899/* Need to cast, because on Haiku, the return type is
900 int. */
901_GL_CXXALIAS_SYS_CAST (random, long, (void));
536# endif 902# endif
537_GL_CXXALIAS_SYS (random, long, (void));
538_GL_CXXALIASWARN (random); 903_GL_CXXALIASWARN (random);
539#elif defined GNULIB_POSIXCHECK 904#elif defined GNULIB_POSIXCHECK
540# undef random 905# undef random
@@ -545,10 +910,21 @@ _GL_WARN_ON_USE (random, "random is unportable - "
545#endif 910#endif
546 911
547#if @GNULIB_RANDOM@ 912#if @GNULIB_RANDOM@
548# if !@HAVE_RANDOM@ 913# if @REPLACE_RANDOM@
914# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
915# undef srandom
916# define srandom rpl_srandom
917# endif
918_GL_FUNCDECL_RPL (srandom, void, (unsigned int seed));
919_GL_CXXALIAS_RPL (srandom, void, (unsigned int seed));
920# else
921# if !@HAVE_RANDOM@
549_GL_FUNCDECL_SYS (srandom, void, (unsigned int seed)); 922_GL_FUNCDECL_SYS (srandom, void, (unsigned int seed));
923# endif
924/* Need to cast, because on FreeBSD, the first parameter is
925 unsigned long seed. */
926_GL_CXXALIAS_SYS_CAST (srandom, void, (unsigned int seed));
550# endif 927# endif
551_GL_CXXALIAS_SYS (srandom, void, (unsigned int seed));
552_GL_CXXALIASWARN (srandom); 928_GL_CXXALIASWARN (srandom);
553#elif defined GNULIB_POSIXCHECK 929#elif defined GNULIB_POSIXCHECK
554# undef srandom 930# undef srandom
@@ -559,31 +935,56 @@ _GL_WARN_ON_USE (srandom, "srandom is unportable - "
559#endif 935#endif
560 936
561#if @GNULIB_RANDOM@ 937#if @GNULIB_RANDOM@
562# if !@HAVE_RANDOM@ 938# if @REPLACE_INITSTATE@
939# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
940# undef initstate
941# define initstate rpl_initstate
942# endif
943_GL_FUNCDECL_RPL (initstate, char *,
944 (unsigned int seed, char *buf, size_t buf_size)
945 _GL_ARG_NONNULL ((2)));
946_GL_CXXALIAS_RPL (initstate, char *,
947 (unsigned int seed, char *buf, size_t buf_size));
948# else
949# if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
563_GL_FUNCDECL_SYS (initstate, char *, 950_GL_FUNCDECL_SYS (initstate, char *,
564 (unsigned int seed, char *buf, size_t buf_size) 951 (unsigned int seed, char *buf, size_t buf_size)
565 _GL_ARG_NONNULL ((2))); 952 _GL_ARG_NONNULL ((2)));
953# endif
954/* Need to cast, because on FreeBSD, the first parameter is
955 unsigned long seed. */
956_GL_CXXALIAS_SYS_CAST (initstate, char *,
957 (unsigned int seed, char *buf, size_t buf_size));
566# endif 958# endif
567_GL_CXXALIAS_SYS (initstate, char *,
568 (unsigned int seed, char *buf, size_t buf_size));
569_GL_CXXALIASWARN (initstate); 959_GL_CXXALIASWARN (initstate);
570#elif defined GNULIB_POSIXCHECK 960#elif defined GNULIB_POSIXCHECK
571# undef initstate 961# undef initstate
572# if HAVE_RAW_DECL_INITSTATE_R 962# if HAVE_RAW_DECL_INITSTATE
573_GL_WARN_ON_USE (initstate, "initstate is unportable - " 963_GL_WARN_ON_USE (initstate, "initstate is unportable - "
574 "use gnulib module random for portability"); 964 "use gnulib module random for portability");
575# endif 965# endif
576#endif 966#endif
577 967
578#if @GNULIB_RANDOM@ 968#if @GNULIB_RANDOM@
579# if !@HAVE_RANDOM@ 969# if @REPLACE_SETSTATE@
970# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
971# undef setstate
972# define setstate rpl_setstate
973# endif
974_GL_FUNCDECL_RPL (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
975_GL_CXXALIAS_RPL (setstate, char *, (char *arg_state));
976# else
977# if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
580_GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1))); 978_GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
979# endif
980/* Need to cast, because on Mac OS X 10.13, HP-UX, Solaris the first parameter
981 is const char *arg_state. */
982_GL_CXXALIAS_SYS_CAST (setstate, char *, (char *arg_state));
581# endif 983# endif
582_GL_CXXALIAS_SYS (setstate, char *, (char *arg_state));
583_GL_CXXALIASWARN (setstate); 984_GL_CXXALIASWARN (setstate);
584#elif defined GNULIB_POSIXCHECK 985#elif defined GNULIB_POSIXCHECK
585# undef setstate 986# undef setstate
586# if HAVE_RAW_DECL_SETSTATE_R 987# if HAVE_RAW_DECL_SETSTATE
587_GL_WARN_ON_USE (setstate, "setstate is unportable - " 988_GL_WARN_ON_USE (setstate, "setstate is unportable - "
588 "use gnulib module random for portability"); 989 "use gnulib module random for portability");
589# endif 990# endif
@@ -664,9 +1065,11 @@ _GL_FUNCDECL_SYS (initstate_r, int,
664 struct random_data *rand_state) 1065 struct random_data *rand_state)
665 _GL_ARG_NONNULL ((2, 4))); 1066 _GL_ARG_NONNULL ((2, 4)));
666# endif 1067# endif
667_GL_CXXALIAS_SYS (initstate_r, int, 1068/* Need to cast, because on Haiku, the third parameter is
668 (unsigned int seed, char *buf, size_t buf_size, 1069 unsigned long buf_size. */
669 struct random_data *rand_state)); 1070_GL_CXXALIAS_SYS_CAST (initstate_r, int,
1071 (unsigned int seed, char *buf, size_t buf_size,
1072 struct random_data *rand_state));
670# endif 1073# endif
671_GL_CXXALIASWARN (initstate_r); 1074_GL_CXXALIASWARN (initstate_r);
672#elif defined GNULIB_POSIXCHECK 1075#elif defined GNULIB_POSIXCHECK
@@ -694,8 +1097,10 @@ _GL_FUNCDECL_SYS (setstate_r, int,
694 (char *arg_state, struct random_data *rand_state) 1097 (char *arg_state, struct random_data *rand_state)
695 _GL_ARG_NONNULL ((1, 2))); 1098 _GL_ARG_NONNULL ((1, 2)));
696# endif 1099# endif
697_GL_CXXALIAS_SYS (setstate_r, int, 1100/* Need to cast, because on Haiku, the first parameter is
698 (char *arg_state, struct random_data *rand_state)); 1101 void *arg_state. */
1102_GL_CXXALIAS_SYS_CAST (setstate_r, int,
1103 (char *arg_state, struct random_data *rand_state));
699# endif 1104# endif
700_GL_CXXALIASWARN (setstate_r); 1105_GL_CXXALIASWARN (setstate_r);
701#elif defined GNULIB_POSIXCHECK 1106#elif defined GNULIB_POSIXCHECK
@@ -708,23 +1113,67 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
708 1113
709 1114
710#if @GNULIB_REALLOC_POSIX@ 1115#if @GNULIB_REALLOC_POSIX@
711# if @REPLACE_REALLOC@ 1116# if (@GNULIB_REALLOC_POSIX@ && @REPLACE_REALLOC_FOR_REALLOC_POSIX@) \
1117 || (@GNULIB_REALLOC_GNU@ && @REPLACE_REALLOC_FOR_REALLOC_GNU@)
712# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \ 1118# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
713 || _GL_USE_STDLIB_ALLOC) 1119 || _GL_USE_STDLIB_ALLOC)
714# undef realloc 1120# undef realloc
715# define realloc rpl_realloc 1121# define realloc rpl_realloc
716# endif 1122# endif
717_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)); 1123_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)
1124 _GL_ATTRIBUTE_DEALLOC_FREE);
718_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); 1125_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
719# else 1126# else
1127# if __GNUC__ >= 11
1128/* For -Wmismatched-dealloc: Associate realloc with free or rpl_free. */
1129_GL_FUNCDECL_SYS (realloc, void *, (void *ptr, size_t size)
1130 _GL_ATTRIBUTE_DEALLOC_FREE);
1131# endif
720_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); 1132_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
721# endif 1133# endif
1134# if __GLIBC__ >= 2
722_GL_CXXALIASWARN (realloc); 1135_GL_CXXALIASWARN (realloc);
723#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC 1136# endif
724# undef realloc 1137#else
1138# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined realloc
1139/* For -Wmismatched-dealloc: Associate realloc with free or rpl_free. */
1140_GL_FUNCDECL_SYS (realloc, void *, (void *ptr, size_t size)
1141 _GL_ATTRIBUTE_DEALLOC_FREE);
1142# endif
1143# if defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
1144# undef realloc
725/* Assume realloc is always declared. */ 1145/* Assume realloc is always declared. */
726_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " 1146_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
727 "use gnulib module realloc-posix for portability"); 1147 "use gnulib module realloc-posix for portability");
1148# endif
1149#endif
1150
1151
1152#if @GNULIB_REALLOCARRAY@
1153# if @REPLACE_REALLOCARRAY@
1154# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1155# undef reallocarray
1156# define reallocarray rpl_reallocarray
1157# endif
1158_GL_FUNCDECL_RPL (reallocarray, void *,
1159 (void *ptr, size_t nmemb, size_t size));
1160_GL_CXXALIAS_RPL (reallocarray, void *,
1161 (void *ptr, size_t nmemb, size_t size));
1162# else
1163# if ! @HAVE_REALLOCARRAY@
1164_GL_FUNCDECL_SYS (reallocarray, void *,
1165 (void *ptr, size_t nmemb, size_t size));
1166# endif
1167_GL_CXXALIAS_SYS (reallocarray, void *,
1168 (void *ptr, size_t nmemb, size_t size));
1169# endif
1170_GL_CXXALIASWARN (reallocarray);
1171#elif defined GNULIB_POSIXCHECK
1172# undef reallocarray
1173# if HAVE_RAW_DECL_REALLOCARRAY
1174_GL_WARN_ON_USE (reallocarray, "reallocarray is not portable - "
1175 "use gnulib module reallocarray for portability");
1176# endif
728#endif 1177#endif
729 1178
730#if @GNULIB_REALPATH@ 1179#if @GNULIB_REALPATH@
@@ -732,15 +1181,19 @@ _GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
732# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1181# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
733# define realpath rpl_realpath 1182# define realpath rpl_realpath
734# endif 1183# endif
735_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved) 1184_GL_FUNCDECL_RPL (realpath, char *,
736 _GL_ARG_NONNULL ((1))); 1185 (const char *restrict name, char *restrict resolved)
737_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved)); 1186 _GL_ARG_NONNULL ((1)));
1187_GL_CXXALIAS_RPL (realpath, char *,
1188 (const char *restrict name, char *restrict resolved));
738# else 1189# else
739# if !@HAVE_REALPATH@ 1190# if !@HAVE_REALPATH@
740_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved) 1191_GL_FUNCDECL_SYS (realpath, char *,
741 _GL_ARG_NONNULL ((1))); 1192 (const char *restrict name, char *restrict resolved)
1193 _GL_ARG_NONNULL ((1)));
742# endif 1194# endif
743_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved)); 1195_GL_CXXALIAS_SYS (realpath, char *,
1196 (const char *restrict name, char *restrict resolved));
744# endif 1197# endif
745_GL_CXXALIASWARN (realpath); 1198_GL_CXXALIASWARN (realpath);
746#elif defined GNULIB_POSIXCHECK 1199#elif defined GNULIB_POSIXCHECK
@@ -822,17 +1275,24 @@ _GL_WARN_ON_USE (setenv, "setenv is unportable - "
822# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1275# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
823# define strtod rpl_strtod 1276# define strtod rpl_strtod
824# endif 1277# endif
825_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp) 1278# define GNULIB_defined_strtod_function 1
826 _GL_ARG_NONNULL ((1))); 1279_GL_FUNCDECL_RPL (strtod, double,
827_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp)); 1280 (const char *restrict str, char **restrict endp)
1281 _GL_ARG_NONNULL ((1)));
1282_GL_CXXALIAS_RPL (strtod, double,
1283 (const char *restrict str, char **restrict endp));
828# else 1284# else
829# if !@HAVE_STRTOD@ 1285# if !@HAVE_STRTOD@
830_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp) 1286_GL_FUNCDECL_SYS (strtod, double,
831 _GL_ARG_NONNULL ((1))); 1287 (const char *restrict str, char **restrict endp)
1288 _GL_ARG_NONNULL ((1)));
832# endif 1289# endif
833_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp)); 1290_GL_CXXALIAS_SYS (strtod, double,
1291 (const char *restrict str, char **restrict endp));
834# endif 1292# endif
1293# if __GLIBC__ >= 2
835_GL_CXXALIASWARN (strtod); 1294_GL_CXXALIASWARN (strtod);
1295# endif
836#elif defined GNULIB_POSIXCHECK 1296#elif defined GNULIB_POSIXCHECK
837# undef strtod 1297# undef strtod
838# if HAVE_RAW_DECL_STRTOD 1298# if HAVE_RAW_DECL_STRTOD
@@ -841,6 +1301,79 @@ _GL_WARN_ON_USE (strtod, "strtod is unportable - "
841# endif 1301# endif
842#endif 1302#endif
843 1303
1304#if @GNULIB_STRTOLD@
1305 /* Parse a 'long double' from STRING, updating ENDP if appropriate. */
1306# if @REPLACE_STRTOLD@
1307# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1308# define strtold rpl_strtold
1309# endif
1310# define GNULIB_defined_strtold_function 1
1311_GL_FUNCDECL_RPL (strtold, long double,
1312 (const char *restrict str, char **restrict endp)
1313 _GL_ARG_NONNULL ((1)));
1314_GL_CXXALIAS_RPL (strtold, long double,
1315 (const char *restrict str, char **restrict endp));
1316# else
1317# if !@HAVE_STRTOLD@
1318_GL_FUNCDECL_SYS (strtold, long double,
1319 (const char *restrict str, char **restrict endp)
1320 _GL_ARG_NONNULL ((1)));
1321# endif
1322_GL_CXXALIAS_SYS (strtold, long double,
1323 (const char *restrict str, char **restrict endp));
1324# endif
1325_GL_CXXALIASWARN (strtold);
1326#elif defined GNULIB_POSIXCHECK
1327# undef strtold
1328# if HAVE_RAW_DECL_STRTOLD
1329_GL_WARN_ON_USE (strtold, "strtold is unportable - "
1330 "use gnulib module strtold for portability");
1331# endif
1332#endif
1333
1334#if @GNULIB_STRTOL@
1335/* Parse a signed integer whose textual representation starts at STRING.
1336 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1337 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1338 "0x").
1339 If ENDPTR is not NULL, the address of the first byte after the integer is
1340 stored in *ENDPTR.
1341 Upon overflow, the return value is LONG_MAX or LONG_MIN, and errno is set
1342 to ERANGE. */
1343# if @REPLACE_STRTOL@
1344# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1345# define strtol rpl_strtol
1346# endif
1347# define GNULIB_defined_strtol_function 1
1348_GL_FUNCDECL_RPL (strtol, long,
1349 (const char *restrict string, char **restrict endptr,
1350 int base)
1351 _GL_ARG_NONNULL ((1)));
1352_GL_CXXALIAS_RPL (strtol, long,
1353 (const char *restrict string, char **restrict endptr,
1354 int base));
1355# else
1356# if !@HAVE_STRTOL@
1357_GL_FUNCDECL_SYS (strtol, long,
1358 (const char *restrict string, char **restrict endptr,
1359 int base)
1360 _GL_ARG_NONNULL ((1)));
1361# endif
1362_GL_CXXALIAS_SYS (strtol, long,
1363 (const char *restrict string, char **restrict endptr,
1364 int base));
1365# endif
1366# if __GLIBC__ >= 2
1367_GL_CXXALIASWARN (strtol);
1368# endif
1369#elif defined GNULIB_POSIXCHECK
1370# undef strtol
1371# if HAVE_RAW_DECL_STRTOL
1372_GL_WARN_ON_USE (strtol, "strtol is unportable - "
1373 "use gnulib module strtol for portability");
1374# endif
1375#endif
1376
844#if @GNULIB_STRTOLL@ 1377#if @GNULIB_STRTOLL@
845/* Parse a signed integer whose textual representation starts at STRING. 1378/* Parse a signed integer whose textual representation starts at STRING.
846 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, 1379 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
@@ -850,13 +1383,29 @@ _GL_WARN_ON_USE (strtod, "strtod is unportable - "
850 stored in *ENDPTR. 1383 stored in *ENDPTR.
851 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set 1384 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
852 to ERANGE. */ 1385 to ERANGE. */
853# if !@HAVE_STRTOLL@ 1386# if @REPLACE_STRTOLL@
1387# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1388# define strtoll rpl_strtoll
1389# endif
1390# define GNULIB_defined_strtoll_function 1
1391_GL_FUNCDECL_RPL (strtoll, long long,
1392 (const char *restrict string, char **restrict endptr,
1393 int base)
1394 _GL_ARG_NONNULL ((1)));
1395_GL_CXXALIAS_RPL (strtoll, long long,
1396 (const char *restrict string, char **restrict endptr,
1397 int base));
1398# else
1399# if !@HAVE_STRTOLL@
854_GL_FUNCDECL_SYS (strtoll, long long, 1400_GL_FUNCDECL_SYS (strtoll, long long,
855 (const char *string, char **endptr, int base) 1401 (const char *restrict string, char **restrict endptr,
1402 int base)
856 _GL_ARG_NONNULL ((1))); 1403 _GL_ARG_NONNULL ((1)));
857# endif 1404# endif
858_GL_CXXALIAS_SYS (strtoll, long long, 1405_GL_CXXALIAS_SYS (strtoll, long long,
859 (const char *string, char **endptr, int base)); 1406 (const char *restrict string, char **restrict endptr,
1407 int base));
1408# endif
860_GL_CXXALIASWARN (strtoll); 1409_GL_CXXALIASWARN (strtoll);
861#elif defined GNULIB_POSIXCHECK 1410#elif defined GNULIB_POSIXCHECK
862# undef strtoll 1411# undef strtoll
@@ -866,6 +1415,48 @@ _GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
866# endif 1415# endif
867#endif 1416#endif
868 1417
1418#if @GNULIB_STRTOUL@
1419/* Parse an unsigned integer whose textual representation starts at STRING.
1420 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1421 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1422 "0x").
1423 If ENDPTR is not NULL, the address of the first byte after the integer is
1424 stored in *ENDPTR.
1425 Upon overflow, the return value is ULONG_MAX, and errno is set to ERANGE. */
1426# if @REPLACE_STRTOUL@
1427# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1428# define strtoul rpl_strtoul
1429# endif
1430# define GNULIB_defined_strtoul_function 1
1431_GL_FUNCDECL_RPL (strtoul, unsigned long,
1432 (const char *restrict string, char **restrict endptr,
1433 int base)
1434 _GL_ARG_NONNULL ((1)));
1435_GL_CXXALIAS_RPL (strtoul, unsigned long,
1436 (const char *restrict string, char **restrict endptr,
1437 int base));
1438# else
1439# if !@HAVE_STRTOUL@
1440_GL_FUNCDECL_SYS (strtoul, unsigned long,
1441 (const char *restrict string, char **restrict endptr,
1442 int base)
1443 _GL_ARG_NONNULL ((1)));
1444# endif
1445_GL_CXXALIAS_SYS (strtoul, unsigned long,
1446 (const char *restrict string, char **restrict endptr,
1447 int base));
1448# endif
1449# if __GLIBC__ >= 2
1450_GL_CXXALIASWARN (strtoul);
1451# endif
1452#elif defined GNULIB_POSIXCHECK
1453# undef strtoul
1454# if HAVE_RAW_DECL_STRTOUL
1455_GL_WARN_ON_USE (strtoul, "strtoul is unportable - "
1456 "use gnulib module strtoul for portability");
1457# endif
1458#endif
1459
869#if @GNULIB_STRTOULL@ 1460#if @GNULIB_STRTOULL@
870/* Parse an unsigned integer whose textual representation starts at STRING. 1461/* Parse an unsigned integer whose textual representation starts at STRING.
871 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, 1462 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
@@ -875,13 +1466,29 @@ _GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
875 stored in *ENDPTR. 1466 stored in *ENDPTR.
876 Upon overflow, the return value is ULLONG_MAX, and errno is set to 1467 Upon overflow, the return value is ULLONG_MAX, and errno is set to
877 ERANGE. */ 1468 ERANGE. */
878# if !@HAVE_STRTOULL@ 1469# if @REPLACE_STRTOULL@
1470# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1471# define strtoull rpl_strtoull
1472# endif
1473# define GNULIB_defined_strtoull_function 1
1474_GL_FUNCDECL_RPL (strtoull, unsigned long long,
1475 (const char *restrict string, char **restrict endptr,
1476 int base)
1477 _GL_ARG_NONNULL ((1)));
1478_GL_CXXALIAS_RPL (strtoull, unsigned long long,
1479 (const char *restrict string, char **restrict endptr,
1480 int base));
1481# else
1482# if !@HAVE_STRTOULL@
879_GL_FUNCDECL_SYS (strtoull, unsigned long long, 1483_GL_FUNCDECL_SYS (strtoull, unsigned long long,
880 (const char *string, char **endptr, int base) 1484 (const char *restrict string, char **restrict endptr,
1485 int base)
881 _GL_ARG_NONNULL ((1))); 1486 _GL_ARG_NONNULL ((1)));
882# endif 1487# endif
883_GL_CXXALIAS_SYS (strtoull, unsigned long long, 1488_GL_CXXALIAS_SYS (strtoull, unsigned long long,
884 (const char *string, char **endptr, int base)); 1489 (const char *restrict string, char **restrict endptr,
1490 int base));
1491# endif
885_GL_CXXALIASWARN (strtoull); 1492_GL_CXXALIASWARN (strtoull);
886#elif defined GNULIB_POSIXCHECK 1493#elif defined GNULIB_POSIXCHECK
887# undef strtoull 1494# undef strtoull
@@ -945,7 +1552,9 @@ _GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc));
945# else 1552# else
946_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc)); 1553_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc));
947# endif 1554# endif
1555# if __GLIBC__ >= 2
948_GL_CXXALIASWARN (wctomb); 1556_GL_CXXALIASWARN (wctomb);
1557# endif
949#endif 1558#endif
950 1559
951 1560
diff --git a/gl/str-two-way.h b/gl/str-two-way.h
index 707145d..dfe7022 100644
--- a/gl/str-two-way.h
+++ b/gl/str-two-way.h
@@ -1,24 +1,24 @@
1/* Byte-wise substring search, using the Two-Way algorithm. 1/* Byte-wise substring search, using the Two-Way algorithm.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008-2023 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 Written by Eric Blake <ebb9@byu.net>, 2008. 4 Written by Eric Blake <ebb9@byu.net>, 2008.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3, or (at your option) 8 published by the Free Software Foundation; either version 2.1 of the
9 any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 with this program; if not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19/* Before including this file, you need to include <config.h> and 19/* Before including this file, you need to include <config.h> and
20 <string.h>, and define: 20 <string.h>, and define:
21 RESULT_TYPE A macro that expands to the return type. 21 RETURN_TYPE A macro that expands to the return type.
22 AVAILABLE(h, h_l, j, n_l) 22 AVAILABLE(h, h_l, j, n_l)
23 A macro that returns nonzero if there are 23 A macro that returns nonzero if there are
24 at least N_L bytes left starting at H[J]. 24 at least N_L bytes left starting at H[J].
@@ -49,9 +49,9 @@
49 character shift table similar to the Boyer-Moore algorithm to 49 character shift table similar to the Boyer-Moore algorithm to
50 achieve improved (potentially sub-linear) performance. 50 achieve improved (potentially sub-linear) performance.
51 51
52 See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260, 52 See https://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260,
53 http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm, 53 https://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm,
54 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.6641&rep=rep1&type=pdf 54 https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.6641&rep=rep1&type=pdf
55*/ 55*/
56 56
57/* Point at which computing a bad-byte shift table is likely to be 57/* Point at which computing a bad-byte shift table is likely to be
@@ -231,7 +231,7 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
231 most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. 231 most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
232 If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 * 232 If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
233 HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */ 233 HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
234static RETURN_TYPE 234static RETURN_TYPE _GL_ATTRIBUTE_PURE
235two_way_short_needle (const unsigned char *haystack, size_t haystack_len, 235two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
236 const unsigned char *needle, size_t needle_len) 236 const unsigned char *needle, size_t needle_len)
237{ 237{
@@ -325,7 +325,7 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
325 If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 * 325 If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
326 HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and 326 HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
327 sublinear performance is not possible. */ 327 sublinear performance is not possible. */
328static RETURN_TYPE 328static RETURN_TYPE _GL_ATTRIBUTE_PURE
329two_way_long_needle (const unsigned char *haystack, size_t haystack_len, 329two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
330 const unsigned char *needle, size_t needle_len) 330 const unsigned char *needle, size_t needle_len)
331{ 331{
diff --git a/gl/strcasecmp.c b/gl/strcasecmp.c
index 0f0a742..3a5ce3e 100644
--- a/gl/strcasecmp.c
+++ b/gl/strcasecmp.c
@@ -1,18 +1,18 @@
1/* Case-insensitive string comparison function. 1/* Case-insensitive string comparison function.
2 Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 1998-1999, 2005-2007, 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
@@ -58,5 +58,5 @@ strcasecmp (const char *s1, const char *s2)
58 /* On machines where 'char' and 'int' are types of the same size, the 58 /* On machines where 'char' and 'int' are types of the same size, the
59 difference of two 'unsigned char' values - including the sign bit - 59 difference of two 'unsigned char' values - including the sign bit -
60 doesn't fit in an 'int'. */ 60 doesn't fit in an 'int'. */
61 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); 61 return _GL_CMP (c1, c2);
62} 62}
diff --git a/gl/strcasestr.c b/gl/strcasestr.c
index 53474a4..8eea435 100644
--- a/gl/strcasestr.c
+++ b/gl/strcasestr.c
@@ -1,19 +1,19 @@
1/* Case-insensitive searching in a string. 1/* Case-insensitive searching in a string.
2 Copyright (C) 2005-2013 Free Software Foundation, Inc. 2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2005. 3 Written by Bruno Haible <bruno@clisp.org>, 2005.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -21,7 +21,6 @@
21#include <string.h> 21#include <string.h>
22 22
23#include <ctype.h> 23#include <ctype.h>
24#include <stdbool.h>
25#include <strings.h> 24#include <strings.h>
26 25
27#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) 26#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
diff --git a/gl/streq.h b/gl/streq.h
index 12c1867..712948e 100644
--- a/gl/streq.h
+++ b/gl/streq.h
@@ -1,18 +1,18 @@
1/* Optimized string comparison. 1/* Optimized string comparison.
2 Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 2001-2002, 2007, 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify it 4 This file is free software: you can redistribute it and/or modify
5 under the terms of the GNU General Public License as published 5 it under the terms of the GNU Lesser General Public License as
6 by the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation; either version 2.1 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Written by Bruno Haible <bruno@clisp.org>. */ 17/* Written by Bruno Haible <bruno@clisp.org>. */
18 18
@@ -29,7 +29,7 @@
29 29
30/* Help GCC to generate good code for string comparisons with 30/* Help GCC to generate good code for string comparisons with
31 immediate strings. */ 31 immediate strings. */
32#if defined (__GNUC__) && defined (__OPTIMIZE__) 32#if (defined __GNUC__ || defined __clang__) && defined __OPTIMIZE__
33 33
34static inline int 34static inline int
35streq9 (const char *s1, const char *s2) 35streq9 (const char *s1, const char *s2)
diff --git a/gl/strerror-override.c b/gl/strerror-override.c
index d0ed2fb..cddaa4a 100644
--- a/gl/strerror-override.c
+++ b/gl/strerror-override.c
@@ -1,19 +1,19 @@
1/* strerror-override.c --- POSIX compatible system error routine 1/* strerror-override.c --- POSIX compatible system error routine
2 2
3 Copyright (C) 2010-2013 Free Software Foundation, Inc. 3 Copyright (C) 2010-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Bruno Haible <bruno@clisp.org>, 2010. */ 18/* Written by Bruno Haible <bruno@clisp.org>, 2010. */
19 19
@@ -29,6 +29,8 @@
29# endif 29# endif
30#endif 30#endif
31 31
32#if !GNULIB_defined_strerror_override_macro
33
32/* If ERRNUM maps to an errno value defined by gnulib, return a string 34/* If ERRNUM maps to an errno value defined by gnulib, return a string
33 describing the error. Otherwise return NULL. */ 35 describing the error. Otherwise return NULL. */
34const char * 36const char *
@@ -37,12 +39,12 @@ strerror_override (int errnum)
37 /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */ 39 /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
38 switch (errnum) 40 switch (errnum)
39 { 41 {
40#if REPLACE_STRERROR_0 42# if REPLACE_STRERROR_0
41 case 0: 43 case 0:
42 return "Success"; 44 return "Success";
43#endif 45# endif
44 46
45#if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */ 47# if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
46 case EINPROGRESS: 48 case EINPROGRESS:
47 return "Operation now in progress"; 49 return "Operation now in progress";
48 case EALREADY: 50 case EALREADY:
@@ -89,8 +91,8 @@ strerror_override (int errnum)
89 return "No route to host"; 91 return "No route to host";
90 case EWOULDBLOCK: 92 case EWOULDBLOCK:
91 return "Operation would block"; 93 return "Operation would block";
92#endif 94# endif
93#if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */ 95# if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */
94 case ETXTBSY: 96 case ETXTBSY:
95 return "Text file busy"; 97 return "Text file busy";
96 case ENODATA: 98 case ENODATA:
@@ -103,8 +105,8 @@ strerror_override (int errnum)
103 return "Timer expired"; 105 return "Timer expired";
104 case EOTHER: 106 case EOTHER:
105 return "Other error"; 107 return "Other error";
106#endif 108# endif
107#if GNULIB_defined_EWINSOCK /* native Windows platforms */ 109# if GNULIB_defined_EWINSOCK /* native Windows platforms */
108 case ESOCKTNOSUPPORT: 110 case ESOCKTNOSUPPORT:
109 return "Socket type not supported"; 111 return "Socket type not supported";
110 case EPFNOSUPPORT: 112 case EPFNOSUPPORT:
@@ -125,7 +127,7 @@ strerror_override (int errnum)
125 return "Stale NFS file handle"; 127 return "Stale NFS file handle";
126 case EREMOTE: 128 case EREMOTE:
127 return "Object is remote"; 129 return "Object is remote";
128# if HAVE_WINSOCK2_H 130# if HAVE_WINSOCK2_H
129 /* WSA_INVALID_HANDLE maps to EBADF */ 131 /* WSA_INVALID_HANDLE maps to EBADF */
130 /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */ 132 /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
131 /* WSA_INVALID_PARAMETER maps to EINVAL */ 133 /* WSA_INVALID_PARAMETER maps to EINVAL */
@@ -213,90 +215,92 @@ strerror_override (int errnum)
213 case WSANO_DATA: 215 case WSANO_DATA:
214 return "Valid name, no data record of requested type"; 216 return "Valid name, no data record of requested type";
215 /* WSA_QOS_* omitted */ 217 /* WSA_QOS_* omitted */
218# endif
216# endif 219# endif
217#endif
218 220
219#if GNULIB_defined_ENOMSG 221# if GNULIB_defined_ENOMSG
220 case ENOMSG: 222 case ENOMSG:
221 return "No message of desired type"; 223 return "No message of desired type";
222#endif 224# endif
223 225
224#if GNULIB_defined_EIDRM 226# if GNULIB_defined_EIDRM
225 case EIDRM: 227 case EIDRM:
226 return "Identifier removed"; 228 return "Identifier removed";
227#endif 229# endif
228 230
229#if GNULIB_defined_ENOLINK 231# if GNULIB_defined_ENOLINK
230 case ENOLINK: 232 case ENOLINK:
231 return "Link has been severed"; 233 return "Link has been severed";
232#endif 234# endif
233 235
234#if GNULIB_defined_EPROTO 236# if GNULIB_defined_EPROTO
235 case EPROTO: 237 case EPROTO:
236 return "Protocol error"; 238 return "Protocol error";
237#endif 239# endif
238 240
239#if GNULIB_defined_EMULTIHOP 241# if GNULIB_defined_EMULTIHOP
240 case EMULTIHOP: 242 case EMULTIHOP:
241 return "Multihop attempted"; 243 return "Multihop attempted";
242#endif 244# endif
243 245
244#if GNULIB_defined_EBADMSG 246# if GNULIB_defined_EBADMSG
245 case EBADMSG: 247 case EBADMSG:
246 return "Bad message"; 248 return "Bad message";
247#endif 249# endif
248 250
249#if GNULIB_defined_EOVERFLOW 251# if GNULIB_defined_EOVERFLOW
250 case EOVERFLOW: 252 case EOVERFLOW:
251 return "Value too large for defined data type"; 253 return "Value too large for defined data type";
252#endif 254# endif
253 255
254#if GNULIB_defined_ENOTSUP 256# if GNULIB_defined_ENOTSUP
255 case ENOTSUP: 257 case ENOTSUP:
256 return "Not supported"; 258 return "Not supported";
257#endif 259# endif
258 260
259#if GNULIB_defined_ENETRESET 261# if GNULIB_defined_ENETRESET
260 case ENETRESET: 262 case ENETRESET:
261 return "Network dropped connection on reset"; 263 return "Network dropped connection on reset";
262#endif 264# endif
263 265
264#if GNULIB_defined_ECONNABORTED 266# if GNULIB_defined_ECONNABORTED
265 case ECONNABORTED: 267 case ECONNABORTED:
266 return "Software caused connection abort"; 268 return "Software caused connection abort";
267#endif 269# endif
268 270
269#if GNULIB_defined_ESTALE 271# if GNULIB_defined_ESTALE
270 case ESTALE: 272 case ESTALE:
271 return "Stale NFS file handle"; 273 return "Stale NFS file handle";
272#endif 274# endif
273 275
274#if GNULIB_defined_EDQUOT 276# if GNULIB_defined_EDQUOT
275 case EDQUOT: 277 case EDQUOT:
276 return "Disk quota exceeded"; 278 return "Disk quota exceeded";
277#endif 279# endif
278 280
279#if GNULIB_defined_ECANCELED 281# if GNULIB_defined_ECANCELED
280 case ECANCELED: 282 case ECANCELED:
281 return "Operation canceled"; 283 return "Operation canceled";
282#endif 284# endif
283 285
284#if GNULIB_defined_EOWNERDEAD 286# if GNULIB_defined_EOWNERDEAD
285 case EOWNERDEAD: 287 case EOWNERDEAD:
286 return "Owner died"; 288 return "Owner died";
287#endif 289# endif
288 290
289#if GNULIB_defined_ENOTRECOVERABLE 291# if GNULIB_defined_ENOTRECOVERABLE
290 case ENOTRECOVERABLE: 292 case ENOTRECOVERABLE:
291 return "State not recoverable"; 293 return "State not recoverable";
292#endif 294# endif
293 295
294#if GNULIB_defined_EILSEQ 296# if GNULIB_defined_EILSEQ
295 case EILSEQ: 297 case EILSEQ:
296 return "Invalid or incomplete multibyte or wide character"; 298 return "Invalid or incomplete multibyte or wide character";
297#endif 299# endif
298 300
299 default: 301 default:
300 return NULL; 302 return NULL;
301 } 303 }
302} 304}
305
306#endif
diff --git a/gl/strerror-override.h b/gl/strerror-override.h
index 3b8f24b..388cc28 100644
--- a/gl/strerror-override.h
+++ b/gl/strerror-override.h
@@ -1,19 +1,19 @@
1/* strerror-override.h --- POSIX compatible system error routine 1/* strerror-override.h --- POSIX compatible system error routine
2 2
3 Copyright (C) 2010-2013 Free Software Foundation, Inc. 3 Copyright (C) 2010-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _GL_STRERROR_OVERRIDE_H 18#ifndef _GL_STRERROR_OVERRIDE_H
19# define _GL_STRERROR_OVERRIDE_H 19# define _GL_STRERROR_OVERRIDE_H
@@ -48,9 +48,10 @@
48 || GNULIB_defined_EOWNERDEAD \ 48 || GNULIB_defined_EOWNERDEAD \
49 || GNULIB_defined_ENOTRECOVERABLE \ 49 || GNULIB_defined_ENOTRECOVERABLE \
50 || GNULIB_defined_EILSEQ 50 || GNULIB_defined_EILSEQ
51extern const char *strerror_override (int errnum); 51extern const char *strerror_override (int errnum) _GL_ATTRIBUTE_CONST;
52# else 52# else
53# define strerror_override(ignored) NULL 53# define strerror_override(ignored) NULL
54# define GNULIB_defined_strerror_override_macro 1
54# endif 55# endif
55 56
56#endif /* _GL_STRERROR_OVERRIDE_H */ 57#endif /* _GL_STRERROR_OVERRIDE_H */
diff --git a/gl/strerror.c b/gl/strerror.c
index 80a2f2e..d754f60 100644
--- a/gl/strerror.c
+++ b/gl/strerror.c
@@ -1,19 +1,19 @@
1/* strerror.c --- POSIX compatible system error routine 1/* strerror.c --- POSIX compatible system error routine
2 2
3 Copyright (C) 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -27,7 +27,6 @@
27 27
28#include "intprops.h" 28#include "intprops.h"
29#include "strerror-override.h" 29#include "strerror-override.h"
30#include "verify.h"
31 30
32/* Use the system functions, not the gnulib overrides in this file. */ 31/* Use the system functions, not the gnulib overrides in this file. */
33#undef sprintf 32#undef sprintf
@@ -55,7 +54,7 @@ strerror (int n)
55 if (!msg || !*msg) 54 if (!msg || !*msg)
56 { 55 {
57 static char const fmt[] = "Unknown error %d"; 56 static char const fmt[] = "Unknown error %d";
58 verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n)); 57 static_assert (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n));
59 sprintf (buf, fmt, n); 58 sprintf (buf, fmt, n);
60 errno = EINVAL; 59 errno = EINVAL;
61 return buf; 60 return buf;
@@ -66,5 +65,6 @@ strerror (int n)
66 if (sizeof buf <= len) 65 if (sizeof buf <= len)
67 abort (); 66 abort ();
68 67
69 return memcpy (buf, msg, len + 1); 68 memcpy (buf, msg, len + 1);
69 return buf;
70} 70}
diff --git a/gl/string.in.h b/gl/string.in.h
index d7a6c9c..e993b2f 100644
--- a/gl/string.in.h
+++ b/gl/string.in.h
@@ -1,30 +1,46 @@
1/* A GNU-like <string.h>. 1/* A GNU-like <string.h>.
2 2
3 Copyright (C) 1995-1996, 2001-2013 Free Software Foundation, Inc. 3 Copyright (C) 1995-1996, 2001-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _@GUARD_PREFIX@_STRING_H
19 17
20#if __GNUC__ >= 3 18#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@ 19@PRAGMA_SYSTEM_HEADER@
22#endif 20#endif
23@PRAGMA_COLUMNS@ 21@PRAGMA_COLUMNS@
24 22
23#if defined _GL_ALREADY_INCLUDING_STRING_H
24/* Special invocation convention:
25 - On OS X/NetBSD we have a sequence of nested includes
26 <string.h> -> <strings.h> -> "string.h"
27 In this situation system _chk variants due to -D_FORTIFY_SOURCE
28 might be used after any replacements defined here. */
29
30#@INCLUDE_NEXT@ @NEXT_STRING_H@
31
32#else
33/* Normal invocation convention. */
34
35#ifndef _@GUARD_PREFIX@_STRING_H
36
37#define _GL_ALREADY_INCLUDING_STRING_H
38
25/* The include_next requires a split double-inclusion guard. */ 39/* The include_next requires a split double-inclusion guard. */
26#@INCLUDE_NEXT@ @NEXT_STRING_H@ 40#@INCLUDE_NEXT@ @NEXT_STRING_H@
27 41
42#undef _GL_ALREADY_INCLUDING_STRING_H
43
28#ifndef _@GUARD_PREFIX@_STRING_H 44#ifndef _@GUARD_PREFIX@_STRING_H
29#define _@GUARD_PREFIX@_STRING_H 45#define _@GUARD_PREFIX@_STRING_H
30 46
@@ -36,14 +52,6 @@
36# include <wchar.h> 52# include <wchar.h>
37#endif 53#endif
38 54
39/* The __attribute__ feature is available in gcc versions 2.5 and later.
40 The attribute __pure__ was added in gcc 2.96. */
41#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
42# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
43#else
44# define _GL_ATTRIBUTE_PURE /* empty */
45#endif
46
47/* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */ 55/* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
48/* But in any case avoid namespace pollution on glibc systems. */ 56/* But in any case avoid namespace pollution on glibc systems. */
49#if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \ 57#if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
@@ -51,12 +59,122 @@
51# include <unistd.h> 59# include <unistd.h>
52#endif 60#endif
53 61
62/* AIX 7.2 declares ffsl and ffsll in <strings.h>, not in <string.h>. */
63/* But in any case avoid namespace pollution on glibc systems. */
64#if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \
65 && defined _AIX) \
66 && ! defined __GLIBC__
67# include <strings.h>
68#endif
69
70/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
71 that can be freed by passing them as the Ith argument to the
72 function F. */
73#ifndef _GL_ATTRIBUTE_DEALLOC
74# if __GNUC__ >= 11
75# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
76# else
77# define _GL_ATTRIBUTE_DEALLOC(f, i)
78# endif
79#endif
80
81/* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
82 can be freed via 'free'; it can be used only after declaring 'free'. */
83/* Applies to: functions. Cannot be used on inline functions. */
84#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
85# if defined __cplusplus && defined __GNUC__ && !defined __clang__
86/* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
87# define _GL_ATTRIBUTE_DEALLOC_FREE \
88 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
89# else
90# define _GL_ATTRIBUTE_DEALLOC_FREE \
91 _GL_ATTRIBUTE_DEALLOC (free, 1)
92# endif
93#endif
94
95/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
96 allocated memory. */
97/* Applies to: functions. */
98#ifndef _GL_ATTRIBUTE_MALLOC
99# if __GNUC__ >= 3 || defined __clang__
100# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
101# else
102# define _GL_ATTRIBUTE_MALLOC
103# endif
104#endif
105
106/* The __attribute__ feature is available in gcc versions 2.5 and later.
107 The attribute __pure__ was added in gcc 2.96. */
108#ifndef _GL_ATTRIBUTE_PURE
109# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
110# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
111# else
112# define _GL_ATTRIBUTE_PURE /* empty */
113# endif
114#endif
115
54/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 116/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
55 117
56/* The definition of _GL_ARG_NONNULL is copied here. */ 118/* The definition of _GL_ARG_NONNULL is copied here. */
57 119
58/* The definition of _GL_WARN_ON_USE is copied here. */ 120/* The definition of _GL_WARN_ON_USE is copied here. */
59 121
122/* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
123 been included yet. */
124#if @GNULIB_FREE_POSIX@
125# if (@REPLACE_FREE@ && !defined free \
126 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
127/* We can't do '#define free rpl_free' here. */
128_GL_EXTERN_C void rpl_free (void *);
129# undef _GL_ATTRIBUTE_DEALLOC_FREE
130# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
131# else
132# if defined _MSC_VER && !defined free
133_GL_EXTERN_C
134# if defined _DLL
135 __declspec (dllimport)
136# endif
137 void __cdecl free (void *);
138# else
139# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
140_GL_EXTERN_C void free (void *) throw ();
141# else
142_GL_EXTERN_C void free (void *);
143# endif
144# endif
145# endif
146#else
147# if defined _MSC_VER && !defined free
148_GL_EXTERN_C
149# if defined _DLL
150 __declspec (dllimport)
151# endif
152 void __cdecl free (void *);
153# else
154# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
155_GL_EXTERN_C void free (void *) throw ();
156# else
157_GL_EXTERN_C void free (void *);
158# endif
159# endif
160#endif
161
162/* Clear a block of memory. The compiler will not delete a call to
163 this function, even if the block is dead after the call. */
164#if @GNULIB_EXPLICIT_BZERO@
165# if ! @HAVE_EXPLICIT_BZERO@
166_GL_FUNCDECL_SYS (explicit_bzero, void,
167 (void *__dest, size_t __n) _GL_ARG_NONNULL ((1)));
168# endif
169_GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
170_GL_CXXALIASWARN (explicit_bzero);
171#elif defined GNULIB_POSIXCHECK
172# undef explicit_bzero
173# if HAVE_RAW_DECL_EXPLICIT_BZERO
174_GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
175 "use gnulib module explicit_bzero for portability");
176# endif
177#endif
60 178
61/* Find the index of the least-significant set bit. */ 179/* Find the index of the least-significant set bit. */
62#if @GNULIB_FFSL@ 180#if @GNULIB_FFSL@
@@ -75,10 +193,18 @@ _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
75 193
76/* Find the index of the least-significant set bit. */ 194/* Find the index of the least-significant set bit. */
77#if @GNULIB_FFSLL@ 195#if @GNULIB_FFSLL@
78# if !@HAVE_FFSLL@ 196# if @REPLACE_FFSLL@
197# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
198# define ffsll rpl_ffsll
199# endif
200_GL_FUNCDECL_RPL (ffsll, int, (long long int i));
201_GL_CXXALIAS_RPL (ffsll, int, (long long int i));
202# else
203# if !@HAVE_FFSLL@
79_GL_FUNCDECL_SYS (ffsll, int, (long long int i)); 204_GL_FUNCDECL_SYS (ffsll, int, (long long int i));
80# endif 205# endif
81_GL_CXXALIAS_SYS (ffsll, int, (long long int i)); 206_GL_CXXALIAS_SYS (ffsll, int, (long long int i));
207# endif
82_GL_CXXALIASWARN (ffsll); 208_GL_CXXALIASWARN (ffsll);
83#elif defined GNULIB_POSIXCHECK 209#elif defined GNULIB_POSIXCHECK
84# undef ffsll 210# undef ffsll
@@ -88,10 +214,30 @@ _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
88#endif 214#endif
89 215
90 216
217#if @GNULIB_MDA_MEMCCPY@
218/* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
219 required. In C++ with GNULIB_NAMESPACE, avoid differences between
220 platforms by defining GNULIB_NAMESPACE::memccpy always. */
221# if defined _WIN32 && !defined __CYGWIN__
222# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
223# undef memccpy
224# define memccpy _memccpy
225# endif
226_GL_CXXALIAS_MDA (memccpy, void *,
227 (void *dest, const void *src, int c, size_t n));
228# else
229_GL_CXXALIAS_SYS (memccpy, void *,
230 (void *dest, const void *src, int c, size_t n));
231# endif
232_GL_CXXALIASWARN (memccpy);
233#endif
234
235
91/* Return the first instance of C within N bytes of S, or NULL. */ 236/* Return the first instance of C within N bytes of S, or NULL. */
92#if @GNULIB_MEMCHR@ 237#if @GNULIB_MEMCHR@
93# if @REPLACE_MEMCHR@ 238# if @REPLACE_MEMCHR@
94# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 239# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
240# undef memchr
95# define memchr rpl_memchr 241# define memchr rpl_memchr
96# endif 242# endif
97_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) 243_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
@@ -99,11 +245,6 @@ _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
99 _GL_ARG_NONNULL ((1))); 245 _GL_ARG_NONNULL ((1)));
100_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); 246_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
101# else 247# else
102# if ! @HAVE_MEMCHR@
103_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
104 _GL_ATTRIBUTE_PURE
105 _GL_ARG_NONNULL ((1)));
106# endif
107 /* On some systems, this function is defined as an overloaded function: 248 /* On some systems, this function is defined as an overloaded function:
108 extern "C" { const void * std::memchr (const void *, int, size_t); } 249 extern "C" { const void * std::memchr (const void *, int, size_t); }
109 extern "C++" { void * std::memchr (void *, int, size_t); } */ 250 extern "C++" { void * std::memchr (void *, int, size_t); } */
@@ -112,11 +253,12 @@ _GL_CXXALIAS_SYS_CAST2 (memchr,
112 void const *, (void const *__s, int __c, size_t __n)); 253 void const *, (void const *__s, int __c, size_t __n));
113# endif 254# endif
114# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 255# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
115 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 256 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
116_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n)); 257 || defined __clang__)
258_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n) throw ());
117_GL_CXXALIASWARN1 (memchr, void const *, 259_GL_CXXALIASWARN1 (memchr, void const *,
118 (void const *__s, int __c, size_t __n)); 260 (void const *__s, int __c, size_t __n) throw ());
119# else 261# elif __GLIBC__ >= 2
120_GL_CXXALIASWARN (memchr); 262_GL_CXXALIASWARN (memchr);
121# endif 263# endif
122#elif defined GNULIB_POSIXCHECK 264#elif defined GNULIB_POSIXCHECK
@@ -197,9 +339,10 @@ _GL_CXXALIAS_SYS_CAST2 (memrchr,
197 void *, (void const *, int, size_t), 339 void *, (void const *, int, size_t),
198 void const *, (void const *, int, size_t)); 340 void const *, (void const *, int, size_t));
199# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 341# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
200 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 342 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
201_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t)); 343 || defined __clang__)
202_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t)); 344_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t) throw ());
345_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t) throw ());
203# else 346# else
204_GL_CXXALIASWARN (memrchr); 347_GL_CXXALIASWARN (memrchr);
205# endif 348# endif
@@ -211,6 +354,23 @@ _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
211# endif 354# endif
212#endif 355#endif
213 356
357/* Overwrite a block of memory. The compiler will not optimize
358 effects away, even if the block is dead after the call. */
359#if @GNULIB_MEMSET_EXPLICIT@
360# if ! @HAVE_MEMSET_EXPLICIT@
361_GL_FUNCDECL_SYS (memset_explicit, void *,
362 (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1)));
363# endif
364_GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n));
365_GL_CXXALIASWARN (memset_explicit);
366#elif defined GNULIB_POSIXCHECK
367# undef memset_explicit
368# if HAVE_RAW_DECL_MEMSET_EXPLICIT
369_GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - "
370 "use gnulib module memset_explicit for portability");
371# endif
372#endif
373
214/* Find the first occurrence of C in S. More efficient than 374/* Find the first occurrence of C in S. More efficient than
215 memchr(S,C,N), at the expense of undefined behavior if C does not 375 memchr(S,C,N), at the expense of undefined behavior if C does not
216 occur within N bytes. */ 376 occur within N bytes. */
@@ -227,9 +387,11 @@ _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
227 void *, (void const *__s, int __c_in), 387 void *, (void const *__s, int __c_in),
228 void const *, (void const *__s, int __c_in)); 388 void const *, (void const *__s, int __c_in));
229# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 389# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
230 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 390 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
231_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in)); 391 || defined __clang__)
232_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in)); 392_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in) throw ());
393_GL_CXXALIASWARN1 (rawmemchr, void const *,
394 (void const *__s, int __c_in) throw ());
233# else 395# else
234_GL_CXXALIASWARN (rawmemchr); 396_GL_CXXALIASWARN (rawmemchr);
235# endif 397# endif
@@ -299,9 +461,11 @@ _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
299 GB18030 and the character to be searched is a digit. */ 461 GB18030 and the character to be searched is a digit. */
300# undef strchr 462# undef strchr
301/* Assume strchr is always declared. */ 463/* Assume strchr is always declared. */
302_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings " 464_GL_WARN_ON_USE_CXX (strchr,
303 "in some multibyte locales - " 465 const char *, char *, (const char *, int),
304 "use mbschr if you care about internationalization"); 466 "strchr cannot work correctly on character strings "
467 "in some multibyte locales - "
468 "use mbschr if you care about internationalization");
305#endif 469#endif
306 470
307/* Find the first occurrence of C in S or the final NUL byte. */ 471/* Find the first occurrence of C in S or the final NUL byte. */
@@ -329,9 +493,11 @@ _GL_CXXALIAS_SYS_CAST2 (strchrnul,
329 char const *, (char const *__s, int __c_in)); 493 char const *, (char const *__s, int __c_in));
330# endif 494# endif
331# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 495# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
332 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 496 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
333_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in)); 497 || defined __clang__)
334_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in)); 498_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in) throw ());
499_GL_CXXALIASWARN1 (strchrnul, char const *,
500 (char const *__s, int __c_in) throw ());
335# else 501# else
336_GL_CXXALIASWARN (strchrnul); 502_GL_CXXALIASWARN (strchrnul);
337# endif 503# endif
@@ -350,24 +516,62 @@ _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
350# undef strdup 516# undef strdup
351# define strdup rpl_strdup 517# define strdup rpl_strdup
352# endif 518# endif
353_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); 519_GL_FUNCDECL_RPL (strdup, char *,
520 (char const *__s)
521 _GL_ARG_NONNULL ((1))
522 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
354_GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); 523_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
524# elif defined _WIN32 && !defined __CYGWIN__
525# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
526# undef strdup
527# define strdup _strdup
528# endif
529_GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
355# else 530# else
356# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup 531# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
357 /* strdup exists as a function and as a macro. Get rid of the macro. */ 532 /* strdup exists as a function and as a macro. Get rid of the macro. */
358# undef strdup 533# undef strdup
359# endif 534# endif
360# if !(@HAVE_DECL_STRDUP@ || defined strdup) 535# if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
361_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); 536_GL_FUNCDECL_SYS (strdup, char *,
537 (char const *__s)
538 _GL_ARG_NONNULL ((1))
539 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
362# endif 540# endif
363_GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); 541_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
364# endif 542# endif
365_GL_CXXALIASWARN (strdup); 543_GL_CXXALIASWARN (strdup);
366#elif defined GNULIB_POSIXCHECK 544#else
367# undef strdup 545# if __GNUC__ >= 11 && !defined strdup
368# if HAVE_RAW_DECL_STRDUP 546/* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
547_GL_FUNCDECL_SYS (strdup, char *,
548 (char const *__s)
549 _GL_ARG_NONNULL ((1))
550 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
551# endif
552# if defined GNULIB_POSIXCHECK
553# undef strdup
554# if HAVE_RAW_DECL_STRDUP
369_GL_WARN_ON_USE (strdup, "strdup is unportable - " 555_GL_WARN_ON_USE (strdup, "strdup is unportable - "
370 "use gnulib module strdup for portability"); 556 "use gnulib module strdup for portability");
557# endif
558# elif @GNULIB_MDA_STRDUP@
559/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
560 required. In C++ with GNULIB_NAMESPACE, avoid differences between
561 platforms by defining GNULIB_NAMESPACE::strdup always. */
562# if defined _WIN32 && !defined __CYGWIN__
563# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
564# undef strdup
565# define strdup _strdup
566# endif
567_GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
568# else
569# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
570# undef strdup
571# endif
572_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
573# endif
574_GL_CXXALIASWARN (strdup);
371# endif 575# endif
372#endif 576#endif
373 577
@@ -378,13 +582,18 @@ _GL_WARN_ON_USE (strdup, "strdup is unportable - "
378# undef strncat 582# undef strncat
379# define strncat rpl_strncat 583# define strncat rpl_strncat
380# endif 584# endif
381_GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n) 585_GL_FUNCDECL_RPL (strncat, char *,
382 _GL_ARG_NONNULL ((1, 2))); 586 (char *restrict dest, const char *restrict src, size_t n)
383_GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n)); 587 _GL_ARG_NONNULL ((1, 2)));
588_GL_CXXALIAS_RPL (strncat, char *,
589 (char *restrict dest, const char *restrict src, size_t n));
384# else 590# else
385_GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n)); 591_GL_CXXALIAS_SYS (strncat, char *,
592 (char *restrict dest, const char *restrict src, size_t n));
386# endif 593# endif
594# if __GLIBC__ >= 2
387_GL_CXXALIASWARN (strncat); 595_GL_CXXALIASWARN (strncat);
596# endif
388#elif defined GNULIB_POSIXCHECK 597#elif defined GNULIB_POSIXCHECK
389# undef strncat 598# undef strncat
390# if HAVE_RAW_DECL_STRNCAT 599# if HAVE_RAW_DECL_STRNCAT
@@ -400,22 +609,35 @@ _GL_WARN_ON_USE (strncat, "strncat is unportable - "
400# undef strndup 609# undef strndup
401# define strndup rpl_strndup 610# define strndup rpl_strndup
402# endif 611# endif
403_GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n) 612_GL_FUNCDECL_RPL (strndup, char *,
404 _GL_ARG_NONNULL ((1))); 613 (char const *__s, size_t __n)
405_GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n)); 614 _GL_ARG_NONNULL ((1))
615 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
616_GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
406# else 617# else
407# if ! @HAVE_DECL_STRNDUP@ 618# if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup)
408_GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n) 619_GL_FUNCDECL_SYS (strndup, char *,
409 _GL_ARG_NONNULL ((1))); 620 (char const *__s, size_t __n)
621 _GL_ARG_NONNULL ((1))
622 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
410# endif 623# endif
411_GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n)); 624_GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
412# endif 625# endif
413_GL_CXXALIASWARN (strndup); 626_GL_CXXALIASWARN (strndup);
414#elif defined GNULIB_POSIXCHECK 627#else
415# undef strndup 628# if __GNUC__ >= 11 && !defined strndup
416# if HAVE_RAW_DECL_STRNDUP 629/* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
630_GL_FUNCDECL_SYS (strndup, char *,
631 (char const *__s, size_t __n)
632 _GL_ARG_NONNULL ((1))
633 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
634# endif
635# if defined GNULIB_POSIXCHECK
636# undef strndup
637# if HAVE_RAW_DECL_STRNDUP
417_GL_WARN_ON_USE (strndup, "strndup is unportable - " 638_GL_WARN_ON_USE (strndup, "strndup is unportable - "
418 "use gnulib module strndup for portability"); 639 "use gnulib module strndup for portability");
640# endif
419# endif 641# endif
420#endif 642#endif
421 643
@@ -428,17 +650,17 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - "
428# undef strnlen 650# undef strnlen
429# define strnlen rpl_strnlen 651# define strnlen rpl_strnlen
430# endif 652# endif
431_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) 653_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)
432 _GL_ATTRIBUTE_PURE 654 _GL_ATTRIBUTE_PURE
433 _GL_ARG_NONNULL ((1))); 655 _GL_ARG_NONNULL ((1)));
434_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); 656_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
435# else 657# else
436# if ! @HAVE_DECL_STRNLEN@ 658# if ! @HAVE_DECL_STRNLEN@
437_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) 659_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)
438 _GL_ATTRIBUTE_PURE 660 _GL_ATTRIBUTE_PURE
439 _GL_ARG_NONNULL ((1))); 661 _GL_ARG_NONNULL ((1)));
440# endif 662# endif
441_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); 663_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
442# endif 664# endif
443_GL_CXXALIASWARN (strnlen); 665_GL_CXXALIASWARN (strnlen);
444#elif defined GNULIB_POSIXCHECK 666#elif defined GNULIB_POSIXCHECK
@@ -475,11 +697,12 @@ _GL_CXXALIAS_SYS_CAST2 (strpbrk,
475 char *, (char const *__s, char const *__accept), 697 char *, (char const *__s, char const *__accept),
476 const char *, (char const *__s, char const *__accept)); 698 const char *, (char const *__s, char const *__accept));
477# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 699# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
478 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 700 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
479_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept)); 701 || defined __clang__)
702_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept) throw ());
480_GL_CXXALIASWARN1 (strpbrk, char const *, 703_GL_CXXALIASWARN1 (strpbrk, char const *,
481 (char const *__s, char const *__accept)); 704 (char const *__s, char const *__accept) throw ());
482# else 705# elif __GLIBC__ >= 2
483_GL_CXXALIASWARN (strpbrk); 706_GL_CXXALIASWARN (strpbrk);
484# endif 707# endif
485# if defined GNULIB_POSIXCHECK 708# if defined GNULIB_POSIXCHECK
@@ -488,15 +711,19 @@ _GL_CXXALIASWARN (strpbrk);
488 locale encoding is GB18030 and one of the characters to be searched is a 711 locale encoding is GB18030 and one of the characters to be searched is a
489 digit. */ 712 digit. */
490# undef strpbrk 713# undef strpbrk
491_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings " 714_GL_WARN_ON_USE_CXX (strpbrk,
492 "in multibyte locales - " 715 const char *, char *, (const char *, const char *),
493 "use mbspbrk if you care about internationalization"); 716 "strpbrk cannot work correctly on character strings "
717 "in multibyte locales - "
718 "use mbspbrk if you care about internationalization");
494# endif 719# endif
495#elif defined GNULIB_POSIXCHECK 720#elif defined GNULIB_POSIXCHECK
496# undef strpbrk 721# undef strpbrk
497# if HAVE_RAW_DECL_STRPBRK 722# if HAVE_RAW_DECL_STRPBRK
498_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - " 723_GL_WARN_ON_USE_CXX (strpbrk,
499 "use gnulib module strpbrk for portability"); 724 const char *, char *, (const char *, const char *),
725 "strpbrk is unportable - "
726 "use gnulib module strpbrk for portability");
500# endif 727# endif
501#endif 728#endif
502 729
@@ -515,9 +742,11 @@ _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
515 GB18030 and the character to be searched is a digit. */ 742 GB18030 and the character to be searched is a digit. */
516# undef strrchr 743# undef strrchr
517/* Assume strrchr is always declared. */ 744/* Assume strrchr is always declared. */
518_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings " 745_GL_WARN_ON_USE_CXX (strrchr,
519 "in some multibyte locales - " 746 const char *, char *, (const char *, int),
520 "use mbsrchr if you care about internationalization"); 747 "strrchr cannot work correctly on character strings "
748 "in some multibyte locales - "
749 "use mbsrchr if you care about internationalization");
521#endif 750#endif
522 751
523/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. 752/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
@@ -577,11 +806,13 @@ _GL_CXXALIAS_SYS_CAST2 (strstr,
577 const char *, (const char *haystack, const char *needle)); 806 const char *, (const char *haystack, const char *needle));
578# endif 807# endif
579# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 808# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
580 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 809 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
581_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle)); 810 || defined __clang__)
811_GL_CXXALIASWARN1 (strstr, char *,
812 (char *haystack, const char *needle) throw ());
582_GL_CXXALIASWARN1 (strstr, const char *, 813_GL_CXXALIASWARN1 (strstr, const char *,
583 (const char *haystack, const char *needle)); 814 (const char *haystack, const char *needle) throw ());
584# else 815# elif __GLIBC__ >= 2
585_GL_CXXALIASWARN (strstr); 816_GL_CXXALIASWARN (strstr);
586# endif 817# endif
587#elif defined GNULIB_POSIXCHECK 818#elif defined GNULIB_POSIXCHECK
@@ -626,10 +857,12 @@ _GL_CXXALIAS_SYS_CAST2 (strcasestr,
626 const char *, (const char *haystack, const char *needle)); 857 const char *, (const char *haystack, const char *needle));
627# endif 858# endif
628# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 859# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
629 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 860 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
630_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle)); 861 || defined __clang__)
862_GL_CXXALIASWARN1 (strcasestr, char *,
863 (char *haystack, const char *needle) throw ());
631_GL_CXXALIASWARN1 (strcasestr, const char *, 864_GL_CXXALIASWARN1 (strcasestr, const char *,
632 (const char *haystack, const char *needle)); 865 (const char *haystack, const char *needle) throw ());
633# else 866# else
634_GL_CXXALIASWARN (strcasestr); 867_GL_CXXALIASWARN (strcasestr);
635# endif 868# endif
@@ -660,7 +893,7 @@ _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
660 This is a variant of strtok() that is multithread-safe. 893 This is a variant of strtok() that is multithread-safe.
661 894
662 For the POSIX documentation for this function, see: 895 For the POSIX documentation for this function, see:
663 http://www.opengroup.org/susv3xsh/strtok.html 896 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
664 897
665 Caveat: It modifies the original string. 898 Caveat: It modifies the original string.
666 Caveat: These functions cannot be used on constant strings. 899 Caveat: These functions cannot be used on constant strings.
@@ -734,7 +967,9 @@ _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string)
734 _GL_ARG_NONNULL ((1))); 967 _GL_ARG_NONNULL ((1)));
735_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); 968_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
736# endif 969# endif
970# if __GLIBC__ >= 2
737_GL_CXXALIASWARN (mbslen); 971_GL_CXXALIASWARN (mbslen);
972# endif
738#endif 973#endif
739 974
740#if @GNULIB_MBSNLEN@ 975#if @GNULIB_MBSNLEN@
@@ -931,7 +1166,8 @@ _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
931 Caveat: The identity of the delimiting character is lost. 1166 Caveat: The identity of the delimiting character is lost.
932 1167
933 See also mbssep(). */ 1168 See also mbssep(). */
934_GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr) 1169_GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1170 char **save_ptr)
935 _GL_ARG_NONNULL ((2, 3)); 1171 _GL_ARG_NONNULL ((2, 3));
936#endif 1172#endif
937 1173
@@ -947,7 +1183,9 @@ _GL_CXXALIAS_RPL (strerror, char *, (int));
947# else 1183# else
948_GL_CXXALIAS_SYS (strerror, char *, (int)); 1184_GL_CXXALIAS_SYS (strerror, char *, (int));
949# endif 1185# endif
1186# if __GLIBC__ >= 2
950_GL_CXXALIASWARN (strerror); 1187_GL_CXXALIASWARN (strerror);
1188# endif
951#elif defined GNULIB_POSIXCHECK 1189#elif defined GNULIB_POSIXCHECK
952# undef strerror 1190# undef strerror
953/* Assume strerror is always declared. */ 1191/* Assume strerror is always declared. */
@@ -984,6 +1222,60 @@ _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
984# endif 1222# endif
985#endif 1223#endif
986 1224
1225/* Return the name of the system error code ERRNUM. */
1226#if @GNULIB_STRERRORNAME_NP@
1227# if @REPLACE_STRERRORNAME_NP@
1228# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1229# undef strerrorname_np
1230# define strerrorname_np rpl_strerrorname_np
1231# endif
1232_GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum));
1233_GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1234# else
1235# if !@HAVE_STRERRORNAME_NP@
1236_GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum));
1237# endif
1238_GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1239# endif
1240_GL_CXXALIASWARN (strerrorname_np);
1241#elif defined GNULIB_POSIXCHECK
1242# undef strerrorname_np
1243# if HAVE_RAW_DECL_STRERRORNAME_NP
1244_GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1245 "use gnulib module strerrorname_np for portability");
1246# endif
1247#endif
1248
1249/* Return an abbreviation string for the signal number SIG. */
1250#if @GNULIB_SIGABBREV_NP@
1251# if ! @HAVE_SIGABBREV_NP@
1252_GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig));
1253# endif
1254_GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig));
1255_GL_CXXALIASWARN (sigabbrev_np);
1256#elif defined GNULIB_POSIXCHECK
1257# undef sigabbrev_np
1258# if HAVE_RAW_DECL_SIGABBREV_NP
1259_GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1260 "use gnulib module sigabbrev_np for portability");
1261# endif
1262#endif
1263
1264/* Return an English description string for the signal number SIG. */
1265#if @GNULIB_SIGDESCR_NP@
1266# if ! @HAVE_SIGDESCR_NP@
1267_GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig));
1268# endif
1269_GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1270_GL_CXXALIASWARN (sigdescr_np);
1271#elif defined GNULIB_POSIXCHECK
1272# undef sigdescr_np
1273# if HAVE_RAW_DECL_SIGDESCR_NP
1274_GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1275 "use gnulib module sigdescr_np for portability");
1276# endif
1277#endif
1278
987#if @GNULIB_STRSIGNAL@ 1279#if @GNULIB_STRSIGNAL@
988# if @REPLACE_STRSIGNAL@ 1280# if @REPLACE_STRSIGNAL@
989# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1281# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -1027,3 +1319,4 @@ _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1027 1319
1028#endif /* _@GUARD_PREFIX@_STRING_H */ 1320#endif /* _@GUARD_PREFIX@_STRING_H */
1029#endif /* _@GUARD_PREFIX@_STRING_H */ 1321#endif /* _@GUARD_PREFIX@_STRING_H */
1322#endif
diff --git a/gl/strings.in.h b/gl/strings.in.h
index 4469f86..2cfe8b1 100644
--- a/gl/strings.in.h
+++ b/gl/strings.in.h
@@ -1,19 +1,19 @@
1/* A substitute <strings.h>. 1/* A substitute <strings.h>.
2 2
3 Copyright (C) 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _@GUARD_PREFIX@_STRINGS_H 18#ifndef _@GUARD_PREFIX@_STRINGS_H
19 19
diff --git a/gl/stripslash.c b/gl/stripslash.c
index 0e452a9..fe46a9c 100644
--- a/gl/stripslash.c
+++ b/gl/stripslash.c
@@ -1,20 +1,20 @@
1/* stripslash.c -- remove redundant trailing slashes from a file name 1/* stripslash.c -- remove redundant trailing slashes from a file name
2 2
3 Copyright (C) 1990, 2001, 2003-2006, 2009-2013 Free Software Foundation, 3 Copyright (C) 1990, 2001, 2003-2006, 2009-2023 Free Software Foundation,
4 Inc. 4 Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 2.1 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
diff --git a/gl/strncasecmp.c b/gl/strncasecmp.c
index 35840bc..c5c2cd3 100644
--- a/gl/strncasecmp.c
+++ b/gl/strncasecmp.c
@@ -1,18 +1,18 @@
1/* strncasecmp.c -- case insensitive string comparator 1/* strncasecmp.c -- case insensitive string comparator
2 Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc. 2 Copyright (C) 1998-1999, 2005-2007, 2009-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
@@ -58,5 +58,5 @@ strncasecmp (const char *s1, const char *s2, size_t n)
58 /* On machines where 'char' and 'int' are types of the same size, the 58 /* On machines where 'char' and 'int' are types of the same size, the
59 difference of two 'unsigned char' values - including the sign bit - 59 difference of two 'unsigned char' values - including the sign bit -
60 doesn't fit in an 'int'. */ 60 doesn't fit in an 'int'. */
61 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); 61 return _GL_CMP (c1, c2);
62} 62}
diff --git a/gl/strndup.c b/gl/strndup.c
deleted file mode 100644
index e60268b..0000000
--- a/gl/strndup.c
+++ /dev/null
@@ -1,36 +0,0 @@
1/* A replacement function, for systems that lack strndup.
2
3 Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2013 Free Software
4 Foundation, Inc.
5
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
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21#include <string.h>
22
23#include <stdlib.h>
24
25char *
26strndup (char const *s, size_t n)
27{
28 size_t len = strnlen (s, n);
29 char *new = malloc (len + 1);
30
31 if (new == NULL)
32 return NULL;
33
34 new[len] = '\0';
35 return memcpy (new, s, len);
36}
diff --git a/gl/strnlen.c b/gl/strnlen.c
deleted file mode 100644
index 57fdfe7..0000000
--- a/gl/strnlen.c
+++ /dev/null
@@ -1,30 +0,0 @@
1/* Find the length of STRING, but scan at most MAXLEN characters.
2 Copyright (C) 2005-2007, 2009-2013 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 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, see <http://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20#include <string.h>
21
22/* Find the length of STRING, but scan at most MAXLEN characters.
23 If no '\0' terminator is found in that many characters, return MAXLEN. */
24
25size_t
26strnlen (const char *string, size_t maxlen)
27{
28 const char *end = memchr (string, '\0', maxlen);
29 return end ? (size_t) (end - string) : maxlen;
30}
diff --git a/gl/strsep.c b/gl/strsep.c
index c51ac0d..8e9708a 100644
--- a/gl/strsep.c
+++ b/gl/strsep.c
@@ -1,19 +1,19 @@
1/* Copyright (C) 2004, 2007, 2009-2013 Free Software Foundation, Inc. 1/* Copyright (C) 2004, 2007, 2009-2023 Free Software Foundation, Inc.
2 2
3 Written by Yoann Vandoorselaere <yoann@prelude-ids.org>. 3 Written by Yoann Vandoorselaere <yoann@prelude-ids.org>.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifdef HAVE_CONFIG_H 18#ifdef HAVE_CONFIG_H
19# include <config.h> 19# include <config.h>
diff --git a/gl/strstr.c b/gl/strstr.c
index b91acec..574f4d5 100644
--- a/gl/strstr.c
+++ b/gl/strstr.c
@@ -1,19 +1,19 @@
1/* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2013 Free Software 1/* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2023 Free Software
2 Foundation, Inc. 2 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* This particular implementation was written by Eric Blake, 2008. */ 18/* This particular implementation was written by Eric Blake, 2008. */
19 19
@@ -24,12 +24,6 @@
24/* Specification of strstr. */ 24/* Specification of strstr. */
25#include <string.h> 25#include <string.h>
26 26
27#include <stdbool.h>
28
29#ifndef _LIBC
30# define __builtin_expect(expr, val) (expr)
31#endif
32
33#define RETURN_TYPE char * 27#define RETURN_TYPE char *
34#define AVAILABLE(h, h_l, j, n_l) \ 28#define AVAILABLE(h, h_l, j, n_l) \
35 (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ 29 (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
diff --git a/gl/sys-limits.h b/gl/sys-limits.h
new file mode 100644
index 0000000..0e9556d
--- /dev/null
+++ b/gl/sys-limits.h
@@ -0,0 +1,42 @@
1/* System call limits
2
3 Copyright 2018-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _GL_SYS_LIMITS_H
19#define _GL_SYS_LIMITS_H
20
21#include <limits.h>
22
23/* Maximum number of bytes to read or write in a single system call.
24 This can be useful for system calls like sendfile on GNU/Linux,
25 which do not handle more than MAX_RW_COUNT bytes correctly.
26 The Linux kernel MAX_RW_COUNT is at least INT_MAX >> 20 << 20,
27 where the 20 comes from the Hexagon port with 1 MiB pages; use that
28 as an approximation, as the exact value may not be available to us.
29
30 Using this also works around a serious Linux bug before 2.6.16; see
31 <https://bugzilla.redhat.com/show_bug.cgi?id=612839>.
32
33 Using this also works around a Tru64 5.1 bug, where attempting
34 to read INT_MAX bytes fails with errno == EINVAL. See
35 <https://lists.gnu.org/r/bug-gnu-utils/2002-04/msg00010.html>.
36
37 Using this is likely to work around similar bugs in other operating
38 systems. */
39
40enum { SYS_BUFSIZE_MAX = INT_MAX >> 20 << 20 };
41
42#endif
diff --git a/gl/sys_socket.c b/gl/sys_socket.c
index 3f017f8..b7388ce 100644
--- a/gl/sys_socket.c
+++ b/gl/sys_socket.c
@@ -1,3 +1,22 @@
1/* Inline functions for <sys/socket.h>.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
1#include <config.h> 18#include <config.h>
19
2#define _GL_SYS_SOCKET_INLINE _GL_EXTERN_INLINE 20#define _GL_SYS_SOCKET_INLINE _GL_EXTERN_INLINE
3#include "sys/socket.h" 21#include "sys/socket.h"
22typedef int dummy;
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index b4cf0c3..6705593 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -1,20 +1,20 @@
1/* Provide a sys/socket header file for systems lacking it (read: MinGW) 1/* Provide a sys/socket header file for systems lacking it (read: MinGW)
2 and for systems where it is incomplete. 2 and for systems where it is incomplete.
3 Copyright (C) 2005-2013 Free Software Foundation, Inc. 3 Copyright (C) 2005-2023 Free Software Foundation, Inc.
4 Written by Simon Josefsson. 4 Written by Simon Josefsson.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This file 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 Lesser General Public License as
8 the Free Software Foundation; either version 3, or (at your option) 8 published by the Free Software Foundation; either version 2.1 of the
9 any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file 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 Lesser 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 Lesser General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19/* This file is supposed to be used on platforms that lack <sys/socket.h>, 19/* This file is supposed to be used on platforms that lack <sys/socket.h>,
20 on platforms where <sys/socket.h> cannot be included standalone, and on 20 on platforms where <sys/socket.h> cannot be included standalone, and on
@@ -63,6 +63,9 @@
63#ifndef _@GUARD_PREFIX@_SYS_SOCKET_H 63#ifndef _@GUARD_PREFIX@_SYS_SOCKET_H
64#define _@GUARD_PREFIX@_SYS_SOCKET_H 64#define _@GUARD_PREFIX@_SYS_SOCKET_H
65 65
66#ifndef _GL_INLINE_HEADER_BEGIN
67 #error "Please include config.h first."
68#endif
66_GL_INLINE_HEADER_BEGIN 69_GL_INLINE_HEADER_BEGIN
67#ifndef _GL_SYS_SOCKET_INLINE 70#ifndef _GL_SYS_SOCKET_INLINE
68# define _GL_SYS_SOCKET_INLINE _GL_INLINE 71# define _GL_SYS_SOCKET_INLINE _GL_INLINE
@@ -76,7 +79,12 @@ _GL_INLINE_HEADER_BEGIN
76 79
77#if !@HAVE_SA_FAMILY_T@ 80#if !@HAVE_SA_FAMILY_T@
78# if !GNULIB_defined_sa_family_t 81# if !GNULIB_defined_sa_family_t
82/* On OS/2 kLIBC, sa_family_t is unsigned char unless TCPV40HDRS is defined. */
83# if !defined __KLIBC__ || defined TCPV40HDRS
79typedef unsigned short sa_family_t; 84typedef unsigned short sa_family_t;
85# else
86typedef unsigned char sa_family_t;
87# endif
80# define GNULIB_defined_sa_family_t 1 88# define GNULIB_defined_sa_family_t 1
81# endif 89# endif
82#endif 90#endif
@@ -89,7 +97,6 @@ typedef unsigned short sa_family_t;
89# endif 97# endif
90# endif 98# endif
91#else 99#else
92# include <stdalign.h>
93/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on 100/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
94 2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */ 101 2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
95# define __ss_aligntype unsigned long int 102# define __ss_aligntype unsigned long int
@@ -133,6 +140,15 @@ struct sockaddr_storage
133# define SHUT_RDWR 2 140# define SHUT_RDWR 2
134# endif 141# endif
135 142
143# ifdef __VMS /* OpenVMS */
144# ifndef CMSG_SPACE
145# define CMSG_SPACE(length) _CMSG_SPACE(length)
146# endif
147# ifndef CMSG_LEN
148# define CMSG_LEN(length) _CMSG_LEN(length)
149# endif
150# endif
151
136#else 152#else
137 153
138# ifdef __CYGWIN__ 154# ifdef __CYGWIN__
@@ -152,7 +168,7 @@ struct sockaddr_storage
152 code may not run on older Windows releases then. My Windows 2000 168 code may not run on older Windows releases then. My Windows 2000
153 box was not able to run the code, for example. The situation is 169 box was not able to run the code, for example. The situation is
154 slightly confusing because 170 slightly confusing because
155 <http://msdn.microsoft.com/en-us/library/ms738520> 171 <https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
156 suggests that getaddrinfo should be available on all Windows 172 suggests that getaddrinfo should be available on all Windows
157 releases. */ 173 releases. */
158 174
@@ -178,12 +194,7 @@ struct sockaddr_storage
178/* Include headers needed by the emulation code. */ 194/* Include headers needed by the emulation code. */
179# include <sys/types.h> 195# include <sys/types.h>
180# include <io.h> 196# include <io.h>
181 197/* If these headers don't define socklen_t, <config.h> does. */
182# if !GNULIB_defined_socklen_t
183typedef int socklen_t;
184# define GNULIB_defined_socklen_t 1
185# endif
186
187# endif 198# endif
188 199
189/* Rudimentary 'struct msghdr'; this works as long as you don't try to 200/* Rudimentary 'struct msghdr'; this works as long as you don't try to
@@ -198,6 +209,15 @@ struct msghdr {
198 209
199#endif 210#endif
200 211
212/* Ensure SO_REUSEPORT is defined. */
213/* For the subtle differences between SO_REUSEPORT and SO_REUSEADDR, see
214 https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t
215 and https://lwn.net/Articles/542629/
216 */
217#ifndef SO_REUSEPORT
218# define SO_REUSEPORT SO_REUSEADDR
219#endif
220
201/* Fix some definitions from <winsock2.h>. */ 221/* Fix some definitions from <winsock2.h>. */
202 222
203#if @HAVE_WINSOCK2_H@ 223#if @HAVE_WINSOCK2_H@
@@ -235,7 +255,7 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
235# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 255# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
236# undef close 256# undef close
237# define close close_used_without_including_unistd_h 257# define close close_used_without_including_unistd_h
238# else 258# elif !defined __clang__
239 _GL_WARN_ON_USE (close, 259 _GL_WARN_ON_USE (close,
240 "close() used without including <unistd.h>"); 260 "close() used without including <unistd.h>");
241# endif 261# endif
@@ -320,14 +340,20 @@ _GL_WARN_ON_USE (connect, "connect is not always POSIX compliant - "
320# define accept rpl_accept 340# define accept rpl_accept
321# endif 341# endif
322_GL_FUNCDECL_RPL (accept, int, 342_GL_FUNCDECL_RPL (accept, int,
323 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 343 (int fd,
344 struct sockaddr *restrict addr,
345 socklen_t *restrict addrlen));
324_GL_CXXALIAS_RPL (accept, int, 346_GL_CXXALIAS_RPL (accept, int,
325 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 347 (int fd,
348 struct sockaddr *restrict addr,
349 socklen_t *restrict addrlen));
326# else 350# else
327/* Need to cast, because on Solaris 10 systems, the third parameter is 351/* Need to cast, because on Solaris 10 systems, the third parameter is
328 void *addrlen. */ 352 void *addrlen. */
329_GL_CXXALIAS_SYS_CAST (accept, int, 353_GL_CXXALIAS_SYS_CAST (accept, int,
330 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 354 (int fd,
355 struct sockaddr *restrict addr,
356 socklen_t *restrict addrlen));
331# endif 357# endif
332_GL_CXXALIASWARN (accept); 358_GL_CXXALIASWARN (accept);
333#elif @HAVE_WINSOCK2_H@ 359#elif @HAVE_WINSOCK2_H@
@@ -378,15 +404,18 @@ _GL_WARN_ON_USE (bind, "bind is not always POSIX compliant - "
378# define getpeername rpl_getpeername 404# define getpeername rpl_getpeername
379# endif 405# endif
380_GL_FUNCDECL_RPL (getpeername, int, 406_GL_FUNCDECL_RPL (getpeername, int,
381 (int fd, struct sockaddr *addr, socklen_t *addrlen) 407 (int fd, struct sockaddr *restrict addr,
408 socklen_t *restrict addrlen)
382 _GL_ARG_NONNULL ((2, 3))); 409 _GL_ARG_NONNULL ((2, 3)));
383_GL_CXXALIAS_RPL (getpeername, int, 410_GL_CXXALIAS_RPL (getpeername, int,
384 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 411 (int fd, struct sockaddr *restrict addr,
412 socklen_t *restrict addrlen));
385# else 413# else
386/* Need to cast, because on Solaris 10 systems, the third parameter is 414/* Need to cast, because on Solaris 10 systems, the third parameter is
387 void *addrlen. */ 415 void *addrlen. */
388_GL_CXXALIAS_SYS_CAST (getpeername, int, 416_GL_CXXALIAS_SYS_CAST (getpeername, int,
389 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 417 (int fd, struct sockaddr *restrict addr,
418 socklen_t *restrict addrlen));
390# endif 419# endif
391_GL_CXXALIASWARN (getpeername); 420_GL_CXXALIASWARN (getpeername);
392#elif @HAVE_WINSOCK2_H@ 421#elif @HAVE_WINSOCK2_H@
@@ -407,15 +436,18 @@ _GL_WARN_ON_USE (getpeername, "getpeername is not always POSIX compliant - "
407# define getsockname rpl_getsockname 436# define getsockname rpl_getsockname
408# endif 437# endif
409_GL_FUNCDECL_RPL (getsockname, int, 438_GL_FUNCDECL_RPL (getsockname, int,
410 (int fd, struct sockaddr *addr, socklen_t *addrlen) 439 (int fd, struct sockaddr *restrict addr,
440 socklen_t *restrict addrlen)
411 _GL_ARG_NONNULL ((2, 3))); 441 _GL_ARG_NONNULL ((2, 3)));
412_GL_CXXALIAS_RPL (getsockname, int, 442_GL_CXXALIAS_RPL (getsockname, int,
413 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 443 (int fd, struct sockaddr *restrict addr,
444 socklen_t *restrict addrlen));
414# else 445# else
415/* Need to cast, because on Solaris 10 systems, the third parameter is 446/* Need to cast, because on Solaris 10 systems, the third parameter is
416 void *addrlen. */ 447 void *addrlen. */
417_GL_CXXALIAS_SYS_CAST (getsockname, int, 448_GL_CXXALIAS_SYS_CAST (getsockname, int,
418 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 449 (int fd, struct sockaddr *restrict addr,
450 socklen_t *restrict addrlen));
419# endif 451# endif
420_GL_CXXALIASWARN (getsockname); 452_GL_CXXALIASWARN (getsockname);
421#elif @HAVE_WINSOCK2_H@ 453#elif @HAVE_WINSOCK2_H@
@@ -435,16 +467,19 @@ _GL_WARN_ON_USE (getsockname, "getsockname is not always POSIX compliant - "
435# undef getsockopt 467# undef getsockopt
436# define getsockopt rpl_getsockopt 468# define getsockopt rpl_getsockopt
437# endif 469# endif
438_GL_FUNCDECL_RPL (getsockopt, int, (int fd, int level, int optname, 470_GL_FUNCDECL_RPL (getsockopt, int,
439 void *optval, socklen_t *optlen) 471 (int fd, int level, int optname,
440 _GL_ARG_NONNULL ((4, 5))); 472 void *restrict optval, socklen_t *restrict optlen)
441_GL_CXXALIAS_RPL (getsockopt, int, (int fd, int level, int optname, 473 _GL_ARG_NONNULL ((4, 5)));
442 void *optval, socklen_t *optlen)); 474_GL_CXXALIAS_RPL (getsockopt, int,
475 (int fd, int level, int optname,
476 void *restrict optval, socklen_t *restrict optlen));
443# else 477# else
444/* Need to cast, because on Solaris 10 systems, the fifth parameter is 478/* Need to cast, because on Solaris 10 systems, the fifth parameter is
445 void *optlen. */ 479 void *optlen. */
446_GL_CXXALIAS_SYS_CAST (getsockopt, int, (int fd, int level, int optname, 480_GL_CXXALIAS_SYS_CAST (getsockopt, int,
447 void *optval, socklen_t *optlen)); 481 (int fd, int level, int optname,
482 void *restrict optval, socklen_t *restrict optlen));
448# endif 483# endif
449_GL_CXXALIASWARN (getsockopt); 484_GL_CXXALIASWARN (getsockopt);
450#elif @HAVE_WINSOCK2_H@ 485#elif @HAVE_WINSOCK2_H@
@@ -491,7 +526,10 @@ _GL_FUNCDECL_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)
491 _GL_ARG_NONNULL ((2))); 526 _GL_ARG_NONNULL ((2)));
492_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)); 527_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
493# else 528# else
494_GL_CXXALIAS_SYS (recv, ssize_t, (int fd, void *buf, size_t len, int flags)); 529/* Need to cast, because on HP-UX 11.31 the return type may be
530 int,
531 depending on compiler options. */
532_GL_CXXALIAS_SYS_CAST (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
495# endif 533# endif
496_GL_CXXALIASWARN (recv); 534_GL_CXXALIASWARN (recv);
497#elif @HAVE_WINSOCK2_H@ 535#elif @HAVE_WINSOCK2_H@
@@ -517,8 +555,11 @@ _GL_FUNCDECL_RPL (send, ssize_t,
517_GL_CXXALIAS_RPL (send, ssize_t, 555_GL_CXXALIAS_RPL (send, ssize_t,
518 (int fd, const void *buf, size_t len, int flags)); 556 (int fd, const void *buf, size_t len, int flags));
519# else 557# else
520_GL_CXXALIAS_SYS (send, ssize_t, 558/* Need to cast, because on HP-UX 11.31 the return type may be
521 (int fd, const void *buf, size_t len, int flags)); 559 int,
560 depending on compiler options. */
561_GL_CXXALIAS_SYS_CAST (send, ssize_t,
562 (int fd, const void *buf, size_t len, int flags));
522# endif 563# endif
523_GL_CXXALIASWARN (send); 564_GL_CXXALIASWARN (send);
524#elif @HAVE_WINSOCK2_H@ 565#elif @HAVE_WINSOCK2_H@
@@ -539,18 +580,21 @@ _GL_WARN_ON_USE (send, "send is not always POSIX compliant - "
539# define recvfrom rpl_recvfrom 580# define recvfrom rpl_recvfrom
540# endif 581# endif
541_GL_FUNCDECL_RPL (recvfrom, ssize_t, 582_GL_FUNCDECL_RPL (recvfrom, ssize_t,
542 (int fd, void *buf, size_t len, int flags, 583 (int fd, void *restrict buf, size_t len, int flags,
543 struct sockaddr *from, socklen_t *fromlen) 584 struct sockaddr *restrict from,
585 socklen_t *restrict fromlen)
544 _GL_ARG_NONNULL ((2))); 586 _GL_ARG_NONNULL ((2)));
545_GL_CXXALIAS_RPL (recvfrom, ssize_t, 587_GL_CXXALIAS_RPL (recvfrom, ssize_t,
546 (int fd, void *buf, size_t len, int flags, 588 (int fd, void *restrict buf, size_t len, int flags,
547 struct sockaddr *from, socklen_t *fromlen)); 589 struct sockaddr *restrict from,
590 socklen_t *restrict fromlen));
548# else 591# else
549/* Need to cast, because on Solaris 10 systems, the sixth parameter is 592/* Need to cast, because on Solaris 10 systems, the sixth parameter is
550 void *fromlen. */ 593 void *fromlen. */
551_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t, 594_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t,
552 (int fd, void *buf, size_t len, int flags, 595 (int fd, void *restrict buf, size_t len, int flags,
553 struct sockaddr *from, socklen_t *fromlen)); 596 struct sockaddr *restrict from,
597 socklen_t *restrict fromlen));
554# endif 598# endif
555_GL_CXXALIASWARN (recvfrom); 599_GL_CXXALIASWARN (recvfrom);
556#elif @HAVE_WINSOCK2_H@ 600#elif @HAVE_WINSOCK2_H@
@@ -654,7 +698,7 @@ _GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX compliant - "
654 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) 698 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
655 and O_TEXT, O_BINARY (defined in "binary-io.h"). 699 and O_TEXT, O_BINARY (defined in "binary-io.h").
656 See also the Linux man page at 700 See also the Linux man page at
657 <http://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */ 701 <https://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */
658# if @HAVE_ACCEPT4@ 702# if @HAVE_ACCEPT4@
659# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 703# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
660# define accept4 rpl_accept4 704# define accept4 rpl_accept4
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
new file mode 100644
index 0000000..096887c
--- /dev/null
+++ b/gl/sys_stat.in.h
@@ -0,0 +1,954 @@
1/* Provide a more complete sys/stat.h header file.
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
18
19/* This file is supposed to be used on platforms where <sys/stat.h> is
20 incomplete. It is intended to provide definitions and prototypes
21 needed by an application. Start with what the system provides. */
22
23#if __GNUC__ >= 3
24@PRAGMA_SYSTEM_HEADER@
25#endif
26@PRAGMA_COLUMNS@
27
28#if defined __need_system_sys_stat_h
29/* Special invocation convention. */
30
31#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
32
33#else
34/* Normal invocation convention. */
35
36#ifndef _@GUARD_PREFIX@_SYS_STAT_H
37
38/* Get nlink_t.
39 May also define off_t to a 64-bit type on native Windows. */
40#include <sys/types.h>
41
42/* Get struct timespec. */
43#include <time.h>
44
45/* The include_next requires a split double-inclusion guard. */
46#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
47
48#ifndef _@GUARD_PREFIX@_SYS_STAT_H
49#define _@GUARD_PREFIX@_SYS_STAT_H
50
51/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
52
53/* The definition of _GL_ARG_NONNULL is copied here. */
54
55/* The definition of _GL_WARN_ON_USE is copied here. */
56
57/* Before doing "#define mknod rpl_mknod" below, we need to include all
58 headers that may declare mknod(). OS/2 kLIBC declares mknod() in
59 <unistd.h>, not in <sys/stat.h>. */
60#ifdef __KLIBC__
61# include <unistd.h>
62#endif
63
64/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
65 headers that may declare mkdir(). Native Windows platforms declare mkdir
66 in <io.h> and/or <direct.h>, not in <sys/stat.h>. */
67#if defined _WIN32 && ! defined __CYGWIN__
68# include <io.h> /* mingw32, mingw64 */
69# include <direct.h> /* mingw64, MSVC 9 */
70#endif
71
72/* Native Windows platforms declare umask() in <io.h>. */
73#if 0 && (defined _WIN32 && ! defined __CYGWIN__)
74# include <io.h>
75#endif
76
77/* Large File Support on native Windows. */
78#if @WINDOWS_64_BIT_ST_SIZE@
79# define stat _stati64
80#endif
81
82/* Optionally, override 'struct stat' on native Windows. */
83#if @GNULIB_OVERRIDES_STRUCT_STAT@
84
85# undef stat
86# if @GNULIB_STAT@
87# define stat rpl_stat
88# else
89 /* Provoke a clear link error if stat() is used as a function and
90 module 'stat' is not in use. */
91# define stat stat_used_without_requesting_gnulib_module_stat
92# endif
93
94# if !GNULIB_defined_struct_stat
95struct stat
96{
97 dev_t st_dev;
98 ino_t st_ino;
99 mode_t st_mode;
100 nlink_t st_nlink;
101# if 0
102 uid_t st_uid;
103# else /* uid_t is not defined by default on native Windows. */
104 short st_uid;
105# endif
106# if 0
107 gid_t st_gid;
108# else /* gid_t is not defined by default on native Windows. */
109 short st_gid;
110# endif
111 dev_t st_rdev;
112 off_t st_size;
113# if 0
114 blksize_t st_blksize;
115 blkcnt_t st_blocks;
116# endif
117
118# if @WINDOWS_STAT_TIMESPEC@
119 struct timespec st_atim;
120 struct timespec st_mtim;
121 struct timespec st_ctim;
122# else
123 time_t st_atime;
124 time_t st_mtime;
125 time_t st_ctime;
126# endif
127};
128# if @WINDOWS_STAT_TIMESPEC@
129# define st_atime st_atim.tv_sec
130# define st_mtime st_mtim.tv_sec
131# define st_ctime st_ctim.tv_sec
132 /* Indicator, for gnulib internal purposes. */
133# define _GL_WINDOWS_STAT_TIMESPEC 1
134# endif
135# define GNULIB_defined_struct_stat 1
136# endif
137
138/* Other possible values of st_mode. */
139# if 0
140# define _S_IFBLK 0x6000
141# endif
142# if 0
143# define _S_IFLNK 0xA000
144# endif
145# if 0
146# define _S_IFSOCK 0xC000
147# endif
148
149#endif
150
151#ifndef S_IFIFO
152# ifdef _S_IFIFO
153# define S_IFIFO _S_IFIFO
154# endif
155#endif
156
157#ifndef S_IFMT
158# define S_IFMT 0170000
159#endif
160
161#if STAT_MACROS_BROKEN
162# undef S_ISBLK
163# undef S_ISCHR
164# undef S_ISDIR
165# undef S_ISFIFO
166# undef S_ISLNK
167# undef S_ISNAM
168# undef S_ISMPB
169# undef S_ISMPC
170# undef S_ISNWK
171# undef S_ISREG
172# undef S_ISSOCK
173#endif
174
175#ifndef S_ISBLK
176# ifdef S_IFBLK
177# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
178# else
179# define S_ISBLK(m) 0
180# endif
181#endif
182
183#ifndef S_ISCHR
184# ifdef S_IFCHR
185# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
186# else
187# define S_ISCHR(m) 0
188# endif
189#endif
190
191#ifndef S_ISDIR
192# ifdef S_IFDIR
193# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
194# else
195# define S_ISDIR(m) 0
196# endif
197#endif
198
199#ifndef S_ISDOOR /* Solaris 2.5 and up */
200# define S_ISDOOR(m) 0
201#endif
202
203#ifndef S_ISFIFO
204# ifdef S_IFIFO
205# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
206# else
207# define S_ISFIFO(m) 0
208# endif
209#endif
210
211#ifndef S_ISLNK
212# ifdef S_IFLNK
213# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
214# else
215# define S_ISLNK(m) 0
216# endif
217#endif
218
219#ifndef S_ISMPB /* V7 */
220# ifdef S_IFMPB
221# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
222# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
223# else
224# define S_ISMPB(m) 0
225# define S_ISMPC(m) 0
226# endif
227#endif
228
229#ifndef S_ISMPX /* AIX */
230# define S_ISMPX(m) 0
231#endif
232
233#ifndef S_ISNAM /* Xenix */
234# ifdef S_IFNAM
235# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
236# else
237# define S_ISNAM(m) 0
238# endif
239#endif
240
241#ifndef S_ISNWK /* HP/UX */
242# ifdef S_IFNWK
243# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
244# else
245# define S_ISNWK(m) 0
246# endif
247#endif
248
249#ifndef S_ISPORT /* Solaris 10 and up */
250# define S_ISPORT(m) 0
251#endif
252
253#ifndef S_ISREG
254# ifdef S_IFREG
255# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
256# else
257# define S_ISREG(m) 0
258# endif
259#endif
260
261#ifndef S_ISSOCK
262# ifdef S_IFSOCK
263# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
264# else
265# define S_ISSOCK(m) 0
266# endif
267#endif
268
269
270#ifndef S_TYPEISMQ
271# define S_TYPEISMQ(p) 0
272#endif
273
274#ifndef S_TYPEISTMO
275# define S_TYPEISTMO(p) 0
276#endif
277
278
279#ifndef S_TYPEISSEM
280# ifdef S_INSEM
281# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
282# else
283# define S_TYPEISSEM(p) 0
284# endif
285#endif
286
287#ifndef S_TYPEISSHM
288# ifdef S_INSHD
289# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
290# else
291# define S_TYPEISSHM(p) 0
292# endif
293#endif
294
295/* high performance ("contiguous data") */
296#ifndef S_ISCTG
297# define S_ISCTG(p) 0
298#endif
299
300/* Cray DMF (data migration facility): off line, with data */
301#ifndef S_ISOFD
302# define S_ISOFD(p) 0
303#endif
304
305/* Cray DMF (data migration facility): off line, with no data */
306#ifndef S_ISOFL
307# define S_ISOFL(p) 0
308#endif
309
310/* 4.4BSD whiteout */
311#ifndef S_ISWHT
312# define S_ISWHT(m) 0
313#endif
314
315/* If any of the following are undefined,
316 define them to their de facto standard values. */
317#if !S_ISUID
318# define S_ISUID 04000
319#endif
320#if !S_ISGID
321# define S_ISGID 02000
322#endif
323
324/* S_ISVTX is a common extension to POSIX. */
325#ifndef S_ISVTX
326# define S_ISVTX 01000
327#endif
328
329#if !S_IRUSR && S_IREAD
330# define S_IRUSR S_IREAD
331#endif
332#if !S_IRUSR
333# define S_IRUSR 00400
334#endif
335#if !S_IRGRP
336# define S_IRGRP (S_IRUSR >> 3)
337#endif
338#if !S_IROTH
339# define S_IROTH (S_IRUSR >> 6)
340#endif
341
342#if !S_IWUSR && S_IWRITE
343# define S_IWUSR S_IWRITE
344#endif
345#if !S_IWUSR
346# define S_IWUSR 00200
347#endif
348#if !S_IWGRP
349# define S_IWGRP (S_IWUSR >> 3)
350#endif
351#if !S_IWOTH
352# define S_IWOTH (S_IWUSR >> 6)
353#endif
354
355#if !S_IXUSR && S_IEXEC
356# define S_IXUSR S_IEXEC
357#endif
358#if !S_IXUSR
359# define S_IXUSR 00100
360#endif
361#if !S_IXGRP
362# define S_IXGRP (S_IXUSR >> 3)
363#endif
364#if !S_IXOTH
365# define S_IXOTH (S_IXUSR >> 6)
366#endif
367
368#if !S_IRWXU
369# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
370#endif
371#if !S_IRWXG
372# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
373#endif
374#if !S_IRWXO
375# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
376#endif
377
378/* Although S_IXUGO and S_IRWXUGO are not specified by POSIX and are
379 not implemented in GNU/Linux, some Gnulib-using apps use the macros. */
380#if !S_IXUGO
381# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
382#endif
383#ifndef S_IRWXUGO
384# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
385#endif
386
387/* Macros for futimens and utimensat. */
388#ifndef UTIME_NOW
389# define UTIME_NOW (-1)
390# define UTIME_OMIT (-2)
391#endif
392
393
394#if @GNULIB_CHMOD@
395# if @REPLACE_CHMOD@
396# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
397# undef chmod
398# define chmod rpl_chmod
399# endif
400_GL_FUNCDECL_RPL (chmod, int, (const char *filename, mode_t mode)
401 _GL_ARG_NONNULL ((1)));
402_GL_CXXALIAS_RPL (chmod, int, (const char *filename, mode_t mode));
403# elif defined _WIN32 && !defined __CYGWIN__
404# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
405# undef chmod
406# define chmod _chmod
407# endif
408/* Need to cast, because in mingw the last argument is 'int mode'. */
409_GL_CXXALIAS_MDA_CAST (chmod, int, (const char *filename, mode_t mode));
410# else
411_GL_CXXALIAS_SYS (chmod, int, (const char *filename, mode_t mode));
412# endif
413_GL_CXXALIASWARN (chmod);
414#elif defined GNULIB_POSIXCHECK
415# undef chmod
416# if HAVE_RAW_DECL_CHMOD
417_GL_WARN_ON_USE (chmod, "chmod has portability problems - "
418 "use gnulib module chmod for portability");
419# endif
420#elif @GNULIB_MDA_CHMOD@
421/* On native Windows, map 'chmod' to '_chmod', so that -loldnames is not
422 required. In C++ with GNULIB_NAMESPACE, avoid differences between
423 platforms by defining GNULIB_NAMESPACE::chmod always. */
424# if defined _WIN32 && !defined __CYGWIN__
425# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
426# undef chmod
427# define chmod _chmod
428# endif
429/* Need to cast, because in mingw the last argument is 'int mode'. */
430_GL_CXXALIAS_MDA_CAST (chmod, int, (const char *filename, mode_t mode));
431# else
432_GL_CXXALIAS_SYS (chmod, int, (const char *filename, mode_t mode));
433# endif
434_GL_CXXALIASWARN (chmod);
435#endif
436
437
438#if @GNULIB_FCHMODAT@
439# if @REPLACE_FCHMODAT@
440# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
441# undef fchmodat
442# define fchmodat rpl_fchmodat
443# endif
444_GL_FUNCDECL_RPL (fchmodat, int,
445 (int fd, char const *file, mode_t mode, int flag)
446 _GL_ARG_NONNULL ((2)));
447_GL_CXXALIAS_RPL (fchmodat, int,
448 (int fd, char const *file, mode_t mode, int flag));
449# else
450# if !@HAVE_FCHMODAT@
451_GL_FUNCDECL_SYS (fchmodat, int,
452 (int fd, char const *file, mode_t mode, int flag)
453 _GL_ARG_NONNULL ((2)));
454# endif
455_GL_CXXALIAS_SYS (fchmodat, int,
456 (int fd, char const *file, mode_t mode, int flag));
457# endif
458_GL_CXXALIASWARN (fchmodat);
459#elif defined GNULIB_POSIXCHECK
460# undef fchmodat
461# if HAVE_RAW_DECL_FCHMODAT
462_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
463 "use gnulib module openat for portability");
464# endif
465#endif
466
467
468#if @GNULIB_FSTAT@
469# if @REPLACE_FSTAT@
470# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
471# undef fstat
472# define fstat rpl_fstat
473# endif
474_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
475_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
476# else
477_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
478# endif
479# if __GLIBC__ >= 2
480_GL_CXXALIASWARN (fstat);
481# endif
482#elif @GNULIB_OVERRIDES_STRUCT_STAT@
483# undef fstat
484# define fstat fstat_used_without_requesting_gnulib_module_fstat
485#elif @WINDOWS_64_BIT_ST_SIZE@
486/* Above, we define stat to _stati64. */
487# define fstat _fstati64
488#elif defined GNULIB_POSIXCHECK
489# undef fstat
490# if HAVE_RAW_DECL_FSTAT
491_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
492 "use gnulib module fstat for portability");
493# endif
494#endif
495
496
497#if @GNULIB_FSTATAT@
498# if @REPLACE_FSTATAT@
499# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
500# undef fstatat
501# define fstatat rpl_fstatat
502# endif
503_GL_FUNCDECL_RPL (fstatat, int,
504 (int fd, char const *restrict name, struct stat *restrict st,
505 int flags)
506 _GL_ARG_NONNULL ((2, 3)));
507_GL_CXXALIAS_RPL (fstatat, int,
508 (int fd, char const *restrict name, struct stat *restrict st,
509 int flags));
510# else
511# if !@HAVE_FSTATAT@
512_GL_FUNCDECL_SYS (fstatat, int,
513 (int fd, char const *restrict name, struct stat *restrict st,
514 int flags)
515 _GL_ARG_NONNULL ((2, 3)));
516# endif
517_GL_CXXALIAS_SYS (fstatat, int,
518 (int fd, char const *restrict name, struct stat *restrict st,
519 int flags));
520# endif
521_GL_CXXALIASWARN (fstatat);
522#elif @GNULIB_OVERRIDES_STRUCT_STAT@
523# undef fstatat
524# define fstatat fstatat_used_without_requesting_gnulib_module_fstatat
525#elif defined GNULIB_POSIXCHECK
526# undef fstatat
527# if HAVE_RAW_DECL_FSTATAT
528_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
529 "use gnulib module openat for portability");
530# endif
531#endif
532
533
534#if @GNULIB_FUTIMENS@
535/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
536 implementation relies on futimesat, which on Solaris 10 makes an invocation
537 to futimens that is meant to invoke the libc's futimens(), not gnulib's
538 futimens(). */
539# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
540# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
541# undef futimens
542# define futimens rpl_futimens
543# endif
544_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
545_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
546# else
547# if !@HAVE_FUTIMENS@
548_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
549# endif
550_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
551# endif
552# if @HAVE_FUTIMENS@
553_GL_CXXALIASWARN (futimens);
554# endif
555#elif defined GNULIB_POSIXCHECK
556# undef futimens
557# if HAVE_RAW_DECL_FUTIMENS
558_GL_WARN_ON_USE (futimens, "futimens is not portable - "
559 "use gnulib module futimens for portability");
560# endif
561#endif
562
563
564#if @GNULIB_GETUMASK@
565# if !@HAVE_GETUMASK@
566_GL_FUNCDECL_SYS (getumask, mode_t, (void));
567# endif
568_GL_CXXALIAS_SYS (getumask, mode_t, (void));
569# if @HAVE_GETUMASK@
570_GL_CXXALIASWARN (getumask);
571# endif
572#elif defined GNULIB_POSIXCHECK
573# undef getumask
574# if HAVE_RAW_DECL_GETUMASK
575_GL_WARN_ON_USE (getumask, "getumask is not portable - "
576 "use gnulib module getumask for portability");
577# endif
578#endif
579
580
581#if @GNULIB_LCHMOD@
582/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
583 denotes a symbolic link. */
584# if !@HAVE_LCHMOD@ || defined __hpux
585_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
586 _GL_ARG_NONNULL ((1)));
587# endif
588_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
589_GL_CXXALIASWARN (lchmod);
590#elif defined GNULIB_POSIXCHECK
591# undef lchmod
592# if HAVE_RAW_DECL_LCHMOD
593_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
594 "use gnulib module lchmod for portability");
595# endif
596#endif
597
598
599#if @GNULIB_MKDIR@
600# if @REPLACE_MKDIR@
601# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
602# undef mkdir
603# define mkdir rpl_mkdir
604# endif
605_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
606 _GL_ARG_NONNULL ((1)));
607_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
608# elif defined _WIN32 && !defined __CYGWIN__
609/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
610 Additionally, it declares _mkdir (and depending on compile flags, an
611 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
612 which are included above. */
613# if !GNULIB_defined_rpl_mkdir
614static int
615rpl_mkdir (char const *name, mode_t mode)
616{
617 return _mkdir (name);
618}
619# define GNULIB_defined_rpl_mkdir 1
620# endif
621# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
622# undef mkdir
623# define mkdir rpl_mkdir
624# endif
625_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
626# else
627_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
628# endif
629_GL_CXXALIASWARN (mkdir);
630#elif defined GNULIB_POSIXCHECK
631# undef mkdir
632# if HAVE_RAW_DECL_MKDIR
633_GL_WARN_ON_USE (mkdir, "mkdir does not always support two parameters - "
634 "use gnulib module mkdir for portability");
635# endif
636#elif @GNULIB_MDA_MKDIR@
637/* On native Windows, map 'mkdir' to '_mkdir', so that -loldnames is not
638 required. In C++ with GNULIB_NAMESPACE, avoid differences between
639 platforms by defining GNULIB_NAMESPACE::mkdir always. */
640# if defined _WIN32 && !defined __CYGWIN__
641# if !GNULIB_defined_rpl_mkdir
642static int
643rpl_mkdir (char const *name, mode_t mode)
644{
645 return _mkdir (name);
646}
647# define GNULIB_defined_rpl_mkdir 1
648# endif
649# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
650# undef mkdir
651# define mkdir rpl_mkdir
652# endif
653_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
654# else
655_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
656# endif
657_GL_CXXALIASWARN (mkdir);
658#endif
659
660
661#if @GNULIB_MKDIRAT@
662# if !@HAVE_MKDIRAT@
663_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
664 _GL_ARG_NONNULL ((2)));
665# endif
666_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
667_GL_CXXALIASWARN (mkdirat);
668#elif defined GNULIB_POSIXCHECK
669# undef mkdirat
670# if HAVE_RAW_DECL_MKDIRAT
671_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
672 "use gnulib module openat for portability");
673# endif
674#endif
675
676
677#if @GNULIB_MKFIFO@
678# if @REPLACE_MKFIFO@
679# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
680# undef mkfifo
681# define mkfifo rpl_mkfifo
682# endif
683_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
684 _GL_ARG_NONNULL ((1)));
685_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
686# else
687# if !@HAVE_MKFIFO@
688_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
689 _GL_ARG_NONNULL ((1)));
690# endif
691_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
692# endif
693_GL_CXXALIASWARN (mkfifo);
694#elif defined GNULIB_POSIXCHECK
695# undef mkfifo
696# if HAVE_RAW_DECL_MKFIFO
697_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
698 "use gnulib module mkfifo for portability");
699# endif
700#endif
701
702
703#if @GNULIB_MKFIFOAT@
704# if @REPLACE_MKFIFOAT@
705# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
706# undef mkfifoat
707# define mkfifoat rpl_mkfifoat
708# endif
709_GL_FUNCDECL_RPL (mkfifoat, int, (int fd, char const *file, mode_t mode)
710 _GL_ARG_NONNULL ((2)));
711_GL_CXXALIAS_RPL (mkfifoat, int, (int fd, char const *file, mode_t mode));
712# else
713# if !@HAVE_MKFIFOAT@
714_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
715 _GL_ARG_NONNULL ((2)));
716# endif
717_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
718# endif
719_GL_CXXALIASWARN (mkfifoat);
720#elif defined GNULIB_POSIXCHECK
721# undef mkfifoat
722# if HAVE_RAW_DECL_MKFIFOAT
723_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
724 "use gnulib module mkfifoat for portability");
725# endif
726#endif
727
728
729#if @GNULIB_MKNOD@
730# if @REPLACE_MKNOD@
731# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
732# undef mknod
733# define mknod rpl_mknod
734# endif
735_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
736 _GL_ARG_NONNULL ((1)));
737_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
738# else
739# if !@HAVE_MKNOD@
740_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
741 _GL_ARG_NONNULL ((1)));
742# endif
743/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
744_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
745# endif
746_GL_CXXALIASWARN (mknod);
747#elif defined GNULIB_POSIXCHECK
748# undef mknod
749# if HAVE_RAW_DECL_MKNOD
750_GL_WARN_ON_USE (mknod, "mknod is not portable - "
751 "use gnulib module mknod for portability");
752# endif
753#endif
754
755
756#if @GNULIB_MKNODAT@
757# if @REPLACE_MKNODAT@
758# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
759# undef mknodat
760# define mknodat rpl_mknodat
761# endif
762_GL_FUNCDECL_RPL (mknodat, int,
763 (int fd, char const *file, mode_t mode, dev_t dev)
764 _GL_ARG_NONNULL ((2)));
765_GL_CXXALIAS_RPL (mknodat, int,
766 (int fd, char const *file, mode_t mode, dev_t dev));
767# else
768# if !@HAVE_MKNODAT@
769_GL_FUNCDECL_SYS (mknodat, int,
770 (int fd, char const *file, mode_t mode, dev_t dev)
771 _GL_ARG_NONNULL ((2)));
772# endif
773_GL_CXXALIAS_SYS (mknodat, int,
774 (int fd, char const *file, mode_t mode, dev_t dev));
775# endif
776_GL_CXXALIASWARN (mknodat);
777#elif defined GNULIB_POSIXCHECK
778# undef mknodat
779# if HAVE_RAW_DECL_MKNODAT
780_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
781 "use gnulib module mkfifoat for portability");
782# endif
783#endif
784
785
786#if @GNULIB_STAT@
787# if @REPLACE_STAT@
788# if !@GNULIB_OVERRIDES_STRUCT_STAT@
789 /* We can't use the object-like #define stat rpl_stat, because of
790 struct stat. This means that rpl_stat will not be used if the user
791 does (stat)(a,b). Oh well. */
792# if defined _AIX && defined stat && defined _LARGE_FILES
793 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
794 so we have to replace stat64() instead of stat(). */
795# undef stat64
796# define stat64(name, st) rpl_stat (name, st)
797# elif @WINDOWS_64_BIT_ST_SIZE@
798 /* Above, we define stat to _stati64. */
799# if defined __MINGW32__ && defined _stati64
800# ifndef _USE_32BIT_TIME_T
801 /* The system headers define _stati64 to _stat64. */
802# undef _stat64
803# define _stat64(name, st) rpl_stat (name, st)
804# endif
805# elif defined _MSC_VER && defined _stati64
806# ifdef _USE_32BIT_TIME_T
807 /* The system headers define _stati64 to _stat32i64. */
808# undef _stat32i64
809# define _stat32i64(name, st) rpl_stat (name, st)
810# else
811 /* The system headers define _stati64 to _stat64. */
812# undef _stat64
813# define _stat64(name, st) rpl_stat (name, st)
814# endif
815# else
816# undef _stati64
817# define _stati64(name, st) rpl_stat (name, st)
818# endif
819# elif defined __MINGW32__ && defined stat
820# ifdef _USE_32BIT_TIME_T
821 /* The system headers define stat to _stat32i64. */
822# undef _stat32i64
823# define _stat32i64(name, st) rpl_stat (name, st)
824# else
825 /* The system headers define stat to _stat64. */
826# undef _stat64
827# define _stat64(name, st) rpl_stat (name, st)
828# endif
829# elif defined _MSC_VER && defined stat
830# ifdef _USE_32BIT_TIME_T
831 /* The system headers define stat to _stat32. */
832# undef _stat32
833# define _stat32(name, st) rpl_stat (name, st)
834# else
835 /* The system headers define stat to _stat64i32. */
836# undef _stat64i32
837# define _stat64i32(name, st) rpl_stat (name, st)
838# endif
839# else /* !(_AIX || __MINGW32__ || _MSC_VER) */
840# undef stat
841# define stat(name, st) rpl_stat (name, st)
842# endif /* !_LARGE_FILES */
843# endif /* !@GNULIB_OVERRIDES_STRUCT_STAT@ */
844_GL_EXTERN_C int stat (const char *restrict name, struct stat *restrict buf)
845 _GL_ARG_NONNULL ((1, 2));
846# endif
847#elif @GNULIB_OVERRIDES_STRUCT_STAT@
848/* see above:
849 #define stat stat_used_without_requesting_gnulib_module_stat
850 */
851#elif defined GNULIB_POSIXCHECK
852# undef stat
853# if HAVE_RAW_DECL_STAT
854_GL_WARN_ON_USE (stat, "stat is unportable - "
855 "use gnulib module stat for portability");
856# endif
857#endif
858
859
860#if @GNULIB_LSTAT@
861# if ! @HAVE_LSTAT@
862/* mingw does not support symlinks, therefore it does not have lstat. But
863 without links, stat does just fine. */
864# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
865# define lstat stat
866# endif
867_GL_CXXALIAS_RPL_1 (lstat, stat, int,
868 (const char *restrict name, struct stat *restrict buf));
869# elif @REPLACE_LSTAT@
870# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
871# undef lstat
872# define lstat rpl_lstat
873# endif
874_GL_FUNCDECL_RPL (lstat, int,
875 (const char *restrict name, struct stat *restrict buf)
876 _GL_ARG_NONNULL ((1, 2)));
877_GL_CXXALIAS_RPL (lstat, int,
878 (const char *restrict name, struct stat *restrict buf));
879# else
880_GL_CXXALIAS_SYS (lstat, int,
881 (const char *restrict name, struct stat *restrict buf));
882# endif
883# if @HAVE_LSTAT@
884_GL_CXXALIASWARN (lstat);
885# endif
886#elif @GNULIB_OVERRIDES_STRUCT_STAT@
887# undef lstat
888# define lstat lstat_used_without_requesting_gnulib_module_lstat
889#elif defined GNULIB_POSIXCHECK
890# undef lstat
891# if HAVE_RAW_DECL_LSTAT
892_GL_WARN_ON_USE (lstat, "lstat is unportable - "
893 "use gnulib module lstat for portability");
894# endif
895#endif
896
897
898#if @GNULIB_MDA_UMASK@
899/* On native Windows, map 'umask' to '_umask', so that -loldnames is not
900 required. In C++ with GNULIB_NAMESPACE, avoid differences between
901 platforms by defining GNULIB_NAMESPACE::umask always. */
902# if defined _WIN32 && !defined __CYGWIN__
903# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
904# undef umask
905# define umask _umask
906# endif
907/* Need to cast, because in mingw the last argument is 'int mode'. */
908_GL_CXXALIAS_MDA_CAST (umask, mode_t, (mode_t mask));
909# else
910_GL_CXXALIAS_SYS (umask, mode_t, (mode_t mask));
911# endif
912_GL_CXXALIASWARN (umask);
913#endif
914
915
916#if @GNULIB_UTIMENSAT@
917/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
918 implementation relies on futimesat, which on Solaris 10 makes an invocation
919 to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
920 utimensat(). */
921# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
922# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
923# undef utimensat
924# define utimensat rpl_utimensat
925# endif
926_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
927 struct timespec const times[2], int flag)
928 _GL_ARG_NONNULL ((2)));
929_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
930 struct timespec const times[2], int flag));
931# else
932# if !@HAVE_UTIMENSAT@
933_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
934 struct timespec const times[2], int flag)
935 _GL_ARG_NONNULL ((2)));
936# endif
937_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
938 struct timespec const times[2], int flag));
939# endif
940# if @HAVE_UTIMENSAT@
941_GL_CXXALIASWARN (utimensat);
942# endif
943#elif defined GNULIB_POSIXCHECK
944# undef utimensat
945# if HAVE_RAW_DECL_UTIMENSAT
946_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
947 "use gnulib module utimensat for portability");
948# endif
949#endif
950
951
952#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
953#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
954#endif
diff --git a/gl/sys_types.in.h b/gl/sys_types.in.h
index d7da356..082a6c6 100644
--- a/gl/sys_types.in.h
+++ b/gl/sys_types.in.h
@@ -1,29 +1,42 @@
1/* Provide a more complete sys/types.h. 1/* Provide a more complete sys/types.h.
2 2
3 Copyright (C) 2011-2013 Free Software Foundation, Inc. 3 Copyright (C) 2011-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#if __GNUC__ >= 3 18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@ 19@PRAGMA_SYSTEM_HEADER@
20#endif 20#endif
21@PRAGMA_COLUMNS@ 21@PRAGMA_COLUMNS@
22 22
23#if defined _WIN32 && !defined __CYGWIN__ \
24 && (defined __need_off_t || defined __need___off64_t \
25 || defined __need_ssize_t || defined __need_time_t)
26
27/* Special invocation convention inside mingw header files. */
28
29#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@
30
31#else
32/* Normal invocation convention. */
33
23#ifndef _@GUARD_PREFIX@_SYS_TYPES_H 34#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
24 35
25/* The include_next requires a split double-inclusion guard. */ 36/* The include_next requires a split double-inclusion guard. */
37# define _GL_INCLUDING_SYS_TYPES_H
26#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@ 38#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@
39# undef _GL_INCLUDING_SYS_TYPES_H
27 40
28#ifndef _@GUARD_PREFIX@_SYS_TYPES_H 41#ifndef _@GUARD_PREFIX@_SYS_TYPES_H
29#define _@GUARD_PREFIX@_SYS_TYPES_H 42#define _@GUARD_PREFIX@_SYS_TYPES_H
@@ -40,12 +53,54 @@
40# define _GL_WINDOWS_64_BIT_OFF_T 1 53# define _GL_WINDOWS_64_BIT_OFF_T 1
41#endif 54#endif
42 55
56/* Override dev_t and ino_t if distinguishable inodes support is requested
57 on native Windows. */
58#if @WINDOWS_STAT_INODES@
59
60# if @WINDOWS_STAT_INODES@ == 2
61/* Experimental, not useful in Windows 10. */
62
63/* Define dev_t to a 64-bit type. */
64# if !defined GNULIB_defined_dev_t
65typedef unsigned long long int rpl_dev_t;
66# undef dev_t
67# define dev_t rpl_dev_t
68# define GNULIB_defined_dev_t 1
69# endif
70
71/* Define ino_t to a 128-bit type. */
72# if !defined GNULIB_defined_ino_t
73/* MSVC does not have a 128-bit integer type.
74 GCC has a 128-bit integer type __int128, but only on 64-bit targets. */
75typedef struct { unsigned long long int _gl_ino[2]; } rpl_ino_t;
76# undef ino_t
77# define ino_t rpl_ino_t
78# define GNULIB_defined_ino_t 1
79# endif
80
81# else /* @WINDOWS_STAT_INODES@ == 1 */
82
83/* Define ino_t to a 64-bit type. */
84# if !defined GNULIB_defined_ino_t
85typedef unsigned long long int rpl_ino_t;
86# undef ino_t
87# define ino_t rpl_ino_t
88# define GNULIB_defined_ino_t 1
89# endif
90
91# endif
92
93/* Indicator, for gnulib internal purposes. */
94# define _GL_WINDOWS_STAT_INODES @WINDOWS_STAT_INODES@
95
96#endif
97
43/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>. */ 98/* MSVC 9 defines size_t in <stddef.h>, not in <sys/types.h>. */
44/* But avoid namespace pollution on glibc systems. */ 99/* But avoid namespace pollution on glibc systems. */
45#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \ 100#if (defined _WIN32 && ! defined __CYGWIN__) && ! defined __GLIBC__
46 && ! defined __GLIBC__
47# include <stddef.h> 101# include <stddef.h>
48#endif 102#endif
49 103
50#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */ 104#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
51#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */ 105#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */
106#endif /* __need_XXX */
diff --git a/gl/sys_uio.in.h b/gl/sys_uio.in.h
index fef19dc..64c4fb6 100644
--- a/gl/sys_uio.in.h
+++ b/gl/sys_uio.in.h
@@ -1,18 +1,18 @@
1/* Substitute for <sys/uio.h>. 1/* Substitute for <sys/uio.h>.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17# if __GNUC__ >= 3 17# if __GNUC__ >= 3
18@PRAGMA_SYSTEM_HEADER@ 18@PRAGMA_SYSTEM_HEADER@
diff --git a/gl/time.in.h b/gl/time.in.h
index 8ced794..50c9b30 100644
--- a/gl/time.in.h
+++ b/gl/time.in.h
@@ -1,19 +1,19 @@
1/* A more-standard <time.h>. 1/* A more-standard <time.h>.
2 2
3 Copyright (C) 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#if __GNUC__ >= 3 18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@ 19@PRAGMA_SYSTEM_HEADER@
@@ -22,11 +22,13 @@
22 22
23/* Don't get in the way of glibc when it includes time.h merely to 23/* Don't get in the way of glibc when it includes time.h merely to
24 declare a few standard symbols, rather than to declare all the 24 declare a few standard symbols, rather than to declare all the
25 symbols. Also, Solaris 8 <time.h> eventually includes itself 25 symbols. (However, skip this for MinGW as it treats __need_time_t
26 incompatibly.) Also, Solaris 8 <time.h> eventually includes itself
26 recursively; if that is happening, just include the system <time.h> 27 recursively; if that is happening, just include the system <time.h>
27 without adding our own declarations. */ 28 without adding our own declarations. */
28#if (defined __need_time_t || defined __need_clock_t \ 29#if (((defined __need_time_t || defined __need_clock_t \
29 || defined __need_timespec \ 30 || defined __need_timespec) \
31 && !defined __MINGW32__) \
30 || defined _@GUARD_PREFIX@_TIME_H) 32 || defined _@GUARD_PREFIX@_TIME_H)
31 33
32# @INCLUDE_NEXT@ @NEXT_TIME_H@ 34# @INCLUDE_NEXT@ @NEXT_TIME_H@
@@ -35,6 +37,12 @@
35 37
36# define _@GUARD_PREFIX@_TIME_H 38# define _@GUARD_PREFIX@_TIME_H
37 39
40/* mingw's <time.h> provides the functions asctime_r, ctime_r, gmtime_r,
41 localtime_r only if <unistd.h> or <pthread.h> has been included before. */
42# if defined __MINGW32__
43# include <unistd.h>
44# endif
45
38# @INCLUDE_NEXT@ @NEXT_TIME_H@ 46# @INCLUDE_NEXT@ @NEXT_TIME_H@
39 47
40/* NetBSD 5.0 mis-defines NULL. */ 48/* NetBSD 5.0 mis-defines NULL. */
@@ -46,22 +54,17 @@
46 54
47/* The definition of _GL_WARN_ON_USE is copied here. */ 55/* The definition of _GL_WARN_ON_USE is copied here. */
48 56
49/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). 57/* Some systems don't define struct timespec (e.g., AIX 4.1).
50 Or they define it with the wrong member names or define it in <sys/time.h> 58 Or they define it with the wrong member names or define it in <sys/time.h>
51 (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the 59 (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it,
52 pthreads-win32 library defines it in <pthread.h>. */ 60 but the pthreads-win32 library defines it in <pthread.h>. */
53# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ 61# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
54# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ 62# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
55# include <sys/time.h> 63# include <sys/time.h>
56# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ 64# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
57# include <pthread.h> 65# include <pthread.h>
58/* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */ 66# elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
59# undef asctime_r 67# include <unistd.h>
60# undef ctime_r
61# undef gmtime_r
62# undef localtime_r
63# undef rand_r
64# undef strtok_r
65# else 68# else
66 69
67# ifdef __cplusplus 70# ifdef __cplusplus
@@ -87,8 +90,8 @@ struct timespec
87# endif 90# endif
88 91
89# if !GNULIB_defined_struct_time_t_must_be_integral 92# if !GNULIB_defined_struct_time_t_must_be_integral
90/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires 93/* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
91 time_t to be an integer type, even though C99 permits floating 94 requires time_t to be an integer type, even though C99 permits floating
92 point. We don't know of any implementation that uses floating 95 point. We don't know of any implementation that uses floating
93 point, and it is much easier to write code that doesn't have to 96 point, and it is much easier to write code that doesn't have to
94 worry about that corner case, so we force the issue. */ 97 worry about that corner case, so we force the issue. */
@@ -98,9 +101,39 @@ struct __time_t_must_be_integral {
98# define GNULIB_defined_struct_time_t_must_be_integral 1 101# define GNULIB_defined_struct_time_t_must_be_integral 1
99# endif 102# endif
100 103
104/* Define TIME_UTC, a positive integer constant used for timespec_get(). */
105# if ! @TIME_H_DEFINES_TIME_UTC@
106# if !GNULIB_defined_TIME_UTC
107# define TIME_UTC 1
108# define GNULIB_defined_TIME_UTC 1
109# endif
110# endif
111
112/* Set *TS to the current time, and return BASE.
113 Upon failure, return 0. */
114# if @GNULIB_TIMESPEC_GET@
115# if ! @HAVE_TIMESPEC_GET@
116_GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base)
117 _GL_ARG_NONNULL ((1)));
118# endif
119_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
120_GL_CXXALIASWARN (timespec_get);
121# endif
122
123/* Set *TS to the current time resolution, and return BASE.
124 Upon failure, return 0. */
125# if @GNULIB_TIMESPEC_GETRES@
126# if ! @HAVE_TIMESPEC_GETRES@
127_GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base)
128 _GL_ARG_NONNULL ((1)));
129# endif
130_GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base));
131_GL_CXXALIASWARN (timespec_getres);
132# endif
133
101/* Sleep for at least RQTP seconds unless interrupted, If interrupted, 134/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
102 return -1 and store the remaining time into RMTP. See 135 return -1 and store the remaining time into RMTP. See
103 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ 136 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html>. */
104# if @GNULIB_NANOSLEEP@ 137# if @GNULIB_NANOSLEEP@
105# if @REPLACE_NANOSLEEP@ 138# if @REPLACE_NANOSLEEP@
106# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 139# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -123,6 +156,41 @@ _GL_CXXALIAS_SYS (nanosleep, int,
123_GL_CXXALIASWARN (nanosleep); 156_GL_CXXALIASWARN (nanosleep);
124# endif 157# endif
125 158
159/* Initialize time conversion information. */
160# if @GNULIB_TZSET@
161# if @REPLACE_TZSET@
162# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
163# undef tzset
164# define tzset rpl_tzset
165# endif
166_GL_FUNCDECL_RPL (tzset, void, (void));
167_GL_CXXALIAS_RPL (tzset, void, (void));
168# elif defined _WIN32 && !defined __CYGWIN__
169# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
170# undef tzset
171# define tzset _tzset
172# endif
173_GL_CXXALIAS_MDA (tzset, void, (void));
174# else
175_GL_CXXALIAS_SYS (tzset, void, (void));
176# endif
177_GL_CXXALIASWARN (tzset);
178# elif @GNULIB_MDA_TZSET@
179/* On native Windows, map 'tzset' to '_tzset', so that -loldnames is not
180 required. In C++ with GNULIB_NAMESPACE, avoid differences between
181 platforms by defining GNULIB_NAMESPACE::tzset always. */
182# if defined _WIN32 && !defined __CYGWIN__
183# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
184# undef tzset
185# define tzset _tzset
186# endif
187_GL_CXXALIAS_MDA (tzset, void, (void));
188# else
189_GL_CXXALIAS_SYS (tzset, void, (void));
190# endif
191_GL_CXXALIASWARN (tzset);
192# endif
193
126/* Return the 'time_t' representation of TP and normalize TP. */ 194/* Return the 'time_t' representation of TP and normalize TP. */
127# if @GNULIB_MKTIME@ 195# if @GNULIB_MKTIME@
128# if @REPLACE_MKTIME@ 196# if @REPLACE_MKTIME@
@@ -134,12 +202,14 @@ _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
134# else 202# else
135_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); 203_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
136# endif 204# endif
205# if __GLIBC__ >= 2
137_GL_CXXALIASWARN (mktime); 206_GL_CXXALIASWARN (mktime);
207# endif
138# endif 208# endif
139 209
140/* Convert TIMER to RESULT, assuming local time and UTC respectively. See 210/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
141 <http://www.opengroup.org/susv3xsh/localtime_r.html> and 211 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime_r.html> and
142 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ 212 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime_r.html>. */
143# if @GNULIB_TIME_R@ 213# if @GNULIB_TIME_R@
144# if @REPLACE_LOCALTIME_R@ 214# if @REPLACE_LOCALTIME_R@
145# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 215# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -187,9 +257,44 @@ _GL_CXXALIASWARN (gmtime_r);
187# endif 257# endif
188# endif 258# endif
189 259
190/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store 260/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
261 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html> and
262 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html>. */
263# if @GNULIB_LOCALTIME@ || @REPLACE_LOCALTIME@
264# if @REPLACE_LOCALTIME@
265# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
266# undef localtime
267# define localtime rpl_localtime
268# endif
269_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
270 _GL_ARG_NONNULL ((1)));
271_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
272# else
273_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
274# endif
275# if __GLIBC__ >= 2
276_GL_CXXALIASWARN (localtime);
277# endif
278# endif
279
280# if 0 || @REPLACE_GMTIME@
281# if @REPLACE_GMTIME@
282# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
283# undef gmtime
284# define gmtime rpl_gmtime
285# endif
286_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
287 _GL_ARG_NONNULL ((1)));
288_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
289# else
290_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
291# endif
292_GL_CXXALIASWARN (gmtime);
293# endif
294
295/* Parse BUF as a timestamp, assuming FORMAT specifies its layout, and store
191 the resulting broken-down time into TM. See 296 the resulting broken-down time into TM. See
192 <http://www.opengroup.org/susv3xsh/strptime.html>. */ 297 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html>. */
193# if @GNULIB_STRPTIME@ 298# if @GNULIB_STRPTIME@
194# if ! @HAVE_STRPTIME@ 299# if ! @HAVE_STRPTIME@
195_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, 300_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
@@ -203,6 +308,106 @@ _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
203_GL_CXXALIASWARN (strptime); 308_GL_CXXALIASWARN (strptime);
204# endif 309# endif
205 310
311/* Convert *TP to a date and time string. See
312 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>. */
313# if @GNULIB_CTIME@
314# if @REPLACE_CTIME@
315# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316# define ctime rpl_ctime
317# endif
318_GL_ATTRIBUTE_DEPRECATED
319_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
320 _GL_ARG_NONNULL ((1)));
321_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
322# else
323_GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
324# endif
325# if __GLIBC__ >= 2
326_GL_CXXALIASWARN (ctime);
327# endif
328# endif
329
330/* Convert *TP to a date and time string. See
331 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
332# if @GNULIB_STRFTIME@
333# if @REPLACE_STRFTIME@
334# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
335# define strftime rpl_strftime
336# endif
337_GL_FUNCDECL_RPL (strftime, size_t,
338 (char *restrict __buf, size_t __bufsize,
339 const char *restrict __fmt, const struct tm *restrict __tp)
340 _GL_ARG_NONNULL ((1, 3, 4)));
341_GL_CXXALIAS_RPL (strftime, size_t,
342 (char *restrict __buf, size_t __bufsize,
343 const char *restrict __fmt, const struct tm *restrict __tp));
344# else
345_GL_CXXALIAS_SYS (strftime, size_t,
346 (char *restrict __buf, size_t __bufsize,
347 const char *restrict __fmt, const struct tm *restrict __tp));
348# endif
349# if __GLIBC__ >= 2
350_GL_CXXALIASWARN (strftime);
351# endif
352# endif
353
354# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
355/* Functions that use a first-class time zone data type, instead of
356 relying on an implicit global time zone.
357 Inspired by NetBSD. */
358
359/* Represents a time zone.
360 (timezone_t) NULL stands for UTC. */
361typedef struct tm_zone *timezone_t;
362
363/* tzalloc (name)
364 Returns a time zone object for the given time zone NAME. This object
365 represents the time zone that other functions would use it the TZ
366 environment variable was set to NAME.
367 If NAME is NULL, the result represents the time zone that other functions
368 would use it the TZ environment variable was unset.
369 May return NULL if NAME is invalid (this is platform dependent) or
370 upon memory allocation failure. */
371_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
372_GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
373
374/* tzfree (tz)
375 Frees a time zone object.
376 The argument must have been returned by tzalloc(). */
377_GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz));
378_GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
379
380/* localtime_rz (tz, &t, &result)
381 Converts an absolute time T to a broken-down time RESULT, assuming the
382 time zone TZ.
383 This function is like 'localtime_r', but relies on the argument TZ instead
384 of an implicit global time zone. */
385_GL_FUNCDECL_SYS (localtime_rz, struct tm *,
386 (timezone_t __tz, time_t const *restrict __timer,
387 struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
388_GL_CXXALIAS_SYS (localtime_rz, struct tm *,
389 (timezone_t __tz, time_t const *restrict __timer,
390 struct tm *restrict __result));
391
392/* mktime_z (tz, &tm)
393 Normalizes the broken-down time TM and converts it to an absolute time,
394 assuming the time zone TZ. Returns the absolute time.
395 This function is like 'mktime', but relies on the argument TZ instead
396 of an implicit global time zone. */
397_GL_FUNCDECL_SYS (mktime_z, time_t,
398 (timezone_t __tz, struct tm *restrict __tm)
399 _GL_ARG_NONNULL ((2)));
400_GL_CXXALIAS_SYS (mktime_z, time_t,
401 (timezone_t __tz, struct tm *restrict __tm));
402
403/* Time zone abbreviation strings (returned by 'localtime_rz' or 'mktime_z'
404 in the 'tm_zone' member of 'struct tm') are valid as long as
405 - the 'struct tm' argument is not destroyed or overwritten,
406 and
407 - the 'timezone_t' argument is not freed through tzfree(). */
408
409# endif
410
206/* Convert TM to a time_t value, assuming UTC. */ 411/* Convert TM to a time_t value, assuming UTC. */
207# if @GNULIB_TIMEGM@ 412# if @GNULIB_TIMEGM@
208# if @REPLACE_TIMEGM@ 413# if @REPLACE_TIMEGM@
@@ -231,18 +436,22 @@ _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
231# endif 436# endif
232# if defined GNULIB_POSIXCHECK 437# if defined GNULIB_POSIXCHECK
233# undef asctime_r 438# undef asctime_r
234_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " 439# if HAVE_RAW_DECL_ASCTIME_R
440_GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - "
235 "better use strftime (or even sprintf) instead"); 441 "better use strftime (or even sprintf) instead");
442# endif
236# endif 443# endif
237# if defined GNULIB_POSIXCHECK 444# if defined GNULIB_POSIXCHECK
238# undef ctime 445# undef ctime
239_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " 446_GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - "
240 "better use strftime (or even sprintf) instead"); 447 "better use strftime (or even sprintf) instead");
241# endif 448# endif
242# if defined GNULIB_POSIXCHECK 449# if defined GNULIB_POSIXCHECK
243# undef ctime_r 450# undef ctime_r
244_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " 451# if HAVE_RAW_DECL_CTIME_R
452_GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - "
245 "better use strftime (or even sprintf) instead"); 453 "better use strftime (or even sprintf) instead");
454# endif
246# endif 455# endif
247 456
248#endif 457#endif
diff --git a/gl/time_r.c b/gl/time_r.c
index 9866299..97be4fd 100644
--- a/gl/time_r.c
+++ b/gl/time_r.c
@@ -1,19 +1,19 @@
1/* Reentrant time functions like localtime_r. 1/* Reentrant time functions like localtime_r.
2 2
3 Copyright (C) 2003, 2006-2007, 2010-2013 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2006-2007, 2010-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Paul Eggert. */ 18/* Written by Paul Eggert. */
19 19
diff --git a/gl/timegm.c b/gl/timegm.c
index 6338baa..b47025a 100644
--- a/gl/timegm.c
+++ b/gl/timegm.c
@@ -1,38 +1,58 @@
1/* Convert UTC calendar time to simple time. Like mktime but assumes UTC. 1/* Convert UTC calendar time to simple time. Like mktime but assumes UTC.
2 2
3 Copyright (C) 1994, 1997, 2003-2004, 2006-2007, 2009-2013 Free Software 3 Copyright (C) 1994-2023 Free Software Foundation, Inc.
4 Foundation, Inc. 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 The GNU C Library is free software; you can redistribute it and/or
7 it under the terms of the GNU General Public License as published by 7 modify it under the terms of the GNU Lesser General Public
8 the Free Software Foundation; either version 3, or (at your option) 8 License as published by the Free Software Foundation; either
9 any later version. 9 version 2.1 of the License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 The GNU C Library 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 GNU
14 GNU General Public License for more details. 14 Lesser 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 Lesser General Public
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
18 19
19#ifndef _LIBC 20#ifndef _LIBC
20# include <config.h> 21# include <libc-config.h>
21#endif 22#endif
22 23
23#include <time.h> 24#include <time.h>
25#include <errno.h>
24 26
25#ifndef _LIBC 27#include "mktime-internal.h"
26# undef __gmtime_r 28
27# define __gmtime_r gmtime_r 29__time64_t
28# define __mktime_internal mktime_internal 30__timegm64 (struct tm *tmp)
29# include "mktime-internal.h" 31{
30#endif 32 static mktime_offset_t gmtime_offset;
33 tmp->tm_isdst = 0;
34 return __mktime_internal (tmp, __gmtime64_r, &gmtime_offset);
35}
36
37#if defined _LIBC && __TIMESIZE != 64
38
39libc_hidden_def (__timegm64)
31 40
32time_t 41time_t
33timegm (struct tm *tmp) 42timegm (struct tm *tmp)
34{ 43{
35 static time_t gmtime_offset; 44 struct tm tm = *tmp;
36 tmp->tm_isdst = 0; 45 __time64_t t = __timegm64 (&tm);
37 return __mktime_internal (tmp, __gmtime_r, &gmtime_offset); 46 if (in_time_t_range (t))
47 {
48 *tmp = tm;
49 return t;
50 }
51 else
52 {
53 __set_errno (EOVERFLOW);
54 return -1;
55 }
38} 56}
57
58#endif
diff --git a/gl/unistd.c b/gl/unistd.c
index 6c6a8e2..be7a825 100644
--- a/gl/unistd.c
+++ b/gl/unistd.c
@@ -1,3 +1,22 @@
1/* Inline functions for <unistd.h>.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
1#include <config.h> 18#include <config.h>
19
2#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE 20#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
3#include "unistd.h" 21#include "unistd.h"
22typedef int dummy;
diff --git a/gl/unistd.in.h b/gl/unistd.in.h
index 2ea9af4..4812fdb 100644
--- a/gl/unistd.in.h
+++ b/gl/unistd.in.h
@@ -1,18 +1,18 @@
1/* Substitute for and wrapper around <unistd.h>. 1/* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2013 Free Software Foundation, Inc. 2 Copyright (C) 2003-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#ifndef _@GUARD_PREFIX@_UNISTD_H 17#ifndef _@GUARD_PREFIX@_UNISTD_H
18 18
@@ -21,9 +21,23 @@
21#endif 21#endif
22@PRAGMA_COLUMNS@ 22@PRAGMA_COLUMNS@
23 23
24#if @HAVE_UNISTD_H@ && defined _GL_INCLUDING_UNISTD_H
25/* Special invocation convention:
26 - On Mac OS X 10.3.9 we have a sequence of nested includes
27 <unistd.h> -> <signal.h> -> <pthread.h> -> <unistd.h>
28 In this situation, the functions are not yet declared, therefore we cannot
29 provide the C++ aliases. */
30
31#@INCLUDE_NEXT@ @NEXT_UNISTD_H@
32
33#else
34/* Normal invocation convention. */
35
24/* The include_next requires a split double-inclusion guard. */ 36/* The include_next requires a split double-inclusion guard. */
25#if @HAVE_UNISTD_H@ 37#if @HAVE_UNISTD_H@
38# define _GL_INCLUDING_UNISTD_H
26# @INCLUDE_NEXT@ @NEXT_UNISTD_H@ 39# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
40# undef _GL_INCLUDING_UNISTD_H
27#endif 41#endif
28 42
29/* Get all possible declarations of gethostname(). */ 43/* Get all possible declarations of gethostname(). */
@@ -38,21 +52,30 @@
38#define _@GUARD_PREFIX@_UNISTD_H 52#define _@GUARD_PREFIX@_UNISTD_H
39 53
40/* NetBSD 5.0 mis-defines NULL. Also get size_t. */ 54/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
41#include <stddef.h> 55/* But avoid namespace pollution on glibc systems. */
56#ifndef __GLIBC__
57# include <stddef.h>
58#endif
42 59
43/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */ 60/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
61/* MSVC declares 'unlink' in <stdio.h>, not in <unistd.h>. We must include
62 it before we #define unlink rpl_unlink. */
44/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */ 63/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
45/* But avoid namespace pollution on glibc systems. */ 64/* But avoid namespace pollution on glibc systems. */
46#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \ 65#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
66 || ((@GNULIB_UNLINK@ || defined GNULIB_POSIXCHECK) \
67 && (defined _WIN32 && ! defined __CYGWIN__)) \
47 || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \ 68 || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \
48 && defined __CYGWIN__)) \ 69 && defined __CYGWIN__)) \
49 && ! defined __GLIBC__ 70 && ! defined __GLIBC__
50# include <stdio.h> 71# include <stdio.h>
51#endif 72#endif
52 73
53/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */ 74/* Cygwin 1.7.1 and Android 4.3 declare unlinkat in <fcntl.h>, not in
75 <unistd.h>. */
54/* But avoid namespace pollution on glibc systems. */ 76/* But avoid namespace pollution on glibc systems. */
55#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \ 77#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) \
78 && (defined __CYGWIN__ || defined __ANDROID__) \
56 && ! defined __GLIBC__ 79 && ! defined __GLIBC__
57# include <fcntl.h> 80# include <fcntl.h>
58#endif 81#endif
@@ -70,20 +93,18 @@
70# undef __need_system_stdlib_h 93# undef __need_system_stdlib_h
71#endif 94#endif
72 95
73/* Native Windows platforms declare chdir, getcwd, rmdir in 96/* Native Windows platforms declare _chdir, _getcwd, _rmdir in
74 <io.h> and/or <direct.h>, not in <unistd.h>. 97 <io.h> and/or <direct.h>, not in <unistd.h>.
75 They also declare access(), chmod(), close(), dup(), dup2(), isatty(), 98 They also declare _access(), _chmod(), _close(), _dup(), _dup2(), _isatty(),
76 lseek(), read(), unlink(), write() in <io.h>. */ 99 _lseek(), _read(), _unlink(), _write() in <io.h>. */
77#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \ 100#if defined _WIN32 && !defined __CYGWIN__
78 || defined GNULIB_POSIXCHECK) \
79 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
80# include <io.h> /* mingw32, mingw64 */
81# include <direct.h> /* mingw64, MSVC 9 */
82#elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \
83 || @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \
84 || defined GNULIB_POSIXCHECK) \
85 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
86# include <io.h> 101# include <io.h>
102# include <direct.h>
103#endif
104
105/* Native Windows platforms declare _execl*, _execv* in <process.h>. */
106#if defined _WIN32 && !defined __CYGWIN__
107# include <process.h>
87#endif 108#endif
88 109
89/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>. 110/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
@@ -95,31 +116,28 @@
95# include <netdb.h> 116# include <netdb.h>
96#endif 117#endif
97 118
98/* MSVC defines off_t in <sys/types.h>. 119/* Mac OS X 10.13, Solaris 11.4, and Android 9.0 declare getentropy in
99 May also define off_t to a 64-bit type on native Windows. */ 120 <sys/random.h>, not in <unistd.h>. */
100#if !@HAVE_UNISTD_H@ || @WINDOWS_64_BIT_OFF_T@ 121/* But avoid namespace pollution on glibc systems. */
101/* Get off_t. */ 122#if (@GNULIB_GETENTROPY@ || defined GNULIB_POSIXCHECK) \
102# include <sys/types.h> 123 && ((defined __APPLE__ && defined __MACH__) || defined __sun \
103#endif 124 || defined __ANDROID__) \
104 125 && @UNISTD_H_HAVE_SYS_RANDOM_H@ \
105#if (@GNULIB_READ@ || @GNULIB_WRITE@ \ 126 && !defined __GLIBC__
106 || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \ 127# include <sys/random.h>
107 || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
108/* Get ssize_t. */
109# include <sys/types.h>
110#endif 128#endif
111 129
112/* Get getopt(), optarg, optind, opterr, optopt. 130/* Android 4.3 declares fchownat in <sys/stat.h>, not in <unistd.h>. */
113 But avoid namespace pollution on glibc systems. */ 131/* But avoid namespace pollution on glibc systems. */
114#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT 132#if (@GNULIB_FCHOWNAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
115# define __need_getopt 133 && !defined __GLIBC__
116# include <getopt.h> 134# include <sys/stat.h>
117#endif 135#endif
118 136
119_GL_INLINE_HEADER_BEGIN 137/* MSVC defines off_t in <sys/types.h>.
120#ifndef _GL_UNISTD_INLINE 138 May also define off_t to a 64-bit type on native Windows. */
121# define _GL_UNISTD_INLINE _GL_INLINE 139/* Get off_t, ssize_t, mode_t. */
122#endif 140#include <sys/types.h>
123 141
124/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 142/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
125 143
@@ -128,6 +146,20 @@ _GL_INLINE_HEADER_BEGIN
128/* The definition of _GL_WARN_ON_USE is copied here. */ 146/* The definition of _GL_WARN_ON_USE is copied here. */
129 147
130 148
149/* Get getopt(), optarg, optind, opterr, optopt. */
150#if @GNULIB_GETOPT_POSIX@ && @GNULIB_UNISTD_H_GETOPT@ && !defined _GL_SYSTEM_GETOPT
151# include <getopt-cdefs.h>
152# include <getopt-pfx-core.h>
153#endif
154
155#ifndef _GL_INLINE_HEADER_BEGIN
156 #error "Please include config.h first."
157#endif
158_GL_INLINE_HEADER_BEGIN
159#ifndef _GL_UNISTD_INLINE
160# define _GL_UNISTD_INLINE _GL_INLINE
161#endif
162
131/* Hide some function declarations from <winsock2.h>. */ 163/* Hide some function declarations from <winsock2.h>. */
132 164
133#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ 165#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@
@@ -227,15 +259,61 @@ _GL_INLINE_HEADER_BEGIN
227/* Declare overridden functions. */ 259/* Declare overridden functions. */
228 260
229 261
230#if defined GNULIB_POSIXCHECK 262#if @GNULIB_ACCESS@
263# if @REPLACE_ACCESS@
264# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
265# undef access
266# define access rpl_access
267# endif
268_GL_FUNCDECL_RPL (access, int, (const char *file, int mode)
269 _GL_ARG_NONNULL ((1)));
270_GL_CXXALIAS_RPL (access, int, (const char *file, int mode));
271# elif defined _WIN32 && !defined __CYGWIN__
272# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
273# undef access
274# define access _access
275# endif
276_GL_CXXALIAS_MDA (access, int, (const char *file, int mode));
277# else
278_GL_CXXALIAS_SYS (access, int, (const char *file, int mode));
279# endif
280_GL_CXXALIASWARN (access);
281#elif defined GNULIB_POSIXCHECK
282# undef access
283# if HAVE_RAW_DECL_ACCESS
231/* The access() function is a security risk. */ 284/* The access() function is a security risk. */
232_GL_WARN_ON_USE (access, "the access function is a security risk - " 285_GL_WARN_ON_USE (access, "access does not always support X_OK - "
286 "use gnulib module access for portability; "
287 "also, this function is a security risk - "
233 "use the gnulib module faccessat instead"); 288 "use the gnulib module faccessat instead");
289# endif
290#elif @GNULIB_MDA_ACCESS@
291/* On native Windows, map 'access' to '_access', so that -loldnames is not
292 required. In C++ with GNULIB_NAMESPACE, avoid differences between
293 platforms by defining GNULIB_NAMESPACE::access always. */
294# if defined _WIN32 && !defined __CYGWIN__
295# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
296# undef access
297# define access _access
298# endif
299_GL_CXXALIAS_MDA (access, int, (const char *file, int mode));
300# else
301_GL_CXXALIAS_SYS (access, int, (const char *file, int mode));
302# endif
303_GL_CXXALIASWARN (access);
234#endif 304#endif
235 305
236 306
237#if @GNULIB_CHDIR@ 307#if @GNULIB_CHDIR@
308# if defined _WIN32 && !defined __CYGWIN__
309# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
310# undef chdir
311# define chdir _chdir
312# endif
313_GL_CXXALIAS_MDA (chdir, int, (const char *file));
314# else
238_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1))); 315_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
316# endif
239_GL_CXXALIASWARN (chdir); 317_GL_CXXALIASWARN (chdir);
240#elif defined GNULIB_POSIXCHECK 318#elif defined GNULIB_POSIXCHECK
241# undef chdir 319# undef chdir
@@ -243,6 +321,20 @@ _GL_CXXALIASWARN (chdir);
243_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - " 321_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
244 "use gnulib module chdir for portability"); 322 "use gnulib module chdir for portability");
245# endif 323# endif
324#elif @GNULIB_MDA_CHDIR@
325/* On native Windows, map 'chdir' to '_chdir', so that -loldnames is not
326 required. In C++ with GNULIB_NAMESPACE, avoid differences between
327 platforms by defining GNULIB_NAMESPACE::chdir always. */
328# if defined _WIN32 && !defined __CYGWIN__
329# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
330# undef chdir
331# define chdir _chdir
332# endif
333_GL_CXXALIAS_MDA (chdir, int, (const char *file));
334# else
335_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
336# endif
337_GL_CXXALIASWARN (chdir);
246#endif 338#endif
247 339
248 340
@@ -251,7 +343,7 @@ _GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
251 to GID (if GID is not -1). Follow symbolic links. 343 to GID (if GID is not -1). Follow symbolic links.
252 Return 0 if successful, otherwise -1 and errno set. 344 Return 0 if successful, otherwise -1 and errno set.
253 See the POSIX:2008 specification 345 See the POSIX:2008 specification
254 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html. */ 346 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html. */
255# if @REPLACE_CHOWN@ 347# if @REPLACE_CHOWN@
256# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 348# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
257# undef chown 349# undef chown
@@ -287,6 +379,12 @@ _GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
287# endif 379# endif
288_GL_FUNCDECL_RPL (close, int, (int fd)); 380_GL_FUNCDECL_RPL (close, int, (int fd));
289_GL_CXXALIAS_RPL (close, int, (int fd)); 381_GL_CXXALIAS_RPL (close, int, (int fd));
382# elif defined _WIN32 && !defined __CYGWIN__
383# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
384# undef close
385# define close _close
386# endif
387_GL_CXXALIAS_MDA (close, int, (int fd));
290# else 388# else
291_GL_CXXALIAS_SYS (close, int, (int fd)); 389_GL_CXXALIAS_SYS (close, int, (int fd));
292# endif 390# endif
@@ -299,6 +397,53 @@ _GL_CXXALIASWARN (close);
299/* Assume close is always declared. */ 397/* Assume close is always declared. */
300_GL_WARN_ON_USE (close, "close does not portably work on sockets - " 398_GL_WARN_ON_USE (close, "close does not portably work on sockets - "
301 "use gnulib module close for portability"); 399 "use gnulib module close for portability");
400#elif @GNULIB_MDA_CLOSE@
401/* On native Windows, map 'close' to '_close', so that -loldnames is not
402 required. In C++ with GNULIB_NAMESPACE, avoid differences between
403 platforms by defining GNULIB_NAMESPACE::close always. */
404# if defined _WIN32 && !defined __CYGWIN__
405# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
406# undef close
407# define close _close
408# endif
409_GL_CXXALIAS_MDA (close, int, (int fd));
410# else
411_GL_CXXALIAS_SYS (close, int, (int fd));
412# endif
413_GL_CXXALIASWARN (close);
414#endif
415
416
417#if @GNULIB_COPY_FILE_RANGE@
418# if @REPLACE_COPY_FILE_RANGE@
419# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
420# undef copy_file_range
421# define copy_file_range rpl_copy_file_range
422# endif
423_GL_FUNCDECL_RPL (copy_file_range, ssize_t, (int ifd, off_t *ipos,
424 int ofd, off_t *opos,
425 size_t len, unsigned flags));
426_GL_CXXALIAS_RPL (copy_file_range, ssize_t, (int ifd, off_t *ipos,
427 int ofd, off_t *opos,
428 size_t len, unsigned flags));
429# else
430# if !@HAVE_COPY_FILE_RANGE@
431_GL_FUNCDECL_SYS (copy_file_range, ssize_t, (int ifd, off_t *ipos,
432 int ofd, off_t *opos,
433 size_t len, unsigned flags));
434# endif
435_GL_CXXALIAS_SYS (copy_file_range, ssize_t, (int ifd, off_t *ipos,
436 int ofd, off_t *opos,
437 size_t len, unsigned flags));
438# endif
439_GL_CXXALIASWARN (copy_file_range);
440#elif defined GNULIB_POSIXCHECK
441# undef copy_file_range
442# if HAVE_RAW_DECL_COPY_FILE_RANGE
443_GL_WARN_ON_USE (copy_file_range,
444 "copy_file_range is unportable - "
445 "use gnulib module copy_file_range for portability");
446# endif
302#endif 447#endif
303 448
304 449
@@ -309,6 +454,12 @@ _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
309# endif 454# endif
310_GL_FUNCDECL_RPL (dup, int, (int oldfd)); 455_GL_FUNCDECL_RPL (dup, int, (int oldfd));
311_GL_CXXALIAS_RPL (dup, int, (int oldfd)); 456_GL_CXXALIAS_RPL (dup, int, (int oldfd));
457# elif defined _WIN32 && !defined __CYGWIN__
458# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
459# undef dup
460# define dup _dup
461# endif
462_GL_CXXALIAS_MDA (dup, int, (int oldfd));
312# else 463# else
313_GL_CXXALIAS_SYS (dup, int, (int oldfd)); 464_GL_CXXALIAS_SYS (dup, int, (int oldfd));
314# endif 465# endif
@@ -319,6 +470,20 @@ _GL_CXXALIASWARN (dup);
319_GL_WARN_ON_USE (dup, "dup is unportable - " 470_GL_WARN_ON_USE (dup, "dup is unportable - "
320 "use gnulib module dup for portability"); 471 "use gnulib module dup for portability");
321# endif 472# endif
473#elif @GNULIB_MDA_DUP@
474/* On native Windows, map 'dup' to '_dup', so that -loldnames is not
475 required. In C++ with GNULIB_NAMESPACE, avoid differences between
476 platforms by defining GNULIB_NAMESPACE::dup always. */
477# if defined _WIN32 && !defined __CYGWIN__
478# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
479# undef dup
480# define dup _dup
481# endif
482_GL_CXXALIAS_MDA (dup, int, (int oldfd));
483# else
484_GL_CXXALIAS_SYS (dup, int, (int oldfd));
485# endif
486_GL_CXXALIASWARN (dup);
322#endif 487#endif
323 488
324 489
@@ -327,17 +492,20 @@ _GL_WARN_ON_USE (dup, "dup is unportable - "
327 NEWFD = OLDFD, otherwise close NEWFD first if it is open. 492 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
328 Return newfd if successful, otherwise -1 and errno set. 493 Return newfd if successful, otherwise -1 and errno set.
329 See the POSIX:2008 specification 494 See the POSIX:2008 specification
330 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */ 495 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */
331# if @REPLACE_DUP2@ 496# if @REPLACE_DUP2@
332# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 497# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
333# define dup2 rpl_dup2 498# define dup2 rpl_dup2
334# endif 499# endif
335_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd)); 500_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
336_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd)); 501_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
337# else 502# elif defined _WIN32 && !defined __CYGWIN__
338# if !@HAVE_DUP2@ 503# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
339_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd)); 504# undef dup2
505# define dup2 _dup2
340# endif 506# endif
507_GL_CXXALIAS_MDA (dup2, int, (int oldfd, int newfd));
508# else
341_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd)); 509_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
342# endif 510# endif
343_GL_CXXALIASWARN (dup2); 511_GL_CXXALIASWARN (dup2);
@@ -347,6 +515,20 @@ _GL_CXXALIASWARN (dup2);
347_GL_WARN_ON_USE (dup2, "dup2 is unportable - " 515_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
348 "use gnulib module dup2 for portability"); 516 "use gnulib module dup2 for portability");
349# endif 517# endif
518#elif @GNULIB_MDA_DUP2@
519/* On native Windows, map 'dup2' to '_dup2', so that -loldnames is not
520 required. In C++ with GNULIB_NAMESPACE, avoid differences between
521 platforms by defining GNULIB_NAMESPACE::dup2 always. */
522# if defined _WIN32 && !defined __CYGWIN__
523# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
524# undef dup2
525# define dup2 _dup2
526# endif
527_GL_CXXALIAS_MDA (dup2, int, (int oldfd, int newfd));
528# else
529_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
530# endif
531_GL_CXXALIASWARN (dup2);
350#endif 532#endif
351 533
352 534
@@ -358,7 +540,7 @@ _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
358 Close NEWFD first if it is open. 540 Close NEWFD first if it is open.
359 Return newfd if successful, otherwise -1 and errno set. 541 Return newfd if successful, otherwise -1 and errno set.
360 See the Linux man page at 542 See the Linux man page at
361 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */ 543 <https://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
362# if @HAVE_DUP3@ 544# if @HAVE_DUP3@
363# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 545# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
364# define dup3 rpl_dup3 546# define dup3 rpl_dup3
@@ -380,10 +562,23 @@ _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
380 562
381 563
382#if @GNULIB_ENVIRON@ 564#if @GNULIB_ENVIRON@
565# if defined __CYGWIN__ && !defined __i386__
566/* The 'environ' variable is defined in a DLL. Therefore its declaration needs
567 the '__declspec(dllimport)' attribute, but the system's <unistd.h> lacks it.
568 This leads to a link error on 64-bit Cygwin when the option
569 -Wl,--disable-auto-import is in use. */
570_GL_EXTERN_C __declspec(dllimport) char **environ;
571# endif
383# if !@HAVE_DECL_ENVIRON@ 572# if !@HAVE_DECL_ENVIRON@
384/* Set of environment variables and values. An array of strings of the form 573/* Set of environment variables and values. An array of strings of the form
385 "VARIABLE=VALUE", terminated with a NULL. */ 574 "VARIABLE=VALUE", terminated with a NULL. */
386# if defined __APPLE__ && defined __MACH__ 575# if defined __APPLE__ && defined __MACH__
576# include <TargetConditionals.h>
577# if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
578# define _GL_USE_CRT_EXTERNS
579# endif
580# endif
581# ifdef _GL_USE_CRT_EXTERNS
387# include <crt_externs.h> 582# include <crt_externs.h>
388# define environ (*_NSGetEnviron ()) 583# define environ (*_NSGetEnviron ())
389# else 584# else
@@ -399,12 +594,12 @@ extern char **environ;
399#elif defined GNULIB_POSIXCHECK 594#elif defined GNULIB_POSIXCHECK
400# if HAVE_RAW_DECL_ENVIRON 595# if HAVE_RAW_DECL_ENVIRON
401_GL_UNISTD_INLINE char *** 596_GL_UNISTD_INLINE char ***
597_GL_WARN_ON_USE_ATTRIBUTE ("environ is unportable - "
598 "use gnulib module environ for portability")
402rpl_environ (void) 599rpl_environ (void)
403{ 600{
404 return &environ; 601 return &environ;
405} 602}
406_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
407 "use gnulib module environ for portability");
408# undef environ 603# undef environ
409# define environ (*rpl_environ ()) 604# define environ (*rpl_environ ())
410# endif 605# endif
@@ -434,14 +629,302 @@ _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
434#endif 629#endif
435 630
436 631
632#if @GNULIB_EXECL@
633# if @REPLACE_EXECL@
634# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
635# undef execl
636# define execl rpl_execl
637# endif
638_GL_FUNCDECL_RPL (execl, int, (const char *program, const char *arg, ...)
639 _GL_ARG_NONNULL ((1)));
640_GL_CXXALIAS_RPL (execl, int, (const char *program, const char *arg, ...));
641# else
642_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...));
643# endif
644_GL_CXXALIASWARN (execl);
645#elif defined GNULIB_POSIXCHECK
646# undef execl
647# if HAVE_RAW_DECL_EXECL
648_GL_WARN_ON_USE (execl, "execl behaves very differently on mingw - "
649 "use gnulib module execl for portability");
650# endif
651#elif @GNULIB_MDA_EXECL@
652/* On native Windows, map 'execl' to '_execl', so that -loldnames is not
653 required. In C++ with GNULIB_NAMESPACE, avoid differences between
654 platforms by defining GNULIB_NAMESPACE::execl always. */
655# if defined _WIN32 && !defined __CYGWIN__
656# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
657# undef execl
658# define execl _execl
659# endif
660_GL_CXXALIAS_MDA (execl, intptr_t, (const char *program, const char *arg, ...));
661# else
662_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...));
663# endif
664_GL_CXXALIASWARN (execl);
665#endif
666
667#if @GNULIB_EXECLE@
668# if @REPLACE_EXECLE@
669# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
670# undef execle
671# define execle rpl_execle
672# endif
673_GL_FUNCDECL_RPL (execle, int, (const char *program, const char *arg, ...)
674 _GL_ARG_NONNULL ((1)));
675_GL_CXXALIAS_RPL (execle, int, (const char *program, const char *arg, ...));
676# else
677_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...));
678# endif
679_GL_CXXALIASWARN (execle);
680#elif defined GNULIB_POSIXCHECK
681# undef execle
682# if HAVE_RAW_DECL_EXECLE
683_GL_WARN_ON_USE (execle, "execle behaves very differently on mingw - "
684 "use gnulib module execle for portability");
685# endif
686#elif @GNULIB_MDA_EXECLE@
687/* On native Windows, map 'execle' to '_execle', so that -loldnames is not
688 required. In C++ with GNULIB_NAMESPACE, avoid differences between
689 platforms by defining GNULIB_NAMESPACE::execle always. */
690# if defined _WIN32 && !defined __CYGWIN__
691# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
692# undef execle
693# define execle _execle
694# endif
695_GL_CXXALIAS_MDA (execle, intptr_t,
696 (const char *program, const char *arg, ...));
697# else
698_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...));
699# endif
700_GL_CXXALIASWARN (execle);
701#endif
702
703#if @GNULIB_EXECLP@
704# if @REPLACE_EXECLP@
705# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
706# undef execlp
707# define execlp rpl_execlp
708# endif
709_GL_FUNCDECL_RPL (execlp, int, (const char *program, const char *arg, ...)
710 _GL_ARG_NONNULL ((1)));
711_GL_CXXALIAS_RPL (execlp, int, (const char *program, const char *arg, ...));
712# else
713_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...));
714# endif
715_GL_CXXALIASWARN (execlp);
716#elif defined GNULIB_POSIXCHECK
717# undef execlp
718# if HAVE_RAW_DECL_EXECLP
719_GL_WARN_ON_USE (execlp, "execlp behaves very differently on mingw - "
720 "use gnulib module execlp for portability");
721# endif
722#elif @GNULIB_MDA_EXECLP@
723/* On native Windows, map 'execlp' to '_execlp', so that -loldnames is not
724 required. In C++ with GNULIB_NAMESPACE, avoid differences between
725 platforms by defining GNULIB_NAMESPACE::execlp always. */
726# if defined _WIN32 && !defined __CYGWIN__
727# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
728# undef execlp
729# define execlp _execlp
730# endif
731_GL_CXXALIAS_MDA (execlp, intptr_t,
732 (const char *program, const char *arg, ...));
733# else
734_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...));
735# endif
736_GL_CXXALIASWARN (execlp);
737#endif
738
739
740#if @GNULIB_EXECV@
741# if @REPLACE_EXECV@
742# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
743# undef execv
744# define execv rpl_execv
745# endif
746_GL_FUNCDECL_RPL (execv, int, (const char *program, char * const *argv)
747 _GL_ARG_NONNULL ((1, 2)));
748_GL_CXXALIAS_RPL (execv, int, (const char *program, char * const *argv));
749# else
750_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv));
751# endif
752_GL_CXXALIASWARN (execv);
753#elif defined GNULIB_POSIXCHECK
754# undef execv
755# if HAVE_RAW_DECL_EXECV
756_GL_WARN_ON_USE (execv, "execv behaves very differently on mingw - "
757 "use gnulib module execv for portability");
758# endif
759#elif @GNULIB_MDA_EXECV@
760/* On native Windows, map 'execv' to '_execv', so that -loldnames is not
761 required. In C++ with GNULIB_NAMESPACE, avoid differences between
762 platforms by defining GNULIB_NAMESPACE::execv always. */
763# if defined _WIN32 && !defined __CYGWIN__
764# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
765# undef execv
766# define execv _execv
767# endif
768_GL_CXXALIAS_MDA_CAST (execv, intptr_t,
769 (const char *program, char * const *argv));
770# else
771_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv));
772# endif
773_GL_CXXALIASWARN (execv);
774#endif
775
776#if @GNULIB_EXECVE@
777# if @REPLACE_EXECVE@
778# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
779# undef execve
780# define execve rpl_execve
781# endif
782_GL_FUNCDECL_RPL (execve, int,
783 (const char *program, char * const *argv, char * const *env)
784 _GL_ARG_NONNULL ((1, 2)));
785_GL_CXXALIAS_RPL (execve, int,
786 (const char *program, char * const *argv, char * const *env));
787# else
788_GL_CXXALIAS_SYS (execve, int,
789 (const char *program, char * const *argv, char * const *env));
790# endif
791_GL_CXXALIASWARN (execve);
792#elif defined GNULIB_POSIXCHECK
793# undef execve
794# if HAVE_RAW_DECL_EXECVE
795_GL_WARN_ON_USE (execve, "execve behaves very differently on mingw - "
796 "use gnulib module execve for portability");
797# endif
798#elif @GNULIB_MDA_EXECVE@
799/* On native Windows, map 'execve' to '_execve', so that -loldnames is not
800 required. In C++ with GNULIB_NAMESPACE, avoid differences between
801 platforms by defining GNULIB_NAMESPACE::execve always. */
802# if defined _WIN32 && !defined __CYGWIN__
803# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
804# undef execve
805# define execve _execve
806# endif
807_GL_CXXALIAS_MDA_CAST (execve, intptr_t,
808 (const char *program, char * const *argv,
809 char * const *env));
810# else
811_GL_CXXALIAS_SYS (execve, int,
812 (const char *program, char * const *argv, char * const *env));
813# endif
814_GL_CXXALIASWARN (execve);
815#endif
816
817#if @GNULIB_EXECVP@
818# if @REPLACE_EXECVP@
819# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
820# undef execvp
821# define execvp rpl_execvp
822# endif
823_GL_FUNCDECL_RPL (execvp, int, (const char *program, char * const *argv)
824 _GL_ARG_NONNULL ((1, 2)));
825_GL_CXXALIAS_RPL (execvp, int, (const char *program, char * const *argv));
826# else
827_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv));
828# endif
829_GL_CXXALIASWARN (execvp);
830#elif defined GNULIB_POSIXCHECK
831# undef execvp
832# if HAVE_RAW_DECL_EXECVP
833_GL_WARN_ON_USE (execvp, "execvp behaves very differently on mingw - "
834 "use gnulib module execvp for portability");
835# endif
836#elif @GNULIB_MDA_EXECVP@
837/* On native Windows, map 'execvp' to '_execvp', so that -loldnames is not
838 required. In C++ with GNULIB_NAMESPACE, avoid differences between
839 platforms by defining GNULIB_NAMESPACE::execvp always. */
840# if defined _WIN32 && !defined __CYGWIN__
841# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
842# undef execvp
843# define execvp _execvp
844# endif
845_GL_CXXALIAS_MDA_CAST (execvp, intptr_t,
846 (const char *program, char * const *argv));
847# else
848_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv));
849# endif
850_GL_CXXALIASWARN (execvp);
851#endif
852
853#if @GNULIB_EXECVPE@
854# if @REPLACE_EXECVPE@
855# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
856# undef execvpe
857# define execvpe rpl_execvpe
858# endif
859_GL_FUNCDECL_RPL (execvpe, int,
860 (const char *program, char * const *argv, char * const *env)
861 _GL_ARG_NONNULL ((1, 2)));
862_GL_CXXALIAS_RPL (execvpe, int,
863 (const char *program, char * const *argv, char * const *env));
864# else
865# if !@HAVE_DECL_EXECVPE@
866_GL_FUNCDECL_SYS (execvpe, int,
867 (const char *program, char * const *argv, char * const *env)
868 _GL_ARG_NONNULL ((1, 2)));
869# endif
870_GL_CXXALIAS_SYS (execvpe, int,
871 (const char *program, char * const *argv, char * const *env));
872# endif
873_GL_CXXALIASWARN (execvpe);
874#elif defined GNULIB_POSIXCHECK
875# undef execvpe
876# if HAVE_RAW_DECL_EXECVPE
877_GL_WARN_ON_USE (execvpe, "execvpe behaves very differently on mingw - "
878 "use gnulib module execvpe for portability");
879# endif
880#elif @GNULIB_MDA_EXECVPE@
881/* On native Windows, map 'execvpe' to '_execvpe', so that -loldnames is not
882 required. In C++ with GNULIB_NAMESPACE, avoid differences between
883 platforms by defining GNULIB_NAMESPACE::execvpe on all platforms that have
884 it. */
885# if defined _WIN32 && !defined __CYGWIN__
886# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
887# undef execvpe
888# define execvpe _execvpe
889# endif
890_GL_CXXALIAS_MDA_CAST (execvpe, intptr_t,
891 (const char *program, char * const *argv,
892 char * const *env));
893# elif @HAVE_EXECVPE@
894# if !@HAVE_DECL_EXECVPE@
895_GL_FUNCDECL_SYS (execvpe, int,
896 (const char *program, char * const *argv, char * const *env)
897 _GL_ARG_NONNULL ((1, 2)));
898# endif
899_GL_CXXALIAS_SYS (execvpe, int,
900 (const char *program, char * const *argv, char * const *env));
901# endif
902# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_EXECVPE@
903_GL_CXXALIASWARN (execvpe);
904# endif
905#endif
906
907
437#if @GNULIB_FACCESSAT@ 908#if @GNULIB_FACCESSAT@
438# if !@HAVE_FACCESSAT@ 909# if @REPLACE_FACCESSAT@
910# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
911# undef faccessat
912# define faccessat rpl_faccessat
913# endif
914_GL_FUNCDECL_RPL (faccessat, int,
915 (int fd, char const *name, int mode, int flag)
916 _GL_ARG_NONNULL ((2)));
917_GL_CXXALIAS_RPL (faccessat, int,
918 (int fd, char const *name, int mode, int flag));
919# else
920# if !@HAVE_FACCESSAT@
439_GL_FUNCDECL_SYS (faccessat, int, 921_GL_FUNCDECL_SYS (faccessat, int,
440 (int fd, char const *file, int mode, int flag) 922 (int fd, char const *file, int mode, int flag)
441 _GL_ARG_NONNULL ((2))); 923 _GL_ARG_NONNULL ((2)));
442# endif 924# endif
443_GL_CXXALIAS_SYS (faccessat, int, 925_GL_CXXALIAS_SYS (faccessat, int,
444 (int fd, char const *file, int mode, int flag)); 926 (int fd, char const *file, int mode, int flag));
927# endif
445_GL_CXXALIASWARN (faccessat); 928_GL_CXXALIASWARN (faccessat);
446#elif defined GNULIB_POSIXCHECK 929#elif defined GNULIB_POSIXCHECK
447# undef faccessat 930# undef faccessat
@@ -457,7 +940,7 @@ _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
457 the given file descriptor is open. 940 the given file descriptor is open.
458 Return 0 if successful, otherwise -1 and errno set. 941 Return 0 if successful, otherwise -1 and errno set.
459 See the POSIX:2008 specification 942 See the POSIX:2008 specification
460 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */ 943 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */
461# if ! @HAVE_FCHDIR@ 944# if ! @HAVE_FCHDIR@
462_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); 945_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
463 946
@@ -509,7 +992,7 @@ _GL_CXXALIASWARN (fchownat);
509# undef fchownat 992# undef fchownat
510# if HAVE_RAW_DECL_FCHOWNAT 993# if HAVE_RAW_DECL_FCHOWNAT
511_GL_WARN_ON_USE (fchownat, "fchownat is not portable - " 994_GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
512 "use gnulib module openat for portability"); 995 "use gnulib module fchownat for portability");
513# endif 996# endif
514#endif 997#endif
515 998
@@ -518,7 +1001,7 @@ _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
518/* Synchronize changes to a file. 1001/* Synchronize changes to a file.
519 Return 0 if successful, otherwise -1 and errno set. 1002 Return 0 if successful, otherwise -1 and errno set.
520 See POSIX:2008 specification 1003 See POSIX:2008 specification
521 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */ 1004 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */
522# if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@ 1005# if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@
523_GL_FUNCDECL_SYS (fdatasync, int, (int fd)); 1006_GL_FUNCDECL_SYS (fdatasync, int, (int fd));
524# endif 1007# endif
@@ -537,7 +1020,7 @@ _GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
537/* Synchronize changes, including metadata, to a file. 1020/* Synchronize changes, including metadata, to a file.
538 Return 0 if successful, otherwise -1 and errno set. 1021 Return 0 if successful, otherwise -1 and errno set.
539 See POSIX:2008 specification 1022 See POSIX:2008 specification
540 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */ 1023 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */
541# if !@HAVE_FSYNC@ 1024# if !@HAVE_FSYNC@
542_GL_FUNCDECL_SYS (fsync, int, (int fd)); 1025_GL_FUNCDECL_SYS (fsync, int, (int fd));
543# endif 1026# endif
@@ -556,7 +1039,7 @@ _GL_WARN_ON_USE (fsync, "fsync is unportable - "
556/* Change the size of the file to which FD is opened to become equal to LENGTH. 1039/* Change the size of the file to which FD is opened to become equal to LENGTH.
557 Return 0 if successful, otherwise -1 and errno set. 1040 Return 0 if successful, otherwise -1 and errno set.
558 See the POSIX:2008 specification 1041 See the POSIX:2008 specification
559 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */ 1042 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */
560# if @REPLACE_FTRUNCATE@ 1043# if @REPLACE_FTRUNCATE@
561# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1044# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
562# undef ftruncate 1045# undef ftruncate
@@ -586,7 +1069,7 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
586 Return BUF if successful, or NULL if the directory couldn't be determined 1069 Return BUF if successful, or NULL if the directory couldn't be determined
587 or SIZE was too small. 1070 or SIZE was too small.
588 See the POSIX:2008 specification 1071 See the POSIX:2008 specification
589 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>. 1072 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
590 Additionally, the gnulib module 'getcwd' guarantees the following GNU 1073 Additionally, the gnulib module 'getcwd' guarantees the following GNU
591 extension: If BUF is NULL, an array is allocated with 'malloc'; the array 1074 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
592 is SIZE bytes long, unless SIZE == 0, in which case it is as big as 1075 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
@@ -597,6 +1080,12 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
597# endif 1080# endif
598_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size)); 1081_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
599_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size)); 1082_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
1083# elif defined _WIN32 && !defined __CYGWIN__
1084# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1085# undef getcwd
1086# define getcwd _getcwd
1087# endif
1088_GL_CXXALIAS_MDA (getcwd, char *, (char *buf, size_t size));
600# else 1089# else
601/* Need to cast, because on mingw, the second parameter is 1090/* Need to cast, because on mingw, the second parameter is
602 int size. */ 1091 int size. */
@@ -609,6 +1098,22 @@ _GL_CXXALIASWARN (getcwd);
609_GL_WARN_ON_USE (getcwd, "getcwd is unportable - " 1098_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
610 "use gnulib module getcwd for portability"); 1099 "use gnulib module getcwd for portability");
611# endif 1100# endif
1101#elif @GNULIB_MDA_GETCWD@
1102/* On native Windows, map 'getcwd' to '_getcwd', so that -loldnames is not
1103 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1104 platforms by defining GNULIB_NAMESPACE::getcwd always. */
1105# if defined _WIN32 && !defined __CYGWIN__
1106# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1107# undef getcwd
1108# define getcwd _getcwd
1109# endif
1110/* Need to cast, because on mingw, the second parameter is either
1111 'int size' or 'size_t size'. */
1112_GL_CXXALIAS_MDA_CAST (getcwd, char *, (char *buf, size_t size));
1113# else
1114_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
1115# endif
1116_GL_CXXALIASWARN (getcwd);
612#endif 1117#endif
613 1118
614 1119
@@ -638,7 +1143,9 @@ _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
638# endif 1143# endif
639_GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len)); 1144_GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len));
640# endif 1145# endif
1146# if __GLIBC__ >= 2
641_GL_CXXALIASWARN (getdomainname); 1147_GL_CXXALIASWARN (getdomainname);
1148# endif
642#elif defined GNULIB_POSIXCHECK 1149#elif defined GNULIB_POSIXCHECK
643# undef getdomainname 1150# undef getdomainname
644# if HAVE_RAW_DECL_GETDOMAINNAME 1151# if HAVE_RAW_DECL_GETDOMAINNAME
@@ -651,10 +1158,21 @@ _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
651#if @GNULIB_GETDTABLESIZE@ 1158#if @GNULIB_GETDTABLESIZE@
652/* Return the maximum number of file descriptors in the current process. 1159/* Return the maximum number of file descriptors in the current process.
653 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ 1160 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
654# if !@HAVE_GETDTABLESIZE@ 1161# if @REPLACE_GETDTABLESIZE@
1162# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1163# undef getdtablesize
1164# define getdtablesize rpl_getdtablesize
1165# endif
1166_GL_FUNCDECL_RPL (getdtablesize, int, (void));
1167_GL_CXXALIAS_RPL (getdtablesize, int, (void));
1168# else
1169# if !@HAVE_GETDTABLESIZE@
655_GL_FUNCDECL_SYS (getdtablesize, int, (void)); 1170_GL_FUNCDECL_SYS (getdtablesize, int, (void));
1171# endif
1172/* Need to cast, because on AIX, the parameter list is
1173 (...). */
1174_GL_CXXALIAS_SYS_CAST (getdtablesize, int, (void));
656# endif 1175# endif
657_GL_CXXALIAS_SYS (getdtablesize, int, (void));
658_GL_CXXALIASWARN (getdtablesize); 1176_GL_CXXALIASWARN (getdtablesize);
659#elif defined GNULIB_POSIXCHECK 1177#elif defined GNULIB_POSIXCHECK
660# undef getdtablesize 1178# undef getdtablesize
@@ -665,6 +1183,22 @@ _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
665#endif 1183#endif
666 1184
667 1185
1186#if @GNULIB_GETENTROPY@
1187/* Fill a buffer with random bytes. */
1188# if !@HAVE_GETENTROPY@
1189_GL_FUNCDECL_SYS (getentropy, int, (void *buffer, size_t length));
1190# endif
1191_GL_CXXALIAS_SYS (getentropy, int, (void *buffer, size_t length));
1192_GL_CXXALIASWARN (getentropy);
1193#elif defined GNULIB_POSIXCHECK
1194# undef getentropy
1195# if HAVE_RAW_DECL_GETENTROPY
1196_GL_WARN_ON_USE (getentropy, "getentropy is unportable - "
1197 "use gnulib module getentropy for portability");
1198# endif
1199#endif
1200
1201
668#if @GNULIB_GETGROUPS@ 1202#if @GNULIB_GETGROUPS@
669/* Return the supplemental groups that the current process belongs to. 1203/* Return the supplemental groups that the current process belongs to.
670 It is unspecified whether the effective group id is in the list. 1204 It is unspecified whether the effective group id is in the list.
@@ -737,14 +1271,14 @@ _GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
737/* Returns the user's login name, or NULL if it cannot be found. Upon error, 1271/* Returns the user's login name, or NULL if it cannot be found. Upon error,
738 returns NULL with errno set. 1272 returns NULL with errno set.
739 1273
740 See <http://www.opengroup.org/susv3xsh/getlogin.html>. 1274 See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html>.
741 1275
742 Most programs don't need to use this function, because the information is 1276 Most programs don't need to use this function, because the information is
743 available through environment variables: 1277 available through environment variables:
744 ${LOGNAME-$USER} on Unix platforms, 1278 ${LOGNAME-$USER} on Unix platforms,
745 $USERNAME on native Windows platforms. 1279 $USERNAME on native Windows platforms.
746 */ 1280 */
747# if !@HAVE_GETLOGIN@ 1281# if !@HAVE_DECL_GETLOGIN@
748_GL_FUNCDECL_SYS (getlogin, char *, (void)); 1282_GL_FUNCDECL_SYS (getlogin, char *, (void));
749# endif 1283# endif
750_GL_CXXALIAS_SYS (getlogin, char *, (void)); 1284_GL_CXXALIAS_SYS (getlogin, char *, (void));
@@ -766,7 +1300,7 @@ _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
766 the case that the login name cannot be found but no specific error is 1300 the case that the login name cannot be found but no specific error is
767 provided (this case is hopefully rare but is left open by the POSIX spec). 1301 provided (this case is hopefully rare but is left open by the POSIX spec).
768 1302
769 See <http://www.opengroup.org/susv3xsh/getlogin.html>. 1303 See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html>.
770 1304
771 Most programs don't need to use this function, because the information is 1305 Most programs don't need to use this function, because the information is
772 available through environment variables: 1306 available through environment variables:
@@ -807,6 +1341,11 @@ _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
807_GL_FUNCDECL_RPL (getpagesize, int, (void)); 1341_GL_FUNCDECL_RPL (getpagesize, int, (void));
808_GL_CXXALIAS_RPL (getpagesize, int, (void)); 1342_GL_CXXALIAS_RPL (getpagesize, int, (void));
809# else 1343# else
1344/* On HP-UX, getpagesize exists, but it is not declared in <unistd.h> even if
1345 the compiler options -D_HPUX_SOURCE -D_XOPEN_SOURCE=600 are used. */
1346# if defined __hpux
1347_GL_FUNCDECL_SYS (getpagesize, int, (void));
1348# endif
810# if !@HAVE_GETPAGESIZE@ 1349# if !@HAVE_GETPAGESIZE@
811# if !defined getpagesize 1350# if !defined getpagesize
812/* This is for POSIX systems. */ 1351/* This is for POSIX systems. */
@@ -881,6 +1420,54 @@ _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
881#endif 1420#endif
882 1421
883 1422
1423#if @GNULIB_GETPASS@
1424/* Function getpass() from module 'getpass':
1425 Read a password from /dev/tty or stdin.
1426 Function getpass() from module 'getpass-gnu':
1427 Read a password of arbitrary length from /dev/tty or stdin. */
1428# if (@GNULIB_GETPASS@ && @REPLACE_GETPASS@) \
1429 || (@GNULIB_GETPASS_GNU@ && @REPLACE_GETPASS_FOR_GETPASS_GNU@)
1430# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1431# undef getpass
1432# define getpass rpl_getpass
1433# endif
1434_GL_FUNCDECL_RPL (getpass, char *, (const char *prompt)
1435 _GL_ARG_NONNULL ((1)));
1436_GL_CXXALIAS_RPL (getpass, char *, (const char *prompt));
1437# else
1438# if !@HAVE_GETPASS@
1439_GL_FUNCDECL_SYS (getpass, char *, (const char *prompt)
1440 _GL_ARG_NONNULL ((1)));
1441# endif
1442_GL_CXXALIAS_SYS (getpass, char *, (const char *prompt));
1443# endif
1444_GL_CXXALIASWARN (getpass);
1445#elif defined GNULIB_POSIXCHECK
1446# undef getpass
1447# if HAVE_RAW_DECL_GETPASS
1448_GL_WARN_ON_USE (getpass, "getpass is unportable - "
1449 "use gnulib module getpass or getpass-gnu for portability");
1450# endif
1451#endif
1452
1453
1454#if @GNULIB_MDA_GETPID@
1455/* On native Windows, map 'getpid' to '_getpid', so that -loldnames is not
1456 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1457 platforms by defining GNULIB_NAMESPACE::getpid always. */
1458# if defined _WIN32 && !defined __CYGWIN__
1459# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1460# undef getpid
1461# define getpid _getpid
1462# endif
1463_GL_CXXALIAS_MDA (getpid, int, (void));
1464# else
1465_GL_CXXALIAS_SYS (getpid, pid_t, (void));
1466# endif
1467_GL_CXXALIASWARN (getpid);
1468#endif
1469
1470
884#if @GNULIB_GETUSERSHELL@ 1471#if @GNULIB_GETUSERSHELL@
885/* Return the next valid login shell on the system, or NULL when the end of 1472/* Return the next valid login shell on the system, or NULL when the end of
886 the list has been reached. */ 1473 the list has been reached. */
@@ -951,8 +1538,15 @@ _GL_WARN_ON_USE (group_member, "group_member is unportable - "
951# undef isatty 1538# undef isatty
952# define isatty rpl_isatty 1539# define isatty rpl_isatty
953# endif 1540# endif
1541# define GNULIB_defined_isatty 1
954_GL_FUNCDECL_RPL (isatty, int, (int fd)); 1542_GL_FUNCDECL_RPL (isatty, int, (int fd));
955_GL_CXXALIAS_RPL (isatty, int, (int fd)); 1543_GL_CXXALIAS_RPL (isatty, int, (int fd));
1544# elif defined _WIN32 && !defined __CYGWIN__
1545# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1546# undef isatty
1547# define isatty _isatty
1548# endif
1549_GL_CXXALIAS_MDA (isatty, int, (int fd));
956# else 1550# else
957_GL_CXXALIAS_SYS (isatty, int, (int fd)); 1551_GL_CXXALIAS_SYS (isatty, int, (int fd));
958# endif 1552# endif
@@ -963,6 +1557,20 @@ _GL_CXXALIASWARN (isatty);
963_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - " 1557_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - "
964 "use gnulib module isatty for portability"); 1558 "use gnulib module isatty for portability");
965# endif 1559# endif
1560#elif @GNULIB_MDA_ISATTY@
1561/* On native Windows, map 'isatty' to '_isatty', so that -loldnames is not
1562 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1563 platforms by defining GNULIB_NAMESPACE::isatty always. */
1564# if defined _WIN32 && !defined __CYGWIN__
1565# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1566# undef isatty
1567# define isatty _isatty
1568# endif
1569_GL_CXXALIAS_MDA (isatty, int, (int fd));
1570# else
1571_GL_CXXALIAS_SYS (isatty, int, (int fd));
1572# endif
1573_GL_CXXALIASWARN (isatty);
966#endif 1574#endif
967 1575
968 1576
@@ -971,7 +1579,7 @@ _GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - "
971 to GID (if GID is not -1). Do not follow symbolic links. 1579 to GID (if GID is not -1). Do not follow symbolic links.
972 Return 0 if successful, otherwise -1 and errno set. 1580 Return 0 if successful, otherwise -1 and errno set.
973 See the POSIX:2008 specification 1581 See the POSIX:2008 specification
974 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */ 1582 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */
975# if @REPLACE_LCHOWN@ 1583# if @REPLACE_LCHOWN@
976# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1584# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
977# undef lchown 1585# undef lchown
@@ -1001,7 +1609,7 @@ _GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
1001/* Create a new hard link for an existing file. 1609/* Create a new hard link for an existing file.
1002 Return 0 if successful, otherwise -1 and errno set. 1610 Return 0 if successful, otherwise -1 and errno set.
1003 See POSIX:2008 specification 1611 See POSIX:2008 specification
1004 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */ 1612 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */
1005# if @REPLACE_LINK@ 1613# if @REPLACE_LINK@
1006# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1614# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1007# define link rpl_link 1615# define link rpl_link
@@ -1067,13 +1675,19 @@ _GL_WARN_ON_USE (linkat, "linkat is unportable - "
1067/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. 1675/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
1068 Return the new offset if successful, otherwise -1 and errno set. 1676 Return the new offset if successful, otherwise -1 and errno set.
1069 See the POSIX:2008 specification 1677 See the POSIX:2008 specification
1070 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */ 1678 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */
1071# if @REPLACE_LSEEK@ 1679# if @REPLACE_LSEEK@
1072# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1680# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1073# define lseek rpl_lseek 1681# define lseek rpl_lseek
1074# endif 1682# endif
1075_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence)); 1683_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
1076_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence)); 1684_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
1685# elif defined _WIN32 && !defined __CYGWIN__
1686# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1687# undef lseek
1688# define lseek _lseek
1689# endif
1690_GL_CXXALIAS_MDA (lseek, off_t, (int fd, off_t offset, int whence));
1077# else 1691# else
1078_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence)); 1692_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
1079# endif 1693# endif
@@ -1084,6 +1698,20 @@ _GL_CXXALIASWARN (lseek);
1084_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some " 1698_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
1085 "systems - use gnulib module lseek for portability"); 1699 "systems - use gnulib module lseek for portability");
1086# endif 1700# endif
1701#elif @GNULIB_MDA_LSEEK@
1702/* On native Windows, map 'lseek' to '_lseek', so that -loldnames is not
1703 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1704 platforms by defining GNULIB_NAMESPACE::lseek always. */
1705# if defined _WIN32 && !defined __CYGWIN__
1706# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1707# undef lseek
1708# define lseek _lseek
1709# endif
1710_GL_CXXALIAS_MDA (lseek, long, (int fd, long offset, int whence));
1711# else
1712_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
1713# endif
1714_GL_CXXALIASWARN (lseek);
1087#endif 1715#endif
1088 1716
1089 1717
@@ -1113,7 +1741,7 @@ _GL_WARN_ON_USE (pipe, "pipe is unportable - "
1113 Store the read-end as fd[0] and the write-end as fd[1]. 1741 Store the read-end as fd[0] and the write-end as fd[1].
1114 Return 0 upon success, or -1 with errno set upon failure. 1742 Return 0 upon success, or -1 with errno set upon failure.
1115 See also the Linux man page at 1743 See also the Linux man page at
1116 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */ 1744 <https://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
1117# if @HAVE_PIPE2@ 1745# if @HAVE_PIPE2@
1118# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1746# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1119# define pipe2 rpl_pipe2 1747# define pipe2 rpl_pipe2
@@ -1139,7 +1767,7 @@ _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
1139 Return the number of bytes placed into BUF if successful, otherwise 1767 Return the number of bytes placed into BUF if successful, otherwise
1140 set errno and return -1. 0 indicates EOF. 1768 set errno and return -1. 0 indicates EOF.
1141 See the POSIX:2008 specification 1769 See the POSIX:2008 specification
1142 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */ 1770 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */
1143# if @REPLACE_PREAD@ 1771# if @REPLACE_PREAD@
1144# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1772# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1145# undef pread 1773# undef pread
@@ -1174,7 +1802,7 @@ _GL_WARN_ON_USE (pread, "pread is unportable - "
1174 Return the number of bytes written if successful, otherwise 1802 Return the number of bytes written if successful, otherwise
1175 set errno and return -1. 0 indicates nothing written. See the 1803 set errno and return -1. 0 indicates nothing written. See the
1176 POSIX:2008 specification 1804 POSIX:2008 specification
1177 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */ 1805 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */
1178# if @REPLACE_PWRITE@ 1806# if @REPLACE_PWRITE@
1179# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1807# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1180# undef pwrite 1808# undef pwrite
@@ -1207,7 +1835,7 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1207#if @GNULIB_READ@ 1835#if @GNULIB_READ@
1208/* Read up to COUNT bytes from file descriptor FD into the buffer starting 1836/* Read up to COUNT bytes from file descriptor FD into the buffer starting
1209 at BUF. See the POSIX:2008 specification 1837 at BUF. See the POSIX:2008 specification
1210 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */ 1838 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */
1211# if @REPLACE_READ@ 1839# if @REPLACE_READ@
1212# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1840# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1213# undef read 1841# undef read
@@ -1216,11 +1844,32 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1216_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count) 1844_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count)
1217 _GL_ARG_NONNULL ((2))); 1845 _GL_ARG_NONNULL ((2)));
1218_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count)); 1846_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
1847# elif defined _WIN32 && !defined __CYGWIN__
1848# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1849# undef read
1850# define read _read
1851# endif
1852_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, size_t count));
1853# else
1854_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count));
1855# endif
1856_GL_CXXALIASWARN (read);
1857#elif @GNULIB_MDA_READ@
1858/* On native Windows, map 'read' to '_read', so that -loldnames is not
1859 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1860 platforms by defining GNULIB_NAMESPACE::read always. */
1861# if defined _WIN32 && !defined __CYGWIN__
1862# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1863# undef read
1864# define read _read
1865# endif
1866# ifdef __MINGW32__
1867_GL_CXXALIAS_MDA (read, int, (int fd, void *buf, unsigned int count));
1868# else
1869_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, unsigned int count));
1870# endif
1219# else 1871# else
1220/* Need to cast, because on mingw, the third parameter is 1872_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count));
1221 unsigned int count
1222 and the return type is 'int'. */
1223_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count));
1224# endif 1873# endif
1225_GL_CXXALIASWARN (read); 1874_GL_CXXALIASWARN (read);
1226#endif 1875#endif
@@ -1231,24 +1880,28 @@ _GL_CXXALIASWARN (read);
1231 bytes of it into BUF. Return the number of bytes placed into BUF if 1880 bytes of it into BUF. Return the number of bytes placed into BUF if
1232 successful, otherwise -1 and errno set. 1881 successful, otherwise -1 and errno set.
1233 See the POSIX:2008 specification 1882 See the POSIX:2008 specification
1234 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */ 1883 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */
1235# if @REPLACE_READLINK@ 1884# if @REPLACE_READLINK@
1236# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1885# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1237# define readlink rpl_readlink 1886# define readlink rpl_readlink
1238# endif 1887# endif
1239_GL_FUNCDECL_RPL (readlink, ssize_t, 1888_GL_FUNCDECL_RPL (readlink, ssize_t,
1240 (const char *file, char *buf, size_t bufsize) 1889 (const char *restrict file,
1890 char *restrict buf, size_t bufsize)
1241 _GL_ARG_NONNULL ((1, 2))); 1891 _GL_ARG_NONNULL ((1, 2)));
1242_GL_CXXALIAS_RPL (readlink, ssize_t, 1892_GL_CXXALIAS_RPL (readlink, ssize_t,
1243 (const char *file, char *buf, size_t bufsize)); 1893 (const char *restrict file,
1894 char *restrict buf, size_t bufsize));
1244# else 1895# else
1245# if !@HAVE_READLINK@ 1896# if !@HAVE_READLINK@
1246_GL_FUNCDECL_SYS (readlink, ssize_t, 1897_GL_FUNCDECL_SYS (readlink, ssize_t,
1247 (const char *file, char *buf, size_t bufsize) 1898 (const char *restrict file,
1899 char *restrict buf, size_t bufsize)
1248 _GL_ARG_NONNULL ((1, 2))); 1900 _GL_ARG_NONNULL ((1, 2)));
1249# endif 1901# endif
1250_GL_CXXALIAS_SYS (readlink, ssize_t, 1902_GL_CXXALIAS_SYS (readlink, ssize_t,
1251 (const char *file, char *buf, size_t bufsize)); 1903 (const char *restrict file,
1904 char *restrict buf, size_t bufsize));
1252# endif 1905# endif
1253_GL_CXXALIASWARN (readlink); 1906_GL_CXXALIASWARN (readlink);
1254#elif defined GNULIB_POSIXCHECK 1907#elif defined GNULIB_POSIXCHECK
@@ -1261,13 +1914,28 @@ _GL_WARN_ON_USE (readlink, "readlink is unportable - "
1261 1914
1262 1915
1263#if @GNULIB_READLINKAT@ 1916#if @GNULIB_READLINKAT@
1264# if !@HAVE_READLINKAT@ 1917# if @REPLACE_READLINKAT@
1918# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1919# define readlinkat rpl_readlinkat
1920# endif
1921_GL_FUNCDECL_RPL (readlinkat, ssize_t,
1922 (int fd, char const *restrict file,
1923 char *restrict buf, size_t len)
1924 _GL_ARG_NONNULL ((2, 3)));
1925_GL_CXXALIAS_RPL (readlinkat, ssize_t,
1926 (int fd, char const *restrict file,
1927 char *restrict buf, size_t len));
1928# else
1929# if !@HAVE_READLINKAT@
1265_GL_FUNCDECL_SYS (readlinkat, ssize_t, 1930_GL_FUNCDECL_SYS (readlinkat, ssize_t,
1266 (int fd, char const *file, char *buf, size_t len) 1931 (int fd, char const *restrict file,
1932 char *restrict buf, size_t len)
1267 _GL_ARG_NONNULL ((2, 3))); 1933 _GL_ARG_NONNULL ((2, 3)));
1268# endif 1934# endif
1269_GL_CXXALIAS_SYS (readlinkat, ssize_t, 1935_GL_CXXALIAS_SYS (readlinkat, ssize_t,
1270 (int fd, char const *file, char *buf, size_t len)); 1936 (int fd, char const *restrict file,
1937 char *restrict buf, size_t len));
1938# endif
1271_GL_CXXALIASWARN (readlinkat); 1939_GL_CXXALIASWARN (readlinkat);
1272#elif defined GNULIB_POSIXCHECK 1940#elif defined GNULIB_POSIXCHECK
1273# undef readlinkat 1941# undef readlinkat
@@ -1286,6 +1954,12 @@ _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1286# endif 1954# endif
1287_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1))); 1955_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1288_GL_CXXALIAS_RPL (rmdir, int, (char const *name)); 1956_GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1957# elif defined _WIN32 && !defined __CYGWIN__
1958# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1959# undef rmdir
1960# define rmdir _rmdir
1961# endif
1962_GL_CXXALIAS_MDA (rmdir, int, (char const *name));
1289# else 1963# else
1290_GL_CXXALIAS_SYS (rmdir, int, (char const *name)); 1964_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1291# endif 1965# endif
@@ -1296,6 +1970,20 @@ _GL_CXXALIASWARN (rmdir);
1296_GL_WARN_ON_USE (rmdir, "rmdir is unportable - " 1970_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1297 "use gnulib module rmdir for portability"); 1971 "use gnulib module rmdir for portability");
1298# endif 1972# endif
1973#elif @GNULIB_MDA_RMDIR@
1974/* On native Windows, map 'rmdir' to '_rmdir', so that -loldnames is not
1975 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1976 platforms by defining GNULIB_NAMESPACE::rmdir always. */
1977# if defined _WIN32 && !defined __CYGWIN__
1978# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1979# undef rmdir
1980# define rmdir _rmdir
1981# endif
1982_GL_CXXALIAS_MDA (rmdir, int, (char const *name));
1983# else
1984_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1985# endif
1986_GL_CXXALIASWARN (rmdir);
1299#endif 1987#endif
1300 1988
1301 1989
@@ -1330,7 +2018,7 @@ _GL_WARN_ON_USE (sethostname, "sethostname is unportable - "
1330/* Pause the execution of the current thread for N seconds. 2018/* Pause the execution of the current thread for N seconds.
1331 Returns the number of seconds left to sleep. 2019 Returns the number of seconds left to sleep.
1332 See the POSIX:2008 specification 2020 See the POSIX:2008 specification
1333 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */ 2021 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */
1334# if @REPLACE_SLEEP@ 2022# if @REPLACE_SLEEP@
1335# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2023# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1336# undef sleep 2024# undef sleep
@@ -1354,6 +2042,31 @@ _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1354#endif 2042#endif
1355 2043
1356 2044
2045#if @GNULIB_MDA_SWAB@
2046/* On native Windows, map 'swab' to '_swab', so that -loldnames is not
2047 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2048 platforms by defining GNULIB_NAMESPACE::swab always. */
2049# if defined _WIN32 && !defined __CYGWIN__
2050# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2051# undef swab
2052# define swab _swab
2053# endif
2054/* Need to cast, because in old mingw the arguments are
2055 (const char *from, char *to, size_t n). */
2056_GL_CXXALIAS_MDA_CAST (swab, void, (char *from, char *to, int n));
2057# else
2058# if defined __hpux /* HP-UX */
2059_GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, int n));
2060# elif defined __sun && (defined __SunOS_5_10 || defined __XOPEN_OR_POSIX) && !defined _XPG4 /* Solaris */
2061_GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, ssize_t n));
2062# else
2063_GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n));
2064# endif
2065# endif
2066_GL_CXXALIASWARN (swab);
2067#endif
2068
2069
1357#if @GNULIB_SYMLINK@ 2070#if @GNULIB_SYMLINK@
1358# if @REPLACE_SYMLINK@ 2071# if @REPLACE_SYMLINK@
1359# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2072# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -1381,13 +2094,25 @@ _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1381 2094
1382 2095
1383#if @GNULIB_SYMLINKAT@ 2096#if @GNULIB_SYMLINKAT@
1384# if !@HAVE_SYMLINKAT@ 2097# if @REPLACE_SYMLINKAT@
2098# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2099# undef symlinkat
2100# define symlinkat rpl_symlinkat
2101# endif
2102_GL_FUNCDECL_RPL (symlinkat, int,
2103 (char const *contents, int fd, char const *file)
2104 _GL_ARG_NONNULL ((1, 3)));
2105_GL_CXXALIAS_RPL (symlinkat, int,
2106 (char const *contents, int fd, char const *file));
2107# else
2108# if !@HAVE_SYMLINKAT@
1385_GL_FUNCDECL_SYS (symlinkat, int, 2109_GL_FUNCDECL_SYS (symlinkat, int,
1386 (char const *contents, int fd, char const *file) 2110 (char const *contents, int fd, char const *file)
1387 _GL_ARG_NONNULL ((1, 3))); 2111 _GL_ARG_NONNULL ((1, 3)));
1388# endif 2112# endif
1389_GL_CXXALIAS_SYS (symlinkat, int, 2113_GL_CXXALIAS_SYS (symlinkat, int,
1390 (char const *contents, int fd, char const *file)); 2114 (char const *contents, int fd, char const *file));
2115# endif
1391_GL_CXXALIASWARN (symlinkat); 2116_GL_CXXALIASWARN (symlinkat);
1392#elif defined GNULIB_POSIXCHECK 2117#elif defined GNULIB_POSIXCHECK
1393# undef symlinkat 2118# undef symlinkat
@@ -1398,6 +2123,36 @@ _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1398#endif 2123#endif
1399 2124
1400 2125
2126#if @GNULIB_TRUNCATE@
2127/* Change the size of the file designated by FILENAME to become equal to LENGTH.
2128 Return 0 if successful, otherwise -1 and errno set.
2129 See the POSIX:2008 specification
2130 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html>. */
2131# if @REPLACE_TRUNCATE@
2132# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2133# undef truncate
2134# define truncate rpl_truncate
2135# endif
2136_GL_FUNCDECL_RPL (truncate, int, (const char *filename, off_t length)
2137 _GL_ARG_NONNULL ((1)));
2138_GL_CXXALIAS_RPL (truncate, int, (const char *filename, off_t length));
2139# else
2140# if !@HAVE_DECL_TRUNCATE@
2141_GL_FUNCDECL_SYS (truncate, int, (const char *filename, off_t length)
2142 _GL_ARG_NONNULL ((1)));
2143# endif
2144_GL_CXXALIAS_SYS (truncate, int, (const char *filename, off_t length));
2145# endif
2146_GL_CXXALIASWARN (truncate);
2147#elif defined GNULIB_POSIXCHECK
2148# undef truncate
2149# if HAVE_RAW_DECL_TRUNCATE
2150_GL_WARN_ON_USE (truncate, "truncate is unportable - "
2151 "use gnulib module truncate for portability");
2152# endif
2153#endif
2154
2155
1401#if @GNULIB_TTYNAME_R@ 2156#if @GNULIB_TTYNAME_R@
1402/* Store at most BUFLEN characters of the pathname of the terminal FD is 2157/* Store at most BUFLEN characters of the pathname of the terminal FD is
1403 open on in BUF. Return 0 on success, otherwise an error number. */ 2158 open on in BUF. Return 0 on success, otherwise an error number. */
@@ -1436,6 +2191,12 @@ _GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1436# endif 2191# endif
1437_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1))); 2192_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1438_GL_CXXALIAS_RPL (unlink, int, (char const *file)); 2193_GL_CXXALIAS_RPL (unlink, int, (char const *file));
2194# elif defined _WIN32 && !defined __CYGWIN__
2195# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2196# undef unlink
2197# define unlink _unlink
2198# endif
2199_GL_CXXALIAS_MDA (unlink, int, (char const *file));
1439# else 2200# else
1440_GL_CXXALIAS_SYS (unlink, int, (char const *file)); 2201_GL_CXXALIAS_SYS (unlink, int, (char const *file));
1441# endif 2202# endif
@@ -1446,6 +2207,20 @@ _GL_CXXALIASWARN (unlink);
1446_GL_WARN_ON_USE (unlink, "unlink is not portable - " 2207_GL_WARN_ON_USE (unlink, "unlink is not portable - "
1447 "use gnulib module unlink for portability"); 2208 "use gnulib module unlink for portability");
1448# endif 2209# endif
2210#elif @GNULIB_MDA_UNLINK@
2211/* On native Windows, map 'unlink' to '_unlink', so that -loldnames is not
2212 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2213 platforms by defining GNULIB_NAMESPACE::unlink always. */
2214# if defined _WIN32 && !defined __CYGWIN__
2215# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2216# undef unlink
2217# define unlink _unlink
2218# endif
2219_GL_CXXALIAS_MDA (unlink, int, (char const *file));
2220# else
2221_GL_CXXALIAS_SYS (unlink, int, (char const *file));
2222# endif
2223_GL_CXXALIASWARN (unlink);
1449#endif 2224#endif
1450 2225
1451 2226
@@ -1470,7 +2245,7 @@ _GL_CXXALIASWARN (unlinkat);
1470# undef unlinkat 2245# undef unlinkat
1471# if HAVE_RAW_DECL_UNLINKAT 2246# if HAVE_RAW_DECL_UNLINKAT
1472_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - " 2247_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1473 "use gnulib module openat for portability"); 2248 "use gnulib module unlinkat for portability");
1474# endif 2249# endif
1475#endif 2250#endif
1476 2251
@@ -1479,7 +2254,7 @@ _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1479/* Pause the execution of the current thread for N microseconds. 2254/* Pause the execution of the current thread for N microseconds.
1480 Returns 0 on completion, or -1 on range error. 2255 Returns 0 on completion, or -1 on range error.
1481 See the POSIX:2001 specification 2256 See the POSIX:2001 specification
1482 <http://www.opengroup.org/susv3xsh/usleep.html>. */ 2257 <https://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html>. */
1483# if @REPLACE_USLEEP@ 2258# if @REPLACE_USLEEP@
1484# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2259# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1485# undef usleep 2260# undef usleep
@@ -1491,7 +2266,9 @@ _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1491# if !@HAVE_USLEEP@ 2266# if !@HAVE_USLEEP@
1492_GL_FUNCDECL_SYS (usleep, int, (useconds_t n)); 2267_GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1493# endif 2268# endif
1494_GL_CXXALIAS_SYS (usleep, int, (useconds_t n)); 2269/* Need to cast, because on Haiku, the first parameter is
2270 unsigned int n. */
2271_GL_CXXALIAS_SYS_CAST (usleep, int, (useconds_t n));
1495# endif 2272# endif
1496_GL_CXXALIASWARN (usleep); 2273_GL_CXXALIASWARN (usleep);
1497#elif defined GNULIB_POSIXCHECK 2274#elif defined GNULIB_POSIXCHECK
@@ -1506,7 +2283,7 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1506#if @GNULIB_WRITE@ 2283#if @GNULIB_WRITE@
1507/* Write up to COUNT bytes starting at BUF to file descriptor FD. 2284/* Write up to COUNT bytes starting at BUF to file descriptor FD.
1508 See the POSIX:2008 specification 2285 See the POSIX:2008 specification
1509 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */ 2286 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */
1510# if @REPLACE_WRITE@ 2287# if @REPLACE_WRITE@
1511# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2288# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1512# undef write 2289# undef write
@@ -1515,11 +2292,32 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1515_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count) 2292_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1516 _GL_ARG_NONNULL ((2))); 2293 _GL_ARG_NONNULL ((2)));
1517_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); 2294_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
2295# elif defined _WIN32 && !defined __CYGWIN__
2296# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2297# undef write
2298# define write _write
2299# endif
2300_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, size_t count));
2301# else
2302_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
2303# endif
2304_GL_CXXALIASWARN (write);
2305#elif @GNULIB_MDA_WRITE@
2306/* On native Windows, map 'write' to '_write', so that -loldnames is not
2307 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2308 platforms by defining GNULIB_NAMESPACE::write always. */
2309# if defined _WIN32 && !defined __CYGWIN__
2310# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2311# undef write
2312# define write _write
2313# endif
2314# ifdef __MINGW32__
2315_GL_CXXALIAS_MDA (write, int, (int fd, const void *buf, unsigned int count));
2316# else
2317_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, unsigned int count));
2318# endif
1518# else 2319# else
1519/* Need to cast, because on mingw, the third parameter is 2320_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1520 unsigned int count
1521 and the return type is 'int'. */
1522_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
1523# endif 2321# endif
1524_GL_CXXALIASWARN (write); 2322_GL_CXXALIASWARN (write);
1525#endif 2323#endif
@@ -1527,4 +2325,5 @@ _GL_CXXALIASWARN (write);
1527_GL_INLINE_HEADER_END 2325_GL_INLINE_HEADER_END
1528 2326
1529#endif /* _@GUARD_PREFIX@_UNISTD_H */ 2327#endif /* _@GUARD_PREFIX@_UNISTD_H */
2328#endif /* _GL_INCLUDING_UNISTD_H */
1530#endif /* _@GUARD_PREFIX@_UNISTD_H */ 2329#endif /* _@GUARD_PREFIX@_UNISTD_H */
diff --git a/gl/unlocked-io.h b/gl/unlocked-io.h
new file mode 100644
index 0000000..fdef624
--- /dev/null
+++ b/gl/unlocked-io.h
@@ -0,0 +1,136 @@
1/* Prefer faster, non-thread-safe stdio functions if available.
2
3 Copyright (C) 2001-2004, 2009-2023 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 <https://www.gnu.org/licenses/>. */
17
18/* Written by Jim Meyering. */
19
20#ifndef UNLOCKED_IO_H
21# define UNLOCKED_IO_H 1
22
23/* These are wrappers for functions/macros from the GNU C library, and
24 from other C libraries supporting POSIX's optional thread-safe functions.
25
26 The standard I/O functions are thread-safe. These *_unlocked ones are
27 more efficient but not thread-safe. That they're not thread-safe is
28 fine since all of the applications in this package are single threaded.
29
30 Also, some code that is shared with the GNU C library may invoke
31 the *_unlocked functions directly. On hosts that lack those
32 functions, invoke the non-thread-safe versions instead. */
33
34# include <stdio.h>
35
36# if HAVE_DECL_CLEARERR_UNLOCKED || defined clearerr_unlocked
37# undef clearerr
38# define clearerr(x) clearerr_unlocked (x)
39# else
40# define clearerr_unlocked(x) clearerr (x)
41# endif
42
43# if HAVE_DECL_FEOF_UNLOCKED || defined feof_unlocked
44# undef feof
45# define feof(x) feof_unlocked (x)
46# else
47# define feof_unlocked(x) feof (x)
48# endif
49
50# if HAVE_DECL_FERROR_UNLOCKED || defined ferror_unlocked
51# undef ferror
52# define ferror(x) ferror_unlocked (x)
53# else
54# define ferror_unlocked(x) ferror (x)
55# endif
56
57# if HAVE_DECL_FFLUSH_UNLOCKED || defined fflush_unlocked
58# undef fflush
59# define fflush(x) fflush_unlocked (x)
60# else
61# define fflush_unlocked(x) fflush (x)
62# endif
63
64# if HAVE_DECL_FGETS_UNLOCKED || defined fgets_unlocked
65# undef fgets
66# define fgets(x,y,z) fgets_unlocked (x,y,z)
67# else
68# define fgets_unlocked(x,y,z) fgets (x,y,z)
69# endif
70
71# if HAVE_DECL_FPUTC_UNLOCKED || defined fputc_unlocked
72# undef fputc
73# define fputc(x,y) fputc_unlocked (x,y)
74# else
75# define fputc_unlocked(x,y) fputc (x,y)
76# endif
77
78# if HAVE_DECL_FPUTS_UNLOCKED || defined fputs_unlocked
79# undef fputs
80# define fputs(x,y) fputs_unlocked (x,y)
81# else
82# define fputs_unlocked(x,y) fputs (x,y)
83# endif
84
85# if HAVE_DECL_FREAD_UNLOCKED || defined fread_unlocked
86# undef fread
87# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
88# else
89# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
90# endif
91
92# if HAVE_DECL_FWRITE_UNLOCKED || defined fwrite_unlocked
93# undef fwrite
94# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
95# else
96# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
97# endif
98
99# if HAVE_DECL_GETC_UNLOCKED || defined get_unlocked
100# undef getc
101# define getc(x) getc_unlocked (x)
102# else
103# define getc_unlocked(x) getc (x)
104# endif
105
106# if HAVE_DECL_GETCHAR_UNLOCKED || defined getchar_unlocked
107# undef getchar
108# define getchar() getchar_unlocked ()
109# else
110# define getchar_unlocked() getchar ()
111# endif
112
113# if HAVE_DECL_PUTC_UNLOCKED || defined putc_unlocked
114# undef putc
115# define putc(x,y) putc_unlocked (x,y)
116# else
117# define putc_unlocked(x,y) putc (x,y)
118# endif
119
120# if HAVE_DECL_PUTCHAR_UNLOCKED || defined putchar_unlocked
121# undef putchar
122# define putchar(x) putchar_unlocked (x)
123# else
124# define putchar_unlocked(x) putchar (x)
125# endif
126
127# undef flockfile
128# define flockfile(x) ((void) 0)
129
130# undef ftrylockfile
131# define ftrylockfile(x) 0
132
133# undef funlockfile
134# define funlockfile(x) ((void) 0)
135
136#endif /* UNLOCKED_IO_H */
diff --git a/gl/unsetenv.c b/gl/unsetenv.c
index c58c82f..e548949 100644
--- a/gl/unsetenv.c
+++ b/gl/unsetenv.c
@@ -1,18 +1,18 @@
1/* Copyright (C) 1992, 1995-2002, 2005-2013 Free Software Foundation, Inc. 1/* Copyright (C) 1992, 1995-2002, 2005-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library. 2 This file is part of the GNU C Library.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3 of the License, or 6 published by the Free Software Foundation; either version 2.1 of the
7 (at your option) any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser 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 Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc 17/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
18 optimizes away the name == NULL test below. */ 18 optimizes away the name == NULL test below. */
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 5267b1b..277c39e 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -1,18 +1,18 @@
1/* vsprintf with automatic memory allocation. 1/* vsprintf with automatic memory allocation.
2 Copyright (C) 1999, 2002-2013 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17/* This file can be parametrized with the following macros: 17/* This file can be parametrized with the following macros:
18 VASNPRINTF The name of the function being defined. 18 VASNPRINTF The name of the function being defined.
@@ -41,7 +41,14 @@
41 DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[]. 41 DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[].
42 DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t. 42 DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t.
43 DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t. 43 DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t.
44 DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */ 44 DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t.
45 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
46 ENABLE_WCHAR_FALLBACK Set to 1 to avoid EILSEQ during conversion of wide
47 characters (wchar_t) and wide character strings
48 (wchar_t[]) to multibyte sequences. The fallback is the
49 hexadecimal escape syntax (\unnnn or \Unnnnnnnn) or,
50 if wchar_t is not Unicode encoded, \wnnnn or \Wnnnnnnnn.
51 */
45 52
46/* Tell glibc's <stdio.h> to provide a prototype for snprintf(). 53/* Tell glibc's <stdio.h> to provide a prototype for snprintf().
47 This must come before <config.h> because <config.h> may include 54 This must come before <config.h> because <config.h> may include
@@ -53,10 +60,16 @@
53#ifndef VASNPRINTF 60#ifndef VASNPRINTF
54# include <config.h> 61# include <config.h>
55#endif 62#endif
56#ifndef IN_LIBINTL 63
57# include <alloca.h> 64/* As of GCC 11.2.1, gcc -Wanalyzer-too-complex reports that main's
65 use of CHECK macros expands to code that is too complicated for gcc
66 -fanalyzer. Suppress the resulting bogus warnings. */
67#if 10 <= __GNUC__
68# pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
58#endif 69#endif
59 70
71#include <alloca.h>
72
60/* Specification. */ 73/* Specification. */
61#ifndef VASNPRINTF 74#ifndef VASNPRINTF
62# if WIDE_CHAR_VERSION 75# if WIDE_CHAR_VERSION
@@ -70,6 +83,7 @@
70#include <stdio.h> /* snprintf(), sprintf() */ 83#include <stdio.h> /* snprintf(), sprintf() */
71#include <stdlib.h> /* abort(), malloc(), realloc(), free() */ 84#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
72#include <string.h> /* memcpy(), strlen() */ 85#include <string.h> /* memcpy(), strlen() */
86#include <wchar.h> /* mbstate_t, mbrtowc(), mbrlen(), wcrtomb() */
73#include <errno.h> /* errno */ 87#include <errno.h> /* errno */
74#include <limits.h> /* CHAR_BIT */ 88#include <limits.h> /* CHAR_BIT */
75#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */ 89#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
@@ -87,7 +101,7 @@
87/* Checked size_t computations. */ 101/* Checked size_t computations. */
88#include "xsize.h" 102#include "xsize.h"
89 103
90#include "verify.h" 104#include "attribute.h"
91 105
92#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL 106#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
93# include <math.h> 107# include <math.h>
@@ -156,6 +170,7 @@
156# define SNPRINTF snwprintf 170# define SNPRINTF snwprintf
157# else 171# else
158# define SNPRINTF _snwprintf 172# define SNPRINTF _snwprintf
173# define USE_MSVC__SNPRINTF 1
159# endif 174# endif
160# else 175# else
161 /* Unix. */ 176 /* Unix. */
@@ -181,7 +196,9 @@
181 /* Here we need to call the native snprintf, not rpl_snprintf. */ 196 /* Here we need to call the native snprintf, not rpl_snprintf. */
182# undef snprintf 197# undef snprintf
183# else 198# else
199 /* MSVC versions < 14 did not have snprintf, only _snprintf. */
184# define SNPRINTF _snprintf 200# define SNPRINTF _snprintf
201# define USE_MSVC__SNPRINTF 1
185# endif 202# endif
186# else 203# else
187 /* Unix. */ 204 /* Unix. */
@@ -195,7 +212,7 @@
195 212
196/* GCC >= 4.0 with -Wall emits unjustified "... may be used uninitialized" 213/* GCC >= 4.0 with -Wall emits unjustified "... may be used uninitialized"
197 warnings in this file. Use -Dlint to suppress them. */ 214 warnings in this file. Use -Dlint to suppress them. */
198#ifdef lint 215#if defined GCC_LINT || defined lint
199# define IF_LINT(Code) Code 216# define IF_LINT(Code) Code
200#else 217#else
201# define IF_LINT(Code) /* empty */ 218# define IF_LINT(Code) /* empty */
@@ -208,7 +225,7 @@
208#undef remainder 225#undef remainder
209#define remainder rem 226#define remainder rem
210 227
211#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION 228#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && !WIDE_CHAR_VERSION
212# if (HAVE_STRNLEN && !defined _AIX) 229# if (HAVE_STRNLEN && !defined _AIX)
213# define local_strnlen strnlen 230# define local_strnlen strnlen
214# else 231# else
@@ -224,7 +241,7 @@ local_strnlen (const char *string, size_t maxlen)
224# endif 241# endif
225#endif 242#endif
226 243
227#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T 244#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
228# if HAVE_WCSLEN 245# if HAVE_WCSLEN
229# define local_wcslen wcslen 246# define local_wcslen wcslen
230# else 247# else
@@ -247,7 +264,7 @@ local_wcslen (const wchar_t *s)
247# endif 264# endif
248#endif 265#endif
249 266
250#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION 267#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
251# if HAVE_WCSNLEN 268# if HAVE_WCSNLEN
252# define local_wcsnlen wcsnlen 269# define local_wcsnlen wcsnlen
253# else 270# else
@@ -266,6 +283,74 @@ local_wcsnlen (const wchar_t *s, size_t maxlen)
266# endif 283# endif
267#endif 284#endif
268 285
286#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T) || (ENABLE_WCHAR_FALLBACK && HAVE_WINT_T)) && !WIDE_CHAR_VERSION
287# if ENABLE_WCHAR_FALLBACK
288static size_t
289wctomb_fallback (char *s, wchar_t wc)
290{
291 static char hex[16] = "0123456789ABCDEF";
292
293 s[0] = '\\';
294 if (sizeof (wchar_t) > 2 && wc > 0xffff)
295 {
296# if __STDC_ISO_10646__ || (__GLIBC__ >= 2) || (defined _WIN32 || defined __CYGWIN__)
297 s[1] = 'U';
298# else
299 s[1] = 'W';
300# endif
301 s[2] = hex[(wc & 0xf0000000U) >> 28];
302 s[3] = hex[(wc & 0xf000000U) >> 24];
303 s[4] = hex[(wc & 0xf00000U) >> 20];
304 s[5] = hex[(wc & 0xf0000U) >> 16];
305 s[6] = hex[(wc & 0xf000U) >> 12];
306 s[7] = hex[(wc & 0xf00U) >> 8];
307 s[8] = hex[(wc & 0xf0U) >> 4];
308 s[9] = hex[wc & 0xfU];
309 return 10;
310 }
311 else
312 {
313# if __STDC_ISO_10646__ || (__GLIBC__ >= 2) || (defined _WIN32 || defined __CYGWIN__)
314 s[1] = 'u';
315# else
316 s[1] = 'w';
317# endif
318 s[2] = hex[(wc & 0xf000U) >> 12];
319 s[3] = hex[(wc & 0xf00U) >> 8];
320 s[4] = hex[(wc & 0xf0U) >> 4];
321 s[5] = hex[wc & 0xfU];
322 return 6;
323 }
324}
325# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
326static size_t
327local_wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
328{
329 size_t count = wcrtomb (s, wc, ps);
330 if (count == (size_t)(-1))
331 count = wctomb_fallback (s, wc);
332 return count;
333}
334# else
335static int
336local_wctomb (char *s, wchar_t wc)
337{
338 int count = wctomb (s, wc);
339 if (count < 0)
340 count = wctomb_fallback (s, wc);
341 return count;
342}
343# define local_wcrtomb(S, WC, PS) local_wctomb ((S), (WC))
344# endif
345# else
346# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
347# define local_wcrtomb(S, WC, PS) wcrtomb ((S), (WC), (PS))
348# else
349# define local_wcrtomb(S, WC, PS) wctomb ((S), (WC))
350# endif
351# endif
352#endif
353
269#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL 354#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
270/* Determine the decimal-point character according to the current locale. */ 355/* Determine the decimal-point character according to the current locale. */
271# ifndef decimal_point_char_defined 356# ifndef decimal_point_char_defined
@@ -323,11 +408,11 @@ is_infinite_or_zerol (long double x)
323 408
324typedef unsigned int mp_limb_t; 409typedef unsigned int mp_limb_t;
325# define GMP_LIMB_BITS 32 410# define GMP_LIMB_BITS 32
326verify (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS); 411static_assert (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS);
327 412
328typedef unsigned long long mp_twolimb_t; 413typedef unsigned long long mp_twolimb_t;
329# define GMP_TWOLIMB_BITS 64 414# define GMP_TWOLIMB_BITS 64
330verify (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS); 415static_assert (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS);
331 416
332/* Representation of a bignum >= 0. */ 417/* Representation of a bignum >= 0. */
333typedef struct 418typedef struct
@@ -554,7 +639,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
554 mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ 639 mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
555 /* Determine s = GMP_LIMB_BITS - integer_length (msd). 640 /* Determine s = GMP_LIMB_BITS - integer_length (msd).
556 Code copied from gnulib's integer_length.c. */ 641 Code copied from gnulib's integer_length.c. */
557# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 642# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
643 || (__clang_major__ >= 4)
558 s = __builtin_clz (msd); 644 s = __builtin_clz (msd);
559# else 645# else
560# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT 646# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
@@ -829,8 +915,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
829 q_ptr[q_len++] = 1; 915 q_ptr[q_len++] = 1;
830 } 916 }
831 keep_q: 917 keep_q:
832 if (tmp_roomptr != NULL) 918 free (tmp_roomptr);
833 free (tmp_roomptr);
834 q->limbs = q_ptr; 919 q->limbs = q_ptr;
835 q->nlimbs = q_len; 920 q->nlimbs = q_len;
836 return roomptr; 921 return roomptr;
@@ -849,7 +934,9 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
849 size_t a_len = a.nlimbs; 934 size_t a_len = a.nlimbs;
850 /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ 935 /* 0.03345 is slightly larger than log(2)/(9*log(10)). */
851 size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1); 936 size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1);
852 char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes)); 937 /* We need extra_zeroes bytes for zeroes, followed by c_len bytes for the
938 digits of a, followed by 1 byte for the terminating NUL. */
939 char *c_ptr = (char *) malloc (xsum (xsum (extra_zeroes, c_len), 1));
853 if (c_ptr != NULL) 940 if (c_ptr != NULL)
854 { 941 {
855 char *d_ptr = c_ptr; 942 char *d_ptr = c_ptr;
@@ -1517,7 +1604,7 @@ is_borderline (const char *digits, size_t precision)
1517 1604
1518#endif 1605#endif
1519 1606
1520#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 1607#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
1521 1608
1522/* Use a different function name, to make it possible that the 'wchar_t' 1609/* Use a different function name, to make it possible that the 'wchar_t'
1523 parametrization and the 'char' parametrization get compiled in the same 1610 parametrization and the 'char' parametrization get compiled in the same
@@ -1540,16 +1627,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1540 switch (conversion) 1627 switch (conversion)
1541 { 1628 {
1542 case 'd': case 'i': case 'u': 1629 case 'd': case 'i': case 'u':
1543# if HAVE_LONG_LONG_INT
1544 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 1630 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
1545 tmp_length = 1631 tmp_length =
1546 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 1632 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
1547 * 0.30103 /* binary -> decimal */ 1633 * 0.30103 /* binary -> decimal */
1548 ) 1634 )
1549 + 1; /* turn floor into ceil */ 1635 + 1; /* turn floor into ceil */
1550 else 1636 else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1551# endif
1552 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1553 tmp_length = 1637 tmp_length =
1554 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 1638 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
1555 * 0.30103 /* binary -> decimal */ 1639 * 0.30103 /* binary -> decimal */
@@ -1570,16 +1654,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1570 break; 1654 break;
1571 1655
1572 case 'o': 1656 case 'o':
1573# if HAVE_LONG_LONG_INT
1574 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 1657 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
1575 tmp_length = 1658 tmp_length =
1576 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 1659 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
1577 * 0.333334 /* binary -> octal */ 1660 * 0.333334 /* binary -> octal */
1578 ) 1661 )
1579 + 1; /* turn floor into ceil */ 1662 + 1; /* turn floor into ceil */
1580 else 1663 else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1581# endif
1582 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1583 tmp_length = 1664 tmp_length =
1584 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 1665 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
1585 * 0.333334 /* binary -> octal */ 1666 * 0.333334 /* binary -> octal */
@@ -1598,16 +1679,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1598 break; 1679 break;
1599 1680
1600 case 'x': case 'X': 1681 case 'x': case 'X':
1601# if HAVE_LONG_LONG_INT
1602 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 1682 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
1603 tmp_length = 1683 tmp_length =
1604 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 1684 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
1605 * 0.25 /* binary -> hexadecimal */ 1685 * 0.25 /* binary -> hexadecimal */
1606 ) 1686 )
1607 + 1; /* turn floor into ceil */ 1687 + 1; /* turn floor into ceil */
1608 else 1688 else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1609# endif
1610 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1611 tmp_length = 1689 tmp_length =
1612 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 1690 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
1613 * 0.25 /* binary -> hexadecimal */ 1691 * 0.25 /* binary -> hexadecimal */
@@ -1673,7 +1751,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1673 case 'c': 1751 case 'c':
1674# if HAVE_WINT_T && !WIDE_CHAR_VERSION 1752# if HAVE_WINT_T && !WIDE_CHAR_VERSION
1675 if (type == TYPE_WIDE_CHAR) 1753 if (type == TYPE_WIDE_CHAR)
1676 tmp_length = MB_CUR_MAX; 1754 {
1755 tmp_length = MB_CUR_MAX;
1756# if ENABLE_WCHAR_FALLBACK
1757 if (tmp_length < (sizeof (wchar_t) > 2 ? 10 : 6))
1758 tmp_length = (sizeof (wchar_t) > 2 ? 10 : 6);
1759# endif
1760 }
1677 else 1761 else
1678# endif 1762# endif
1679 tmp_length = 1; 1763 tmp_length = 1;
@@ -1780,6 +1864,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1780 /* errno is already set. */ 1864 /* errno is already set. */
1781 return NULL; 1865 return NULL;
1782 1866
1867 /* Frees the memory allocated by this function. Preserves errno. */
1783#define CLEANUP() \ 1868#define CLEANUP() \
1784 if (d.dir != d.direct_alloc_dir) \ 1869 if (d.dir != d.direct_alloc_dir) \
1785 free (d.dir); \ 1870 free (d.dir); \
@@ -1787,11 +1872,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1787 free (a.arg); 1872 free (a.arg);
1788 1873
1789 if (PRINTF_FETCHARGS (args, &a) < 0) 1874 if (PRINTF_FETCHARGS (args, &a) < 0)
1790 { 1875 goto fail_1_with_EINVAL;
1791 CLEANUP ();
1792 errno = EINVAL;
1793 return NULL;
1794 }
1795 1876
1796 { 1877 {
1797 size_t buf_neededlength; 1878 size_t buf_neededlength;
@@ -1827,24 +1908,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1827 buf_malloced = buf; 1908 buf_malloced = buf;
1828 } 1909 }
1829 1910
1830 if (resultbuf != NULL) 1911 result = resultbuf;
1831 { 1912 allocated = (resultbuf != NULL ? *lengthp : 0);
1832 result = resultbuf;
1833 allocated = *lengthp;
1834 }
1835 else
1836 {
1837 result = NULL;
1838 allocated = 0;
1839 }
1840 length = 0; 1913 length = 0;
1841 /* Invariants: 1914 /* Invariants:
1842 result is either == resultbuf or == NULL or malloc-allocated. 1915 result is either == resultbuf or malloc-allocated.
1916 If result == NULL, resultbuf is == NULL as well.
1843 If length > 0, then result != NULL. */ 1917 If length > 0, then result != NULL. */
1844 1918
1845 /* Ensures that allocated >= needed. Aborts through a jump to 1919 /* Ensures that allocated >= needed. Aborts through a jump to
1846 out_of_memory if needed is SIZE_MAX or otherwise too big. */ 1920 out_of_memory if needed is SIZE_MAX or otherwise too big. */
1847#define ENSURE_ALLOCATION(needed) \ 1921#define ENSURE_ALLOCATION_ELSE(needed, oom_statement) \
1848 if ((needed) > allocated) \ 1922 if ((needed) > allocated) \
1849 { \ 1923 { \
1850 size_t memory_size; \ 1924 size_t memory_size; \
@@ -1855,17 +1929,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1855 allocated = (needed); \ 1929 allocated = (needed); \
1856 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ 1930 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
1857 if (size_overflow_p (memory_size)) \ 1931 if (size_overflow_p (memory_size)) \
1858 goto out_of_memory; \ 1932 oom_statement \
1859 if (result == resultbuf || result == NULL) \ 1933 if (result == resultbuf) \
1860 memory = (DCHAR_T *) malloc (memory_size); \ 1934 memory = (DCHAR_T *) malloc (memory_size); \
1861 else \ 1935 else \
1862 memory = (DCHAR_T *) realloc (result, memory_size); \ 1936 memory = (DCHAR_T *) realloc (result, memory_size); \
1863 if (memory == NULL) \ 1937 if (memory == NULL) \
1864 goto out_of_memory; \ 1938 oom_statement \
1865 if (result == resultbuf && length > 0) \ 1939 if (result == resultbuf && length > 0) \
1866 DCHAR_CPY (memory, result, length); \ 1940 DCHAR_CPY (memory, result, length); \
1867 result = memory; \ 1941 result = memory; \
1868 } 1942 }
1943#define ENSURE_ALLOCATION(needed) \
1944 ENSURE_ALLOCATION_ELSE((needed), goto out_of_memory; )
1869 1945
1870 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) 1946 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
1871 { 1947 {
@@ -1886,7 +1962,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1886 else 1962 else
1887 { 1963 {
1888 do 1964 do
1889 result[length++] = (unsigned char) *cp++; 1965 result[length++] = *cp++;
1890 while (--n > 0); 1966 while (--n > 0);
1891 } 1967 }
1892 } 1968 }
@@ -1926,11 +2002,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1926 case TYPE_COUNT_LONGINT_POINTER: 2002 case TYPE_COUNT_LONGINT_POINTER:
1927 *a.arg[dp->arg_index].a.a_count_longint_pointer = length; 2003 *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
1928 break; 2004 break;
1929#if HAVE_LONG_LONG_INT
1930 case TYPE_COUNT_LONGLONGINT_POINTER: 2005 case TYPE_COUNT_LONGLONGINT_POINTER:
1931 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; 2006 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
1932 break; 2007 break;
1933#endif
1934 default: 2008 default:
1935 abort (); 2009 abort ();
1936 } 2010 }
@@ -1957,15 +2031,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1957 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 2031 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
1958 abort (); 2032 abort ();
1959 arg = a.arg[dp->width_arg_index].a.a_int; 2033 arg = a.arg[dp->width_arg_index].a.a_int;
2034 width = arg;
1960 if (arg < 0) 2035 if (arg < 0)
1961 { 2036 {
1962 /* "A negative field width is taken as a '-' flag 2037 /* "A negative field width is taken as a '-' flag
1963 followed by a positive field width." */ 2038 followed by a positive field width." */
1964 flags |= FLAG_LEFT; 2039 flags |= FLAG_LEFT;
1965 width = (unsigned int) (-arg); 2040 width = -width;
1966 } 2041 }
1967 else
1968 width = arg;
1969 } 2042 }
1970 else 2043 else
1971 { 2044 {
@@ -2027,15 +2100,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2027 if (count == 0) 2100 if (count == 0)
2028 break; 2101 break;
2029 if (count < 0) 2102 if (count < 0)
2030 { 2103 goto fail_with_EILSEQ;
2031 if (!(result == resultbuf || result == NULL))
2032 free (result);
2033 if (buf_malloced != NULL)
2034 free (buf_malloced);
2035 CLEANUP ();
2036 errno = EILSEQ;
2037 return NULL;
2038 }
2039 arg_end += count; 2104 arg_end += count;
2040 characters++; 2105 characters++;
2041 } 2106 }
@@ -2052,15 +2117,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2052 if (count == 0) 2117 if (count == 0)
2053 break; 2118 break;
2054 if (count < 0) 2119 if (count < 0)
2055 { 2120 goto fail_with_EILSEQ;
2056 if (!(result == resultbuf || result == NULL))
2057 free (result);
2058 if (buf_malloced != NULL)
2059 free (buf_malloced);
2060 CLEANUP ();
2061 errno = EILSEQ;
2062 return NULL;
2063 }
2064 arg_end += count; 2121 arg_end += count;
2065 characters++; 2122 characters++;
2066 } 2123 }
@@ -2073,8 +2130,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2073 characters = 0; 2130 characters = 0;
2074 } 2131 }
2075 2132
2076 if (has_width && width > characters 2133 if (characters < width && !(dp->flags & FLAG_LEFT))
2077 && !(dp->flags & FLAG_LEFT))
2078 { 2134 {
2079 size_t n = width - characters; 2135 size_t n = width - characters;
2080 ENSURE_ALLOCATION (xsum (length, n)); 2136 ENSURE_ALLOCATION (xsum (length, n));
@@ -2107,19 +2163,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2107 converted, &converted_len); 2163 converted, &converted_len);
2108# endif 2164# endif
2109 if (converted == NULL) 2165 if (converted == NULL)
2110 { 2166 goto fail_with_errno;
2111 int saved_errno = errno;
2112 if (!(result == resultbuf || result == NULL))
2113 free (result);
2114 if (buf_malloced != NULL)
2115 free (buf_malloced);
2116 CLEANUP ();
2117 errno = saved_errno;
2118 return NULL;
2119 }
2120 if (converted != result + length) 2167 if (converted != result + length)
2121 { 2168 {
2122 ENSURE_ALLOCATION (xsum (length, converted_len)); 2169 ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2170 { free (converted); goto out_of_memory; });
2123 DCHAR_CPY (result + length, converted, converted_len); 2171 DCHAR_CPY (result + length, converted, converted_len);
2124 free (converted); 2172 free (converted);
2125 } 2173 }
@@ -2127,8 +2175,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2127 } 2175 }
2128# endif 2176# endif
2129 2177
2130 if (has_width && width > characters 2178 if (characters < width && (dp->flags & FLAG_LEFT))
2131 && (dp->flags & FLAG_LEFT))
2132 { 2179 {
2133 size_t n = width - characters; 2180 size_t n = width - characters;
2134 ENSURE_ALLOCATION (xsum (length, n)); 2181 ENSURE_ALLOCATION (xsum (length, n));
@@ -2155,15 +2202,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2155 if (count == 0) 2202 if (count == 0)
2156 break; 2203 break;
2157 if (count < 0) 2204 if (count < 0)
2158 { 2205 goto fail_with_EILSEQ;
2159 if (!(result == resultbuf || result == NULL))
2160 free (result);
2161 if (buf_malloced != NULL)
2162 free (buf_malloced);
2163 CLEANUP ();
2164 errno = EILSEQ;
2165 return NULL;
2166 }
2167 arg_end += count; 2206 arg_end += count;
2168 characters++; 2207 characters++;
2169 } 2208 }
@@ -2180,15 +2219,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2180 if (count == 0) 2219 if (count == 0)
2181 break; 2220 break;
2182 if (count < 0) 2221 if (count < 0)
2183 { 2222 goto fail_with_EILSEQ;
2184 if (!(result == resultbuf || result == NULL))
2185 free (result);
2186 if (buf_malloced != NULL)
2187 free (buf_malloced);
2188 CLEANUP ();
2189 errno = EILSEQ;
2190 return NULL;
2191 }
2192 arg_end += count; 2223 arg_end += count;
2193 characters++; 2224 characters++;
2194 } 2225 }
@@ -2201,8 +2232,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2201 characters = 0; 2232 characters = 0;
2202 } 2233 }
2203 2234
2204 if (has_width && width > characters 2235 if (characters < width && !(dp->flags & FLAG_LEFT))
2205 && !(dp->flags & FLAG_LEFT))
2206 { 2236 {
2207 size_t n = width - characters; 2237 size_t n = width - characters;
2208 ENSURE_ALLOCATION (xsum (length, n)); 2238 ENSURE_ALLOCATION (xsum (length, n));
@@ -2235,19 +2265,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2235 converted, &converted_len); 2265 converted, &converted_len);
2236# endif 2266# endif
2237 if (converted == NULL) 2267 if (converted == NULL)
2238 { 2268 goto fail_with_errno;
2239 int saved_errno = errno;
2240 if (!(result == resultbuf || result == NULL))
2241 free (result);
2242 if (buf_malloced != NULL)
2243 free (buf_malloced);
2244 CLEANUP ();
2245 errno = saved_errno;
2246 return NULL;
2247 }
2248 if (converted != result + length) 2269 if (converted != result + length)
2249 { 2270 {
2250 ENSURE_ALLOCATION (xsum (length, converted_len)); 2271 ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2272 { free (converted); goto out_of_memory; });
2251 DCHAR_CPY (result + length, converted, converted_len); 2273 DCHAR_CPY (result + length, converted, converted_len);
2252 free (converted); 2274 free (converted);
2253 } 2275 }
@@ -2255,8 +2277,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2255 } 2277 }
2256# endif 2278# endif
2257 2279
2258 if (has_width && width > characters 2280 if (characters < width && (dp->flags & FLAG_LEFT))
2259 && (dp->flags & FLAG_LEFT))
2260 { 2281 {
2261 size_t n = width - characters; 2282 size_t n = width - characters;
2262 ENSURE_ALLOCATION (xsum (length, n)); 2283 ENSURE_ALLOCATION (xsum (length, n));
@@ -2283,15 +2304,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2283 if (count == 0) 2304 if (count == 0)
2284 break; 2305 break;
2285 if (count < 0) 2306 if (count < 0)
2286 { 2307 goto fail_with_EILSEQ;
2287 if (!(result == resultbuf || result == NULL))
2288 free (result);
2289 if (buf_malloced != NULL)
2290 free (buf_malloced);
2291 CLEANUP ();
2292 errno = EILSEQ;
2293 return NULL;
2294 }
2295 arg_end += count; 2308 arg_end += count;
2296 characters++; 2309 characters++;
2297 } 2310 }
@@ -2308,15 +2321,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2308 if (count == 0) 2321 if (count == 0)
2309 break; 2322 break;
2310 if (count < 0) 2323 if (count < 0)
2311 { 2324 goto fail_with_EILSEQ;
2312 if (!(result == resultbuf || result == NULL))
2313 free (result);
2314 if (buf_malloced != NULL)
2315 free (buf_malloced);
2316 CLEANUP ();
2317 errno = EILSEQ;
2318 return NULL;
2319 }
2320 arg_end += count; 2325 arg_end += count;
2321 characters++; 2326 characters++;
2322 } 2327 }
@@ -2329,8 +2334,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2329 characters = 0; 2334 characters = 0;
2330 } 2335 }
2331 2336
2332 if (has_width && width > characters 2337 if (characters < width && !(dp->flags & FLAG_LEFT))
2333 && !(dp->flags & FLAG_LEFT))
2334 { 2338 {
2335 size_t n = width - characters; 2339 size_t n = width - characters;
2336 ENSURE_ALLOCATION (xsum (length, n)); 2340 ENSURE_ALLOCATION (xsum (length, n));
@@ -2363,19 +2367,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2363 converted, &converted_len); 2367 converted, &converted_len);
2364# endif 2368# endif
2365 if (converted == NULL) 2369 if (converted == NULL)
2366 { 2370 goto fail_with_errno;
2367 int saved_errno = errno;
2368 if (!(result == resultbuf || result == NULL))
2369 free (result);
2370 if (buf_malloced != NULL)
2371 free (buf_malloced);
2372 CLEANUP ();
2373 errno = saved_errno;
2374 return NULL;
2375 }
2376 if (converted != result + length) 2371 if (converted != result + length)
2377 { 2372 {
2378 ENSURE_ALLOCATION (xsum (length, converted_len)); 2373 ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2374 { free (converted); goto out_of_memory; });
2379 DCHAR_CPY (result + length, converted, converted_len); 2375 DCHAR_CPY (result + length, converted, converted_len);
2380 free (converted); 2376 free (converted);
2381 } 2377 }
@@ -2383,8 +2379,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2383 } 2379 }
2384# endif 2380# endif
2385 2381
2386 if (has_width && width > characters 2382 if (characters < width && (dp->flags & FLAG_LEFT))
2387 && (dp->flags & FLAG_LEFT))
2388 { 2383 {
2389 size_t n = width - characters; 2384 size_t n = width - characters;
2390 ENSURE_ALLOCATION (xsum (length, n)); 2385 ENSURE_ALLOCATION (xsum (length, n));
@@ -2399,7 +2394,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2399 } 2394 }
2400 } 2395 }
2401#endif 2396#endif
2402#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T 2397#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T
2403 else if (dp->conversion == 's' 2398 else if (dp->conversion == 's'
2404# if WIDE_CHAR_VERSION 2399# if WIDE_CHAR_VERSION
2405 && a.arg[dp->arg_index].type != TYPE_WIDE_STRING 2400 && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
@@ -2435,15 +2430,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2435 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 2430 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2436 abort (); 2431 abort ();
2437 arg = a.arg[dp->width_arg_index].a.a_int; 2432 arg = a.arg[dp->width_arg_index].a.a_int;
2433 width = arg;
2438 if (arg < 0) 2434 if (arg < 0)
2439 { 2435 {
2440 /* "A negative field width is taken as a '-' flag 2436 /* "A negative field width is taken as a '-' flag
2441 followed by a positive field width." */ 2437 followed by a positive field width." */
2442 flags |= FLAG_LEFT; 2438 flags |= FLAG_LEFT;
2443 width = (unsigned int) (-arg); 2439 width = -width;
2444 } 2440 }
2445 else
2446 width = arg;
2447 } 2441 }
2448 else 2442 else
2449 { 2443 {
@@ -2515,16 +2509,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2515 /* Found the terminating NUL. */ 2509 /* Found the terminating NUL. */
2516 break; 2510 break;
2517 if (count < 0) 2511 if (count < 0)
2518 { 2512 /* Invalid or incomplete multibyte character. */
2519 /* Invalid or incomplete multibyte character. */ 2513 goto fail_with_EILSEQ;
2520 if (!(result == resultbuf || result == NULL))
2521 free (result);
2522 if (buf_malloced != NULL)
2523 free (buf_malloced);
2524 CLEANUP ();
2525 errno = EILSEQ;
2526 return NULL;
2527 }
2528 arg_end += count; 2514 arg_end += count;
2529 characters++; 2515 characters++;
2530 } 2516 }
@@ -2551,16 +2537,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2551 /* Found the terminating NUL. */ 2537 /* Found the terminating NUL. */
2552 break; 2538 break;
2553 if (count < 0) 2539 if (count < 0)
2554 { 2540 /* Invalid or incomplete multibyte character. */
2555 /* Invalid or incomplete multibyte character. */ 2541 goto fail_with_EILSEQ;
2556 if (!(result == resultbuf || result == NULL))
2557 free (result);
2558 if (buf_malloced != NULL)
2559 free (buf_malloced);
2560 CLEANUP ();
2561 errno = EILSEQ;
2562 return NULL;
2563 }
2564 arg_end += count; 2542 arg_end += count;
2565 characters++; 2543 characters++;
2566 } 2544 }
@@ -2573,8 +2551,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2573 characters = 0; 2551 characters = 0;
2574 } 2552 }
2575 2553
2576 if (has_width && width > characters 2554 if (characters < width && !(dp->flags & FLAG_LEFT))
2577 && !(dp->flags & FLAG_LEFT))
2578 { 2555 {
2579 size_t n = width - characters; 2556 size_t n = width - characters;
2580 ENSURE_ALLOCATION (xsum (length, n)); 2557 ENSURE_ALLOCATION (xsum (length, n));
@@ -2635,8 +2612,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2635 } 2612 }
2636 } 2613 }
2637 2614
2638 if (has_width && width > characters 2615 if (characters < width && (dp->flags & FLAG_LEFT))
2639 && (dp->flags & FLAG_LEFT))
2640 { 2616 {
2641 size_t n = width - characters; 2617 size_t n = width - characters;
2642 ENSURE_ALLOCATION (xsum (length, n)); 2618 ENSURE_ALLOCATION (xsum (length, n));
@@ -2652,7 +2628,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2652 size_t characters; 2628 size_t characters;
2653# if !DCHAR_IS_TCHAR 2629# if !DCHAR_IS_TCHAR
2654 /* This code assumes that TCHAR_T is 'char'. */ 2630 /* This code assumes that TCHAR_T is 'char'. */
2655 verify (sizeof (TCHAR_T) == 1); 2631 static_assert (sizeof (TCHAR_T) == 1);
2656 TCHAR_T *tmpsrc; 2632 TCHAR_T *tmpsrc;
2657 DCHAR_T *tmpdst; 2633 DCHAR_T *tmpdst;
2658 size_t tmpdst_len; 2634 size_t tmpdst_len;
@@ -2677,23 +2653,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2677 if (*arg_end == 0) 2653 if (*arg_end == 0)
2678 /* Found the terminating null wide character. */ 2654 /* Found the terminating null wide character. */
2679 break; 2655 break;
2680# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2656 count = local_wcrtomb (cbuf, *arg_end, &state);
2681 count = wcrtomb (cbuf, *arg_end, &state);
2682# else
2683 count = wctomb (cbuf, *arg_end);
2684# endif
2685 if (count < 0) 2657 if (count < 0)
2686 { 2658 /* Cannot convert. */
2687 /* Cannot convert. */ 2659 goto fail_with_EILSEQ;
2688 if (!(result == resultbuf || result == NULL)) 2660 if (precision < (unsigned int) count)
2689 free (result);
2690 if (buf_malloced != NULL)
2691 free (buf_malloced);
2692 CLEANUP ();
2693 errno = EILSEQ;
2694 return NULL;
2695 }
2696 if (precision < count)
2697 break; 2661 break;
2698 arg_end++; 2662 arg_end++;
2699 characters += count; 2663 characters += count;
@@ -2722,22 +2686,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2722 if (*arg_end == 0) 2686 if (*arg_end == 0)
2723 /* Found the terminating null wide character. */ 2687 /* Found the terminating null wide character. */
2724 break; 2688 break;
2725# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2689 count = local_wcrtomb (cbuf, *arg_end, &state);
2726 count = wcrtomb (cbuf, *arg_end, &state);
2727# else
2728 count = wctomb (cbuf, *arg_end);
2729# endif
2730 if (count < 0) 2690 if (count < 0)
2731 { 2691 /* Cannot convert. */
2732 /* Cannot convert. */ 2692 goto fail_with_EILSEQ;
2733 if (!(result == resultbuf || result == NULL))
2734 free (result);
2735 if (buf_malloced != NULL)
2736 free (buf_malloced);
2737 CLEANUP ();
2738 errno = EILSEQ;
2739 return NULL;
2740 }
2741 arg_end++; 2693 arg_end++;
2742 characters += count; 2694 characters += count;
2743 } 2695 }
@@ -2771,11 +2723,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2771 2723
2772 if (*arg == 0) 2724 if (*arg == 0)
2773 abort (); 2725 abort ();
2774# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2726 count = local_wcrtomb (cbuf, *arg, &state);
2775 count = wcrtomb (cbuf, *arg, &state);
2776# else
2777 count = wctomb (cbuf, *arg);
2778# endif
2779 if (count <= 0) 2727 if (count <= 0)
2780 /* Inconsistency. */ 2728 /* Inconsistency. */
2781 abort (); 2729 abort ();
@@ -2797,15 +2745,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2797 NULL, &tmpdst_len); 2745 NULL, &tmpdst_len);
2798 if (tmpdst == NULL) 2746 if (tmpdst == NULL)
2799 { 2747 {
2800 int saved_errno = errno;
2801 free (tmpsrc); 2748 free (tmpsrc);
2802 if (!(result == resultbuf || result == NULL)) 2749 goto fail_with_errno;
2803 free (result);
2804 if (buf_malloced != NULL)
2805 free (buf_malloced);
2806 CLEANUP ();
2807 errno = saved_errno;
2808 return NULL;
2809 } 2750 }
2810 free (tmpsrc); 2751 free (tmpsrc);
2811# endif 2752# endif
@@ -2827,8 +2768,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2827 /* w doesn't matter. */ 2768 /* w doesn't matter. */
2828 w = 0; 2769 w = 0;
2829 2770
2830 if (has_width && width > w 2771 if (w < width && !(dp->flags & FLAG_LEFT))
2831 && !(dp->flags & FLAG_LEFT))
2832 { 2772 {
2833 size_t n = width - w; 2773 size_t n = width - w;
2834 ENSURE_ALLOCATION (xsum (length, n)); 2774 ENSURE_ALLOCATION (xsum (length, n));
@@ -2853,11 +2793,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2853 2793
2854 if (*arg == 0) 2794 if (*arg == 0)
2855 abort (); 2795 abort ();
2856# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2796 count = local_wcrtomb (cbuf, *arg, &state);
2857 count = wcrtomb (cbuf, *arg, &state);
2858# else
2859 count = wctomb (cbuf, *arg);
2860# endif
2861 if (count <= 0) 2797 if (count <= 0)
2862 /* Inconsistency. */ 2798 /* Inconsistency. */
2863 abort (); 2799 abort ();
@@ -2882,22 +2818,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2882 2818
2883 if (*arg == 0) 2819 if (*arg == 0)
2884 abort (); 2820 abort ();
2885# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2821 count = local_wcrtomb (cbuf, *arg, &state);
2886 count = wcrtomb (cbuf, *arg, &state);
2887# else
2888 count = wctomb (cbuf, *arg);
2889# endif
2890 if (count <= 0) 2822 if (count <= 0)
2891 { 2823 /* Cannot convert. */
2892 /* Cannot convert. */ 2824 goto fail_with_EILSEQ;
2893 if (!(result == resultbuf || result == NULL))
2894 free (result);
2895 if (buf_malloced != NULL)
2896 free (buf_malloced);
2897 CLEANUP ();
2898 errno = EILSEQ;
2899 return NULL;
2900 }
2901 ENSURE_ALLOCATION (xsum (length, count)); 2825 ENSURE_ALLOCATION (xsum (length, count));
2902 memcpy (result + length, cbuf, count); 2826 memcpy (result + length, cbuf, count);
2903 length += count; 2827 length += count;
@@ -2905,14 +2829,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2905 } 2829 }
2906 } 2830 }
2907# else 2831# else
2908 ENSURE_ALLOCATION (xsum (length, tmpdst_len)); 2832 ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
2833 { free (tmpdst); goto out_of_memory; });
2909 DCHAR_CPY (result + length, tmpdst, tmpdst_len); 2834 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
2910 free (tmpdst); 2835 free (tmpdst);
2911 length += tmpdst_len; 2836 length += tmpdst_len;
2912# endif 2837# endif
2913 2838
2914 if (has_width && width > w 2839 if (w < width && (dp->flags & FLAG_LEFT))
2915 && (dp->flags & FLAG_LEFT))
2916 { 2840 {
2917 size_t n = width - w; 2841 size_t n = width - w;
2918 ENSURE_ALLOCATION (xsum (length, n)); 2842 ENSURE_ALLOCATION (xsum (length, n));
@@ -2923,6 +2847,202 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2923# endif 2847# endif
2924 } 2848 }
2925#endif 2849#endif
2850#if ENABLE_WCHAR_FALLBACK && HAVE_WINT_T && !WIDE_CHAR_VERSION
2851 else if (dp->conversion == 'c'
2852 && a.arg[dp->arg_index].type == TYPE_WIDE_CHAR)
2853 {
2854 /* Implement the 'lc' directive ourselves, in order to provide
2855 the fallback that avoids EILSEQ. */
2856 int flags = dp->flags;
2857 int has_width;
2858 size_t width;
2859
2860 has_width = 0;
2861 width = 0;
2862 if (dp->width_start != dp->width_end)
2863 {
2864 if (dp->width_arg_index != ARG_NONE)
2865 {
2866 int arg;
2867
2868 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2869 abort ();
2870 arg = a.arg[dp->width_arg_index].a.a_int;
2871 width = arg;
2872 if (arg < 0)
2873 {
2874 /* "A negative field width is taken as a '-' flag
2875 followed by a positive field width." */
2876 flags |= FLAG_LEFT;
2877 width = -width;
2878 }
2879 }
2880 else
2881 {
2882 const FCHAR_T *digitp = dp->width_start;
2883
2884 do
2885 width = xsum (xtimes (width, 10), *digitp++ - '0');
2886 while (digitp != dp->width_end);
2887 }
2888 has_width = 1;
2889 }
2890
2891 /* %lc in vasnprintf. See the specification of fprintf. */
2892 {
2893 wchar_t arg = (wchar_t) a.arg[dp->arg_index].a.a_wide_char;
2894 size_t characters;
2895# if !DCHAR_IS_TCHAR
2896 /* This code assumes that TCHAR_T is 'char'. */
2897 static_assert (sizeof (TCHAR_T) == 1);
2898 TCHAR_T tmpsrc[64]; /* Assume MB_CUR_MAX <= 64. */
2899 DCHAR_T *tmpdst;
2900 size_t tmpdst_len;
2901# endif
2902 size_t w;
2903
2904# if DCHAR_IS_TCHAR
2905 if (has_width)
2906# endif
2907 {
2908 /* Count the number of bytes. */
2909 characters = 0;
2910 if (arg != 0)
2911 {
2912 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2913 int count;
2914# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2915 mbstate_t state;
2916 memset (&state, '\0', sizeof (mbstate_t));
2917# endif
2918
2919 count = local_wcrtomb (cbuf, arg, &state);
2920 if (count < 0)
2921 /* Inconsistency. */
2922 abort ();
2923 characters = count;
2924 }
2925 }
2926# if DCHAR_IS_TCHAR
2927 else
2928 {
2929 /* The number of bytes doesn't matter. */
2930 characters = 0;
2931 }
2932# endif
2933
2934# if !DCHAR_IS_TCHAR
2935 /* Convert the string into a piece of temporary memory. */
2936 if (characters > 0) /* implies arg != 0 */
2937 {
2938 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
2939 int count;
2940# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2941 mbstate_t state;
2942 memset (&state, '\0', sizeof (mbstate_t));
2943# endif
2944
2945 count = local_wcrtomb (cbuf, arg, &state);
2946 if (count <= 0)
2947 /* Inconsistency. */
2948 abort ();
2949 memcpy (tmpsrc, cbuf, count);
2950 }
2951
2952 /* Convert from TCHAR_T[] to DCHAR_T[]. */
2953 tmpdst =
2954 DCHAR_CONV_FROM_ENCODING (locale_charset (),
2955 iconveh_question_mark,
2956 tmpsrc, characters,
2957 NULL,
2958 NULL, &tmpdst_len);
2959 if (tmpdst == NULL)
2960 goto fail_with_errno;
2961# endif
2962
2963 if (has_width)
2964 {
2965# if ENABLE_UNISTDIO
2966 /* Outside POSIX, it's preferable to compare the width
2967 against the number of _characters_ of the converted
2968 value. */
2969 w = DCHAR_MBSNLEN (result + length, characters);
2970# else
2971 /* The width is compared against the number of _bytes_
2972 of the converted value, says POSIX. */
2973 w = characters;
2974# endif
2975 }
2976 else
2977 /* w doesn't matter. */
2978 w = 0;
2979
2980 if (w < width && !(dp->flags & FLAG_LEFT))
2981 {
2982 size_t n = width - w;
2983 ENSURE_ALLOCATION (xsum (length, n));
2984 DCHAR_SET (result + length, ' ', n);
2985 length += n;
2986 }
2987
2988# if DCHAR_IS_TCHAR
2989 if (has_width)
2990 {
2991 /* We know the number of bytes in advance. */
2992 ENSURE_ALLOCATION (xsum (length, characters));
2993 if (characters > 0) /* implies arg != 0 */
2994 {
2995 int count;
2996# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
2997 mbstate_t state;
2998 memset (&state, '\0', sizeof (mbstate_t));
2999# endif
3000
3001 count = local_wcrtomb (result + length, arg, &state);
3002 if (count <= 0)
3003 /* Inconsistency. */
3004 abort ();
3005 length += count;
3006 }
3007 }
3008 else
3009 {
3010 if (arg != 0)
3011 {
3012 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
3013 int count;
3014# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
3015 mbstate_t state;
3016 memset (&state, '\0', sizeof (mbstate_t));
3017# endif
3018
3019 count = local_wcrtomb (cbuf, arg, &state);
3020 if (count <= 0)
3021 /* Inconsistency. */
3022 abort ();
3023 ENSURE_ALLOCATION (xsum (length, count));
3024 memcpy (result + length, cbuf, count);
3025 length += count;
3026 }
3027 }
3028# else
3029 ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
3030 { free (tmpdst); goto out_of_memory; });
3031 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
3032 free (tmpdst);
3033 length += tmpdst_len;
3034# endif
3035
3036 if (w < width && (dp->flags & FLAG_LEFT))
3037 {
3038 size_t n = width - w;
3039 ENSURE_ALLOCATION (xsum (length, n));
3040 DCHAR_SET (result + length, ' ', n);
3041 length += n;
3042 }
3043 }
3044 }
3045#endif
2926#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL 3046#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
2927 else if ((dp->conversion == 'a' || dp->conversion == 'A') 3047 else if ((dp->conversion == 'a' || dp->conversion == 'A')
2928# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) 3048# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
@@ -2939,17 +3059,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2939 { 3059 {
2940 arg_type type = a.arg[dp->arg_index].type; 3060 arg_type type = a.arg[dp->arg_index].type;
2941 int flags = dp->flags; 3061 int flags = dp->flags;
2942 int has_width;
2943 size_t width; 3062 size_t width;
2944 int has_precision; 3063 int has_precision;
2945 size_t precision; 3064 size_t precision;
2946 size_t tmp_length; 3065 size_t tmp_length;
3066 size_t count;
2947 DCHAR_T tmpbuf[700]; 3067 DCHAR_T tmpbuf[700];
2948 DCHAR_T *tmp; 3068 DCHAR_T *tmp;
2949 DCHAR_T *pad_ptr; 3069 DCHAR_T *pad_ptr;
2950 DCHAR_T *p; 3070 DCHAR_T *p;
2951 3071
2952 has_width = 0;
2953 width = 0; 3072 width = 0;
2954 if (dp->width_start != dp->width_end) 3073 if (dp->width_start != dp->width_end)
2955 { 3074 {
@@ -2960,15 +3079,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2960 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 3079 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2961 abort (); 3080 abort ();
2962 arg = a.arg[dp->width_arg_index].a.a_int; 3081 arg = a.arg[dp->width_arg_index].a.a_int;
3082 width = arg;
2963 if (arg < 0) 3083 if (arg < 0)
2964 { 3084 {
2965 /* "A negative field width is taken as a '-' flag 3085 /* "A negative field width is taken as a '-' flag
2966 followed by a positive field width." */ 3086 followed by a positive field width." */
2967 flags |= FLAG_LEFT; 3087 flags |= FLAG_LEFT;
2968 width = (unsigned int) (-arg); 3088 width = -width;
2969 } 3089 }
2970 else
2971 width = arg;
2972 } 3090 }
2973 else 3091 else
2974 { 3092 {
@@ -2978,7 +3096,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2978 width = xsum (xtimes (width, 10), *digitp++ - '0'); 3096 width = xsum (xtimes (width, 10), *digitp++ - '0');
2979 while (digitp != dp->width_end); 3097 while (digitp != dp->width_end);
2980 } 3098 }
2981 has_width = 1;
2982 } 3099 }
2983 3100
2984 has_precision = 0; 3101 has_precision = 0;
@@ -3354,11 +3471,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3354 abort (); 3471 abort ();
3355# endif 3472# endif
3356 } 3473 }
3474
3357 /* The generated string now extends from tmp to p, with the 3475 /* The generated string now extends from tmp to p, with the
3358 zero padding insertion point being at pad_ptr. */ 3476 zero padding insertion point being at pad_ptr. */
3359 if (has_width && p - tmp < width) 3477 count = p - tmp;
3478
3479 if (count < width)
3360 { 3480 {
3361 size_t pad = width - (p - tmp); 3481 size_t pad = width - count;
3362 DCHAR_T *end = p + pad; 3482 DCHAR_T *end = p + pad;
3363 3483
3364 if (flags & FLAG_LEFT) 3484 if (flags & FLAG_LEFT)
@@ -3391,28 +3511,26 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3391 p = end; 3511 p = end;
3392 } 3512 }
3393 3513
3394 { 3514 count = p - tmp;
3395 size_t count = p - tmp;
3396 3515
3397 if (count >= tmp_length) 3516 if (count >= tmp_length)
3398 /* tmp_length was incorrectly calculated - fix the 3517 /* tmp_length was incorrectly calculated - fix the
3399 code above! */ 3518 code above! */
3400 abort (); 3519 abort ();
3401 3520
3402 /* Make room for the result. */ 3521 /* Make room for the result. */
3403 if (count >= allocated - length) 3522 if (count >= allocated - length)
3404 { 3523 {
3405 size_t n = xsum (length, count); 3524 size_t n = xsum (length, count);
3406 3525
3407 ENSURE_ALLOCATION (n); 3526 ENSURE_ALLOCATION (n);
3408 } 3527 }
3409 3528
3410 /* Append the result. */ 3529 /* Append the result. */
3411 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 3530 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
3412 if (tmp != tmpbuf) 3531 if (tmp != tmpbuf)
3413 free (tmp); 3532 free (tmp);
3414 length += count; 3533 length += count;
3415 }
3416 } 3534 }
3417#endif 3535#endif
3418#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL 3536#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
@@ -3446,8 +3564,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3446 arg_type type = a.arg[dp->arg_index].type; 3564 arg_type type = a.arg[dp->arg_index].type;
3447# endif 3565# endif
3448 int flags = dp->flags; 3566 int flags = dp->flags;
3449 int has_width;
3450 size_t width; 3567 size_t width;
3568 size_t count;
3451 int has_precision; 3569 int has_precision;
3452 size_t precision; 3570 size_t precision;
3453 size_t tmp_length; 3571 size_t tmp_length;
@@ -3456,7 +3574,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3456 DCHAR_T *pad_ptr; 3574 DCHAR_T *pad_ptr;
3457 DCHAR_T *p; 3575 DCHAR_T *p;
3458 3576
3459 has_width = 0;
3460 width = 0; 3577 width = 0;
3461 if (dp->width_start != dp->width_end) 3578 if (dp->width_start != dp->width_end)
3462 { 3579 {
@@ -3467,15 +3584,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3467 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 3584 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
3468 abort (); 3585 abort ();
3469 arg = a.arg[dp->width_arg_index].a.a_int; 3586 arg = a.arg[dp->width_arg_index].a.a_int;
3587 width = arg;
3470 if (arg < 0) 3588 if (arg < 0)
3471 { 3589 {
3472 /* "A negative field width is taken as a '-' flag 3590 /* "A negative field width is taken as a '-' flag
3473 followed by a positive field width." */ 3591 followed by a positive field width." */
3474 flags |= FLAG_LEFT; 3592 flags |= FLAG_LEFT;
3475 width = (unsigned int) (-arg); 3593 width = -width;
3476 } 3594 }
3477 else
3478 width = arg;
3479 } 3595 }
3480 else 3596 else
3481 { 3597 {
@@ -3485,7 +3601,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3485 width = xsum (xtimes (width, 10), *digitp++ - '0'); 3601 width = xsum (xtimes (width, 10), *digitp++ - '0');
3486 while (digitp != dp->width_end); 3602 while (digitp != dp->width_end);
3487 } 3603 }
3488 has_width = 1;
3489 } 3604 }
3490 3605
3491 has_precision = 0; 3606 has_precision = 0;
@@ -3925,9 +4040,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3925 digits without trailing zeroes. */ 4040 digits without trailing zeroes. */
3926 if (exponent >= 0) 4041 if (exponent >= 0)
3927 { 4042 {
3928 size_t count = exponent + 1; 4043 size_t ecount = exponent + 1;
3929 /* Note: count <= precision = ndigits. */ 4044 /* Note: count <= precision = ndigits. */
3930 for (; count > 0; count--) 4045 for (; ecount > 0; ecount--)
3931 *p++ = digits[--ndigits]; 4046 *p++ = digits[--ndigits];
3932 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4047 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3933 { 4048 {
@@ -3941,10 +4056,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3941 } 4056 }
3942 else 4057 else
3943 { 4058 {
3944 size_t count = -exponent - 1; 4059 size_t ecount = -exponent - 1;
3945 *p++ = '0'; 4060 *p++ = '0';
3946 *p++ = decimal_point_char (); 4061 *p++ = decimal_point_char ();
3947 for (; count > 0; count--) 4062 for (; ecount > 0; ecount--)
3948 *p++ = '0'; 4063 *p++ = '0';
3949 while (ndigits > nzeroes) 4064 while (ndigits > nzeroes)
3950 { 4065 {
@@ -4249,7 +4364,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4249 static const wchar_t decimal_format[] = 4364 static const wchar_t decimal_format[] =
4250 /* Produce the same number of exponent digits 4365 /* Produce the same number of exponent digits
4251 as the native printf implementation. */ 4366 as the native printf implementation. */
4252# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4367# if defined _WIN32 && ! defined __CYGWIN__
4253 { '%', '+', '.', '3', 'd', '\0' }; 4368 { '%', '+', '.', '3', 'd', '\0' };
4254# else 4369# else
4255 { '%', '+', '.', '2', 'd', '\0' }; 4370 { '%', '+', '.', '2', 'd', '\0' };
@@ -4263,7 +4378,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4263 static const char decimal_format[] = 4378 static const char decimal_format[] =
4264 /* Produce the same number of exponent digits 4379 /* Produce the same number of exponent digits
4265 as the native printf implementation. */ 4380 as the native printf implementation. */
4266# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4381# if defined _WIN32 && ! defined __CYGWIN__
4267 "%+.3d"; 4382 "%+.3d";
4268# else 4383# else
4269 "%+.2d"; 4384 "%+.2d";
@@ -4395,9 +4510,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4395 digits without trailing zeroes. */ 4510 digits without trailing zeroes. */
4396 if (exponent >= 0) 4511 if (exponent >= 0)
4397 { 4512 {
4398 size_t count = exponent + 1; 4513 size_t ecount = exponent + 1;
4399 /* Note: count <= precision = ndigits. */ 4514 /* Note: ecount <= precision = ndigits. */
4400 for (; count > 0; count--) 4515 for (; ecount > 0; ecount--)
4401 *p++ = digits[--ndigits]; 4516 *p++ = digits[--ndigits];
4402 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4517 if ((flags & FLAG_ALT) || ndigits > nzeroes)
4403 { 4518 {
@@ -4411,10 +4526,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4411 } 4526 }
4412 else 4527 else
4413 { 4528 {
4414 size_t count = -exponent - 1; 4529 size_t ecount = -exponent - 1;
4415 *p++ = '0'; 4530 *p++ = '0';
4416 *p++ = decimal_point_char (); 4531 *p++ = decimal_point_char ();
4417 for (; count > 0; count--) 4532 for (; ecount > 0; ecount--)
4418 *p++ = '0'; 4533 *p++ = '0';
4419 while (ndigits > nzeroes) 4534 while (ndigits > nzeroes)
4420 { 4535 {
@@ -4442,7 +4557,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4442 static const wchar_t decimal_format[] = 4557 static const wchar_t decimal_format[] =
4443 /* Produce the same number of exponent digits 4558 /* Produce the same number of exponent digits
4444 as the native printf implementation. */ 4559 as the native printf implementation. */
4445# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4560# if defined _WIN32 && ! defined __CYGWIN__
4446 { '%', '+', '.', '3', 'd', '\0' }; 4561 { '%', '+', '.', '3', 'd', '\0' };
4447# else 4562# else
4448 { '%', '+', '.', '2', 'd', '\0' }; 4563 { '%', '+', '.', '2', 'd', '\0' };
@@ -4456,7 +4571,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4456 static const char decimal_format[] = 4571 static const char decimal_format[] =
4457 /* Produce the same number of exponent digits 4572 /* Produce the same number of exponent digits
4458 as the native printf implementation. */ 4573 as the native printf implementation. */
4459# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4574# if defined _WIN32 && ! defined __CYGWIN__
4460 "%+.3d"; 4575 "%+.3d";
4461# else 4576# else
4462 "%+.2d"; 4577 "%+.2d";
@@ -4514,7 +4629,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4514 *p++ = '+'; 4629 *p++ = '+';
4515 /* Produce the same number of exponent digits as 4630 /* Produce the same number of exponent digits as
4516 the native printf implementation. */ 4631 the native printf implementation. */
4517# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4632# if defined _WIN32 && ! defined __CYGWIN__
4518 *p++ = '0'; 4633 *p++ = '0';
4519# endif 4634# endif
4520 *p++ = '0'; 4635 *p++ = '0';
@@ -4542,9 +4657,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4542 4657
4543 /* The generated string now extends from tmp to p, with the 4658 /* The generated string now extends from tmp to p, with the
4544 zero padding insertion point being at pad_ptr. */ 4659 zero padding insertion point being at pad_ptr. */
4545 if (has_width && p - tmp < width) 4660 count = p - tmp;
4661
4662 if (count < width)
4546 { 4663 {
4547 size_t pad = width - (p - tmp); 4664 size_t pad = width - count;
4548 DCHAR_T *end = p + pad; 4665 DCHAR_T *end = p + pad;
4549 4666
4550 if (flags & FLAG_LEFT) 4667 if (flags & FLAG_LEFT)
@@ -4577,39 +4694,39 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4577 p = end; 4694 p = end;
4578 } 4695 }
4579 4696
4580 { 4697 count = p - tmp;
4581 size_t count = p - tmp;
4582 4698
4583 if (count >= tmp_length) 4699 if (count >= tmp_length)
4584 /* tmp_length was incorrectly calculated - fix the 4700 /* tmp_length was incorrectly calculated - fix the
4585 code above! */ 4701 code above! */
4586 abort (); 4702 abort ();
4587 4703
4588 /* Make room for the result. */ 4704 /* Make room for the result. */
4589 if (count >= allocated - length) 4705 if (count >= allocated - length)
4590 { 4706 {
4591 size_t n = xsum (length, count); 4707 size_t n = xsum (length, count);
4592 4708
4593 ENSURE_ALLOCATION (n); 4709 ENSURE_ALLOCATION (n);
4594 } 4710 }
4595 4711
4596 /* Append the result. */ 4712 /* Append the result. */
4597 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 4713 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
4598 if (tmp != tmpbuf) 4714 if (tmp != tmpbuf)
4599 free (tmp); 4715 free (tmp);
4600 length += count; 4716 length += count;
4601 }
4602 } 4717 }
4603#endif 4718#endif
4604 else 4719 else
4605 { 4720 {
4606 arg_type type = a.arg[dp->arg_index].type; 4721 arg_type type = a.arg[dp->arg_index].type;
4607 int flags = dp->flags; 4722 int flags = dp->flags;
4608#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION 4723#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4609 int has_width; 4724 int has_width;
4725#endif
4726#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4610 size_t width; 4727 size_t width;
4611#endif 4728#endif
4612#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION 4729#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
4613 int has_precision; 4730 int has_precision;
4614 size_t precision; 4731 size_t precision;
4615#endif 4732#endif
@@ -4635,8 +4752,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4635 TCHAR_T *tmp; 4752 TCHAR_T *tmp;
4636#endif 4753#endif
4637 4754
4638#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION 4755#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4639 has_width = 0; 4756 has_width = 0;
4757#endif
4758#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4640 width = 0; 4759 width = 0;
4641 if (dp->width_start != dp->width_end) 4760 if (dp->width_start != dp->width_end)
4642 { 4761 {
@@ -4647,15 +4766,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4647 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 4766 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
4648 abort (); 4767 abort ();
4649 arg = a.arg[dp->width_arg_index].a.a_int; 4768 arg = a.arg[dp->width_arg_index].a.a_int;
4769 width = arg;
4650 if (arg < 0) 4770 if (arg < 0)
4651 { 4771 {
4652 /* "A negative field width is taken as a '-' flag 4772 /* "A negative field width is taken as a '-' flag
4653 followed by a positive field width." */ 4773 followed by a positive field width." */
4654 flags |= FLAG_LEFT; 4774 flags |= FLAG_LEFT;
4655 width = (unsigned int) (-arg); 4775 width = -width;
4656 } 4776 }
4657 else
4658 width = arg;
4659 } 4777 }
4660 else 4778 else
4661 { 4779 {
@@ -4665,11 +4783,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4665 width = xsum (xtimes (width, 10), *digitp++ - '0'); 4783 width = xsum (xtimes (width, 10), *digitp++ - '0');
4666 while (digitp != dp->width_end); 4784 while (digitp != dp->width_end);
4667 } 4785 }
4786#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4668 has_width = 1; 4787 has_width = 1;
4788#endif
4669 } 4789 }
4670#endif 4790#endif
4671 4791
4672#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION 4792#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
4673 has_precision = 0; 4793 has_precision = 0;
4674 precision = 6; 4794 precision = 6;
4675 if (dp->precision_start != dp->precision_end) 4795 if (dp->precision_start != dp->precision_end)
@@ -4805,7 +4925,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4805 { 4925 {
4806 const FCHAR_T *mp = dp->width_start; 4926 const FCHAR_T *mp = dp->width_start;
4807 do 4927 do
4808 *fbp++ = (unsigned char) *mp++; 4928 *fbp++ = *mp++;
4809 while (--n > 0); 4929 while (--n > 0);
4810 } 4930 }
4811 } 4931 }
@@ -4826,7 +4946,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4826 { 4946 {
4827 const FCHAR_T *mp = dp->precision_start; 4947 const FCHAR_T *mp = dp->precision_start;
4828 do 4948 do
4829 *fbp++ = (unsigned char) *mp++; 4949 *fbp++ = *mp++;
4830 while (--n > 0); 4950 while (--n > 0);
4831 } 4951 }
4832 } 4952 }
@@ -4834,19 +4954,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4834 4954
4835 switch (type) 4955 switch (type)
4836 { 4956 {
4837#if HAVE_LONG_LONG_INT
4838 case TYPE_LONGLONGINT: 4957 case TYPE_LONGLONGINT:
4839 case TYPE_ULONGLONGINT: 4958 case TYPE_ULONGLONGINT:
4840# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4959#if defined _WIN32 && ! defined __CYGWIN__
4841 *fbp++ = 'I'; 4960 *fbp++ = 'I';
4842 *fbp++ = '6'; 4961 *fbp++ = '6';
4843 *fbp++ = '4'; 4962 *fbp++ = '4';
4844 break; 4963 break;
4845# else 4964#else
4846 *fbp++ = 'l'; 4965 *fbp++ = 'l';
4847 /*FALLTHROUGH*/
4848# endif
4849#endif 4966#endif
4967 FALLTHROUGH;
4850 case TYPE_LONGINT: 4968 case TYPE_LONGINT:
4851 case TYPE_ULONGINT: 4969 case TYPE_ULONGINT:
4852#if HAVE_WINT_T 4970#if HAVE_WINT_T
@@ -4870,20 +4988,32 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4870#endif 4988#endif
4871 *fbp = dp->conversion; 4989 *fbp = dp->conversion;
4872#if USE_SNPRINTF 4990#if USE_SNPRINTF
4873# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) 4991# if ((HAVE_SNPRINTF_RETVAL_C99 && HAVE_SNPRINTF_TRUNCATION_C99) \
4874 fbp[1] = '%'; 4992 || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
4875 fbp[2] = 'n'; 4993 && !defined __UCLIBC__) \
4876 fbp[3] = '\0'; 4994 || (defined __APPLE__ && defined __MACH__) \
4877# else 4995 || defined __ANDROID__ \
4878 /* On glibc2 systems from glibc >= 2.3 - probably also older 4996 || (defined _WIN32 && ! defined __CYGWIN__))
4879 ones - we know that snprintf's return value conforms to 4997 /* On systems where we know that snprintf's return value
4880 ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and 4998 conforms to ISO C 99 (HAVE_SNPRINTF_RETVAL_C99) and that
4881 gl_SNPRINTF_TRUNCATION_C99 pass. 4999 snprintf always produces NUL-terminated strings
4882 Therefore we can avoid using %n in this situation. 5000 (HAVE_SNPRINTF_TRUNCATION_C99), it is possible to avoid
4883 On glibc2 systems from 2004-10-18 or newer, the use of %n 5001 using %n. And it is desirable to do so, because more and
4884 in format strings in writable memory may crash the program 5002 more platforms no longer support %n, for "security reasons".
4885 (if compiled with _FORTIFY_SOURCE=2), so we should avoid it 5003 In particular, the following platforms:
4886 in this situation. */ 5004 - On glibc2 systems from 2004-10-18 or newer, the use of
5005 %n in format strings in writable memory may crash the
5006 program (if compiled with _FORTIFY_SOURCE=2).
5007 - On Mac OS X 10.13 or newer, the use of %n in format
5008 strings in writable memory by default crashes the
5009 program.
5010 - On Android, starting on 2018-03-07, the use of %n in
5011 format strings produces a fatal error (see
5012 <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>).
5013 On these platforms, HAVE_SNPRINTF_RETVAL_C99 and
5014 HAVE_SNPRINTF_TRUNCATION_C99 are 1. We have listed them
5015 explicitly in the condition above, in case of cross-
5016 compilation (just to be sure). */
4887 /* On native Windows systems (such as mingw), we can avoid using 5017 /* On native Windows systems (such as mingw), we can avoid using
4888 %n because: 5018 %n because:
4889 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, 5019 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
@@ -4896,10 +5026,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4896 On native Windows systems (such as mingw) where the OS is 5026 On native Windows systems (such as mingw) where the OS is
4897 Windows Vista, the use of %n in format strings by default 5027 Windows Vista, the use of %n in format strings by default
4898 crashes the program. See 5028 crashes the program. See
4899 <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and 5029 <https://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
4900 <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx> 5030 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output>
4901 So we should avoid %n in this situation. */ 5031 So we should avoid %n in this situation. */
4902 fbp[1] = '\0'; 5032 fbp[1] = '\0';
5033# else /* AIX <= 5.1, HP-UX, IRIX, OSF/1, Solaris <= 9, BeOS */
5034 fbp[1] = '%';
5035 fbp[2] = 'n';
5036 fbp[3] = '\0';
4903# endif 5037# endif
4904#else 5038#else
4905 fbp[1] = '\0'; 5039 fbp[1] = '\0';
@@ -5043,7 +5177,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5043 SNPRINTF_BUF (arg); 5177 SNPRINTF_BUF (arg);
5044 } 5178 }
5045 break; 5179 break;
5046#if HAVE_LONG_LONG_INT
5047 case TYPE_LONGLONGINT: 5180 case TYPE_LONGLONGINT:
5048 { 5181 {
5049 long long int arg = a.arg[dp->arg_index].a.a_longlongint; 5182 long long int arg = a.arg[dp->arg_index].a.a_longlongint;
@@ -5056,7 +5189,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5056 SNPRINTF_BUF (arg); 5189 SNPRINTF_BUF (arg);
5057 } 5190 }
5058 break; 5191 break;
5059#endif
5060 case TYPE_DOUBLE: 5192 case TYPE_DOUBLE:
5061 { 5193 {
5062 double arg = a.arg[dp->arg_index].a.a_double; 5194 double arg = a.arg[dp->arg_index].a.a_double;
@@ -5116,7 +5248,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5116 { 5248 {
5117 /* Verify that snprintf() has NUL-terminated its 5249 /* Verify that snprintf() has NUL-terminated its
5118 result. */ 5250 result. */
5119 if (count < maxlen 5251 if ((unsigned int) count < maxlen
5120 && ((TCHAR_T *) (result + length)) [count] != '\0') 5252 && ((TCHAR_T *) (result + length)) [count] != '\0')
5121 abort (); 5253 abort ();
5122 /* Portability hack. */ 5254 /* Portability hack. */
@@ -5139,7 +5271,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5139 /* Look at the snprintf() return value. */ 5271 /* Look at the snprintf() return value. */
5140 if (retcount < 0) 5272 if (retcount < 0)
5141 { 5273 {
5142# if !HAVE_SNPRINTF_RETVAL_C99 5274# if !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
5143 /* HP-UX 10.20 snprintf() is doubly deficient: 5275 /* HP-UX 10.20 snprintf() is doubly deficient:
5144 It doesn't understand the '%n' directive, 5276 It doesn't understand the '%n' directive,
5145 *and* it returns -1 (rather than the length 5277 *and* it returns -1 (rather than the length
@@ -5153,7 +5285,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5153 size_t tmp_length = 5285 size_t tmp_length =
5154 MAX_ROOM_NEEDED (&a, dp->arg_index, 5286 MAX_ROOM_NEEDED (&a, dp->arg_index,
5155 dp->conversion, type, flags, 5287 dp->conversion, type, flags,
5156 has_width ? width : 0, 5288 width,
5157 has_precision, 5289 has_precision,
5158 precision, pad_ourselves); 5290 precision, pad_ourselves);
5159 5291
@@ -5188,22 +5320,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5188 /* Attempt to handle failure. */ 5320 /* Attempt to handle failure. */
5189 if (count < 0) 5321 if (count < 0)
5190 { 5322 {
5191 /* SNPRINTF or sprintf failed. Save and use the errno 5323 /* SNPRINTF or sprintf failed. Use the errno that it
5192 that it has set, if any. */ 5324 has set, if any. */
5193 int saved_errno = errno; 5325 if (errno == 0)
5194 5326 {
5195 if (!(result == resultbuf || result == NULL)) 5327 if (dp->conversion == 'c' || dp->conversion == 's')
5196 free (result); 5328 errno = EILSEQ;
5197 if (buf_malloced != NULL) 5329 else
5198 free (buf_malloced); 5330 errno = EINVAL;
5199 CLEANUP (); 5331 }
5200 errno = 5332
5201 (saved_errno != 0 5333 goto fail_with_errno;
5202 ? saved_errno
5203 : (dp->conversion == 'c' || dp->conversion == 's'
5204 ? EILSEQ
5205 : EINVAL));
5206 return NULL;
5207 } 5334 }
5208 5335
5209#if USE_SNPRINTF 5336#if USE_SNPRINTF
@@ -5324,7 +5451,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5324 DCHAR_T *tmpdst; 5451 DCHAR_T *tmpdst;
5325 size_t tmpdst_len; 5452 size_t tmpdst_len;
5326 /* This code assumes that TCHAR_T is 'char'. */ 5453 /* This code assumes that TCHAR_T is 'char'. */
5327 verify (sizeof (TCHAR_T) == 1); 5454 static_assert (sizeof (TCHAR_T) == 1);
5328# if USE_SNPRINTF 5455# if USE_SNPRINTF
5329 tmpsrc = (TCHAR_T *) (result + length); 5456 tmpsrc = (TCHAR_T *) (result + length);
5330# else 5457# else
@@ -5337,17 +5464,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5337 NULL, 5464 NULL,
5338 NULL, &tmpdst_len); 5465 NULL, &tmpdst_len);
5339 if (tmpdst == NULL) 5466 if (tmpdst == NULL)
5340 { 5467 goto fail_with_errno;
5341 int saved_errno = errno; 5468 ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
5342 if (!(result == resultbuf || result == NULL)) 5469 { free (tmpdst); goto out_of_memory; });
5343 free (result);
5344 if (buf_malloced != NULL)
5345 free (buf_malloced);
5346 CLEANUP ();
5347 errno = saved_errno;
5348 return NULL;
5349 }
5350 ENSURE_ALLOCATION (xsum (length, tmpdst_len));
5351 DCHAR_CPY (result + length, tmpdst, tmpdst_len); 5470 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
5352 free (tmpdst); 5471 free (tmpdst);
5353 count = tmpdst_len; 5472 count = tmpdst_len;
@@ -5391,7 +5510,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5391 tmpsrc += count; 5510 tmpsrc += count;
5392 tmpdst += count; 5511 tmpdst += count;
5393 for (n = count; n > 0; n--) 5512 for (n = count; n > 0; n--)
5394 *--tmpdst = (unsigned char) *--tmpsrc; 5513 *--tmpdst = *--tmpsrc;
5395 } 5514 }
5396 } 5515 }
5397#endif 5516#endif
@@ -5570,25 +5689,40 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5570 5689
5571#if USE_SNPRINTF 5690#if USE_SNPRINTF
5572 overflow: 5691 overflow:
5573 if (!(result == resultbuf || result == NULL))
5574 free (result);
5575 if (buf_malloced != NULL)
5576 free (buf_malloced);
5577 CLEANUP ();
5578 errno = EOVERFLOW; 5692 errno = EOVERFLOW;
5579 return NULL; 5693 goto fail_with_errno;
5580#endif 5694#endif
5581 5695
5582 out_of_memory: 5696 out_of_memory:
5583 if (!(result == resultbuf || result == NULL)) 5697 errno = ENOMEM;
5698 goto fail_with_errno;
5699
5700#if ENABLE_UNISTDIO || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL) || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T)
5701 fail_with_EILSEQ:
5702 errno = EILSEQ;
5703 goto fail_with_errno;
5704#endif
5705
5706 fail_with_errno:
5707 if (result != resultbuf)
5584 free (result); 5708 free (result);
5585 if (buf_malloced != NULL) 5709 if (buf_malloced != NULL)
5586 free (buf_malloced); 5710 free (buf_malloced);
5587 out_of_memory_1:
5588 CLEANUP (); 5711 CLEANUP ();
5589 errno = ENOMEM;
5590 return NULL; 5712 return NULL;
5591 } 5713 }
5714
5715 out_of_memory_1:
5716 errno = ENOMEM;
5717 goto fail_1_with_errno;
5718
5719 fail_1_with_EINVAL:
5720 errno = EINVAL;
5721 goto fail_1_with_errno;
5722
5723 fail_1_with_errno:
5724 CLEANUP ();
5725 return NULL;
5592} 5726}
5593 5727
5594#undef MAX_ROOM_NEEDED 5728#undef MAX_ROOM_NEEDED
diff --git a/gl/vasnprintf.h b/gl/vasnprintf.h
index 7658f50..f69649f 100644
--- a/gl/vasnprintf.h
+++ b/gl/vasnprintf.h
@@ -1,18 +1,18 @@
1/* vsprintf with automatic memory allocation. 1/* vsprintf with automatic memory allocation.
2 Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc. 2 Copyright (C) 2002-2004, 2007-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#ifndef _VASNPRINTF_H 17#ifndef _VASNPRINTF_H
18#define _VASNPRINTF_H 18#define _VASNPRINTF_H
@@ -23,17 +23,8 @@
23/* Get size_t. */ 23/* Get size_t. */
24#include <stddef.h> 24#include <stddef.h>
25 25
26/* The __attribute__ feature is available in gcc versions 2.5 and later. 26/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
27 The __-protected variants of the attributes 'format' and 'printf' are 27#include <stdio.h>
28 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
29 We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
30 gnulib and libintl do '#define printf __printf__' when they override
31 the 'printf' function. */
32#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
33# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
34#else
35# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
36#endif
37 28
38#ifdef __cplusplus 29#ifdef __cplusplus
39extern "C" { 30extern "C" {
@@ -67,10 +58,12 @@ extern "C" {
67# define asnprintf rpl_asnprintf 58# define asnprintf rpl_asnprintf
68# define vasnprintf rpl_vasnprintf 59# define vasnprintf rpl_vasnprintf
69#endif 60#endif
70extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) 61extern char * asnprintf (char *restrict resultbuf, size_t *lengthp,
71 _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); 62 const char *format, ...)
72extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) 63 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4));
73 _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); 64extern char * vasnprintf (char *restrict resultbuf, size_t *lengthp,
65 const char *format, va_list args)
66 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0));
74 67
75#ifdef __cplusplus 68#ifdef __cplusplus
76} 69}
diff --git a/gl/vasprintf.c b/gl/vasprintf.c
index d0d4a11..d2878cd 100644
--- a/gl/vasprintf.c
+++ b/gl/vasprintf.c
@@ -1,18 +1,18 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006-2013 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002, 2006-2023 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This file 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 Lesser General Public License as
6 the Free Software Foundation; either version 3, or (at your option) 6 published by the Free Software Foundation; either version 2.1 of the
7 any later version. 7 License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This file 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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU Lesser General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License along 14 You should have received a copy of the GNU Lesser General Public License
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16 16
17#include <config.h> 17#include <config.h>
18 18
diff --git a/gl/verify.h b/gl/verify.h
index d42d075..b63cb26 100644
--- a/gl/verify.h
+++ b/gl/verify.h
@@ -1,19 +1,19 @@
1/* Compile-time assert-like macros. 1/* Compile-time assert-like macros.
2 2
3 Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2009-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ 18/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
19 19
@@ -21,31 +21,32 @@
21#define _GL_VERIFY_H 21#define _GL_VERIFY_H
22 22
23 23
24/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. 24/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
25 This is supported by GCC 4.6.0 and later, in C mode, and its use 25 works as per C11. This is supported by GCC 4.6.0+ and by clang 4+.
26 here generates easier-to-read diagnostics when verify (R) fails.
27 26
28 Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11. 27 Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
29 This will likely be supported by future GCC versions, in C++ mode. 28 per C23. This is supported by GCC 9.1+.
30 29
31 Use this only with GCC. If we were willing to slow 'configure' 30 Support compilers claiming conformance to the relevant standard,
32 down we could also use it with other compilers, but since this 31 and also support GCC when not pedantic. If we were willing to slow
33 affects only the quality of diagnostics, why bother? */ 32 'configure' down we could also use it with other compilers, but
34#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ 33 since this affects only the quality of diagnostics, why bother? */
35 && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ 34#ifndef __cplusplus
36 && !defined __cplusplus) 35# if (201112 <= __STDC_VERSION__ \
37# define _GL_HAVE__STATIC_ASSERT 1 36 || (!defined __STRICT_ANSI__ \
38#endif 37 && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 5 <= __clang_major__)))
39/* The condition (99 < __GNUC__) is temporary, until we know about the 38# define _GL_HAVE__STATIC_ASSERT 1
40 first G++ release that supports static_assert. */ 39# endif
41#if (99 < __GNUC__) && defined __cplusplus 40# if (202311 <= __STDC_VERSION__ \
42# define _GL_HAVE_STATIC_ASSERT 1 41 || (!defined __STRICT_ANSI__ && 9 <= __GNUC__))
42# define _GL_HAVE__STATIC_ASSERT1 1
43# endif
43#endif 44#endif
44 45
45/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other 46/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
46 system headers, defines a conflicting _Static_assert that is no 47 system headers, defines a conflicting _Static_assert that is no
47 better than ours; override it. */ 48 better than ours; override it. */
48#ifndef _GL_HAVE_STATIC_ASSERT 49#ifndef _GL_HAVE__STATIC_ASSERT
49# include <stddef.h> 50# include <stddef.h>
50# undef _Static_assert 51# undef _Static_assert
51#endif 52#endif
@@ -143,9 +144,9 @@
143 which do not support _Static_assert, also do not warn about the 144 which do not support _Static_assert, also do not warn about the
144 last declaration mentioned above. 145 last declaration mentioned above.
145 146
146 * GCC warns if -Wnested-externs is enabled and verify() is used 147 * GCC warns if -Wnested-externs is enabled and 'verify' is used
147 within a function body; but inside a function, you can always 148 within a function body; but inside a function, you can always
148 arrange to use verify_expr() instead. 149 arrange to use verify_expr instead.
149 150
150 * In C++, any struct definition inside sizeof is invalid. 151 * In C++, any struct definition inside sizeof is invalid.
151 Use a template type to work around the problem. */ 152 Use a template type to work around the problem. */
@@ -197,48 +198,95 @@ template <int w>
197#endif 198#endif
198 199
199/* Verify requirement R at compile-time, as a declaration without a 200/* Verify requirement R at compile-time, as a declaration without a
200 trailing ';'. If R is false, fail at compile-time, preferably 201 trailing ';'. If R is false, fail at compile-time.
201 with a diagnostic that includes the string-literal DIAGNOSTIC. 202
203 This macro requires three or more arguments but uses at most the first
204 two, so that the _Static_assert macro optionally defined below supports
205 both the C11 two-argument syntax and the C23 one-argument syntax.
202 206
203 Unfortunately, unlike C11, this implementation must appear as an 207 Unfortunately, unlike C11, this implementation must appear as an
204 ordinary declaration, and cannot appear inside struct { ... }. */ 208 ordinary declaration, and cannot appear inside struct { ... }. */
205 209
206#ifdef _GL_HAVE__STATIC_ASSERT 210#if 202311 <= __STDC_VERSION__ || 200410 <= __cpp_static_assert
207# define _GL_VERIFY _Static_assert 211# define _GL_VERIFY(R, DIAGNOSTIC, ...) static_assert (R, DIAGNOSTIC)
212#elif defined _GL_HAVE__STATIC_ASSERT
213# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
208#else 214#else
209# define _GL_VERIFY(R, DIAGNOSTIC) \ 215# define _GL_VERIFY(R, DIAGNOSTIC, ...) \
210 extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ 216 extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
211 [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] 217 [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
218# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
219# pragma GCC diagnostic ignored "-Wnested-externs"
220# endif
212#endif 221#endif
213 222
214/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ 223/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
215#ifdef _GL_STATIC_ASSERT_H 224#ifdef _GL_STATIC_ASSERT_H
216# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert 225# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
217# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) 226# if !defined _MSC_VER || defined __clang__
227# define _Static_assert(...) \
228 _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
229# else
230 /* Work around MSVC preprocessor incompatibility with ISO C; see
231 <https://stackoverflow.com/questions/5134523/>. */
232# define _Static_assert(R, ...) \
233 _GL_VERIFY ((R), "static assertion failed", -)
234# endif
218# endif 235# endif
219# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert 236# if (!defined static_assert \
220# define static_assert _Static_assert /* C11 requires this #define. */ 237 && __STDC_VERSION__ < 202311 \
238 && (!defined __cplusplus \
239 || (__cpp_static_assert < 201411 \
240 && __GNUG__ < 6 && __clang_major__ < 6)))
241# if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
242/* MSVC 14 in C++ mode supports the two-arguments static_assert but not
243 the one-argument static_assert, and it does not support _Static_assert.
244 We have to play preprocessor tricks to distinguish the two cases.
245 Since the MSVC preprocessor is not ISO C compliant (see above),.
246 the solution is specific to MSVC. */
247# define _GL_EXPAND(x) x
248# define _GL_SA1(a1) static_assert ((a1), "static assertion failed")
249# define _GL_SA2 static_assert
250# define _GL_SA3 static_assert
251# define _GL_SA_PICK(x1,x2,x3,x4,...) x4
252# define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__)
253# else
254# define static_assert _Static_assert /* C11 requires this #define. */
255# endif
221# endif 256# endif
222#endif 257#endif
223 258
224/* @assert.h omit start@ */ 259/* @assert.h omit start@ */
225 260
261#if defined __clang_major__ && __clang_major__ < 5
262# define _GL_HAS_BUILTIN_TRAP 0
263#elif 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
264# define _GL_HAS_BUILTIN_TRAP 1
265#elif defined __has_builtin
266# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap)
267#else
268# define _GL_HAS_BUILTIN_TRAP 0
269#endif
270
271#if defined __clang_major__ && __clang_major__ < 5
272# define _GL_HAS_BUILTIN_UNREACHABLE 0
273#elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
274# define _GL_HAS_BUILTIN_UNREACHABLE 1
275#elif defined __has_builtin
276# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
277#else
278# define _GL_HAS_BUILTIN_UNREACHABLE 0
279#endif
280
226/* Each of these macros verifies that its argument R is nonzero. To 281/* Each of these macros verifies that its argument R is nonzero. To
227 be portable, R should be an integer constant expression. Unlike 282 be portable, R should be an integer constant expression. Unlike
228 assert (R), there is no run-time overhead. 283 assert (R), there is no run-time overhead.
229 284
230 There are two macros, since no single macro can be used in all 285 There are two macros, since no single macro can be used in all
231 contexts in C. verify_true (R) is for scalar contexts, including 286 contexts in C. verify_expr (R, E) is for scalar contexts, including
232 integer constant expression contexts. verify (R) is for declaration 287 integer constant expression contexts. verify (R) is for declaration
233 contexts, e.g., the top level. */ 288 contexts, e.g., the top level. */
234 289
235/* Verify requirement R at compile-time, as an integer constant expression.
236 Return 1. This is equivalent to verify_expr (R, 1).
237
238 verify_true is obsolescent; please use verify_expr instead. */
239
240#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
241
242/* Verify requirement R at compile-time. Return the value of the 290/* Verify requirement R at compile-time. Return the value of the
243 expression E. */ 291 expression E. */
244 292
@@ -246,9 +294,56 @@ template <int w>
246 (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) 294 (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
247 295
248/* Verify requirement R at compile-time, as a declaration without a 296/* Verify requirement R at compile-time, as a declaration without a
249 trailing ';'. */ 297 trailing ';'. verify (R) acts like static_assert (R) except that
298 it is portable to C11/C++14 and earlier, it can issue better
299 diagnostics, and its name is shorter and may be more convenient. */
300
301#ifdef __PGI
302/* PGI barfs if R is long. */
303# define verify(R) _GL_VERIFY (R, "verify (...)", -)
304#else
305# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -)
306#endif
250 307
251#define verify(R) _GL_VERIFY (R, "verify (" #R ")") 308/* Assume that R always holds. Behavior is undefined if R is false,
309 fails to evaluate, or has side effects.
310
311 'assume (R)' is a directive from the programmer telling the
312 compiler that R is true so the compiler needn't generate code to
313 test R. This is why 'assume' is in verify.h: it's related to
314 static checking (in this case, static checking done by the
315 programmer), not dynamic checking.
316
317 'assume (R)' can affect compilation of all the code, not just code
318 that happens to be executed after the assume (R) is "executed".
319 For example, if the code mistakenly does 'assert (R); assume (R);'
320 the compiler is entitled to optimize away the 'assert (R)'.
321
322 Although assuming R can help a compiler generate better code or
323 diagnostics, performance can suffer if R uses hard-to-optimize
324 features such as function calls not inlined by the compiler.
325
326 Avoid Clang's __builtin_assume, as it breaks GNU Emacs master
327 as of 2020-08-23T21:09:49Z!eggert@cs.ucla.edu; see
328 <https://bugs.gnu.org/43152#71>. It's not known whether this breakage
329 is a Clang bug or an Emacs bug; play it safe for now. */
330
331#if _GL_HAS_BUILTIN_UNREACHABLE
332# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
333#elif 1200 <= _MSC_VER
334# define assume(R) __assume (R)
335#elif 202311 <= __STDC_VERSION__
336# include <stddef.h>
337# define assume(R) ((R) ? (void) 0 : unreachable ())
338#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
339 /* Doing it this way helps various packages when configured with
340 --enable-gcc-warnings, which compiles with -Dlint. It's nicer
341 if 'assume' silences warnings with GCC 3.4 through GCC 4.4.7 (2012). */
342# define assume(R) ((R) ? (void) 0 : __builtin_trap ())
343#else
344 /* Some older tools grok NOTREACHED, e.g., Oracle Studio 12.6 (2017). */
345# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
346#endif
252 347
253/* @assert.h omit end@ */ 348/* @assert.h omit end@ */
254 349
diff --git a/gl/vsnprintf.c b/gl/vsnprintf.c
index 7d4dfbe..acd4e2d 100644
--- a/gl/vsnprintf.c
+++ b/gl/vsnprintf.c
@@ -1,19 +1,19 @@
1/* Formatted output to strings. 1/* Formatted output to strings.
2 Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2006-2023 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 file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifdef HAVE_CONFIG_H 18#ifdef HAVE_CONFIG_H
19# include <config.h> 19# include <config.h>
diff --git a/gl/w32sock.h b/gl/w32sock.h
index 44f3a1a..84e46e3 100644
--- a/gl/w32sock.h
+++ b/gl/w32sock.h
@@ -1,19 +1,19 @@
1/* w32sock.h --- internal auxiliary functions for Windows socket functions 1/* w32sock.h --- internal auxiliary functions for Windows socket functions
2 2
3 Copyright (C) 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Paolo Bonzini */ 18/* Written by Paolo Bonzini */
19 19
@@ -26,7 +26,11 @@
26#include <io.h> 26#include <io.h>
27 27
28/* Get _get_osfhandle(). */ 28/* Get _get_osfhandle(). */
29#include "msvc-nothrow.h" 29#if GNULIB_MSVC_NOTHROW
30# include "msvc-nothrow.h"
31#else
32# include <io.h>
33#endif
30 34
31#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd))) 35#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd)))
32#define SOCKET_TO_FD(fh) (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY)) 36#define SOCKET_TO_FD(fh) (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY))
diff --git a/gl/warn-on-use.h b/gl/warn-on-use.h
new file mode 100644
index 0000000..3075603
--- /dev/null
+++ b/gl/warn-on-use.h
@@ -0,0 +1,149 @@
1/* A C macro for emitting warnings if a function is used.
2 Copyright (C) 2010-2023 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
18 for FUNCTION which will then trigger a compiler warning containing
19 the text of "literal string" anywhere that function is called, if
20 supported by the compiler. If the compiler does not support this
21 feature, the macro expands to an unused extern declaration.
22
23 _GL_WARN_ON_USE_ATTRIBUTE ("literal string") expands to the
24 attribute used in _GL_WARN_ON_USE. If the compiler does not support
25 this feature, it expands to empty.
26
27 These macros are useful for marking a function as a potential
28 portability trap, with the intent that "literal string" include
29 instructions on the replacement function that should be used
30 instead.
31 _GL_WARN_ON_USE is for functions with 'extern' linkage.
32 _GL_WARN_ON_USE_ATTRIBUTE is for functions with 'static' or 'inline'
33 linkage.
34
35 However, one of the reasons that a function is a portability trap is
36 if it has the wrong signature. Declaring FUNCTION with a different
37 signature in C is a compilation error, so this macro must use the
38 same type as any existing declaration so that programs that avoid
39 the problematic FUNCTION do not fail to compile merely because they
40 included a header that poisoned the function. But this implies that
41 _GL_WARN_ON_USE is only safe to use if FUNCTION is known to already
42 have a declaration. Use of this macro implies that there must not
43 be any other macro hiding the declaration of FUNCTION; but
44 undefining FUNCTION first is part of the poisoning process anyway
45 (although for symbols that are provided only via a macro, the result
46 is a compilation error rather than a warning containing
47 "literal string"). Also note that in C++, it is only safe to use if
48 FUNCTION has no overloads.
49
50 For an example, it is possible to poison 'getline' by:
51 - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
52 [getline]) in configure.ac, which potentially defines
53 HAVE_RAW_DECL_GETLINE
54 - adding this code to a header that wraps the system <stdio.h>:
55 #undef getline
56 #if HAVE_RAW_DECL_GETLINE
57 _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
58 "not universally present; use the gnulib module getline");
59 #endif
60
61 It is not possible to directly poison global variables. But it is
62 possible to write a wrapper accessor function, and poison that
63 (less common usage, like &environ, will cause a compilation error
64 rather than issue the nice warning, but the end result of informing
65 the developer about their portability problem is still achieved):
66 #if HAVE_RAW_DECL_ENVIRON
67 static char ***
68 rpl_environ (void) { return &environ; }
69 _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
70 # undef environ
71 # define environ (*rpl_environ ())
72 #endif
73 or better (avoiding contradictory use of 'static' and 'extern'):
74 #if HAVE_RAW_DECL_ENVIRON
75 static char ***
76 _GL_WARN_ON_USE_ATTRIBUTE ("environ is not always properly declared")
77 rpl_environ (void) { return &environ; }
78 # undef environ
79 # define environ (*rpl_environ ())
80 #endif
81 */
82#ifndef _GL_WARN_ON_USE
83
84# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
85/* A compiler attribute is available in gcc versions 4.3.0 and later. */
86# define _GL_WARN_ON_USE(function, message) \
87_GL_WARN_EXTERN_C __typeof__ (function) function __attribute__ ((__warning__ (message)))
88# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
89 __attribute__ ((__warning__ (message)))
90# elif __clang_major__ >= 4
91/* Another compiler attribute is available in clang. */
92# define _GL_WARN_ON_USE(function, message) \
93_GL_WARN_EXTERN_C __typeof__ (function) function \
94 __attribute__ ((__diagnose_if__ (1, message, "warning")))
95# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
96 __attribute__ ((__diagnose_if__ (1, message, "warning")))
97# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
98/* Verify the existence of the function. */
99# define _GL_WARN_ON_USE(function, message) \
100_GL_WARN_EXTERN_C __typeof__ (function) function
101# define _GL_WARN_ON_USE_ATTRIBUTE(message)
102# else /* Unsupported. */
103# define _GL_WARN_ON_USE(function, message) \
104_GL_WARN_EXTERN_C int _gl_warn_on_use
105# define _GL_WARN_ON_USE_ATTRIBUTE(message)
106# endif
107#endif
108
109/* _GL_WARN_ON_USE_CXX (function, rettype_gcc, rettype_clang, parameters_and_attributes, "message")
110 is like _GL_WARN_ON_USE (function, "message"), except that in C++ mode the
111 function is declared with the given prototype, consisting of return type,
112 parameters, and attributes.
113 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
114 not work in this case. */
115#ifndef _GL_WARN_ON_USE_CXX
116# if !defined __cplusplus
117# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
118 _GL_WARN_ON_USE (function, msg)
119# else
120# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
121/* A compiler attribute is available in gcc versions 4.3.0 and later. */
122# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
123extern rettype_gcc function parameters_and_attributes \
124 __attribute__ ((__warning__ (msg)))
125# elif __clang_major__ >= 4
126/* Another compiler attribute is available in clang. */
127# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
128extern rettype_clang function parameters_and_attributes \
129 __attribute__ ((__diagnose_if__ (1, msg, "warning")))
130# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
131/* Verify the existence of the function. */
132# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
133extern rettype_gcc function parameters_and_attributes
134# else /* Unsupported. */
135# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
136_GL_WARN_EXTERN_C int _gl_warn_on_use
137# endif
138# endif
139#endif
140
141/* _GL_WARN_EXTERN_C declaration;
142 performs the declaration with C linkage. */
143#ifndef _GL_WARN_EXTERN_C
144# if defined __cplusplus
145# define _GL_WARN_EXTERN_C extern "C"
146# else
147# define _GL_WARN_EXTERN_C extern
148# endif
149#endif
diff --git a/gl/wchar.in.h b/gl/wchar.in.h
index b6e4362..09c9185 100644
--- a/gl/wchar.in.h
+++ b/gl/wchar.in.h
@@ -1,25 +1,25 @@
1/* A substitute for ISO C99 <wchar.h>, for platforms that have issues. 1/* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
2 2
3 Copyright (C) 2007-2013 Free Software Foundation, Inc. 3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Eric Blake. */ 18/* Written by Eric Blake. */
19 19
20/* 20/*
21 * ISO C 99 <wchar.h> for platforms that have issues. 21 * ISO C 99 <wchar.h> for platforms that have issues.
22 * <http://www.opengroup.org/susv3xbd/wchar.h.html> 22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/wchar.h.html>
23 * 23 *
24 * For now, this just ensures proper prerequisite inclusion order and 24 * For now, this just ensures proper prerequisite inclusion order and
25 * the declaration of wcwidth(). 25 * the declaration of wcwidth().
@@ -30,15 +30,24 @@
30#endif 30#endif
31@PRAGMA_COLUMNS@ 31@PRAGMA_COLUMNS@
32 32
33#if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H 33#if (((defined __need_mbstate_t || defined __need_wint_t) \
34 && !defined __MINGW32__) \
35 || (defined __hpux \
36 && ((defined _INTTYPES_INCLUDED \
37 && !defined _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H) \
38 || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) \
39 || (defined __MINGW32__ && defined __STRING_H_SOURCED__) \
40 || defined _GL_ALREADY_INCLUDING_WCHAR_H)
34/* Special invocation convention: 41/* Special invocation convention:
35 - Inside glibc and uClibc header files. 42 - Inside glibc and uClibc header files, but not MinGW.
36 - On HP-UX 11.00 we have a sequence of nested includes 43 - On HP-UX 11.00 we have a sequence of nested includes
37 <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>, 44 <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
38 once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h> 45 once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
39 and once directly. In both situations 'wint_t' is not yet defined, 46 and once directly. In both situations 'wint_t' is not yet defined,
40 therefore we cannot provide the function overrides; instead include only 47 therefore we cannot provide the function overrides; instead include only
41 the system's <wchar.h>. 48 the system's <wchar.h>.
49 - With MinGW 3.22, when <string.h> includes <wchar.h>, only some part of
50 <wchar.h> is actually processed, and that doesn't include 'mbstate_t'.
42 - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and 51 - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
43 the latter includes <wchar.h>. But here, we have no way to detect whether 52 the latter includes <wchar.h>. But here, we have no way to detect whether
44 <wctype.h> is completely included or is still being included. */ 53 <wctype.h> is completely included or is still being included. */
@@ -56,20 +65,12 @@
56# include <features.h> /* for __GLIBC__ */ 65# include <features.h> /* for __GLIBC__ */
57#endif 66#endif
58 67
59/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before 68/* In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
60 <wchar.h>.
61 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
62 included before <wchar.h>.
63 In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
64 by <stddef.h>. 69 by <stddef.h>.
65 But avoid namespace pollution on glibc systems. */ 70 But avoid namespace pollution on glibc systems. */
66#if !(defined __GLIBC__ && !defined __UCLIBC__) 71#if !(defined __GLIBC__ && !defined __UCLIBC__)
67# include <stddef.h> 72# include <stddef.h>
68#endif 73#endif
69#ifndef __GLIBC__
70# include <stdio.h>
71# include <time.h>
72#endif
73 74
74/* Include the original <wchar.h> if it exists. 75/* Include the original <wchar.h> if it exists.
75 Some builds of uClibc lack it. */ 76 Some builds of uClibc lack it. */
@@ -83,12 +84,50 @@
83#ifndef _@GUARD_PREFIX@_WCHAR_H 84#ifndef _@GUARD_PREFIX@_WCHAR_H
84#define _@GUARD_PREFIX@_WCHAR_H 85#define _@GUARD_PREFIX@_WCHAR_H
85 86
87/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
88 that can be freed by passing them as the Ith argument to the
89 function F. */
90#ifndef _GL_ATTRIBUTE_DEALLOC
91# if __GNUC__ >= 11
92# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
93# else
94# define _GL_ATTRIBUTE_DEALLOC(f, i)
95# endif
96#endif
97
98/* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
99 can be freed via 'free'; it can be used only after declaring 'free'. */
100/* Applies to: functions. Cannot be used on inline functions. */
101#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
102# if defined __cplusplus && defined __GNUC__ && !defined __clang__
103/* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
104# define _GL_ATTRIBUTE_DEALLOC_FREE \
105 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
106# else
107# define _GL_ATTRIBUTE_DEALLOC_FREE \
108 _GL_ATTRIBUTE_DEALLOC (free, 1)
109# endif
110#endif
111
112/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
113 allocated memory. */
114/* Applies to: functions. */
115#ifndef _GL_ATTRIBUTE_MALLOC
116# if __GNUC__ >= 3 || defined __clang__
117# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
118# else
119# define _GL_ATTRIBUTE_MALLOC
120# endif
121#endif
122
86/* The __attribute__ feature is available in gcc versions 2.5 and later. 123/* The __attribute__ feature is available in gcc versions 2.5 and later.
87 The attribute __pure__ was added in gcc 2.96. */ 124 The attribute __pure__ was added in gcc 2.96. */
88#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 125#ifndef _GL_ATTRIBUTE_PURE
89# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 126# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
90#else 127# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
91# define _GL_ATTRIBUTE_PURE /* empty */ 128# else
129# define _GL_ATTRIBUTE_PURE /* empty */
130# endif
92#endif 131#endif
93 132
94/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 133/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
@@ -105,12 +144,16 @@
105# define WEOF -1 144# define WEOF -1
106# endif 145# endif
107#else 146#else
108/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>. 147/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h> or
109 This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be 148 <stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
110 "unchanged by default argument promotions". Override it. */ 149 wint_t must be "unchanged by default argument promotions". Override it. */
111# if defined _MSC_VER 150# if @GNULIBHEADERS_OVERRIDE_WINT_T@
112# if !GNULIB_defined_wint_t 151# if !GNULIB_defined_wint_t
113# include <crtdefs.h> 152# if @HAVE_CRTDEFS_H@
153# include <crtdefs.h>
154# else
155# include <stddef.h>
156# endif
114typedef unsigned int rpl_wint_t; 157typedef unsigned int rpl_wint_t;
115# undef wint_t 158# undef wint_t
116# define wint_t rpl_wint_t 159# define wint_t rpl_wint_t
@@ -125,16 +168,59 @@ typedef unsigned int rpl_wint_t;
125 168
126/* Override mbstate_t if it is too small. 169/* Override mbstate_t if it is too small.
127 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for 170 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
128 implementing mbrtowc for encodings like UTF-8. */ 171 implementing mbrtowc for encodings like UTF-8.
129#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@ 172 On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
173 large enough and overriding it would cause problems in C++ mode. */
174#if !(((defined _WIN32 && !defined __CYGWIN__) || @HAVE_MBSINIT@) && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
130# if !GNULIB_defined_mbstate_t 175# if !GNULIB_defined_mbstate_t
176# if !(defined _AIX || defined _MSC_VER)
131typedef int rpl_mbstate_t; 177typedef int rpl_mbstate_t;
132# undef mbstate_t 178# undef mbstate_t
133# define mbstate_t rpl_mbstate_t 179# define mbstate_t rpl_mbstate_t
180# endif
134# define GNULIB_defined_mbstate_t 1 181# define GNULIB_defined_mbstate_t 1
135# endif 182# endif
136#endif 183#endif
137 184
185/* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
186 been included yet. */
187#if @GNULIB_FREE_POSIX@
188# if (@REPLACE_FREE@ && !defined free \
189 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
190/* We can't do '#define free rpl_free' here. */
191_GL_EXTERN_C void rpl_free (void *);
192# undef _GL_ATTRIBUTE_DEALLOC_FREE
193# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
194# else
195# if defined _MSC_VER && !defined free
196_GL_EXTERN_C
197# if defined _DLL
198 __declspec (dllimport)
199# endif
200 void __cdecl free (void *);
201# else
202# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
203_GL_EXTERN_C void free (void *) throw ();
204# else
205_GL_EXTERN_C void free (void *);
206# endif
207# endif
208# endif
209#else
210# if defined _MSC_VER && !defined free
211_GL_EXTERN_C
212# if defined _DLL
213 __declspec (dllimport)
214# endif
215 void __cdecl free (void *);
216# else
217# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
218_GL_EXTERN_C void free (void *) throw ();
219# else
220_GL_EXTERN_C void free (void *);
221# endif
222# endif
223#endif
138 224
139/* Convert a single-byte character to a wide character. */ 225/* Convert a single-byte character to a wide character. */
140#if @GNULIB_BTOWC@ 226#if @GNULIB_BTOWC@
@@ -149,9 +235,12 @@ _GL_CXXALIAS_RPL (btowc, wint_t, (int c));
149# if !@HAVE_BTOWC@ 235# if !@HAVE_BTOWC@
150_GL_FUNCDECL_SYS (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE); 236_GL_FUNCDECL_SYS (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE);
151# endif 237# endif
152_GL_CXXALIAS_SYS (btowc, wint_t, (int c)); 238/* Need to cast, because on mingw, the return type is 'unsigned short'. */
239_GL_CXXALIAS_SYS_CAST (btowc, wint_t, (int c));
153# endif 240# endif
241# if __GLIBC__ >= 2
154_GL_CXXALIASWARN (btowc); 242_GL_CXXALIASWARN (btowc);
243# endif
155#elif defined GNULIB_POSIXCHECK 244#elif defined GNULIB_POSIXCHECK
156# undef btowc 245# undef btowc
157# if HAVE_RAW_DECL_BTOWC 246# if HAVE_RAW_DECL_BTOWC
@@ -177,7 +266,9 @@ _GL_FUNCDECL_SYS (wctob, int, (wint_t wc) _GL_ATTRIBUTE_PURE);
177# endif 266# endif
178_GL_CXXALIAS_SYS (wctob, int, (wint_t wc)); 267_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
179# endif 268# endif
269# if __GLIBC__ >= 2
180_GL_CXXALIASWARN (wctob); 270_GL_CXXALIASWARN (wctob);
271# endif
181#elif defined GNULIB_POSIXCHECK 272#elif defined GNULIB_POSIXCHECK
182# undef wctob 273# undef wctob
183# if HAVE_RAW_DECL_WCTOB 274# if HAVE_RAW_DECL_WCTOB
@@ -202,7 +293,9 @@ _GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
202# endif 293# endif
203_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps)); 294_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
204# endif 295# endif
296# if __GLIBC__ >= 2
205_GL_CXXALIASWARN (mbsinit); 297_GL_CXXALIASWARN (mbsinit);
298# endif
206#elif defined GNULIB_POSIXCHECK 299#elif defined GNULIB_POSIXCHECK
207# undef mbsinit 300# undef mbsinit
208# if HAVE_RAW_DECL_MBSINIT 301# if HAVE_RAW_DECL_MBSINIT
@@ -220,18 +313,24 @@ _GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
220# define mbrtowc rpl_mbrtowc 313# define mbrtowc rpl_mbrtowc
221# endif 314# endif
222_GL_FUNCDECL_RPL (mbrtowc, size_t, 315_GL_FUNCDECL_RPL (mbrtowc, size_t,
223 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 316 (wchar_t *restrict pwc, const char *restrict s, size_t n,
317 mbstate_t *restrict ps));
224_GL_CXXALIAS_RPL (mbrtowc, size_t, 318_GL_CXXALIAS_RPL (mbrtowc, size_t,
225 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 319 (wchar_t *restrict pwc, const char *restrict s, size_t n,
320 mbstate_t *restrict ps));
226# else 321# else
227# if !@HAVE_MBRTOWC@ 322# if !@HAVE_MBRTOWC@
228_GL_FUNCDECL_SYS (mbrtowc, size_t, 323_GL_FUNCDECL_SYS (mbrtowc, size_t,
229 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 324 (wchar_t *restrict pwc, const char *restrict s, size_t n,
325 mbstate_t *restrict ps));
230# endif 326# endif
231_GL_CXXALIAS_SYS (mbrtowc, size_t, 327_GL_CXXALIAS_SYS (mbrtowc, size_t,
232 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 328 (wchar_t *restrict pwc, const char *restrict s, size_t n,
329 mbstate_t *restrict ps));
233# endif 330# endif
331# if __GLIBC__ >= 2
234_GL_CXXALIASWARN (mbrtowc); 332_GL_CXXALIASWARN (mbrtowc);
333# endif
235#elif defined GNULIB_POSIXCHECK 334#elif defined GNULIB_POSIXCHECK
236# undef mbrtowc 335# undef mbrtowc
237# if HAVE_RAW_DECL_MBRTOWC 336# if HAVE_RAW_DECL_MBRTOWC
@@ -248,15 +347,21 @@ _GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
248# undef mbrlen 347# undef mbrlen
249# define mbrlen rpl_mbrlen 348# define mbrlen rpl_mbrlen
250# endif 349# endif
251_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 350_GL_FUNCDECL_RPL (mbrlen, size_t,
252_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 351 (const char *restrict s, size_t n, mbstate_t *restrict ps));
352_GL_CXXALIAS_RPL (mbrlen, size_t,
353 (const char *restrict s, size_t n, mbstate_t *restrict ps));
253# else 354# else
254# if !@HAVE_MBRLEN@ 355# if !@HAVE_MBRLEN@
255_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 356_GL_FUNCDECL_SYS (mbrlen, size_t,
357 (const char *restrict s, size_t n, mbstate_t *restrict ps));
256# endif 358# endif
257_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 359_GL_CXXALIAS_SYS (mbrlen, size_t,
360 (const char *restrict s, size_t n, mbstate_t *restrict ps));
258# endif 361# endif
362# if __GLIBC__ >= 2
259_GL_CXXALIASWARN (mbrlen); 363_GL_CXXALIASWARN (mbrlen);
364# endif
260#elif defined GNULIB_POSIXCHECK 365#elif defined GNULIB_POSIXCHECK
261# undef mbrlen 366# undef mbrlen
262# if HAVE_RAW_DECL_MBRLEN 367# if HAVE_RAW_DECL_MBRLEN
@@ -274,22 +379,30 @@ _GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
274# define mbsrtowcs rpl_mbsrtowcs 379# define mbsrtowcs rpl_mbsrtowcs
275# endif 380# endif
276_GL_FUNCDECL_RPL (mbsrtowcs, size_t, 381_GL_FUNCDECL_RPL (mbsrtowcs, size_t,
277 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) 382 (wchar_t *restrict dest,
383 const char **restrict srcp, size_t len,
384 mbstate_t *restrict ps)
278 _GL_ARG_NONNULL ((2))); 385 _GL_ARG_NONNULL ((2)));
279_GL_CXXALIAS_RPL (mbsrtowcs, size_t, 386_GL_CXXALIAS_RPL (mbsrtowcs, size_t,
280 (wchar_t *dest, const char **srcp, size_t len, 387 (wchar_t *restrict dest,
281 mbstate_t *ps)); 388 const char **restrict srcp, size_t len,
389 mbstate_t *restrict ps));
282# else 390# else
283# if !@HAVE_MBSRTOWCS@ 391# if !@HAVE_MBSRTOWCS@
284_GL_FUNCDECL_SYS (mbsrtowcs, size_t, 392_GL_FUNCDECL_SYS (mbsrtowcs, size_t,
285 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) 393 (wchar_t *restrict dest,
394 const char **restrict srcp, size_t len,
395 mbstate_t *restrict ps)
286 _GL_ARG_NONNULL ((2))); 396 _GL_ARG_NONNULL ((2)));
287# endif 397# endif
288_GL_CXXALIAS_SYS (mbsrtowcs, size_t, 398_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
289 (wchar_t *dest, const char **srcp, size_t len, 399 (wchar_t *restrict dest,
290 mbstate_t *ps)); 400 const char **restrict srcp, size_t len,
401 mbstate_t *restrict ps));
291# endif 402# endif
403# if __GLIBC__ >= 2
292_GL_CXXALIASWARN (mbsrtowcs); 404_GL_CXXALIASWARN (mbsrtowcs);
405# endif
293#elif defined GNULIB_POSIXCHECK 406#elif defined GNULIB_POSIXCHECK
294# undef mbsrtowcs 407# undef mbsrtowcs
295# if HAVE_RAW_DECL_MBSRTOWCS 408# if HAVE_RAW_DECL_MBSRTOWCS
@@ -307,22 +420,26 @@ _GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
307# define mbsnrtowcs rpl_mbsnrtowcs 420# define mbsnrtowcs rpl_mbsnrtowcs
308# endif 421# endif
309_GL_FUNCDECL_RPL (mbsnrtowcs, size_t, 422_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
310 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 423 (wchar_t *restrict dest,
311 mbstate_t *ps) 424 const char **restrict srcp, size_t srclen, size_t len,
425 mbstate_t *restrict ps)
312 _GL_ARG_NONNULL ((2))); 426 _GL_ARG_NONNULL ((2)));
313_GL_CXXALIAS_RPL (mbsnrtowcs, size_t, 427_GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
314 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 428 (wchar_t *restrict dest,
315 mbstate_t *ps)); 429 const char **restrict srcp, size_t srclen, size_t len,
430 mbstate_t *restrict ps));
316# else 431# else
317# if !@HAVE_MBSNRTOWCS@ 432# if !@HAVE_MBSNRTOWCS@
318_GL_FUNCDECL_SYS (mbsnrtowcs, size_t, 433_GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
319 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 434 (wchar_t *restrict dest,
320 mbstate_t *ps) 435 const char **restrict srcp, size_t srclen, size_t len,
436 mbstate_t *restrict ps)
321 _GL_ARG_NONNULL ((2))); 437 _GL_ARG_NONNULL ((2)));
322# endif 438# endif
323_GL_CXXALIAS_SYS (mbsnrtowcs, size_t, 439_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
324 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 440 (wchar_t *restrict dest,
325 mbstate_t *ps)); 441 const char **restrict srcp, size_t srclen, size_t len,
442 mbstate_t *restrict ps));
326# endif 443# endif
327_GL_CXXALIASWARN (mbsnrtowcs); 444_GL_CXXALIASWARN (mbsnrtowcs);
328#elif defined GNULIB_POSIXCHECK 445#elif defined GNULIB_POSIXCHECK
@@ -341,15 +458,21 @@ _GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
341# undef wcrtomb 458# undef wcrtomb
342# define wcrtomb rpl_wcrtomb 459# define wcrtomb rpl_wcrtomb
343# endif 460# endif
344_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 461_GL_FUNCDECL_RPL (wcrtomb, size_t,
345_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 462 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
463_GL_CXXALIAS_RPL (wcrtomb, size_t,
464 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
346# else 465# else
347# if !@HAVE_WCRTOMB@ 466# if !@HAVE_WCRTOMB@
348_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 467_GL_FUNCDECL_SYS (wcrtomb, size_t,
468 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
349# endif 469# endif
350_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 470_GL_CXXALIAS_SYS (wcrtomb, size_t,
471 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
351# endif 472# endif
473# if __GLIBC__ >= 2
352_GL_CXXALIASWARN (wcrtomb); 474_GL_CXXALIASWARN (wcrtomb);
475# endif
353#elif defined GNULIB_POSIXCHECK 476#elif defined GNULIB_POSIXCHECK
354# undef wcrtomb 477# undef wcrtomb
355# if HAVE_RAW_DECL_WCRTOMB 478# if HAVE_RAW_DECL_WCRTOMB
@@ -367,22 +490,30 @@ _GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
367# define wcsrtombs rpl_wcsrtombs 490# define wcsrtombs rpl_wcsrtombs
368# endif 491# endif
369_GL_FUNCDECL_RPL (wcsrtombs, size_t, 492_GL_FUNCDECL_RPL (wcsrtombs, size_t,
370 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) 493 (char *restrict dest, const wchar_t **restrict srcp,
494 size_t len,
495 mbstate_t *restrict ps)
371 _GL_ARG_NONNULL ((2))); 496 _GL_ARG_NONNULL ((2)));
372_GL_CXXALIAS_RPL (wcsrtombs, size_t, 497_GL_CXXALIAS_RPL (wcsrtombs, size_t,
373 (char *dest, const wchar_t **srcp, size_t len, 498 (char *restrict dest, const wchar_t **restrict srcp,
374 mbstate_t *ps)); 499 size_t len,
500 mbstate_t *restrict ps));
375# else 501# else
376# if !@HAVE_WCSRTOMBS@ 502# if !@HAVE_WCSRTOMBS@
377_GL_FUNCDECL_SYS (wcsrtombs, size_t, 503_GL_FUNCDECL_SYS (wcsrtombs, size_t,
378 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) 504 (char *restrict dest, const wchar_t **restrict srcp,
505 size_t len,
506 mbstate_t *restrict ps)
379 _GL_ARG_NONNULL ((2))); 507 _GL_ARG_NONNULL ((2)));
380# endif 508# endif
381_GL_CXXALIAS_SYS (wcsrtombs, size_t, 509_GL_CXXALIAS_SYS (wcsrtombs, size_t,
382 (char *dest, const wchar_t **srcp, size_t len, 510 (char *restrict dest, const wchar_t **restrict srcp,
383 mbstate_t *ps)); 511 size_t len,
512 mbstate_t *restrict ps));
384# endif 513# endif
514# if __GLIBC__ >= 2
385_GL_CXXALIASWARN (wcsrtombs); 515_GL_CXXALIASWARN (wcsrtombs);
516# endif
386#elif defined GNULIB_POSIXCHECK 517#elif defined GNULIB_POSIXCHECK
387# undef wcsrtombs 518# undef wcsrtombs
388# if HAVE_RAW_DECL_WCSRTOMBS 519# if HAVE_RAW_DECL_WCSRTOMBS
@@ -400,24 +531,34 @@ _GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
400# define wcsnrtombs rpl_wcsnrtombs 531# define wcsnrtombs rpl_wcsnrtombs
401# endif 532# endif
402_GL_FUNCDECL_RPL (wcsnrtombs, size_t, 533_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
403 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 534 (char *restrict dest,
404 mbstate_t *ps) 535 const wchar_t **restrict srcp, size_t srclen,
536 size_t len,
537 mbstate_t *restrict ps)
405 _GL_ARG_NONNULL ((2))); 538 _GL_ARG_NONNULL ((2)));
406_GL_CXXALIAS_RPL (wcsnrtombs, size_t, 539_GL_CXXALIAS_RPL (wcsnrtombs, size_t,
407 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 540 (char *restrict dest,
408 mbstate_t *ps)); 541 const wchar_t **restrict srcp, size_t srclen,
542 size_t len,
543 mbstate_t *restrict ps));
409# else 544# else
410# if !@HAVE_WCSNRTOMBS@ 545# if !@HAVE_WCSNRTOMBS@ || (defined __cplusplus && defined __sun)
411_GL_FUNCDECL_SYS (wcsnrtombs, size_t, 546_GL_FUNCDECL_SYS (wcsnrtombs, size_t,
412 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 547 (char *restrict dest,
413 mbstate_t *ps) 548 const wchar_t **restrict srcp, size_t srclen,
549 size_t len,
550 mbstate_t *restrict ps)
414 _GL_ARG_NONNULL ((2))); 551 _GL_ARG_NONNULL ((2)));
415# endif 552# endif
416_GL_CXXALIAS_SYS (wcsnrtombs, size_t, 553_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
417 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 554 (char *restrict dest,
418 mbstate_t *ps)); 555 const wchar_t **restrict srcp, size_t srclen,
556 size_t len,
557 mbstate_t *restrict ps));
419# endif 558# endif
559# if __GLIBC__ >= 2
420_GL_CXXALIASWARN (wcsnrtombs); 560_GL_CXXALIASWARN (wcsnrtombs);
561# endif
421#elif defined GNULIB_POSIXCHECK 562#elif defined GNULIB_POSIXCHECK
422# undef wcsnrtombs 563# undef wcsnrtombs
423# if HAVE_RAW_DECL_WCSNRTOMBS 564# if HAVE_RAW_DECL_WCSNRTOMBS
@@ -443,7 +584,9 @@ _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t) _GL_ATTRIBUTE_PURE);
443# endif 584# endif
444_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t)); 585_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
445# endif 586# endif
587# if __GLIBC__ >= 2
446_GL_CXXALIASWARN (wcwidth); 588_GL_CXXALIASWARN (wcwidth);
589# endif
447#elif defined GNULIB_POSIXCHECK 590#elif defined GNULIB_POSIXCHECK
448# undef wcwidth 591# undef wcwidth
449# if HAVE_RAW_DECL_WCWIDTH 592# if HAVE_RAW_DECL_WCWIDTH
@@ -472,7 +615,7 @@ _GL_CXXALIAS_SYS_CAST2 (wmemchr,
472_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); 615_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
473_GL_CXXALIASWARN1 (wmemchr, const wchar_t *, 616_GL_CXXALIASWARN1 (wmemchr, const wchar_t *,
474 (const wchar_t *s, wchar_t c, size_t n)); 617 (const wchar_t *s, wchar_t c, size_t n));
475# else 618# elif __GLIBC__ >= 2
476_GL_CXXALIASWARN (wmemchr); 619_GL_CXXALIASWARN (wmemchr);
477# endif 620# endif
478#elif defined GNULIB_POSIXCHECK 621#elif defined GNULIB_POSIXCHECK
@@ -493,7 +636,9 @@ _GL_FUNCDECL_SYS (wmemcmp, int,
493# endif 636# endif
494_GL_CXXALIAS_SYS (wmemcmp, int, 637_GL_CXXALIAS_SYS (wmemcmp, int,
495 (const wchar_t *s1, const wchar_t *s2, size_t n)); 638 (const wchar_t *s1, const wchar_t *s2, size_t n));
639# if __GLIBC__ >= 2
496_GL_CXXALIASWARN (wmemcmp); 640_GL_CXXALIASWARN (wmemcmp);
641# endif
497#elif defined GNULIB_POSIXCHECK 642#elif defined GNULIB_POSIXCHECK
498# undef wmemcmp 643# undef wmemcmp
499# if HAVE_RAW_DECL_WMEMCMP 644# if HAVE_RAW_DECL_WMEMCMP
@@ -507,11 +652,15 @@ _GL_WARN_ON_USE (wmemcmp, "wmemcmp is unportable - "
507#if @GNULIB_WMEMCPY@ 652#if @GNULIB_WMEMCPY@
508# if !@HAVE_WMEMCPY@ 653# if !@HAVE_WMEMCPY@
509_GL_FUNCDECL_SYS (wmemcpy, wchar_t *, 654_GL_FUNCDECL_SYS (wmemcpy, wchar_t *,
510 (wchar_t *dest, const wchar_t *src, size_t n)); 655 (wchar_t *restrict dest,
656 const wchar_t *restrict src, size_t n));
511# endif 657# endif
512_GL_CXXALIAS_SYS (wmemcpy, wchar_t *, 658_GL_CXXALIAS_SYS (wmemcpy, wchar_t *,
513 (wchar_t *dest, const wchar_t *src, size_t n)); 659 (wchar_t *restrict dest,
660 const wchar_t *restrict src, size_t n));
661# if __GLIBC__ >= 2
514_GL_CXXALIASWARN (wmemcpy); 662_GL_CXXALIASWARN (wmemcpy);
663# endif
515#elif defined GNULIB_POSIXCHECK 664#elif defined GNULIB_POSIXCHECK
516# undef wmemcpy 665# undef wmemcpy
517# if HAVE_RAW_DECL_WMEMCPY 666# if HAVE_RAW_DECL_WMEMCPY
@@ -530,7 +679,9 @@ _GL_FUNCDECL_SYS (wmemmove, wchar_t *,
530# endif 679# endif
531_GL_CXXALIAS_SYS (wmemmove, wchar_t *, 680_GL_CXXALIAS_SYS (wmemmove, wchar_t *,
532 (wchar_t *dest, const wchar_t *src, size_t n)); 681 (wchar_t *dest, const wchar_t *src, size_t n));
682# if __GLIBC__ >= 2
533_GL_CXXALIASWARN (wmemmove); 683_GL_CXXALIASWARN (wmemmove);
684# endif
534#elif defined GNULIB_POSIXCHECK 685#elif defined GNULIB_POSIXCHECK
535# undef wmemmove 686# undef wmemmove
536# if HAVE_RAW_DECL_WMEMMOVE 687# if HAVE_RAW_DECL_WMEMMOVE
@@ -540,13 +691,38 @@ _GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - "
540#endif 691#endif
541 692
542 693
694/* Copy N wide characters of SRC to DEST.
695 Return pointer to wide characters after the last written wide character. */
696#if @GNULIB_WMEMPCPY@
697# if !@HAVE_WMEMPCPY@
698_GL_FUNCDECL_SYS (wmempcpy, wchar_t *,
699 (wchar_t *restrict dest,
700 const wchar_t *restrict src, size_t n));
701# endif
702_GL_CXXALIAS_SYS (wmempcpy, wchar_t *,
703 (wchar_t *restrict dest,
704 const wchar_t *restrict src, size_t n));
705# if __GLIBC__ >= 2
706_GL_CXXALIASWARN (wmempcpy);
707# endif
708#elif defined GNULIB_POSIXCHECK
709# undef wmempcpy
710# if HAVE_RAW_DECL_WMEMPCPY
711_GL_WARN_ON_USE (wmempcpy, "wmempcpy is unportable - "
712 "use gnulib module wmempcpy for portability");
713# endif
714#endif
715
716
543/* Set N wide characters of S to C. */ 717/* Set N wide characters of S to C. */
544#if @GNULIB_WMEMSET@ 718#if @GNULIB_WMEMSET@
545# if !@HAVE_WMEMSET@ 719# if !@HAVE_WMEMSET@
546_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); 720_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
547# endif 721# endif
548_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); 722_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
723# if __GLIBC__ >= 2
549_GL_CXXALIASWARN (wmemset); 724_GL_CXXALIASWARN (wmemset);
725# endif
550#elif defined GNULIB_POSIXCHECK 726#elif defined GNULIB_POSIXCHECK
551# undef wmemset 727# undef wmemset
552# if HAVE_RAW_DECL_WMEMSET 728# if HAVE_RAW_DECL_WMEMSET
@@ -562,7 +738,9 @@ _GL_WARN_ON_USE (wmemset, "wmemset is unportable - "
562_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s) _GL_ATTRIBUTE_PURE); 738_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s) _GL_ATTRIBUTE_PURE);
563# endif 739# endif
564_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s)); 740_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s));
741# if __GLIBC__ >= 2
565_GL_CXXALIASWARN (wcslen); 742_GL_CXXALIASWARN (wcslen);
743# endif
566#elif defined GNULIB_POSIXCHECK 744#elif defined GNULIB_POSIXCHECK
567# undef wcslen 745# undef wcslen
568# if HAVE_RAW_DECL_WCSLEN 746# if HAVE_RAW_DECL_WCSLEN
@@ -574,7 +752,10 @@ _GL_WARN_ON_USE (wcslen, "wcslen is unportable - "
574 752
575/* Return the number of wide characters in S, but at most MAXLEN. */ 753/* Return the number of wide characters in S, but at most MAXLEN. */
576#if @GNULIB_WCSNLEN@ 754#if @GNULIB_WCSNLEN@
577# if !@HAVE_WCSNLEN@ 755/* On Solaris 11.3, the header files declare the function in the std::
756 namespace, not in the global namespace. So, force a declaration in
757 the global namespace. */
758# if !@HAVE_WCSNLEN@ || (defined __sun && defined __cplusplus)
578_GL_FUNCDECL_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen) 759_GL_FUNCDECL_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen)
579 _GL_ATTRIBUTE_PURE); 760 _GL_ATTRIBUTE_PURE);
580# endif 761# endif
@@ -592,10 +773,14 @@ _GL_WARN_ON_USE (wcsnlen, "wcsnlen is unportable - "
592/* Copy SRC to DEST. */ 773/* Copy SRC to DEST. */
593#if @GNULIB_WCSCPY@ 774#if @GNULIB_WCSCPY@
594# if !@HAVE_WCSCPY@ 775# if !@HAVE_WCSCPY@
595_GL_FUNCDECL_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 776_GL_FUNCDECL_SYS (wcscpy, wchar_t *,
777 (wchar_t *restrict dest, const wchar_t *restrict src));
596# endif 778# endif
597_GL_CXXALIAS_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 779_GL_CXXALIAS_SYS (wcscpy, wchar_t *,
780 (wchar_t *restrict dest, const wchar_t *restrict src));
781# if __GLIBC__ >= 2
598_GL_CXXALIASWARN (wcscpy); 782_GL_CXXALIASWARN (wcscpy);
783# endif
599#elif defined GNULIB_POSIXCHECK 784#elif defined GNULIB_POSIXCHECK
600# undef wcscpy 785# undef wcscpy
601# if HAVE_RAW_DECL_WCSCPY 786# if HAVE_RAW_DECL_WCSCPY
@@ -607,10 +792,15 @@ _GL_WARN_ON_USE (wcscpy, "wcscpy is unportable - "
607 792
608/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */ 793/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */
609#if @GNULIB_WCPCPY@ 794#if @GNULIB_WCPCPY@
610# if !@HAVE_WCPCPY@ 795/* On Solaris 11.3, the header files declare the function in the std::
611_GL_FUNCDECL_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 796 namespace, not in the global namespace. So, force a declaration in
612# endif 797 the global namespace. */
613_GL_CXXALIAS_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 798# if !@HAVE_WCPCPY@ || (defined __sun && defined __cplusplus)
799_GL_FUNCDECL_SYS (wcpcpy, wchar_t *,
800 (wchar_t *restrict dest, const wchar_t *restrict src));
801# endif
802_GL_CXXALIAS_SYS (wcpcpy, wchar_t *,
803 (wchar_t *restrict dest, const wchar_t *restrict src));
614_GL_CXXALIASWARN (wcpcpy); 804_GL_CXXALIASWARN (wcpcpy);
615#elif defined GNULIB_POSIXCHECK 805#elif defined GNULIB_POSIXCHECK
616# undef wcpcpy 806# undef wcpcpy
@@ -625,11 +815,15 @@ _GL_WARN_ON_USE (wcpcpy, "wcpcpy is unportable - "
625#if @GNULIB_WCSNCPY@ 815#if @GNULIB_WCSNCPY@
626# if !@HAVE_WCSNCPY@ 816# if !@HAVE_WCSNCPY@
627_GL_FUNCDECL_SYS (wcsncpy, wchar_t *, 817_GL_FUNCDECL_SYS (wcsncpy, wchar_t *,
628 (wchar_t *dest, const wchar_t *src, size_t n)); 818 (wchar_t *restrict dest,
819 const wchar_t *restrict src, size_t n));
629# endif 820# endif
630_GL_CXXALIAS_SYS (wcsncpy, wchar_t *, 821_GL_CXXALIAS_SYS (wcsncpy, wchar_t *,
631 (wchar_t *dest, const wchar_t *src, size_t n)); 822 (wchar_t *restrict dest,
823 const wchar_t *restrict src, size_t n));
824# if __GLIBC__ >= 2
632_GL_CXXALIASWARN (wcsncpy); 825_GL_CXXALIASWARN (wcsncpy);
826# endif
633#elif defined GNULIB_POSIXCHECK 827#elif defined GNULIB_POSIXCHECK
634# undef wcsncpy 828# undef wcsncpy
635# if HAVE_RAW_DECL_WCSNCPY 829# if HAVE_RAW_DECL_WCSNCPY
@@ -642,12 +836,17 @@ _GL_WARN_ON_USE (wcsncpy, "wcsncpy is unportable - "
642/* Copy no more than N characters of SRC to DEST, returning the address of 836/* Copy no more than N characters of SRC to DEST, returning the address of
643 the last character written into DEST. */ 837 the last character written into DEST. */
644#if @GNULIB_WCPNCPY@ 838#if @GNULIB_WCPNCPY@
645# if !@HAVE_WCPNCPY@ 839/* On Solaris 11.3, the header files declare the function in the std::
840 namespace, not in the global namespace. So, force a declaration in
841 the global namespace. */
842# if !@HAVE_WCPNCPY@ || (defined __sun && defined __cplusplus)
646_GL_FUNCDECL_SYS (wcpncpy, wchar_t *, 843_GL_FUNCDECL_SYS (wcpncpy, wchar_t *,
647 (wchar_t *dest, const wchar_t *src, size_t n)); 844 (wchar_t *restrict dest,
845 const wchar_t *restrict src, size_t n));
648# endif 846# endif
649_GL_CXXALIAS_SYS (wcpncpy, wchar_t *, 847_GL_CXXALIAS_SYS (wcpncpy, wchar_t *,
650 (wchar_t *dest, const wchar_t *src, size_t n)); 848 (wchar_t *restrict dest,
849 const wchar_t *restrict src, size_t n));
651_GL_CXXALIASWARN (wcpncpy); 850_GL_CXXALIASWARN (wcpncpy);
652#elif defined GNULIB_POSIXCHECK 851#elif defined GNULIB_POSIXCHECK
653# undef wcpncpy 852# undef wcpncpy
@@ -661,10 +860,14 @@ _GL_WARN_ON_USE (wcpncpy, "wcpncpy is unportable - "
661/* Append SRC onto DEST. */ 860/* Append SRC onto DEST. */
662#if @GNULIB_WCSCAT@ 861#if @GNULIB_WCSCAT@
663# if !@HAVE_WCSCAT@ 862# if !@HAVE_WCSCAT@
664_GL_FUNCDECL_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src)); 863_GL_FUNCDECL_SYS (wcscat, wchar_t *,
864 (wchar_t *restrict dest, const wchar_t *restrict src));
665# endif 865# endif
666_GL_CXXALIAS_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src)); 866_GL_CXXALIAS_SYS (wcscat, wchar_t *,
867 (wchar_t *restrict dest, const wchar_t *restrict src));
868# if __GLIBC__ >= 2
667_GL_CXXALIASWARN (wcscat); 869_GL_CXXALIASWARN (wcscat);
870# endif
668#elif defined GNULIB_POSIXCHECK 871#elif defined GNULIB_POSIXCHECK
669# undef wcscat 872# undef wcscat
670# if HAVE_RAW_DECL_WCSCAT 873# if HAVE_RAW_DECL_WCSCAT
@@ -678,11 +881,15 @@ _GL_WARN_ON_USE (wcscat, "wcscat is unportable - "
678#if @GNULIB_WCSNCAT@ 881#if @GNULIB_WCSNCAT@
679# if !@HAVE_WCSNCAT@ 882# if !@HAVE_WCSNCAT@
680_GL_FUNCDECL_SYS (wcsncat, wchar_t *, 883_GL_FUNCDECL_SYS (wcsncat, wchar_t *,
681 (wchar_t *dest, const wchar_t *src, size_t n)); 884 (wchar_t *restrict dest, const wchar_t *restrict src,
885 size_t n));
682# endif 886# endif
683_GL_CXXALIAS_SYS (wcsncat, wchar_t *, 887_GL_CXXALIAS_SYS (wcsncat, wchar_t *,
684 (wchar_t *dest, const wchar_t *src, size_t n)); 888 (wchar_t *restrict dest, const wchar_t *restrict src,
889 size_t n));
890# if __GLIBC__ >= 2
685_GL_CXXALIASWARN (wcsncat); 891_GL_CXXALIASWARN (wcsncat);
892# endif
686#elif defined GNULIB_POSIXCHECK 893#elif defined GNULIB_POSIXCHECK
687# undef wcsncat 894# undef wcsncat
688# if HAVE_RAW_DECL_WCSNCAT 895# if HAVE_RAW_DECL_WCSNCAT
@@ -699,7 +906,9 @@ _GL_FUNCDECL_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)
699 _GL_ATTRIBUTE_PURE); 906 _GL_ATTRIBUTE_PURE);
700# endif 907# endif
701_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)); 908_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2));
909# if __GLIBC__ >= 2
702_GL_CXXALIASWARN (wcscmp); 910_GL_CXXALIASWARN (wcscmp);
911# endif
703#elif defined GNULIB_POSIXCHECK 912#elif defined GNULIB_POSIXCHECK
704# undef wcscmp 913# undef wcscmp
705# if HAVE_RAW_DECL_WCSCMP 914# if HAVE_RAW_DECL_WCSCMP
@@ -718,7 +927,9 @@ _GL_FUNCDECL_SYS (wcsncmp, int,
718# endif 927# endif
719_GL_CXXALIAS_SYS (wcsncmp, int, 928_GL_CXXALIAS_SYS (wcsncmp, int,
720 (const wchar_t *s1, const wchar_t *s2, size_t n)); 929 (const wchar_t *s1, const wchar_t *s2, size_t n));
930# if __GLIBC__ >= 2
721_GL_CXXALIASWARN (wcsncmp); 931_GL_CXXALIASWARN (wcsncmp);
932# endif
722#elif defined GNULIB_POSIXCHECK 933#elif defined GNULIB_POSIXCHECK
723# undef wcsncmp 934# undef wcsncmp
724# if HAVE_RAW_DECL_WCSNCMP 935# if HAVE_RAW_DECL_WCSNCMP
@@ -730,7 +941,10 @@ _GL_WARN_ON_USE (wcsncmp, "wcsncmp is unportable - "
730 941
731/* Compare S1 and S2, ignoring case. */ 942/* Compare S1 and S2, ignoring case. */
732#if @GNULIB_WCSCASECMP@ 943#if @GNULIB_WCSCASECMP@
733# if !@HAVE_WCSCASECMP@ 944/* On Solaris 11.3, the header files declare the function in the std::
945 namespace, not in the global namespace. So, force a declaration in
946 the global namespace. */
947# if !@HAVE_WCSCASECMP@ || (defined __sun && defined __cplusplus)
734_GL_FUNCDECL_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2) 948_GL_FUNCDECL_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2)
735 _GL_ATTRIBUTE_PURE); 949 _GL_ATTRIBUTE_PURE);
736# endif 950# endif
@@ -747,7 +961,10 @@ _GL_WARN_ON_USE (wcscasecmp, "wcscasecmp is unportable - "
747 961
748/* Compare no more than N chars of S1 and S2, ignoring case. */ 962/* Compare no more than N chars of S1 and S2, ignoring case. */
749#if @GNULIB_WCSNCASECMP@ 963#if @GNULIB_WCSNCASECMP@
750# if !@HAVE_WCSNCASECMP@ 964/* On Solaris 11.3, the header files declare the function in the std::
965 namespace, not in the global namespace. So, force a declaration in
966 the global namespace. */
967# if !@HAVE_WCSNCASECMP@ || (defined __sun && defined __cplusplus)
751_GL_FUNCDECL_SYS (wcsncasecmp, int, 968_GL_FUNCDECL_SYS (wcsncasecmp, int,
752 (const wchar_t *s1, const wchar_t *s2, size_t n) 969 (const wchar_t *s1, const wchar_t *s2, size_t n)
753 _GL_ATTRIBUTE_PURE); 970 _GL_ATTRIBUTE_PURE);
@@ -771,7 +988,9 @@ _GL_WARN_ON_USE (wcsncasecmp, "wcsncasecmp is unportable - "
771_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2)); 988_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
772# endif 989# endif
773_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2)); 990_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
991# if __GLIBC__ >= 2
774_GL_CXXALIASWARN (wcscoll); 992_GL_CXXALIASWARN (wcscoll);
993# endif
775#elif defined GNULIB_POSIXCHECK 994#elif defined GNULIB_POSIXCHECK
776# undef wcscoll 995# undef wcscoll
777# if HAVE_RAW_DECL_WCSCOLL 996# if HAVE_RAW_DECL_WCSCOLL
@@ -786,10 +1005,14 @@ _GL_WARN_ON_USE (wcscoll, "wcscoll is unportable - "
786 original strings. */ 1005 original strings. */
787#if @GNULIB_WCSXFRM@ 1006#if @GNULIB_WCSXFRM@
788# if !@HAVE_WCSXFRM@ 1007# if !@HAVE_WCSXFRM@
789_GL_FUNCDECL_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n)); 1008_GL_FUNCDECL_SYS (wcsxfrm, size_t,
1009 (wchar_t *restrict s1, const wchar_t *restrict s2, size_t n));
790# endif 1010# endif
791_GL_CXXALIAS_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n)); 1011_GL_CXXALIAS_SYS (wcsxfrm, size_t,
1012 (wchar_t *restrict s1, const wchar_t *restrict s2, size_t n));
1013# if __GLIBC__ >= 2
792_GL_CXXALIASWARN (wcsxfrm); 1014_GL_CXXALIASWARN (wcsxfrm);
1015# endif
793#elif defined GNULIB_POSIXCHECK 1016#elif defined GNULIB_POSIXCHECK
794# undef wcsxfrm 1017# undef wcsxfrm
795# if HAVE_RAW_DECL_WCSXFRM 1018# if HAVE_RAW_DECL_WCSXFRM
@@ -801,16 +1024,58 @@ _GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - "
801 1024
802/* Duplicate S, returning an identical malloc'd string. */ 1025/* Duplicate S, returning an identical malloc'd string. */
803#if @GNULIB_WCSDUP@ 1026#if @GNULIB_WCSDUP@
804# if !@HAVE_WCSDUP@ 1027# if defined _WIN32 && !defined __CYGWIN__
805_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s)); 1028# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
806# endif 1029# undef wcsdup
1030# define wcsdup _wcsdup
1031# endif
1032_GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s));
1033# else
1034/* On Solaris 11.3, the header files declare the function in the std::
1035 namespace, not in the global namespace. So, force a declaration in
1036 the global namespace. */
1037# if !@HAVE_WCSDUP@ || (defined __sun && defined __cplusplus) || __GNUC__ >= 11
1038_GL_FUNCDECL_SYS (wcsdup, wchar_t *,
1039 (const wchar_t *s)
1040 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
1041# endif
807_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); 1042_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
1043# endif
808_GL_CXXALIASWARN (wcsdup); 1044_GL_CXXALIASWARN (wcsdup);
809#elif defined GNULIB_POSIXCHECK 1045#else
810# undef wcsdup 1046# if __GNUC__ >= 11 && !defined wcsdup
811# if HAVE_RAW_DECL_WCSDUP 1047/* For -Wmismatched-dealloc: Associate wcsdup with free or rpl_free. */
1048_GL_FUNCDECL_SYS (wcsdup, wchar_t *,
1049 (const wchar_t *s)
1050 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
1051# endif
1052# if defined GNULIB_POSIXCHECK
1053# undef wcsdup
1054# if HAVE_RAW_DECL_WCSDUP
812_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - " 1055_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - "
813 "use gnulib module wcsdup for portability"); 1056 "use gnulib module wcsdup for portability");
1057# endif
1058# elif @GNULIB_MDA_WCSDUP@
1059/* On native Windows, map 'wcsdup' to '_wcsdup', so that -loldnames is not
1060 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1061 platforms by defining GNULIB_NAMESPACE::wcsdup always. */
1062# if defined _WIN32 && !defined __CYGWIN__
1063# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1064# undef wcsdup
1065# define wcsdup _wcsdup
1066# endif
1067_GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s));
1068# else
1069_GL_FUNCDECL_SYS (wcsdup, wchar_t *,
1070 (const wchar_t *s)
1071 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
1072# if @HAVE_DECL_WCSDUP@
1073_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
1074# endif
1075# endif
1076# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_WCSDUP@
1077_GL_CXXALIASWARN (wcsdup);
1078# endif
814# endif 1079# endif
815#endif 1080#endif
816 1081
@@ -833,7 +1098,7 @@ _GL_CXXALIAS_SYS_CAST2 (wcschr,
833 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 1098 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
834_GL_CXXALIASWARN1 (wcschr, wchar_t *, (wchar_t *wcs, wchar_t wc)); 1099_GL_CXXALIASWARN1 (wcschr, wchar_t *, (wchar_t *wcs, wchar_t wc));
835_GL_CXXALIASWARN1 (wcschr, const wchar_t *, (const wchar_t *wcs, wchar_t wc)); 1100_GL_CXXALIASWARN1 (wcschr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
836# else 1101# elif __GLIBC__ >= 2
837_GL_CXXALIASWARN (wcschr); 1102_GL_CXXALIASWARN (wcschr);
838# endif 1103# endif
839#elif defined GNULIB_POSIXCHECK 1104#elif defined GNULIB_POSIXCHECK
@@ -863,7 +1128,7 @@ _GL_CXXALIAS_SYS_CAST2 (wcsrchr,
863 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 1128 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
864_GL_CXXALIASWARN1 (wcsrchr, wchar_t *, (wchar_t *wcs, wchar_t wc)); 1129_GL_CXXALIASWARN1 (wcsrchr, wchar_t *, (wchar_t *wcs, wchar_t wc));
865_GL_CXXALIASWARN1 (wcsrchr, const wchar_t *, (const wchar_t *wcs, wchar_t wc)); 1130_GL_CXXALIASWARN1 (wcsrchr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
866# else 1131# elif __GLIBC__ >= 2
867_GL_CXXALIASWARN (wcsrchr); 1132_GL_CXXALIASWARN (wcsrchr);
868# endif 1133# endif
869#elif defined GNULIB_POSIXCHECK 1134#elif defined GNULIB_POSIXCHECK
@@ -883,7 +1148,9 @@ _GL_FUNCDECL_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject)
883 _GL_ATTRIBUTE_PURE); 1148 _GL_ATTRIBUTE_PURE);
884# endif 1149# endif
885_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject)); 1150_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject));
1151# if __GLIBC__ >= 2
886_GL_CXXALIASWARN (wcscspn); 1152_GL_CXXALIASWARN (wcscspn);
1153# endif
887#elif defined GNULIB_POSIXCHECK 1154#elif defined GNULIB_POSIXCHECK
888# undef wcscspn 1155# undef wcscspn
889# if HAVE_RAW_DECL_WCSCSPN 1156# if HAVE_RAW_DECL_WCSCSPN
@@ -901,7 +1168,9 @@ _GL_FUNCDECL_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)
901 _GL_ATTRIBUTE_PURE); 1168 _GL_ATTRIBUTE_PURE);
902# endif 1169# endif
903_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)); 1170_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept));
1171# if __GLIBC__ >= 2
904_GL_CXXALIASWARN (wcsspn); 1172_GL_CXXALIASWARN (wcsspn);
1173# endif
905#elif defined GNULIB_POSIXCHECK 1174#elif defined GNULIB_POSIXCHECK
906# undef wcsspn 1175# undef wcsspn
907# if HAVE_RAW_DECL_WCSSPN 1176# if HAVE_RAW_DECL_WCSSPN
@@ -932,7 +1201,7 @@ _GL_CXXALIASWARN1 (wcspbrk, wchar_t *,
932 (wchar_t *wcs, const wchar_t *accept)); 1201 (wchar_t *wcs, const wchar_t *accept));
933_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *, 1202_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *,
934 (const wchar_t *wcs, const wchar_t *accept)); 1203 (const wchar_t *wcs, const wchar_t *accept));
935# else 1204# elif __GLIBC__ >= 2
936_GL_CXXALIASWARN (wcspbrk); 1205_GL_CXXALIASWARN (wcspbrk);
937# endif 1206# endif
938#elif defined GNULIB_POSIXCHECK 1207#elif defined GNULIB_POSIXCHECK
@@ -948,7 +1217,8 @@ _GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - "
948#if @GNULIB_WCSSTR@ 1217#if @GNULIB_WCSSTR@
949# if !@HAVE_WCSSTR@ 1218# if !@HAVE_WCSSTR@
950_GL_FUNCDECL_SYS (wcsstr, wchar_t *, 1219_GL_FUNCDECL_SYS (wcsstr, wchar_t *,
951 (const wchar_t *haystack, const wchar_t *needle) 1220 (const wchar_t *restrict haystack,
1221 const wchar_t *restrict needle)
952 _GL_ATTRIBUTE_PURE); 1222 _GL_ATTRIBUTE_PURE);
953# endif 1223# endif
954 /* On some systems, this function is defined as an overloaded function: 1224 /* On some systems, this function is defined as an overloaded function:
@@ -957,15 +1227,19 @@ _GL_FUNCDECL_SYS (wcsstr, wchar_t *,
957 wchar_t * std::wcsstr (wchar_t *, const wchar_t *); 1227 wchar_t * std::wcsstr (wchar_t *, const wchar_t *);
958 } */ 1228 } */
959_GL_CXXALIAS_SYS_CAST2 (wcsstr, 1229_GL_CXXALIAS_SYS_CAST2 (wcsstr,
960 wchar_t *, (const wchar_t *, const wchar_t *), 1230 wchar_t *,
961 const wchar_t *, (const wchar_t *, const wchar_t *)); 1231 (const wchar_t *restrict, const wchar_t *restrict),
1232 const wchar_t *,
1233 (const wchar_t *restrict, const wchar_t *restrict));
962# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 1234# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
963 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 1235 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
964_GL_CXXALIASWARN1 (wcsstr, wchar_t *, 1236_GL_CXXALIASWARN1 (wcsstr, wchar_t *,
965 (wchar_t *haystack, const wchar_t *needle)); 1237 (wchar_t *restrict haystack,
1238 const wchar_t *restrict needle));
966_GL_CXXALIASWARN1 (wcsstr, const wchar_t *, 1239_GL_CXXALIASWARN1 (wcsstr, const wchar_t *,
967 (const wchar_t *haystack, const wchar_t *needle)); 1240 (const wchar_t *restrict haystack,
968# else 1241 const wchar_t *restrict needle));
1242# elif __GLIBC__ >= 2
969_GL_CXXALIASWARN (wcsstr); 1243_GL_CXXALIASWARN (wcsstr);
970# endif 1244# endif
971#elif defined GNULIB_POSIXCHECK 1245#elif defined GNULIB_POSIXCHECK
@@ -979,13 +1253,30 @@ _GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - "
979 1253
980/* Divide WCS into tokens separated by characters in DELIM. */ 1254/* Divide WCS into tokens separated by characters in DELIM. */
981#if @GNULIB_WCSTOK@ 1255#if @GNULIB_WCSTOK@
982# if !@HAVE_WCSTOK@ 1256# if @REPLACE_WCSTOK@
1257# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1258# undef wcstok
1259# define wcstok rpl_wcstok
1260# endif
1261_GL_FUNCDECL_RPL (wcstok, wchar_t *,
1262 (wchar_t *restrict wcs, const wchar_t *restrict delim,
1263 wchar_t **restrict ptr));
1264_GL_CXXALIAS_RPL (wcstok, wchar_t *,
1265 (wchar_t *restrict wcs, const wchar_t *restrict delim,
1266 wchar_t **restrict ptr));
1267# else
1268# if !@HAVE_WCSTOK@
983_GL_FUNCDECL_SYS (wcstok, wchar_t *, 1269_GL_FUNCDECL_SYS (wcstok, wchar_t *,
984 (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); 1270 (wchar_t *restrict wcs, const wchar_t *restrict delim,
985# endif 1271 wchar_t **restrict ptr));
1272# endif
986_GL_CXXALIAS_SYS (wcstok, wchar_t *, 1273_GL_CXXALIAS_SYS (wcstok, wchar_t *,
987 (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); 1274 (wchar_t *restrict wcs, const wchar_t *restrict delim,
1275 wchar_t **restrict ptr));
1276# endif
1277# if __GLIBC__ >= 2
988_GL_CXXALIASWARN (wcstok); 1278_GL_CXXALIASWARN (wcstok);
1279# endif
989#elif defined GNULIB_POSIXCHECK 1280#elif defined GNULIB_POSIXCHECK
990# undef wcstok 1281# undef wcstok
991# if HAVE_RAW_DECL_WCSTOK 1282# if HAVE_RAW_DECL_WCSTOK
@@ -1013,7 +1304,9 @@ _GL_FUNCDECL_SYS (wcswidth, int, (const wchar_t *s, size_t n)
1013# endif 1304# endif
1014_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n)); 1305_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n));
1015# endif 1306# endif
1307# if __GLIBC__ >= 2
1016_GL_CXXALIASWARN (wcswidth); 1308_GL_CXXALIASWARN (wcswidth);
1309# endif
1017#elif defined GNULIB_POSIXCHECK 1310#elif defined GNULIB_POSIXCHECK
1018# undef wcswidth 1311# undef wcswidth
1019# if HAVE_RAW_DECL_WCSWIDTH 1312# if HAVE_RAW_DECL_WCSWIDTH
@@ -1023,6 +1316,48 @@ _GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - "
1023#endif 1316#endif
1024 1317
1025 1318
1319/* Convert *TP to a date and time wide string. See
1320 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html>. */
1321#if @GNULIB_WCSFTIME@
1322# if @REPLACE_WCSFTIME@
1323# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1324# undef wcsftime
1325# define wcsftime rpl_wcsftime
1326# endif
1327_GL_FUNCDECL_RPL (wcsftime, size_t,
1328 (wchar_t *restrict __buf, size_t __bufsize,
1329 const wchar_t *restrict __fmt,
1330 const struct tm *restrict __tp)
1331 _GL_ARG_NONNULL ((1, 3, 4)));
1332_GL_CXXALIAS_RPL (wcsftime, size_t,
1333 (wchar_t *restrict __buf, size_t __bufsize,
1334 const wchar_t *restrict __fmt,
1335 const struct tm *restrict __tp));
1336# else
1337# if !@HAVE_WCSFTIME@
1338_GL_FUNCDECL_SYS (wcsftime, size_t,
1339 (wchar_t *restrict __buf, size_t __bufsize,
1340 const wchar_t *restrict __fmt,
1341 const struct tm *restrict __tp)
1342 _GL_ARG_NONNULL ((1, 3, 4)));
1343# endif
1344_GL_CXXALIAS_SYS (wcsftime, size_t,
1345 (wchar_t *restrict __buf, size_t __bufsize,
1346 const wchar_t *restrict __fmt,
1347 const struct tm *restrict __tp));
1348# endif
1349# if __GLIBC__ >= 2
1350_GL_CXXALIASWARN (wcsftime);
1351# endif
1352#elif defined GNULIB_POSIXCHECK
1353# undef wcsftime
1354# if HAVE_RAW_DECL_WCSFTIME
1355_GL_WARN_ON_USE (wcsftime, "wcsftime is unportable - "
1356 "use gnulib module wcsftime for portability");
1357# endif
1358#endif
1359
1360
1026#endif /* _@GUARD_PREFIX@_WCHAR_H */ 1361#endif /* _@GUARD_PREFIX@_WCHAR_H */
1027#endif /* _@GUARD_PREFIX@_WCHAR_H */ 1362#endif /* _@GUARD_PREFIX@_WCHAR_H */
1028#endif 1363#endif
diff --git a/gl/wcrtomb.c b/gl/wcrtomb.c
index da42809..48a6c8e 100644
--- a/gl/wcrtomb.c
+++ b/gl/wcrtomb.c
@@ -1,19 +1,19 @@
1/* Convert wide character to multibyte character. 1/* Convert wide character to multibyte character.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -26,20 +26,46 @@
26 26
27size_t 27size_t
28wcrtomb (char *s, wchar_t wc, mbstate_t *ps) 28wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
29#undef wcrtomb
29{ 30{
30 /* This implementation of wcrtomb on top of wctomb() supports only 31 /* This implementation of wcrtomb supports only stateless encodings.
31 stateless encodings. ps must be in the initial state. */ 32 ps must be in the initial state. */
32 if (ps != NULL && !mbsinit (ps)) 33 if (ps != NULL && !mbsinit (ps))
33 { 34 {
34 errno = EINVAL; 35 errno = EINVAL;
35 return (size_t)(-1); 36 return (size_t)(-1);
36 } 37 }
37 38
39#if !HAVE_WCRTOMB /* IRIX 6.5 */ \
40 || WCRTOMB_RETVAL_BUG /* Solaris 11.3, MSVC */ \
41 || WCRTOMB_C_LOCALE_BUG /* Android */
38 if (s == NULL) 42 if (s == NULL)
39 /* We know the NUL wide character corresponds to the NUL character. */ 43 /* We know the NUL wide character corresponds to the NUL character. */
40 return 1; 44 return 1;
41 else 45 else
46#endif
42 { 47 {
48#if HAVE_WCRTOMB
49# if WCRTOMB_C_LOCALE_BUG /* Android */
50 /* Implement consistently with mbrtowc(): through a 1:1 correspondence,
51 as in ISO-8859-1. */
52 if (wc >= 0 && wc <= 0xff)
53 {
54 *s = (unsigned char) wc;
55 return 1;
56 }
57 else
58 {
59 errno = EILSEQ;
60 return (size_t)(-1);
61 }
62# else
63 return wcrtomb (s, wc, ps);
64# endif
65#else /* IRIX 6.5 */
66 /* Fallback for platforms that don't have wcrtomb().
67 Implement on top of wctomb().
68 This code is not multithread-safe. */
43 int ret = wctomb (s, wc); 69 int ret = wctomb (s, wc);
44 70
45 if (ret >= 0) 71 if (ret >= 0)
@@ -49,5 +75,6 @@ wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
49 errno = EILSEQ; 75 errno = EILSEQ;
50 return (size_t)(-1); 76 return (size_t)(-1);
51 } 77 }
78#endif
52 } 79 }
53} 80}
diff --git a/gl/wctype-h.c b/gl/wctype-h.c
index bb5f847..7d3e14a 100644
--- a/gl/wctype-h.c
+++ b/gl/wctype-h.c
@@ -1,4 +1,23 @@
1/* Inline functions for <wctype.h>.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
1/* Normally this would be wctype.c, but that name's already taken. */ 18/* Normally this would be wctype.c, but that name's already taken. */
19
2#include <config.h> 20#include <config.h>
21
3#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE 22#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE
4#include "wctype.h" 23#include "wctype.h"
diff --git a/gl/wctype.in.h b/gl/wctype.in.h
index a7c07d1..f6e474d 100644
--- a/gl/wctype.in.h
+++ b/gl/wctype.in.h
@@ -1,54 +1,61 @@
1/* A substitute for ISO C99 <wctype.h>, for platforms that lack it. 1/* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2 2
3 Copyright (C) 2006-2013 Free Software Foundation, Inc. 3 Copyright (C) 2006-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* Written by Bruno Haible and Paul Eggert. */ 18/* Written by Bruno Haible and Paul Eggert. */
19 19
20/* 20/*
21 * ISO C 99 <wctype.h> for platforms that lack it. 21 * ISO C 99 <wctype.h> for platforms that lack it.
22 * <http://www.opengroup.org/susv3xbd/wctype.h.html> 22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/wctype.h.html>
23 * 23 *
24 * iswctype, towctrans, towlower, towupper, wctrans, wctype, 24 * iswctype, towctrans, towlower, towupper, wctrans, wctype,
25 * wctrans_t, and wctype_t are not yet implemented. 25 * wctrans_t, and wctype_t are not yet implemented.
26 */ 26 */
27 27
28#ifndef _@GUARD_PREFIX@_WCTYPE_H
29
30#if __GNUC__ >= 3 28#if __GNUC__ >= 3
31@PRAGMA_SYSTEM_HEADER@ 29@PRAGMA_SYSTEM_HEADER@
32#endif 30#endif
33@PRAGMA_COLUMNS@ 31@PRAGMA_COLUMNS@
34 32
33#if (defined __MINGW32__ && defined __CTYPE_H_SOURCED__)
34
35/* Special invocation convention:
36 - With MinGW 3.22, when <ctype.h> includes <wctype.h>, only some part of
37 <wctype.h> is being processed, which doesn't include the idempotency
38 guard. */
39
40#@INCLUDE_NEXT@ @NEXT_WCTYPE_H@
41
42#else
43/* Normal invocation convention. */
44
45#ifndef _@GUARD_PREFIX@_WCTYPE_H
46
35#if @HAVE_WINT_T@ 47#if @HAVE_WINT_T@
36/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. 48/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */
37 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
38 <wchar.h>.
39 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
40 included before <wchar.h>. */
41# include <stddef.h>
42# include <stdio.h>
43# include <time.h>
44# include <wchar.h> 49# include <wchar.h>
45#endif 50#endif
46 51
47/* mingw has declarations of towupper and towlower in <ctype.h> as 52/* Native Windows (mingw, MSVC) have declarations of towupper, towlower, and
48 well <wctype.h>. Include <ctype.h> in advance to avoid rpl_ prefix 53 isw* functions in <ctype.h>, <wchar.h> as well as in <wctype.h>. Include
49 being added to the declarations. */ 54 <ctype.h>, <wchar.h> in advance to avoid rpl_ prefix being added to the
50#ifdef __MINGW32__ 55 declarations. */
56#if defined _WIN32 && ! defined __CYGWIN__
51# include <ctype.h> 57# include <ctype.h>
58# include <wchar.h>
52#endif 59#endif
53 60
54/* Include the original <wctype.h> if it exists. 61/* Include the original <wctype.h> if it exists.
@@ -61,6 +68,9 @@
61#ifndef _@GUARD_PREFIX@_WCTYPE_H 68#ifndef _@GUARD_PREFIX@_WCTYPE_H
62#define _@GUARD_PREFIX@_WCTYPE_H 69#define _@GUARD_PREFIX@_WCTYPE_H
63 70
71#ifndef _GL_INLINE_HEADER_BEGIN
72 #error "Please include config.h first."
73#endif
64_GL_INLINE_HEADER_BEGIN 74_GL_INLINE_HEADER_BEGIN
65#ifndef _GL_WCTYPE_INLINE 75#ifndef _GL_WCTYPE_INLINE
66# define _GL_WCTYPE_INLINE _GL_INLINE 76# define _GL_WCTYPE_INLINE _GL_INLINE
@@ -90,12 +100,16 @@ _GL_INLINE_HEADER_BEGIN
90# define WEOF -1 100# define WEOF -1
91# endif 101# endif
92#else 102#else
93/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>. 103/* mingw and MSVC define wint_t as 'unsigned short' in <crtdefs.h> or
94 This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be 104 <stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
95 "unchanged by default argument promotions". Override it. */ 105 wint_t must be "unchanged by default argument promotions". Override it. */
96# if defined _MSC_VER 106# if @GNULIBHEADERS_OVERRIDE_WINT_T@
97# if !GNULIB_defined_wint_t 107# if !GNULIB_defined_wint_t
98# include <crtdefs.h> 108# if @HAVE_CRTDEFS_H@
109# include <crtdefs.h>
110# else
111# include <stddef.h>
112# endif
99typedef unsigned int rpl_wint_t; 113typedef unsigned int rpl_wint_t;
100# undef wint_t 114# undef wint_t
101# define wint_t rpl_wint_t 115# define wint_t rpl_wint_t
@@ -112,33 +126,116 @@ typedef unsigned int rpl_wint_t;
112 126
113/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions. 127/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
114 Linux libc5 has <wctype.h> and the functions but they are broken. 128 Linux libc5 has <wctype.h> and the functions but they are broken.
129 mingw and MSVC have <wctype.h> and the functions but they take a wchar_t
130 as argument, not an rpl_wint_t.
115 Assume all 11 functions (all isw* except iswblank) are implemented the 131 Assume all 11 functions (all isw* except iswblank) are implemented the
116 same way, or not at all. */ 132 same way, or not at all. */
117# if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@ 133# if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
118 134
119/* IRIX 5.3 has macros but no functions, its isw* macros refer to an 135# if @GNULIBHEADERS_OVERRIDE_WINT_T@ /* implies @REPLACE_ISWCNTRL@ */
120 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they 136
121 refer to system functions like _iswctype that are not in the 137_GL_WCTYPE_INLINE int
122 standard C library. Rather than try to get ancient buggy 138rpl_iswalnum (wint_t wc)
123 implementations like this to work, just disable them. */ 139{
124# undef iswalnum 140 return ((wchar_t) wc == wc ? iswalnum ((wchar_t) wc) : 0);
125# undef iswalpha 141}
126# undef iswblank 142
127# undef iswcntrl 143_GL_WCTYPE_INLINE int
128# undef iswdigit 144rpl_iswalpha (wint_t wc)
129# undef iswgraph 145{
130# undef iswlower 146 return ((wchar_t) wc == wc ? iswalpha ((wchar_t) wc) : 0);
131# undef iswprint 147}
132# undef iswpunct 148
133# undef iswspace 149_GL_WCTYPE_INLINE int
134# undef iswupper 150rpl_iswblank (wint_t wc)
135# undef iswxdigit 151{
136# undef towlower 152 return ((wchar_t) wc == wc ? iswblank ((wchar_t) wc) : 0);
137# undef towupper 153}
154
155_GL_WCTYPE_INLINE int
156rpl_iswcntrl (wint_t wc)
157{
158 return ((wchar_t) wc == wc ? iswcntrl ((wchar_t) wc) : 0);
159}
160
161_GL_WCTYPE_INLINE int
162rpl_iswdigit (wint_t wc)
163{
164 return ((wchar_t) wc == wc ? wc >= '0' && wc <= '9' : 0);
165}
166
167_GL_WCTYPE_INLINE int
168rpl_iswgraph (wint_t wc)
169{
170 return ((wchar_t) wc == wc ? iswgraph ((wchar_t) wc) : 0);
171}
172
173_GL_WCTYPE_INLINE int
174rpl_iswlower (wint_t wc)
175{
176 return ((wchar_t) wc == wc ? iswlower ((wchar_t) wc) : 0);
177}
178
179_GL_WCTYPE_INLINE int
180rpl_iswprint (wint_t wc)
181{
182 return ((wchar_t) wc == wc ? iswprint ((wchar_t) wc) : 0);
183}
184
185_GL_WCTYPE_INLINE int
186rpl_iswpunct (wint_t wc)
187{
188 return ((wchar_t) wc == wc ? iswpunct ((wchar_t) wc) : 0);
189}
190
191_GL_WCTYPE_INLINE int
192rpl_iswspace (wint_t wc)
193{
194 return ((wchar_t) wc == wc ? iswspace ((wchar_t) wc) : 0);
195}
196
197_GL_WCTYPE_INLINE int
198rpl_iswupper (wint_t wc)
199{
200 return ((wchar_t) wc == wc ? iswupper ((wchar_t) wc) : 0);
201}
202
203_GL_WCTYPE_INLINE int
204rpl_iswxdigit (wint_t wc)
205{
206 return ((wchar_t) wc == wc
207 ? (wc >= '0' && wc <= '9')
208 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')
209 : 0);
210}
211
212_GL_WCTYPE_INLINE wint_t
213rpl_towlower (wint_t wc)
214{
215 return ((wchar_t) wc == wc ? (wchar_t) towlower ((wchar_t) wc) : wc);
216}
217
218_GL_WCTYPE_INLINE wint_t
219rpl_towupper (wint_t wc)
220{
221 return ((wchar_t) wc == wc ? (wchar_t) towupper ((wchar_t) wc) : wc);
222}
138 223
139/* Linux libc5 has <wctype.h> and the functions but they are broken. */
140# if @REPLACE_ISWCNTRL@
141# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 224# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
225# undef iswalnum
226# undef iswalpha
227# undef iswblank
228# undef iswcntrl
229# undef iswdigit
230# undef iswgraph
231# undef iswlower
232# undef iswprint
233# undef iswpunct
234# undef iswspace
235# undef iswupper
236# undef iswxdigit
237# undef towlower
238# undef towupper
142# define iswalnum rpl_iswalnum 239# define iswalnum rpl_iswalnum
143# define iswalpha rpl_iswalpha 240# define iswalpha rpl_iswalpha
144# define iswblank rpl_iswblank 241# define iswblank rpl_iswblank
@@ -151,21 +248,62 @@ typedef unsigned int rpl_wint_t;
151# define iswspace rpl_iswspace 248# define iswspace rpl_iswspace
152# define iswupper rpl_iswupper 249# define iswupper rpl_iswupper
153# define iswxdigit rpl_iswxdigit 250# define iswxdigit rpl_iswxdigit
154# endif
155# endif
156# if @REPLACE_TOWLOWER@
157# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
158# define towlower rpl_towlower 251# define towlower rpl_towlower
159# define towupper rpl_towupper 252# define towupper rpl_towupper
160# endif 253# endif
161# endif 254
255# else
256
257/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
258 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
259 refer to system functions like _iswctype that are not in the
260 standard C library. Rather than try to get ancient buggy
261 implementations like this to work, just disable them. */
262# undef iswalnum
263# undef iswalpha
264# undef iswblank
265# undef iswcntrl
266# undef iswdigit
267# undef iswgraph
268# undef iswlower
269# undef iswprint
270# undef iswpunct
271# undef iswspace
272# undef iswupper
273# undef iswxdigit
274# undef towlower
275# undef towupper
276
277/* Linux libc5 has <wctype.h> and the functions but they are broken. */
278# if @REPLACE_ISWCNTRL@
279# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
280# define iswalnum rpl_iswalnum
281# define iswalpha rpl_iswalpha
282# define iswblank rpl_iswblank
283# define iswcntrl rpl_iswcntrl
284# define iswdigit rpl_iswdigit
285# define iswgraph rpl_iswgraph
286# define iswlower rpl_iswlower
287# define iswprint rpl_iswprint
288# define iswpunct rpl_iswpunct
289# define iswspace rpl_iswspace
290# define iswupper rpl_iswupper
291# define iswxdigit rpl_iswxdigit
292# endif
293# endif
294# if @REPLACE_TOWLOWER@
295# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
296# define towlower rpl_towlower
297# define towupper rpl_towupper
298# endif
299# endif
162 300
163_GL_WCTYPE_INLINE int 301_GL_WCTYPE_INLINE int
164# if @REPLACE_ISWCNTRL@ 302# if @REPLACE_ISWCNTRL@
165rpl_iswalnum 303rpl_iswalnum
166# else 304# else
167iswalnum 305iswalnum
168# endif 306# endif
169 (wint_t wc) 307 (wint_t wc)
170{ 308{
171 return ((wc >= '0' && wc <= '9') 309 return ((wc >= '0' && wc <= '9')
@@ -173,88 +311,88 @@ iswalnum
173} 311}
174 312
175_GL_WCTYPE_INLINE int 313_GL_WCTYPE_INLINE int
176# if @REPLACE_ISWCNTRL@ 314# if @REPLACE_ISWCNTRL@
177rpl_iswalpha 315rpl_iswalpha
178# else 316# else
179iswalpha 317iswalpha
180# endif 318# endif
181 (wint_t wc) 319 (wint_t wc)
182{ 320{
183 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; 321 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
184} 322}
185 323
186_GL_WCTYPE_INLINE int 324_GL_WCTYPE_INLINE int
187# if @REPLACE_ISWCNTRL@ 325# if @REPLACE_ISWCNTRL@
188rpl_iswblank 326rpl_iswblank
189# else 327# else
190iswblank 328iswblank
191# endif 329# endif
192 (wint_t wc) 330 (wint_t wc)
193{ 331{
194 return wc == ' ' || wc == '\t'; 332 return wc == ' ' || wc == '\t';
195} 333}
196 334
197_GL_WCTYPE_INLINE int 335_GL_WCTYPE_INLINE int
198# if @REPLACE_ISWCNTRL@ 336# if @REPLACE_ISWCNTRL@
199rpl_iswcntrl 337rpl_iswcntrl
200# else 338# else
201iswcntrl 339iswcntrl
202# endif 340# endif
203 (wint_t wc) 341 (wint_t wc)
204{ 342{
205 return (wc & ~0x1f) == 0 || wc == 0x7f; 343 return (wc & ~0x1f) == 0 || wc == 0x7f;
206} 344}
207 345
208_GL_WCTYPE_INLINE int 346_GL_WCTYPE_INLINE int
209# if @REPLACE_ISWCNTRL@ 347# if @REPLACE_ISWDIGIT@
210rpl_iswdigit 348rpl_iswdigit
211# else 349# else
212iswdigit 350iswdigit
213# endif 351# endif
214 (wint_t wc) 352 (wint_t wc)
215{ 353{
216 return wc >= '0' && wc <= '9'; 354 return wc >= '0' && wc <= '9';
217} 355}
218 356
219_GL_WCTYPE_INLINE int 357_GL_WCTYPE_INLINE int
220# if @REPLACE_ISWCNTRL@ 358# if @REPLACE_ISWCNTRL@
221rpl_iswgraph 359rpl_iswgraph
222# else 360# else
223iswgraph 361iswgraph
224# endif 362# endif
225 (wint_t wc) 363 (wint_t wc)
226{ 364{
227 return wc >= '!' && wc <= '~'; 365 return wc >= '!' && wc <= '~';
228} 366}
229 367
230_GL_WCTYPE_INLINE int 368_GL_WCTYPE_INLINE int
231# if @REPLACE_ISWCNTRL@ 369# if @REPLACE_ISWCNTRL@
232rpl_iswlower 370rpl_iswlower
233# else 371# else
234iswlower 372iswlower
235# endif 373# endif
236 (wint_t wc) 374 (wint_t wc)
237{ 375{
238 return wc >= 'a' && wc <= 'z'; 376 return wc >= 'a' && wc <= 'z';
239} 377}
240 378
241_GL_WCTYPE_INLINE int 379_GL_WCTYPE_INLINE int
242# if @REPLACE_ISWCNTRL@ 380# if @REPLACE_ISWCNTRL@
243rpl_iswprint 381rpl_iswprint
244# else 382# else
245iswprint 383iswprint
246# endif 384# endif
247 (wint_t wc) 385 (wint_t wc)
248{ 386{
249 return wc >= ' ' && wc <= '~'; 387 return wc >= ' ' && wc <= '~';
250} 388}
251 389
252_GL_WCTYPE_INLINE int 390_GL_WCTYPE_INLINE int
253# if @REPLACE_ISWCNTRL@ 391# if @REPLACE_ISWCNTRL@
254rpl_iswpunct 392rpl_iswpunct
255# else 393# else
256iswpunct 394iswpunct
257# endif 395# endif
258 (wint_t wc) 396 (wint_t wc)
259{ 397{
260 return (wc >= '!' && wc <= '~' 398 return (wc >= '!' && wc <= '~'
@@ -263,11 +401,11 @@ iswpunct
263} 401}
264 402
265_GL_WCTYPE_INLINE int 403_GL_WCTYPE_INLINE int
266# if @REPLACE_ISWCNTRL@ 404# if @REPLACE_ISWCNTRL@
267rpl_iswspace 405rpl_iswspace
268# else 406# else
269iswspace 407iswspace
270# endif 408# endif
271 (wint_t wc) 409 (wint_t wc)
272{ 410{
273 return (wc == ' ' || wc == '\t' 411 return (wc == ' ' || wc == '\t'
@@ -275,22 +413,22 @@ iswspace
275} 413}
276 414
277_GL_WCTYPE_INLINE int 415_GL_WCTYPE_INLINE int
278# if @REPLACE_ISWCNTRL@ 416# if @REPLACE_ISWCNTRL@
279rpl_iswupper 417rpl_iswupper
280# else 418# else
281iswupper 419iswupper
282# endif 420# endif
283 (wint_t wc) 421 (wint_t wc)
284{ 422{
285 return wc >= 'A' && wc <= 'Z'; 423 return wc >= 'A' && wc <= 'Z';
286} 424}
287 425
288_GL_WCTYPE_INLINE int 426_GL_WCTYPE_INLINE int
289# if @REPLACE_ISWCNTRL@ 427# if @REPLACE_ISWXDIGIT@
290rpl_iswxdigit 428rpl_iswxdigit
291# else 429# else
292iswxdigit 430iswxdigit
293# endif 431# endif
294 (wint_t wc) 432 (wint_t wc)
295{ 433{
296 return ((wc >= '0' && wc <= '9') 434 return ((wc >= '0' && wc <= '9')
@@ -298,42 +436,67 @@ iswxdigit
298} 436}
299 437
300_GL_WCTYPE_INLINE wint_t 438_GL_WCTYPE_INLINE wint_t
301# if @REPLACE_TOWLOWER@ 439# if @REPLACE_TOWLOWER@
302rpl_towlower 440rpl_towlower
303# else 441# else
304towlower 442towlower
305# endif 443# endif
306 (wint_t wc) 444 (wint_t wc)
307{ 445{
308 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc); 446 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
309} 447}
310 448
311_GL_WCTYPE_INLINE wint_t 449_GL_WCTYPE_INLINE wint_t
312# if @REPLACE_TOWLOWER@ 450# if @REPLACE_TOWLOWER@
313rpl_towupper 451rpl_towupper
314# else 452# else
315towupper 453towupper
316# endif 454# endif
317 (wint_t wc) 455 (wint_t wc)
318{ 456{
319 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc); 457 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
320} 458}
321 459
322# elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@) 460# endif
323/* Only the iswblank function is missing. */
324 461
325# if @REPLACE_ISWBLANK@ 462# else
326# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 463/* Only some of the functions are missing or broken. */
327# define iswblank rpl_iswblank 464
328# endif 465# if @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
466/* Only the iswblank function is missing. */
467# if @REPLACE_ISWBLANK@
468# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
469# define iswblank rpl_iswblank
470# endif
329_GL_FUNCDECL_RPL (iswblank, int, (wint_t wc)); 471_GL_FUNCDECL_RPL (iswblank, int, (wint_t wc));
330# else 472# else
331_GL_FUNCDECL_SYS (iswblank, int, (wint_t wc)); 473_GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
474# endif
475# endif
476
477# if @GNULIB_ISWDIGIT@
478# if @REPLACE_ISWDIGIT@
479# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
480# undef iswdigit
481# define iswdigit rpl_iswdigit
482# endif
483_GL_FUNCDECL_RPL (iswdigit, int, (wint_t wc));
484# endif
485# endif
486
487# if @GNULIB_ISWXDIGIT@
488# if @REPLACE_ISWXDIGIT@
489# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
490# undef iswxdigit
491# define iswxdigit rpl_iswxdigit
492# endif
493_GL_FUNCDECL_RPL (iswxdigit, int, (wint_t wc));
494# endif
332# endif 495# endif
333 496
334# endif 497# endif
335 498
336# if defined __MINGW32__ 499# if defined __MINGW32__ && !@GNULIBHEADERS_OVERRIDE_WINT_T@
337 500
338/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t. 501/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
339 The functions towlower and towupper are implemented in the MSVCRT library 502 The functions towlower and towupper are implemented in the MSVCRT library
@@ -366,36 +529,71 @@ rpl_towupper (wint_t wc)
366# define towupper rpl_towupper 529# define towupper rpl_towupper
367# endif 530# endif
368 531
369# endif /* __MINGW32__ */ 532# endif /* __MINGW32__ && !@GNULIBHEADERS_OVERRIDE_WINT_T@ */
370 533
371# define GNULIB_defined_wctype_functions 1 534# define GNULIB_defined_wctype_functions 1
372#endif 535#endif
373 536
374#if @REPLACE_ISWCNTRL@ 537#if @REPLACE_ISWCNTRL@
375_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc)); 538_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
376_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
377_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
378_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
379_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
380_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
381_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
382_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
383_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
384_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
385_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
386#else 539#else
387_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc)); 540_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
541#endif
542#if @REPLACE_ISWCNTRL@
543_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
544#else
388_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc)); 545_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
546#endif
547#if @REPLACE_ISWCNTRL@
548_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
549#else
389_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc)); 550_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
551#endif
552#if @GNULIB_ISWDIGIT@
553# if @REPLACE_ISWDIGIT@
554_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
555# else
390_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc)); 556_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
557# endif
558#endif
559#if @REPLACE_ISWCNTRL@
560_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
561#else
391_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc)); 562_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
563#endif
564#if @REPLACE_ISWCNTRL@
565_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
566#else
392_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc)); 567_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
568#endif
569#if @REPLACE_ISWCNTRL@
570_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
571#else
393_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc)); 572_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
573#endif
574#if @REPLACE_ISWCNTRL@
575_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
576#else
394_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc)); 577_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
578#endif
579#if @REPLACE_ISWCNTRL@
580_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
581#else
395_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc)); 582_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
583#endif
584#if @REPLACE_ISWCNTRL@
585_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
586#else
396_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc)); 587_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
588#endif
589#if @GNULIB_ISWXDIGIT@
590# if @REPLACE_ISWXDIGIT@
591_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
592# else
397_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc)); 593_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
594# endif
398#endif 595#endif
596#if __GLIBC__ >= 2
399_GL_CXXALIASWARN (iswalnum); 597_GL_CXXALIASWARN (iswalnum);
400_GL_CXXALIASWARN (iswalpha); 598_GL_CXXALIASWARN (iswalpha);
401_GL_CXXALIASWARN (iswcntrl); 599_GL_CXXALIASWARN (iswcntrl);
@@ -407,6 +605,7 @@ _GL_CXXALIASWARN (iswpunct);
407_GL_CXXALIASWARN (iswspace); 605_GL_CXXALIASWARN (iswspace);
408_GL_CXXALIASWARN (iswupper); 606_GL_CXXALIASWARN (iswupper);
409_GL_CXXALIASWARN (iswxdigit); 607_GL_CXXALIASWARN (iswxdigit);
608#endif
410 609
411#if @GNULIB_ISWBLANK@ 610#if @GNULIB_ISWBLANK@
412# if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@ 611# if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@
@@ -414,7 +613,9 @@ _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
414# else 613# else
415_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc)); 614_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
416# endif 615# endif
616# if __GLIBC__ >= 2
417_GL_CXXALIASWARN (iswblank); 617_GL_CXXALIASWARN (iswblank);
618# endif
418#endif 619#endif
419 620
420#if !@HAVE_WCTYPE_T@ 621#if !@HAVE_WCTYPE_T@
@@ -430,7 +631,9 @@ typedef void * wctype_t;
430_GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name)); 631_GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name));
431# endif 632# endif
432_GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name)); 633_GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name));
634# if __GLIBC__ >= 2
433_GL_CXXALIASWARN (wctype); 635_GL_CXXALIASWARN (wctype);
636# endif
434#elif defined GNULIB_POSIXCHECK 637#elif defined GNULIB_POSIXCHECK
435# undef wctype 638# undef wctype
436# if HAVE_RAW_DECL_WCTYPE 639# if HAVE_RAW_DECL_WCTYPE
@@ -443,11 +646,22 @@ _GL_WARN_ON_USE (wctype, "wctype is unportable - "
443 The argument WC must be either a wchar_t value or WEOF. 646 The argument WC must be either a wchar_t value or WEOF.
444 The argument DESC must have been returned by the wctype() function. */ 647 The argument DESC must have been returned by the wctype() function. */
445#if @GNULIB_ISWCTYPE@ 648#if @GNULIB_ISWCTYPE@
446# if !@HAVE_WCTYPE_T@ 649# if @GNULIBHEADERS_OVERRIDE_WINT_T@
650# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
651# undef iswctype
652# define iswctype rpl_iswctype
653# endif
654_GL_FUNCDECL_RPL (iswctype, int, (wint_t wc, wctype_t desc));
655_GL_CXXALIAS_RPL (iswctype, int, (wint_t wc, wctype_t desc));
656# else
657# if !@HAVE_WCTYPE_T@
447_GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc)); 658_GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc));
448# endif 659# endif
449_GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc)); 660_GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc));
661# endif
662# if __GLIBC__ >= 2
450_GL_CXXALIASWARN (iswctype); 663_GL_CXXALIASWARN (iswctype);
664# endif
451#elif defined GNULIB_POSIXCHECK 665#elif defined GNULIB_POSIXCHECK
452# undef iswctype 666# undef iswctype
453# if HAVE_RAW_DECL_ISWCTYPE 667# if HAVE_RAW_DECL_ISWCTYPE
@@ -463,8 +677,10 @@ _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
463_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc)); 677_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
464_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc)); 678_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
465#endif 679#endif
680#if __GLIBC__ >= 2
466_GL_CXXALIASWARN (towlower); 681_GL_CXXALIASWARN (towlower);
467_GL_CXXALIASWARN (towupper); 682_GL_CXXALIASWARN (towupper);
683#endif
468 684
469#if !@HAVE_WCTRANS_T@ 685#if !@HAVE_WCTRANS_T@
470# if !GNULIB_defined_wctrans_t 686# if !GNULIB_defined_wctrans_t
@@ -479,7 +695,9 @@ typedef void * wctrans_t;
479_GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name)); 695_GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name));
480# endif 696# endif
481_GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name)); 697_GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name));
698# if __GLIBC__ >= 2
482_GL_CXXALIASWARN (wctrans); 699_GL_CXXALIASWARN (wctrans);
700# endif
483#elif defined GNULIB_POSIXCHECK 701#elif defined GNULIB_POSIXCHECK
484# undef wctrans 702# undef wctrans
485# if HAVE_RAW_DECL_WCTRANS 703# if HAVE_RAW_DECL_WCTRANS
@@ -496,7 +714,9 @@ _GL_WARN_ON_USE (wctrans, "wctrans is unportable - "
496_GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc)); 714_GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
497# endif 715# endif
498_GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc)); 716_GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
717# if __GLIBC__ >= 2
499_GL_CXXALIASWARN (towctrans); 718_GL_CXXALIASWARN (towctrans);
719# endif
500#elif defined GNULIB_POSIXCHECK 720#elif defined GNULIB_POSIXCHECK
501# undef towctrans 721# undef towctrans
502# if HAVE_RAW_DECL_TOWCTRANS 722# if HAVE_RAW_DECL_TOWCTRANS
@@ -509,3 +729,4 @@ _GL_INLINE_HEADER_END
509 729
510#endif /* _@GUARD_PREFIX@_WCTYPE_H */ 730#endif /* _@GUARD_PREFIX@_WCTYPE_H */
511#endif /* _@GUARD_PREFIX@_WCTYPE_H */ 731#endif /* _@GUARD_PREFIX@_WCTYPE_H */
732#endif
diff --git a/gl/windows-initguard.h b/gl/windows-initguard.h
new file mode 100644
index 0000000..9d36f53
--- /dev/null
+++ b/gl/windows-initguard.h
@@ -0,0 +1,35 @@
1/* Init guards, somewhat like spinlocks (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#ifndef _WINDOWS_INITGUARD_H
21#define _WINDOWS_INITGUARD_H
22
23#define WIN32_LEAN_AND_MEAN /* avoid including junk */
24#include <windows.h>
25
26typedef struct
27 {
28 volatile int done;
29 volatile LONG started;
30 }
31 glwthread_initguard_t;
32
33#define GLWTHREAD_INITGUARD_INIT { 0, -1 }
34
35#endif /* _WINDOWS_INITGUARD_H */
diff --git a/gl/windows-mutex.c b/gl/windows-mutex.c
new file mode 100644
index 0000000..ab7258c
--- /dev/null
+++ b/gl/windows-mutex.c
@@ -0,0 +1,95 @@
1/* Plain mutexes (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#include <config.h>
21
22/* Specification. */
23#include "windows-mutex.h"
24
25#include <errno.h>
26
27void
28glwthread_mutex_init (glwthread_mutex_t *mutex)
29{
30 InitializeCriticalSection (&mutex->lock);
31 mutex->guard.done = 1;
32}
33
34int
35glwthread_mutex_lock (glwthread_mutex_t *mutex)
36{
37 if (!mutex->guard.done)
38 {
39 if (InterlockedIncrement (&mutex->guard.started) == 0)
40 /* This thread is the first one to need this mutex. Initialize it. */
41 glwthread_mutex_init (mutex);
42 else
43 {
44 /* Don't let mutex->guard.started grow and wrap around. */
45 InterlockedDecrement (&mutex->guard.started);
46 /* Yield the CPU while waiting for another thread to finish
47 initializing this mutex. */
48 while (!mutex->guard.done)
49 Sleep (0);
50 }
51 }
52 EnterCriticalSection (&mutex->lock);
53 return 0;
54}
55
56int
57glwthread_mutex_trylock (glwthread_mutex_t *mutex)
58{
59 if (!mutex->guard.done)
60 {
61 if (InterlockedIncrement (&mutex->guard.started) == 0)
62 /* This thread is the first one to need this mutex. Initialize it. */
63 glwthread_mutex_init (mutex);
64 else
65 {
66 /* Don't let mutex->guard.started grow and wrap around. */
67 InterlockedDecrement (&mutex->guard.started);
68 /* Let another thread finish initializing this mutex, and let it also
69 lock this mutex. */
70 return EBUSY;
71 }
72 }
73 if (!TryEnterCriticalSection (&mutex->lock))
74 return EBUSY;
75 return 0;
76}
77
78int
79glwthread_mutex_unlock (glwthread_mutex_t *mutex)
80{
81 if (!mutex->guard.done)
82 return EINVAL;
83 LeaveCriticalSection (&mutex->lock);
84 return 0;
85}
86
87int
88glwthread_mutex_destroy (glwthread_mutex_t *mutex)
89{
90 if (!mutex->guard.done)
91 return EINVAL;
92 DeleteCriticalSection (&mutex->lock);
93 mutex->guard.done = 0;
94 return 0;
95}
diff --git a/gl/windows-mutex.h b/gl/windows-mutex.h
new file mode 100644
index 0000000..039eb70
--- /dev/null
+++ b/gl/windows-mutex.h
@@ -0,0 +1,51 @@
1/* Plain mutexes (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#ifndef _WINDOWS_MUTEX_H
21#define _WINDOWS_MUTEX_H
22
23#define WIN32_LEAN_AND_MEAN /* avoid including junk */
24#include <windows.h>
25
26#include "windows-initguard.h"
27
28typedef struct
29 {
30 glwthread_initguard_t guard; /* protects the initialization */
31 CRITICAL_SECTION lock;
32 }
33 glwthread_mutex_t;
34
35#define GLWTHREAD_MUTEX_INIT { GLWTHREAD_INITGUARD_INIT }
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41extern void glwthread_mutex_init (glwthread_mutex_t *mutex);
42extern int glwthread_mutex_lock (glwthread_mutex_t *mutex);
43extern int glwthread_mutex_trylock (glwthread_mutex_t *mutex);
44extern int glwthread_mutex_unlock (glwthread_mutex_t *mutex);
45extern int glwthread_mutex_destroy (glwthread_mutex_t *mutex);
46
47#ifdef __cplusplus
48}
49#endif
50
51#endif /* _WINDOWS_MUTEX_H */
diff --git a/gl/windows-once.c b/gl/windows-once.c
new file mode 100644
index 0000000..0d28281
--- /dev/null
+++ b/gl/windows-once.c
@@ -0,0 +1,62 @@
1/* Once-only control (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#include <config.h>
21
22/* Specification. */
23#include "windows-once.h"
24
25#include <stdlib.h>
26
27void
28glwthread_once (glwthread_once_t *once_control, void (*initfunction) (void))
29{
30 if (once_control->inited <= 0)
31 {
32 if (InterlockedIncrement (&once_control->started) == 0)
33 {
34 /* This thread is the first one to come to this once_control. */
35 InitializeCriticalSection (&once_control->lock);
36 EnterCriticalSection (&once_control->lock);
37 once_control->inited = 0;
38 initfunction ();
39 once_control->inited = 1;
40 LeaveCriticalSection (&once_control->lock);
41 }
42 else
43 {
44 /* Don't let once_control->started grow and wrap around. */
45 InterlockedDecrement (&once_control->started);
46 /* Some other thread has already started the initialization.
47 Yield the CPU while waiting for the other thread to finish
48 initializing and taking the lock. */
49 while (once_control->inited < 0)
50 Sleep (0);
51 if (once_control->inited <= 0)
52 {
53 /* Take the lock. This blocks until the other thread has
54 finished calling the initfunction. */
55 EnterCriticalSection (&once_control->lock);
56 LeaveCriticalSection (&once_control->lock);
57 if (!(once_control->inited > 0))
58 abort ();
59 }
60 }
61 }
62}
diff --git a/gl/windows-once.h b/gl/windows-once.h
new file mode 100644
index 0000000..5488568
--- /dev/null
+++ b/gl/windows-once.h
@@ -0,0 +1,47 @@
1/* Once-only control (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#ifndef _WINDOWS_ONCE_H
21#define _WINDOWS_ONCE_H
22
23#define WIN32_LEAN_AND_MEAN /* avoid including junk */
24#include <windows.h>
25
26typedef struct
27 {
28 volatile int inited;
29 volatile LONG started;
30 CRITICAL_SECTION lock;
31 }
32 glwthread_once_t;
33
34#define GLWTHREAD_ONCE_INIT { -1, -1 }
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40extern void glwthread_once (glwthread_once_t *once_control,
41 void (*initfunction) (void));
42
43#ifdef __cplusplus
44}
45#endif
46
47#endif /* _WINDOWS_ONCE_H */
diff --git a/gl/windows-recmutex.c b/gl/windows-recmutex.c
new file mode 100644
index 0000000..a8ce9a0
--- /dev/null
+++ b/gl/windows-recmutex.c
@@ -0,0 +1,127 @@
1/* Plain recursive mutexes (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#include <config.h>
21
22/* Specification. */
23#include "windows-recmutex.h"
24
25#include <errno.h>
26
27void
28glwthread_recmutex_init (glwthread_recmutex_t *mutex)
29{
30 mutex->owner = 0;
31 mutex->depth = 0;
32 InitializeCriticalSection (&mutex->lock);
33 mutex->guard.done = 1;
34}
35
36int
37glwthread_recmutex_lock (glwthread_recmutex_t *mutex)
38{
39 if (!mutex->guard.done)
40 {
41 if (InterlockedIncrement (&mutex->guard.started) == 0)
42 /* This thread is the first one to need this mutex. Initialize it. */
43 glwthread_recmutex_init (mutex);
44 else
45 {
46 /* Don't let mutex->guard.started grow and wrap around. */
47 InterlockedDecrement (&mutex->guard.started);
48 /* Yield the CPU while waiting for another thread to finish
49 initializing this mutex. */
50 while (!mutex->guard.done)
51 Sleep (0);
52 }
53 }
54 {
55 DWORD self = GetCurrentThreadId ();
56 if (mutex->owner != self)
57 {
58 EnterCriticalSection (&mutex->lock);
59 mutex->owner = self;
60 }
61 if (++(mutex->depth) == 0) /* wraparound? */
62 {
63 mutex->depth--;
64 return EAGAIN;
65 }
66 }
67 return 0;
68}
69
70int
71glwthread_recmutex_trylock (glwthread_recmutex_t *mutex)
72{
73 if (!mutex->guard.done)
74 {
75 if (InterlockedIncrement (&mutex->guard.started) == 0)
76 /* This thread is the first one to need this mutex. Initialize it. */
77 glwthread_recmutex_init (mutex);
78 else
79 {
80 /* Don't let mutex->guard.started grow and wrap around. */
81 InterlockedDecrement (&mutex->guard.started);
82 /* Let another thread finish initializing this mutex, and let it also
83 lock this mutex. */
84 return EBUSY;
85 }
86 }
87 {
88 DWORD self = GetCurrentThreadId ();
89 if (mutex->owner != self)
90 {
91 if (!TryEnterCriticalSection (&mutex->lock))
92 return EBUSY;
93 mutex->owner = self;
94 }
95 if (++(mutex->depth) == 0) /* wraparound? */
96 {
97 mutex->depth--;
98 return EAGAIN;
99 }
100 }
101 return 0;
102}
103
104int
105glwthread_recmutex_unlock (glwthread_recmutex_t *mutex)
106{
107 if (mutex->owner != GetCurrentThreadId ())
108 return EPERM;
109 if (mutex->depth == 0)
110 return EINVAL;
111 if (--(mutex->depth) == 0)
112 {
113 mutex->owner = 0;
114 LeaveCriticalSection (&mutex->lock);
115 }
116 return 0;
117}
118
119int
120glwthread_recmutex_destroy (glwthread_recmutex_t *mutex)
121{
122 if (mutex->owner != 0)
123 return EBUSY;
124 DeleteCriticalSection (&mutex->lock);
125 mutex->guard.done = 0;
126 return 0;
127}
diff --git a/gl/windows-recmutex.h b/gl/windows-recmutex.h
new file mode 100644
index 0000000..08ff459
--- /dev/null
+++ b/gl/windows-recmutex.h
@@ -0,0 +1,57 @@
1/* Plain recursive mutexes (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#ifndef _WINDOWS_RECMUTEX_H
21#define _WINDOWS_RECMUTEX_H
22
23#define WIN32_LEAN_AND_MEAN /* avoid including junk */
24#include <windows.h>
25
26#include "windows-initguard.h"
27
28/* The native Windows documentation says that CRITICAL_SECTION already
29 implements a recursive lock. But we need not rely on it: It's easy to
30 implement a recursive lock without this assumption. */
31
32typedef struct
33 {
34 glwthread_initguard_t guard; /* protects the initialization */
35 DWORD owner;
36 unsigned long depth;
37 CRITICAL_SECTION lock;
38 }
39 glwthread_recmutex_t;
40
41#define GLWTHREAD_RECMUTEX_INIT { GLWTHREAD_INITGUARD_INIT, 0, 0 }
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47extern void glwthread_recmutex_init (glwthread_recmutex_t *mutex);
48extern int glwthread_recmutex_lock (glwthread_recmutex_t *mutex);
49extern int glwthread_recmutex_trylock (glwthread_recmutex_t *mutex);
50extern int glwthread_recmutex_unlock (glwthread_recmutex_t *mutex);
51extern int glwthread_recmutex_destroy (glwthread_recmutex_t *mutex);
52
53#ifdef __cplusplus
54}
55#endif
56
57#endif /* _WINDOWS_RECMUTEX_H */
diff --git a/gl/windows-rwlock.c b/gl/windows-rwlock.c
new file mode 100644
index 0000000..7cbd7bb
--- /dev/null
+++ b/gl/windows-rwlock.c
@@ -0,0 +1,377 @@
1/* Read-write locks (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#include <config.h>
21
22/* Specification. */
23#include "windows-rwlock.h"
24
25#include <errno.h>
26#include <stdlib.h>
27
28/* Don't assume that UNICODE is not defined. */
29#undef CreateEvent
30#define CreateEvent CreateEventA
31
32/* In this file, the waitqueues are implemented as circular arrays. */
33#define glwthread_waitqueue_t glwthread_carray_waitqueue_t
34
35static void
36glwthread_waitqueue_init (glwthread_waitqueue_t *wq)
37{
38 wq->array = NULL;
39 wq->count = 0;
40 wq->alloc = 0;
41 wq->offset = 0;
42}
43
44/* Enqueues the current thread, represented by an event, in a wait queue.
45 Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */
46static HANDLE
47glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
48{
49 HANDLE event;
50 unsigned int index;
51
52 if (wq->count == wq->alloc)
53 {
54 unsigned int new_alloc = 2 * wq->alloc + 1;
55 HANDLE *new_array =
56 (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE));
57 if (new_array == NULL)
58 /* No more memory. */
59 return INVALID_HANDLE_VALUE;
60 /* Now is a good opportunity to rotate the array so that its contents
61 starts at offset 0. */
62 if (wq->offset > 0)
63 {
64 unsigned int old_count = wq->count;
65 unsigned int old_alloc = wq->alloc;
66 unsigned int old_offset = wq->offset;
67 unsigned int i;
68 if (old_offset + old_count > old_alloc)
69 {
70 unsigned int limit = old_offset + old_count - old_alloc;
71 for (i = 0; i < limit; i++)
72 new_array[old_alloc + i] = new_array[i];
73 }
74 for (i = 0; i < old_count; i++)
75 new_array[i] = new_array[old_offset + i];
76 wq->offset = 0;
77 }
78 wq->array = new_array;
79 wq->alloc = new_alloc;
80 }
81 /* Whether the created event is a manual-reset one or an auto-reset one,
82 does not matter, since we will wait on it only once. */
83 event = CreateEvent (NULL, TRUE, FALSE, NULL);
84 if (event == INVALID_HANDLE_VALUE)
85 /* No way to allocate an event. */
86 return INVALID_HANDLE_VALUE;
87 index = wq->offset + wq->count;
88 if (index >= wq->alloc)
89 index -= wq->alloc;
90 wq->array[index] = event;
91 wq->count++;
92 return event;
93}
94
95/* Notifies the first thread from a wait queue and dequeues it. */
96static void
97glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq)
98{
99 SetEvent (wq->array[wq->offset + 0]);
100 wq->offset++;
101 wq->count--;
102 if (wq->count == 0 || wq->offset == wq->alloc)
103 wq->offset = 0;
104}
105
106/* Notifies all threads from a wait queue and dequeues them all. */
107static void
108glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq)
109{
110 unsigned int i;
111
112 for (i = 0; i < wq->count; i++)
113 {
114 unsigned int index = wq->offset + i;
115 if (index >= wq->alloc)
116 index -= wq->alloc;
117 SetEvent (wq->array[index]);
118 }
119 wq->count = 0;
120 wq->offset = 0;
121}
122
123void
124glwthread_rwlock_init (glwthread_rwlock_t *lock)
125{
126 InitializeCriticalSection (&lock->lock);
127 glwthread_waitqueue_init (&lock->waiting_readers);
128 glwthread_waitqueue_init (&lock->waiting_writers);
129 lock->runcount = 0;
130 lock->guard.done = 1;
131}
132
133int
134glwthread_rwlock_rdlock (glwthread_rwlock_t *lock)
135{
136 if (!lock->guard.done)
137 {
138 if (InterlockedIncrement (&lock->guard.started) == 0)
139 /* This thread is the first one to need this lock. Initialize it. */
140 glwthread_rwlock_init (lock);
141 else
142 {
143 /* Don't let lock->guard.started grow and wrap around. */
144 InterlockedDecrement (&lock->guard.started);
145 /* Yield the CPU while waiting for another thread to finish
146 initializing this lock. */
147 while (!lock->guard.done)
148 Sleep (0);
149 }
150 }
151 EnterCriticalSection (&lock->lock);
152 /* Test whether only readers are currently running, and whether the runcount
153 field will not overflow, and whether no writer is waiting. The latter
154 condition is because POSIX recommends that "write locks shall take
155 precedence over read locks", to avoid "writer starvation". */
156 if (!(lock->runcount + 1 > 0 && lock->waiting_writers.count == 0))
157 {
158 /* This thread has to wait for a while. Enqueue it among the
159 waiting_readers. */
160 HANDLE event = glwthread_waitqueue_add (&lock->waiting_readers);
161 if (event != INVALID_HANDLE_VALUE)
162 {
163 DWORD result;
164 LeaveCriticalSection (&lock->lock);
165 /* Wait until another thread signals this event. */
166 result = WaitForSingleObject (event, INFINITE);
167 if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
168 abort ();
169 CloseHandle (event);
170 /* The thread which signalled the event already did the bookkeeping:
171 removed us from the waiting_readers, incremented lock->runcount. */
172 if (!(lock->runcount > 0))
173 abort ();
174 return 0;
175 }
176 else
177 {
178 /* Allocation failure. Weird. */
179 do
180 {
181 LeaveCriticalSection (&lock->lock);
182 Sleep (1);
183 EnterCriticalSection (&lock->lock);
184 }
185 while (!(lock->runcount + 1 > 0));
186 }
187 }
188 lock->runcount++;
189 LeaveCriticalSection (&lock->lock);
190 return 0;
191}
192
193int
194glwthread_rwlock_wrlock (glwthread_rwlock_t *lock)
195{
196 if (!lock->guard.done)
197 {
198 if (InterlockedIncrement (&lock->guard.started) == 0)
199 /* This thread is the first one to need this lock. Initialize it. */
200 glwthread_rwlock_init (lock);
201 else
202 {
203 /* Don't let lock->guard.started grow and wrap around. */
204 InterlockedDecrement (&lock->guard.started);
205 /* Yield the CPU while waiting for another thread to finish
206 initializing this lock. */
207 while (!lock->guard.done)
208 Sleep (0);
209 }
210 }
211 EnterCriticalSection (&lock->lock);
212 /* Test whether no readers or writers are currently running. */
213 if (!(lock->runcount == 0))
214 {
215 /* This thread has to wait for a while. Enqueue it among the
216 waiting_writers. */
217 HANDLE event = glwthread_waitqueue_add (&lock->waiting_writers);
218 if (event != INVALID_HANDLE_VALUE)
219 {
220 DWORD result;
221 LeaveCriticalSection (&lock->lock);
222 /* Wait until another thread signals this event. */
223 result = WaitForSingleObject (event, INFINITE);
224 if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
225 abort ();
226 CloseHandle (event);
227 /* The thread which signalled the event already did the bookkeeping:
228 removed us from the waiting_writers, set lock->runcount = -1. */
229 if (!(lock->runcount == -1))
230 abort ();
231 return 0;
232 }
233 else
234 {
235 /* Allocation failure. Weird. */
236 do
237 {
238 LeaveCriticalSection (&lock->lock);
239 Sleep (1);
240 EnterCriticalSection (&lock->lock);
241 }
242 while (!(lock->runcount == 0));
243 }
244 }
245 lock->runcount--; /* runcount becomes -1 */
246 LeaveCriticalSection (&lock->lock);
247 return 0;
248}
249
250int
251glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock)
252{
253 if (!lock->guard.done)
254 {
255 if (InterlockedIncrement (&lock->guard.started) == 0)
256 /* This thread is the first one to need this lock. Initialize it. */
257 glwthread_rwlock_init (lock);
258 else
259 {
260 /* Don't let lock->guard.started grow and wrap around. */
261 InterlockedDecrement (&lock->guard.started);
262 /* Yield the CPU while waiting for another thread to finish
263 initializing this lock. */
264 while (!lock->guard.done)
265 Sleep (0);
266 }
267 }
268 /* It's OK to wait for this critical section, because it is never taken for a
269 long time. */
270 EnterCriticalSection (&lock->lock);
271 /* Test whether only readers are currently running, and whether the runcount
272 field will not overflow, and whether no writer is waiting. The latter
273 condition is because POSIX recommends that "write locks shall take
274 precedence over read locks", to avoid "writer starvation". */
275 if (!(lock->runcount + 1 > 0 && lock->waiting_writers.count == 0))
276 {
277 /* This thread would have to wait for a while. Return instead. */
278 LeaveCriticalSection (&lock->lock);
279 return EBUSY;
280 }
281 lock->runcount++;
282 LeaveCriticalSection (&lock->lock);
283 return 0;
284}
285
286int
287glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock)
288{
289 if (!lock->guard.done)
290 {
291 if (InterlockedIncrement (&lock->guard.started) == 0)
292 /* This thread is the first one to need this lock. Initialize it. */
293 glwthread_rwlock_init (lock);
294 else
295 {
296 /* Don't let lock->guard.started grow and wrap around. */
297 InterlockedDecrement (&lock->guard.started);
298 /* Yield the CPU while waiting for another thread to finish
299 initializing this lock. */
300 while (!lock->guard.done)
301 Sleep (0);
302 }
303 }
304 /* It's OK to wait for this critical section, because it is never taken for a
305 long time. */
306 EnterCriticalSection (&lock->lock);
307 /* Test whether no readers or writers are currently running. */
308 if (!(lock->runcount == 0))
309 {
310 /* This thread would have to wait for a while. Return instead. */
311 LeaveCriticalSection (&lock->lock);
312 return EBUSY;
313 }
314 lock->runcount--; /* runcount becomes -1 */
315 LeaveCriticalSection (&lock->lock);
316 return 0;
317}
318
319int
320glwthread_rwlock_unlock (glwthread_rwlock_t *lock)
321{
322 if (!lock->guard.done)
323 return EINVAL;
324 EnterCriticalSection (&lock->lock);
325 if (lock->runcount < 0)
326 {
327 /* Drop a writer lock. */
328 if (!(lock->runcount == -1))
329 abort ();
330 lock->runcount = 0;
331 }
332 else
333 {
334 /* Drop a reader lock. */
335 if (!(lock->runcount > 0))
336 {
337 LeaveCriticalSection (&lock->lock);
338 return EPERM;
339 }
340 lock->runcount--;
341 }
342 if (lock->runcount == 0)
343 {
344 /* POSIX recommends that "write locks shall take precedence over read
345 locks", to avoid "writer starvation". */
346 if (lock->waiting_writers.count > 0)
347 {
348 /* Wake up one of the waiting writers. */
349 lock->runcount--;
350 glwthread_waitqueue_notify_first (&lock->waiting_writers);
351 }
352 else
353 {
354 /* Wake up all waiting readers. */
355 lock->runcount += lock->waiting_readers.count;
356 glwthread_waitqueue_notify_all (&lock->waiting_readers);
357 }
358 }
359 LeaveCriticalSection (&lock->lock);
360 return 0;
361}
362
363int
364glwthread_rwlock_destroy (glwthread_rwlock_t *lock)
365{
366 if (!lock->guard.done)
367 return EINVAL;
368 if (lock->runcount != 0)
369 return EBUSY;
370 DeleteCriticalSection (&lock->lock);
371 if (lock->waiting_readers.array != NULL)
372 free (lock->waiting_readers.array);
373 if (lock->waiting_writers.array != NULL)
374 free (lock->waiting_writers.array);
375 lock->guard.done = 0;
376 return 0;
377}
diff --git a/gl/windows-rwlock.h b/gl/windows-rwlock.h
new file mode 100644
index 0000000..fe8381e
--- /dev/null
+++ b/gl/windows-rwlock.h
@@ -0,0 +1,68 @@
1/* Read-write locks (native Windows implementation).
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2005.
18 Based on GCC's gthr-win32.h. */
19
20#ifndef _WINDOWS_RWLOCK_H
21#define _WINDOWS_RWLOCK_H
22
23#define WIN32_LEAN_AND_MEAN /* avoid including junk */
24#include <windows.h>
25
26#include "windows-initguard.h"
27
28/* It is impossible to implement read-write locks using plain locks, without
29 introducing an extra thread dedicated to managing read-write locks.
30 Therefore here we need to use the low-level Event type. */
31
32typedef struct
33 {
34 HANDLE *array; /* array of waiting threads, each represented by an event */
35 unsigned int count; /* number of waiting threads */
36 unsigned int alloc; /* length of allocated array */
37 unsigned int offset; /* index of first waiting thread in array */
38 }
39 glwthread_carray_waitqueue_t;
40typedef struct
41 {
42 glwthread_initguard_t guard; /* protects the initialization */
43 CRITICAL_SECTION lock; /* protects the remaining fields */
44 glwthread_carray_waitqueue_t waiting_readers; /* waiting readers */
45 glwthread_carray_waitqueue_t waiting_writers; /* waiting writers */
46 int runcount; /* number of readers running, or -1 when a writer runs */
47 }
48 glwthread_rwlock_t;
49
50#define GLWTHREAD_RWLOCK_INIT { GLWTHREAD_INITGUARD_INIT }
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56extern void glwthread_rwlock_init (glwthread_rwlock_t *lock);
57extern int glwthread_rwlock_rdlock (glwthread_rwlock_t *lock);
58extern int glwthread_rwlock_wrlock (glwthread_rwlock_t *lock);
59extern int glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock);
60extern int glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock);
61extern int glwthread_rwlock_unlock (glwthread_rwlock_t *lock);
62extern int glwthread_rwlock_destroy (glwthread_rwlock_t *lock);
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif /* _WINDOWS_RWLOCK_H */
diff --git a/gl/xalloc-die.c b/gl/xalloc-die.c
index daa403b..7605eee 100644
--- a/gl/xalloc-die.c
+++ b/gl/xalloc-die.c
@@ -1,11 +1,11 @@
1/* Report a memory allocation failure and exit. 1/* Report a memory allocation failure and exit.
2 2
3 Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2013 Free Software 3 Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2023 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 3 of the License, or 8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) 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,
@@ -14,7 +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, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
diff --git a/gl/xalloc-oversized.h b/gl/xalloc-oversized.h
index a971c78..5dbdfb5 100644
--- a/gl/xalloc-oversized.h
+++ b/gl/xalloc-oversized.h
@@ -1,38 +1,65 @@
1/* xalloc-oversized.h -- memory allocation size checking 1/* xalloc-oversized.h -- memory allocation size checking
2 2
3 Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc. 3 Copyright (C) 1990-2000, 2003-2004, 2006-2023 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef XALLOC_OVERSIZED_H_ 18#ifndef XALLOC_OVERSIZED_H_
19# define XALLOC_OVERSIZED_H_ 19#define XALLOC_OVERSIZED_H_
20 20
21# include <stddef.h> 21#include <stddef.h>
22 22#include <stdint.h>
23/* Return 1 if an array of N objects, each of size S, cannot exist due 23
24 to size arithmetic overflow. S must be positive and N must be 24/* True if N * S does not fit into both ptrdiff_t and size_t.
25 nonnegative. This is a macro, not a function, so that it 25 N and S should be nonnegative and free of side effects.
26 works correctly even when SIZE_MAX < N. 26 This expands to a constant expression if N and S are both constants.
27 27 By gnulib convention, SIZE_MAX represents overflow in size_t
28 By gnulib convention, SIZE_MAX represents overflow in size 28 calculations, so the conservative size_t-based dividend to use here
29 calculations, so the conservative dividend to use here is 29 is SIZE_MAX - 1. */
30 SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. 30#define __xalloc_oversized(n, s) \
31 However, malloc (SIZE_MAX) fails on all known hosts where 31 ((s) != 0 \
32 sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for 32 && ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) \
33 exactly-SIZE_MAX allocations on such hosts; this avoids a test and 33 < (n)))
34 branch when S is known to be 1. */ 34
35/* Return 1 if and only if an array of N objects, each of size S,
36 cannot exist reliably because its total size in bytes would exceed
37 MIN (PTRDIFF_MAX, SIZE_MAX - 1).
38
39 N and S should be nonnegative and free of side effects.
40
41 Warning: (xalloc_oversized (N, S) ? NULL : malloc (N * S)) can
42 misbehave if N and S are both narrower than ptrdiff_t and size_t,
43 and can be rewritten as (xalloc_oversized (N, S) ? NULL
44 : malloc (N * (size_t) S)).
45
46 This is a macro, not a function, so that it works even if an
47 argument exceeds MAX (PTRDIFF_MAX, SIZE_MAX). */
48#if 7 <= __GNUC__ && !defined __clang__ && PTRDIFF_MAX < SIZE_MAX
35# define xalloc_oversized(n, s) \ 49# define xalloc_oversized(n, s) \
36 ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) 50 __builtin_mul_overflow_p (n, s, (ptrdiff_t) 1)
51#elif (5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ \
52 && PTRDIFF_MAX < SIZE_MAX)
53# define xalloc_oversized(n, s) \
54 (__builtin_constant_p (n) && __builtin_constant_p (s) \
55 ? __xalloc_oversized (n, s) \
56 : ({ ptrdiff_t __xalloc_count; \
57 __builtin_mul_overflow (n, s, &__xalloc_count); }))
58
59/* Other compilers use integer division; this may be slower but is
60 more portable. */
61#else
62# define xalloc_oversized(n, s) __xalloc_oversized (n, s)
63#endif
37 64
38#endif /* !XALLOC_OVERSIZED_H_ */ 65#endif /* !XALLOC_OVERSIZED_H_ */
diff --git a/gl/xalloc.h b/gl/xalloc.h
index da7c4b6..f373c2f 100644
--- a/gl/xalloc.h
+++ b/gl/xalloc.h
@@ -1,10 +1,10 @@
1/* xalloc.h -- malloc with out-of-memory checking 1/* xalloc.h -- malloc with out-of-memory checking
2 2
3 Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc. 3 Copyright (C) 1990-2000, 2003-2004, 2006-2023 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 3 of the License, or 7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) 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,
@@ -13,57 +13,92 @@
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, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef XALLOC_H_ 18#ifndef XALLOC_H_
19#define XALLOC_H_ 19#define XALLOC_H_
20 20
21#include <stddef.h> 21#include <stddef.h>
22#include <stdlib.h>
22 23
23#include "xalloc-oversized.h" 24#if GNULIB_XALLOC
25# include "idx.h"
26#endif
24 27
28#ifndef _GL_INLINE_HEADER_BEGIN
29 #error "Please include config.h first."
30#endif
25_GL_INLINE_HEADER_BEGIN 31_GL_INLINE_HEADER_BEGIN
26#ifndef XALLOC_INLINE 32#ifndef XALLOC_INLINE
27# define XALLOC_INLINE _GL_INLINE 33# define XALLOC_INLINE _GL_INLINE
28#endif 34#endif
29 35
36
30#ifdef __cplusplus 37#ifdef __cplusplus
31extern "C" { 38extern "C" {
32#endif 39#endif
33 40
34 41
35#if __GNUC__ >= 3 42#if GNULIB_XALLOC_DIE
36# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
37#else
38# define _GL_ATTRIBUTE_MALLOC
39#endif
40
41#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
42# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
43#else
44# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
45#endif
46 43
47/* This function is always triggered when memory is exhausted. 44/* This function is always triggered when memory is exhausted.
48 It must be defined by the application, either explicitly 45 It must be defined by the application, either explicitly
49 or by using gnulib's xalloc-die module. This is the 46 or by using gnulib's xalloc-die module. This is the
50 function to call when one wants the program to die because of a 47 function to call when one wants the program to die because of a
51 memory allocation failure. */ 48 memory allocation failure. */
52extern _Noreturn void xalloc_die (void); 49/*extern*/ _Noreturn void xalloc_die (void);
50
51#endif /* GNULIB_XALLOC_DIE */
52
53#if GNULIB_XALLOC
53 54
54void *xmalloc (size_t s) 55void *xmalloc (size_t s)
55 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 56 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
57 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
58void *ximalloc (idx_t s)
59 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
60 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
61void *xinmalloc (idx_t n, idx_t s)
62 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
63 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
56void *xzalloc (size_t s) 64void *xzalloc (size_t s)
57 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 65 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
66 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
67void *xizalloc (idx_t s)
68 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
69 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
58void *xcalloc (size_t n, size_t s) 70void *xcalloc (size_t n, size_t s)
59 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)); 71 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
72 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
73void *xicalloc (idx_t n, idx_t s)
74 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
75 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
60void *xrealloc (void *p, size_t s) 76void *xrealloc (void *p, size_t s)
61 _GL_ATTRIBUTE_ALLOC_SIZE ((2)); 77 _GL_ATTRIBUTE_ALLOC_SIZE ((2));
62void *x2realloc (void *p, size_t *pn); 78void *xirealloc (void *p, idx_t s)
79 _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
80void *xreallocarray (void *p, size_t n, size_t s)
81 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
82void *xireallocarray (void *p, idx_t n, idx_t s)
83 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3)) _GL_ATTRIBUTE_RETURNS_NONNULL;
84void *x2realloc (void *p, size_t *ps) /* superseded by xpalloc */
85 _GL_ATTRIBUTE_RETURNS_NONNULL;
86void *x2nrealloc (void *p, size_t *pn, size_t s) /* superseded by xpalloc */
87 _GL_ATTRIBUTE_RETURNS_NONNULL;
88void *xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
89 _GL_ATTRIBUTE_RETURNS_NONNULL;
63void *xmemdup (void const *p, size_t s) 90void *xmemdup (void const *p, size_t s)
64 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2)); 91 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
92 _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
93void *ximemdup (void const *p, idx_t s)
94 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
95 _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
96char *ximemdup0 (void const *p, idx_t s)
97 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
98 _GL_ATTRIBUTE_RETURNS_NONNULL;
65char *xstrdup (char const *str) 99char *xstrdup (char const *str)
66 _GL_ATTRIBUTE_MALLOC; 100 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
101 _GL_ATTRIBUTE_RETURNS_NONNULL;
67 102
68/* In the following macros, T must be an elementary or structure/union or 103/* In the following macros, T must be an elementary or structure/union or
69 typedef'ed type, or a pointer to such a type. To apply one of the 104 typedef'ed type, or a pointer to such a type. To apply one of the
@@ -72,153 +107,60 @@ char *xstrdup (char const *str)
72 107
73/* Allocate an object of type T dynamically, with error checking. */ 108/* Allocate an object of type T dynamically, with error checking. */
74/* extern t *XMALLOC (typename t); */ 109/* extern t *XMALLOC (typename t); */
75#define XMALLOC(t) ((t *) xmalloc (sizeof (t))) 110# define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
76 111
77/* Allocate memory for N elements of type T, with error checking. */ 112/* Allocate memory for N elements of type T, with error checking. */
78/* extern t *XNMALLOC (size_t n, typename t); */ 113/* extern t *XNMALLOC (size_t n, typename t); */
79#define XNMALLOC(n, t) \ 114# define XNMALLOC(n, t) \
80 ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) 115 ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
81 116
82/* Allocate an object of type T dynamically, with error checking, 117/* Allocate an object of type T dynamically, with error checking,
83 and zero it. */ 118 and zero it. */
84/* extern t *XZALLOC (typename t); */ 119/* extern t *XZALLOC (typename t); */
85#define XZALLOC(t) ((t *) xzalloc (sizeof (t))) 120# define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
86 121
87/* Allocate memory for N elements of type T, with error checking, 122/* Allocate memory for N elements of type T, with error checking,
88 and zero it. */ 123 and zero it. */
89/* extern t *XCALLOC (size_t n, typename t); */ 124/* extern t *XCALLOC (size_t n, typename t); */
90#define XCALLOC(n, t) \ 125# define XCALLOC(n, t) \
91 ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) 126 ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
92 127
93 128
94/* Allocate an array of N objects, each with S bytes of memory, 129/* Allocate an array of N objects, each with S bytes of memory,
95 dynamically, with error checking. S must be nonzero. */ 130 dynamically, with error checking. S must be nonzero. */
96 131
97XALLOC_INLINE void *xnmalloc (size_t n, size_t s) 132void *xnmalloc (size_t n, size_t s)
98 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)); 133 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
99XALLOC_INLINE void * 134 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
100xnmalloc (size_t n, size_t s)
101{
102 if (xalloc_oversized (n, s))
103 xalloc_die ();
104 return xmalloc (n * s);
105}
106 135
136/* FIXME: Deprecate this in favor of xreallocarray? */
107/* Change the size of an allocated block of memory P to an array of N 137/* Change the size of an allocated block of memory P to an array of N
108 objects each of S bytes, with error checking. S must be nonzero. */ 138 objects each of S bytes, with error checking. S must be nonzero. */
109 139
110XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s) 140XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s)
111 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3)); 141 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
112XALLOC_INLINE void * 142XALLOC_INLINE void *
113xnrealloc (void *p, size_t n, size_t s) 143xnrealloc (void *p, size_t n, size_t s)
114{ 144{
115 if (xalloc_oversized (n, s)) 145 return xreallocarray (p, n, s);
116 xalloc_die ();
117 return xrealloc (p, n * s);
118}
119
120/* If P is null, allocate a block of at least *PN such objects;
121 otherwise, reallocate P so that it contains more than *PN objects
122 each of S bytes. *PN must be nonzero unless P is null, and S must
123 be nonzero. Set *PN to the new number of objects, and return the
124 pointer to the new block. *PN is never set to zero, and the
125 returned pointer is never null.
126
127 Repeated reallocations are guaranteed to make progress, either by
128 allocating an initial block with a nonzero size, or by allocating a
129 larger block.
130
131 In the following implementation, nonzero sizes are increased by a
132 factor of approximately 1.5 so that repeated reallocations have
133 O(N) overall cost rather than O(N**2) cost, but the
134 specification for this function does not guarantee that rate.
135
136 Here is an example of use:
137
138 int *p = NULL;
139 size_t used = 0;
140 size_t allocated = 0;
141
142 void
143 append_int (int value)
144 {
145 if (used == allocated)
146 p = x2nrealloc (p, &allocated, sizeof *p);
147 p[used++] = value;
148 }
149
150 This causes x2nrealloc to allocate a block of some nonzero size the
151 first time it is called.
152
153 To have finer-grained control over the initial size, set *PN to a
154 nonzero value before calling this function with P == NULL. For
155 example:
156
157 int *p = NULL;
158 size_t used = 0;
159 size_t allocated = 0;
160 size_t allocated1 = 1000;
161
162 void
163 append_int (int value)
164 {
165 if (used == allocated)
166 {
167 p = x2nrealloc (p, &allocated1, sizeof *p);
168 allocated = allocated1;
169 }
170 p[used++] = value;
171 }
172
173 */
174
175XALLOC_INLINE void *
176x2nrealloc (void *p, size_t *pn, size_t s)
177{
178 size_t n = *pn;
179
180 if (! p)
181 {
182 if (! n)
183 {
184 /* The approximate size to use for initial small allocation
185 requests, when the invoking code specifies an old size of
186 zero. This is the largest "small" request for the GNU C
187 library malloc. */
188 enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
189
190 n = DEFAULT_MXFAST / s;
191 n += !n;
192 }
193 }
194 else
195 {
196 /* Set N = ceil (1.5 * N) so that progress is made if N == 1.
197 Check for overflow, so that N * S stays in size_t range.
198 The check is slightly conservative, but an exact check isn't
199 worth the trouble. */
200 if ((size_t) -1 / 3 * 2 / s <= n)
201 xalloc_die ();
202 n += (n + 1) / 2;
203 }
204
205 *pn = n;
206 return xrealloc (p, n * s);
207} 146}
208 147
209/* Return a pointer to a new buffer of N bytes. This is like xmalloc, 148/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
210 except it returns char *. */ 149 except it returns char *. */
211 150
212XALLOC_INLINE char *xcharalloc (size_t n) 151char *xcharalloc (size_t n)
213 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 152 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
214XALLOC_INLINE char * 153 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
215xcharalloc (size_t n) 154
216{ 155#endif /* GNULIB_XALLOC */
217 return XNMALLOC (n, char); 156
218}
219 157
220#ifdef __cplusplus 158#ifdef __cplusplus
221} 159}
160#endif
161
162
163#if GNULIB_XALLOC && defined __cplusplus
222 164
223/* C++ does not allow conversions from void * to other pointer types 165/* C++ does not allow conversions from void * to other pointer types
224 without a cast. Use templates to work around the problem when 166 without a cast. Use templates to work around the problem when
@@ -231,9 +173,16 @@ xrealloc (T *p, size_t s)
231} 173}
232 174
233template <typename T> inline T * 175template <typename T> inline T *
176xreallocarray (T *p, size_t n, size_t s)
177{
178 return (T *) xreallocarray ((void *) p, n, s);
179}
180
181/* FIXME: Deprecate this in favor of xreallocarray? */
182template <typename T> inline T *
234xnrealloc (T *p, size_t n, size_t s) 183xnrealloc (T *p, size_t n, size_t s)
235{ 184{
236 return (T *) xnrealloc ((void *) p, n, s); 185 return xreallocarray (p, n, s);
237} 186}
238 187
239template <typename T> inline T * 188template <typename T> inline T *
@@ -254,7 +203,9 @@ xmemdup (T const *p, size_t s)
254 return (T *) xmemdup ((void const *) p, s); 203 return (T *) xmemdup ((void const *) p, s);
255} 204}
256 205
257#endif 206#endif /* GNULIB_XALLOC && C++ */
207
258 208
209_GL_INLINE_HEADER_END
259 210
260#endif /* !XALLOC_H_ */ 211#endif /* !XALLOC_H_ */
diff --git a/gl/xmalloc.c b/gl/xmalloc.c
index 57e34b7..289cbd0 100644
--- a/gl/xmalloc.c
+++ b/gl/xmalloc.c
@@ -1,10 +1,10 @@
1/* xmalloc.c -- malloc with out of memory checking 1/* xmalloc.c -- malloc with out of memory checking
2 2
3 Copyright (C) 1990-2000, 2002-2006, 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 1990-2000, 2002-2006, 2008-2023 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 3 of the License, or 7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) 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,
@@ -13,7 +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, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -21,59 +21,256 @@
21 21
22#include "xalloc.h" 22#include "xalloc.h"
23 23
24#include "ialloc.h"
25#include "minmax.h"
26
27#include <stdckdint.h>
24#include <stdlib.h> 28#include <stdlib.h>
29#include <stdint.h>
25#include <string.h> 30#include <string.h>
26 31
27/* 1 if calloc is known to be compatible with GNU calloc. This 32static void * _GL_ATTRIBUTE_PURE
28 matters if we are not also using the calloc module, which defines 33nonnull (void *p)
29 HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms. */ 34{
30#if defined HAVE_CALLOC_GNU || (defined __GLIBC__ && !defined __UCLIBC__) 35 if (!p)
31enum { HAVE_GNU_CALLOC = 1 }; 36 xalloc_die ();
32#else 37 return p;
33enum { HAVE_GNU_CALLOC = 0 }; 38}
34#endif
35 39
36/* Allocate N bytes of memory dynamically, with error checking. */ 40/* Allocate S bytes of memory dynamically, with error checking. */
37 41
38void * 42void *
39xmalloc (size_t n) 43xmalloc (size_t s)
40{ 44{
41 void *p = malloc (n); 45 return nonnull (malloc (s));
42 if (!p && n != 0) 46}
43 xalloc_die (); 47
44 return p; 48void *
49ximalloc (idx_t s)
50{
51 return nonnull (imalloc (s));
45} 52}
46 53
47/* Change the size of an allocated block of memory P to N bytes, 54char *
55xcharalloc (size_t n)
56{
57 return XNMALLOC (n, char);
58}
59
60/* Change the size of an allocated block of memory P to S bytes,
48 with error checking. */ 61 with error checking. */
49 62
50void * 63void *
51xrealloc (void *p, size_t n) 64xrealloc (void *p, size_t s)
65{
66 void *r = realloc (p, s);
67 if (!r && (!p || s))
68 xalloc_die ();
69 return r;
70}
71
72void *
73xirealloc (void *p, idx_t s)
74{
75 return nonnull (irealloc (p, s));
76}
77
78/* Change the size of an allocated block of memory P to an array of N
79 objects each of S bytes, with error checking. */
80
81void *
82xreallocarray (void *p, size_t n, size_t s)
83{
84 void *r = reallocarray (p, n, s);
85 if (!r && (!p || (n && s)))
86 xalloc_die ();
87 return r;
88}
89
90void *
91xireallocarray (void *p, idx_t n, idx_t s)
92{
93 return nonnull (ireallocarray (p, n, s));
94}
95
96/* Allocate an array of N objects, each with S bytes of memory,
97 dynamically, with error checking. S must be nonzero. */
98
99void *
100xnmalloc (size_t n, size_t s)
101{
102 return xreallocarray (NULL, n, s);
103}
104
105void *
106xinmalloc (idx_t n, idx_t s)
107{
108 return xireallocarray (NULL, n, s);
109}
110
111/* If P is null, allocate a block of at least *PS bytes; otherwise,
112 reallocate P so that it contains more than *PS bytes. *PS must be
113 nonzero unless P is null. Set *PS to the new block's size, and
114 return the pointer to the new block. *PS is never set to zero, and
115 the returned pointer is never null. */
116
117void *
118x2realloc (void *p, size_t *ps)
119{
120 return x2nrealloc (p, ps, 1);
121}
122
123/* If P is null, allocate a block of at least *PN such objects;
124 otherwise, reallocate P so that it contains more than *PN objects
125 each of S bytes. S must be nonzero. Set *PN to the new number of
126 objects, and return the pointer to the new block. *PN is never set
127 to zero, and the returned pointer is never null.
128
129 Repeated reallocations are guaranteed to make progress, either by
130 allocating an initial block with a nonzero size, or by allocating a
131 larger block.
132
133 In the following implementation, nonzero sizes are increased by a
134 factor of approximately 1.5 so that repeated reallocations have
135 O(N) overall cost rather than O(N**2) cost, but the
136 specification for this function does not guarantee that rate.
137
138 Here is an example of use:
139
140 int *p = NULL;
141 size_t used = 0;
142 size_t allocated = 0;
143
144 void
145 append_int (int value)
146 {
147 if (used == allocated)
148 p = x2nrealloc (p, &allocated, sizeof *p);
149 p[used++] = value;
150 }
151
152 This causes x2nrealloc to allocate a block of some nonzero size the
153 first time it is called.
154
155 To have finer-grained control over the initial size, set *PN to a
156 nonzero value before calling this function with P == NULL. For
157 example:
158
159 int *p = NULL;
160 size_t used = 0;
161 size_t allocated = 0;
162 size_t allocated1 = 1000;
163
164 void
165 append_int (int value)
166 {
167 if (used == allocated)
168 {
169 p = x2nrealloc (p, &allocated1, sizeof *p);
170 allocated = allocated1;
171 }
172 p[used++] = value;
173 }
174
175 */
176
177void *
178x2nrealloc (void *p, size_t *pn, size_t s)
52{ 179{
53 if (!n && p) 180 size_t n = *pn;
181
182 if (! p)
54 { 183 {
55 /* The GNU and C99 realloc behaviors disagree here. Act like 184 if (! n)
56 GNU, even if the underlying realloc is C99. */ 185 {
57 free (p); 186 /* The approximate size to use for initial small allocation
58 return NULL; 187 requests, when the invoking code specifies an old size of
188 zero. This is the largest "small" request for the GNU C
189 library malloc. */
190 enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
191
192 n = DEFAULT_MXFAST / s;
193 n += !n;
194 }
195 }
196 else
197 {
198 /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */
199 if (ckd_add (&n, n, (n >> 1) + 1))
200 xalloc_die ();
59 } 201 }
60 202
61 p = realloc (p, n); 203 p = xreallocarray (p, n, s);
62 if (!p && n) 204 *pn = n;
63 xalloc_die ();
64 return p; 205 return p;
65} 206}
66 207
67/* If P is null, allocate a block of at least *PN bytes; otherwise, 208/* Grow PA, which points to an array of *PN items, and return the
68 reallocate P so that it contains more than *PN bytes. *PN must be 209 location of the reallocated array, updating *PN to reflect its
69 nonzero unless P is null. Set *PN to the new block's size, and 210 new size. The new array will contain at least N_INCR_MIN more
70 return the pointer to the new block. *PN is never set to zero, and 211 items, but will not contain more than N_MAX items total.
71 the returned pointer is never null. */ 212 S is the size of each item, in bytes.
213
214 S and N_INCR_MIN must be positive. *PN must be
215 nonnegative. If N_MAX is -1, it is treated as if it were
216 infinity.
217
218 If PA is null, then allocate a new array instead of reallocating
219 the old one.
220
221 Thus, to grow an array A without saving its old contents, do
222 { free (A); A = xpalloc (NULL, &AITEMS, ...); }. */
72 223
73void * 224void *
74x2realloc (void *p, size_t *pn) 225xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
75{ 226{
76 return x2nrealloc (p, pn, 1); 227 idx_t n0 = *pn;
228
229 /* The approximate size to use for initial small allocation
230 requests. This is the largest "small" request for the GNU C
231 library malloc. */
232 enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
233
234 /* If the array is tiny, grow it to about (but no greater than)
235 DEFAULT_MXFAST bytes. Otherwise, grow it by about 50%.
236 Adjust the growth according to three constraints: N_INCR_MIN,
237 N_MAX, and what the C language can represent safely. */
238
239 idx_t n;
240 if (ckd_add (&n, n0, n0 >> 1))
241 n = IDX_MAX;
242 if (0 <= n_max && n_max < n)
243 n = n_max;
244
245 /* NBYTES is of a type suitable for holding the count of bytes in an object.
246 This is typically idx_t, but it should be size_t on (theoretical?)
247 platforms where SIZE_MAX < IDX_MAX so xpalloc does not pass
248 values greater than SIZE_MAX to xrealloc. */
249#if IDX_MAX <= SIZE_MAX
250 idx_t nbytes;
251#else
252 size_t nbytes;
253#endif
254 idx_t adjusted_nbytes
255 = (ckd_mul (&nbytes, n, s)
256 ? MIN (IDX_MAX, SIZE_MAX)
257 : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
258 if (adjusted_nbytes)
259 {
260 n = adjusted_nbytes / s;
261 nbytes = adjusted_nbytes - adjusted_nbytes % s;
262 }
263
264 if (! pa)
265 *pn = 0;
266 if (n - n0 < n_incr_min
267 && (ckd_add (&n, n0, n_incr_min)
268 || (0 <= n_max && n_max < n)
269 || ckd_mul (&nbytes, n, s)))
270 xalloc_die ();
271 pa = xrealloc (pa, nbytes);
272 *pn = n;
273 return pa;
77} 274}
78 275
79/* Allocate S bytes of zeroed memory dynamically, with error checking. 276/* Allocate S bytes of zeroed memory dynamically, with error checking.
@@ -83,7 +280,13 @@ x2realloc (void *p, size_t *pn)
83void * 280void *
84xzalloc (size_t s) 281xzalloc (size_t s)
85{ 282{
86 return memset (xmalloc (s), 0, s); 283 return xcalloc (s, 1);
284}
285
286void *
287xizalloc (idx_t s)
288{
289 return xicalloc (s, 1);
87} 290}
88 291
89/* Allocate zeroed memory for N elements of S bytes, with error 292/* Allocate zeroed memory for N elements of S bytes, with error
@@ -92,15 +295,13 @@ xzalloc (size_t s)
92void * 295void *
93xcalloc (size_t n, size_t s) 296xcalloc (size_t n, size_t s)
94{ 297{
95 void *p; 298 return nonnull (calloc (n, s));
96 /* Test for overflow, since some calloc implementations don't have 299}
97 proper overflow checks. But omit overflow and size-zero tests if 300
98 HAVE_GNU_CALLOC, since GNU calloc catches overflow and never 301void *
99 returns NULL if successful. */ 302xicalloc (idx_t n, idx_t s)
100 if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) 303{
101 || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) 304 return nonnull (icalloc (n, s));
102 xalloc_die ();
103 return p;
104} 305}
105 306
106/* Clone an object P of size S, with error checking. There's no need 307/* Clone an object P of size S, with error checking. There's no need
@@ -113,6 +314,23 @@ xmemdup (void const *p, size_t s)
113 return memcpy (xmalloc (s), p, s); 314 return memcpy (xmalloc (s), p, s);
114} 315}
115 316
317void *
318ximemdup (void const *p, idx_t s)
319{
320 return memcpy (ximalloc (s), p, s);
321}
322
323/* Clone an object P of size S, with error checking. Append
324 a terminating NUL byte. */
325
326char *
327ximemdup0 (void const *p, idx_t s)
328{
329 char *result = ximalloc (s + 1);
330 result[s] = 0;
331 return memcpy (result, p, s);
332}
333
116/* Clone STRING. */ 334/* Clone STRING. */
117 335
118char * 336char *
diff --git a/gl/xsize.c b/gl/xsize.c
index 4b4914c..279ae82 100644
--- a/gl/xsize.c
+++ b/gl/xsize.c
@@ -1,3 +1,21 @@
1/* Checked size_t computations.
2
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
1#include <config.h> 18#include <config.h>
19
2#define XSIZE_INLINE _GL_EXTERN_INLINE 20#define XSIZE_INLINE _GL_EXTERN_INLINE
3#include "xsize.h" 21#include "xsize.h"
diff --git a/gl/xsize.h b/gl/xsize.h
index 2922f35..1ec78e7 100644
--- a/gl/xsize.h
+++ b/gl/xsize.h
@@ -1,19 +1,19 @@
1/* xsize.h -- Checked size_t computations. 1/* xsize.h -- Checked size_t computations.
2 2
3 Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. 3 Copyright (C) 2003, 2008-2023 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file 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 Lesser General Public License as
7 the Free Software Foundation; either version 3, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file 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 Lesser 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 Lesser General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#ifndef _XSIZE_H 18#ifndef _XSIZE_H
19#define _XSIZE_H 19#define _XSIZE_H
@@ -27,6 +27,12 @@
27# include <stdint.h> 27# include <stdint.h>
28#endif 28#endif
29 29
30/* Get ATTRIBUTE_PURE. */
31#include "attribute.h"
32
33#ifndef _GL_INLINE_HEADER_BEGIN
34 #error "Please include config.h first."
35#endif
30_GL_INLINE_HEADER_BEGIN 36_GL_INLINE_HEADER_BEGIN
31#ifndef XSIZE_INLINE 37#ifndef XSIZE_INLINE
32# define XSIZE_INLINE _GL_INLINE 38# define XSIZE_INLINE _GL_INLINE
@@ -53,10 +59,7 @@ _GL_INLINE_HEADER_BEGIN
53 ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) 59 ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
54 60
55/* Sum of two sizes, with overflow check. */ 61/* Sum of two sizes, with overflow check. */
56XSIZE_INLINE size_t 62XSIZE_INLINE size_t ATTRIBUTE_PURE
57#if __GNUC__ >= 3
58__attribute__ ((__pure__))
59#endif
60xsum (size_t size1, size_t size2) 63xsum (size_t size1, size_t size2)
61{ 64{
62 size_t sum = size1 + size2; 65 size_t sum = size1 + size2;
@@ -64,30 +67,21 @@ xsum (size_t size1, size_t size2)
64} 67}
65 68
66/* Sum of three sizes, with overflow check. */ 69/* Sum of three sizes, with overflow check. */
67XSIZE_INLINE size_t 70XSIZE_INLINE size_t ATTRIBUTE_PURE
68#if __GNUC__ >= 3
69__attribute__ ((__pure__))
70#endif
71xsum3 (size_t size1, size_t size2, size_t size3) 71xsum3 (size_t size1, size_t size2, size_t size3)
72{ 72{
73 return xsum (xsum (size1, size2), size3); 73 return xsum (xsum (size1, size2), size3);
74} 74}
75 75
76/* Sum of four sizes, with overflow check. */ 76/* Sum of four sizes, with overflow check. */
77XSIZE_INLINE size_t 77XSIZE_INLINE size_t ATTRIBUTE_PURE
78#if __GNUC__ >= 3
79__attribute__ ((__pure__))
80#endif
81xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) 78xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
82{ 79{
83 return xsum (xsum (xsum (size1, size2), size3), size4); 80 return xsum (xsum (xsum (size1, size2), size3), size4);
84} 81}
85 82
86/* Maximum of two sizes, with overflow check. */ 83/* Maximum of two sizes, with overflow check. */
87XSIZE_INLINE size_t 84XSIZE_INLINE size_t ATTRIBUTE_PURE
88#if __GNUC__ >= 3
89__attribute__ ((__pure__))
90#endif
91xmax (size_t size1, size_t size2) 85xmax (size_t size1, size_t size2)
92{ 86{
93 /* No explicit check is needed here, because for any n: 87 /* No explicit check is needed here, because for any n:
diff --git a/gl/xstrndup.c b/gl/xstrndup.c
deleted file mode 100644
index eae92d0..0000000
--- a/gl/xstrndup.c
+++ /dev/null
@@ -1,36 +0,0 @@
1/* Duplicate a bounded initial segment of a string, with out-of-memory
2 checking.
3 Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#include "xstrndup.h"
22
23#include <string.h>
24#include "xalloc.h"
25
26/* Return a newly allocated copy of at most N bytes of STRING.
27 In other words, return a copy of the initial segment of length N of
28 STRING. */
29char *
30xstrndup (const char *string, size_t n)
31{
32 char *s = strndup (string, n);
33 if (! s)
34 xalloc_die ();
35 return s;
36}
diff --git a/gl/xstrndup.h b/gl/xstrndup.h
deleted file mode 100644
index 59673b0..0000000
--- a/gl/xstrndup.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/* Duplicate a bounded initial segment of a string, with out-of-memory
2 checking.
3 Copyright (C) 2003, 2009-2013 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 <stddef.h>
19
20/* Return a newly allocated copy of at most N bytes of STRING.
21 In other words, return a copy of the initial segment of length N of
22 STRING. */
23extern char *xstrndup (const char *string, size_t n);